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.

252454 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_PLUGINHOST_VST
  187. // #define JUCE_PLUGINHOST_VST 1
  188. #endif
  189. #ifndef JUCE_PLUGINHOST_AU
  190. // #define JUCE_PLUGINHOST_AU 1
  191. #endif
  192. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  193. //#define JUCE_ONLY_BUILD_CORE_LIBRARY 1
  194. #endif
  195. #ifndef JUCE_WEB_BROWSER
  196. #define JUCE_WEB_BROWSER 0
  197. #endif
  198. #ifndef JUCE_SUPPORT_CARBON
  199. #define JUCE_SUPPORT_CARBON 1
  200. #endif
  201. #ifndef JUCE_INCLUDE_ZLIB_CODE
  202. #define JUCE_INCLUDE_ZLIB_CODE 1
  203. #endif
  204. #ifndef JUCE_INCLUDE_FLAC_CODE
  205. #define JUCE_INCLUDE_FLAC_CODE 1
  206. #endif
  207. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  208. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  209. #endif
  210. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  211. #define JUCE_INCLUDE_PNGLIB_CODE 1
  212. #endif
  213. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  214. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  215. #endif
  216. #ifndef JUCE_CHECK_MEMORY_LEAKS
  217. #define JUCE_CHECK_MEMORY_LEAKS 1
  218. #endif
  219. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  220. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  221. #endif
  222. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  223. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  224. #undef JUCE_QUICKTIME
  225. #define JUCE_QUICKTIME 0
  226. #undef JUCE_OPENGL
  227. #define JUCE_OPENGL 0
  228. #undef JUCE_USE_CDBURNER
  229. #define JUCE_USE_CDBURNER 0
  230. #undef JUCE_USE_CDREADER
  231. #define JUCE_USE_CDREADER 0
  232. #undef JUCE_WEB_BROWSER
  233. #define JUCE_WEB_BROWSER 0
  234. #undef JUCE_PLUGINHOST_AU
  235. #define JUCE_PLUGINHOST_AU 0
  236. #undef JUCE_PLUGINHOST_VST
  237. #define JUCE_PLUGINHOST_VST 0
  238. #endif
  239. #endif
  240. /*** End of inlined file: juce_Config.h ***/
  241. // FORCE_AMALGAMATOR_INCLUDE
  242. #ifndef JUCE_BUILD_CORE
  243. #define JUCE_BUILD_CORE 1
  244. #endif
  245. #ifndef JUCE_BUILD_MISC
  246. #define JUCE_BUILD_MISC 1
  247. #endif
  248. #ifndef JUCE_BUILD_GUI
  249. #define JUCE_BUILD_GUI 1
  250. #endif
  251. #ifndef JUCE_BUILD_NATIVE
  252. #define JUCE_BUILD_NATIVE 1
  253. #endif
  254. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  255. #undef JUCE_BUILD_MISC
  256. #undef JUCE_BUILD_GUI
  257. #endif
  258. //==============================================================================
  259. #if JUCE_BUILD_NATIVE || JUCE_BUILD_CORE || (JUCE_BUILD_MISC && (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_AU))
  260. #if JUCE_WINDOWS
  261. /*** Start of inlined file: juce_win32_NativeIncludes.h ***/
  262. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  263. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  264. #ifndef STRICT
  265. #define STRICT 1
  266. #endif
  267. #undef WIN32_LEAN_AND_MEAN
  268. #define WIN32_LEAN_AND_MEAN 1
  269. #ifdef _MSC_VER
  270. #pragma warning (push)
  271. #pragma warning (disable : 4100 4201 4514 4312 4995)
  272. #endif
  273. #define _WIN32_WINNT 0x0500
  274. #define _UNICODE 1
  275. #define UNICODE 1
  276. #ifndef _WIN32_IE
  277. #define _WIN32_IE 0x0400
  278. #endif
  279. #include <windows.h>
  280. #include <windowsx.h>
  281. #include <commdlg.h>
  282. #include <shellapi.h>
  283. #include <mmsystem.h>
  284. #include <vfw.h>
  285. #include <tchar.h>
  286. #include <stddef.h>
  287. #include <ctime>
  288. #include <wininet.h>
  289. #include <nb30.h>
  290. #include <iphlpapi.h>
  291. #include <mapi.h>
  292. #include <float.h>
  293. #include <process.h>
  294. #include <Exdisp.h>
  295. #include <exdispid.h>
  296. #include <shlobj.h>
  297. #if ! JUCE_MINGW
  298. #include <crtdbg.h>
  299. #include <comutil.h>
  300. #endif
  301. #if JUCE_OPENGL
  302. #include <gl/gl.h>
  303. #endif
  304. #undef PACKED
  305. #if JUCE_ASIO
  306. #include "iasiodrv.h"
  307. #endif
  308. #if JUCE_USE_CDBURNER
  309. #include <imapi.h>
  310. #include <imapierror.h>
  311. #endif
  312. #if JUCE_USE_CAMERA
  313. #include <dshow.h>
  314. #include <qedit.h>
  315. #include <dshowasf.h>
  316. #endif
  317. #if JUCE_WASAPI
  318. #include <MMReg.h>
  319. #include <mmdeviceapi.h>
  320. #include <Audioclient.h>
  321. #include <Avrt.h>
  322. #include <functiondiscoverykeys.h>
  323. #endif
  324. #if JUCE_QUICKTIME
  325. #include <Movies.h>
  326. #include <QTML.h>
  327. #include <QuickTimeComponents.h>
  328. #include <MediaHandlers.h>
  329. #include <ImageCodec.h>
  330. #import <QTOLibrary.dll>
  331. #import <QTOControl.dll>
  332. #endif
  333. #ifdef _MSC_VER
  334. #pragma warning (pop)
  335. #endif
  336. template <class T>
  337. class ComSmartPtr
  338. {
  339. public:
  340. ComSmartPtr() throw() : p (0) {}
  341. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  342. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  343. ~ComSmartPtr() { if (p != 0) p->Release(); }
  344. operator T*() const throw() { return p; }
  345. T& operator*() const throw() { return *p; }
  346. T** operator&() throw() { return &p; }
  347. T* operator->() const throw() { return p; }
  348. T* operator= (T* const newP)
  349. {
  350. if (newP != 0)
  351. newP->AddRef();
  352. if (p != 0)
  353. p->Release();
  354. p = newP;
  355. return newP;
  356. }
  357. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  358. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  359. {
  360. #ifndef __MINGW32__
  361. operator= (0);
  362. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  363. #else
  364. return S_FALSE;
  365. #endif
  366. }
  367. T* p;
  368. };
  369. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  370. /*** End of inlined file: juce_win32_NativeIncludes.h ***/
  371. #elif JUCE_LINUX
  372. /*** Start of inlined file: juce_linux_NativeIncludes.h ***/
  373. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  374. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  375. #include <sched.h>
  376. #include <pthread.h>
  377. #include <sys/time.h>
  378. #include <errno.h>
  379. #include <sys/stat.h>
  380. #include <sys/dir.h>
  381. #include <sys/ptrace.h>
  382. #include <sys/vfs.h>
  383. #include <sys/wait.h>
  384. #include <fnmatch.h>
  385. #include <utime.h>
  386. #include <pwd.h>
  387. #include <fcntl.h>
  388. #include <dlfcn.h>
  389. #include <netdb.h>
  390. #include <arpa/inet.h>
  391. #include <netinet/in.h>
  392. #include <sys/types.h>
  393. #include <sys/ioctl.h>
  394. #include <sys/socket.h>
  395. #include <linux/if.h>
  396. #include <sys/sysinfo.h>
  397. #include <sys/file.h>
  398. #include <signal.h>
  399. #include <ft2build.h>
  400. #include FT_FREETYPE_H
  401. #include <X11/Xlib.h>
  402. #include <X11/Xatom.h>
  403. #include <X11/Xresource.h>
  404. #include <X11/Xutil.h>
  405. #include <X11/Xmd.h>
  406. #include <X11/keysym.h>
  407. #include <X11/cursorfont.h>
  408. #if JUCE_USE_XINERAMA
  409. #include <X11/extensions/Xinerama.h>
  410. #endif
  411. #if JUCE_USE_XSHM
  412. #include <X11/extensions/XShm.h>
  413. #include <sys/shm.h>
  414. #include <sys/ipc.h>
  415. #endif
  416. #if JUCE_USE_XRENDER
  417. // If you're missing these headers, try installing the libxrender-dev and libxcomposite-dev
  418. #include <X11/extensions/Xrender.h>
  419. #include <X11/extensions/Xcomposite.h>
  420. #endif
  421. #if JUCE_OPENGL
  422. #include <GL/glx.h>
  423. #endif
  424. #undef KeyPress
  425. #if JUCE_ALSA
  426. #include <alsa/asoundlib.h>
  427. #endif
  428. #if JUCE_JACK
  429. #include <jack/jack.h>
  430. //#include <jack/transport.h>
  431. #endif
  432. #undef SIZEOF
  433. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  434. /*** End of inlined file: juce_linux_NativeIncludes.h ***/
  435. #elif JUCE_MAC || JUCE_IPHONE
  436. /*** Start of inlined file: juce_mac_NativeIncludes.h ***/
  437. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  438. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  439. #define USE_COREGRAPHICS_RENDERING 1
  440. #if JUCE_IPHONE
  441. #import <Foundation/Foundation.h>
  442. #import <UIKit/UIKit.h>
  443. #import <AudioToolbox/AudioToolbox.h>
  444. #import <AVFoundation/AVFoundation.h>
  445. #import <CoreData/CoreData.h>
  446. #import <MobileCoreServices/MobileCoreServices.h>
  447. #import <QuartzCore/QuartzCore.h>
  448. #include <sys/fcntl.h>
  449. #if JUCE_OPENGL
  450. #include <OpenGLES/ES1/gl.h>
  451. #include <OpenGLES/ES1/glext.h>
  452. #endif
  453. #else
  454. #import <Cocoa/Cocoa.h>
  455. #import <CoreAudio/HostTime.h>
  456. #import <CoreAudio/AudioHardware.h>
  457. #import <CoreMIDI/MIDIServices.h>
  458. #import <QTKit/QTKit.h>
  459. #import <WebKit/WebKit.h>
  460. #import <DiscRecording/DiscRecording.h>
  461. #import <IOKit/IOKitLib.h>
  462. #import <IOKit/IOCFPlugIn.h>
  463. #import <IOKit/hid/IOHIDLib.h>
  464. #import <IOKit/hid/IOHIDKeys.h>
  465. #import <IOKit/pwr_mgt/IOPMLib.h>
  466. #include <Carbon/Carbon.h>
  467. #include <sys/dir.h>
  468. #include <sys/socket.h>
  469. #endif
  470. #include <sys/sysctl.h>
  471. #include <sys/stat.h>
  472. #include <sys/param.h>
  473. #include <sys/mount.h>
  474. #include <fnmatch.h>
  475. #include <utime.h>
  476. #include <dlfcn.h>
  477. #include <ifaddrs.h>
  478. #include <net/if_dl.h>
  479. #include <mach/mach_time.h>
  480. #if MACOS_10_4_OR_EARLIER
  481. #include <GLUT/glut.h>
  482. #endif
  483. #if ! CGFLOAT_DEFINED
  484. #define CGFloat float
  485. #endif
  486. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  487. /*** End of inlined file: juce_mac_NativeIncludes.h ***/
  488. #else
  489. #error "Unknown platform!"
  490. #endif
  491. #endif
  492. //==============================================================================
  493. #define DONT_SET_USING_JUCE_NAMESPACE 1
  494. #undef max
  495. #undef min
  496. #define NO_DUMMY_DECL
  497. #if JUCE_BUILD_NATIVE
  498. #include "juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE
  499. #endif
  500. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  501. #pragma warning (disable: 4309 4305)
  502. #endif
  503. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  504. BEGIN_JUCE_NAMESPACE
  505. /*** Start of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  506. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  507. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  508. class CarbonViewWrapperComponent : public Component,
  509. public ComponentMovementWatcher,
  510. public Timer
  511. {
  512. public:
  513. CarbonViewWrapperComponent()
  514. : ComponentMovementWatcher (this),
  515. wrapperWindow (0),
  516. embeddedView (0),
  517. recursiveResize (false)
  518. {
  519. }
  520. virtual ~CarbonViewWrapperComponent()
  521. {
  522. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  523. }
  524. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  525. virtual void removeView (HIViewRef embeddedView) = 0;
  526. virtual void mouseDown (int x, int y) {}
  527. virtual void paint() {}
  528. virtual bool getEmbeddedViewSize (int& w, int& h)
  529. {
  530. if (embeddedView == 0)
  531. return false;
  532. HIRect bounds;
  533. HIViewGetBounds (embeddedView, &bounds);
  534. w = jmax (1, roundToInt (bounds.size.width));
  535. h = jmax (1, roundToInt (bounds.size.height));
  536. return true;
  537. }
  538. void createWindow()
  539. {
  540. if (wrapperWindow == 0)
  541. {
  542. Rect r;
  543. r.left = getScreenX();
  544. r.top = getScreenY();
  545. r.right = r.left + getWidth();
  546. r.bottom = r.top + getHeight();
  547. CreateNewWindow (kDocumentWindowClass,
  548. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  549. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  550. &r, &wrapperWindow);
  551. jassert (wrapperWindow != 0);
  552. if (wrapperWindow == 0)
  553. return;
  554. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  555. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  556. [ownerWindow addChildWindow: carbonWindow
  557. ordered: NSWindowAbove];
  558. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  559. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  560. { kEventClassWindow, kEventWindowHandleDeactivate } };
  561. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  562. InstallWindowEventHandler (wrapperWindow, upp,
  563. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  564. windowEventTypes, this, &eventHandlerRef);
  565. setOurSizeToEmbeddedViewSize();
  566. setEmbeddedWindowToOurSize();
  567. creationTime = Time::getCurrentTime();
  568. }
  569. }
  570. void deleteWindow()
  571. {
  572. removeView (embeddedView);
  573. embeddedView = 0;
  574. if (wrapperWindow != 0)
  575. {
  576. RemoveEventHandler (eventHandlerRef);
  577. DisposeWindow (wrapperWindow);
  578. wrapperWindow = 0;
  579. }
  580. }
  581. void setOurSizeToEmbeddedViewSize()
  582. {
  583. int w, h;
  584. if (getEmbeddedViewSize (w, h))
  585. {
  586. if (w != getWidth() || h != getHeight())
  587. {
  588. startTimer (50);
  589. setSize (w, h);
  590. if (getParentComponent() != 0)
  591. getParentComponent()->setSize (w, h);
  592. }
  593. else
  594. {
  595. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  596. }
  597. }
  598. else
  599. {
  600. stopTimer();
  601. }
  602. }
  603. void setEmbeddedWindowToOurSize()
  604. {
  605. if (! recursiveResize)
  606. {
  607. recursiveResize = true;
  608. if (embeddedView != 0)
  609. {
  610. HIRect r;
  611. r.origin.x = 0;
  612. r.origin.y = 0;
  613. r.size.width = (float) getWidth();
  614. r.size.height = (float) getHeight();
  615. HIViewSetFrame (embeddedView, &r);
  616. }
  617. if (wrapperWindow != 0)
  618. {
  619. Rect wr;
  620. wr.left = getScreenX();
  621. wr.top = getScreenY();
  622. wr.right = wr.left + getWidth();
  623. wr.bottom = wr.top + getHeight();
  624. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  625. ShowWindow (wrapperWindow);
  626. }
  627. recursiveResize = false;
  628. }
  629. }
  630. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  631. {
  632. setEmbeddedWindowToOurSize();
  633. }
  634. void componentPeerChanged()
  635. {
  636. deleteWindow();
  637. createWindow();
  638. }
  639. void componentVisibilityChanged (Component&)
  640. {
  641. if (isShowing())
  642. createWindow();
  643. else
  644. deleteWindow();
  645. setEmbeddedWindowToOurSize();
  646. }
  647. static void recursiveHIViewRepaint (HIViewRef view)
  648. {
  649. HIViewSetNeedsDisplay (view, true);
  650. HIViewRef child = HIViewGetFirstSubview (view);
  651. while (child != 0)
  652. {
  653. recursiveHIViewRepaint (child);
  654. child = HIViewGetNextView (child);
  655. }
  656. }
  657. void timerCallback()
  658. {
  659. setOurSizeToEmbeddedViewSize();
  660. // To avoid strange overpainting problems when the UI is first opened, we'll
  661. // repaint it a few times during the first second that it's on-screen..
  662. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  663. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  664. }
  665. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  666. EventRef event)
  667. {
  668. switch (GetEventKind (event))
  669. {
  670. case kEventWindowHandleDeactivate:
  671. ActivateWindow (wrapperWindow, TRUE);
  672. break;
  673. case kEventWindowGetClickActivation:
  674. {
  675. getTopLevelComponent()->toFront (false);
  676. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  677. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  678. sizeof (ClickActivationResult), &howToHandleClick);
  679. HIViewSetNeedsDisplay (embeddedView, true);
  680. }
  681. break;
  682. }
  683. return noErr;
  684. }
  685. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  686. EventRef event, void* userData)
  687. {
  688. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  689. }
  690. protected:
  691. WindowRef wrapperWindow;
  692. HIViewRef embeddedView;
  693. bool recursiveResize;
  694. Time creationTime;
  695. EventHandlerRef eventHandlerRef;
  696. };
  697. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  698. /*** End of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  699. END_JUCE_NAMESPACE
  700. #endif
  701. #define JUCE_AMALGAMATED_TEMPLATE 1
  702. //==============================================================================
  703. #if JUCE_BUILD_CORE
  704. /*** Start of inlined file: juce_FileLogger.cpp ***/
  705. BEGIN_JUCE_NAMESPACE
  706. FileLogger::FileLogger (const File& logFile_,
  707. const String& welcomeMessage,
  708. const int maxInitialFileSizeBytes)
  709. : logFile (logFile_)
  710. {
  711. if (maxInitialFileSizeBytes >= 0)
  712. trimFileSize (maxInitialFileSizeBytes);
  713. if (! logFile_.exists())
  714. {
  715. // do this so that the parent directories get created..
  716. logFile_.create();
  717. }
  718. logStream = logFile_.createOutputStream (256);
  719. jassert (logStream != 0);
  720. String welcome;
  721. welcome << "\r\n**********************************************************\r\n"
  722. << welcomeMessage
  723. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  724. << "\r\n";
  725. logMessage (welcome);
  726. }
  727. FileLogger::~FileLogger()
  728. {
  729. }
  730. void FileLogger::logMessage (const String& message)
  731. {
  732. if (logStream != 0)
  733. {
  734. DBG (message);
  735. const ScopedLock sl (logLock);
  736. (*logStream) << message << T("\r\n");
  737. logStream->flush();
  738. }
  739. }
  740. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  741. {
  742. if (maxFileSizeBytes <= 0)
  743. {
  744. logFile.deleteFile();
  745. }
  746. else
  747. {
  748. const int64 fileSize = logFile.getSize();
  749. if (fileSize > maxFileSizeBytes)
  750. {
  751. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  752. jassert (in != 0);
  753. if (in != 0)
  754. {
  755. in->setPosition (fileSize - maxFileSizeBytes);
  756. String content;
  757. {
  758. MemoryBlock contentToSave;
  759. contentToSave.setSize (maxFileSizeBytes + 4);
  760. contentToSave.fillWith (0);
  761. in->read (contentToSave.getData(), maxFileSizeBytes);
  762. in = 0;
  763. content = contentToSave.toString();
  764. }
  765. int newStart = 0;
  766. while (newStart < fileSize
  767. && content[newStart] != '\n'
  768. && content[newStart] != '\r')
  769. ++newStart;
  770. logFile.deleteFile();
  771. logFile.appendText (content.substring (newStart), false, false);
  772. }
  773. }
  774. }
  775. }
  776. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  777. const String& logFileName,
  778. const String& welcomeMessage,
  779. const int maxInitialFileSizeBytes)
  780. {
  781. #if JUCE_MAC
  782. File logFile ("~/Library/Logs");
  783. logFile = logFile.getChildFile (logFileSubDirectoryName)
  784. .getChildFile (logFileName);
  785. #else
  786. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  787. if (logFile.isDirectory())
  788. {
  789. logFile = logFile.getChildFile (logFileSubDirectoryName)
  790. .getChildFile (logFileName);
  791. }
  792. #endif
  793. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  794. }
  795. END_JUCE_NAMESPACE
  796. /*** End of inlined file: juce_FileLogger.cpp ***/
  797. /*** Start of inlined file: juce_Logger.cpp ***/
  798. BEGIN_JUCE_NAMESPACE
  799. Logger::Logger()
  800. {
  801. }
  802. Logger::~Logger()
  803. {
  804. }
  805. static Logger* currentLogger = 0;
  806. void Logger::setCurrentLogger (Logger* const newLogger,
  807. const bool deleteOldLogger)
  808. {
  809. Logger* const oldLogger = currentLogger;
  810. currentLogger = newLogger;
  811. if (deleteOldLogger)
  812. delete oldLogger;
  813. }
  814. void Logger::writeToLog (const String& message)
  815. {
  816. if (currentLogger != 0)
  817. currentLogger->logMessage (message);
  818. else
  819. outputDebugString (message);
  820. }
  821. #if JUCE_LOG_ASSERTIONS
  822. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  823. {
  824. String m ("JUCE Assertion failure in ");
  825. m << filename << ", line " << lineNum;
  826. Logger::writeToLog (m);
  827. }
  828. #endif
  829. END_JUCE_NAMESPACE
  830. /*** End of inlined file: juce_Logger.cpp ***/
  831. /*** Start of inlined file: juce_Random.cpp ***/
  832. BEGIN_JUCE_NAMESPACE
  833. Random::Random (const int64 seedValue) throw()
  834. : seed (seedValue)
  835. {
  836. }
  837. Random::~Random() throw()
  838. {
  839. }
  840. void Random::setSeed (const int64 newSeed) throw()
  841. {
  842. seed = newSeed;
  843. }
  844. void Random::combineSeed (const int64 seedValue) throw()
  845. {
  846. seed ^= nextInt64() ^ seedValue;
  847. }
  848. void Random::setSeedRandomly()
  849. {
  850. combineSeed ((int64) (pointer_sized_int) this);
  851. combineSeed (Time::getMillisecondCounter());
  852. combineSeed (Time::getHighResolutionTicks());
  853. combineSeed (Time::getHighResolutionTicksPerSecond());
  854. combineSeed (Time::currentTimeMillis());
  855. }
  856. int Random::nextInt() throw()
  857. {
  858. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  859. return (int) (seed >> 16);
  860. }
  861. int Random::nextInt (const int maxValue) throw()
  862. {
  863. jassert (maxValue > 0);
  864. return (nextInt() & 0x7fffffff) % maxValue;
  865. }
  866. int64 Random::nextInt64() throw()
  867. {
  868. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  869. }
  870. bool Random::nextBool() throw()
  871. {
  872. return (nextInt() & 0x80000000) != 0;
  873. }
  874. float Random::nextFloat() throw()
  875. {
  876. return static_cast <uint32> (nextInt()) / (float) 0xffffffff;
  877. }
  878. double Random::nextDouble() throw()
  879. {
  880. return static_cast <uint32> (nextInt()) / (double) 0xffffffff;
  881. }
  882. const BigInteger Random::nextLargeNumber (const BigInteger& maximumValue)
  883. {
  884. BigInteger n;
  885. do
  886. {
  887. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  888. }
  889. while (n >= maximumValue);
  890. return n;
  891. }
  892. void Random::fillBitsRandomly (BigInteger& arrayToChange, int startBit, int numBits)
  893. {
  894. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  895. while ((startBit & 31) != 0 && numBits > 0)
  896. {
  897. arrayToChange.setBit (startBit++, nextBool());
  898. --numBits;
  899. }
  900. while (numBits >= 32)
  901. {
  902. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  903. startBit += 32;
  904. numBits -= 32;
  905. }
  906. while (--numBits >= 0)
  907. arrayToChange.setBit (startBit + numBits, nextBool());
  908. }
  909. Random& Random::getSystemRandom() throw()
  910. {
  911. static Random sysRand (1);
  912. return sysRand;
  913. }
  914. END_JUCE_NAMESPACE
  915. /*** End of inlined file: juce_Random.cpp ***/
  916. /*** Start of inlined file: juce_RelativeTime.cpp ***/
  917. BEGIN_JUCE_NAMESPACE
  918. RelativeTime::RelativeTime (const double seconds_) throw()
  919. : seconds (seconds_)
  920. {
  921. }
  922. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  923. : seconds (other.seconds)
  924. {
  925. }
  926. RelativeTime::~RelativeTime() throw()
  927. {
  928. }
  929. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  930. {
  931. return RelativeTime (milliseconds * 0.001);
  932. }
  933. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  934. {
  935. return RelativeTime (milliseconds * 0.001);
  936. }
  937. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  938. {
  939. return RelativeTime (numberOfMinutes * 60.0);
  940. }
  941. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  942. {
  943. return RelativeTime (numberOfHours * (60.0 * 60.0));
  944. }
  945. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  946. {
  947. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  948. }
  949. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  950. {
  951. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  952. }
  953. int64 RelativeTime::inMilliseconds() const throw()
  954. {
  955. return (int64)(seconds * 1000.0);
  956. }
  957. double RelativeTime::inMinutes() const throw()
  958. {
  959. return seconds / 60.0;
  960. }
  961. double RelativeTime::inHours() const throw()
  962. {
  963. return seconds / (60.0 * 60.0);
  964. }
  965. double RelativeTime::inDays() const throw()
  966. {
  967. return seconds / (60.0 * 60.0 * 24.0);
  968. }
  969. double RelativeTime::inWeeks() const throw()
  970. {
  971. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  972. }
  973. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  974. {
  975. if (seconds < 0.001 && seconds > -0.001)
  976. return returnValueForZeroTime;
  977. String result;
  978. if (seconds < 0)
  979. result = T("-");
  980. int fieldsShown = 0;
  981. int n = abs ((int) inWeeks());
  982. if (n > 0)
  983. {
  984. result << n << ((n == 1) ? TRANS(" week ")
  985. : TRANS(" weeks "));
  986. ++fieldsShown;
  987. }
  988. n = abs ((int) inDays()) % 7;
  989. if (n > 0)
  990. {
  991. result << n << ((n == 1) ? TRANS(" day ")
  992. : TRANS(" days "));
  993. ++fieldsShown;
  994. }
  995. if (fieldsShown < 2)
  996. {
  997. n = abs ((int) inHours()) % 24;
  998. if (n > 0)
  999. {
  1000. result << n << ((n == 1) ? TRANS(" hr ")
  1001. : TRANS(" hrs "));
  1002. ++fieldsShown;
  1003. }
  1004. if (fieldsShown < 2)
  1005. {
  1006. n = abs ((int) inMinutes()) % 60;
  1007. if (n > 0)
  1008. {
  1009. result << n << ((n == 1) ? TRANS(" min ")
  1010. : TRANS(" mins "));
  1011. ++fieldsShown;
  1012. }
  1013. if (fieldsShown < 2)
  1014. {
  1015. n = abs ((int) inSeconds()) % 60;
  1016. if (n > 0)
  1017. {
  1018. result << n << ((n == 1) ? TRANS(" sec ")
  1019. : TRANS(" secs "));
  1020. ++fieldsShown;
  1021. }
  1022. if (fieldsShown < 1)
  1023. {
  1024. n = abs ((int) inMilliseconds()) % 1000;
  1025. if (n > 0)
  1026. {
  1027. result << n << TRANS(" ms");
  1028. ++fieldsShown;
  1029. }
  1030. }
  1031. }
  1032. }
  1033. }
  1034. return result.trimEnd();
  1035. }
  1036. RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  1037. {
  1038. seconds = other.seconds;
  1039. return *this;
  1040. }
  1041. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  1042. {
  1043. return seconds == other.seconds;
  1044. }
  1045. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  1046. {
  1047. return seconds != other.seconds;
  1048. }
  1049. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  1050. {
  1051. return seconds > other.seconds;
  1052. }
  1053. bool RelativeTime::operator< (const RelativeTime& other) const throw()
  1054. {
  1055. return seconds < other.seconds;
  1056. }
  1057. bool RelativeTime::operator>= (const RelativeTime& other) const throw()
  1058. {
  1059. return seconds >= other.seconds;
  1060. }
  1061. bool RelativeTime::operator<= (const RelativeTime& other) const throw()
  1062. {
  1063. return seconds <= other.seconds;
  1064. }
  1065. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1066. {
  1067. return RelativeTime (seconds + timeToAdd.seconds);
  1068. }
  1069. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1070. {
  1071. return RelativeTime (seconds - timeToSubtract.seconds);
  1072. }
  1073. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1074. {
  1075. return RelativeTime (seconds + secondsToAdd);
  1076. }
  1077. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1078. {
  1079. return RelativeTime (seconds - secondsToSubtract);
  1080. }
  1081. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1082. {
  1083. seconds += timeToAdd.seconds;
  1084. return *this;
  1085. }
  1086. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1087. {
  1088. seconds -= timeToSubtract.seconds;
  1089. return *this;
  1090. }
  1091. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1092. {
  1093. seconds += secondsToAdd;
  1094. return *this;
  1095. }
  1096. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1097. {
  1098. seconds -= secondsToSubtract;
  1099. return *this;
  1100. }
  1101. END_JUCE_NAMESPACE
  1102. /*** End of inlined file: juce_RelativeTime.cpp ***/
  1103. /*** Start of inlined file: juce_SystemStats.cpp ***/
  1104. BEGIN_JUCE_NAMESPACE
  1105. const String SystemStats::getJUCEVersion() throw()
  1106. {
  1107. return "JUCE v" + String (JUCE_MAJOR_VERSION)
  1108. + "." + String (JUCE_MINOR_VERSION)
  1109. + "." + String (JUCE_BUILDNUMBER);
  1110. }
  1111. const StringArray SystemStats::getMACAddressStrings()
  1112. {
  1113. int64 macAddresses [16];
  1114. const int numAddresses = getMACAddresses (macAddresses, numElementsInArray (macAddresses), false);
  1115. StringArray s;
  1116. for (int i = 0; i < numAddresses; ++i)
  1117. {
  1118. s.add (String::toHexString (0xff & (int) (macAddresses [i] >> 40)).paddedLeft ('0', 2)
  1119. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 32)).paddedLeft ('0', 2)
  1120. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 24)).paddedLeft ('0', 2)
  1121. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 16)).paddedLeft ('0', 2)
  1122. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 8)).paddedLeft ('0', 2)
  1123. + "-" + String::toHexString (0xff & (int) (macAddresses [i] >> 0)).paddedLeft ('0', 2));
  1124. }
  1125. return s;
  1126. }
  1127. static bool juceInitialisedNonGUI = false;
  1128. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1129. {
  1130. if (! juceInitialisedNonGUI)
  1131. {
  1132. #if JUCE_MAC || JUCE_IPHONE
  1133. const ScopedAutoReleasePool pool;
  1134. #endif
  1135. #ifdef JUCE_DEBUG
  1136. {
  1137. // Some simple test code to keep an eye on things and make sure these functions
  1138. // work ok on all platforms. Let me know if any of these assertions fail!
  1139. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1140. char a1[7];
  1141. jassert (numElementsInArray(a1) == 7);
  1142. int a2[3];
  1143. jassert (numElementsInArray(a2) == 3);
  1144. int n = 1;
  1145. Atomic::increment (n);
  1146. jassert (Atomic::incrementAndReturn (n) == 3);
  1147. Atomic::decrement (n);
  1148. jassert (Atomic::decrementAndReturn (n) == 1);
  1149. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1150. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1151. // Some quick stream tests..
  1152. int randomInt = Random::getSystemRandom().nextInt();
  1153. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1154. double randomDouble = Random::getSystemRandom().nextDouble();
  1155. String randomString;
  1156. for (int i = 50; --i >= 0;)
  1157. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1158. MemoryOutputStream mo;
  1159. mo.writeInt (randomInt);
  1160. mo.writeIntBigEndian (randomInt);
  1161. mo.writeCompressedInt (randomInt);
  1162. mo.writeString (randomString);
  1163. mo.writeInt64 (randomInt64);
  1164. mo.writeInt64BigEndian (randomInt64);
  1165. mo.writeDouble (randomDouble);
  1166. mo.writeDoubleBigEndian (randomDouble);
  1167. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1168. jassert (mi.readInt() == randomInt);
  1169. jassert (mi.readIntBigEndian() == randomInt);
  1170. jassert (mi.readCompressedInt() == randomInt);
  1171. jassert (mi.readString() == randomString);
  1172. jassert (mi.readInt64() == randomInt64);
  1173. jassert (mi.readInt64BigEndian() == randomInt64);
  1174. jassert (mi.readDouble() == randomDouble);
  1175. jassert (mi.readDoubleBigEndian() == randomDouble);
  1176. }
  1177. #endif
  1178. // Now the real initialisation..
  1179. juceInitialisedNonGUI = true;
  1180. DBG (SystemStats::getJUCEVersion());
  1181. SystemStats::initialiseStats();
  1182. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1183. }
  1184. }
  1185. #if JUCE_WINDOWS
  1186. // This is imported from the sockets code..
  1187. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1188. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1189. #endif
  1190. #if JUCE_DEBUG
  1191. extern void juce_CheckForDanglingStreams();
  1192. #endif
  1193. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1194. {
  1195. if (juceInitialisedNonGUI)
  1196. {
  1197. #if JUCE_MAC || JUCE_IPHONE
  1198. const ScopedAutoReleasePool pool;
  1199. #endif
  1200. #if JUCE_WINDOWS
  1201. // need to shut down sockets if they were used..
  1202. if (juce_CloseWin32SocketLib != 0)
  1203. (*juce_CloseWin32SocketLib)();
  1204. #endif
  1205. LocalisedStrings::setCurrentMappings (0);
  1206. Thread::stopAllThreads (3000);
  1207. #if JUCE_DEBUG
  1208. juce_CheckForDanglingStreams();
  1209. #endif
  1210. juceInitialisedNonGUI = false;
  1211. }
  1212. }
  1213. #ifdef JUCE_DLL
  1214. void* juce_Malloc (const int size)
  1215. {
  1216. return malloc (size);
  1217. }
  1218. void* juce_Calloc (const int size)
  1219. {
  1220. return calloc (1, size);
  1221. }
  1222. void* juce_Realloc (void* const block, const int size)
  1223. {
  1224. return realloc (block, size);
  1225. }
  1226. void juce_Free (void* const block)
  1227. {
  1228. free (block);
  1229. }
  1230. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1231. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1232. {
  1233. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1234. }
  1235. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1236. {
  1237. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1238. }
  1239. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1240. {
  1241. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1242. }
  1243. void juce_DebugFree (void* const block)
  1244. {
  1245. _free_dbg (block, _NORMAL_BLOCK);
  1246. }
  1247. #endif
  1248. #endif
  1249. END_JUCE_NAMESPACE
  1250. /*** End of inlined file: juce_SystemStats.cpp ***/
  1251. /*** Start of inlined file: juce_Time.cpp ***/
  1252. #ifdef _MSC_VER
  1253. #pragma warning (disable: 4514)
  1254. #pragma warning (push)
  1255. #endif
  1256. #ifndef JUCE_WINDOWS
  1257. #include <sys/time.h>
  1258. #else
  1259. #include <ctime>
  1260. #endif
  1261. #include <sys/timeb.h>
  1262. BEGIN_JUCE_NAMESPACE
  1263. #ifdef _MSC_VER
  1264. #pragma warning (pop)
  1265. #ifdef _INC_TIME_INL
  1266. #define USE_NEW_SECURE_TIME_FNS
  1267. #endif
  1268. #endif
  1269. namespace TimeHelpers
  1270. {
  1271. static struct tm millisToLocal (const int64 millis) throw()
  1272. {
  1273. struct tm result;
  1274. const int64 seconds = millis / 1000;
  1275. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1276. {
  1277. // use extended maths for dates beyond 1970 to 2037..
  1278. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1279. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1280. const int days = (int) (jdm / literal64bit (86400));
  1281. const int a = 32044 + days;
  1282. const int b = (4 * a + 3) / 146097;
  1283. const int c = a - (b * 146097) / 4;
  1284. const int d = (4 * c + 3) / 1461;
  1285. const int e = c - (d * 1461) / 4;
  1286. const int m = (5 * e + 2) / 153;
  1287. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1288. result.tm_mon = m + 2 - 12 * (m / 10);
  1289. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1290. result.tm_wday = (days + 1) % 7;
  1291. result.tm_yday = -1;
  1292. int t = (int) (jdm % literal64bit (86400));
  1293. result.tm_hour = t / 3600;
  1294. t %= 3600;
  1295. result.tm_min = t / 60;
  1296. result.tm_sec = t % 60;
  1297. result.tm_isdst = -1;
  1298. }
  1299. else
  1300. {
  1301. time_t now = static_cast <time_t> (seconds);
  1302. #if JUCE_WINDOWS
  1303. #ifdef USE_NEW_SECURE_TIME_FNS
  1304. if (now >= 0 && now <= 0x793406fff)
  1305. localtime_s (&result, &now);
  1306. else
  1307. zeromem (&result, sizeof (result));
  1308. #else
  1309. result = *localtime (&now);
  1310. #endif
  1311. #else
  1312. // more thread-safe
  1313. localtime_r (&now, &result);
  1314. #endif
  1315. }
  1316. return result;
  1317. }
  1318. static int extendedModulo (const int64 value, const int modulo) throw()
  1319. {
  1320. return (int) (value >= 0 ? (value % modulo)
  1321. : (value - ((value / modulo) + 1) * modulo));
  1322. }
  1323. static uint32 lastMSCounterValue = 0;
  1324. }
  1325. Time::Time() throw()
  1326. : millisSinceEpoch (0)
  1327. {
  1328. }
  1329. Time::Time (const Time& other) throw()
  1330. : millisSinceEpoch (other.millisSinceEpoch)
  1331. {
  1332. }
  1333. Time::Time (const int64 ms) throw()
  1334. : millisSinceEpoch (ms)
  1335. {
  1336. }
  1337. Time::Time (const int year,
  1338. const int month,
  1339. const int day,
  1340. const int hours,
  1341. const int minutes,
  1342. const int seconds,
  1343. const int milliseconds,
  1344. const bool useLocalTime) throw()
  1345. {
  1346. jassert (year > 100); // year must be a 4-digit version
  1347. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1348. {
  1349. // use extended maths for dates beyond 1970 to 2037..
  1350. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1351. : 0;
  1352. const int a = (13 - month) / 12;
  1353. const int y = year + 4800 - a;
  1354. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1355. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1356. - 32045;
  1357. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1358. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1359. + milliseconds;
  1360. }
  1361. else
  1362. {
  1363. struct tm t;
  1364. t.tm_year = year - 1900;
  1365. t.tm_mon = month;
  1366. t.tm_mday = day;
  1367. t.tm_hour = hours;
  1368. t.tm_min = minutes;
  1369. t.tm_sec = seconds;
  1370. t.tm_isdst = -1;
  1371. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1372. if (millisSinceEpoch < 0)
  1373. millisSinceEpoch = 0;
  1374. else
  1375. millisSinceEpoch += milliseconds;
  1376. }
  1377. }
  1378. Time::~Time() throw()
  1379. {
  1380. }
  1381. Time& Time::operator= (const Time& other) throw()
  1382. {
  1383. millisSinceEpoch = other.millisSinceEpoch;
  1384. return *this;
  1385. }
  1386. int64 Time::currentTimeMillis() throw()
  1387. {
  1388. static uint32 lastCounterResult = 0xffffffff;
  1389. static int64 correction = 0;
  1390. const uint32 now = getMillisecondCounter();
  1391. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1392. if (now < lastCounterResult)
  1393. {
  1394. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1395. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1396. {
  1397. // get the time once using normal library calls, and store the difference needed to
  1398. // turn the millisecond counter into a real time.
  1399. #if JUCE_WINDOWS
  1400. struct _timeb t;
  1401. #ifdef USE_NEW_SECURE_TIME_FNS
  1402. _ftime_s (&t);
  1403. #else
  1404. _ftime (&t);
  1405. #endif
  1406. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1407. #else
  1408. struct timeval tv;
  1409. struct timezone tz;
  1410. gettimeofday (&tv, &tz);
  1411. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1412. #endif
  1413. }
  1414. }
  1415. lastCounterResult = now;
  1416. return correction + now;
  1417. }
  1418. uint32 juce_millisecondsSinceStartup() throw();
  1419. uint32 Time::getMillisecondCounter() throw()
  1420. {
  1421. const uint32 now = juce_millisecondsSinceStartup();
  1422. if (now < TimeHelpers::lastMSCounterValue)
  1423. {
  1424. // in multi-threaded apps this might be called concurrently, so
  1425. // make sure that our last counter value only increases and doesn't
  1426. // go backwards..
  1427. if (now < TimeHelpers::lastMSCounterValue - 1000)
  1428. TimeHelpers::lastMSCounterValue = now;
  1429. }
  1430. else
  1431. {
  1432. TimeHelpers::lastMSCounterValue = now;
  1433. }
  1434. return now;
  1435. }
  1436. uint32 Time::getApproximateMillisecondCounter() throw()
  1437. {
  1438. jassert (TimeHelpers::lastMSCounterValue != 0);
  1439. return TimeHelpers::lastMSCounterValue;
  1440. }
  1441. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1442. {
  1443. for (;;)
  1444. {
  1445. const uint32 now = getMillisecondCounter();
  1446. if (now >= targetTime)
  1447. break;
  1448. const int toWait = targetTime - now;
  1449. if (toWait > 2)
  1450. {
  1451. Thread::sleep (jmin (20, toWait >> 1));
  1452. }
  1453. else
  1454. {
  1455. // xxx should consider using mutex_pause on the mac as it apparently
  1456. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1457. for (int i = 10; --i >= 0;)
  1458. Thread::yield();
  1459. }
  1460. }
  1461. }
  1462. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1463. {
  1464. return ticks / (double) getHighResolutionTicksPerSecond();
  1465. }
  1466. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1467. {
  1468. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1469. }
  1470. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1471. {
  1472. return Time (currentTimeMillis());
  1473. }
  1474. const String Time::toString (const bool includeDate,
  1475. const bool includeTime,
  1476. const bool includeSeconds,
  1477. const bool use24HourClock) const throw()
  1478. {
  1479. String result;
  1480. if (includeDate)
  1481. {
  1482. result << getDayOfMonth() << ' '
  1483. << getMonthName (true) << ' '
  1484. << getYear();
  1485. if (includeTime)
  1486. result << ' ';
  1487. }
  1488. if (includeTime)
  1489. {
  1490. const int mins = getMinutes();
  1491. result << (use24HourClock ? getHours() : getHoursInAmPmFormat())
  1492. << (mins < 10 ? ":0" : ":") << mins;
  1493. if (includeSeconds)
  1494. {
  1495. const int secs = getSeconds();
  1496. result << (secs < 10 ? ":0" : ":") << secs;
  1497. }
  1498. if (! use24HourClock)
  1499. result << (isAfternoon() ? "pm" : "am");
  1500. }
  1501. return result.trimEnd();
  1502. }
  1503. const String Time::formatted (const juce_wchar* const format) const throw()
  1504. {
  1505. String buffer;
  1506. int bufferSize = 128;
  1507. buffer.preallocateStorage (bufferSize);
  1508. struct tm t (TimeHelpers::millisToLocal (millisSinceEpoch));
  1509. while (CharacterFunctions::ftime (static_cast <juce_wchar*> (buffer), bufferSize, format, &t) <= 0)
  1510. {
  1511. bufferSize += 128;
  1512. buffer.preallocateStorage (bufferSize);
  1513. }
  1514. return buffer;
  1515. }
  1516. int Time::getYear() const throw()
  1517. {
  1518. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_year + 1900;
  1519. }
  1520. int Time::getMonth() const throw()
  1521. {
  1522. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mon;
  1523. }
  1524. int Time::getDayOfMonth() const throw()
  1525. {
  1526. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mday;
  1527. }
  1528. int Time::getDayOfWeek() const throw()
  1529. {
  1530. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_wday;
  1531. }
  1532. int Time::getHours() const throw()
  1533. {
  1534. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_hour;
  1535. }
  1536. int Time::getHoursInAmPmFormat() const throw()
  1537. {
  1538. const int hours = getHours();
  1539. if (hours == 0)
  1540. return 12;
  1541. else if (hours <= 12)
  1542. return hours;
  1543. else
  1544. return hours - 12;
  1545. }
  1546. bool Time::isAfternoon() const throw()
  1547. {
  1548. return getHours() >= 12;
  1549. }
  1550. int Time::getMinutes() const throw()
  1551. {
  1552. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_min;
  1553. }
  1554. int Time::getSeconds() const throw()
  1555. {
  1556. return TimeHelpers::extendedModulo (millisSinceEpoch / 1000, 60);
  1557. }
  1558. int Time::getMilliseconds() const throw()
  1559. {
  1560. return TimeHelpers::extendedModulo (millisSinceEpoch, 1000);
  1561. }
  1562. bool Time::isDaylightSavingTime() const throw()
  1563. {
  1564. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_isdst != 0;
  1565. }
  1566. const String Time::getTimeZone() const throw()
  1567. {
  1568. String zone[2];
  1569. #if JUCE_WINDOWS
  1570. _tzset();
  1571. #ifdef USE_NEW_SECURE_TIME_FNS
  1572. {
  1573. char name [128];
  1574. size_t length;
  1575. for (int i = 0; i < 2; ++i)
  1576. {
  1577. zeromem (name, sizeof (name));
  1578. _get_tzname (&length, name, 127, i);
  1579. zone[i] = name;
  1580. }
  1581. }
  1582. #else
  1583. const char** const zonePtr = (const char**) _tzname;
  1584. zone[0] = zonePtr[0];
  1585. zone[1] = zonePtr[1];
  1586. #endif
  1587. #else
  1588. tzset();
  1589. const char** const zonePtr = (const char**) tzname;
  1590. zone[0] = zonePtr[0];
  1591. zone[1] = zonePtr[1];
  1592. #endif
  1593. if (isDaylightSavingTime())
  1594. {
  1595. zone[0] = zone[1];
  1596. if (zone[0].length() > 3
  1597. && zone[0].containsIgnoreCase (T("daylight"))
  1598. && zone[0].contains (T("GMT")))
  1599. zone[0] = "BST";
  1600. }
  1601. return zone[0].substring (0, 3);
  1602. }
  1603. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1604. {
  1605. return getMonthName (getMonth(), threeLetterVersion);
  1606. }
  1607. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1608. {
  1609. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1610. }
  1611. const String Time::getMonthName (int monthNumber, const bool threeLetterVersion) throw()
  1612. {
  1613. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1614. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1615. monthNumber %= 12;
  1616. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1617. : longMonthNames [monthNumber]);
  1618. }
  1619. const String Time::getWeekdayName (int day, const bool threeLetterVersion) throw()
  1620. {
  1621. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1622. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1623. day %= 7;
  1624. return TRANS (threeLetterVersion ? shortDayNames [day]
  1625. : longDayNames [day]);
  1626. }
  1627. END_JUCE_NAMESPACE
  1628. /*** End of inlined file: juce_Time.cpp ***/
  1629. /*** Start of inlined file: juce_BitArray.cpp ***/
  1630. BEGIN_JUCE_NAMESPACE
  1631. BigInteger::BigInteger()
  1632. : numValues (4),
  1633. highestBit (-1),
  1634. negative (false)
  1635. {
  1636. values.calloc (numValues + 1);
  1637. }
  1638. BigInteger::BigInteger (const int value)
  1639. : numValues (4),
  1640. highestBit (31),
  1641. negative (value < 0)
  1642. {
  1643. values.calloc (numValues + 1);
  1644. values[0] = abs (value);
  1645. highestBit = getHighestBit();
  1646. }
  1647. BigInteger::BigInteger (int64 value)
  1648. : numValues (4),
  1649. highestBit (63),
  1650. negative (value < 0)
  1651. {
  1652. values.calloc (numValues + 1);
  1653. if (value < 0)
  1654. value = -value;
  1655. values[0] = (unsigned int) value;
  1656. values[1] = (unsigned int) (value >> 32);
  1657. highestBit = getHighestBit();
  1658. }
  1659. BigInteger::BigInteger (const unsigned int value)
  1660. : numValues (4),
  1661. highestBit (31),
  1662. negative (false)
  1663. {
  1664. values.calloc (numValues + 1);
  1665. values[0] = value;
  1666. highestBit = getHighestBit();
  1667. }
  1668. BigInteger::BigInteger (const BigInteger& other)
  1669. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1670. highestBit (other.getHighestBit()),
  1671. negative (other.negative)
  1672. {
  1673. values.malloc (numValues + 1);
  1674. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1675. }
  1676. BigInteger::~BigInteger()
  1677. {
  1678. }
  1679. void BigInteger::swapWith (BigInteger& other) throw()
  1680. {
  1681. values.swapWith (other.values);
  1682. swapVariables (numValues, other.numValues);
  1683. swapVariables (highestBit, other.highestBit);
  1684. swapVariables (negative, other.negative);
  1685. }
  1686. BigInteger& BigInteger::operator= (const BigInteger& other)
  1687. {
  1688. if (this != &other)
  1689. {
  1690. highestBit = other.getHighestBit();
  1691. numValues = jmax (4, (highestBit >> 5) + 1);
  1692. negative = other.negative;
  1693. values.malloc (numValues + 1);
  1694. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1695. }
  1696. return *this;
  1697. }
  1698. void BigInteger::ensureSize (const int numVals)
  1699. {
  1700. if (numVals + 2 >= numValues)
  1701. {
  1702. int oldSize = numValues;
  1703. numValues = ((numVals + 2) * 3) / 2;
  1704. values.realloc (numValues + 1);
  1705. while (oldSize < numValues)
  1706. values [oldSize++] = 0;
  1707. }
  1708. }
  1709. bool BigInteger::operator[] (const int bit) const throw()
  1710. {
  1711. return bit <= highestBit && bit >= 0
  1712. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1713. }
  1714. int BigInteger::toInteger() const throw()
  1715. {
  1716. const int n = (int) (values[0] & 0x7fffffff);
  1717. return negative ? -n : n;
  1718. }
  1719. const BigInteger BigInteger::getBitRange (int startBit, int numBits) const
  1720. {
  1721. BigInteger r;
  1722. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  1723. r.ensureSize (numBits >> 5);
  1724. r.highestBit = numBits;
  1725. int i = 0;
  1726. while (numBits > 0)
  1727. {
  1728. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  1729. numBits -= 32;
  1730. startBit += 32;
  1731. }
  1732. r.highestBit = r.getHighestBit();
  1733. return r;
  1734. }
  1735. int BigInteger::getBitRangeAsInt (const int startBit, int numBits) const throw()
  1736. {
  1737. if (numBits > 32)
  1738. {
  1739. jassertfalse // use getBitRange() if you need more than 32 bits..
  1740. numBits = 32;
  1741. }
  1742. numBits = jmin (numBits, highestBit + 1 - startBit);
  1743. if (numBits <= 0)
  1744. return 0;
  1745. const int pos = startBit >> 5;
  1746. const int offset = startBit & 31;
  1747. const int endSpace = 32 - numBits;
  1748. uint32 n = ((uint32) values [pos]) >> offset;
  1749. if (offset > endSpace)
  1750. n |= ((uint32) values [pos + 1]) << (32 - offset);
  1751. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  1752. }
  1753. void BigInteger::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet)
  1754. {
  1755. if (numBits > 32)
  1756. {
  1757. jassertfalse
  1758. numBits = 32;
  1759. }
  1760. for (int i = 0; i < numBits; ++i)
  1761. {
  1762. setBit (startBit + i, (valueToSet & 1) != 0);
  1763. valueToSet >>= 1;
  1764. }
  1765. }
  1766. void BigInteger::clear()
  1767. {
  1768. if (numValues > 16)
  1769. {
  1770. numValues = 4;
  1771. values.calloc (numValues + 1);
  1772. }
  1773. else
  1774. {
  1775. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1776. }
  1777. highestBit = -1;
  1778. negative = false;
  1779. }
  1780. void BigInteger::setBit (const int bit)
  1781. {
  1782. if (bit >= 0)
  1783. {
  1784. if (bit > highestBit)
  1785. {
  1786. ensureSize (bit >> 5);
  1787. highestBit = bit;
  1788. }
  1789. values [bit >> 5] |= (1 << (bit & 31));
  1790. }
  1791. }
  1792. void BigInteger::setBit (const int bit, const bool shouldBeSet)
  1793. {
  1794. if (shouldBeSet)
  1795. setBit (bit);
  1796. else
  1797. clearBit (bit);
  1798. }
  1799. void BigInteger::clearBit (const int bit) throw()
  1800. {
  1801. if (bit >= 0 && bit <= highestBit)
  1802. values [bit >> 5] &= ~(1 << (bit & 31));
  1803. }
  1804. void BigInteger::setRange (int startBit, int numBits, const bool shouldBeSet)
  1805. {
  1806. while (--numBits >= 0)
  1807. setBit (startBit++, shouldBeSet);
  1808. }
  1809. void BigInteger::insertBit (const int bit, const bool shouldBeSet)
  1810. {
  1811. if (bit >= 0)
  1812. shiftBits (1, bit);
  1813. setBit (bit, shouldBeSet);
  1814. }
  1815. bool BigInteger::isZero() const throw()
  1816. {
  1817. return getHighestBit() < 0;
  1818. }
  1819. bool BigInteger::isOne() const throw()
  1820. {
  1821. return getHighestBit() == 0 && ! negative;
  1822. }
  1823. bool BigInteger::isNegative() const throw()
  1824. {
  1825. return negative && ! isZero();
  1826. }
  1827. void BigInteger::setNegative (const bool neg) throw()
  1828. {
  1829. negative = neg;
  1830. }
  1831. void BigInteger::negate() throw()
  1832. {
  1833. negative = (! negative) && ! isZero();
  1834. }
  1835. int BigInteger::countNumberOfSetBits() const throw()
  1836. {
  1837. int total = 0;
  1838. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  1839. {
  1840. unsigned int n = values[i];
  1841. if (n == 0xffffffff)
  1842. {
  1843. total += 32;
  1844. }
  1845. else
  1846. {
  1847. while (n != 0)
  1848. {
  1849. total += (n & 1);
  1850. n >>= 1;
  1851. }
  1852. }
  1853. }
  1854. return total;
  1855. }
  1856. int BigInteger::getHighestBit() const throw()
  1857. {
  1858. for (int i = highestBit + 1; --i >= 0;)
  1859. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1860. return i;
  1861. return -1;
  1862. }
  1863. int BigInteger::findNextSetBit (int i) const throw()
  1864. {
  1865. for (; i <= highestBit; ++i)
  1866. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1867. return i;
  1868. return -1;
  1869. }
  1870. int BigInteger::findNextClearBit (int i) const throw()
  1871. {
  1872. for (; i <= highestBit; ++i)
  1873. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  1874. break;
  1875. return i;
  1876. }
  1877. BigInteger& BigInteger::operator+= (const BigInteger& other)
  1878. {
  1879. if (other.isNegative())
  1880. return operator-= (-other);
  1881. if (isNegative())
  1882. {
  1883. if (compareAbsolute (other) < 0)
  1884. {
  1885. BigInteger temp (*this);
  1886. temp.negate();
  1887. *this = other;
  1888. operator-= (temp);
  1889. }
  1890. else
  1891. {
  1892. negate();
  1893. operator-= (other);
  1894. negate();
  1895. }
  1896. }
  1897. else
  1898. {
  1899. if (other.highestBit > highestBit)
  1900. highestBit = other.highestBit;
  1901. ++highestBit;
  1902. const int numInts = (highestBit >> 5) + 1;
  1903. ensureSize (numInts);
  1904. int64 remainder = 0;
  1905. for (int i = 0; i <= numInts; ++i)
  1906. {
  1907. if (i < numValues)
  1908. remainder += values[i];
  1909. if (i < other.numValues)
  1910. remainder += other.values[i];
  1911. values[i] = (unsigned int) remainder;
  1912. remainder >>= 32;
  1913. }
  1914. jassert (remainder == 0);
  1915. highestBit = getHighestBit();
  1916. }
  1917. return *this;
  1918. }
  1919. BigInteger& BigInteger::operator-= (const BigInteger& other)
  1920. {
  1921. if (other.isNegative())
  1922. return operator+= (-other);
  1923. if (! isNegative())
  1924. {
  1925. if (compareAbsolute (other) < 0)
  1926. {
  1927. BigInteger temp (other);
  1928. swapWith (temp);
  1929. operator-= (temp);
  1930. negate();
  1931. return *this;
  1932. }
  1933. }
  1934. else
  1935. {
  1936. negate();
  1937. operator+= (other);
  1938. negate();
  1939. return *this;
  1940. }
  1941. const int numInts = (highestBit >> 5) + 1;
  1942. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1943. int64 amountToSubtract = 0;
  1944. for (int i = 0; i <= numInts; ++i)
  1945. {
  1946. if (i <= maxOtherInts)
  1947. amountToSubtract += (int64) other.values[i];
  1948. if (values[i] >= amountToSubtract)
  1949. {
  1950. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1951. amountToSubtract = 0;
  1952. }
  1953. else
  1954. {
  1955. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1956. values[i] = (unsigned int) n;
  1957. amountToSubtract = 1;
  1958. }
  1959. }
  1960. return *this;
  1961. }
  1962. BigInteger& BigInteger::operator*= (const BigInteger& other)
  1963. {
  1964. BigInteger total;
  1965. highestBit = getHighestBit();
  1966. const bool wasNegative = isNegative();
  1967. setNegative (false);
  1968. for (int i = 0; i <= highestBit; ++i)
  1969. {
  1970. if (operator[](i))
  1971. {
  1972. BigInteger n (other);
  1973. n.setNegative (false);
  1974. n <<= i;
  1975. total += n;
  1976. }
  1977. }
  1978. total.setNegative (wasNegative ^ other.isNegative());
  1979. swapWith (total);
  1980. return *this;
  1981. }
  1982. void BigInteger::divideBy (const BigInteger& divisor, BigInteger& remainder)
  1983. {
  1984. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  1985. const int divHB = divisor.getHighestBit();
  1986. const int ourHB = getHighestBit();
  1987. if (divHB < 0 || ourHB < 0)
  1988. {
  1989. // division by zero
  1990. remainder.clear();
  1991. clear();
  1992. }
  1993. else
  1994. {
  1995. const bool wasNegative = isNegative();
  1996. swapWith (remainder);
  1997. remainder.setNegative (false);
  1998. clear();
  1999. BigInteger temp (divisor);
  2000. temp.setNegative (false);
  2001. int leftShift = ourHB - divHB;
  2002. temp <<= leftShift;
  2003. while (leftShift >= 0)
  2004. {
  2005. if (remainder.compareAbsolute (temp) >= 0)
  2006. {
  2007. remainder -= temp;
  2008. setBit (leftShift);
  2009. }
  2010. if (--leftShift >= 0)
  2011. temp >>= 1;
  2012. }
  2013. negative = wasNegative ^ divisor.isNegative();
  2014. remainder.setNegative (wasNegative);
  2015. }
  2016. }
  2017. BigInteger& BigInteger::operator/= (const BigInteger& other)
  2018. {
  2019. BigInteger remainder;
  2020. divideBy (other, remainder);
  2021. return *this;
  2022. }
  2023. BigInteger& BigInteger::operator|= (const BigInteger& other)
  2024. {
  2025. // this operation doesn't take into account negative values..
  2026. jassert (isNegative() == other.isNegative());
  2027. if (other.highestBit >= 0)
  2028. {
  2029. ensureSize (other.highestBit >> 5);
  2030. int n = (other.highestBit >> 5) + 1;
  2031. while (--n >= 0)
  2032. values[n] |= other.values[n];
  2033. if (other.highestBit > highestBit)
  2034. highestBit = other.highestBit;
  2035. highestBit = getHighestBit();
  2036. }
  2037. return *this;
  2038. }
  2039. BigInteger& BigInteger::operator&= (const BigInteger& other)
  2040. {
  2041. // this operation doesn't take into account negative values..
  2042. jassert (isNegative() == other.isNegative());
  2043. int n = numValues;
  2044. while (n > other.numValues)
  2045. values[--n] = 0;
  2046. while (--n >= 0)
  2047. values[n] &= other.values[n];
  2048. if (other.highestBit < highestBit)
  2049. highestBit = other.highestBit;
  2050. highestBit = getHighestBit();
  2051. return *this;
  2052. }
  2053. BigInteger& BigInteger::operator^= (const BigInteger& other)
  2054. {
  2055. // this operation will only work with the absolute values
  2056. jassert (isNegative() == other.isNegative());
  2057. if (other.highestBit >= 0)
  2058. {
  2059. ensureSize (other.highestBit >> 5);
  2060. int n = (other.highestBit >> 5) + 1;
  2061. while (--n >= 0)
  2062. values[n] ^= other.values[n];
  2063. if (other.highestBit > highestBit)
  2064. highestBit = other.highestBit;
  2065. highestBit = getHighestBit();
  2066. }
  2067. return *this;
  2068. }
  2069. BigInteger& BigInteger::operator%= (const BigInteger& divisor)
  2070. {
  2071. BigInteger remainder;
  2072. divideBy (divisor, remainder);
  2073. swapWith (remainder);
  2074. return *this;
  2075. }
  2076. BigInteger& BigInteger::operator<<= (int numBitsToShift)
  2077. {
  2078. shiftBits (numBitsToShift, 0);
  2079. return *this;
  2080. }
  2081. BigInteger& BigInteger::operator>>= (int numBitsToShift)
  2082. {
  2083. return operator<<= (-numBitsToShift);
  2084. }
  2085. BigInteger& BigInteger::operator++() { return operator+= (1); }
  2086. BigInteger& BigInteger::operator--() { return operator-= (1); }
  2087. const BigInteger BigInteger::operator++ (int) { const BigInteger old (*this); operator+= (1); return old; }
  2088. const BigInteger BigInteger::operator-- (int) { const BigInteger old (*this); operator-= (1); return old; }
  2089. const BigInteger BigInteger::operator+ (const BigInteger& other) const { BigInteger b (*this); return b += other; }
  2090. const BigInteger BigInteger::operator- (const BigInteger& other) const { BigInteger b (*this); return b -= other; }
  2091. const BigInteger BigInteger::operator* (const BigInteger& other) const { BigInteger b (*this); return b *= other; }
  2092. const BigInteger BigInteger::operator/ (const BigInteger& other) const { BigInteger b (*this); return b /= other; }
  2093. const BigInteger BigInteger::operator| (const BigInteger& other) const { BigInteger b (*this); return b |= other; }
  2094. const BigInteger BigInteger::operator& (const BigInteger& other) const { BigInteger b (*this); return b &= other; }
  2095. const BigInteger BigInteger::operator^ (const BigInteger& other) const { BigInteger b (*this); return b ^= other; }
  2096. const BigInteger BigInteger::operator% (const BigInteger& other) const { BigInteger b (*this); return b %= other; }
  2097. const BigInteger BigInteger::operator<< (const int numBits) const { BigInteger b (*this); return b <<= numBits; }
  2098. const BigInteger BigInteger::operator>> (const int numBits) const { BigInteger b (*this); return b >>= numBits; }
  2099. const BigInteger BigInteger::operator-() const { BigInteger b (*this); b.negate(); return b; }
  2100. int BigInteger::compare (const BigInteger& other) const throw()
  2101. {
  2102. if (isNegative() == other.isNegative())
  2103. {
  2104. const int absComp = compareAbsolute (other);
  2105. return isNegative() ? -absComp : absComp;
  2106. }
  2107. else
  2108. {
  2109. return isNegative() ? -1 : 1;
  2110. }
  2111. }
  2112. int BigInteger::compareAbsolute (const BigInteger& other) const throw()
  2113. {
  2114. const int h1 = getHighestBit();
  2115. const int h2 = other.getHighestBit();
  2116. if (h1 > h2)
  2117. return 1;
  2118. else if (h1 < h2)
  2119. return -1;
  2120. for (int i = (h1 >> 5) + 1; --i >= 0;)
  2121. if (values[i] != other.values[i])
  2122. return (values[i] > other.values[i]) ? 1 : -1;
  2123. return 0;
  2124. }
  2125. bool BigInteger::operator== (const BigInteger& other) const throw() { return compare (other) == 0; }
  2126. bool BigInteger::operator!= (const BigInteger& other) const throw() { return compare (other) != 0; }
  2127. bool BigInteger::operator< (const BigInteger& other) const throw() { return compare (other) < 0; }
  2128. bool BigInteger::operator<= (const BigInteger& other) const throw() { return compare (other) <= 0; }
  2129. bool BigInteger::operator> (const BigInteger& other) const throw() { return compare (other) > 0; }
  2130. bool BigInteger::operator>= (const BigInteger& other) const throw() { return compare (other) >= 0; }
  2131. void BigInteger::shiftBits (int bits, const int startBit)
  2132. {
  2133. if (highestBit < 0)
  2134. return;
  2135. if (startBit > 0)
  2136. {
  2137. if (bits < 0)
  2138. {
  2139. // right shift
  2140. for (int i = startBit; i <= highestBit; ++i)
  2141. setBit (i, operator[] (i - bits));
  2142. highestBit = getHighestBit();
  2143. }
  2144. else if (bits > 0)
  2145. {
  2146. // left shift
  2147. for (int i = highestBit + 1; --i >= startBit;)
  2148. setBit (i + bits, operator[] (i));
  2149. while (--bits >= 0)
  2150. clearBit (bits + startBit);
  2151. }
  2152. }
  2153. else
  2154. {
  2155. if (bits < 0)
  2156. {
  2157. // right shift
  2158. bits = -bits;
  2159. if (bits > highestBit)
  2160. {
  2161. clear();
  2162. }
  2163. else
  2164. {
  2165. const int wordsToMove = bits >> 5;
  2166. int top = 1 + (highestBit >> 5) - wordsToMove;
  2167. highestBit -= bits;
  2168. if (wordsToMove > 0)
  2169. {
  2170. int i;
  2171. for (i = 0; i < top; ++i)
  2172. values [i] = values [i + wordsToMove];
  2173. for (i = 0; i < wordsToMove; ++i)
  2174. values [top + i] = 0;
  2175. bits &= 31;
  2176. }
  2177. if (bits != 0)
  2178. {
  2179. const int invBits = 32 - bits;
  2180. --top;
  2181. for (int i = 0; i < top; ++i)
  2182. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2183. values[top] = (values[top] >> bits);
  2184. }
  2185. highestBit = getHighestBit();
  2186. }
  2187. }
  2188. else if (bits > 0)
  2189. {
  2190. // left shift
  2191. ensureSize (((highestBit + bits) >> 5) + 1);
  2192. const int wordsToMove = bits >> 5;
  2193. int top = 1 + (highestBit >> 5);
  2194. highestBit += bits;
  2195. if (wordsToMove > 0)
  2196. {
  2197. int i;
  2198. for (i = top; --i >= 0;)
  2199. values [i + wordsToMove] = values [i];
  2200. for (i = 0; i < wordsToMove; ++i)
  2201. values [i] = 0;
  2202. bits &= 31;
  2203. }
  2204. if (bits != 0)
  2205. {
  2206. const int invBits = 32 - bits;
  2207. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2208. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2209. values [wordsToMove] = values [wordsToMove] << bits;
  2210. }
  2211. highestBit = getHighestBit();
  2212. }
  2213. }
  2214. }
  2215. const BigInteger BigInteger::simpleGCD (BigInteger* m, BigInteger* n)
  2216. {
  2217. while (! m->isZero())
  2218. {
  2219. if (n->compareAbsolute (*m) > 0)
  2220. swapVariables (m, n);
  2221. *m -= *n;
  2222. }
  2223. return *n;
  2224. }
  2225. const BigInteger BigInteger::findGreatestCommonDivisor (BigInteger n) const
  2226. {
  2227. BigInteger m (*this);
  2228. while (! n.isZero())
  2229. {
  2230. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  2231. return simpleGCD (&m, &n);
  2232. BigInteger temp1 (m), temp2;
  2233. temp1.divideBy (n, temp2);
  2234. m = n;
  2235. n = temp2;
  2236. }
  2237. return m;
  2238. }
  2239. void BigInteger::exponentModulo (const BigInteger& exponent, const BigInteger& modulus)
  2240. {
  2241. BigInteger exp (exponent);
  2242. exp %= modulus;
  2243. BigInteger value (1);
  2244. swapWith (value);
  2245. value %= modulus;
  2246. while (! exp.isZero())
  2247. {
  2248. if (exp [0])
  2249. {
  2250. operator*= (value);
  2251. operator%= (modulus);
  2252. }
  2253. value *= value;
  2254. value %= modulus;
  2255. exp >>= 1;
  2256. }
  2257. }
  2258. void BigInteger::inverseModulo (const BigInteger& modulus)
  2259. {
  2260. if (modulus.isOne() || modulus.isNegative())
  2261. {
  2262. clear();
  2263. return;
  2264. }
  2265. if (isNegative() || compareAbsolute (modulus) >= 0)
  2266. operator%= (modulus);
  2267. if (isOne())
  2268. return;
  2269. if (! (*this)[0])
  2270. {
  2271. // not invertible
  2272. clear();
  2273. return;
  2274. }
  2275. BigInteger a1 (modulus);
  2276. BigInteger a2 (*this);
  2277. BigInteger b1 (modulus);
  2278. BigInteger b2 (1);
  2279. while (! a2.isOne())
  2280. {
  2281. BigInteger temp1, temp2, multiplier (a1);
  2282. multiplier.divideBy (a2, temp1);
  2283. temp1 = a2;
  2284. temp1 *= multiplier;
  2285. temp2 = a1;
  2286. temp2 -= temp1;
  2287. a1 = a2;
  2288. a2 = temp2;
  2289. temp1 = b2;
  2290. temp1 *= multiplier;
  2291. temp2 = b1;
  2292. temp2 -= temp1;
  2293. b1 = b2;
  2294. b2 = temp2;
  2295. }
  2296. while (b2.isNegative())
  2297. b2 += modulus;
  2298. b2 %= modulus;
  2299. swapWith (b2);
  2300. }
  2301. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const BigInteger& value)
  2302. {
  2303. return stream << value.toString (10);
  2304. }
  2305. const String BigInteger::toString (const int base, const int minimumNumCharacters) const
  2306. {
  2307. String s;
  2308. BigInteger v (*this);
  2309. if (base == 2 || base == 8 || base == 16)
  2310. {
  2311. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2312. static const juce_wchar* const hexDigits = T("0123456789abcdef");
  2313. for (;;)
  2314. {
  2315. const int remainder = v.getBitRangeAsInt (0, bits);
  2316. v >>= bits;
  2317. if (remainder == 0 && v.isZero())
  2318. break;
  2319. s = String::charToString (hexDigits [remainder]) + s;
  2320. }
  2321. }
  2322. else if (base == 10)
  2323. {
  2324. const BigInteger ten (10);
  2325. BigInteger remainder;
  2326. for (;;)
  2327. {
  2328. v.divideBy (ten, remainder);
  2329. if (remainder.isZero() && v.isZero())
  2330. break;
  2331. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2332. }
  2333. }
  2334. else
  2335. {
  2336. jassertfalse // can't do the specified base!
  2337. return String::empty;
  2338. }
  2339. s = s.paddedLeft ('0', minimumNumCharacters);
  2340. return isNegative() ? T("-") + s : s;
  2341. }
  2342. void BigInteger::parseString (const String& text, const int base)
  2343. {
  2344. clear();
  2345. const juce_wchar* t = (const juce_wchar*) text;
  2346. if (base == 2 || base == 8 || base == 16)
  2347. {
  2348. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2349. for (;;)
  2350. {
  2351. const juce_wchar c = *t++;
  2352. const int digit = CharacterFunctions::getHexDigitValue (c);
  2353. if (((unsigned int) digit) < (unsigned int) base)
  2354. {
  2355. operator<<= (bits);
  2356. operator+= (digit);
  2357. }
  2358. else if (c == 0)
  2359. {
  2360. break;
  2361. }
  2362. }
  2363. }
  2364. else if (base == 10)
  2365. {
  2366. const BigInteger ten ((unsigned int) 10);
  2367. for (;;)
  2368. {
  2369. const juce_wchar c = *t++;
  2370. if (c >= T('0') && c <= T('9'))
  2371. {
  2372. operator*= (ten);
  2373. operator+= ((int) (c - T('0')));
  2374. }
  2375. else if (c == 0)
  2376. {
  2377. break;
  2378. }
  2379. }
  2380. }
  2381. setNegative (text.trimStart().startsWithChar (T('-')));
  2382. }
  2383. const MemoryBlock BigInteger::toMemoryBlock() const
  2384. {
  2385. const int numBytes = (getHighestBit() + 8) >> 3;
  2386. MemoryBlock mb ((size_t) numBytes);
  2387. for (int i = 0; i < numBytes; ++i)
  2388. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2389. return mb;
  2390. }
  2391. void BigInteger::loadFromMemoryBlock (const MemoryBlock& data)
  2392. {
  2393. clear();
  2394. for (int i = (int) data.getSize(); --i >= 0;)
  2395. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2396. }
  2397. END_JUCE_NAMESPACE
  2398. /*** End of inlined file: juce_BitArray.cpp ***/
  2399. /*** Start of inlined file: juce_MemoryBlock.cpp ***/
  2400. BEGIN_JUCE_NAMESPACE
  2401. MemoryBlock::MemoryBlock() throw()
  2402. : size (0)
  2403. {
  2404. }
  2405. MemoryBlock::MemoryBlock (const size_t initialSize,
  2406. const bool initialiseToZero) throw()
  2407. {
  2408. if (initialSize > 0)
  2409. {
  2410. size = initialSize;
  2411. data.allocate (initialSize, initialiseToZero);
  2412. }
  2413. else
  2414. {
  2415. size = 0;
  2416. }
  2417. }
  2418. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2419. : size (other.size)
  2420. {
  2421. if (size > 0)
  2422. {
  2423. jassert (other.data != 0);
  2424. data.malloc (size);
  2425. memcpy (data, other.data, size);
  2426. }
  2427. }
  2428. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2429. const size_t sizeInBytes) throw()
  2430. : size (jmax ((size_t) 0, sizeInBytes))
  2431. {
  2432. jassert (sizeInBytes >= 0);
  2433. if (size > 0)
  2434. {
  2435. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2436. data.malloc (size);
  2437. if (dataToInitialiseFrom != 0)
  2438. memcpy (data, dataToInitialiseFrom, size);
  2439. }
  2440. }
  2441. MemoryBlock::~MemoryBlock() throw()
  2442. {
  2443. jassert (size >= 0); // should never happen
  2444. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2445. }
  2446. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2447. {
  2448. if (this != &other)
  2449. {
  2450. setSize (other.size, false);
  2451. memcpy (data, other.data, size);
  2452. }
  2453. return *this;
  2454. }
  2455. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2456. {
  2457. return matches (other.data, other.size);
  2458. }
  2459. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2460. {
  2461. return ! operator== (other);
  2462. }
  2463. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2464. {
  2465. return size == dataSize
  2466. && memcmp (data, dataToCompare, size) == 0;
  2467. }
  2468. // this will resize the block to this size
  2469. void MemoryBlock::setSize (const size_t newSize,
  2470. const bool initialiseToZero) throw()
  2471. {
  2472. if (size != newSize)
  2473. {
  2474. if (newSize <= 0)
  2475. {
  2476. data.free();
  2477. size = 0;
  2478. }
  2479. else
  2480. {
  2481. if (data != 0)
  2482. {
  2483. data.realloc (newSize);
  2484. if (initialiseToZero && (newSize > size))
  2485. zeromem (data + size, newSize - size);
  2486. }
  2487. else
  2488. {
  2489. data.allocate (newSize, initialiseToZero);
  2490. }
  2491. size = newSize;
  2492. }
  2493. }
  2494. }
  2495. void MemoryBlock::ensureSize (const size_t minimumSize,
  2496. const bool initialiseToZero) throw()
  2497. {
  2498. if (size < minimumSize)
  2499. setSize (minimumSize, initialiseToZero);
  2500. }
  2501. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2502. {
  2503. swapVariables (size, other.size);
  2504. data.swapWith (other.data);
  2505. }
  2506. void MemoryBlock::fillWith (const uint8 value) throw()
  2507. {
  2508. memset (data, (int) value, size);
  2509. }
  2510. void MemoryBlock::append (const void* const srcData,
  2511. const size_t numBytes) throw()
  2512. {
  2513. if (numBytes > 0)
  2514. {
  2515. const size_t oldSize = size;
  2516. setSize (size + numBytes);
  2517. memcpy (data + oldSize, srcData, numBytes);
  2518. }
  2519. }
  2520. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2521. {
  2522. const char* d = static_cast<const char*> (src);
  2523. if (offset < 0)
  2524. {
  2525. d -= offset;
  2526. num -= offset;
  2527. offset = 0;
  2528. }
  2529. if (offset + num > size)
  2530. num = size - offset;
  2531. if (num > 0)
  2532. memcpy (data + offset, d, num);
  2533. }
  2534. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2535. {
  2536. char* d = static_cast<char*> (dst);
  2537. if (offset < 0)
  2538. {
  2539. zeromem (d, -offset);
  2540. d -= offset;
  2541. num += offset;
  2542. offset = 0;
  2543. }
  2544. if (offset + num > size)
  2545. {
  2546. const size_t newNum = size - offset;
  2547. zeromem (d + newNum, num - newNum);
  2548. num = newNum;
  2549. }
  2550. if (num > 0)
  2551. memcpy (d, data + offset, num);
  2552. }
  2553. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2554. {
  2555. if (startByte < 0)
  2556. {
  2557. numBytesToRemove += startByte;
  2558. startByte = 0;
  2559. }
  2560. if (startByte + numBytesToRemove >= size)
  2561. {
  2562. setSize (startByte);
  2563. }
  2564. else if (numBytesToRemove > 0)
  2565. {
  2566. memmove (data + startByte,
  2567. data + startByte + numBytesToRemove,
  2568. size - (startByte + numBytesToRemove));
  2569. setSize (size - numBytesToRemove);
  2570. }
  2571. }
  2572. const String MemoryBlock::toString() const throw()
  2573. {
  2574. return String ((const char*) data, size);
  2575. }
  2576. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2577. {
  2578. int res = 0;
  2579. size_t byte = bitRangeStart >> 3;
  2580. int offsetInByte = (int) bitRangeStart & 7;
  2581. size_t bitsSoFar = 0;
  2582. while (numBits > 0 && (size_t) byte < size)
  2583. {
  2584. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2585. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2586. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2587. bitsSoFar += bitsThisTime;
  2588. numBits -= bitsThisTime;
  2589. ++byte;
  2590. offsetInByte = 0;
  2591. }
  2592. return res;
  2593. }
  2594. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2595. {
  2596. size_t byte = bitRangeStart >> 3;
  2597. int offsetInByte = (int) bitRangeStart & 7;
  2598. unsigned int mask = ~((((unsigned int) 0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2599. while (numBits > 0 && (size_t) byte < size)
  2600. {
  2601. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2602. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int) 0xffffffff) >> offsetInByte) << offsetInByte);
  2603. const unsigned int tempBits = bitsToSet << offsetInByte;
  2604. data[byte] = (char) ((data[byte] & tempMask) | tempBits);
  2605. ++byte;
  2606. numBits -= bitsThisTime;
  2607. bitsToSet >>= bitsThisTime;
  2608. mask >>= bitsThisTime;
  2609. offsetInByte = 0;
  2610. }
  2611. }
  2612. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2613. {
  2614. ensureSize (hex.length() >> 1);
  2615. char* dest = data;
  2616. int i = 0;
  2617. for (;;)
  2618. {
  2619. int byte = 0;
  2620. for (int loop = 2; --loop >= 0;)
  2621. {
  2622. byte <<= 4;
  2623. for (;;)
  2624. {
  2625. const juce_wchar c = hex [i++];
  2626. if (c >= T('0') && c <= T('9'))
  2627. {
  2628. byte |= c - T('0');
  2629. break;
  2630. }
  2631. else if (c >= T('a') && c <= T('z'))
  2632. {
  2633. byte |= c - (T('a') - 10);
  2634. break;
  2635. }
  2636. else if (c >= T('A') && c <= T('Z'))
  2637. {
  2638. byte |= c - (T('A') - 10);
  2639. break;
  2640. }
  2641. else if (c == 0)
  2642. {
  2643. setSize (static_cast <size_t> (dest - data));
  2644. return;
  2645. }
  2646. }
  2647. }
  2648. *dest++ = (char) byte;
  2649. }
  2650. }
  2651. static const char* const encodingTable
  2652. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2653. const String MemoryBlock::toBase64Encoding() const throw()
  2654. {
  2655. const size_t numChars = ((size << 3) + 5) / 6;
  2656. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2657. const int initialLen = destString.length();
  2658. destString.preallocateStorage (initialLen + 2 + numChars);
  2659. tchar* d = const_cast <tchar*> (((const tchar*) destString) + initialLen);
  2660. *d++ = T('.');
  2661. for (size_t i = 0; i < numChars; ++i)
  2662. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2663. *d++ = 0;
  2664. return destString;
  2665. }
  2666. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2667. {
  2668. const int startPos = s.indexOfChar (T('.')) + 1;
  2669. if (startPos <= 0)
  2670. return false;
  2671. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2672. setSize (numBytesNeeded, true);
  2673. const int numChars = s.length() - startPos;
  2674. const tchar* const srcChars = ((const tchar*) s) + startPos;
  2675. int pos = 0;
  2676. for (int i = 0; i < numChars; ++i)
  2677. {
  2678. const char c = (char) srcChars[i];
  2679. for (int j = 0; j < 64; ++j)
  2680. {
  2681. if (encodingTable[j] == c)
  2682. {
  2683. setBitRange (pos, 6, j);
  2684. pos += 6;
  2685. break;
  2686. }
  2687. }
  2688. }
  2689. return true;
  2690. }
  2691. END_JUCE_NAMESPACE
  2692. /*** End of inlined file: juce_MemoryBlock.cpp ***/
  2693. /*** Start of inlined file: juce_PropertySet.cpp ***/
  2694. BEGIN_JUCE_NAMESPACE
  2695. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2696. : properties (ignoreCaseOfKeyNames),
  2697. fallbackProperties (0),
  2698. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2699. {
  2700. }
  2701. PropertySet::PropertySet (const PropertySet& other) throw()
  2702. : properties (other.properties),
  2703. fallbackProperties (other.fallbackProperties),
  2704. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2705. {
  2706. }
  2707. PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2708. {
  2709. properties = other.properties;
  2710. fallbackProperties = other.fallbackProperties;
  2711. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2712. propertyChanged();
  2713. return *this;
  2714. }
  2715. PropertySet::~PropertySet()
  2716. {
  2717. }
  2718. void PropertySet::clear()
  2719. {
  2720. const ScopedLock sl (lock);
  2721. if (properties.size() > 0)
  2722. {
  2723. properties.clear();
  2724. propertyChanged();
  2725. }
  2726. }
  2727. const String PropertySet::getValue (const String& keyName,
  2728. const String& defaultValue) const throw()
  2729. {
  2730. const ScopedLock sl (lock);
  2731. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2732. if (index >= 0)
  2733. return properties.getAllValues() [index];
  2734. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2735. : defaultValue;
  2736. }
  2737. int PropertySet::getIntValue (const String& keyName,
  2738. const int defaultValue) const throw()
  2739. {
  2740. const ScopedLock sl (lock);
  2741. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2742. if (index >= 0)
  2743. return properties.getAllValues() [index].getIntValue();
  2744. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2745. : defaultValue;
  2746. }
  2747. double PropertySet::getDoubleValue (const String& keyName,
  2748. const double defaultValue) const throw()
  2749. {
  2750. const ScopedLock sl (lock);
  2751. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2752. if (index >= 0)
  2753. return properties.getAllValues()[index].getDoubleValue();
  2754. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2755. : defaultValue;
  2756. }
  2757. bool PropertySet::getBoolValue (const String& keyName,
  2758. const bool defaultValue) const throw()
  2759. {
  2760. const ScopedLock sl (lock);
  2761. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2762. if (index >= 0)
  2763. return properties.getAllValues() [index].getIntValue() != 0;
  2764. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2765. : defaultValue;
  2766. }
  2767. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2768. {
  2769. XmlDocument doc (getValue (keyName));
  2770. return doc.getDocumentElement();
  2771. }
  2772. void PropertySet::setValue (const String& keyName,
  2773. const String& value) throw()
  2774. {
  2775. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2776. if (keyName.isNotEmpty())
  2777. {
  2778. const ScopedLock sl (lock);
  2779. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2780. if (index < 0 || properties.getAllValues() [index] != value)
  2781. {
  2782. properties.set (keyName, value);
  2783. propertyChanged();
  2784. }
  2785. }
  2786. }
  2787. void PropertySet::removeValue (const String& keyName) throw()
  2788. {
  2789. if (keyName.isNotEmpty())
  2790. {
  2791. const ScopedLock sl (lock);
  2792. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2793. if (index >= 0)
  2794. {
  2795. properties.remove (keyName);
  2796. propertyChanged();
  2797. }
  2798. }
  2799. }
  2800. void PropertySet::setValue (const String& keyName, const tchar* const value) throw()
  2801. {
  2802. setValue (keyName, String (value));
  2803. }
  2804. void PropertySet::setValue (const String& keyName, const int value) throw()
  2805. {
  2806. setValue (keyName, String (value));
  2807. }
  2808. void PropertySet::setValue (const String& keyName, const double value) throw()
  2809. {
  2810. setValue (keyName, String (value));
  2811. }
  2812. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2813. {
  2814. setValue (keyName, String ((value) ? T("1") : T("0")));
  2815. }
  2816. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2817. {
  2818. setValue (keyName, (xml == 0) ? String::empty
  2819. : xml->createDocument (String::empty, true));
  2820. }
  2821. bool PropertySet::containsKey (const String& keyName) const throw()
  2822. {
  2823. const ScopedLock sl (lock);
  2824. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2825. }
  2826. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2827. {
  2828. const ScopedLock sl (lock);
  2829. fallbackProperties = fallbackProperties_;
  2830. }
  2831. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2832. {
  2833. const ScopedLock sl (lock);
  2834. XmlElement* const xml = new XmlElement (nodeName);
  2835. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2836. {
  2837. XmlElement* const e = xml->createNewChildElement ("VALUE");
  2838. e->setAttribute (T("name"), properties.getAllKeys()[i]);
  2839. e->setAttribute (T("val"), properties.getAllValues()[i]);
  2840. }
  2841. return xml;
  2842. }
  2843. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2844. {
  2845. const ScopedLock sl (lock);
  2846. clear();
  2847. forEachXmlChildElementWithTagName (xml, e, T("VALUE"))
  2848. {
  2849. if (e->hasAttribute (T("name"))
  2850. && e->hasAttribute (T("val")))
  2851. {
  2852. properties.set (e->getStringAttribute (T("name")),
  2853. e->getStringAttribute (T("val")));
  2854. }
  2855. }
  2856. if (properties.size() > 0)
  2857. propertyChanged();
  2858. }
  2859. void PropertySet::propertyChanged()
  2860. {
  2861. }
  2862. END_JUCE_NAMESPACE
  2863. /*** End of inlined file: juce_PropertySet.cpp ***/
  2864. /*** Start of inlined file: juce_Variant.cpp ***/
  2865. BEGIN_JUCE_NAMESPACE
  2866. var::var() throw()
  2867. : type (voidType)
  2868. {
  2869. value.doubleValue = 0;
  2870. }
  2871. var::~var() throw()
  2872. {
  2873. if (type == stringType)
  2874. delete value.stringValue;
  2875. else if (type == objectType && value.objectValue != 0)
  2876. value.objectValue->decReferenceCount();
  2877. }
  2878. const var var::null;
  2879. var::var (const var& valueToCopy)
  2880. : type (valueToCopy.type),
  2881. value (valueToCopy.value)
  2882. {
  2883. if (type == stringType)
  2884. value.stringValue = new String (*(value.stringValue));
  2885. else if (type == objectType && value.objectValue != 0)
  2886. value.objectValue->incReferenceCount();
  2887. }
  2888. var::var (const int value_) throw()
  2889. : type (intType)
  2890. {
  2891. value.intValue = value_;
  2892. }
  2893. var::var (const bool value_) throw()
  2894. : type (boolType)
  2895. {
  2896. value.boolValue = value_;
  2897. }
  2898. var::var (const double value_) throw()
  2899. : type (doubleType)
  2900. {
  2901. value.doubleValue = value_;
  2902. }
  2903. var::var (const String& value_)
  2904. : type (stringType)
  2905. {
  2906. value.stringValue = new String (value_);
  2907. }
  2908. var::var (const char* const value_)
  2909. : type (stringType)
  2910. {
  2911. value.stringValue = new String (value_);
  2912. }
  2913. var::var (const juce_wchar* const value_)
  2914. : type (stringType)
  2915. {
  2916. value.stringValue = new String (value_);
  2917. }
  2918. var::var (DynamicObject* const object)
  2919. : type (objectType)
  2920. {
  2921. value.objectValue = object;
  2922. if (object != 0)
  2923. object->incReferenceCount();
  2924. }
  2925. var::var (MethodFunction method_) throw()
  2926. : type (methodType)
  2927. {
  2928. value.methodValue = method_;
  2929. }
  2930. void var::swapWith (var& other) throw()
  2931. {
  2932. swapVariables (type, other.type);
  2933. swapVariables (value, other.value);
  2934. }
  2935. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2936. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2937. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2938. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2939. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2940. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2941. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2942. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2943. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2944. var::operator int() const
  2945. {
  2946. switch (type)
  2947. {
  2948. case voidType: break;
  2949. case intType: return value.intValue;
  2950. case boolType: return value.boolValue ? 1 : 0;
  2951. case doubleType: return static_cast <int> (value.doubleValue);
  2952. case stringType: return value.stringValue->getIntValue();
  2953. case objectType: break;
  2954. default: jassertfalse; break;
  2955. }
  2956. return 0;
  2957. }
  2958. var::operator bool() const
  2959. {
  2960. switch (type)
  2961. {
  2962. case voidType: break;
  2963. case intType: return value.intValue != 0;
  2964. case boolType: return value.boolValue;
  2965. case doubleType: return value.doubleValue != 0;
  2966. case stringType: return value.stringValue->getIntValue() != 0
  2967. || value.stringValue->trim().equalsIgnoreCase (T("true"))
  2968. || value.stringValue->trim().equalsIgnoreCase (T("yes"));
  2969. case objectType: return value.objectValue != 0;
  2970. default: jassertfalse; break;
  2971. }
  2972. return false;
  2973. }
  2974. var::operator float() const
  2975. {
  2976. return (float) operator double();
  2977. }
  2978. var::operator double() const
  2979. {
  2980. switch (type)
  2981. {
  2982. case voidType: break;
  2983. case intType: return value.intValue;
  2984. case boolType: return value.boolValue ? 1.0 : 0.0;
  2985. case doubleType: return value.doubleValue;
  2986. case stringType: return value.stringValue->getDoubleValue();
  2987. case objectType: break;
  2988. default: jassertfalse; break;
  2989. }
  2990. return 0.0;
  2991. }
  2992. const String var::toString() const
  2993. {
  2994. switch (type)
  2995. {
  2996. case voidType: return String::empty;
  2997. case intType: return String (value.intValue);
  2998. case boolType: return value.boolValue ? T("1") : T("0");
  2999. case doubleType: return String (value.doubleValue);
  3000. case stringType: return *(value.stringValue);
  3001. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  3002. case methodType: return "Method";
  3003. default: jassertfalse; break;
  3004. }
  3005. return String::empty;
  3006. }
  3007. var::operator const String() const
  3008. {
  3009. return toString();
  3010. }
  3011. DynamicObject* var::getObject() const
  3012. {
  3013. return type == objectType ? value.objectValue : 0;
  3014. }
  3015. bool var::equals (const var& other) const throw()
  3016. {
  3017. switch (type)
  3018. {
  3019. case voidType: return other.isVoid();
  3020. case intType: return value.intValue == static_cast <int> (other);
  3021. case boolType: return value.boolValue == static_cast <bool> (other);
  3022. case doubleType: return value.doubleValue == static_cast <double> (other);
  3023. case stringType: return (*(value.stringValue)) == other.toString();
  3024. case objectType: return value.objectValue == other.getObject();
  3025. case methodType: return value.methodValue == other.value.methodValue && other.isMethod();
  3026. default: jassertfalse; break;
  3027. }
  3028. return false;
  3029. }
  3030. bool operator== (const var& v1, const var& v2) throw() { return v1.equals (v2); }
  3031. bool operator!= (const var& v1, const var& v2) throw() { return ! v1.equals (v2); }
  3032. bool operator== (const var& v1, const String& v2) throw() { return v1.toString() == v2; }
  3033. bool operator!= (const var& v1, const String& v2) throw() { return v1.toString() != v2; }
  3034. void var::writeToStream (OutputStream& output) const
  3035. {
  3036. switch (type)
  3037. {
  3038. case voidType: output.writeCompressedInt (0); break;
  3039. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  3040. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  3041. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  3042. case stringType:
  3043. {
  3044. const int len = value.stringValue->getNumBytesAsUTF8() + 1;
  3045. output.writeCompressedInt (len + 1);
  3046. output.writeByte (5);
  3047. HeapBlock<char> temp (len);
  3048. value.stringValue->copyToUTF8 (temp, len);
  3049. output.write (temp, len);
  3050. break;
  3051. }
  3052. case objectType:
  3053. case methodType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  3054. default: jassertfalse; break; // Is this a corrupted object?
  3055. }
  3056. }
  3057. const var var::readFromStream (InputStream& input)
  3058. {
  3059. const int numBytes = input.readCompressedInt();
  3060. if (numBytes > 0)
  3061. {
  3062. switch (input.readByte())
  3063. {
  3064. case 1: return var (input.readInt());
  3065. case 2: return var (true);
  3066. case 3: return var (false);
  3067. case 4: return var (input.readDouble());
  3068. case 5:
  3069. {
  3070. MemoryBlock mb;
  3071. input.readIntoMemoryBlock (mb, numBytes - 1);
  3072. return var (String::fromUTF8 ((const char*) mb.getData(), (int) mb.getSize()));
  3073. }
  3074. default: input.skipNextBytes (numBytes - 1); break;
  3075. }
  3076. }
  3077. return var::null;
  3078. }
  3079. const var var::operator[] (const var::identifier& propertyName) const
  3080. {
  3081. if (type == objectType && value.objectValue != 0)
  3082. return value.objectValue->getProperty (propertyName);
  3083. return var::null;
  3084. }
  3085. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  3086. {
  3087. if (type == objectType && value.objectValue != 0)
  3088. return value.objectValue->invokeMethod (method, arguments, numArguments);
  3089. return var::null;
  3090. }
  3091. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  3092. {
  3093. if (isMethod())
  3094. {
  3095. DynamicObject* const target = targetObject.getObject();
  3096. if (target != 0)
  3097. return (target->*(value.methodValue)) (arguments, numArguments);
  3098. }
  3099. return var::null;
  3100. }
  3101. const var var::call (const var::identifier& method) const
  3102. {
  3103. return invoke (method, 0, 0);
  3104. }
  3105. const var var::call (const var::identifier& method, const var& arg1) const
  3106. {
  3107. return invoke (method, &arg1, 1);
  3108. }
  3109. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3110. {
  3111. var args[] = { arg1, arg2 };
  3112. return invoke (method, args, 2);
  3113. }
  3114. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3115. {
  3116. var args[] = { arg1, arg2, arg3 };
  3117. return invoke (method, args, 3);
  3118. }
  3119. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3120. {
  3121. var args[] = { arg1, arg2, arg3, arg4 };
  3122. return invoke (method, args, 4);
  3123. }
  3124. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3125. {
  3126. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3127. return invoke (method, args, 5);
  3128. }
  3129. var::identifier::identifier() throw()
  3130. : hashCode (0)
  3131. {
  3132. }
  3133. var::identifier::identifier (const String& name_)
  3134. : name (name_),
  3135. hashCode (name_.hashCode())
  3136. {
  3137. /* An identifier string must be suitable for use as a script variable or XML
  3138. attribute, so it can only contain this limited set of characters.. */
  3139. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3140. }
  3141. var::identifier::identifier (const char* const name_)
  3142. : name (name_),
  3143. hashCode (name.hashCode())
  3144. {
  3145. /* An identifier string must be suitable for use as a script variable or XML
  3146. attribute, so it can only contain this limited set of characters.. */
  3147. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3148. }
  3149. var::identifier::~identifier()
  3150. {
  3151. }
  3152. END_JUCE_NAMESPACE
  3153. /*** End of inlined file: juce_Variant.cpp ***/
  3154. /*** Start of inlined file: juce_NamedValueSet.cpp ***/
  3155. BEGIN_JUCE_NAMESPACE
  3156. NamedValueSet::NamedValue::NamedValue() throw()
  3157. {
  3158. }
  3159. inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
  3160. : name (name_), value (value_)
  3161. {
  3162. }
  3163. NamedValueSet::NamedValueSet() throw()
  3164. {
  3165. }
  3166. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  3167. : values (other.values)
  3168. {
  3169. }
  3170. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  3171. {
  3172. values = other.values;
  3173. return *this;
  3174. }
  3175. NamedValueSet::~NamedValueSet()
  3176. {
  3177. }
  3178. int NamedValueSet::size() const throw()
  3179. {
  3180. return values.size();
  3181. }
  3182. const var& NamedValueSet::operator[] (const var::identifier& name) const
  3183. {
  3184. for (int i = values.size(); --i >= 0;)
  3185. {
  3186. const NamedValue& v = values.getReference(i);
  3187. if (v.name == name)
  3188. return v.value;
  3189. }
  3190. return var::null;
  3191. }
  3192. const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
  3193. {
  3194. const var* v = getItem (name);
  3195. return v != 0 ? *v : defaultReturnValue;
  3196. }
  3197. var* NamedValueSet::getItem (const var::identifier& name) const
  3198. {
  3199. for (int i = values.size(); --i >= 0;)
  3200. {
  3201. NamedValue& v = values.getReference(i);
  3202. if (v.name == name)
  3203. return &(v.value);
  3204. }
  3205. return 0;
  3206. }
  3207. bool NamedValueSet::set (const var::identifier& name, const var& newValue)
  3208. {
  3209. for (int i = values.size(); --i >= 0;)
  3210. {
  3211. NamedValue& v = values.getReference(i);
  3212. if (v.name == name)
  3213. {
  3214. if (v.value == newValue)
  3215. return false;
  3216. v.value = newValue;
  3217. return true;
  3218. }
  3219. }
  3220. values.add (NamedValue (name, newValue));
  3221. return true;
  3222. }
  3223. bool NamedValueSet::contains (const var::identifier& name) const
  3224. {
  3225. return getItem (name) != 0;
  3226. }
  3227. bool NamedValueSet::remove (const var::identifier& name)
  3228. {
  3229. for (int i = values.size(); --i >= 0;)
  3230. {
  3231. if (values.getReference(i).name == name)
  3232. {
  3233. values.remove (i);
  3234. return true;
  3235. }
  3236. }
  3237. return false;
  3238. }
  3239. const var::identifier NamedValueSet::getName (int index) const
  3240. {
  3241. jassert (((unsigned int) index) < (unsigned int) values.size());
  3242. return values [index].name;
  3243. }
  3244. void NamedValueSet::clear()
  3245. {
  3246. values.clear();
  3247. }
  3248. END_JUCE_NAMESPACE
  3249. /*** End of inlined file: juce_NamedValueSet.cpp ***/
  3250. /*** Start of inlined file: juce_DynamicObject.cpp ***/
  3251. BEGIN_JUCE_NAMESPACE
  3252. DynamicObject::DynamicObject()
  3253. {
  3254. }
  3255. DynamicObject::~DynamicObject()
  3256. {
  3257. }
  3258. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3259. {
  3260. var* const v = properties.getItem (propertyName);
  3261. return v != 0 && ! v->isMethod();
  3262. }
  3263. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3264. {
  3265. return properties [propertyName];
  3266. }
  3267. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3268. {
  3269. properties.set (propertyName, newValue);
  3270. }
  3271. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3272. {
  3273. properties.remove (propertyName);
  3274. }
  3275. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3276. {
  3277. return getProperty (methodName).isMethod();
  3278. }
  3279. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3280. const var* parameters,
  3281. int numParameters)
  3282. {
  3283. return properties [methodName].invoke (var (this), parameters, numParameters);
  3284. }
  3285. void DynamicObject::setMethod (const var::identifier& name,
  3286. var::MethodFunction methodFunction)
  3287. {
  3288. properties.set (name, var (methodFunction));
  3289. }
  3290. void DynamicObject::clear()
  3291. {
  3292. properties.clear();
  3293. }
  3294. END_JUCE_NAMESPACE
  3295. /*** End of inlined file: juce_DynamicObject.cpp ***/
  3296. /*** Start of inlined file: juce_BlowFish.cpp ***/
  3297. BEGIN_JUCE_NAMESPACE
  3298. BlowFish::BlowFish (const void* const keyData, const int keyBytes)
  3299. {
  3300. jassert (keyData != 0);
  3301. jassert (keyBytes > 0);
  3302. static const uint32 initialPValues [18] =
  3303. {
  3304. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3305. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3306. 0x9216d5d9, 0x8979fb1b
  3307. };
  3308. static const uint32 initialSValues [4 * 256] =
  3309. {
  3310. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3311. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3312. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3313. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3314. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3315. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3316. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3317. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3318. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3319. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3320. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3321. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3322. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3323. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3324. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3325. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3326. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3327. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3328. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3329. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3330. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3331. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3332. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3333. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3334. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3335. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3336. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3337. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3338. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3339. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3340. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3341. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3342. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3343. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3344. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3345. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3346. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3347. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3348. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3349. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3350. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3351. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3352. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3353. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3354. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3355. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3356. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3357. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3358. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3359. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3360. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3361. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3362. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3363. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3364. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3365. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3366. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3367. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3368. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3369. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3370. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3371. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3372. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3373. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3374. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3375. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3376. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3377. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3378. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3379. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3380. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3381. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3382. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3383. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3384. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3385. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3386. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3387. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3388. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3389. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3390. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3391. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3392. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3393. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3394. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3395. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3396. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3397. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3398. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3399. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3400. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3401. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3402. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3403. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3404. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3405. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3406. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3407. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3408. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3409. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3410. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3411. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3412. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3413. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3414. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3415. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3416. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3417. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3418. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3419. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3420. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3421. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3422. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3423. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3424. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3425. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3426. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3427. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3428. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3429. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3430. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3431. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3432. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3433. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3434. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3435. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3436. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3437. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3438. };
  3439. memcpy (p, initialPValues, sizeof (p));
  3440. int i, j = 0;
  3441. for (i = 4; --i >= 0;)
  3442. {
  3443. s[i].malloc (256);
  3444. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3445. }
  3446. for (i = 0; i < 18; ++i)
  3447. {
  3448. uint32 d = 0;
  3449. for (int k = 0; k < 4; ++k)
  3450. {
  3451. d = (d << 8) | static_cast <const uint8*> (keyData)[j];
  3452. if (++j >= keyBytes)
  3453. j = 0;
  3454. }
  3455. p[i] = initialPValues[i] ^ d;
  3456. }
  3457. uint32 l = 0, r = 0;
  3458. for (i = 0; i < 18; i += 2)
  3459. {
  3460. encrypt (l, r);
  3461. p[i] = l;
  3462. p[i + 1] = r;
  3463. }
  3464. for (i = 0; i < 4; ++i)
  3465. {
  3466. for (j = 0; j < 256; j += 2)
  3467. {
  3468. encrypt (l, r);
  3469. s[i][j] = l;
  3470. s[i][j + 1] = r;
  3471. }
  3472. }
  3473. }
  3474. BlowFish::BlowFish (const BlowFish& other)
  3475. {
  3476. for (int i = 4; --i >= 0;)
  3477. s[i].malloc (256);
  3478. operator= (other);
  3479. }
  3480. BlowFish& BlowFish::operator= (const BlowFish& other)
  3481. {
  3482. memcpy (p, other.p, sizeof (p));
  3483. for (int i = 4; --i >= 0;)
  3484. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3485. return *this;
  3486. }
  3487. BlowFish::~BlowFish()
  3488. {
  3489. }
  3490. uint32 BlowFish::F (const uint32 x) const throw()
  3491. {
  3492. return ((s[0][(x >> 24) & 0xff] + s[1][(x >> 16) & 0xff])
  3493. ^ s[2][(x >> 8) & 0xff]) + s[3][x & 0xff];
  3494. }
  3495. void BlowFish::encrypt (uint32& data1, uint32& data2) const throw()
  3496. {
  3497. uint32 l = data1;
  3498. uint32 r = data2;
  3499. for (int i = 0; i < 16; ++i)
  3500. {
  3501. l ^= p[i];
  3502. r ^= F(l);
  3503. swapVariables (l, r);
  3504. }
  3505. data1 = r ^ p[17];
  3506. data2 = l ^ p[16];
  3507. }
  3508. void BlowFish::decrypt (uint32& data1, uint32& data2) const throw()
  3509. {
  3510. uint32 l = data1;
  3511. uint32 r = data2;
  3512. for (int i = 17; i > 1; --i)
  3513. {
  3514. l ^= p[i];
  3515. r ^= F(l);
  3516. swapVariables (l, r);
  3517. }
  3518. data1 = r ^ p[0];
  3519. data2 = l ^ p[1];
  3520. }
  3521. END_JUCE_NAMESPACE
  3522. /*** End of inlined file: juce_BlowFish.cpp ***/
  3523. /*** Start of inlined file: juce_MD5.cpp ***/
  3524. BEGIN_JUCE_NAMESPACE
  3525. MD5::MD5()
  3526. {
  3527. zerostruct (result);
  3528. }
  3529. MD5::MD5 (const MD5& other)
  3530. {
  3531. memcpy (result, other.result, sizeof (result));
  3532. }
  3533. MD5& MD5::operator= (const MD5& other)
  3534. {
  3535. memcpy (result, other.result, sizeof (result));
  3536. return *this;
  3537. }
  3538. MD5::MD5 (const MemoryBlock& data)
  3539. {
  3540. ProcessContext context;
  3541. context.processBlock ((const uint8*) data.getData(), data.getSize());
  3542. context.finish (result);
  3543. }
  3544. MD5::MD5 (const char* data, const size_t numBytes)
  3545. {
  3546. ProcessContext context;
  3547. context.processBlock ((const uint8*) data, numBytes);
  3548. context.finish (result);
  3549. }
  3550. MD5::MD5 (const String& text)
  3551. {
  3552. ProcessContext context;
  3553. const int len = text.length();
  3554. const juce_wchar* const t = text;
  3555. for (int i = 0; i < len; ++i)
  3556. {
  3557. // force the string into integer-sized unicode characters, to try to make it
  3558. // get the same results on all platforms + compilers.
  3559. uint32 unicodeChar = (uint32) t[i];
  3560. ByteOrder::swapIfBigEndian (unicodeChar);
  3561. context.processBlock ((const uint8*) &unicodeChar,
  3562. sizeof (unicodeChar));
  3563. }
  3564. context.finish (result);
  3565. }
  3566. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3567. {
  3568. ProcessContext context;
  3569. if (numBytesToRead < 0)
  3570. numBytesToRead = std::numeric_limits<int64>::max();
  3571. while (numBytesToRead > 0)
  3572. {
  3573. char tempBuffer [512];
  3574. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3575. if (bytesRead <= 0)
  3576. break;
  3577. numBytesToRead -= bytesRead;
  3578. context.processBlock ((const uint8*) tempBuffer, bytesRead);
  3579. }
  3580. context.finish (result);
  3581. }
  3582. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3583. {
  3584. processStream (input, numBytesToRead);
  3585. }
  3586. MD5::MD5 (const File& file)
  3587. {
  3588. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3589. if (fin != 0)
  3590. processStream (*fin, -1);
  3591. else
  3592. zerostruct (result);
  3593. }
  3594. MD5::~MD5()
  3595. {
  3596. }
  3597. namespace MD5Functions
  3598. {
  3599. static void encode (uint8* const output, const uint32* const input, const int numBytes) throw()
  3600. {
  3601. uint32* const o = (uint32*) output;
  3602. for (int i = 0; i < (numBytes >> 2); ++i)
  3603. o[i] = ByteOrder::swapIfBigEndian (input [i]);
  3604. }
  3605. static void decode (uint32* const output, const uint8* const input, const int numBytes) throw()
  3606. {
  3607. for (int i = 0; i < (numBytes >> 2); ++i)
  3608. output[i] = ByteOrder::littleEndianInt ((const char*) input + (i << 2));
  3609. }
  3610. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & y) | (~x & z); }
  3611. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & z) | (y & ~z); }
  3612. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) throw() { return x ^ y ^ z; }
  3613. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) throw() { return y ^ (x | ~z); }
  3614. static inline uint32 rotateLeft (const uint32 x, const uint32 n) throw() { return (x << n) | (x >> (32 - n)); }
  3615. static void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3616. {
  3617. a += F (b, c, d) + x + ac;
  3618. a = rotateLeft (a, s) + b;
  3619. }
  3620. static void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3621. {
  3622. a += G (b, c, d) + x + ac;
  3623. a = rotateLeft (a, s) + b;
  3624. }
  3625. static void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3626. {
  3627. a += H (b, c, d) + x + ac;
  3628. a = rotateLeft (a, s) + b;
  3629. }
  3630. static void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3631. {
  3632. a += I (b, c, d) + x + ac;
  3633. a = rotateLeft (a, s) + b;
  3634. }
  3635. }
  3636. MD5::ProcessContext::ProcessContext()
  3637. {
  3638. state[0] = 0x67452301;
  3639. state[1] = 0xefcdab89;
  3640. state[2] = 0x98badcfe;
  3641. state[3] = 0x10325476;
  3642. count[0] = 0;
  3643. count[1] = 0;
  3644. }
  3645. void MD5::ProcessContext::processBlock (const uint8* const data, size_t dataSize)
  3646. {
  3647. int bufferPos = ((count[0] >> 3) & 0x3F);
  3648. count[0] += (uint32) (dataSize << 3);
  3649. if (count[0] < ((uint32) dataSize << 3))
  3650. count[1]++;
  3651. count[1] += (uint32) (dataSize >> 29);
  3652. const size_t spaceLeft = 64 - bufferPos;
  3653. size_t i = 0;
  3654. if (dataSize >= spaceLeft)
  3655. {
  3656. memcpy (buffer + bufferPos, data, spaceLeft);
  3657. transform (buffer);
  3658. i = spaceLeft;
  3659. while (i + 64 <= dataSize)
  3660. {
  3661. transform (data + i);
  3662. i += 64;
  3663. }
  3664. bufferPos = 0;
  3665. }
  3666. memcpy (buffer + bufferPos, data + i, dataSize - i);
  3667. }
  3668. void MD5::ProcessContext::finish (uint8* const result)
  3669. {
  3670. unsigned char encodedLength[8];
  3671. MD5Functions::encode (encodedLength, count, 8);
  3672. // Pad out to 56 mod 64.
  3673. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3674. const int paddingLength = (index < 56) ? (56 - index)
  3675. : (120 - index);
  3676. uint8 paddingBuffer [64];
  3677. zeromem (paddingBuffer, paddingLength);
  3678. paddingBuffer [0] = 0x80;
  3679. processBlock (paddingBuffer, paddingLength);
  3680. processBlock (encodedLength, 8);
  3681. MD5Functions::encode (result, state, 16);
  3682. zerostruct (buffer);
  3683. }
  3684. void MD5::ProcessContext::transform (const uint8* const bufferToTransform)
  3685. {
  3686. using namespace MD5Functions;
  3687. uint32 a = state[0];
  3688. uint32 b = state[1];
  3689. uint32 c = state[2];
  3690. uint32 d = state[3];
  3691. uint32 x[16];
  3692. decode (x, bufferToTransform, 64);
  3693. enum Constants
  3694. {
  3695. S11 = 7, S12 = 12, S13 = 17, S14 = 22, S21 = 5, S22 = 9, S23 = 14, S24 = 20,
  3696. S31 = 4, S32 = 11, S33 = 16, S34 = 23, S41 = 6, S42 = 10, S43 = 15, S44 = 21
  3697. };
  3698. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  3699. FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  3700. FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  3701. FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  3702. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  3703. FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  3704. FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  3705. FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  3706. FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  3707. FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  3708. FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  3709. FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  3710. FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  3711. FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  3712. FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  3713. FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  3714. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  3715. GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  3716. GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  3717. GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  3718. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  3719. GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
  3720. GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  3721. GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  3722. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  3723. GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  3724. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  3725. GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  3726. GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  3727. GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  3728. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  3729. GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  3730. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  3731. HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  3732. HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  3733. HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  3734. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  3735. HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  3736. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  3737. HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  3738. HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  3739. HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  3740. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  3741. HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
  3742. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  3743. HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  3744. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  3745. HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  3746. II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  3747. II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  3748. II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  3749. II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  3750. II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  3751. II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  3752. II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  3753. II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  3754. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  3755. II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  3756. II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  3757. II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  3758. II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  3759. II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  3760. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  3761. II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  3762. state[0] += a;
  3763. state[1] += b;
  3764. state[2] += c;
  3765. state[3] += d;
  3766. zerostruct (x);
  3767. }
  3768. const MemoryBlock MD5::getRawChecksumData() const
  3769. {
  3770. return MemoryBlock (result, sizeof (result));
  3771. }
  3772. const String MD5::toHexString() const
  3773. {
  3774. return String::toHexString (result, sizeof (result), 0);
  3775. }
  3776. bool MD5::operator== (const MD5& other) const
  3777. {
  3778. return memcmp (result, other.result, sizeof (result)) == 0;
  3779. }
  3780. bool MD5::operator!= (const MD5& other) const
  3781. {
  3782. return ! operator== (other);
  3783. }
  3784. END_JUCE_NAMESPACE
  3785. /*** End of inlined file: juce_MD5.cpp ***/
  3786. /*** Start of inlined file: juce_Primes.cpp ***/
  3787. BEGIN_JUCE_NAMESPACE
  3788. namespace PrimesHelpers
  3789. {
  3790. static void createSmallSieve (const int numBits, BigInteger& result)
  3791. {
  3792. result.setBit (numBits);
  3793. result.clearBit (numBits); // to enlarge the array
  3794. result.setBit (0);
  3795. int n = 2;
  3796. do
  3797. {
  3798. for (int i = n + n; i < numBits; i += n)
  3799. result.setBit (i);
  3800. n = result.findNextClearBit (n + 1);
  3801. }
  3802. while (n <= (numBits >> 1));
  3803. }
  3804. static void bigSieve (const BigInteger& base, const int numBits, BigInteger& result,
  3805. const BigInteger& smallSieve, const int smallSieveSize)
  3806. {
  3807. jassert (! base[0]); // must be even!
  3808. result.setBit (numBits);
  3809. result.clearBit (numBits); // to enlarge the array
  3810. int index = smallSieve.findNextClearBit (0);
  3811. do
  3812. {
  3813. const int prime = (index << 1) + 1;
  3814. BigInteger r (base), remainder;
  3815. r.divideBy (prime, remainder);
  3816. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3817. if (r.isZero())
  3818. i += prime;
  3819. if ((i & 1) == 0)
  3820. i += prime;
  3821. i = (i - 1) >> 1;
  3822. while (i < numBits)
  3823. {
  3824. result.setBit (i);
  3825. i += prime;
  3826. }
  3827. index = smallSieve.findNextClearBit (index + 1);
  3828. }
  3829. while (index < smallSieveSize);
  3830. }
  3831. static bool findCandidate (const BigInteger& base, const BigInteger& sieve,
  3832. const int numBits, BigInteger& result, const int certainty)
  3833. {
  3834. for (int i = 0; i < numBits; ++i)
  3835. {
  3836. if (! sieve[i])
  3837. {
  3838. result = base + (unsigned int) ((i << 1) + 1);
  3839. if (Primes::isProbablyPrime (result, certainty))
  3840. return true;
  3841. }
  3842. }
  3843. return false;
  3844. }
  3845. static bool passesMillerRabin (const BigInteger& n, int iterations)
  3846. {
  3847. const BigInteger one (1), two (2);
  3848. const BigInteger nMinusOne (n - one);
  3849. BigInteger d (nMinusOne);
  3850. const int s = d.findNextSetBit (0);
  3851. d >>= s;
  3852. BigInteger smallPrimes;
  3853. int numBitsInSmallPrimes = 0;
  3854. for (;;)
  3855. {
  3856. numBitsInSmallPrimes += 256;
  3857. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  3858. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  3859. if (numPrimesFound > iterations + 1)
  3860. break;
  3861. }
  3862. int smallPrime = 2;
  3863. while (--iterations >= 0)
  3864. {
  3865. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  3866. BigInteger r (smallPrime);
  3867. r.exponentModulo (d, n);
  3868. if (r != one && r != nMinusOne)
  3869. {
  3870. for (int j = 0; j < s; ++j)
  3871. {
  3872. r.exponentModulo (two, n);
  3873. if (r == nMinusOne)
  3874. break;
  3875. }
  3876. if (r != nMinusOne)
  3877. return false;
  3878. }
  3879. }
  3880. return true;
  3881. }
  3882. }
  3883. const BigInteger Primes::createProbablePrime (const int bitLength,
  3884. const int certainty,
  3885. const int* randomSeeds,
  3886. int numRandomSeeds)
  3887. {
  3888. using namespace PrimesHelpers;
  3889. int defaultSeeds [16];
  3890. if (numRandomSeeds <= 0)
  3891. {
  3892. randomSeeds = defaultSeeds;
  3893. numRandomSeeds = numElementsInArray (defaultSeeds);
  3894. Random r (0);
  3895. for (int j = 10; --j >= 0;)
  3896. {
  3897. r.setSeedRandomly();
  3898. for (int i = numRandomSeeds; --i >= 0;)
  3899. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3900. }
  3901. }
  3902. BigInteger smallSieve;
  3903. const int smallSieveSize = 15000;
  3904. createSmallSieve (smallSieveSize, smallSieve);
  3905. BigInteger p;
  3906. for (int i = numRandomSeeds; --i >= 0;)
  3907. {
  3908. BigInteger p2;
  3909. Random r (randomSeeds[i]);
  3910. r.fillBitsRandomly (p2, 0, bitLength);
  3911. p ^= p2;
  3912. }
  3913. p.setBit (bitLength - 1);
  3914. p.clearBit (0);
  3915. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  3916. while (p.getHighestBit() < bitLength)
  3917. {
  3918. p += 2 * searchLen;
  3919. BigInteger sieve;
  3920. bigSieve (p, searchLen, sieve,
  3921. smallSieve, smallSieveSize);
  3922. BigInteger candidate;
  3923. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  3924. return candidate;
  3925. }
  3926. jassertfalse
  3927. return BigInteger();
  3928. }
  3929. bool Primes::isProbablyPrime (const BigInteger& number, const int certainty)
  3930. {
  3931. using namespace PrimesHelpers;
  3932. if (! number[0])
  3933. return false;
  3934. if (number.getHighestBit() <= 10)
  3935. {
  3936. const int num = number.getBitRangeAsInt (0, 10);
  3937. for (int i = num / 2; --i > 1;)
  3938. if (num % i == 0)
  3939. return false;
  3940. return true;
  3941. }
  3942. else
  3943. {
  3944. if (number.findGreatestCommonDivisor (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23) != 1)
  3945. return false;
  3946. return passesMillerRabin (number, certainty);
  3947. }
  3948. }
  3949. END_JUCE_NAMESPACE
  3950. /*** End of inlined file: juce_Primes.cpp ***/
  3951. /*** Start of inlined file: juce_RSAKey.cpp ***/
  3952. BEGIN_JUCE_NAMESPACE
  3953. RSAKey::RSAKey()
  3954. {
  3955. }
  3956. RSAKey::RSAKey (const String& s)
  3957. {
  3958. if (s.containsChar (T(',')))
  3959. {
  3960. part1.parseString (s.upToFirstOccurrenceOf (T(","), false, false), 16);
  3961. part2.parseString (s.fromFirstOccurrenceOf (T(","), false, false), 16);
  3962. }
  3963. else
  3964. {
  3965. // the string needs to be two hex numbers, comma-separated..
  3966. jassertfalse;
  3967. }
  3968. }
  3969. RSAKey::~RSAKey()
  3970. {
  3971. }
  3972. const String RSAKey::toString() const
  3973. {
  3974. return part1.toString (16) + "," + part2.toString (16);
  3975. }
  3976. bool RSAKey::applyToValue (BigInteger& value) const
  3977. {
  3978. if (part1.isZero() || part2.isZero() || value <= 0)
  3979. {
  3980. jassertfalse // using an uninitialised key
  3981. value.clear();
  3982. return false;
  3983. }
  3984. BigInteger result;
  3985. while (! value.isZero())
  3986. {
  3987. result *= part2;
  3988. BigInteger remainder;
  3989. value.divideBy (part2, remainder);
  3990. remainder.exponentModulo (part1, part2);
  3991. result += remainder;
  3992. }
  3993. value.swapWith (result);
  3994. return true;
  3995. }
  3996. static const BigInteger findBestCommonDivisor (const BigInteger& p, const BigInteger& q)
  3997. {
  3998. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  3999. // are fast to divide + multiply
  4000. for (int i = 2; i <= 65536; i *= 2)
  4001. {
  4002. const BigInteger e (1 + i);
  4003. if (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne())
  4004. return e;
  4005. }
  4006. BigInteger e (4);
  4007. while (! (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne()))
  4008. ++e;
  4009. return e;
  4010. }
  4011. void RSAKey::createKeyPair (RSAKey& publicKey, RSAKey& privateKey,
  4012. const int numBits, const int* randomSeeds, const int numRandomSeeds)
  4013. {
  4014. jassert (numBits > 16); // not much point using less than this..
  4015. BigInteger p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  4016. BigInteger q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  4017. const BigInteger n (p * q);
  4018. const BigInteger m (--p * --q);
  4019. const BigInteger e (findBestCommonDivisor (p, q));
  4020. BigInteger d (e);
  4021. d.inverseModulo (m);
  4022. publicKey.part1 = e;
  4023. publicKey.part2 = n;
  4024. privateKey.part1 = d;
  4025. privateKey.part2 = n;
  4026. }
  4027. END_JUCE_NAMESPACE
  4028. /*** End of inlined file: juce_RSAKey.cpp ***/
  4029. /*** Start of inlined file: juce_InputStream.cpp ***/
  4030. BEGIN_JUCE_NAMESPACE
  4031. char InputStream::readByte()
  4032. {
  4033. char temp = 0;
  4034. read (&temp, 1);
  4035. return temp;
  4036. }
  4037. bool InputStream::readBool()
  4038. {
  4039. return readByte() != 0;
  4040. }
  4041. short InputStream::readShort()
  4042. {
  4043. char temp[2];
  4044. if (read (temp, 2) == 2)
  4045. return (short) ByteOrder::littleEndianShort (temp);
  4046. return 0;
  4047. }
  4048. short InputStream::readShortBigEndian()
  4049. {
  4050. char temp[2];
  4051. if (read (temp, 2) == 2)
  4052. return (short) ByteOrder::bigEndianShort (temp);
  4053. return 0;
  4054. }
  4055. int InputStream::readInt()
  4056. {
  4057. char temp[4];
  4058. if (read (temp, 4) == 4)
  4059. return (int) ByteOrder::littleEndianInt (temp);
  4060. return 0;
  4061. }
  4062. int InputStream::readIntBigEndian()
  4063. {
  4064. char temp[4];
  4065. if (read (temp, 4) == 4)
  4066. return (int) ByteOrder::bigEndianInt (temp);
  4067. return 0;
  4068. }
  4069. int InputStream::readCompressedInt()
  4070. {
  4071. const unsigned char sizeByte = readByte();
  4072. if (sizeByte == 0)
  4073. return 0;
  4074. const int numBytes = (sizeByte & 0x7f);
  4075. if (numBytes > 4)
  4076. {
  4077. jassertfalse // trying to read corrupt data - this method must only be used
  4078. // to read data that was written by OutputStream::writeCompressedInt()
  4079. return 0;
  4080. }
  4081. char bytes[4] = { 0, 0, 0, 0 };
  4082. if (read (bytes, numBytes) != numBytes)
  4083. return 0;
  4084. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4085. return (sizeByte >> 7) ? -num : num;
  4086. }
  4087. int64 InputStream::readInt64()
  4088. {
  4089. char temp[8];
  4090. if (read (temp, 8) == 8)
  4091. return (int64) ByteOrder::swapIfBigEndian (*reinterpret_cast <uint64*> (temp));
  4092. return 0;
  4093. }
  4094. int64 InputStream::readInt64BigEndian()
  4095. {
  4096. char temp[8];
  4097. if (read (temp, 8) == 8)
  4098. return (int64) ByteOrder::swapIfLittleEndian (*reinterpret_cast <uint64*> (temp));
  4099. return 0;
  4100. }
  4101. float InputStream::readFloat()
  4102. {
  4103. union { int asInt; float asFloat; } n;
  4104. n.asInt = readInt();
  4105. return n.asFloat;
  4106. }
  4107. float InputStream::readFloatBigEndian()
  4108. {
  4109. union { int asInt; float asFloat; } n;
  4110. n.asInt = readIntBigEndian();
  4111. return n.asFloat;
  4112. }
  4113. double InputStream::readDouble()
  4114. {
  4115. union { int64 asInt; double asDouble; } n;
  4116. n.asInt = readInt64();
  4117. return n.asDouble;
  4118. }
  4119. double InputStream::readDoubleBigEndian()
  4120. {
  4121. union { int64 asInt; double asDouble; } n;
  4122. n.asInt = readInt64BigEndian();
  4123. return n.asDouble;
  4124. }
  4125. const String InputStream::readString()
  4126. {
  4127. MemoryBlock buffer (256);
  4128. char* data = static_cast<char*> (buffer.getData());
  4129. size_t i = 0;
  4130. while ((data[i] = readByte()) != 0)
  4131. {
  4132. if (++i >= buffer.getSize())
  4133. {
  4134. buffer.setSize (buffer.getSize() + 512);
  4135. data = static_cast<char*> (buffer.getData());
  4136. }
  4137. }
  4138. return String::fromUTF8 (data, (int) i);
  4139. }
  4140. const String InputStream::readNextLine()
  4141. {
  4142. MemoryBlock buffer (256);
  4143. char* data = static_cast<char*> (buffer.getData());
  4144. size_t i = 0;
  4145. while ((data[i] = readByte()) != 0)
  4146. {
  4147. if (data[i] == '\n')
  4148. break;
  4149. if (data[i] == '\r')
  4150. {
  4151. const int64 lastPos = getPosition();
  4152. if (readByte() != '\n')
  4153. setPosition (lastPos);
  4154. break;
  4155. }
  4156. if (++i >= buffer.getSize())
  4157. {
  4158. buffer.setSize (buffer.getSize() + 512);
  4159. data = static_cast<char*> (buffer.getData());
  4160. }
  4161. }
  4162. return String::fromUTF8 (data, (int) i);
  4163. }
  4164. int InputStream::readIntoMemoryBlock (MemoryBlock& block, int numBytes)
  4165. {
  4166. const int64 totalLength = getTotalLength();
  4167. if (totalLength >= 0)
  4168. {
  4169. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4170. totalLength - getPosition());
  4171. if (numBytes < 0)
  4172. numBytes = totalBytesRemaining;
  4173. else if (numBytes > 0)
  4174. numBytes = jmin (numBytes, totalBytesRemaining);
  4175. else
  4176. return 0;
  4177. }
  4178. const size_t originalBlockSize = block.getSize();
  4179. int totalBytesRead = 0;
  4180. if (numBytes > 0)
  4181. {
  4182. // know how many bytes we want, so we can resize the block first..
  4183. block.setSize (originalBlockSize + numBytes, false);
  4184. totalBytesRead = read (static_cast<char*> (block.getData()) + originalBlockSize, numBytes);
  4185. }
  4186. else
  4187. {
  4188. // read until end of stram..
  4189. const int chunkSize = 32768;
  4190. for (;;)
  4191. {
  4192. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4193. const int bytesJustIn = read (static_cast<char*> (block.getData())
  4194. + originalBlockSize
  4195. + totalBytesRead,
  4196. chunkSize);
  4197. if (bytesJustIn == 0)
  4198. break;
  4199. totalBytesRead += bytesJustIn;
  4200. }
  4201. }
  4202. // trim off any excess left at the end
  4203. block.setSize (originalBlockSize + totalBytesRead, false);
  4204. return totalBytesRead;
  4205. }
  4206. const String InputStream::readEntireStreamAsString()
  4207. {
  4208. MemoryBlock mb;
  4209. const int size = readIntoMemoryBlock (mb);
  4210. return String::createStringFromData (static_cast<const char*> (mb.getData()), size);
  4211. }
  4212. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4213. {
  4214. if (numBytesToSkip > 0)
  4215. {
  4216. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4217. HeapBlock<char> temp (skipBufferSize);
  4218. while (numBytesToSkip > 0 && ! isExhausted())
  4219. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4220. }
  4221. }
  4222. END_JUCE_NAMESPACE
  4223. /*** End of inlined file: juce_InputStream.cpp ***/
  4224. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4225. BEGIN_JUCE_NAMESPACE
  4226. #if JUCE_DEBUG
  4227. static CriticalSection activeStreamLock;
  4228. static VoidArray activeStreams;
  4229. void juce_CheckForDanglingStreams()
  4230. {
  4231. /*
  4232. It's always a bad idea to leak any object, but if you're leaking output
  4233. streams, then there's a good chance that you're failing to flush a file
  4234. to disk properly, which could result in corrupted data and other similar
  4235. nastiness..
  4236. */
  4237. jassert (activeStreams.size() == 0);
  4238. };
  4239. #endif
  4240. OutputStream::OutputStream()
  4241. {
  4242. #if JUCE_DEBUG
  4243. const ScopedLock sl (activeStreamLock);
  4244. activeStreams.add (this);
  4245. #endif
  4246. }
  4247. OutputStream::~OutputStream()
  4248. {
  4249. #if JUCE_DEBUG
  4250. const ScopedLock sl (activeStreamLock);
  4251. activeStreams.removeValue (this);
  4252. #endif
  4253. }
  4254. void OutputStream::writeBool (const bool b)
  4255. {
  4256. writeByte (b ? (char) 1
  4257. : (char) 0);
  4258. }
  4259. void OutputStream::writeByte (char byte)
  4260. {
  4261. write (&byte, 1);
  4262. }
  4263. void OutputStream::writeShort (short value)
  4264. {
  4265. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4266. write (&v, 2);
  4267. }
  4268. void OutputStream::writeShortBigEndian (short value)
  4269. {
  4270. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4271. write (&v, 2);
  4272. }
  4273. void OutputStream::writeInt (int value)
  4274. {
  4275. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4276. write (&v, 4);
  4277. }
  4278. void OutputStream::writeIntBigEndian (int value)
  4279. {
  4280. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4281. write (&v, 4);
  4282. }
  4283. void OutputStream::writeCompressedInt (int value)
  4284. {
  4285. unsigned int un = (value < 0) ? (unsigned int) -value
  4286. : (unsigned int) value;
  4287. uint8 data[5];
  4288. int num = 0;
  4289. while (un > 0)
  4290. {
  4291. data[++num] = (uint8) un;
  4292. un >>= 8;
  4293. }
  4294. data[0] = (uint8) num;
  4295. if (value < 0)
  4296. data[0] |= 0x80;
  4297. write (data, num + 1);
  4298. }
  4299. void OutputStream::writeInt64 (int64 value)
  4300. {
  4301. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4302. write (&v, 8);
  4303. }
  4304. void OutputStream::writeInt64BigEndian (int64 value)
  4305. {
  4306. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4307. write (&v, 8);
  4308. }
  4309. void OutputStream::writeFloat (float value)
  4310. {
  4311. union { int asInt; float asFloat; } n;
  4312. n.asFloat = value;
  4313. writeInt (n.asInt);
  4314. }
  4315. void OutputStream::writeFloatBigEndian (float value)
  4316. {
  4317. union { int asInt; float asFloat; } n;
  4318. n.asFloat = value;
  4319. writeIntBigEndian (n.asInt);
  4320. }
  4321. void OutputStream::writeDouble (double value)
  4322. {
  4323. union { int64 asInt; double asDouble; } n;
  4324. n.asDouble = value;
  4325. writeInt64 (n.asInt);
  4326. }
  4327. void OutputStream::writeDoubleBigEndian (double value)
  4328. {
  4329. union { int64 asInt; double asDouble; } n;
  4330. n.asDouble = value;
  4331. writeInt64BigEndian (n.asInt);
  4332. }
  4333. void OutputStream::writeString (const String& text)
  4334. {
  4335. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  4336. // if lots of large, persistent strings were to be written to streams).
  4337. const int numBytes = text.getNumBytesAsUTF8() + 1;
  4338. HeapBlock<char> temp (numBytes);
  4339. text.copyToUTF8 (temp, numBytes);
  4340. write (temp, numBytes);
  4341. }
  4342. void OutputStream::writeText (const String& text, const bool asUnicode,
  4343. const bool writeUnicodeHeaderBytes)
  4344. {
  4345. if (asUnicode)
  4346. {
  4347. if (writeUnicodeHeaderBytes)
  4348. write ("\x0ff\x0fe", 2);
  4349. const juce_wchar* src = (const juce_wchar*) text;
  4350. bool lastCharWasReturn = false;
  4351. while (*src != 0)
  4352. {
  4353. if (*src == L'\n' && ! lastCharWasReturn)
  4354. writeShort ((short) L'\r');
  4355. lastCharWasReturn = (*src == L'\r');
  4356. writeShort ((short) *src++);
  4357. }
  4358. }
  4359. else
  4360. {
  4361. const char* src = text.toUTF8();
  4362. const char* t = src;
  4363. for (;;)
  4364. {
  4365. if (*t == '\n')
  4366. {
  4367. if (t > src)
  4368. write (src, (int) (t - src));
  4369. write ("\r\n", 2);
  4370. src = t + 1;
  4371. }
  4372. else if (*t == '\r')
  4373. {
  4374. if (t[1] == '\n')
  4375. ++t;
  4376. }
  4377. else if (*t == 0)
  4378. {
  4379. if (t > src)
  4380. write (src, (int) (t - src));
  4381. break;
  4382. }
  4383. ++t;
  4384. }
  4385. }
  4386. }
  4387. int OutputStream::writeFromInputStream (InputStream& source, int numBytesToWrite)
  4388. {
  4389. if (numBytesToWrite < 0)
  4390. numBytesToWrite = 0x7fffffff;
  4391. int numWritten = 0;
  4392. while (numBytesToWrite > 0 && ! source.isExhausted())
  4393. {
  4394. char buffer [8192];
  4395. const int num = (int) source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4396. if (num == 0)
  4397. break;
  4398. write (buffer, num);
  4399. numBytesToWrite -= num;
  4400. numWritten += num;
  4401. }
  4402. return numWritten;
  4403. }
  4404. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const int number)
  4405. {
  4406. return stream << String (number);
  4407. }
  4408. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const double number)
  4409. {
  4410. return stream << String (number);
  4411. }
  4412. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char character)
  4413. {
  4414. stream.writeByte (character);
  4415. return stream;
  4416. }
  4417. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char* const text)
  4418. {
  4419. stream.write (text, (int) strlen (text));
  4420. return stream;
  4421. }
  4422. END_JUCE_NAMESPACE
  4423. /*** End of inlined file: juce_OutputStream.cpp ***/
  4424. /*** Start of inlined file: juce_DirectoryIterator.cpp ***/
  4425. BEGIN_JUCE_NAMESPACE
  4426. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4427. bool* isDirectory, bool* isHidden, int64* fileSize,
  4428. Time* modTime, Time* creationTime, bool* isReadOnly);
  4429. bool juce_findFileNext (void* handle, String& resultFile,
  4430. bool* isDirectory, bool* isHidden, int64* fileSize,
  4431. Time* modTime, Time* creationTime, bool* isReadOnly);
  4432. void juce_findFileClose (void* handle);
  4433. DirectoryIterator::DirectoryIterator (const File& directory,
  4434. bool isRecursive,
  4435. const String& wc,
  4436. const int whatToLookFor_)
  4437. : wildCard (wc),
  4438. index (-1),
  4439. whatToLookFor (whatToLookFor_)
  4440. {
  4441. // you have to specify the type of files you're looking for!
  4442. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4443. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4444. String path (directory.getFullPathName());
  4445. if (! path.endsWithChar (File::separator))
  4446. path += File::separator;
  4447. String filename;
  4448. bool isDirectory, isHidden;
  4449. void* const handle = juce_findFileStart (path,
  4450. isRecursive ? T("*") : wc,
  4451. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4452. if (handle != 0)
  4453. {
  4454. do
  4455. {
  4456. if (! filename.containsOnly (T(".")))
  4457. {
  4458. bool addToList = false;
  4459. if (isDirectory)
  4460. {
  4461. if (isRecursive
  4462. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4463. || ! isHidden))
  4464. {
  4465. dirsFound.add (File (path + filename, 0));
  4466. }
  4467. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4468. }
  4469. else
  4470. {
  4471. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4472. }
  4473. // if it's recursive, we're not relying on the OS iterator
  4474. // to do the wildcard match, so do it now..
  4475. if (isRecursive && addToList)
  4476. addToList = filename.matchesWildcard (wc, true);
  4477. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4478. addToList = ! isHidden;
  4479. if (addToList)
  4480. filesFound.add (File (path + filename, 0));
  4481. }
  4482. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4483. juce_findFileClose (handle);
  4484. }
  4485. }
  4486. DirectoryIterator::~DirectoryIterator()
  4487. {
  4488. }
  4489. bool DirectoryIterator::next()
  4490. {
  4491. if (subIterator != 0)
  4492. {
  4493. if (subIterator->next())
  4494. return true;
  4495. subIterator = 0;
  4496. }
  4497. if (index >= filesFound.size() + dirsFound.size() - 1)
  4498. return false;
  4499. ++index;
  4500. if (index >= filesFound.size())
  4501. {
  4502. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4503. true, wildCard, whatToLookFor);
  4504. return next();
  4505. }
  4506. return true;
  4507. }
  4508. const File DirectoryIterator::getFile() const
  4509. {
  4510. if (subIterator != 0)
  4511. return subIterator->getFile();
  4512. return filesFound [index];
  4513. }
  4514. float DirectoryIterator::getEstimatedProgress() const
  4515. {
  4516. if (filesFound.size() + dirsFound.size() == 0)
  4517. {
  4518. return 0.0f;
  4519. }
  4520. else
  4521. {
  4522. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4523. : (float) index;
  4524. return detailedIndex / (filesFound.size() + dirsFound.size());
  4525. }
  4526. }
  4527. END_JUCE_NAMESPACE
  4528. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4529. /*** Start of inlined file: juce_File.cpp ***/
  4530. #ifdef _MSC_VER
  4531. #pragma warning (disable: 4514)
  4532. #pragma warning (push)
  4533. #endif
  4534. #if ! JUCE_WINDOWS
  4535. #include <pwd.h>
  4536. #endif
  4537. BEGIN_JUCE_NAMESPACE
  4538. #ifdef _MSC_VER
  4539. #pragma warning (pop)
  4540. #endif
  4541. void* juce_fileOpen (const String& path, bool forWriting);
  4542. void juce_fileClose (void* handle);
  4543. int juce_fileWrite (void* handle, const void* buffer, int size);
  4544. int64 juce_fileGetPosition (void* handle);
  4545. int64 juce_fileSetPosition (void* handle, int64 pos);
  4546. void juce_fileFlush (void* handle);
  4547. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4548. bool juce_isDirectory (const String& fileName);
  4549. int64 juce_getFileSize (const String& fileName);
  4550. bool juce_canWriteToFile (const String& fileName);
  4551. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4552. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4553. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4554. bool juce_deleteFile (const String& fileName);
  4555. bool juce_copyFile (const String& source, const String& dest);
  4556. bool juce_moveFile (const String& source, const String& dest);
  4557. // this must also create all paths involved in the directory.
  4558. void juce_createDirectory (const String& fileName);
  4559. bool juce_launchFile (const String& fileName, const String& parameters);
  4560. const StringArray juce_getFileSystemRoots();
  4561. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4562. // starts a directory search operation with a wildcard, returning a handle for
  4563. // use in calls to juce_findFileNext.
  4564. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4565. // the other pointers, if non-null, are set based on the properties of the file.
  4566. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4567. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4568. Time* creationTime, bool* isReadOnly);
  4569. // returns false when no more files are found
  4570. bool juce_findFileNext (void* handle, String& resultFile,
  4571. bool* isDirectory, bool* isHidden, int64* fileSize,
  4572. Time* modTime, Time* creationTime, bool* isReadOnly);
  4573. void juce_findFileClose (void* handle);
  4574. static const String juce_addTrailingSeparator (const String& path)
  4575. {
  4576. return path.endsWithChar (File::separator) ? path
  4577. : path + File::separator;
  4578. }
  4579. static const String parseAbsolutePath (String path)
  4580. {
  4581. if (path.isEmpty())
  4582. return String::empty;
  4583. #if JUCE_WINDOWS
  4584. // Windows..
  4585. path = path.replaceCharacter (T('/'), T('\\'));
  4586. if (path.startsWithChar (File::separator))
  4587. {
  4588. if (path[1] != File::separator)
  4589. {
  4590. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4591. If you're trying to parse a string that may be either a relative path or an absolute path,
  4592. you MUST provide a context against which the partial path can be evaluated - you can do
  4593. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4594. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4595. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4596. */
  4597. jassertfalse
  4598. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4599. }
  4600. }
  4601. else if (path.indexOfChar (T(':')) < 0)
  4602. {
  4603. if (path.isEmpty())
  4604. return String::empty;
  4605. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4606. If you're trying to parse a string that may be either a relative path or an absolute path,
  4607. you MUST provide a context against which the partial path can be evaluated - you can do
  4608. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4609. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4610. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4611. */
  4612. jassertfalse
  4613. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4614. }
  4615. #else
  4616. // Mac or Linux..
  4617. path = path.replaceCharacter (T('\\'), T('/'));
  4618. if (path.startsWithChar (T('~')))
  4619. {
  4620. const char* homeDir = 0;
  4621. if (path[1] == File::separator || path[1] == 0)
  4622. {
  4623. // expand a name of the form "~/abc"
  4624. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4625. + path.substring (1);
  4626. }
  4627. else
  4628. {
  4629. // expand a name of type "~dave/abc"
  4630. const String userName (path.substring (1).upToFirstOccurrenceOf (T("/"), false, false));
  4631. struct passwd* const pw = getpwnam (userName.toUTF8());
  4632. if (pw != 0)
  4633. {
  4634. String home (homeDir);
  4635. if (home.endsWithChar (File::separator))
  4636. home [home.length() - 1] = 0;
  4637. path = String (pw->pw_dir)
  4638. + path.substring (userName.length());
  4639. }
  4640. }
  4641. }
  4642. else if (! path.startsWithChar (File::separator))
  4643. {
  4644. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4645. If you're trying to parse a string that may be either a relative path or an absolute path,
  4646. you MUST provide a context against which the partial path can be evaluated - you can do
  4647. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4648. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4649. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4650. */
  4651. jassert (path.startsWith (T("./"))); // (assume that a path "./xyz" is deliberately intended to be relative to the CWD)
  4652. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4653. }
  4654. #endif
  4655. int len = path.length();
  4656. while (--len > 0 && path [len] == File::separator)
  4657. path [len] = 0;
  4658. return path;
  4659. }
  4660. const File File::nonexistent;
  4661. File::File (const String& fullPathName)
  4662. : fullPath (parseAbsolutePath (fullPathName))
  4663. {
  4664. }
  4665. File::File (const String& path, int)
  4666. : fullPath (path)
  4667. {
  4668. }
  4669. const File File::createFileWithoutCheckingPath (const String& path)
  4670. {
  4671. return File (path, 0);
  4672. }
  4673. File::File (const File& other)
  4674. : fullPath (other.fullPath)
  4675. {
  4676. }
  4677. File& File::operator= (const String& newPath)
  4678. {
  4679. fullPath = parseAbsolutePath (newPath);
  4680. return *this;
  4681. }
  4682. File& File::operator= (const File& other)
  4683. {
  4684. fullPath = other.fullPath;
  4685. return *this;
  4686. }
  4687. #if JUCE_LINUX
  4688. #define NAMES_ARE_CASE_SENSITIVE 1
  4689. #endif
  4690. bool File::areFileNamesCaseSensitive()
  4691. {
  4692. #if NAMES_ARE_CASE_SENSITIVE
  4693. return true;
  4694. #else
  4695. return false;
  4696. #endif
  4697. }
  4698. bool File::operator== (const File& other) const
  4699. {
  4700. // case-insensitive on Windows, but not on linux.
  4701. #if NAMES_ARE_CASE_SENSITIVE
  4702. return fullPath == other.fullPath;
  4703. #else
  4704. return fullPath.equalsIgnoreCase (other.fullPath);
  4705. #endif
  4706. }
  4707. bool File::operator!= (const File& other) const
  4708. {
  4709. return ! operator== (other);
  4710. }
  4711. bool File::exists() const
  4712. {
  4713. return juce_fileExists (fullPath, false);
  4714. }
  4715. bool File::existsAsFile() const
  4716. {
  4717. return juce_fileExists (fullPath, true);
  4718. }
  4719. bool File::isDirectory() const
  4720. {
  4721. return juce_isDirectory (fullPath);
  4722. }
  4723. bool File::hasWriteAccess() const
  4724. {
  4725. if (exists())
  4726. return juce_canWriteToFile (fullPath);
  4727. #if ! JUCE_WINDOWS
  4728. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4729. return getParentDirectory().hasWriteAccess();
  4730. else
  4731. return false;
  4732. #else
  4733. // on windows, it seems that even read-only directories can still be written into,
  4734. // so checking the parent directory's permissions would return the wrong result..
  4735. else
  4736. return true;
  4737. #endif
  4738. }
  4739. bool File::setReadOnly (const bool shouldBeReadOnly,
  4740. const bool applyRecursively) const
  4741. {
  4742. bool worked = true;
  4743. if (applyRecursively && isDirectory())
  4744. {
  4745. Array <File> subFiles;
  4746. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4747. for (int i = subFiles.size(); --i >= 0;)
  4748. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4749. }
  4750. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4751. }
  4752. bool File::deleteFile() const
  4753. {
  4754. return (! exists())
  4755. || juce_deleteFile (fullPath);
  4756. }
  4757. bool File::deleteRecursively() const
  4758. {
  4759. bool worked = true;
  4760. if (isDirectory())
  4761. {
  4762. Array<File> subFiles;
  4763. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4764. for (int i = subFiles.size(); --i >= 0;)
  4765. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4766. }
  4767. return deleteFile() && worked;
  4768. }
  4769. bool File::moveFileTo (const File& newFile) const
  4770. {
  4771. if (newFile.fullPath == fullPath)
  4772. return true;
  4773. #if ! NAMES_ARE_CASE_SENSITIVE
  4774. if (*this != newFile)
  4775. #endif
  4776. if (! newFile.deleteFile())
  4777. return false;
  4778. return juce_moveFile (fullPath, newFile.fullPath);
  4779. }
  4780. bool File::copyFileTo (const File& newFile) const
  4781. {
  4782. if (*this == newFile)
  4783. return true;
  4784. if (! newFile.deleteFile())
  4785. return false;
  4786. return juce_copyFile (fullPath, newFile.fullPath);
  4787. }
  4788. bool File::copyDirectoryTo (const File& newDirectory) const
  4789. {
  4790. if (isDirectory() && newDirectory.createDirectory())
  4791. {
  4792. Array<File> subFiles;
  4793. findChildFiles (subFiles, File::findFiles, false);
  4794. int i;
  4795. for (i = 0; i < subFiles.size(); ++i)
  4796. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4797. return false;
  4798. subFiles.clear();
  4799. findChildFiles (subFiles, File::findDirectories, false);
  4800. for (i = 0; i < subFiles.size(); ++i)
  4801. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4802. return false;
  4803. return true;
  4804. }
  4805. return false;
  4806. }
  4807. const String File::getPathUpToLastSlash() const
  4808. {
  4809. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4810. if (lastSlash > 0)
  4811. return fullPath.substring (0, lastSlash);
  4812. else if (lastSlash == 0)
  4813. return separatorString;
  4814. else
  4815. return fullPath;
  4816. }
  4817. const File File::getParentDirectory() const
  4818. {
  4819. return File (getPathUpToLastSlash());
  4820. }
  4821. const String File::getFileName() const
  4822. {
  4823. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  4824. }
  4825. int File::hashCode() const
  4826. {
  4827. return fullPath.hashCode();
  4828. }
  4829. int64 File::hashCode64() const
  4830. {
  4831. return fullPath.hashCode64();
  4832. }
  4833. const String File::getFileNameWithoutExtension() const
  4834. {
  4835. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  4836. const int lastDot = fullPath.lastIndexOfChar (T('.'));
  4837. if (lastDot > lastSlash)
  4838. return fullPath.substring (lastSlash, lastDot);
  4839. else
  4840. return fullPath.substring (lastSlash);
  4841. }
  4842. bool File::isAChildOf (const File& potentialParent) const
  4843. {
  4844. if (potentialParent == File::nonexistent)
  4845. return false;
  4846. const String ourPath (getPathUpToLastSlash());
  4847. #if NAMES_ARE_CASE_SENSITIVE
  4848. if (potentialParent.fullPath == ourPath)
  4849. #else
  4850. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  4851. #endif
  4852. {
  4853. return true;
  4854. }
  4855. else if (potentialParent.fullPath.length() >= ourPath.length())
  4856. {
  4857. return false;
  4858. }
  4859. else
  4860. {
  4861. return getParentDirectory().isAChildOf (potentialParent);
  4862. }
  4863. }
  4864. bool File::isAbsolutePath (const String& path)
  4865. {
  4866. return path.startsWithChar (T('/')) || path.startsWithChar (T('\\'))
  4867. #if JUCE_WINDOWS
  4868. || (path.isNotEmpty() && ((const String&) path)[1] == T(':'));
  4869. #else
  4870. || path.startsWithChar (T('~'));
  4871. #endif
  4872. }
  4873. const File File::getChildFile (String relativePath) const
  4874. {
  4875. if (isAbsolutePath (relativePath))
  4876. {
  4877. // the path is really absolute..
  4878. return File (relativePath);
  4879. }
  4880. else
  4881. {
  4882. // it's relative, so remove any ../ or ./ bits at the start.
  4883. String path (fullPath);
  4884. if (relativePath[0] == T('.'))
  4885. {
  4886. #if JUCE_WINDOWS
  4887. relativePath = relativePath.replaceCharacter (T('/'), T('\\')).trimStart();
  4888. #else
  4889. relativePath = relativePath.replaceCharacter (T('\\'), T('/')).trimStart();
  4890. #endif
  4891. while (relativePath[0] == T('.'))
  4892. {
  4893. if (relativePath[1] == T('.'))
  4894. {
  4895. if (relativePath [2] == 0 || relativePath[2] == separator)
  4896. {
  4897. const int lastSlash = path.lastIndexOfChar (separator);
  4898. if (lastSlash >= 0)
  4899. path = path.substring (0, lastSlash);
  4900. relativePath = relativePath.substring (3);
  4901. }
  4902. else
  4903. {
  4904. break;
  4905. }
  4906. }
  4907. else if (relativePath[1] == separator)
  4908. {
  4909. relativePath = relativePath.substring (2);
  4910. }
  4911. else
  4912. {
  4913. break;
  4914. }
  4915. }
  4916. }
  4917. return File (juce_addTrailingSeparator (path) + relativePath);
  4918. }
  4919. }
  4920. const File File::getSiblingFile (const String& fileName) const
  4921. {
  4922. return getParentDirectory().getChildFile (fileName);
  4923. }
  4924. int64 File::getSize() const
  4925. {
  4926. return juce_getFileSize (fullPath);
  4927. }
  4928. const String File::descriptionOfSizeInBytes (const int64 bytes)
  4929. {
  4930. if (bytes == 1)
  4931. {
  4932. return "1 byte";
  4933. }
  4934. else if (bytes < 1024)
  4935. {
  4936. return String ((int) bytes) + " bytes";
  4937. }
  4938. else if (bytes < 1024 * 1024)
  4939. {
  4940. return String (bytes / 1024.0, 1) + " KB";
  4941. }
  4942. else if (bytes < 1024 * 1024 * 1024)
  4943. {
  4944. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  4945. }
  4946. else
  4947. {
  4948. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  4949. }
  4950. }
  4951. bool File::create() const
  4952. {
  4953. if (! exists())
  4954. {
  4955. const File parentDir (getParentDirectory());
  4956. if (parentDir == *this || ! parentDir.createDirectory())
  4957. return false;
  4958. void* const fh = juce_fileOpen (fullPath, true);
  4959. if (fh == 0)
  4960. return false;
  4961. juce_fileClose (fh);
  4962. }
  4963. return true;
  4964. }
  4965. bool File::createDirectory() const
  4966. {
  4967. if (! isDirectory())
  4968. {
  4969. const File parentDir (getParentDirectory());
  4970. if (parentDir == *this || ! parentDir.createDirectory())
  4971. return false;
  4972. String dir (fullPath);
  4973. while (dir.endsWithChar (separator))
  4974. dir [dir.length() - 1] = 0;
  4975. juce_createDirectory (dir);
  4976. return isDirectory();
  4977. }
  4978. return true;
  4979. }
  4980. const Time File::getCreationTime() const
  4981. {
  4982. int64 m, a, c;
  4983. juce_getFileTimes (fullPath, m, a, c);
  4984. return Time (c);
  4985. }
  4986. bool File::setCreationTime (const Time& t) const
  4987. {
  4988. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  4989. }
  4990. const Time File::getLastModificationTime() const
  4991. {
  4992. int64 m, a, c;
  4993. juce_getFileTimes (fullPath, m, a, c);
  4994. return Time (m);
  4995. }
  4996. bool File::setLastModificationTime (const Time& t) const
  4997. {
  4998. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  4999. }
  5000. const Time File::getLastAccessTime() const
  5001. {
  5002. int64 m, a, c;
  5003. juce_getFileTimes (fullPath, m, a, c);
  5004. return Time (a);
  5005. }
  5006. bool File::setLastAccessTime (const Time& t) const
  5007. {
  5008. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  5009. }
  5010. bool File::loadFileAsData (MemoryBlock& destBlock) const
  5011. {
  5012. if (! existsAsFile())
  5013. return false;
  5014. FileInputStream in (*this);
  5015. return getSize() == in.readIntoMemoryBlock (destBlock);
  5016. }
  5017. const String File::loadFileAsString() const
  5018. {
  5019. if (! existsAsFile())
  5020. return String::empty;
  5021. FileInputStream in (*this);
  5022. return in.readEntireStreamAsString();
  5023. }
  5024. static inline bool fileTypeMatches (const int whatToLookFor,
  5025. const bool isDir,
  5026. const bool isHidden)
  5027. {
  5028. return (whatToLookFor & (isDir ? File::findDirectories
  5029. : File::findFiles)) != 0
  5030. && ((! isHidden)
  5031. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5032. }
  5033. int File::findChildFiles (Array<File>& results,
  5034. const int whatToLookFor,
  5035. const bool searchRecursively,
  5036. const String& wildCardPattern) const
  5037. {
  5038. // you have to specify the type of files you're looking for!
  5039. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5040. int total = 0;
  5041. // find child files or directories in this directory first..
  5042. if (isDirectory())
  5043. {
  5044. const String path (juce_addTrailingSeparator (fullPath));
  5045. String filename;
  5046. bool itemIsDirectory, itemIsHidden;
  5047. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5048. &itemIsDirectory, &itemIsHidden,
  5049. 0, 0, 0, 0);
  5050. if (handle != 0)
  5051. {
  5052. do
  5053. {
  5054. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5055. && ! filename.containsOnly (T(".")))
  5056. {
  5057. results.add (File (path + filename, 0));
  5058. ++total;
  5059. }
  5060. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5061. juce_findFileClose (handle);
  5062. }
  5063. }
  5064. else
  5065. {
  5066. // trying to search for files inside a non-directory?
  5067. //jassertfalse
  5068. }
  5069. // and recurse down if required.
  5070. if (searchRecursively)
  5071. {
  5072. Array<File> subDirectories;
  5073. findChildFiles (subDirectories, File::findDirectories, false);
  5074. for (int i = 0; i < subDirectories.size(); ++i)
  5075. {
  5076. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5077. true, wildCardPattern);
  5078. }
  5079. }
  5080. return total;
  5081. }
  5082. int File::getNumberOfChildFiles (const int whatToLookFor,
  5083. const String& wildCardPattern) const
  5084. {
  5085. // you have to specify the type of files you're looking for!
  5086. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5087. int count = 0;
  5088. if (isDirectory())
  5089. {
  5090. String filename;
  5091. bool itemIsDirectory, itemIsHidden;
  5092. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5093. &itemIsDirectory, &itemIsHidden,
  5094. 0, 0, 0, 0);
  5095. if (handle != 0)
  5096. {
  5097. do
  5098. {
  5099. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5100. && ! filename.containsOnly (T(".")))
  5101. {
  5102. ++count;
  5103. }
  5104. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5105. juce_findFileClose (handle);
  5106. }
  5107. }
  5108. else
  5109. {
  5110. // trying to search for files inside a non-directory?
  5111. jassertfalse
  5112. }
  5113. return count;
  5114. }
  5115. bool File::containsSubDirectories() const
  5116. {
  5117. bool result = false;
  5118. if (isDirectory())
  5119. {
  5120. String filename;
  5121. bool itemIsDirectory, itemIsHidden;
  5122. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5123. T("*"), filename,
  5124. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5125. if (handle != 0)
  5126. {
  5127. do
  5128. {
  5129. if (itemIsDirectory)
  5130. {
  5131. result = true;
  5132. break;
  5133. }
  5134. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5135. juce_findFileClose (handle);
  5136. }
  5137. }
  5138. return result;
  5139. }
  5140. const File File::getNonexistentChildFile (const String& prefix_,
  5141. const String& suffix,
  5142. bool putNumbersInBrackets) const
  5143. {
  5144. File f (getChildFile (prefix_ + suffix));
  5145. if (f.exists())
  5146. {
  5147. int num = 2;
  5148. String prefix (prefix_);
  5149. // remove any bracketed numbers that may already be on the end..
  5150. if (prefix.trim().endsWithChar (T(')')))
  5151. {
  5152. putNumbersInBrackets = true;
  5153. const int openBracks = prefix.lastIndexOfChar (T('('));
  5154. const int closeBracks = prefix.lastIndexOfChar (T(')'));
  5155. if (openBracks > 0
  5156. && closeBracks > openBracks
  5157. && prefix.substring (openBracks + 1, closeBracks).containsOnly (T("0123456789")))
  5158. {
  5159. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5160. prefix = prefix.substring (0, openBracks);
  5161. }
  5162. }
  5163. // also use brackets if it ends in a digit.
  5164. putNumbersInBrackets = putNumbersInBrackets
  5165. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5166. do
  5167. {
  5168. if (putNumbersInBrackets)
  5169. f = getChildFile (prefix + T('(') + String (num++) + T(')') + suffix);
  5170. else
  5171. f = getChildFile (prefix + String (num++) + suffix);
  5172. } while (f.exists());
  5173. }
  5174. return f;
  5175. }
  5176. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5177. {
  5178. if (exists())
  5179. {
  5180. return getParentDirectory()
  5181. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5182. getFileExtension(),
  5183. putNumbersInBrackets);
  5184. }
  5185. else
  5186. {
  5187. return *this;
  5188. }
  5189. }
  5190. const String File::getFileExtension() const
  5191. {
  5192. String ext;
  5193. if (! isDirectory())
  5194. {
  5195. const int indexOfDot = fullPath.lastIndexOfChar (T('.'));
  5196. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5197. ext = fullPath.substring (indexOfDot);
  5198. }
  5199. return ext;
  5200. }
  5201. bool File::hasFileExtension (const String& possibleSuffix) const
  5202. {
  5203. if (possibleSuffix.isEmpty())
  5204. return fullPath.lastIndexOfChar (T('.')) <= fullPath.lastIndexOfChar (separator);
  5205. const int semicolon = possibleSuffix.indexOfChar (0, T(';'));
  5206. if (semicolon >= 0)
  5207. {
  5208. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5209. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5210. }
  5211. else
  5212. {
  5213. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5214. {
  5215. if (possibleSuffix.startsWithChar (T('.')))
  5216. return true;
  5217. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5218. if (dotPos >= 0)
  5219. return fullPath [dotPos] == T('.');
  5220. }
  5221. }
  5222. return false;
  5223. }
  5224. const File File::withFileExtension (const String& newExtension) const
  5225. {
  5226. if (fullPath.isEmpty())
  5227. return File::nonexistent;
  5228. String filePart (getFileName());
  5229. int i = filePart.lastIndexOfChar (T('.'));
  5230. if (i >= 0)
  5231. filePart = filePart.substring (0, i);
  5232. if (newExtension.isNotEmpty() && ! newExtension.startsWithChar (T('.')))
  5233. filePart << '.';
  5234. return getSiblingFile (filePart + newExtension);
  5235. }
  5236. bool File::startAsProcess (const String& parameters) const
  5237. {
  5238. return exists() && juce_launchFile (fullPath, parameters);
  5239. }
  5240. FileInputStream* File::createInputStream() const
  5241. {
  5242. if (existsAsFile())
  5243. return new FileInputStream (*this);
  5244. return 0;
  5245. }
  5246. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5247. {
  5248. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5249. if (out->failedToOpen())
  5250. return 0;
  5251. return out.release();
  5252. }
  5253. bool File::appendData (const void* const dataToAppend,
  5254. const int numberOfBytes) const
  5255. {
  5256. if (numberOfBytes > 0)
  5257. {
  5258. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5259. if (out == 0)
  5260. return false;
  5261. out->write (dataToAppend, numberOfBytes);
  5262. }
  5263. return true;
  5264. }
  5265. bool File::replaceWithData (const void* const dataToWrite,
  5266. const int numberOfBytes) const
  5267. {
  5268. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5269. if (numberOfBytes <= 0)
  5270. return deleteFile();
  5271. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5272. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5273. return tempFile.overwriteTargetFileWithTemporary();
  5274. }
  5275. bool File::appendText (const String& text,
  5276. const bool asUnicode,
  5277. const bool writeUnicodeHeaderBytes) const
  5278. {
  5279. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5280. if (out != 0)
  5281. {
  5282. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5283. return true;
  5284. }
  5285. return false;
  5286. }
  5287. bool File::replaceWithText (const String& textToWrite,
  5288. const bool asUnicode,
  5289. const bool writeUnicodeHeaderBytes) const
  5290. {
  5291. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5292. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5293. return tempFile.overwriteTargetFileWithTemporary();
  5294. }
  5295. const String File::createLegalPathName (const String& original)
  5296. {
  5297. String s (original);
  5298. String start;
  5299. if (s[1] == T(':'))
  5300. {
  5301. start = s.substring (0, 2);
  5302. s = s.substring (2);
  5303. }
  5304. return start + s.removeCharacters (T("\"#@,;:<>*^|?"))
  5305. .substring (0, 1024);
  5306. }
  5307. const String File::createLegalFileName (const String& original)
  5308. {
  5309. String s (original.removeCharacters (T("\"#@,;:<>*^|?\\/")));
  5310. const int maxLength = 128; // only the length of the filename, not the whole path
  5311. const int len = s.length();
  5312. if (len > maxLength)
  5313. {
  5314. const int lastDot = s.lastIndexOfChar (T('.'));
  5315. if (lastDot > jmax (0, len - 12))
  5316. {
  5317. s = s.substring (0, maxLength - (len - lastDot))
  5318. + s.substring (lastDot);
  5319. }
  5320. else
  5321. {
  5322. s = s.substring (0, maxLength);
  5323. }
  5324. }
  5325. return s;
  5326. }
  5327. const String File::getRelativePathFrom (const File& dir) const
  5328. {
  5329. String thisPath (fullPath);
  5330. {
  5331. int len = thisPath.length();
  5332. while (--len >= 0 && thisPath [len] == File::separator)
  5333. thisPath [len] = 0;
  5334. }
  5335. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5336. : dir.fullPath));
  5337. const int len = jmin (thisPath.length(), dirPath.length());
  5338. int commonBitLength = 0;
  5339. for (int i = 0; i < len; ++i)
  5340. {
  5341. #if NAMES_ARE_CASE_SENSITIVE
  5342. if (thisPath[i] != dirPath[i])
  5343. #else
  5344. if (CharacterFunctions::toLowerCase (thisPath[i])
  5345. != CharacterFunctions::toLowerCase (dirPath[i]))
  5346. #endif
  5347. {
  5348. break;
  5349. }
  5350. ++commonBitLength;
  5351. }
  5352. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5353. --commonBitLength;
  5354. // if the only common bit is the root, then just return the full path..
  5355. if (commonBitLength <= 0
  5356. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5357. return fullPath;
  5358. thisPath = thisPath.substring (commonBitLength);
  5359. dirPath = dirPath.substring (commonBitLength);
  5360. while (dirPath.isNotEmpty())
  5361. {
  5362. #if JUCE_WINDOWS
  5363. thisPath = T("..\\") + thisPath;
  5364. #else
  5365. thisPath = T("../") + thisPath;
  5366. #endif
  5367. const int sep = dirPath.indexOfChar (separator);
  5368. if (sep >= 0)
  5369. dirPath = dirPath.substring (sep + 1);
  5370. else
  5371. dirPath = String::empty;
  5372. }
  5373. return thisPath;
  5374. }
  5375. void File::findFileSystemRoots (Array<File>& destArray)
  5376. {
  5377. const StringArray roots (juce_getFileSystemRoots());
  5378. for (int i = 0; i < roots.size(); ++i)
  5379. destArray.add (File (roots[i]));
  5380. }
  5381. const String File::getVolumeLabel() const
  5382. {
  5383. int serialNum;
  5384. return juce_getVolumeLabel (fullPath, serialNum);
  5385. }
  5386. int File::getVolumeSerialNumber() const
  5387. {
  5388. int serialNum;
  5389. juce_getVolumeLabel (fullPath, serialNum);
  5390. return serialNum;
  5391. }
  5392. const File File::createTempFile (const String& fileNameEnding)
  5393. {
  5394. const File tempFile (getSpecialLocation (tempDirectory)
  5395. .getChildFile (T("temp_") + String (Random::getSystemRandom().nextInt()))
  5396. .withFileExtension (fileNameEnding));
  5397. if (tempFile.exists())
  5398. return createTempFile (fileNameEnding);
  5399. else
  5400. return tempFile;
  5401. }
  5402. END_JUCE_NAMESPACE
  5403. /*** End of inlined file: juce_File.cpp ***/
  5404. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5405. BEGIN_JUCE_NAMESPACE
  5406. void* juce_fileOpen (const String& path, bool forWriting);
  5407. void juce_fileClose (void* handle);
  5408. int juce_fileRead (void* handle, void* buffer, int size);
  5409. int64 juce_fileSetPosition (void* handle, int64 pos);
  5410. FileInputStream::FileInputStream (const File& f)
  5411. : file (f),
  5412. currentPosition (0),
  5413. needToSeek (true)
  5414. {
  5415. totalSize = f.getSize();
  5416. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5417. }
  5418. FileInputStream::~FileInputStream()
  5419. {
  5420. juce_fileClose (fileHandle);
  5421. }
  5422. int64 FileInputStream::getTotalLength()
  5423. {
  5424. return totalSize;
  5425. }
  5426. int FileInputStream::read (void* buffer, int bytesToRead)
  5427. {
  5428. int num = 0;
  5429. if (needToSeek)
  5430. {
  5431. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5432. return 0;
  5433. needToSeek = false;
  5434. }
  5435. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5436. currentPosition += num;
  5437. return num;
  5438. }
  5439. bool FileInputStream::isExhausted()
  5440. {
  5441. return currentPosition >= totalSize;
  5442. }
  5443. int64 FileInputStream::getPosition()
  5444. {
  5445. return currentPosition;
  5446. }
  5447. bool FileInputStream::setPosition (int64 pos)
  5448. {
  5449. pos = jlimit ((int64) 0, totalSize, pos);
  5450. needToSeek |= (currentPosition != pos);
  5451. currentPosition = pos;
  5452. return true;
  5453. }
  5454. END_JUCE_NAMESPACE
  5455. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5456. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5457. BEGIN_JUCE_NAMESPACE
  5458. void* juce_fileOpen (const String& path, bool forWriting);
  5459. void juce_fileClose (void* handle);
  5460. int juce_fileWrite (void* handle, const void* buffer, int size);
  5461. void juce_fileFlush (void* handle);
  5462. int64 juce_fileGetPosition (void* handle);
  5463. int64 juce_fileSetPosition (void* handle, int64 pos);
  5464. FileOutputStream::FileOutputStream (const File& f,
  5465. const int bufferSize_)
  5466. : file (f),
  5467. bufferSize (bufferSize_),
  5468. bytesInBuffer (0)
  5469. {
  5470. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5471. if (fileHandle != 0)
  5472. {
  5473. currentPosition = juce_fileGetPosition (fileHandle);
  5474. if (currentPosition < 0)
  5475. {
  5476. jassertfalse
  5477. juce_fileClose (fileHandle);
  5478. fileHandle = 0;
  5479. }
  5480. }
  5481. buffer.malloc (jmax (bufferSize_, 16));
  5482. }
  5483. FileOutputStream::~FileOutputStream()
  5484. {
  5485. flush();
  5486. juce_fileClose (fileHandle);
  5487. }
  5488. int64 FileOutputStream::getPosition()
  5489. {
  5490. return currentPosition;
  5491. }
  5492. bool FileOutputStream::setPosition (int64 newPosition)
  5493. {
  5494. if (newPosition != currentPosition)
  5495. {
  5496. flush();
  5497. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5498. }
  5499. return newPosition == currentPosition;
  5500. }
  5501. void FileOutputStream::flush()
  5502. {
  5503. if (bytesInBuffer > 0)
  5504. {
  5505. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5506. bytesInBuffer = 0;
  5507. }
  5508. juce_fileFlush (fileHandle);
  5509. }
  5510. bool FileOutputStream::write (const void* const src, const int numBytes)
  5511. {
  5512. if (bytesInBuffer + numBytes < bufferSize)
  5513. {
  5514. memcpy (buffer + bytesInBuffer, src, numBytes);
  5515. bytesInBuffer += numBytes;
  5516. currentPosition += numBytes;
  5517. }
  5518. else
  5519. {
  5520. if (bytesInBuffer > 0)
  5521. {
  5522. // flush the reservoir
  5523. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5524. bytesInBuffer = 0;
  5525. if (! wroteOk)
  5526. return false;
  5527. }
  5528. if (numBytes < bufferSize)
  5529. {
  5530. memcpy (buffer + bytesInBuffer, src, numBytes);
  5531. bytesInBuffer += numBytes;
  5532. currentPosition += numBytes;
  5533. }
  5534. else
  5535. {
  5536. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5537. currentPosition += bytesWritten;
  5538. return bytesWritten == numBytes;
  5539. }
  5540. }
  5541. return true;
  5542. }
  5543. END_JUCE_NAMESPACE
  5544. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5545. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5546. BEGIN_JUCE_NAMESPACE
  5547. FileSearchPath::FileSearchPath()
  5548. {
  5549. }
  5550. FileSearchPath::FileSearchPath (const String& path)
  5551. {
  5552. init (path);
  5553. }
  5554. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5555. : directories (other.directories)
  5556. {
  5557. }
  5558. FileSearchPath::~FileSearchPath()
  5559. {
  5560. }
  5561. FileSearchPath& FileSearchPath::operator= (const String& path)
  5562. {
  5563. init (path);
  5564. return *this;
  5565. }
  5566. void FileSearchPath::init (const String& path)
  5567. {
  5568. directories.clear();
  5569. directories.addTokens (path, T(";"), T("\""));
  5570. directories.trim();
  5571. directories.removeEmptyStrings();
  5572. for (int i = directories.size(); --i >= 0;)
  5573. directories.set (i, directories[i].unquoted());
  5574. }
  5575. int FileSearchPath::getNumPaths() const
  5576. {
  5577. return directories.size();
  5578. }
  5579. const File FileSearchPath::operator[] (const int index) const
  5580. {
  5581. return File (directories [index]);
  5582. }
  5583. const String FileSearchPath::toString() const
  5584. {
  5585. StringArray directories2 (directories);
  5586. for (int i = directories2.size(); --i >= 0;)
  5587. if (directories2[i].containsChar (T(';')))
  5588. directories2.set (i, directories2[i].quoted());
  5589. return directories2.joinIntoString (T(";"));
  5590. }
  5591. void FileSearchPath::add (const File& dir, const int insertIndex)
  5592. {
  5593. directories.insert (insertIndex, dir.getFullPathName());
  5594. }
  5595. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5596. {
  5597. for (int i = 0; i < directories.size(); ++i)
  5598. if (File (directories[i]) == dir)
  5599. return;
  5600. add (dir);
  5601. }
  5602. void FileSearchPath::remove (const int index)
  5603. {
  5604. directories.remove (index);
  5605. }
  5606. void FileSearchPath::addPath (const FileSearchPath& other)
  5607. {
  5608. for (int i = 0; i < other.getNumPaths(); ++i)
  5609. addIfNotAlreadyThere (other[i]);
  5610. }
  5611. void FileSearchPath::removeRedundantPaths()
  5612. {
  5613. for (int i = directories.size(); --i >= 0;)
  5614. {
  5615. const File d1 (directories[i]);
  5616. for (int j = directories.size(); --j >= 0;)
  5617. {
  5618. const File d2 (directories[j]);
  5619. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5620. {
  5621. directories.remove (i);
  5622. break;
  5623. }
  5624. }
  5625. }
  5626. }
  5627. void FileSearchPath::removeNonExistentPaths()
  5628. {
  5629. for (int i = directories.size(); --i >= 0;)
  5630. if (! File (directories[i]).isDirectory())
  5631. directories.remove (i);
  5632. }
  5633. int FileSearchPath::findChildFiles (Array<File>& results,
  5634. const int whatToLookFor,
  5635. const bool searchRecursively,
  5636. const String& wildCardPattern) const
  5637. {
  5638. int total = 0;
  5639. for (int i = 0; i < directories.size(); ++i)
  5640. total += operator[] (i).findChildFiles (results,
  5641. whatToLookFor,
  5642. searchRecursively,
  5643. wildCardPattern);
  5644. return total;
  5645. }
  5646. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5647. const bool checkRecursively) const
  5648. {
  5649. for (int i = directories.size(); --i >= 0;)
  5650. {
  5651. const File d (directories[i]);
  5652. if (checkRecursively)
  5653. {
  5654. if (fileToCheck.isAChildOf (d))
  5655. return true;
  5656. }
  5657. else
  5658. {
  5659. if (fileToCheck.getParentDirectory() == d)
  5660. return true;
  5661. }
  5662. }
  5663. return false;
  5664. }
  5665. END_JUCE_NAMESPACE
  5666. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5667. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5668. BEGIN_JUCE_NAMESPACE
  5669. NamedPipe::NamedPipe()
  5670. : internal (0)
  5671. {
  5672. }
  5673. NamedPipe::~NamedPipe()
  5674. {
  5675. close();
  5676. }
  5677. bool NamedPipe::openExisting (const String& pipeName)
  5678. {
  5679. currentPipeName = pipeName;
  5680. return openInternal (pipeName, false);
  5681. }
  5682. bool NamedPipe::createNewPipe (const String& pipeName)
  5683. {
  5684. currentPipeName = pipeName;
  5685. return openInternal (pipeName, true);
  5686. }
  5687. bool NamedPipe::isOpen() const
  5688. {
  5689. return internal != 0;
  5690. }
  5691. const String NamedPipe::getName() const
  5692. {
  5693. return currentPipeName;
  5694. }
  5695. // other methods for this class are implemented in the platform-specific files
  5696. END_JUCE_NAMESPACE
  5697. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5698. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5699. BEGIN_JUCE_NAMESPACE
  5700. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5701. {
  5702. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5703. T("temp_") + String (Random::getSystemRandom().nextInt()),
  5704. suffix,
  5705. optionFlags);
  5706. }
  5707. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5708. : targetFile (targetFile_)
  5709. {
  5710. // If you use this constructor, you need to give it a valid target file!
  5711. jassert (targetFile != File::nonexistent);
  5712. createTempFile (targetFile.getParentDirectory(),
  5713. targetFile.getFileNameWithoutExtension() + T("_temp") + String (Random::getSystemRandom().nextInt()),
  5714. targetFile.getFileExtension(),
  5715. optionFlags);
  5716. }
  5717. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5718. const String& suffix, const int optionFlags)
  5719. {
  5720. if ((optionFlags & useHiddenFile) != 0)
  5721. name = T(".") + name;
  5722. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5723. }
  5724. TemporaryFile::~TemporaryFile()
  5725. {
  5726. // Have a few attempts at deleting the file before giving up..
  5727. for (int i = 5; --i >= 0;)
  5728. {
  5729. if (temporaryFile.deleteFile())
  5730. return;
  5731. Thread::sleep (50);
  5732. }
  5733. // Failed to delete our temporary file! Check that you've deleted all the
  5734. // file output streams that were using it!
  5735. jassertfalse;
  5736. }
  5737. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5738. {
  5739. // This method only works if you created this object with the constructor
  5740. // that takes a target file!
  5741. jassert (targetFile != File::nonexistent);
  5742. if (temporaryFile.exists())
  5743. {
  5744. // Have a few attempts at overwriting the file before giving up..
  5745. for (int i = 5; --i >= 0;)
  5746. {
  5747. if (temporaryFile.moveFileTo (targetFile))
  5748. return true;
  5749. Thread::sleep (100);
  5750. }
  5751. }
  5752. else
  5753. {
  5754. // There's no temporary file to use. If your write failed, you should
  5755. // probably check, and not bother calling this method.
  5756. jassertfalse
  5757. }
  5758. return false;
  5759. }
  5760. END_JUCE_NAMESPACE
  5761. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5762. /*** Start of inlined file: juce_Socket.cpp ***/
  5763. #if JUCE_WINDOWS
  5764. #include <winsock2.h>
  5765. #ifdef _MSC_VER
  5766. #pragma warning (disable : 4127 4389 4018)
  5767. #endif
  5768. #else
  5769. #if JUCE_LINUX
  5770. #include <sys/types.h>
  5771. #include <sys/socket.h>
  5772. #include <sys/errno.h>
  5773. #include <unistd.h>
  5774. #include <netinet/in.h>
  5775. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5776. #include <CoreServices/CoreServices.h>
  5777. #endif
  5778. #include <fcntl.h>
  5779. #include <netdb.h>
  5780. #include <arpa/inet.h>
  5781. #include <netinet/tcp.h>
  5782. #endif
  5783. BEGIN_JUCE_NAMESPACE
  5784. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5785. typedef socklen_t juce_socklen_t;
  5786. #else
  5787. typedef int juce_socklen_t;
  5788. #endif
  5789. #if JUCE_WINDOWS
  5790. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5791. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5792. static void initWin32Sockets()
  5793. {
  5794. static CriticalSection lock;
  5795. const ScopedLock sl (lock);
  5796. if (juce_CloseWin32SocketLib == 0)
  5797. {
  5798. WSADATA wsaData;
  5799. const WORD wVersionRequested = MAKEWORD (1, 1);
  5800. WSAStartup (wVersionRequested, &wsaData);
  5801. juce_CloseWin32SocketLib = &WSACleanup;
  5802. }
  5803. }
  5804. #endif
  5805. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5806. {
  5807. const int sndBufSize = 65536;
  5808. const int rcvBufSize = 65536;
  5809. const int one = 1;
  5810. return handle > 0
  5811. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  5812. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  5813. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  5814. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  5815. }
  5816. static bool bindSocketToPort (const int handle, const int port) throw()
  5817. {
  5818. if (handle <= 0 || port <= 0)
  5819. return false;
  5820. struct sockaddr_in servTmpAddr;
  5821. zerostruct (servTmpAddr);
  5822. servTmpAddr.sin_family = PF_INET;
  5823. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  5824. servTmpAddr.sin_port = htons ((uint16) port);
  5825. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  5826. }
  5827. static int readSocket (const int handle,
  5828. void* const destBuffer, const int maxBytesToRead,
  5829. bool volatile& connected,
  5830. const bool blockUntilSpecifiedAmountHasArrived) throw()
  5831. {
  5832. int bytesRead = 0;
  5833. while (bytesRead < maxBytesToRead)
  5834. {
  5835. int bytesThisTime;
  5836. #if JUCE_WINDOWS
  5837. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  5838. #else
  5839. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  5840. && errno == EINTR
  5841. && connected)
  5842. {
  5843. }
  5844. #endif
  5845. if (bytesThisTime <= 0 || ! connected)
  5846. {
  5847. if (bytesRead == 0)
  5848. bytesRead = -1;
  5849. break;
  5850. }
  5851. bytesRead += bytesThisTime;
  5852. if (! blockUntilSpecifiedAmountHasArrived)
  5853. break;
  5854. }
  5855. return bytesRead;
  5856. }
  5857. static int waitForReadiness (const int handle, const bool forReading,
  5858. const int timeoutMsecs) throw()
  5859. {
  5860. struct timeval timeout;
  5861. struct timeval* timeoutp;
  5862. if (timeoutMsecs >= 0)
  5863. {
  5864. timeout.tv_sec = timeoutMsecs / 1000;
  5865. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  5866. timeoutp = &timeout;
  5867. }
  5868. else
  5869. {
  5870. timeoutp = 0;
  5871. }
  5872. fd_set rset, wset;
  5873. FD_ZERO (&rset);
  5874. FD_SET (handle, &rset);
  5875. FD_ZERO (&wset);
  5876. FD_SET (handle, &wset);
  5877. fd_set* const prset = forReading ? &rset : 0;
  5878. fd_set* const pwset = forReading ? 0 : &wset;
  5879. #if JUCE_WINDOWS
  5880. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  5881. return -1;
  5882. #else
  5883. {
  5884. int result;
  5885. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  5886. && errno == EINTR)
  5887. {
  5888. }
  5889. if (result < 0)
  5890. return -1;
  5891. }
  5892. #endif
  5893. {
  5894. int opt;
  5895. juce_socklen_t len = sizeof (opt);
  5896. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  5897. || opt != 0)
  5898. return -1;
  5899. }
  5900. if ((forReading && FD_ISSET (handle, &rset))
  5901. || ((! forReading) && FD_ISSET (handle, &wset)))
  5902. return 1;
  5903. return 0;
  5904. }
  5905. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  5906. {
  5907. #if JUCE_WINDOWS
  5908. u_long nonBlocking = shouldBlock ? 0 : 1;
  5909. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  5910. return false;
  5911. #else
  5912. int socketFlags = fcntl (handle, F_GETFL, 0);
  5913. if (socketFlags == -1)
  5914. return false;
  5915. if (shouldBlock)
  5916. socketFlags &= ~O_NONBLOCK;
  5917. else
  5918. socketFlags |= O_NONBLOCK;
  5919. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  5920. return false;
  5921. #endif
  5922. return true;
  5923. }
  5924. static bool connectSocket (int volatile& handle,
  5925. const bool isDatagram,
  5926. void** serverAddress,
  5927. const String& hostName,
  5928. const int portNumber,
  5929. const int timeOutMillisecs) throw()
  5930. {
  5931. struct hostent* const hostEnt = gethostbyname (hostName.toUTF8());
  5932. if (hostEnt == 0)
  5933. return false;
  5934. struct in_addr targetAddress;
  5935. memcpy (&targetAddress.s_addr,
  5936. *(hostEnt->h_addr_list),
  5937. sizeof (targetAddress.s_addr));
  5938. struct sockaddr_in servTmpAddr;
  5939. zerostruct (servTmpAddr);
  5940. servTmpAddr.sin_family = PF_INET;
  5941. servTmpAddr.sin_addr = targetAddress;
  5942. servTmpAddr.sin_port = htons ((uint16) portNumber);
  5943. if (handle < 0)
  5944. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  5945. if (handle < 0)
  5946. return false;
  5947. if (isDatagram)
  5948. {
  5949. *serverAddress = new struct sockaddr_in();
  5950. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  5951. return true;
  5952. }
  5953. setSocketBlockingState (handle, false);
  5954. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  5955. if (result < 0)
  5956. {
  5957. #if JUCE_WINDOWS
  5958. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  5959. #else
  5960. if (errno == EINPROGRESS)
  5961. #endif
  5962. {
  5963. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  5964. {
  5965. setSocketBlockingState (handle, true);
  5966. return false;
  5967. }
  5968. }
  5969. }
  5970. setSocketBlockingState (handle, true);
  5971. resetSocketOptions (handle, false, false);
  5972. return true;
  5973. }
  5974. StreamingSocket::StreamingSocket()
  5975. : portNumber (0),
  5976. handle (-1),
  5977. connected (false),
  5978. isListener (false)
  5979. {
  5980. #if JUCE_WINDOWS
  5981. initWin32Sockets();
  5982. #endif
  5983. }
  5984. StreamingSocket::StreamingSocket (const String& hostName_,
  5985. const int portNumber_,
  5986. const int handle_)
  5987. : hostName (hostName_),
  5988. portNumber (portNumber_),
  5989. handle (handle_),
  5990. connected (true),
  5991. isListener (false)
  5992. {
  5993. #if JUCE_WINDOWS
  5994. initWin32Sockets();
  5995. #endif
  5996. resetSocketOptions (handle_, false, false);
  5997. }
  5998. StreamingSocket::~StreamingSocket()
  5999. {
  6000. close();
  6001. }
  6002. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6003. {
  6004. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6005. : -1;
  6006. }
  6007. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6008. {
  6009. if (isListener || ! connected)
  6010. return -1;
  6011. #if JUCE_WINDOWS
  6012. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  6013. #else
  6014. int result;
  6015. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  6016. && errno == EINTR)
  6017. {
  6018. }
  6019. return result;
  6020. #endif
  6021. }
  6022. int StreamingSocket::waitUntilReady (const bool readyForReading,
  6023. const int timeoutMsecs) const
  6024. {
  6025. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6026. : -1;
  6027. }
  6028. bool StreamingSocket::bindToPort (const int port)
  6029. {
  6030. return bindSocketToPort (handle, port);
  6031. }
  6032. bool StreamingSocket::connect (const String& remoteHostName,
  6033. const int remotePortNumber,
  6034. const int timeOutMillisecs)
  6035. {
  6036. if (isListener)
  6037. {
  6038. jassertfalse // a listener socket can't connect to another one!
  6039. return false;
  6040. }
  6041. if (connected)
  6042. close();
  6043. hostName = remoteHostName;
  6044. portNumber = remotePortNumber;
  6045. isListener = false;
  6046. connected = connectSocket (handle, false, 0, remoteHostName,
  6047. remotePortNumber, timeOutMillisecs);
  6048. if (! (connected && resetSocketOptions (handle, false, false)))
  6049. {
  6050. close();
  6051. return false;
  6052. }
  6053. return true;
  6054. }
  6055. void StreamingSocket::close()
  6056. {
  6057. #if JUCE_WINDOWS
  6058. closesocket (handle);
  6059. connected = false;
  6060. #else
  6061. if (connected)
  6062. {
  6063. connected = false;
  6064. if (isListener)
  6065. {
  6066. // need to do this to interrupt the accept() function..
  6067. StreamingSocket temp;
  6068. temp.connect ("localhost", portNumber, 1000);
  6069. }
  6070. }
  6071. ::close (handle);
  6072. #endif
  6073. hostName = String::empty;
  6074. portNumber = 0;
  6075. handle = -1;
  6076. isListener = false;
  6077. }
  6078. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6079. {
  6080. if (connected)
  6081. close();
  6082. hostName = "listener";
  6083. portNumber = newPortNumber;
  6084. isListener = true;
  6085. struct sockaddr_in servTmpAddr;
  6086. zerostruct (servTmpAddr);
  6087. servTmpAddr.sin_family = PF_INET;
  6088. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6089. if (localHostName.isNotEmpty())
  6090. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6091. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6092. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6093. if (handle < 0)
  6094. return false;
  6095. const int reuse = 1;
  6096. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6097. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6098. || listen (handle, SOMAXCONN) < 0)
  6099. {
  6100. close();
  6101. return false;
  6102. }
  6103. connected = true;
  6104. return true;
  6105. }
  6106. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6107. {
  6108. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6109. // prepare this socket as a listener.
  6110. if (connected && isListener)
  6111. {
  6112. struct sockaddr address;
  6113. juce_socklen_t len = sizeof (sockaddr);
  6114. const int newSocket = (int) accept (handle, &address, &len);
  6115. if (newSocket >= 0 && connected)
  6116. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6117. portNumber, newSocket);
  6118. }
  6119. return 0;
  6120. }
  6121. bool StreamingSocket::isLocal() const throw()
  6122. {
  6123. return hostName == T("127.0.0.1");
  6124. }
  6125. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6126. : portNumber (0),
  6127. handle (-1),
  6128. connected (true),
  6129. allowBroadcast (allowBroadcast_),
  6130. serverAddress (0)
  6131. {
  6132. #if JUCE_WINDOWS
  6133. initWin32Sockets();
  6134. #endif
  6135. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6136. bindToPort (localPortNumber);
  6137. }
  6138. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6139. const int handle_, const int localPortNumber)
  6140. : hostName (hostName_),
  6141. portNumber (portNumber_),
  6142. handle (handle_),
  6143. connected (true),
  6144. allowBroadcast (false),
  6145. serverAddress (0)
  6146. {
  6147. #if JUCE_WINDOWS
  6148. initWin32Sockets();
  6149. #endif
  6150. resetSocketOptions (handle_, true, allowBroadcast);
  6151. bindToPort (localPortNumber);
  6152. }
  6153. DatagramSocket::~DatagramSocket()
  6154. {
  6155. close();
  6156. delete ((struct sockaddr_in*) serverAddress);
  6157. serverAddress = 0;
  6158. }
  6159. void DatagramSocket::close()
  6160. {
  6161. #if JUCE_WINDOWS
  6162. closesocket (handle);
  6163. connected = false;
  6164. #else
  6165. connected = false;
  6166. ::close (handle);
  6167. #endif
  6168. hostName = String::empty;
  6169. portNumber = 0;
  6170. handle = -1;
  6171. }
  6172. bool DatagramSocket::bindToPort (const int port)
  6173. {
  6174. return bindSocketToPort (handle, port);
  6175. }
  6176. bool DatagramSocket::connect (const String& remoteHostName,
  6177. const int remotePortNumber,
  6178. const int timeOutMillisecs)
  6179. {
  6180. if (connected)
  6181. close();
  6182. hostName = remoteHostName;
  6183. portNumber = remotePortNumber;
  6184. connected = connectSocket (handle, true, &serverAddress,
  6185. remoteHostName, remotePortNumber,
  6186. timeOutMillisecs);
  6187. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6188. {
  6189. close();
  6190. return false;
  6191. }
  6192. return true;
  6193. }
  6194. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6195. {
  6196. struct sockaddr address;
  6197. juce_socklen_t len = sizeof (sockaddr);
  6198. while (waitUntilReady (true, -1) == 1)
  6199. {
  6200. char buf[1];
  6201. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6202. {
  6203. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6204. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6205. -1, -1);
  6206. }
  6207. }
  6208. return 0;
  6209. }
  6210. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6211. const int timeoutMsecs) const
  6212. {
  6213. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6214. : -1;
  6215. }
  6216. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6217. {
  6218. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6219. : -1;
  6220. }
  6221. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6222. {
  6223. // You need to call connect() first to set the server address..
  6224. jassert (serverAddress != 0 && connected);
  6225. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6226. numBytesToWrite, 0,
  6227. (const struct sockaddr*) serverAddress,
  6228. sizeof (struct sockaddr_in))
  6229. : -1;
  6230. }
  6231. bool DatagramSocket::isLocal() const throw()
  6232. {
  6233. return hostName == T("127.0.0.1");
  6234. }
  6235. END_JUCE_NAMESPACE
  6236. /*** End of inlined file: juce_Socket.cpp ***/
  6237. /*** Start of inlined file: juce_URL.cpp ***/
  6238. BEGIN_JUCE_NAMESPACE
  6239. URL::URL()
  6240. {
  6241. }
  6242. URL::URL (const String& url_)
  6243. : url (url_)
  6244. {
  6245. int i = url.indexOfChar (T('?'));
  6246. if (i >= 0)
  6247. {
  6248. do
  6249. {
  6250. const int nextAmp = url.indexOfChar (i + 1, T('&'));
  6251. const int equalsPos = url.indexOfChar (i + 1, T('='));
  6252. if (equalsPos > i + 1)
  6253. {
  6254. if (nextAmp < 0)
  6255. {
  6256. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6257. removeEscapeChars (url.substring (equalsPos + 1)));
  6258. }
  6259. else if (nextAmp > 0 && equalsPos < nextAmp)
  6260. {
  6261. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6262. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6263. }
  6264. }
  6265. i = nextAmp;
  6266. }
  6267. while (i >= 0);
  6268. url = url.upToFirstOccurrenceOf (T("?"), false, false);
  6269. }
  6270. }
  6271. URL::URL (const URL& other)
  6272. : url (other.url),
  6273. postData (other.postData),
  6274. parameters (other.parameters),
  6275. filesToUpload (other.filesToUpload),
  6276. mimeTypes (other.mimeTypes)
  6277. {
  6278. }
  6279. URL& URL::operator= (const URL& other)
  6280. {
  6281. url = other.url;
  6282. postData = other.postData;
  6283. parameters = other.parameters;
  6284. filesToUpload = other.filesToUpload;
  6285. mimeTypes = other.mimeTypes;
  6286. return *this;
  6287. }
  6288. URL::~URL()
  6289. {
  6290. }
  6291. static const String getMangledParameters (const StringPairArray& parameters)
  6292. {
  6293. String p;
  6294. for (int i = 0; i < parameters.size(); ++i)
  6295. {
  6296. if (i > 0)
  6297. p += T("&");
  6298. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6299. << T("=")
  6300. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6301. }
  6302. return p;
  6303. }
  6304. const String URL::toString (const bool includeGetParameters) const
  6305. {
  6306. if (includeGetParameters && parameters.size() > 0)
  6307. return url + T("?") + getMangledParameters (parameters);
  6308. else
  6309. return url;
  6310. }
  6311. bool URL::isWellFormed() const
  6312. {
  6313. //xxx TODO
  6314. return url.isNotEmpty();
  6315. }
  6316. static int findStartOfDomain (const String& url)
  6317. {
  6318. int i = 0;
  6319. while (CharacterFunctions::isLetterOrDigit (url[i])
  6320. || CharacterFunctions::indexOfChar (T("+-."), url[i], false) >= 0)
  6321. ++i;
  6322. return url[i] == T(':') ? i + 1 : 0;
  6323. }
  6324. const String URL::getDomain() const
  6325. {
  6326. int start = findStartOfDomain (url);
  6327. while (url[start] == T('/'))
  6328. ++start;
  6329. const int end1 = url.indexOfChar (start, T('/'));
  6330. const int end2 = url.indexOfChar (start, T(':'));
  6331. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6332. : jmin (end1, end2);
  6333. return url.substring (start, end);
  6334. }
  6335. const String URL::getSubPath() const
  6336. {
  6337. int start = findStartOfDomain (url);
  6338. while (url[start] == T('/'))
  6339. ++start;
  6340. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6341. return startOfPath <= 0 ? String::empty
  6342. : url.substring (startOfPath);
  6343. }
  6344. const String URL::getScheme() const
  6345. {
  6346. return url.substring (0, findStartOfDomain (url) - 1);
  6347. }
  6348. const URL URL::withNewSubPath (const String& newPath) const
  6349. {
  6350. int start = findStartOfDomain (url);
  6351. while (url[start] == T('/'))
  6352. ++start;
  6353. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6354. URL u (*this);
  6355. if (startOfPath > 0)
  6356. u.url = url.substring (0, startOfPath);
  6357. if (! u.url.endsWithChar (T('/')))
  6358. u.url << '/';
  6359. if (newPath.startsWithChar (T('/')))
  6360. u.url << newPath.substring (1);
  6361. else
  6362. u.url << newPath;
  6363. return u;
  6364. }
  6365. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6366. {
  6367. if (possibleURL.startsWithIgnoreCase (T("http:"))
  6368. || possibleURL.startsWithIgnoreCase (T("ftp:")))
  6369. return true;
  6370. if (possibleURL.startsWithIgnoreCase (T("file:"))
  6371. || possibleURL.containsChar (T('@'))
  6372. || possibleURL.endsWithChar (T('.'))
  6373. || (! possibleURL.containsChar (T('.'))))
  6374. return false;
  6375. if (possibleURL.startsWithIgnoreCase (T("www."))
  6376. && possibleURL.substring (5).containsChar (T('.')))
  6377. return true;
  6378. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6379. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6380. if ((possibleURL + T("/")).containsIgnoreCase (T(".") + String (commonTLDs[i]) + T("/")))
  6381. return true;
  6382. return false;
  6383. }
  6384. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6385. {
  6386. const int atSign = possibleEmailAddress.indexOfChar (T('@'));
  6387. return atSign > 0
  6388. && possibleEmailAddress.lastIndexOfChar (T('.')) > (atSign + 1)
  6389. && (! possibleEmailAddress.endsWithChar (T('.')));
  6390. }
  6391. void* juce_openInternetFile (const String& url,
  6392. const String& headers,
  6393. const MemoryBlock& optionalPostData,
  6394. const bool isPost,
  6395. URL::OpenStreamProgressCallback* callback,
  6396. void* callbackContext,
  6397. int timeOutMs);
  6398. void juce_closeInternetFile (void* handle);
  6399. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6400. int juce_seekInInternetFile (void* handle, int newPosition);
  6401. int64 juce_getInternetFileContentLength (void* handle);
  6402. class WebInputStream : public InputStream
  6403. {
  6404. public:
  6405. WebInputStream (const URL& url,
  6406. const bool isPost_,
  6407. URL::OpenStreamProgressCallback* const progressCallback_,
  6408. void* const progressCallbackContext_,
  6409. const String& extraHeaders,
  6410. int timeOutMs_)
  6411. : position (0),
  6412. finished (false),
  6413. isPost (isPost_),
  6414. progressCallback (progressCallback_),
  6415. progressCallbackContext (progressCallbackContext_),
  6416. timeOutMs (timeOutMs_)
  6417. {
  6418. server = url.toString (! isPost);
  6419. if (isPost_)
  6420. createHeadersAndPostData (url);
  6421. headers += extraHeaders;
  6422. if (! headers.endsWithChar (T('\n')))
  6423. headers << "\r\n";
  6424. handle = juce_openInternetFile (server, headers, postData, isPost,
  6425. progressCallback_, progressCallbackContext_,
  6426. timeOutMs);
  6427. }
  6428. ~WebInputStream()
  6429. {
  6430. juce_closeInternetFile (handle);
  6431. }
  6432. bool isError() const
  6433. {
  6434. return handle == 0;
  6435. }
  6436. int64 getTotalLength()
  6437. {
  6438. return juce_getInternetFileContentLength (handle);
  6439. }
  6440. bool isExhausted()
  6441. {
  6442. return finished;
  6443. }
  6444. int read (void* dest, int bytes)
  6445. {
  6446. if (finished || isError())
  6447. {
  6448. return 0;
  6449. }
  6450. else
  6451. {
  6452. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6453. position += bytesRead;
  6454. if (bytesRead == 0)
  6455. finished = true;
  6456. return bytesRead;
  6457. }
  6458. }
  6459. int64 getPosition()
  6460. {
  6461. return position;
  6462. }
  6463. bool setPosition (int64 wantedPos)
  6464. {
  6465. if (wantedPos != position)
  6466. {
  6467. finished = false;
  6468. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6469. if (actualPos == wantedPos)
  6470. {
  6471. position = wantedPos;
  6472. }
  6473. else
  6474. {
  6475. if (wantedPos < position)
  6476. {
  6477. juce_closeInternetFile (handle);
  6478. position = 0;
  6479. finished = false;
  6480. handle = juce_openInternetFile (server, headers, postData, isPost,
  6481. progressCallback, progressCallbackContext,
  6482. timeOutMs);
  6483. }
  6484. skipNextBytes (wantedPos - position);
  6485. }
  6486. }
  6487. return true;
  6488. }
  6489. juce_UseDebuggingNewOperator
  6490. private:
  6491. String server, headers;
  6492. MemoryBlock postData;
  6493. int64 position;
  6494. bool finished;
  6495. const bool isPost;
  6496. void* handle;
  6497. URL::OpenStreamProgressCallback* const progressCallback;
  6498. void* const progressCallbackContext;
  6499. const int timeOutMs;
  6500. void createHeadersAndPostData (const URL& url)
  6501. {
  6502. if (url.getFilesToUpload().size() > 0)
  6503. {
  6504. // need to upload some files, so do it as multi-part...
  6505. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6506. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6507. appendUTF8ToPostData ("--" + boundary);
  6508. int i;
  6509. for (i = 0; i < url.getParameters().size(); ++i)
  6510. {
  6511. String s;
  6512. s << "\r\nContent-Disposition: form-data; name=\""
  6513. << url.getParameters().getAllKeys() [i]
  6514. << "\"\r\n\r\n"
  6515. << url.getParameters().getAllValues() [i]
  6516. << "\r\n--"
  6517. << boundary;
  6518. appendUTF8ToPostData (s);
  6519. }
  6520. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6521. {
  6522. const File f (url.getFilesToUpload().getAllValues() [i]);
  6523. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6524. String s;
  6525. s << "\r\nContent-Disposition: form-data; name=\""
  6526. << paramName
  6527. << "\"; filename=\""
  6528. << f.getFileName()
  6529. << "\"\r\n";
  6530. const String mimeType (url.getMimeTypesOfUploadFiles()
  6531. .getValue (paramName, String::empty));
  6532. if (mimeType.isNotEmpty())
  6533. s << "Content-Type: " << mimeType << "\r\n";
  6534. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6535. appendUTF8ToPostData (s);
  6536. f.loadFileAsData (postData);
  6537. s = "\r\n--" + boundary;
  6538. appendUTF8ToPostData (s);
  6539. }
  6540. appendUTF8ToPostData ("--\r\n");
  6541. }
  6542. else
  6543. {
  6544. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6545. appendUTF8ToPostData (url.getPostData());
  6546. // just a short text attachment, so use simple url encoding..
  6547. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6548. + String ((unsigned int) postData.getSize())
  6549. + "\r\n";
  6550. }
  6551. }
  6552. void appendUTF8ToPostData (const String& text)
  6553. {
  6554. postData.append (text.toUTF8(),
  6555. (int) strlen (text.toUTF8()));
  6556. }
  6557. WebInputStream (const WebInputStream&);
  6558. WebInputStream& operator= (const WebInputStream&);
  6559. };
  6560. InputStream* URL::createInputStream (const bool usePostCommand,
  6561. OpenStreamProgressCallback* const progressCallback,
  6562. void* const progressCallbackContext,
  6563. const String& extraHeaders,
  6564. const int timeOutMs) const
  6565. {
  6566. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6567. progressCallback, progressCallbackContext,
  6568. extraHeaders,
  6569. timeOutMs));
  6570. return wi->isError() ? 0 : wi.release();
  6571. }
  6572. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6573. const bool usePostCommand) const
  6574. {
  6575. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6576. if (in != 0)
  6577. {
  6578. in->readIntoMemoryBlock (destData, -1);
  6579. return true;
  6580. }
  6581. return false;
  6582. }
  6583. const String URL::readEntireTextStream (const bool usePostCommand) const
  6584. {
  6585. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6586. if (in != 0)
  6587. return in->readEntireStreamAsString();
  6588. return String::empty;
  6589. }
  6590. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6591. {
  6592. XmlDocument doc (readEntireTextStream (usePostCommand));
  6593. return doc.getDocumentElement();
  6594. }
  6595. const URL URL::withParameter (const String& parameterName,
  6596. const String& parameterValue) const
  6597. {
  6598. URL u (*this);
  6599. u.parameters.set (parameterName, parameterValue);
  6600. return u;
  6601. }
  6602. const URL URL::withFileToUpload (const String& parameterName,
  6603. const File& fileToUpload,
  6604. const String& mimeType) const
  6605. {
  6606. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6607. URL u (*this);
  6608. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6609. u.mimeTypes.set (parameterName, mimeType);
  6610. return u;
  6611. }
  6612. const URL URL::withPOSTData (const String& postData_) const
  6613. {
  6614. URL u (*this);
  6615. u.postData = postData_;
  6616. return u;
  6617. }
  6618. const StringPairArray& URL::getParameters() const
  6619. {
  6620. return parameters;
  6621. }
  6622. const StringPairArray& URL::getFilesToUpload() const
  6623. {
  6624. return filesToUpload;
  6625. }
  6626. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6627. {
  6628. return mimeTypes;
  6629. }
  6630. const String URL::removeEscapeChars (const String& s)
  6631. {
  6632. const int len = s.length();
  6633. HeapBlock <char> resultUTF8 (len * 4);
  6634. char* r = resultUTF8;
  6635. for (int i = 0; i < len; ++i)
  6636. {
  6637. char c = (char) s[i];
  6638. if (c == 0)
  6639. break;
  6640. if (c == '+')
  6641. {
  6642. c = ' ';
  6643. }
  6644. else if (c == '%')
  6645. {
  6646. c = (char) s.substring (i + 1, i + 3).getHexValue32();
  6647. i += 2;
  6648. }
  6649. *r++ = c;
  6650. }
  6651. return String::fromUTF8 (resultUTF8);
  6652. }
  6653. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6654. {
  6655. String result;
  6656. result.preallocateStorage (s.length() + 8);
  6657. const char* utf8 = s.toUTF8();
  6658. const char* legalChars = isParameter ? "_-.*!'()"
  6659. : "_-$.*!'(),";
  6660. while (*utf8 != 0)
  6661. {
  6662. const char c = *utf8++;
  6663. if (CharacterFunctions::isLetterOrDigit (c)
  6664. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6665. {
  6666. result << c;
  6667. }
  6668. else
  6669. {
  6670. const int v = (int) (uint8) c;
  6671. if (v < 0x10)
  6672. result << T("%0");
  6673. else
  6674. result << T('%');
  6675. result << String::toHexString (v);
  6676. }
  6677. }
  6678. return result;
  6679. }
  6680. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6681. bool URL::launchInDefaultBrowser() const
  6682. {
  6683. String u (toString (true));
  6684. if (u.contains (T("@")) && ! u.contains (T(":")))
  6685. u = "mailto:" + u;
  6686. return juce_launchFile (u, String::empty);
  6687. }
  6688. END_JUCE_NAMESPACE
  6689. /*** End of inlined file: juce_URL.cpp ***/
  6690. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6691. BEGIN_JUCE_NAMESPACE
  6692. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6693. const int bufferSize_,
  6694. const bool deleteSourceWhenDestroyed)
  6695. : source (source_),
  6696. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6697. bufferSize (jmax (256, bufferSize_)),
  6698. position (source_->getPosition()),
  6699. lastReadPos (0),
  6700. bufferOverlap (128)
  6701. {
  6702. const int sourceSize = (int) source_->getTotalLength();
  6703. if (sourceSize >= 0)
  6704. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6705. bufferStart = position;
  6706. buffer.malloc (bufferSize);
  6707. }
  6708. BufferedInputStream::~BufferedInputStream()
  6709. {
  6710. }
  6711. int64 BufferedInputStream::getTotalLength()
  6712. {
  6713. return source->getTotalLength();
  6714. }
  6715. int64 BufferedInputStream::getPosition()
  6716. {
  6717. return position;
  6718. }
  6719. bool BufferedInputStream::setPosition (int64 newPosition)
  6720. {
  6721. position = jmax ((int64) 0, newPosition);
  6722. return true;
  6723. }
  6724. bool BufferedInputStream::isExhausted()
  6725. {
  6726. return (position >= lastReadPos)
  6727. && source->isExhausted();
  6728. }
  6729. void BufferedInputStream::ensureBuffered()
  6730. {
  6731. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6732. if (position < bufferStart || position >= bufferEndOverlap)
  6733. {
  6734. int bytesRead;
  6735. if (position < lastReadPos
  6736. && position >= bufferEndOverlap
  6737. && position >= bufferStart)
  6738. {
  6739. const int bytesToKeep = (int) (lastReadPos - position);
  6740. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6741. bufferStart = position;
  6742. bytesRead = source->read (buffer + bytesToKeep,
  6743. bufferSize - bytesToKeep);
  6744. lastReadPos += bytesRead;
  6745. bytesRead += bytesToKeep;
  6746. }
  6747. else
  6748. {
  6749. bufferStart = position;
  6750. source->setPosition (bufferStart);
  6751. bytesRead = source->read (buffer, bufferSize);
  6752. lastReadPos = bufferStart + bytesRead;
  6753. }
  6754. while (bytesRead < bufferSize)
  6755. buffer [bytesRead++] = 0;
  6756. }
  6757. }
  6758. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6759. {
  6760. if (position >= bufferStart
  6761. && position + maxBytesToRead <= lastReadPos)
  6762. {
  6763. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6764. position += maxBytesToRead;
  6765. return maxBytesToRead;
  6766. }
  6767. else
  6768. {
  6769. if (position < bufferStart || position >= lastReadPos)
  6770. ensureBuffered();
  6771. int bytesRead = 0;
  6772. while (maxBytesToRead > 0)
  6773. {
  6774. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6775. if (bytesAvailable > 0)
  6776. {
  6777. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6778. maxBytesToRead -= bytesAvailable;
  6779. bytesRead += bytesAvailable;
  6780. position += bytesAvailable;
  6781. destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
  6782. }
  6783. const int64 oldLastReadPos = lastReadPos;
  6784. ensureBuffered();
  6785. if (oldLastReadPos == lastReadPos)
  6786. break; // if ensureBuffered() failed to read any more data, bail out
  6787. if (isExhausted())
  6788. break;
  6789. }
  6790. return bytesRead;
  6791. }
  6792. }
  6793. const String BufferedInputStream::readString()
  6794. {
  6795. if (position >= bufferStart
  6796. && position < lastReadPos)
  6797. {
  6798. const int maxChars = (int) (lastReadPos - position);
  6799. const char* const src = buffer + (int) (position - bufferStart);
  6800. for (int i = 0; i < maxChars; ++i)
  6801. {
  6802. if (src[i] == 0)
  6803. {
  6804. position += i + 1;
  6805. return String::fromUTF8 (src, i);
  6806. }
  6807. }
  6808. }
  6809. return InputStream::readString();
  6810. }
  6811. END_JUCE_NAMESPACE
  6812. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  6813. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  6814. BEGIN_JUCE_NAMESPACE
  6815. FileInputSource::FileInputSource (const File& file_)
  6816. : file (file_)
  6817. {
  6818. }
  6819. FileInputSource::~FileInputSource()
  6820. {
  6821. }
  6822. InputStream* FileInputSource::createInputStream()
  6823. {
  6824. return file.createInputStream();
  6825. }
  6826. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  6827. {
  6828. return file.getSiblingFile (relatedItemPath).createInputStream();
  6829. }
  6830. int64 FileInputSource::hashCode() const
  6831. {
  6832. return file.hashCode();
  6833. }
  6834. END_JUCE_NAMESPACE
  6835. /*** End of inlined file: juce_FileInputSource.cpp ***/
  6836. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  6837. BEGIN_JUCE_NAMESPACE
  6838. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  6839. const size_t sourceDataSize,
  6840. const bool keepInternalCopy)
  6841. : data (static_cast <const char*> (sourceData)),
  6842. dataSize (sourceDataSize),
  6843. position (0)
  6844. {
  6845. if (keepInternalCopy)
  6846. {
  6847. internalCopy.append (data, sourceDataSize);
  6848. data = static_cast <const char*> (internalCopy.getData());
  6849. }
  6850. }
  6851. MemoryInputStream::MemoryInputStream (const MemoryBlock& sourceData,
  6852. const bool keepInternalCopy)
  6853. : data (static_cast <const char*> (sourceData.getData())),
  6854. dataSize (sourceData.getSize()),
  6855. position (0)
  6856. {
  6857. if (keepInternalCopy)
  6858. {
  6859. internalCopy = sourceData;
  6860. data = static_cast <const char*> (internalCopy.getData());
  6861. }
  6862. }
  6863. MemoryInputStream::~MemoryInputStream()
  6864. {
  6865. }
  6866. int64 MemoryInputStream::getTotalLength()
  6867. {
  6868. return dataSize;
  6869. }
  6870. int MemoryInputStream::read (void* const buffer, const int howMany)
  6871. {
  6872. jassert (howMany >= 0);
  6873. const int num = jmin (howMany, (int) (dataSize - position));
  6874. memcpy (buffer, data + position, num);
  6875. position += num;
  6876. return (int) num;
  6877. }
  6878. bool MemoryInputStream::isExhausted()
  6879. {
  6880. return (position >= dataSize);
  6881. }
  6882. bool MemoryInputStream::setPosition (const int64 pos)
  6883. {
  6884. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  6885. return true;
  6886. }
  6887. int64 MemoryInputStream::getPosition()
  6888. {
  6889. return position;
  6890. }
  6891. END_JUCE_NAMESPACE
  6892. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  6893. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  6894. BEGIN_JUCE_NAMESPACE
  6895. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  6896. const size_t blockSizeToIncreaseBy,
  6897. MemoryBlock* const memoryBlockToWriteTo)
  6898. : data (memoryBlockToWriteTo),
  6899. position (0),
  6900. size (0),
  6901. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  6902. {
  6903. if (data == 0)
  6904. dataToDelete = data = new MemoryBlock (initialSize);
  6905. else
  6906. data->setSize (initialSize, false);
  6907. }
  6908. MemoryOutputStream::~MemoryOutputStream()
  6909. {
  6910. flush();
  6911. }
  6912. void MemoryOutputStream::flush()
  6913. {
  6914. if (dataToDelete == 0)
  6915. data->setSize (size, false);
  6916. }
  6917. void MemoryOutputStream::reset() throw()
  6918. {
  6919. position = 0;
  6920. size = 0;
  6921. }
  6922. bool MemoryOutputStream::write (const void* const buffer, int howMany)
  6923. {
  6924. if (howMany > 0)
  6925. {
  6926. size_t storageNeeded = position + howMany;
  6927. if (storageNeeded >= data->getSize())
  6928. {
  6929. // if we need more space, increase the block by at least 10%..
  6930. storageNeeded += jmax (blockSize, storageNeeded / 10);
  6931. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  6932. data->ensureSize (storageNeeded);
  6933. }
  6934. data->copyFrom (buffer, (int) position, howMany);
  6935. position += howMany;
  6936. size = jmax (size, position);
  6937. }
  6938. return true;
  6939. }
  6940. const char* MemoryOutputStream::getData() const throw()
  6941. {
  6942. char* const d = static_cast <char*> (data->getData());
  6943. if (data->getSize() > size)
  6944. d [size] = 0;
  6945. return d;
  6946. }
  6947. size_t MemoryOutputStream::getDataSize() const throw()
  6948. {
  6949. return size;
  6950. }
  6951. int64 MemoryOutputStream::getPosition()
  6952. {
  6953. return position;
  6954. }
  6955. bool MemoryOutputStream::setPosition (int64 newPosition)
  6956. {
  6957. if (newPosition <= (int64) size)
  6958. {
  6959. // ok to seek backwards
  6960. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  6961. return true;
  6962. }
  6963. else
  6964. {
  6965. // trying to make it bigger isn't a good thing to do..
  6966. return false;
  6967. }
  6968. }
  6969. END_JUCE_NAMESPACE
  6970. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  6971. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  6972. BEGIN_JUCE_NAMESPACE
  6973. SubregionStream::SubregionStream (InputStream* const sourceStream,
  6974. const int64 startPositionInSourceStream_,
  6975. const int64 lengthOfSourceStream_,
  6976. const bool deleteSourceWhenDestroyed) throw()
  6977. : source (sourceStream),
  6978. startPositionInSourceStream (startPositionInSourceStream_),
  6979. lengthOfSourceStream (lengthOfSourceStream_)
  6980. {
  6981. if (deleteSourceWhenDestroyed)
  6982. sourceToDelete = source;
  6983. setPosition (0);
  6984. }
  6985. SubregionStream::~SubregionStream() throw()
  6986. {
  6987. }
  6988. int64 SubregionStream::getTotalLength()
  6989. {
  6990. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  6991. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  6992. : srcLen;
  6993. }
  6994. int64 SubregionStream::getPosition()
  6995. {
  6996. return source->getPosition() - startPositionInSourceStream;
  6997. }
  6998. bool SubregionStream::setPosition (int64 newPosition)
  6999. {
  7000. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  7001. }
  7002. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  7003. {
  7004. if (lengthOfSourceStream < 0)
  7005. {
  7006. return source->read (destBuffer, maxBytesToRead);
  7007. }
  7008. else
  7009. {
  7010. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  7011. if (maxBytesToRead <= 0)
  7012. return 0;
  7013. return source->read (destBuffer, maxBytesToRead);
  7014. }
  7015. }
  7016. bool SubregionStream::isExhausted()
  7017. {
  7018. if (lengthOfSourceStream >= 0)
  7019. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  7020. else
  7021. return source->isExhausted();
  7022. }
  7023. END_JUCE_NAMESPACE
  7024. /*** End of inlined file: juce_SubregionStream.cpp ***/
  7025. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  7026. BEGIN_JUCE_NAMESPACE
  7027. PerformanceCounter::PerformanceCounter (const String& name_,
  7028. int runsPerPrintout,
  7029. const File& loggingFile)
  7030. : name (name_),
  7031. numRuns (0),
  7032. runsPerPrint (runsPerPrintout),
  7033. totalTime (0),
  7034. outputFile (loggingFile)
  7035. {
  7036. if (outputFile != File::nonexistent)
  7037. {
  7038. String s ("**** Counter for \"");
  7039. s << name_ << "\" started at: "
  7040. << Time::getCurrentTime().toString (true, true)
  7041. << "\r\n";
  7042. outputFile.appendText (s, false, false);
  7043. }
  7044. }
  7045. PerformanceCounter::~PerformanceCounter()
  7046. {
  7047. printStatistics();
  7048. }
  7049. void PerformanceCounter::start()
  7050. {
  7051. started = Time::getHighResolutionTicks();
  7052. }
  7053. void PerformanceCounter::stop()
  7054. {
  7055. const int64 now = Time::getHighResolutionTicks();
  7056. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7057. if (++numRuns == runsPerPrint)
  7058. printStatistics();
  7059. }
  7060. void PerformanceCounter::printStatistics()
  7061. {
  7062. if (numRuns > 0)
  7063. {
  7064. String s ("Performance count for \"");
  7065. s << name << "\" - average over " << numRuns << " run(s) = ";
  7066. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7067. if (micros > 10000)
  7068. s << (micros/1000) << " millisecs";
  7069. else
  7070. s << micros << " microsecs";
  7071. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7072. Logger::outputDebugString (s);
  7073. s << "\r\n";
  7074. if (outputFile != File::nonexistent)
  7075. outputFile.appendText (s, false, false);
  7076. numRuns = 0;
  7077. totalTime = 0;
  7078. }
  7079. }
  7080. END_JUCE_NAMESPACE
  7081. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  7082. /*** Start of inlined file: juce_Uuid.cpp ***/
  7083. BEGIN_JUCE_NAMESPACE
  7084. Uuid::Uuid()
  7085. {
  7086. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7087. // to make it very very unlikely that two UUIDs will ever be the same..
  7088. static int64 macAddresses[2];
  7089. static bool hasCheckedMacAddresses = false;
  7090. if (! hasCheckedMacAddresses)
  7091. {
  7092. hasCheckedMacAddresses = true;
  7093. SystemStats::getMACAddresses (macAddresses, 2);
  7094. }
  7095. value.asInt64[0] = macAddresses[0];
  7096. value.asInt64[1] = macAddresses[1];
  7097. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7098. // whose seed will carry over between calls to this method.
  7099. Random r (macAddresses[0] ^ macAddresses[1]
  7100. ^ Random::getSystemRandom().nextInt64());
  7101. for (int i = 4; --i >= 0;)
  7102. {
  7103. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7104. value.asInt[i] ^= r.nextInt();
  7105. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7106. }
  7107. }
  7108. Uuid::~Uuid() throw()
  7109. {
  7110. }
  7111. Uuid::Uuid (const Uuid& other)
  7112. : value (other.value)
  7113. {
  7114. }
  7115. Uuid& Uuid::operator= (const Uuid& other)
  7116. {
  7117. value = other.value;
  7118. return *this;
  7119. }
  7120. bool Uuid::operator== (const Uuid& other) const
  7121. {
  7122. return memcmp (value.asBytes, other.value.asBytes, 16) == 0;
  7123. }
  7124. bool Uuid::operator!= (const Uuid& other) const
  7125. {
  7126. return ! operator== (other);
  7127. }
  7128. bool Uuid::isNull() const throw()
  7129. {
  7130. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7131. }
  7132. const String Uuid::toString() const
  7133. {
  7134. return String::toHexString (value.asBytes, 16, 0);
  7135. }
  7136. Uuid::Uuid (const String& uuidString)
  7137. {
  7138. operator= (uuidString);
  7139. }
  7140. Uuid& Uuid::operator= (const String& uuidString)
  7141. {
  7142. int destIndex = 0;
  7143. int i = 0;
  7144. for (;;)
  7145. {
  7146. int byte = 0;
  7147. for (int loop = 2; --loop >= 0;)
  7148. {
  7149. byte <<= 4;
  7150. for (;;)
  7151. {
  7152. const tchar c = uuidString [i++];
  7153. if (c >= T('0') && c <= T('9'))
  7154. {
  7155. byte |= c - T('0');
  7156. break;
  7157. }
  7158. else if (c >= T('a') && c <= T('z'))
  7159. {
  7160. byte |= c - (T('a') - 10);
  7161. break;
  7162. }
  7163. else if (c >= T('A') && c <= T('Z'))
  7164. {
  7165. byte |= c - (T('A') - 10);
  7166. break;
  7167. }
  7168. else if (c == 0)
  7169. {
  7170. while (destIndex < 16)
  7171. value.asBytes [destIndex++] = 0;
  7172. return *this;
  7173. }
  7174. }
  7175. }
  7176. value.asBytes [destIndex++] = (uint8) byte;
  7177. }
  7178. }
  7179. Uuid::Uuid (const uint8* const rawData)
  7180. {
  7181. operator= (rawData);
  7182. }
  7183. Uuid& Uuid::operator= (const uint8* const rawData)
  7184. {
  7185. if (rawData != 0)
  7186. memcpy (value.asBytes, rawData, 16);
  7187. else
  7188. zeromem (value.asBytes, 16);
  7189. return *this;
  7190. }
  7191. END_JUCE_NAMESPACE
  7192. /*** End of inlined file: juce_Uuid.cpp ***/
  7193. /*** Start of inlined file: juce_ZipFile.cpp ***/
  7194. BEGIN_JUCE_NAMESPACE
  7195. class ZipFile::ZipEntryInfo
  7196. {
  7197. public:
  7198. ZipFile::ZipEntry entry;
  7199. int streamOffset;
  7200. int compressedSize;
  7201. bool compressed;
  7202. };
  7203. class ZipFile::ZipInputStream : public InputStream
  7204. {
  7205. public:
  7206. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7207. : file (file_),
  7208. zipEntryInfo (zei),
  7209. pos (0),
  7210. headerSize (0),
  7211. inputStream (0)
  7212. {
  7213. inputStream = file_.inputStream;
  7214. if (file_.inputSource != 0)
  7215. {
  7216. inputStream = file.inputSource->createInputStream();
  7217. }
  7218. else
  7219. {
  7220. #ifdef JUCE_DEBUG
  7221. file_.numOpenStreams++;
  7222. #endif
  7223. }
  7224. char buffer [30];
  7225. if (inputStream != 0
  7226. && inputStream->setPosition (zei.streamOffset)
  7227. && inputStream->read (buffer, 30) == 30
  7228. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7229. {
  7230. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7231. + ByteOrder::littleEndianShort (buffer + 28);
  7232. }
  7233. }
  7234. ~ZipInputStream() throw()
  7235. {
  7236. #ifdef JUCE_DEBUG
  7237. if (inputStream != 0 && inputStream == file.inputStream)
  7238. file.numOpenStreams--;
  7239. #endif
  7240. if (inputStream != file.inputStream)
  7241. delete inputStream;
  7242. }
  7243. int64 getTotalLength() throw()
  7244. {
  7245. return zipEntryInfo.compressedSize;
  7246. }
  7247. int read (void* buffer, int howMany) throw()
  7248. {
  7249. if (headerSize <= 0)
  7250. return 0;
  7251. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7252. if (inputStream == 0)
  7253. return 0;
  7254. int num;
  7255. if (inputStream == file.inputStream)
  7256. {
  7257. const ScopedLock sl (file.lock);
  7258. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7259. num = inputStream->read (buffer, howMany);
  7260. }
  7261. else
  7262. {
  7263. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7264. num = inputStream->read (buffer, howMany);
  7265. }
  7266. pos += num;
  7267. return num;
  7268. }
  7269. bool isExhausted() throw()
  7270. {
  7271. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7272. }
  7273. int64 getPosition() throw()
  7274. {
  7275. return pos;
  7276. }
  7277. bool setPosition (int64 newPos) throw()
  7278. {
  7279. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7280. return true;
  7281. }
  7282. private:
  7283. ZipFile& file;
  7284. ZipEntryInfo zipEntryInfo;
  7285. int64 pos;
  7286. int headerSize;
  7287. InputStream* inputStream;
  7288. ZipInputStream (const ZipInputStream&);
  7289. ZipInputStream& operator= (const ZipInputStream&);
  7290. };
  7291. ZipFile::ZipFile (InputStream* const source_,
  7292. const bool deleteStreamWhenDestroyed) throw()
  7293. : inputStream (source_)
  7294. #ifdef JUCE_DEBUG
  7295. , numOpenStreams (0)
  7296. #endif
  7297. {
  7298. if (deleteStreamWhenDestroyed)
  7299. streamToDelete = inputStream;
  7300. init();
  7301. }
  7302. ZipFile::ZipFile (const File& file)
  7303. : inputStream (0)
  7304. #ifdef JUCE_DEBUG
  7305. , numOpenStreams (0)
  7306. #endif
  7307. {
  7308. inputSource = new FileInputSource (file);
  7309. init();
  7310. }
  7311. ZipFile::ZipFile (InputSource* const inputSource_)
  7312. : inputStream (0),
  7313. inputSource (inputSource_)
  7314. #ifdef JUCE_DEBUG
  7315. , numOpenStreams (0)
  7316. #endif
  7317. {
  7318. init();
  7319. }
  7320. ZipFile::~ZipFile() throw()
  7321. {
  7322. #ifdef JUCE_DEBUG
  7323. entries.clear();
  7324. // If you hit this assertion, it means you've created a stream to read
  7325. // one of the items in the zipfile, but you've forgotten to delete that
  7326. // stream object before deleting the file.. Streams can't be kept open
  7327. // after the file is deleted because they need to share the input
  7328. // stream that the file uses to read itself.
  7329. jassert (numOpenStreams == 0);
  7330. #endif
  7331. }
  7332. int ZipFile::getNumEntries() const throw()
  7333. {
  7334. return entries.size();
  7335. }
  7336. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7337. {
  7338. ZipEntryInfo* const zei = (ZipEntryInfo*) entries [index];
  7339. return (zei != 0) ? &(zei->entry)
  7340. : 0;
  7341. }
  7342. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7343. {
  7344. for (int i = 0; i < entries.size(); ++i)
  7345. if (entries.getUnchecked (i)->entry.filename == fileName)
  7346. return i;
  7347. return -1;
  7348. }
  7349. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7350. {
  7351. return getEntry (getIndexOfFileName (fileName));
  7352. }
  7353. InputStream* ZipFile::createStreamForEntry (const int index)
  7354. {
  7355. ZipEntryInfo* const zei = entries[index];
  7356. InputStream* stream = 0;
  7357. if (zei != 0)
  7358. {
  7359. stream = new ZipInputStream (*this, *zei);
  7360. if (zei->compressed)
  7361. {
  7362. stream = new GZIPDecompressorInputStream (stream, true, true,
  7363. zei->entry.uncompressedSize);
  7364. // (much faster to unzip in big blocks using a buffer..)
  7365. stream = new BufferedInputStream (stream, 32768, true);
  7366. }
  7367. }
  7368. return stream;
  7369. }
  7370. class ZipFile::ZipFilenameComparator
  7371. {
  7372. public:
  7373. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7374. {
  7375. return first->entry.filename.compare (second->entry.filename);
  7376. }
  7377. };
  7378. void ZipFile::sortEntriesByFilename()
  7379. {
  7380. ZipFilenameComparator sorter;
  7381. entries.sort (sorter);
  7382. }
  7383. void ZipFile::init()
  7384. {
  7385. ScopedPointer <InputStream> toDelete;
  7386. InputStream* in = inputStream;
  7387. if (inputSource != 0)
  7388. {
  7389. in = inputSource->createInputStream();
  7390. toDelete = in;
  7391. }
  7392. if (in != 0)
  7393. {
  7394. int numEntries = 0;
  7395. int pos = findEndOfZipEntryTable (in, numEntries);
  7396. if (pos >= 0 && pos < in->getTotalLength())
  7397. {
  7398. const int size = (int) (in->getTotalLength() - pos);
  7399. in->setPosition (pos);
  7400. MemoryBlock headerData;
  7401. if (in->readIntoMemoryBlock (headerData, size) == size)
  7402. {
  7403. pos = 0;
  7404. for (int i = 0; i < numEntries; ++i)
  7405. {
  7406. if (pos + 46 > size)
  7407. break;
  7408. const char* const buffer = ((const char*) headerData.getData()) + pos;
  7409. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7410. if (pos + 46 + fileNameLen > size)
  7411. break;
  7412. ZipEntryInfo* const zei = new ZipEntryInfo();
  7413. zei->entry.filename = String::fromUTF8 (buffer + 46, fileNameLen);
  7414. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7415. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7416. const int year = 1980 + (date >> 9);
  7417. const int month = ((date >> 5) & 15) - 1;
  7418. const int day = date & 31;
  7419. const int hours = time >> 11;
  7420. const int minutes = (time >> 5) & 63;
  7421. const int seconds = (time & 31) << 1;
  7422. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7423. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7424. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7425. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7426. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7427. entries.add (zei);
  7428. pos += 46 + fileNameLen
  7429. + ByteOrder::littleEndianShort (buffer + 30)
  7430. + ByteOrder::littleEndianShort (buffer + 32);
  7431. }
  7432. }
  7433. }
  7434. }
  7435. }
  7436. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7437. {
  7438. BufferedInputStream in (input, 8192, false);
  7439. in.setPosition (in.getTotalLength());
  7440. int64 pos = in.getPosition();
  7441. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7442. char buffer [32];
  7443. zeromem (buffer, sizeof (buffer));
  7444. while (pos > lowestPos)
  7445. {
  7446. in.setPosition (pos - 22);
  7447. pos = in.getPosition();
  7448. memcpy (buffer + 22, buffer, 4);
  7449. if (in.read (buffer, 22) != 22)
  7450. return 0;
  7451. for (int i = 0; i < 22; ++i)
  7452. {
  7453. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7454. {
  7455. in.setPosition (pos + i);
  7456. in.read (buffer, 22);
  7457. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7458. return ByteOrder::littleEndianInt (buffer + 16);
  7459. }
  7460. }
  7461. }
  7462. return 0;
  7463. }
  7464. void ZipFile::uncompressTo (const File& targetDirectory,
  7465. const bool shouldOverwriteFiles)
  7466. {
  7467. for (int i = 0; i < entries.size(); ++i)
  7468. {
  7469. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7470. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7471. if (zei.filename.endsWithChar (T('/')))
  7472. {
  7473. targetFile.createDirectory(); // (entry is a directory, not a file)
  7474. }
  7475. else
  7476. {
  7477. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7478. if (in != 0)
  7479. {
  7480. if (shouldOverwriteFiles)
  7481. targetFile.deleteFile();
  7482. if ((! targetFile.exists())
  7483. && targetFile.getParentDirectory().createDirectory())
  7484. {
  7485. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7486. if (out != 0)
  7487. {
  7488. out->writeFromInputStream (*in, -1);
  7489. out = 0;
  7490. targetFile.setCreationTime (zei.fileTime);
  7491. targetFile.setLastModificationTime (zei.fileTime);
  7492. targetFile.setLastAccessTime (zei.fileTime);
  7493. }
  7494. }
  7495. }
  7496. }
  7497. }
  7498. }
  7499. END_JUCE_NAMESPACE
  7500. /*** End of inlined file: juce_ZipFile.cpp ***/
  7501. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7502. #ifdef _MSC_VER
  7503. #pragma warning (disable: 4514 4996)
  7504. #pragma warning (push)
  7505. #endif
  7506. #include <cwctype>
  7507. #include <cctype>
  7508. #include <ctime>
  7509. #ifdef _MSC_VER
  7510. #pragma warning (pop)
  7511. #endif
  7512. BEGIN_JUCE_NAMESPACE
  7513. int CharacterFunctions::length (const char* const s) throw()
  7514. {
  7515. return (int) strlen (s);
  7516. }
  7517. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7518. {
  7519. return (int) wcslen (s);
  7520. }
  7521. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7522. {
  7523. strncpy (dest, src, maxChars);
  7524. }
  7525. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7526. {
  7527. wcsncpy (dest, src, maxChars);
  7528. }
  7529. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7530. {
  7531. mbstowcs (dest, src, maxChars);
  7532. }
  7533. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7534. {
  7535. wcstombs (dest, src, maxChars);
  7536. }
  7537. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7538. {
  7539. return (int) wcstombs (0, src, 0);
  7540. }
  7541. void CharacterFunctions::append (char* dest, const char* src) throw()
  7542. {
  7543. strcat (dest, src);
  7544. }
  7545. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7546. {
  7547. wcscat (dest, src);
  7548. }
  7549. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7550. {
  7551. return strcmp (s1, s2);
  7552. }
  7553. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7554. {
  7555. jassert (s1 != 0 && s2 != 0);
  7556. return wcscmp (s1, s2);
  7557. }
  7558. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7559. {
  7560. jassert (s1 != 0 && s2 != 0);
  7561. return strncmp (s1, s2, maxChars);
  7562. }
  7563. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7564. {
  7565. jassert (s1 != 0 && s2 != 0);
  7566. return wcsncmp (s1, s2, maxChars);
  7567. }
  7568. int CharacterFunctions::compare (const juce_wchar* s1, const char* s2) throw()
  7569. {
  7570. jassert (s1 != 0 && s2 != 0);
  7571. for (;;)
  7572. {
  7573. const int diff = (int) (*s1 - (juce_wchar) (unsigned char) *s2);
  7574. if (diff != 0)
  7575. return diff;
  7576. else if (*s1 == 0)
  7577. break;
  7578. ++s1;
  7579. ++s2;
  7580. }
  7581. return 0;
  7582. }
  7583. int CharacterFunctions::compare (const char* s1, const juce_wchar* s2) throw()
  7584. {
  7585. return -compare (s2, s1);
  7586. }
  7587. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7588. {
  7589. jassert (s1 != 0 && s2 != 0);
  7590. #if JUCE_WIN32
  7591. return stricmp (s1, s2);
  7592. #else
  7593. return strcasecmp (s1, s2);
  7594. #endif
  7595. }
  7596. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7597. {
  7598. jassert (s1 != 0 && s2 != 0);
  7599. #if JUCE_WIN32
  7600. return _wcsicmp (s1, s2);
  7601. #else
  7602. for (;;)
  7603. {
  7604. if (*s1 != *s2)
  7605. {
  7606. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7607. if (diff != 0)
  7608. return diff < 0 ? -1 : 1;
  7609. }
  7610. else if (*s1 == 0)
  7611. break;
  7612. ++s1;
  7613. ++s2;
  7614. }
  7615. return 0;
  7616. #endif
  7617. }
  7618. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7619. {
  7620. jassert (s1 != 0 && s2 != 0);
  7621. #if JUCE_WIN32
  7622. return strnicmp (s1, s2, maxChars);
  7623. #else
  7624. return strncasecmp (s1, s2, maxChars);
  7625. #endif
  7626. }
  7627. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7628. {
  7629. jassert (s1 != 0 && s2 != 0);
  7630. #if JUCE_WIN32
  7631. return _wcsnicmp (s1, s2, maxChars);
  7632. #else
  7633. while (--maxChars >= 0)
  7634. {
  7635. if (*s1 != *s2)
  7636. {
  7637. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7638. if (diff != 0)
  7639. return diff < 0 ? -1 : 1;
  7640. }
  7641. else if (*s1 == 0)
  7642. break;
  7643. ++s1;
  7644. ++s2;
  7645. }
  7646. return 0;
  7647. #endif
  7648. }
  7649. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7650. {
  7651. return strstr (haystack, needle);
  7652. }
  7653. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7654. {
  7655. return wcsstr (haystack, needle);
  7656. }
  7657. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7658. {
  7659. if (haystack != 0)
  7660. {
  7661. int i = 0;
  7662. if (ignoreCase)
  7663. {
  7664. const char n1 = toLowerCase (needle);
  7665. const char n2 = toUpperCase (needle);
  7666. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7667. {
  7668. while (haystack[i] != 0)
  7669. {
  7670. if (haystack[i] == n1 || haystack[i] == n2)
  7671. return i;
  7672. ++i;
  7673. }
  7674. return -1;
  7675. }
  7676. jassert (n1 == needle);
  7677. }
  7678. while (haystack[i] != 0)
  7679. {
  7680. if (haystack[i] == needle)
  7681. return i;
  7682. ++i;
  7683. }
  7684. }
  7685. return -1;
  7686. }
  7687. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7688. {
  7689. if (haystack != 0)
  7690. {
  7691. int i = 0;
  7692. if (ignoreCase)
  7693. {
  7694. const juce_wchar n1 = toLowerCase (needle);
  7695. const juce_wchar n2 = toUpperCase (needle);
  7696. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7697. {
  7698. while (haystack[i] != 0)
  7699. {
  7700. if (haystack[i] == n1 || haystack[i] == n2)
  7701. return i;
  7702. ++i;
  7703. }
  7704. return -1;
  7705. }
  7706. jassert (n1 == needle);
  7707. }
  7708. while (haystack[i] != 0)
  7709. {
  7710. if (haystack[i] == needle)
  7711. return i;
  7712. ++i;
  7713. }
  7714. }
  7715. return -1;
  7716. }
  7717. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7718. {
  7719. jassert (haystack != 0);
  7720. int i = 0;
  7721. while (haystack[i] != 0)
  7722. {
  7723. if (haystack[i] == needle)
  7724. return i;
  7725. ++i;
  7726. }
  7727. return -1;
  7728. }
  7729. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7730. {
  7731. jassert (haystack != 0);
  7732. int i = 0;
  7733. while (haystack[i] != 0)
  7734. {
  7735. if (haystack[i] == needle)
  7736. return i;
  7737. ++i;
  7738. }
  7739. return -1;
  7740. }
  7741. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7742. {
  7743. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7744. }
  7745. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7746. {
  7747. if (allowedChars == 0)
  7748. return 0;
  7749. int i = 0;
  7750. for (;;)
  7751. {
  7752. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7753. break;
  7754. ++i;
  7755. }
  7756. return i;
  7757. }
  7758. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7759. {
  7760. return (int) strftime (dest, maxChars, format, tm);
  7761. }
  7762. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7763. {
  7764. return (int) wcsftime (dest, maxChars, format, tm);
  7765. }
  7766. int CharacterFunctions::getIntValue (const char* const s) throw()
  7767. {
  7768. return atoi (s);
  7769. }
  7770. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7771. {
  7772. #if JUCE_WIN32
  7773. return _wtoi (s);
  7774. #else
  7775. int v = 0;
  7776. while (isWhitespace (*s))
  7777. ++s;
  7778. const bool isNeg = *s == T('-');
  7779. if (isNeg)
  7780. ++s;
  7781. for (;;)
  7782. {
  7783. const wchar_t c = *s++;
  7784. if (c >= T('0') && c <= T('9'))
  7785. v = v * 10 + (int) (c - T('0'));
  7786. else
  7787. break;
  7788. }
  7789. return isNeg ? -v : v;
  7790. #endif
  7791. }
  7792. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7793. {
  7794. #if JUCE_LINUX
  7795. return atoll (s);
  7796. #elif defined (JUCE_WIN32)
  7797. return _atoi64 (s);
  7798. #else
  7799. int64 v = 0;
  7800. while (isWhitespace (*s))
  7801. ++s;
  7802. const bool isNeg = *s == T('-');
  7803. if (isNeg)
  7804. ++s;
  7805. for (;;)
  7806. {
  7807. const char c = *s++;
  7808. if (c >= '0' && c <= '9')
  7809. v = v * 10 + (int64) (c - '0');
  7810. else
  7811. break;
  7812. }
  7813. return isNeg ? -v : v;
  7814. #endif
  7815. }
  7816. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7817. {
  7818. #if JUCE_WIN32
  7819. return _wtoi64 (s);
  7820. #else
  7821. int64 v = 0;
  7822. while (isWhitespace (*s))
  7823. ++s;
  7824. const bool isNeg = *s == T('-');
  7825. if (isNeg)
  7826. ++s;
  7827. for (;;)
  7828. {
  7829. const juce_wchar c = *s++;
  7830. if (c >= T('0') && c <= T('9'))
  7831. v = v * 10 + (int64) (c - T('0'));
  7832. else
  7833. break;
  7834. }
  7835. return isNeg ? -v : v;
  7836. #endif
  7837. }
  7838. static double juce_mulexp10 (const double value, int exponent) throw()
  7839. {
  7840. if (exponent == 0)
  7841. return value;
  7842. if (value == 0)
  7843. return 0;
  7844. const bool negative = (exponent < 0);
  7845. if (negative)
  7846. exponent = -exponent;
  7847. double result = 1.0, power = 10.0;
  7848. for (int bit = 1; exponent != 0; bit <<= 1)
  7849. {
  7850. if ((exponent & bit) != 0)
  7851. {
  7852. exponent ^= bit;
  7853. result *= power;
  7854. if (exponent == 0)
  7855. break;
  7856. }
  7857. power *= power;
  7858. }
  7859. return negative ? (value / result) : (value * result);
  7860. }
  7861. template <class CharType>
  7862. double juce_atof (const CharType* const original) throw()
  7863. {
  7864. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  7865. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  7866. int exponent = 0, decPointIndex = 0, digit = 0;
  7867. int lastDigit = 0, numSignificantDigits = 0;
  7868. bool isNegative = false, digitsFound = false;
  7869. const int maxSignificantDigits = 15 + 2;
  7870. const CharType* s = original;
  7871. while (CharacterFunctions::isWhitespace (*s))
  7872. ++s;
  7873. switch (*s)
  7874. {
  7875. case '-': isNegative = true; // fall-through..
  7876. case '+': ++s;
  7877. }
  7878. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  7879. return atof (String (original).toUTF8()); // Let the c library deal with NAN and INF
  7880. for (;;)
  7881. {
  7882. if (CharacterFunctions::isDigit (*s))
  7883. {
  7884. lastDigit = digit;
  7885. digit = *s++ - '0';
  7886. digitsFound = true;
  7887. if (decPointIndex != 0)
  7888. exponentAdjustment[1]++;
  7889. if (numSignificantDigits == 0 && digit == 0)
  7890. continue;
  7891. if (++numSignificantDigits > maxSignificantDigits)
  7892. {
  7893. if (digit > 5)
  7894. ++accumulator [decPointIndex];
  7895. else if (digit == 5 && (lastDigit & 1) != 0)
  7896. ++accumulator [decPointIndex];
  7897. if (decPointIndex > 0)
  7898. exponentAdjustment[1]--;
  7899. else
  7900. exponentAdjustment[0]++;
  7901. while (CharacterFunctions::isDigit (*s))
  7902. {
  7903. ++s;
  7904. if (decPointIndex == 0)
  7905. exponentAdjustment[0]++;
  7906. }
  7907. }
  7908. else
  7909. {
  7910. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  7911. if (accumulator [decPointIndex] > maxAccumulatorValue)
  7912. {
  7913. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  7914. + accumulator [decPointIndex];
  7915. accumulator [decPointIndex] = 0;
  7916. exponentAccumulator [decPointIndex] = 0;
  7917. }
  7918. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  7919. exponentAccumulator [decPointIndex]++;
  7920. }
  7921. }
  7922. else if (decPointIndex == 0 && *s == '.')
  7923. {
  7924. ++s;
  7925. decPointIndex = 1;
  7926. if (numSignificantDigits > maxSignificantDigits)
  7927. {
  7928. while (CharacterFunctions::isDigit (*s))
  7929. ++s;
  7930. break;
  7931. }
  7932. }
  7933. else
  7934. {
  7935. break;
  7936. }
  7937. }
  7938. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  7939. if (decPointIndex != 0)
  7940. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  7941. if ((*s == 'e' || *s == 'E') && digitsFound)
  7942. {
  7943. bool negativeExponent = false;
  7944. switch (*++s)
  7945. {
  7946. case '-': negativeExponent = true; // fall-through..
  7947. case '+': ++s;
  7948. }
  7949. while (CharacterFunctions::isDigit (*s))
  7950. exponent = (exponent * 10) + (*s++ - '0');
  7951. if (negativeExponent)
  7952. exponent = -exponent;
  7953. }
  7954. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  7955. if (decPointIndex != 0)
  7956. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  7957. return isNegative ? -r : r;
  7958. }
  7959. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  7960. {
  7961. return juce_atof <char> (s);
  7962. }
  7963. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  7964. {
  7965. return juce_atof <juce_wchar> (s);
  7966. }
  7967. char CharacterFunctions::toUpperCase (const char character) throw()
  7968. {
  7969. return (char) toupper (character);
  7970. }
  7971. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  7972. {
  7973. return towupper (character);
  7974. }
  7975. void CharacterFunctions::toUpperCase (char* s) throw()
  7976. {
  7977. #if JUCE_WIN32
  7978. strupr (s);
  7979. #else
  7980. while (*s != 0)
  7981. {
  7982. *s = toUpperCase (*s);
  7983. ++s;
  7984. }
  7985. #endif
  7986. }
  7987. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  7988. {
  7989. #if JUCE_WIN32
  7990. _wcsupr (s);
  7991. #else
  7992. while (*s != 0)
  7993. {
  7994. *s = toUpperCase (*s);
  7995. ++s;
  7996. }
  7997. #endif
  7998. }
  7999. bool CharacterFunctions::isUpperCase (const char character) throw()
  8000. {
  8001. return isupper (character) != 0;
  8002. }
  8003. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  8004. {
  8005. #if JUCE_WIN32
  8006. return iswupper (character) != 0;
  8007. #else
  8008. return toLowerCase (character) != character;
  8009. #endif
  8010. }
  8011. char CharacterFunctions::toLowerCase (const char character) throw()
  8012. {
  8013. return (char) tolower (character);
  8014. }
  8015. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  8016. {
  8017. return towlower (character);
  8018. }
  8019. void CharacterFunctions::toLowerCase (char* s) throw()
  8020. {
  8021. #if JUCE_WIN32
  8022. strlwr (s);
  8023. #else
  8024. while (*s != 0)
  8025. {
  8026. *s = toLowerCase (*s);
  8027. ++s;
  8028. }
  8029. #endif
  8030. }
  8031. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  8032. {
  8033. #if JUCE_WIN32
  8034. _wcslwr (s);
  8035. #else
  8036. while (*s != 0)
  8037. {
  8038. *s = toLowerCase (*s);
  8039. ++s;
  8040. }
  8041. #endif
  8042. }
  8043. bool CharacterFunctions::isLowerCase (const char character) throw()
  8044. {
  8045. return islower (character) != 0;
  8046. }
  8047. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  8048. {
  8049. #if JUCE_WIN32
  8050. return iswlower (character) != 0;
  8051. #else
  8052. return toUpperCase (character) != character;
  8053. #endif
  8054. }
  8055. bool CharacterFunctions::isWhitespace (const char character) throw()
  8056. {
  8057. return character == T(' ') || (character <= 13 && character >= 9);
  8058. }
  8059. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8060. {
  8061. return iswspace (character) != 0;
  8062. }
  8063. bool CharacterFunctions::isDigit (const char character) throw()
  8064. {
  8065. return (character >= '0' && character <= '9');
  8066. }
  8067. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8068. {
  8069. return iswdigit (character) != 0;
  8070. }
  8071. bool CharacterFunctions::isLetter (const char character) throw()
  8072. {
  8073. return (character >= 'a' && character <= 'z')
  8074. || (character >= 'A' && character <= 'Z');
  8075. }
  8076. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8077. {
  8078. return iswalpha (character) != 0;
  8079. }
  8080. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8081. {
  8082. return (character >= 'a' && character <= 'z')
  8083. || (character >= 'A' && character <= 'Z')
  8084. || (character >= '0' && character <= '9');
  8085. }
  8086. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8087. {
  8088. return iswalnum (character) != 0;
  8089. }
  8090. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) throw()
  8091. {
  8092. if (digit >= '0' && digit <= '9')
  8093. return digit - '0';
  8094. else if (digit >= 'a' && digit <= 'f')
  8095. return digit - ('a' - 10);
  8096. else if (digit >= 'A' && digit <= 'F')
  8097. return digit - ('A' - 10);
  8098. return -1;
  8099. }
  8100. END_JUCE_NAMESPACE
  8101. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  8102. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  8103. BEGIN_JUCE_NAMESPACE
  8104. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8105. {
  8106. loadFromText (fileContents);
  8107. }
  8108. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8109. {
  8110. loadFromText (fileToLoad.loadFileAsString());
  8111. }
  8112. LocalisedStrings::~LocalisedStrings()
  8113. {
  8114. }
  8115. const String LocalisedStrings::translate (const String& text) const
  8116. {
  8117. return translations.getValue (text, text);
  8118. }
  8119. static int findCloseQuote (const String& text, int startPos)
  8120. {
  8121. tchar lastChar = 0;
  8122. for (;;)
  8123. {
  8124. const tchar c = text [startPos];
  8125. if (c == 0 || (c == T('"') && lastChar != T('\\')))
  8126. break;
  8127. lastChar = c;
  8128. ++startPos;
  8129. }
  8130. return startPos;
  8131. }
  8132. static const String unescapeString (const String& s)
  8133. {
  8134. return s.replace (T("\\\""), T("\""))
  8135. .replace (T("\\\'"), T("\'"))
  8136. .replace (T("\\t"), T("\t"))
  8137. .replace (T("\\r"), T("\r"))
  8138. .replace (T("\\n"), T("\n"));
  8139. }
  8140. void LocalisedStrings::loadFromText (const String& fileContents)
  8141. {
  8142. StringArray lines;
  8143. lines.addLines (fileContents);
  8144. for (int i = 0; i < lines.size(); ++i)
  8145. {
  8146. String line (lines[i].trim());
  8147. if (line.startsWithChar (T('"')))
  8148. {
  8149. int closeQuote = findCloseQuote (line, 1);
  8150. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8151. if (originalText.isNotEmpty())
  8152. {
  8153. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8154. closeQuote = findCloseQuote (line, openingQuote + 1);
  8155. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8156. if (newText.isNotEmpty())
  8157. translations.set (originalText, newText);
  8158. }
  8159. }
  8160. else if (line.startsWithIgnoreCase (T("language:")))
  8161. {
  8162. languageName = line.substring (9).trim();
  8163. }
  8164. else if (line.startsWithIgnoreCase (T("countries:")))
  8165. {
  8166. countryCodes.addTokens (line.substring (10).trim(), true);
  8167. countryCodes.trim();
  8168. countryCodes.removeEmptyStrings();
  8169. }
  8170. }
  8171. }
  8172. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8173. {
  8174. translations.setIgnoresCase (shouldIgnoreCase);
  8175. }
  8176. static CriticalSection currentMappingsLock;
  8177. static LocalisedStrings* currentMappings = 0;
  8178. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8179. {
  8180. const ScopedLock sl (currentMappingsLock);
  8181. delete currentMappings;
  8182. currentMappings = newTranslations;
  8183. }
  8184. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8185. {
  8186. return currentMappings;
  8187. }
  8188. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8189. {
  8190. const ScopedLock sl (currentMappingsLock);
  8191. if (currentMappings != 0)
  8192. return currentMappings->translate (text);
  8193. return text;
  8194. }
  8195. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8196. {
  8197. return translateWithCurrentMappings (String (text));
  8198. }
  8199. END_JUCE_NAMESPACE
  8200. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  8201. /*** Start of inlined file: juce_String.cpp ***/
  8202. #ifdef _MSC_VER
  8203. #pragma warning (disable: 4514)
  8204. #pragma warning (push)
  8205. #endif
  8206. #include <locale>
  8207. #if JUCE_MSVC
  8208. #include <float.h>
  8209. #endif
  8210. BEGIN_JUCE_NAMESPACE
  8211. #ifdef _MSC_VER
  8212. #pragma warning (pop)
  8213. #endif
  8214. #if defined (JUCE_STRINGS_ARE_UNICODE) && ! JUCE_STRINGS_ARE_UNICODE
  8215. #error "JUCE_STRINGS_ARE_UNICODE is deprecated! All strings are now unicode by default."
  8216. #endif
  8217. class StringHolder
  8218. {
  8219. public:
  8220. StringHolder()
  8221. : refCount (0x3fffffff), allocatedNumChars (0)
  8222. {
  8223. text[0] = 0;
  8224. }
  8225. static juce_wchar* create (const size_t numChars)
  8226. {
  8227. StringHolder* const s = reinterpret_cast <StringHolder*> (juce_malloc (sizeof (StringHolder) + numChars * sizeof (juce_wchar)));
  8228. s->refCount = 0;
  8229. s->allocatedNumChars = numChars;
  8230. return &(s->text[0]);
  8231. }
  8232. static inline juce_wchar* getEmpty() throw()
  8233. {
  8234. return &(empty.text[0]);
  8235. }
  8236. static void retain (juce_wchar* const text) throw()
  8237. {
  8238. Atomic::increment (bufferFromText (text)->refCount);
  8239. }
  8240. static inline void release (StringHolder* const b) throw()
  8241. {
  8242. if (Atomic::decrementAndReturn (b->refCount) == -1 && b != &empty)
  8243. juce_free (b);
  8244. }
  8245. static void release (juce_wchar* const text) throw()
  8246. {
  8247. release (bufferFromText (text));
  8248. }
  8249. static juce_wchar* makeUnique (juce_wchar* const text)
  8250. {
  8251. StringHolder* const b = bufferFromText (text);
  8252. if (b->refCount <= 0)
  8253. return text;
  8254. juce_wchar* const newText = create (b->allocatedNumChars);
  8255. copyChars (newText, text, b->allocatedNumChars);
  8256. release (b);
  8257. return newText;
  8258. }
  8259. static juce_wchar* makeUniqueWithSize (juce_wchar* const text, size_t numChars)
  8260. {
  8261. StringHolder* const b = bufferFromText (text);
  8262. if (b->refCount <= 0 && b->allocatedNumChars >= numChars)
  8263. return text;
  8264. juce_wchar* const newText = create (jmax (b->allocatedNumChars, numChars));
  8265. copyChars (newText, text, b->allocatedNumChars);
  8266. release (b);
  8267. return newText;
  8268. }
  8269. static size_t getAllocatedNumChars (juce_wchar* const text) throw()
  8270. {
  8271. return bufferFromText (text)->allocatedNumChars;
  8272. }
  8273. static void copyChars (juce_wchar* const dest, const juce_wchar* const src, const size_t numChars) throw()
  8274. {
  8275. memcpy (dest, src, numChars * sizeof (juce_wchar));
  8276. dest [numChars] = 0;
  8277. }
  8278. int refCount;
  8279. size_t allocatedNumChars;
  8280. juce_wchar text[1];
  8281. static StringHolder empty;
  8282. private:
  8283. static inline StringHolder* bufferFromText (juce_wchar* const text) throw()
  8284. {
  8285. // (Can't use offsetof() here because of warnings about this not being a POD)
  8286. return reinterpret_cast <StringHolder*> (reinterpret_cast <char*> (text)
  8287. - (reinterpret_cast <size_t> (reinterpret_cast <StringHolder*> (1)->text) - 1));
  8288. }
  8289. };
  8290. StringHolder StringHolder::empty;
  8291. const String String::empty;
  8292. void String::createInternal (const juce_wchar* const t, const size_t numChars)
  8293. {
  8294. jassert (t[numChars] == 0); // must have a null terminator
  8295. text = StringHolder::create (numChars);
  8296. StringHolder::copyChars (text, t, numChars);
  8297. }
  8298. void String::appendInternal (const juce_wchar* const newText, const int numExtraChars)
  8299. {
  8300. if (numExtraChars > 0)
  8301. {
  8302. const int oldLen = length();
  8303. const int newTotalLen = oldLen + numExtraChars;
  8304. text = StringHolder::makeUniqueWithSize (text, newTotalLen);
  8305. StringHolder::copyChars (text + oldLen, newText, numExtraChars);
  8306. }
  8307. }
  8308. void String::preallocateStorage (const size_t numChars)
  8309. {
  8310. text = StringHolder::makeUniqueWithSize (text, numChars);
  8311. }
  8312. String::String() throw()
  8313. : text (StringHolder::getEmpty())
  8314. {
  8315. }
  8316. String::~String() throw()
  8317. {
  8318. StringHolder::release (text);
  8319. }
  8320. String::String (const String& other) throw()
  8321. : text (other.text)
  8322. {
  8323. StringHolder::retain (text);
  8324. }
  8325. void String::swapWith (String& other) throw()
  8326. {
  8327. swapVariables (text, other.text);
  8328. }
  8329. String& String::operator= (const String& other) throw()
  8330. {
  8331. juce_wchar* const newText = other.text;
  8332. StringHolder::retain (newText);
  8333. StringHolder::release (static_cast <juce_wchar*> (Atomic::swapPointers ((void* volatile*) &text, newText)));
  8334. return *this;
  8335. }
  8336. String::String (const size_t numChars, const int /*dummyVariable*/)
  8337. : text (StringHolder::create (numChars))
  8338. {
  8339. }
  8340. String::String (const String& stringToCopy, const size_t charsToAllocate)
  8341. {
  8342. const size_t otherSize = StringHolder::getAllocatedNumChars (stringToCopy.text);
  8343. text = StringHolder::create (jmax (charsToAllocate, otherSize));
  8344. StringHolder::copyChars (text, stringToCopy.text, otherSize);
  8345. }
  8346. String::String (const char* const t)
  8347. {
  8348. if (t != 0 && *t != 0)
  8349. {
  8350. const int len = CharacterFunctions::length (t);
  8351. text = StringHolder::create (len);
  8352. CharacterFunctions::copy (text, t, len + 1);
  8353. }
  8354. else
  8355. {
  8356. text = StringHolder::getEmpty();
  8357. }
  8358. }
  8359. String::String (const juce_wchar* const t)
  8360. {
  8361. if (t != 0 && *t != 0)
  8362. {
  8363. const int len = CharacterFunctions::length (t);
  8364. text = StringHolder::create (len);
  8365. StringHolder::copyChars (text, t, len);
  8366. }
  8367. else
  8368. {
  8369. text = StringHolder::getEmpty();
  8370. }
  8371. }
  8372. String::String (const char* const t, const size_t maxChars)
  8373. {
  8374. int i;
  8375. for (i = 0; (size_t) i < maxChars; ++i)
  8376. if (t[i] == 0)
  8377. break;
  8378. if (i > 0)
  8379. {
  8380. text = StringHolder::create (i);
  8381. CharacterFunctions::copy (text, t, i);
  8382. text[i] = 0;
  8383. }
  8384. else
  8385. {
  8386. text = StringHolder::getEmpty();
  8387. }
  8388. }
  8389. String::String (const juce_wchar* const t, const size_t maxChars)
  8390. {
  8391. int i;
  8392. for (i = 0; (size_t) i < maxChars; ++i)
  8393. if (t[i] == 0)
  8394. break;
  8395. if (i > 0)
  8396. {
  8397. text = StringHolder::create (i);
  8398. StringHolder::copyChars (text, t, i);
  8399. }
  8400. else
  8401. {
  8402. text = StringHolder::getEmpty();
  8403. }
  8404. }
  8405. const String String::charToString (const juce_wchar character)
  8406. {
  8407. juce_wchar temp[] = { character, 0 };
  8408. return String (temp);
  8409. }
  8410. namespace NumberToStringConverters
  8411. {
  8412. // pass in a pointer to the END of a buffer..
  8413. static juce_wchar* int64ToString (juce_wchar* t, const int64 n) throw()
  8414. {
  8415. *--t = 0;
  8416. int64 v = (n >= 0) ? n : -n;
  8417. do
  8418. {
  8419. *--t = (juce_wchar) (T('0') + (int) (v % 10));
  8420. v /= 10;
  8421. } while (v > 0);
  8422. if (n < 0)
  8423. *--t = T('-');
  8424. return t;
  8425. }
  8426. static juce_wchar* uint64ToString (juce_wchar* t, int64 v) throw()
  8427. {
  8428. *--t = 0;
  8429. do
  8430. {
  8431. *--t = (juce_wchar) (T('0') + (int) (v % 10));
  8432. v /= 10;
  8433. } while (v > 0);
  8434. return t;
  8435. }
  8436. static juce_wchar* intToString (juce_wchar* t, const int n) throw()
  8437. {
  8438. if (n == (int) 0x80000000) // (would cause an overflow)
  8439. return int64ToString (t, n);
  8440. *--t = 0;
  8441. int v = abs (n);
  8442. do
  8443. {
  8444. *--t = (juce_wchar) (T('0') + (v % 10));
  8445. v /= 10;
  8446. } while (v > 0);
  8447. if (n < 0)
  8448. *--t = T('-');
  8449. return t;
  8450. }
  8451. static juce_wchar* uintToString (juce_wchar* t, unsigned int v) throw()
  8452. {
  8453. *--t = 0;
  8454. do
  8455. {
  8456. *--t = (juce_wchar) (T('0') + (v % 10));
  8457. v /= 10;
  8458. } while (v > 0);
  8459. return t;
  8460. }
  8461. static juce_wchar getDecimalPoint()
  8462. {
  8463. #if JUCE_WINDOWS && _MSC_VER < 1400
  8464. static juce_wchar dp = std::_USE (std::locale(), std::numpunct <wchar_t>).decimal_point();
  8465. #else
  8466. static juce_wchar dp = std::use_facet <std::numpunct <wchar_t> > (std::locale()).decimal_point();
  8467. #endif
  8468. return dp;
  8469. }
  8470. static juce_wchar* doubleToString (juce_wchar* buffer, int numChars, double n, int numDecPlaces, size_t& len) throw()
  8471. {
  8472. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8473. {
  8474. juce_wchar* const end = buffer + numChars;
  8475. juce_wchar* t = end;
  8476. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8477. *--t = (juce_wchar) 0;
  8478. while (numDecPlaces >= 0 || v > 0)
  8479. {
  8480. if (numDecPlaces == 0)
  8481. *--t = getDecimalPoint();
  8482. *--t = (juce_wchar) (T('0') + (v % 10));
  8483. v /= 10;
  8484. --numDecPlaces;
  8485. }
  8486. if (n < 0)
  8487. *--t = T('-');
  8488. len = end - t - 1;
  8489. return t;
  8490. }
  8491. else
  8492. {
  8493. #if JUCE_WIN32
  8494. #if _MSC_VER <= 1200
  8495. len = _snwprintf (buffer, numChars, L"%.9g", n);
  8496. #else
  8497. len = _snwprintf_s (buffer, numChars, _TRUNCATE, L"%.9g", n);
  8498. #endif
  8499. #else
  8500. len = swprintf (buffer, numChars, L"%.9g", n);
  8501. #endif
  8502. return buffer;
  8503. }
  8504. }
  8505. }
  8506. String::String (const int number)
  8507. {
  8508. juce_wchar buffer [16];
  8509. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8510. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8511. createInternal (start, end - start - 1);
  8512. }
  8513. String::String (const unsigned int number)
  8514. {
  8515. juce_wchar buffer [16];
  8516. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8517. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8518. createInternal (start, end - start - 1);
  8519. }
  8520. String::String (const short number)
  8521. {
  8522. juce_wchar buffer [16];
  8523. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8524. juce_wchar* const start = NumberToStringConverters::intToString (end, (int) number);
  8525. createInternal (start, end - start - 1);
  8526. }
  8527. String::String (const unsigned short number)
  8528. {
  8529. juce_wchar buffer [16];
  8530. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8531. juce_wchar* const start = NumberToStringConverters::uintToString (end, (unsigned int) number);
  8532. createInternal (start, end - start - 1);
  8533. }
  8534. String::String (const int64 number)
  8535. {
  8536. juce_wchar buffer [32];
  8537. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8538. juce_wchar* const start = NumberToStringConverters::int64ToString (end, number);
  8539. createInternal (start, end - start - 1);
  8540. }
  8541. String::String (const uint64 number)
  8542. {
  8543. juce_wchar buffer [32];
  8544. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8545. juce_wchar* const start = NumberToStringConverters::uint64ToString (end, number);
  8546. createInternal (start, end - start - 1);
  8547. }
  8548. String::String (const float number, const int numberOfDecimalPlaces)
  8549. {
  8550. juce_wchar buffer [48];
  8551. size_t len;
  8552. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), (double) number, numberOfDecimalPlaces, len);
  8553. createInternal (start, len);
  8554. }
  8555. String::String (const double number, const int numberOfDecimalPlaces)
  8556. {
  8557. juce_wchar buffer [48];
  8558. size_t len;
  8559. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), number, numberOfDecimalPlaces, len);
  8560. createInternal (start, len);
  8561. }
  8562. int String::length() const throw()
  8563. {
  8564. return CharacterFunctions::length (text);
  8565. }
  8566. int String::hashCode() const throw()
  8567. {
  8568. const juce_wchar* t = text;
  8569. int result = 0;
  8570. while (*t != (juce_wchar) 0)
  8571. result = 31 * result + *t++;
  8572. return result;
  8573. }
  8574. int64 String::hashCode64() const throw()
  8575. {
  8576. const juce_wchar* t = text;
  8577. int64 result = 0;
  8578. while (*t != (juce_wchar) 0)
  8579. result = 101 * result + *t++;
  8580. return result;
  8581. }
  8582. bool JUCE_CALLTYPE operator== (const String& string1, const String& string2) throw()
  8583. {
  8584. return string1.compare (string2) == 0;
  8585. }
  8586. bool JUCE_CALLTYPE operator== (const String& string1, const char* string2) throw()
  8587. {
  8588. return string1.compare (string2) == 0;
  8589. }
  8590. bool JUCE_CALLTYPE operator== (const String& string1, const juce_wchar* string2) throw()
  8591. {
  8592. return string1.compare (string2) == 0;
  8593. }
  8594. bool JUCE_CALLTYPE operator!= (const String& string1, const String& string2) throw()
  8595. {
  8596. return string1.compare (string2) != 0;
  8597. }
  8598. bool JUCE_CALLTYPE operator!= (const String& string1, const char* string2) throw()
  8599. {
  8600. return string1.compare (string2) != 0;
  8601. }
  8602. bool JUCE_CALLTYPE operator!= (const String& string1, const juce_wchar* string2) throw()
  8603. {
  8604. return string1.compare (string2) != 0;
  8605. }
  8606. bool JUCE_CALLTYPE operator> (const String& string1, const String& string2) throw()
  8607. {
  8608. return string1.compare (string2) > 0;
  8609. }
  8610. bool JUCE_CALLTYPE operator< (const String& string1, const String& string2) throw()
  8611. {
  8612. return string1.compare (string2) < 0;
  8613. }
  8614. bool JUCE_CALLTYPE operator>= (const String& string1, const String& string2) throw()
  8615. {
  8616. return string1.compare (string2) >= 0;
  8617. }
  8618. bool JUCE_CALLTYPE operator<= (const String& string1, const String& string2) throw()
  8619. {
  8620. return string1.compare (string2) <= 0;
  8621. }
  8622. bool String::equalsIgnoreCase (const juce_wchar* t) const throw()
  8623. {
  8624. return t != 0 ? CharacterFunctions::compareIgnoreCase (text, t) == 0
  8625. : isEmpty();
  8626. }
  8627. bool String::equalsIgnoreCase (const String& other) const throw()
  8628. {
  8629. return text == other.text
  8630. || CharacterFunctions::compareIgnoreCase (text, other.text) == 0;
  8631. }
  8632. int String::compare (const String& other) const throw()
  8633. {
  8634. return (text == other.text) ? 0 : CharacterFunctions::compare (text, other.text);
  8635. }
  8636. int String::compare (const char* other) const throw()
  8637. {
  8638. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8639. }
  8640. int String::compare (const juce_wchar* other) const throw()
  8641. {
  8642. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8643. }
  8644. int String::compareIgnoreCase (const String& other) const throw()
  8645. {
  8646. return (text == other.text) ? 0 : CharacterFunctions::compareIgnoreCase (text, other.text);
  8647. }
  8648. int String::compareLexicographically (const String& other) const throw()
  8649. {
  8650. const juce_wchar* s1 = text;
  8651. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8652. ++s1;
  8653. const juce_wchar* s2 = other.text;
  8654. while (*s2 != 0 && ! CharacterFunctions::isLetterOrDigit (*s2))
  8655. ++s2;
  8656. return CharacterFunctions::compareIgnoreCase (s1, s2);
  8657. }
  8658. String& String::operator+= (const juce_wchar* const t)
  8659. {
  8660. if (t != 0)
  8661. appendInternal (t, CharacterFunctions::length (t));
  8662. return *this;
  8663. }
  8664. String& String::operator+= (const String& other)
  8665. {
  8666. if (isEmpty())
  8667. operator= (other);
  8668. else
  8669. appendInternal (other.text, other.length());
  8670. return *this;
  8671. }
  8672. String& String::operator+= (const char ch)
  8673. {
  8674. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8675. return operator+= ((const juce_wchar*) asString);
  8676. }
  8677. String& String::operator+= (const juce_wchar ch)
  8678. {
  8679. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8680. return operator+= ((const juce_wchar*) asString);
  8681. }
  8682. String& String::operator+= (const int number)
  8683. {
  8684. juce_wchar buffer [16];
  8685. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8686. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8687. appendInternal (start, (int) (end - start));
  8688. return *this;
  8689. }
  8690. String& String::operator+= (const unsigned int number)
  8691. {
  8692. juce_wchar buffer [16];
  8693. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8694. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8695. appendInternal (start, (int) (end - start));
  8696. return *this;
  8697. }
  8698. void String::append (const juce_wchar* const other, const int howMany)
  8699. {
  8700. if (howMany > 0)
  8701. {
  8702. int i;
  8703. for (i = 0; i < howMany; ++i)
  8704. if (other[i] == 0)
  8705. break;
  8706. appendInternal (other, i);
  8707. }
  8708. }
  8709. const String JUCE_CALLTYPE operator+ (const char* const string1, const String& string2)
  8710. {
  8711. String s (string1);
  8712. return s += string2;
  8713. }
  8714. const String JUCE_CALLTYPE operator+ (const juce_wchar* const string1, const String& string2)
  8715. {
  8716. String s (string1);
  8717. return s += string2;
  8718. }
  8719. const String JUCE_CALLTYPE operator+ (const char string1, const String& string2)
  8720. {
  8721. return String::charToString (string1) + string2;
  8722. }
  8723. const String JUCE_CALLTYPE operator+ (const juce_wchar string1, const String& string2)
  8724. {
  8725. return String::charToString (string1) + string2;
  8726. }
  8727. const String JUCE_CALLTYPE operator+ (String string1, const String& string2)
  8728. {
  8729. return string1 += string2;
  8730. }
  8731. const String JUCE_CALLTYPE operator+ (String string1, const char* const string2)
  8732. {
  8733. return string1 += string2;
  8734. }
  8735. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar* const string2)
  8736. {
  8737. return string1 += string2;
  8738. }
  8739. const String JUCE_CALLTYPE operator+ (String string1, const char string2)
  8740. {
  8741. return string1 += string2;
  8742. }
  8743. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar string2)
  8744. {
  8745. return string1 += string2;
  8746. }
  8747. String& JUCE_CALLTYPE operator<< (String& string1, const char characterToAppend)
  8748. {
  8749. return string1 += characterToAppend;
  8750. }
  8751. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar characterToAppend)
  8752. {
  8753. return string1 += characterToAppend;
  8754. }
  8755. String& JUCE_CALLTYPE operator<< (String& string1, const char* const string2)
  8756. {
  8757. return string1 += string2;
  8758. }
  8759. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar* const string2)
  8760. {
  8761. return string1 += string2;
  8762. }
  8763. String& JUCE_CALLTYPE operator<< (String& string1, const String& string2)
  8764. {
  8765. return string1 += string2;
  8766. }
  8767. String& JUCE_CALLTYPE operator<< (String& string1, const short number)
  8768. {
  8769. return string1 += (int) number;
  8770. }
  8771. String& JUCE_CALLTYPE operator<< (String& string1, const int number)
  8772. {
  8773. return string1 += number;
  8774. }
  8775. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned int number)
  8776. {
  8777. return string1 += number;
  8778. }
  8779. String& JUCE_CALLTYPE operator<< (String& string1, const long number)
  8780. {
  8781. return string1 += (int) number;
  8782. }
  8783. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned long number)
  8784. {
  8785. return string1 += (unsigned int) number;
  8786. }
  8787. String& JUCE_CALLTYPE operator<< (String& string1, const float number)
  8788. {
  8789. return string1 += String (number);
  8790. }
  8791. String& JUCE_CALLTYPE operator<< (String& string1, const double number)
  8792. {
  8793. return string1 += String (number);
  8794. }
  8795. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const String& text)
  8796. {
  8797. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  8798. // if lots of large, persistent strings were to be written to streams).
  8799. const int numBytes = text.getNumBytesAsUTF8();
  8800. HeapBlock<char> temp (numBytes + 1);
  8801. text.copyToUTF8 (temp, numBytes + 1);
  8802. stream.write (temp, numBytes);
  8803. return stream;
  8804. }
  8805. int String::indexOfChar (const juce_wchar character) const throw()
  8806. {
  8807. const juce_wchar* t = text;
  8808. for (;;)
  8809. {
  8810. if (*t == character)
  8811. return (int) (t - text);
  8812. if (*t++ == 0)
  8813. return -1;
  8814. }
  8815. }
  8816. int String::lastIndexOfChar (const juce_wchar character) const throw()
  8817. {
  8818. for (int i = length(); --i >= 0;)
  8819. if (text[i] == character)
  8820. return i;
  8821. return -1;
  8822. }
  8823. int String::indexOf (const juce_wchar* const t) const throw()
  8824. {
  8825. const juce_wchar* const r = CharacterFunctions::find (text, t);
  8826. return (r == 0) ? -1
  8827. : (int) (r - text);
  8828. }
  8829. int String::indexOfChar (const int startIndex,
  8830. const juce_wchar character) const throw()
  8831. {
  8832. if (startIndex >= 0 && startIndex >= length())
  8833. return -1;
  8834. const juce_wchar* t = text + jmax (0, startIndex);
  8835. for (;;)
  8836. {
  8837. if (*t == character)
  8838. return (int) (t - text);
  8839. if (*t == 0)
  8840. return -1;
  8841. ++t;
  8842. }
  8843. }
  8844. int String::indexOfAnyOf (const juce_wchar* const charactersToLookFor,
  8845. const int startIndex,
  8846. const bool ignoreCase) const throw()
  8847. {
  8848. if (charactersToLookFor == 0
  8849. || (startIndex >= 0 && startIndex >= length()))
  8850. return -1;
  8851. const juce_wchar* t = text + jmax (0, startIndex);
  8852. while (*t != 0)
  8853. {
  8854. if (CharacterFunctions::indexOfChar (charactersToLookFor, *t, ignoreCase) >= 0)
  8855. return (int) (t - text);
  8856. ++t;
  8857. }
  8858. return -1;
  8859. }
  8860. int String::indexOf (const int startIndex,
  8861. const juce_wchar* const other) const throw()
  8862. {
  8863. if (other == 0 || startIndex >= length())
  8864. return -1;
  8865. const juce_wchar* const found = CharacterFunctions::find (text + jmax (0, startIndex), other);
  8866. return (found == 0) ? -1
  8867. : (int) (found - text);
  8868. }
  8869. int String::indexOfIgnoreCase (const juce_wchar* const other) const throw()
  8870. {
  8871. if (other != 0 && *other != 0)
  8872. {
  8873. const int len = CharacterFunctions::length (other);
  8874. const int end = length() - len;
  8875. for (int i = 0; i <= end; ++i)
  8876. if (CharacterFunctions::compareIgnoreCase (text + i, other, len) == 0)
  8877. return i;
  8878. }
  8879. return -1;
  8880. }
  8881. int String::indexOfIgnoreCase (const int startIndex,
  8882. const juce_wchar* const other) const throw()
  8883. {
  8884. if (other != 0 && *other != 0)
  8885. {
  8886. const int len = CharacterFunctions::length (other);
  8887. const int end = length() - len;
  8888. for (int i = jmax (0, startIndex); i <= end; ++i)
  8889. if (CharacterFunctions::compareIgnoreCase (text + i, other, len) == 0)
  8890. return i;
  8891. }
  8892. return -1;
  8893. }
  8894. int String::lastIndexOf (const juce_wchar* const other) const throw()
  8895. {
  8896. if (other != 0 && *other != 0)
  8897. {
  8898. const int len = CharacterFunctions::length (other);
  8899. int i = length() - len;
  8900. if (i >= 0)
  8901. {
  8902. const juce_wchar* n = text + i;
  8903. while (i >= 0)
  8904. {
  8905. if (CharacterFunctions::compare (n--, other, len) == 0)
  8906. return i;
  8907. --i;
  8908. }
  8909. }
  8910. }
  8911. return -1;
  8912. }
  8913. int String::lastIndexOfIgnoreCase (const juce_wchar* const other) const throw()
  8914. {
  8915. if (other != 0 && *other != 0)
  8916. {
  8917. const int len = CharacterFunctions::length (other);
  8918. int i = length() - len;
  8919. if (i >= 0)
  8920. {
  8921. const juce_wchar* n = text + i;
  8922. while (i >= 0)
  8923. {
  8924. if (CharacterFunctions::compareIgnoreCase (n--, other, len) == 0)
  8925. return i;
  8926. --i;
  8927. }
  8928. }
  8929. }
  8930. return -1;
  8931. }
  8932. int String::lastIndexOfAnyOf (const juce_wchar* const charactersToLookFor,
  8933. const bool ignoreCase) const throw()
  8934. {
  8935. for (int i = length(); --i >= 0;)
  8936. if (CharacterFunctions::indexOfChar (charactersToLookFor, text[i], ignoreCase) >= 0)
  8937. return i;
  8938. return -1;
  8939. }
  8940. bool String::contains (const juce_wchar* const other) const throw()
  8941. {
  8942. return indexOf (other) >= 0;
  8943. }
  8944. bool String::containsChar (const juce_wchar character) const throw()
  8945. {
  8946. const juce_wchar* t = text;
  8947. for (;;)
  8948. {
  8949. if (*t == character)
  8950. return true;
  8951. if (*t == 0)
  8952. return false;
  8953. ++t;
  8954. }
  8955. }
  8956. bool String::containsIgnoreCase (const juce_wchar* const t) const throw()
  8957. {
  8958. return indexOfIgnoreCase (t) >= 0;
  8959. }
  8960. int String::indexOfWholeWord (const juce_wchar* const word) const throw()
  8961. {
  8962. if (word != 0 && *word != 0)
  8963. {
  8964. const int wordLen = CharacterFunctions::length (word);
  8965. const int end = length() - wordLen;
  8966. const juce_wchar* t = text;
  8967. for (int i = 0; i <= end; ++i)
  8968. {
  8969. if (CharacterFunctions::compare (t, word, wordLen) == 0
  8970. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  8971. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  8972. {
  8973. return i;
  8974. }
  8975. ++t;
  8976. }
  8977. }
  8978. return -1;
  8979. }
  8980. int String::indexOfWholeWordIgnoreCase (const juce_wchar* const word) const throw()
  8981. {
  8982. if (word != 0 && *word != 0)
  8983. {
  8984. const int wordLen = CharacterFunctions::length (word);
  8985. const int end = length() - wordLen;
  8986. const juce_wchar* t = text;
  8987. for (int i = 0; i <= end; ++i)
  8988. {
  8989. if (CharacterFunctions::compareIgnoreCase (t, word, wordLen) == 0
  8990. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  8991. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  8992. {
  8993. return i;
  8994. }
  8995. ++t;
  8996. }
  8997. }
  8998. return -1;
  8999. }
  9000. bool String::containsWholeWord (const juce_wchar* const wordToLookFor) const throw()
  9001. {
  9002. return indexOfWholeWord (wordToLookFor) >= 0;
  9003. }
  9004. bool String::containsWholeWordIgnoreCase (const juce_wchar* const wordToLookFor) const throw()
  9005. {
  9006. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  9007. }
  9008. static int indexOfMatch (const juce_wchar* const wildcard,
  9009. const juce_wchar* const test,
  9010. const bool ignoreCase) throw()
  9011. {
  9012. int start = 0;
  9013. while (test [start] != 0)
  9014. {
  9015. int i = 0;
  9016. for (;;)
  9017. {
  9018. const juce_wchar wc = wildcard [i];
  9019. const juce_wchar c = test [i + start];
  9020. if (wc == c
  9021. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9022. || (wc == T('?') && c != 0))
  9023. {
  9024. if (wc == 0)
  9025. return start;
  9026. ++i;
  9027. }
  9028. else
  9029. {
  9030. if (wc == T('*') && (wildcard [i + 1] == 0
  9031. || indexOfMatch (wildcard + i + 1,
  9032. test + start + i,
  9033. ignoreCase) >= 0))
  9034. {
  9035. return start;
  9036. }
  9037. break;
  9038. }
  9039. }
  9040. ++start;
  9041. }
  9042. return -1;
  9043. }
  9044. bool String::matchesWildcard (const juce_wchar* wildcard, const bool ignoreCase) const throw()
  9045. {
  9046. int i = 0;
  9047. for (;;)
  9048. {
  9049. const juce_wchar wc = wildcard [i];
  9050. const juce_wchar c = text [i];
  9051. if (wc == c
  9052. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9053. || (wc == T('?') && c != 0))
  9054. {
  9055. if (wc == 0)
  9056. return true;
  9057. ++i;
  9058. }
  9059. else
  9060. {
  9061. return wc == T('*') && (wildcard [i + 1] == 0
  9062. || indexOfMatch (wildcard + i + 1,
  9063. text + i,
  9064. ignoreCase) >= 0);
  9065. }
  9066. }
  9067. }
  9068. const String String::repeatedString (const juce_wchar* const stringToRepeat, int numberOfTimesToRepeat)
  9069. {
  9070. const int len = CharacterFunctions::length (stringToRepeat);
  9071. String result ((size_t) (len * numberOfTimesToRepeat + 1), (int) 0);
  9072. juce_wchar* n = result.text;
  9073. *n = 0;
  9074. while (--numberOfTimesToRepeat >= 0)
  9075. {
  9076. StringHolder::copyChars (n, stringToRepeat, len);
  9077. n += len;
  9078. }
  9079. return result;
  9080. }
  9081. const String String::paddedLeft (const juce_wchar padCharacter, int minimumLength) const
  9082. {
  9083. jassert (padCharacter != 0);
  9084. const int len = length();
  9085. if (len >= minimumLength || padCharacter == 0)
  9086. return *this;
  9087. String result ((size_t) minimumLength + 1, (int) 0);
  9088. juce_wchar* n = result.text;
  9089. minimumLength -= len;
  9090. while (--minimumLength >= 0)
  9091. *n++ = padCharacter;
  9092. StringHolder::copyChars (n, text, len);
  9093. return result;
  9094. }
  9095. const String String::paddedRight (const juce_wchar padCharacter, int minimumLength) const
  9096. {
  9097. jassert (padCharacter != 0);
  9098. const int len = length();
  9099. if (len >= minimumLength || padCharacter == 0)
  9100. return *this;
  9101. String result (*this, (size_t) minimumLength);
  9102. juce_wchar* n = result.text + len;
  9103. minimumLength -= len;
  9104. while (--minimumLength >= 0)
  9105. *n++ = padCharacter;
  9106. *n = 0;
  9107. return result;
  9108. }
  9109. const String String::replaceSection (int index, int numCharsToReplace,
  9110. const juce_wchar* const stringToInsert) const
  9111. {
  9112. if (index < 0)
  9113. {
  9114. // a negative index to replace from?
  9115. jassertfalse
  9116. index = 0;
  9117. }
  9118. if (numCharsToReplace < 0)
  9119. {
  9120. // replacing a negative number of characters?
  9121. numCharsToReplace = 0;
  9122. jassertfalse;
  9123. }
  9124. const int len = length();
  9125. if (index + numCharsToReplace > len)
  9126. {
  9127. if (index > len)
  9128. {
  9129. // replacing beyond the end of the string?
  9130. index = len;
  9131. jassertfalse
  9132. }
  9133. numCharsToReplace = len - index;
  9134. }
  9135. const int newStringLen = (stringToInsert != 0) ? CharacterFunctions::length (stringToInsert) : 0;
  9136. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9137. if (newTotalLen <= 0)
  9138. return String::empty;
  9139. String result ((size_t) newTotalLen, (int) 0);
  9140. StringHolder::copyChars (result.text, text, index);
  9141. if (newStringLen > 0)
  9142. StringHolder::copyChars (result.text + index, stringToInsert, newStringLen);
  9143. const int endStringLen = newTotalLen - (index + newStringLen);
  9144. if (endStringLen > 0)
  9145. StringHolder::copyChars (result.text + (index + newStringLen),
  9146. text + (index + numCharsToReplace),
  9147. endStringLen);
  9148. return result;
  9149. }
  9150. const String String::replace (const juce_wchar* const stringToReplace,
  9151. const juce_wchar* const stringToInsert,
  9152. const bool ignoreCase) const
  9153. {
  9154. const int stringToReplaceLen = CharacterFunctions::length (stringToReplace);
  9155. const int stringToInsertLen = CharacterFunctions::length (stringToInsert);
  9156. int i = 0;
  9157. String result (*this);
  9158. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9159. : result.indexOf (i, stringToReplace))) >= 0)
  9160. {
  9161. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9162. i += stringToInsertLen;
  9163. }
  9164. return result;
  9165. }
  9166. const String String::replaceCharacter (const juce_wchar charToReplace, const juce_wchar charToInsert) const
  9167. {
  9168. const int index = indexOfChar (charToReplace);
  9169. if (index < 0)
  9170. return *this;
  9171. String result (*this, size_t());
  9172. juce_wchar* t = result.text + index;
  9173. while (*t != 0)
  9174. {
  9175. if (*t == charToReplace)
  9176. *t = charToInsert;
  9177. ++t;
  9178. }
  9179. return result;
  9180. }
  9181. const String String::replaceCharacters (const String& charactersToReplace,
  9182. const juce_wchar* const charactersToInsertInstead) const
  9183. {
  9184. String result (*this, size_t());
  9185. juce_wchar* t = result.text;
  9186. const int len2 = CharacterFunctions::length (charactersToInsertInstead);
  9187. // the two strings passed in are supposed to be the same length!
  9188. jassert (len2 == charactersToReplace.length());
  9189. while (*t != 0)
  9190. {
  9191. const int index = charactersToReplace.indexOfChar (*t);
  9192. if (((unsigned int) index) < (unsigned int) len2)
  9193. *t = charactersToInsertInstead [index];
  9194. ++t;
  9195. }
  9196. return result;
  9197. }
  9198. bool String::startsWith (const juce_wchar* const other) const throw()
  9199. {
  9200. return other != 0
  9201. && CharacterFunctions::compare (text, other, CharacterFunctions::length (other)) == 0;
  9202. }
  9203. bool String::startsWithIgnoreCase (const juce_wchar* const other) const throw()
  9204. {
  9205. return other != 0
  9206. && CharacterFunctions::compareIgnoreCase (text, other, CharacterFunctions::length (other)) == 0;
  9207. }
  9208. bool String::startsWithChar (const juce_wchar character) const throw()
  9209. {
  9210. jassert (character != 0); // strings can't contain a null character!
  9211. return text[0] == character;
  9212. }
  9213. bool String::endsWithChar (const juce_wchar character) const throw()
  9214. {
  9215. jassert (character != 0); // strings can't contain a null character!
  9216. return text[0] != 0
  9217. && text [length() - 1] == character;
  9218. }
  9219. bool String::endsWith (const juce_wchar* const other) const throw()
  9220. {
  9221. if (other == 0)
  9222. return false;
  9223. const int thisLen = length();
  9224. const int otherLen = CharacterFunctions::length (other);
  9225. return thisLen >= otherLen
  9226. && CharacterFunctions::compare (text + thisLen - otherLen, other) == 0;
  9227. }
  9228. bool String::endsWithIgnoreCase (const juce_wchar* const other) const throw()
  9229. {
  9230. if (other == 0)
  9231. return false;
  9232. const int thisLen = length();
  9233. const int otherLen = CharacterFunctions::length (other);
  9234. return thisLen >= otherLen
  9235. && CharacterFunctions::compareIgnoreCase (text + thisLen - otherLen, other) == 0;
  9236. }
  9237. const String String::toUpperCase() const
  9238. {
  9239. String result (*this, size_t());
  9240. CharacterFunctions::toUpperCase (result.text);
  9241. return result;
  9242. }
  9243. const String String::toLowerCase() const
  9244. {
  9245. String result (*this, size_t());
  9246. CharacterFunctions::toLowerCase (result.text);
  9247. return result;
  9248. }
  9249. juce_wchar& String::operator[] (const int index)
  9250. {
  9251. jassert (((unsigned int) index) <= (unsigned int) length());
  9252. text = StringHolder::makeUnique (text);
  9253. return text [index];
  9254. }
  9255. juce_wchar String::getLastCharacter() const throw()
  9256. {
  9257. return isEmpty() ? juce_wchar() : text [length() - 1];
  9258. }
  9259. const String String::substring (int start, int end) const
  9260. {
  9261. if (start < 0)
  9262. start = 0;
  9263. else if (end <= start)
  9264. return empty;
  9265. int len = 0;
  9266. const juce_wchar* const t = text;
  9267. while (len <= end && t [len] != 0)
  9268. ++len;
  9269. if (end >= len)
  9270. {
  9271. if (start == 0)
  9272. return *this;
  9273. end = len;
  9274. }
  9275. return String (text + start, end - start);
  9276. }
  9277. const String String::substring (const int start) const
  9278. {
  9279. if (start <= 0)
  9280. return *this;
  9281. const int len = length();
  9282. if (start >= len)
  9283. return empty;
  9284. else
  9285. return String (text + start, len - start);
  9286. }
  9287. const String String::dropLastCharacters (const int numberToDrop) const
  9288. {
  9289. return String (text, jmax (0, length() - numberToDrop));
  9290. }
  9291. const String String::getLastCharacters (const int numCharacters) const
  9292. {
  9293. return String (text + jmax (0, length() - jmax (0, numCharacters)));
  9294. }
  9295. const String String::fromFirstOccurrenceOf (const juce_wchar* const sub,
  9296. const bool includeSubString,
  9297. const bool ignoreCase) const
  9298. {
  9299. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9300. : indexOf (sub);
  9301. if (i < 0)
  9302. return empty;
  9303. else
  9304. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9305. }
  9306. const String String::fromLastOccurrenceOf (const juce_wchar* const sub,
  9307. const bool includeSubString,
  9308. const bool ignoreCase) const
  9309. {
  9310. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9311. : lastIndexOf (sub);
  9312. if (i < 0)
  9313. return *this;
  9314. else
  9315. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9316. }
  9317. const String String::upToFirstOccurrenceOf (const juce_wchar* const sub,
  9318. const bool includeSubString,
  9319. const bool ignoreCase) const
  9320. {
  9321. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9322. : indexOf (sub);
  9323. if (i < 0)
  9324. return *this;
  9325. else
  9326. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9327. }
  9328. const String String::upToLastOccurrenceOf (const juce_wchar* const sub,
  9329. const bool includeSubString,
  9330. const bool ignoreCase) const
  9331. {
  9332. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9333. : lastIndexOf (sub);
  9334. if (i < 0)
  9335. return *this;
  9336. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9337. }
  9338. bool String::isQuotedString() const
  9339. {
  9340. const String trimmed (trimStart());
  9341. return trimmed[0] == T('"')
  9342. || trimmed[0] == T('\'');
  9343. }
  9344. const String String::unquoted() const
  9345. {
  9346. String s (*this);
  9347. if (s.text[0] == T('"') || s.text[0] == T('\''))
  9348. s = s.substring (1);
  9349. const int lastCharIndex = s.length() - 1;
  9350. if (lastCharIndex >= 0
  9351. && (s [lastCharIndex] == T('"') || s[lastCharIndex] == T('\'')))
  9352. s [lastCharIndex] = 0;
  9353. return s;
  9354. }
  9355. const String String::quoted (const juce_wchar quoteCharacter) const
  9356. {
  9357. if (isEmpty())
  9358. return charToString (quoteCharacter) + quoteCharacter;
  9359. String t (*this);
  9360. if (! t.startsWithChar (quoteCharacter))
  9361. t = charToString (quoteCharacter) + t;
  9362. if (! t.endsWithChar (quoteCharacter))
  9363. t += quoteCharacter;
  9364. return t;
  9365. }
  9366. const String String::trim() const
  9367. {
  9368. if (isEmpty())
  9369. return empty;
  9370. int start = 0;
  9371. while (CharacterFunctions::isWhitespace (text [start]))
  9372. ++start;
  9373. const int len = length();
  9374. int end = len - 1;
  9375. while ((end >= start) && CharacterFunctions::isWhitespace (text [end]))
  9376. --end;
  9377. ++end;
  9378. if (end <= start)
  9379. return empty;
  9380. else if (start > 0 || end < len)
  9381. return String (text + start, end - start);
  9382. else
  9383. return *this;
  9384. }
  9385. const String String::trimStart() const
  9386. {
  9387. if (isEmpty())
  9388. return empty;
  9389. const juce_wchar* t = text;
  9390. while (CharacterFunctions::isWhitespace (*t))
  9391. ++t;
  9392. if (t == text)
  9393. return *this;
  9394. else
  9395. return String (t);
  9396. }
  9397. const String String::trimEnd() const
  9398. {
  9399. if (isEmpty())
  9400. return empty;
  9401. const juce_wchar* endT = text + (length() - 1);
  9402. while ((endT >= text) && CharacterFunctions::isWhitespace (*endT))
  9403. --endT;
  9404. return String (text, (int) (++endT - text));
  9405. }
  9406. const String String::trimCharactersAtStart (const juce_wchar* charactersToTrim) const
  9407. {
  9408. jassert (charactersToTrim != 0);
  9409. if (isEmpty())
  9410. return empty;
  9411. const juce_wchar* t = text;
  9412. while (CharacterFunctions::indexOfCharFast (charactersToTrim, *t) >= 0)
  9413. ++t;
  9414. if (t == text)
  9415. return *this;
  9416. else
  9417. return String (t);
  9418. }
  9419. const String String::trimCharactersAtEnd (const juce_wchar* charactersToTrim) const
  9420. {
  9421. jassert (charactersToTrim != 0);
  9422. if (isEmpty())
  9423. return empty;
  9424. const juce_wchar* endT = text + (length() - 1);
  9425. while ((endT >= text) && CharacterFunctions::indexOfCharFast (charactersToTrim, *endT) >= 0)
  9426. --endT;
  9427. return String (text, (int) (++endT - text));
  9428. }
  9429. const String String::retainCharacters (const juce_wchar* const charactersToRetain) const
  9430. {
  9431. jassert (charactersToRetain != 0);
  9432. if (isEmpty())
  9433. return empty;
  9434. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9435. juce_wchar* dst = result.text;
  9436. const juce_wchar* src = text;
  9437. while (*src != 0)
  9438. {
  9439. if (CharacterFunctions::indexOfCharFast (charactersToRetain, *src) >= 0)
  9440. *dst++ = *src;
  9441. ++src;
  9442. }
  9443. *dst = 0;
  9444. return result;
  9445. }
  9446. const String String::removeCharacters (const juce_wchar* const charactersToRemove) const
  9447. {
  9448. jassert (charactersToRemove != 0);
  9449. if (isEmpty())
  9450. return empty;
  9451. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9452. juce_wchar* dst = result.text;
  9453. const juce_wchar* src = text;
  9454. while (*src != 0)
  9455. {
  9456. if (CharacterFunctions::indexOfCharFast (charactersToRemove, *src) < 0)
  9457. *dst++ = *src;
  9458. ++src;
  9459. }
  9460. *dst = 0;
  9461. return result;
  9462. }
  9463. const String String::initialSectionContainingOnly (const juce_wchar* const permittedCharacters) const
  9464. {
  9465. return substring (0, CharacterFunctions::getIntialSectionContainingOnly (text, permittedCharacters));
  9466. }
  9467. const String String::initialSectionNotContaining (const juce_wchar* const charactersToStopAt) const
  9468. {
  9469. jassert (charactersToStopAt != 0);
  9470. const juce_wchar* const t = text;
  9471. int i = 0;
  9472. while (t[i] != 0)
  9473. {
  9474. if (CharacterFunctions::indexOfCharFast (charactersToStopAt, t[i]) >= 0)
  9475. return String (text, i);
  9476. ++i;
  9477. }
  9478. return empty;
  9479. }
  9480. bool String::containsOnly (const juce_wchar* const chars) const throw()
  9481. {
  9482. jassert (chars != 0);
  9483. const juce_wchar* t = text;
  9484. while (*t != 0)
  9485. if (CharacterFunctions::indexOfCharFast (chars, *t++) < 0)
  9486. return false;
  9487. return true;
  9488. }
  9489. bool String::containsAnyOf (const juce_wchar* const chars) const throw()
  9490. {
  9491. jassert (chars != 0);
  9492. const juce_wchar* t = text;
  9493. while (*t != 0)
  9494. if (CharacterFunctions::indexOfCharFast (chars, *t++) >= 0)
  9495. return true;
  9496. return false;
  9497. }
  9498. bool String::containsNonWhitespaceChars() const throw()
  9499. {
  9500. const juce_wchar* t = text;
  9501. while (*t != 0)
  9502. if (! CharacterFunctions::isWhitespace (*t++))
  9503. return true;
  9504. return false;
  9505. }
  9506. const String String::formatted (const juce_wchar* const pf, ... )
  9507. {
  9508. jassert (pf != 0);
  9509. va_list args;
  9510. va_start (args, pf);
  9511. size_t bufferSize = 256;
  9512. String result (bufferSize, (int) 0);
  9513. result.text[0] = 0;
  9514. for (;;)
  9515. {
  9516. #if JUCE_LINUX && JUCE_64BIT
  9517. va_list tempArgs;
  9518. va_copy (tempArgs, args);
  9519. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, tempArgs);
  9520. va_end (tempArgs);
  9521. #elif JUCE_WINDOWS
  9522. const int num = (int) _vsnwprintf (result.text, bufferSize - 1, pf, args);
  9523. #else
  9524. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, args);
  9525. #endif
  9526. if (num > 0)
  9527. return result;
  9528. bufferSize += 256;
  9529. if (num == 0 || bufferSize > 65536) // the upper limit is a sanity check to avoid situations where vprintf repeatedly
  9530. break; // returns -1 because of an error rather than because it needs more space.
  9531. result.preallocateStorage (bufferSize);
  9532. }
  9533. return empty;
  9534. }
  9535. int String::getIntValue() const throw()
  9536. {
  9537. return CharacterFunctions::getIntValue (text);
  9538. }
  9539. int String::getTrailingIntValue() const throw()
  9540. {
  9541. int n = 0;
  9542. int mult = 1;
  9543. const juce_wchar* t = text + length();
  9544. while (--t >= text)
  9545. {
  9546. const juce_wchar c = *t;
  9547. if (! CharacterFunctions::isDigit (c))
  9548. {
  9549. if (c == T('-'))
  9550. n = -n;
  9551. break;
  9552. }
  9553. n += mult * (c - T('0'));
  9554. mult *= 10;
  9555. }
  9556. return n;
  9557. }
  9558. int64 String::getLargeIntValue() const throw()
  9559. {
  9560. return CharacterFunctions::getInt64Value (text);
  9561. }
  9562. float String::getFloatValue() const throw()
  9563. {
  9564. return (float) CharacterFunctions::getDoubleValue (text);
  9565. }
  9566. double String::getDoubleValue() const throw()
  9567. {
  9568. return CharacterFunctions::getDoubleValue (text);
  9569. }
  9570. static const juce_wchar* const hexDigits = T("0123456789abcdef");
  9571. const String String::toHexString (const int number)
  9572. {
  9573. juce_wchar buffer[32];
  9574. juce_wchar* const end = buffer + 32;
  9575. juce_wchar* t = end;
  9576. *--t = 0;
  9577. unsigned int v = (unsigned int) number;
  9578. do
  9579. {
  9580. *--t = hexDigits [v & 15];
  9581. v >>= 4;
  9582. } while (v != 0);
  9583. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9584. }
  9585. const String String::toHexString (const int64 number)
  9586. {
  9587. juce_wchar buffer[32];
  9588. juce_wchar* const end = buffer + 32;
  9589. juce_wchar* t = end;
  9590. *--t = 0;
  9591. uint64 v = (uint64) number;
  9592. do
  9593. {
  9594. *--t = hexDigits [(int) (v & 15)];
  9595. v >>= 4;
  9596. } while (v != 0);
  9597. return String (t, (int) (((char*) end) - (char*) t));
  9598. }
  9599. const String String::toHexString (const short number)
  9600. {
  9601. return toHexString ((int) (unsigned short) number);
  9602. }
  9603. const String String::toHexString (const unsigned char* data,
  9604. const int size,
  9605. const int groupSize)
  9606. {
  9607. if (size <= 0)
  9608. return empty;
  9609. int numChars = (size * 2) + 2;
  9610. if (groupSize > 0)
  9611. numChars += size / groupSize;
  9612. String s ((size_t) numChars, (int) 0);
  9613. juce_wchar* d = s.text;
  9614. for (int i = 0; i < size; ++i)
  9615. {
  9616. *d++ = hexDigits [(*data) >> 4];
  9617. *d++ = hexDigits [(*data) & 0xf];
  9618. ++data;
  9619. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9620. *d++ = T(' ');
  9621. }
  9622. *d = 0;
  9623. return s;
  9624. }
  9625. int String::getHexValue32() const throw()
  9626. {
  9627. int result = 0;
  9628. const juce_wchar* c = text;
  9629. for (;;)
  9630. {
  9631. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9632. if (hexValue >= 0)
  9633. result = (result << 4) | hexValue;
  9634. else if (*c == 0)
  9635. break;
  9636. ++c;
  9637. }
  9638. return result;
  9639. }
  9640. int64 String::getHexValue64() const throw()
  9641. {
  9642. int64 result = 0;
  9643. const juce_wchar* c = text;
  9644. for (;;)
  9645. {
  9646. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9647. if (hexValue >= 0)
  9648. result = (result << 4) | hexValue;
  9649. else if (*c == 0)
  9650. break;
  9651. ++c;
  9652. }
  9653. return result;
  9654. }
  9655. const String String::createStringFromData (const void* const data_, const int size)
  9656. {
  9657. const char* const data = (const char*) data_;
  9658. if (size <= 0 || data == 0)
  9659. {
  9660. return empty;
  9661. }
  9662. else if (size < 2)
  9663. {
  9664. return charToString (data[0]);
  9665. }
  9666. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9667. || (data[0] == (char)-1 && data[1] == (char)-2))
  9668. {
  9669. // assume it's 16-bit unicode
  9670. const bool bigEndian = (data[0] == (char)-2);
  9671. const int numChars = size / 2 - 1;
  9672. String result;
  9673. result.preallocateStorage (numChars + 2);
  9674. const uint16* const src = (const uint16*) (data + 2);
  9675. juce_wchar* const dst = const_cast <juce_wchar*> ((const juce_wchar*) result);
  9676. if (bigEndian)
  9677. {
  9678. for (int i = 0; i < numChars; ++i)
  9679. dst[i] = (juce_wchar) ByteOrder::swapIfLittleEndian (src[i]);
  9680. }
  9681. else
  9682. {
  9683. for (int i = 0; i < numChars; ++i)
  9684. dst[i] = (juce_wchar) ByteOrder::swapIfBigEndian (src[i]);
  9685. }
  9686. dst [numChars] = 0;
  9687. return result;
  9688. }
  9689. else
  9690. {
  9691. return String::fromUTF8 (data, size);
  9692. }
  9693. }
  9694. const char* String::toUTF8() const
  9695. {
  9696. if (isEmpty())
  9697. {
  9698. return reinterpret_cast <const char*> (text);
  9699. }
  9700. else
  9701. {
  9702. const int currentLen = length() + 1;
  9703. const int utf8BytesNeeded = getNumBytesAsUTF8();
  9704. String* const mutableThis = const_cast <String*> (this);
  9705. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, currentLen + 1 + utf8BytesNeeded / sizeof (juce_wchar));
  9706. char* const otherCopy = (char*) (text + currentLen);
  9707. copyToUTF8 (otherCopy, std::numeric_limits<int>::max());
  9708. return otherCopy;
  9709. }
  9710. }
  9711. int String::copyToUTF8 (char* const buffer, const int maxBufferSizeBytes) const throw()
  9712. {
  9713. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9714. int num = 0, index = 0;
  9715. for (;;)
  9716. {
  9717. const uint32 c = (uint32) text [index++];
  9718. if (c >= 0x80)
  9719. {
  9720. int numExtraBytes = 1;
  9721. if (c >= 0x800)
  9722. {
  9723. ++numExtraBytes;
  9724. if (c >= 0x10000)
  9725. {
  9726. ++numExtraBytes;
  9727. if (c >= 0x200000)
  9728. {
  9729. ++numExtraBytes;
  9730. if (c >= 0x4000000)
  9731. ++numExtraBytes;
  9732. }
  9733. }
  9734. }
  9735. if (buffer != 0)
  9736. {
  9737. if (num + numExtraBytes >= maxBufferSizeBytes)
  9738. {
  9739. buffer [num++] = 0;
  9740. break;
  9741. }
  9742. else
  9743. {
  9744. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  9745. while (--numExtraBytes >= 0)
  9746. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  9747. }
  9748. }
  9749. else
  9750. {
  9751. num += numExtraBytes + 1;
  9752. }
  9753. }
  9754. else
  9755. {
  9756. if (buffer != 0)
  9757. {
  9758. if (num + 1 >= maxBufferSizeBytes)
  9759. {
  9760. buffer [num++] = 0;
  9761. break;
  9762. }
  9763. buffer [num] = (uint8) c;
  9764. }
  9765. ++num;
  9766. }
  9767. if (c == 0)
  9768. break;
  9769. }
  9770. return num;
  9771. }
  9772. int String::getNumBytesAsUTF8() const throw()
  9773. {
  9774. int num = 0;
  9775. const juce_wchar* t = text;
  9776. for (;;)
  9777. {
  9778. const uint32 c = (uint32) *t;
  9779. if (c >= 0x80)
  9780. {
  9781. ++num;
  9782. if (c >= 0x800)
  9783. {
  9784. ++num;
  9785. if (c >= 0x10000)
  9786. {
  9787. ++num;
  9788. if (c >= 0x200000)
  9789. {
  9790. ++num;
  9791. if (c >= 0x4000000)
  9792. ++num;
  9793. }
  9794. }
  9795. }
  9796. }
  9797. else if (c == 0)
  9798. break;
  9799. ++num;
  9800. ++t;
  9801. }
  9802. return num;
  9803. }
  9804. const String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
  9805. {
  9806. if (buffer == 0)
  9807. return empty;
  9808. if (bufferSizeBytes < 0)
  9809. bufferSizeBytes = std::numeric_limits<int>::max();
  9810. size_t numBytes;
  9811. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  9812. if (buffer [numBytes] == 0)
  9813. break;
  9814. String result ((size_t) numBytes + 1, (int) 0);
  9815. juce_wchar* dest = result.text;
  9816. size_t i = 0;
  9817. while (i < numBytes)
  9818. {
  9819. const char c = buffer [i++];
  9820. if (c < 0)
  9821. {
  9822. unsigned int mask = 0x7f;
  9823. int bit = 0x40;
  9824. int numExtraValues = 0;
  9825. while (bit != 0 && (c & bit) != 0)
  9826. {
  9827. bit >>= 1;
  9828. mask >>= 1;
  9829. ++numExtraValues;
  9830. }
  9831. int n = (mask & (unsigned char) c);
  9832. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  9833. {
  9834. const char nextByte = buffer[i];
  9835. if ((nextByte & 0xc0) != 0x80)
  9836. break;
  9837. n <<= 6;
  9838. n |= (nextByte & 0x3f);
  9839. ++i;
  9840. }
  9841. *dest++ = (juce_wchar) n;
  9842. }
  9843. else
  9844. {
  9845. *dest++ = (juce_wchar) c;
  9846. }
  9847. }
  9848. *dest = 0;
  9849. return result;
  9850. }
  9851. const char* String::toCString() const
  9852. {
  9853. if (isEmpty())
  9854. {
  9855. return reinterpret_cast <const char*> (text);
  9856. }
  9857. else
  9858. {
  9859. int len = length();
  9860. String* const mutableThis = const_cast <String*> (this);
  9861. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, (len + 1) * 2);
  9862. char* otherCopy = (char*) (text + len + 1);
  9863. CharacterFunctions::copy (otherCopy, text, len);
  9864. otherCopy [len] = 0;
  9865. return otherCopy;
  9866. }
  9867. }
  9868. #ifdef _MSC_VER
  9869. #pragma warning (disable: 4514 4996)
  9870. #pragma warning (push)
  9871. #endif
  9872. int String::getNumBytesAsCString() const throw()
  9873. {
  9874. return (int) wcstombs (0, text, 0);
  9875. }
  9876. int String::copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw()
  9877. {
  9878. const int numBytes = (int) wcstombs (destBuffer, text, maxBufferSizeBytes);
  9879. if (destBuffer != 0 && numBytes >= 0)
  9880. destBuffer [numBytes] = 0;
  9881. return numBytes;
  9882. }
  9883. #ifdef _MSC_VER
  9884. #pragma warning (pop)
  9885. #endif
  9886. void String::copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw()
  9887. {
  9888. StringHolder::copyChars (destBuffer, text, jmin (maxCharsToCopy, length()));
  9889. }
  9890. String::Concatenator::Concatenator (String& stringToAppendTo)
  9891. : result (stringToAppendTo),
  9892. nextIndex (stringToAppendTo.length())
  9893. {
  9894. }
  9895. String::Concatenator::~Concatenator()
  9896. {
  9897. }
  9898. void String::Concatenator::append (const String& s)
  9899. {
  9900. const int len = s.length();
  9901. if (len > 0)
  9902. {
  9903. result.preallocateStorage (nextIndex + len);
  9904. s.copyToUnicode (((juce_wchar*) result) + nextIndex, len);
  9905. nextIndex += len;
  9906. }
  9907. }
  9908. END_JUCE_NAMESPACE
  9909. /*** End of inlined file: juce_String.cpp ***/
  9910. /*** Start of inlined file: juce_StringArray.cpp ***/
  9911. BEGIN_JUCE_NAMESPACE
  9912. StringArray::StringArray() throw()
  9913. {
  9914. }
  9915. StringArray::StringArray (const StringArray& other)
  9916. : strings (other.strings)
  9917. {
  9918. }
  9919. StringArray::StringArray (const juce_wchar** const initialStrings,
  9920. const int numberOfStrings)
  9921. {
  9922. for (int i = 0; i < numberOfStrings; ++i)
  9923. add (initialStrings [i]);
  9924. }
  9925. StringArray::StringArray (const char** const initialStrings,
  9926. const int numberOfStrings)
  9927. {
  9928. for (int i = 0; i < numberOfStrings; ++i)
  9929. add (initialStrings [i]);
  9930. }
  9931. StringArray::StringArray (const juce_wchar** const initialStrings)
  9932. {
  9933. int i = 0;
  9934. while (initialStrings[i] != 0)
  9935. add (initialStrings [i++]);
  9936. }
  9937. StringArray::StringArray (const char** const initialStrings)
  9938. {
  9939. int i = 0;
  9940. while (initialStrings[i] != 0)
  9941. add (initialStrings [i++]);
  9942. }
  9943. StringArray& StringArray::operator= (const StringArray& other)
  9944. {
  9945. strings = other.strings;
  9946. return *this;
  9947. }
  9948. StringArray::~StringArray()
  9949. {
  9950. }
  9951. bool StringArray::operator== (const StringArray& other) const
  9952. {
  9953. if (other.size() != size())
  9954. return false;
  9955. for (int i = size(); --i >= 0;)
  9956. if (other.strings.getReference(i) != strings.getReference(i))
  9957. return false;
  9958. return true;
  9959. }
  9960. bool StringArray::operator!= (const StringArray& other) const
  9961. {
  9962. return ! operator== (other);
  9963. }
  9964. void StringArray::clear()
  9965. {
  9966. strings.clear();
  9967. }
  9968. const String& StringArray::operator[] (const int index) const throw()
  9969. {
  9970. if (((unsigned int) index) < (unsigned int) strings.size())
  9971. return strings.getReference (index);
  9972. return String::empty;
  9973. }
  9974. void StringArray::add (const String& newString)
  9975. {
  9976. strings.add (newString);
  9977. }
  9978. void StringArray::insert (const int index, const String& newString)
  9979. {
  9980. strings.insert (index, newString);
  9981. }
  9982. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  9983. {
  9984. if (! contains (newString, ignoreCase))
  9985. add (newString);
  9986. }
  9987. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  9988. {
  9989. if (startIndex < 0)
  9990. {
  9991. jassertfalse
  9992. startIndex = 0;
  9993. }
  9994. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  9995. numElementsToAdd = otherArray.size() - startIndex;
  9996. while (--numElementsToAdd >= 0)
  9997. strings.add (otherArray.strings.getReference (startIndex++));
  9998. }
  9999. void StringArray::set (const int index, const String& newString)
  10000. {
  10001. strings.set (index, newString);
  10002. }
  10003. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  10004. {
  10005. if (ignoreCase)
  10006. {
  10007. for (int i = size(); --i >= 0;)
  10008. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10009. return true;
  10010. }
  10011. else
  10012. {
  10013. for (int i = size(); --i >= 0;)
  10014. if (stringToLookFor == strings.getReference(i))
  10015. return true;
  10016. }
  10017. return false;
  10018. }
  10019. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  10020. {
  10021. if (i < 0)
  10022. i = 0;
  10023. const int numElements = size();
  10024. if (ignoreCase)
  10025. {
  10026. while (i < numElements)
  10027. {
  10028. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10029. return i;
  10030. ++i;
  10031. }
  10032. }
  10033. else
  10034. {
  10035. while (i < numElements)
  10036. {
  10037. if (stringToLookFor == strings.getReference (i))
  10038. return i;
  10039. ++i;
  10040. }
  10041. }
  10042. return -1;
  10043. }
  10044. void StringArray::remove (const int index)
  10045. {
  10046. strings.remove (index);
  10047. }
  10048. void StringArray::removeString (const String& stringToRemove,
  10049. const bool ignoreCase)
  10050. {
  10051. if (ignoreCase)
  10052. {
  10053. for (int i = size(); --i >= 0;)
  10054. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  10055. strings.remove (i);
  10056. }
  10057. else
  10058. {
  10059. for (int i = size(); --i >= 0;)
  10060. if (stringToRemove == strings.getReference (i))
  10061. strings.remove (i);
  10062. }
  10063. }
  10064. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  10065. {
  10066. if (removeWhitespaceStrings)
  10067. {
  10068. for (int i = size(); --i >= 0;)
  10069. if (! strings.getReference(i).containsNonWhitespaceChars())
  10070. strings.remove (i);
  10071. }
  10072. else
  10073. {
  10074. for (int i = size(); --i >= 0;)
  10075. if (strings.getReference(i).isEmpty())
  10076. strings.remove (i);
  10077. }
  10078. }
  10079. void StringArray::trim()
  10080. {
  10081. for (int i = size(); --i >= 0;)
  10082. {
  10083. String& s = strings.getReference(i);
  10084. s = s.trim();
  10085. }
  10086. }
  10087. class InternalStringArrayComparator_CaseSensitive
  10088. {
  10089. public:
  10090. static int compareElements (String& first, String& second) { return first.compare (second); }
  10091. };
  10092. class InternalStringArrayComparator_CaseInsensitive
  10093. {
  10094. public:
  10095. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10096. };
  10097. void StringArray::sort (const bool ignoreCase)
  10098. {
  10099. if (ignoreCase)
  10100. {
  10101. InternalStringArrayComparator_CaseInsensitive comp;
  10102. strings.sort (comp);
  10103. }
  10104. else
  10105. {
  10106. InternalStringArrayComparator_CaseSensitive comp;
  10107. strings.sort (comp);
  10108. }
  10109. }
  10110. void StringArray::move (const int currentIndex, int newIndex) throw()
  10111. {
  10112. strings.move (currentIndex, newIndex);
  10113. }
  10114. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10115. {
  10116. const int last = (numberToJoin < 0) ? size()
  10117. : jmin (size(), start + numberToJoin);
  10118. if (start < 0)
  10119. start = 0;
  10120. if (start >= last)
  10121. return String::empty;
  10122. if (start == last - 1)
  10123. return strings.getReference (start);
  10124. const int separatorLen = separator.length();
  10125. int charsNeeded = separatorLen * (last - start - 1);
  10126. for (int i = start; i < last; ++i)
  10127. charsNeeded += strings.getReference(i).length();
  10128. String result;
  10129. result.preallocateStorage (charsNeeded);
  10130. juce_wchar* dest = (juce_wchar*) result;
  10131. while (start < last)
  10132. {
  10133. const String& s = strings.getReference (start);
  10134. const int len = s.length();
  10135. if (len > 0)
  10136. {
  10137. s.copyToUnicode (dest, len);
  10138. dest += len;
  10139. }
  10140. if (++start < last && separatorLen > 0)
  10141. {
  10142. separator.copyToUnicode (dest, separatorLen);
  10143. dest += separatorLen;
  10144. }
  10145. }
  10146. *dest = 0;
  10147. return result;
  10148. }
  10149. int StringArray::addTokens (const String& text, const bool preserveQuotedStrings)
  10150. {
  10151. return addTokens (text, T(" \n\r\t"), preserveQuotedStrings ? T("\"") : T(""));
  10152. }
  10153. int StringArray::addTokens (const String& text, const String& breakCharacters, const String& quoteCharacters)
  10154. {
  10155. int num = 0;
  10156. if (text.isNotEmpty())
  10157. {
  10158. bool insideQuotes = false;
  10159. juce_wchar currentQuoteChar = 0;
  10160. int i = 0;
  10161. int tokenStart = 0;
  10162. for (;;)
  10163. {
  10164. const juce_wchar c = text[i];
  10165. const bool isBreak = (c == 0) || ((! insideQuotes) && breakCharacters.containsChar (c));
  10166. if (! isBreak)
  10167. {
  10168. if (quoteCharacters.containsChar (c))
  10169. {
  10170. if (insideQuotes)
  10171. {
  10172. // only break out of quotes-mode if we find a matching quote to the
  10173. // one that we opened with..
  10174. if (currentQuoteChar == c)
  10175. insideQuotes = false;
  10176. }
  10177. else
  10178. {
  10179. insideQuotes = true;
  10180. currentQuoteChar = c;
  10181. }
  10182. }
  10183. }
  10184. else
  10185. {
  10186. add (String (static_cast <const juce_wchar*> (text) + tokenStart, i - tokenStart));
  10187. ++num;
  10188. tokenStart = i + 1;
  10189. }
  10190. if (c == 0)
  10191. break;
  10192. ++i;
  10193. }
  10194. }
  10195. return num;
  10196. }
  10197. int StringArray::addLines (const String& sourceText)
  10198. {
  10199. int numLines = 0;
  10200. const juce_wchar* text = sourceText;
  10201. while (*text != 0)
  10202. {
  10203. const juce_wchar* const startOfLine = text;
  10204. while (*text != 0)
  10205. {
  10206. if (*text == T('\r'))
  10207. {
  10208. ++text;
  10209. if (*text == T('\n'))
  10210. ++text;
  10211. break;
  10212. }
  10213. if (*text == T('\n'))
  10214. {
  10215. ++text;
  10216. break;
  10217. }
  10218. ++text;
  10219. }
  10220. const juce_wchar* endOfLine = text;
  10221. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10222. --endOfLine;
  10223. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10224. --endOfLine;
  10225. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10226. ++numLines;
  10227. }
  10228. return numLines;
  10229. }
  10230. void StringArray::removeDuplicates (const bool ignoreCase)
  10231. {
  10232. for (int i = 0; i < size() - 1; ++i)
  10233. {
  10234. const String s (strings.getReference(i));
  10235. int nextIndex = i + 1;
  10236. for (;;)
  10237. {
  10238. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10239. if (nextIndex < 0)
  10240. break;
  10241. strings.remove (nextIndex);
  10242. }
  10243. }
  10244. }
  10245. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10246. const bool appendNumberToFirstInstance,
  10247. const juce_wchar* const preNumberString,
  10248. const juce_wchar* const postNumberString)
  10249. {
  10250. jassert (preNumberString != 0 && postNumberString != 0); // These strings can't be null pointers..
  10251. for (int i = 0; i < size() - 1; ++i)
  10252. {
  10253. String& s = strings.getReference(i);
  10254. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10255. if (nextIndex >= 0)
  10256. {
  10257. const String original (s);
  10258. int number = 0;
  10259. if (appendNumberToFirstInstance)
  10260. s = original + preNumberString + String (++number) + postNumberString;
  10261. else
  10262. ++number;
  10263. while (nextIndex >= 0)
  10264. {
  10265. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10266. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10267. }
  10268. }
  10269. }
  10270. }
  10271. void StringArray::minimiseStorageOverheads()
  10272. {
  10273. strings.minimiseStorageOverheads();
  10274. }
  10275. END_JUCE_NAMESPACE
  10276. /*** End of inlined file: juce_StringArray.cpp ***/
  10277. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10278. BEGIN_JUCE_NAMESPACE
  10279. StringPairArray::StringPairArray (const bool ignoreCase_)
  10280. : ignoreCase (ignoreCase_)
  10281. {
  10282. }
  10283. StringPairArray::StringPairArray (const StringPairArray& other)
  10284. : keys (other.keys),
  10285. values (other.values),
  10286. ignoreCase (other.ignoreCase)
  10287. {
  10288. }
  10289. StringPairArray::~StringPairArray()
  10290. {
  10291. }
  10292. StringPairArray& StringPairArray::operator= (const StringPairArray& other)
  10293. {
  10294. keys = other.keys;
  10295. values = other.values;
  10296. return *this;
  10297. }
  10298. bool StringPairArray::operator== (const StringPairArray& other) const
  10299. {
  10300. for (int i = keys.size(); --i >= 0;)
  10301. if (other [keys[i]] != values[i])
  10302. return false;
  10303. return true;
  10304. }
  10305. bool StringPairArray::operator!= (const StringPairArray& other) const
  10306. {
  10307. return ! operator== (other);
  10308. }
  10309. const String& StringPairArray::operator[] (const String& key) const
  10310. {
  10311. return values [keys.indexOf (key, ignoreCase)];
  10312. }
  10313. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10314. {
  10315. const int i = keys.indexOf (key, ignoreCase);
  10316. if (i >= 0)
  10317. return values[i];
  10318. return defaultReturnValue;
  10319. }
  10320. void StringPairArray::set (const String& key, const String& value)
  10321. {
  10322. const int i = keys.indexOf (key, ignoreCase);
  10323. if (i >= 0)
  10324. {
  10325. values.set (i, value);
  10326. }
  10327. else
  10328. {
  10329. keys.add (key);
  10330. values.add (value);
  10331. }
  10332. }
  10333. void StringPairArray::addArray (const StringPairArray& other)
  10334. {
  10335. for (int i = 0; i < other.size(); ++i)
  10336. set (other.keys[i], other.values[i]);
  10337. }
  10338. void StringPairArray::clear()
  10339. {
  10340. keys.clear();
  10341. values.clear();
  10342. }
  10343. void StringPairArray::remove (const String& key)
  10344. {
  10345. remove (keys.indexOf (key, ignoreCase));
  10346. }
  10347. void StringPairArray::remove (const int index)
  10348. {
  10349. keys.remove (index);
  10350. values.remove (index);
  10351. }
  10352. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase)
  10353. {
  10354. ignoreCase = shouldIgnoreCase;
  10355. }
  10356. const String StringPairArray::getDescription() const
  10357. {
  10358. String s;
  10359. for (int i = 0; i < keys.size(); ++i)
  10360. {
  10361. s << keys[i] << T(" = ") << values[i];
  10362. if (i < keys.size())
  10363. s << T(", ");
  10364. }
  10365. return s;
  10366. }
  10367. void StringPairArray::minimiseStorageOverheads()
  10368. {
  10369. keys.minimiseStorageOverheads();
  10370. values.minimiseStorageOverheads();
  10371. }
  10372. END_JUCE_NAMESPACE
  10373. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10374. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10375. BEGIN_JUCE_NAMESPACE
  10376. XmlDocument::XmlDocument (const String& documentText)
  10377. : originalText (documentText),
  10378. ignoreEmptyTextElements (true)
  10379. {
  10380. }
  10381. XmlDocument::XmlDocument (const File& file)
  10382. {
  10383. inputSource = new FileInputSource (file);
  10384. }
  10385. XmlDocument::~XmlDocument()
  10386. {
  10387. }
  10388. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10389. {
  10390. inputSource = newSource;
  10391. }
  10392. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10393. {
  10394. ignoreEmptyTextElements = shouldBeIgnored;
  10395. }
  10396. bool XmlDocument::isXmlIdentifierCharSlow (const juce_wchar c) throw()
  10397. {
  10398. return CharacterFunctions::isLetterOrDigit (c)
  10399. || c == T('_')
  10400. || c == T('-')
  10401. || c == T(':')
  10402. || c == T('.');
  10403. }
  10404. inline bool XmlDocument::isXmlIdentifierChar (const juce_wchar c) const throw()
  10405. {
  10406. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10407. : isXmlIdentifierCharSlow (c);
  10408. }
  10409. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10410. {
  10411. String textToParse (originalText);
  10412. if (textToParse.isEmpty() && inputSource != 0)
  10413. {
  10414. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10415. if (in != 0)
  10416. {
  10417. MemoryBlock data;
  10418. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10419. if (data.getSize() >= 2
  10420. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10421. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10422. {
  10423. textToParse = String::createStringFromData ((const char*) data.getData(), (int) data.getSize());
  10424. }
  10425. else
  10426. {
  10427. textToParse = String::fromUTF8 ((const char*) data.getData(), (int) data.getSize());
  10428. }
  10429. if (! onlyReadOuterDocumentElement)
  10430. originalText = textToParse;
  10431. }
  10432. }
  10433. input = textToParse;
  10434. lastError = String::empty;
  10435. errorOccurred = false;
  10436. outOfData = false;
  10437. needToLoadDTD = true;
  10438. for (int i = 0; i < 128; ++i)
  10439. identifierLookupTable[i] = isXmlIdentifierCharSlow ((juce_wchar) i);
  10440. if (textToParse.isEmpty())
  10441. {
  10442. lastError = "not enough input";
  10443. }
  10444. else
  10445. {
  10446. skipHeader();
  10447. if (input != 0)
  10448. {
  10449. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10450. if (! errorOccurred)
  10451. return result.release();
  10452. }
  10453. else
  10454. {
  10455. lastError = "incorrect xml header";
  10456. }
  10457. }
  10458. return 0;
  10459. }
  10460. const String& XmlDocument::getLastParseError() const throw()
  10461. {
  10462. return lastError;
  10463. }
  10464. void XmlDocument::setLastError (const String& desc, const bool carryOn)
  10465. {
  10466. lastError = desc;
  10467. errorOccurred = ! carryOn;
  10468. }
  10469. const String XmlDocument::getFileContents (const String& filename) const
  10470. {
  10471. if (inputSource != 0)
  10472. {
  10473. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10474. if (in != 0)
  10475. return in->readEntireStreamAsString();
  10476. }
  10477. return String::empty;
  10478. }
  10479. juce_wchar XmlDocument::readNextChar() throw()
  10480. {
  10481. if (*input != 0)
  10482. {
  10483. return *input++;
  10484. }
  10485. else
  10486. {
  10487. outOfData = true;
  10488. return 0;
  10489. }
  10490. }
  10491. int XmlDocument::findNextTokenLength() throw()
  10492. {
  10493. int len = 0;
  10494. juce_wchar c = *input;
  10495. while (isXmlIdentifierChar (c))
  10496. c = input [++len];
  10497. return len;
  10498. }
  10499. void XmlDocument::skipHeader()
  10500. {
  10501. const juce_wchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10502. if (found != 0)
  10503. {
  10504. input = found;
  10505. input = CharacterFunctions::find (input, T("?>"));
  10506. if (input == 0)
  10507. return;
  10508. input += 2;
  10509. }
  10510. skipNextWhiteSpace();
  10511. const juce_wchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10512. if (docType == 0)
  10513. return;
  10514. input = docType + 9;
  10515. int n = 1;
  10516. while (n > 0)
  10517. {
  10518. const juce_wchar c = readNextChar();
  10519. if (outOfData)
  10520. return;
  10521. if (c == T('<'))
  10522. ++n;
  10523. else if (c == T('>'))
  10524. --n;
  10525. }
  10526. docType += 9;
  10527. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10528. }
  10529. void XmlDocument::skipNextWhiteSpace()
  10530. {
  10531. for (;;)
  10532. {
  10533. juce_wchar c = *input;
  10534. while (CharacterFunctions::isWhitespace (c))
  10535. c = *++input;
  10536. if (c == 0)
  10537. {
  10538. outOfData = true;
  10539. break;
  10540. }
  10541. else if (c == T('<'))
  10542. {
  10543. if (input[1] == T('!')
  10544. && input[2] == T('-')
  10545. && input[3] == T('-'))
  10546. {
  10547. const juce_wchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10548. if (closeComment == 0)
  10549. {
  10550. outOfData = true;
  10551. break;
  10552. }
  10553. input = closeComment + 3;
  10554. continue;
  10555. }
  10556. else if (input[1] == T('?'))
  10557. {
  10558. const juce_wchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10559. if (closeBracket == 0)
  10560. {
  10561. outOfData = true;
  10562. break;
  10563. }
  10564. input = closeBracket + 2;
  10565. continue;
  10566. }
  10567. }
  10568. break;
  10569. }
  10570. }
  10571. void XmlDocument::readQuotedString (String& result)
  10572. {
  10573. const juce_wchar quote = readNextChar();
  10574. while (! outOfData)
  10575. {
  10576. const juce_wchar c = readNextChar();
  10577. if (c == quote)
  10578. break;
  10579. if (c == T('&'))
  10580. {
  10581. --input;
  10582. readEntity (result);
  10583. }
  10584. else
  10585. {
  10586. --input;
  10587. const juce_wchar* const start = input;
  10588. for (;;)
  10589. {
  10590. const juce_wchar character = *input;
  10591. if (character == quote)
  10592. {
  10593. result.append (start, (int) (input - start));
  10594. ++input;
  10595. return;
  10596. }
  10597. else if (character == T('&'))
  10598. {
  10599. result.append (start, (int) (input - start));
  10600. break;
  10601. }
  10602. else if (character == 0)
  10603. {
  10604. outOfData = true;
  10605. setLastError ("unmatched quotes", false);
  10606. break;
  10607. }
  10608. ++input;
  10609. }
  10610. }
  10611. }
  10612. }
  10613. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements)
  10614. {
  10615. XmlElement* node = 0;
  10616. skipNextWhiteSpace();
  10617. if (outOfData)
  10618. return 0;
  10619. input = CharacterFunctions::find (input, T("<"));
  10620. if (input != 0)
  10621. {
  10622. ++input;
  10623. int tagLen = findNextTokenLength();
  10624. if (tagLen == 0)
  10625. {
  10626. // no tag name - but allow for a gap after the '<' before giving an error
  10627. skipNextWhiteSpace();
  10628. tagLen = findNextTokenLength();
  10629. if (tagLen == 0)
  10630. {
  10631. setLastError ("tag name missing", false);
  10632. return node;
  10633. }
  10634. }
  10635. node = new XmlElement (String (input, tagLen));
  10636. input += tagLen;
  10637. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10638. // look for attributes
  10639. for (;;)
  10640. {
  10641. skipNextWhiteSpace();
  10642. const juce_wchar c = *input;
  10643. // empty tag..
  10644. if (c == T('/') && input[1] == T('>'))
  10645. {
  10646. input += 2;
  10647. break;
  10648. }
  10649. // parse the guts of the element..
  10650. if (c == T('>'))
  10651. {
  10652. ++input;
  10653. skipNextWhiteSpace();
  10654. if (alsoParseSubElements)
  10655. readChildElements (node);
  10656. break;
  10657. }
  10658. // get an attribute..
  10659. if (isXmlIdentifierChar (c))
  10660. {
  10661. const int attNameLen = findNextTokenLength();
  10662. if (attNameLen > 0)
  10663. {
  10664. const juce_wchar* attNameStart = input;
  10665. input += attNameLen;
  10666. skipNextWhiteSpace();
  10667. if (readNextChar() == T('='))
  10668. {
  10669. skipNextWhiteSpace();
  10670. const juce_wchar nextChar = *input;
  10671. if (nextChar == T('"') || nextChar == T('\''))
  10672. {
  10673. XmlElement::XmlAttributeNode* const newAtt
  10674. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10675. String::empty);
  10676. readQuotedString (newAtt->value);
  10677. if (lastAttribute == 0)
  10678. node->attributes = newAtt;
  10679. else
  10680. lastAttribute->next = newAtt;
  10681. lastAttribute = newAtt;
  10682. continue;
  10683. }
  10684. }
  10685. }
  10686. }
  10687. else
  10688. {
  10689. if (! outOfData)
  10690. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10691. }
  10692. break;
  10693. }
  10694. }
  10695. return node;
  10696. }
  10697. void XmlDocument::readChildElements (XmlElement* parent)
  10698. {
  10699. XmlElement* lastChildNode = 0;
  10700. for (;;)
  10701. {
  10702. skipNextWhiteSpace();
  10703. if (outOfData)
  10704. {
  10705. setLastError ("unmatched tags", false);
  10706. break;
  10707. }
  10708. if (*input == T('<'))
  10709. {
  10710. if (input[1] == T('/'))
  10711. {
  10712. // our close tag..
  10713. input = CharacterFunctions::find (input, T(">"));
  10714. ++input;
  10715. break;
  10716. }
  10717. else if (input[1] == T('!')
  10718. && input[2] == T('[')
  10719. && input[3] == T('C')
  10720. && input[4] == T('D')
  10721. && input[5] == T('A')
  10722. && input[6] == T('T')
  10723. && input[7] == T('A')
  10724. && input[8] == T('['))
  10725. {
  10726. input += 9;
  10727. const juce_wchar* const inputStart = input;
  10728. int len = 0;
  10729. for (;;)
  10730. {
  10731. if (*input == 0)
  10732. {
  10733. setLastError ("unterminated CDATA section", false);
  10734. outOfData = true;
  10735. break;
  10736. }
  10737. else if (input[0] == T(']')
  10738. && input[1] == T(']')
  10739. && input[2] == T('>'))
  10740. {
  10741. input += 3;
  10742. break;
  10743. }
  10744. ++input;
  10745. ++len;
  10746. }
  10747. XmlElement* const e = new XmlElement ((int) 0);
  10748. e->setText (String (inputStart, len));
  10749. if (lastChildNode != 0)
  10750. lastChildNode->nextElement = e;
  10751. else
  10752. parent->addChildElement (e);
  10753. lastChildNode = e;
  10754. }
  10755. else
  10756. {
  10757. // this is some other element, so parse and add it..
  10758. XmlElement* const n = readNextElement (true);
  10759. if (n != 0)
  10760. {
  10761. if (lastChildNode == 0)
  10762. parent->addChildElement (n);
  10763. else
  10764. lastChildNode->nextElement = n;
  10765. lastChildNode = n;
  10766. }
  10767. else
  10768. {
  10769. return;
  10770. }
  10771. }
  10772. }
  10773. else
  10774. {
  10775. // read character block..
  10776. XmlElement* const e = new XmlElement ((int)0);
  10777. if (lastChildNode != 0)
  10778. lastChildNode->nextElement = e;
  10779. else
  10780. parent->addChildElement (e);
  10781. lastChildNode = e;
  10782. String textElementContent;
  10783. for (;;)
  10784. {
  10785. const juce_wchar c = *input;
  10786. if (c == T('<'))
  10787. break;
  10788. if (c == 0)
  10789. {
  10790. setLastError ("unmatched tags", false);
  10791. outOfData = true;
  10792. return;
  10793. }
  10794. if (c == T('&'))
  10795. {
  10796. String entity;
  10797. readEntity (entity);
  10798. if (entity.startsWithChar (T('<')) && entity [1] != 0)
  10799. {
  10800. const juce_wchar* const oldInput = input;
  10801. const bool oldOutOfData = outOfData;
  10802. input = entity;
  10803. outOfData = false;
  10804. for (;;)
  10805. {
  10806. XmlElement* const n = readNextElement (true);
  10807. if (n == 0)
  10808. break;
  10809. if (lastChildNode == 0)
  10810. parent->addChildElement (n);
  10811. else
  10812. lastChildNode->nextElement = n;
  10813. lastChildNode = n;
  10814. }
  10815. input = oldInput;
  10816. outOfData = oldOutOfData;
  10817. }
  10818. else
  10819. {
  10820. textElementContent += entity;
  10821. }
  10822. }
  10823. else
  10824. {
  10825. const juce_wchar* start = input;
  10826. int len = 0;
  10827. for (;;)
  10828. {
  10829. const juce_wchar nextChar = *input;
  10830. if (nextChar == T('<') || nextChar == T('&'))
  10831. {
  10832. break;
  10833. }
  10834. else if (nextChar == 0)
  10835. {
  10836. setLastError ("unmatched tags", false);
  10837. outOfData = true;
  10838. return;
  10839. }
  10840. ++input;
  10841. ++len;
  10842. }
  10843. textElementContent.append (start, len);
  10844. }
  10845. }
  10846. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  10847. : textElementContent.isNotEmpty())
  10848. e->setText (textElementContent);
  10849. }
  10850. }
  10851. }
  10852. void XmlDocument::readEntity (String& result)
  10853. {
  10854. // skip over the ampersand
  10855. ++input;
  10856. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  10857. {
  10858. input += 4;
  10859. result += T("&");
  10860. }
  10861. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  10862. {
  10863. input += 5;
  10864. result += T("\"");
  10865. }
  10866. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  10867. {
  10868. input += 5;
  10869. result += T("\'");
  10870. }
  10871. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  10872. {
  10873. input += 3;
  10874. result += T("<");
  10875. }
  10876. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  10877. {
  10878. input += 3;
  10879. result += T(">");
  10880. }
  10881. else if (*input == T('#'))
  10882. {
  10883. int charCode = 0;
  10884. ++input;
  10885. if (*input == T('x') || *input == T('X'))
  10886. {
  10887. ++input;
  10888. int numChars = 0;
  10889. while (input[0] != T(';'))
  10890. {
  10891. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  10892. if (hexValue < 0 || ++numChars > 8)
  10893. {
  10894. setLastError ("illegal escape sequence", true);
  10895. break;
  10896. }
  10897. charCode = (charCode << 4) | hexValue;
  10898. ++input;
  10899. }
  10900. ++input;
  10901. }
  10902. else if (input[0] >= T('0') && input[0] <= T('9'))
  10903. {
  10904. int numChars = 0;
  10905. while (input[0] != T(';'))
  10906. {
  10907. if (++numChars > 12)
  10908. {
  10909. setLastError ("illegal escape sequence", true);
  10910. break;
  10911. }
  10912. charCode = charCode * 10 + (input[0] - T('0'));
  10913. ++input;
  10914. }
  10915. ++input;
  10916. }
  10917. else
  10918. {
  10919. setLastError ("illegal escape sequence", true);
  10920. result += T("&");
  10921. return;
  10922. }
  10923. result << (juce_wchar) charCode;
  10924. }
  10925. else
  10926. {
  10927. const juce_wchar* const entityNameStart = input;
  10928. const juce_wchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  10929. if (closingSemiColon == 0)
  10930. {
  10931. outOfData = true;
  10932. result += T("&");
  10933. }
  10934. else
  10935. {
  10936. input = closingSemiColon + 1;
  10937. result += expandExternalEntity (String (entityNameStart,
  10938. (int) (closingSemiColon - entityNameStart)));
  10939. }
  10940. }
  10941. }
  10942. const String XmlDocument::expandEntity (const String& ent)
  10943. {
  10944. if (ent.equalsIgnoreCase (T("amp")))
  10945. return T("&");
  10946. if (ent.equalsIgnoreCase (T("quot")))
  10947. return T("\"");
  10948. if (ent.equalsIgnoreCase (T("apos")))
  10949. return T("\'");
  10950. if (ent.equalsIgnoreCase (T("lt")))
  10951. return T("<");
  10952. if (ent.equalsIgnoreCase (T("gt")))
  10953. return T(">");
  10954. if (ent[0] == T('#'))
  10955. {
  10956. if (ent[1] == T('x') || ent[1] == T('X'))
  10957. return String::charToString (static_cast <juce_wchar> (ent.substring (2).getHexValue32()));
  10958. if (ent[1] >= T('0') && ent[1] <= T('9'))
  10959. return String::charToString (static_cast <juce_wchar> (ent.substring (1).getIntValue()));
  10960. setLastError ("illegal escape sequence", false);
  10961. return T("&");
  10962. }
  10963. return expandExternalEntity (ent);
  10964. }
  10965. const String XmlDocument::expandExternalEntity (const String& entity)
  10966. {
  10967. if (needToLoadDTD)
  10968. {
  10969. if (dtdText.isNotEmpty())
  10970. {
  10971. while (dtdText.endsWithChar (T('>')))
  10972. dtdText = dtdText.dropLastCharacters (1);
  10973. tokenisedDTD.addTokens (dtdText, true);
  10974. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase (T("system"))
  10975. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  10976. {
  10977. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  10978. tokenisedDTD.clear();
  10979. tokenisedDTD.addTokens (getFileContents (fn), true);
  10980. }
  10981. else
  10982. {
  10983. tokenisedDTD.clear();
  10984. const int openBracket = dtdText.indexOfChar (T('['));
  10985. if (openBracket > 0)
  10986. {
  10987. const int closeBracket = dtdText.lastIndexOfChar (T(']'));
  10988. if (closeBracket > openBracket)
  10989. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  10990. closeBracket), true);
  10991. }
  10992. }
  10993. for (int i = tokenisedDTD.size(); --i >= 0;)
  10994. {
  10995. if (tokenisedDTD[i].startsWithChar (T('%'))
  10996. && tokenisedDTD[i].endsWithChar (T(';')))
  10997. {
  10998. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  10999. StringArray newToks;
  11000. newToks.addTokens (parsed, true);
  11001. tokenisedDTD.remove (i);
  11002. for (int j = newToks.size(); --j >= 0;)
  11003. tokenisedDTD.insert (i, newToks[j]);
  11004. }
  11005. }
  11006. }
  11007. needToLoadDTD = false;
  11008. }
  11009. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11010. {
  11011. if (tokenisedDTD[i] == entity)
  11012. {
  11013. if (tokenisedDTD[i - 1].equalsIgnoreCase (T("<!entity")))
  11014. {
  11015. String ent (tokenisedDTD [i + 1]);
  11016. while (ent.endsWithChar (T('>')))
  11017. ent = ent.dropLastCharacters (1);
  11018. ent = ent.trim().unquoted();
  11019. // check for sub-entities..
  11020. int ampersand = ent.indexOfChar (T('&'));
  11021. while (ampersand >= 0)
  11022. {
  11023. const int semiColon = ent.indexOf (i + 1, T(";"));
  11024. if (semiColon < 0)
  11025. {
  11026. setLastError ("entity without terminating semi-colon", false);
  11027. break;
  11028. }
  11029. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  11030. ent = ent.substring (0, ampersand)
  11031. + resolved
  11032. + ent.substring (semiColon + 1);
  11033. ampersand = ent.indexOfChar (semiColon + 1, T('&'));
  11034. }
  11035. return ent;
  11036. }
  11037. }
  11038. }
  11039. setLastError ("unknown entity", true);
  11040. return entity;
  11041. }
  11042. const String XmlDocument::getParameterEntity (const String& entity)
  11043. {
  11044. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11045. {
  11046. if (tokenisedDTD[i] == entity)
  11047. {
  11048. if (tokenisedDTD [i - 1] == T("%")
  11049. && tokenisedDTD [i - 2].equalsIgnoreCase (T("<!entity")))
  11050. {
  11051. String ent (tokenisedDTD [i + 1]);
  11052. while (ent.endsWithChar (T('>')))
  11053. ent = ent.dropLastCharacters (1);
  11054. if (ent.equalsIgnoreCase (T("system")))
  11055. {
  11056. String filename (tokenisedDTD [i + 2]);
  11057. while (filename.endsWithChar (T('>')))
  11058. filename = filename.dropLastCharacters (1);
  11059. return getFileContents (filename);
  11060. }
  11061. else
  11062. {
  11063. return ent.trim().unquoted();
  11064. }
  11065. }
  11066. }
  11067. }
  11068. return entity;
  11069. }
  11070. END_JUCE_NAMESPACE
  11071. /*** End of inlined file: juce_XmlDocument.cpp ***/
  11072. /*** Start of inlined file: juce_XmlElement.cpp ***/
  11073. BEGIN_JUCE_NAMESPACE
  11074. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11075. : name (other.name),
  11076. value (other.value),
  11077. next (0)
  11078. {
  11079. }
  11080. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_, const String& value_) throw()
  11081. : name (name_),
  11082. value (value_),
  11083. next (0)
  11084. {
  11085. }
  11086. XmlElement::XmlElement (const String& tagName_) throw()
  11087. : tagName (tagName_),
  11088. firstChildElement (0),
  11089. nextElement (0),
  11090. attributes (0)
  11091. {
  11092. // the tag name mustn't be empty, or it'll look like a text element!
  11093. jassert (tagName_.containsNonWhitespaceChars())
  11094. // The tag can't contain spaces or other characters that would create invalid XML!
  11095. jassert (! tagName_.containsAnyOf (T(" <>/&")));
  11096. }
  11097. XmlElement::XmlElement (int /*dummy*/) throw()
  11098. : firstChildElement (0),
  11099. nextElement (0),
  11100. attributes (0)
  11101. {
  11102. }
  11103. XmlElement::XmlElement (const XmlElement& other) throw()
  11104. : tagName (other.tagName),
  11105. firstChildElement (0),
  11106. nextElement (0),
  11107. attributes (0)
  11108. {
  11109. copyChildrenAndAttributesFrom (other);
  11110. }
  11111. XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11112. {
  11113. if (this != &other)
  11114. {
  11115. removeAllAttributes();
  11116. deleteAllChildElements();
  11117. tagName = other.tagName;
  11118. copyChildrenAndAttributesFrom (other);
  11119. }
  11120. return *this;
  11121. }
  11122. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11123. {
  11124. XmlElement* child = other.firstChildElement;
  11125. XmlElement* lastChild = 0;
  11126. while (child != 0)
  11127. {
  11128. XmlElement* const copiedChild = new XmlElement (*child);
  11129. if (lastChild != 0)
  11130. lastChild->nextElement = copiedChild;
  11131. else
  11132. firstChildElement = copiedChild;
  11133. lastChild = copiedChild;
  11134. child = child->nextElement;
  11135. }
  11136. const XmlAttributeNode* att = other.attributes;
  11137. XmlAttributeNode* lastAtt = 0;
  11138. while (att != 0)
  11139. {
  11140. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11141. if (lastAtt != 0)
  11142. lastAtt->next = newAtt;
  11143. else
  11144. attributes = newAtt;
  11145. lastAtt = newAtt;
  11146. att = att->next;
  11147. }
  11148. }
  11149. XmlElement::~XmlElement() throw()
  11150. {
  11151. XmlElement* child = firstChildElement;
  11152. while (child != 0)
  11153. {
  11154. XmlElement* const nextChild = child->nextElement;
  11155. delete child;
  11156. child = nextChild;
  11157. }
  11158. XmlAttributeNode* att = attributes;
  11159. while (att != 0)
  11160. {
  11161. XmlAttributeNode* const nextAtt = att->next;
  11162. delete att;
  11163. att = nextAtt;
  11164. }
  11165. }
  11166. namespace XmlOutputFunctions
  11167. {
  11168. static bool isLegalXmlChar (const uint32 c) throw()
  11169. {
  11170. static const unsigned char legalChars[] = { 0, 0, 0, 0, 171, 255, 255, 175, 255, 255, 255, 191, 254, 255, 255, 111 };
  11171. return c < sizeof (legalChars) * 8
  11172. && (legalChars [c >> 3] & (1 << (c & 7))) != 0;
  11173. }
  11174. static void escapeIllegalXmlChars (OutputStream& outputStream, const String& text, const bool changeNewLines)
  11175. {
  11176. const juce_wchar* t = (const juce_wchar*) text;
  11177. for (;;)
  11178. {
  11179. const juce_wchar character = *t++;
  11180. if (character == 0)
  11181. {
  11182. break;
  11183. }
  11184. else if (isLegalXmlChar ((uint32) character))
  11185. {
  11186. outputStream << (char) character;
  11187. }
  11188. else
  11189. {
  11190. switch (character)
  11191. {
  11192. case '&': outputStream << "&amp;"; break;
  11193. case '"': outputStream << "&quot;"; break;
  11194. case '>': outputStream << "&gt;"; break;
  11195. case '<': outputStream << "&lt;"; break;
  11196. case '\n':
  11197. if (changeNewLines)
  11198. outputStream << "&#10;";
  11199. else
  11200. outputStream << (char) character;
  11201. break;
  11202. case '\r':
  11203. if (changeNewLines)
  11204. outputStream << "&#13;";
  11205. else
  11206. outputStream << (char) character;
  11207. break;
  11208. default:
  11209. outputStream << "&#" << ((int) (unsigned int) character) << ';';
  11210. break;
  11211. }
  11212. }
  11213. }
  11214. }
  11215. static void writeSpaces (OutputStream& out, int numSpaces)
  11216. {
  11217. if (numSpaces > 0)
  11218. {
  11219. const char* const blanks = " ";
  11220. const int blankSize = (int) sizeof (blanks) - 1;
  11221. while (numSpaces > blankSize)
  11222. {
  11223. out.write (blanks, blankSize);
  11224. numSpaces -= blankSize;
  11225. }
  11226. out.write (blanks, numSpaces);
  11227. }
  11228. }
  11229. }
  11230. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11231. const int indentationLevel,
  11232. const int lineWrapLength) const
  11233. {
  11234. using namespace XmlOutputFunctions;
  11235. writeSpaces (outputStream, indentationLevel);
  11236. if (! isTextElement())
  11237. {
  11238. outputStream.writeByte ('<');
  11239. outputStream << tagName;
  11240. const int attIndent = indentationLevel + tagName.length() + 1;
  11241. int lineLen = 0;
  11242. const XmlAttributeNode* att = attributes;
  11243. while (att != 0)
  11244. {
  11245. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11246. {
  11247. outputStream.write ("\r\n", 2);
  11248. writeSpaces (outputStream, attIndent);
  11249. lineLen = 0;
  11250. }
  11251. const int64 startPos = outputStream.getPosition();
  11252. outputStream.writeByte (' ');
  11253. outputStream << att->name;
  11254. outputStream.write ("=\"", 2);
  11255. escapeIllegalXmlChars (outputStream, att->value, true);
  11256. outputStream.writeByte ('"');
  11257. lineLen += (int) (outputStream.getPosition() - startPos);
  11258. att = att->next;
  11259. }
  11260. if (firstChildElement != 0)
  11261. {
  11262. XmlElement* child = firstChildElement;
  11263. if (child->nextElement == 0 && child->isTextElement())
  11264. {
  11265. outputStream.writeByte ('>');
  11266. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11267. }
  11268. else
  11269. {
  11270. if (indentationLevel >= 0)
  11271. outputStream.write (">\r\n", 3);
  11272. else
  11273. outputStream.writeByte ('>');
  11274. bool lastWasTextNode = false;
  11275. while (child != 0)
  11276. {
  11277. if (child->isTextElement())
  11278. {
  11279. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11280. writeSpaces (outputStream, indentationLevel + 2);
  11281. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11282. lastWasTextNode = true;
  11283. }
  11284. else
  11285. {
  11286. if (indentationLevel >= 0)
  11287. {
  11288. if (lastWasTextNode)
  11289. outputStream.write ("\r\n", 2);
  11290. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11291. }
  11292. else
  11293. {
  11294. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11295. }
  11296. lastWasTextNode = false;
  11297. }
  11298. child = child->nextElement;
  11299. }
  11300. if (indentationLevel >= 0)
  11301. {
  11302. if (lastWasTextNode)
  11303. outputStream.write ("\r\n", 2);
  11304. writeSpaces (outputStream, indentationLevel);
  11305. }
  11306. }
  11307. outputStream.write ("</", 2);
  11308. outputStream << tagName;
  11309. if (indentationLevel >= 0)
  11310. outputStream.write (">\r\n", 3);
  11311. else
  11312. outputStream.writeByte ('>');
  11313. }
  11314. else
  11315. {
  11316. if (indentationLevel >= 0)
  11317. outputStream.write ("/>\r\n", 4);
  11318. else
  11319. outputStream.write ("/>", 2);
  11320. }
  11321. }
  11322. else
  11323. {
  11324. if (indentationLevel >= 0)
  11325. writeSpaces (outputStream, indentationLevel + 2);
  11326. escapeIllegalXmlChars (outputStream, getText(), false);
  11327. }
  11328. }
  11329. const String XmlElement::createDocument (const String& dtdToUse,
  11330. const bool allOnOneLine,
  11331. const bool includeXmlHeader,
  11332. const String& encodingType,
  11333. const int lineWrapLength) const
  11334. {
  11335. MemoryOutputStream mem (2048, 4096);
  11336. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11337. return String (mem.getData(), mem.getDataSize());
  11338. }
  11339. void XmlElement::writeToStream (OutputStream& output,
  11340. const String& dtdToUse,
  11341. const bool allOnOneLine,
  11342. const bool includeXmlHeader,
  11343. const String& encodingType,
  11344. const int lineWrapLength) const
  11345. {
  11346. if (includeXmlHeader)
  11347. output << "<?xml version=\"1.0\" encoding=\"" << encodingType
  11348. << (allOnOneLine ? "\"?> " : "\"?>\r\n\r\n");
  11349. if (dtdToUse.isNotEmpty())
  11350. output << dtdToUse << (allOnOneLine ? " " : "\r\n");
  11351. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11352. }
  11353. bool XmlElement::writeToFile (const File& file,
  11354. const String& dtdToUse,
  11355. const String& encodingType,
  11356. const int lineWrapLength) const
  11357. {
  11358. if (file.hasWriteAccess())
  11359. {
  11360. TemporaryFile tempFile (file);
  11361. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11362. if (out != 0)
  11363. {
  11364. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11365. out = 0;
  11366. return tempFile.overwriteTargetFileWithTemporary();
  11367. }
  11368. }
  11369. return false;
  11370. }
  11371. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11372. {
  11373. #ifdef JUCE_DEBUG
  11374. // if debugging, check that the case is actually the same, because
  11375. // valid xml is case-sensitive, and although this lets it pass, it's
  11376. // better not to..
  11377. if (tagName.equalsIgnoreCase (tagNameWanted))
  11378. {
  11379. jassert (tagName == tagNameWanted);
  11380. return true;
  11381. }
  11382. else
  11383. {
  11384. return false;
  11385. }
  11386. #else
  11387. return tagName.equalsIgnoreCase (tagNameWanted);
  11388. #endif
  11389. }
  11390. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11391. {
  11392. XmlElement* e = nextElement;
  11393. while (e != 0 && ! e->hasTagName (requiredTagName))
  11394. e = e->nextElement;
  11395. return e;
  11396. }
  11397. int XmlElement::getNumAttributes() const throw()
  11398. {
  11399. const XmlAttributeNode* att = attributes;
  11400. int count = 0;
  11401. while (att != 0)
  11402. {
  11403. att = att->next;
  11404. ++count;
  11405. }
  11406. return count;
  11407. }
  11408. const String& XmlElement::getAttributeName (const int index) const throw()
  11409. {
  11410. const XmlAttributeNode* att = attributes;
  11411. int count = 0;
  11412. while (att != 0)
  11413. {
  11414. if (count == index)
  11415. return att->name;
  11416. att = att->next;
  11417. ++count;
  11418. }
  11419. return String::empty;
  11420. }
  11421. const String& XmlElement::getAttributeValue (const int index) const throw()
  11422. {
  11423. const XmlAttributeNode* att = attributes;
  11424. int count = 0;
  11425. while (att != 0)
  11426. {
  11427. if (count == index)
  11428. return att->value;
  11429. att = att->next;
  11430. ++count;
  11431. }
  11432. return String::empty;
  11433. }
  11434. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11435. {
  11436. const XmlAttributeNode* att = attributes;
  11437. while (att != 0)
  11438. {
  11439. if (att->name.equalsIgnoreCase (attributeName))
  11440. return true;
  11441. att = att->next;
  11442. }
  11443. return false;
  11444. }
  11445. const String& XmlElement::getStringAttribute (const String& attributeName) const throw()
  11446. {
  11447. const XmlAttributeNode* att = attributes;
  11448. while (att != 0)
  11449. {
  11450. if (att->name.equalsIgnoreCase (attributeName))
  11451. return att->value;
  11452. att = att->next;
  11453. }
  11454. return String::empty;
  11455. }
  11456. const String XmlElement::getStringAttribute (const String& attributeName, const String& defaultReturnValue) const
  11457. {
  11458. const XmlAttributeNode* att = attributes;
  11459. while (att != 0)
  11460. {
  11461. if (att->name.equalsIgnoreCase (attributeName))
  11462. return att->value;
  11463. att = att->next;
  11464. }
  11465. return defaultReturnValue;
  11466. }
  11467. int XmlElement::getIntAttribute (const String& attributeName, const int defaultReturnValue) const
  11468. {
  11469. const XmlAttributeNode* att = attributes;
  11470. while (att != 0)
  11471. {
  11472. if (att->name.equalsIgnoreCase (attributeName))
  11473. return att->value.getIntValue();
  11474. att = att->next;
  11475. }
  11476. return defaultReturnValue;
  11477. }
  11478. double XmlElement::getDoubleAttribute (const String& attributeName, const double defaultReturnValue) const
  11479. {
  11480. const XmlAttributeNode* att = attributes;
  11481. while (att != 0)
  11482. {
  11483. if (att->name.equalsIgnoreCase (attributeName))
  11484. return att->value.getDoubleValue();
  11485. att = att->next;
  11486. }
  11487. return defaultReturnValue;
  11488. }
  11489. bool XmlElement::getBoolAttribute (const String& attributeName, const bool defaultReturnValue) const
  11490. {
  11491. const XmlAttributeNode* att = attributes;
  11492. while (att != 0)
  11493. {
  11494. if (att->name.equalsIgnoreCase (attributeName))
  11495. {
  11496. juce_wchar firstChar = att->value[0];
  11497. if (CharacterFunctions::isWhitespace (firstChar))
  11498. firstChar = att->value.trimStart() [0];
  11499. return firstChar == T('1')
  11500. || firstChar == T('t')
  11501. || firstChar == T('y')
  11502. || firstChar == T('T')
  11503. || firstChar == T('Y');
  11504. }
  11505. att = att->next;
  11506. }
  11507. return defaultReturnValue;
  11508. }
  11509. bool XmlElement::compareAttribute (const String& attributeName,
  11510. const String& stringToCompareAgainst,
  11511. const bool ignoreCase) const throw()
  11512. {
  11513. const XmlAttributeNode* att = attributes;
  11514. while (att != 0)
  11515. {
  11516. if (att->name.equalsIgnoreCase (attributeName))
  11517. {
  11518. if (ignoreCase)
  11519. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11520. else
  11521. return att->value == stringToCompareAgainst;
  11522. }
  11523. att = att->next;
  11524. }
  11525. return false;
  11526. }
  11527. void XmlElement::setAttribute (const String& attributeName, const String& value)
  11528. {
  11529. #ifdef JUCE_DEBUG
  11530. // check the identifier being passed in is legal..
  11531. const juce_wchar* t = attributeName;
  11532. while (*t != 0)
  11533. {
  11534. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11535. || *t == T('_')
  11536. || *t == T('-')
  11537. || *t == T(':'));
  11538. ++t;
  11539. }
  11540. #endif
  11541. if (attributes == 0)
  11542. {
  11543. attributes = new XmlAttributeNode (attributeName, value);
  11544. }
  11545. else
  11546. {
  11547. XmlAttributeNode* att = attributes;
  11548. for (;;)
  11549. {
  11550. if (att->name.equalsIgnoreCase (attributeName))
  11551. {
  11552. att->value = value;
  11553. break;
  11554. }
  11555. else if (att->next == 0)
  11556. {
  11557. att->next = new XmlAttributeNode (attributeName, value);
  11558. break;
  11559. }
  11560. att = att->next;
  11561. }
  11562. }
  11563. }
  11564. void XmlElement::setAttribute (const String& attributeName, const int number)
  11565. {
  11566. setAttribute (attributeName, String (number));
  11567. }
  11568. void XmlElement::setAttribute (const String& attributeName, const double number)
  11569. {
  11570. setAttribute (attributeName, String (number));
  11571. }
  11572. void XmlElement::removeAttribute (const String& attributeName) throw()
  11573. {
  11574. XmlAttributeNode* att = attributes;
  11575. XmlAttributeNode* lastAtt = 0;
  11576. while (att != 0)
  11577. {
  11578. if (att->name.equalsIgnoreCase (attributeName))
  11579. {
  11580. if (lastAtt == 0)
  11581. attributes = att->next;
  11582. else
  11583. lastAtt->next = att->next;
  11584. delete att;
  11585. break;
  11586. }
  11587. lastAtt = att;
  11588. att = att->next;
  11589. }
  11590. }
  11591. void XmlElement::removeAllAttributes() throw()
  11592. {
  11593. while (attributes != 0)
  11594. {
  11595. XmlAttributeNode* const nextAtt = attributes->next;
  11596. delete attributes;
  11597. attributes = nextAtt;
  11598. }
  11599. }
  11600. int XmlElement::getNumChildElements() const throw()
  11601. {
  11602. int count = 0;
  11603. const XmlElement* child = firstChildElement;
  11604. while (child != 0)
  11605. {
  11606. ++count;
  11607. child = child->nextElement;
  11608. }
  11609. return count;
  11610. }
  11611. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11612. {
  11613. int count = 0;
  11614. XmlElement* child = firstChildElement;
  11615. while (child != 0 && count < index)
  11616. {
  11617. child = child->nextElement;
  11618. ++count;
  11619. }
  11620. return child;
  11621. }
  11622. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11623. {
  11624. XmlElement* child = firstChildElement;
  11625. while (child != 0)
  11626. {
  11627. if (child->hasTagName (childName))
  11628. break;
  11629. child = child->nextElement;
  11630. }
  11631. return child;
  11632. }
  11633. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11634. {
  11635. if (newNode != 0)
  11636. {
  11637. if (firstChildElement == 0)
  11638. {
  11639. firstChildElement = newNode;
  11640. }
  11641. else
  11642. {
  11643. XmlElement* child = firstChildElement;
  11644. while (child->nextElement != 0)
  11645. child = child->nextElement;
  11646. child->nextElement = newNode;
  11647. // if this is non-zero, then something's probably
  11648. // gone wrong..
  11649. jassert (newNode->nextElement == 0);
  11650. }
  11651. }
  11652. }
  11653. void XmlElement::insertChildElement (XmlElement* const newNode,
  11654. int indexToInsertAt) throw()
  11655. {
  11656. if (newNode != 0)
  11657. {
  11658. removeChildElement (newNode, false);
  11659. if (indexToInsertAt == 0)
  11660. {
  11661. newNode->nextElement = firstChildElement;
  11662. firstChildElement = newNode;
  11663. }
  11664. else
  11665. {
  11666. if (firstChildElement == 0)
  11667. {
  11668. firstChildElement = newNode;
  11669. }
  11670. else
  11671. {
  11672. if (indexToInsertAt < 0)
  11673. indexToInsertAt = std::numeric_limits<int>::max();
  11674. XmlElement* child = firstChildElement;
  11675. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11676. child = child->nextElement;
  11677. newNode->nextElement = child->nextElement;
  11678. child->nextElement = newNode;
  11679. }
  11680. }
  11681. }
  11682. }
  11683. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11684. {
  11685. XmlElement* const newElement = new XmlElement (tagName);
  11686. addChildElement (newElement);
  11687. return newElement;
  11688. }
  11689. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11690. XmlElement* const newNode) throw()
  11691. {
  11692. if (newNode != 0)
  11693. {
  11694. XmlElement* child = firstChildElement;
  11695. XmlElement* previousNode = 0;
  11696. while (child != 0)
  11697. {
  11698. if (child == currentChildElement)
  11699. {
  11700. if (child != newNode)
  11701. {
  11702. if (previousNode == 0)
  11703. firstChildElement = newNode;
  11704. else
  11705. previousNode->nextElement = newNode;
  11706. newNode->nextElement = child->nextElement;
  11707. delete child;
  11708. }
  11709. return true;
  11710. }
  11711. previousNode = child;
  11712. child = child->nextElement;
  11713. }
  11714. }
  11715. return false;
  11716. }
  11717. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  11718. const bool shouldDeleteTheChild) throw()
  11719. {
  11720. if (childToRemove != 0)
  11721. {
  11722. if (firstChildElement == childToRemove)
  11723. {
  11724. firstChildElement = childToRemove->nextElement;
  11725. childToRemove->nextElement = 0;
  11726. }
  11727. else
  11728. {
  11729. XmlElement* child = firstChildElement;
  11730. XmlElement* last = 0;
  11731. while (child != 0)
  11732. {
  11733. if (child == childToRemove)
  11734. {
  11735. if (last == 0)
  11736. firstChildElement = child->nextElement;
  11737. else
  11738. last->nextElement = child->nextElement;
  11739. childToRemove->nextElement = 0;
  11740. break;
  11741. }
  11742. last = child;
  11743. child = child->nextElement;
  11744. }
  11745. }
  11746. if (shouldDeleteTheChild)
  11747. delete childToRemove;
  11748. }
  11749. }
  11750. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  11751. const bool ignoreOrderOfAttributes) const throw()
  11752. {
  11753. if (this != other)
  11754. {
  11755. if (other == 0 || tagName != other->tagName)
  11756. {
  11757. return false;
  11758. }
  11759. if (ignoreOrderOfAttributes)
  11760. {
  11761. int totalAtts = 0;
  11762. const XmlAttributeNode* att = attributes;
  11763. while (att != 0)
  11764. {
  11765. if (! other->compareAttribute (att->name, att->value))
  11766. return false;
  11767. att = att->next;
  11768. ++totalAtts;
  11769. }
  11770. if (totalAtts != other->getNumAttributes())
  11771. return false;
  11772. }
  11773. else
  11774. {
  11775. const XmlAttributeNode* thisAtt = attributes;
  11776. const XmlAttributeNode* otherAtt = other->attributes;
  11777. for (;;)
  11778. {
  11779. if (thisAtt == 0 || otherAtt == 0)
  11780. {
  11781. if (thisAtt == otherAtt) // both 0, so it's a match
  11782. break;
  11783. return false;
  11784. }
  11785. if (thisAtt->name != otherAtt->name
  11786. || thisAtt->value != otherAtt->value)
  11787. {
  11788. return false;
  11789. }
  11790. thisAtt = thisAtt->next;
  11791. otherAtt = otherAtt->next;
  11792. }
  11793. }
  11794. const XmlElement* thisChild = firstChildElement;
  11795. const XmlElement* otherChild = other->firstChildElement;
  11796. for (;;)
  11797. {
  11798. if (thisChild == 0 || otherChild == 0)
  11799. {
  11800. if (thisChild == otherChild) // both 0, so it's a match
  11801. break;
  11802. return false;
  11803. }
  11804. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  11805. return false;
  11806. thisChild = thisChild->nextElement;
  11807. otherChild = otherChild->nextElement;
  11808. }
  11809. }
  11810. return true;
  11811. }
  11812. void XmlElement::deleteAllChildElements() throw()
  11813. {
  11814. while (firstChildElement != 0)
  11815. {
  11816. XmlElement* const nextChild = firstChildElement->nextElement;
  11817. delete firstChildElement;
  11818. firstChildElement = nextChild;
  11819. }
  11820. }
  11821. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  11822. {
  11823. XmlElement* child = firstChildElement;
  11824. while (child != 0)
  11825. {
  11826. if (child->hasTagName (name))
  11827. {
  11828. XmlElement* const nextChild = child->nextElement;
  11829. removeChildElement (child, true);
  11830. child = nextChild;
  11831. }
  11832. else
  11833. {
  11834. child = child->nextElement;
  11835. }
  11836. }
  11837. }
  11838. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  11839. {
  11840. const XmlElement* child = firstChildElement;
  11841. while (child != 0)
  11842. {
  11843. if (child == possibleChild)
  11844. return true;
  11845. child = child->nextElement;
  11846. }
  11847. return false;
  11848. }
  11849. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  11850. {
  11851. if (this == elementToLookFor || elementToLookFor == 0)
  11852. return 0;
  11853. XmlElement* child = firstChildElement;
  11854. while (child != 0)
  11855. {
  11856. if (elementToLookFor == child)
  11857. return this;
  11858. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  11859. if (found != 0)
  11860. return found;
  11861. child = child->nextElement;
  11862. }
  11863. return 0;
  11864. }
  11865. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  11866. {
  11867. XmlElement* e = firstChildElement;
  11868. while (e != 0)
  11869. {
  11870. *elems++ = e;
  11871. e = e->nextElement;
  11872. }
  11873. }
  11874. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  11875. {
  11876. XmlElement* e = firstChildElement = elems[0];
  11877. for (int i = 1; i < num; ++i)
  11878. {
  11879. e->nextElement = elems[i];
  11880. e = e->nextElement;
  11881. }
  11882. e->nextElement = 0;
  11883. }
  11884. bool XmlElement::isTextElement() const throw()
  11885. {
  11886. return tagName.isEmpty();
  11887. }
  11888. static const juce_wchar* const juce_xmltextContentAttributeName = T("text");
  11889. const String XmlElement::getText() const throw()
  11890. {
  11891. jassert (isTextElement()); // you're trying to get the text from an element that
  11892. // isn't actually a text element.. If this contains text sub-nodes, you
  11893. // probably want to use getAllSubText instead.
  11894. return getStringAttribute (juce_xmltextContentAttributeName);
  11895. }
  11896. void XmlElement::setText (const String& newText) throw()
  11897. {
  11898. if (isTextElement())
  11899. {
  11900. setAttribute (juce_xmltextContentAttributeName, newText);
  11901. }
  11902. else
  11903. {
  11904. jassertfalse // you can only change the text in a text element, not a normal one.
  11905. }
  11906. }
  11907. const String XmlElement::getAllSubText() const throw()
  11908. {
  11909. String result;
  11910. String::Concatenator concatenator (result);
  11911. const XmlElement* child = firstChildElement;
  11912. while (child != 0)
  11913. {
  11914. if (child->isTextElement())
  11915. concatenator.append (child->getText());
  11916. child = child->nextElement;
  11917. }
  11918. return result;
  11919. }
  11920. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  11921. const String& defaultReturnValue) const throw()
  11922. {
  11923. const XmlElement* const child = getChildByName (childTagName);
  11924. if (child != 0)
  11925. return child->getAllSubText();
  11926. return defaultReturnValue;
  11927. }
  11928. XmlElement* XmlElement::createTextElement (const String& text) throw()
  11929. {
  11930. XmlElement* const e = new XmlElement ((int) 0);
  11931. e->setAttribute (juce_xmltextContentAttributeName, text);
  11932. return e;
  11933. }
  11934. void XmlElement::addTextElement (const String& text) throw()
  11935. {
  11936. addChildElement (createTextElement (text));
  11937. }
  11938. void XmlElement::deleteAllTextElements() throw()
  11939. {
  11940. XmlElement* child = firstChildElement;
  11941. while (child != 0)
  11942. {
  11943. XmlElement* const next = child->nextElement;
  11944. if (child->isTextElement())
  11945. removeChildElement (child, true);
  11946. child = next;
  11947. }
  11948. }
  11949. END_JUCE_NAMESPACE
  11950. /*** End of inlined file: juce_XmlElement.cpp ***/
  11951. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  11952. BEGIN_JUCE_NAMESPACE
  11953. ReadWriteLock::ReadWriteLock() throw()
  11954. : numWaitingWriters (0),
  11955. numWriters (0),
  11956. writerThreadId (0)
  11957. {
  11958. }
  11959. ReadWriteLock::~ReadWriteLock() throw()
  11960. {
  11961. jassert (readerThreads.size() == 0);
  11962. jassert (numWriters == 0);
  11963. }
  11964. void ReadWriteLock::enterRead() const throw()
  11965. {
  11966. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11967. const ScopedLock sl (accessLock);
  11968. for (;;)
  11969. {
  11970. jassert (readerThreads.size() % 2 == 0);
  11971. int i;
  11972. for (i = 0; i < readerThreads.size(); i += 2)
  11973. if (readerThreads.getUnchecked(i) == threadId)
  11974. break;
  11975. if (i < readerThreads.size()
  11976. || numWriters + numWaitingWriters == 0
  11977. || (threadId == writerThreadId && numWriters > 0))
  11978. {
  11979. if (i < readerThreads.size())
  11980. {
  11981. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  11982. }
  11983. else
  11984. {
  11985. readerThreads.add (threadId);
  11986. readerThreads.add ((Thread::ThreadID) 1);
  11987. }
  11988. return;
  11989. }
  11990. const ScopedUnlock ul (accessLock);
  11991. waitEvent.wait (100);
  11992. }
  11993. }
  11994. void ReadWriteLock::exitRead() const throw()
  11995. {
  11996. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11997. const ScopedLock sl (accessLock);
  11998. for (int i = 0; i < readerThreads.size(); i += 2)
  11999. {
  12000. if (readerThreads.getUnchecked(i) == threadId)
  12001. {
  12002. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  12003. if (newCount == 0)
  12004. {
  12005. readerThreads.removeRange (i, 2);
  12006. waitEvent.signal();
  12007. }
  12008. else
  12009. {
  12010. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  12011. }
  12012. return;
  12013. }
  12014. }
  12015. jassertfalse // unlocking a lock that wasn't locked..
  12016. }
  12017. void ReadWriteLock::enterWrite() const throw()
  12018. {
  12019. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12020. const ScopedLock sl (accessLock);
  12021. for (;;)
  12022. {
  12023. if (readerThreads.size() + numWriters == 0
  12024. || threadId == writerThreadId
  12025. || (readerThreads.size() == 2
  12026. && readerThreads.getUnchecked(0) == threadId))
  12027. {
  12028. writerThreadId = threadId;
  12029. ++numWriters;
  12030. break;
  12031. }
  12032. ++numWaitingWriters;
  12033. accessLock.exit();
  12034. waitEvent.wait (100);
  12035. accessLock.enter();
  12036. --numWaitingWriters;
  12037. }
  12038. }
  12039. bool ReadWriteLock::tryEnterWrite() const throw()
  12040. {
  12041. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12042. const ScopedLock sl (accessLock);
  12043. if (readerThreads.size() + numWriters == 0
  12044. || threadId == writerThreadId
  12045. || (readerThreads.size() == 2
  12046. && readerThreads.getUnchecked(0) == threadId))
  12047. {
  12048. writerThreadId = threadId;
  12049. ++numWriters;
  12050. return true;
  12051. }
  12052. return false;
  12053. }
  12054. void ReadWriteLock::exitWrite() const throw()
  12055. {
  12056. const ScopedLock sl (accessLock);
  12057. // check this thread actually had the lock..
  12058. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  12059. if (--numWriters == 0)
  12060. {
  12061. writerThreadId = 0;
  12062. waitEvent.signal();
  12063. }
  12064. }
  12065. END_JUCE_NAMESPACE
  12066. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  12067. /*** Start of inlined file: juce_Thread.cpp ***/
  12068. BEGIN_JUCE_NAMESPACE
  12069. // these functions are implemented in the platform-specific code.
  12070. void* juce_createThread (void* userData);
  12071. void juce_killThread (void* handle);
  12072. bool juce_setThreadPriority (void* handle, int priority);
  12073. void juce_setCurrentThreadName (const String& name);
  12074. #if JUCE_WIN32
  12075. void juce_CloseThreadHandle (void* handle);
  12076. #endif
  12077. void Thread::threadEntryPoint (Thread* const thread)
  12078. {
  12079. {
  12080. const ScopedLock sl (runningThreadsLock);
  12081. runningThreads.add (thread);
  12082. }
  12083. JUCE_TRY
  12084. {
  12085. thread->threadId_ = Thread::getCurrentThreadId();
  12086. if (thread->threadName_.isNotEmpty())
  12087. juce_setCurrentThreadName (thread->threadName_);
  12088. if (thread->startSuspensionEvent_.wait (10000))
  12089. {
  12090. if (thread->affinityMask_ != 0)
  12091. setCurrentThreadAffinityMask (thread->affinityMask_);
  12092. thread->run();
  12093. }
  12094. }
  12095. JUCE_CATCH_ALL_ASSERT
  12096. {
  12097. const ScopedLock sl (runningThreadsLock);
  12098. jassert (runningThreads.contains (thread));
  12099. runningThreads.removeValue (thread);
  12100. }
  12101. #if JUCE_WIN32
  12102. juce_CloseThreadHandle (thread->threadHandle_);
  12103. #endif
  12104. thread->threadHandle_ = 0;
  12105. thread->threadId_ = 0;
  12106. }
  12107. // used to wrap the incoming call from the platform-specific code
  12108. void JUCE_API juce_threadEntryPoint (void* userData)
  12109. {
  12110. Thread::threadEntryPoint ((Thread*) userData);
  12111. }
  12112. Thread::Thread (const String& threadName)
  12113. : threadName_ (threadName),
  12114. threadHandle_ (0),
  12115. threadPriority_ (5),
  12116. threadId_ (0),
  12117. affinityMask_ (0),
  12118. threadShouldExit_ (false)
  12119. {
  12120. }
  12121. Thread::~Thread()
  12122. {
  12123. stopThread (100);
  12124. }
  12125. void Thread::startThread()
  12126. {
  12127. const ScopedLock sl (startStopLock);
  12128. threadShouldExit_ = false;
  12129. if (threadHandle_ == 0)
  12130. {
  12131. threadHandle_ = juce_createThread ((void*) this);
  12132. juce_setThreadPriority (threadHandle_, threadPriority_);
  12133. startSuspensionEvent_.signal();
  12134. }
  12135. }
  12136. void Thread::startThread (const int priority)
  12137. {
  12138. const ScopedLock sl (startStopLock);
  12139. if (threadHandle_ == 0)
  12140. {
  12141. threadPriority_ = priority;
  12142. startThread();
  12143. }
  12144. else
  12145. {
  12146. setPriority (priority);
  12147. }
  12148. }
  12149. bool Thread::isThreadRunning() const
  12150. {
  12151. return threadHandle_ != 0;
  12152. }
  12153. void Thread::signalThreadShouldExit()
  12154. {
  12155. threadShouldExit_ = true;
  12156. }
  12157. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12158. {
  12159. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12160. jassert (getThreadId() != getCurrentThreadId());
  12161. const int sleepMsPerIteration = 5;
  12162. int count = timeOutMilliseconds / sleepMsPerIteration;
  12163. while (isThreadRunning())
  12164. {
  12165. if (timeOutMilliseconds > 0 && --count < 0)
  12166. return false;
  12167. sleep (sleepMsPerIteration);
  12168. }
  12169. return true;
  12170. }
  12171. void Thread::stopThread (const int timeOutMilliseconds)
  12172. {
  12173. // agh! You can't stop the thread that's calling this method! How on earth
  12174. // would that work??
  12175. jassert (getCurrentThreadId() != getThreadId());
  12176. const ScopedLock sl (startStopLock);
  12177. if (isThreadRunning())
  12178. {
  12179. signalThreadShouldExit();
  12180. notify();
  12181. if (timeOutMilliseconds != 0)
  12182. waitForThreadToExit (timeOutMilliseconds);
  12183. if (isThreadRunning())
  12184. {
  12185. // very bad karma if this point is reached, as
  12186. // there are bound to be locks and events left in
  12187. // silly states when a thread is killed by force..
  12188. jassertfalse
  12189. Logger::writeToLog ("!! killing thread by force !!");
  12190. juce_killThread (threadHandle_);
  12191. threadHandle_ = 0;
  12192. threadId_ = 0;
  12193. const ScopedLock sl2 (runningThreadsLock);
  12194. runningThreads.removeValue (this);
  12195. }
  12196. }
  12197. }
  12198. bool Thread::setPriority (const int priority)
  12199. {
  12200. const ScopedLock sl (startStopLock);
  12201. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12202. if (worked)
  12203. threadPriority_ = priority;
  12204. return worked;
  12205. }
  12206. bool Thread::setCurrentThreadPriority (const int priority)
  12207. {
  12208. return juce_setThreadPriority (0, priority);
  12209. }
  12210. void Thread::setAffinityMask (const uint32 affinityMask)
  12211. {
  12212. affinityMask_ = affinityMask;
  12213. }
  12214. bool Thread::wait (const int timeOutMilliseconds) const
  12215. {
  12216. return defaultEvent_.wait (timeOutMilliseconds);
  12217. }
  12218. void Thread::notify() const
  12219. {
  12220. defaultEvent_.signal();
  12221. }
  12222. int Thread::getNumRunningThreads()
  12223. {
  12224. return runningThreads.size();
  12225. }
  12226. Thread* Thread::getCurrentThread()
  12227. {
  12228. const ThreadID thisId = getCurrentThreadId();
  12229. const ScopedLock sl (runningThreadsLock);
  12230. for (int i = runningThreads.size(); --i >= 0;)
  12231. {
  12232. Thread* const t = runningThreads.getUnchecked(i);
  12233. if (t->threadId_ == thisId)
  12234. return t;
  12235. }
  12236. return 0;
  12237. }
  12238. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12239. {
  12240. {
  12241. const ScopedLock sl (runningThreadsLock);
  12242. for (int i = runningThreads.size(); --i >= 0;)
  12243. runningThreads.getUnchecked(i)->signalThreadShouldExit();
  12244. }
  12245. for (;;)
  12246. {
  12247. Thread* firstThread;
  12248. {
  12249. const ScopedLock sl (runningThreadsLock);
  12250. firstThread = runningThreads.getFirst();
  12251. }
  12252. if (firstThread == 0)
  12253. break;
  12254. firstThread->stopThread (timeOutMilliseconds);
  12255. }
  12256. }
  12257. Array<Thread*> Thread::runningThreads;
  12258. CriticalSection Thread::runningThreadsLock;
  12259. END_JUCE_NAMESPACE
  12260. /*** End of inlined file: juce_Thread.cpp ***/
  12261. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12262. BEGIN_JUCE_NAMESPACE
  12263. ThreadPoolJob::ThreadPoolJob (const String& name)
  12264. : jobName (name),
  12265. pool (0),
  12266. shouldStop (false),
  12267. isActive (false),
  12268. shouldBeDeleted (false)
  12269. {
  12270. }
  12271. ThreadPoolJob::~ThreadPoolJob()
  12272. {
  12273. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12274. // to remove it first!
  12275. jassert (pool == 0 || ! pool->contains (this));
  12276. }
  12277. const String ThreadPoolJob::getJobName() const
  12278. {
  12279. return jobName;
  12280. }
  12281. void ThreadPoolJob::setJobName (const String& newName)
  12282. {
  12283. jobName = newName;
  12284. }
  12285. void ThreadPoolJob::signalJobShouldExit()
  12286. {
  12287. shouldStop = true;
  12288. }
  12289. class ThreadPool::ThreadPoolThread : public Thread
  12290. {
  12291. public:
  12292. ThreadPoolThread (ThreadPool& pool_)
  12293. : Thread (T("Pool")),
  12294. pool (pool_),
  12295. busy (false)
  12296. {
  12297. }
  12298. ~ThreadPoolThread()
  12299. {
  12300. }
  12301. void run()
  12302. {
  12303. while (! threadShouldExit())
  12304. {
  12305. if (! pool.runNextJob())
  12306. wait (500);
  12307. }
  12308. }
  12309. private:
  12310. ThreadPool& pool;
  12311. bool volatile busy;
  12312. ThreadPoolThread (const ThreadPoolThread&);
  12313. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12314. };
  12315. ThreadPool::ThreadPool (const int numThreads,
  12316. const bool startThreadsOnlyWhenNeeded,
  12317. const int stopThreadsWhenNotUsedTimeoutMs)
  12318. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12319. priority (5)
  12320. {
  12321. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12322. for (int i = jmax (1, numThreads); --i >= 0;)
  12323. threads.add (new ThreadPoolThread (*this));
  12324. if (! startThreadsOnlyWhenNeeded)
  12325. for (int i = threads.size(); --i >= 0;)
  12326. threads.getUnchecked(i)->startThread (priority);
  12327. }
  12328. ThreadPool::~ThreadPool()
  12329. {
  12330. removeAllJobs (true, 4000);
  12331. int i;
  12332. for (i = threads.size(); --i >= 0;)
  12333. threads.getUnchecked(i)->signalThreadShouldExit();
  12334. for (i = threads.size(); --i >= 0;)
  12335. threads.getUnchecked(i)->stopThread (500);
  12336. }
  12337. void ThreadPool::addJob (ThreadPoolJob* const job)
  12338. {
  12339. jassert (job != 0);
  12340. jassert (job->pool == 0);
  12341. if (job->pool == 0)
  12342. {
  12343. job->pool = this;
  12344. job->shouldStop = false;
  12345. job->isActive = false;
  12346. {
  12347. const ScopedLock sl (lock);
  12348. jobs.add (job);
  12349. int numRunning = 0;
  12350. for (int i = threads.size(); --i >= 0;)
  12351. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12352. ++numRunning;
  12353. if (numRunning < threads.size())
  12354. {
  12355. bool startedOne = false;
  12356. int n = 1000;
  12357. while (--n >= 0 && ! startedOne)
  12358. {
  12359. for (int i = threads.size(); --i >= 0;)
  12360. {
  12361. if (! threads.getUnchecked(i)->isThreadRunning())
  12362. {
  12363. threads.getUnchecked(i)->startThread (priority);
  12364. startedOne = true;
  12365. break;
  12366. }
  12367. }
  12368. if (! startedOne)
  12369. Thread::sleep (2);
  12370. }
  12371. }
  12372. }
  12373. for (int i = threads.size(); --i >= 0;)
  12374. threads.getUnchecked(i)->notify();
  12375. }
  12376. }
  12377. int ThreadPool::getNumJobs() const
  12378. {
  12379. return jobs.size();
  12380. }
  12381. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12382. {
  12383. const ScopedLock sl (lock);
  12384. return (ThreadPoolJob*) jobs [index];
  12385. }
  12386. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12387. {
  12388. const ScopedLock sl (lock);
  12389. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12390. }
  12391. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12392. {
  12393. const ScopedLock sl (lock);
  12394. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12395. }
  12396. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12397. const int timeOutMs) const
  12398. {
  12399. if (job != 0)
  12400. {
  12401. const uint32 start = Time::getMillisecondCounter();
  12402. while (contains (job))
  12403. {
  12404. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12405. return false;
  12406. jobFinishedSignal.wait (2);
  12407. }
  12408. }
  12409. return true;
  12410. }
  12411. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12412. const bool interruptIfRunning,
  12413. const int timeOutMs)
  12414. {
  12415. bool dontWait = true;
  12416. if (job != 0)
  12417. {
  12418. const ScopedLock sl (lock);
  12419. if (jobs.contains (job))
  12420. {
  12421. if (job->isActive)
  12422. {
  12423. if (interruptIfRunning)
  12424. job->signalJobShouldExit();
  12425. dontWait = false;
  12426. }
  12427. else
  12428. {
  12429. jobs.removeValue (job);
  12430. }
  12431. }
  12432. }
  12433. return dontWait || waitForJobToFinish (job, timeOutMs);
  12434. }
  12435. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12436. const int timeOutMs,
  12437. const bool deleteInactiveJobs,
  12438. ThreadPool::JobSelector* selectedJobsToRemove)
  12439. {
  12440. Array <ThreadPoolJob*> jobsToWaitFor;
  12441. {
  12442. const ScopedLock sl (lock);
  12443. for (int i = jobs.size(); --i >= 0;)
  12444. {
  12445. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12446. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12447. {
  12448. if (job->isActive)
  12449. {
  12450. jobsToWaitFor.add (job);
  12451. if (interruptRunningJobs)
  12452. job->signalJobShouldExit();
  12453. }
  12454. else
  12455. {
  12456. jobs.remove (i);
  12457. if (deleteInactiveJobs)
  12458. delete job;
  12459. }
  12460. }
  12461. }
  12462. }
  12463. const uint32 start = Time::getMillisecondCounter();
  12464. for (;;)
  12465. {
  12466. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12467. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12468. jobsToWaitFor.remove (i);
  12469. if (jobsToWaitFor.size() == 0)
  12470. break;
  12471. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12472. return false;
  12473. jobFinishedSignal.wait (20);
  12474. }
  12475. return true;
  12476. }
  12477. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12478. {
  12479. StringArray s;
  12480. const ScopedLock sl (lock);
  12481. for (int i = 0; i < jobs.size(); ++i)
  12482. {
  12483. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12484. if (job->isActive || ! onlyReturnActiveJobs)
  12485. s.add (job->getJobName());
  12486. }
  12487. return s;
  12488. }
  12489. bool ThreadPool::setThreadPriorities (const int newPriority)
  12490. {
  12491. bool ok = true;
  12492. if (priority != newPriority)
  12493. {
  12494. priority = newPriority;
  12495. for (int i = threads.size(); --i >= 0;)
  12496. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12497. ok = false;
  12498. }
  12499. return ok;
  12500. }
  12501. bool ThreadPool::runNextJob()
  12502. {
  12503. ThreadPoolJob* job = 0;
  12504. {
  12505. const ScopedLock sl (lock);
  12506. for (int i = 0; i < jobs.size(); ++i)
  12507. {
  12508. job = jobs[i];
  12509. if (job != 0 && ! (job->isActive || job->shouldStop))
  12510. break;
  12511. job = 0;
  12512. }
  12513. if (job != 0)
  12514. job->isActive = true;
  12515. }
  12516. if (job != 0)
  12517. {
  12518. JUCE_TRY
  12519. {
  12520. ThreadPoolJob::JobStatus result = job->runJob();
  12521. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12522. const ScopedLock sl (lock);
  12523. if (jobs.contains (job))
  12524. {
  12525. job->isActive = false;
  12526. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12527. {
  12528. job->pool = 0;
  12529. job->shouldStop = true;
  12530. jobs.removeValue (job);
  12531. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12532. delete job;
  12533. jobFinishedSignal.signal();
  12534. }
  12535. else
  12536. {
  12537. // move the job to the end of the queue if it wants another go
  12538. jobs.move (jobs.indexOf (job), -1);
  12539. }
  12540. }
  12541. }
  12542. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12543. catch (...)
  12544. {
  12545. const ScopedLock sl (lock);
  12546. jobs.removeValue (job);
  12547. }
  12548. #endif
  12549. }
  12550. else
  12551. {
  12552. if (threadStopTimeout > 0
  12553. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12554. {
  12555. const ScopedLock sl (lock);
  12556. if (jobs.size() == 0)
  12557. for (int i = threads.size(); --i >= 0;)
  12558. threads.getUnchecked(i)->signalThreadShouldExit();
  12559. }
  12560. else
  12561. {
  12562. return false;
  12563. }
  12564. }
  12565. return true;
  12566. }
  12567. END_JUCE_NAMESPACE
  12568. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12569. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12570. BEGIN_JUCE_NAMESPACE
  12571. TimeSliceThread::TimeSliceThread (const String& threadName)
  12572. : Thread (threadName),
  12573. index (0),
  12574. clientBeingCalled (0),
  12575. clientsChanged (false)
  12576. {
  12577. }
  12578. TimeSliceThread::~TimeSliceThread()
  12579. {
  12580. stopThread (2000);
  12581. }
  12582. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12583. {
  12584. const ScopedLock sl (listLock);
  12585. clients.addIfNotAlreadyThere (client);
  12586. clientsChanged = true;
  12587. notify();
  12588. }
  12589. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12590. {
  12591. const ScopedLock sl1 (listLock);
  12592. clientsChanged = true;
  12593. // if there's a chance we're in the middle of calling this client, we need to
  12594. // also lock the outer lock..
  12595. if (clientBeingCalled == client)
  12596. {
  12597. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12598. const ScopedLock sl2 (callbackLock);
  12599. const ScopedLock sl3 (listLock);
  12600. clients.removeValue (client);
  12601. }
  12602. else
  12603. {
  12604. clients.removeValue (client);
  12605. }
  12606. }
  12607. int TimeSliceThread::getNumClients() const
  12608. {
  12609. return clients.size();
  12610. }
  12611. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12612. {
  12613. const ScopedLock sl (listLock);
  12614. return clients [i];
  12615. }
  12616. void TimeSliceThread::run()
  12617. {
  12618. int numCallsSinceBusy = 0;
  12619. while (! threadShouldExit())
  12620. {
  12621. int timeToWait = 500;
  12622. {
  12623. const ScopedLock sl (callbackLock);
  12624. {
  12625. const ScopedLock sl2 (listLock);
  12626. if (clients.size() > 0)
  12627. {
  12628. index = (index + 1) % clients.size();
  12629. clientBeingCalled = clients [index];
  12630. }
  12631. else
  12632. {
  12633. index = 0;
  12634. clientBeingCalled = 0;
  12635. }
  12636. if (clientsChanged)
  12637. {
  12638. clientsChanged = false;
  12639. numCallsSinceBusy = 0;
  12640. }
  12641. }
  12642. if (clientBeingCalled != 0)
  12643. {
  12644. if (clientBeingCalled->useTimeSlice())
  12645. numCallsSinceBusy = 0;
  12646. else
  12647. ++numCallsSinceBusy;
  12648. if (numCallsSinceBusy >= clients.size())
  12649. timeToWait = 500;
  12650. else if (index == 0)
  12651. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12652. else
  12653. timeToWait = 0;
  12654. }
  12655. }
  12656. if (timeToWait > 0)
  12657. wait (timeToWait);
  12658. }
  12659. }
  12660. END_JUCE_NAMESPACE
  12661. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12662. #endif
  12663. #if JUCE_BUILD_MISC
  12664. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12665. BEGIN_JUCE_NAMESPACE
  12666. class ValueTreeSetPropertyAction : public UndoableAction
  12667. {
  12668. public:
  12669. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12670. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12671. : target (target_), name (name_), newValue (newValue_),
  12672. isAddingNewProperty (isAddingNewProperty_),
  12673. isDeletingProperty (isDeletingProperty_)
  12674. {
  12675. if (! isAddingNewProperty)
  12676. oldValue = target_->getProperty (name_);
  12677. }
  12678. ~ValueTreeSetPropertyAction() {}
  12679. bool perform()
  12680. {
  12681. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12682. if (isDeletingProperty)
  12683. target->removeProperty (name, 0);
  12684. else
  12685. target->setProperty (name, newValue, 0);
  12686. return true;
  12687. }
  12688. bool undo()
  12689. {
  12690. if (isAddingNewProperty)
  12691. target->removeProperty (name, 0);
  12692. else
  12693. target->setProperty (name, oldValue, 0);
  12694. return true;
  12695. }
  12696. int getSizeInUnits()
  12697. {
  12698. return (int) sizeof (*this); //xxx should be more accurate
  12699. }
  12700. private:
  12701. const ValueTree::SharedObjectPtr target;
  12702. const var::identifier name;
  12703. const var newValue;
  12704. var oldValue;
  12705. const bool isAddingNewProperty, isDeletingProperty;
  12706. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  12707. ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  12708. };
  12709. class ValueTreeChildChangeAction : public UndoableAction
  12710. {
  12711. public:
  12712. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  12713. const ValueTree::SharedObjectPtr& newChild_)
  12714. : target (target_),
  12715. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  12716. childIndex (childIndex_),
  12717. isDeleting (newChild_ == 0)
  12718. {
  12719. jassert (child != 0);
  12720. }
  12721. ~ValueTreeChildChangeAction() {}
  12722. bool perform()
  12723. {
  12724. if (isDeleting)
  12725. target->removeChild (childIndex, 0);
  12726. else
  12727. target->addChild (child, childIndex, 0);
  12728. return true;
  12729. }
  12730. bool undo()
  12731. {
  12732. if (isDeleting)
  12733. target->addChild (child, childIndex, 0);
  12734. else
  12735. target->removeChild (childIndex, 0);
  12736. return true;
  12737. }
  12738. int getSizeInUnits()
  12739. {
  12740. return (int) sizeof (*this); //xxx should be more accurate
  12741. }
  12742. private:
  12743. const ValueTree::SharedObjectPtr target, child;
  12744. const int childIndex;
  12745. const bool isDeleting;
  12746. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  12747. ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  12748. };
  12749. ValueTree::SharedObject::SharedObject (const String& type_)
  12750. : type (type_), parent (0)
  12751. {
  12752. }
  12753. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  12754. : type (other.type), properties (other.properties), parent (0)
  12755. {
  12756. for (int i = 0; i < other.children.size(); ++i)
  12757. children.add (new SharedObject (*other.children.getUnchecked(i)));
  12758. }
  12759. ValueTree::SharedObject::~SharedObject()
  12760. {
  12761. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  12762. for (int i = children.size(); --i >= 0;)
  12763. {
  12764. const SharedObjectPtr c (children.getUnchecked(i));
  12765. c->parent = 0;
  12766. children.remove (i);
  12767. c->sendParentChangeMessage();
  12768. }
  12769. }
  12770. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12771. {
  12772. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12773. {
  12774. ValueTree* const v = valueTreesWithListeners[i];
  12775. if (v != 0)
  12776. v->listeners.call (&ValueTree::Listener::valueTreePropertyChanged, tree, property);
  12777. }
  12778. }
  12779. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  12780. {
  12781. ValueTree tree (this);
  12782. ValueTree::SharedObject* t = this;
  12783. while (t != 0)
  12784. {
  12785. t->sendPropertyChangeMessage (tree, property);
  12786. t = t->parent;
  12787. }
  12788. }
  12789. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  12790. {
  12791. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12792. {
  12793. ValueTree* const v = valueTreesWithListeners[i];
  12794. if (v != 0)
  12795. v->listeners.call (&ValueTree::Listener::valueTreeChildrenChanged, tree);
  12796. }
  12797. }
  12798. void ValueTree::SharedObject::sendChildChangeMessage()
  12799. {
  12800. ValueTree tree (this);
  12801. ValueTree::SharedObject* t = this;
  12802. while (t != 0)
  12803. {
  12804. t->sendChildChangeMessage (tree);
  12805. t = t->parent;
  12806. }
  12807. }
  12808. void ValueTree::SharedObject::sendParentChangeMessage()
  12809. {
  12810. ValueTree tree (this);
  12811. int i;
  12812. for (i = children.size(); --i >= 0;)
  12813. {
  12814. SharedObject* const t = children[i];
  12815. if (t != 0)
  12816. t->sendParentChangeMessage();
  12817. }
  12818. for (i = valueTreesWithListeners.size(); --i >= 0;)
  12819. {
  12820. ValueTree* const v = valueTreesWithListeners[i];
  12821. if (v != 0)
  12822. v->listeners.call (&ValueTree::Listener::valueTreeParentChanged, tree);
  12823. }
  12824. }
  12825. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  12826. {
  12827. return properties [name];
  12828. }
  12829. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  12830. {
  12831. if (undoManager == 0)
  12832. {
  12833. if (properties.set (name, newValue))
  12834. sendPropertyChangeMessage (name);
  12835. }
  12836. else
  12837. {
  12838. var* const existingValue = properties.getItem (name);
  12839. if (existingValue != 0)
  12840. {
  12841. if (*existingValue != newValue)
  12842. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  12843. }
  12844. else
  12845. {
  12846. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  12847. }
  12848. }
  12849. }
  12850. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  12851. {
  12852. return properties.contains (name);
  12853. }
  12854. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  12855. {
  12856. if (undoManager == 0)
  12857. {
  12858. if (properties.remove (name))
  12859. sendPropertyChangeMessage (name);
  12860. }
  12861. else
  12862. {
  12863. if (properties.contains (name))
  12864. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var::null, false, true));
  12865. }
  12866. }
  12867. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  12868. {
  12869. if (undoManager == 0)
  12870. {
  12871. while (properties.size() > 0)
  12872. {
  12873. const var::identifier name (properties.getName (properties.size() - 1));
  12874. properties.remove (name);
  12875. sendPropertyChangeMessage (name);
  12876. }
  12877. }
  12878. else
  12879. {
  12880. for (int i = properties.size(); --i >= 0;)
  12881. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getName(i), var::null, false, true));
  12882. }
  12883. }
  12884. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  12885. {
  12886. for (int i = 0; i < children.size(); ++i)
  12887. if (children.getUnchecked(i)->type == typeToMatch)
  12888. return (SharedObject*) children.getUnchecked(i);
  12889. return (SharedObject*) 0;
  12890. }
  12891. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  12892. {
  12893. for (int i = 0; i < children.size(); ++i)
  12894. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  12895. return (SharedObject*) children.getUnchecked(i);
  12896. return (SharedObject*) 0;
  12897. }
  12898. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  12899. {
  12900. const SharedObject* p = parent;
  12901. while (p != 0)
  12902. {
  12903. if (p == possibleParent)
  12904. return true;
  12905. p = p->parent;
  12906. }
  12907. return false;
  12908. }
  12909. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  12910. {
  12911. if (child != 0 && child->parent != this)
  12912. {
  12913. if (child != this && ! isAChildOf (child))
  12914. {
  12915. // You should always make sure that a child is removed from its previous parent before
  12916. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  12917. // undomanager should be used when removing it from its current parent..
  12918. jassert (child->parent == 0);
  12919. if (child->parent != 0)
  12920. {
  12921. jassert (child->parent->children.indexOf (child) >= 0);
  12922. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  12923. }
  12924. if (undoManager == 0)
  12925. {
  12926. children.insert (index, child);
  12927. child->parent = this;
  12928. sendChildChangeMessage();
  12929. child->sendParentChangeMessage();
  12930. }
  12931. else
  12932. {
  12933. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  12934. }
  12935. }
  12936. else
  12937. {
  12938. // You're attempting to create a recursive loop! A node
  12939. // can't be a child of one of its own children!
  12940. jassertfalse
  12941. }
  12942. }
  12943. }
  12944. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  12945. {
  12946. const SharedObjectPtr child (children [childIndex]);
  12947. if (child != 0)
  12948. {
  12949. if (undoManager == 0)
  12950. {
  12951. children.remove (childIndex);
  12952. child->parent = 0;
  12953. sendChildChangeMessage();
  12954. child->sendParentChangeMessage();
  12955. }
  12956. else
  12957. {
  12958. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  12959. }
  12960. }
  12961. }
  12962. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  12963. {
  12964. while (children.size() > 0)
  12965. removeChild (children.size() - 1, undoManager);
  12966. }
  12967. ValueTree::ValueTree (const String& type_)
  12968. : object (new ValueTree::SharedObject (type_))
  12969. {
  12970. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  12971. }
  12972. ValueTree::ValueTree (SharedObject* const object_)
  12973. : object (object_)
  12974. {
  12975. }
  12976. ValueTree::ValueTree (const ValueTree& other)
  12977. : object (other.object)
  12978. {
  12979. }
  12980. ValueTree& ValueTree::operator= (const ValueTree& other)
  12981. {
  12982. if (listeners.size() > 0)
  12983. {
  12984. if (object != 0)
  12985. object->valueTreesWithListeners.removeValue (this);
  12986. if (other.object != 0)
  12987. other.object->valueTreesWithListeners.add (this);
  12988. }
  12989. object = other.object;
  12990. return *this;
  12991. }
  12992. ValueTree::~ValueTree()
  12993. {
  12994. if (listeners.size() > 0 && object != 0)
  12995. object->valueTreesWithListeners.removeValue (this);
  12996. }
  12997. bool ValueTree::operator== (const ValueTree& other) const
  12998. {
  12999. return object == other.object;
  13000. }
  13001. bool ValueTree::operator!= (const ValueTree& other) const
  13002. {
  13003. return object != other.object;
  13004. }
  13005. ValueTree ValueTree::createCopy() const
  13006. {
  13007. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  13008. }
  13009. bool ValueTree::hasType (const String& typeName) const
  13010. {
  13011. return object != 0 && object->type == typeName;
  13012. }
  13013. const String ValueTree::getType() const
  13014. {
  13015. return object != 0 ? object->type : String::empty;
  13016. }
  13017. ValueTree ValueTree::getParent() const
  13018. {
  13019. return object != 0 ? ValueTree (object->parent) : ValueTree ((SharedObject*) 0);
  13020. }
  13021. const var& ValueTree::operator[] (const var::identifier& name) const
  13022. {
  13023. return object == 0 ? var::null : object->getProperty (name);
  13024. }
  13025. const var& ValueTree::getProperty (const var::identifier& name) const
  13026. {
  13027. return object == 0 ? var::null : object->getProperty (name);
  13028. }
  13029. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13030. {
  13031. jassert (name.name.isNotEmpty());
  13032. if (object != 0 && name.name.isNotEmpty())
  13033. object->setProperty (name, newValue, undoManager);
  13034. }
  13035. bool ValueTree::hasProperty (const var::identifier& name) const
  13036. {
  13037. return object != 0 && object->hasProperty (name);
  13038. }
  13039. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13040. {
  13041. if (object != 0)
  13042. object->removeProperty (name, undoManager);
  13043. }
  13044. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  13045. {
  13046. if (object != 0)
  13047. object->removeAllProperties (undoManager);
  13048. }
  13049. int ValueTree::getNumProperties() const
  13050. {
  13051. return object == 0 ? 0 : object->properties.size();
  13052. }
  13053. const var::identifier ValueTree::getPropertyName (int index) const
  13054. {
  13055. return (object == 0) ? var::identifier()
  13056. : object->properties.getName (index);
  13057. }
  13058. class ValueTreePropertyValueSource : public Value::ValueSource,
  13059. public ValueTree::Listener
  13060. {
  13061. public:
  13062. ValueTreePropertyValueSource (const ValueTree& tree_,
  13063. const var::identifier& property_,
  13064. UndoManager* const undoManager_)
  13065. : tree (tree_),
  13066. property (property_),
  13067. undoManager (undoManager_)
  13068. {
  13069. tree.addListener (this);
  13070. }
  13071. ~ValueTreePropertyValueSource()
  13072. {
  13073. tree.removeListener (this);
  13074. }
  13075. const var getValue() const
  13076. {
  13077. return tree [property];
  13078. }
  13079. void setValue (const var& newValue)
  13080. {
  13081. tree.setProperty (property, newValue, undoManager);
  13082. }
  13083. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13084. {
  13085. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13086. sendChangeMessage (false);
  13087. }
  13088. void valueTreeChildrenChanged (ValueTree&) {}
  13089. void valueTreeParentChanged (ValueTree&) {}
  13090. private:
  13091. ValueTree tree;
  13092. const var::identifier property;
  13093. UndoManager* const undoManager;
  13094. ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13095. };
  13096. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13097. {
  13098. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13099. }
  13100. int ValueTree::getNumChildren() const
  13101. {
  13102. return object == 0 ? 0 : object->children.size();
  13103. }
  13104. ValueTree ValueTree::getChild (int index) const
  13105. {
  13106. return object != 0 ? (SharedObject*) object->children [index] : ValueTree ((SharedObject*) 0);
  13107. }
  13108. ValueTree ValueTree::getChildWithName (const String& type) const
  13109. {
  13110. return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0);
  13111. }
  13112. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13113. {
  13114. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0);
  13115. }
  13116. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13117. {
  13118. return object != 0 && object->isAChildOf (possibleParent.object);
  13119. }
  13120. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13121. {
  13122. if (object != 0)
  13123. object->addChild (child.object, index, undoManager);
  13124. }
  13125. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13126. {
  13127. if (object != 0)
  13128. object->removeChild (childIndex, undoManager);
  13129. }
  13130. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13131. {
  13132. if (object != 0)
  13133. object->removeChild (object->children.indexOf (child.object), undoManager);
  13134. }
  13135. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13136. {
  13137. if (object != 0)
  13138. object->removeAllChildren (undoManager);
  13139. }
  13140. void ValueTree::addListener (Listener* listener)
  13141. {
  13142. if (listener != 0)
  13143. {
  13144. if (listeners.size() == 0 && object != 0)
  13145. object->valueTreesWithListeners.add (this);
  13146. listeners.add (listener);
  13147. }
  13148. }
  13149. void ValueTree::removeListener (Listener* listener)
  13150. {
  13151. listeners.remove (listener);
  13152. if (listeners.size() == 0 && object != 0)
  13153. object->valueTreesWithListeners.removeValue (this);
  13154. }
  13155. XmlElement* ValueTree::SharedObject::createXml() const
  13156. {
  13157. XmlElement* xml = new XmlElement (type);
  13158. int i;
  13159. for (i = 0; i < properties.size(); ++i)
  13160. {
  13161. var::identifier name (properties.getName(i));
  13162. const var& v = properties [name];
  13163. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13164. xml->setAttribute (name.name, v.toString());
  13165. }
  13166. for (i = 0; i < children.size(); ++i)
  13167. xml->addChildElement (children.getUnchecked(i)->createXml());
  13168. return xml;
  13169. }
  13170. XmlElement* ValueTree::createXml() const
  13171. {
  13172. return object != 0 ? object->createXml() : 0;
  13173. }
  13174. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13175. {
  13176. ValueTree v (xml.getTagName());
  13177. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13178. for (int i = 0; i < numAtts; ++i)
  13179. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13180. forEachXmlChildElement (xml, e)
  13181. {
  13182. v.addChild (fromXml (*e), -1, 0);
  13183. }
  13184. return v;
  13185. }
  13186. void ValueTree::writeToStream (OutputStream& output)
  13187. {
  13188. output.writeString (getType());
  13189. const int numProps = getNumProperties();
  13190. output.writeCompressedInt (numProps);
  13191. int i;
  13192. for (i = 0; i < numProps; ++i)
  13193. {
  13194. const var::identifier name (getPropertyName(i));
  13195. output.writeString (name.name);
  13196. getProperty(name).writeToStream (output);
  13197. }
  13198. const int numChildren = getNumChildren();
  13199. output.writeCompressedInt (numChildren);
  13200. for (i = 0; i < numChildren; ++i)
  13201. getChild (i).writeToStream (output);
  13202. }
  13203. ValueTree ValueTree::readFromStream (InputStream& input)
  13204. {
  13205. String type (input.readString());
  13206. if (type.isEmpty())
  13207. return ValueTree ((SharedObject*) 0);
  13208. ValueTree v (type);
  13209. const int numProps = input.readCompressedInt();
  13210. if (numProps < 0)
  13211. {
  13212. jassertfalse // trying to read corrupted data!
  13213. return v;
  13214. }
  13215. int i;
  13216. for (i = 0; i < numProps; ++i)
  13217. {
  13218. const String name (input.readString());
  13219. jassert (name.isNotEmpty());
  13220. const var value (var::readFromStream (input));
  13221. v.setProperty (name, value, 0);
  13222. }
  13223. const int numChildren = input.readCompressedInt();
  13224. for (i = 0; i < numChildren; ++i)
  13225. v.addChild (readFromStream (input), -1, 0);
  13226. return v;
  13227. }
  13228. END_JUCE_NAMESPACE
  13229. /*** End of inlined file: juce_ValueTree.cpp ***/
  13230. /*** Start of inlined file: juce_Value.cpp ***/
  13231. BEGIN_JUCE_NAMESPACE
  13232. Value::ValueSource::ValueSource()
  13233. {
  13234. }
  13235. Value::ValueSource::~ValueSource()
  13236. {
  13237. }
  13238. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13239. {
  13240. if (synchronous)
  13241. {
  13242. for (int i = valuesWithListeners.size(); --i >= 0;)
  13243. {
  13244. Value* const v = valuesWithListeners[i];
  13245. if (v != 0)
  13246. v->callListeners();
  13247. }
  13248. }
  13249. else
  13250. {
  13251. triggerAsyncUpdate();
  13252. }
  13253. }
  13254. void Value::ValueSource::handleAsyncUpdate()
  13255. {
  13256. sendChangeMessage (true);
  13257. }
  13258. class SimpleValueSource : public Value::ValueSource
  13259. {
  13260. public:
  13261. SimpleValueSource()
  13262. {
  13263. }
  13264. SimpleValueSource (const var& initialValue)
  13265. : value (initialValue)
  13266. {
  13267. }
  13268. ~SimpleValueSource()
  13269. {
  13270. }
  13271. const var getValue() const
  13272. {
  13273. return value;
  13274. }
  13275. void setValue (const var& newValue)
  13276. {
  13277. if (newValue != value)
  13278. {
  13279. value = newValue;
  13280. sendChangeMessage (false);
  13281. }
  13282. }
  13283. private:
  13284. var value;
  13285. SimpleValueSource (const SimpleValueSource&);
  13286. SimpleValueSource& operator= (const SimpleValueSource&);
  13287. };
  13288. Value::Value()
  13289. : value (new SimpleValueSource())
  13290. {
  13291. }
  13292. Value::Value (ValueSource* const value_)
  13293. : value (value_)
  13294. {
  13295. jassert (value_ != 0);
  13296. }
  13297. Value::Value (const var& initialValue)
  13298. : value (new SimpleValueSource (initialValue))
  13299. {
  13300. }
  13301. Value::Value (const Value& other)
  13302. : value (other.value)
  13303. {
  13304. }
  13305. Value& Value::operator= (const Value& other)
  13306. {
  13307. value = other.value;
  13308. return *this;
  13309. }
  13310. Value::~Value()
  13311. {
  13312. if (listeners.size() > 0)
  13313. value->valuesWithListeners.removeValue (this);
  13314. }
  13315. const var Value::getValue() const
  13316. {
  13317. return value->getValue();
  13318. }
  13319. Value::operator const var() const
  13320. {
  13321. return getValue();
  13322. }
  13323. void Value::setValue (const var& newValue)
  13324. {
  13325. value->setValue (newValue);
  13326. }
  13327. const String Value::toString() const
  13328. {
  13329. return value->getValue().toString();
  13330. }
  13331. Value& Value::operator= (const var& newValue)
  13332. {
  13333. value->setValue (newValue);
  13334. return *this;
  13335. }
  13336. void Value::referTo (const Value& valueToReferTo)
  13337. {
  13338. if (valueToReferTo.value != value)
  13339. {
  13340. if (listeners.size() > 0)
  13341. {
  13342. value->valuesWithListeners.removeValue (this);
  13343. valueToReferTo.value->valuesWithListeners.add (this);
  13344. }
  13345. value = valueToReferTo.value;
  13346. callListeners();
  13347. }
  13348. }
  13349. bool Value::refersToSameSourceAs (const Value& other) const
  13350. {
  13351. return value == other.value;
  13352. }
  13353. bool Value::operator== (const Value& other) const
  13354. {
  13355. return value == other.value || value->getValue() == other.getValue();
  13356. }
  13357. bool Value::operator!= (const Value& other) const
  13358. {
  13359. return value != other.value && value->getValue() != other.getValue();
  13360. }
  13361. void Value::addListener (Listener* const listener)
  13362. {
  13363. if (listener != 0)
  13364. {
  13365. if (listeners.size() == 0)
  13366. value->valuesWithListeners.add (this);
  13367. listeners.add (listener);
  13368. }
  13369. }
  13370. void Value::removeListener (Listener* const listener)
  13371. {
  13372. listeners.remove (listener);
  13373. if (listeners.size() == 0)
  13374. value->valuesWithListeners.removeValue (this);
  13375. }
  13376. void Value::callListeners()
  13377. {
  13378. Value v (*this); // (create a copy in case this gets deleted by a callback)
  13379. listeners.call (&Listener::valueChanged, v);
  13380. }
  13381. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const Value& value)
  13382. {
  13383. return stream << value.toString();
  13384. }
  13385. END_JUCE_NAMESPACE
  13386. /*** End of inlined file: juce_Value.cpp ***/
  13387. /*** Start of inlined file: juce_Application.cpp ***/
  13388. #if JUCE_MSVC
  13389. #pragma warning (push)
  13390. #pragma warning (disable: 4245 4514 4100)
  13391. #include <crtdbg.h>
  13392. #pragma warning (pop)
  13393. #endif
  13394. BEGIN_JUCE_NAMESPACE
  13395. void juce_setCurrentThreadName (const String& name);
  13396. static JUCEApplication* appInstance = 0;
  13397. JUCEApplication::JUCEApplication()
  13398. : appReturnValue (0),
  13399. stillInitialising (true)
  13400. {
  13401. }
  13402. JUCEApplication::~JUCEApplication()
  13403. {
  13404. if (appLock != 0)
  13405. {
  13406. appLock->exit();
  13407. appLock = 0;
  13408. }
  13409. }
  13410. JUCEApplication* JUCEApplication::getInstance() throw()
  13411. {
  13412. return appInstance;
  13413. }
  13414. bool JUCEApplication::isInitialising() const throw()
  13415. {
  13416. return stillInitialising;
  13417. }
  13418. const String JUCEApplication::getApplicationVersion()
  13419. {
  13420. return String::empty;
  13421. }
  13422. bool JUCEApplication::moreThanOneInstanceAllowed()
  13423. {
  13424. return true;
  13425. }
  13426. void JUCEApplication::anotherInstanceStarted (const String&)
  13427. {
  13428. }
  13429. void JUCEApplication::systemRequestedQuit()
  13430. {
  13431. quit();
  13432. }
  13433. void JUCEApplication::quit()
  13434. {
  13435. MessageManager::getInstance()->stopDispatchLoop();
  13436. }
  13437. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13438. {
  13439. appReturnValue = newReturnValue;
  13440. }
  13441. void JUCEApplication::unhandledException (const std::exception*,
  13442. const String&,
  13443. const int)
  13444. {
  13445. jassertfalse
  13446. }
  13447. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13448. const char* const sourceFile,
  13449. const int lineNumber)
  13450. {
  13451. if (appInstance != 0)
  13452. appInstance->unhandledException (e, sourceFile, lineNumber);
  13453. }
  13454. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13455. {
  13456. return 0;
  13457. }
  13458. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13459. {
  13460. commands.add (StandardApplicationCommandIDs::quit);
  13461. }
  13462. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13463. {
  13464. if (commandID == StandardApplicationCommandIDs::quit)
  13465. {
  13466. result.setInfo (TRANS("Quit"),
  13467. TRANS("Quits the application"),
  13468. "Application",
  13469. 0);
  13470. result.defaultKeypresses.add (KeyPress (T('q'), ModifierKeys::commandModifier, 0));
  13471. }
  13472. }
  13473. bool JUCEApplication::perform (const InvocationInfo& info)
  13474. {
  13475. if (info.commandID == StandardApplicationCommandIDs::quit)
  13476. {
  13477. systemRequestedQuit();
  13478. return true;
  13479. }
  13480. return false;
  13481. }
  13482. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13483. {
  13484. if (! app->initialiseApp (commandLine))
  13485. return 0;
  13486. // now loop until a quit message is received..
  13487. JUCE_TRY
  13488. {
  13489. MessageManager::getInstance()->runDispatchLoop();
  13490. }
  13491. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13492. catch (const std::exception& e)
  13493. {
  13494. app->unhandledException (&e, __FILE__, __LINE__);
  13495. }
  13496. catch (...)
  13497. {
  13498. app->unhandledException (0, __FILE__, __LINE__);
  13499. }
  13500. #endif
  13501. return shutdownAppAndClearUp();
  13502. }
  13503. bool JUCEApplication::initialiseApp (String& commandLine)
  13504. {
  13505. jassert (appInstance == 0);
  13506. appInstance = this;
  13507. commandLineParameters = commandLine.trim();
  13508. commandLine = String::empty;
  13509. initialiseJuce_GUI();
  13510. #if ! JUCE_IPHONE
  13511. jassert (appLock == 0); // initialiseApp must only be called once!
  13512. if (! moreThanOneInstanceAllowed())
  13513. {
  13514. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13515. if (! appLock->enter(0))
  13516. {
  13517. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13518. delete appInstance;
  13519. appInstance = 0;
  13520. DBG ("Another instance is running - quitting...");
  13521. return false;
  13522. }
  13523. }
  13524. #endif
  13525. // let the app do its setting-up..
  13526. initialise (commandLineParameters);
  13527. // register for broadcast new app messages
  13528. MessageManager::getInstance()->registerBroadcastListener (this);
  13529. stillInitialising = false;
  13530. return true;
  13531. }
  13532. int JUCEApplication::shutdownAppAndClearUp()
  13533. {
  13534. jassert (appInstance != 0);
  13535. ScopedPointer<JUCEApplication> app (appInstance);
  13536. int returnValue = 0;
  13537. MessageManager::getInstance()->deregisterBroadcastListener ((JUCEApplication*) app);
  13538. static bool reentrancyCheck = false;
  13539. if (! reentrancyCheck)
  13540. {
  13541. reentrancyCheck = true;
  13542. JUCE_TRY
  13543. {
  13544. // give the app a chance to clean up..
  13545. app->shutdown();
  13546. }
  13547. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13548. catch (const std::exception& e)
  13549. {
  13550. app->unhandledException (&e, __FILE__, __LINE__);
  13551. }
  13552. catch (...)
  13553. {
  13554. app->unhandledException (0, __FILE__, __LINE__);
  13555. }
  13556. #endif
  13557. JUCE_TRY
  13558. {
  13559. shutdownJuce_GUI();
  13560. returnValue = app->getApplicationReturnValue();
  13561. appInstance = 0;
  13562. app = 0;
  13563. }
  13564. JUCE_CATCH_ALL_ASSERT
  13565. reentrancyCheck = false;
  13566. }
  13567. return returnValue;
  13568. }
  13569. #if JUCE_IPHONE
  13570. extern int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app);
  13571. #endif
  13572. #if ! JUCE_WINDOWS
  13573. extern const char* juce_Argv0;
  13574. #endif
  13575. int JUCEApplication::main (int argc, const char* argv[], JUCEApplication* const newApp)
  13576. {
  13577. #if ! JUCE_WINDOWS
  13578. juce_Argv0 = argv[0];
  13579. #endif
  13580. #if JUCE_IPHONE
  13581. const ScopedAutoReleasePool pool;
  13582. return juce_IPhoneMain (argc, argv, newApp);
  13583. #else
  13584. #if JUCE_MAC
  13585. const ScopedAutoReleasePool pool;
  13586. #endif
  13587. String cmd;
  13588. for (int i = 1; i < argc; ++i)
  13589. cmd << argv[i] << ' ';
  13590. return JUCEApplication::main (cmd, newApp);
  13591. #endif
  13592. }
  13593. void JUCEApplication::actionListenerCallback (const String& message)
  13594. {
  13595. if (message.startsWith (getApplicationName() + "/"))
  13596. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13597. }
  13598. static bool juceInitialisedGUI = false;
  13599. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13600. {
  13601. if (! juceInitialisedGUI)
  13602. {
  13603. #if JUCE_MAC || JUCE_IPHONE
  13604. const ScopedAutoReleasePool pool;
  13605. #endif
  13606. juceInitialisedGUI = true;
  13607. initialiseJuce_NonGUI();
  13608. MessageManager::getInstance();
  13609. LookAndFeel::setDefaultLookAndFeel (0);
  13610. juce_setCurrentThreadName ("Juce Message Thread");
  13611. #if JUCE_WINDOWS && JUCE_DEBUG
  13612. // This section is just for catching people who mess up their project settings and
  13613. // turn RTTI off..
  13614. try
  13615. {
  13616. TextButton tb (String::empty);
  13617. Component* c = &tb;
  13618. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13619. c = dynamic_cast <Button*> (c);
  13620. }
  13621. catch (...)
  13622. {
  13623. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13624. // got as far as this catch statement, then why haven't you got exception catching
  13625. // turned on in the debugger???
  13626. jassertfalse
  13627. }
  13628. #endif
  13629. }
  13630. }
  13631. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13632. {
  13633. if (juceInitialisedGUI)
  13634. {
  13635. #if JUCE_MAC
  13636. const ScopedAutoReleasePool pool;
  13637. #endif
  13638. {
  13639. DeletedAtShutdown::deleteAll();
  13640. LookAndFeel::clearDefaultLookAndFeel();
  13641. }
  13642. delete MessageManager::getInstance();
  13643. shutdownJuce_NonGUI();
  13644. juceInitialisedGUI = false;
  13645. }
  13646. }
  13647. END_JUCE_NAMESPACE
  13648. /*** End of inlined file: juce_Application.cpp ***/
  13649. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13650. BEGIN_JUCE_NAMESPACE
  13651. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13652. : commandID (commandID_),
  13653. flags (0)
  13654. {
  13655. }
  13656. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13657. const String& description_,
  13658. const String& categoryName_,
  13659. const int flags_) throw()
  13660. {
  13661. shortName = shortName_;
  13662. description = description_;
  13663. categoryName = categoryName_;
  13664. flags = flags_;
  13665. }
  13666. void ApplicationCommandInfo::setActive (const bool b) throw()
  13667. {
  13668. if (b)
  13669. flags &= ~isDisabled;
  13670. else
  13671. flags |= isDisabled;
  13672. }
  13673. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13674. {
  13675. if (b)
  13676. flags |= isTicked;
  13677. else
  13678. flags &= ~isTicked;
  13679. }
  13680. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13681. {
  13682. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13683. }
  13684. END_JUCE_NAMESPACE
  13685. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13686. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  13687. BEGIN_JUCE_NAMESPACE
  13688. ApplicationCommandManager::ApplicationCommandManager()
  13689. : firstTarget (0)
  13690. {
  13691. keyMappings = new KeyPressMappingSet (this);
  13692. Desktop::getInstance().addFocusChangeListener (this);
  13693. }
  13694. ApplicationCommandManager::~ApplicationCommandManager()
  13695. {
  13696. Desktop::getInstance().removeFocusChangeListener (this);
  13697. keyMappings = 0;
  13698. }
  13699. void ApplicationCommandManager::clearCommands()
  13700. {
  13701. commands.clear();
  13702. keyMappings->clearAllKeyPresses();
  13703. triggerAsyncUpdate();
  13704. }
  13705. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  13706. {
  13707. // zero isn't a valid command ID!
  13708. jassert (newCommand.commandID != 0);
  13709. // the name isn't optional!
  13710. jassert (newCommand.shortName.isNotEmpty());
  13711. if (getCommandForID (newCommand.commandID) == 0)
  13712. {
  13713. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  13714. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  13715. commands.add (newInfo);
  13716. keyMappings->resetToDefaultMapping (newCommand.commandID);
  13717. triggerAsyncUpdate();
  13718. }
  13719. else
  13720. {
  13721. // trying to re-register the same command with different parameters?
  13722. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  13723. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  13724. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  13725. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  13726. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  13727. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  13728. }
  13729. }
  13730. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  13731. {
  13732. if (target != 0)
  13733. {
  13734. Array <CommandID> commandIDs;
  13735. target->getAllCommands (commandIDs);
  13736. for (int i = 0; i < commandIDs.size(); ++i)
  13737. {
  13738. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  13739. target->getCommandInfo (info.commandID, info);
  13740. registerCommand (info);
  13741. }
  13742. }
  13743. }
  13744. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  13745. {
  13746. for (int i = commands.size(); --i >= 0;)
  13747. {
  13748. if (commands.getUnchecked (i)->commandID == commandID)
  13749. {
  13750. commands.remove (i);
  13751. triggerAsyncUpdate();
  13752. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  13753. for (int j = keys.size(); --j >= 0;)
  13754. keyMappings->removeKeyPress (keys.getReference (j));
  13755. }
  13756. }
  13757. }
  13758. void ApplicationCommandManager::commandStatusChanged()
  13759. {
  13760. triggerAsyncUpdate();
  13761. }
  13762. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  13763. {
  13764. for (int i = commands.size(); --i >= 0;)
  13765. if (commands.getUnchecked(i)->commandID == commandID)
  13766. return commands.getUnchecked(i);
  13767. return 0;
  13768. }
  13769. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  13770. {
  13771. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13772. return (ci != 0) ? ci->shortName : String::empty;
  13773. }
  13774. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  13775. {
  13776. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13777. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  13778. : String::empty;
  13779. }
  13780. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  13781. {
  13782. StringArray s;
  13783. for (int i = 0; i < commands.size(); ++i)
  13784. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  13785. return s;
  13786. }
  13787. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  13788. {
  13789. Array <CommandID> results;
  13790. for (int i = 0; i < commands.size(); ++i)
  13791. if (commands.getUnchecked(i)->categoryName == categoryName)
  13792. results.add (commands.getUnchecked(i)->commandID);
  13793. return results;
  13794. }
  13795. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  13796. {
  13797. ApplicationCommandTarget::InvocationInfo info (commandID);
  13798. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  13799. return invoke (info, asynchronously);
  13800. }
  13801. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  13802. {
  13803. // This call isn't thread-safe for use from a non-UI thread without locking the message
  13804. // manager first..
  13805. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  13806. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  13807. if (target == 0)
  13808. return false;
  13809. ApplicationCommandInfo commandInfo (0);
  13810. target->getCommandInfo (info_.commandID, commandInfo);
  13811. ApplicationCommandTarget::InvocationInfo info (info_);
  13812. info.commandFlags = commandInfo.flags;
  13813. sendListenerInvokeCallback (info);
  13814. const bool ok = target->invoke (info, asynchronously);
  13815. commandStatusChanged();
  13816. return ok;
  13817. }
  13818. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  13819. {
  13820. return firstTarget != 0 ? firstTarget
  13821. : findDefaultComponentTarget();
  13822. }
  13823. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  13824. {
  13825. firstTarget = newTarget;
  13826. }
  13827. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  13828. ApplicationCommandInfo& upToDateInfo)
  13829. {
  13830. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  13831. if (target == 0)
  13832. target = JUCEApplication::getInstance();
  13833. if (target != 0)
  13834. target = target->getTargetForCommand (commandID);
  13835. if (target != 0)
  13836. target->getCommandInfo (commandID, upToDateInfo);
  13837. return target;
  13838. }
  13839. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  13840. {
  13841. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  13842. if (target == 0 && c != 0)
  13843. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13844. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13845. return target;
  13846. }
  13847. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  13848. {
  13849. Component* c = Component::getCurrentlyFocusedComponent();
  13850. if (c == 0)
  13851. {
  13852. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  13853. if (activeWindow != 0)
  13854. {
  13855. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  13856. if (c == 0)
  13857. c = activeWindow;
  13858. }
  13859. }
  13860. if (c == 0 && Process::isForegroundProcess())
  13861. {
  13862. // getting a bit desperate now - try all desktop comps..
  13863. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  13864. {
  13865. ApplicationCommandTarget* const target
  13866. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  13867. ->getPeer()->getLastFocusedSubcomponent());
  13868. if (target != 0)
  13869. return target;
  13870. }
  13871. }
  13872. if (c != 0)
  13873. {
  13874. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  13875. // if we're focused on a ResizableWindow, chances are that it's the content
  13876. // component that really should get the event. And if not, the event will
  13877. // still be passed up to the top level window anyway, so let's send it to the
  13878. // content comp.
  13879. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  13880. c = resizableWindow->getContentComponent();
  13881. ApplicationCommandTarget* const target = findTargetForComponent (c);
  13882. if (target != 0)
  13883. return target;
  13884. }
  13885. return JUCEApplication::getInstance();
  13886. }
  13887. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  13888. {
  13889. listeners.add (listener);
  13890. }
  13891. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  13892. {
  13893. listeners.remove (listener);
  13894. }
  13895. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info)
  13896. {
  13897. listeners.call (&ApplicationCommandManagerListener::applicationCommandInvoked, info);
  13898. }
  13899. void ApplicationCommandManager::handleAsyncUpdate()
  13900. {
  13901. listeners.call (&ApplicationCommandManagerListener::applicationCommandListChanged);
  13902. }
  13903. void ApplicationCommandManager::globalFocusChanged (Component*)
  13904. {
  13905. commandStatusChanged();
  13906. }
  13907. END_JUCE_NAMESPACE
  13908. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  13909. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  13910. BEGIN_JUCE_NAMESPACE
  13911. ApplicationCommandTarget::ApplicationCommandTarget()
  13912. {
  13913. }
  13914. ApplicationCommandTarget::~ApplicationCommandTarget()
  13915. {
  13916. messageInvoker = 0;
  13917. }
  13918. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  13919. {
  13920. if (isCommandActive (info.commandID))
  13921. {
  13922. if (async)
  13923. {
  13924. if (messageInvoker == 0)
  13925. messageInvoker = new CommandTargetMessageInvoker (this);
  13926. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  13927. return true;
  13928. }
  13929. else
  13930. {
  13931. const bool success = perform (info);
  13932. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  13933. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  13934. // returns the command's info.
  13935. return success;
  13936. }
  13937. }
  13938. return false;
  13939. }
  13940. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  13941. {
  13942. Component* c = dynamic_cast <Component*> (this);
  13943. if (c != 0)
  13944. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13945. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13946. return 0;
  13947. }
  13948. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  13949. {
  13950. ApplicationCommandTarget* target = this;
  13951. int depth = 0;
  13952. while (target != 0)
  13953. {
  13954. Array <CommandID> commandIDs;
  13955. target->getAllCommands (commandIDs);
  13956. if (commandIDs.contains (commandID))
  13957. return target;
  13958. target = target->getNextCommandTarget();
  13959. ++depth;
  13960. jassert (depth < 100); // could be a recursive command chain??
  13961. jassert (target != this); // definitely a recursive command chain!
  13962. if (depth > 100 || target == this)
  13963. break;
  13964. }
  13965. if (target == 0)
  13966. {
  13967. target = JUCEApplication::getInstance();
  13968. if (target != 0)
  13969. {
  13970. Array <CommandID> commandIDs;
  13971. target->getAllCommands (commandIDs);
  13972. if (commandIDs.contains (commandID))
  13973. return target;
  13974. }
  13975. }
  13976. return 0;
  13977. }
  13978. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  13979. {
  13980. ApplicationCommandInfo info (commandID);
  13981. info.flags = ApplicationCommandInfo::isDisabled;
  13982. getCommandInfo (commandID, info);
  13983. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  13984. }
  13985. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  13986. {
  13987. ApplicationCommandTarget* target = this;
  13988. int depth = 0;
  13989. while (target != 0)
  13990. {
  13991. if (target->tryToInvoke (info, async))
  13992. return true;
  13993. target = target->getNextCommandTarget();
  13994. ++depth;
  13995. jassert (depth < 100); // could be a recursive command chain??
  13996. jassert (target != this); // definitely a recursive command chain!
  13997. if (depth > 100 || target == this)
  13998. break;
  13999. }
  14000. if (target == 0)
  14001. {
  14002. target = JUCEApplication::getInstance();
  14003. if (target != 0)
  14004. return target->tryToInvoke (info, async);
  14005. }
  14006. return false;
  14007. }
  14008. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14009. {
  14010. ApplicationCommandTarget::InvocationInfo info (commandID);
  14011. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14012. return invoke (info, asynchronously);
  14013. }
  14014. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  14015. : commandID (commandID_),
  14016. commandFlags (0),
  14017. invocationMethod (direct),
  14018. originatingComponent (0),
  14019. isKeyDown (false),
  14020. millisecsSinceKeyPressed (0)
  14021. {
  14022. }
  14023. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  14024. : owner (owner_)
  14025. {
  14026. }
  14027. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  14028. {
  14029. }
  14030. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  14031. {
  14032. const ScopedPointer <InvocationInfo> info ((InvocationInfo*) message.pointerParameter);
  14033. owner->tryToInvoke (*info, false);
  14034. }
  14035. END_JUCE_NAMESPACE
  14036. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14037. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  14038. BEGIN_JUCE_NAMESPACE
  14039. juce_ImplementSingleton (ApplicationProperties)
  14040. ApplicationProperties::ApplicationProperties() throw()
  14041. : msBeforeSaving (3000),
  14042. options (PropertiesFile::storeAsBinary),
  14043. commonSettingsAreReadOnly (0)
  14044. {
  14045. }
  14046. ApplicationProperties::~ApplicationProperties()
  14047. {
  14048. closeFiles();
  14049. clearSingletonInstance();
  14050. }
  14051. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14052. const String& fileNameSuffix,
  14053. const String& folderName_,
  14054. const int millisecondsBeforeSaving,
  14055. const int propertiesFileOptions) throw()
  14056. {
  14057. appName = applicationName;
  14058. fileSuffix = fileNameSuffix;
  14059. folderName = folderName_;
  14060. msBeforeSaving = millisecondsBeforeSaving;
  14061. options = propertiesFileOptions;
  14062. }
  14063. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14064. const bool testCommonSettings,
  14065. const bool showWarningDialogOnFailure)
  14066. {
  14067. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14068. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14069. if (! (userOk && commonOk))
  14070. {
  14071. if (showWarningDialogOnFailure)
  14072. {
  14073. String filenames;
  14074. if (userProps != 0 && ! userOk)
  14075. filenames << '\n' << userProps->getFile().getFullPathName();
  14076. if (commonProps != 0 && ! commonOk)
  14077. filenames << '\n' << commonProps->getFile().getFullPathName();
  14078. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14079. appName + TRANS(" - Unable to save settings"),
  14080. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14081. + appName + TRANS(" needs to be able to write to the following files:\n")
  14082. + filenames
  14083. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14084. }
  14085. return false;
  14086. }
  14087. return true;
  14088. }
  14089. void ApplicationProperties::openFiles() throw()
  14090. {
  14091. // You need to call setStorageParameters() before trying to get hold of the
  14092. // properties!
  14093. jassert (appName.isNotEmpty());
  14094. if (appName.isNotEmpty())
  14095. {
  14096. if (userProps == 0)
  14097. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14098. false, msBeforeSaving, options);
  14099. if (commonProps == 0)
  14100. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14101. true, msBeforeSaving, options);
  14102. userProps->setFallbackPropertySet (commonProps);
  14103. }
  14104. }
  14105. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14106. {
  14107. if (userProps == 0)
  14108. openFiles();
  14109. return userProps;
  14110. }
  14111. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14112. {
  14113. if (commonProps == 0)
  14114. openFiles();
  14115. if (returnUserPropsIfReadOnly)
  14116. {
  14117. if (commonSettingsAreReadOnly == 0)
  14118. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14119. if (commonSettingsAreReadOnly > 0)
  14120. return userProps;
  14121. }
  14122. return commonProps;
  14123. }
  14124. bool ApplicationProperties::saveIfNeeded()
  14125. {
  14126. return (userProps == 0 || userProps->saveIfNeeded())
  14127. && (commonProps == 0 || commonProps->saveIfNeeded());
  14128. }
  14129. void ApplicationProperties::closeFiles()
  14130. {
  14131. userProps = 0;
  14132. commonProps = 0;
  14133. }
  14134. END_JUCE_NAMESPACE
  14135. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14136. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14137. BEGIN_JUCE_NAMESPACE
  14138. static VoidArray objectsToDelete;
  14139. static CriticalSection lock;
  14140. DeletedAtShutdown::DeletedAtShutdown()
  14141. {
  14142. const ScopedLock sl (lock);
  14143. objectsToDelete.add (this);
  14144. }
  14145. DeletedAtShutdown::~DeletedAtShutdown()
  14146. {
  14147. const ScopedLock sl (lock);
  14148. objectsToDelete.removeValue (this);
  14149. }
  14150. void DeletedAtShutdown::deleteAll()
  14151. {
  14152. // make a local copy of the array, so it can't get into a loop if something
  14153. // creates another DeletedAtShutdown object during its destructor.
  14154. VoidArray localCopy;
  14155. {
  14156. const ScopedLock sl (lock);
  14157. localCopy = objectsToDelete;
  14158. }
  14159. for (int i = localCopy.size(); --i >= 0;)
  14160. {
  14161. JUCE_TRY
  14162. {
  14163. DeletedAtShutdown* deletee = (DeletedAtShutdown*) localCopy.getUnchecked(i);
  14164. // double-check that it's not already been deleted during another object's destructor.
  14165. {
  14166. const ScopedLock sl (lock);
  14167. if (! objectsToDelete.contains (deletee))
  14168. deletee = 0;
  14169. }
  14170. delete deletee;
  14171. }
  14172. JUCE_CATCH_EXCEPTION
  14173. }
  14174. // if no objects got re-created during shutdown, this should have been emptied by their
  14175. // destructors
  14176. jassert (objectsToDelete.size() == 0);
  14177. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14178. }
  14179. END_JUCE_NAMESPACE
  14180. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14181. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14182. BEGIN_JUCE_NAMESPACE
  14183. namespace PropertyFileConstants
  14184. {
  14185. static const int magicNumber = (int) ByteOrder::littleEndianInt ("PROP");
  14186. static const int magicNumberCompressed = (int) ByteOrder::littleEndianInt ("CPRP");
  14187. static const char* const fileTag = "PROPERTIES";
  14188. static const char* const valueTag = "VALUE";
  14189. static const char* const nameAttribute = "name";
  14190. static const char* const valueAttribute = "val";
  14191. }
  14192. PropertiesFile::PropertiesFile (const File& f, const int millisecondsBeforeSaving, const int options_)
  14193. : PropertySet (ignoreCaseOfKeyNames),
  14194. file (f),
  14195. timerInterval (millisecondsBeforeSaving),
  14196. options (options_),
  14197. loadedOk (false),
  14198. needsWriting (false)
  14199. {
  14200. // You need to correctly specify just one storage format for the file
  14201. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14202. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14203. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14204. ScopedPointer<InputStream> fileStream (f.createInputStream());
  14205. if (fileStream != 0)
  14206. {
  14207. int magicNumber = fileStream->readInt();
  14208. if (magicNumber == PropertyFileConstants::magicNumberCompressed)
  14209. {
  14210. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true), true);
  14211. magicNumber = PropertyFileConstants::magicNumber;
  14212. }
  14213. if (magicNumber == PropertyFileConstants::magicNumber)
  14214. {
  14215. loadedOk = true;
  14216. BufferedInputStream in (fileStream.release(), 2048, true);
  14217. int numValues = in.readInt();
  14218. while (--numValues >= 0 && ! in.isExhausted())
  14219. {
  14220. const String key (in.readString());
  14221. const String value (in.readString());
  14222. jassert (key.isNotEmpty());
  14223. if (key.isNotEmpty())
  14224. getAllProperties().set (key, value);
  14225. }
  14226. }
  14227. else
  14228. {
  14229. // Not a binary props file - let's see if it's XML..
  14230. fileStream = 0;
  14231. XmlDocument parser (f);
  14232. ScopedPointer<XmlElement> doc (parser.getDocumentElement (true));
  14233. if (doc != 0 && doc->hasTagName (PropertyFileConstants::fileTag))
  14234. {
  14235. doc = parser.getDocumentElement();
  14236. if (doc != 0)
  14237. {
  14238. loadedOk = true;
  14239. forEachXmlChildElementWithTagName (*doc, e, PropertyFileConstants::valueTag)
  14240. {
  14241. const String name (e->getStringAttribute (PropertyFileConstants::nameAttribute));
  14242. if (name.isNotEmpty())
  14243. {
  14244. getAllProperties().set (name,
  14245. e->getFirstChildElement() != 0
  14246. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14247. : e->getStringAttribute (PropertyFileConstants::valueAttribute));
  14248. }
  14249. }
  14250. }
  14251. else
  14252. {
  14253. // must be a pretty broken XML file we're trying to parse here!
  14254. jassertfalse
  14255. }
  14256. }
  14257. }
  14258. }
  14259. else
  14260. {
  14261. loadedOk = ! f.exists();
  14262. }
  14263. }
  14264. PropertiesFile::~PropertiesFile()
  14265. {
  14266. if (! saveIfNeeded())
  14267. jassertfalse;
  14268. }
  14269. bool PropertiesFile::saveIfNeeded()
  14270. {
  14271. const ScopedLock sl (getLock());
  14272. return (! needsWriting) || save();
  14273. }
  14274. bool PropertiesFile::needsToBeSaved() const
  14275. {
  14276. const ScopedLock sl (getLock());
  14277. return needsWriting;
  14278. }
  14279. void PropertiesFile::setNeedsToBeSaved (const bool needsToBeSaved)
  14280. {
  14281. const ScopedLock sl (getLock());
  14282. needsWriting = needsToBeSaved;
  14283. }
  14284. bool PropertiesFile::save()
  14285. {
  14286. const ScopedLock sl (getLock());
  14287. stopTimer();
  14288. if (file == File::nonexistent
  14289. || file.isDirectory()
  14290. || ! file.getParentDirectory().createDirectory())
  14291. return false;
  14292. if ((options & storeAsXML) != 0)
  14293. {
  14294. XmlElement doc (PropertyFileConstants::fileTag);
  14295. for (int i = 0; i < getAllProperties().size(); ++i)
  14296. {
  14297. XmlElement* const e = doc.createNewChildElement (PropertyFileConstants::valueTag);
  14298. e->setAttribute (PropertyFileConstants::nameAttribute, getAllProperties().getAllKeys() [i]);
  14299. // if the value seems to contain xml, store it as such..
  14300. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14301. XmlElement* const childElement = xmlContent.getDocumentElement();
  14302. if (childElement != 0)
  14303. e->addChildElement (childElement);
  14304. else
  14305. e->setAttribute (PropertyFileConstants::valueAttribute,
  14306. getAllProperties().getAllValues() [i]);
  14307. }
  14308. if (doc.writeToFile (file, String::empty))
  14309. {
  14310. needsWriting = false;
  14311. return true;
  14312. }
  14313. }
  14314. else
  14315. {
  14316. TemporaryFile tempFile (file);
  14317. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14318. if (out != 0)
  14319. {
  14320. if ((options & storeAsCompressedBinary) != 0)
  14321. {
  14322. out->writeInt (PropertyFileConstants::magicNumberCompressed);
  14323. out->flush();
  14324. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14325. }
  14326. else
  14327. {
  14328. // have you set up the storage option flags correctly?
  14329. jassert ((options & storeAsBinary) != 0);
  14330. out->writeInt (PropertyFileConstants::magicNumber);
  14331. }
  14332. const int numProperties = getAllProperties().size();
  14333. out->writeInt (numProperties);
  14334. for (int i = 0; i < numProperties; ++i)
  14335. {
  14336. out->writeString (getAllProperties().getAllKeys() [i]);
  14337. out->writeString (getAllProperties().getAllValues() [i]);
  14338. }
  14339. out = 0;
  14340. if (tempFile.overwriteTargetFileWithTemporary())
  14341. {
  14342. needsWriting = false;
  14343. return true;
  14344. }
  14345. }
  14346. }
  14347. return false;
  14348. }
  14349. void PropertiesFile::timerCallback()
  14350. {
  14351. saveIfNeeded();
  14352. }
  14353. void PropertiesFile::propertyChanged()
  14354. {
  14355. sendChangeMessage (this);
  14356. needsWriting = true;
  14357. if (timerInterval > 0)
  14358. startTimer (timerInterval);
  14359. else if (timerInterval == 0)
  14360. saveIfNeeded();
  14361. }
  14362. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14363. const String& fileNameSuffix,
  14364. const String& folderName,
  14365. const bool commonToAllUsers)
  14366. {
  14367. // mustn't have illegal characters in this name..
  14368. jassert (applicationName == File::createLegalFileName (applicationName));
  14369. #if JUCE_MAC || JUCE_IPHONE
  14370. File dir (commonToAllUsers ? "/Library/Preferences"
  14371. : "~/Library/Preferences");
  14372. if (folderName.isNotEmpty())
  14373. dir = dir.getChildFile (folderName);
  14374. #endif
  14375. #ifdef JUCE_LINUX
  14376. const File dir ((commonToAllUsers ? "/var/" : "~/")
  14377. + (folderName.isNotEmpty() ? folderName
  14378. : ("." + applicationName)));
  14379. #endif
  14380. #if JUCE_WIN32
  14381. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14382. : File::userApplicationDataDirectory));
  14383. if (dir == File::nonexistent)
  14384. return File::nonexistent;
  14385. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14386. : applicationName);
  14387. #endif
  14388. return dir.getChildFile (applicationName)
  14389. .withFileExtension (fileNameSuffix);
  14390. }
  14391. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14392. const String& fileNameSuffix,
  14393. const String& folderName,
  14394. const bool commonToAllUsers,
  14395. const int millisecondsBeforeSaving,
  14396. const int propertiesFileOptions)
  14397. {
  14398. const File file (getDefaultAppSettingsFile (applicationName,
  14399. fileNameSuffix,
  14400. folderName,
  14401. commonToAllUsers));
  14402. jassert (file != File::nonexistent);
  14403. if (file == File::nonexistent)
  14404. return 0;
  14405. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions);
  14406. }
  14407. END_JUCE_NAMESPACE
  14408. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14409. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14410. BEGIN_JUCE_NAMESPACE
  14411. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14412. const String& fileWildcard_,
  14413. const String& openFileDialogTitle_,
  14414. const String& saveFileDialogTitle_)
  14415. : changedSinceSave (false),
  14416. fileExtension (fileExtension_),
  14417. fileWildcard (fileWildcard_),
  14418. openFileDialogTitle (openFileDialogTitle_),
  14419. saveFileDialogTitle (saveFileDialogTitle_)
  14420. {
  14421. }
  14422. FileBasedDocument::~FileBasedDocument()
  14423. {
  14424. }
  14425. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14426. {
  14427. changedSinceSave = hasChanged;
  14428. }
  14429. void FileBasedDocument::changed()
  14430. {
  14431. changedSinceSave = true;
  14432. sendChangeMessage (this);
  14433. }
  14434. void FileBasedDocument::setFile (const File& newFile)
  14435. {
  14436. if (documentFile != newFile)
  14437. {
  14438. documentFile = newFile;
  14439. changedSinceSave = true;
  14440. }
  14441. }
  14442. bool FileBasedDocument::loadFrom (const File& newFile,
  14443. const bool showMessageOnFailure)
  14444. {
  14445. MouseCursor::showWaitCursor();
  14446. const File oldFile (documentFile);
  14447. documentFile = newFile;
  14448. String error;
  14449. if (newFile.existsAsFile())
  14450. {
  14451. error = loadDocument (newFile);
  14452. if (error.isEmpty())
  14453. {
  14454. setChangedFlag (false);
  14455. MouseCursor::hideWaitCursor();
  14456. setLastDocumentOpened (newFile);
  14457. return true;
  14458. }
  14459. }
  14460. else
  14461. {
  14462. error = "The file doesn't exist";
  14463. }
  14464. documentFile = oldFile;
  14465. MouseCursor::hideWaitCursor();
  14466. if (showMessageOnFailure)
  14467. {
  14468. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14469. TRANS("Failed to open file..."),
  14470. TRANS("There was an error while trying to load the file:\n\n")
  14471. + newFile.getFullPathName()
  14472. + T("\n\n")
  14473. + error);
  14474. }
  14475. return false;
  14476. }
  14477. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14478. {
  14479. FileChooser fc (openFileDialogTitle,
  14480. getLastDocumentOpened(),
  14481. fileWildcard);
  14482. if (fc.browseForFileToOpen())
  14483. return loadFrom (fc.getResult(), showMessageOnFailure);
  14484. return false;
  14485. }
  14486. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14487. const bool showMessageOnFailure)
  14488. {
  14489. return saveAs (documentFile,
  14490. false,
  14491. askUserForFileIfNotSpecified,
  14492. showMessageOnFailure);
  14493. }
  14494. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14495. const bool warnAboutOverwritingExistingFiles,
  14496. const bool askUserForFileIfNotSpecified,
  14497. const bool showMessageOnFailure)
  14498. {
  14499. if (newFile == File::nonexistent)
  14500. {
  14501. if (askUserForFileIfNotSpecified)
  14502. {
  14503. return saveAsInteractive (true);
  14504. }
  14505. else
  14506. {
  14507. // can't save to an unspecified file
  14508. jassertfalse
  14509. return failedToWriteToFile;
  14510. }
  14511. }
  14512. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14513. {
  14514. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14515. TRANS("File already exists"),
  14516. TRANS("There's already a file called:\n\n")
  14517. + newFile.getFullPathName()
  14518. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14519. TRANS("overwrite"),
  14520. TRANS("cancel")))
  14521. {
  14522. return userCancelledSave;
  14523. }
  14524. }
  14525. MouseCursor::showWaitCursor();
  14526. const File oldFile (documentFile);
  14527. documentFile = newFile;
  14528. String error (saveDocument (newFile));
  14529. if (error.isEmpty())
  14530. {
  14531. setChangedFlag (false);
  14532. MouseCursor::hideWaitCursor();
  14533. return savedOk;
  14534. }
  14535. documentFile = oldFile;
  14536. MouseCursor::hideWaitCursor();
  14537. if (showMessageOnFailure)
  14538. {
  14539. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14540. TRANS("Error writing to file..."),
  14541. TRANS("An error occurred while trying to save \"")
  14542. + getDocumentTitle()
  14543. + TRANS("\" to the file:\n\n")
  14544. + newFile.getFullPathName()
  14545. + T("\n\n")
  14546. + error);
  14547. }
  14548. return failedToWriteToFile;
  14549. }
  14550. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14551. {
  14552. if (! hasChangedSinceSaved())
  14553. return savedOk;
  14554. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14555. TRANS("Closing document..."),
  14556. TRANS("Do you want to save the changes to \"")
  14557. + getDocumentTitle() + T("\"?"),
  14558. TRANS("save"),
  14559. TRANS("discard changes"),
  14560. TRANS("cancel"));
  14561. if (r == 1)
  14562. {
  14563. // save changes
  14564. return save (true, true);
  14565. }
  14566. else if (r == 2)
  14567. {
  14568. // discard changes
  14569. return savedOk;
  14570. }
  14571. return userCancelledSave;
  14572. }
  14573. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14574. {
  14575. File f;
  14576. if (documentFile.existsAsFile())
  14577. f = documentFile;
  14578. else
  14579. f = getLastDocumentOpened();
  14580. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14581. if (legalFilename.isEmpty())
  14582. legalFilename = "unnamed";
  14583. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14584. f = f.getSiblingFile (legalFilename);
  14585. else
  14586. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14587. f = f.withFileExtension (fileExtension)
  14588. .getNonexistentSibling (true);
  14589. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14590. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14591. {
  14592. setLastDocumentOpened (fc.getResult());
  14593. File chosen (fc.getResult());
  14594. if (chosen.getFileExtension().isEmpty())
  14595. {
  14596. chosen = chosen.withFileExtension (fileExtension);
  14597. if (chosen.exists())
  14598. {
  14599. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14600. TRANS("File already exists"),
  14601. TRANS("There's already a file called:\n\n")
  14602. + chosen.getFullPathName()
  14603. + T("\n\nAre you sure you want to overwrite it?"),
  14604. TRANS("overwrite"),
  14605. TRANS("cancel")))
  14606. {
  14607. return userCancelledSave;
  14608. }
  14609. }
  14610. }
  14611. return saveAs (chosen, false, false, true);
  14612. }
  14613. return userCancelledSave;
  14614. }
  14615. END_JUCE_NAMESPACE
  14616. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14617. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14618. BEGIN_JUCE_NAMESPACE
  14619. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14620. : maxNumberOfItems (10)
  14621. {
  14622. }
  14623. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14624. {
  14625. }
  14626. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14627. {
  14628. maxNumberOfItems = jmax (1, newMaxNumber);
  14629. while (getNumFiles() > maxNumberOfItems)
  14630. files.remove (getNumFiles() - 1);
  14631. }
  14632. int RecentlyOpenedFilesList::getNumFiles() const
  14633. {
  14634. return files.size();
  14635. }
  14636. const File RecentlyOpenedFilesList::getFile (const int index) const
  14637. {
  14638. return File (files [index]);
  14639. }
  14640. void RecentlyOpenedFilesList::clear()
  14641. {
  14642. files.clear();
  14643. }
  14644. void RecentlyOpenedFilesList::addFile (const File& file)
  14645. {
  14646. const String path (file.getFullPathName());
  14647. files.removeString (path, true);
  14648. files.insert (0, path);
  14649. setMaxNumberOfItems (maxNumberOfItems);
  14650. }
  14651. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14652. {
  14653. for (int i = getNumFiles(); --i >= 0;)
  14654. if (! getFile(i).exists())
  14655. files.remove (i);
  14656. }
  14657. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14658. const int baseItemId,
  14659. const bool showFullPaths,
  14660. const bool dontAddNonExistentFiles,
  14661. const File** filesToAvoid)
  14662. {
  14663. int num = 0;
  14664. for (int i = 0; i < getNumFiles(); ++i)
  14665. {
  14666. const File f (getFile(i));
  14667. if ((! dontAddNonExistentFiles) || f.exists())
  14668. {
  14669. bool needsAvoiding = false;
  14670. if (filesToAvoid != 0)
  14671. {
  14672. const File** avoid = filesToAvoid;
  14673. while (*avoid != 0)
  14674. {
  14675. if (f == **avoid)
  14676. {
  14677. needsAvoiding = true;
  14678. break;
  14679. }
  14680. ++avoid;
  14681. }
  14682. }
  14683. if (! needsAvoiding)
  14684. {
  14685. menuToAddTo.addItem (baseItemId + i,
  14686. showFullPaths ? f.getFullPathName()
  14687. : f.getFileName());
  14688. ++num;
  14689. }
  14690. }
  14691. }
  14692. return num;
  14693. }
  14694. const String RecentlyOpenedFilesList::toString() const
  14695. {
  14696. return files.joinIntoString (T("\n"));
  14697. }
  14698. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14699. {
  14700. clear();
  14701. files.addLines (stringifiedVersion);
  14702. setMaxNumberOfItems (maxNumberOfItems);
  14703. }
  14704. END_JUCE_NAMESPACE
  14705. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14706. /*** Start of inlined file: juce_UndoManager.cpp ***/
  14707. BEGIN_JUCE_NAMESPACE
  14708. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  14709. const int minimumTransactions)
  14710. : totalUnitsStored (0),
  14711. nextIndex (0),
  14712. newTransaction (true),
  14713. reentrancyCheck (false)
  14714. {
  14715. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  14716. minimumTransactions);
  14717. }
  14718. UndoManager::~UndoManager()
  14719. {
  14720. clearUndoHistory();
  14721. }
  14722. void UndoManager::clearUndoHistory()
  14723. {
  14724. transactions.clear();
  14725. transactionNames.clear();
  14726. totalUnitsStored = 0;
  14727. nextIndex = 0;
  14728. sendChangeMessage (this);
  14729. }
  14730. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  14731. {
  14732. return totalUnitsStored;
  14733. }
  14734. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  14735. const int minimumTransactions)
  14736. {
  14737. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  14738. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  14739. }
  14740. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  14741. {
  14742. if (command != 0)
  14743. {
  14744. if (actionName.isNotEmpty())
  14745. currentTransactionName = actionName;
  14746. if (reentrancyCheck)
  14747. {
  14748. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  14749. // undo() methods, or else these actions won't actually get done.
  14750. return false;
  14751. }
  14752. else
  14753. {
  14754. bool success = false;
  14755. JUCE_TRY
  14756. {
  14757. success = command->perform();
  14758. }
  14759. JUCE_CATCH_EXCEPTION
  14760. jassert (success);
  14761. if (success)
  14762. {
  14763. if (nextIndex > 0 && ! newTransaction)
  14764. {
  14765. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  14766. jassert (commandSet != 0);
  14767. if (commandSet == 0)
  14768. return false;
  14769. commandSet->add (command);
  14770. }
  14771. else
  14772. {
  14773. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  14774. commandSet->add (command);
  14775. transactions.insert (nextIndex, commandSet);
  14776. transactionNames.insert (nextIndex, currentTransactionName);
  14777. ++nextIndex;
  14778. }
  14779. totalUnitsStored += command->getSizeInUnits();
  14780. newTransaction = false;
  14781. }
  14782. while (nextIndex < transactions.size())
  14783. {
  14784. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  14785. for (int i = lastSet->size(); --i >= 0;)
  14786. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  14787. transactions.removeLast();
  14788. transactionNames.remove (transactionNames.size() - 1);
  14789. }
  14790. while (nextIndex > 0
  14791. && totalUnitsStored > maxNumUnitsToKeep
  14792. && transactions.size() > minimumTransactionsToKeep)
  14793. {
  14794. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  14795. for (int i = firstSet->size(); --i >= 0;)
  14796. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  14797. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  14798. transactions.remove (0);
  14799. transactionNames.remove (0);
  14800. --nextIndex;
  14801. }
  14802. sendChangeMessage (this);
  14803. return success;
  14804. }
  14805. }
  14806. return false;
  14807. }
  14808. void UndoManager::beginNewTransaction (const String& actionName)
  14809. {
  14810. newTransaction = true;
  14811. currentTransactionName = actionName;
  14812. }
  14813. void UndoManager::setCurrentTransactionName (const String& newName)
  14814. {
  14815. currentTransactionName = newName;
  14816. }
  14817. bool UndoManager::canUndo() const
  14818. {
  14819. return nextIndex > 0;
  14820. }
  14821. bool UndoManager::canRedo() const
  14822. {
  14823. return nextIndex < transactions.size();
  14824. }
  14825. const String UndoManager::getUndoDescription() const
  14826. {
  14827. return transactionNames [nextIndex - 1];
  14828. }
  14829. const String UndoManager::getRedoDescription() const
  14830. {
  14831. return transactionNames [nextIndex];
  14832. }
  14833. bool UndoManager::undo()
  14834. {
  14835. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14836. if (commandSet == 0)
  14837. return false;
  14838. reentrancyCheck = true;
  14839. bool failed = false;
  14840. for (int i = commandSet->size(); --i >= 0;)
  14841. {
  14842. if (! commandSet->getUnchecked(i)->undo())
  14843. {
  14844. jassertfalse
  14845. failed = true;
  14846. break;
  14847. }
  14848. }
  14849. reentrancyCheck = false;
  14850. if (failed)
  14851. {
  14852. clearUndoHistory();
  14853. }
  14854. else
  14855. {
  14856. --nextIndex;
  14857. }
  14858. beginNewTransaction();
  14859. sendChangeMessage (this);
  14860. return true;
  14861. }
  14862. bool UndoManager::redo()
  14863. {
  14864. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  14865. if (commandSet == 0)
  14866. return false;
  14867. reentrancyCheck = true;
  14868. bool failed = false;
  14869. for (int i = 0; i < commandSet->size(); ++i)
  14870. {
  14871. if (! commandSet->getUnchecked(i)->perform())
  14872. {
  14873. jassertfalse
  14874. failed = true;
  14875. break;
  14876. }
  14877. }
  14878. reentrancyCheck = false;
  14879. if (failed)
  14880. {
  14881. clearUndoHistory();
  14882. }
  14883. else
  14884. {
  14885. ++nextIndex;
  14886. }
  14887. beginNewTransaction();
  14888. sendChangeMessage (this);
  14889. return true;
  14890. }
  14891. bool UndoManager::undoCurrentTransactionOnly()
  14892. {
  14893. return newTransaction ? false
  14894. : undo();
  14895. }
  14896. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  14897. {
  14898. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14899. if (commandSet != 0 && ! newTransaction)
  14900. {
  14901. for (int i = 0; i < commandSet->size(); ++i)
  14902. actionsFound.add (commandSet->getUnchecked(i));
  14903. }
  14904. }
  14905. int UndoManager::getNumActionsInCurrentTransaction() const
  14906. {
  14907. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14908. if (commandSet != 0 && ! newTransaction)
  14909. return commandSet->size();
  14910. return 0;
  14911. }
  14912. END_JUCE_NAMESPACE
  14913. /*** End of inlined file: juce_UndoManager.cpp ***/
  14914. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  14915. BEGIN_JUCE_NAMESPACE
  14916. static const char* const aiffFormatName = "AIFF file";
  14917. static const tchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  14918. class AiffAudioFormatReader : public AudioFormatReader
  14919. {
  14920. public:
  14921. int bytesPerFrame;
  14922. int64 dataChunkStart;
  14923. bool littleEndian;
  14924. AiffAudioFormatReader (InputStream* in)
  14925. : AudioFormatReader (in, TRANS (aiffFormatName))
  14926. {
  14927. if (input->readInt() == chunkName ("FORM"))
  14928. {
  14929. const int len = input->readIntBigEndian();
  14930. const int64 end = input->getPosition() + len;
  14931. const int nextType = input->readInt();
  14932. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  14933. {
  14934. bool hasGotVer = false;
  14935. bool hasGotData = false;
  14936. bool hasGotType = false;
  14937. while (input->getPosition() < end)
  14938. {
  14939. const int type = input->readInt();
  14940. const uint32 length = (uint32) input->readIntBigEndian();
  14941. const int64 chunkEnd = input->getPosition() + length;
  14942. if (type == chunkName ("FVER"))
  14943. {
  14944. hasGotVer = true;
  14945. const int ver = input->readIntBigEndian();
  14946. if (ver != 0 && ver != (int)0xa2805140)
  14947. break;
  14948. }
  14949. else if (type == chunkName ("COMM"))
  14950. {
  14951. hasGotType = true;
  14952. numChannels = (unsigned int)input->readShortBigEndian();
  14953. lengthInSamples = input->readIntBigEndian();
  14954. bitsPerSample = input->readShortBigEndian();
  14955. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  14956. unsigned char sampleRateBytes[10];
  14957. input->read (sampleRateBytes, 10);
  14958. const int byte0 = sampleRateBytes[0];
  14959. if ((byte0 & 0x80) != 0
  14960. || byte0 <= 0x3F || byte0 > 0x40
  14961. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  14962. break;
  14963. unsigned int sampRate = ByteOrder::bigEndianInt ((char*) sampleRateBytes + 2);
  14964. sampRate >>= (16414 - ByteOrder::bigEndianShort ((char*) sampleRateBytes));
  14965. sampleRate = (int) sampRate;
  14966. if (length <= 18)
  14967. {
  14968. // some types don't have a chunk large enough to include a compression
  14969. // type, so assume it's just big-endian pcm
  14970. littleEndian = false;
  14971. }
  14972. else
  14973. {
  14974. const int compType = input->readInt();
  14975. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  14976. {
  14977. littleEndian = false;
  14978. }
  14979. else if (compType == chunkName ("sowt"))
  14980. {
  14981. littleEndian = true;
  14982. }
  14983. else
  14984. {
  14985. sampleRate = 0;
  14986. break;
  14987. }
  14988. }
  14989. }
  14990. else if (type == chunkName ("SSND"))
  14991. {
  14992. hasGotData = true;
  14993. const int offset = input->readIntBigEndian();
  14994. dataChunkStart = input->getPosition() + 4 + offset;
  14995. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  14996. }
  14997. else if ((hasGotVer && hasGotData && hasGotType)
  14998. || chunkEnd < input->getPosition()
  14999. || input->isExhausted())
  15000. {
  15001. break;
  15002. }
  15003. input->setPosition (chunkEnd);
  15004. }
  15005. }
  15006. }
  15007. }
  15008. ~AiffAudioFormatReader()
  15009. {
  15010. }
  15011. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15012. int64 startSampleInFile, int numSamples)
  15013. {
  15014. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  15015. if (samplesAvailable < numSamples)
  15016. {
  15017. for (int i = numDestChannels; --i >= 0;)
  15018. if (destSamples[i] != 0)
  15019. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  15020. numSamples = (int) samplesAvailable;
  15021. }
  15022. if (numSamples <= 0)
  15023. return true;
  15024. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  15025. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  15026. char tempBuffer [tempBufSize];
  15027. while (numSamples > 0)
  15028. {
  15029. int* left = destSamples[0];
  15030. if (left != 0)
  15031. left += startOffsetInDestBuffer;
  15032. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15033. if (right != 0)
  15034. right += startOffsetInDestBuffer;
  15035. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15036. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15037. if (bytesRead < numThisTime * bytesPerFrame)
  15038. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15039. if (bitsPerSample == 16)
  15040. {
  15041. if (littleEndian)
  15042. {
  15043. const short* src = (const short*) tempBuffer;
  15044. if (numChannels > 1)
  15045. {
  15046. if (left == 0)
  15047. {
  15048. for (int i = numThisTime; --i >= 0;)
  15049. {
  15050. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15051. ++src;
  15052. }
  15053. }
  15054. else if (right == 0)
  15055. {
  15056. for (int i = numThisTime; --i >= 0;)
  15057. {
  15058. ++src;
  15059. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15060. }
  15061. }
  15062. else
  15063. {
  15064. for (int i = numThisTime; --i >= 0;)
  15065. {
  15066. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15067. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15068. }
  15069. }
  15070. }
  15071. else
  15072. {
  15073. for (int i = numThisTime; --i >= 0;)
  15074. {
  15075. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15076. }
  15077. }
  15078. }
  15079. else
  15080. {
  15081. const char* src = (const char*) tempBuffer;
  15082. if (numChannels > 1)
  15083. {
  15084. if (left == 0)
  15085. {
  15086. for (int i = numThisTime; --i >= 0;)
  15087. {
  15088. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15089. src += 4;
  15090. }
  15091. }
  15092. else if (right == 0)
  15093. {
  15094. for (int i = numThisTime; --i >= 0;)
  15095. {
  15096. src += 2;
  15097. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15098. src += 2;
  15099. }
  15100. }
  15101. else
  15102. {
  15103. for (int i = numThisTime; --i >= 0;)
  15104. {
  15105. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15106. src += 2;
  15107. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15108. src += 2;
  15109. }
  15110. }
  15111. }
  15112. else
  15113. {
  15114. for (int i = numThisTime; --i >= 0;)
  15115. {
  15116. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15117. src += 2;
  15118. }
  15119. }
  15120. }
  15121. }
  15122. else if (bitsPerSample == 24)
  15123. {
  15124. const char* src = (const char*)tempBuffer;
  15125. if (littleEndian)
  15126. {
  15127. if (numChannels > 1)
  15128. {
  15129. if (left == 0)
  15130. {
  15131. for (int i = numThisTime; --i >= 0;)
  15132. {
  15133. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15134. src += 6;
  15135. }
  15136. }
  15137. else if (right == 0)
  15138. {
  15139. for (int i = numThisTime; --i >= 0;)
  15140. {
  15141. src += 3;
  15142. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15143. src += 3;
  15144. }
  15145. }
  15146. else
  15147. {
  15148. for (int i = numThisTime; --i >= 0;)
  15149. {
  15150. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15151. src += 3;
  15152. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15153. src += 3;
  15154. }
  15155. }
  15156. }
  15157. else
  15158. {
  15159. for (int i = numThisTime; --i >= 0;)
  15160. {
  15161. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15162. src += 3;
  15163. }
  15164. }
  15165. }
  15166. else
  15167. {
  15168. if (numChannels > 1)
  15169. {
  15170. if (left == 0)
  15171. {
  15172. for (int i = numThisTime; --i >= 0;)
  15173. {
  15174. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15175. src += 6;
  15176. }
  15177. }
  15178. else if (right == 0)
  15179. {
  15180. for (int i = numThisTime; --i >= 0;)
  15181. {
  15182. src += 3;
  15183. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15184. src += 3;
  15185. }
  15186. }
  15187. else
  15188. {
  15189. for (int i = numThisTime; --i >= 0;)
  15190. {
  15191. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15192. src += 3;
  15193. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15194. src += 3;
  15195. }
  15196. }
  15197. }
  15198. else
  15199. {
  15200. for (int i = numThisTime; --i >= 0;)
  15201. {
  15202. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15203. src += 3;
  15204. }
  15205. }
  15206. }
  15207. }
  15208. else if (bitsPerSample == 32)
  15209. {
  15210. const unsigned int* src = (const unsigned int*) tempBuffer;
  15211. unsigned int* l = (unsigned int*) left;
  15212. unsigned int* r = (unsigned int*) right;
  15213. if (littleEndian)
  15214. {
  15215. if (numChannels > 1)
  15216. {
  15217. if (l == 0)
  15218. {
  15219. for (int i = numThisTime; --i >= 0;)
  15220. {
  15221. ++src;
  15222. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15223. }
  15224. }
  15225. else if (r == 0)
  15226. {
  15227. for (int i = numThisTime; --i >= 0;)
  15228. {
  15229. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15230. ++src;
  15231. }
  15232. }
  15233. else
  15234. {
  15235. for (int i = numThisTime; --i >= 0;)
  15236. {
  15237. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15238. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15239. }
  15240. }
  15241. }
  15242. else
  15243. {
  15244. for (int i = numThisTime; --i >= 0;)
  15245. {
  15246. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15247. }
  15248. }
  15249. }
  15250. else
  15251. {
  15252. if (numChannels > 1)
  15253. {
  15254. if (l == 0)
  15255. {
  15256. for (int i = numThisTime; --i >= 0;)
  15257. {
  15258. ++src;
  15259. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15260. }
  15261. }
  15262. else if (r == 0)
  15263. {
  15264. for (int i = numThisTime; --i >= 0;)
  15265. {
  15266. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15267. ++src;
  15268. }
  15269. }
  15270. else
  15271. {
  15272. for (int i = numThisTime; --i >= 0;)
  15273. {
  15274. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15275. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15276. }
  15277. }
  15278. }
  15279. else
  15280. {
  15281. for (int i = numThisTime; --i >= 0;)
  15282. {
  15283. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15284. }
  15285. }
  15286. }
  15287. left = (int*) l;
  15288. right = (int*) r;
  15289. }
  15290. else if (bitsPerSample == 8)
  15291. {
  15292. const char* src = (const char*) tempBuffer;
  15293. if (numChannels > 1)
  15294. {
  15295. if (left == 0)
  15296. {
  15297. for (int i = numThisTime; --i >= 0;)
  15298. {
  15299. *right++ = ((int) *src++) << 24;
  15300. ++src;
  15301. }
  15302. }
  15303. else if (right == 0)
  15304. {
  15305. for (int i = numThisTime; --i >= 0;)
  15306. {
  15307. ++src;
  15308. *left++ = ((int) *src++) << 24;
  15309. }
  15310. }
  15311. else
  15312. {
  15313. for (int i = numThisTime; --i >= 0;)
  15314. {
  15315. *left++ = ((int) *src++) << 24;
  15316. *right++ = ((int) *src++) << 24;
  15317. }
  15318. }
  15319. }
  15320. else
  15321. {
  15322. for (int i = numThisTime; --i >= 0;)
  15323. {
  15324. *left++ = ((int) *src++) << 24;
  15325. }
  15326. }
  15327. }
  15328. startOffsetInDestBuffer += numThisTime;
  15329. numSamples -= numThisTime;
  15330. }
  15331. if (numSamples > 0)
  15332. {
  15333. for (int i = numDestChannels; --i >= 0;)
  15334. if (destSamples[i] != 0)
  15335. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15336. sizeof (int) * numSamples);
  15337. }
  15338. return true;
  15339. }
  15340. juce_UseDebuggingNewOperator
  15341. private:
  15342. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15343. AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15344. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15345. };
  15346. class AiffAudioFormatWriter : public AudioFormatWriter
  15347. {
  15348. MemoryBlock tempBlock;
  15349. uint32 lengthInSamples, bytesWritten;
  15350. int64 headerPosition;
  15351. bool writeFailed;
  15352. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15353. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15354. AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15355. void writeHeader()
  15356. {
  15357. const bool couldSeekOk = output->setPosition (headerPosition);
  15358. (void) couldSeekOk;
  15359. // if this fails, you've given it an output stream that can't seek! It needs
  15360. // to be able to seek back to write the header
  15361. jassert (couldSeekOk);
  15362. const int headerLen = 54;
  15363. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15364. audioBytes += (audioBytes & 1);
  15365. output->writeInt (chunkName ("FORM"));
  15366. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15367. output->writeInt (chunkName ("AIFF"));
  15368. output->writeInt (chunkName ("COMM"));
  15369. output->writeIntBigEndian (18);
  15370. output->writeShortBigEndian ((short) numChannels);
  15371. output->writeIntBigEndian (lengthInSamples);
  15372. output->writeShortBigEndian ((short) bitsPerSample);
  15373. uint8 sampleRateBytes[10];
  15374. zeromem (sampleRateBytes, 10);
  15375. if (sampleRate <= 1)
  15376. {
  15377. sampleRateBytes[0] = 0x3f;
  15378. sampleRateBytes[1] = 0xff;
  15379. sampleRateBytes[2] = 0x80;
  15380. }
  15381. else
  15382. {
  15383. int mask = 0x40000000;
  15384. sampleRateBytes[0] = 0x40;
  15385. if (sampleRate >= mask)
  15386. {
  15387. jassertfalse
  15388. sampleRateBytes[1] = 0x1d;
  15389. }
  15390. else
  15391. {
  15392. int n = (int) sampleRate;
  15393. int i;
  15394. for (i = 0; i <= 32 ; ++i)
  15395. {
  15396. if ((n & mask) != 0)
  15397. break;
  15398. mask >>= 1;
  15399. }
  15400. n = n << (i + 1);
  15401. sampleRateBytes[1] = (uint8) (29 - i);
  15402. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15403. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15404. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15405. sampleRateBytes[5] = (uint8) (n & 0xff);
  15406. }
  15407. }
  15408. output->write (sampleRateBytes, 10);
  15409. output->writeInt (chunkName ("SSND"));
  15410. output->writeIntBigEndian (audioBytes + 8);
  15411. output->writeInt (0);
  15412. output->writeInt (0);
  15413. jassert (output->getPosition() == headerLen);
  15414. }
  15415. public:
  15416. AiffAudioFormatWriter (OutputStream* out,
  15417. const double sampleRate_,
  15418. const unsigned int chans,
  15419. const int bits)
  15420. : AudioFormatWriter (out,
  15421. TRANS (aiffFormatName),
  15422. sampleRate_,
  15423. chans,
  15424. bits),
  15425. lengthInSamples (0),
  15426. bytesWritten (0),
  15427. writeFailed (false)
  15428. {
  15429. headerPosition = out->getPosition();
  15430. writeHeader();
  15431. }
  15432. ~AiffAudioFormatWriter()
  15433. {
  15434. if ((bytesWritten & 1) != 0)
  15435. output->writeByte (0);
  15436. writeHeader();
  15437. }
  15438. bool write (const int** data, int numSamples)
  15439. {
  15440. if (writeFailed)
  15441. return false;
  15442. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15443. tempBlock.ensureSize (bytes, false);
  15444. char* buffer = (char*) tempBlock.getData();
  15445. const int* left = data[0];
  15446. const int* right = data[1];
  15447. if (right == 0)
  15448. right = left;
  15449. if (bitsPerSample == 16)
  15450. {
  15451. short* b = (short*) buffer;
  15452. if (numChannels > 1)
  15453. {
  15454. for (int i = numSamples; --i >= 0;)
  15455. {
  15456. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15457. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15458. }
  15459. }
  15460. else
  15461. {
  15462. for (int i = numSamples; --i >= 0;)
  15463. {
  15464. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15465. }
  15466. }
  15467. }
  15468. else if (bitsPerSample == 24)
  15469. {
  15470. char* b = (char*) buffer;
  15471. if (numChannels > 1)
  15472. {
  15473. for (int i = numSamples; --i >= 0;)
  15474. {
  15475. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15476. b += 3;
  15477. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15478. b += 3;
  15479. }
  15480. }
  15481. else
  15482. {
  15483. for (int i = numSamples; --i >= 0;)
  15484. {
  15485. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15486. b += 3;
  15487. }
  15488. }
  15489. }
  15490. else if (bitsPerSample == 32)
  15491. {
  15492. uint32* b = (uint32*) buffer;
  15493. if (numChannels > 1)
  15494. {
  15495. for (int i = numSamples; --i >= 0;)
  15496. {
  15497. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15498. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15499. }
  15500. }
  15501. else
  15502. {
  15503. for (int i = numSamples; --i >= 0;)
  15504. {
  15505. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15506. }
  15507. }
  15508. }
  15509. else if (bitsPerSample == 8)
  15510. {
  15511. char* b = (char*) buffer;
  15512. if (numChannels > 1)
  15513. {
  15514. for (int i = numSamples; --i >= 0;)
  15515. {
  15516. *b++ = (char) (*left++ >> 24);
  15517. *b++ = (char) (*right++ >> 24);
  15518. }
  15519. }
  15520. else
  15521. {
  15522. for (int i = numSamples; --i >= 0;)
  15523. {
  15524. *b++ = (char) (*left++ >> 24);
  15525. }
  15526. }
  15527. }
  15528. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15529. || ! output->write (buffer, bytes))
  15530. {
  15531. // failed to write to disk, so let's try writing the header.
  15532. // If it's just run out of disk space, then if it does manage
  15533. // to write the header, we'll still have a useable file..
  15534. writeHeader();
  15535. writeFailed = true;
  15536. return false;
  15537. }
  15538. else
  15539. {
  15540. bytesWritten += bytes;
  15541. lengthInSamples += numSamples;
  15542. return true;
  15543. }
  15544. }
  15545. juce_UseDebuggingNewOperator
  15546. };
  15547. AiffAudioFormat::AiffAudioFormat()
  15548. : AudioFormat (TRANS (aiffFormatName), (const tchar**) aiffExtensions)
  15549. {
  15550. }
  15551. AiffAudioFormat::~AiffAudioFormat()
  15552. {
  15553. }
  15554. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15555. {
  15556. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15557. return Array <int> (rates);
  15558. }
  15559. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15560. {
  15561. const int depths[] = { 8, 16, 24, 0 };
  15562. return Array <int> (depths);
  15563. }
  15564. bool AiffAudioFormat::canDoStereo()
  15565. {
  15566. return true;
  15567. }
  15568. bool AiffAudioFormat::canDoMono()
  15569. {
  15570. return true;
  15571. }
  15572. #if JUCE_MAC
  15573. bool AiffAudioFormat::canHandleFile (const File& f)
  15574. {
  15575. if (AudioFormat::canHandleFile (f))
  15576. return true;
  15577. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15578. return type == 'AIFF' || type == 'AIFC'
  15579. || type == 'aiff' || type == 'aifc';
  15580. }
  15581. #endif
  15582. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15583. const bool deleteStreamIfOpeningFails)
  15584. {
  15585. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15586. if (w->sampleRate != 0)
  15587. return w.release();
  15588. if (! deleteStreamIfOpeningFails)
  15589. w->input = 0;
  15590. return 0;
  15591. }
  15592. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15593. double sampleRate,
  15594. unsigned int chans,
  15595. int bitsPerSample,
  15596. const StringPairArray& /*metadataValues*/,
  15597. int /*qualityOptionIndex*/)
  15598. {
  15599. if (getPossibleBitDepths().contains (bitsPerSample))
  15600. {
  15601. return new AiffAudioFormatWriter (out,
  15602. sampleRate,
  15603. chans,
  15604. bitsPerSample);
  15605. }
  15606. return 0;
  15607. }
  15608. END_JUCE_NAMESPACE
  15609. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15610. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15611. BEGIN_JUCE_NAMESPACE
  15612. #if JUCE_MAC && JUCE_USE_CDREADER
  15613. // Mac version doesn't need any native code because it's all done with files..
  15614. // Windows + Linux versions are in the platform-dependent code sections.
  15615. static void findCDs (Array<File>& cds)
  15616. {
  15617. File volumes ("/Volumes");
  15618. volumes.findChildFiles (cds, File::findDirectories, false);
  15619. for (int i = cds.size(); --i >= 0;)
  15620. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15621. cds.remove (i);
  15622. }
  15623. const StringArray AudioCDReader::getAvailableCDNames()
  15624. {
  15625. Array<File> cds;
  15626. findCDs (cds);
  15627. StringArray names;
  15628. for (int i = 0; i < cds.size(); ++i)
  15629. names.add (cds.getReference(i).getFileName());
  15630. return names;
  15631. }
  15632. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15633. {
  15634. Array<File> cds;
  15635. findCDs (cds);
  15636. if (cds[index] != File::nonexistent)
  15637. return new AudioCDReader (cds[index]);
  15638. else
  15639. return 0;
  15640. }
  15641. AudioCDReader::AudioCDReader (const File& volume)
  15642. : AudioFormatReader (0, "CD Audio"),
  15643. volumeDir (volume),
  15644. currentReaderTrack (-1),
  15645. reader (0)
  15646. {
  15647. sampleRate = 44100.0;
  15648. bitsPerSample = 16;
  15649. numChannels = 2;
  15650. usesFloatingPointData = false;
  15651. refreshTrackLengths();
  15652. }
  15653. AudioCDReader::~AudioCDReader()
  15654. {
  15655. }
  15656. static int getTrackNumber (const File& file)
  15657. {
  15658. return file.getFileName()
  15659. .initialSectionContainingOnly (T("0123456789"))
  15660. .getIntValue();
  15661. }
  15662. int AudioCDReader::compareElements (const File& first, const File& second)
  15663. {
  15664. const int firstTrack = getTrackNumber (first);
  15665. const int secondTrack = getTrackNumber (second);
  15666. jassert (firstTrack > 0 && secondTrack > 0);
  15667. return firstTrack - secondTrack;
  15668. }
  15669. void AudioCDReader::refreshTrackLengths()
  15670. {
  15671. tracks.clear();
  15672. trackStartSamples.clear();
  15673. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, T("*.aiff"));
  15674. tracks.sort (*this);
  15675. AiffAudioFormat format;
  15676. int sample = 0;
  15677. for (int i = 0; i < tracks.size(); ++i)
  15678. {
  15679. trackStartSamples.add (sample);
  15680. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15681. if (in != 0)
  15682. {
  15683. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15684. if (r != 0)
  15685. sample += (int) r->lengthInSamples;
  15686. }
  15687. }
  15688. trackStartSamples.add (sample);
  15689. lengthInSamples = sample;
  15690. }
  15691. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15692. int64 startSampleInFile, int numSamples)
  15693. {
  15694. while (numSamples > 0)
  15695. {
  15696. int track = -1;
  15697. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15698. {
  15699. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15700. {
  15701. track = i;
  15702. break;
  15703. }
  15704. }
  15705. if (track < 0)
  15706. return false;
  15707. if (track != currentReaderTrack)
  15708. {
  15709. reader = 0;
  15710. FileInputStream* const in = tracks [track].createInputStream();
  15711. if (in != 0)
  15712. {
  15713. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  15714. AiffAudioFormat format;
  15715. reader = format.createReaderFor (bin, true);
  15716. if (reader == 0)
  15717. currentReaderTrack = -1;
  15718. else
  15719. currentReaderTrack = track;
  15720. }
  15721. }
  15722. if (reader == 0)
  15723. return false;
  15724. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  15725. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  15726. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  15727. numSamples -= numAvailable;
  15728. startSampleInFile += numAvailable;
  15729. }
  15730. return true;
  15731. }
  15732. bool AudioCDReader::isCDStillPresent() const
  15733. {
  15734. return volumeDir.exists();
  15735. }
  15736. int AudioCDReader::getNumTracks() const
  15737. {
  15738. return tracks.size();
  15739. }
  15740. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  15741. {
  15742. return trackStartSamples [trackNum];
  15743. }
  15744. bool AudioCDReader::isTrackAudio (int trackNum) const
  15745. {
  15746. return tracks [trackNum] != File::nonexistent;
  15747. }
  15748. void AudioCDReader::enableIndexScanning (bool b)
  15749. {
  15750. // any way to do this on a Mac??
  15751. }
  15752. int AudioCDReader::getLastIndex() const
  15753. {
  15754. return 0;
  15755. }
  15756. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  15757. {
  15758. return Array <int>();
  15759. }
  15760. int AudioCDReader::getCDDBId()
  15761. {
  15762. return 0; //xxx
  15763. }
  15764. #endif
  15765. END_JUCE_NAMESPACE
  15766. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  15767. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  15768. BEGIN_JUCE_NAMESPACE
  15769. AudioFormatReader::AudioFormatReader (InputStream* const in,
  15770. const String& formatName_)
  15771. : sampleRate (0),
  15772. bitsPerSample (0),
  15773. lengthInSamples (0),
  15774. numChannels (0),
  15775. usesFloatingPointData (false),
  15776. input (in),
  15777. formatName (formatName_)
  15778. {
  15779. }
  15780. AudioFormatReader::~AudioFormatReader()
  15781. {
  15782. delete input;
  15783. }
  15784. bool AudioFormatReader::read (int** destSamples,
  15785. int numDestChannels,
  15786. int64 startSampleInSource,
  15787. int numSamplesToRead,
  15788. const bool fillLeftoverChannelsWithCopies)
  15789. {
  15790. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  15791. int startOffsetInDestBuffer = 0;
  15792. if (startSampleInSource < 0)
  15793. {
  15794. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  15795. for (int i = numDestChannels; --i >= 0;)
  15796. if (destSamples[i] != 0)
  15797. zeromem (destSamples[i], sizeof (int) * silence);
  15798. startOffsetInDestBuffer += silence;
  15799. numSamplesToRead -= silence;
  15800. startSampleInSource = 0;
  15801. }
  15802. if (numSamplesToRead <= 0)
  15803. return true;
  15804. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  15805. startSampleInSource, numSamplesToRead))
  15806. return false;
  15807. if (numDestChannels > (int) numChannels)
  15808. {
  15809. if (fillLeftoverChannelsWithCopies)
  15810. {
  15811. int* lastFullChannel = destSamples[0];
  15812. for (int i = numDestChannels; --i > 0;)
  15813. {
  15814. if (destSamples[i] != 0)
  15815. {
  15816. lastFullChannel = destSamples[i];
  15817. break;
  15818. }
  15819. }
  15820. if (lastFullChannel != 0)
  15821. for (int i = numChannels; i < numDestChannels; ++i)
  15822. if (destSamples[i] != 0)
  15823. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  15824. }
  15825. else
  15826. {
  15827. for (int i = numChannels; i < numDestChannels; ++i)
  15828. if (destSamples[i] != 0)
  15829. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  15830. }
  15831. }
  15832. return true;
  15833. }
  15834. static void findAudioBufferMaxMin (const float* const buffer, const int num, float& maxVal, float& minVal) throw()
  15835. {
  15836. float mn = buffer[0];
  15837. float mx = mn;
  15838. for (int i = 1; i < num; ++i)
  15839. {
  15840. const float s = buffer[i];
  15841. if (s > mx) mx = s;
  15842. if (s < mn) mn = s;
  15843. }
  15844. maxVal = mx;
  15845. minVal = mn;
  15846. }
  15847. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  15848. int64 numSamples,
  15849. float& lowestLeft, float& highestLeft,
  15850. float& lowestRight, float& highestRight)
  15851. {
  15852. if (numSamples <= 0)
  15853. {
  15854. lowestLeft = 0;
  15855. lowestRight = 0;
  15856. highestLeft = 0;
  15857. highestRight = 0;
  15858. return;
  15859. }
  15860. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  15861. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15862. int* tempBuffer[3];
  15863. tempBuffer[0] = (int*) tempSpace.getData();
  15864. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15865. tempBuffer[2] = 0;
  15866. if (usesFloatingPointData)
  15867. {
  15868. float lmin = 1.0e6f;
  15869. float lmax = -lmin;
  15870. float rmin = lmin;
  15871. float rmax = lmax;
  15872. while (numSamples > 0)
  15873. {
  15874. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15875. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15876. numSamples -= numToDo;
  15877. startSampleInFile += numToDo;
  15878. float bufmin, bufmax;
  15879. findAudioBufferMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  15880. lmin = jmin (lmin, bufmin);
  15881. lmax = jmax (lmax, bufmax);
  15882. if (numChannels > 1)
  15883. {
  15884. findAudioBufferMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  15885. rmin = jmin (rmin, bufmin);
  15886. rmax = jmax (rmax, bufmax);
  15887. }
  15888. }
  15889. if (numChannels <= 1)
  15890. {
  15891. rmax = lmax;
  15892. rmin = lmin;
  15893. }
  15894. lowestLeft = lmin;
  15895. highestLeft = lmax;
  15896. lowestRight = rmin;
  15897. highestRight = rmax;
  15898. }
  15899. else
  15900. {
  15901. int lmax = std::numeric_limits<int>::min();
  15902. int lmin = std::numeric_limits<int>::max();
  15903. int rmax = std::numeric_limits<int>::min();
  15904. int rmin = std::numeric_limits<int>::max();
  15905. while (numSamples > 0)
  15906. {
  15907. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15908. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15909. numSamples -= numToDo;
  15910. startSampleInFile += numToDo;
  15911. for (int j = numChannels; --j >= 0;)
  15912. {
  15913. int bufMax = std::numeric_limits<int>::min();
  15914. int bufMin = std::numeric_limits<int>::max();
  15915. const int* const b = tempBuffer[j];
  15916. for (int i = 0; i < numToDo; ++i)
  15917. {
  15918. const int samp = b[i];
  15919. if (samp < bufMin)
  15920. bufMin = samp;
  15921. if (samp > bufMax)
  15922. bufMax = samp;
  15923. }
  15924. if (j == 0)
  15925. {
  15926. lmax = jmax (lmax, bufMax);
  15927. lmin = jmin (lmin, bufMin);
  15928. }
  15929. else
  15930. {
  15931. rmax = jmax (rmax, bufMax);
  15932. rmin = jmin (rmin, bufMin);
  15933. }
  15934. }
  15935. }
  15936. if (numChannels <= 1)
  15937. {
  15938. rmax = lmax;
  15939. rmin = lmin;
  15940. }
  15941. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  15942. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  15943. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  15944. highestRight = rmax / (float) std::numeric_limits<int>::max();
  15945. }
  15946. }
  15947. int64 AudioFormatReader::searchForLevel (int64 startSample,
  15948. int64 numSamplesToSearch,
  15949. const double magnitudeRangeMinimum,
  15950. const double magnitudeRangeMaximum,
  15951. const int minimumConsecutiveSamples)
  15952. {
  15953. if (numSamplesToSearch == 0)
  15954. return -1;
  15955. const int bufferSize = 4096;
  15956. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15957. int* tempBuffer[3];
  15958. tempBuffer[0] = (int*) tempSpace.getData();
  15959. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15960. tempBuffer[2] = 0;
  15961. int consecutive = 0;
  15962. int64 firstMatchPos = -1;
  15963. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  15964. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  15965. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  15966. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  15967. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  15968. while (numSamplesToSearch != 0)
  15969. {
  15970. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  15971. int64 bufferStart = startSample;
  15972. if (numSamplesToSearch < 0)
  15973. bufferStart -= numThisTime;
  15974. if (bufferStart >= (int) lengthInSamples)
  15975. break;
  15976. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  15977. int num = numThisTime;
  15978. while (--num >= 0)
  15979. {
  15980. if (numSamplesToSearch < 0)
  15981. --startSample;
  15982. bool matches = false;
  15983. const int index = (int) (startSample - bufferStart);
  15984. if (usesFloatingPointData)
  15985. {
  15986. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  15987. if (sample1 >= magnitudeRangeMinimum
  15988. && sample1 <= magnitudeRangeMaximum)
  15989. {
  15990. matches = true;
  15991. }
  15992. else if (numChannels > 1)
  15993. {
  15994. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  15995. matches = (sample2 >= magnitudeRangeMinimum
  15996. && sample2 <= magnitudeRangeMaximum);
  15997. }
  15998. }
  15999. else
  16000. {
  16001. const int sample1 = abs (tempBuffer[0] [index]);
  16002. if (sample1 >= intMagnitudeRangeMinimum
  16003. && sample1 <= intMagnitudeRangeMaximum)
  16004. {
  16005. matches = true;
  16006. }
  16007. else if (numChannels > 1)
  16008. {
  16009. const int sample2 = abs (tempBuffer[1][index]);
  16010. matches = (sample2 >= intMagnitudeRangeMinimum
  16011. && sample2 <= intMagnitudeRangeMaximum);
  16012. }
  16013. }
  16014. if (matches)
  16015. {
  16016. if (firstMatchPos < 0)
  16017. firstMatchPos = startSample;
  16018. if (++consecutive >= minimumConsecutiveSamples)
  16019. {
  16020. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  16021. return -1;
  16022. return firstMatchPos;
  16023. }
  16024. }
  16025. else
  16026. {
  16027. consecutive = 0;
  16028. firstMatchPos = -1;
  16029. }
  16030. if (numSamplesToSearch > 0)
  16031. ++startSample;
  16032. }
  16033. if (numSamplesToSearch > 0)
  16034. numSamplesToSearch -= numThisTime;
  16035. else
  16036. numSamplesToSearch += numThisTime;
  16037. }
  16038. return -1;
  16039. }
  16040. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16041. const String& formatName_,
  16042. const double rate,
  16043. const unsigned int numChannels_,
  16044. const unsigned int bitsPerSample_)
  16045. : sampleRate (rate),
  16046. numChannels (numChannels_),
  16047. bitsPerSample (bitsPerSample_),
  16048. usesFloatingPointData (false),
  16049. output (out),
  16050. formatName (formatName_)
  16051. {
  16052. }
  16053. AudioFormatWriter::~AudioFormatWriter()
  16054. {
  16055. delete output;
  16056. }
  16057. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16058. int64 startSample,
  16059. int64 numSamplesToRead)
  16060. {
  16061. const int bufferSize = 16384;
  16062. const int maxChans = 128;
  16063. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16064. int* buffers [maxChans];
  16065. for (int i = maxChans; --i >= 0;)
  16066. buffers[i] = 0;
  16067. if (numSamplesToRead < 0)
  16068. numSamplesToRead = reader.lengthInSamples;
  16069. while (numSamplesToRead > 0)
  16070. {
  16071. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16072. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16073. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16074. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16075. return false;
  16076. if (reader.usesFloatingPointData != isFloatingPoint())
  16077. {
  16078. int** bufferChan = buffers;
  16079. while (*bufferChan != 0)
  16080. {
  16081. int* b = *bufferChan++;
  16082. if (isFloatingPoint())
  16083. {
  16084. // int -> float
  16085. const double factor = 1.0 / std::numeric_limits<int>::max();
  16086. for (int i = 0; i < numToDo; ++i)
  16087. ((float*) b)[i] = (float) (factor * b[i]);
  16088. }
  16089. else
  16090. {
  16091. // float -> int
  16092. for (int i = 0; i < numToDo; ++i)
  16093. {
  16094. const double samp = *(const float*) b;
  16095. if (samp <= -1.0)
  16096. *b++ = std::numeric_limits<int>::min();
  16097. else if (samp >= 1.0)
  16098. *b++ = std::numeric_limits<int>::max();
  16099. else
  16100. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16101. }
  16102. }
  16103. }
  16104. }
  16105. if (! write ((const int**) buffers, numToDo))
  16106. return false;
  16107. numSamplesToRead -= numToDo;
  16108. startSample += numToDo;
  16109. }
  16110. return true;
  16111. }
  16112. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16113. int numSamplesToRead,
  16114. const int samplesPerBlock)
  16115. {
  16116. const int maxChans = 128;
  16117. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16118. int* buffers [maxChans];
  16119. while (numSamplesToRead > 0)
  16120. {
  16121. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16122. AudioSourceChannelInfo info;
  16123. info.buffer = &tempBuffer;
  16124. info.startSample = 0;
  16125. info.numSamples = numToDo;
  16126. info.clearActiveBufferRegion();
  16127. source.getNextAudioBlock (info);
  16128. int i;
  16129. for (i = maxChans; --i >= 0;)
  16130. buffers[i] = 0;
  16131. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16132. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16133. if (! isFloatingPoint())
  16134. {
  16135. int** bufferChan = buffers;
  16136. while (*bufferChan != 0)
  16137. {
  16138. int* b = *bufferChan++;
  16139. // float -> int
  16140. for (int j = numToDo; --j >= 0;)
  16141. {
  16142. const double samp = *(const float*) b;
  16143. if (samp <= -1.0)
  16144. *b++ = std::numeric_limits<int>::min();
  16145. else if (samp >= 1.0)
  16146. *b++ = std::numeric_limits<int>::max();
  16147. else
  16148. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16149. }
  16150. }
  16151. }
  16152. if (! write ((const int**) buffers, numToDo))
  16153. return false;
  16154. numSamplesToRead -= numToDo;
  16155. }
  16156. return true;
  16157. }
  16158. AudioFormat::AudioFormat (const String& name,
  16159. const tchar** const extensions)
  16160. : formatName (name),
  16161. fileExtensions (extensions)
  16162. {
  16163. }
  16164. AudioFormat::~AudioFormat()
  16165. {
  16166. }
  16167. const String& AudioFormat::getFormatName() const
  16168. {
  16169. return formatName;
  16170. }
  16171. const StringArray& AudioFormat::getFileExtensions() const
  16172. {
  16173. return fileExtensions;
  16174. }
  16175. bool AudioFormat::canHandleFile (const File& f)
  16176. {
  16177. for (int i = 0; i < fileExtensions.size(); ++i)
  16178. if (f.hasFileExtension (fileExtensions[i]))
  16179. return true;
  16180. return false;
  16181. }
  16182. bool AudioFormat::isCompressed()
  16183. {
  16184. return false;
  16185. }
  16186. const StringArray AudioFormat::getQualityOptions()
  16187. {
  16188. return StringArray();
  16189. }
  16190. END_JUCE_NAMESPACE
  16191. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16192. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16193. BEGIN_JUCE_NAMESPACE
  16194. AudioFormatManager::AudioFormatManager()
  16195. : defaultFormatIndex (0)
  16196. {
  16197. }
  16198. AudioFormatManager::~AudioFormatManager()
  16199. {
  16200. clearFormats();
  16201. clearSingletonInstance();
  16202. }
  16203. juce_ImplementSingleton (AudioFormatManager);
  16204. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16205. const bool makeThisTheDefaultFormat)
  16206. {
  16207. jassert (newFormat != 0);
  16208. if (newFormat != 0)
  16209. {
  16210. #ifdef JUCE_DEBUG
  16211. for (int i = getNumKnownFormats(); --i >= 0;)
  16212. {
  16213. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16214. {
  16215. jassertfalse // trying to add the same format twice!
  16216. }
  16217. }
  16218. #endif
  16219. if (makeThisTheDefaultFormat)
  16220. defaultFormatIndex = knownFormats.size();
  16221. knownFormats.add (newFormat);
  16222. }
  16223. }
  16224. void AudioFormatManager::registerBasicFormats()
  16225. {
  16226. #if JUCE_MAC
  16227. registerFormat (new AiffAudioFormat(), true);
  16228. registerFormat (new WavAudioFormat(), false);
  16229. #else
  16230. registerFormat (new WavAudioFormat(), true);
  16231. registerFormat (new AiffAudioFormat(), false);
  16232. #endif
  16233. #if JUCE_USE_FLAC
  16234. registerFormat (new FlacAudioFormat(), false);
  16235. #endif
  16236. #if JUCE_USE_OGGVORBIS
  16237. registerFormat (new OggVorbisAudioFormat(), false);
  16238. #endif
  16239. }
  16240. void AudioFormatManager::clearFormats()
  16241. {
  16242. for (int i = getNumKnownFormats(); --i >= 0;)
  16243. delete getKnownFormat(i);
  16244. knownFormats.clear();
  16245. defaultFormatIndex = 0;
  16246. }
  16247. int AudioFormatManager::getNumKnownFormats() const
  16248. {
  16249. return knownFormats.size();
  16250. }
  16251. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16252. {
  16253. return (AudioFormat*) knownFormats [index];
  16254. }
  16255. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16256. {
  16257. return getKnownFormat (defaultFormatIndex);
  16258. }
  16259. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16260. {
  16261. String e (fileExtension);
  16262. if (! e.startsWithChar (T('.')))
  16263. e = T(".") + e;
  16264. for (int i = 0; i < getNumKnownFormats(); ++i)
  16265. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16266. return getKnownFormat(i);
  16267. return 0;
  16268. }
  16269. const String AudioFormatManager::getWildcardForAllFormats() const
  16270. {
  16271. StringArray allExtensions;
  16272. int i;
  16273. for (i = 0; i < getNumKnownFormats(); ++i)
  16274. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16275. allExtensions.trim();
  16276. allExtensions.removeEmptyStrings();
  16277. String s;
  16278. for (i = 0; i < allExtensions.size(); ++i)
  16279. {
  16280. s << T('*');
  16281. if (! allExtensions[i].startsWithChar (T('.')))
  16282. s << T('.');
  16283. s << allExtensions[i];
  16284. if (i < allExtensions.size() - 1)
  16285. s << T(';');
  16286. }
  16287. return s;
  16288. }
  16289. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16290. {
  16291. // you need to actually register some formats before the manager can
  16292. // use them to open a file!
  16293. jassert (knownFormats.size() > 0);
  16294. for (int i = 0; i < getNumKnownFormats(); ++i)
  16295. {
  16296. AudioFormat* const af = getKnownFormat(i);
  16297. if (af->canHandleFile (file))
  16298. {
  16299. InputStream* const in = file.createInputStream();
  16300. if (in != 0)
  16301. {
  16302. AudioFormatReader* const r = af->createReaderFor (in, true);
  16303. if (r != 0)
  16304. return r;
  16305. }
  16306. }
  16307. }
  16308. return 0;
  16309. }
  16310. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16311. {
  16312. // you need to actually register some formats before the manager can
  16313. // use them to open a file!
  16314. jassert (knownFormats.size() > 0);
  16315. ScopedPointer <InputStream> in (audioFileStream);
  16316. if (in != 0)
  16317. {
  16318. const int64 originalStreamPos = in->getPosition();
  16319. for (int i = 0; i < getNumKnownFormats(); ++i)
  16320. {
  16321. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16322. if (r != 0)
  16323. {
  16324. in.release();
  16325. return r;
  16326. }
  16327. in->setPosition (originalStreamPos);
  16328. // the stream that is passed-in must be capable of being repositioned so
  16329. // that all the formats can have a go at opening it.
  16330. jassert (in->getPosition() == originalStreamPos);
  16331. }
  16332. }
  16333. return 0;
  16334. }
  16335. END_JUCE_NAMESPACE
  16336. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16337. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16338. BEGIN_JUCE_NAMESPACE
  16339. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16340. const int64 startSample_,
  16341. const int64 length_,
  16342. const bool deleteSourceWhenDeleted_)
  16343. : AudioFormatReader (0, source_->getFormatName()),
  16344. source (source_),
  16345. startSample (startSample_),
  16346. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16347. {
  16348. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16349. sampleRate = source->sampleRate;
  16350. bitsPerSample = source->bitsPerSample;
  16351. lengthInSamples = length;
  16352. numChannels = source->numChannels;
  16353. usesFloatingPointData = source->usesFloatingPointData;
  16354. }
  16355. AudioSubsectionReader::~AudioSubsectionReader()
  16356. {
  16357. if (deleteSourceWhenDeleted)
  16358. delete source;
  16359. }
  16360. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16361. int64 startSampleInFile, int numSamples)
  16362. {
  16363. if (startSampleInFile + numSamples > length)
  16364. {
  16365. for (int i = numDestChannels; --i >= 0;)
  16366. if (destSamples[i] != 0)
  16367. zeromem (destSamples[i], sizeof (int) * numSamples);
  16368. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16369. if (numSamples <= 0)
  16370. return true;
  16371. }
  16372. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16373. startSampleInFile + startSample, numSamples);
  16374. }
  16375. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16376. int64 numSamples,
  16377. float& lowestLeft,
  16378. float& highestLeft,
  16379. float& lowestRight,
  16380. float& highestRight)
  16381. {
  16382. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16383. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16384. source->readMaxLevels (startSampleInFile + startSample,
  16385. numSamples,
  16386. lowestLeft,
  16387. highestLeft,
  16388. lowestRight,
  16389. highestRight);
  16390. }
  16391. END_JUCE_NAMESPACE
  16392. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16393. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16394. BEGIN_JUCE_NAMESPACE
  16395. const int timeBeforeDeletingReader = 2000;
  16396. struct AudioThumbnailDataFormat
  16397. {
  16398. char thumbnailMagic[4];
  16399. int samplesPerThumbSample;
  16400. int64 totalSamples; // source samples
  16401. int64 numFinishedSamples; // source samples
  16402. int numThumbnailSamples;
  16403. int numChannels;
  16404. int sampleRate;
  16405. char future[16];
  16406. char data[1];
  16407. void swapEndiannessIfNeeded() throw()
  16408. {
  16409. #if JUCE_BIG_ENDIAN
  16410. flip (samplesPerThumbSample);
  16411. flip (totalSamples);
  16412. flip (numFinishedSamples);
  16413. flip (numThumbnailSamples);
  16414. flip (numChannels);
  16415. flip (sampleRate);
  16416. #endif
  16417. }
  16418. private:
  16419. #if JUCE_BIG_ENDIAN
  16420. static void flip (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16421. static void flip (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16422. #endif
  16423. };
  16424. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16425. AudioFormatManager& formatManagerToUse_,
  16426. AudioThumbnailCache& cacheToUse)
  16427. : formatManagerToUse (formatManagerToUse_),
  16428. cache (cacheToUse),
  16429. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16430. {
  16431. clear();
  16432. }
  16433. AudioThumbnail::~AudioThumbnail()
  16434. {
  16435. cache.removeThumbnail (this);
  16436. const ScopedLock sl (readerLock);
  16437. reader = 0;
  16438. }
  16439. void AudioThumbnail::setSource (InputSource* const newSource)
  16440. {
  16441. cache.removeThumbnail (this);
  16442. timerCallback(); // stops the timer and deletes the reader
  16443. source = newSource;
  16444. clear();
  16445. if (newSource != 0
  16446. && ! (cache.loadThumb (*this, newSource->hashCode())
  16447. && isFullyLoaded()))
  16448. {
  16449. {
  16450. const ScopedLock sl (readerLock);
  16451. reader = createReader();
  16452. }
  16453. if (reader != 0)
  16454. {
  16455. initialiseFromAudioFile (*reader);
  16456. cache.addThumbnail (this);
  16457. }
  16458. }
  16459. sendChangeMessage (this);
  16460. }
  16461. bool AudioThumbnail::useTimeSlice()
  16462. {
  16463. const ScopedLock sl (readerLock);
  16464. if (isFullyLoaded())
  16465. {
  16466. if (reader != 0)
  16467. startTimer (timeBeforeDeletingReader);
  16468. cache.removeThumbnail (this);
  16469. return false;
  16470. }
  16471. if (reader == 0)
  16472. reader = createReader();
  16473. if (reader != 0)
  16474. {
  16475. readNextBlockFromAudioFile (*reader);
  16476. stopTimer();
  16477. sendChangeMessage (this);
  16478. const bool justFinished = isFullyLoaded();
  16479. if (justFinished)
  16480. cache.storeThumb (*this, source->hashCode());
  16481. return ! justFinished;
  16482. }
  16483. return false;
  16484. }
  16485. AudioFormatReader* AudioThumbnail::createReader() const
  16486. {
  16487. if (source != 0)
  16488. {
  16489. InputStream* const audioFileStream = source->createInputStream();
  16490. if (audioFileStream != 0)
  16491. return formatManagerToUse.createReaderFor (audioFileStream);
  16492. }
  16493. return 0;
  16494. }
  16495. void AudioThumbnail::timerCallback()
  16496. {
  16497. stopTimer();
  16498. const ScopedLock sl (readerLock);
  16499. reader = 0;
  16500. }
  16501. void AudioThumbnail::clear()
  16502. {
  16503. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16504. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16505. d->thumbnailMagic[0] = 'j';
  16506. d->thumbnailMagic[1] = 'a';
  16507. d->thumbnailMagic[2] = 't';
  16508. d->thumbnailMagic[3] = 'm';
  16509. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16510. d->totalSamples = 0;
  16511. d->numFinishedSamples = 0;
  16512. d->numThumbnailSamples = 0;
  16513. d->numChannels = 0;
  16514. d->sampleRate = 0;
  16515. numSamplesCached = 0;
  16516. cacheNeedsRefilling = true;
  16517. }
  16518. void AudioThumbnail::loadFrom (InputStream& input)
  16519. {
  16520. const ScopedLock sl (readerLock);
  16521. data.setSize (0);
  16522. input.readIntoMemoryBlock (data);
  16523. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16524. d->swapEndiannessIfNeeded();
  16525. if (! (d->thumbnailMagic[0] == 'j'
  16526. && d->thumbnailMagic[1] == 'a'
  16527. && d->thumbnailMagic[2] == 't'
  16528. && d->thumbnailMagic[3] == 'm'))
  16529. {
  16530. clear();
  16531. }
  16532. numSamplesCached = 0;
  16533. cacheNeedsRefilling = true;
  16534. }
  16535. void AudioThumbnail::saveTo (OutputStream& output) const
  16536. {
  16537. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16538. d->swapEndiannessIfNeeded();
  16539. output.write (data.getData(), (int) data.getSize());
  16540. d->swapEndiannessIfNeeded();
  16541. }
  16542. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16543. {
  16544. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16545. d->totalSamples = fileReader.lengthInSamples;
  16546. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16547. d->numFinishedSamples = 0;
  16548. d->sampleRate = roundToInt (fileReader.sampleRate);
  16549. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16550. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16551. d = (AudioThumbnailDataFormat*) data.getData();
  16552. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16553. return d->totalSamples > 0;
  16554. }
  16555. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16556. {
  16557. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16558. if (d->numFinishedSamples < d->totalSamples)
  16559. {
  16560. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16561. generateSection (fileReader,
  16562. d->numFinishedSamples,
  16563. numToDo);
  16564. d->numFinishedSamples += numToDo;
  16565. }
  16566. cacheNeedsRefilling = true;
  16567. return (d->numFinishedSamples < d->totalSamples);
  16568. }
  16569. int AudioThumbnail::getNumChannels() const throw()
  16570. {
  16571. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16572. jassert (d != 0);
  16573. return d->numChannels;
  16574. }
  16575. double AudioThumbnail::getTotalLength() const throw()
  16576. {
  16577. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16578. jassert (d != 0);
  16579. if (d->sampleRate > 0)
  16580. return d->totalSamples / (double)d->sampleRate;
  16581. else
  16582. return 0.0;
  16583. }
  16584. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16585. int64 startSample,
  16586. int numSamples)
  16587. {
  16588. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16589. jassert (d != 0);
  16590. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16591. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16592. char* l = getChannelData (0);
  16593. char* r = getChannelData (1);
  16594. for (int i = firstDataPos; i < lastDataPos; ++i)
  16595. {
  16596. const int sourceStart = i * d->samplesPerThumbSample;
  16597. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16598. float lowestLeft, highestLeft, lowestRight, highestRight;
  16599. fileReader.readMaxLevels (sourceStart,
  16600. sourceEnd - sourceStart,
  16601. lowestLeft,
  16602. highestLeft,
  16603. lowestRight,
  16604. highestRight);
  16605. int n = i * 2;
  16606. if (r != 0)
  16607. {
  16608. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16609. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16610. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16611. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16612. }
  16613. else
  16614. {
  16615. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16616. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16617. }
  16618. }
  16619. }
  16620. char* AudioThumbnail::getChannelData (int channel) const
  16621. {
  16622. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16623. jassert (d != 0);
  16624. if (channel >= 0 && channel < d->numChannels)
  16625. return d->data + (channel * 2 * d->numThumbnailSamples);
  16626. return 0;
  16627. }
  16628. bool AudioThumbnail::isFullyLoaded() const throw()
  16629. {
  16630. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16631. jassert (d != 0);
  16632. return d->numFinishedSamples >= d->totalSamples;
  16633. }
  16634. void AudioThumbnail::refillCache (const int numSamples,
  16635. double startTime,
  16636. const double timePerPixel)
  16637. {
  16638. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16639. jassert (d != 0);
  16640. if (numSamples <= 0
  16641. || timePerPixel <= 0.0
  16642. || d->sampleRate <= 0)
  16643. {
  16644. numSamplesCached = 0;
  16645. cacheNeedsRefilling = true;
  16646. return;
  16647. }
  16648. if (numSamples == numSamplesCached
  16649. && numChannelsCached == d->numChannels
  16650. && startTime == cachedStart
  16651. && timePerPixel == cachedTimePerPixel
  16652. && ! cacheNeedsRefilling)
  16653. {
  16654. return;
  16655. }
  16656. numSamplesCached = numSamples;
  16657. numChannelsCached = d->numChannels;
  16658. cachedStart = startTime;
  16659. cachedTimePerPixel = timePerPixel;
  16660. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16661. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16662. const ScopedLock sl (readerLock);
  16663. cacheNeedsRefilling = false;
  16664. if (needExtraDetail && reader == 0)
  16665. reader = createReader();
  16666. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16667. {
  16668. startTimer (timeBeforeDeletingReader);
  16669. char* cacheData = (char*) cachedLevels.getData();
  16670. int sample = roundToInt (startTime * d->sampleRate);
  16671. for (int i = numSamples; --i >= 0;)
  16672. {
  16673. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16674. if (sample >= 0)
  16675. {
  16676. if (sample >= reader->lengthInSamples)
  16677. break;
  16678. float lmin, lmax, rmin, rmax;
  16679. reader->readMaxLevels (sample,
  16680. jmax (1, nextSample - sample),
  16681. lmin, lmax, rmin, rmax);
  16682. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16683. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16684. if (numChannelsCached > 1)
  16685. {
  16686. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16687. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16688. }
  16689. cacheData += 2 * numChannelsCached;
  16690. }
  16691. startTime += timePerPixel;
  16692. sample = nextSample;
  16693. }
  16694. }
  16695. else
  16696. {
  16697. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  16698. {
  16699. char* const channelData = getChannelData (channelNum);
  16700. char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2;
  16701. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  16702. startTime = cachedStart;
  16703. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  16704. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  16705. for (int i = numSamples; --i >= 0;)
  16706. {
  16707. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  16708. if (sample >= 0 && channelData != 0)
  16709. {
  16710. char mx = -128;
  16711. char mn = 127;
  16712. while (sample <= nextSample)
  16713. {
  16714. if (sample >= numFinished)
  16715. break;
  16716. const int n = sample << 1;
  16717. const char sampMin = channelData [n];
  16718. const char sampMax = channelData [n + 1];
  16719. if (sampMin < mn)
  16720. mn = sampMin;
  16721. if (sampMax > mx)
  16722. mx = sampMax;
  16723. ++sample;
  16724. }
  16725. if (mn <= mx)
  16726. {
  16727. cacheData[0] = mn;
  16728. cacheData[1] = mx;
  16729. }
  16730. else
  16731. {
  16732. cacheData[0] = 1;
  16733. cacheData[1] = 0;
  16734. }
  16735. }
  16736. else
  16737. {
  16738. cacheData[0] = 1;
  16739. cacheData[1] = 0;
  16740. }
  16741. cacheData += numChannelsCached * 2;
  16742. startTime += timePerPixel;
  16743. sample = nextSample;
  16744. }
  16745. }
  16746. }
  16747. }
  16748. void AudioThumbnail::drawChannel (Graphics& g,
  16749. int x, int y, int w, int h,
  16750. double startTime,
  16751. double endTime,
  16752. int channelNum,
  16753. const float verticalZoomFactor)
  16754. {
  16755. refillCache (w, startTime, (endTime - startTime) / w);
  16756. if (numSamplesCached >= w
  16757. && channelNum >= 0
  16758. && channelNum < numChannelsCached)
  16759. {
  16760. const float topY = (float) y;
  16761. const float bottomY = topY + h;
  16762. const float midY = topY + h * 0.5f;
  16763. const float vscale = verticalZoomFactor * h / 256.0f;
  16764. const Rectangle<int> clip (g.getClipBounds());
  16765. const int skipLeft = jlimit (0, w, clip.getX() - x);
  16766. w -= skipLeft;
  16767. x += skipLeft;
  16768. const char* cacheData = ((const char*) cachedLevels.getData())
  16769. + (channelNum << 1)
  16770. + skipLeft * (numChannelsCached << 1);
  16771. while (--w >= 0)
  16772. {
  16773. const char mn = cacheData[0];
  16774. const char mx = cacheData[1];
  16775. cacheData += numChannelsCached << 1;
  16776. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  16777. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  16778. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  16779. ++x;
  16780. if (x >= clip.getRight())
  16781. break;
  16782. }
  16783. }
  16784. }
  16785. END_JUCE_NAMESPACE
  16786. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  16787. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  16788. BEGIN_JUCE_NAMESPACE
  16789. struct ThumbnailCacheEntry
  16790. {
  16791. int64 hash;
  16792. uint32 lastUsed;
  16793. MemoryBlock data;
  16794. juce_UseDebuggingNewOperator
  16795. };
  16796. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  16797. : TimeSliceThread (T("thumb cache")),
  16798. maxNumThumbsToStore (maxNumThumbsToStore_)
  16799. {
  16800. startThread (2);
  16801. }
  16802. AudioThumbnailCache::~AudioThumbnailCache()
  16803. {
  16804. }
  16805. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  16806. {
  16807. for (int i = thumbs.size(); --i >= 0;)
  16808. {
  16809. if (thumbs[i]->hash == hashCode)
  16810. {
  16811. MemoryInputStream in ((const char*) thumbs[i]->data.getData(),
  16812. thumbs[i]->data.getSize(),
  16813. false);
  16814. thumb.loadFrom (in);
  16815. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  16816. return true;
  16817. }
  16818. }
  16819. return false;
  16820. }
  16821. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  16822. const int64 hashCode)
  16823. {
  16824. MemoryOutputStream out;
  16825. thumb.saveTo (out);
  16826. ThumbnailCacheEntry* te = 0;
  16827. for (int i = thumbs.size(); --i >= 0;)
  16828. {
  16829. if (thumbs[i]->hash == hashCode)
  16830. {
  16831. te = thumbs[i];
  16832. break;
  16833. }
  16834. }
  16835. if (te == 0)
  16836. {
  16837. te = new ThumbnailCacheEntry();
  16838. te->hash = hashCode;
  16839. if (thumbs.size() < maxNumThumbsToStore)
  16840. {
  16841. thumbs.add (te);
  16842. }
  16843. else
  16844. {
  16845. int oldest = 0;
  16846. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  16847. int i;
  16848. for (i = thumbs.size(); --i >= 0;)
  16849. if (thumbs[i]->lastUsed < oldestTime)
  16850. oldest = i;
  16851. thumbs.set (i, te);
  16852. }
  16853. }
  16854. te->lastUsed = Time::getMillisecondCounter();
  16855. te->data.setSize (0);
  16856. te->data.append (out.getData(), out.getDataSize());
  16857. }
  16858. void AudioThumbnailCache::clear()
  16859. {
  16860. thumbs.clear();
  16861. }
  16862. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  16863. {
  16864. addTimeSliceClient (thumb);
  16865. }
  16866. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  16867. {
  16868. removeTimeSliceClient (thumb);
  16869. }
  16870. END_JUCE_NAMESPACE
  16871. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  16872. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  16873. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  16874. #if ! JUCE_WINDOWS
  16875. #include <QuickTime/Movies.h>
  16876. #include <QuickTime/QTML.h>
  16877. #include <QuickTime/QuickTimeComponents.h>
  16878. #include <QuickTime/MediaHandlers.h>
  16879. #include <QuickTime/ImageCodec.h>
  16880. #else
  16881. #if JUCE_MSVC
  16882. #pragma warning (push)
  16883. #pragma warning (disable : 4100)
  16884. #endif
  16885. #include <Movies.h>
  16886. #include <QTML.h>
  16887. #include <QuickTimeComponents.h>
  16888. #include <MediaHandlers.h>
  16889. #include <ImageCodec.h>
  16890. #if JUCE_MSVC
  16891. #pragma warning (pop)
  16892. #endif
  16893. #endif
  16894. BEGIN_JUCE_NAMESPACE
  16895. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  16896. static const char* const quickTimeFormatName = "QuickTime file";
  16897. static const tchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  16898. class QTAudioReader : public AudioFormatReader
  16899. {
  16900. public:
  16901. QTAudioReader (InputStream* const input_, const int trackNum_)
  16902. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  16903. ok (false),
  16904. movie (0),
  16905. trackNum (trackNum_),
  16906. lastSampleRead (0),
  16907. lastThreadId (0),
  16908. extractor (0),
  16909. dataHandle (0)
  16910. {
  16911. bufferList.calloc (256, 1);
  16912. #ifdef WIN32
  16913. if (InitializeQTML (0) != noErr)
  16914. return;
  16915. #endif
  16916. if (EnterMovies() != noErr)
  16917. return;
  16918. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  16919. if (! opened)
  16920. return;
  16921. {
  16922. const int numTracks = GetMovieTrackCount (movie);
  16923. int trackCount = 0;
  16924. for (int i = 1; i <= numTracks; ++i)
  16925. {
  16926. track = GetMovieIndTrack (movie, i);
  16927. media = GetTrackMedia (track);
  16928. OSType mediaType;
  16929. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  16930. if (mediaType == SoundMediaType
  16931. && trackCount++ == trackNum_)
  16932. {
  16933. ok = true;
  16934. break;
  16935. }
  16936. }
  16937. }
  16938. if (! ok)
  16939. return;
  16940. ok = false;
  16941. lengthInSamples = GetMediaDecodeDuration (media);
  16942. usesFloatingPointData = false;
  16943. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  16944. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  16945. / GetMediaTimeScale (media);
  16946. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  16947. unsigned long output_layout_size;
  16948. err = MovieAudioExtractionGetPropertyInfo (extractor,
  16949. kQTPropertyClass_MovieAudioExtraction_Audio,
  16950. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16951. 0, &output_layout_size, 0);
  16952. if (err != noErr)
  16953. return;
  16954. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  16955. qt_audio_channel_layout.calloc (output_layout_size, 1);
  16956. err = MovieAudioExtractionGetProperty (extractor,
  16957. kQTPropertyClass_MovieAudioExtraction_Audio,
  16958. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16959. output_layout_size, qt_audio_channel_layout, 0);
  16960. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  16961. err = MovieAudioExtractionSetProperty (extractor,
  16962. kQTPropertyClass_MovieAudioExtraction_Audio,
  16963. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16964. output_layout_size,
  16965. qt_audio_channel_layout);
  16966. err = MovieAudioExtractionGetProperty (extractor,
  16967. kQTPropertyClass_MovieAudioExtraction_Audio,
  16968. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  16969. sizeof (inputStreamDesc),
  16970. &inputStreamDesc, 0);
  16971. if (err != noErr)
  16972. return;
  16973. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  16974. | kAudioFormatFlagIsPacked
  16975. | kAudioFormatFlagsNativeEndian;
  16976. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  16977. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  16978. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  16979. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  16980. err = MovieAudioExtractionSetProperty (extractor,
  16981. kQTPropertyClass_MovieAudioExtraction_Audio,
  16982. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  16983. sizeof (inputStreamDesc),
  16984. &inputStreamDesc);
  16985. if (err != noErr)
  16986. return;
  16987. Boolean allChannelsDiscrete = false;
  16988. err = MovieAudioExtractionSetProperty (extractor,
  16989. kQTPropertyClass_MovieAudioExtraction_Movie,
  16990. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  16991. sizeof (allChannelsDiscrete),
  16992. &allChannelsDiscrete);
  16993. if (err != noErr)
  16994. return;
  16995. bufferList->mNumberBuffers = 1;
  16996. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  16997. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  16998. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  16999. sampleRate = inputStreamDesc.mSampleRate;
  17000. bitsPerSample = 16;
  17001. numChannels = inputStreamDesc.mChannelsPerFrame;
  17002. detachThread();
  17003. ok = true;
  17004. }
  17005. ~QTAudioReader()
  17006. {
  17007. if (dataHandle != 0)
  17008. DisposeHandle (dataHandle);
  17009. if (extractor != 0)
  17010. {
  17011. MovieAudioExtractionEnd (extractor);
  17012. extractor = 0;
  17013. }
  17014. checkThreadIsAttached();
  17015. DisposeMovie (movie);
  17016. juce_free (bufferList->mBuffers[0].mData);
  17017. #if JUCE_MAC
  17018. ExitMoviesOnThread ();
  17019. #endif
  17020. }
  17021. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17022. int64 startSampleInFile, int numSamples)
  17023. {
  17024. checkThreadIsAttached();
  17025. while (numSamples > 0)
  17026. {
  17027. if (! loadFrame ((int) startSampleInFile))
  17028. return false;
  17029. const int numToDo = jmin (numSamples, samplesPerFrame);
  17030. for (int j = numDestChannels; --j >= 0;)
  17031. {
  17032. if (destSamples[j] != 0)
  17033. {
  17034. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17035. for (int i = 0; i < numToDo; ++i)
  17036. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17037. }
  17038. }
  17039. startOffsetInDestBuffer += numToDo;
  17040. startSampleInFile += numToDo;
  17041. numSamples -= numToDo;
  17042. }
  17043. detachThread();
  17044. return true;
  17045. }
  17046. bool loadFrame (const int sampleNum)
  17047. {
  17048. if (lastSampleRead != sampleNum)
  17049. {
  17050. TimeRecord time;
  17051. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17052. time.base = 0;
  17053. time.value.hi = 0;
  17054. time.value.lo = (UInt32) sampleNum;
  17055. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17056. kQTPropertyClass_MovieAudioExtraction_Movie,
  17057. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17058. sizeof (time), &time);
  17059. if (err != noErr)
  17060. return false;
  17061. }
  17062. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17063. UInt32 outFlags = 0;
  17064. UInt32 actualNumSamples = samplesPerFrame;
  17065. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17066. bufferList, &outFlags);
  17067. lastSampleRead = sampleNum + samplesPerFrame;
  17068. return err == noErr;
  17069. }
  17070. juce_UseDebuggingNewOperator
  17071. bool ok;
  17072. private:
  17073. Movie movie;
  17074. Media media;
  17075. Track track;
  17076. const int trackNum;
  17077. double trackUnitsPerFrame;
  17078. int samplesPerFrame;
  17079. int lastSampleRead;
  17080. Thread::ThreadID lastThreadId;
  17081. MovieAudioExtractionRef extractor;
  17082. AudioStreamBasicDescription inputStreamDesc;
  17083. HeapBlock <AudioBufferList> bufferList;
  17084. Handle dataHandle;
  17085. void checkThreadIsAttached()
  17086. {
  17087. #if JUCE_MAC
  17088. if (Thread::getCurrentThreadId() != lastThreadId)
  17089. EnterMoviesOnThread (0);
  17090. AttachMovieToCurrentThread (movie);
  17091. #endif
  17092. }
  17093. void detachThread()
  17094. {
  17095. #if JUCE_MAC
  17096. DetachMovieFromCurrentThread (movie);
  17097. #endif
  17098. }
  17099. QTAudioReader (const QTAudioReader&);
  17100. QTAudioReader& operator= (const QTAudioReader&);
  17101. };
  17102. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17103. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17104. {
  17105. }
  17106. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17107. {
  17108. }
  17109. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17110. {
  17111. return Array<int>();
  17112. }
  17113. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17114. {
  17115. return Array<int>();
  17116. }
  17117. bool QuickTimeAudioFormat::canDoStereo()
  17118. {
  17119. return true;
  17120. }
  17121. bool QuickTimeAudioFormat::canDoMono()
  17122. {
  17123. return true;
  17124. }
  17125. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17126. const bool deleteStreamIfOpeningFails)
  17127. {
  17128. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17129. if (r->ok)
  17130. return r.release();
  17131. if (! deleteStreamIfOpeningFails)
  17132. r->input = 0;
  17133. return 0;
  17134. }
  17135. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17136. double /*sampleRateToUse*/,
  17137. unsigned int /*numberOfChannels*/,
  17138. int /*bitsPerSample*/,
  17139. const StringPairArray& /*metadataValues*/,
  17140. int /*qualityOptionIndex*/)
  17141. {
  17142. jassertfalse // not yet implemented!
  17143. return 0;
  17144. }
  17145. END_JUCE_NAMESPACE
  17146. #endif
  17147. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17148. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17149. BEGIN_JUCE_NAMESPACE
  17150. static const char* const wavFormatName = "WAV file";
  17151. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17152. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17153. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17154. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17155. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17156. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17157. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17158. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17159. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17160. const String& originator,
  17161. const String& originatorRef,
  17162. const Time& date,
  17163. const int64 timeReferenceSamples,
  17164. const String& codingHistory)
  17165. {
  17166. StringPairArray m;
  17167. m.set (bwavDescription, description);
  17168. m.set (bwavOriginator, originator);
  17169. m.set (bwavOriginatorRef, originatorRef);
  17170. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17171. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17172. m.set (bwavTimeReference, String (timeReferenceSamples));
  17173. m.set (bwavCodingHistory, codingHistory);
  17174. return m;
  17175. }
  17176. #if JUCE_MSVC
  17177. #pragma pack (push, 1)
  17178. #define PACKED
  17179. #elif JUCE_GCC
  17180. #define PACKED __attribute__((packed))
  17181. #else
  17182. #define PACKED
  17183. #endif
  17184. struct BWAVChunk
  17185. {
  17186. char description [256];
  17187. char originator [32];
  17188. char originatorRef [32];
  17189. char originationDate [10];
  17190. char originationTime [8];
  17191. uint32 timeRefLow;
  17192. uint32 timeRefHigh;
  17193. uint16 version;
  17194. uint8 umid[64];
  17195. uint8 reserved[190];
  17196. char codingHistory[1];
  17197. void copyTo (StringPairArray& values) const
  17198. {
  17199. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17200. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17201. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17202. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17203. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17204. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17205. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17206. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17207. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17208. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17209. }
  17210. static MemoryBlock createFrom (const StringPairArray& values)
  17211. {
  17212. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8();
  17213. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17214. data.fillWith (0);
  17215. BWAVChunk* b = (BWAVChunk*) data.getData();
  17216. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17217. // as they get called in the right order..
  17218. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17219. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17220. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17221. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17222. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17223. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17224. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17225. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17226. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff);
  17227. if (b->description[0] != 0
  17228. || b->originator[0] != 0
  17229. || b->originationDate[0] != 0
  17230. || b->originationTime[0] != 0
  17231. || b->codingHistory[0] != 0
  17232. || time != 0)
  17233. {
  17234. return data;
  17235. }
  17236. return MemoryBlock();
  17237. }
  17238. } PACKED;
  17239. struct SMPLChunk
  17240. {
  17241. struct SampleLoop
  17242. {
  17243. uint32 identifier;
  17244. uint32 type;
  17245. uint32 start;
  17246. uint32 end;
  17247. uint32 fraction;
  17248. uint32 playCount;
  17249. } PACKED;
  17250. uint32 manufacturer;
  17251. uint32 product;
  17252. uint32 samplePeriod;
  17253. uint32 midiUnityNote;
  17254. uint32 midiPitchFraction;
  17255. uint32 smpteFormat;
  17256. uint32 smpteOffset;
  17257. uint32 numSampleLoops;
  17258. uint32 samplerData;
  17259. SampleLoop loops[1];
  17260. void copyTo (StringPairArray& values, const int totalSize) const
  17261. {
  17262. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17263. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17264. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17265. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17266. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17267. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17268. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17269. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17270. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17271. for (uint32 i = 0; i < numSampleLoops; ++i)
  17272. {
  17273. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17274. break;
  17275. const String prefix ("Loop" + String(i));
  17276. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17277. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17278. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17279. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17280. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17281. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17282. }
  17283. }
  17284. static MemoryBlock createFrom (const StringPairArray& values)
  17285. {
  17286. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17287. if (numLoops <= 0)
  17288. return MemoryBlock();
  17289. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17290. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17291. data.fillWith (0);
  17292. SMPLChunk* s = (SMPLChunk*) data.getData();
  17293. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17294. // as they get called in the right order..
  17295. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17296. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17297. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17298. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17299. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17300. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17301. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17302. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17303. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17304. for (int i = 0; i < numLoops; ++i)
  17305. {
  17306. const String prefix ("Loop" + String(i));
  17307. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17308. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17309. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17310. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17311. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17312. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17313. }
  17314. return data;
  17315. }
  17316. } PACKED;
  17317. struct ExtensibleWavSubFormat
  17318. {
  17319. uint32 data1;
  17320. uint16 data2;
  17321. uint16 data3;
  17322. uint8 data4[8];
  17323. } PACKED;
  17324. #if JUCE_MSVC
  17325. #pragma pack (pop)
  17326. #endif
  17327. #undef PACKED
  17328. class WavAudioFormatReader : public AudioFormatReader
  17329. {
  17330. int bytesPerFrame;
  17331. int64 dataChunkStart, dataLength;
  17332. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17333. WavAudioFormatReader (const WavAudioFormatReader&);
  17334. WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17335. public:
  17336. int64 bwavChunkStart, bwavSize;
  17337. WavAudioFormatReader (InputStream* const in)
  17338. : AudioFormatReader (in, TRANS (wavFormatName)),
  17339. dataLength (0),
  17340. bwavChunkStart (0),
  17341. bwavSize (0)
  17342. {
  17343. if (input->readInt() == chunkName ("RIFF"))
  17344. {
  17345. const uint32 len = (uint32) input->readInt();
  17346. const int64 end = input->getPosition() + len;
  17347. bool hasGotType = false;
  17348. bool hasGotData = false;
  17349. if (input->readInt() == chunkName ("WAVE"))
  17350. {
  17351. while (input->getPosition() < end
  17352. && ! input->isExhausted())
  17353. {
  17354. const int chunkType = input->readInt();
  17355. uint32 length = (uint32) input->readInt();
  17356. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17357. if (chunkType == chunkName ("fmt "))
  17358. {
  17359. // read the format chunk
  17360. const unsigned short format = input->readShort();
  17361. const short numChans = input->readShort();
  17362. sampleRate = input->readInt();
  17363. const int bytesPerSec = input->readInt();
  17364. numChannels = numChans;
  17365. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17366. bitsPerSample = 8 * bytesPerFrame / numChans;
  17367. if (format == 3)
  17368. {
  17369. usesFloatingPointData = true;
  17370. }
  17371. else if (format == 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/)
  17372. {
  17373. if (length < 40) // too short
  17374. {
  17375. bytesPerFrame = 0;
  17376. }
  17377. else
  17378. {
  17379. input->skipNextBytes (12); // skip over blockAlign, bitsPerSample and speakerPosition mask
  17380. ExtensibleWavSubFormat subFormat;
  17381. subFormat.data1 = input->readInt();
  17382. subFormat.data2 = input->readShort();
  17383. subFormat.data3 = input->readShort();
  17384. input->read (subFormat.data4, sizeof (subFormat.data4));
  17385. const ExtensibleWavSubFormat pcmFormat
  17386. = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
  17387. if (memcmp (&subFormat, &pcmFormat, sizeof (subFormat)) != 0)
  17388. {
  17389. const ExtensibleWavSubFormat ambisonicFormat
  17390. = { 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 } };
  17391. if (memcmp (&subFormat, &ambisonicFormat, sizeof (subFormat)) != 0)
  17392. bytesPerFrame = 0;
  17393. }
  17394. }
  17395. }
  17396. else if (format != 1)
  17397. {
  17398. bytesPerFrame = 0;
  17399. }
  17400. hasGotType = true;
  17401. }
  17402. else if (chunkType == chunkName ("data"))
  17403. {
  17404. // get the data chunk's position
  17405. dataLength = length;
  17406. dataChunkStart = input->getPosition();
  17407. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17408. hasGotData = true;
  17409. }
  17410. else if (chunkType == chunkName ("bext"))
  17411. {
  17412. bwavChunkStart = input->getPosition();
  17413. bwavSize = length;
  17414. // Broadcast-wav extension chunk..
  17415. HeapBlock <BWAVChunk> bwav;
  17416. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17417. input->read (bwav, length);
  17418. bwav->copyTo (metadataValues);
  17419. }
  17420. else if (chunkType == chunkName ("smpl"))
  17421. {
  17422. HeapBlock <SMPLChunk> smpl;
  17423. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17424. input->read (smpl, length);
  17425. smpl->copyTo (metadataValues, length);
  17426. }
  17427. else if (chunkEnd <= input->getPosition())
  17428. {
  17429. break;
  17430. }
  17431. input->setPosition (chunkEnd);
  17432. }
  17433. }
  17434. }
  17435. }
  17436. ~WavAudioFormatReader()
  17437. {
  17438. }
  17439. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17440. int64 startSampleInFile, int numSamples)
  17441. {
  17442. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17443. if (samplesAvailable < numSamples)
  17444. {
  17445. for (int i = numDestChannels; --i >= 0;)
  17446. if (destSamples[i] != 0)
  17447. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17448. numSamples = (int) samplesAvailable;
  17449. }
  17450. if (numSamples <= 0)
  17451. return true;
  17452. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17453. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17454. char tempBuffer [tempBufSize];
  17455. while (numSamples > 0)
  17456. {
  17457. int* left = destSamples[0];
  17458. if (left != 0)
  17459. left += startOffsetInDestBuffer;
  17460. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17461. if (right != 0)
  17462. right += startOffsetInDestBuffer;
  17463. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17464. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17465. if (bytesRead < numThisTime * bytesPerFrame)
  17466. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17467. if (bitsPerSample == 16)
  17468. {
  17469. const short* src = (const short*) tempBuffer;
  17470. if (numChannels > 1)
  17471. {
  17472. if (left == 0)
  17473. {
  17474. for (int i = numThisTime; --i >= 0;)
  17475. {
  17476. ++src;
  17477. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17478. }
  17479. }
  17480. else if (right == 0)
  17481. {
  17482. for (int i = numThisTime; --i >= 0;)
  17483. {
  17484. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17485. ++src;
  17486. }
  17487. }
  17488. else
  17489. {
  17490. for (int i = numThisTime; --i >= 0;)
  17491. {
  17492. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17493. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17494. }
  17495. }
  17496. }
  17497. else
  17498. {
  17499. for (int i = numThisTime; --i >= 0;)
  17500. {
  17501. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17502. }
  17503. }
  17504. }
  17505. else if (bitsPerSample == 24)
  17506. {
  17507. const char* src = (const char*) tempBuffer;
  17508. if (numChannels > 1)
  17509. {
  17510. if (left == 0)
  17511. {
  17512. for (int i = numThisTime; --i >= 0;)
  17513. {
  17514. src += 3;
  17515. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17516. src += 3;
  17517. }
  17518. }
  17519. else if (right == 0)
  17520. {
  17521. for (int i = numThisTime; --i >= 0;)
  17522. {
  17523. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17524. src += 6;
  17525. }
  17526. }
  17527. else
  17528. {
  17529. for (int i = 0; i < numThisTime; ++i)
  17530. {
  17531. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17532. src += 3;
  17533. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17534. src += 3;
  17535. }
  17536. }
  17537. }
  17538. else
  17539. {
  17540. for (int i = 0; i < numThisTime; ++i)
  17541. {
  17542. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17543. src += 3;
  17544. }
  17545. }
  17546. }
  17547. else if (bitsPerSample == 32)
  17548. {
  17549. const unsigned int* src = (const unsigned int*) tempBuffer;
  17550. unsigned int* l = (unsigned int*) left;
  17551. unsigned int* r = (unsigned int*) right;
  17552. if (numChannels > 1)
  17553. {
  17554. if (l == 0)
  17555. {
  17556. for (int i = numThisTime; --i >= 0;)
  17557. {
  17558. ++src;
  17559. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17560. }
  17561. }
  17562. else if (r == 0)
  17563. {
  17564. for (int i = numThisTime; --i >= 0;)
  17565. {
  17566. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17567. ++src;
  17568. }
  17569. }
  17570. else
  17571. {
  17572. for (int i = numThisTime; --i >= 0;)
  17573. {
  17574. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17575. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17576. }
  17577. }
  17578. }
  17579. else
  17580. {
  17581. for (int i = numThisTime; --i >= 0;)
  17582. {
  17583. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17584. }
  17585. }
  17586. left = (int*)l;
  17587. right = (int*)r;
  17588. }
  17589. else if (bitsPerSample == 8)
  17590. {
  17591. const unsigned char* src = (const unsigned char*) tempBuffer;
  17592. if (numChannels > 1)
  17593. {
  17594. if (left == 0)
  17595. {
  17596. for (int i = numThisTime; --i >= 0;)
  17597. {
  17598. ++src;
  17599. *right++ = ((int) *src++ - 128) << 24;
  17600. }
  17601. }
  17602. else if (right == 0)
  17603. {
  17604. for (int i = numThisTime; --i >= 0;)
  17605. {
  17606. *left++ = ((int) *src++ - 128) << 24;
  17607. ++src;
  17608. }
  17609. }
  17610. else
  17611. {
  17612. for (int i = numThisTime; --i >= 0;)
  17613. {
  17614. *left++ = ((int) *src++ - 128) << 24;
  17615. *right++ = ((int) *src++ - 128) << 24;
  17616. }
  17617. }
  17618. }
  17619. else
  17620. {
  17621. for (int i = numThisTime; --i >= 0;)
  17622. {
  17623. *left++ = ((int)*src++ - 128) << 24;
  17624. }
  17625. }
  17626. }
  17627. startOffsetInDestBuffer += numThisTime;
  17628. numSamples -= numThisTime;
  17629. }
  17630. if (numSamples > 0)
  17631. {
  17632. for (int i = numDestChannels; --i >= 0;)
  17633. if (destSamples[i] != 0)
  17634. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17635. sizeof (int) * numSamples);
  17636. }
  17637. return true;
  17638. }
  17639. juce_UseDebuggingNewOperator
  17640. };
  17641. class WavAudioFormatWriter : public AudioFormatWriter
  17642. {
  17643. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17644. uint32 lengthInSamples, bytesWritten;
  17645. int64 headerPosition;
  17646. bool writeFailed;
  17647. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17648. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17649. WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17650. void writeHeader()
  17651. {
  17652. const bool seekedOk = output->setPosition (headerPosition);
  17653. (void) seekedOk;
  17654. // if this fails, you've given it an output stream that can't seek! It needs
  17655. // to be able to seek back to write the header
  17656. jassert (seekedOk);
  17657. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17658. output->writeInt (chunkName ("RIFF"));
  17659. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17660. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17661. output->writeInt (chunkName ("WAVE"));
  17662. output->writeInt (chunkName ("fmt "));
  17663. output->writeInt (16);
  17664. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17665. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17666. output->writeShort ((short) numChannels);
  17667. output->writeInt ((int) sampleRate);
  17668. output->writeInt (bytesPerFrame * (int) sampleRate);
  17669. output->writeShort ((short) bytesPerFrame);
  17670. output->writeShort ((short) bitsPerSample);
  17671. if (bwavChunk.getSize() > 0)
  17672. {
  17673. output->writeInt (chunkName ("bext"));
  17674. output->writeInt ((int) bwavChunk.getSize());
  17675. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17676. }
  17677. if (smplChunk.getSize() > 0)
  17678. {
  17679. output->writeInt (chunkName ("smpl"));
  17680. output->writeInt ((int) smplChunk.getSize());
  17681. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17682. }
  17683. output->writeInt (chunkName ("data"));
  17684. output->writeInt (lengthInSamples * bytesPerFrame);
  17685. usesFloatingPointData = (bitsPerSample == 32);
  17686. }
  17687. public:
  17688. WavAudioFormatWriter (OutputStream* const out,
  17689. const double sampleRate_,
  17690. const unsigned int numChannels_,
  17691. const int bits,
  17692. const StringPairArray& metadataValues)
  17693. : AudioFormatWriter (out,
  17694. TRANS (wavFormatName),
  17695. sampleRate_,
  17696. numChannels_,
  17697. bits),
  17698. lengthInSamples (0),
  17699. bytesWritten (0),
  17700. writeFailed (false)
  17701. {
  17702. if (metadataValues.size() > 0)
  17703. {
  17704. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17705. smplChunk = SMPLChunk::createFrom (metadataValues);
  17706. }
  17707. headerPosition = out->getPosition();
  17708. writeHeader();
  17709. }
  17710. ~WavAudioFormatWriter()
  17711. {
  17712. writeHeader();
  17713. }
  17714. bool write (const int** data, int numSamples)
  17715. {
  17716. if (writeFailed)
  17717. return false;
  17718. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17719. tempBlock.ensureSize (bytes, false);
  17720. char* buffer = (char*) tempBlock.getData();
  17721. const int* left = data[0];
  17722. const int* right = data[1];
  17723. if (right == 0)
  17724. right = left;
  17725. if (bitsPerSample == 16)
  17726. {
  17727. short* b = (short*) buffer;
  17728. if (numChannels > 1)
  17729. {
  17730. for (int i = numSamples; --i >= 0;)
  17731. {
  17732. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17733. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17734. }
  17735. }
  17736. else
  17737. {
  17738. for (int i = numSamples; --i >= 0;)
  17739. {
  17740. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17741. }
  17742. }
  17743. }
  17744. else if (bitsPerSample == 24)
  17745. {
  17746. char* b = (char*) buffer;
  17747. if (numChannels > 1)
  17748. {
  17749. for (int i = numSamples; --i >= 0;)
  17750. {
  17751. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17752. b += 3;
  17753. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17754. b += 3;
  17755. }
  17756. }
  17757. else
  17758. {
  17759. for (int i = numSamples; --i >= 0;)
  17760. {
  17761. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17762. b += 3;
  17763. }
  17764. }
  17765. }
  17766. else if (bitsPerSample == 32)
  17767. {
  17768. unsigned int* b = (unsigned int*) buffer;
  17769. if (numChannels > 1)
  17770. {
  17771. for (int i = numSamples; --i >= 0;)
  17772. {
  17773. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17774. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  17775. }
  17776. }
  17777. else
  17778. {
  17779. for (int i = numSamples; --i >= 0;)
  17780. {
  17781. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17782. }
  17783. }
  17784. }
  17785. else if (bitsPerSample == 8)
  17786. {
  17787. unsigned char* b = (unsigned char*) buffer;
  17788. if (numChannels > 1)
  17789. {
  17790. for (int i = numSamples; --i >= 0;)
  17791. {
  17792. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17793. *b++ = (unsigned char) (128 + (*right++ >> 24));
  17794. }
  17795. }
  17796. else
  17797. {
  17798. for (int i = numSamples; --i >= 0;)
  17799. {
  17800. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17801. }
  17802. }
  17803. }
  17804. if (bytesWritten + bytes >= (uint32) 0xfff00000
  17805. || ! output->write (buffer, bytes))
  17806. {
  17807. // failed to write to disk, so let's try writing the header.
  17808. // If it's just run out of disk space, then if it does manage
  17809. // to write the header, we'll still have a useable file..
  17810. writeHeader();
  17811. writeFailed = true;
  17812. return false;
  17813. }
  17814. else
  17815. {
  17816. bytesWritten += bytes;
  17817. lengthInSamples += numSamples;
  17818. return true;
  17819. }
  17820. }
  17821. juce_UseDebuggingNewOperator
  17822. };
  17823. WavAudioFormat::WavAudioFormat()
  17824. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  17825. {
  17826. }
  17827. WavAudioFormat::~WavAudioFormat()
  17828. {
  17829. }
  17830. const Array <int> WavAudioFormat::getPossibleSampleRates()
  17831. {
  17832. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  17833. return Array <int> (rates);
  17834. }
  17835. const Array <int> WavAudioFormat::getPossibleBitDepths()
  17836. {
  17837. const int depths[] = { 8, 16, 24, 32, 0 };
  17838. return Array <int> (depths);
  17839. }
  17840. bool WavAudioFormat::canDoStereo()
  17841. {
  17842. return true;
  17843. }
  17844. bool WavAudioFormat::canDoMono()
  17845. {
  17846. return true;
  17847. }
  17848. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  17849. const bool deleteStreamIfOpeningFails)
  17850. {
  17851. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  17852. if (r->sampleRate != 0)
  17853. return r.release();
  17854. if (! deleteStreamIfOpeningFails)
  17855. r->input = 0;
  17856. return 0;
  17857. }
  17858. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  17859. double sampleRate,
  17860. unsigned int numChannels,
  17861. int bitsPerSample,
  17862. const StringPairArray& metadataValues,
  17863. int /*qualityOptionIndex*/)
  17864. {
  17865. if (getPossibleBitDepths().contains (bitsPerSample))
  17866. {
  17867. return new WavAudioFormatWriter (out,
  17868. sampleRate,
  17869. numChannels,
  17870. bitsPerSample,
  17871. metadataValues);
  17872. }
  17873. return 0;
  17874. }
  17875. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  17876. {
  17877. TemporaryFile tempFile (file);
  17878. WavAudioFormat wav;
  17879. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  17880. if (reader != 0)
  17881. {
  17882. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  17883. if (outStream != 0)
  17884. {
  17885. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  17886. reader->numChannels, reader->bitsPerSample,
  17887. metadata, 0));
  17888. if (writer != 0)
  17889. {
  17890. outStream.release();
  17891. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  17892. writer = 0;
  17893. reader = 0;
  17894. return ok && tempFile.overwriteTargetFileWithTemporary();
  17895. }
  17896. }
  17897. }
  17898. return false;
  17899. }
  17900. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  17901. {
  17902. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  17903. if (reader != 0)
  17904. {
  17905. const int64 bwavPos = reader->bwavChunkStart;
  17906. const int64 bwavSize = reader->bwavSize;
  17907. reader = 0;
  17908. if (bwavSize > 0)
  17909. {
  17910. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  17911. if (chunk.getSize() <= (size_t) bwavSize)
  17912. {
  17913. // the new one will fit in the space available, so write it directly..
  17914. const int64 oldSize = wavFile.getSize();
  17915. {
  17916. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  17917. out->setPosition (bwavPos);
  17918. out->write (chunk.getData(), (int) chunk.getSize());
  17919. out->setPosition (oldSize);
  17920. }
  17921. jassert (wavFile.getSize() == oldSize);
  17922. return true;
  17923. }
  17924. }
  17925. }
  17926. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  17927. }
  17928. END_JUCE_NAMESPACE
  17929. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  17930. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  17931. BEGIN_JUCE_NAMESPACE
  17932. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  17933. const bool deleteReaderWhenThisIsDeleted)
  17934. : reader (reader_),
  17935. deleteReader (deleteReaderWhenThisIsDeleted),
  17936. nextPlayPos (0),
  17937. looping (false)
  17938. {
  17939. jassert (reader != 0);
  17940. }
  17941. AudioFormatReaderSource::~AudioFormatReaderSource()
  17942. {
  17943. releaseResources();
  17944. if (deleteReader)
  17945. delete reader;
  17946. }
  17947. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  17948. {
  17949. nextPlayPos = newPosition;
  17950. }
  17951. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  17952. {
  17953. looping = shouldLoop;
  17954. }
  17955. int AudioFormatReaderSource::getNextReadPosition() const
  17956. {
  17957. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  17958. : nextPlayPos;
  17959. }
  17960. int AudioFormatReaderSource::getTotalLength() const
  17961. {
  17962. return (int) reader->lengthInSamples;
  17963. }
  17964. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  17965. double /*sampleRate*/)
  17966. {
  17967. }
  17968. void AudioFormatReaderSource::releaseResources()
  17969. {
  17970. }
  17971. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  17972. {
  17973. if (info.numSamples > 0)
  17974. {
  17975. const int start = nextPlayPos;
  17976. if (looping)
  17977. {
  17978. const int newStart = start % (int) reader->lengthInSamples;
  17979. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  17980. if (newEnd > newStart)
  17981. {
  17982. info.buffer->readFromAudioReader (reader,
  17983. info.startSample,
  17984. newEnd - newStart,
  17985. newStart,
  17986. true, true);
  17987. }
  17988. else
  17989. {
  17990. const int endSamps = (int) reader->lengthInSamples - newStart;
  17991. info.buffer->readFromAudioReader (reader,
  17992. info.startSample,
  17993. endSamps,
  17994. newStart,
  17995. true, true);
  17996. info.buffer->readFromAudioReader (reader,
  17997. info.startSample + endSamps,
  17998. newEnd,
  17999. 0,
  18000. true, true);
  18001. }
  18002. nextPlayPos = newEnd;
  18003. }
  18004. else
  18005. {
  18006. info.buffer->readFromAudioReader (reader,
  18007. info.startSample,
  18008. info.numSamples,
  18009. start,
  18010. true, true);
  18011. nextPlayPos += info.numSamples;
  18012. }
  18013. }
  18014. }
  18015. END_JUCE_NAMESPACE
  18016. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18017. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  18018. BEGIN_JUCE_NAMESPACE
  18019. AudioSourcePlayer::AudioSourcePlayer()
  18020. : source (0),
  18021. sampleRate (0),
  18022. bufferSize (0),
  18023. tempBuffer (2, 8),
  18024. lastGain (1.0f),
  18025. gain (1.0f)
  18026. {
  18027. }
  18028. AudioSourcePlayer::~AudioSourcePlayer()
  18029. {
  18030. setSource (0);
  18031. }
  18032. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18033. {
  18034. if (source != newSource)
  18035. {
  18036. AudioSource* const oldSource = source;
  18037. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18038. newSource->prepareToPlay (bufferSize, sampleRate);
  18039. {
  18040. const ScopedLock sl (readLock);
  18041. source = newSource;
  18042. }
  18043. if (oldSource != 0)
  18044. oldSource->releaseResources();
  18045. }
  18046. }
  18047. void AudioSourcePlayer::setGain (const float newGain) throw()
  18048. {
  18049. gain = newGain;
  18050. }
  18051. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18052. int totalNumInputChannels,
  18053. float** outputChannelData,
  18054. int totalNumOutputChannels,
  18055. int numSamples)
  18056. {
  18057. // these should have been prepared by audioDeviceAboutToStart()...
  18058. jassert (sampleRate > 0 && bufferSize > 0);
  18059. const ScopedLock sl (readLock);
  18060. if (source != 0)
  18061. {
  18062. AudioSourceChannelInfo info;
  18063. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18064. // messy stuff needed to compact the channels down into an array
  18065. // of non-zero pointers..
  18066. for (i = 0; i < totalNumInputChannels; ++i)
  18067. {
  18068. if (inputChannelData[i] != 0)
  18069. {
  18070. inputChans [numInputs++] = inputChannelData[i];
  18071. if (numInputs >= numElementsInArray (inputChans))
  18072. break;
  18073. }
  18074. }
  18075. for (i = 0; i < totalNumOutputChannels; ++i)
  18076. {
  18077. if (outputChannelData[i] != 0)
  18078. {
  18079. outputChans [numOutputs++] = outputChannelData[i];
  18080. if (numOutputs >= numElementsInArray (outputChans))
  18081. break;
  18082. }
  18083. }
  18084. if (numInputs > numOutputs)
  18085. {
  18086. // if there aren't enough output channels for the number of
  18087. // inputs, we need to create some temporary extra ones (can't
  18088. // use the input data in case it gets written to)
  18089. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18090. false, false, true);
  18091. for (i = 0; i < numOutputs; ++i)
  18092. {
  18093. channels[numActiveChans] = outputChans[i];
  18094. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18095. ++numActiveChans;
  18096. }
  18097. for (i = numOutputs; i < numInputs; ++i)
  18098. {
  18099. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18100. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18101. ++numActiveChans;
  18102. }
  18103. }
  18104. else
  18105. {
  18106. for (i = 0; i < numInputs; ++i)
  18107. {
  18108. channels[numActiveChans] = outputChans[i];
  18109. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18110. ++numActiveChans;
  18111. }
  18112. for (i = numInputs; i < numOutputs; ++i)
  18113. {
  18114. channels[numActiveChans] = outputChans[i];
  18115. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18116. ++numActiveChans;
  18117. }
  18118. }
  18119. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18120. info.buffer = &buffer;
  18121. info.startSample = 0;
  18122. info.numSamples = numSamples;
  18123. source->getNextAudioBlock (info);
  18124. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18125. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18126. lastGain = gain;
  18127. }
  18128. else
  18129. {
  18130. for (int i = 0; i < totalNumOutputChannels; ++i)
  18131. if (outputChannelData[i] != 0)
  18132. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18133. }
  18134. }
  18135. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18136. {
  18137. sampleRate = device->getCurrentSampleRate();
  18138. bufferSize = device->getCurrentBufferSizeSamples();
  18139. zeromem (channels, sizeof (channels));
  18140. if (source != 0)
  18141. source->prepareToPlay (bufferSize, sampleRate);
  18142. }
  18143. void AudioSourcePlayer::audioDeviceStopped()
  18144. {
  18145. if (source != 0)
  18146. source->releaseResources();
  18147. sampleRate = 0.0;
  18148. bufferSize = 0;
  18149. tempBuffer.setSize (2, 8);
  18150. }
  18151. END_JUCE_NAMESPACE
  18152. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18153. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18154. BEGIN_JUCE_NAMESPACE
  18155. AudioTransportSource::AudioTransportSource()
  18156. : source (0),
  18157. resamplerSource (0),
  18158. bufferingSource (0),
  18159. positionableSource (0),
  18160. masterSource (0),
  18161. gain (1.0f),
  18162. lastGain (1.0f),
  18163. playing (false),
  18164. stopped (true),
  18165. sampleRate (44100.0),
  18166. sourceSampleRate (0.0),
  18167. blockSize (128),
  18168. readAheadBufferSize (0),
  18169. isPrepared (false),
  18170. inputStreamEOF (false)
  18171. {
  18172. }
  18173. AudioTransportSource::~AudioTransportSource()
  18174. {
  18175. setSource (0);
  18176. releaseResources();
  18177. }
  18178. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18179. int readAheadBufferSize_,
  18180. double sourceSampleRateToCorrectFor)
  18181. {
  18182. if (source == newSource)
  18183. {
  18184. if (source == 0)
  18185. return;
  18186. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18187. }
  18188. readAheadBufferSize = readAheadBufferSize_;
  18189. sourceSampleRate = sourceSampleRateToCorrectFor;
  18190. ResamplingAudioSource* newResamplerSource = 0;
  18191. BufferingAudioSource* newBufferingSource = 0;
  18192. PositionableAudioSource* newPositionableSource = 0;
  18193. AudioSource* newMasterSource = 0;
  18194. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18195. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18196. AudioSource* oldMasterSource = masterSource;
  18197. if (newSource != 0)
  18198. {
  18199. newPositionableSource = newSource;
  18200. if (readAheadBufferSize_ > 0)
  18201. newPositionableSource = newBufferingSource
  18202. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18203. newPositionableSource->setNextReadPosition (0);
  18204. if (sourceSampleRateToCorrectFor != 0)
  18205. newMasterSource = newResamplerSource
  18206. = new ResamplingAudioSource (newPositionableSource, false);
  18207. else
  18208. newMasterSource = newPositionableSource;
  18209. if (isPrepared)
  18210. {
  18211. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18212. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18213. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18214. }
  18215. }
  18216. {
  18217. const ScopedLock sl (callbackLock);
  18218. source = newSource;
  18219. resamplerSource = newResamplerSource;
  18220. bufferingSource = newBufferingSource;
  18221. masterSource = newMasterSource;
  18222. positionableSource = newPositionableSource;
  18223. playing = false;
  18224. }
  18225. if (oldMasterSource != 0)
  18226. oldMasterSource->releaseResources();
  18227. }
  18228. void AudioTransportSource::start()
  18229. {
  18230. if ((! playing) && masterSource != 0)
  18231. {
  18232. {
  18233. const ScopedLock sl (callbackLock);
  18234. playing = true;
  18235. stopped = false;
  18236. inputStreamEOF = false;
  18237. }
  18238. sendChangeMessage (this);
  18239. }
  18240. }
  18241. void AudioTransportSource::stop()
  18242. {
  18243. if (playing)
  18244. {
  18245. {
  18246. const ScopedLock sl (callbackLock);
  18247. playing = false;
  18248. }
  18249. int n = 500;
  18250. while (--n >= 0 && ! stopped)
  18251. Thread::sleep (2);
  18252. sendChangeMessage (this);
  18253. }
  18254. }
  18255. void AudioTransportSource::setPosition (double newPosition)
  18256. {
  18257. if (sampleRate > 0.0)
  18258. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18259. }
  18260. double AudioTransportSource::getCurrentPosition() const
  18261. {
  18262. if (sampleRate > 0.0)
  18263. return getNextReadPosition() / sampleRate;
  18264. else
  18265. return 0.0;
  18266. }
  18267. void AudioTransportSource::setNextReadPosition (int newPosition)
  18268. {
  18269. if (positionableSource != 0)
  18270. {
  18271. if (sampleRate > 0 && sourceSampleRate > 0)
  18272. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18273. positionableSource->setNextReadPosition (newPosition);
  18274. }
  18275. }
  18276. int AudioTransportSource::getNextReadPosition() const
  18277. {
  18278. if (positionableSource != 0)
  18279. {
  18280. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18281. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18282. }
  18283. return 0;
  18284. }
  18285. int AudioTransportSource::getTotalLength() const
  18286. {
  18287. const ScopedLock sl (callbackLock);
  18288. if (positionableSource != 0)
  18289. {
  18290. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18291. return roundToInt (positionableSource->getTotalLength() * ratio);
  18292. }
  18293. return 0;
  18294. }
  18295. bool AudioTransportSource::isLooping() const
  18296. {
  18297. const ScopedLock sl (callbackLock);
  18298. return positionableSource != 0
  18299. && positionableSource->isLooping();
  18300. }
  18301. void AudioTransportSource::setGain (const float newGain) throw()
  18302. {
  18303. gain = newGain;
  18304. }
  18305. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18306. double sampleRate_)
  18307. {
  18308. const ScopedLock sl (callbackLock);
  18309. sampleRate = sampleRate_;
  18310. blockSize = samplesPerBlockExpected;
  18311. if (masterSource != 0)
  18312. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18313. if (resamplerSource != 0 && sourceSampleRate != 0)
  18314. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18315. isPrepared = true;
  18316. }
  18317. void AudioTransportSource::releaseResources()
  18318. {
  18319. const ScopedLock sl (callbackLock);
  18320. if (masterSource != 0)
  18321. masterSource->releaseResources();
  18322. isPrepared = false;
  18323. }
  18324. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18325. {
  18326. const ScopedLock sl (callbackLock);
  18327. inputStreamEOF = false;
  18328. if (masterSource != 0 && ! stopped)
  18329. {
  18330. masterSource->getNextAudioBlock (info);
  18331. if (! playing)
  18332. {
  18333. // just stopped playing, so fade out the last block..
  18334. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18335. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18336. if (info.numSamples > 256)
  18337. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18338. }
  18339. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18340. && ! positionableSource->isLooping())
  18341. {
  18342. playing = false;
  18343. inputStreamEOF = true;
  18344. sendChangeMessage (this);
  18345. }
  18346. stopped = ! playing;
  18347. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18348. {
  18349. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18350. lastGain, gain);
  18351. }
  18352. }
  18353. else
  18354. {
  18355. info.clearActiveBufferRegion();
  18356. stopped = true;
  18357. }
  18358. lastGain = gain;
  18359. }
  18360. END_JUCE_NAMESPACE
  18361. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18362. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18363. BEGIN_JUCE_NAMESPACE
  18364. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18365. public Thread,
  18366. private Timer
  18367. {
  18368. public:
  18369. SharedBufferingAudioSourceThread()
  18370. : Thread ("Audio Buffer")
  18371. {
  18372. }
  18373. ~SharedBufferingAudioSourceThread()
  18374. {
  18375. stopThread (10000);
  18376. clearSingletonInstance();
  18377. }
  18378. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18379. void addSource (BufferingAudioSource* source)
  18380. {
  18381. const ScopedLock sl (lock);
  18382. if (! sources.contains ((void*) source))
  18383. {
  18384. sources.add ((void*) source);
  18385. startThread();
  18386. stopTimer();
  18387. }
  18388. notify();
  18389. }
  18390. void removeSource (BufferingAudioSource* source)
  18391. {
  18392. const ScopedLock sl (lock);
  18393. sources.removeValue ((void*) source);
  18394. if (sources.size() == 0)
  18395. startTimer (5000);
  18396. }
  18397. private:
  18398. VoidArray sources;
  18399. CriticalSection lock;
  18400. void run()
  18401. {
  18402. while (! threadShouldExit())
  18403. {
  18404. bool busy = false;
  18405. for (int i = sources.size(); --i >= 0;)
  18406. {
  18407. if (threadShouldExit())
  18408. return;
  18409. const ScopedLock sl (lock);
  18410. BufferingAudioSource* const b = (BufferingAudioSource*) sources[i];
  18411. if (b != 0 && b->readNextBufferChunk())
  18412. busy = true;
  18413. }
  18414. if (! busy)
  18415. wait (500);
  18416. }
  18417. }
  18418. void timerCallback()
  18419. {
  18420. stopTimer();
  18421. if (sources.size() == 0)
  18422. deleteInstance();
  18423. }
  18424. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18425. SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18426. };
  18427. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18428. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18429. const bool deleteSourceWhenDeleted_,
  18430. int numberOfSamplesToBuffer_)
  18431. : source (source_),
  18432. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18433. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18434. buffer (2, 0),
  18435. bufferValidStart (0),
  18436. bufferValidEnd (0),
  18437. nextPlayPos (0),
  18438. wasSourceLooping (false)
  18439. {
  18440. jassert (source_ != 0);
  18441. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18442. // not using a larger buffer..
  18443. }
  18444. BufferingAudioSource::~BufferingAudioSource()
  18445. {
  18446. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18447. if (thread != 0)
  18448. thread->removeSource (this);
  18449. if (deleteSourceWhenDeleted)
  18450. delete source;
  18451. }
  18452. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18453. {
  18454. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18455. sampleRate = sampleRate_;
  18456. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18457. buffer.clear();
  18458. bufferValidStart = 0;
  18459. bufferValidEnd = 0;
  18460. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18461. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18462. buffer.getNumSamples() / 2))
  18463. {
  18464. SharedBufferingAudioSourceThread::getInstance()->notify();
  18465. Thread::sleep (5);
  18466. }
  18467. }
  18468. void BufferingAudioSource::releaseResources()
  18469. {
  18470. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18471. if (thread != 0)
  18472. thread->removeSource (this);
  18473. buffer.setSize (2, 0);
  18474. source->releaseResources();
  18475. }
  18476. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18477. {
  18478. const ScopedLock sl (bufferStartPosLock);
  18479. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18480. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18481. if (validStart == validEnd)
  18482. {
  18483. // total cache miss
  18484. info.clearActiveBufferRegion();
  18485. }
  18486. else
  18487. {
  18488. if (validStart > 0)
  18489. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18490. if (validEnd < info.numSamples)
  18491. info.buffer->clear (info.startSample + validEnd,
  18492. info.numSamples - validEnd); // partial cache miss at end
  18493. if (validStart < validEnd)
  18494. {
  18495. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18496. {
  18497. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18498. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18499. if (startBufferIndex < endBufferIndex)
  18500. {
  18501. info.buffer->copyFrom (chan, info.startSample + validStart,
  18502. buffer,
  18503. chan, startBufferIndex,
  18504. validEnd - validStart);
  18505. }
  18506. else
  18507. {
  18508. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18509. info.buffer->copyFrom (chan, info.startSample + validStart,
  18510. buffer,
  18511. chan, startBufferIndex,
  18512. initialSize);
  18513. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18514. buffer,
  18515. chan, 0,
  18516. (validEnd - validStart) - initialSize);
  18517. }
  18518. }
  18519. }
  18520. nextPlayPos += info.numSamples;
  18521. if (source->isLooping() && nextPlayPos > 0)
  18522. nextPlayPos %= source->getTotalLength();
  18523. }
  18524. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18525. if (thread != 0)
  18526. thread->notify();
  18527. }
  18528. int BufferingAudioSource::getNextReadPosition() const
  18529. {
  18530. return (source->isLooping() && nextPlayPos > 0)
  18531. ? nextPlayPos % source->getTotalLength()
  18532. : nextPlayPos;
  18533. }
  18534. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18535. {
  18536. const ScopedLock sl (bufferStartPosLock);
  18537. nextPlayPos = newPosition;
  18538. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18539. if (thread != 0)
  18540. thread->notify();
  18541. }
  18542. bool BufferingAudioSource::readNextBufferChunk()
  18543. {
  18544. int newBVS, newBVE, sectionToReadStart, sectionToReadEnd;
  18545. {
  18546. const ScopedLock sl (bufferStartPosLock);
  18547. if (wasSourceLooping != isLooping())
  18548. {
  18549. wasSourceLooping = isLooping();
  18550. bufferValidStart = 0;
  18551. bufferValidEnd = 0;
  18552. }
  18553. newBVS = jmax (0, nextPlayPos);
  18554. newBVE = newBVS + buffer.getNumSamples() - 4;
  18555. sectionToReadStart = 0;
  18556. sectionToReadEnd = 0;
  18557. const int maxChunkSize = 2048;
  18558. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18559. {
  18560. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18561. sectionToReadStart = newBVS;
  18562. sectionToReadEnd = newBVE;
  18563. bufferValidStart = 0;
  18564. bufferValidEnd = 0;
  18565. }
  18566. else if (abs (newBVS - bufferValidStart) > 512
  18567. || abs (newBVE - bufferValidEnd) > 512)
  18568. {
  18569. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18570. sectionToReadStart = bufferValidEnd;
  18571. sectionToReadEnd = newBVE;
  18572. bufferValidStart = newBVS;
  18573. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18574. }
  18575. }
  18576. if (sectionToReadStart != sectionToReadEnd)
  18577. {
  18578. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18579. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18580. if (bufferIndexStart < bufferIndexEnd)
  18581. {
  18582. readBufferSection (sectionToReadStart,
  18583. sectionToReadEnd - sectionToReadStart,
  18584. bufferIndexStart);
  18585. }
  18586. else
  18587. {
  18588. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18589. readBufferSection (sectionToReadStart,
  18590. initialSize,
  18591. bufferIndexStart);
  18592. readBufferSection (sectionToReadStart + initialSize,
  18593. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18594. 0);
  18595. }
  18596. const ScopedLock sl2 (bufferStartPosLock);
  18597. bufferValidStart = newBVS;
  18598. bufferValidEnd = newBVE;
  18599. return true;
  18600. }
  18601. else
  18602. {
  18603. return false;
  18604. }
  18605. }
  18606. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18607. {
  18608. if (source->getNextReadPosition() != start)
  18609. source->setNextReadPosition (start);
  18610. AudioSourceChannelInfo info;
  18611. info.buffer = &buffer;
  18612. info.startSample = bufferOffset;
  18613. info.numSamples = length;
  18614. source->getNextAudioBlock (info);
  18615. }
  18616. END_JUCE_NAMESPACE
  18617. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18618. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18619. BEGIN_JUCE_NAMESPACE
  18620. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18621. const bool deleteSourceWhenDeleted_)
  18622. : requiredNumberOfChannels (2),
  18623. source (source_),
  18624. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18625. buffer (2, 16)
  18626. {
  18627. remappedInfo.buffer = &buffer;
  18628. remappedInfo.startSample = 0;
  18629. }
  18630. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18631. {
  18632. if (deleteSourceWhenDeleted)
  18633. delete source;
  18634. }
  18635. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18636. {
  18637. const ScopedLock sl (lock);
  18638. requiredNumberOfChannels = requiredNumberOfChannels_;
  18639. }
  18640. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18641. {
  18642. const ScopedLock sl (lock);
  18643. remappedInputs.clear();
  18644. remappedOutputs.clear();
  18645. }
  18646. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18647. {
  18648. const ScopedLock sl (lock);
  18649. while (remappedInputs.size() < destIndex)
  18650. remappedInputs.add (-1);
  18651. remappedInputs.set (destIndex, sourceIndex);
  18652. }
  18653. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18654. {
  18655. const ScopedLock sl (lock);
  18656. while (remappedOutputs.size() < sourceIndex)
  18657. remappedOutputs.add (-1);
  18658. remappedOutputs.set (sourceIndex, destIndex);
  18659. }
  18660. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18661. {
  18662. const ScopedLock sl (lock);
  18663. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18664. return remappedInputs.getUnchecked (inputChannelIndex);
  18665. return -1;
  18666. }
  18667. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18668. {
  18669. const ScopedLock sl (lock);
  18670. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18671. return remappedOutputs .getUnchecked (outputChannelIndex);
  18672. return -1;
  18673. }
  18674. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18675. {
  18676. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18677. }
  18678. void ChannelRemappingAudioSource::releaseResources()
  18679. {
  18680. source->releaseResources();
  18681. }
  18682. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18683. {
  18684. const ScopedLock sl (lock);
  18685. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18686. const int numChans = bufferToFill.buffer->getNumChannels();
  18687. int i;
  18688. for (i = 0; i < buffer.getNumChannels(); ++i)
  18689. {
  18690. const int remappedChan = getRemappedInputChannel (i);
  18691. if (remappedChan >= 0 && remappedChan < numChans)
  18692. {
  18693. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18694. remappedChan,
  18695. bufferToFill.startSample,
  18696. bufferToFill.numSamples);
  18697. }
  18698. else
  18699. {
  18700. buffer.clear (i, 0, bufferToFill.numSamples);
  18701. }
  18702. }
  18703. remappedInfo.numSamples = bufferToFill.numSamples;
  18704. source->getNextAudioBlock (remappedInfo);
  18705. bufferToFill.clearActiveBufferRegion();
  18706. for (i = 0; i < requiredNumberOfChannels; ++i)
  18707. {
  18708. const int remappedChan = getRemappedOutputChannel (i);
  18709. if (remappedChan >= 0 && remappedChan < numChans)
  18710. {
  18711. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18712. buffer, i, 0, bufferToFill.numSamples);
  18713. }
  18714. }
  18715. }
  18716. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18717. {
  18718. XmlElement* e = new XmlElement (T("MAPPINGS"));
  18719. String ins, outs;
  18720. int i;
  18721. const ScopedLock sl (lock);
  18722. for (i = 0; i < remappedInputs.size(); ++i)
  18723. ins << remappedInputs.getUnchecked(i) << T(' ');
  18724. for (i = 0; i < remappedOutputs.size(); ++i)
  18725. outs << remappedOutputs.getUnchecked(i) << T(' ');
  18726. e->setAttribute (T("inputs"), ins.trimEnd());
  18727. e->setAttribute (T("outputs"), outs.trimEnd());
  18728. return e;
  18729. }
  18730. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18731. {
  18732. if (e.hasTagName (T("MAPPINGS")))
  18733. {
  18734. const ScopedLock sl (lock);
  18735. clearAllMappings();
  18736. StringArray ins, outs;
  18737. ins.addTokens (e.getStringAttribute (T("inputs")), false);
  18738. outs.addTokens (e.getStringAttribute (T("outputs")), false);
  18739. int i;
  18740. for (i = 0; i < ins.size(); ++i)
  18741. remappedInputs.add (ins[i].getIntValue());
  18742. for (i = 0; i < outs.size(); ++i)
  18743. remappedOutputs.add (outs[i].getIntValue());
  18744. }
  18745. }
  18746. END_JUCE_NAMESPACE
  18747. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18748. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18749. BEGIN_JUCE_NAMESPACE
  18750. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18751. const bool deleteInputWhenDeleted_)
  18752. : input (inputSource),
  18753. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18754. {
  18755. jassert (inputSource != 0);
  18756. for (int i = 2; --i >= 0;)
  18757. iirFilters.add (new IIRFilter());
  18758. }
  18759. IIRFilterAudioSource::~IIRFilterAudioSource()
  18760. {
  18761. if (deleteInputWhenDeleted)
  18762. delete input;
  18763. }
  18764. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18765. {
  18766. for (int i = iirFilters.size(); --i >= 0;)
  18767. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18768. }
  18769. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18770. {
  18771. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18772. for (int i = iirFilters.size(); --i >= 0;)
  18773. iirFilters.getUnchecked(i)->reset();
  18774. }
  18775. void IIRFilterAudioSource::releaseResources()
  18776. {
  18777. input->releaseResources();
  18778. }
  18779. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18780. {
  18781. input->getNextAudioBlock (bufferToFill);
  18782. const int numChannels = bufferToFill.buffer->getNumChannels();
  18783. while (numChannels > iirFilters.size())
  18784. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  18785. for (int i = 0; i < numChannels; ++i)
  18786. iirFilters.getUnchecked(i)
  18787. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  18788. bufferToFill.numSamples);
  18789. }
  18790. END_JUCE_NAMESPACE
  18791. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18792. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  18793. BEGIN_JUCE_NAMESPACE
  18794. MixerAudioSource::MixerAudioSource()
  18795. : tempBuffer (2, 0),
  18796. currentSampleRate (0.0),
  18797. bufferSizeExpected (0)
  18798. {
  18799. }
  18800. MixerAudioSource::~MixerAudioSource()
  18801. {
  18802. removeAllInputs();
  18803. }
  18804. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  18805. {
  18806. if (input != 0 && ! inputs.contains (input))
  18807. {
  18808. double localRate;
  18809. int localBufferSize;
  18810. {
  18811. const ScopedLock sl (lock);
  18812. localRate = currentSampleRate;
  18813. localBufferSize = bufferSizeExpected;
  18814. }
  18815. if (localRate != 0.0)
  18816. input->prepareToPlay (localBufferSize, localRate);
  18817. const ScopedLock sl (lock);
  18818. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  18819. inputs.add (input);
  18820. }
  18821. }
  18822. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  18823. {
  18824. if (input != 0)
  18825. {
  18826. int index;
  18827. {
  18828. const ScopedLock sl (lock);
  18829. index = inputs.indexOf ((void*) input);
  18830. if (index >= 0)
  18831. {
  18832. inputsToDelete.shiftBits (index, 1);
  18833. inputs.remove (index);
  18834. }
  18835. }
  18836. if (index >= 0)
  18837. {
  18838. input->releaseResources();
  18839. if (deleteInput)
  18840. delete input;
  18841. }
  18842. }
  18843. }
  18844. void MixerAudioSource::removeAllInputs()
  18845. {
  18846. VoidArray inputsCopy;
  18847. BigInteger inputsToDeleteCopy;
  18848. {
  18849. const ScopedLock sl (lock);
  18850. inputsCopy = inputs;
  18851. inputsToDeleteCopy = inputsToDelete;
  18852. }
  18853. for (int i = inputsCopy.size(); --i >= 0;)
  18854. if (inputsToDeleteCopy[i])
  18855. delete (AudioSource*) inputsCopy[i];
  18856. }
  18857. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18858. {
  18859. tempBuffer.setSize (2, samplesPerBlockExpected);
  18860. const ScopedLock sl (lock);
  18861. currentSampleRate = sampleRate;
  18862. bufferSizeExpected = samplesPerBlockExpected;
  18863. for (int i = inputs.size(); --i >= 0;)
  18864. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  18865. sampleRate);
  18866. }
  18867. void MixerAudioSource::releaseResources()
  18868. {
  18869. const ScopedLock sl (lock);
  18870. for (int i = inputs.size(); --i >= 0;)
  18871. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  18872. tempBuffer.setSize (2, 0);
  18873. currentSampleRate = 0;
  18874. bufferSizeExpected = 0;
  18875. }
  18876. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18877. {
  18878. const ScopedLock sl (lock);
  18879. if (inputs.size() > 0)
  18880. {
  18881. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  18882. if (inputs.size() > 1)
  18883. {
  18884. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  18885. info.buffer->getNumSamples());
  18886. AudioSourceChannelInfo info2;
  18887. info2.buffer = &tempBuffer;
  18888. info2.numSamples = info.numSamples;
  18889. info2.startSample = 0;
  18890. for (int i = 1; i < inputs.size(); ++i)
  18891. {
  18892. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  18893. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  18894. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  18895. }
  18896. }
  18897. }
  18898. else
  18899. {
  18900. info.clearActiveBufferRegion();
  18901. }
  18902. }
  18903. END_JUCE_NAMESPACE
  18904. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  18905. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  18906. BEGIN_JUCE_NAMESPACE
  18907. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  18908. const bool deleteInputWhenDeleted_)
  18909. : input (inputSource),
  18910. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  18911. ratio (1.0),
  18912. lastRatio (1.0),
  18913. buffer (2, 0),
  18914. sampsInBuffer (0)
  18915. {
  18916. jassert (input != 0);
  18917. }
  18918. ResamplingAudioSource::~ResamplingAudioSource()
  18919. {
  18920. if (deleteInputWhenDeleted)
  18921. delete input;
  18922. }
  18923. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  18924. {
  18925. jassert (samplesInPerOutputSample > 0);
  18926. const ScopedLock sl (ratioLock);
  18927. ratio = jmax (0.0, samplesInPerOutputSample);
  18928. }
  18929. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  18930. double sampleRate)
  18931. {
  18932. const ScopedLock sl (ratioLock);
  18933. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18934. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  18935. buffer.clear();
  18936. sampsInBuffer = 0;
  18937. bufferPos = 0;
  18938. subSampleOffset = 0.0;
  18939. createLowPass (ratio);
  18940. resetFilters();
  18941. }
  18942. void ResamplingAudioSource::releaseResources()
  18943. {
  18944. input->releaseResources();
  18945. buffer.setSize (2, 0);
  18946. }
  18947. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18948. {
  18949. const ScopedLock sl (ratioLock);
  18950. if (lastRatio != ratio)
  18951. {
  18952. createLowPass (ratio);
  18953. lastRatio = ratio;
  18954. }
  18955. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  18956. int bufferSize = buffer.getNumSamples();
  18957. if (bufferSize < sampsNeeded + 8)
  18958. {
  18959. bufferPos %= bufferSize;
  18960. bufferSize = sampsNeeded + 32;
  18961. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  18962. }
  18963. bufferPos %= bufferSize;
  18964. int endOfBufferPos = bufferPos + sampsInBuffer;
  18965. while (sampsNeeded > sampsInBuffer)
  18966. {
  18967. endOfBufferPos %= bufferSize;
  18968. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  18969. bufferSize - endOfBufferPos);
  18970. AudioSourceChannelInfo readInfo;
  18971. readInfo.buffer = &buffer;
  18972. readInfo.numSamples = numToDo;
  18973. readInfo.startSample = endOfBufferPos;
  18974. input->getNextAudioBlock (readInfo);
  18975. if (ratio > 1.0001)
  18976. {
  18977. // for down-sampling, pre-apply the filter..
  18978. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  18979. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  18980. }
  18981. sampsInBuffer += numToDo;
  18982. endOfBufferPos += numToDo;
  18983. }
  18984. float* dl = info.buffer->getSampleData (0, info.startSample);
  18985. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  18986. const float* const bl = buffer.getSampleData (0, 0);
  18987. const float* const br = buffer.getSampleData (1, 0);
  18988. int nextPos = (bufferPos + 1) % bufferSize;
  18989. for (int m = info.numSamples; --m >= 0;)
  18990. {
  18991. const float alpha = (float) subSampleOffset;
  18992. const float invAlpha = 1.0f - alpha;
  18993. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  18994. if (dr != 0)
  18995. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  18996. subSampleOffset += ratio;
  18997. jassert (sampsInBuffer > 0);
  18998. while (subSampleOffset >= 1.0)
  18999. {
  19000. if (++bufferPos >= bufferSize)
  19001. bufferPos = 0;
  19002. --sampsInBuffer;
  19003. nextPos = (bufferPos + 1) % bufferSize;
  19004. subSampleOffset -= 1.0;
  19005. }
  19006. }
  19007. if (ratio < 0.9999)
  19008. {
  19009. // for up-sampling, apply the filter after transposing..
  19010. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19011. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19012. }
  19013. else if (ratio <= 1.0001)
  19014. {
  19015. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19016. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19017. {
  19018. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19019. FilterState& fs = filterStates[i];
  19020. if (info.numSamples > 1)
  19021. {
  19022. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19023. }
  19024. else
  19025. {
  19026. fs.y2 = fs.y1;
  19027. fs.x2 = fs.x1;
  19028. }
  19029. fs.y1 = fs.x1 = *endOfBuffer;
  19030. }
  19031. }
  19032. jassert (sampsInBuffer >= 0);
  19033. }
  19034. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19035. {
  19036. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19037. : 0.5 * frequencyRatio;
  19038. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19039. const double nSquared = n * n;
  19040. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19041. setFilterCoefficients (c1,
  19042. c1 * 2.0f,
  19043. c1,
  19044. 1.0,
  19045. c1 * 2.0 * (1.0 - nSquared),
  19046. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19047. }
  19048. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19049. {
  19050. const double a = 1.0 / c4;
  19051. c1 *= a;
  19052. c2 *= a;
  19053. c3 *= a;
  19054. c5 *= a;
  19055. c6 *= a;
  19056. coefficients[0] = c1;
  19057. coefficients[1] = c2;
  19058. coefficients[2] = c3;
  19059. coefficients[3] = c4;
  19060. coefficients[4] = c5;
  19061. coefficients[5] = c6;
  19062. }
  19063. void ResamplingAudioSource::resetFilters()
  19064. {
  19065. zeromem (filterStates, sizeof (filterStates));
  19066. }
  19067. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19068. {
  19069. while (--num >= 0)
  19070. {
  19071. const double in = *samples;
  19072. double out = coefficients[0] * in
  19073. + coefficients[1] * fs.x1
  19074. + coefficients[2] * fs.x2
  19075. - coefficients[4] * fs.y1
  19076. - coefficients[5] * fs.y2;
  19077. #if JUCE_INTEL
  19078. if (! (out < -1.0e-8 || out > 1.0e-8))
  19079. out = 0;
  19080. #endif
  19081. fs.x2 = fs.x1;
  19082. fs.x1 = in;
  19083. fs.y2 = fs.y1;
  19084. fs.y1 = out;
  19085. *samples++ = (float) out;
  19086. }
  19087. }
  19088. END_JUCE_NAMESPACE
  19089. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19090. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19091. BEGIN_JUCE_NAMESPACE
  19092. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19093. : frequency (1000.0),
  19094. sampleRate (44100.0),
  19095. currentPhase (0.0),
  19096. phasePerSample (0.0),
  19097. amplitude (0.5f)
  19098. {
  19099. }
  19100. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19101. {
  19102. }
  19103. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19104. {
  19105. amplitude = newAmplitude;
  19106. }
  19107. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19108. {
  19109. frequency = newFrequencyHz;
  19110. phasePerSample = 0.0;
  19111. }
  19112. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19113. double sampleRate_)
  19114. {
  19115. currentPhase = 0.0;
  19116. phasePerSample = 0.0;
  19117. sampleRate = sampleRate_;
  19118. }
  19119. void ToneGeneratorAudioSource::releaseResources()
  19120. {
  19121. }
  19122. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19123. {
  19124. if (phasePerSample == 0.0)
  19125. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19126. for (int i = 0; i < info.numSamples; ++i)
  19127. {
  19128. const float sample = amplitude * (float) sin (currentPhase);
  19129. currentPhase += phasePerSample;
  19130. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19131. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19132. }
  19133. }
  19134. END_JUCE_NAMESPACE
  19135. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19136. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19137. BEGIN_JUCE_NAMESPACE
  19138. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19139. : sampleRate (0),
  19140. bufferSize (0),
  19141. useDefaultInputChannels (true),
  19142. useDefaultOutputChannels (true)
  19143. {
  19144. }
  19145. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19146. {
  19147. return outputDeviceName == other.outputDeviceName
  19148. && inputDeviceName == other.inputDeviceName
  19149. && sampleRate == other.sampleRate
  19150. && bufferSize == other.bufferSize
  19151. && inputChannels == other.inputChannels
  19152. && useDefaultInputChannels == other.useDefaultInputChannels
  19153. && outputChannels == other.outputChannels
  19154. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19155. }
  19156. AudioDeviceManager::AudioDeviceManager()
  19157. : currentAudioDevice (0),
  19158. numInputChansNeeded (0),
  19159. numOutputChansNeeded (2),
  19160. listNeedsScanning (true),
  19161. useInputNames (false),
  19162. inputLevelMeasurementEnabledCount (0),
  19163. inputLevel (0),
  19164. tempBuffer (2, 2),
  19165. defaultMidiOutput (0),
  19166. cpuUsageMs (0),
  19167. timeToCpuScale (0)
  19168. {
  19169. callbackHandler.owner = this;
  19170. }
  19171. AudioDeviceManager::~AudioDeviceManager()
  19172. {
  19173. currentAudioDevice = 0;
  19174. defaultMidiOutput = 0;
  19175. }
  19176. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19177. {
  19178. if (availableDeviceTypes.size() == 0)
  19179. {
  19180. createAudioDeviceTypes (availableDeviceTypes);
  19181. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19182. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19183. if (availableDeviceTypes.size() > 0)
  19184. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19185. }
  19186. }
  19187. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19188. {
  19189. scanDevicesIfNeeded();
  19190. return availableDeviceTypes;
  19191. }
  19192. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19193. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19194. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19195. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19196. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19197. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19198. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19199. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19200. {
  19201. #if JUCE_WINDOWS
  19202. #if JUCE_WASAPI
  19203. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19204. list.add (juce_createAudioIODeviceType_WASAPI());
  19205. #endif
  19206. #if JUCE_DIRECTSOUND
  19207. list.add (juce_createAudioIODeviceType_DirectSound());
  19208. #endif
  19209. #if JUCE_ASIO
  19210. list.add (juce_createAudioIODeviceType_ASIO());
  19211. #endif
  19212. #endif
  19213. #if JUCE_MAC
  19214. list.add (juce_createAudioIODeviceType_CoreAudio());
  19215. #endif
  19216. #if JUCE_IPHONE
  19217. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19218. #endif
  19219. #if JUCE_LINUX && JUCE_ALSA
  19220. list.add (juce_createAudioIODeviceType_ALSA());
  19221. #endif
  19222. #if JUCE_LINUX && JUCE_JACK
  19223. list.add (juce_createAudioIODeviceType_JACK());
  19224. #endif
  19225. }
  19226. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19227. const int numOutputChannelsNeeded,
  19228. const XmlElement* const e,
  19229. const bool selectDefaultDeviceOnFailure,
  19230. const String& preferredDefaultDeviceName,
  19231. const AudioDeviceSetup* preferredSetupOptions)
  19232. {
  19233. scanDevicesIfNeeded();
  19234. numInputChansNeeded = numInputChannelsNeeded;
  19235. numOutputChansNeeded = numOutputChannelsNeeded;
  19236. if (e != 0 && e->hasTagName (T("DEVICESETUP")))
  19237. {
  19238. lastExplicitSettings = new XmlElement (*e);
  19239. String error;
  19240. AudioDeviceSetup setup;
  19241. if (preferredSetupOptions != 0)
  19242. setup = *preferredSetupOptions;
  19243. if (e->getStringAttribute (T("audioDeviceName")).isNotEmpty())
  19244. {
  19245. setup.inputDeviceName = setup.outputDeviceName
  19246. = e->getStringAttribute (T("audioDeviceName"));
  19247. }
  19248. else
  19249. {
  19250. setup.inputDeviceName = e->getStringAttribute (T("audioInputDeviceName"));
  19251. setup.outputDeviceName = e->getStringAttribute (T("audioOutputDeviceName"));
  19252. }
  19253. currentDeviceType = e->getStringAttribute (T("deviceType"));
  19254. if (currentDeviceType.isEmpty())
  19255. {
  19256. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19257. if (type != 0)
  19258. currentDeviceType = type->getTypeName();
  19259. else if (availableDeviceTypes.size() > 0)
  19260. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19261. }
  19262. setup.bufferSize = e->getIntAttribute (T("audioDeviceBufferSize"));
  19263. setup.sampleRate = e->getDoubleAttribute (T("audioDeviceRate"));
  19264. setup.inputChannels.parseString (e->getStringAttribute (T("audioDeviceInChans"), T("11")), 2);
  19265. setup.outputChannels.parseString (e->getStringAttribute (T("audioDeviceOutChans"), T("11")), 2);
  19266. setup.useDefaultInputChannels = ! e->hasAttribute (T("audioDeviceInChans"));
  19267. setup.useDefaultOutputChannels = ! e->hasAttribute (T("audioDeviceOutChans"));
  19268. error = setAudioDeviceSetup (setup, true);
  19269. midiInsFromXml.clear();
  19270. forEachXmlChildElementWithTagName (*e, c, T("MIDIINPUT"))
  19271. midiInsFromXml.add (c->getStringAttribute (T("name")));
  19272. const StringArray allMidiIns (MidiInput::getDevices());
  19273. for (int i = allMidiIns.size(); --i >= 0;)
  19274. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19275. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19276. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19277. false, preferredDefaultDeviceName);
  19278. setDefaultMidiOutput (e->getStringAttribute (T("defaultMidiOutput")));
  19279. return error;
  19280. }
  19281. else
  19282. {
  19283. AudioDeviceSetup setup;
  19284. if (preferredSetupOptions != 0)
  19285. {
  19286. setup = *preferredSetupOptions;
  19287. }
  19288. else if (preferredDefaultDeviceName.isNotEmpty())
  19289. {
  19290. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19291. {
  19292. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19293. StringArray outs (type->getDeviceNames (false));
  19294. int i;
  19295. for (i = 0; i < outs.size(); ++i)
  19296. {
  19297. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19298. {
  19299. setup.outputDeviceName = outs[i];
  19300. break;
  19301. }
  19302. }
  19303. StringArray ins (type->getDeviceNames (true));
  19304. for (i = 0; i < ins.size(); ++i)
  19305. {
  19306. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19307. {
  19308. setup.inputDeviceName = ins[i];
  19309. break;
  19310. }
  19311. }
  19312. }
  19313. }
  19314. insertDefaultDeviceNames (setup);
  19315. return setAudioDeviceSetup (setup, false);
  19316. }
  19317. }
  19318. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19319. {
  19320. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19321. if (type != 0)
  19322. {
  19323. if (setup.outputDeviceName.isEmpty())
  19324. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19325. if (setup.inputDeviceName.isEmpty())
  19326. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19327. }
  19328. }
  19329. XmlElement* AudioDeviceManager::createStateXml() const
  19330. {
  19331. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19332. }
  19333. void AudioDeviceManager::scanDevicesIfNeeded()
  19334. {
  19335. if (listNeedsScanning)
  19336. {
  19337. listNeedsScanning = false;
  19338. createDeviceTypesIfNeeded();
  19339. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19340. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19341. }
  19342. }
  19343. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19344. {
  19345. scanDevicesIfNeeded();
  19346. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19347. {
  19348. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19349. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19350. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19351. {
  19352. return type;
  19353. }
  19354. }
  19355. return 0;
  19356. }
  19357. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19358. {
  19359. setup = currentSetup;
  19360. }
  19361. void AudioDeviceManager::deleteCurrentDevice()
  19362. {
  19363. currentAudioDevice = 0;
  19364. currentSetup.inputDeviceName = String::empty;
  19365. currentSetup.outputDeviceName = String::empty;
  19366. }
  19367. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19368. const bool treatAsChosenDevice)
  19369. {
  19370. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19371. {
  19372. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19373. && currentDeviceType != type)
  19374. {
  19375. currentDeviceType = type;
  19376. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19377. insertDefaultDeviceNames (s);
  19378. setAudioDeviceSetup (s, treatAsChosenDevice);
  19379. sendChangeMessage (this);
  19380. break;
  19381. }
  19382. }
  19383. }
  19384. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19385. {
  19386. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19387. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19388. return availableDeviceTypes[i];
  19389. return availableDeviceTypes[0];
  19390. }
  19391. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19392. const bool treatAsChosenDevice)
  19393. {
  19394. jassert (&newSetup != &currentSetup); // this will have no effect
  19395. if (newSetup == currentSetup && currentAudioDevice != 0)
  19396. return String::empty;
  19397. if (! (newSetup == currentSetup))
  19398. sendChangeMessage (this);
  19399. stopDevice();
  19400. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19401. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19402. String error;
  19403. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19404. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19405. {
  19406. deleteCurrentDevice();
  19407. if (treatAsChosenDevice)
  19408. updateXml();
  19409. return String::empty;
  19410. }
  19411. if (currentSetup.inputDeviceName != newInputDeviceName
  19412. || currentSetup.outputDeviceName != newOutputDeviceName
  19413. || currentAudioDevice == 0)
  19414. {
  19415. deleteCurrentDevice();
  19416. scanDevicesIfNeeded();
  19417. if (newOutputDeviceName.isNotEmpty()
  19418. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19419. {
  19420. return "No such device: " + newOutputDeviceName;
  19421. }
  19422. if (newInputDeviceName.isNotEmpty()
  19423. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19424. {
  19425. return "No such device: " + newInputDeviceName;
  19426. }
  19427. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19428. if (currentAudioDevice == 0)
  19429. 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!";
  19430. else
  19431. error = currentAudioDevice->getLastError();
  19432. if (error.isNotEmpty())
  19433. {
  19434. deleteCurrentDevice();
  19435. return error;
  19436. }
  19437. if (newSetup.useDefaultInputChannels)
  19438. {
  19439. inputChannels.clear();
  19440. inputChannels.setRange (0, numInputChansNeeded, true);
  19441. }
  19442. if (newSetup.useDefaultOutputChannels)
  19443. {
  19444. outputChannels.clear();
  19445. outputChannels.setRange (0, numOutputChansNeeded, true);
  19446. }
  19447. if (newInputDeviceName.isEmpty())
  19448. inputChannels.clear();
  19449. if (newOutputDeviceName.isEmpty())
  19450. outputChannels.clear();
  19451. }
  19452. if (! newSetup.useDefaultInputChannels)
  19453. inputChannels = newSetup.inputChannels;
  19454. if (! newSetup.useDefaultOutputChannels)
  19455. outputChannels = newSetup.outputChannels;
  19456. currentSetup = newSetup;
  19457. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19458. error = currentAudioDevice->open (inputChannels,
  19459. outputChannels,
  19460. currentSetup.sampleRate,
  19461. currentSetup.bufferSize);
  19462. if (error.isEmpty())
  19463. {
  19464. currentDeviceType = currentAudioDevice->getTypeName();
  19465. currentAudioDevice->start (&callbackHandler);
  19466. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19467. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19468. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19469. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19470. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19471. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19472. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19473. if (treatAsChosenDevice)
  19474. updateXml();
  19475. }
  19476. else
  19477. {
  19478. deleteCurrentDevice();
  19479. }
  19480. return error;
  19481. }
  19482. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19483. {
  19484. jassert (currentAudioDevice != 0);
  19485. if (rate > 0)
  19486. {
  19487. bool ok = false;
  19488. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19489. {
  19490. const double sr = currentAudioDevice->getSampleRate (i);
  19491. if (sr == rate)
  19492. ok = true;
  19493. }
  19494. if (! ok)
  19495. rate = 0;
  19496. }
  19497. if (rate == 0)
  19498. {
  19499. double lowestAbove44 = 0.0;
  19500. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19501. {
  19502. const double sr = currentAudioDevice->getSampleRate (i);
  19503. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19504. lowestAbove44 = sr;
  19505. }
  19506. if (lowestAbove44 == 0.0)
  19507. rate = currentAudioDevice->getSampleRate (0);
  19508. else
  19509. rate = lowestAbove44;
  19510. }
  19511. return rate;
  19512. }
  19513. void AudioDeviceManager::stopDevice()
  19514. {
  19515. if (currentAudioDevice != 0)
  19516. currentAudioDevice->stop();
  19517. testSound = 0;
  19518. }
  19519. void AudioDeviceManager::closeAudioDevice()
  19520. {
  19521. stopDevice();
  19522. currentAudioDevice = 0;
  19523. }
  19524. void AudioDeviceManager::restartLastAudioDevice()
  19525. {
  19526. if (currentAudioDevice == 0)
  19527. {
  19528. if (currentSetup.inputDeviceName.isEmpty()
  19529. && currentSetup.outputDeviceName.isEmpty())
  19530. {
  19531. // This method will only reload the last device that was running
  19532. // before closeAudioDevice() was called - you need to actually open
  19533. // one first, with setAudioDevice().
  19534. jassertfalse
  19535. return;
  19536. }
  19537. AudioDeviceSetup s (currentSetup);
  19538. setAudioDeviceSetup (s, false);
  19539. }
  19540. }
  19541. void AudioDeviceManager::updateXml()
  19542. {
  19543. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19544. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19545. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19546. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19547. if (currentAudioDevice != 0)
  19548. {
  19549. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19550. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19551. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19552. if (! currentSetup.useDefaultInputChannels)
  19553. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19554. if (! currentSetup.useDefaultOutputChannels)
  19555. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19556. }
  19557. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19558. {
  19559. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19560. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19561. }
  19562. if (midiInsFromXml.size() > 0)
  19563. {
  19564. // Add any midi devices that have been enabled before, but which aren't currently
  19565. // open because the device has been disconnected.
  19566. const StringArray availableMidiDevices (MidiInput::getDevices());
  19567. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19568. {
  19569. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19570. {
  19571. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19572. m->setAttribute ("name", midiInsFromXml[i]);
  19573. }
  19574. }
  19575. }
  19576. if (defaultMidiOutputName.isNotEmpty())
  19577. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19578. }
  19579. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19580. {
  19581. {
  19582. const ScopedLock sl (audioCallbackLock);
  19583. if (callbacks.contains (newCallback))
  19584. return;
  19585. }
  19586. if (currentAudioDevice != 0 && newCallback != 0)
  19587. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19588. const ScopedLock sl (audioCallbackLock);
  19589. callbacks.add (newCallback);
  19590. }
  19591. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19592. {
  19593. if (callback != 0)
  19594. {
  19595. bool needsDeinitialising = currentAudioDevice != 0;
  19596. {
  19597. const ScopedLock sl (audioCallbackLock);
  19598. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19599. callbacks.removeValue (callback);
  19600. }
  19601. if (needsDeinitialising)
  19602. callback->audioDeviceStopped();
  19603. }
  19604. }
  19605. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19606. int numInputChannels,
  19607. float** outputChannelData,
  19608. int numOutputChannels,
  19609. int numSamples)
  19610. {
  19611. const ScopedLock sl (audioCallbackLock);
  19612. if (inputLevelMeasurementEnabledCount > 0)
  19613. {
  19614. for (int j = 0; j < numSamples; ++j)
  19615. {
  19616. float s = 0;
  19617. for (int i = 0; i < numInputChannels; ++i)
  19618. s += fabsf (inputChannelData[i][j]);
  19619. s /= numInputChannels;
  19620. const double decayFactor = 0.99992;
  19621. if (s > inputLevel)
  19622. inputLevel = s;
  19623. else if (inputLevel > 0.001f)
  19624. inputLevel *= decayFactor;
  19625. else
  19626. inputLevel = 0;
  19627. }
  19628. }
  19629. if (callbacks.size() > 0)
  19630. {
  19631. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19632. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19633. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19634. outputChannelData, numOutputChannels, numSamples);
  19635. float** const tempChans = tempBuffer.getArrayOfChannels();
  19636. for (int i = callbacks.size(); --i > 0;)
  19637. {
  19638. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19639. tempChans, numOutputChannels, numSamples);
  19640. for (int chan = 0; chan < numOutputChannels; ++chan)
  19641. {
  19642. const float* const src = tempChans [chan];
  19643. float* const dst = outputChannelData [chan];
  19644. if (src != 0 && dst != 0)
  19645. for (int j = 0; j < numSamples; ++j)
  19646. dst[j] += src[j];
  19647. }
  19648. }
  19649. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19650. const double filterAmount = 0.2;
  19651. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19652. }
  19653. else
  19654. {
  19655. for (int i = 0; i < numOutputChannels; ++i)
  19656. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19657. }
  19658. if (testSound != 0)
  19659. {
  19660. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19661. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19662. for (int i = 0; i < numOutputChannels; ++i)
  19663. for (int j = 0; j < numSamps; ++j)
  19664. outputChannelData [i][j] += src[j];
  19665. testSoundPosition += numSamps;
  19666. if (testSoundPosition >= testSound->getNumSamples())
  19667. testSound = 0;
  19668. }
  19669. }
  19670. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19671. {
  19672. cpuUsageMs = 0;
  19673. const double sampleRate = device->getCurrentSampleRate();
  19674. const int blockSize = device->getCurrentBufferSizeSamples();
  19675. if (sampleRate > 0.0 && blockSize > 0)
  19676. {
  19677. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19678. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19679. }
  19680. {
  19681. const ScopedLock sl (audioCallbackLock);
  19682. for (int i = callbacks.size(); --i >= 0;)
  19683. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19684. }
  19685. sendChangeMessage (this);
  19686. }
  19687. void AudioDeviceManager::audioDeviceStoppedInt()
  19688. {
  19689. cpuUsageMs = 0;
  19690. timeToCpuScale = 0;
  19691. sendChangeMessage (this);
  19692. const ScopedLock sl (audioCallbackLock);
  19693. for (int i = callbacks.size(); --i >= 0;)
  19694. callbacks.getUnchecked(i)->audioDeviceStopped();
  19695. }
  19696. double AudioDeviceManager::getCpuUsage() const
  19697. {
  19698. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19699. }
  19700. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19701. const bool enabled)
  19702. {
  19703. if (enabled != isMidiInputEnabled (name))
  19704. {
  19705. if (enabled)
  19706. {
  19707. const int index = MidiInput::getDevices().indexOf (name);
  19708. if (index >= 0)
  19709. {
  19710. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19711. if (min != 0)
  19712. {
  19713. enabledMidiInputs.add (min);
  19714. min->start();
  19715. }
  19716. }
  19717. }
  19718. else
  19719. {
  19720. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19721. if (enabledMidiInputs[i]->getName() == name)
  19722. enabledMidiInputs.remove (i);
  19723. }
  19724. updateXml();
  19725. sendChangeMessage (this);
  19726. }
  19727. }
  19728. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19729. {
  19730. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19731. if (enabledMidiInputs[i]->getName() == name)
  19732. return true;
  19733. return false;
  19734. }
  19735. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19736. MidiInputCallback* callback)
  19737. {
  19738. removeMidiInputCallback (name, callback);
  19739. if (name.isEmpty())
  19740. {
  19741. midiCallbacks.add (callback);
  19742. midiCallbackDevices.add (0);
  19743. }
  19744. else
  19745. {
  19746. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19747. {
  19748. if (enabledMidiInputs[i]->getName() == name)
  19749. {
  19750. const ScopedLock sl (midiCallbackLock);
  19751. midiCallbacks.add (callback);
  19752. midiCallbackDevices.add (enabledMidiInputs[i]);
  19753. break;
  19754. }
  19755. }
  19756. }
  19757. }
  19758. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19759. MidiInputCallback* /*callback*/)
  19760. {
  19761. const ScopedLock sl (midiCallbackLock);
  19762. for (int i = midiCallbacks.size(); --i >= 0;)
  19763. {
  19764. String devName;
  19765. if (midiCallbackDevices.getUnchecked(i) != 0)
  19766. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19767. if (devName == name)
  19768. {
  19769. midiCallbacks.remove (i);
  19770. midiCallbackDevices.remove (i);
  19771. }
  19772. }
  19773. }
  19774. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  19775. const MidiMessage& message)
  19776. {
  19777. if (! message.isActiveSense())
  19778. {
  19779. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  19780. const ScopedLock sl (midiCallbackLock);
  19781. for (int i = midiCallbackDevices.size(); --i >= 0;)
  19782. {
  19783. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  19784. if (md == source || (md == 0 && isDefaultSource))
  19785. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  19786. }
  19787. }
  19788. }
  19789. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  19790. {
  19791. if (defaultMidiOutputName != deviceName)
  19792. {
  19793. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  19794. {
  19795. const ScopedLock sl (audioCallbackLock);
  19796. oldCallbacks = callbacks;
  19797. callbacks.clear();
  19798. }
  19799. if (currentAudioDevice != 0)
  19800. for (int i = oldCallbacks.size(); --i >= 0;)
  19801. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  19802. defaultMidiOutput = 0;
  19803. defaultMidiOutputName = deviceName;
  19804. if (deviceName.isNotEmpty())
  19805. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  19806. if (currentAudioDevice != 0)
  19807. for (int i = oldCallbacks.size(); --i >= 0;)
  19808. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  19809. {
  19810. const ScopedLock sl (audioCallbackLock);
  19811. callbacks = oldCallbacks;
  19812. }
  19813. updateXml();
  19814. sendChangeMessage (this);
  19815. }
  19816. }
  19817. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  19818. int numInputChannels,
  19819. float** outputChannelData,
  19820. int numOutputChannels,
  19821. int numSamples)
  19822. {
  19823. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  19824. }
  19825. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  19826. {
  19827. owner->audioDeviceAboutToStartInt (device);
  19828. }
  19829. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  19830. {
  19831. owner->audioDeviceStoppedInt();
  19832. }
  19833. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  19834. {
  19835. owner->handleIncomingMidiMessageInt (source, message);
  19836. }
  19837. void AudioDeviceManager::playTestSound()
  19838. {
  19839. { // cunningly nested to swap, unlock and delete in that order.
  19840. ScopedPointer <AudioSampleBuffer> oldSound;
  19841. {
  19842. const ScopedLock sl (audioCallbackLock);
  19843. oldSound = testSound;
  19844. }
  19845. }
  19846. testSoundPosition = 0;
  19847. if (currentAudioDevice != 0)
  19848. {
  19849. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  19850. const int soundLength = (int) sampleRate;
  19851. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  19852. float* samples = newSound->getSampleData (0);
  19853. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  19854. const float amplitude = 0.5f;
  19855. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19856. for (int i = 0; i < soundLength; ++i)
  19857. samples[i] = amplitude * (float) sin (i * phasePerSample);
  19858. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  19859. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  19860. const ScopedLock sl (audioCallbackLock);
  19861. testSound = newSound;
  19862. }
  19863. }
  19864. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  19865. {
  19866. const ScopedLock sl (audioCallbackLock);
  19867. if (enableMeasurement)
  19868. ++inputLevelMeasurementEnabledCount;
  19869. else
  19870. --inputLevelMeasurementEnabledCount;
  19871. inputLevel = 0;
  19872. }
  19873. double AudioDeviceManager::getCurrentInputLevel() const
  19874. {
  19875. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  19876. return inputLevel;
  19877. }
  19878. END_JUCE_NAMESPACE
  19879. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  19880. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  19881. BEGIN_JUCE_NAMESPACE
  19882. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  19883. : name (deviceName),
  19884. typeName (typeName_)
  19885. {
  19886. }
  19887. AudioIODevice::~AudioIODevice()
  19888. {
  19889. }
  19890. bool AudioIODevice::hasControlPanel() const
  19891. {
  19892. return false;
  19893. }
  19894. bool AudioIODevice::showControlPanel()
  19895. {
  19896. jassertfalse // this should only be called for devices which return true from
  19897. // their hasControlPanel() method.
  19898. return false;
  19899. }
  19900. END_JUCE_NAMESPACE
  19901. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  19902. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  19903. BEGIN_JUCE_NAMESPACE
  19904. AudioIODeviceType::AudioIODeviceType (const tchar* const name)
  19905. : typeName (name)
  19906. {
  19907. }
  19908. AudioIODeviceType::~AudioIODeviceType()
  19909. {
  19910. }
  19911. END_JUCE_NAMESPACE
  19912. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  19913. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  19914. BEGIN_JUCE_NAMESPACE
  19915. MidiOutput::MidiOutput()
  19916. : Thread ("midi out"),
  19917. internal (0),
  19918. firstMessage (0)
  19919. {
  19920. }
  19921. MidiOutput::PendingMessage::PendingMessage (const uint8* const data, const int len,
  19922. const double sampleNumber)
  19923. : message (data, len, sampleNumber)
  19924. {
  19925. }
  19926. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  19927. const double millisecondCounterToStartAt,
  19928. double samplesPerSecondForBuffer)
  19929. {
  19930. // You've got to call startBackgroundThread() for this to actually work..
  19931. jassert (isThreadRunning());
  19932. // this needs to be a value in the future - RTFM for this method!
  19933. jassert (millisecondCounterToStartAt > 0);
  19934. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  19935. MidiBuffer::Iterator i (buffer);
  19936. const uint8* data;
  19937. int len, time;
  19938. while (i.getNextEvent (data, len, time))
  19939. {
  19940. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  19941. PendingMessage* const m
  19942. = new PendingMessage (data, len, eventTime);
  19943. const ScopedLock sl (lock);
  19944. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  19945. {
  19946. m->next = firstMessage;
  19947. firstMessage = m;
  19948. }
  19949. else
  19950. {
  19951. PendingMessage* mm = firstMessage;
  19952. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  19953. mm = mm->next;
  19954. m->next = mm->next;
  19955. mm->next = m;
  19956. }
  19957. }
  19958. notify();
  19959. }
  19960. void MidiOutput::clearAllPendingMessages()
  19961. {
  19962. const ScopedLock sl (lock);
  19963. while (firstMessage != 0)
  19964. {
  19965. PendingMessage* const m = firstMessage;
  19966. firstMessage = firstMessage->next;
  19967. delete m;
  19968. }
  19969. }
  19970. void MidiOutput::startBackgroundThread()
  19971. {
  19972. startThread (9);
  19973. }
  19974. void MidiOutput::stopBackgroundThread()
  19975. {
  19976. stopThread (5000);
  19977. }
  19978. void MidiOutput::run()
  19979. {
  19980. while (! threadShouldExit())
  19981. {
  19982. uint32 now = Time::getMillisecondCounter();
  19983. uint32 eventTime = 0;
  19984. uint32 timeToWait = 500;
  19985. PendingMessage* message;
  19986. {
  19987. const ScopedLock sl (lock);
  19988. message = firstMessage;
  19989. if (message != 0)
  19990. {
  19991. eventTime = roundToInt (message->message.getTimeStamp());
  19992. if (eventTime > now + 20)
  19993. {
  19994. timeToWait = eventTime - (now + 20);
  19995. message = 0;
  19996. }
  19997. else
  19998. {
  19999. firstMessage = message->next;
  20000. }
  20001. }
  20002. }
  20003. if (message != 0)
  20004. {
  20005. if (eventTime > now)
  20006. {
  20007. Time::waitForMillisecondCounter (eventTime);
  20008. if (threadShouldExit())
  20009. break;
  20010. }
  20011. if (eventTime > now - 200)
  20012. sendMessageNow (message->message);
  20013. delete message;
  20014. }
  20015. else
  20016. {
  20017. jassert (timeToWait < 1000 * 30);
  20018. wait (timeToWait);
  20019. }
  20020. }
  20021. clearAllPendingMessages();
  20022. }
  20023. END_JUCE_NAMESPACE
  20024. /*** End of inlined file: juce_MidiOutput.cpp ***/
  20025. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  20026. BEGIN_JUCE_NAMESPACE
  20027. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20028. {
  20029. const double maxVal = (double) 0x7fff;
  20030. char* intData = (char*) dest;
  20031. if (dest != (void*) source || destBytesPerSample <= 4)
  20032. {
  20033. for (int i = 0; i < numSamples; ++i)
  20034. {
  20035. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20036. intData += destBytesPerSample;
  20037. }
  20038. }
  20039. else
  20040. {
  20041. intData += destBytesPerSample * numSamples;
  20042. for (int i = numSamples; --i >= 0;)
  20043. {
  20044. intData -= destBytesPerSample;
  20045. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20046. }
  20047. }
  20048. }
  20049. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20050. {
  20051. const double maxVal = (double) 0x7fff;
  20052. char* intData = (char*) dest;
  20053. if (dest != (void*) source || destBytesPerSample <= 4)
  20054. {
  20055. for (int i = 0; i < numSamples; ++i)
  20056. {
  20057. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20058. intData += destBytesPerSample;
  20059. }
  20060. }
  20061. else
  20062. {
  20063. intData += destBytesPerSample * numSamples;
  20064. for (int i = numSamples; --i >= 0;)
  20065. {
  20066. intData -= destBytesPerSample;
  20067. *(uint16*)intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20068. }
  20069. }
  20070. }
  20071. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20072. {
  20073. const double maxVal = (double) 0x7fffff;
  20074. char* intData = (char*) dest;
  20075. if (dest != (void*) source || destBytesPerSample <= 4)
  20076. {
  20077. for (int i = 0; i < numSamples; ++i)
  20078. {
  20079. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20080. intData += destBytesPerSample;
  20081. }
  20082. }
  20083. else
  20084. {
  20085. intData += destBytesPerSample * numSamples;
  20086. for (int i = numSamples; --i >= 0;)
  20087. {
  20088. intData -= destBytesPerSample;
  20089. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20090. }
  20091. }
  20092. }
  20093. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20094. {
  20095. const double maxVal = (double) 0x7fffff;
  20096. char* intData = (char*) dest;
  20097. if (dest != (void*) source || destBytesPerSample <= 4)
  20098. {
  20099. for (int i = 0; i < numSamples; ++i)
  20100. {
  20101. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20102. intData += destBytesPerSample;
  20103. }
  20104. }
  20105. else
  20106. {
  20107. intData += destBytesPerSample * numSamples;
  20108. for (int i = numSamples; --i >= 0;)
  20109. {
  20110. intData -= destBytesPerSample;
  20111. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20112. }
  20113. }
  20114. }
  20115. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20116. {
  20117. const double maxVal = (double) 0x7fffffff;
  20118. char* intData = (char*) dest;
  20119. if (dest != (void*) source || destBytesPerSample <= 4)
  20120. {
  20121. for (int i = 0; i < numSamples; ++i)
  20122. {
  20123. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20124. intData += destBytesPerSample;
  20125. }
  20126. }
  20127. else
  20128. {
  20129. intData += destBytesPerSample * numSamples;
  20130. for (int i = numSamples; --i >= 0;)
  20131. {
  20132. intData -= destBytesPerSample;
  20133. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20134. }
  20135. }
  20136. }
  20137. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20138. {
  20139. const double maxVal = (double) 0x7fffffff;
  20140. char* intData = (char*) dest;
  20141. if (dest != (void*) source || destBytesPerSample <= 4)
  20142. {
  20143. for (int i = 0; i < numSamples; ++i)
  20144. {
  20145. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20146. intData += destBytesPerSample;
  20147. }
  20148. }
  20149. else
  20150. {
  20151. intData += destBytesPerSample * numSamples;
  20152. for (int i = numSamples; --i >= 0;)
  20153. {
  20154. intData -= destBytesPerSample;
  20155. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20156. }
  20157. }
  20158. }
  20159. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20160. {
  20161. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20162. char* d = (char*) dest;
  20163. for (int i = 0; i < numSamples; ++i)
  20164. {
  20165. *(float*) d = source[i];
  20166. #if JUCE_BIG_ENDIAN
  20167. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20168. #endif
  20169. d += destBytesPerSample;
  20170. }
  20171. }
  20172. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20173. {
  20174. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20175. char* d = (char*) dest;
  20176. for (int i = 0; i < numSamples; ++i)
  20177. {
  20178. *(float*) d = source[i];
  20179. #if JUCE_LITTLE_ENDIAN
  20180. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20181. #endif
  20182. d += destBytesPerSample;
  20183. }
  20184. }
  20185. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20186. {
  20187. const float scale = 1.0f / 0x7fff;
  20188. const char* intData = (const char*) source;
  20189. if (source != (void*) dest || srcBytesPerSample >= 4)
  20190. {
  20191. for (int i = 0; i < numSamples; ++i)
  20192. {
  20193. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20194. intData += srcBytesPerSample;
  20195. }
  20196. }
  20197. else
  20198. {
  20199. intData += srcBytesPerSample * numSamples;
  20200. for (int i = numSamples; --i >= 0;)
  20201. {
  20202. intData -= srcBytesPerSample;
  20203. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20204. }
  20205. }
  20206. }
  20207. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20208. {
  20209. const float scale = 1.0f / 0x7fff;
  20210. const char* intData = (const char*) source;
  20211. if (source != (void*) dest || srcBytesPerSample >= 4)
  20212. {
  20213. for (int i = 0; i < numSamples; ++i)
  20214. {
  20215. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20216. intData += srcBytesPerSample;
  20217. }
  20218. }
  20219. else
  20220. {
  20221. intData += srcBytesPerSample * numSamples;
  20222. for (int i = numSamples; --i >= 0;)
  20223. {
  20224. intData -= srcBytesPerSample;
  20225. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20226. }
  20227. }
  20228. }
  20229. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20230. {
  20231. const float scale = 1.0f / 0x7fffff;
  20232. const char* intData = (const char*) source;
  20233. if (source != (void*) dest || srcBytesPerSample >= 4)
  20234. {
  20235. for (int i = 0; i < numSamples; ++i)
  20236. {
  20237. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20238. intData += srcBytesPerSample;
  20239. }
  20240. }
  20241. else
  20242. {
  20243. intData += srcBytesPerSample * numSamples;
  20244. for (int i = numSamples; --i >= 0;)
  20245. {
  20246. intData -= srcBytesPerSample;
  20247. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20248. }
  20249. }
  20250. }
  20251. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20252. {
  20253. const float scale = 1.0f / 0x7fffff;
  20254. const char* intData = (const char*) source;
  20255. if (source != (void*) dest || srcBytesPerSample >= 4)
  20256. {
  20257. for (int i = 0; i < numSamples; ++i)
  20258. {
  20259. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20260. intData += srcBytesPerSample;
  20261. }
  20262. }
  20263. else
  20264. {
  20265. intData += srcBytesPerSample * numSamples;
  20266. for (int i = numSamples; --i >= 0;)
  20267. {
  20268. intData -= srcBytesPerSample;
  20269. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20270. }
  20271. }
  20272. }
  20273. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20274. {
  20275. const float scale = 1.0f / 0x7fffffff;
  20276. const char* intData = (const char*) source;
  20277. if (source != (void*) dest || srcBytesPerSample >= 4)
  20278. {
  20279. for (int i = 0; i < numSamples; ++i)
  20280. {
  20281. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20282. intData += srcBytesPerSample;
  20283. }
  20284. }
  20285. else
  20286. {
  20287. intData += srcBytesPerSample * numSamples;
  20288. for (int i = numSamples; --i >= 0;)
  20289. {
  20290. intData -= srcBytesPerSample;
  20291. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20292. }
  20293. }
  20294. }
  20295. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20296. {
  20297. const float scale = 1.0f / 0x7fffffff;
  20298. const char* intData = (const char*) source;
  20299. if (source != (void*) dest || srcBytesPerSample >= 4)
  20300. {
  20301. for (int i = 0; i < numSamples; ++i)
  20302. {
  20303. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20304. intData += srcBytesPerSample;
  20305. }
  20306. }
  20307. else
  20308. {
  20309. intData += srcBytesPerSample * numSamples;
  20310. for (int i = numSamples; --i >= 0;)
  20311. {
  20312. intData -= srcBytesPerSample;
  20313. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20314. }
  20315. }
  20316. }
  20317. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20318. {
  20319. const char* s = (const char*) source;
  20320. for (int i = 0; i < numSamples; ++i)
  20321. {
  20322. dest[i] = *(float*)s;
  20323. #if JUCE_BIG_ENDIAN
  20324. uint32* const d = (uint32*) (dest + i);
  20325. *d = ByteOrder::swap (*d);
  20326. #endif
  20327. s += srcBytesPerSample;
  20328. }
  20329. }
  20330. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20331. {
  20332. const char* s = (const char*) source;
  20333. for (int i = 0; i < numSamples; ++i)
  20334. {
  20335. dest[i] = *(float*)s;
  20336. #if JUCE_LITTLE_ENDIAN
  20337. uint32* const d = (uint32*) (dest + i);
  20338. *d = ByteOrder::swap (*d);
  20339. #endif
  20340. s += srcBytesPerSample;
  20341. }
  20342. }
  20343. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20344. const float* const source,
  20345. void* const dest,
  20346. const int numSamples)
  20347. {
  20348. switch (destFormat)
  20349. {
  20350. case int16LE:
  20351. convertFloatToInt16LE (source, dest, numSamples);
  20352. break;
  20353. case int16BE:
  20354. convertFloatToInt16BE (source, dest, numSamples);
  20355. break;
  20356. case int24LE:
  20357. convertFloatToInt24LE (source, dest, numSamples);
  20358. break;
  20359. case int24BE:
  20360. convertFloatToInt24BE (source, dest, numSamples);
  20361. break;
  20362. case int32LE:
  20363. convertFloatToInt32LE (source, dest, numSamples);
  20364. break;
  20365. case int32BE:
  20366. convertFloatToInt32BE (source, dest, numSamples);
  20367. break;
  20368. case float32LE:
  20369. convertFloatToFloat32LE (source, dest, numSamples);
  20370. break;
  20371. case float32BE:
  20372. convertFloatToFloat32BE (source, dest, numSamples);
  20373. break;
  20374. default:
  20375. jassertfalse
  20376. break;
  20377. }
  20378. }
  20379. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20380. const void* const source,
  20381. float* const dest,
  20382. const int numSamples)
  20383. {
  20384. switch (sourceFormat)
  20385. {
  20386. case int16LE:
  20387. convertInt16LEToFloat (source, dest, numSamples);
  20388. break;
  20389. case int16BE:
  20390. convertInt16BEToFloat (source, dest, numSamples);
  20391. break;
  20392. case int24LE:
  20393. convertInt24LEToFloat (source, dest, numSamples);
  20394. break;
  20395. case int24BE:
  20396. convertInt24BEToFloat (source, dest, numSamples);
  20397. break;
  20398. case int32LE:
  20399. convertInt32LEToFloat (source, dest, numSamples);
  20400. break;
  20401. case int32BE:
  20402. convertInt32BEToFloat (source, dest, numSamples);
  20403. break;
  20404. case float32LE:
  20405. convertFloat32LEToFloat (source, dest, numSamples);
  20406. break;
  20407. case float32BE:
  20408. convertFloat32BEToFloat (source, dest, numSamples);
  20409. break;
  20410. default:
  20411. jassertfalse
  20412. break;
  20413. }
  20414. }
  20415. void AudioDataConverters::interleaveSamples (const float** const source,
  20416. float* const dest,
  20417. const int numSamples,
  20418. const int numChannels)
  20419. {
  20420. for (int chan = 0; chan < numChannels; ++chan)
  20421. {
  20422. int i = chan;
  20423. const float* src = source [chan];
  20424. for (int j = 0; j < numSamples; ++j)
  20425. {
  20426. dest [i] = src [j];
  20427. i += numChannels;
  20428. }
  20429. }
  20430. }
  20431. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20432. float** const dest,
  20433. const int numSamples,
  20434. const int numChannels)
  20435. {
  20436. for (int chan = 0; chan < numChannels; ++chan)
  20437. {
  20438. int i = chan;
  20439. float* dst = dest [chan];
  20440. for (int j = 0; j < numSamples; ++j)
  20441. {
  20442. dst [j] = source [i];
  20443. i += numChannels;
  20444. }
  20445. }
  20446. }
  20447. END_JUCE_NAMESPACE
  20448. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20449. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20450. BEGIN_JUCE_NAMESPACE
  20451. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20452. const int numSamples) throw()
  20453. : numChannels (numChannels_),
  20454. size (numSamples)
  20455. {
  20456. jassert (numSamples >= 0);
  20457. jassert (numChannels_ > 0);
  20458. allocateData();
  20459. }
  20460. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20461. : numChannels (other.numChannels),
  20462. size (other.size)
  20463. {
  20464. allocateData();
  20465. const size_t numBytes = size * sizeof (float);
  20466. for (int i = 0; i < numChannels; ++i)
  20467. memcpy (channels[i], other.channels[i], numBytes);
  20468. }
  20469. void AudioSampleBuffer::allocateData()
  20470. {
  20471. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20472. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20473. allocatedData.malloc (allocatedBytes);
  20474. channels = reinterpret_cast <float**> (allocatedData.getData());
  20475. float* chan = (float*) (allocatedData + channelListSize);
  20476. for (int i = 0; i < numChannels; ++i)
  20477. {
  20478. channels[i] = chan;
  20479. chan += size;
  20480. }
  20481. channels [numChannels] = 0;
  20482. }
  20483. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20484. const int numChannels_,
  20485. const int numSamples) throw()
  20486. : numChannels (numChannels_),
  20487. size (numSamples),
  20488. allocatedBytes (0)
  20489. {
  20490. jassert (numChannels_ > 0);
  20491. allocateChannels (dataToReferTo);
  20492. }
  20493. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20494. const int newNumChannels,
  20495. const int newNumSamples) throw()
  20496. {
  20497. jassert (newNumChannels > 0);
  20498. allocatedBytes = 0;
  20499. allocatedData.free();
  20500. numChannels = newNumChannels;
  20501. size = newNumSamples;
  20502. allocateChannels (dataToReferTo);
  20503. }
  20504. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20505. {
  20506. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20507. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20508. {
  20509. channels = static_cast <float**> (preallocatedChannelSpace);
  20510. }
  20511. else
  20512. {
  20513. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20514. channels = reinterpret_cast <float**> (allocatedData.getData());
  20515. }
  20516. for (int i = 0; i < numChannels; ++i)
  20517. {
  20518. // you have to pass in the same number of valid pointers as numChannels
  20519. jassert (dataToReferTo[i] != 0);
  20520. channels[i] = dataToReferTo[i];
  20521. }
  20522. channels [numChannels] = 0;
  20523. }
  20524. AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20525. {
  20526. if (this != &other)
  20527. {
  20528. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20529. const size_t numBytes = size * sizeof (float);
  20530. for (int i = 0; i < numChannels; ++i)
  20531. memcpy (channels[i], other.channels[i], numBytes);
  20532. }
  20533. return *this;
  20534. }
  20535. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20536. {
  20537. }
  20538. void AudioSampleBuffer::setSize (const int newNumChannels,
  20539. const int newNumSamples,
  20540. const bool keepExistingContent,
  20541. const bool clearExtraSpace,
  20542. const bool avoidReallocating) throw()
  20543. {
  20544. jassert (newNumChannels > 0);
  20545. if (newNumSamples != size || newNumChannels != numChannels)
  20546. {
  20547. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20548. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20549. if (keepExistingContent)
  20550. {
  20551. HeapBlock <char> newData;
  20552. newData.allocate (newTotalBytes, clearExtraSpace);
  20553. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20554. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20555. float** const newChannels = reinterpret_cast <float**> (newData.getData());
  20556. float* newChan = reinterpret_cast <float*> (newData + channelListSize);
  20557. for (int i = 0; i < numChansToCopy; ++i)
  20558. {
  20559. memcpy (newChan, channels[i], numBytesToCopy);
  20560. newChannels[i] = newChan;
  20561. newChan += newNumSamples;
  20562. }
  20563. allocatedData.swapWith (newData);
  20564. allocatedBytes = (int) newTotalBytes;
  20565. channels = newChannels;
  20566. }
  20567. else
  20568. {
  20569. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20570. {
  20571. if (clearExtraSpace)
  20572. zeromem (allocatedData, newTotalBytes);
  20573. }
  20574. else
  20575. {
  20576. allocatedBytes = newTotalBytes;
  20577. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20578. channels = reinterpret_cast <float**> (allocatedData.getData());
  20579. }
  20580. float* chan = reinterpret_cast <float*> (allocatedData + channelListSize);
  20581. for (int i = 0; i < newNumChannels; ++i)
  20582. {
  20583. channels[i] = chan;
  20584. chan += newNumSamples;
  20585. }
  20586. }
  20587. channels [newNumChannels] = 0;
  20588. size = newNumSamples;
  20589. numChannels = newNumChannels;
  20590. }
  20591. }
  20592. void AudioSampleBuffer::clear() throw()
  20593. {
  20594. for (int i = 0; i < numChannels; ++i)
  20595. zeromem (channels[i], size * sizeof (float));
  20596. }
  20597. void AudioSampleBuffer::clear (const int startSample,
  20598. const int numSamples) throw()
  20599. {
  20600. jassert (startSample >= 0 && startSample + numSamples <= size);
  20601. for (int i = 0; i < numChannels; ++i)
  20602. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20603. }
  20604. void AudioSampleBuffer::clear (const int channel,
  20605. const int startSample,
  20606. const int numSamples) throw()
  20607. {
  20608. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20609. jassert (startSample >= 0 && startSample + numSamples <= size);
  20610. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20611. }
  20612. void AudioSampleBuffer::applyGain (const int channel,
  20613. const int startSample,
  20614. int numSamples,
  20615. const float gain) throw()
  20616. {
  20617. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20618. jassert (startSample >= 0 && startSample + numSamples <= size);
  20619. if (gain != 1.0f)
  20620. {
  20621. float* d = channels [channel] + startSample;
  20622. if (gain == 0.0f)
  20623. {
  20624. zeromem (d, sizeof (float) * numSamples);
  20625. }
  20626. else
  20627. {
  20628. while (--numSamples >= 0)
  20629. *d++ *= gain;
  20630. }
  20631. }
  20632. }
  20633. void AudioSampleBuffer::applyGainRamp (const int channel,
  20634. const int startSample,
  20635. int numSamples,
  20636. float startGain,
  20637. float endGain) throw()
  20638. {
  20639. if (startGain == endGain)
  20640. {
  20641. applyGain (channel, startSample, numSamples, startGain);
  20642. }
  20643. else
  20644. {
  20645. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20646. jassert (startSample >= 0 && startSample + numSamples <= size);
  20647. const float increment = (endGain - startGain) / numSamples;
  20648. float* d = channels [channel] + startSample;
  20649. while (--numSamples >= 0)
  20650. {
  20651. *d++ *= startGain;
  20652. startGain += increment;
  20653. }
  20654. }
  20655. }
  20656. void AudioSampleBuffer::applyGain (const int startSample,
  20657. const int numSamples,
  20658. const float gain) throw()
  20659. {
  20660. for (int i = 0; i < numChannels; ++i)
  20661. applyGain (i, startSample, numSamples, gain);
  20662. }
  20663. void AudioSampleBuffer::addFrom (const int destChannel,
  20664. const int destStartSample,
  20665. const AudioSampleBuffer& source,
  20666. const int sourceChannel,
  20667. const int sourceStartSample,
  20668. int numSamples,
  20669. const float gain) throw()
  20670. {
  20671. jassert (&source != this || sourceChannel != destChannel);
  20672. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20673. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20674. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20675. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20676. if (gain != 0.0f && numSamples > 0)
  20677. {
  20678. float* d = channels [destChannel] + destStartSample;
  20679. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20680. if (gain != 1.0f)
  20681. {
  20682. while (--numSamples >= 0)
  20683. *d++ += gain * *s++;
  20684. }
  20685. else
  20686. {
  20687. while (--numSamples >= 0)
  20688. *d++ += *s++;
  20689. }
  20690. }
  20691. }
  20692. void AudioSampleBuffer::addFrom (const int destChannel,
  20693. const int destStartSample,
  20694. const float* source,
  20695. int numSamples,
  20696. const float gain) throw()
  20697. {
  20698. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20699. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20700. jassert (source != 0);
  20701. if (gain != 0.0f && numSamples > 0)
  20702. {
  20703. float* d = channels [destChannel] + destStartSample;
  20704. if (gain != 1.0f)
  20705. {
  20706. while (--numSamples >= 0)
  20707. *d++ += gain * *source++;
  20708. }
  20709. else
  20710. {
  20711. while (--numSamples >= 0)
  20712. *d++ += *source++;
  20713. }
  20714. }
  20715. }
  20716. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20717. const int destStartSample,
  20718. const float* source,
  20719. int numSamples,
  20720. float startGain,
  20721. const float endGain) throw()
  20722. {
  20723. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20724. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20725. jassert (source != 0);
  20726. if (startGain == endGain)
  20727. {
  20728. addFrom (destChannel,
  20729. destStartSample,
  20730. source,
  20731. numSamples,
  20732. startGain);
  20733. }
  20734. else
  20735. {
  20736. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20737. {
  20738. const float increment = (endGain - startGain) / numSamples;
  20739. float* d = channels [destChannel] + destStartSample;
  20740. while (--numSamples >= 0)
  20741. {
  20742. *d++ += startGain * *source++;
  20743. startGain += increment;
  20744. }
  20745. }
  20746. }
  20747. }
  20748. void AudioSampleBuffer::copyFrom (const int destChannel,
  20749. const int destStartSample,
  20750. const AudioSampleBuffer& source,
  20751. const int sourceChannel,
  20752. const int sourceStartSample,
  20753. int numSamples) throw()
  20754. {
  20755. jassert (&source != this || sourceChannel != destChannel);
  20756. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20757. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20758. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20759. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20760. if (numSamples > 0)
  20761. {
  20762. memcpy (channels [destChannel] + destStartSample,
  20763. source.channels [sourceChannel] + sourceStartSample,
  20764. sizeof (float) * numSamples);
  20765. }
  20766. }
  20767. void AudioSampleBuffer::copyFrom (const int destChannel,
  20768. const int destStartSample,
  20769. const float* source,
  20770. int numSamples) throw()
  20771. {
  20772. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20773. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20774. jassert (source != 0);
  20775. if (numSamples > 0)
  20776. {
  20777. memcpy (channels [destChannel] + destStartSample,
  20778. source,
  20779. sizeof (float) * numSamples);
  20780. }
  20781. }
  20782. void AudioSampleBuffer::copyFrom (const int destChannel,
  20783. const int destStartSample,
  20784. const float* source,
  20785. int numSamples,
  20786. const float gain) throw()
  20787. {
  20788. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20789. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20790. jassert (source != 0);
  20791. if (numSamples > 0)
  20792. {
  20793. float* d = channels [destChannel] + destStartSample;
  20794. if (gain != 1.0f)
  20795. {
  20796. if (gain == 0)
  20797. {
  20798. zeromem (d, sizeof (float) * numSamples);
  20799. }
  20800. else
  20801. {
  20802. while (--numSamples >= 0)
  20803. *d++ = gain * *source++;
  20804. }
  20805. }
  20806. else
  20807. {
  20808. memcpy (d, source, sizeof (float) * numSamples);
  20809. }
  20810. }
  20811. }
  20812. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  20813. const int destStartSample,
  20814. const float* source,
  20815. int numSamples,
  20816. float startGain,
  20817. float endGain) throw()
  20818. {
  20819. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20820. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20821. jassert (source != 0);
  20822. if (startGain == endGain)
  20823. {
  20824. copyFrom (destChannel,
  20825. destStartSample,
  20826. source,
  20827. numSamples,
  20828. startGain);
  20829. }
  20830. else
  20831. {
  20832. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20833. {
  20834. const float increment = (endGain - startGain) / numSamples;
  20835. float* d = channels [destChannel] + destStartSample;
  20836. while (--numSamples >= 0)
  20837. {
  20838. *d++ = startGain * *source++;
  20839. startGain += increment;
  20840. }
  20841. }
  20842. }
  20843. }
  20844. void AudioSampleBuffer::findMinMax (const int channel,
  20845. const int startSample,
  20846. int numSamples,
  20847. float& minVal,
  20848. float& maxVal) const throw()
  20849. {
  20850. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20851. jassert (startSample >= 0 && startSample + numSamples <= size);
  20852. if (numSamples <= 0)
  20853. {
  20854. minVal = 0.0f;
  20855. maxVal = 0.0f;
  20856. }
  20857. else
  20858. {
  20859. const float* d = channels [channel] + startSample;
  20860. float mn = *d++;
  20861. float mx = mn;
  20862. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  20863. {
  20864. const float samp = *d++;
  20865. if (samp > mx)
  20866. mx = samp;
  20867. if (samp < mn)
  20868. mn = samp;
  20869. }
  20870. maxVal = mx;
  20871. minVal = mn;
  20872. }
  20873. }
  20874. float AudioSampleBuffer::getMagnitude (const int channel,
  20875. const int startSample,
  20876. const int numSamples) const throw()
  20877. {
  20878. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20879. jassert (startSample >= 0 && startSample + numSamples <= size);
  20880. float mn, mx;
  20881. findMinMax (channel, startSample, numSamples, mn, mx);
  20882. return jmax (mn, -mn, mx, -mx);
  20883. }
  20884. float AudioSampleBuffer::getMagnitude (const int startSample,
  20885. const int numSamples) const throw()
  20886. {
  20887. float mag = 0.0f;
  20888. for (int i = 0; i < numChannels; ++i)
  20889. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  20890. return mag;
  20891. }
  20892. float AudioSampleBuffer::getRMSLevel (const int channel,
  20893. const int startSample,
  20894. const int numSamples) const throw()
  20895. {
  20896. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20897. jassert (startSample >= 0 && startSample + numSamples <= size);
  20898. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  20899. return 0.0f;
  20900. const float* const data = channels [channel] + startSample;
  20901. double sum = 0.0;
  20902. for (int i = 0; i < numSamples; ++i)
  20903. {
  20904. const float sample = data [i];
  20905. sum += sample * sample;
  20906. }
  20907. return (float) sqrt (sum / numSamples);
  20908. }
  20909. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  20910. const int startSample,
  20911. const int numSamples,
  20912. const int readerStartSample,
  20913. const bool useLeftChan,
  20914. const bool useRightChan) throw()
  20915. {
  20916. jassert (reader != 0);
  20917. jassert (startSample >= 0 && startSample + numSamples <= size);
  20918. if (numSamples > 0)
  20919. {
  20920. int* chans[3];
  20921. if (useLeftChan == useRightChan)
  20922. {
  20923. chans[0] = (int*) getSampleData (0, startSample);
  20924. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  20925. }
  20926. else if (useLeftChan || (reader->numChannels == 1))
  20927. {
  20928. chans[0] = (int*) getSampleData (0, startSample);
  20929. chans[1] = 0;
  20930. }
  20931. else if (useRightChan)
  20932. {
  20933. chans[0] = 0;
  20934. chans[1] = (int*) getSampleData (0, startSample);
  20935. }
  20936. chans[2] = 0;
  20937. reader->read (chans, 2, readerStartSample, numSamples, true);
  20938. if (! reader->usesFloatingPointData)
  20939. {
  20940. for (int j = 0; j < 2; ++j)
  20941. {
  20942. float* const d = (float*) (chans[j]);
  20943. if (d != 0)
  20944. {
  20945. const float multiplier = 1.0f / 0x7fffffff;
  20946. for (int i = 0; i < numSamples; ++i)
  20947. d[i] = *(int*)(d + i) * multiplier;
  20948. }
  20949. }
  20950. }
  20951. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  20952. {
  20953. // if this is a stereo buffer and the source was mono, dupe the first channel..
  20954. memcpy (getSampleData (1, startSample),
  20955. getSampleData (0, startSample),
  20956. sizeof (float) * numSamples);
  20957. }
  20958. }
  20959. }
  20960. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  20961. const int startSample,
  20962. const int numSamples) const throw()
  20963. {
  20964. jassert (startSample >= 0 && startSample + numSamples <= size);
  20965. if (numSamples > 0)
  20966. {
  20967. int* chans [3];
  20968. if (writer->isFloatingPoint())
  20969. {
  20970. chans[0] = (int*) getSampleData (0, startSample);
  20971. if (numChannels > 1)
  20972. chans[1] = (int*) getSampleData (1, startSample);
  20973. else
  20974. chans[1] = 0;
  20975. chans[2] = 0;
  20976. writer->write ((const int**) chans, numSamples);
  20977. }
  20978. else
  20979. {
  20980. HeapBlock <int> tempBuffer (numSamples * 2);
  20981. chans[0] = tempBuffer;
  20982. if (numChannels > 1)
  20983. chans[1] = chans[0] + numSamples;
  20984. else
  20985. chans[1] = 0;
  20986. chans[2] = 0;
  20987. for (int j = 0; j < 2; ++j)
  20988. {
  20989. int* const dest = chans[j];
  20990. if (dest != 0)
  20991. {
  20992. const float* const src = channels [j] + startSample;
  20993. for (int i = 0; i < numSamples; ++i)
  20994. {
  20995. const double samp = src[i];
  20996. if (samp <= -1.0)
  20997. dest[i] = std::numeric_limits<int>::min();
  20998. else if (samp >= 1.0)
  20999. dest[i] = std::numeric_limits<int>::max();
  21000. else
  21001. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  21002. }
  21003. }
  21004. }
  21005. writer->write ((const int**) chans, numSamples);
  21006. }
  21007. }
  21008. }
  21009. END_JUCE_NAMESPACE
  21010. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  21011. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  21012. BEGIN_JUCE_NAMESPACE
  21013. IIRFilter::IIRFilter() throw()
  21014. : active (false)
  21015. {
  21016. reset();
  21017. }
  21018. IIRFilter::IIRFilter (const IIRFilter& other) throw()
  21019. : active (other.active)
  21020. {
  21021. const ScopedLock sl (other.processLock);
  21022. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21023. reset();
  21024. }
  21025. IIRFilter::~IIRFilter() throw()
  21026. {
  21027. }
  21028. void IIRFilter::reset() throw()
  21029. {
  21030. const ScopedLock sl (processLock);
  21031. x1 = 0;
  21032. x2 = 0;
  21033. y1 = 0;
  21034. y2 = 0;
  21035. }
  21036. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21037. {
  21038. float out = coefficients[0] * in
  21039. + coefficients[1] * x1
  21040. + coefficients[2] * x2
  21041. - coefficients[4] * y1
  21042. - coefficients[5] * y2;
  21043. #if JUCE_INTEL
  21044. if (! (out < -1.0e-8 || out > 1.0e-8))
  21045. out = 0;
  21046. #endif
  21047. x2 = x1;
  21048. x1 = in;
  21049. y2 = y1;
  21050. y1 = out;
  21051. return out;
  21052. }
  21053. void IIRFilter::processSamples (float* const samples,
  21054. const int numSamples) throw()
  21055. {
  21056. const ScopedLock sl (processLock);
  21057. if (active)
  21058. {
  21059. for (int i = 0; i < numSamples; ++i)
  21060. {
  21061. const float in = samples[i];
  21062. float out = coefficients[0] * in
  21063. + coefficients[1] * x1
  21064. + coefficients[2] * x2
  21065. - coefficients[4] * y1
  21066. - coefficients[5] * y2;
  21067. #if JUCE_INTEL
  21068. if (! (out < -1.0e-8 || out > 1.0e-8))
  21069. out = 0;
  21070. #endif
  21071. x2 = x1;
  21072. x1 = in;
  21073. y2 = y1;
  21074. y1 = out;
  21075. samples[i] = out;
  21076. }
  21077. }
  21078. }
  21079. void IIRFilter::makeLowPass (const double sampleRate,
  21080. const double frequency) throw()
  21081. {
  21082. jassert (sampleRate > 0);
  21083. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21084. const double nSquared = n * n;
  21085. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21086. setCoefficients (c1,
  21087. c1 * 2.0f,
  21088. c1,
  21089. 1.0,
  21090. c1 * 2.0 * (1.0 - nSquared),
  21091. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21092. }
  21093. void IIRFilter::makeHighPass (const double sampleRate,
  21094. const double frequency) throw()
  21095. {
  21096. const double n = tan (double_Pi * frequency / sampleRate);
  21097. const double nSquared = n * n;
  21098. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21099. setCoefficients (c1,
  21100. c1 * -2.0f,
  21101. c1,
  21102. 1.0,
  21103. c1 * 2.0 * (nSquared - 1.0),
  21104. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21105. }
  21106. void IIRFilter::makeLowShelf (const double sampleRate,
  21107. const double cutOffFrequency,
  21108. const double Q,
  21109. const float gainFactor) throw()
  21110. {
  21111. jassert (sampleRate > 0);
  21112. jassert (Q > 0);
  21113. const double A = jmax (0.0f, gainFactor);
  21114. const double aminus1 = A - 1.0;
  21115. const double aplus1 = A + 1.0;
  21116. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21117. const double coso = cos (omega);
  21118. const double beta = sin (omega) * sqrt (A) / Q;
  21119. const double aminus1TimesCoso = aminus1 * coso;
  21120. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21121. A * 2.0 * (aminus1 - aplus1 * coso),
  21122. A * (aplus1 - aminus1TimesCoso - beta),
  21123. aplus1 + aminus1TimesCoso + beta,
  21124. -2.0 * (aminus1 + aplus1 * coso),
  21125. aplus1 + aminus1TimesCoso - beta);
  21126. }
  21127. void IIRFilter::makeHighShelf (const double sampleRate,
  21128. const double cutOffFrequency,
  21129. const double Q,
  21130. const float gainFactor) throw()
  21131. {
  21132. jassert (sampleRate > 0);
  21133. jassert (Q > 0);
  21134. const double A = jmax (0.0f, gainFactor);
  21135. const double aminus1 = A - 1.0;
  21136. const double aplus1 = A + 1.0;
  21137. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21138. const double coso = cos (omega);
  21139. const double beta = sin (omega) * sqrt (A) / Q;
  21140. const double aminus1TimesCoso = aminus1 * coso;
  21141. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21142. A * -2.0 * (aminus1 + aplus1 * coso),
  21143. A * (aplus1 + aminus1TimesCoso - beta),
  21144. aplus1 - aminus1TimesCoso + beta,
  21145. 2.0 * (aminus1 - aplus1 * coso),
  21146. aplus1 - aminus1TimesCoso - beta);
  21147. }
  21148. void IIRFilter::makeBandPass (const double sampleRate,
  21149. const double centreFrequency,
  21150. const double Q,
  21151. const float gainFactor) throw()
  21152. {
  21153. jassert (sampleRate > 0);
  21154. jassert (Q > 0);
  21155. const double A = jmax (0.0f, gainFactor);
  21156. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21157. const double alpha = 0.5 * sin (omega) / Q;
  21158. const double c2 = -2.0 * cos (omega);
  21159. const double alphaTimesA = alpha * A;
  21160. const double alphaOverA = alpha / A;
  21161. setCoefficients (1.0 + alphaTimesA,
  21162. c2,
  21163. 1.0 - alphaTimesA,
  21164. 1.0 + alphaOverA,
  21165. c2,
  21166. 1.0 - alphaOverA);
  21167. }
  21168. void IIRFilter::makeInactive() throw()
  21169. {
  21170. const ScopedLock sl (processLock);
  21171. active = false;
  21172. }
  21173. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21174. {
  21175. const ScopedLock sl (processLock);
  21176. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21177. active = other.active;
  21178. }
  21179. void IIRFilter::setCoefficients (double c1,
  21180. double c2,
  21181. double c3,
  21182. double c4,
  21183. double c5,
  21184. double c6) throw()
  21185. {
  21186. const double a = 1.0 / c4;
  21187. c1 *= a;
  21188. c2 *= a;
  21189. c3 *= a;
  21190. c5 *= a;
  21191. c6 *= a;
  21192. const ScopedLock sl (processLock);
  21193. coefficients[0] = (float) c1;
  21194. coefficients[1] = (float) c2;
  21195. coefficients[2] = (float) c3;
  21196. coefficients[3] = (float) c4;
  21197. coefficients[4] = (float) c5;
  21198. coefficients[5] = (float) c6;
  21199. active = true;
  21200. }
  21201. END_JUCE_NAMESPACE
  21202. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21203. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21204. BEGIN_JUCE_NAMESPACE
  21205. MidiBuffer::MidiBuffer() throw()
  21206. : bytesUsed (0)
  21207. {
  21208. }
  21209. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21210. : bytesUsed (0)
  21211. {
  21212. addEvent (message, 0);
  21213. }
  21214. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21215. : data (other.data),
  21216. bytesUsed (other.bytesUsed)
  21217. {
  21218. }
  21219. MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21220. {
  21221. bytesUsed = other.bytesUsed;
  21222. data = other.data;
  21223. return *this;
  21224. }
  21225. void MidiBuffer::swap (MidiBuffer& other)
  21226. {
  21227. data.swapWith (other.data);
  21228. swapVariables <int> (bytesUsed, other.bytesUsed);
  21229. }
  21230. MidiBuffer::~MidiBuffer() throw()
  21231. {
  21232. }
  21233. void MidiBuffer::clear() throw()
  21234. {
  21235. bytesUsed = 0;
  21236. }
  21237. void MidiBuffer::clear (const int startSample,
  21238. const int numSamples) throw()
  21239. {
  21240. uint8* const start = findEventAfter (getData(), startSample - 1);
  21241. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21242. if (end > start)
  21243. {
  21244. const int bytesToMove = bytesUsed - (int) (end - getData());
  21245. if (bytesToMove > 0)
  21246. memmove (start, end, bytesToMove);
  21247. bytesUsed -= (int) (end - start);
  21248. }
  21249. }
  21250. void MidiBuffer::addEvent (const MidiMessage& m,
  21251. const int sampleNumber) throw()
  21252. {
  21253. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21254. }
  21255. static int findActualEventLength (const uint8* const data,
  21256. const int maxBytes) throw()
  21257. {
  21258. unsigned int byte = (unsigned int) *data;
  21259. int size = 0;
  21260. if (byte == 0xf0 || byte == 0xf7)
  21261. {
  21262. const uint8* d = data + 1;
  21263. while (d < data + maxBytes)
  21264. if (*d++ == 0xf7)
  21265. break;
  21266. size = (int) (d - data);
  21267. }
  21268. else if (byte == 0xff)
  21269. {
  21270. int n;
  21271. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21272. size = jmin (maxBytes, n + 2 + bytesLeft);
  21273. }
  21274. else if (byte >= 0x80)
  21275. {
  21276. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21277. }
  21278. return size;
  21279. }
  21280. void MidiBuffer::addEvent (const uint8* const newData,
  21281. const int maxBytes,
  21282. const int sampleNumber) throw()
  21283. {
  21284. const int numBytes = findActualEventLength (newData, maxBytes);
  21285. if (numBytes > 0)
  21286. {
  21287. int spaceNeeded = bytesUsed + numBytes + 6;
  21288. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21289. uint8* d = findEventAfter (getData(), sampleNumber);
  21290. const int bytesToMove = bytesUsed - (int) (d - getData());
  21291. if (bytesToMove > 0)
  21292. memmove (d + numBytes + 6,
  21293. d,
  21294. bytesToMove);
  21295. *(int*) d = sampleNumber;
  21296. d += 4;
  21297. *(uint16*) d = (uint16) numBytes;
  21298. d += 2;
  21299. memcpy (d, newData, numBytes);
  21300. bytesUsed += numBytes + 6;
  21301. }
  21302. }
  21303. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21304. const int startSample,
  21305. const int numSamples,
  21306. const int sampleDeltaToAdd) throw()
  21307. {
  21308. Iterator i (otherBuffer);
  21309. i.setNextSamplePosition (startSample);
  21310. const uint8* eventData;
  21311. int eventSize, position;
  21312. while (i.getNextEvent (eventData, eventSize, position)
  21313. && (position < startSample + numSamples || numSamples < 0))
  21314. {
  21315. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21316. }
  21317. }
  21318. bool MidiBuffer::isEmpty() const throw()
  21319. {
  21320. return bytesUsed == 0;
  21321. }
  21322. int MidiBuffer::getNumEvents() const throw()
  21323. {
  21324. int n = 0;
  21325. const uint8* d = getData();
  21326. const uint8* const end = d + bytesUsed;
  21327. while (d < end)
  21328. {
  21329. d += 4;
  21330. d += 2 + *(const uint16*) d;
  21331. ++n;
  21332. }
  21333. return n;
  21334. }
  21335. int MidiBuffer::getFirstEventTime() const throw()
  21336. {
  21337. return (bytesUsed > 0) ? *reinterpret_cast <const int*> (data.getData()) : 0;
  21338. }
  21339. int MidiBuffer::getLastEventTime() const throw()
  21340. {
  21341. if (bytesUsed == 0)
  21342. return 0;
  21343. const uint8* d = getData();
  21344. const uint8* const endData = d + bytesUsed;
  21345. for (;;)
  21346. {
  21347. const uint8* nextOne = d + 6 + * (const uint16*) (d + 4);
  21348. if (nextOne >= endData)
  21349. return *(const int*) d;
  21350. d = nextOne;
  21351. }
  21352. }
  21353. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21354. {
  21355. const uint8* const endData = getData() + bytesUsed;
  21356. while (d < endData && *(int*) d <= samplePosition)
  21357. {
  21358. d += 4;
  21359. d += 2 + *(uint16*) d;
  21360. }
  21361. return d;
  21362. }
  21363. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21364. : buffer (buffer_),
  21365. data (buffer_.getData())
  21366. {
  21367. }
  21368. MidiBuffer::Iterator::~Iterator() throw()
  21369. {
  21370. }
  21371. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21372. {
  21373. data = buffer.getData();
  21374. const uint8* dataEnd = data + buffer.bytesUsed;
  21375. while (data < dataEnd && *reinterpret_cast<const int*> (data) < samplePosition)
  21376. {
  21377. data += 4;
  21378. data += 2 + *(uint16*) data;
  21379. }
  21380. }
  21381. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData,
  21382. int& numBytes,
  21383. int& samplePosition) throw()
  21384. {
  21385. if (data >= buffer.getData() + buffer.bytesUsed)
  21386. return false;
  21387. samplePosition = *(int*) data;
  21388. data += 4;
  21389. numBytes = *(uint16*) data;
  21390. data += 2;
  21391. midiData = data;
  21392. data += numBytes;
  21393. return true;
  21394. }
  21395. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result,
  21396. int& samplePosition) throw()
  21397. {
  21398. if (data >= buffer.getData() + buffer.bytesUsed)
  21399. return false;
  21400. samplePosition = *reinterpret_cast <const int*> (data);
  21401. data += 4;
  21402. const int numBytes = *reinterpret_cast <const uint16*> (data);
  21403. data += 2;
  21404. result = MidiMessage (data, numBytes, samplePosition);
  21405. data += numBytes;
  21406. return true;
  21407. }
  21408. END_JUCE_NAMESPACE
  21409. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21410. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21411. BEGIN_JUCE_NAMESPACE
  21412. namespace MidiFileHelpers
  21413. {
  21414. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21415. {
  21416. unsigned int buffer = v & 0x7F;
  21417. while ((v >>= 7) != 0)
  21418. {
  21419. buffer <<= 8;
  21420. buffer |= ((v & 0x7F) | 0x80);
  21421. }
  21422. for (;;)
  21423. {
  21424. out.writeByte ((char) buffer);
  21425. if (buffer & 0x80)
  21426. buffer >>= 8;
  21427. else
  21428. break;
  21429. }
  21430. }
  21431. static bool parseMidiHeader (const char* &data, short& timeFormat, short& fileType, short& numberOfTracks) throw()
  21432. {
  21433. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21434. data += 4;
  21435. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21436. {
  21437. bool ok = false;
  21438. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21439. {
  21440. for (int i = 0; i < 8; ++i)
  21441. {
  21442. ch = ByteOrder::bigEndianInt (data);
  21443. data += 4;
  21444. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21445. {
  21446. ok = true;
  21447. break;
  21448. }
  21449. }
  21450. }
  21451. if (! ok)
  21452. return false;
  21453. }
  21454. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21455. data += 4;
  21456. fileType = (short) ByteOrder::bigEndianShort (data);
  21457. data += 2;
  21458. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21459. data += 2;
  21460. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21461. data += 2;
  21462. bytesRemaining -= 6;
  21463. data += bytesRemaining;
  21464. return true;
  21465. }
  21466. static double convertTicksToSeconds (const double time,
  21467. const MidiMessageSequence& tempoEvents,
  21468. const int timeFormat)
  21469. {
  21470. if (timeFormat > 0)
  21471. {
  21472. int numer = 4, denom = 4;
  21473. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21474. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21475. double secsPerTick = 0.5 * tickLen;
  21476. const int numEvents = tempoEvents.getNumEvents();
  21477. for (int i = 0; i < numEvents; ++i)
  21478. {
  21479. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21480. if (time <= m.getTimeStamp())
  21481. break;
  21482. if (timeFormat > 0)
  21483. {
  21484. correctedTempoTime = correctedTempoTime
  21485. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21486. }
  21487. else
  21488. {
  21489. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21490. }
  21491. tempoTime = m.getTimeStamp();
  21492. if (m.isTempoMetaEvent())
  21493. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21494. else if (m.isTimeSignatureMetaEvent())
  21495. m.getTimeSignatureInfo (numer, denom);
  21496. while (i + 1 < numEvents)
  21497. {
  21498. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21499. if (m2.getTimeStamp() == tempoTime)
  21500. {
  21501. ++i;
  21502. if (m2.isTempoMetaEvent())
  21503. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21504. else if (m2.isTimeSignatureMetaEvent())
  21505. m2.getTimeSignatureInfo (numer, denom);
  21506. }
  21507. else
  21508. {
  21509. break;
  21510. }
  21511. }
  21512. }
  21513. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21514. }
  21515. else
  21516. {
  21517. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21518. }
  21519. }
  21520. }
  21521. MidiFile::MidiFile() throw()
  21522. : timeFormat ((short) (unsigned short) 0xe728)
  21523. {
  21524. }
  21525. MidiFile::~MidiFile() throw()
  21526. {
  21527. clear();
  21528. }
  21529. void MidiFile::clear() throw()
  21530. {
  21531. tracks.clear();
  21532. }
  21533. int MidiFile::getNumTracks() const throw()
  21534. {
  21535. return tracks.size();
  21536. }
  21537. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21538. {
  21539. return tracks [index];
  21540. }
  21541. void MidiFile::addTrack (const MidiMessageSequence& trackSequence) throw()
  21542. {
  21543. tracks.add (new MidiMessageSequence (trackSequence));
  21544. }
  21545. short MidiFile::getTimeFormat() const throw()
  21546. {
  21547. return timeFormat;
  21548. }
  21549. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21550. {
  21551. timeFormat = (short)ticks;
  21552. }
  21553. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21554. const int subframeResolution) throw()
  21555. {
  21556. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21557. }
  21558. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21559. {
  21560. for (int i = tracks.size(); --i >= 0;)
  21561. {
  21562. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21563. for (int j = 0; j < numEvents; ++j)
  21564. {
  21565. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21566. if (m.isTempoMetaEvent())
  21567. tempoChangeEvents.addEvent (m);
  21568. }
  21569. }
  21570. }
  21571. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21572. {
  21573. for (int i = tracks.size(); --i >= 0;)
  21574. {
  21575. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21576. for (int j = 0; j < numEvents; ++j)
  21577. {
  21578. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21579. if (m.isTimeSignatureMetaEvent())
  21580. timeSigEvents.addEvent (m);
  21581. }
  21582. }
  21583. }
  21584. double MidiFile::getLastTimestamp() const
  21585. {
  21586. double t = 0.0;
  21587. for (int i = tracks.size(); --i >= 0;)
  21588. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21589. return t;
  21590. }
  21591. bool MidiFile::readFrom (InputStream& sourceStream)
  21592. {
  21593. clear();
  21594. MemoryBlock data;
  21595. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21596. // (put a sanity-check on the file size, as midi files are generally small)
  21597. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21598. {
  21599. size_t size = data.getSize();
  21600. const char* d = (char*) data.getData();
  21601. short fileType, expectedTracks;
  21602. if (size > 16 && MidiFileHelpers::parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21603. {
  21604. size -= (int) (d - (char*) data.getData());
  21605. int track = 0;
  21606. while (size > 0 && track < expectedTracks)
  21607. {
  21608. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21609. d += 4;
  21610. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21611. d += 4;
  21612. if (chunkSize <= 0)
  21613. break;
  21614. if (size < 0)
  21615. return false;
  21616. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21617. {
  21618. readNextTrack (d, chunkSize);
  21619. }
  21620. size -= chunkSize + 8;
  21621. d += chunkSize;
  21622. ++track;
  21623. }
  21624. return true;
  21625. }
  21626. }
  21627. return false;
  21628. }
  21629. // a comparator that puts all the note-offs before note-ons that have the same time
  21630. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21631. const MidiMessageSequence::MidiEventHolder* const second) throw()
  21632. {
  21633. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21634. if (diff == 0)
  21635. {
  21636. if (first->message.isNoteOff() && second->message.isNoteOn())
  21637. return -1;
  21638. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21639. return 1;
  21640. else
  21641. return 0;
  21642. }
  21643. else
  21644. {
  21645. return (diff > 0) ? 1 : -1;
  21646. }
  21647. }
  21648. void MidiFile::readNextTrack (const char* data, int size)
  21649. {
  21650. double time = 0;
  21651. char lastStatusByte = 0;
  21652. MidiMessageSequence result;
  21653. while (size > 0)
  21654. {
  21655. int bytesUsed;
  21656. const int delay = MidiMessage::readVariableLengthVal ((const uint8*) data, bytesUsed);
  21657. data += bytesUsed;
  21658. size -= bytesUsed;
  21659. time += delay;
  21660. int messSize = 0;
  21661. const MidiMessage mm ((const uint8*) data, size, messSize, lastStatusByte, time);
  21662. if (messSize <= 0)
  21663. break;
  21664. size -= messSize;
  21665. data += messSize;
  21666. result.addEvent (mm);
  21667. const char firstByte = *(mm.getRawData());
  21668. if ((firstByte & 0xf0) != 0xf0)
  21669. lastStatusByte = firstByte;
  21670. }
  21671. // use a sort that puts all the note-offs before note-ons that have the same time
  21672. result.list.sort (*this, true);
  21673. result.updateMatchedPairs();
  21674. addTrack (result);
  21675. }
  21676. void MidiFile::convertTimestampTicksToSeconds()
  21677. {
  21678. MidiMessageSequence tempoEvents;
  21679. findAllTempoEvents (tempoEvents);
  21680. findAllTimeSigEvents (tempoEvents);
  21681. for (int i = 0; i < tracks.size(); ++i)
  21682. {
  21683. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21684. for (int j = ms.getNumEvents(); --j >= 0;)
  21685. {
  21686. MidiMessage& m = ms.getEventPointer(j)->message;
  21687. m.setTimeStamp (MidiFileHelpers::convertTicksToSeconds (m.getTimeStamp(),
  21688. tempoEvents,
  21689. timeFormat));
  21690. }
  21691. }
  21692. }
  21693. bool MidiFile::writeTo (OutputStream& out)
  21694. {
  21695. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21696. out.writeIntBigEndian (6);
  21697. out.writeShortBigEndian (1); // type
  21698. out.writeShortBigEndian ((short) tracks.size());
  21699. out.writeShortBigEndian (timeFormat);
  21700. for (int i = 0; i < tracks.size(); ++i)
  21701. writeTrack (out, i);
  21702. out.flush();
  21703. return true;
  21704. }
  21705. void MidiFile::writeTrack (OutputStream& mainOut,
  21706. const int trackNum)
  21707. {
  21708. MemoryOutputStream out;
  21709. const MidiMessageSequence& ms = *tracks[trackNum];
  21710. int lastTick = 0;
  21711. char lastStatusByte = 0;
  21712. for (int i = 0; i < ms.getNumEvents(); ++i)
  21713. {
  21714. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21715. const int tick = roundToInt (mm.getTimeStamp());
  21716. const int delta = jmax (0, tick - lastTick);
  21717. MidiFileHelpers::writeVariableLengthInt (out, delta);
  21718. lastTick = tick;
  21719. const char statusByte = *(mm.getRawData());
  21720. if ((statusByte == lastStatusByte)
  21721. && ((statusByte & 0xf0) != 0xf0)
  21722. && i > 0
  21723. && mm.getRawDataSize() > 1)
  21724. {
  21725. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21726. }
  21727. else
  21728. {
  21729. out.write (mm.getRawData(), mm.getRawDataSize());
  21730. }
  21731. lastStatusByte = statusByte;
  21732. }
  21733. out.writeByte (0);
  21734. const MidiMessage m (MidiMessage::endOfTrack());
  21735. out.write (m.getRawData(),
  21736. m.getRawDataSize());
  21737. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21738. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21739. mainOut.write (out.getData(), (int) out.getDataSize());
  21740. }
  21741. END_JUCE_NAMESPACE
  21742. /*** End of inlined file: juce_MidiFile.cpp ***/
  21743. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  21744. BEGIN_JUCE_NAMESPACE
  21745. MidiKeyboardState::MidiKeyboardState()
  21746. {
  21747. zeromem (noteStates, sizeof (noteStates));
  21748. }
  21749. MidiKeyboardState::~MidiKeyboardState()
  21750. {
  21751. }
  21752. void MidiKeyboardState::reset()
  21753. {
  21754. const ScopedLock sl (lock);
  21755. zeromem (noteStates, sizeof (noteStates));
  21756. eventsToAdd.clear();
  21757. }
  21758. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21759. {
  21760. jassert (midiChannel >= 0 && midiChannel <= 16);
  21761. return ((unsigned int) n) < 128
  21762. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21763. }
  21764. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21765. {
  21766. return ((unsigned int) n) < 128
  21767. && (noteStates[n] & midiChannelMask) != 0;
  21768. }
  21769. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21770. {
  21771. jassert (midiChannel >= 0 && midiChannel <= 16);
  21772. jassert (((unsigned int) midiNoteNumber) < 128);
  21773. const ScopedLock sl (lock);
  21774. if (((unsigned int) midiNoteNumber) < 128)
  21775. {
  21776. const int timeNow = (int) Time::getMillisecondCounter();
  21777. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  21778. eventsToAdd.clear (0, timeNow - 500);
  21779. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  21780. }
  21781. }
  21782. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  21783. {
  21784. if (((unsigned int) midiNoteNumber) < 128)
  21785. {
  21786. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  21787. for (int i = listeners.size(); --i >= 0;)
  21788. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  21789. ->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  21790. }
  21791. }
  21792. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  21793. {
  21794. const ScopedLock sl (lock);
  21795. if (isNoteOn (midiChannel, midiNoteNumber))
  21796. {
  21797. const int timeNow = (int) Time::getMillisecondCounter();
  21798. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  21799. eventsToAdd.clear (0, timeNow - 500);
  21800. noteOffInternal (midiChannel, midiNoteNumber);
  21801. }
  21802. }
  21803. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  21804. {
  21805. if (isNoteOn (midiChannel, midiNoteNumber))
  21806. {
  21807. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  21808. for (int i = listeners.size(); --i >= 0;)
  21809. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  21810. ->handleNoteOff (this, midiChannel, midiNoteNumber);
  21811. }
  21812. }
  21813. void MidiKeyboardState::allNotesOff (const int midiChannel)
  21814. {
  21815. const ScopedLock sl (lock);
  21816. if (midiChannel <= 0)
  21817. {
  21818. for (int i = 1; i <= 16; ++i)
  21819. allNotesOff (i);
  21820. }
  21821. else
  21822. {
  21823. for (int i = 0; i < 128; ++i)
  21824. noteOff (midiChannel, i);
  21825. }
  21826. }
  21827. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  21828. {
  21829. if (message.isNoteOn())
  21830. {
  21831. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  21832. }
  21833. else if (message.isNoteOff())
  21834. {
  21835. noteOffInternal (message.getChannel(), message.getNoteNumber());
  21836. }
  21837. else if (message.isAllNotesOff())
  21838. {
  21839. for (int i = 0; i < 128; ++i)
  21840. noteOffInternal (message.getChannel(), i);
  21841. }
  21842. }
  21843. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  21844. const int startSample,
  21845. const int numSamples,
  21846. const bool injectIndirectEvents)
  21847. {
  21848. MidiBuffer::Iterator i (buffer);
  21849. MidiMessage message (0xf4, 0.0);
  21850. int time;
  21851. const ScopedLock sl (lock);
  21852. while (i.getNextEvent (message, time))
  21853. processNextMidiEvent (message);
  21854. if (injectIndirectEvents)
  21855. {
  21856. MidiBuffer::Iterator i2 (eventsToAdd);
  21857. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  21858. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  21859. while (i2.getNextEvent (message, time))
  21860. {
  21861. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  21862. buffer.addEvent (message, startSample + pos);
  21863. }
  21864. }
  21865. eventsToAdd.clear();
  21866. }
  21867. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  21868. {
  21869. const ScopedLock sl (lock);
  21870. listeners.addIfNotAlreadyThere (listener);
  21871. }
  21872. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  21873. {
  21874. const ScopedLock sl (lock);
  21875. listeners.removeValue (listener);
  21876. }
  21877. END_JUCE_NAMESPACE
  21878. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  21879. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  21880. BEGIN_JUCE_NAMESPACE
  21881. int MidiMessage::readVariableLengthVal (const uint8* data,
  21882. int& numBytesUsed) throw()
  21883. {
  21884. numBytesUsed = 0;
  21885. int v = 0;
  21886. int i;
  21887. do
  21888. {
  21889. i = (int) *data++;
  21890. if (++numBytesUsed > 6)
  21891. break;
  21892. v = (v << 7) + (i & 0x7f);
  21893. } while (i & 0x80);
  21894. return v;
  21895. }
  21896. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  21897. {
  21898. // this method only works for valid starting bytes of a short midi message
  21899. jassert (firstByte >= 0x80
  21900. && firstByte != 0xf0
  21901. && firstByte != 0xf7);
  21902. static const char messageLengths[] =
  21903. {
  21904. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21905. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21906. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21907. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21908. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21909. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21910. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21911. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  21912. };
  21913. return messageLengths [firstByte & 0x7f];
  21914. }
  21915. MidiMessage::MidiMessage (const uint8* const d,
  21916. const int dataSize,
  21917. const double t) throw()
  21918. : timeStamp (t),
  21919. message (0),
  21920. size (dataSize)
  21921. {
  21922. jassert (dataSize > 0);
  21923. if (dataSize <= 4)
  21924. data = (uint8*) &message;
  21925. else
  21926. data = (uint8*) juce_malloc (dataSize);
  21927. memcpy (data, d, dataSize);
  21928. // check that the length matches the data..
  21929. jassert (size > 3 || *d >= 0xf0 || getMessageLengthFromFirstByte (*d) == size);
  21930. }
  21931. MidiMessage::MidiMessage (const int byte1,
  21932. const double t) throw()
  21933. : timeStamp (t),
  21934. data ((uint8*) &message),
  21935. size (1)
  21936. {
  21937. data[0] = (uint8) byte1;
  21938. // check that the length matches the data..
  21939. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  21940. }
  21941. MidiMessage::MidiMessage (const int byte1,
  21942. const int byte2,
  21943. const double t) throw()
  21944. : timeStamp (t),
  21945. data ((uint8*) &message),
  21946. size (2)
  21947. {
  21948. data[0] = (uint8) byte1;
  21949. data[1] = (uint8) byte2;
  21950. // check that the length matches the data..
  21951. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  21952. }
  21953. MidiMessage::MidiMessage (const int byte1,
  21954. const int byte2,
  21955. const int byte3,
  21956. const double t) throw()
  21957. : timeStamp (t),
  21958. data ((uint8*) &message),
  21959. size (3)
  21960. {
  21961. data[0] = (uint8) byte1;
  21962. data[1] = (uint8) byte2;
  21963. data[2] = (uint8) byte3;
  21964. // check that the length matches the data..
  21965. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  21966. }
  21967. MidiMessage::MidiMessage (const MidiMessage& other) throw()
  21968. : timeStamp (other.timeStamp),
  21969. message (other.message),
  21970. size (other.size)
  21971. {
  21972. if (other.data != (uint8*) &other.message)
  21973. {
  21974. data = (uint8*) juce_malloc (size);
  21975. memcpy (data, other.data, size);
  21976. }
  21977. else
  21978. {
  21979. data = (uint8*) &message;
  21980. }
  21981. }
  21982. MidiMessage::MidiMessage (const MidiMessage& other,
  21983. const double newTimeStamp) throw()
  21984. : timeStamp (newTimeStamp),
  21985. message (other.message),
  21986. size (other.size)
  21987. {
  21988. if (other.data != (uint8*) &other.message)
  21989. {
  21990. data = (uint8*) juce_malloc (size);
  21991. memcpy (data, other.data, size);
  21992. }
  21993. else
  21994. {
  21995. data = (uint8*) &message;
  21996. }
  21997. }
  21998. MidiMessage::MidiMessage (const uint8* src,
  21999. int sz,
  22000. int& numBytesUsed,
  22001. const uint8 lastStatusByte,
  22002. double t) throw()
  22003. : timeStamp (t),
  22004. data ((uint8*) &message),
  22005. message (0)
  22006. {
  22007. unsigned int byte = (unsigned int) *src;
  22008. if (byte < 0x80)
  22009. {
  22010. byte = (unsigned int) (uint8) lastStatusByte;
  22011. numBytesUsed = -1;
  22012. }
  22013. else
  22014. {
  22015. numBytesUsed = 0;
  22016. --sz;
  22017. ++src;
  22018. }
  22019. if (byte >= 0x80)
  22020. {
  22021. if (byte == 0xf0)
  22022. {
  22023. const uint8* d = (const uint8*) src;
  22024. while (d < src + sz)
  22025. {
  22026. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22027. {
  22028. if (*d == 0xf7) // include an 0xf7 if we hit one
  22029. ++d;
  22030. break;
  22031. }
  22032. ++d;
  22033. }
  22034. size = 1 + (int) (d - src);
  22035. data = (uint8*) juce_malloc (size);
  22036. *data = (uint8) byte;
  22037. memcpy (data + 1, src, size - 1);
  22038. }
  22039. else if (byte == 0xff)
  22040. {
  22041. int n;
  22042. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22043. size = jmin (sz + 1, n + 2 + bytesLeft);
  22044. data = (uint8*) juce_malloc (size);
  22045. *data = (uint8) byte;
  22046. memcpy (data + 1, src, size - 1);
  22047. }
  22048. else
  22049. {
  22050. size = getMessageLengthFromFirstByte ((uint8) byte);
  22051. *data = (uint8) byte;
  22052. if (size > 1)
  22053. {
  22054. data[1] = src[0];
  22055. if (size > 2)
  22056. data[2] = src[1];
  22057. }
  22058. }
  22059. numBytesUsed += size;
  22060. }
  22061. else
  22062. {
  22063. message = 0;
  22064. size = 0;
  22065. }
  22066. }
  22067. MidiMessage& MidiMessage::operator= (const MidiMessage& other) throw()
  22068. {
  22069. if (this != &other)
  22070. {
  22071. timeStamp = other.timeStamp;
  22072. size = other.size;
  22073. message = other.message;
  22074. if (data != (uint8*) &message)
  22075. juce_free (data);
  22076. if (other.data != (uint8*) &other.message)
  22077. {
  22078. data = (uint8*) juce_malloc (size);
  22079. memcpy (data, other.data, size);
  22080. }
  22081. else
  22082. {
  22083. data = (uint8*) &message;
  22084. }
  22085. }
  22086. return *this;
  22087. }
  22088. MidiMessage::~MidiMessage() throw()
  22089. {
  22090. if (data != (uint8*) &message)
  22091. juce_free (data);
  22092. }
  22093. int MidiMessage::getChannel() const throw()
  22094. {
  22095. if ((data[0] & 0xf0) != 0xf0)
  22096. return (data[0] & 0xf) + 1;
  22097. else
  22098. return 0;
  22099. }
  22100. bool MidiMessage::isForChannel (const int channel) const throw()
  22101. {
  22102. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22103. return ((data[0] & 0xf) == channel - 1)
  22104. && ((data[0] & 0xf0) != 0xf0);
  22105. }
  22106. void MidiMessage::setChannel (const int channel) throw()
  22107. {
  22108. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22109. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22110. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22111. | (uint8)(channel - 1));
  22112. }
  22113. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22114. {
  22115. return ((data[0] & 0xf0) == 0x90)
  22116. && (returnTrueForVelocity0 || data[2] != 0);
  22117. }
  22118. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22119. {
  22120. return ((data[0] & 0xf0) == 0x80)
  22121. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22122. }
  22123. bool MidiMessage::isNoteOnOrOff() const throw()
  22124. {
  22125. const int d = data[0] & 0xf0;
  22126. return (d == 0x90) || (d == 0x80);
  22127. }
  22128. int MidiMessage::getNoteNumber() const throw()
  22129. {
  22130. return data[1];
  22131. }
  22132. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22133. {
  22134. if (isNoteOnOrOff())
  22135. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22136. }
  22137. uint8 MidiMessage::getVelocity() const throw()
  22138. {
  22139. if (isNoteOnOrOff())
  22140. return data[2];
  22141. else
  22142. return 0;
  22143. }
  22144. float MidiMessage::getFloatVelocity() const throw()
  22145. {
  22146. return getVelocity() * (1.0f / 127.0f);
  22147. }
  22148. void MidiMessage::setVelocity (const float newVelocity) throw()
  22149. {
  22150. if (isNoteOnOrOff())
  22151. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22152. }
  22153. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22154. {
  22155. if (isNoteOnOrOff())
  22156. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22157. }
  22158. bool MidiMessage::isAftertouch() const throw()
  22159. {
  22160. return (data[0] & 0xf0) == 0xa0;
  22161. }
  22162. int MidiMessage::getAfterTouchValue() const throw()
  22163. {
  22164. return data[2];
  22165. }
  22166. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22167. const int noteNum,
  22168. const int aftertouchValue) throw()
  22169. {
  22170. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22171. jassert (((unsigned int) noteNum) <= 127);
  22172. jassert (((unsigned int) aftertouchValue) <= 127);
  22173. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22174. noteNum & 0x7f,
  22175. aftertouchValue & 0x7f);
  22176. }
  22177. bool MidiMessage::isChannelPressure() const throw()
  22178. {
  22179. return (data[0] & 0xf0) == 0xd0;
  22180. }
  22181. int MidiMessage::getChannelPressureValue() const throw()
  22182. {
  22183. jassert (isChannelPressure());
  22184. return data[1];
  22185. }
  22186. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22187. const int pressure) throw()
  22188. {
  22189. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22190. jassert (((unsigned int) pressure) <= 127);
  22191. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22192. pressure & 0x7f);
  22193. }
  22194. bool MidiMessage::isProgramChange() const throw()
  22195. {
  22196. return (data[0] & 0xf0) == 0xc0;
  22197. }
  22198. int MidiMessage::getProgramChangeNumber() const throw()
  22199. {
  22200. return data[1];
  22201. }
  22202. const MidiMessage MidiMessage::programChange (const int channel,
  22203. const int programNumber) throw()
  22204. {
  22205. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22206. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22207. programNumber & 0x7f);
  22208. }
  22209. bool MidiMessage::isPitchWheel() const throw()
  22210. {
  22211. return (data[0] & 0xf0) == 0xe0;
  22212. }
  22213. int MidiMessage::getPitchWheelValue() const throw()
  22214. {
  22215. return data[1] | (data[2] << 7);
  22216. }
  22217. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22218. const int position) throw()
  22219. {
  22220. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22221. jassert (((unsigned int) position) <= 0x3fff);
  22222. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22223. position & 127,
  22224. (position >> 7) & 127);
  22225. }
  22226. bool MidiMessage::isController() const throw()
  22227. {
  22228. return (data[0] & 0xf0) == 0xb0;
  22229. }
  22230. int MidiMessage::getControllerNumber() const throw()
  22231. {
  22232. jassert (isController());
  22233. return data[1];
  22234. }
  22235. int MidiMessage::getControllerValue() const throw()
  22236. {
  22237. jassert (isController());
  22238. return data[2];
  22239. }
  22240. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22241. const int controllerType,
  22242. const int value) throw()
  22243. {
  22244. // the channel must be between 1 and 16 inclusive
  22245. jassert (channel > 0 && channel <= 16);
  22246. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22247. controllerType & 127,
  22248. value & 127);
  22249. }
  22250. const MidiMessage MidiMessage::noteOn (const int channel,
  22251. const int noteNumber,
  22252. const float velocity) throw()
  22253. {
  22254. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22255. }
  22256. const MidiMessage MidiMessage::noteOn (const int channel,
  22257. const int noteNumber,
  22258. const uint8 velocity) throw()
  22259. {
  22260. jassert (channel > 0 && channel <= 16);
  22261. jassert (((unsigned int) noteNumber) <= 127);
  22262. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22263. noteNumber & 127,
  22264. jlimit (0, 127, roundToInt (velocity)));
  22265. }
  22266. const MidiMessage MidiMessage::noteOff (const int channel,
  22267. const int noteNumber) throw()
  22268. {
  22269. jassert (channel > 0 && channel <= 16);
  22270. jassert (((unsigned int) noteNumber) <= 127);
  22271. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22272. }
  22273. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22274. {
  22275. jassert (channel > 0 && channel <= 16);
  22276. return controllerEvent (channel, 123, 0);
  22277. }
  22278. bool MidiMessage::isAllNotesOff() const throw()
  22279. {
  22280. return (data[0] & 0xf0) == 0xb0
  22281. && data[1] == 123;
  22282. }
  22283. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22284. {
  22285. return controllerEvent (channel, 120, 0);
  22286. }
  22287. bool MidiMessage::isAllSoundOff() const throw()
  22288. {
  22289. return (data[0] & 0xf0) == 0xb0
  22290. && data[1] == 120;
  22291. }
  22292. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22293. {
  22294. return controllerEvent (channel, 121, 0);
  22295. }
  22296. const MidiMessage MidiMessage::masterVolume (const float volume) throw()
  22297. {
  22298. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22299. uint8 buf[8];
  22300. buf[0] = 0xf0;
  22301. buf[1] = 0x7f;
  22302. buf[2] = 0x7f;
  22303. buf[3] = 0x04;
  22304. buf[4] = 0x01;
  22305. buf[5] = (uint8) (vol & 0x7f);
  22306. buf[6] = (uint8) (vol >> 7);
  22307. buf[7] = 0xf7;
  22308. return MidiMessage (buf, 8);
  22309. }
  22310. bool MidiMessage::isSysEx() const throw()
  22311. {
  22312. return *data == 0xf0;
  22313. }
  22314. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData,
  22315. const int dataSize) throw()
  22316. {
  22317. MemoryBlock mm (dataSize + 2);
  22318. uint8* const m = (uint8*) mm.getData();
  22319. m[0] = 0xf0;
  22320. memcpy (m + 1, sysexData, dataSize);
  22321. m[dataSize + 1] = 0xf7;
  22322. return MidiMessage (m, dataSize + 2);
  22323. }
  22324. const uint8* MidiMessage::getSysExData() const throw()
  22325. {
  22326. return (isSysEx()) ? getRawData() + 1
  22327. : 0;
  22328. }
  22329. int MidiMessage::getSysExDataSize() const throw()
  22330. {
  22331. return (isSysEx()) ? size - 2
  22332. : 0;
  22333. }
  22334. bool MidiMessage::isMetaEvent() const throw()
  22335. {
  22336. return *data == 0xff;
  22337. }
  22338. bool MidiMessage::isActiveSense() const throw()
  22339. {
  22340. return *data == 0xfe;
  22341. }
  22342. int MidiMessage::getMetaEventType() const throw()
  22343. {
  22344. if (*data != 0xff)
  22345. return -1;
  22346. else
  22347. return data[1];
  22348. }
  22349. int MidiMessage::getMetaEventLength() const throw()
  22350. {
  22351. if (*data == 0xff)
  22352. {
  22353. int n;
  22354. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22355. }
  22356. return 0;
  22357. }
  22358. const uint8* MidiMessage::getMetaEventData() const throw()
  22359. {
  22360. int n;
  22361. const uint8* d = data + 2;
  22362. readVariableLengthVal (d, n);
  22363. return d + n;
  22364. }
  22365. bool MidiMessage::isTrackMetaEvent() const throw()
  22366. {
  22367. return getMetaEventType() == 0;
  22368. }
  22369. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22370. {
  22371. return getMetaEventType() == 47;
  22372. }
  22373. bool MidiMessage::isTextMetaEvent() const throw()
  22374. {
  22375. const int t = getMetaEventType();
  22376. return t > 0 && t < 16;
  22377. }
  22378. const String MidiMessage::getTextFromTextMetaEvent() const throw()
  22379. {
  22380. return String ((const char*) getMetaEventData(),
  22381. getMetaEventLength());
  22382. }
  22383. bool MidiMessage::isTrackNameEvent() const throw()
  22384. {
  22385. return (data[1] == 3)
  22386. && (*data == 0xff);
  22387. }
  22388. bool MidiMessage::isTempoMetaEvent() const throw()
  22389. {
  22390. return (data[1] == 81)
  22391. && (*data == 0xff);
  22392. }
  22393. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22394. {
  22395. return (data[1] == 0x20)
  22396. && (*data == 0xff)
  22397. && (data[2] == 1);
  22398. }
  22399. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22400. {
  22401. return data[3] + 1;
  22402. }
  22403. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22404. {
  22405. if (! isTempoMetaEvent())
  22406. return 0.0;
  22407. const uint8* const d = getMetaEventData();
  22408. return (((unsigned int) d[0] << 16)
  22409. | ((unsigned int) d[1] << 8)
  22410. | d[2])
  22411. / 1000000.0;
  22412. }
  22413. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22414. {
  22415. if (timeFormat > 0)
  22416. {
  22417. if (! isTempoMetaEvent())
  22418. return 0.5 / timeFormat;
  22419. return getTempoSecondsPerQuarterNote() / timeFormat;
  22420. }
  22421. else
  22422. {
  22423. const int frameCode = (-timeFormat) >> 8;
  22424. double framesPerSecond;
  22425. switch (frameCode)
  22426. {
  22427. case 24: framesPerSecond = 24.0; break;
  22428. case 25: framesPerSecond = 25.0; break;
  22429. case 29: framesPerSecond = 29.97; break;
  22430. case 30: framesPerSecond = 30.0; break;
  22431. default: framesPerSecond = 30.0; break;
  22432. }
  22433. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22434. }
  22435. }
  22436. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22437. {
  22438. uint8 d[8];
  22439. d[0] = 0xff;
  22440. d[1] = 81;
  22441. d[2] = 3;
  22442. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22443. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22444. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22445. return MidiMessage (d, 6, 0.0);
  22446. }
  22447. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22448. {
  22449. return (data[1] == 0x58)
  22450. && (*data == (uint8) 0xff);
  22451. }
  22452. void MidiMessage::getTimeSignatureInfo (int& numerator,
  22453. int& denominator) const throw()
  22454. {
  22455. if (isTimeSignatureMetaEvent())
  22456. {
  22457. const uint8* const d = getMetaEventData();
  22458. numerator = d[0];
  22459. denominator = 1 << d[1];
  22460. }
  22461. else
  22462. {
  22463. numerator = 4;
  22464. denominator = 4;
  22465. }
  22466. }
  22467. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator,
  22468. const int denominator) throw()
  22469. {
  22470. uint8 d[8];
  22471. d[0] = 0xff;
  22472. d[1] = 0x58;
  22473. d[2] = 0x04;
  22474. d[3] = (uint8) numerator;
  22475. int n = 1;
  22476. int powerOfTwo = 0;
  22477. while (n < denominator)
  22478. {
  22479. n <<= 1;
  22480. ++powerOfTwo;
  22481. }
  22482. d[4] = (uint8) powerOfTwo;
  22483. d[5] = 0x01;
  22484. d[6] = 96;
  22485. return MidiMessage (d, 7, 0.0);
  22486. }
  22487. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22488. {
  22489. uint8 d[8];
  22490. d[0] = 0xff;
  22491. d[1] = 0x20;
  22492. d[2] = 0x01;
  22493. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22494. return MidiMessage (d, 4, 0.0);
  22495. }
  22496. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22497. {
  22498. return getMetaEventType() == 89;
  22499. }
  22500. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22501. {
  22502. return (int) *getMetaEventData();
  22503. }
  22504. const MidiMessage MidiMessage::endOfTrack() throw()
  22505. {
  22506. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22507. }
  22508. bool MidiMessage::isSongPositionPointer() const throw()
  22509. {
  22510. return *data == 0xf2;
  22511. }
  22512. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22513. {
  22514. return data[1] | (data[2] << 7);
  22515. }
  22516. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22517. {
  22518. return MidiMessage (0xf2,
  22519. positionInMidiBeats & 127,
  22520. (positionInMidiBeats >> 7) & 127);
  22521. }
  22522. bool MidiMessage::isMidiStart() const throw()
  22523. {
  22524. return *data == 0xfa;
  22525. }
  22526. const MidiMessage MidiMessage::midiStart() throw()
  22527. {
  22528. return MidiMessage (0xfa);
  22529. }
  22530. bool MidiMessage::isMidiContinue() const throw()
  22531. {
  22532. return *data == 0xfb;
  22533. }
  22534. const MidiMessage MidiMessage::midiContinue() throw()
  22535. {
  22536. return MidiMessage (0xfb);
  22537. }
  22538. bool MidiMessage::isMidiStop() const throw()
  22539. {
  22540. return *data == 0xfc;
  22541. }
  22542. const MidiMessage MidiMessage::midiStop() throw()
  22543. {
  22544. return MidiMessage (0xfc);
  22545. }
  22546. bool MidiMessage::isMidiClock() const throw()
  22547. {
  22548. return *data == 0xf8;
  22549. }
  22550. const MidiMessage MidiMessage::midiClock() throw()
  22551. {
  22552. return MidiMessage (0xf8);
  22553. }
  22554. bool MidiMessage::isQuarterFrame() const throw()
  22555. {
  22556. return *data == 0xf1;
  22557. }
  22558. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22559. {
  22560. return ((int) data[1]) >> 4;
  22561. }
  22562. int MidiMessage::getQuarterFrameValue() const throw()
  22563. {
  22564. return ((int) data[1]) & 0x0f;
  22565. }
  22566. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22567. const int value) throw()
  22568. {
  22569. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22570. }
  22571. bool MidiMessage::isFullFrame() const throw()
  22572. {
  22573. return data[0] == 0xf0
  22574. && data[1] == 0x7f
  22575. && size >= 10
  22576. && data[3] == 0x01
  22577. && data[4] == 0x01;
  22578. }
  22579. void MidiMessage::getFullFrameParameters (int& hours,
  22580. int& minutes,
  22581. int& seconds,
  22582. int& frames,
  22583. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22584. {
  22585. jassert (isFullFrame());
  22586. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22587. hours = data[5] & 0x1f;
  22588. minutes = data[6];
  22589. seconds = data[7];
  22590. frames = data[8];
  22591. }
  22592. const MidiMessage MidiMessage::fullFrame (const int hours,
  22593. const int minutes,
  22594. const int seconds,
  22595. const int frames,
  22596. MidiMessage::SmpteTimecodeType timecodeType)
  22597. {
  22598. uint8 d[10];
  22599. d[0] = 0xf0;
  22600. d[1] = 0x7f;
  22601. d[2] = 0x7f;
  22602. d[3] = 0x01;
  22603. d[4] = 0x01;
  22604. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22605. d[6] = (uint8) minutes;
  22606. d[7] = (uint8) seconds;
  22607. d[8] = (uint8) frames;
  22608. d[9] = 0xf7;
  22609. return MidiMessage (d, 10, 0.0);
  22610. }
  22611. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22612. {
  22613. return data[0] == 0xf0
  22614. && data[1] == 0x7f
  22615. && data[3] == 0x06
  22616. && size > 5;
  22617. }
  22618. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22619. {
  22620. jassert (isMidiMachineControlMessage());
  22621. return (MidiMachineControlCommand) data[4];
  22622. }
  22623. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22624. {
  22625. uint8 d[6];
  22626. d[0] = 0xf0;
  22627. d[1] = 0x7f;
  22628. d[2] = 0x00;
  22629. d[3] = 0x06;
  22630. d[4] = (uint8) command;
  22631. d[5] = 0xf7;
  22632. return MidiMessage (d, 6, 0.0);
  22633. }
  22634. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22635. int& minutes,
  22636. int& seconds,
  22637. int& frames) const throw()
  22638. {
  22639. if (size >= 12
  22640. && data[0] == 0xf0
  22641. && data[1] == 0x7f
  22642. && data[3] == 0x06
  22643. && data[4] == 0x44
  22644. && data[5] == 0x06
  22645. && data[6] == 0x01)
  22646. {
  22647. hours = data[7] % 24; // (that some machines send out hours > 24)
  22648. minutes = data[8];
  22649. seconds = data[9];
  22650. frames = data[10];
  22651. return true;
  22652. }
  22653. return false;
  22654. }
  22655. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22656. int minutes,
  22657. int seconds,
  22658. int frames)
  22659. {
  22660. uint8 d[12];
  22661. d[0] = 0xf0;
  22662. d[1] = 0x7f;
  22663. d[2] = 0x00;
  22664. d[3] = 0x06;
  22665. d[4] = 0x44;
  22666. d[5] = 0x06;
  22667. d[6] = 0x01;
  22668. d[7] = (uint8) hours;
  22669. d[8] = (uint8) minutes;
  22670. d[9] = (uint8) seconds;
  22671. d[10] = (uint8) frames;
  22672. d[11] = 0xf7;
  22673. return MidiMessage (d, 12, 0.0);
  22674. }
  22675. const String MidiMessage::getMidiNoteName (int note,
  22676. bool useSharps,
  22677. bool includeOctaveNumber,
  22678. int octaveNumForMiddleC) throw()
  22679. {
  22680. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22681. "F", "F#", "G", "G#", "A",
  22682. "A#", "B" };
  22683. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22684. "F", "Gb", "G", "Ab", "A",
  22685. "Bb", "B" };
  22686. if (((unsigned int) note) < 128)
  22687. {
  22688. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22689. : flatNoteNames [note % 12]);
  22690. if (includeOctaveNumber)
  22691. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22692. else
  22693. return s;
  22694. }
  22695. return String::empty;
  22696. }
  22697. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22698. {
  22699. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22700. return 440.0 * pow (2.0, noteNumber / 12.0);
  22701. }
  22702. const String MidiMessage::getGMInstrumentName (int n) throw()
  22703. {
  22704. const char *names[] =
  22705. {
  22706. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22707. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22708. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22709. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22710. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22711. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22712. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22713. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22714. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22715. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22716. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22717. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22718. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22719. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22720. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22721. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22722. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22723. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22724. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22725. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22726. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22727. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22728. "Applause", "Gunshot"
  22729. };
  22730. return (((unsigned int) n) < 128) ? names[n]
  22731. : (const char*)0;
  22732. }
  22733. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22734. {
  22735. const char* names[] =
  22736. {
  22737. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22738. "Bass", "Strings", "Ensemble", "Brass",
  22739. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22740. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22741. };
  22742. return (((unsigned int) n) <= 15) ? names[n]
  22743. : (const char*)0;
  22744. }
  22745. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22746. {
  22747. const char* names[] =
  22748. {
  22749. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22750. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22751. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22752. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22753. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22754. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22755. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22756. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22757. "Mute Triangle", "Open Triangle"
  22758. };
  22759. return (n >= 35 && n <= 81) ? names [n - 35]
  22760. : (const char*)0;
  22761. }
  22762. const String MidiMessage::getControllerName (int n) throw()
  22763. {
  22764. const char* names[] =
  22765. {
  22766. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22767. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22768. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22769. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22770. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22771. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  22772. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  22773. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  22774. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  22775. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22776. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  22777. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  22778. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  22779. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  22780. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  22781. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  22782. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  22783. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  22784. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  22785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  22786. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  22787. "Poly Operation"
  22788. };
  22789. return (((unsigned int) n) < 128) ? names[n]
  22790. : (const char*)0;
  22791. }
  22792. END_JUCE_NAMESPACE
  22793. /*** End of inlined file: juce_MidiMessage.cpp ***/
  22794. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  22795. BEGIN_JUCE_NAMESPACE
  22796. MidiMessageCollector::MidiMessageCollector()
  22797. : lastCallbackTime (0),
  22798. sampleRate (44100.0001)
  22799. {
  22800. }
  22801. MidiMessageCollector::~MidiMessageCollector()
  22802. {
  22803. }
  22804. void MidiMessageCollector::reset (const double sampleRate_)
  22805. {
  22806. jassert (sampleRate_ > 0);
  22807. const ScopedLock sl (midiCallbackLock);
  22808. sampleRate = sampleRate_;
  22809. incomingMessages.clear();
  22810. lastCallbackTime = Time::getMillisecondCounterHiRes();
  22811. }
  22812. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  22813. {
  22814. // you need to call reset() to set the correct sample rate before using this object
  22815. jassert (sampleRate != 44100.0001);
  22816. // the messages that come in here need to be time-stamped correctly - see MidiInput
  22817. // for details of what the number should be.
  22818. jassert (message.getTimeStamp() != 0);
  22819. const ScopedLock sl (midiCallbackLock);
  22820. const int sampleNumber
  22821. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  22822. incomingMessages.addEvent (message, sampleNumber);
  22823. // if the messages don't get used for over a second, we'd better
  22824. // get rid of any old ones to avoid the queue getting too big
  22825. if (sampleNumber > sampleRate)
  22826. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  22827. }
  22828. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  22829. const int numSamples)
  22830. {
  22831. // you need to call reset() to set the correct sample rate before using this object
  22832. jassert (sampleRate != 44100.0001);
  22833. const double timeNow = Time::getMillisecondCounterHiRes();
  22834. const double msElapsed = timeNow - lastCallbackTime;
  22835. const ScopedLock sl (midiCallbackLock);
  22836. lastCallbackTime = timeNow;
  22837. if (! incomingMessages.isEmpty())
  22838. {
  22839. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  22840. int startSample = 0;
  22841. int scale = 1 << 16;
  22842. const uint8* midiData;
  22843. int numBytes, samplePosition;
  22844. MidiBuffer::Iterator iter (incomingMessages);
  22845. if (numSourceSamples > numSamples)
  22846. {
  22847. // if our list of events is longer than the buffer we're being
  22848. // asked for, scale them down to squeeze them all in..
  22849. const int maxBlockLengthToUse = numSamples << 5;
  22850. if (numSourceSamples > maxBlockLengthToUse)
  22851. {
  22852. startSample = numSourceSamples - maxBlockLengthToUse;
  22853. numSourceSamples = maxBlockLengthToUse;
  22854. iter.setNextSamplePosition (startSample);
  22855. }
  22856. scale = (numSamples << 10) / numSourceSamples;
  22857. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22858. {
  22859. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  22860. destBuffer.addEvent (midiData, numBytes,
  22861. jlimit (0, numSamples - 1, samplePosition));
  22862. }
  22863. }
  22864. else
  22865. {
  22866. // if our event list is shorter than the number we need, put them
  22867. // towards the end of the buffer
  22868. startSample = numSamples - numSourceSamples;
  22869. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22870. {
  22871. destBuffer.addEvent (midiData, numBytes,
  22872. jlimit (0, numSamples - 1, samplePosition + startSample));
  22873. }
  22874. }
  22875. incomingMessages.clear();
  22876. }
  22877. }
  22878. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  22879. {
  22880. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  22881. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22882. addMessageToQueue (m);
  22883. }
  22884. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  22885. {
  22886. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  22887. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22888. addMessageToQueue (m);
  22889. }
  22890. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  22891. {
  22892. addMessageToQueue (message);
  22893. }
  22894. END_JUCE_NAMESPACE
  22895. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  22896. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  22897. BEGIN_JUCE_NAMESPACE
  22898. MidiMessageSequence::MidiMessageSequence()
  22899. {
  22900. }
  22901. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  22902. {
  22903. list.ensureStorageAllocated (other.list.size());
  22904. for (int i = 0; i < other.list.size(); ++i)
  22905. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  22906. }
  22907. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  22908. {
  22909. MidiMessageSequence otherCopy (other);
  22910. swapWith (otherCopy);
  22911. return *this;
  22912. }
  22913. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  22914. {
  22915. list.swapWithArray (other.list);
  22916. }
  22917. MidiMessageSequence::~MidiMessageSequence()
  22918. {
  22919. }
  22920. void MidiMessageSequence::clear()
  22921. {
  22922. list.clear();
  22923. }
  22924. int MidiMessageSequence::getNumEvents() const
  22925. {
  22926. return list.size();
  22927. }
  22928. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  22929. {
  22930. return list [index];
  22931. }
  22932. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  22933. {
  22934. const MidiEventHolder* const meh = list [index];
  22935. if (meh != 0 && meh->noteOffObject != 0)
  22936. return meh->noteOffObject->message.getTimeStamp();
  22937. else
  22938. return 0.0;
  22939. }
  22940. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  22941. {
  22942. const MidiEventHolder* const meh = list [index];
  22943. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  22944. }
  22945. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  22946. {
  22947. return list.indexOf (event);
  22948. }
  22949. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  22950. {
  22951. const int numEvents = list.size();
  22952. int i;
  22953. for (i = 0; i < numEvents; ++i)
  22954. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  22955. break;
  22956. return i;
  22957. }
  22958. double MidiMessageSequence::getStartTime() const
  22959. {
  22960. if (list.size() > 0)
  22961. return list.getUnchecked(0)->message.getTimeStamp();
  22962. else
  22963. return 0;
  22964. }
  22965. double MidiMessageSequence::getEndTime() const
  22966. {
  22967. if (list.size() > 0)
  22968. return list.getLast()->message.getTimeStamp();
  22969. else
  22970. return 0;
  22971. }
  22972. double MidiMessageSequence::getEventTime (const int index) const
  22973. {
  22974. if (((unsigned int) index) < (unsigned int) list.size())
  22975. return list.getUnchecked (index)->message.getTimeStamp();
  22976. return 0.0;
  22977. }
  22978. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  22979. double timeAdjustment)
  22980. {
  22981. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  22982. timeAdjustment += newMessage.getTimeStamp();
  22983. newOne->message.setTimeStamp (timeAdjustment);
  22984. int i;
  22985. for (i = list.size(); --i >= 0;)
  22986. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  22987. break;
  22988. list.insert (i + 1, newOne);
  22989. }
  22990. void MidiMessageSequence::deleteEvent (const int index,
  22991. const bool deleteMatchingNoteUp)
  22992. {
  22993. if (((unsigned int) index) < (unsigned int) list.size())
  22994. {
  22995. if (deleteMatchingNoteUp)
  22996. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  22997. list.remove (index);
  22998. }
  22999. }
  23000. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  23001. double timeAdjustment,
  23002. double firstAllowableTime,
  23003. double endOfAllowableDestTimes)
  23004. {
  23005. firstAllowableTime -= timeAdjustment;
  23006. endOfAllowableDestTimes -= timeAdjustment;
  23007. for (int i = 0; i < other.list.size(); ++i)
  23008. {
  23009. const MidiMessage& m = other.list.getUnchecked(i)->message;
  23010. const double t = m.getTimeStamp();
  23011. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  23012. {
  23013. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23014. newOne->message.setTimeStamp (timeAdjustment + t);
  23015. list.add (newOne);
  23016. }
  23017. }
  23018. sort();
  23019. }
  23020. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23021. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23022. {
  23023. const double diff = first->message.getTimeStamp()
  23024. - second->message.getTimeStamp();
  23025. return (diff > 0) - (diff < 0);
  23026. }
  23027. void MidiMessageSequence::sort()
  23028. {
  23029. list.sort (*this, true);
  23030. }
  23031. void MidiMessageSequence::updateMatchedPairs()
  23032. {
  23033. for (int i = 0; i < list.size(); ++i)
  23034. {
  23035. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23036. if (m1.isNoteOn())
  23037. {
  23038. list.getUnchecked(i)->noteOffObject = 0;
  23039. const int note = m1.getNoteNumber();
  23040. const int chan = m1.getChannel();
  23041. const int len = list.size();
  23042. for (int j = i + 1; j < len; ++j)
  23043. {
  23044. const MidiMessage& m = list.getUnchecked(j)->message;
  23045. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23046. {
  23047. if (m.isNoteOff())
  23048. {
  23049. list.getUnchecked(i)->noteOffObject = list[j];
  23050. break;
  23051. }
  23052. else if (m.isNoteOn())
  23053. {
  23054. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23055. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23056. list.getUnchecked(i)->noteOffObject = list[j];
  23057. break;
  23058. }
  23059. }
  23060. }
  23061. }
  23062. }
  23063. }
  23064. void MidiMessageSequence::addTimeToMessages (const double delta)
  23065. {
  23066. for (int i = list.size(); --i >= 0;)
  23067. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23068. + delta);
  23069. }
  23070. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23071. MidiMessageSequence& destSequence,
  23072. const bool alsoIncludeMetaEvents) const
  23073. {
  23074. for (int i = 0; i < list.size(); ++i)
  23075. {
  23076. const MidiMessage& mm = list.getUnchecked(i)->message;
  23077. if (mm.isForChannel (channelNumberToExtract)
  23078. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23079. {
  23080. destSequence.addEvent (mm);
  23081. }
  23082. }
  23083. }
  23084. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23085. {
  23086. for (int i = 0; i < list.size(); ++i)
  23087. {
  23088. const MidiMessage& mm = list.getUnchecked(i)->message;
  23089. if (mm.isSysEx())
  23090. destSequence.addEvent (mm);
  23091. }
  23092. }
  23093. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23094. {
  23095. for (int i = list.size(); --i >= 0;)
  23096. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23097. list.remove(i);
  23098. }
  23099. void MidiMessageSequence::deleteSysExMessages()
  23100. {
  23101. for (int i = list.size(); --i >= 0;)
  23102. if (list.getUnchecked(i)->message.isSysEx())
  23103. list.remove(i);
  23104. }
  23105. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23106. const double time,
  23107. OwnedArray<MidiMessage>& dest)
  23108. {
  23109. bool doneProg = false;
  23110. bool donePitchWheel = false;
  23111. Array <int> doneControllers;
  23112. doneControllers.ensureStorageAllocated (32);
  23113. for (int i = list.size(); --i >= 0;)
  23114. {
  23115. const MidiMessage& mm = list.getUnchecked(i)->message;
  23116. if (mm.isForChannel (channelNumber)
  23117. && mm.getTimeStamp() <= time)
  23118. {
  23119. if (mm.isProgramChange())
  23120. {
  23121. if (! doneProg)
  23122. {
  23123. dest.add (new MidiMessage (mm, 0.0));
  23124. doneProg = true;
  23125. }
  23126. }
  23127. else if (mm.isController())
  23128. {
  23129. if (! doneControllers.contains (mm.getControllerNumber()))
  23130. {
  23131. dest.add (new MidiMessage (mm, 0.0));
  23132. doneControllers.add (mm.getControllerNumber());
  23133. }
  23134. }
  23135. else if (mm.isPitchWheel())
  23136. {
  23137. if (! donePitchWheel)
  23138. {
  23139. dest.add (new MidiMessage (mm, 0.0));
  23140. donePitchWheel = true;
  23141. }
  23142. }
  23143. }
  23144. }
  23145. }
  23146. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23147. : message (message_),
  23148. noteOffObject (0)
  23149. {
  23150. }
  23151. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23152. {
  23153. }
  23154. END_JUCE_NAMESPACE
  23155. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23156. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23157. BEGIN_JUCE_NAMESPACE
  23158. AudioPluginFormat::AudioPluginFormat() throw()
  23159. {
  23160. }
  23161. AudioPluginFormat::~AudioPluginFormat()
  23162. {
  23163. }
  23164. END_JUCE_NAMESPACE
  23165. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23166. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23167. BEGIN_JUCE_NAMESPACE
  23168. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23169. {
  23170. }
  23171. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23172. {
  23173. clearSingletonInstance();
  23174. }
  23175. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23176. void AudioPluginFormatManager::addDefaultFormats()
  23177. {
  23178. #ifdef JUCE_DEBUG
  23179. // you should only call this method once!
  23180. for (int i = formats.size(); --i >= 0;)
  23181. {
  23182. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23183. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23184. #endif
  23185. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23186. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23187. #endif
  23188. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23189. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23190. #endif
  23191. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23192. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23193. #endif
  23194. }
  23195. #endif
  23196. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23197. formats.add (new AudioUnitPluginFormat());
  23198. #endif
  23199. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23200. formats.add (new VSTPluginFormat());
  23201. #endif
  23202. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23203. formats.add (new DirectXPluginFormat());
  23204. #endif
  23205. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23206. formats.add (new LADSPAPluginFormat());
  23207. #endif
  23208. }
  23209. int AudioPluginFormatManager::getNumFormats() throw()
  23210. {
  23211. return formats.size();
  23212. }
  23213. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23214. {
  23215. return formats [index];
  23216. }
  23217. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23218. {
  23219. formats.add (format);
  23220. }
  23221. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23222. String& errorMessage) const
  23223. {
  23224. AudioPluginInstance* result = 0;
  23225. for (int i = 0; i < formats.size(); ++i)
  23226. {
  23227. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23228. if (result != 0)
  23229. break;
  23230. }
  23231. if (result == 0)
  23232. {
  23233. if (! doesPluginStillExist (description))
  23234. errorMessage = TRANS ("This plug-in file no longer exists");
  23235. else
  23236. errorMessage = TRANS ("This plug-in failed to load correctly");
  23237. }
  23238. return result;
  23239. }
  23240. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23241. {
  23242. for (int i = 0; i < formats.size(); ++i)
  23243. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23244. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23245. return false;
  23246. }
  23247. END_JUCE_NAMESPACE
  23248. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23249. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23250. #define JUCE_PLUGIN_HOST 1
  23251. BEGIN_JUCE_NAMESPACE
  23252. AudioPluginInstance::AudioPluginInstance()
  23253. {
  23254. }
  23255. AudioPluginInstance::~AudioPluginInstance()
  23256. {
  23257. }
  23258. END_JUCE_NAMESPACE
  23259. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23260. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23261. BEGIN_JUCE_NAMESPACE
  23262. KnownPluginList::KnownPluginList()
  23263. {
  23264. }
  23265. KnownPluginList::~KnownPluginList()
  23266. {
  23267. }
  23268. void KnownPluginList::clear()
  23269. {
  23270. if (types.size() > 0)
  23271. {
  23272. types.clear();
  23273. sendChangeMessage (this);
  23274. }
  23275. }
  23276. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23277. {
  23278. for (int i = 0; i < types.size(); ++i)
  23279. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23280. return types.getUnchecked(i);
  23281. return 0;
  23282. }
  23283. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23284. {
  23285. for (int i = 0; i < types.size(); ++i)
  23286. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23287. return types.getUnchecked(i);
  23288. return 0;
  23289. }
  23290. bool KnownPluginList::addType (const PluginDescription& type)
  23291. {
  23292. for (int i = types.size(); --i >= 0;)
  23293. {
  23294. if (types.getUnchecked(i)->isDuplicateOf (type))
  23295. {
  23296. // strange - found a duplicate plugin with different info..
  23297. jassert (types.getUnchecked(i)->name == type.name);
  23298. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23299. *types.getUnchecked(i) = type;
  23300. return false;
  23301. }
  23302. }
  23303. types.add (new PluginDescription (type));
  23304. sendChangeMessage (this);
  23305. return true;
  23306. }
  23307. void KnownPluginList::removeType (const int index) throw()
  23308. {
  23309. types.remove (index);
  23310. sendChangeMessage (this);
  23311. }
  23312. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23313. {
  23314. if (fileOrIdentifier.startsWithChar (T('/'))
  23315. || fileOrIdentifier[1] == T(':'))
  23316. {
  23317. return File (fileOrIdentifier).getLastModificationTime();
  23318. }
  23319. return Time (0);
  23320. }
  23321. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23322. {
  23323. return t1 != t2 || t1 == Time (0);
  23324. }
  23325. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23326. {
  23327. if (getTypeForFile (fileOrIdentifier) == 0)
  23328. return false;
  23329. for (int i = types.size(); --i >= 0;)
  23330. {
  23331. const PluginDescription* const d = types.getUnchecked(i);
  23332. if (d->fileOrIdentifier == fileOrIdentifier
  23333. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23334. {
  23335. return false;
  23336. }
  23337. }
  23338. return true;
  23339. }
  23340. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23341. const bool dontRescanIfAlreadyInList,
  23342. OwnedArray <PluginDescription>& typesFound,
  23343. AudioPluginFormat& format)
  23344. {
  23345. bool addedOne = false;
  23346. if (dontRescanIfAlreadyInList
  23347. && getTypeForFile (fileOrIdentifier) != 0)
  23348. {
  23349. bool needsRescanning = false;
  23350. for (int i = types.size(); --i >= 0;)
  23351. {
  23352. const PluginDescription* const d = types.getUnchecked(i);
  23353. if (d->fileOrIdentifier == fileOrIdentifier)
  23354. {
  23355. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23356. needsRescanning = true;
  23357. else
  23358. typesFound.add (new PluginDescription (*d));
  23359. }
  23360. }
  23361. if (! needsRescanning)
  23362. return false;
  23363. }
  23364. OwnedArray <PluginDescription> found;
  23365. format.findAllTypesForFile (found, fileOrIdentifier);
  23366. for (int i = 0; i < found.size(); ++i)
  23367. {
  23368. PluginDescription* const desc = found.getUnchecked(i);
  23369. jassert (desc != 0);
  23370. if (addType (*desc))
  23371. addedOne = true;
  23372. typesFound.add (new PluginDescription (*desc));
  23373. }
  23374. return addedOne;
  23375. }
  23376. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23377. OwnedArray <PluginDescription>& typesFound)
  23378. {
  23379. for (int i = 0; i < files.size(); ++i)
  23380. {
  23381. bool loaded = false;
  23382. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23383. {
  23384. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23385. if (scanAndAddFile (files[i], true, typesFound, *format))
  23386. loaded = true;
  23387. }
  23388. if (! loaded)
  23389. {
  23390. const File f (files[i]);
  23391. if (f.isDirectory())
  23392. {
  23393. StringArray s;
  23394. {
  23395. Array<File> subFiles;
  23396. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23397. for (int j = 0; j < subFiles.size(); ++j)
  23398. s.add (subFiles.getReference(j).getFullPathName());
  23399. }
  23400. scanAndAddDragAndDroppedFiles (s, typesFound);
  23401. }
  23402. }
  23403. }
  23404. }
  23405. class PluginSorter
  23406. {
  23407. public:
  23408. KnownPluginList::SortMethod method;
  23409. PluginSorter() throw() {}
  23410. int compareElements (const PluginDescription* const first,
  23411. const PluginDescription* const second) const throw()
  23412. {
  23413. int diff = 0;
  23414. if (method == KnownPluginList::sortByCategory)
  23415. diff = first->category.compareLexicographically (second->category);
  23416. else if (method == KnownPluginList::sortByManufacturer)
  23417. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23418. else if (method == KnownPluginList::sortByFileSystemLocation)
  23419. diff = first->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23420. .upToLastOccurrenceOf (T("/"), false, false)
  23421. .compare (second->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23422. .upToLastOccurrenceOf (T("/"), false, false));
  23423. if (diff == 0)
  23424. diff = first->name.compareLexicographically (second->name);
  23425. return diff;
  23426. }
  23427. };
  23428. void KnownPluginList::sort (const SortMethod method)
  23429. {
  23430. if (method != defaultOrder)
  23431. {
  23432. PluginSorter sorter;
  23433. sorter.method = method;
  23434. types.sort (sorter, true);
  23435. sendChangeMessage (this);
  23436. }
  23437. }
  23438. XmlElement* KnownPluginList::createXml() const
  23439. {
  23440. XmlElement* const e = new XmlElement (T("KNOWNPLUGINS"));
  23441. for (int i = 0; i < types.size(); ++i)
  23442. e->addChildElement (types.getUnchecked(i)->createXml());
  23443. return e;
  23444. }
  23445. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23446. {
  23447. clear();
  23448. if (xml.hasTagName (T("KNOWNPLUGINS")))
  23449. {
  23450. forEachXmlChildElement (xml, e)
  23451. {
  23452. PluginDescription info;
  23453. if (info.loadFromXml (*e))
  23454. addType (info);
  23455. }
  23456. }
  23457. }
  23458. const int menuIdBase = 0x324503f4;
  23459. // This is used to turn a bunch of paths into a nested menu structure.
  23460. struct PluginFilesystemTree
  23461. {
  23462. private:
  23463. String folder;
  23464. OwnedArray <PluginFilesystemTree> subFolders;
  23465. Array <PluginDescription*> plugins;
  23466. void addPlugin (PluginDescription* const pd, const String& path)
  23467. {
  23468. if (path.isEmpty())
  23469. {
  23470. plugins.add (pd);
  23471. }
  23472. else
  23473. {
  23474. const String firstSubFolder (path.upToFirstOccurrenceOf (T("/"), false, false));
  23475. const String remainingPath (path.fromFirstOccurrenceOf (T("/"), false, false));
  23476. for (int i = subFolders.size(); --i >= 0;)
  23477. {
  23478. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23479. {
  23480. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23481. return;
  23482. }
  23483. }
  23484. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23485. newFolder->folder = firstSubFolder;
  23486. subFolders.add (newFolder);
  23487. newFolder->addPlugin (pd, remainingPath);
  23488. }
  23489. }
  23490. // removes any deeply nested folders that don't contain any actual plugins
  23491. void optimise()
  23492. {
  23493. for (int i = subFolders.size(); --i >= 0;)
  23494. {
  23495. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23496. sub->optimise();
  23497. if (sub->plugins.size() == 0)
  23498. {
  23499. for (int j = 0; j < sub->subFolders.size(); ++j)
  23500. subFolders.add (sub->subFolders.getUnchecked(j));
  23501. sub->subFolders.clear (false);
  23502. subFolders.remove (i);
  23503. }
  23504. }
  23505. }
  23506. public:
  23507. void buildTree (const Array <PluginDescription*>& allPlugins)
  23508. {
  23509. for (int i = 0; i < allPlugins.size(); ++i)
  23510. {
  23511. String path (allPlugins.getUnchecked(i)
  23512. ->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23513. .upToLastOccurrenceOf (T("/"), false, false));
  23514. if (path.substring (1, 2) == T(":"))
  23515. path = path.substring (2);
  23516. addPlugin (allPlugins.getUnchecked(i), path);
  23517. }
  23518. optimise();
  23519. }
  23520. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23521. {
  23522. int i;
  23523. for (i = 0; i < subFolders.size(); ++i)
  23524. {
  23525. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23526. PopupMenu subMenu;
  23527. sub->addToMenu (subMenu, allPlugins);
  23528. #if JUCE_MAC
  23529. // avoid the special AU formatting nonsense on Mac..
  23530. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (T(":"), false, false), subMenu);
  23531. #else
  23532. m.addSubMenu (sub->folder, subMenu);
  23533. #endif
  23534. }
  23535. for (i = 0; i < plugins.size(); ++i)
  23536. {
  23537. PluginDescription* const plugin = plugins.getUnchecked(i);
  23538. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23539. plugin->name, true, false);
  23540. }
  23541. }
  23542. };
  23543. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23544. {
  23545. Array <PluginDescription*> sorted;
  23546. {
  23547. PluginSorter sorter;
  23548. sorter.method = sortMethod;
  23549. for (int i = 0; i < types.size(); ++i)
  23550. sorted.addSorted (sorter, types.getUnchecked(i));
  23551. }
  23552. if (sortMethod == sortByCategory
  23553. || sortMethod == sortByManufacturer)
  23554. {
  23555. String lastSubMenuName;
  23556. PopupMenu sub;
  23557. for (int i = 0; i < sorted.size(); ++i)
  23558. {
  23559. const PluginDescription* const pd = sorted.getUnchecked(i);
  23560. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23561. : pd->manufacturerName);
  23562. if (! thisSubMenuName.containsNonWhitespaceChars())
  23563. thisSubMenuName = T("Other");
  23564. if (thisSubMenuName != lastSubMenuName)
  23565. {
  23566. if (sub.getNumItems() > 0)
  23567. {
  23568. menu.addSubMenu (lastSubMenuName, sub);
  23569. sub.clear();
  23570. }
  23571. lastSubMenuName = thisSubMenuName;
  23572. }
  23573. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23574. }
  23575. if (sub.getNumItems() > 0)
  23576. menu.addSubMenu (lastSubMenuName, sub);
  23577. }
  23578. else if (sortMethod == sortByFileSystemLocation)
  23579. {
  23580. PluginFilesystemTree root;
  23581. root.buildTree (sorted);
  23582. root.addToMenu (menu, types);
  23583. }
  23584. else
  23585. {
  23586. for (int i = 0; i < sorted.size(); ++i)
  23587. {
  23588. const PluginDescription* const pd = sorted.getUnchecked(i);
  23589. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23590. }
  23591. }
  23592. }
  23593. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23594. {
  23595. const int i = menuResultCode - menuIdBase;
  23596. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23597. }
  23598. END_JUCE_NAMESPACE
  23599. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23600. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23601. BEGIN_JUCE_NAMESPACE
  23602. PluginDescription::PluginDescription() throw()
  23603. : uid (0),
  23604. isInstrument (false),
  23605. numInputChannels (0),
  23606. numOutputChannels (0)
  23607. {
  23608. }
  23609. PluginDescription::~PluginDescription() throw()
  23610. {
  23611. }
  23612. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23613. : name (other.name),
  23614. pluginFormatName (other.pluginFormatName),
  23615. category (other.category),
  23616. manufacturerName (other.manufacturerName),
  23617. version (other.version),
  23618. fileOrIdentifier (other.fileOrIdentifier),
  23619. lastFileModTime (other.lastFileModTime),
  23620. uid (other.uid),
  23621. isInstrument (other.isInstrument),
  23622. numInputChannels (other.numInputChannels),
  23623. numOutputChannels (other.numOutputChannels)
  23624. {
  23625. }
  23626. PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23627. {
  23628. name = other.name;
  23629. pluginFormatName = other.pluginFormatName;
  23630. category = other.category;
  23631. manufacturerName = other.manufacturerName;
  23632. version = other.version;
  23633. fileOrIdentifier = other.fileOrIdentifier;
  23634. uid = other.uid;
  23635. isInstrument = other.isInstrument;
  23636. lastFileModTime = other.lastFileModTime;
  23637. numInputChannels = other.numInputChannels;
  23638. numOutputChannels = other.numOutputChannels;
  23639. return *this;
  23640. }
  23641. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23642. {
  23643. return fileOrIdentifier == other.fileOrIdentifier
  23644. && uid == other.uid;
  23645. }
  23646. const String PluginDescription::createIdentifierString() const throw()
  23647. {
  23648. return pluginFormatName
  23649. + T("-") + name
  23650. + T("-") + String::toHexString (fileOrIdentifier.hashCode())
  23651. + T("-") + String::toHexString (uid);
  23652. }
  23653. XmlElement* PluginDescription::createXml() const
  23654. {
  23655. XmlElement* const e = new XmlElement (T("PLUGIN"));
  23656. e->setAttribute (T("name"), name);
  23657. e->setAttribute (T("format"), pluginFormatName);
  23658. e->setAttribute (T("category"), category);
  23659. e->setAttribute (T("manufacturer"), manufacturerName);
  23660. e->setAttribute (T("version"), version);
  23661. e->setAttribute (T("file"), fileOrIdentifier);
  23662. e->setAttribute (T("uid"), String::toHexString (uid));
  23663. e->setAttribute (T("isInstrument"), isInstrument);
  23664. e->setAttribute (T("fileTime"), String::toHexString (lastFileModTime.toMilliseconds()));
  23665. e->setAttribute (T("numInputs"), numInputChannels);
  23666. e->setAttribute (T("numOutputs"), numOutputChannels);
  23667. return e;
  23668. }
  23669. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23670. {
  23671. if (xml.hasTagName (T("PLUGIN")))
  23672. {
  23673. name = xml.getStringAttribute (T("name"));
  23674. pluginFormatName = xml.getStringAttribute (T("format"));
  23675. category = xml.getStringAttribute (T("category"));
  23676. manufacturerName = xml.getStringAttribute (T("manufacturer"));
  23677. version = xml.getStringAttribute (T("version"));
  23678. fileOrIdentifier = xml.getStringAttribute (T("file"));
  23679. uid = xml.getStringAttribute (T("uid")).getHexValue32();
  23680. isInstrument = xml.getBoolAttribute (T("isInstrument"), false);
  23681. lastFileModTime = Time (xml.getStringAttribute (T("fileTime")).getHexValue64());
  23682. numInputChannels = xml.getIntAttribute (T("numInputs"));
  23683. numOutputChannels = xml.getIntAttribute (T("numOutputs"));
  23684. return true;
  23685. }
  23686. return false;
  23687. }
  23688. END_JUCE_NAMESPACE
  23689. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23690. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23691. BEGIN_JUCE_NAMESPACE
  23692. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23693. AudioPluginFormat& formatToLookFor,
  23694. FileSearchPath directoriesToSearch,
  23695. const bool recursive,
  23696. const File& deadMansPedalFile_)
  23697. : list (listToAddTo),
  23698. format (formatToLookFor),
  23699. deadMansPedalFile (deadMansPedalFile_),
  23700. nextIndex (0),
  23701. progress (0)
  23702. {
  23703. directoriesToSearch.removeRedundantPaths();
  23704. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23705. // If any plugins have crashed recently when being loaded, move them to the
  23706. // end of the list to give the others a chance to load correctly..
  23707. const StringArray crashedPlugins (getDeadMansPedalFile());
  23708. for (int i = 0; i < crashedPlugins.size(); ++i)
  23709. {
  23710. const String f = crashedPlugins[i];
  23711. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23712. if (f == filesOrIdentifiersToScan[j])
  23713. filesOrIdentifiersToScan.move (j, -1);
  23714. }
  23715. }
  23716. PluginDirectoryScanner::~PluginDirectoryScanner()
  23717. {
  23718. }
  23719. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23720. {
  23721. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23722. }
  23723. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23724. {
  23725. String file (filesOrIdentifiersToScan [nextIndex]);
  23726. if (file.isNotEmpty())
  23727. {
  23728. if (! list.isListingUpToDate (file))
  23729. {
  23730. OwnedArray <PluginDescription> typesFound;
  23731. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23732. StringArray crashedPlugins (getDeadMansPedalFile());
  23733. crashedPlugins.removeString (file);
  23734. crashedPlugins.add (file);
  23735. setDeadMansPedalFile (crashedPlugins);
  23736. list.scanAndAddFile (file,
  23737. dontRescanIfAlreadyInList,
  23738. typesFound,
  23739. format);
  23740. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23741. crashedPlugins.removeString (file);
  23742. setDeadMansPedalFile (crashedPlugins);
  23743. if (typesFound.size() == 0)
  23744. failedFiles.add (file);
  23745. }
  23746. ++nextIndex;
  23747. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23748. }
  23749. return nextIndex < filesOrIdentifiersToScan.size();
  23750. }
  23751. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23752. {
  23753. StringArray lines;
  23754. if (deadMansPedalFile != File::nonexistent)
  23755. {
  23756. lines.addLines (deadMansPedalFile.loadFileAsString());
  23757. lines.removeEmptyStrings();
  23758. }
  23759. return lines;
  23760. }
  23761. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23762. {
  23763. if (deadMansPedalFile != File::nonexistent)
  23764. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23765. }
  23766. END_JUCE_NAMESPACE
  23767. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23768. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  23769. BEGIN_JUCE_NAMESPACE
  23770. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23771. const File& deadMansPedalFile_,
  23772. PropertiesFile* const propertiesToUse_)
  23773. : list (listToEdit),
  23774. deadMansPedalFile (deadMansPedalFile_),
  23775. propertiesToUse (propertiesToUse_)
  23776. {
  23777. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  23778. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  23779. optionsButton->addButtonListener (this);
  23780. optionsButton->setTriggeredOnMouseDown (true);
  23781. setSize (400, 600);
  23782. list.addChangeListener (this);
  23783. }
  23784. PluginListComponent::~PluginListComponent()
  23785. {
  23786. list.removeChangeListener (this);
  23787. deleteAllChildren();
  23788. }
  23789. void PluginListComponent::resized()
  23790. {
  23791. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  23792. optionsButton->changeWidthToFitText (24);
  23793. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  23794. }
  23795. void PluginListComponent::changeListenerCallback (void*)
  23796. {
  23797. listBox->updateContent();
  23798. listBox->repaint();
  23799. }
  23800. int PluginListComponent::getNumRows()
  23801. {
  23802. return list.getNumTypes();
  23803. }
  23804. void PluginListComponent::paintListBoxItem (int row,
  23805. Graphics& g,
  23806. int width, int height,
  23807. bool rowIsSelected)
  23808. {
  23809. if (rowIsSelected)
  23810. g.fillAll (findColour (TextEditor::highlightColourId));
  23811. const PluginDescription* const pd = list.getType (row);
  23812. if (pd != 0)
  23813. {
  23814. GlyphArrangement ga;
  23815. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  23816. g.setColour (Colours::black);
  23817. ga.draw (g);
  23818. float x, y, r, b;
  23819. ga.getBoundingBox (0, -1, x, y, r, b, false);
  23820. String desc;
  23821. desc << pd->pluginFormatName
  23822. << (pd->isInstrument ? " instrument" : " effect")
  23823. << " - "
  23824. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  23825. << " / "
  23826. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  23827. if (pd->manufacturerName.isNotEmpty())
  23828. desc << " - " << pd->manufacturerName;
  23829. if (pd->version.isNotEmpty())
  23830. desc << " - " << pd->version;
  23831. if (pd->category.isNotEmpty())
  23832. desc << " - category: '" << pd->category << '\'';
  23833. g.setColour (Colours::grey);
  23834. ga.clear();
  23835. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, r + 10.0f, height * 0.8f, width - r - 12.0f, true);
  23836. ga.draw (g);
  23837. }
  23838. }
  23839. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  23840. {
  23841. list.removeType (lastRowSelected);
  23842. }
  23843. void PluginListComponent::buttonClicked (Button* b)
  23844. {
  23845. if (optionsButton == b)
  23846. {
  23847. PopupMenu menu;
  23848. menu.addItem (1, TRANS("Clear list"));
  23849. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  23850. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  23851. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  23852. menu.addSeparator();
  23853. menu.addItem (2, TRANS("Sort alphabetically"));
  23854. menu.addItem (3, TRANS("Sort by category"));
  23855. menu.addItem (4, TRANS("Sort by manufacturer"));
  23856. menu.addSeparator();
  23857. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  23858. {
  23859. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  23860. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  23861. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  23862. }
  23863. const int r = menu.showAt (optionsButton);
  23864. if (r == 1)
  23865. {
  23866. list.clear();
  23867. }
  23868. else if (r == 2)
  23869. {
  23870. list.sort (KnownPluginList::sortAlphabetically);
  23871. }
  23872. else if (r == 3)
  23873. {
  23874. list.sort (KnownPluginList::sortByCategory);
  23875. }
  23876. else if (r == 4)
  23877. {
  23878. list.sort (KnownPluginList::sortByManufacturer);
  23879. }
  23880. else if (r == 5)
  23881. {
  23882. const SparseSet <int> selected (listBox->getSelectedRows());
  23883. for (int i = list.getNumTypes(); --i >= 0;)
  23884. if (selected.contains (i))
  23885. list.removeType (i);
  23886. }
  23887. else if (r == 6)
  23888. {
  23889. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  23890. if (desc != 0)
  23891. {
  23892. if (File (desc->fileOrIdentifier).existsAsFile())
  23893. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  23894. }
  23895. }
  23896. else if (r == 7)
  23897. {
  23898. for (int i = list.getNumTypes(); --i >= 0;)
  23899. {
  23900. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  23901. {
  23902. list.removeType (i);
  23903. }
  23904. }
  23905. }
  23906. else if (r != 0)
  23907. {
  23908. typeToScan = r - 10;
  23909. startTimer (1);
  23910. }
  23911. }
  23912. }
  23913. void PluginListComponent::timerCallback()
  23914. {
  23915. stopTimer();
  23916. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  23917. }
  23918. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  23919. {
  23920. return true;
  23921. }
  23922. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  23923. {
  23924. OwnedArray <PluginDescription> typesFound;
  23925. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  23926. }
  23927. void PluginListComponent::scanFor (AudioPluginFormat* format)
  23928. {
  23929. if (format == 0)
  23930. return;
  23931. FileSearchPath path (format->getDefaultLocationsToSearch());
  23932. if (propertiesToUse != 0)
  23933. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23934. {
  23935. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  23936. FileSearchPathListComponent pathList;
  23937. pathList.setSize (500, 300);
  23938. pathList.setPath (path);
  23939. aw.addCustomComponent (&pathList);
  23940. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  23941. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23942. if (aw.runModalLoop() == 0)
  23943. return;
  23944. path = pathList.getPath();
  23945. }
  23946. if (propertiesToUse != 0)
  23947. {
  23948. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23949. propertiesToUse->saveIfNeeded();
  23950. }
  23951. double progress = 0.0;
  23952. AlertWindow aw (TRANS("Scanning for plugins..."),
  23953. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  23954. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23955. aw.addProgressBarComponent (progress);
  23956. aw.enterModalState();
  23957. MessageManager::getInstance()->runDispatchLoopUntil (300);
  23958. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  23959. for (;;)
  23960. {
  23961. aw.setMessage (TRANS("Testing:\n\n")
  23962. + scanner.getNextPluginFileThatWillBeScanned());
  23963. MessageManager::getInstance()->runDispatchLoopUntil (20);
  23964. if (! scanner.scanNextFile (true))
  23965. break;
  23966. if (! aw.isCurrentlyModal())
  23967. break;
  23968. progress = scanner.getProgress();
  23969. }
  23970. if (scanner.getFailedFiles().size() > 0)
  23971. {
  23972. StringArray shortNames;
  23973. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  23974. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  23975. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  23976. TRANS("Scan complete"),
  23977. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  23978. + shortNames.joinIntoString (", "));
  23979. }
  23980. }
  23981. END_JUCE_NAMESPACE
  23982. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  23983. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  23984. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  23985. #include <AudioUnit/AudioUnit.h>
  23986. #include <AudioUnit/AUCocoaUIView.h>
  23987. #include <CoreAudioKit/AUGenericView.h>
  23988. #if JUCE_SUPPORT_CARBON
  23989. #include <AudioToolbox/AudioUnitUtilities.h>
  23990. #include <AudioUnit/AudioUnitCarbonView.h>
  23991. #endif
  23992. BEGIN_JUCE_NAMESPACE
  23993. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  23994. #endif
  23995. #if JUCE_MAC
  23996. // Change this to disable logging of various activities
  23997. #ifndef AU_LOGGING
  23998. #define AU_LOGGING 1
  23999. #endif
  24000. #if AU_LOGGING
  24001. #define log(a) Logger::writeToLog(a);
  24002. #else
  24003. #define log(a)
  24004. #endif
  24005. static int insideCallback = 0;
  24006. static const String osTypeToString (OSType type)
  24007. {
  24008. char s[4];
  24009. s[0] = (char) (((uint32) type) >> 24);
  24010. s[1] = (char) (((uint32) type) >> 16);
  24011. s[2] = (char) (((uint32) type) >> 8);
  24012. s[3] = (char) ((uint32) type);
  24013. return String (s, 4);
  24014. }
  24015. static OSType stringToOSType (const String& s1)
  24016. {
  24017. const String s (s1 + " ");
  24018. return (((OSType) (unsigned char) s[0]) << 24)
  24019. | (((OSType) (unsigned char) s[1]) << 16)
  24020. | (((OSType) (unsigned char) s[2]) << 8)
  24021. | ((OSType) (unsigned char) s[3]);
  24022. }
  24023. static const tchar* auIdentifierPrefix = T("AudioUnit:");
  24024. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24025. {
  24026. jassert (osTypeToString ('abcd') == T("abcd")); // agh, must have got the endianness wrong..
  24027. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24028. String s (auIdentifierPrefix);
  24029. if (desc.componentType == kAudioUnitType_MusicDevice)
  24030. s << "Synths/";
  24031. else if (desc.componentType == kAudioUnitType_MusicEffect
  24032. || desc.componentType == kAudioUnitType_Effect)
  24033. s << "Effects/";
  24034. else if (desc.componentType == kAudioUnitType_Generator)
  24035. s << "Generators/";
  24036. else if (desc.componentType == kAudioUnitType_Panner)
  24037. s << "Panners/";
  24038. s << osTypeToString (desc.componentType) << ","
  24039. << osTypeToString (desc.componentSubType) << ","
  24040. << osTypeToString (desc.componentManufacturer);
  24041. return s;
  24042. }
  24043. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24044. {
  24045. Handle componentNameHandle = NewHandle (sizeof (void*));
  24046. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24047. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24048. {
  24049. ComponentDescription desc;
  24050. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24051. {
  24052. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24053. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24054. if (nameString != 0 && nameString[0] != 0)
  24055. {
  24056. const String all ((const char*) nameString + 1, nameString[0]);
  24057. DBG ("name: "+ all);
  24058. manufacturer = all.upToFirstOccurrenceOf (T(":"), false, false).trim();
  24059. name = all.fromFirstOccurrenceOf (T(":"), false, false).trim();
  24060. }
  24061. if (infoString != 0 && infoString[0] != 0)
  24062. {
  24063. DBG ("info: " + String ((const char*) infoString + 1, infoString[0]));
  24064. }
  24065. if (name.isEmpty())
  24066. name = "<Unknown>";
  24067. }
  24068. DisposeHandle (componentNameHandle);
  24069. DisposeHandle (componentInfoHandle);
  24070. }
  24071. }
  24072. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24073. String& name, String& version, String& manufacturer)
  24074. {
  24075. zerostruct (desc);
  24076. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24077. {
  24078. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (T(':')),
  24079. fileOrIdentifier.lastIndexOfChar (T('/'))) + 1));
  24080. StringArray tokens;
  24081. tokens.addTokens (s, T(","), String::empty);
  24082. tokens.trim();
  24083. tokens.removeEmptyStrings();
  24084. if (tokens.size() == 3)
  24085. {
  24086. desc.componentType = stringToOSType (tokens[0]);
  24087. desc.componentSubType = stringToOSType (tokens[1]);
  24088. desc.componentManufacturer = stringToOSType (tokens[2]);
  24089. ComponentRecord* comp = FindNextComponent (0, &desc);
  24090. if (comp != 0)
  24091. {
  24092. getAUDetails (comp, name, manufacturer);
  24093. return true;
  24094. }
  24095. }
  24096. }
  24097. return false;
  24098. }
  24099. class AudioUnitPluginWindowCarbon;
  24100. class AudioUnitPluginWindowCocoa;
  24101. class AudioUnitPluginInstance : public AudioPluginInstance
  24102. {
  24103. public:
  24104. ~AudioUnitPluginInstance();
  24105. // AudioPluginInstance methods:
  24106. void fillInPluginDescription (PluginDescription& desc) const
  24107. {
  24108. desc.name = pluginName;
  24109. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24110. desc.uid = ((int) componentDesc.componentType)
  24111. ^ ((int) componentDesc.componentSubType)
  24112. ^ ((int) componentDesc.componentManufacturer);
  24113. desc.lastFileModTime = 0;
  24114. desc.pluginFormatName = "AudioUnit";
  24115. desc.category = getCategory();
  24116. desc.manufacturerName = manufacturer;
  24117. desc.version = version;
  24118. desc.numInputChannels = getNumInputChannels();
  24119. desc.numOutputChannels = getNumOutputChannels();
  24120. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24121. }
  24122. const String getName() const { return pluginName; }
  24123. bool acceptsMidi() const { return wantsMidiMessages; }
  24124. bool producesMidi() const { return false; }
  24125. // AudioProcessor methods:
  24126. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24127. void releaseResources();
  24128. void processBlock (AudioSampleBuffer& buffer,
  24129. MidiBuffer& midiMessages);
  24130. AudioProcessorEditor* createEditor();
  24131. const String getInputChannelName (const int index) const;
  24132. bool isInputChannelStereoPair (int index) const;
  24133. const String getOutputChannelName (const int index) const;
  24134. bool isOutputChannelStereoPair (int index) const;
  24135. int getNumParameters();
  24136. float getParameter (int index);
  24137. void setParameter (int index, float newValue);
  24138. const String getParameterName (int index);
  24139. const String getParameterText (int index);
  24140. bool isParameterAutomatable (int index) const;
  24141. int getNumPrograms();
  24142. int getCurrentProgram();
  24143. void setCurrentProgram (int index);
  24144. const String getProgramName (int index);
  24145. void changeProgramName (int index, const String& newName);
  24146. void getStateInformation (MemoryBlock& destData);
  24147. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24148. void setStateInformation (const void* data, int sizeInBytes);
  24149. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24150. juce_UseDebuggingNewOperator
  24151. private:
  24152. friend class AudioUnitPluginWindowCarbon;
  24153. friend class AudioUnitPluginWindowCocoa;
  24154. friend class AudioUnitPluginFormat;
  24155. ComponentDescription componentDesc;
  24156. String pluginName, manufacturer, version;
  24157. String fileOrIdentifier;
  24158. CriticalSection lock;
  24159. bool initialised, wantsMidiMessages, wasPlaying;
  24160. HeapBlock <AudioBufferList> outputBufferList;
  24161. AudioTimeStamp timeStamp;
  24162. AudioSampleBuffer* currentBuffer;
  24163. AudioUnit audioUnit;
  24164. Array <int> parameterIds;
  24165. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24166. void initialise();
  24167. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24168. const AudioTimeStamp* inTimeStamp,
  24169. UInt32 inBusNumber,
  24170. UInt32 inNumberFrames,
  24171. AudioBufferList* ioData) const;
  24172. static OSStatus renderGetInputCallback (void* inRefCon,
  24173. AudioUnitRenderActionFlags* ioActionFlags,
  24174. const AudioTimeStamp* inTimeStamp,
  24175. UInt32 inBusNumber,
  24176. UInt32 inNumberFrames,
  24177. AudioBufferList* ioData)
  24178. {
  24179. return ((AudioUnitPluginInstance*) inRefCon)
  24180. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24181. }
  24182. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24183. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24184. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24185. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24186. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24187. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24188. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24189. {
  24190. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24191. }
  24192. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24193. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24194. Float64* outCurrentMeasureDownBeat)
  24195. {
  24196. return ((AudioUnitPluginInstance*) inHostUserData)
  24197. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24198. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24199. }
  24200. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24201. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24202. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24203. {
  24204. return ((AudioUnitPluginInstance*) inHostUserData)
  24205. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24206. outCurrentSampleInTimeLine, outIsCycling,
  24207. outCycleStartBeat, outCycleEndBeat);
  24208. }
  24209. void getNumChannels (int& numIns, int& numOuts)
  24210. {
  24211. numIns = 0;
  24212. numOuts = 0;
  24213. AUChannelInfo supportedChannels [128];
  24214. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24215. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24216. 0, supportedChannels, &supportedChannelsSize) == noErr
  24217. && supportedChannelsSize > 0)
  24218. {
  24219. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24220. {
  24221. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24222. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24223. }
  24224. }
  24225. else
  24226. {
  24227. // (this really means the plugin will take any number of ins/outs as long
  24228. // as they are the same)
  24229. numIns = numOuts = 2;
  24230. }
  24231. }
  24232. const String getCategory() const;
  24233. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24234. };
  24235. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24236. : fileOrIdentifier (fileOrIdentifier),
  24237. initialised (false),
  24238. wantsMidiMessages (false),
  24239. audioUnit (0),
  24240. currentBuffer (0)
  24241. {
  24242. try
  24243. {
  24244. ++insideCallback;
  24245. log (T("Opening AU: ") + fileOrIdentifier);
  24246. if (getComponentDescFromFile (fileOrIdentifier))
  24247. {
  24248. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24249. if (comp != 0)
  24250. {
  24251. audioUnit = (AudioUnit) OpenComponent (comp);
  24252. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24253. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24254. }
  24255. }
  24256. --insideCallback;
  24257. }
  24258. catch (...)
  24259. {
  24260. --insideCallback;
  24261. }
  24262. }
  24263. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24264. {
  24265. const ScopedLock sl (lock);
  24266. jassert (insideCallback == 0);
  24267. if (audioUnit != 0)
  24268. {
  24269. AudioUnitUninitialize (audioUnit);
  24270. CloseComponent (audioUnit);
  24271. audioUnit = 0;
  24272. }
  24273. }
  24274. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24275. {
  24276. zerostruct (componentDesc);
  24277. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24278. return true;
  24279. const File file (fileOrIdentifier);
  24280. if (! file.hasFileExtension (T(".component")))
  24281. return false;
  24282. const char* const utf8 = fileOrIdentifier.toUTF8();
  24283. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24284. strlen (utf8), file.isDirectory());
  24285. if (url != 0)
  24286. {
  24287. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24288. CFRelease (url);
  24289. if (bundleRef != 0)
  24290. {
  24291. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24292. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24293. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24294. if (pluginName.isEmpty())
  24295. pluginName = file.getFileNameWithoutExtension();
  24296. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24297. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24298. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24299. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24300. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24301. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24302. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24303. UseResFile (resFileId);
  24304. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24305. {
  24306. Handle h = Get1IndResource ('thng', i);
  24307. if (h != 0)
  24308. {
  24309. HLock (h);
  24310. const uint32* const types = (const uint32*) *h;
  24311. if (types[0] == kAudioUnitType_MusicDevice
  24312. || types[0] == kAudioUnitType_MusicEffect
  24313. || types[0] == kAudioUnitType_Effect
  24314. || types[0] == kAudioUnitType_Generator
  24315. || types[0] == kAudioUnitType_Panner)
  24316. {
  24317. componentDesc.componentType = types[0];
  24318. componentDesc.componentSubType = types[1];
  24319. componentDesc.componentManufacturer = types[2];
  24320. break;
  24321. }
  24322. HUnlock (h);
  24323. ReleaseResource (h);
  24324. }
  24325. }
  24326. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24327. CFRelease (bundleRef);
  24328. }
  24329. }
  24330. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24331. }
  24332. void AudioUnitPluginInstance::initialise()
  24333. {
  24334. if (initialised || audioUnit == 0)
  24335. return;
  24336. log (T("Initialising AU: ") + pluginName);
  24337. parameterIds.clear();
  24338. {
  24339. UInt32 paramListSize = 0;
  24340. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24341. 0, 0, &paramListSize);
  24342. if (paramListSize > 0)
  24343. {
  24344. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24345. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24346. 0, &parameterIds.getReference(0), &paramListSize);
  24347. }
  24348. }
  24349. {
  24350. AURenderCallbackStruct info;
  24351. zerostruct (info);
  24352. info.inputProcRefCon = this;
  24353. info.inputProc = renderGetInputCallback;
  24354. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24355. 0, &info, sizeof (info));
  24356. }
  24357. {
  24358. HostCallbackInfo info;
  24359. zerostruct (info);
  24360. info.hostUserData = this;
  24361. info.beatAndTempoProc = getBeatAndTempoCallback;
  24362. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24363. info.transportStateProc = getTransportStateCallback;
  24364. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24365. 0, &info, sizeof (info));
  24366. }
  24367. int numIns, numOuts;
  24368. getNumChannels (numIns, numOuts);
  24369. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24370. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24371. setLatencySamples (0);
  24372. }
  24373. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24374. int samplesPerBlockExpected)
  24375. {
  24376. initialise();
  24377. if (initialised)
  24378. {
  24379. int numIns, numOuts;
  24380. getNumChannels (numIns, numOuts);
  24381. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24382. Float64 latencySecs = 0.0;
  24383. UInt32 latencySize = sizeof (latencySecs);
  24384. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24385. 0, &latencySecs, &latencySize);
  24386. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24387. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24388. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24389. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24390. AudioStreamBasicDescription stream;
  24391. zerostruct (stream);
  24392. stream.mSampleRate = sampleRate_;
  24393. stream.mFormatID = kAudioFormatLinearPCM;
  24394. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24395. stream.mFramesPerPacket = 1;
  24396. stream.mBytesPerPacket = 4;
  24397. stream.mBytesPerFrame = 4;
  24398. stream.mBitsPerChannel = 32;
  24399. stream.mChannelsPerFrame = numIns;
  24400. OSStatus err = AudioUnitSetProperty (audioUnit,
  24401. kAudioUnitProperty_StreamFormat,
  24402. kAudioUnitScope_Input,
  24403. 0, &stream, sizeof (stream));
  24404. stream.mChannelsPerFrame = numOuts;
  24405. err = AudioUnitSetProperty (audioUnit,
  24406. kAudioUnitProperty_StreamFormat,
  24407. kAudioUnitScope_Output,
  24408. 0, &stream, sizeof (stream));
  24409. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24410. outputBufferList->mNumberBuffers = numOuts;
  24411. for (int i = numOuts; --i >= 0;)
  24412. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24413. zerostruct (timeStamp);
  24414. timeStamp.mSampleTime = 0;
  24415. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24416. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24417. currentBuffer = 0;
  24418. wasPlaying = false;
  24419. }
  24420. }
  24421. void AudioUnitPluginInstance::releaseResources()
  24422. {
  24423. if (initialised)
  24424. {
  24425. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24426. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24427. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24428. outputBufferList.free();
  24429. currentBuffer = 0;
  24430. }
  24431. }
  24432. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24433. const AudioTimeStamp* inTimeStamp,
  24434. UInt32 inBusNumber,
  24435. UInt32 inNumberFrames,
  24436. AudioBufferList* ioData) const
  24437. {
  24438. if (inBusNumber == 0
  24439. && currentBuffer != 0)
  24440. {
  24441. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24442. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24443. {
  24444. if (i < currentBuffer->getNumChannels())
  24445. {
  24446. memcpy (ioData->mBuffers[i].mData,
  24447. currentBuffer->getSampleData (i, 0),
  24448. sizeof (float) * inNumberFrames);
  24449. }
  24450. else
  24451. {
  24452. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24453. }
  24454. }
  24455. }
  24456. return noErr;
  24457. }
  24458. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24459. MidiBuffer& midiMessages)
  24460. {
  24461. const int numSamples = buffer.getNumSamples();
  24462. if (initialised)
  24463. {
  24464. AudioUnitRenderActionFlags flags = 0;
  24465. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24466. for (int i = getNumOutputChannels(); --i >= 0;)
  24467. {
  24468. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24469. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24470. }
  24471. currentBuffer = &buffer;
  24472. if (wantsMidiMessages)
  24473. {
  24474. const uint8* midiEventData;
  24475. int midiEventSize, midiEventPosition;
  24476. MidiBuffer::Iterator i (midiMessages);
  24477. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24478. {
  24479. if (midiEventSize <= 3)
  24480. MusicDeviceMIDIEvent (audioUnit,
  24481. midiEventData[0], midiEventData[1], midiEventData[2],
  24482. midiEventPosition);
  24483. else
  24484. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24485. }
  24486. midiMessages.clear();
  24487. }
  24488. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24489. 0, numSamples, outputBufferList);
  24490. timeStamp.mSampleTime += numSamples;
  24491. }
  24492. else
  24493. {
  24494. // Not initialised, so just bypass..
  24495. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24496. buffer.clear (i, 0, buffer.getNumSamples());
  24497. }
  24498. }
  24499. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24500. {
  24501. AudioPlayHead* const ph = getPlayHead();
  24502. AudioPlayHead::CurrentPositionInfo result;
  24503. if (ph != 0 && ph->getCurrentPosition (result))
  24504. {
  24505. if (outCurrentBeat != 0)
  24506. *outCurrentBeat = result.ppqPosition;
  24507. if (outCurrentTempo != 0)
  24508. *outCurrentTempo = result.bpm;
  24509. }
  24510. else
  24511. {
  24512. if (outCurrentBeat != 0)
  24513. *outCurrentBeat = 0;
  24514. if (outCurrentTempo != 0)
  24515. *outCurrentTempo = 120.0;
  24516. }
  24517. return noErr;
  24518. }
  24519. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24520. Float32* outTimeSig_Numerator,
  24521. UInt32* outTimeSig_Denominator,
  24522. Float64* outCurrentMeasureDownBeat) const
  24523. {
  24524. AudioPlayHead* const ph = getPlayHead();
  24525. AudioPlayHead::CurrentPositionInfo result;
  24526. if (ph != 0 && ph->getCurrentPosition (result))
  24527. {
  24528. if (outTimeSig_Numerator != 0)
  24529. *outTimeSig_Numerator = result.timeSigNumerator;
  24530. if (outTimeSig_Denominator != 0)
  24531. *outTimeSig_Denominator = result.timeSigDenominator;
  24532. if (outDeltaSampleOffsetToNextBeat != 0)
  24533. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24534. if (outCurrentMeasureDownBeat != 0)
  24535. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24536. }
  24537. else
  24538. {
  24539. if (outDeltaSampleOffsetToNextBeat != 0)
  24540. *outDeltaSampleOffsetToNextBeat = 0;
  24541. if (outTimeSig_Numerator != 0)
  24542. *outTimeSig_Numerator = 4;
  24543. if (outTimeSig_Denominator != 0)
  24544. *outTimeSig_Denominator = 4;
  24545. if (outCurrentMeasureDownBeat != 0)
  24546. *outCurrentMeasureDownBeat = 0;
  24547. }
  24548. return noErr;
  24549. }
  24550. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24551. Boolean* outTransportStateChanged,
  24552. Float64* outCurrentSampleInTimeLine,
  24553. Boolean* outIsCycling,
  24554. Float64* outCycleStartBeat,
  24555. Float64* outCycleEndBeat)
  24556. {
  24557. AudioPlayHead* const ph = getPlayHead();
  24558. AudioPlayHead::CurrentPositionInfo result;
  24559. if (ph != 0 && ph->getCurrentPosition (result))
  24560. {
  24561. if (outIsPlaying != 0)
  24562. *outIsPlaying = result.isPlaying;
  24563. if (outTransportStateChanged != 0)
  24564. {
  24565. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24566. wasPlaying = result.isPlaying;
  24567. }
  24568. if (outCurrentSampleInTimeLine != 0)
  24569. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24570. if (outIsCycling != 0)
  24571. *outIsCycling = false;
  24572. if (outCycleStartBeat != 0)
  24573. *outCycleStartBeat = 0;
  24574. if (outCycleEndBeat != 0)
  24575. *outCycleEndBeat = 0;
  24576. }
  24577. else
  24578. {
  24579. if (outIsPlaying != 0)
  24580. *outIsPlaying = false;
  24581. if (outTransportStateChanged != 0)
  24582. *outTransportStateChanged = false;
  24583. if (outCurrentSampleInTimeLine != 0)
  24584. *outCurrentSampleInTimeLine = 0;
  24585. if (outIsCycling != 0)
  24586. *outIsCycling = false;
  24587. if (outCycleStartBeat != 0)
  24588. *outCycleStartBeat = 0;
  24589. if (outCycleEndBeat != 0)
  24590. *outCycleEndBeat = 0;
  24591. }
  24592. return noErr;
  24593. }
  24594. static VoidArray activeWindows;
  24595. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24596. {
  24597. public:
  24598. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24599. : AudioProcessorEditor (&plugin_),
  24600. plugin (plugin_),
  24601. wrapper (0)
  24602. {
  24603. addAndMakeVisible (wrapper = new NSViewComponent());
  24604. activeWindows.add (this);
  24605. setOpaque (true);
  24606. setVisible (true);
  24607. setSize (100, 100);
  24608. createView (createGenericViewIfNeeded);
  24609. }
  24610. ~AudioUnitPluginWindowCocoa()
  24611. {
  24612. const bool wasValid = isValid();
  24613. wrapper->setView (0);
  24614. activeWindows.removeValue (this);
  24615. if (wasValid)
  24616. plugin.editorBeingDeleted (this);
  24617. delete wrapper;
  24618. }
  24619. bool isValid() const { return wrapper->getView() != 0; }
  24620. void paint (Graphics& g)
  24621. {
  24622. g.fillAll (Colours::white);
  24623. }
  24624. void resized()
  24625. {
  24626. wrapper->setSize (getWidth(), getHeight());
  24627. }
  24628. private:
  24629. AudioUnitPluginInstance& plugin;
  24630. NSViewComponent* wrapper;
  24631. bool createView (const bool createGenericViewIfNeeded)
  24632. {
  24633. NSView* pluginView = 0;
  24634. UInt32 dataSize = 0;
  24635. Boolean isWritable = false;
  24636. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24637. 0, &dataSize, &isWritable) == noErr
  24638. && dataSize != 0
  24639. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24640. 0, &dataSize, &isWritable) == noErr)
  24641. {
  24642. HeapBlock <AudioUnitCocoaViewInfo> info;
  24643. info.calloc (dataSize, 1);
  24644. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24645. 0, info, &dataSize) == noErr)
  24646. {
  24647. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24648. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24649. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24650. Class viewClass = [viewBundle classNamed: viewClassName];
  24651. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24652. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24653. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24654. {
  24655. id factory = [[[viewClass alloc] init] autorelease];
  24656. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24657. withSize: NSMakeSize (getWidth(), getHeight())];
  24658. }
  24659. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24660. {
  24661. CFRelease (info->mCocoaAUViewClass[i]);
  24662. CFRelease (info->mCocoaAUViewBundleLocation);
  24663. }
  24664. }
  24665. }
  24666. if (createGenericViewIfNeeded && (pluginView == 0))
  24667. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24668. wrapper->setView (pluginView);
  24669. if (pluginView != 0)
  24670. setSize ([pluginView frame].size.width,
  24671. [pluginView frame].size.height);
  24672. return pluginView != 0;
  24673. }
  24674. };
  24675. #if JUCE_SUPPORT_CARBON
  24676. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24677. {
  24678. public:
  24679. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24680. : AudioProcessorEditor (&plugin_),
  24681. plugin (plugin_),
  24682. viewComponent (0)
  24683. {
  24684. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24685. activeWindows.add (this);
  24686. setOpaque (true);
  24687. setVisible (true);
  24688. setSize (400, 300);
  24689. ComponentDescription viewList [16];
  24690. UInt32 viewListSize = sizeof (viewList);
  24691. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24692. 0, &viewList, &viewListSize);
  24693. componentRecord = FindNextComponent (0, &viewList[0]);
  24694. }
  24695. ~AudioUnitPluginWindowCarbon()
  24696. {
  24697. innerWrapper = 0;
  24698. activeWindows.removeValue (this);
  24699. if (isValid())
  24700. plugin.editorBeingDeleted (this);
  24701. }
  24702. bool isValid() const throw() { return componentRecord != 0; }
  24703. void paint (Graphics& g)
  24704. {
  24705. g.fillAll (Colours::black);
  24706. }
  24707. void resized()
  24708. {
  24709. innerWrapper->setSize (getWidth(), getHeight());
  24710. }
  24711. bool keyStateChanged (const bool)
  24712. {
  24713. return false;
  24714. }
  24715. bool keyPressed (const KeyPress&)
  24716. {
  24717. return false;
  24718. }
  24719. void broughtToFront()
  24720. {
  24721. activeWindows.removeValue (this);
  24722. activeWindows.add (this);
  24723. }
  24724. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24725. AudioUnitCarbonView getViewComponent()
  24726. {
  24727. if (viewComponent == 0 && componentRecord != 0)
  24728. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24729. return viewComponent;
  24730. }
  24731. void closeViewComponent()
  24732. {
  24733. if (viewComponent != 0)
  24734. {
  24735. CloseComponent (viewComponent);
  24736. viewComponent = 0;
  24737. }
  24738. }
  24739. juce_UseDebuggingNewOperator
  24740. private:
  24741. AudioUnitPluginInstance& plugin;
  24742. ComponentRecord* componentRecord;
  24743. AudioUnitCarbonView viewComponent;
  24744. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24745. {
  24746. public:
  24747. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24748. : owner (owner_)
  24749. {
  24750. }
  24751. ~InnerWrapperComponent()
  24752. {
  24753. deleteWindow();
  24754. }
  24755. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24756. {
  24757. log (T("Opening AU GUI: ") + owner->plugin.getName());
  24758. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24759. if (viewComponent == 0)
  24760. return 0;
  24761. Float32Point pos = { 0, 0 };
  24762. Float32Point size = { 250, 200 };
  24763. HIViewRef pluginView = 0;
  24764. AudioUnitCarbonViewCreate (viewComponent,
  24765. owner->getAudioUnit(),
  24766. windowRef,
  24767. rootView,
  24768. &pos,
  24769. &size,
  24770. (ControlRef*) &pluginView);
  24771. return pluginView;
  24772. }
  24773. void removeView (HIViewRef)
  24774. {
  24775. log (T("Closing AU GUI: ") + owner->plugin.getName());
  24776. owner->closeViewComponent();
  24777. }
  24778. private:
  24779. AudioUnitPluginWindowCarbon* const owner;
  24780. };
  24781. friend class InnerWrapperComponent;
  24782. ScopedPointer<InnerWrapperComponent> innerWrapper;
  24783. };
  24784. #endif
  24785. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  24786. {
  24787. ScopedPointer <AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  24788. if (! static_cast <AudioUnitPluginWindowCocoa*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24789. w = 0;
  24790. #if JUCE_SUPPORT_CARBON
  24791. if (w == 0)
  24792. {
  24793. w = new AudioUnitPluginWindowCarbon (*this);
  24794. if (! static_cast <AudioUnitPluginWindowCocoa*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24795. w = 0;
  24796. }
  24797. #endif
  24798. if (w == 0)
  24799. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  24800. return w.release();
  24801. }
  24802. const String AudioUnitPluginInstance::getCategory() const
  24803. {
  24804. const char* result = 0;
  24805. switch (componentDesc.componentType)
  24806. {
  24807. case kAudioUnitType_Effect:
  24808. case kAudioUnitType_MusicEffect:
  24809. result = "Effect";
  24810. break;
  24811. case kAudioUnitType_MusicDevice:
  24812. result = "Synth";
  24813. break;
  24814. case kAudioUnitType_Generator:
  24815. result = "Generator";
  24816. break;
  24817. case kAudioUnitType_Panner:
  24818. result = "Panner";
  24819. break;
  24820. default:
  24821. break;
  24822. }
  24823. return result;
  24824. }
  24825. int AudioUnitPluginInstance::getNumParameters()
  24826. {
  24827. return parameterIds.size();
  24828. }
  24829. float AudioUnitPluginInstance::getParameter (int index)
  24830. {
  24831. const ScopedLock sl (lock);
  24832. Float32 value = 0.0f;
  24833. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24834. {
  24835. AudioUnitGetParameter (audioUnit,
  24836. (UInt32) parameterIds.getUnchecked (index),
  24837. kAudioUnitScope_Global, 0,
  24838. &value);
  24839. }
  24840. return value;
  24841. }
  24842. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  24843. {
  24844. const ScopedLock sl (lock);
  24845. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24846. {
  24847. AudioUnitSetParameter (audioUnit,
  24848. (UInt32) parameterIds.getUnchecked (index),
  24849. kAudioUnitScope_Global, 0,
  24850. newValue, 0);
  24851. }
  24852. }
  24853. const String AudioUnitPluginInstance::getParameterName (int index)
  24854. {
  24855. AudioUnitParameterInfo info;
  24856. zerostruct (info);
  24857. UInt32 sz = sizeof (info);
  24858. String name;
  24859. if (AudioUnitGetProperty (audioUnit,
  24860. kAudioUnitProperty_ParameterInfo,
  24861. kAudioUnitScope_Global,
  24862. parameterIds [index], &info, &sz) == noErr)
  24863. {
  24864. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  24865. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  24866. else
  24867. name = String (info.name, sizeof (info.name));
  24868. }
  24869. return name;
  24870. }
  24871. const String AudioUnitPluginInstance::getParameterText (int index)
  24872. {
  24873. return String (getParameter (index));
  24874. }
  24875. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  24876. {
  24877. AudioUnitParameterInfo info;
  24878. UInt32 sz = sizeof (info);
  24879. if (AudioUnitGetProperty (audioUnit,
  24880. kAudioUnitProperty_ParameterInfo,
  24881. kAudioUnitScope_Global,
  24882. parameterIds [index], &info, &sz) == noErr)
  24883. {
  24884. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  24885. }
  24886. return true;
  24887. }
  24888. int AudioUnitPluginInstance::getNumPrograms()
  24889. {
  24890. CFArrayRef presets;
  24891. UInt32 sz = sizeof (CFArrayRef);
  24892. int num = 0;
  24893. if (AudioUnitGetProperty (audioUnit,
  24894. kAudioUnitProperty_FactoryPresets,
  24895. kAudioUnitScope_Global,
  24896. 0, &presets, &sz) == noErr)
  24897. {
  24898. num = (int) CFArrayGetCount (presets);
  24899. CFRelease (presets);
  24900. }
  24901. return num;
  24902. }
  24903. int AudioUnitPluginInstance::getCurrentProgram()
  24904. {
  24905. AUPreset current;
  24906. current.presetNumber = 0;
  24907. UInt32 sz = sizeof (AUPreset);
  24908. AudioUnitGetProperty (audioUnit,
  24909. kAudioUnitProperty_FactoryPresets,
  24910. kAudioUnitScope_Global,
  24911. 0, &current, &sz);
  24912. return current.presetNumber;
  24913. }
  24914. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  24915. {
  24916. AUPreset current;
  24917. current.presetNumber = newIndex;
  24918. current.presetName = 0;
  24919. AudioUnitSetProperty (audioUnit,
  24920. kAudioUnitProperty_FactoryPresets,
  24921. kAudioUnitScope_Global,
  24922. 0, &current, sizeof (AUPreset));
  24923. }
  24924. const String AudioUnitPluginInstance::getProgramName (int index)
  24925. {
  24926. String s;
  24927. CFArrayRef presets;
  24928. UInt32 sz = sizeof (CFArrayRef);
  24929. if (AudioUnitGetProperty (audioUnit,
  24930. kAudioUnitProperty_FactoryPresets,
  24931. kAudioUnitScope_Global,
  24932. 0, &presets, &sz) == noErr)
  24933. {
  24934. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  24935. {
  24936. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  24937. if (p != 0 && p->presetNumber == index)
  24938. {
  24939. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  24940. break;
  24941. }
  24942. }
  24943. CFRelease (presets);
  24944. }
  24945. return s;
  24946. }
  24947. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  24948. {
  24949. jassertfalse // xxx not implemented!
  24950. }
  24951. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  24952. {
  24953. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  24954. return T("Input ") + String (index + 1);
  24955. return String::empty;
  24956. }
  24957. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  24958. {
  24959. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  24960. return false;
  24961. return true;
  24962. }
  24963. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  24964. {
  24965. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  24966. return T("Output ") + String (index + 1);
  24967. return String::empty;
  24968. }
  24969. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  24970. {
  24971. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  24972. return false;
  24973. return true;
  24974. }
  24975. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  24976. {
  24977. getCurrentProgramStateInformation (destData);
  24978. }
  24979. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  24980. {
  24981. CFPropertyListRef propertyList = 0;
  24982. UInt32 sz = sizeof (CFPropertyListRef);
  24983. if (AudioUnitGetProperty (audioUnit,
  24984. kAudioUnitProperty_ClassInfo,
  24985. kAudioUnitScope_Global,
  24986. 0, &propertyList, &sz) == noErr)
  24987. {
  24988. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  24989. CFWriteStreamOpen (stream);
  24990. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  24991. CFWriteStreamClose (stream);
  24992. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  24993. destData.setSize (bytesWritten);
  24994. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  24995. CFRelease (data);
  24996. CFRelease (stream);
  24997. CFRelease (propertyList);
  24998. }
  24999. }
  25000. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  25001. {
  25002. setCurrentProgramStateInformation (data, sizeInBytes);
  25003. }
  25004. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  25005. {
  25006. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  25007. (const UInt8*) data,
  25008. sizeInBytes,
  25009. kCFAllocatorNull);
  25010. CFReadStreamOpen (stream);
  25011. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  25012. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  25013. stream,
  25014. 0,
  25015. kCFPropertyListImmutable,
  25016. &format,
  25017. 0);
  25018. CFRelease (stream);
  25019. if (propertyList != 0)
  25020. AudioUnitSetProperty (audioUnit,
  25021. kAudioUnitProperty_ClassInfo,
  25022. kAudioUnitScope_Global,
  25023. 0, &propertyList, sizeof (propertyList));
  25024. }
  25025. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25026. {
  25027. }
  25028. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25029. {
  25030. }
  25031. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25032. const String& fileOrIdentifier)
  25033. {
  25034. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25035. return;
  25036. PluginDescription desc;
  25037. desc.fileOrIdentifier = fileOrIdentifier;
  25038. desc.uid = 0;
  25039. try
  25040. {
  25041. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25042. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25043. if (auInstance != 0)
  25044. {
  25045. auInstance->fillInPluginDescription (desc);
  25046. results.add (new PluginDescription (desc));
  25047. }
  25048. }
  25049. catch (...)
  25050. {
  25051. // crashed while loading...
  25052. }
  25053. }
  25054. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25055. {
  25056. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25057. {
  25058. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25059. if (result->audioUnit != 0)
  25060. {
  25061. result->initialise();
  25062. return result.release();
  25063. }
  25064. }
  25065. return 0;
  25066. }
  25067. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25068. const bool /*recursive*/)
  25069. {
  25070. StringArray result;
  25071. ComponentRecord* comp = 0;
  25072. ComponentDescription desc;
  25073. zerostruct (desc);
  25074. for (;;)
  25075. {
  25076. zerostruct (desc);
  25077. comp = FindNextComponent (comp, &desc);
  25078. if (comp == 0)
  25079. break;
  25080. GetComponentInfo (comp, &desc, 0, 0, 0);
  25081. if (desc.componentType == kAudioUnitType_MusicDevice
  25082. || desc.componentType == kAudioUnitType_MusicEffect
  25083. || desc.componentType == kAudioUnitType_Effect
  25084. || desc.componentType == kAudioUnitType_Generator
  25085. || desc.componentType == kAudioUnitType_Panner)
  25086. {
  25087. const String s (createAUPluginIdentifier (desc));
  25088. DBG (s);
  25089. result.add (s);
  25090. }
  25091. }
  25092. return result;
  25093. }
  25094. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25095. {
  25096. ComponentDescription desc;
  25097. String name, version, manufacturer;
  25098. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25099. return FindNextComponent (0, &desc) != 0;
  25100. const File f (fileOrIdentifier);
  25101. return f.hasFileExtension (T(".component"))
  25102. && f.isDirectory();
  25103. }
  25104. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25105. {
  25106. ComponentDescription desc;
  25107. String name, version, manufacturer;
  25108. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25109. if (name.isEmpty())
  25110. name = fileOrIdentifier;
  25111. return name;
  25112. }
  25113. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25114. {
  25115. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25116. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25117. else
  25118. return File (desc.fileOrIdentifier).exists();
  25119. }
  25120. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25121. {
  25122. return FileSearchPath ("/(Default AudioUnit locations)");
  25123. }
  25124. #endif
  25125. END_JUCE_NAMESPACE
  25126. #undef log
  25127. #endif
  25128. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25129. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25130. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25131. #define JUCE_MAC_VST_INCLUDED 1
  25132. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25133. #if JUCE_PLUGINHOST_VST
  25134. #if (defined (_WIN32) || defined (_WIN64))
  25135. #undef _WIN32_WINNT
  25136. #define _WIN32_WINNT 0x500
  25137. #undef STRICT
  25138. #define STRICT
  25139. #include <windows.h>
  25140. #include <float.h>
  25141. #pragma warning (disable : 4312 4355)
  25142. #elif defined (LINUX) || defined (__linux__)
  25143. #include <float.h>
  25144. #include <sys/time.h>
  25145. #include <X11/Xlib.h>
  25146. #include <X11/Xutil.h>
  25147. #include <X11/Xatom.h>
  25148. #undef Font
  25149. #undef KeyPress
  25150. #undef Drawable
  25151. #undef Time
  25152. #else
  25153. #ifndef JUCE_MAC_VST_INCLUDED
  25154. // On the mac, this file needs to be compiled indirectly, by using
  25155. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25156. #error
  25157. #endif
  25158. #include <Cocoa/Cocoa.h>
  25159. #include <Carbon/Carbon.h>
  25160. #endif
  25161. #if ! (JUCE_MAC && JUCE_64BIT)
  25162. BEGIN_JUCE_NAMESPACE
  25163. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25164. #endif
  25165. #undef PRAGMA_ALIGN_SUPPORTED
  25166. #define VST_FORCE_DEPRECATED 0
  25167. #ifdef _MSC_VER
  25168. #pragma warning (push)
  25169. #pragma warning (disable: 4996)
  25170. #endif
  25171. #include "pluginterfaces/vst2.x/aeffectx.h"
  25172. #ifdef _MSC_VER
  25173. #pragma warning (pop)
  25174. #endif
  25175. #if JUCE_LINUX
  25176. #define Font JUCE_NAMESPACE::Font
  25177. #define KeyPress JUCE_NAMESPACE::KeyPress
  25178. #define Drawable JUCE_NAMESPACE::Drawable
  25179. #define Time JUCE_NAMESPACE::Time
  25180. #endif
  25181. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25182. #ifdef __aeffect__
  25183. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25184. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25185. class VSTMidiEventList
  25186. {
  25187. public:
  25188. VSTMidiEventList()
  25189. : numEventsUsed (0), numEventsAllocated (0)
  25190. {
  25191. }
  25192. ~VSTMidiEventList()
  25193. {
  25194. freeEvents();
  25195. }
  25196. void clear()
  25197. {
  25198. numEventsUsed = 0;
  25199. if (events != 0)
  25200. events->numEvents = 0;
  25201. }
  25202. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25203. {
  25204. ensureSize (numEventsUsed + 1);
  25205. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25206. events->numEvents = ++numEventsUsed;
  25207. if (numBytes <= 4)
  25208. {
  25209. if (e->type == kVstSysExType)
  25210. {
  25211. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25212. e->type = kVstMidiType;
  25213. e->byteSize = sizeof (VstMidiEvent);
  25214. e->noteLength = 0;
  25215. e->noteOffset = 0;
  25216. e->detune = 0;
  25217. e->noteOffVelocity = 0;
  25218. }
  25219. e->deltaFrames = frameOffset;
  25220. memcpy (e->midiData, midiData, numBytes);
  25221. }
  25222. else
  25223. {
  25224. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25225. if (se->type == kVstSysExType)
  25226. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25227. else
  25228. se->sysexDump = (char*) juce_malloc (numBytes);
  25229. memcpy (se->sysexDump, midiData, numBytes);
  25230. se->type = kVstSysExType;
  25231. se->byteSize = sizeof (VstMidiSysexEvent);
  25232. se->deltaFrames = frameOffset;
  25233. se->flags = 0;
  25234. se->dumpBytes = numBytes;
  25235. se->resvd1 = 0;
  25236. se->resvd2 = 0;
  25237. }
  25238. }
  25239. // Handy method to pull the events out of an event buffer supplied by the host
  25240. // or plugin.
  25241. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25242. {
  25243. for (int i = 0; i < events->numEvents; ++i)
  25244. {
  25245. const VstEvent* const e = events->events[i];
  25246. if (e != 0)
  25247. {
  25248. if (e->type == kVstMidiType)
  25249. {
  25250. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25251. 4, e->deltaFrames);
  25252. }
  25253. else if (e->type == kVstSysExType)
  25254. {
  25255. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25256. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25257. e->deltaFrames);
  25258. }
  25259. }
  25260. }
  25261. }
  25262. void ensureSize (int numEventsNeeded)
  25263. {
  25264. if (numEventsNeeded > numEventsAllocated)
  25265. {
  25266. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25267. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25268. if (events == 0)
  25269. events.calloc (size, 1);
  25270. else
  25271. events.realloc (size, 1);
  25272. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25273. {
  25274. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25275. (int) sizeof (VstMidiSysexEvent)));
  25276. e->type = kVstMidiType;
  25277. e->byteSize = sizeof (VstMidiEvent);
  25278. events->events[i] = (VstEvent*) e;
  25279. }
  25280. numEventsAllocated = numEventsNeeded;
  25281. }
  25282. }
  25283. void freeEvents()
  25284. {
  25285. if (events != 0)
  25286. {
  25287. for (int i = numEventsAllocated; --i >= 0;)
  25288. {
  25289. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25290. if (e->type == kVstSysExType)
  25291. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25292. juce_free (e);
  25293. }
  25294. events.free();
  25295. numEventsUsed = 0;
  25296. numEventsAllocated = 0;
  25297. }
  25298. }
  25299. HeapBlock <VstEvents> events;
  25300. private:
  25301. int numEventsUsed, numEventsAllocated;
  25302. };
  25303. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25304. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25305. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25306. #if ! JUCE_WIN32
  25307. static void _fpreset() {}
  25308. static void _clearfp() {}
  25309. #endif
  25310. extern void juce_callAnyTimersSynchronously();
  25311. const int fxbVersionNum = 1;
  25312. struct fxProgram
  25313. {
  25314. long chunkMagic; // 'CcnK'
  25315. long byteSize; // of this chunk, excl. magic + byteSize
  25316. long fxMagic; // 'FxCk'
  25317. long version;
  25318. long fxID; // fx unique id
  25319. long fxVersion;
  25320. long numParams;
  25321. char prgName[28];
  25322. float params[1]; // variable no. of parameters
  25323. };
  25324. struct fxSet
  25325. {
  25326. long chunkMagic; // 'CcnK'
  25327. long byteSize; // of this chunk, excl. magic + byteSize
  25328. long fxMagic; // 'FxBk'
  25329. long version;
  25330. long fxID; // fx unique id
  25331. long fxVersion;
  25332. long numPrograms;
  25333. char future[128];
  25334. fxProgram programs[1]; // variable no. of programs
  25335. };
  25336. struct fxChunkSet
  25337. {
  25338. long chunkMagic; // 'CcnK'
  25339. long byteSize; // of this chunk, excl. magic + byteSize
  25340. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25341. long version;
  25342. long fxID; // fx unique id
  25343. long fxVersion;
  25344. long numPrograms;
  25345. char future[128];
  25346. long chunkSize;
  25347. char chunk[8]; // variable
  25348. };
  25349. struct fxProgramSet
  25350. {
  25351. long chunkMagic; // 'CcnK'
  25352. long byteSize; // of this chunk, excl. magic + byteSize
  25353. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25354. long version;
  25355. long fxID; // fx unique id
  25356. long fxVersion;
  25357. long numPrograms;
  25358. char name[28];
  25359. long chunkSize;
  25360. char chunk[8]; // variable
  25361. };
  25362. static long vst_swap (const long x) throw()
  25363. {
  25364. #ifdef JUCE_LITTLE_ENDIAN
  25365. return (long) ByteOrder::swap ((uint32) x);
  25366. #else
  25367. return x;
  25368. #endif
  25369. }
  25370. static float vst_swapFloat (const float x) throw()
  25371. {
  25372. #ifdef JUCE_LITTLE_ENDIAN
  25373. union { uint32 asInt; float asFloat; } n;
  25374. n.asFloat = x;
  25375. n.asInt = ByteOrder::swap (n.asInt);
  25376. return n.asFloat;
  25377. #else
  25378. return x;
  25379. #endif
  25380. }
  25381. typedef AEffect* (*MainCall) (audioMasterCallback);
  25382. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25383. static int shellUIDToCreate = 0;
  25384. static int insideVSTCallback = 0;
  25385. class VSTPluginWindow;
  25386. // Change this to disable logging of various VST activities
  25387. #ifndef VST_LOGGING
  25388. #define VST_LOGGING 1
  25389. #endif
  25390. #if VST_LOGGING
  25391. #define log(a) Logger::writeToLog(a);
  25392. #else
  25393. #define log(a)
  25394. #endif
  25395. #if JUCE_MAC && JUCE_PPC
  25396. static void* NewCFMFromMachO (void* const machofp) throw()
  25397. {
  25398. void* result = juce_malloc (8);
  25399. ((void**) result)[0] = machofp;
  25400. ((void**) result)[1] = result;
  25401. return result;
  25402. }
  25403. #endif
  25404. #if JUCE_LINUX
  25405. extern Display* display;
  25406. extern XContext improbableNumber;
  25407. typedef void (*EventProcPtr) (XEvent* ev);
  25408. static bool xErrorTriggered;
  25409. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25410. {
  25411. xErrorTriggered = true;
  25412. return 0;
  25413. }
  25414. static int getPropertyFromXWindow (Window handle, Atom atom)
  25415. {
  25416. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25417. xErrorTriggered = false;
  25418. int userSize;
  25419. unsigned long bytes, userCount;
  25420. unsigned char* data;
  25421. Atom userType;
  25422. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25423. &userType, &userSize, &userCount, &bytes, &data);
  25424. XSetErrorHandler (oldErrorHandler);
  25425. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25426. : 0;
  25427. }
  25428. static Window getChildWindow (Window windowToCheck)
  25429. {
  25430. Window rootWindow, parentWindow;
  25431. Window* childWindows;
  25432. unsigned int numChildren;
  25433. XQueryTree (display,
  25434. windowToCheck,
  25435. &rootWindow,
  25436. &parentWindow,
  25437. &childWindows,
  25438. &numChildren);
  25439. if (numChildren > 0)
  25440. return childWindows [0];
  25441. return 0;
  25442. }
  25443. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25444. {
  25445. if (e.mods.isLeftButtonDown())
  25446. {
  25447. ev.xbutton.button = Button1;
  25448. ev.xbutton.state |= Button1Mask;
  25449. }
  25450. else if (e.mods.isRightButtonDown())
  25451. {
  25452. ev.xbutton.button = Button3;
  25453. ev.xbutton.state |= Button3Mask;
  25454. }
  25455. else if (e.mods.isMiddleButtonDown())
  25456. {
  25457. ev.xbutton.button = Button2;
  25458. ev.xbutton.state |= Button2Mask;
  25459. }
  25460. }
  25461. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25462. {
  25463. if (e.mods.isLeftButtonDown())
  25464. ev.xmotion.state |= Button1Mask;
  25465. else if (e.mods.isRightButtonDown())
  25466. ev.xmotion.state |= Button3Mask;
  25467. else if (e.mods.isMiddleButtonDown())
  25468. ev.xmotion.state |= Button2Mask;
  25469. }
  25470. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25471. {
  25472. if (e.mods.isLeftButtonDown())
  25473. ev.xcrossing.state |= Button1Mask;
  25474. else if (e.mods.isRightButtonDown())
  25475. ev.xcrossing.state |= Button3Mask;
  25476. else if (e.mods.isMiddleButtonDown())
  25477. ev.xcrossing.state |= Button2Mask;
  25478. }
  25479. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25480. {
  25481. if (increment < 0)
  25482. {
  25483. ev.xbutton.button = Button5;
  25484. ev.xbutton.state |= Button5Mask;
  25485. }
  25486. else if (increment > 0)
  25487. {
  25488. ev.xbutton.button = Button4;
  25489. ev.xbutton.state |= Button4Mask;
  25490. }
  25491. }
  25492. #endif
  25493. static VoidArray activeModules;
  25494. class ModuleHandle : public ReferenceCountedObject
  25495. {
  25496. public:
  25497. File file;
  25498. MainCall moduleMain;
  25499. String pluginName;
  25500. static ModuleHandle* findOrCreateModule (const File& file)
  25501. {
  25502. for (int i = activeModules.size(); --i >= 0;)
  25503. {
  25504. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25505. if (module->file == file)
  25506. return module;
  25507. }
  25508. _fpreset(); // (doesn't do any harm)
  25509. ++insideVSTCallback;
  25510. shellUIDToCreate = 0;
  25511. log ("Attempting to load VST: " + file.getFullPathName());
  25512. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25513. if (! m->open())
  25514. m = 0;
  25515. --insideVSTCallback;
  25516. _fpreset(); // (doesn't do any harm)
  25517. return m.release();
  25518. }
  25519. ModuleHandle (const File& file_)
  25520. : file (file_),
  25521. moduleMain (0),
  25522. #if JUCE_WIN32 || JUCE_LINUX
  25523. hModule (0)
  25524. #elif JUCE_MAC
  25525. fragId (0),
  25526. resHandle (0),
  25527. bundleRef (0),
  25528. resFileId (0)
  25529. #endif
  25530. {
  25531. activeModules.add (this);
  25532. #if JUCE_WIN32 || JUCE_LINUX
  25533. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25534. #elif JUCE_MAC
  25535. FSRef ref;
  25536. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25537. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25538. #endif
  25539. }
  25540. ~ModuleHandle()
  25541. {
  25542. activeModules.removeValue (this);
  25543. close();
  25544. }
  25545. juce_UseDebuggingNewOperator
  25546. #if JUCE_WIN32 || JUCE_LINUX
  25547. void* hModule;
  25548. String fullParentDirectoryPathName;
  25549. bool open()
  25550. {
  25551. #if JUCE_WIN32
  25552. static bool timePeriodSet = false;
  25553. if (! timePeriodSet)
  25554. {
  25555. timePeriodSet = true;
  25556. timeBeginPeriod (2);
  25557. }
  25558. #endif
  25559. pluginName = file.getFileNameWithoutExtension();
  25560. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25561. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25562. if (moduleMain == 0)
  25563. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25564. return moduleMain != 0;
  25565. }
  25566. void close()
  25567. {
  25568. _fpreset(); // (doesn't do any harm)
  25569. PlatformUtilities::freeDynamicLibrary (hModule);
  25570. }
  25571. void closeEffect (AEffect* eff)
  25572. {
  25573. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25574. }
  25575. #else
  25576. CFragConnectionID fragId;
  25577. Handle resHandle;
  25578. CFBundleRef bundleRef;
  25579. FSSpec parentDirFSSpec;
  25580. short resFileId;
  25581. bool open()
  25582. {
  25583. bool ok = false;
  25584. const String filename (file.getFullPathName());
  25585. if (file.hasFileExtension (T(".vst")))
  25586. {
  25587. const char* const utf8 = filename.toUTF8();
  25588. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25589. strlen (utf8), file.isDirectory());
  25590. if (url != 0)
  25591. {
  25592. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25593. CFRelease (url);
  25594. if (bundleRef != 0)
  25595. {
  25596. if (CFBundleLoadExecutable (bundleRef))
  25597. {
  25598. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25599. if (moduleMain == 0)
  25600. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25601. if (moduleMain != 0)
  25602. {
  25603. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25604. if (name != 0)
  25605. {
  25606. if (CFGetTypeID (name) == CFStringGetTypeID())
  25607. {
  25608. char buffer[1024];
  25609. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25610. pluginName = buffer;
  25611. }
  25612. }
  25613. if (pluginName.isEmpty())
  25614. pluginName = file.getFileNameWithoutExtension();
  25615. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25616. ok = true;
  25617. }
  25618. }
  25619. if (! ok)
  25620. {
  25621. CFBundleUnloadExecutable (bundleRef);
  25622. CFRelease (bundleRef);
  25623. bundleRef = 0;
  25624. }
  25625. }
  25626. }
  25627. }
  25628. #if JUCE_PPC
  25629. else
  25630. {
  25631. FSRef fn;
  25632. if (FSPathMakeRef ((UInt8*) filename.toUTF8(), &fn, 0) == noErr)
  25633. {
  25634. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25635. if (resFileId != -1)
  25636. {
  25637. const int numEffs = Count1Resources ('aEff');
  25638. for (int i = 0; i < numEffs; ++i)
  25639. {
  25640. resHandle = Get1IndResource ('aEff', i + 1);
  25641. if (resHandle != 0)
  25642. {
  25643. OSType type;
  25644. Str255 name;
  25645. SInt16 id;
  25646. GetResInfo (resHandle, &id, &type, name);
  25647. pluginName = String ((const char*) name + 1, name[0]);
  25648. DetachResource (resHandle);
  25649. HLock (resHandle);
  25650. Ptr ptr;
  25651. Str255 errorText;
  25652. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25653. name, kPrivateCFragCopy,
  25654. &fragId, &ptr, errorText);
  25655. if (err == noErr)
  25656. {
  25657. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25658. ok = true;
  25659. }
  25660. else
  25661. {
  25662. HUnlock (resHandle);
  25663. }
  25664. break;
  25665. }
  25666. }
  25667. if (! ok)
  25668. CloseResFile (resFileId);
  25669. }
  25670. }
  25671. }
  25672. #endif
  25673. return ok;
  25674. }
  25675. void close()
  25676. {
  25677. #if JUCE_PPC
  25678. if (fragId != 0)
  25679. {
  25680. if (moduleMain != 0)
  25681. disposeMachOFromCFM ((void*) moduleMain);
  25682. CloseConnection (&fragId);
  25683. HUnlock (resHandle);
  25684. if (resFileId != 0)
  25685. CloseResFile (resFileId);
  25686. }
  25687. else
  25688. #endif
  25689. if (bundleRef != 0)
  25690. {
  25691. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25692. if (CFGetRetainCount (bundleRef) == 1)
  25693. CFBundleUnloadExecutable (bundleRef);
  25694. if (CFGetRetainCount (bundleRef) > 0)
  25695. CFRelease (bundleRef);
  25696. }
  25697. }
  25698. void closeEffect (AEffect* eff)
  25699. {
  25700. #if JUCE_PPC
  25701. if (fragId != 0)
  25702. {
  25703. VoidArray thingsToDelete;
  25704. thingsToDelete.add ((void*) eff->dispatcher);
  25705. thingsToDelete.add ((void*) eff->process);
  25706. thingsToDelete.add ((void*) eff->setParameter);
  25707. thingsToDelete.add ((void*) eff->getParameter);
  25708. thingsToDelete.add ((void*) eff->processReplacing);
  25709. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25710. for (int i = thingsToDelete.size(); --i >= 0;)
  25711. disposeMachOFromCFM (thingsToDelete[i]);
  25712. }
  25713. else
  25714. #endif
  25715. {
  25716. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25717. }
  25718. }
  25719. #if JUCE_PPC
  25720. static void* newMachOFromCFM (void* cfmfp)
  25721. {
  25722. if (cfmfp == 0)
  25723. return 0;
  25724. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25725. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25726. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25727. mfp[2] = 0x800c0000;
  25728. mfp[3] = 0x804c0004;
  25729. mfp[4] = 0x7c0903a6;
  25730. mfp[5] = 0x4e800420;
  25731. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25732. return mfp;
  25733. }
  25734. static void disposeMachOFromCFM (void* ptr)
  25735. {
  25736. juce_free (ptr);
  25737. }
  25738. void coerceAEffectFunctionCalls (AEffect* eff)
  25739. {
  25740. if (fragId != 0)
  25741. {
  25742. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25743. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25744. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25745. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25746. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25747. }
  25748. }
  25749. #endif
  25750. #endif
  25751. };
  25752. class VSTPluginInstance : public AudioPluginInstance,
  25753. private Timer,
  25754. private AsyncUpdater
  25755. {
  25756. public:
  25757. ~VSTPluginInstance();
  25758. // AudioPluginInstance methods:
  25759. void fillInPluginDescription (PluginDescription& desc) const
  25760. {
  25761. desc.name = name;
  25762. desc.fileOrIdentifier = module->file.getFullPathName();
  25763. desc.uid = getUID();
  25764. desc.lastFileModTime = module->file.getLastModificationTime();
  25765. desc.pluginFormatName = "VST";
  25766. desc.category = getCategory();
  25767. {
  25768. char buffer [kVstMaxVendorStrLen + 8];
  25769. zerostruct (buffer);
  25770. dispatch (effGetVendorString, 0, 0, buffer, 0);
  25771. desc.manufacturerName = buffer;
  25772. }
  25773. desc.version = getVersion();
  25774. desc.numInputChannels = getNumInputChannels();
  25775. desc.numOutputChannels = getNumOutputChannels();
  25776. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  25777. }
  25778. const String getName() const { return name; }
  25779. int getUID() const throw();
  25780. bool acceptsMidi() const { return wantsMidiMessages; }
  25781. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  25782. // AudioProcessor methods:
  25783. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  25784. void releaseResources();
  25785. void processBlock (AudioSampleBuffer& buffer,
  25786. MidiBuffer& midiMessages);
  25787. AudioProcessorEditor* createEditor();
  25788. const String getInputChannelName (const int index) const;
  25789. bool isInputChannelStereoPair (int index) const;
  25790. const String getOutputChannelName (const int index) const;
  25791. bool isOutputChannelStereoPair (int index) const;
  25792. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  25793. float getParameter (int index);
  25794. void setParameter (int index, float newValue);
  25795. const String getParameterName (int index);
  25796. const String getParameterText (int index);
  25797. bool isParameterAutomatable (int index) const;
  25798. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  25799. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  25800. void setCurrentProgram (int index);
  25801. const String getProgramName (int index);
  25802. void changeProgramName (int index, const String& newName);
  25803. void getStateInformation (MemoryBlock& destData);
  25804. void getCurrentProgramStateInformation (MemoryBlock& destData);
  25805. void setStateInformation (const void* data, int sizeInBytes);
  25806. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  25807. void timerCallback();
  25808. void handleAsyncUpdate();
  25809. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  25810. juce_UseDebuggingNewOperator
  25811. private:
  25812. friend class VSTPluginWindow;
  25813. friend class VSTPluginFormat;
  25814. AEffect* effect;
  25815. String name;
  25816. CriticalSection lock;
  25817. bool wantsMidiMessages, initialised, isPowerOn;
  25818. mutable StringArray programNames;
  25819. AudioSampleBuffer tempBuffer;
  25820. CriticalSection midiInLock;
  25821. MidiBuffer incomingMidi;
  25822. VSTMidiEventList midiEventsToSend;
  25823. VstTimeInfo vstHostTime;
  25824. HeapBlock <float*> channels;
  25825. ReferenceCountedObjectPtr <ModuleHandle> module;
  25826. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  25827. bool restoreProgramSettings (const fxProgram* const prog);
  25828. const String getCurrentProgramName();
  25829. void setParamsInProgramBlock (fxProgram* const prog) throw();
  25830. void updateStoredProgramNames();
  25831. void initialise();
  25832. void handleMidiFromPlugin (const VstEvents* const events);
  25833. void createTempParameterStore (MemoryBlock& dest);
  25834. void restoreFromTempParameterStore (const MemoryBlock& mb);
  25835. const String getParameterLabel (int index) const;
  25836. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  25837. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  25838. void setChunkData (const char* data, int size, bool isPreset);
  25839. bool loadFromFXBFile (const void* data, int numBytes);
  25840. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  25841. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  25842. const String getVersion() const throw();
  25843. const String getCategory() const throw();
  25844. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  25845. void setPower (const bool on);
  25846. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  25847. };
  25848. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  25849. : effect (0),
  25850. wantsMidiMessages (false),
  25851. initialised (false),
  25852. isPowerOn (false),
  25853. tempBuffer (1, 1),
  25854. module (module_)
  25855. {
  25856. try
  25857. {
  25858. _fpreset();
  25859. ++insideVSTCallback;
  25860. name = module->pluginName;
  25861. log (T("Creating VST instance: ") + name);
  25862. #if JUCE_MAC
  25863. if (module->resFileId != 0)
  25864. UseResFile (module->resFileId);
  25865. #if JUCE_PPC
  25866. if (module->fragId != 0)
  25867. {
  25868. static void* audioMasterCoerced = 0;
  25869. if (audioMasterCoerced == 0)
  25870. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  25871. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  25872. }
  25873. else
  25874. #endif
  25875. #endif
  25876. {
  25877. effect = module->moduleMain (&audioMaster);
  25878. }
  25879. --insideVSTCallback;
  25880. if (effect != 0 && effect->magic == kEffectMagic)
  25881. {
  25882. #if JUCE_PPC
  25883. module->coerceAEffectFunctionCalls (effect);
  25884. #endif
  25885. jassert (effect->resvd2 == 0);
  25886. jassert (effect->object != 0);
  25887. _fpreset(); // some dodgy plugs fuck around with this
  25888. }
  25889. else
  25890. {
  25891. effect = 0;
  25892. }
  25893. }
  25894. catch (...)
  25895. {
  25896. --insideVSTCallback;
  25897. }
  25898. }
  25899. VSTPluginInstance::~VSTPluginInstance()
  25900. {
  25901. {
  25902. const ScopedLock sl (lock);
  25903. jassert (insideVSTCallback == 0);
  25904. if (effect != 0 && effect->magic == kEffectMagic)
  25905. {
  25906. try
  25907. {
  25908. #if JUCE_MAC
  25909. if (module->resFileId != 0)
  25910. UseResFile (module->resFileId);
  25911. #endif
  25912. // Must delete any editors before deleting the plugin instance!
  25913. jassert (getActiveEditor() == 0);
  25914. _fpreset(); // some dodgy plugs fuck around with this
  25915. module->closeEffect (effect);
  25916. }
  25917. catch (...)
  25918. {}
  25919. }
  25920. module = 0;
  25921. effect = 0;
  25922. }
  25923. }
  25924. void VSTPluginInstance::initialise()
  25925. {
  25926. if (initialised || effect == 0)
  25927. return;
  25928. log (T("Initialising VST: ") + module->pluginName);
  25929. initialised = true;
  25930. dispatch (effIdentify, 0, 0, 0, 0);
  25931. // this code would ask the plugin for its name, but so few plugins
  25932. // actually bother implementing this correctly, that it's better to
  25933. // just ignore it and use the file name instead.
  25934. if (getSampleRate() > 0)
  25935. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  25936. if (getBlockSize() > 0)
  25937. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  25938. dispatch (effOpen, 0, 0, 0, 0);
  25939. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25940. getSampleRate(), getBlockSize());
  25941. if (getNumPrograms() > 1)
  25942. setCurrentProgram (0);
  25943. else
  25944. dispatch (effSetProgram, 0, 0, 0, 0);
  25945. int i;
  25946. for (i = effect->numInputs; --i >= 0;)
  25947. dispatch (effConnectInput, i, 1, 0, 0);
  25948. for (i = effect->numOutputs; --i >= 0;)
  25949. dispatch (effConnectOutput, i, 1, 0, 0);
  25950. updateStoredProgramNames();
  25951. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  25952. setLatencySamples (effect->initialDelay);
  25953. }
  25954. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  25955. int samplesPerBlockExpected)
  25956. {
  25957. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25958. sampleRate_, samplesPerBlockExpected);
  25959. setLatencySamples (effect->initialDelay);
  25960. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  25961. vstHostTime.tempo = 120.0;
  25962. vstHostTime.timeSigNumerator = 4;
  25963. vstHostTime.timeSigDenominator = 4;
  25964. vstHostTime.sampleRate = sampleRate_;
  25965. vstHostTime.samplePos = 0;
  25966. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  25967. initialise();
  25968. if (initialised)
  25969. {
  25970. wantsMidiMessages = wantsMidiMessages
  25971. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  25972. if (wantsMidiMessages)
  25973. midiEventsToSend.ensureSize (256);
  25974. else
  25975. midiEventsToSend.freeEvents();
  25976. incomingMidi.clear();
  25977. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  25978. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  25979. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  25980. if (! isPowerOn)
  25981. setPower (true);
  25982. // dodgy hack to force some plugins to initialise the sample rate..
  25983. if ((! hasEditor()) && getNumParameters() > 0)
  25984. {
  25985. const float old = getParameter (0);
  25986. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  25987. setParameter (0, old);
  25988. }
  25989. dispatch (effStartProcess, 0, 0, 0, 0);
  25990. }
  25991. }
  25992. void VSTPluginInstance::releaseResources()
  25993. {
  25994. if (initialised)
  25995. {
  25996. dispatch (effStopProcess, 0, 0, 0, 0);
  25997. setPower (false);
  25998. }
  25999. tempBuffer.setSize (1, 1);
  26000. incomingMidi.clear();
  26001. midiEventsToSend.freeEvents();
  26002. channels.free();
  26003. }
  26004. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  26005. MidiBuffer& midiMessages)
  26006. {
  26007. const int numSamples = buffer.getNumSamples();
  26008. if (initialised)
  26009. {
  26010. AudioPlayHead* playHead = getPlayHead();
  26011. if (playHead != 0)
  26012. {
  26013. AudioPlayHead::CurrentPositionInfo position;
  26014. playHead->getCurrentPosition (position);
  26015. vstHostTime.tempo = position.bpm;
  26016. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26017. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26018. vstHostTime.ppqPos = position.ppqPosition;
  26019. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26020. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26021. if (position.isPlaying)
  26022. vstHostTime.flags |= kVstTransportPlaying;
  26023. else
  26024. vstHostTime.flags &= ~kVstTransportPlaying;
  26025. }
  26026. #if JUCE_WIN32
  26027. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26028. #elif JUCE_LINUX
  26029. timeval micro;
  26030. gettimeofday (&micro, 0);
  26031. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26032. #elif JUCE_MAC
  26033. UnsignedWide micro;
  26034. Microseconds (&micro);
  26035. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26036. #endif
  26037. if (wantsMidiMessages)
  26038. {
  26039. midiEventsToSend.clear();
  26040. midiEventsToSend.ensureSize (1);
  26041. MidiBuffer::Iterator iter (midiMessages);
  26042. const uint8* midiData;
  26043. int numBytesOfMidiData, samplePosition;
  26044. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26045. {
  26046. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26047. jlimit (0, numSamples - 1, samplePosition));
  26048. }
  26049. try
  26050. {
  26051. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26052. }
  26053. catch (...)
  26054. {}
  26055. }
  26056. int i;
  26057. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26058. for (i = 0; i < maxChans; ++i)
  26059. channels[i] = buffer.getSampleData (i);
  26060. channels [maxChans] = 0;
  26061. _clearfp();
  26062. if ((effect->flags & effFlagsCanReplacing) != 0)
  26063. {
  26064. try
  26065. {
  26066. effect->processReplacing (effect, channels, channels, numSamples);
  26067. }
  26068. catch (...)
  26069. {}
  26070. }
  26071. else
  26072. {
  26073. tempBuffer.setSize (effect->numOutputs, numSamples);
  26074. tempBuffer.clear();
  26075. float* outs [64];
  26076. for (i = effect->numOutputs; --i >= 0;)
  26077. outs[i] = tempBuffer.getSampleData (i);
  26078. outs [effect->numOutputs] = 0;
  26079. try
  26080. {
  26081. effect->process (effect, channels, outs, numSamples);
  26082. }
  26083. catch (...)
  26084. {}
  26085. for (i = effect->numOutputs; --i >= 0;)
  26086. buffer.copyFrom (i, 0, outs[i], numSamples);
  26087. }
  26088. }
  26089. else
  26090. {
  26091. // Not initialised, so just bypass..
  26092. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26093. buffer.clear (i, 0, buffer.getNumSamples());
  26094. }
  26095. {
  26096. // copy any incoming midi..
  26097. const ScopedLock sl (midiInLock);
  26098. midiMessages = incomingMidi;
  26099. incomingMidi.clear();
  26100. }
  26101. }
  26102. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26103. {
  26104. if (events != 0)
  26105. {
  26106. const ScopedLock sl (midiInLock);
  26107. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26108. }
  26109. }
  26110. static Array <VSTPluginWindow*> activeVSTWindows;
  26111. class VSTPluginWindow : public AudioProcessorEditor,
  26112. #if ! JUCE_MAC
  26113. public ComponentMovementWatcher,
  26114. #endif
  26115. public Timer
  26116. {
  26117. public:
  26118. VSTPluginWindow (VSTPluginInstance& plugin_)
  26119. : AudioProcessorEditor (&plugin_),
  26120. #if ! JUCE_MAC
  26121. ComponentMovementWatcher (this),
  26122. #endif
  26123. plugin (plugin_),
  26124. isOpen (false),
  26125. wasShowing (false),
  26126. pluginRefusesToResize (false),
  26127. pluginWantsKeys (false),
  26128. alreadyInside (false),
  26129. recursiveResize (false)
  26130. {
  26131. #if JUCE_WIN32
  26132. sizeCheckCount = 0;
  26133. pluginHWND = 0;
  26134. #elif JUCE_LINUX
  26135. pluginWindow = None;
  26136. pluginProc = None;
  26137. #else
  26138. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26139. #endif
  26140. activeVSTWindows.add (this);
  26141. setSize (1, 1);
  26142. setOpaque (true);
  26143. setVisible (true);
  26144. }
  26145. ~VSTPluginWindow()
  26146. {
  26147. #if JUCE_MAC
  26148. innerWrapper = 0;
  26149. #else
  26150. closePluginWindow();
  26151. #endif
  26152. activeVSTWindows.removeValue (this);
  26153. plugin.editorBeingDeleted (this);
  26154. }
  26155. #if ! JUCE_MAC
  26156. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26157. {
  26158. if (recursiveResize)
  26159. return;
  26160. Component* const topComp = getTopLevelComponent();
  26161. if (topComp->getPeer() != 0)
  26162. {
  26163. const Point<int> pos (relativePositionToOtherComponent (topComp, Point<int>()));
  26164. recursiveResize = true;
  26165. #if JUCE_WIN32
  26166. if (pluginHWND != 0)
  26167. MoveWindow (pluginHWND, pos.getX(), pos.getY(), getWidth(), getHeight(), TRUE);
  26168. #elif JUCE_LINUX
  26169. if (pluginWindow != 0)
  26170. {
  26171. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26172. XMoveWindow (display, pluginWindow, pos.getX(), pos.getY());
  26173. XMapRaised (display, pluginWindow);
  26174. }
  26175. #endif
  26176. recursiveResize = false;
  26177. }
  26178. }
  26179. void componentVisibilityChanged (Component&)
  26180. {
  26181. const bool isShowingNow = isShowing();
  26182. if (wasShowing != isShowingNow)
  26183. {
  26184. wasShowing = isShowingNow;
  26185. if (isShowingNow)
  26186. openPluginWindow();
  26187. else
  26188. closePluginWindow();
  26189. }
  26190. componentMovedOrResized (true, true);
  26191. }
  26192. void componentPeerChanged()
  26193. {
  26194. closePluginWindow();
  26195. openPluginWindow();
  26196. }
  26197. #endif
  26198. bool keyStateChanged (const bool)
  26199. {
  26200. return pluginWantsKeys;
  26201. }
  26202. bool keyPressed (const KeyPress&)
  26203. {
  26204. return pluginWantsKeys;
  26205. }
  26206. #if JUCE_MAC
  26207. void paint (Graphics& g)
  26208. {
  26209. g.fillAll (Colours::black);
  26210. }
  26211. #else
  26212. void paint (Graphics& g)
  26213. {
  26214. if (isOpen)
  26215. {
  26216. ComponentPeer* const peer = getPeer();
  26217. if (peer != 0)
  26218. {
  26219. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26220. peer->addMaskedRegion (pos.getX(), pos.getY(), getWidth(), getHeight());
  26221. #if JUCE_LINUX
  26222. if (pluginWindow != 0)
  26223. {
  26224. const Rectangle<int> clip (g.getClipBounds());
  26225. XEvent ev;
  26226. zerostruct (ev);
  26227. ev.xexpose.type = Expose;
  26228. ev.xexpose.display = display;
  26229. ev.xexpose.window = pluginWindow;
  26230. ev.xexpose.x = clip.getX();
  26231. ev.xexpose.y = clip.getY();
  26232. ev.xexpose.width = clip.getWidth();
  26233. ev.xexpose.height = clip.getHeight();
  26234. sendEventToChild (&ev);
  26235. }
  26236. #endif
  26237. }
  26238. }
  26239. else
  26240. {
  26241. g.fillAll (Colours::black);
  26242. }
  26243. }
  26244. #endif
  26245. void timerCallback()
  26246. {
  26247. #if JUCE_WIN32
  26248. if (--sizeCheckCount <= 0)
  26249. {
  26250. sizeCheckCount = 10;
  26251. checkPluginWindowSize();
  26252. }
  26253. #endif
  26254. try
  26255. {
  26256. static bool reentrant = false;
  26257. if (! reentrant)
  26258. {
  26259. reentrant = true;
  26260. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26261. reentrant = false;
  26262. }
  26263. }
  26264. catch (...)
  26265. {}
  26266. }
  26267. void mouseDown (const MouseEvent& e)
  26268. {
  26269. #if JUCE_LINUX
  26270. if (pluginWindow == 0)
  26271. return;
  26272. toFront (true);
  26273. XEvent ev;
  26274. zerostruct (ev);
  26275. ev.xbutton.display = display;
  26276. ev.xbutton.type = ButtonPress;
  26277. ev.xbutton.window = pluginWindow;
  26278. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26279. ev.xbutton.time = CurrentTime;
  26280. ev.xbutton.x = e.x;
  26281. ev.xbutton.y = e.y;
  26282. ev.xbutton.x_root = e.getScreenX();
  26283. ev.xbutton.y_root = e.getScreenY();
  26284. translateJuceToXButtonModifiers (e, ev);
  26285. sendEventToChild (&ev);
  26286. #elif JUCE_WIN32
  26287. (void) e;
  26288. toFront (true);
  26289. #endif
  26290. }
  26291. void broughtToFront()
  26292. {
  26293. activeVSTWindows.removeValue (this);
  26294. activeVSTWindows.add (this);
  26295. #if JUCE_MAC
  26296. dispatch (effEditTop, 0, 0, 0, 0);
  26297. #endif
  26298. }
  26299. juce_UseDebuggingNewOperator
  26300. private:
  26301. VSTPluginInstance& plugin;
  26302. bool isOpen, wasShowing, recursiveResize;
  26303. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26304. #if JUCE_WIN32
  26305. HWND pluginHWND;
  26306. void* originalWndProc;
  26307. int sizeCheckCount;
  26308. #elif JUCE_LINUX
  26309. Window pluginWindow;
  26310. EventProcPtr pluginProc;
  26311. #endif
  26312. #if JUCE_MAC
  26313. void openPluginWindow (WindowRef parentWindow)
  26314. {
  26315. if (isOpen || parentWindow == 0)
  26316. return;
  26317. isOpen = true;
  26318. ERect* rect = 0;
  26319. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26320. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26321. // do this before and after like in the steinberg example
  26322. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26323. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26324. // Install keyboard hooks
  26325. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26326. // double-check it's not too tiny
  26327. int w = 250, h = 150;
  26328. if (rect != 0)
  26329. {
  26330. w = rect->right - rect->left;
  26331. h = rect->bottom - rect->top;
  26332. if (w == 0 || h == 0)
  26333. {
  26334. w = 250;
  26335. h = 150;
  26336. }
  26337. }
  26338. w = jmax (w, 32);
  26339. h = jmax (h, 32);
  26340. setSize (w, h);
  26341. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26342. repaint();
  26343. }
  26344. #else
  26345. void openPluginWindow()
  26346. {
  26347. if (isOpen || getWindowHandle() == 0)
  26348. return;
  26349. log (T("Opening VST UI: ") + plugin.name);
  26350. isOpen = true;
  26351. ERect* rect = 0;
  26352. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26353. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26354. // do this before and after like in the steinberg example
  26355. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26356. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26357. // Install keyboard hooks
  26358. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26359. #if JUCE_WIN32
  26360. originalWndProc = 0;
  26361. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26362. if (pluginHWND == 0)
  26363. {
  26364. isOpen = false;
  26365. setSize (300, 150);
  26366. return;
  26367. }
  26368. #pragma warning (push)
  26369. #pragma warning (disable: 4244)
  26370. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26371. if (! pluginWantsKeys)
  26372. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) vstHookWndProc);
  26373. #pragma warning (pop)
  26374. int w, h;
  26375. RECT r;
  26376. GetWindowRect (pluginHWND, &r);
  26377. w = r.right - r.left;
  26378. h = r.bottom - r.top;
  26379. if (rect != 0)
  26380. {
  26381. const int rw = rect->right - rect->left;
  26382. const int rh = rect->bottom - rect->top;
  26383. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26384. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26385. {
  26386. // very dodgy logic to decide which size is right.
  26387. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26388. {
  26389. SetWindowPos (pluginHWND, 0,
  26390. 0, 0, rw, rh,
  26391. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26392. GetWindowRect (pluginHWND, &r);
  26393. w = r.right - r.left;
  26394. h = r.bottom - r.top;
  26395. pluginRefusesToResize = (w != rw) || (h != rh);
  26396. w = rw;
  26397. h = rh;
  26398. }
  26399. }
  26400. }
  26401. #elif JUCE_LINUX
  26402. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26403. if (pluginWindow != 0)
  26404. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26405. XInternAtom (display, "_XEventProc", False));
  26406. int w = 250, h = 150;
  26407. if (rect != 0)
  26408. {
  26409. w = rect->right - rect->left;
  26410. h = rect->bottom - rect->top;
  26411. if (w == 0 || h == 0)
  26412. {
  26413. w = 250;
  26414. h = 150;
  26415. }
  26416. }
  26417. if (pluginWindow != 0)
  26418. XMapRaised (display, pluginWindow);
  26419. #endif
  26420. // double-check it's not too tiny
  26421. w = jmax (w, 32);
  26422. h = jmax (h, 32);
  26423. setSize (w, h);
  26424. #if JUCE_WIN32
  26425. checkPluginWindowSize();
  26426. #endif
  26427. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26428. repaint();
  26429. }
  26430. #endif
  26431. #if ! JUCE_MAC
  26432. void closePluginWindow()
  26433. {
  26434. if (isOpen)
  26435. {
  26436. log (T("Closing VST UI: ") + plugin.getName());
  26437. isOpen = false;
  26438. dispatch (effEditClose, 0, 0, 0, 0);
  26439. #if JUCE_WIN32
  26440. #pragma warning (push)
  26441. #pragma warning (disable: 4244)
  26442. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26443. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) originalWndProc);
  26444. #pragma warning (pop)
  26445. stopTimer();
  26446. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26447. DestroyWindow (pluginHWND);
  26448. pluginHWND = 0;
  26449. #elif JUCE_LINUX
  26450. stopTimer();
  26451. pluginWindow = 0;
  26452. pluginProc = 0;
  26453. #endif
  26454. }
  26455. }
  26456. #endif
  26457. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26458. {
  26459. return plugin.dispatch (opcode, index, value, ptr, opt);
  26460. }
  26461. #if JUCE_WIN32
  26462. void checkPluginWindowSize() throw()
  26463. {
  26464. RECT r;
  26465. GetWindowRect (pluginHWND, &r);
  26466. const int w = r.right - r.left;
  26467. const int h = r.bottom - r.top;
  26468. if (isShowing() && w > 0 && h > 0
  26469. && (w != getWidth() || h != getHeight())
  26470. && ! pluginRefusesToResize)
  26471. {
  26472. setSize (w, h);
  26473. sizeCheckCount = 0;
  26474. }
  26475. }
  26476. // hooks to get keyboard events from VST windows..
  26477. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26478. {
  26479. for (int i = activeVSTWindows.size(); --i >= 0;)
  26480. {
  26481. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26482. if (w->pluginHWND == hW)
  26483. {
  26484. if (message == WM_CHAR
  26485. || message == WM_KEYDOWN
  26486. || message == WM_SYSKEYDOWN
  26487. || message == WM_KEYUP
  26488. || message == WM_SYSKEYUP
  26489. || message == WM_APPCOMMAND)
  26490. {
  26491. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26492. message, wParam, lParam);
  26493. }
  26494. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26495. (HWND) w->pluginHWND,
  26496. message,
  26497. wParam,
  26498. lParam);
  26499. }
  26500. }
  26501. return DefWindowProc (hW, message, wParam, lParam);
  26502. }
  26503. #endif
  26504. #if JUCE_LINUX
  26505. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26506. void sendEventToChild (XEvent* event)
  26507. {
  26508. if (pluginProc != 0)
  26509. {
  26510. // if the plugin publishes an event procedure, pass the event directly..
  26511. pluginProc (event);
  26512. }
  26513. else if (pluginWindow != 0)
  26514. {
  26515. // if the plugin has a window, then send the event to the window so that
  26516. // its message thread will pick it up..
  26517. XSendEvent (display, pluginWindow, False, 0L, event);
  26518. XFlush (display);
  26519. }
  26520. }
  26521. void mouseEnter (const MouseEvent& e)
  26522. {
  26523. if (pluginWindow != 0)
  26524. {
  26525. XEvent ev;
  26526. zerostruct (ev);
  26527. ev.xcrossing.display = display;
  26528. ev.xcrossing.type = EnterNotify;
  26529. ev.xcrossing.window = pluginWindow;
  26530. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26531. ev.xcrossing.time = CurrentTime;
  26532. ev.xcrossing.x = e.x;
  26533. ev.xcrossing.y = e.y;
  26534. ev.xcrossing.x_root = e.getScreenX();
  26535. ev.xcrossing.y_root = e.getScreenY();
  26536. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26537. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26538. translateJuceToXCrossingModifiers (e, ev);
  26539. sendEventToChild (&ev);
  26540. }
  26541. }
  26542. void mouseExit (const MouseEvent& e)
  26543. {
  26544. if (pluginWindow != 0)
  26545. {
  26546. XEvent ev;
  26547. zerostruct (ev);
  26548. ev.xcrossing.display = display;
  26549. ev.xcrossing.type = LeaveNotify;
  26550. ev.xcrossing.window = pluginWindow;
  26551. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26552. ev.xcrossing.time = CurrentTime;
  26553. ev.xcrossing.x = e.x;
  26554. ev.xcrossing.y = e.y;
  26555. ev.xcrossing.x_root = e.getScreenX();
  26556. ev.xcrossing.y_root = e.getScreenY();
  26557. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26558. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26559. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26560. translateJuceToXCrossingModifiers (e, ev);
  26561. sendEventToChild (&ev);
  26562. }
  26563. }
  26564. void mouseMove (const MouseEvent& e)
  26565. {
  26566. if (pluginWindow != 0)
  26567. {
  26568. XEvent ev;
  26569. zerostruct (ev);
  26570. ev.xmotion.display = display;
  26571. ev.xmotion.type = MotionNotify;
  26572. ev.xmotion.window = pluginWindow;
  26573. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26574. ev.xmotion.time = CurrentTime;
  26575. ev.xmotion.is_hint = NotifyNormal;
  26576. ev.xmotion.x = e.x;
  26577. ev.xmotion.y = e.y;
  26578. ev.xmotion.x_root = e.getScreenX();
  26579. ev.xmotion.y_root = e.getScreenY();
  26580. sendEventToChild (&ev);
  26581. }
  26582. }
  26583. void mouseDrag (const MouseEvent& e)
  26584. {
  26585. if (pluginWindow != 0)
  26586. {
  26587. XEvent ev;
  26588. zerostruct (ev);
  26589. ev.xmotion.display = display;
  26590. ev.xmotion.type = MotionNotify;
  26591. ev.xmotion.window = pluginWindow;
  26592. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26593. ev.xmotion.time = CurrentTime;
  26594. ev.xmotion.x = e.x ;
  26595. ev.xmotion.y = e.y;
  26596. ev.xmotion.x_root = e.getScreenX();
  26597. ev.xmotion.y_root = e.getScreenY();
  26598. ev.xmotion.is_hint = NotifyNormal;
  26599. translateJuceToXMotionModifiers (e, ev);
  26600. sendEventToChild (&ev);
  26601. }
  26602. }
  26603. void mouseUp (const MouseEvent& e)
  26604. {
  26605. if (pluginWindow != 0)
  26606. {
  26607. XEvent ev;
  26608. zerostruct (ev);
  26609. ev.xbutton.display = display;
  26610. ev.xbutton.type = ButtonRelease;
  26611. ev.xbutton.window = pluginWindow;
  26612. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26613. ev.xbutton.time = CurrentTime;
  26614. ev.xbutton.x = e.x;
  26615. ev.xbutton.y = e.y;
  26616. ev.xbutton.x_root = e.getScreenX();
  26617. ev.xbutton.y_root = e.getScreenY();
  26618. translateJuceToXButtonModifiers (e, ev);
  26619. sendEventToChild (&ev);
  26620. }
  26621. }
  26622. void mouseWheelMove (const MouseEvent& e,
  26623. float incrementX,
  26624. float incrementY)
  26625. {
  26626. if (pluginWindow != 0)
  26627. {
  26628. XEvent ev;
  26629. zerostruct (ev);
  26630. ev.xbutton.display = display;
  26631. ev.xbutton.type = ButtonPress;
  26632. ev.xbutton.window = pluginWindow;
  26633. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26634. ev.xbutton.time = CurrentTime;
  26635. ev.xbutton.x = e.x;
  26636. ev.xbutton.y = e.y;
  26637. ev.xbutton.x_root = e.getScreenX();
  26638. ev.xbutton.y_root = e.getScreenY();
  26639. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26640. sendEventToChild (&ev);
  26641. // TODO - put a usleep here ?
  26642. ev.xbutton.type = ButtonRelease;
  26643. sendEventToChild (&ev);
  26644. }
  26645. }
  26646. #endif
  26647. #if JUCE_MAC
  26648. #if ! JUCE_SUPPORT_CARBON
  26649. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26650. #endif
  26651. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26652. {
  26653. public:
  26654. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26655. : owner (owner_),
  26656. alreadyInside (false)
  26657. {
  26658. }
  26659. ~InnerWrapperComponent()
  26660. {
  26661. deleteWindow();
  26662. }
  26663. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26664. {
  26665. owner->openPluginWindow (windowRef);
  26666. return 0;
  26667. }
  26668. void removeView (HIViewRef)
  26669. {
  26670. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26671. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26672. }
  26673. bool getEmbeddedViewSize (int& w, int& h)
  26674. {
  26675. ERect* rect = 0;
  26676. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26677. w = rect->right - rect->left;
  26678. h = rect->bottom - rect->top;
  26679. return true;
  26680. }
  26681. void mouseDown (int x, int y)
  26682. {
  26683. if (! alreadyInside)
  26684. {
  26685. alreadyInside = true;
  26686. getTopLevelComponent()->toFront (true);
  26687. owner->dispatch (effEditMouse, x, y, 0, 0);
  26688. alreadyInside = false;
  26689. }
  26690. else
  26691. {
  26692. PostEvent (::mouseDown, 0);
  26693. }
  26694. }
  26695. void paint()
  26696. {
  26697. ComponentPeer* const peer = getPeer();
  26698. if (peer != 0)
  26699. {
  26700. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26701. ERect r;
  26702. r.left = pos.getX();
  26703. r.right = r.left + getWidth();
  26704. r.top = pos.getY();
  26705. r.bottom = r.top + getHeight();
  26706. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26707. }
  26708. }
  26709. private:
  26710. VSTPluginWindow* const owner;
  26711. bool alreadyInside;
  26712. };
  26713. friend class InnerWrapperComponent;
  26714. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26715. void resized()
  26716. {
  26717. innerWrapper->setSize (getWidth(), getHeight());
  26718. }
  26719. #endif
  26720. };
  26721. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26722. {
  26723. if (hasEditor())
  26724. return new VSTPluginWindow (*this);
  26725. return 0;
  26726. }
  26727. void VSTPluginInstance::handleAsyncUpdate()
  26728. {
  26729. // indicates that something about the plugin has changed..
  26730. updateHostDisplay();
  26731. }
  26732. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26733. {
  26734. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26735. {
  26736. changeProgramName (getCurrentProgram(), prog->prgName);
  26737. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26738. setParameter (i, vst_swapFloat (prog->params[i]));
  26739. return true;
  26740. }
  26741. return false;
  26742. }
  26743. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26744. const int dataSize)
  26745. {
  26746. if (dataSize < 28)
  26747. return false;
  26748. const fxSet* const set = (const fxSet*) data;
  26749. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26750. || vst_swap (set->version) > fxbVersionNum)
  26751. return false;
  26752. if (vst_swap (set->fxMagic) == 'FxBk')
  26753. {
  26754. // bank of programs
  26755. if (vst_swap (set->numPrograms) >= 0)
  26756. {
  26757. const int oldProg = getCurrentProgram();
  26758. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26759. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26760. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26761. {
  26762. if (i != oldProg)
  26763. {
  26764. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26765. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26766. return false;
  26767. if (vst_swap (set->numPrograms) > 0)
  26768. setCurrentProgram (i);
  26769. if (! restoreProgramSettings (prog))
  26770. return false;
  26771. }
  26772. }
  26773. if (vst_swap (set->numPrograms) > 0)
  26774. setCurrentProgram (oldProg);
  26775. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  26776. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26777. return false;
  26778. if (! restoreProgramSettings (prog))
  26779. return false;
  26780. }
  26781. }
  26782. else if (vst_swap (set->fxMagic) == 'FxCk')
  26783. {
  26784. // single program
  26785. const fxProgram* const prog = (const fxProgram*) data;
  26786. if (vst_swap (prog->chunkMagic) != 'CcnK')
  26787. return false;
  26788. changeProgramName (getCurrentProgram(), prog->prgName);
  26789. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26790. setParameter (i, vst_swapFloat (prog->params[i]));
  26791. }
  26792. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  26793. {
  26794. // non-preset chunk
  26795. const fxChunkSet* const cset = (const fxChunkSet*) data;
  26796. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  26797. return false;
  26798. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  26799. }
  26800. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  26801. {
  26802. // preset chunk
  26803. const fxProgramSet* const cset = (const fxProgramSet*) data;
  26804. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  26805. return false;
  26806. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  26807. changeProgramName (getCurrentProgram(), cset->name);
  26808. }
  26809. else
  26810. {
  26811. return false;
  26812. }
  26813. return true;
  26814. }
  26815. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  26816. {
  26817. const int numParams = getNumParameters();
  26818. prog->chunkMagic = vst_swap ('CcnK');
  26819. prog->byteSize = 0;
  26820. prog->fxMagic = vst_swap ('FxCk');
  26821. prog->version = vst_swap (fxbVersionNum);
  26822. prog->fxID = vst_swap (getUID());
  26823. prog->fxVersion = vst_swap (getVersionNumber());
  26824. prog->numParams = vst_swap (numParams);
  26825. getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1);
  26826. for (int i = 0; i < numParams; ++i)
  26827. prog->params[i] = vst_swapFloat (getParameter (i));
  26828. }
  26829. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  26830. {
  26831. const int numPrograms = getNumPrograms();
  26832. const int numParams = getNumParameters();
  26833. if (usesChunks())
  26834. {
  26835. if (isFXB)
  26836. {
  26837. MemoryBlock chunk;
  26838. getChunkData (chunk, false, maxSizeMB);
  26839. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  26840. dest.setSize (totalLen, true);
  26841. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  26842. set->chunkMagic = vst_swap ('CcnK');
  26843. set->byteSize = 0;
  26844. set->fxMagic = vst_swap ('FBCh');
  26845. set->version = vst_swap (fxbVersionNum);
  26846. set->fxID = vst_swap (getUID());
  26847. set->fxVersion = vst_swap (getVersionNumber());
  26848. set->numPrograms = vst_swap (numPrograms);
  26849. set->chunkSize = vst_swap ((long) chunk.getSize());
  26850. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26851. }
  26852. else
  26853. {
  26854. MemoryBlock chunk;
  26855. getChunkData (chunk, true, maxSizeMB);
  26856. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  26857. dest.setSize (totalLen, true);
  26858. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  26859. set->chunkMagic = vst_swap ('CcnK');
  26860. set->byteSize = 0;
  26861. set->fxMagic = vst_swap ('FPCh');
  26862. set->version = vst_swap (fxbVersionNum);
  26863. set->fxID = vst_swap (getUID());
  26864. set->fxVersion = vst_swap (getVersionNumber());
  26865. set->numPrograms = vst_swap (numPrograms);
  26866. set->chunkSize = vst_swap ((long) chunk.getSize());
  26867. getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1);
  26868. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26869. }
  26870. }
  26871. else
  26872. {
  26873. if (isFXB)
  26874. {
  26875. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26876. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  26877. dest.setSize (len, true);
  26878. fxSet* const set = (fxSet*) dest.getData();
  26879. set->chunkMagic = vst_swap ('CcnK');
  26880. set->byteSize = 0;
  26881. set->fxMagic = vst_swap ('FxBk');
  26882. set->version = vst_swap (fxbVersionNum);
  26883. set->fxID = vst_swap (getUID());
  26884. set->fxVersion = vst_swap (getVersionNumber());
  26885. set->numPrograms = vst_swap (numPrograms);
  26886. const int oldProgram = getCurrentProgram();
  26887. MemoryBlock oldSettings;
  26888. createTempParameterStore (oldSettings);
  26889. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  26890. for (int i = 0; i < numPrograms; ++i)
  26891. {
  26892. if (i != oldProgram)
  26893. {
  26894. setCurrentProgram (i);
  26895. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  26896. }
  26897. }
  26898. setCurrentProgram (oldProgram);
  26899. restoreFromTempParameterStore (oldSettings);
  26900. }
  26901. else
  26902. {
  26903. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26904. dest.setSize (totalLen, true);
  26905. setParamsInProgramBlock ((fxProgram*) dest.getData());
  26906. }
  26907. }
  26908. return true;
  26909. }
  26910. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  26911. {
  26912. if (usesChunks())
  26913. {
  26914. void* data = 0;
  26915. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  26916. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  26917. {
  26918. mb.setSize (bytes);
  26919. mb.copyFrom (data, 0, bytes);
  26920. }
  26921. }
  26922. }
  26923. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  26924. {
  26925. if (size > 0 && usesChunks())
  26926. {
  26927. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  26928. if (! isPreset)
  26929. updateStoredProgramNames();
  26930. }
  26931. }
  26932. void VSTPluginInstance::timerCallback()
  26933. {
  26934. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  26935. stopTimer();
  26936. }
  26937. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  26938. {
  26939. const ScopedLock sl (lock);
  26940. ++insideVSTCallback;
  26941. int result = 0;
  26942. try
  26943. {
  26944. if (effect != 0)
  26945. {
  26946. #if JUCE_MAC
  26947. if (module->resFileId != 0)
  26948. UseResFile (module->resFileId);
  26949. CGrafPtr oldPort;
  26950. if (getActiveEditor() != 0)
  26951. {
  26952. const Point<int> pos (getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), Point<int>()));
  26953. GetPort (&oldPort);
  26954. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  26955. SetOrigin (-pos.getX(), -pos.getY());
  26956. }
  26957. #endif
  26958. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  26959. #if JUCE_MAC
  26960. if (getActiveEditor() != 0)
  26961. SetPort (oldPort);
  26962. module->resFileId = CurResFile();
  26963. #endif
  26964. --insideVSTCallback;
  26965. return result;
  26966. }
  26967. }
  26968. catch (...)
  26969. {
  26970. }
  26971. --insideVSTCallback;
  26972. return result;
  26973. }
  26974. // handles non plugin-specific callbacks..
  26975. static const int defaultVSTSampleRateValue = 16384;
  26976. static const int defaultVSTBlockSizeValue = 512;
  26977. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  26978. {
  26979. (void) index;
  26980. (void) value;
  26981. (void) opt;
  26982. switch (opcode)
  26983. {
  26984. case audioMasterCanDo:
  26985. {
  26986. static const char* canDos[] = { "supplyIdle",
  26987. "sendVstEvents",
  26988. "sendVstMidiEvent",
  26989. "sendVstTimeInfo",
  26990. "receiveVstEvents",
  26991. "receiveVstMidiEvent",
  26992. "supportShell",
  26993. "shellCategory" };
  26994. for (int i = 0; i < numElementsInArray (canDos); ++i)
  26995. if (strcmp (canDos[i], (const char*) ptr) == 0)
  26996. return 1;
  26997. return 0;
  26998. }
  26999. case audioMasterVersion:
  27000. return 0x2400;
  27001. case audioMasterCurrentId:
  27002. return shellUIDToCreate;
  27003. case audioMasterGetNumAutomatableParameters:
  27004. return 0;
  27005. case audioMasterGetAutomationState:
  27006. return 1;
  27007. case audioMasterGetVendorVersion:
  27008. return 0x0101;
  27009. case audioMasterGetVendorString:
  27010. case audioMasterGetProductString:
  27011. {
  27012. String hostName ("Juce VST Host");
  27013. if (JUCEApplication::getInstance() != 0)
  27014. hostName = JUCEApplication::getInstance()->getApplicationName();
  27015. hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27016. }
  27017. break;
  27018. case audioMasterGetSampleRate:
  27019. return (VstIntPtr) defaultVSTSampleRateValue;
  27020. case audioMasterGetBlockSize:
  27021. return (VstIntPtr) defaultVSTBlockSizeValue;
  27022. case audioMasterSetOutputSampleRate:
  27023. return 0;
  27024. default:
  27025. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27026. break;
  27027. }
  27028. return 0;
  27029. }
  27030. // handles callbacks for a specific plugin
  27031. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27032. {
  27033. switch (opcode)
  27034. {
  27035. case audioMasterAutomate:
  27036. sendParamChangeMessageToListeners (index, opt);
  27037. break;
  27038. case audioMasterProcessEvents:
  27039. handleMidiFromPlugin ((const VstEvents*) ptr);
  27040. break;
  27041. case audioMasterGetTime:
  27042. #ifdef _MSC_VER
  27043. #pragma warning (push)
  27044. #pragma warning (disable: 4311)
  27045. #endif
  27046. return (VstIntPtr) &vstHostTime;
  27047. #ifdef _MSC_VER
  27048. #pragma warning (pop)
  27049. #endif
  27050. break;
  27051. case audioMasterIdle:
  27052. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27053. {
  27054. ++insideVSTCallback;
  27055. #if JUCE_MAC
  27056. if (getActiveEditor() != 0)
  27057. dispatch (effEditIdle, 0, 0, 0, 0);
  27058. #endif
  27059. juce_callAnyTimersSynchronously();
  27060. handleUpdateNowIfNeeded();
  27061. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27062. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27063. --insideVSTCallback;
  27064. }
  27065. break;
  27066. case audioMasterUpdateDisplay:
  27067. triggerAsyncUpdate();
  27068. break;
  27069. case audioMasterTempoAt:
  27070. // returns (10000 * bpm)
  27071. break;
  27072. case audioMasterNeedIdle:
  27073. startTimer (50);
  27074. break;
  27075. case audioMasterSizeWindow:
  27076. if (getActiveEditor() != 0)
  27077. getActiveEditor()->setSize (index, value);
  27078. return 1;
  27079. case audioMasterGetSampleRate:
  27080. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27081. case audioMasterGetBlockSize:
  27082. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27083. case audioMasterWantMidi:
  27084. wantsMidiMessages = true;
  27085. break;
  27086. case audioMasterGetDirectory:
  27087. #if JUCE_MAC
  27088. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27089. #else
  27090. return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8();
  27091. #endif
  27092. case audioMasterGetAutomationState:
  27093. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27094. break;
  27095. // none of these are handled (yet)..
  27096. case audioMasterBeginEdit:
  27097. case audioMasterEndEdit:
  27098. case audioMasterSetTime:
  27099. case audioMasterPinConnected:
  27100. case audioMasterGetParameterQuantization:
  27101. case audioMasterIOChanged:
  27102. case audioMasterGetInputLatency:
  27103. case audioMasterGetOutputLatency:
  27104. case audioMasterGetPreviousPlug:
  27105. case audioMasterGetNextPlug:
  27106. case audioMasterWillReplaceOrAccumulate:
  27107. case audioMasterGetCurrentProcessLevel:
  27108. case audioMasterOfflineStart:
  27109. case audioMasterOfflineRead:
  27110. case audioMasterOfflineWrite:
  27111. case audioMasterOfflineGetCurrentPass:
  27112. case audioMasterOfflineGetCurrentMetaPass:
  27113. case audioMasterVendorSpecific:
  27114. case audioMasterSetIcon:
  27115. case audioMasterGetLanguage:
  27116. case audioMasterOpenWindow:
  27117. case audioMasterCloseWindow:
  27118. break;
  27119. default:
  27120. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27121. }
  27122. return 0;
  27123. }
  27124. // entry point for all callbacks from the plugin
  27125. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27126. {
  27127. try
  27128. {
  27129. if (effect != 0 && effect->resvd2 != 0)
  27130. {
  27131. return ((VSTPluginInstance*)(effect->resvd2))
  27132. ->handleCallback (opcode, index, value, ptr, opt);
  27133. }
  27134. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27135. }
  27136. catch (...)
  27137. {
  27138. return 0;
  27139. }
  27140. }
  27141. const String VSTPluginInstance::getVersion() const throw()
  27142. {
  27143. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27144. String s;
  27145. if (v == 0 || v == -1)
  27146. v = getVersionNumber();
  27147. if (v != 0)
  27148. {
  27149. int versionBits[4];
  27150. int n = 0;
  27151. while (v != 0)
  27152. {
  27153. versionBits [n++] = (v & 0xff);
  27154. v >>= 8;
  27155. }
  27156. s << 'V';
  27157. while (n > 0)
  27158. {
  27159. s << versionBits [--n];
  27160. if (n > 0)
  27161. s << '.';
  27162. }
  27163. }
  27164. return s;
  27165. }
  27166. int VSTPluginInstance::getUID() const throw()
  27167. {
  27168. int uid = effect != 0 ? effect->uniqueID : 0;
  27169. if (uid == 0)
  27170. uid = module->file.hashCode();
  27171. return uid;
  27172. }
  27173. const String VSTPluginInstance::getCategory() const throw()
  27174. {
  27175. const char* result = 0;
  27176. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27177. {
  27178. case kPlugCategEffect:
  27179. result = "Effect";
  27180. break;
  27181. case kPlugCategSynth:
  27182. result = "Synth";
  27183. break;
  27184. case kPlugCategAnalysis:
  27185. result = "Anaylsis";
  27186. break;
  27187. case kPlugCategMastering:
  27188. result = "Mastering";
  27189. break;
  27190. case kPlugCategSpacializer:
  27191. result = "Spacial";
  27192. break;
  27193. case kPlugCategRoomFx:
  27194. result = "Reverb";
  27195. break;
  27196. case kPlugSurroundFx:
  27197. result = "Surround";
  27198. break;
  27199. case kPlugCategRestoration:
  27200. result = "Restoration";
  27201. break;
  27202. case kPlugCategGenerator:
  27203. result = "Tone generation";
  27204. break;
  27205. default:
  27206. break;
  27207. }
  27208. return result;
  27209. }
  27210. float VSTPluginInstance::getParameter (int index)
  27211. {
  27212. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27213. {
  27214. try
  27215. {
  27216. const ScopedLock sl (lock);
  27217. return effect->getParameter (effect, index);
  27218. }
  27219. catch (...)
  27220. {
  27221. }
  27222. }
  27223. return 0.0f;
  27224. }
  27225. void VSTPluginInstance::setParameter (int index, float newValue)
  27226. {
  27227. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27228. {
  27229. try
  27230. {
  27231. const ScopedLock sl (lock);
  27232. if (effect->getParameter (effect, index) != newValue)
  27233. effect->setParameter (effect, index, newValue);
  27234. }
  27235. catch (...)
  27236. {
  27237. }
  27238. }
  27239. }
  27240. const String VSTPluginInstance::getParameterName (int index)
  27241. {
  27242. if (effect != 0)
  27243. {
  27244. jassert (index >= 0 && index < effect->numParams);
  27245. char nm [256];
  27246. zerostruct (nm);
  27247. dispatch (effGetParamName, index, 0, nm, 0);
  27248. return String (nm).trim();
  27249. }
  27250. return String::empty;
  27251. }
  27252. const String VSTPluginInstance::getParameterLabel (int index) const
  27253. {
  27254. if (effect != 0)
  27255. {
  27256. jassert (index >= 0 && index < effect->numParams);
  27257. char nm [256];
  27258. zerostruct (nm);
  27259. dispatch (effGetParamLabel, index, 0, nm, 0);
  27260. return String (nm).trim();
  27261. }
  27262. return String::empty;
  27263. }
  27264. const String VSTPluginInstance::getParameterText (int index)
  27265. {
  27266. if (effect != 0)
  27267. {
  27268. jassert (index >= 0 && index < effect->numParams);
  27269. char nm [256];
  27270. zerostruct (nm);
  27271. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27272. return String (nm).trim();
  27273. }
  27274. return String::empty;
  27275. }
  27276. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27277. {
  27278. if (effect != 0)
  27279. {
  27280. jassert (index >= 0 && index < effect->numParams);
  27281. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27282. }
  27283. return false;
  27284. }
  27285. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27286. {
  27287. dest.setSize (64 + 4 * getNumParameters());
  27288. dest.fillWith (0);
  27289. getCurrentProgramName().copyToCString ((char*) dest.getData(), 63);
  27290. float* const p = (float*) (((char*) dest.getData()) + 64);
  27291. for (int i = 0; i < getNumParameters(); ++i)
  27292. p[i] = getParameter(i);
  27293. }
  27294. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27295. {
  27296. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27297. float* p = (float*) (((char*) m.getData()) + 64);
  27298. for (int i = 0; i < getNumParameters(); ++i)
  27299. setParameter (i, p[i]);
  27300. }
  27301. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27302. {
  27303. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27304. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27305. }
  27306. const String VSTPluginInstance::getProgramName (int index)
  27307. {
  27308. if (index == getCurrentProgram())
  27309. {
  27310. return getCurrentProgramName();
  27311. }
  27312. else if (effect != 0)
  27313. {
  27314. char nm [256];
  27315. zerostruct (nm);
  27316. if (dispatch (effGetProgramNameIndexed,
  27317. jlimit (0, getNumPrograms(), index),
  27318. -1, nm, 0) != 0)
  27319. {
  27320. return String (nm).trim();
  27321. }
  27322. }
  27323. return programNames [index];
  27324. }
  27325. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27326. {
  27327. if (index == getCurrentProgram())
  27328. {
  27329. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27330. dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f);
  27331. }
  27332. else
  27333. {
  27334. jassertfalse // xxx not implemented!
  27335. }
  27336. }
  27337. void VSTPluginInstance::updateStoredProgramNames()
  27338. {
  27339. if (effect != 0 && getNumPrograms() > 0)
  27340. {
  27341. char nm [256];
  27342. zerostruct (nm);
  27343. // only do this if the plugin can't use indexed names..
  27344. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27345. {
  27346. const int oldProgram = getCurrentProgram();
  27347. MemoryBlock oldSettings;
  27348. createTempParameterStore (oldSettings);
  27349. for (int i = 0; i < getNumPrograms(); ++i)
  27350. {
  27351. setCurrentProgram (i);
  27352. getCurrentProgramName(); // (this updates the list)
  27353. }
  27354. setCurrentProgram (oldProgram);
  27355. restoreFromTempParameterStore (oldSettings);
  27356. }
  27357. }
  27358. }
  27359. const String VSTPluginInstance::getCurrentProgramName()
  27360. {
  27361. if (effect != 0)
  27362. {
  27363. char nm [256];
  27364. zerostruct (nm);
  27365. dispatch (effGetProgramName, 0, 0, nm, 0);
  27366. const int index = getCurrentProgram();
  27367. if (programNames[index].isEmpty())
  27368. {
  27369. while (programNames.size() < index)
  27370. programNames.add (String::empty);
  27371. programNames.set (index, String (nm).trim());
  27372. }
  27373. return String (nm).trim();
  27374. }
  27375. return String::empty;
  27376. }
  27377. const String VSTPluginInstance::getInputChannelName (const int index) const
  27378. {
  27379. if (index >= 0 && index < getNumInputChannels())
  27380. {
  27381. VstPinProperties pinProps;
  27382. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27383. return String (pinProps.label, sizeof (pinProps.label));
  27384. }
  27385. return String::empty;
  27386. }
  27387. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27388. {
  27389. if (index < 0 || index >= getNumInputChannels())
  27390. return false;
  27391. VstPinProperties pinProps;
  27392. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27393. return (pinProps.flags & kVstPinIsStereo) != 0;
  27394. return true;
  27395. }
  27396. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27397. {
  27398. if (index >= 0 && index < getNumOutputChannels())
  27399. {
  27400. VstPinProperties pinProps;
  27401. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27402. return String (pinProps.label, sizeof (pinProps.label));
  27403. }
  27404. return String::empty;
  27405. }
  27406. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27407. {
  27408. if (index < 0 || index >= getNumOutputChannels())
  27409. return false;
  27410. VstPinProperties pinProps;
  27411. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27412. return (pinProps.flags & kVstPinIsStereo) != 0;
  27413. return true;
  27414. }
  27415. void VSTPluginInstance::setPower (const bool on)
  27416. {
  27417. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27418. isPowerOn = on;
  27419. }
  27420. const int defaultMaxSizeMB = 64;
  27421. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27422. {
  27423. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27424. }
  27425. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27426. {
  27427. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27428. }
  27429. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27430. {
  27431. loadFromFXBFile (data, sizeInBytes);
  27432. }
  27433. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27434. {
  27435. loadFromFXBFile (data, sizeInBytes);
  27436. }
  27437. VSTPluginFormat::VSTPluginFormat()
  27438. {
  27439. }
  27440. VSTPluginFormat::~VSTPluginFormat()
  27441. {
  27442. }
  27443. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27444. const String& fileOrIdentifier)
  27445. {
  27446. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27447. return;
  27448. PluginDescription desc;
  27449. desc.fileOrIdentifier = fileOrIdentifier;
  27450. desc.uid = 0;
  27451. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27452. if (instance == 0)
  27453. return;
  27454. try
  27455. {
  27456. #if JUCE_MAC
  27457. if (instance->module->resFileId != 0)
  27458. UseResFile (instance->module->resFileId);
  27459. #endif
  27460. instance->fillInPluginDescription (desc);
  27461. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27462. if (category != kPlugCategShell)
  27463. {
  27464. // Normal plugin...
  27465. results.add (new PluginDescription (desc));
  27466. ++insideVSTCallback;
  27467. instance->dispatch (effOpen, 0, 0, 0, 0);
  27468. --insideVSTCallback;
  27469. }
  27470. else
  27471. {
  27472. // It's a shell plugin, so iterate all the subtypes...
  27473. char shellEffectName [64];
  27474. for (;;)
  27475. {
  27476. zerostruct (shellEffectName);
  27477. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27478. if (uid == 0)
  27479. {
  27480. break;
  27481. }
  27482. else
  27483. {
  27484. desc.uid = uid;
  27485. desc.name = shellEffectName;
  27486. bool alreadyThere = false;
  27487. for (int i = results.size(); --i >= 0;)
  27488. {
  27489. PluginDescription* const d = results.getUnchecked(i);
  27490. if (d->isDuplicateOf (desc))
  27491. {
  27492. alreadyThere = true;
  27493. break;
  27494. }
  27495. }
  27496. if (! alreadyThere)
  27497. results.add (new PluginDescription (desc));
  27498. }
  27499. }
  27500. }
  27501. }
  27502. catch (...)
  27503. {
  27504. // crashed while loading...
  27505. }
  27506. }
  27507. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27508. {
  27509. ScopedPointer <VSTPluginInstance> result;
  27510. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27511. {
  27512. File file (desc.fileOrIdentifier);
  27513. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27514. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27515. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27516. if (module != 0)
  27517. {
  27518. shellUIDToCreate = desc.uid;
  27519. result = new VSTPluginInstance (module);
  27520. if (result->effect != 0)
  27521. {
  27522. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27523. result->initialise();
  27524. }
  27525. else
  27526. {
  27527. result = 0;
  27528. }
  27529. }
  27530. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27531. }
  27532. return result.release();
  27533. }
  27534. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27535. {
  27536. const File f (fileOrIdentifier);
  27537. #if JUCE_MAC
  27538. if (f.isDirectory() && f.hasFileExtension (T(".vst")))
  27539. return true;
  27540. #if JUCE_PPC
  27541. FSRef fileRef;
  27542. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27543. {
  27544. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27545. if (resFileId != -1)
  27546. {
  27547. const int numEffects = Count1Resources ('aEff');
  27548. CloseResFile (resFileId);
  27549. if (numEffects > 0)
  27550. return true;
  27551. }
  27552. }
  27553. #endif
  27554. return false;
  27555. #elif JUCE_WIN32
  27556. return f.existsAsFile()
  27557. && f.hasFileExtension (T(".dll"));
  27558. #elif JUCE_LINUX
  27559. return f.existsAsFile()
  27560. && f.hasFileExtension (T(".so"));
  27561. #endif
  27562. }
  27563. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27564. {
  27565. return fileOrIdentifier;
  27566. }
  27567. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27568. {
  27569. return File (desc.fileOrIdentifier).exists();
  27570. }
  27571. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27572. {
  27573. StringArray results;
  27574. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27575. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27576. return results;
  27577. }
  27578. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27579. {
  27580. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27581. // .component or .vst directories.
  27582. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27583. while (iter.next())
  27584. {
  27585. const File f (iter.getFile());
  27586. bool isPlugin = false;
  27587. if (fileMightContainThisPluginType (f.getFullPathName()))
  27588. {
  27589. isPlugin = true;
  27590. results.add (f.getFullPathName());
  27591. }
  27592. if (recursive && (! isPlugin) && f.isDirectory())
  27593. recursiveFileSearch (results, f, true);
  27594. }
  27595. }
  27596. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27597. {
  27598. #if JUCE_MAC
  27599. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27600. #elif JUCE_WIN32
  27601. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27602. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27603. #elif JUCE_LINUX
  27604. return FileSearchPath ("/usr/lib/vst");
  27605. #endif
  27606. }
  27607. END_JUCE_NAMESPACE
  27608. #endif
  27609. #undef log
  27610. #endif
  27611. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27612. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27613. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27614. BEGIN_JUCE_NAMESPACE
  27615. AudioProcessor::AudioProcessor()
  27616. : playHead (0),
  27617. activeEditor (0),
  27618. sampleRate (0),
  27619. blockSize (0),
  27620. numInputChannels (0),
  27621. numOutputChannels (0),
  27622. latencySamples (0),
  27623. suspended (false),
  27624. nonRealtime (false)
  27625. {
  27626. }
  27627. AudioProcessor::~AudioProcessor()
  27628. {
  27629. // ooh, nasty - the editor should have been deleted before the filter
  27630. // that it refers to is deleted..
  27631. jassert (activeEditor == 0);
  27632. #ifdef JUCE_DEBUG
  27633. // This will fail if you've called beginParameterChangeGesture() for one
  27634. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27635. jassert (changingParams.countNumberOfSetBits() == 0);
  27636. #endif
  27637. }
  27638. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27639. {
  27640. playHead = newPlayHead;
  27641. }
  27642. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27643. {
  27644. const ScopedLock sl (listenerLock);
  27645. listeners.addIfNotAlreadyThere (newListener);
  27646. }
  27647. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27648. {
  27649. const ScopedLock sl (listenerLock);
  27650. listeners.removeValue (listenerToRemove);
  27651. }
  27652. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27653. const int numOuts,
  27654. const double sampleRate_,
  27655. const int blockSize_) throw()
  27656. {
  27657. numInputChannels = numIns;
  27658. numOutputChannels = numOuts;
  27659. sampleRate = sampleRate_;
  27660. blockSize = blockSize_;
  27661. }
  27662. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27663. {
  27664. nonRealtime = nonRealtime_;
  27665. }
  27666. void AudioProcessor::setLatencySamples (const int newLatency)
  27667. {
  27668. if (latencySamples != newLatency)
  27669. {
  27670. latencySamples = newLatency;
  27671. updateHostDisplay();
  27672. }
  27673. }
  27674. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27675. const float newValue)
  27676. {
  27677. setParameter (parameterIndex, newValue);
  27678. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27679. }
  27680. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27681. {
  27682. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27683. for (int i = listeners.size(); --i >= 0;)
  27684. {
  27685. AudioProcessorListener* l;
  27686. {
  27687. const ScopedLock sl (listenerLock);
  27688. l = (AudioProcessorListener*) listeners [i];
  27689. }
  27690. if (l != 0)
  27691. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27692. }
  27693. }
  27694. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27695. {
  27696. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27697. #ifdef JUCE_DEBUG
  27698. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27699. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27700. jassert (! changingParams [parameterIndex]);
  27701. changingParams.setBit (parameterIndex);
  27702. #endif
  27703. for (int i = listeners.size(); --i >= 0;)
  27704. {
  27705. AudioProcessorListener* l;
  27706. {
  27707. const ScopedLock sl (listenerLock);
  27708. l = (AudioProcessorListener*) listeners [i];
  27709. }
  27710. if (l != 0)
  27711. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27712. }
  27713. }
  27714. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27715. {
  27716. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27717. #ifdef JUCE_DEBUG
  27718. // This means you've called endParameterChangeGesture without having previously called
  27719. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27720. // calls matched correctly.
  27721. jassert (changingParams [parameterIndex]);
  27722. changingParams.clearBit (parameterIndex);
  27723. #endif
  27724. for (int i = listeners.size(); --i >= 0;)
  27725. {
  27726. AudioProcessorListener* l;
  27727. {
  27728. const ScopedLock sl (listenerLock);
  27729. l = (AudioProcessorListener*) listeners [i];
  27730. }
  27731. if (l != 0)
  27732. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27733. }
  27734. }
  27735. void AudioProcessor::updateHostDisplay()
  27736. {
  27737. for (int i = listeners.size(); --i >= 0;)
  27738. {
  27739. AudioProcessorListener* l;
  27740. {
  27741. const ScopedLock sl (listenerLock);
  27742. l = (AudioProcessorListener*) listeners [i];
  27743. }
  27744. if (l != 0)
  27745. l->audioProcessorChanged (this);
  27746. }
  27747. }
  27748. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27749. {
  27750. return true;
  27751. }
  27752. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27753. {
  27754. return false;
  27755. }
  27756. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27757. {
  27758. const ScopedLock sl (callbackLock);
  27759. suspended = shouldBeSuspended;
  27760. }
  27761. void AudioProcessor::reset()
  27762. {
  27763. }
  27764. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27765. {
  27766. const ScopedLock sl (callbackLock);
  27767. jassert (activeEditor == editor);
  27768. if (activeEditor == editor)
  27769. activeEditor = 0;
  27770. }
  27771. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  27772. {
  27773. if (activeEditor != 0)
  27774. return activeEditor;
  27775. AudioProcessorEditor* const ed = createEditor();
  27776. if (ed != 0)
  27777. {
  27778. // you must give your editor comp a size before returning it..
  27779. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  27780. const ScopedLock sl (callbackLock);
  27781. activeEditor = ed;
  27782. }
  27783. return ed;
  27784. }
  27785. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  27786. {
  27787. getStateInformation (destData);
  27788. }
  27789. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27790. {
  27791. setStateInformation (data, sizeInBytes);
  27792. }
  27793. // magic number to identify memory blocks that we've stored as XML
  27794. const uint32 magicXmlNumber = 0x21324356;
  27795. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  27796. JUCE_NAMESPACE::MemoryBlock& destData)
  27797. {
  27798. const String xmlString (xml.createDocument (String::empty, true, false));
  27799. const int stringLength = xmlString.getNumBytesAsUTF8();
  27800. destData.setSize (stringLength + 10);
  27801. char* const d = (char*) destData.getData();
  27802. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  27803. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  27804. xmlString.copyToUTF8 (d + 8, stringLength + 1);
  27805. }
  27806. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  27807. const int sizeInBytes)
  27808. {
  27809. if (sizeInBytes > 8
  27810. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  27811. {
  27812. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  27813. if (stringLength > 0)
  27814. {
  27815. XmlDocument doc (String::fromUTF8 (((const char*) data) + 8,
  27816. jmin ((sizeInBytes - 8), stringLength)));
  27817. return doc.getDocumentElement();
  27818. }
  27819. }
  27820. return 0;
  27821. }
  27822. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  27823. {
  27824. }
  27825. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  27826. {
  27827. }
  27828. END_JUCE_NAMESPACE
  27829. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  27830. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  27831. BEGIN_JUCE_NAMESPACE
  27832. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  27833. : owner (owner_)
  27834. {
  27835. // the filter must be valid..
  27836. jassert (owner != 0);
  27837. }
  27838. AudioProcessorEditor::~AudioProcessorEditor()
  27839. {
  27840. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  27841. // filter for some reason..
  27842. jassert (owner->getActiveEditor() != this);
  27843. }
  27844. END_JUCE_NAMESPACE
  27845. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  27846. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  27847. BEGIN_JUCE_NAMESPACE
  27848. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  27849. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  27850. : id (id_),
  27851. processor (processor_),
  27852. isPrepared (false)
  27853. {
  27854. jassert (processor_ != 0);
  27855. }
  27856. AudioProcessorGraph::Node::~Node()
  27857. {
  27858. delete processor;
  27859. }
  27860. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  27861. AudioProcessorGraph* const graph)
  27862. {
  27863. if (! isPrepared)
  27864. {
  27865. isPrepared = true;
  27866. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27867. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  27868. if (ioProc != 0)
  27869. ioProc->setParentGraph (graph);
  27870. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  27871. processor->getNumOutputChannels(),
  27872. sampleRate, blockSize);
  27873. processor->prepareToPlay (sampleRate, blockSize);
  27874. }
  27875. }
  27876. void AudioProcessorGraph::Node::unprepare()
  27877. {
  27878. if (isPrepared)
  27879. {
  27880. isPrepared = false;
  27881. processor->releaseResources();
  27882. }
  27883. }
  27884. AudioProcessorGraph::AudioProcessorGraph()
  27885. : lastNodeId (0),
  27886. renderingBuffers (1, 1),
  27887. currentAudioOutputBuffer (1, 1)
  27888. {
  27889. }
  27890. AudioProcessorGraph::~AudioProcessorGraph()
  27891. {
  27892. clearRenderingSequence();
  27893. clear();
  27894. }
  27895. const String AudioProcessorGraph::getName() const
  27896. {
  27897. return "Audio Graph";
  27898. }
  27899. void AudioProcessorGraph::clear()
  27900. {
  27901. nodes.clear();
  27902. connections.clear();
  27903. triggerAsyncUpdate();
  27904. }
  27905. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  27906. {
  27907. for (int i = nodes.size(); --i >= 0;)
  27908. if (nodes.getUnchecked(i)->id == nodeId)
  27909. return nodes.getUnchecked(i);
  27910. return 0;
  27911. }
  27912. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  27913. uint32 nodeId)
  27914. {
  27915. if (newProcessor == 0)
  27916. {
  27917. jassertfalse
  27918. return 0;
  27919. }
  27920. if (nodeId == 0)
  27921. {
  27922. nodeId = ++lastNodeId;
  27923. }
  27924. else
  27925. {
  27926. // you can't add a node with an id that already exists in the graph..
  27927. jassert (getNodeForId (nodeId) == 0);
  27928. removeNode (nodeId);
  27929. }
  27930. lastNodeId = nodeId;
  27931. Node* const n = new Node (nodeId, newProcessor);
  27932. nodes.add (n);
  27933. triggerAsyncUpdate();
  27934. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27935. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  27936. if (ioProc != 0)
  27937. ioProc->setParentGraph (this);
  27938. return n;
  27939. }
  27940. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  27941. {
  27942. disconnectNode (nodeId);
  27943. for (int i = nodes.size(); --i >= 0;)
  27944. {
  27945. if (nodes.getUnchecked(i)->id == nodeId)
  27946. {
  27947. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27948. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  27949. if (ioProc != 0)
  27950. ioProc->setParentGraph (0);
  27951. nodes.remove (i);
  27952. triggerAsyncUpdate();
  27953. return true;
  27954. }
  27955. }
  27956. return false;
  27957. }
  27958. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  27959. const int sourceChannelIndex,
  27960. const uint32 destNodeId,
  27961. const int destChannelIndex) const
  27962. {
  27963. for (int i = connections.size(); --i >= 0;)
  27964. {
  27965. const Connection* const c = connections.getUnchecked(i);
  27966. if (c->sourceNodeId == sourceNodeId
  27967. && c->destNodeId == destNodeId
  27968. && c->sourceChannelIndex == sourceChannelIndex
  27969. && c->destChannelIndex == destChannelIndex)
  27970. {
  27971. return c;
  27972. }
  27973. }
  27974. return 0;
  27975. }
  27976. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  27977. const uint32 possibleDestNodeId) const
  27978. {
  27979. for (int i = connections.size(); --i >= 0;)
  27980. {
  27981. const Connection* const c = connections.getUnchecked(i);
  27982. if (c->sourceNodeId == possibleSourceNodeId
  27983. && c->destNodeId == possibleDestNodeId)
  27984. {
  27985. return true;
  27986. }
  27987. }
  27988. return false;
  27989. }
  27990. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  27991. const int sourceChannelIndex,
  27992. const uint32 destNodeId,
  27993. const int destChannelIndex) const
  27994. {
  27995. if (sourceChannelIndex < 0
  27996. || destChannelIndex < 0
  27997. || sourceNodeId == destNodeId
  27998. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  27999. return false;
  28000. const Node* const source = getNodeForId (sourceNodeId);
  28001. if (source == 0
  28002. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28003. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28004. return false;
  28005. const Node* const dest = getNodeForId (destNodeId);
  28006. if (dest == 0
  28007. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28008. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28009. return false;
  28010. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28011. destNodeId, destChannelIndex) == 0;
  28012. }
  28013. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28014. const int sourceChannelIndex,
  28015. const uint32 destNodeId,
  28016. const int destChannelIndex)
  28017. {
  28018. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28019. return false;
  28020. Connection* const c = new Connection();
  28021. c->sourceNodeId = sourceNodeId;
  28022. c->sourceChannelIndex = sourceChannelIndex;
  28023. c->destNodeId = destNodeId;
  28024. c->destChannelIndex = destChannelIndex;
  28025. connections.add (c);
  28026. triggerAsyncUpdate();
  28027. return true;
  28028. }
  28029. void AudioProcessorGraph::removeConnection (const int index)
  28030. {
  28031. connections.remove (index);
  28032. triggerAsyncUpdate();
  28033. }
  28034. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28035. const uint32 destNodeId, const int destChannelIndex)
  28036. {
  28037. bool doneAnything = false;
  28038. for (int i = connections.size(); --i >= 0;)
  28039. {
  28040. const Connection* const c = connections.getUnchecked(i);
  28041. if (c->sourceNodeId == sourceNodeId
  28042. && c->destNodeId == destNodeId
  28043. && c->sourceChannelIndex == sourceChannelIndex
  28044. && c->destChannelIndex == destChannelIndex)
  28045. {
  28046. removeConnection (i);
  28047. doneAnything = true;
  28048. triggerAsyncUpdate();
  28049. }
  28050. }
  28051. return doneAnything;
  28052. }
  28053. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28054. {
  28055. bool doneAnything = false;
  28056. for (int i = connections.size(); --i >= 0;)
  28057. {
  28058. const Connection* const c = connections.getUnchecked(i);
  28059. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28060. {
  28061. removeConnection (i);
  28062. doneAnything = true;
  28063. triggerAsyncUpdate();
  28064. }
  28065. }
  28066. return doneAnything;
  28067. }
  28068. bool AudioProcessorGraph::removeIllegalConnections()
  28069. {
  28070. bool doneAnything = false;
  28071. for (int i = connections.size(); --i >= 0;)
  28072. {
  28073. const Connection* const c = connections.getUnchecked(i);
  28074. const Node* const source = getNodeForId (c->sourceNodeId);
  28075. const Node* const dest = getNodeForId (c->destNodeId);
  28076. if (source == 0 || dest == 0
  28077. || (c->sourceChannelIndex != midiChannelIndex
  28078. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28079. || (c->sourceChannelIndex == midiChannelIndex
  28080. && ! source->processor->producesMidi())
  28081. || (c->destChannelIndex != midiChannelIndex
  28082. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28083. || (c->destChannelIndex == midiChannelIndex
  28084. && ! dest->processor->acceptsMidi()))
  28085. {
  28086. removeConnection (i);
  28087. doneAnything = true;
  28088. triggerAsyncUpdate();
  28089. }
  28090. }
  28091. return doneAnything;
  28092. }
  28093. namespace GraphRenderingOps
  28094. {
  28095. class AudioGraphRenderingOp
  28096. {
  28097. public:
  28098. AudioGraphRenderingOp() {}
  28099. virtual ~AudioGraphRenderingOp() {}
  28100. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28101. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28102. const int numSamples) = 0;
  28103. juce_UseDebuggingNewOperator
  28104. };
  28105. class ClearChannelOp : public AudioGraphRenderingOp
  28106. {
  28107. public:
  28108. ClearChannelOp (const int channelNum_)
  28109. : channelNum (channelNum_)
  28110. {}
  28111. ~ClearChannelOp() {}
  28112. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28113. {
  28114. sharedBufferChans.clear (channelNum, 0, numSamples);
  28115. }
  28116. private:
  28117. const int channelNum;
  28118. ClearChannelOp (const ClearChannelOp&);
  28119. ClearChannelOp& operator= (const ClearChannelOp&);
  28120. };
  28121. class CopyChannelOp : public AudioGraphRenderingOp
  28122. {
  28123. public:
  28124. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28125. : srcChannelNum (srcChannelNum_),
  28126. dstChannelNum (dstChannelNum_)
  28127. {}
  28128. ~CopyChannelOp() {}
  28129. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28130. {
  28131. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28132. }
  28133. private:
  28134. const int srcChannelNum, dstChannelNum;
  28135. CopyChannelOp (const CopyChannelOp&);
  28136. CopyChannelOp& operator= (const CopyChannelOp&);
  28137. };
  28138. class AddChannelOp : public AudioGraphRenderingOp
  28139. {
  28140. public:
  28141. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28142. : srcChannelNum (srcChannelNum_),
  28143. dstChannelNum (dstChannelNum_)
  28144. {}
  28145. ~AddChannelOp() {}
  28146. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28147. {
  28148. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28149. }
  28150. private:
  28151. const int srcChannelNum, dstChannelNum;
  28152. AddChannelOp (const AddChannelOp&);
  28153. AddChannelOp& operator= (const AddChannelOp&);
  28154. };
  28155. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28156. {
  28157. public:
  28158. ClearMidiBufferOp (const int bufferNum_)
  28159. : bufferNum (bufferNum_)
  28160. {}
  28161. ~ClearMidiBufferOp() {}
  28162. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28163. {
  28164. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28165. }
  28166. private:
  28167. const int bufferNum;
  28168. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28169. ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28170. };
  28171. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28172. {
  28173. public:
  28174. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28175. : srcBufferNum (srcBufferNum_),
  28176. dstBufferNum (dstBufferNum_)
  28177. {}
  28178. ~CopyMidiBufferOp() {}
  28179. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28180. {
  28181. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28182. }
  28183. private:
  28184. const int srcBufferNum, dstBufferNum;
  28185. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28186. CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28187. };
  28188. class AddMidiBufferOp : public AudioGraphRenderingOp
  28189. {
  28190. public:
  28191. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28192. : srcBufferNum (srcBufferNum_),
  28193. dstBufferNum (dstBufferNum_)
  28194. {}
  28195. ~AddMidiBufferOp() {}
  28196. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28197. {
  28198. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28199. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28200. }
  28201. private:
  28202. const int srcBufferNum, dstBufferNum;
  28203. AddMidiBufferOp (const AddMidiBufferOp&);
  28204. AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28205. };
  28206. class ProcessBufferOp : public AudioGraphRenderingOp
  28207. {
  28208. public:
  28209. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28210. const Array <int>& audioChannelsToUse_,
  28211. const int totalChans_,
  28212. const int midiBufferToUse_)
  28213. : node (node_),
  28214. processor (node_->processor),
  28215. audioChannelsToUse (audioChannelsToUse_),
  28216. totalChans (jmax (1, totalChans_)),
  28217. midiBufferToUse (midiBufferToUse_)
  28218. {
  28219. channels.calloc (totalChans);
  28220. while (audioChannelsToUse.size() < totalChans)
  28221. audioChannelsToUse.add (0);
  28222. }
  28223. ~ProcessBufferOp()
  28224. {
  28225. }
  28226. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28227. {
  28228. for (int i = totalChans; --i >= 0;)
  28229. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28230. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28231. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28232. }
  28233. const AudioProcessorGraph::Node::Ptr node;
  28234. AudioProcessor* const processor;
  28235. private:
  28236. Array <int> audioChannelsToUse;
  28237. HeapBlock <float*> channels;
  28238. int totalChans;
  28239. int midiBufferToUse;
  28240. ProcessBufferOp (const ProcessBufferOp&);
  28241. ProcessBufferOp& operator= (const ProcessBufferOp&);
  28242. };
  28243. class RenderingOpSequenceCalculator
  28244. {
  28245. public:
  28246. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28247. const VoidArray& orderedNodes_,
  28248. VoidArray& renderingOps)
  28249. : graph (graph_),
  28250. orderedNodes (orderedNodes_)
  28251. {
  28252. nodeIds.add (-2); // first buffer is read-only zeros
  28253. channels.add (0);
  28254. midiNodeIds.add (-2);
  28255. for (int i = 0; i < orderedNodes.size(); ++i)
  28256. {
  28257. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28258. renderingOps, i);
  28259. markAnyUnusedBuffersAsFree (i);
  28260. }
  28261. }
  28262. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28263. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28264. juce_UseDebuggingNewOperator
  28265. private:
  28266. AudioProcessorGraph& graph;
  28267. const VoidArray& orderedNodes;
  28268. Array <int> nodeIds, channels, midiNodeIds;
  28269. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28270. VoidArray& renderingOps,
  28271. const int ourRenderingIndex)
  28272. {
  28273. const int numIns = node->processor->getNumInputChannels();
  28274. const int numOuts = node->processor->getNumOutputChannels();
  28275. const int totalChans = jmax (numIns, numOuts);
  28276. Array <int> audioChannelsToUse;
  28277. int midiBufferToUse = -1;
  28278. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28279. {
  28280. // get a list of all the inputs to this node
  28281. Array <int> sourceNodes, sourceOutputChans;
  28282. for (int i = graph.getNumConnections(); --i >= 0;)
  28283. {
  28284. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28285. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28286. {
  28287. sourceNodes.add (c->sourceNodeId);
  28288. sourceOutputChans.add (c->sourceChannelIndex);
  28289. }
  28290. }
  28291. int bufIndex = -1;
  28292. if (sourceNodes.size() == 0)
  28293. {
  28294. // unconnected input channel
  28295. if (inputChan >= numOuts)
  28296. {
  28297. bufIndex = getReadOnlyEmptyBuffer();
  28298. jassert (bufIndex >= 0);
  28299. }
  28300. else
  28301. {
  28302. bufIndex = getFreeBuffer (false);
  28303. renderingOps.add (new ClearChannelOp (bufIndex));
  28304. }
  28305. }
  28306. else if (sourceNodes.size() == 1)
  28307. {
  28308. // channel with a straightforward single input..
  28309. const int srcNode = sourceNodes.getUnchecked(0);
  28310. const int srcChan = sourceOutputChans.getUnchecked(0);
  28311. bufIndex = getBufferContaining (srcNode, srcChan);
  28312. if (bufIndex < 0)
  28313. {
  28314. // if not found, this is probably a feedback loop
  28315. bufIndex = getReadOnlyEmptyBuffer();
  28316. jassert (bufIndex >= 0);
  28317. }
  28318. if (inputChan < numOuts
  28319. && isBufferNeededLater (ourRenderingIndex,
  28320. inputChan,
  28321. srcNode, srcChan))
  28322. {
  28323. // can't mess up this channel because it's needed later by another node, so we
  28324. // need to use a copy of it..
  28325. const int newFreeBuffer = getFreeBuffer (false);
  28326. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28327. bufIndex = newFreeBuffer;
  28328. }
  28329. }
  28330. else
  28331. {
  28332. // channel with a mix of several inputs..
  28333. // try to find a re-usable channel from our inputs..
  28334. int reusableInputIndex = -1;
  28335. for (int i = 0; i < sourceNodes.size(); ++i)
  28336. {
  28337. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28338. sourceOutputChans.getUnchecked(i));
  28339. if (sourceBufIndex >= 0
  28340. && ! isBufferNeededLater (ourRenderingIndex,
  28341. inputChan,
  28342. sourceNodes.getUnchecked(i),
  28343. sourceOutputChans.getUnchecked(i)))
  28344. {
  28345. // we've found one of our input chans that can be re-used..
  28346. reusableInputIndex = i;
  28347. bufIndex = sourceBufIndex;
  28348. break;
  28349. }
  28350. }
  28351. if (reusableInputIndex < 0)
  28352. {
  28353. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28354. bufIndex = getFreeBuffer (false);
  28355. jassert (bufIndex != 0);
  28356. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28357. sourceOutputChans.getUnchecked (0));
  28358. if (srcIndex < 0)
  28359. {
  28360. // if not found, this is probably a feedback loop
  28361. renderingOps.add (new ClearChannelOp (bufIndex));
  28362. }
  28363. else
  28364. {
  28365. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28366. }
  28367. reusableInputIndex = 0;
  28368. }
  28369. for (int j = 0; j < sourceNodes.size(); ++j)
  28370. {
  28371. if (j != reusableInputIndex)
  28372. {
  28373. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28374. sourceOutputChans.getUnchecked(j));
  28375. if (srcIndex >= 0)
  28376. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28377. }
  28378. }
  28379. }
  28380. jassert (bufIndex >= 0);
  28381. audioChannelsToUse.add (bufIndex);
  28382. if (inputChan < numOuts)
  28383. markBufferAsContaining (bufIndex, node->id, inputChan);
  28384. }
  28385. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28386. {
  28387. const int bufIndex = getFreeBuffer (false);
  28388. jassert (bufIndex != 0);
  28389. audioChannelsToUse.add (bufIndex);
  28390. markBufferAsContaining (bufIndex, node->id, outputChan);
  28391. }
  28392. // Now the same thing for midi..
  28393. Array <int> midiSourceNodes;
  28394. for (int i = graph.getNumConnections(); --i >= 0;)
  28395. {
  28396. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28397. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28398. midiSourceNodes.add (c->sourceNodeId);
  28399. }
  28400. if (midiSourceNodes.size() == 0)
  28401. {
  28402. // No midi inputs..
  28403. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28404. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28405. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28406. }
  28407. else if (midiSourceNodes.size() == 1)
  28408. {
  28409. // One midi input..
  28410. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28411. AudioProcessorGraph::midiChannelIndex);
  28412. if (midiBufferToUse >= 0)
  28413. {
  28414. if (isBufferNeededLater (ourRenderingIndex,
  28415. AudioProcessorGraph::midiChannelIndex,
  28416. midiSourceNodes.getUnchecked(0),
  28417. AudioProcessorGraph::midiChannelIndex))
  28418. {
  28419. // can't mess up this channel because it's needed later by another node, so we
  28420. // need to use a copy of it..
  28421. const int newFreeBuffer = getFreeBuffer (true);
  28422. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28423. midiBufferToUse = newFreeBuffer;
  28424. }
  28425. }
  28426. else
  28427. {
  28428. // probably a feedback loop, so just use an empty one..
  28429. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28430. }
  28431. }
  28432. else
  28433. {
  28434. // More than one midi input being mixed..
  28435. int reusableInputIndex = -1;
  28436. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28437. {
  28438. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28439. AudioProcessorGraph::midiChannelIndex);
  28440. if (sourceBufIndex >= 0
  28441. && ! isBufferNeededLater (ourRenderingIndex,
  28442. AudioProcessorGraph::midiChannelIndex,
  28443. midiSourceNodes.getUnchecked(i),
  28444. AudioProcessorGraph::midiChannelIndex))
  28445. {
  28446. // we've found one of our input buffers that can be re-used..
  28447. reusableInputIndex = i;
  28448. midiBufferToUse = sourceBufIndex;
  28449. break;
  28450. }
  28451. }
  28452. if (reusableInputIndex < 0)
  28453. {
  28454. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28455. midiBufferToUse = getFreeBuffer (true);
  28456. jassert (midiBufferToUse >= 0);
  28457. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28458. AudioProcessorGraph::midiChannelIndex);
  28459. if (srcIndex >= 0)
  28460. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28461. else
  28462. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28463. reusableInputIndex = 0;
  28464. }
  28465. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28466. {
  28467. if (j != reusableInputIndex)
  28468. {
  28469. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28470. AudioProcessorGraph::midiChannelIndex);
  28471. if (srcIndex >= 0)
  28472. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28473. }
  28474. }
  28475. }
  28476. if (node->processor->producesMidi())
  28477. markBufferAsContaining (midiBufferToUse, node->id,
  28478. AudioProcessorGraph::midiChannelIndex);
  28479. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28480. totalChans, midiBufferToUse));
  28481. }
  28482. int getFreeBuffer (const bool forMidi)
  28483. {
  28484. if (forMidi)
  28485. {
  28486. for (int i = 1; i < midiNodeIds.size(); ++i)
  28487. if (midiNodeIds.getUnchecked(i) < 0)
  28488. return i;
  28489. midiNodeIds.add (-1);
  28490. return midiNodeIds.size() - 1;
  28491. }
  28492. else
  28493. {
  28494. for (int i = 1; i < nodeIds.size(); ++i)
  28495. if (nodeIds.getUnchecked(i) < 0)
  28496. return i;
  28497. nodeIds.add (-1);
  28498. channels.add (0);
  28499. return nodeIds.size() - 1;
  28500. }
  28501. }
  28502. int getReadOnlyEmptyBuffer() const
  28503. {
  28504. return 0;
  28505. }
  28506. int getBufferContaining (const int nodeId, const int outputChannel) const
  28507. {
  28508. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28509. {
  28510. for (int i = midiNodeIds.size(); --i >= 0;)
  28511. if (midiNodeIds.getUnchecked(i) == nodeId)
  28512. return i;
  28513. }
  28514. else
  28515. {
  28516. for (int i = nodeIds.size(); --i >= 0;)
  28517. if (nodeIds.getUnchecked(i) == nodeId
  28518. && channels.getUnchecked(i) == outputChannel)
  28519. return i;
  28520. }
  28521. return -1;
  28522. }
  28523. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28524. {
  28525. int i;
  28526. for (i = 0; i < nodeIds.size(); ++i)
  28527. {
  28528. if (nodeIds.getUnchecked(i) >= 0
  28529. && ! isBufferNeededLater (stepIndex, -1,
  28530. nodeIds.getUnchecked(i),
  28531. channels.getUnchecked(i)))
  28532. {
  28533. nodeIds.set (i, -1);
  28534. }
  28535. }
  28536. for (i = 0; i < midiNodeIds.size(); ++i)
  28537. {
  28538. if (midiNodeIds.getUnchecked(i) >= 0
  28539. && ! isBufferNeededLater (stepIndex, -1,
  28540. midiNodeIds.getUnchecked(i),
  28541. AudioProcessorGraph::midiChannelIndex))
  28542. {
  28543. midiNodeIds.set (i, -1);
  28544. }
  28545. }
  28546. }
  28547. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28548. int inputChannelOfIndexToIgnore,
  28549. const int nodeId,
  28550. const int outputChanIndex) const
  28551. {
  28552. while (stepIndexToSearchFrom < orderedNodes.size())
  28553. {
  28554. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28555. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28556. {
  28557. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28558. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28559. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28560. return true;
  28561. }
  28562. else
  28563. {
  28564. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28565. if (i != inputChannelOfIndexToIgnore
  28566. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28567. node->id, i) != 0)
  28568. return true;
  28569. }
  28570. inputChannelOfIndexToIgnore = -1;
  28571. ++stepIndexToSearchFrom;
  28572. }
  28573. return false;
  28574. }
  28575. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28576. {
  28577. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28578. {
  28579. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28580. midiNodeIds.set (bufferNum, nodeId);
  28581. }
  28582. else
  28583. {
  28584. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28585. nodeIds.set (bufferNum, nodeId);
  28586. channels.set (bufferNum, outputIndex);
  28587. }
  28588. }
  28589. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28590. RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28591. };
  28592. }
  28593. void AudioProcessorGraph::clearRenderingSequence()
  28594. {
  28595. const ScopedLock sl (renderLock);
  28596. for (int i = renderingOps.size(); --i >= 0;)
  28597. {
  28598. GraphRenderingOps::AudioGraphRenderingOp* const r
  28599. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28600. renderingOps.remove (i);
  28601. delete r;
  28602. }
  28603. }
  28604. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28605. const uint32 possibleDestinationId,
  28606. const int recursionCheck) const
  28607. {
  28608. if (recursionCheck > 0)
  28609. {
  28610. for (int i = connections.size(); --i >= 0;)
  28611. {
  28612. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28613. if (c->destNodeId == possibleDestinationId
  28614. && (c->sourceNodeId == possibleInputId
  28615. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28616. return true;
  28617. }
  28618. }
  28619. return false;
  28620. }
  28621. void AudioProcessorGraph::buildRenderingSequence()
  28622. {
  28623. VoidArray newRenderingOps;
  28624. int numRenderingBuffersNeeded = 2;
  28625. int numMidiBuffersNeeded = 1;
  28626. {
  28627. MessageManagerLock mml;
  28628. VoidArray orderedNodes;
  28629. int i;
  28630. for (i = 0; i < nodes.size(); ++i)
  28631. {
  28632. Node* const node = nodes.getUnchecked(i);
  28633. node->prepare (getSampleRate(), getBlockSize(), this);
  28634. int j = 0;
  28635. for (; j < orderedNodes.size(); ++j)
  28636. if (isAnInputTo (node->id,
  28637. ((Node*) orderedNodes.getUnchecked (j))->id,
  28638. nodes.size() + 1))
  28639. break;
  28640. orderedNodes.insert (j, node);
  28641. }
  28642. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28643. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28644. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28645. }
  28646. VoidArray oldRenderingOps (renderingOps);
  28647. {
  28648. // swap over to the new rendering sequence..
  28649. const ScopedLock sl (renderLock);
  28650. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28651. renderingBuffers.clear();
  28652. for (int i = midiBuffers.size(); --i >= 0;)
  28653. midiBuffers.getUnchecked(i)->clear();
  28654. while (midiBuffers.size() < numMidiBuffersNeeded)
  28655. midiBuffers.add (new MidiBuffer());
  28656. renderingOps = newRenderingOps;
  28657. }
  28658. for (int i = oldRenderingOps.size(); --i >= 0;)
  28659. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28660. }
  28661. void AudioProcessorGraph::handleAsyncUpdate()
  28662. {
  28663. buildRenderingSequence();
  28664. }
  28665. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28666. {
  28667. currentAudioInputBuffer = 0;
  28668. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28669. currentMidiInputBuffer = 0;
  28670. currentMidiOutputBuffer.clear();
  28671. clearRenderingSequence();
  28672. buildRenderingSequence();
  28673. }
  28674. void AudioProcessorGraph::releaseResources()
  28675. {
  28676. for (int i = 0; i < nodes.size(); ++i)
  28677. nodes.getUnchecked(i)->unprepare();
  28678. renderingBuffers.setSize (1, 1);
  28679. midiBuffers.clear();
  28680. currentAudioInputBuffer = 0;
  28681. currentAudioOutputBuffer.setSize (1, 1);
  28682. currentMidiInputBuffer = 0;
  28683. currentMidiOutputBuffer.clear();
  28684. }
  28685. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28686. {
  28687. const int numSamples = buffer.getNumSamples();
  28688. const ScopedLock sl (renderLock);
  28689. currentAudioInputBuffer = &buffer;
  28690. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28691. currentAudioOutputBuffer.clear();
  28692. currentMidiInputBuffer = &midiMessages;
  28693. currentMidiOutputBuffer.clear();
  28694. int i;
  28695. for (i = 0; i < renderingOps.size(); ++i)
  28696. {
  28697. GraphRenderingOps::AudioGraphRenderingOp* const op
  28698. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28699. op->perform (renderingBuffers, midiBuffers, numSamples);
  28700. }
  28701. for (i = 0; i < buffer.getNumChannels(); ++i)
  28702. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28703. midiMessages.clear();
  28704. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28705. }
  28706. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28707. {
  28708. return "Input " + String (channelIndex + 1);
  28709. }
  28710. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28711. {
  28712. return "Output " + String (channelIndex + 1);
  28713. }
  28714. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28715. {
  28716. return true;
  28717. }
  28718. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28719. {
  28720. return true;
  28721. }
  28722. bool AudioProcessorGraph::acceptsMidi() const
  28723. {
  28724. return true;
  28725. }
  28726. bool AudioProcessorGraph::producesMidi() const
  28727. {
  28728. return true;
  28729. }
  28730. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28731. {
  28732. }
  28733. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28734. {
  28735. }
  28736. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28737. : type (type_),
  28738. graph (0)
  28739. {
  28740. }
  28741. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28742. {
  28743. }
  28744. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28745. {
  28746. switch (type)
  28747. {
  28748. case audioOutputNode:
  28749. return "Audio Output";
  28750. case audioInputNode:
  28751. return "Audio Input";
  28752. case midiOutputNode:
  28753. return "Midi Output";
  28754. case midiInputNode:
  28755. return "Midi Input";
  28756. default:
  28757. break;
  28758. }
  28759. return String::empty;
  28760. }
  28761. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28762. {
  28763. d.name = getName();
  28764. d.uid = d.name.hashCode();
  28765. d.category = "I/O devices";
  28766. d.pluginFormatName = "Internal";
  28767. d.manufacturerName = "Raw Material Software";
  28768. d.version = "1.0";
  28769. d.isInstrument = false;
  28770. d.numInputChannels = getNumInputChannels();
  28771. if (type == audioOutputNode && graph != 0)
  28772. d.numInputChannels = graph->getNumInputChannels();
  28773. d.numOutputChannels = getNumOutputChannels();
  28774. if (type == audioInputNode && graph != 0)
  28775. d.numOutputChannels = graph->getNumOutputChannels();
  28776. }
  28777. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  28778. {
  28779. jassert (graph != 0);
  28780. }
  28781. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  28782. {
  28783. }
  28784. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  28785. MidiBuffer& midiMessages)
  28786. {
  28787. jassert (graph != 0);
  28788. switch (type)
  28789. {
  28790. case audioOutputNode:
  28791. {
  28792. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  28793. buffer.getNumChannels()); --i >= 0;)
  28794. {
  28795. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  28796. }
  28797. break;
  28798. }
  28799. case audioInputNode:
  28800. {
  28801. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  28802. buffer.getNumChannels()); --i >= 0;)
  28803. {
  28804. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  28805. }
  28806. break;
  28807. }
  28808. case midiOutputNode:
  28809. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  28810. break;
  28811. case midiInputNode:
  28812. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  28813. break;
  28814. default:
  28815. break;
  28816. }
  28817. }
  28818. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  28819. {
  28820. return type == midiOutputNode;
  28821. }
  28822. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  28823. {
  28824. return type == midiInputNode;
  28825. }
  28826. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  28827. {
  28828. switch (type)
  28829. {
  28830. case audioOutputNode:
  28831. return "Output " + String (channelIndex + 1);
  28832. case midiOutputNode:
  28833. return "Midi Output";
  28834. default:
  28835. break;
  28836. }
  28837. return String::empty;
  28838. }
  28839. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  28840. {
  28841. switch (type)
  28842. {
  28843. case audioInputNode:
  28844. return "Input " + String (channelIndex + 1);
  28845. case midiInputNode:
  28846. return "Midi Input";
  28847. default:
  28848. break;
  28849. }
  28850. return String::empty;
  28851. }
  28852. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  28853. {
  28854. return type == audioInputNode || type == audioOutputNode;
  28855. }
  28856. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  28857. {
  28858. return isInputChannelStereoPair (index);
  28859. }
  28860. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  28861. {
  28862. return type == audioInputNode || type == midiInputNode;
  28863. }
  28864. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  28865. {
  28866. return type == audioOutputNode || type == midiOutputNode;
  28867. }
  28868. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  28869. {
  28870. return 0;
  28871. }
  28872. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  28873. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  28874. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  28875. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  28876. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  28877. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  28878. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  28879. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  28880. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  28881. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  28882. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  28883. {
  28884. }
  28885. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  28886. {
  28887. }
  28888. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  28889. {
  28890. graph = newGraph;
  28891. if (graph != 0)
  28892. {
  28893. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  28894. type == audioInputNode ? graph->getNumInputChannels() : 0,
  28895. getSampleRate(),
  28896. getBlockSize());
  28897. updateHostDisplay();
  28898. }
  28899. }
  28900. END_JUCE_NAMESPACE
  28901. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  28902. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  28903. BEGIN_JUCE_NAMESPACE
  28904. AudioProcessorPlayer::AudioProcessorPlayer()
  28905. : processor (0),
  28906. sampleRate (0),
  28907. blockSize (0),
  28908. isPrepared (false),
  28909. numInputChans (0),
  28910. numOutputChans (0),
  28911. tempBuffer (1, 1)
  28912. {
  28913. }
  28914. AudioProcessorPlayer::~AudioProcessorPlayer()
  28915. {
  28916. setProcessor (0);
  28917. }
  28918. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  28919. {
  28920. if (processor != processorToPlay)
  28921. {
  28922. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  28923. {
  28924. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  28925. sampleRate, blockSize);
  28926. processorToPlay->prepareToPlay (sampleRate, blockSize);
  28927. }
  28928. AudioProcessor* oldOne;
  28929. {
  28930. const ScopedLock sl (lock);
  28931. oldOne = isPrepared ? processor : 0;
  28932. processor = processorToPlay;
  28933. isPrepared = true;
  28934. }
  28935. if (oldOne != 0)
  28936. oldOne->releaseResources();
  28937. }
  28938. }
  28939. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  28940. int numInputChannels,
  28941. float** outputChannelData,
  28942. int numOutputChannels,
  28943. int numSamples)
  28944. {
  28945. // these should have been prepared by audioDeviceAboutToStart()...
  28946. jassert (sampleRate > 0 && blockSize > 0);
  28947. incomingMidi.clear();
  28948. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  28949. int i, totalNumChans = 0;
  28950. if (numInputChannels > numOutputChannels)
  28951. {
  28952. // if there aren't enough output channels for the number of
  28953. // inputs, we need to create some temporary extra ones (can't
  28954. // use the input data in case it gets written to)
  28955. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  28956. false, false, true);
  28957. for (i = 0; i < numOutputChannels; ++i)
  28958. {
  28959. channels[totalNumChans] = outputChannelData[i];
  28960. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28961. ++totalNumChans;
  28962. }
  28963. for (i = numOutputChannels; i < numInputChannels; ++i)
  28964. {
  28965. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  28966. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28967. ++totalNumChans;
  28968. }
  28969. }
  28970. else
  28971. {
  28972. for (i = 0; i < numInputChannels; ++i)
  28973. {
  28974. channels[totalNumChans] = outputChannelData[i];
  28975. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28976. ++totalNumChans;
  28977. }
  28978. for (i = numInputChannels; i < numOutputChannels; ++i)
  28979. {
  28980. channels[totalNumChans] = outputChannelData[i];
  28981. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  28982. ++totalNumChans;
  28983. }
  28984. }
  28985. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  28986. const ScopedLock sl (lock);
  28987. if (processor != 0)
  28988. processor->processBlock (buffer, incomingMidi);
  28989. }
  28990. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  28991. {
  28992. const ScopedLock sl (lock);
  28993. sampleRate = device->getCurrentSampleRate();
  28994. blockSize = device->getCurrentBufferSizeSamples();
  28995. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  28996. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  28997. messageCollector.reset (sampleRate);
  28998. zeromem (channels, sizeof (channels));
  28999. if (processor != 0)
  29000. {
  29001. if (isPrepared)
  29002. processor->releaseResources();
  29003. AudioProcessor* const oldProcessor = processor;
  29004. setProcessor (0);
  29005. setProcessor (oldProcessor);
  29006. }
  29007. }
  29008. void AudioProcessorPlayer::audioDeviceStopped()
  29009. {
  29010. const ScopedLock sl (lock);
  29011. if (processor != 0 && isPrepared)
  29012. processor->releaseResources();
  29013. sampleRate = 0.0;
  29014. blockSize = 0;
  29015. isPrepared = false;
  29016. tempBuffer.setSize (1, 1);
  29017. }
  29018. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29019. {
  29020. messageCollector.addMessageToQueue (message);
  29021. }
  29022. END_JUCE_NAMESPACE
  29023. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29024. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29025. BEGIN_JUCE_NAMESPACE
  29026. class ProcessorParameterPropertyComp : public PropertyComponent,
  29027. public AudioProcessorListener,
  29028. public AsyncUpdater
  29029. {
  29030. public:
  29031. ProcessorParameterPropertyComp (const String& name,
  29032. AudioProcessor* const owner_,
  29033. const int index_)
  29034. : PropertyComponent (name),
  29035. owner (owner_),
  29036. index (index_)
  29037. {
  29038. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29039. owner_->addListener (this);
  29040. }
  29041. ~ProcessorParameterPropertyComp()
  29042. {
  29043. owner->removeListener (this);
  29044. deleteAllChildren();
  29045. }
  29046. void refresh()
  29047. {
  29048. slider->setValue (owner->getParameter (index), false);
  29049. }
  29050. void audioProcessorChanged (AudioProcessor*) {}
  29051. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29052. {
  29053. if (parameterIndex == index)
  29054. triggerAsyncUpdate();
  29055. }
  29056. void handleAsyncUpdate()
  29057. {
  29058. refresh();
  29059. }
  29060. juce_UseDebuggingNewOperator
  29061. private:
  29062. AudioProcessor* const owner;
  29063. const int index;
  29064. Slider* slider;
  29065. class ParamSlider : public Slider
  29066. {
  29067. public:
  29068. ParamSlider (AudioProcessor* const owner_, const int index_)
  29069. : Slider (String::empty),
  29070. owner (owner_),
  29071. index (index_)
  29072. {
  29073. setRange (0.0, 1.0, 0.0);
  29074. setSliderStyle (Slider::LinearBar);
  29075. setTextBoxIsEditable (false);
  29076. setScrollWheelEnabled (false);
  29077. }
  29078. ~ParamSlider()
  29079. {
  29080. }
  29081. void valueChanged()
  29082. {
  29083. const float newVal = (float) getValue();
  29084. if (owner->getParameter (index) != newVal)
  29085. owner->setParameter (index, newVal);
  29086. }
  29087. const String getTextFromValue (double /*value*/)
  29088. {
  29089. return owner->getParameterText (index);
  29090. }
  29091. juce_UseDebuggingNewOperator
  29092. private:
  29093. AudioProcessor* const owner;
  29094. const int index;
  29095. ParamSlider (const ParamSlider&);
  29096. ParamSlider& operator= (const ParamSlider&);
  29097. };
  29098. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29099. ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29100. };
  29101. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29102. : AudioProcessorEditor (owner_)
  29103. {
  29104. setOpaque (true);
  29105. addAndMakeVisible (panel = new PropertyPanel());
  29106. Array <PropertyComponent*> params;
  29107. const int numParams = owner_->getNumParameters();
  29108. int totalHeight = 0;
  29109. for (int i = 0; i < numParams; ++i)
  29110. {
  29111. String name (owner_->getParameterName (i));
  29112. if (name.trim().isEmpty())
  29113. name = "Unnamed";
  29114. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29115. params.add (pc);
  29116. totalHeight += pc->getPreferredHeight();
  29117. }
  29118. panel->addProperties (params);
  29119. setSize (400, jlimit (25, 400, totalHeight));
  29120. }
  29121. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29122. {
  29123. deleteAllChildren();
  29124. }
  29125. void GenericAudioProcessorEditor::paint (Graphics& g)
  29126. {
  29127. g.fillAll (Colours::white);
  29128. }
  29129. void GenericAudioProcessorEditor::resized()
  29130. {
  29131. panel->setSize (getWidth(), getHeight());
  29132. }
  29133. END_JUCE_NAMESPACE
  29134. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29135. /*** Start of inlined file: juce_Sampler.cpp ***/
  29136. BEGIN_JUCE_NAMESPACE
  29137. SamplerSound::SamplerSound (const String& name_,
  29138. AudioFormatReader& source,
  29139. const BigInteger& midiNotes_,
  29140. const int midiNoteForNormalPitch,
  29141. const double attackTimeSecs,
  29142. const double releaseTimeSecs,
  29143. const double maxSampleLengthSeconds)
  29144. : name (name_),
  29145. midiNotes (midiNotes_),
  29146. midiRootNote (midiNoteForNormalPitch)
  29147. {
  29148. sourceSampleRate = source.sampleRate;
  29149. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29150. {
  29151. length = 0;
  29152. attackSamples = 0;
  29153. releaseSamples = 0;
  29154. }
  29155. else
  29156. {
  29157. length = jmin ((int) source.lengthInSamples,
  29158. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29159. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29160. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29161. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29162. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29163. }
  29164. }
  29165. SamplerSound::~SamplerSound()
  29166. {
  29167. }
  29168. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29169. {
  29170. return midiNotes [midiNoteNumber];
  29171. }
  29172. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29173. {
  29174. return true;
  29175. }
  29176. SamplerVoice::SamplerVoice()
  29177. : pitchRatio (0.0),
  29178. sourceSamplePosition (0.0),
  29179. lgain (0.0f),
  29180. rgain (0.0f),
  29181. isInAttack (false),
  29182. isInRelease (false)
  29183. {
  29184. }
  29185. SamplerVoice::~SamplerVoice()
  29186. {
  29187. }
  29188. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29189. {
  29190. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29191. }
  29192. void SamplerVoice::startNote (const int midiNoteNumber,
  29193. const float velocity,
  29194. SynthesiserSound* s,
  29195. const int /*currentPitchWheelPosition*/)
  29196. {
  29197. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29198. jassert (sound != 0); // this object can only play SamplerSounds!
  29199. if (sound != 0)
  29200. {
  29201. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29202. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29203. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29204. sourceSamplePosition = 0.0;
  29205. lgain = velocity;
  29206. rgain = velocity;
  29207. isInAttack = (sound->attackSamples > 0);
  29208. isInRelease = false;
  29209. if (isInAttack)
  29210. {
  29211. attackReleaseLevel = 0.0f;
  29212. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29213. }
  29214. else
  29215. {
  29216. attackReleaseLevel = 1.0f;
  29217. attackDelta = 0.0f;
  29218. }
  29219. if (sound->releaseSamples > 0)
  29220. {
  29221. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29222. }
  29223. else
  29224. {
  29225. releaseDelta = 0.0f;
  29226. }
  29227. }
  29228. }
  29229. void SamplerVoice::stopNote (const bool allowTailOff)
  29230. {
  29231. if (allowTailOff)
  29232. {
  29233. isInAttack = false;
  29234. isInRelease = true;
  29235. }
  29236. else
  29237. {
  29238. clearCurrentNote();
  29239. }
  29240. }
  29241. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29242. {
  29243. }
  29244. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29245. const int /*newValue*/)
  29246. {
  29247. }
  29248. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29249. {
  29250. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29251. if (playingSound != 0)
  29252. {
  29253. const float* const inL = playingSound->data->getSampleData (0, 0);
  29254. const float* const inR = playingSound->data->getNumChannels() > 1
  29255. ? playingSound->data->getSampleData (1, 0) : 0;
  29256. float* outL = outputBuffer.getSampleData (0, startSample);
  29257. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29258. while (--numSamples >= 0)
  29259. {
  29260. const int pos = (int) sourceSamplePosition;
  29261. const float alpha = (float) (sourceSamplePosition - pos);
  29262. const float invAlpha = 1.0f - alpha;
  29263. // just using a very simple linear interpolation here..
  29264. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29265. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29266. : l;
  29267. l *= lgain;
  29268. r *= rgain;
  29269. if (isInAttack)
  29270. {
  29271. l *= attackReleaseLevel;
  29272. r *= attackReleaseLevel;
  29273. attackReleaseLevel += attackDelta;
  29274. if (attackReleaseLevel >= 1.0f)
  29275. {
  29276. attackReleaseLevel = 1.0f;
  29277. isInAttack = false;
  29278. }
  29279. }
  29280. else if (isInRelease)
  29281. {
  29282. l *= attackReleaseLevel;
  29283. r *= attackReleaseLevel;
  29284. attackReleaseLevel += releaseDelta;
  29285. if (attackReleaseLevel <= 0.0f)
  29286. {
  29287. stopNote (false);
  29288. break;
  29289. }
  29290. }
  29291. if (outR != 0)
  29292. {
  29293. *outL++ += l;
  29294. *outR++ += r;
  29295. }
  29296. else
  29297. {
  29298. *outL++ += (l + r) * 0.5f;
  29299. }
  29300. sourceSamplePosition += pitchRatio;
  29301. if (sourceSamplePosition > playingSound->length)
  29302. {
  29303. stopNote (false);
  29304. break;
  29305. }
  29306. }
  29307. }
  29308. }
  29309. END_JUCE_NAMESPACE
  29310. /*** End of inlined file: juce_Sampler.cpp ***/
  29311. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29312. BEGIN_JUCE_NAMESPACE
  29313. SynthesiserSound::SynthesiserSound()
  29314. {
  29315. }
  29316. SynthesiserSound::~SynthesiserSound()
  29317. {
  29318. }
  29319. SynthesiserVoice::SynthesiserVoice()
  29320. : currentSampleRate (44100.0),
  29321. currentlyPlayingNote (-1),
  29322. noteOnTime (0),
  29323. currentlyPlayingSound (0)
  29324. {
  29325. }
  29326. SynthesiserVoice::~SynthesiserVoice()
  29327. {
  29328. }
  29329. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29330. {
  29331. return currentlyPlayingSound != 0
  29332. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29333. }
  29334. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29335. {
  29336. currentSampleRate = newRate;
  29337. }
  29338. void SynthesiserVoice::clearCurrentNote()
  29339. {
  29340. currentlyPlayingNote = -1;
  29341. currentlyPlayingSound = 0;
  29342. }
  29343. Synthesiser::Synthesiser()
  29344. : sampleRate (0),
  29345. lastNoteOnCounter (0),
  29346. shouldStealNotes (true)
  29347. {
  29348. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29349. lastPitchWheelValues[i] = 0x2000;
  29350. }
  29351. Synthesiser::~Synthesiser()
  29352. {
  29353. }
  29354. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29355. {
  29356. const ScopedLock sl (lock);
  29357. return voices [index];
  29358. }
  29359. void Synthesiser::clearVoices()
  29360. {
  29361. const ScopedLock sl (lock);
  29362. voices.clear();
  29363. }
  29364. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29365. {
  29366. const ScopedLock sl (lock);
  29367. voices.add (newVoice);
  29368. }
  29369. void Synthesiser::removeVoice (const int index)
  29370. {
  29371. const ScopedLock sl (lock);
  29372. voices.remove (index);
  29373. }
  29374. void Synthesiser::clearSounds()
  29375. {
  29376. const ScopedLock sl (lock);
  29377. sounds.clear();
  29378. }
  29379. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29380. {
  29381. const ScopedLock sl (lock);
  29382. sounds.add (newSound);
  29383. }
  29384. void Synthesiser::removeSound (const int index)
  29385. {
  29386. const ScopedLock sl (lock);
  29387. sounds.remove (index);
  29388. }
  29389. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29390. {
  29391. shouldStealNotes = shouldStealNotes_;
  29392. }
  29393. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29394. {
  29395. if (sampleRate != newRate)
  29396. {
  29397. const ScopedLock sl (lock);
  29398. allNotesOff (0, false);
  29399. sampleRate = newRate;
  29400. for (int i = voices.size(); --i >= 0;)
  29401. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29402. }
  29403. }
  29404. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29405. const MidiBuffer& midiData,
  29406. int startSample,
  29407. int numSamples)
  29408. {
  29409. // must set the sample rate before using this!
  29410. jassert (sampleRate != 0);
  29411. const ScopedLock sl (lock);
  29412. MidiBuffer::Iterator midiIterator (midiData);
  29413. midiIterator.setNextSamplePosition (startSample);
  29414. MidiMessage m (0xf4, 0.0);
  29415. while (numSamples > 0)
  29416. {
  29417. int midiEventPos;
  29418. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29419. && midiEventPos < startSample + numSamples;
  29420. const int numThisTime = useEvent ? midiEventPos - startSample
  29421. : numSamples;
  29422. if (numThisTime > 0)
  29423. {
  29424. for (int i = voices.size(); --i >= 0;)
  29425. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29426. }
  29427. if (useEvent)
  29428. {
  29429. if (m.isNoteOn())
  29430. {
  29431. const int channel = m.getChannel();
  29432. noteOn (channel,
  29433. m.getNoteNumber(),
  29434. m.getFloatVelocity());
  29435. }
  29436. else if (m.isNoteOff())
  29437. {
  29438. noteOff (m.getChannel(),
  29439. m.getNoteNumber(),
  29440. true);
  29441. }
  29442. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29443. {
  29444. allNotesOff (m.getChannel(), true);
  29445. }
  29446. else if (m.isPitchWheel())
  29447. {
  29448. const int channel = m.getChannel();
  29449. const int wheelPos = m.getPitchWheelValue();
  29450. lastPitchWheelValues [channel - 1] = wheelPos;
  29451. handlePitchWheel (channel, wheelPos);
  29452. }
  29453. else if (m.isController())
  29454. {
  29455. handleController (m.getChannel(),
  29456. m.getControllerNumber(),
  29457. m.getControllerValue());
  29458. }
  29459. }
  29460. startSample += numThisTime;
  29461. numSamples -= numThisTime;
  29462. }
  29463. }
  29464. void Synthesiser::noteOn (const int midiChannel,
  29465. const int midiNoteNumber,
  29466. const float velocity)
  29467. {
  29468. const ScopedLock sl (lock);
  29469. for (int i = sounds.size(); --i >= 0;)
  29470. {
  29471. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29472. if (sound->appliesToNote (midiNoteNumber)
  29473. && sound->appliesToChannel (midiChannel))
  29474. {
  29475. startVoice (findFreeVoice (sound, shouldStealNotes),
  29476. sound, midiChannel, midiNoteNumber, velocity);
  29477. }
  29478. }
  29479. }
  29480. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29481. SynthesiserSound* const sound,
  29482. const int midiChannel,
  29483. const int midiNoteNumber,
  29484. const float velocity)
  29485. {
  29486. if (voice != 0 && sound != 0)
  29487. {
  29488. if (voice->currentlyPlayingSound != 0)
  29489. voice->stopNote (false);
  29490. voice->startNote (midiNoteNumber,
  29491. velocity,
  29492. sound,
  29493. lastPitchWheelValues [midiChannel - 1]);
  29494. voice->currentlyPlayingNote = midiNoteNumber;
  29495. voice->noteOnTime = ++lastNoteOnCounter;
  29496. voice->currentlyPlayingSound = sound;
  29497. }
  29498. }
  29499. void Synthesiser::noteOff (const int midiChannel,
  29500. const int midiNoteNumber,
  29501. const bool allowTailOff)
  29502. {
  29503. const ScopedLock sl (lock);
  29504. for (int i = voices.size(); --i >= 0;)
  29505. {
  29506. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29507. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29508. {
  29509. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29510. if (sound != 0
  29511. && sound->appliesToNote (midiNoteNumber)
  29512. && sound->appliesToChannel (midiChannel))
  29513. {
  29514. voice->stopNote (allowTailOff);
  29515. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29516. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29517. }
  29518. }
  29519. }
  29520. }
  29521. void Synthesiser::allNotesOff (const int midiChannel,
  29522. const bool allowTailOff)
  29523. {
  29524. const ScopedLock sl (lock);
  29525. for (int i = voices.size(); --i >= 0;)
  29526. {
  29527. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29528. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29529. voice->stopNote (allowTailOff);
  29530. }
  29531. }
  29532. void Synthesiser::handlePitchWheel (const int midiChannel,
  29533. const int wheelValue)
  29534. {
  29535. const ScopedLock sl (lock);
  29536. for (int i = voices.size(); --i >= 0;)
  29537. {
  29538. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29539. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29540. {
  29541. voice->pitchWheelMoved (wheelValue);
  29542. }
  29543. }
  29544. }
  29545. void Synthesiser::handleController (const int midiChannel,
  29546. const int controllerNumber,
  29547. const int controllerValue)
  29548. {
  29549. const ScopedLock sl (lock);
  29550. for (int i = voices.size(); --i >= 0;)
  29551. {
  29552. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29553. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29554. voice->controllerMoved (controllerNumber, controllerValue);
  29555. }
  29556. }
  29557. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29558. const bool stealIfNoneAvailable) const
  29559. {
  29560. const ScopedLock sl (lock);
  29561. for (int i = voices.size(); --i >= 0;)
  29562. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29563. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29564. return voices.getUnchecked (i);
  29565. if (stealIfNoneAvailable)
  29566. {
  29567. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29568. SynthesiserVoice* oldest = 0;
  29569. for (int i = voices.size(); --i >= 0;)
  29570. {
  29571. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29572. if (voice->canPlaySound (soundToPlay)
  29573. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29574. oldest = voice;
  29575. }
  29576. jassert (oldest != 0);
  29577. return oldest;
  29578. }
  29579. return 0;
  29580. }
  29581. END_JUCE_NAMESPACE
  29582. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29583. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29584. BEGIN_JUCE_NAMESPACE
  29585. ActionBroadcaster::ActionBroadcaster() throw()
  29586. {
  29587. // are you trying to create this object before or after juce has been intialised??
  29588. jassert (MessageManager::instance != 0);
  29589. }
  29590. ActionBroadcaster::~ActionBroadcaster()
  29591. {
  29592. // all event-based objects must be deleted BEFORE juce is shut down!
  29593. jassert (MessageManager::instance != 0);
  29594. }
  29595. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29596. {
  29597. actionListenerList.addActionListener (listener);
  29598. }
  29599. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29600. {
  29601. jassert (actionListenerList.isValidMessageListener());
  29602. if (actionListenerList.isValidMessageListener())
  29603. actionListenerList.removeActionListener (listener);
  29604. }
  29605. void ActionBroadcaster::removeAllActionListeners()
  29606. {
  29607. actionListenerList.removeAllActionListeners();
  29608. }
  29609. void ActionBroadcaster::sendActionMessage (const String& message) const
  29610. {
  29611. actionListenerList.sendActionMessage (message);
  29612. }
  29613. END_JUCE_NAMESPACE
  29614. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29615. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29616. BEGIN_JUCE_NAMESPACE
  29617. // special message of our own with a string in it
  29618. class ActionMessage : public Message
  29619. {
  29620. public:
  29621. const String message;
  29622. ActionMessage (const String& messageText,
  29623. void* const listener_) throw()
  29624. : message (messageText)
  29625. {
  29626. pointerParameter = listener_;
  29627. }
  29628. ~ActionMessage() throw()
  29629. {
  29630. }
  29631. private:
  29632. ActionMessage (const ActionMessage&);
  29633. ActionMessage& operator= (const ActionMessage&);
  29634. };
  29635. ActionListenerList::ActionListenerList() throw()
  29636. {
  29637. }
  29638. ActionListenerList::~ActionListenerList() throw()
  29639. {
  29640. }
  29641. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29642. {
  29643. const ScopedLock sl (actionListenerLock_);
  29644. jassert (listener != 0);
  29645. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29646. if (listener != 0)
  29647. actionListeners_.add (listener);
  29648. }
  29649. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29650. {
  29651. const ScopedLock sl (actionListenerLock_);
  29652. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29653. actionListeners_.removeValue (listener);
  29654. }
  29655. void ActionListenerList::removeAllActionListeners() throw()
  29656. {
  29657. const ScopedLock sl (actionListenerLock_);
  29658. actionListeners_.clear();
  29659. }
  29660. void ActionListenerList::sendActionMessage (const String& message) const
  29661. {
  29662. const ScopedLock sl (actionListenerLock_);
  29663. for (int i = actionListeners_.size(); --i >= 0;)
  29664. {
  29665. postMessage (new ActionMessage (message,
  29666. (ActionListener*) actionListeners_.getUnchecked(i)));
  29667. }
  29668. }
  29669. void ActionListenerList::handleMessage (const Message& message)
  29670. {
  29671. const ActionMessage& am = (const ActionMessage&) message;
  29672. if (actionListeners_.contains (am.pointerParameter))
  29673. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29674. }
  29675. END_JUCE_NAMESPACE
  29676. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29677. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29678. BEGIN_JUCE_NAMESPACE
  29679. AsyncUpdater::AsyncUpdater() throw()
  29680. : asyncMessagePending (false)
  29681. {
  29682. internalAsyncHandler.owner = this;
  29683. }
  29684. AsyncUpdater::~AsyncUpdater()
  29685. {
  29686. }
  29687. void AsyncUpdater::triggerAsyncUpdate() throw()
  29688. {
  29689. if (! asyncMessagePending)
  29690. {
  29691. asyncMessagePending = true;
  29692. internalAsyncHandler.postMessage (new Message());
  29693. }
  29694. }
  29695. void AsyncUpdater::cancelPendingUpdate() throw()
  29696. {
  29697. asyncMessagePending = false;
  29698. }
  29699. void AsyncUpdater::handleUpdateNowIfNeeded()
  29700. {
  29701. if (asyncMessagePending)
  29702. {
  29703. asyncMessagePending = false;
  29704. handleAsyncUpdate();
  29705. }
  29706. }
  29707. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29708. {
  29709. owner->handleUpdateNowIfNeeded();
  29710. }
  29711. END_JUCE_NAMESPACE
  29712. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29713. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29714. BEGIN_JUCE_NAMESPACE
  29715. ChangeBroadcaster::ChangeBroadcaster() throw()
  29716. {
  29717. // are you trying to create this object before or after juce has been intialised??
  29718. jassert (MessageManager::instance != 0);
  29719. }
  29720. ChangeBroadcaster::~ChangeBroadcaster()
  29721. {
  29722. // all event-based objects must be deleted BEFORE juce is shut down!
  29723. jassert (MessageManager::instance != 0);
  29724. }
  29725. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29726. {
  29727. changeListenerList.addChangeListener (listener);
  29728. }
  29729. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29730. {
  29731. jassert (changeListenerList.isValidMessageListener());
  29732. if (changeListenerList.isValidMessageListener())
  29733. changeListenerList.removeChangeListener (listener);
  29734. }
  29735. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29736. {
  29737. changeListenerList.removeAllChangeListeners();
  29738. }
  29739. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29740. {
  29741. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29742. }
  29743. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29744. {
  29745. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29746. }
  29747. void ChangeBroadcaster::dispatchPendingMessages()
  29748. {
  29749. changeListenerList.dispatchPendingMessages();
  29750. }
  29751. END_JUCE_NAMESPACE
  29752. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  29753. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  29754. BEGIN_JUCE_NAMESPACE
  29755. ChangeListenerList::ChangeListenerList() throw()
  29756. : lastChangedObject (0),
  29757. messagePending (false)
  29758. {
  29759. }
  29760. ChangeListenerList::~ChangeListenerList() throw()
  29761. {
  29762. }
  29763. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29764. {
  29765. const ScopedLock sl (lock);
  29766. jassert (listener != 0);
  29767. if (listener != 0)
  29768. listeners.add (listener);
  29769. }
  29770. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  29771. {
  29772. const ScopedLock sl (lock);
  29773. listeners.removeValue (listener);
  29774. }
  29775. void ChangeListenerList::removeAllChangeListeners() throw()
  29776. {
  29777. const ScopedLock sl (lock);
  29778. listeners.clear();
  29779. }
  29780. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  29781. {
  29782. const ScopedLock sl (lock);
  29783. if ((! messagePending) && (listeners.size() > 0))
  29784. {
  29785. lastChangedObject = objectThatHasChanged;
  29786. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  29787. messagePending = true;
  29788. }
  29789. }
  29790. void ChangeListenerList::handleMessage (const Message& message)
  29791. {
  29792. sendSynchronousChangeMessage (message.pointerParameter);
  29793. }
  29794. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  29795. {
  29796. const ScopedLock sl (lock);
  29797. messagePending = false;
  29798. for (int i = listeners.size(); --i >= 0;)
  29799. {
  29800. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  29801. {
  29802. const ScopedUnlock tempUnlocker (lock);
  29803. l->changeListenerCallback (objectThatHasChanged);
  29804. }
  29805. i = jmin (i, listeners.size());
  29806. }
  29807. }
  29808. void ChangeListenerList::dispatchPendingMessages()
  29809. {
  29810. if (messagePending)
  29811. sendSynchronousChangeMessage (lastChangedObject);
  29812. }
  29813. END_JUCE_NAMESPACE
  29814. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  29815. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  29816. BEGIN_JUCE_NAMESPACE
  29817. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  29818. const uint32 magicMessageHeaderNumber)
  29819. : Thread ("Juce IPC connection"),
  29820. callbackConnectionState (false),
  29821. useMessageThread (callbacksOnMessageThread),
  29822. magicMessageHeader (magicMessageHeaderNumber),
  29823. pipeReceiveMessageTimeout (-1)
  29824. {
  29825. }
  29826. InterprocessConnection::~InterprocessConnection()
  29827. {
  29828. callbackConnectionState = false;
  29829. disconnect();
  29830. }
  29831. bool InterprocessConnection::connectToSocket (const String& hostName,
  29832. const int portNumber,
  29833. const int timeOutMillisecs)
  29834. {
  29835. disconnect();
  29836. const ScopedLock sl (pipeAndSocketLock);
  29837. socket = new StreamingSocket();
  29838. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  29839. {
  29840. connectionMadeInt();
  29841. startThread();
  29842. return true;
  29843. }
  29844. else
  29845. {
  29846. socket = 0;
  29847. return false;
  29848. }
  29849. }
  29850. bool InterprocessConnection::connectToPipe (const String& pipeName,
  29851. const int pipeReceiveMessageTimeoutMs)
  29852. {
  29853. disconnect();
  29854. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29855. if (newPipe->openExisting (pipeName))
  29856. {
  29857. const ScopedLock sl (pipeAndSocketLock);
  29858. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29859. initialiseWithPipe (newPipe.release());
  29860. return true;
  29861. }
  29862. return false;
  29863. }
  29864. bool InterprocessConnection::createPipe (const String& pipeName,
  29865. const int pipeReceiveMessageTimeoutMs)
  29866. {
  29867. disconnect();
  29868. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29869. if (newPipe->createNewPipe (pipeName))
  29870. {
  29871. const ScopedLock sl (pipeAndSocketLock);
  29872. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29873. initialiseWithPipe (newPipe.release());
  29874. return true;
  29875. }
  29876. return false;
  29877. }
  29878. void InterprocessConnection::disconnect()
  29879. {
  29880. if (socket != 0)
  29881. socket->close();
  29882. if (pipe != 0)
  29883. {
  29884. pipe->cancelPendingReads();
  29885. pipe->close();
  29886. }
  29887. stopThread (4000);
  29888. {
  29889. const ScopedLock sl (pipeAndSocketLock);
  29890. socket = 0;
  29891. pipe = 0;
  29892. }
  29893. connectionLostInt();
  29894. }
  29895. bool InterprocessConnection::isConnected() const
  29896. {
  29897. const ScopedLock sl (pipeAndSocketLock);
  29898. return ((socket != 0 && socket->isConnected())
  29899. || (pipe != 0 && pipe->isOpen()))
  29900. && isThreadRunning();
  29901. }
  29902. const String InterprocessConnection::getConnectedHostName() const
  29903. {
  29904. if (pipe != 0)
  29905. {
  29906. return "localhost";
  29907. }
  29908. else if (socket != 0)
  29909. {
  29910. if (! socket->isLocal())
  29911. return socket->getHostName();
  29912. return "localhost";
  29913. }
  29914. return String::empty;
  29915. }
  29916. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  29917. {
  29918. uint32 messageHeader[2];
  29919. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  29920. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  29921. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  29922. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  29923. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  29924. size_t bytesWritten = 0;
  29925. const ScopedLock sl (pipeAndSocketLock);
  29926. if (socket != 0)
  29927. {
  29928. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  29929. }
  29930. else if (pipe != 0)
  29931. {
  29932. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  29933. }
  29934. if (bytesWritten < 0)
  29935. {
  29936. // error..
  29937. return false;
  29938. }
  29939. return (bytesWritten == messageData.getSize());
  29940. }
  29941. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  29942. {
  29943. jassert (socket == 0);
  29944. socket = socket_;
  29945. connectionMadeInt();
  29946. startThread();
  29947. }
  29948. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  29949. {
  29950. jassert (pipe == 0);
  29951. pipe = pipe_;
  29952. connectionMadeInt();
  29953. startThread();
  29954. }
  29955. const int messageMagicNumber = 0xb734128b;
  29956. void InterprocessConnection::handleMessage (const Message& message)
  29957. {
  29958. if (message.intParameter1 == messageMagicNumber)
  29959. {
  29960. switch (message.intParameter2)
  29961. {
  29962. case 0:
  29963. {
  29964. ScopedPointer <MemoryBlock> data ((MemoryBlock*) message.pointerParameter);
  29965. messageReceived (*data);
  29966. break;
  29967. }
  29968. case 1:
  29969. connectionMade();
  29970. break;
  29971. case 2:
  29972. connectionLost();
  29973. break;
  29974. }
  29975. }
  29976. }
  29977. void InterprocessConnection::connectionMadeInt()
  29978. {
  29979. if (! callbackConnectionState)
  29980. {
  29981. callbackConnectionState = true;
  29982. if (useMessageThread)
  29983. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  29984. else
  29985. connectionMade();
  29986. }
  29987. }
  29988. void InterprocessConnection::connectionLostInt()
  29989. {
  29990. if (callbackConnectionState)
  29991. {
  29992. callbackConnectionState = false;
  29993. if (useMessageThread)
  29994. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  29995. else
  29996. connectionLost();
  29997. }
  29998. }
  29999. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30000. {
  30001. jassert (callbackConnectionState);
  30002. if (useMessageThread)
  30003. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30004. else
  30005. messageReceived (data);
  30006. }
  30007. bool InterprocessConnection::readNextMessageInt()
  30008. {
  30009. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30010. uint32 messageHeader[2];
  30011. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30012. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30013. if (bytes == sizeof (messageHeader)
  30014. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30015. {
  30016. int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30017. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30018. {
  30019. MemoryBlock messageData (bytesInMessage, true);
  30020. int bytesRead = 0;
  30021. while (bytesInMessage > 0)
  30022. {
  30023. if (threadShouldExit())
  30024. return false;
  30025. const int numThisTime = jmin (bytesInMessage, 65536);
  30026. const int bytesIn = (socket != 0) ? socket->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, true)
  30027. : pipe->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, pipeReceiveMessageTimeout);
  30028. if (bytesIn <= 0)
  30029. break;
  30030. bytesRead += bytesIn;
  30031. bytesInMessage -= bytesIn;
  30032. }
  30033. if (bytesRead >= 0)
  30034. deliverDataInt (messageData);
  30035. }
  30036. }
  30037. else if (bytes < 0)
  30038. {
  30039. {
  30040. const ScopedLock sl (pipeAndSocketLock);
  30041. socket = 0;
  30042. }
  30043. connectionLostInt();
  30044. return false;
  30045. }
  30046. return true;
  30047. }
  30048. void InterprocessConnection::run()
  30049. {
  30050. while (! threadShouldExit())
  30051. {
  30052. if (socket != 0)
  30053. {
  30054. const int ready = socket->waitUntilReady (true, 0);
  30055. if (ready < 0)
  30056. {
  30057. {
  30058. const ScopedLock sl (pipeAndSocketLock);
  30059. socket = 0;
  30060. }
  30061. connectionLostInt();
  30062. break;
  30063. }
  30064. else if (ready > 0)
  30065. {
  30066. if (! readNextMessageInt())
  30067. break;
  30068. }
  30069. else
  30070. {
  30071. Thread::sleep (2);
  30072. }
  30073. }
  30074. else if (pipe != 0)
  30075. {
  30076. if (! pipe->isOpen())
  30077. {
  30078. {
  30079. const ScopedLock sl (pipeAndSocketLock);
  30080. pipe = 0;
  30081. }
  30082. connectionLostInt();
  30083. break;
  30084. }
  30085. else
  30086. {
  30087. if (! readNextMessageInt())
  30088. break;
  30089. }
  30090. }
  30091. else
  30092. {
  30093. break;
  30094. }
  30095. }
  30096. }
  30097. END_JUCE_NAMESPACE
  30098. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30099. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30100. BEGIN_JUCE_NAMESPACE
  30101. InterprocessConnectionServer::InterprocessConnectionServer()
  30102. : Thread ("Juce IPC server")
  30103. {
  30104. }
  30105. InterprocessConnectionServer::~InterprocessConnectionServer()
  30106. {
  30107. stop();
  30108. }
  30109. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30110. {
  30111. stop();
  30112. socket = new StreamingSocket();
  30113. if (socket->createListener (portNumber))
  30114. {
  30115. startThread();
  30116. return true;
  30117. }
  30118. socket = 0;
  30119. return false;
  30120. }
  30121. void InterprocessConnectionServer::stop()
  30122. {
  30123. signalThreadShouldExit();
  30124. if (socket != 0)
  30125. socket->close();
  30126. stopThread (4000);
  30127. socket = 0;
  30128. }
  30129. void InterprocessConnectionServer::run()
  30130. {
  30131. while ((! threadShouldExit()) && socket != 0)
  30132. {
  30133. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30134. if (clientSocket != 0)
  30135. {
  30136. InterprocessConnection* newConnection = createConnectionObject();
  30137. if (newConnection != 0)
  30138. newConnection->initialiseWithSocket (clientSocket.release());
  30139. }
  30140. }
  30141. }
  30142. END_JUCE_NAMESPACE
  30143. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30144. /*** Start of inlined file: juce_Message.cpp ***/
  30145. BEGIN_JUCE_NAMESPACE
  30146. Message::Message() throw()
  30147. {
  30148. }
  30149. Message::~Message() throw()
  30150. {
  30151. }
  30152. Message::Message (const int intParameter1_,
  30153. const int intParameter2_,
  30154. const int intParameter3_,
  30155. void* const pointerParameter_) throw()
  30156. : intParameter1 (intParameter1_),
  30157. intParameter2 (intParameter2_),
  30158. intParameter3 (intParameter3_),
  30159. pointerParameter (pointerParameter_)
  30160. {
  30161. }
  30162. END_JUCE_NAMESPACE
  30163. /*** End of inlined file: juce_Message.cpp ***/
  30164. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30165. BEGIN_JUCE_NAMESPACE
  30166. MessageListener::MessageListener() throw()
  30167. {
  30168. // are you trying to create a messagelistener before or after juce has been intialised??
  30169. jassert (MessageManager::instance != 0);
  30170. if (MessageManager::instance != 0)
  30171. MessageManager::instance->messageListeners.add (this);
  30172. }
  30173. MessageListener::~MessageListener()
  30174. {
  30175. if (MessageManager::instance != 0)
  30176. MessageManager::instance->messageListeners.removeValue (this);
  30177. }
  30178. void MessageListener::postMessage (Message* const message) const throw()
  30179. {
  30180. message->messageRecipient = const_cast <MessageListener*> (this);
  30181. if (MessageManager::instance == 0)
  30182. MessageManager::getInstance();
  30183. MessageManager::instance->postMessageToQueue (message);
  30184. }
  30185. bool MessageListener::isValidMessageListener() const throw()
  30186. {
  30187. return (MessageManager::instance != 0)
  30188. && MessageManager::instance->messageListeners.contains (this);
  30189. }
  30190. END_JUCE_NAMESPACE
  30191. /*** End of inlined file: juce_MessageListener.cpp ***/
  30192. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30193. BEGIN_JUCE_NAMESPACE
  30194. // platform-specific functions..
  30195. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30196. bool juce_postMessageToSystemQueue (void* message);
  30197. MessageManager* MessageManager::instance = 0;
  30198. static const int quitMessageId = 0xfffff321;
  30199. MessageManager::MessageManager() throw()
  30200. : quitMessagePosted (false),
  30201. quitMessageReceived (false),
  30202. threadWithLock (0)
  30203. {
  30204. messageThreadId = Thread::getCurrentThreadId();
  30205. }
  30206. MessageManager::~MessageManager() throw()
  30207. {
  30208. broadcastListeners = 0;
  30209. doPlatformSpecificShutdown();
  30210. jassert (instance == this);
  30211. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30212. }
  30213. MessageManager* MessageManager::getInstance() throw()
  30214. {
  30215. if (instance == 0)
  30216. {
  30217. instance = new MessageManager();
  30218. doPlatformSpecificInitialisation();
  30219. }
  30220. return instance;
  30221. }
  30222. void MessageManager::postMessageToQueue (Message* const message)
  30223. {
  30224. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30225. delete message;
  30226. }
  30227. CallbackMessage::CallbackMessage() throw() {}
  30228. CallbackMessage::~CallbackMessage() throw() {}
  30229. void CallbackMessage::post()
  30230. {
  30231. if (MessageManager::instance != 0)
  30232. MessageManager::instance->postCallbackMessage (this);
  30233. }
  30234. void MessageManager::postCallbackMessage (Message* const message)
  30235. {
  30236. message->messageRecipient = 0;
  30237. postMessageToQueue (message);
  30238. }
  30239. // not for public use..
  30240. void MessageManager::deliverMessage (void* message)
  30241. {
  30242. const ScopedPointer <Message> m ((Message*) message);
  30243. MessageListener* const recipient = m->messageRecipient;
  30244. JUCE_TRY
  30245. {
  30246. if (messageListeners.contains (recipient))
  30247. {
  30248. recipient->handleMessage (*m);
  30249. }
  30250. else if (recipient == 0)
  30251. {
  30252. if (m->intParameter1 == quitMessageId)
  30253. {
  30254. quitMessageReceived = true;
  30255. }
  30256. else
  30257. {
  30258. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> ((Message*) m);
  30259. if (cm != 0)
  30260. cm->messageCallback();
  30261. }
  30262. }
  30263. }
  30264. JUCE_CATCH_EXCEPTION
  30265. }
  30266. #if ! (JUCE_MAC || JUCE_IPHONE)
  30267. void MessageManager::runDispatchLoop()
  30268. {
  30269. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30270. runDispatchLoopUntil (-1);
  30271. }
  30272. void MessageManager::stopDispatchLoop()
  30273. {
  30274. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30275. m->messageRecipient = 0;
  30276. postMessageToQueue (m);
  30277. quitMessagePosted = true;
  30278. }
  30279. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30280. {
  30281. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30282. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30283. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30284. && ! quitMessageReceived)
  30285. {
  30286. JUCE_TRY
  30287. {
  30288. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30289. {
  30290. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30291. if (msToWait > 0)
  30292. Thread::sleep (jmin (5, msToWait));
  30293. }
  30294. }
  30295. JUCE_CATCH_EXCEPTION
  30296. }
  30297. return ! quitMessageReceived;
  30298. }
  30299. #endif
  30300. void MessageManager::deliverBroadcastMessage (const String& value)
  30301. {
  30302. if (broadcastListeners != 0)
  30303. broadcastListeners->sendActionMessage (value);
  30304. }
  30305. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30306. {
  30307. if (broadcastListeners == 0)
  30308. broadcastListeners = new ActionListenerList();
  30309. broadcastListeners->addActionListener (listener);
  30310. }
  30311. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30312. {
  30313. if (broadcastListeners != 0)
  30314. broadcastListeners->removeActionListener (listener);
  30315. }
  30316. bool MessageManager::isThisTheMessageThread() const throw()
  30317. {
  30318. return Thread::getCurrentThreadId() == messageThreadId;
  30319. }
  30320. void MessageManager::setCurrentThreadAsMessageThread()
  30321. {
  30322. if (messageThreadId != Thread::getCurrentThreadId())
  30323. {
  30324. messageThreadId = Thread::getCurrentThreadId();
  30325. // This is needed on windows to make sure the message window is created by this thread
  30326. doPlatformSpecificShutdown();
  30327. doPlatformSpecificInitialisation();
  30328. }
  30329. }
  30330. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30331. {
  30332. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30333. return thisThread == messageThreadId || thisThread == threadWithLock;
  30334. }
  30335. class MessageManagerLock::SharedEvents : public ReferenceCountedObject
  30336. {
  30337. public:
  30338. SharedEvents() {}
  30339. ~SharedEvents() {}
  30340. WaitableEvent lockedEvent, releaseEvent;
  30341. private:
  30342. SharedEvents (const SharedEvents&);
  30343. SharedEvents& operator= (const SharedEvents&);
  30344. };
  30345. class MessageManagerLock::BlockingMessage : public CallbackMessage
  30346. {
  30347. public:
  30348. BlockingMessage (MessageManagerLock::SharedEvents* const events_) : events (events_) {}
  30349. ~BlockingMessage() throw() {}
  30350. void messageCallback()
  30351. {
  30352. events->lockedEvent.signal();
  30353. events->releaseEvent.wait();
  30354. }
  30355. juce_UseDebuggingNewOperator
  30356. private:
  30357. ReferenceCountedObjectPtr <MessageManagerLock::SharedEvents> events;
  30358. BlockingMessage (const BlockingMessage&);
  30359. BlockingMessage& operator= (const BlockingMessage&);
  30360. };
  30361. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30362. : sharedEvents (0),
  30363. locked (false)
  30364. {
  30365. init (threadToCheck, 0);
  30366. }
  30367. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30368. : sharedEvents (0),
  30369. locked (false)
  30370. {
  30371. init (0, jobToCheckForExitSignal);
  30372. }
  30373. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30374. {
  30375. if (MessageManager::instance != 0)
  30376. {
  30377. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30378. {
  30379. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30380. }
  30381. else
  30382. {
  30383. if (threadToCheck == 0 && job == 0)
  30384. {
  30385. MessageManager::instance->lockingLock.enter();
  30386. }
  30387. else
  30388. {
  30389. while (! MessageManager::instance->lockingLock.tryEnter())
  30390. {
  30391. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30392. || (job != 0 && job->shouldExit()))
  30393. return;
  30394. Thread::sleep (1);
  30395. }
  30396. }
  30397. sharedEvents = new SharedEvents();
  30398. sharedEvents->incReferenceCount();
  30399. (new BlockingMessage (sharedEvents))->post();
  30400. while (! sharedEvents->lockedEvent.wait (50))
  30401. {
  30402. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30403. || (job != 0 && job->shouldExit()))
  30404. {
  30405. sharedEvents->releaseEvent.signal();
  30406. sharedEvents->decReferenceCount();
  30407. sharedEvents = 0;
  30408. MessageManager::instance->lockingLock.exit();
  30409. return;
  30410. }
  30411. }
  30412. jassert (MessageManager::instance->threadWithLock == 0);
  30413. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30414. locked = true;
  30415. }
  30416. }
  30417. }
  30418. MessageManagerLock::~MessageManagerLock() throw()
  30419. {
  30420. if (sharedEvents != 0)
  30421. {
  30422. jassert (MessageManager::instance == 0 || MessageManager::instance->currentThreadHasLockedMessageManager());
  30423. sharedEvents->releaseEvent.signal();
  30424. sharedEvents->decReferenceCount();
  30425. if (MessageManager::instance != 0)
  30426. {
  30427. MessageManager::instance->threadWithLock = 0;
  30428. MessageManager::instance->lockingLock.exit();
  30429. }
  30430. }
  30431. }
  30432. END_JUCE_NAMESPACE
  30433. /*** End of inlined file: juce_MessageManager.cpp ***/
  30434. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30435. BEGIN_JUCE_NAMESPACE
  30436. class MultiTimer::MultiTimerCallback : public Timer
  30437. {
  30438. public:
  30439. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30440. : timerId (timerId_),
  30441. owner (owner_)
  30442. {
  30443. }
  30444. ~MultiTimerCallback()
  30445. {
  30446. }
  30447. void timerCallback()
  30448. {
  30449. owner.timerCallback (timerId);
  30450. }
  30451. const int timerId;
  30452. private:
  30453. MultiTimer& owner;
  30454. };
  30455. MultiTimer::MultiTimer() throw()
  30456. {
  30457. }
  30458. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30459. {
  30460. }
  30461. MultiTimer::~MultiTimer()
  30462. {
  30463. const ScopedLock sl (timerListLock);
  30464. timers.clear();
  30465. }
  30466. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30467. {
  30468. const ScopedLock sl (timerListLock);
  30469. for (int i = timers.size(); --i >= 0;)
  30470. {
  30471. MultiTimerCallback* const t = timers.getUnchecked(i);
  30472. if (t->timerId == timerId)
  30473. {
  30474. t->startTimer (intervalInMilliseconds);
  30475. return;
  30476. }
  30477. }
  30478. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30479. timers.add (newTimer);
  30480. newTimer->startTimer (intervalInMilliseconds);
  30481. }
  30482. void MultiTimer::stopTimer (const int timerId) throw()
  30483. {
  30484. const ScopedLock sl (timerListLock);
  30485. for (int i = timers.size(); --i >= 0;)
  30486. {
  30487. MultiTimerCallback* const t = timers.getUnchecked(i);
  30488. if (t->timerId == timerId)
  30489. t->stopTimer();
  30490. }
  30491. }
  30492. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30493. {
  30494. const ScopedLock sl (timerListLock);
  30495. for (int i = timers.size(); --i >= 0;)
  30496. {
  30497. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30498. if (t->timerId == timerId)
  30499. return t->isTimerRunning();
  30500. }
  30501. return false;
  30502. }
  30503. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30504. {
  30505. const ScopedLock sl (timerListLock);
  30506. for (int i = timers.size(); --i >= 0;)
  30507. {
  30508. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30509. if (t->timerId == timerId)
  30510. return t->getTimerInterval();
  30511. }
  30512. return 0;
  30513. }
  30514. END_JUCE_NAMESPACE
  30515. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30516. /*** Start of inlined file: juce_Timer.cpp ***/
  30517. BEGIN_JUCE_NAMESPACE
  30518. class InternalTimerThread : private Thread,
  30519. private MessageListener,
  30520. private DeletedAtShutdown,
  30521. private AsyncUpdater
  30522. {
  30523. public:
  30524. InternalTimerThread()
  30525. : Thread ("Juce Timer"),
  30526. firstTimer (0),
  30527. callbackNeeded (false)
  30528. {
  30529. triggerAsyncUpdate();
  30530. }
  30531. ~InternalTimerThread() throw()
  30532. {
  30533. stopThread (4000);
  30534. jassert (instance == this || instance == 0);
  30535. if (instance == this)
  30536. instance = 0;
  30537. }
  30538. void run()
  30539. {
  30540. uint32 lastTime = Time::getMillisecondCounter();
  30541. while (! threadShouldExit())
  30542. {
  30543. const uint32 now = Time::getMillisecondCounter();
  30544. if (now <= lastTime)
  30545. {
  30546. wait (2);
  30547. continue;
  30548. }
  30549. const int elapsed = now - lastTime;
  30550. lastTime = now;
  30551. int timeUntilFirstTimer = 1000;
  30552. {
  30553. const ScopedLock sl (lock);
  30554. decrementAllCounters (elapsed);
  30555. if (firstTimer != 0)
  30556. timeUntilFirstTimer = firstTimer->countdownMs;
  30557. }
  30558. if (timeUntilFirstTimer <= 0)
  30559. {
  30560. if (callbackNeeded.set (true))
  30561. {
  30562. postMessage (new Message());
  30563. const uint32 messageDeliveryTimeout = now + 2000;
  30564. while (callbackNeeded.get())
  30565. {
  30566. wait (4);
  30567. if (threadShouldExit())
  30568. return;
  30569. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30570. break;
  30571. }
  30572. }
  30573. }
  30574. else
  30575. {
  30576. // don't wait for too long because running this loop also helps keep the
  30577. // Time::getApproximateMillisecondTimer value stay up-to-date
  30578. wait (jlimit (1, 50, timeUntilFirstTimer));
  30579. }
  30580. }
  30581. }
  30582. void callTimers()
  30583. {
  30584. const ScopedLock sl (lock);
  30585. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30586. {
  30587. Timer* const t = firstTimer;
  30588. t->countdownMs = t->periodMs;
  30589. removeTimer (t);
  30590. addTimer (t);
  30591. const ScopedUnlock ul (lock);
  30592. JUCE_TRY
  30593. {
  30594. t->timerCallback();
  30595. }
  30596. JUCE_CATCH_EXCEPTION
  30597. }
  30598. callbackNeeded.set (false);
  30599. }
  30600. void handleMessage (const Message&)
  30601. {
  30602. callTimers();
  30603. }
  30604. void callTimersSynchronously()
  30605. {
  30606. if (! isThreadRunning())
  30607. {
  30608. // (This is relied on by some plugins in cases where the MM has
  30609. // had to restart and the async callback never started)
  30610. cancelPendingUpdate();
  30611. triggerAsyncUpdate();
  30612. }
  30613. callTimers();
  30614. }
  30615. static void callAnyTimersSynchronously()
  30616. {
  30617. if (InternalTimerThread::instance != 0)
  30618. InternalTimerThread::instance->callTimersSynchronously();
  30619. }
  30620. static inline void add (Timer* const tim) throw()
  30621. {
  30622. if (instance == 0)
  30623. instance = new InternalTimerThread();
  30624. const ScopedLock sl (instance->lock);
  30625. instance->addTimer (tim);
  30626. }
  30627. static inline void remove (Timer* const tim) throw()
  30628. {
  30629. if (instance != 0)
  30630. {
  30631. const ScopedLock sl (instance->lock);
  30632. instance->removeTimer (tim);
  30633. }
  30634. }
  30635. static inline void resetCounter (Timer* const tim,
  30636. const int newCounter) throw()
  30637. {
  30638. if (instance != 0)
  30639. {
  30640. tim->countdownMs = newCounter;
  30641. tim->periodMs = newCounter;
  30642. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30643. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30644. {
  30645. const ScopedLock sl (instance->lock);
  30646. instance->removeTimer (tim);
  30647. instance->addTimer (tim);
  30648. }
  30649. }
  30650. }
  30651. private:
  30652. friend class Timer;
  30653. static InternalTimerThread* instance;
  30654. static CriticalSection lock;
  30655. Timer* volatile firstTimer;
  30656. class AtomicBool
  30657. {
  30658. public:
  30659. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30660. ~AtomicBool() throw() {}
  30661. bool get() const throw() { return value != 0; }
  30662. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30663. private:
  30664. int32 value;
  30665. AtomicBool (const AtomicBool&);
  30666. AtomicBool& operator= (const AtomicBool&);
  30667. };
  30668. AtomicBool callbackNeeded;
  30669. void addTimer (Timer* const t) throw()
  30670. {
  30671. #ifdef JUCE_DEBUG
  30672. Timer* tt = firstTimer;
  30673. while (tt != 0)
  30674. {
  30675. // trying to add a timer that's already here - shouldn't get to this point,
  30676. // so if you get this assertion, let me know!
  30677. jassert (tt != t);
  30678. tt = tt->next;
  30679. }
  30680. jassert (t->previous == 0 && t->next == 0);
  30681. #endif
  30682. Timer* i = firstTimer;
  30683. if (i == 0 || i->countdownMs > t->countdownMs)
  30684. {
  30685. t->next = firstTimer;
  30686. firstTimer = t;
  30687. }
  30688. else
  30689. {
  30690. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30691. i = i->next;
  30692. jassert (i != 0);
  30693. t->next = i->next;
  30694. t->previous = i;
  30695. i->next = t;
  30696. }
  30697. if (t->next != 0)
  30698. t->next->previous = t;
  30699. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30700. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30701. notify();
  30702. }
  30703. void removeTimer (Timer* const t) throw()
  30704. {
  30705. #ifdef JUCE_DEBUG
  30706. Timer* tt = firstTimer;
  30707. bool found = false;
  30708. while (tt != 0)
  30709. {
  30710. if (tt == t)
  30711. {
  30712. found = true;
  30713. break;
  30714. }
  30715. tt = tt->next;
  30716. }
  30717. // trying to remove a timer that's not here - shouldn't get to this point,
  30718. // so if you get this assertion, let me know!
  30719. jassert (found);
  30720. #endif
  30721. if (t->previous != 0)
  30722. {
  30723. jassert (firstTimer != t);
  30724. t->previous->next = t->next;
  30725. }
  30726. else
  30727. {
  30728. jassert (firstTimer == t);
  30729. firstTimer = t->next;
  30730. }
  30731. if (t->next != 0)
  30732. t->next->previous = t->previous;
  30733. t->next = 0;
  30734. t->previous = 0;
  30735. }
  30736. void decrementAllCounters (const int numMillisecs) const
  30737. {
  30738. Timer* t = firstTimer;
  30739. while (t != 0)
  30740. {
  30741. t->countdownMs -= numMillisecs;
  30742. t = t->next;
  30743. }
  30744. }
  30745. void handleAsyncUpdate()
  30746. {
  30747. startThread (7);
  30748. }
  30749. InternalTimerThread (const InternalTimerThread&);
  30750. InternalTimerThread& operator= (const InternalTimerThread&);
  30751. };
  30752. InternalTimerThread* InternalTimerThread::instance = 0;
  30753. CriticalSection InternalTimerThread::lock;
  30754. void juce_callAnyTimersSynchronously()
  30755. {
  30756. InternalTimerThread::callAnyTimersSynchronously();
  30757. }
  30758. #ifdef JUCE_DEBUG
  30759. static SortedSet <Timer*> activeTimers;
  30760. #endif
  30761. Timer::Timer() throw()
  30762. : countdownMs (0),
  30763. periodMs (0),
  30764. previous (0),
  30765. next (0)
  30766. {
  30767. #ifdef JUCE_DEBUG
  30768. activeTimers.add (this);
  30769. #endif
  30770. }
  30771. Timer::Timer (const Timer&) throw()
  30772. : countdownMs (0),
  30773. periodMs (0),
  30774. previous (0),
  30775. next (0)
  30776. {
  30777. #ifdef JUCE_DEBUG
  30778. activeTimers.add (this);
  30779. #endif
  30780. }
  30781. Timer::~Timer()
  30782. {
  30783. stopTimer();
  30784. #ifdef JUCE_DEBUG
  30785. activeTimers.removeValue (this);
  30786. #endif
  30787. }
  30788. void Timer::startTimer (const int interval) throw()
  30789. {
  30790. const ScopedLock sl (InternalTimerThread::lock);
  30791. #ifdef JUCE_DEBUG
  30792. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30793. jassert (activeTimers.contains (this));
  30794. #endif
  30795. if (periodMs == 0)
  30796. {
  30797. countdownMs = interval;
  30798. periodMs = jmax (1, interval);
  30799. InternalTimerThread::add (this);
  30800. }
  30801. else
  30802. {
  30803. InternalTimerThread::resetCounter (this, interval);
  30804. }
  30805. }
  30806. void Timer::stopTimer() throw()
  30807. {
  30808. const ScopedLock sl (InternalTimerThread::lock);
  30809. #ifdef JUCE_DEBUG
  30810. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30811. jassert (activeTimers.contains (this));
  30812. #endif
  30813. if (periodMs > 0)
  30814. {
  30815. InternalTimerThread::remove (this);
  30816. periodMs = 0;
  30817. }
  30818. }
  30819. END_JUCE_NAMESPACE
  30820. /*** End of inlined file: juce_Timer.cpp ***/
  30821. #endif
  30822. #if JUCE_BUILD_GUI
  30823. /*** Start of inlined file: juce_Component.cpp ***/
  30824. BEGIN_JUCE_NAMESPACE
  30825. Component* Component::currentlyFocusedComponent = 0;
  30826. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  30827. static Array <int> modalReturnValues;
  30828. enum ComponentMessageNumbers
  30829. {
  30830. customCommandMessage = 0x7fff0001,
  30831. exitModalStateMessage = 0x7fff0002
  30832. };
  30833. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  30834. static uint32 nextComponentUID = 0;
  30835. Component::Component()
  30836. : parentComponent_ (0),
  30837. componentUID (++nextComponentUID),
  30838. numDeepMouseListeners (0),
  30839. lookAndFeel_ (0),
  30840. effect_ (0),
  30841. bufferedImage_ (0),
  30842. mouseListeners_ (0),
  30843. keyListeners_ (0),
  30844. componentFlags_ (0)
  30845. {
  30846. }
  30847. Component::Component (const String& name)
  30848. : componentName_ (name),
  30849. parentComponent_ (0),
  30850. componentUID (++nextComponentUID),
  30851. numDeepMouseListeners (0),
  30852. lookAndFeel_ (0),
  30853. effect_ (0),
  30854. bufferedImage_ (0),
  30855. mouseListeners_ (0),
  30856. keyListeners_ (0),
  30857. componentFlags_ (0)
  30858. {
  30859. }
  30860. Component::~Component()
  30861. {
  30862. componentListeners.call (&ComponentListener::componentBeingDeleted, *this);
  30863. if (parentComponent_ != 0)
  30864. {
  30865. parentComponent_->removeChildComponent (this);
  30866. }
  30867. else if ((currentlyFocusedComponent == this)
  30868. || isParentOf (currentlyFocusedComponent))
  30869. {
  30870. giveAwayFocus();
  30871. }
  30872. if (flags.hasHeavyweightPeerFlag)
  30873. removeFromDesktop();
  30874. modalComponentStack.removeValue (this);
  30875. for (int i = childComponentList_.size(); --i >= 0;)
  30876. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  30877. delete bufferedImage_;
  30878. delete mouseListeners_;
  30879. delete keyListeners_;
  30880. }
  30881. void Component::setName (const String& name)
  30882. {
  30883. // if component methods are being called from threads other than the message
  30884. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30885. checkMessageManagerIsLocked
  30886. if (componentName_ != name)
  30887. {
  30888. componentName_ = name;
  30889. if (flags.hasHeavyweightPeerFlag)
  30890. {
  30891. ComponentPeer* const peer = getPeer();
  30892. jassert (peer != 0);
  30893. if (peer != 0)
  30894. peer->setTitle (name);
  30895. }
  30896. BailOutChecker checker (this);
  30897. componentListeners.callChecked (checker, &ComponentListener::componentNameChanged, *this);
  30898. }
  30899. }
  30900. void Component::setVisible (bool shouldBeVisible)
  30901. {
  30902. if (flags.visibleFlag != shouldBeVisible)
  30903. {
  30904. // if component methods are being called from threads other than the message
  30905. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30906. checkMessageManagerIsLocked
  30907. SafePointer<Component> safePointer (this);
  30908. flags.visibleFlag = shouldBeVisible;
  30909. internalRepaint (0, 0, getWidth(), getHeight());
  30910. sendFakeMouseMove();
  30911. if (! shouldBeVisible)
  30912. {
  30913. if (currentlyFocusedComponent == this
  30914. || isParentOf (currentlyFocusedComponent))
  30915. {
  30916. if (parentComponent_ != 0)
  30917. parentComponent_->grabKeyboardFocus();
  30918. else
  30919. giveAwayFocus();
  30920. }
  30921. }
  30922. sendVisibilityChangeMessage();
  30923. if (safePointer != 0 && flags.hasHeavyweightPeerFlag)
  30924. {
  30925. ComponentPeer* const peer = getPeer();
  30926. jassert (peer != 0);
  30927. if (peer != 0)
  30928. {
  30929. peer->setVisible (shouldBeVisible);
  30930. internalHierarchyChanged();
  30931. }
  30932. }
  30933. }
  30934. }
  30935. void Component::visibilityChanged()
  30936. {
  30937. }
  30938. void Component::sendVisibilityChangeMessage()
  30939. {
  30940. BailOutChecker checker (this);
  30941. visibilityChanged();
  30942. if (! checker.shouldBailOut())
  30943. componentListeners.callChecked (checker, &ComponentListener::componentVisibilityChanged, *this);
  30944. }
  30945. bool Component::isShowing() const
  30946. {
  30947. if (flags.visibleFlag)
  30948. {
  30949. if (parentComponent_ != 0)
  30950. {
  30951. return parentComponent_->isShowing();
  30952. }
  30953. else
  30954. {
  30955. const ComponentPeer* const peer = getPeer();
  30956. return peer != 0 && ! peer->isMinimised();
  30957. }
  30958. }
  30959. return false;
  30960. }
  30961. class FadeOutProxyComponent : public Component,
  30962. public Timer
  30963. {
  30964. public:
  30965. FadeOutProxyComponent (Component* comp,
  30966. const int fadeLengthMs,
  30967. const int deltaXToMove,
  30968. const int deltaYToMove,
  30969. const float scaleFactorAtEnd)
  30970. : lastTime (0),
  30971. alpha (1.0f),
  30972. scale (1.0f)
  30973. {
  30974. image = comp->createComponentSnapshot (Rectangle<int> (0, 0, comp->getWidth(), comp->getHeight()));
  30975. setBounds (comp->getBounds());
  30976. comp->getParentComponent()->addAndMakeVisible (this);
  30977. toBehind (comp);
  30978. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  30979. centreX = comp->getX() + comp->getWidth() * 0.5f;
  30980. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  30981. centreY = comp->getY() + comp->getHeight() * 0.5f;
  30982. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  30983. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  30984. setInterceptsMouseClicks (false, false);
  30985. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  30986. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  30987. }
  30988. ~FadeOutProxyComponent()
  30989. {
  30990. delete image;
  30991. }
  30992. void paint (Graphics& g)
  30993. {
  30994. g.setOpacity (alpha);
  30995. g.drawImage (image,
  30996. 0, 0, getWidth(), getHeight(),
  30997. 0, 0, image->getWidth(), image->getHeight());
  30998. }
  30999. void timerCallback()
  31000. {
  31001. const uint32 now = Time::getMillisecondCounter();
  31002. if (lastTime == 0)
  31003. lastTime = now;
  31004. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31005. lastTime = now;
  31006. alpha += alphaChangePerMs * msPassed;
  31007. if (alpha > 0)
  31008. {
  31009. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31010. {
  31011. centreX += xChangePerMs * msPassed;
  31012. centreY += yChangePerMs * msPassed;
  31013. scale += scaleChangePerMs * msPassed;
  31014. const int w = roundToInt (image->getWidth() * scale);
  31015. const int h = roundToInt (image->getHeight() * scale);
  31016. setBounds (roundToInt (centreX) - w / 2,
  31017. roundToInt (centreY) - h / 2,
  31018. w, h);
  31019. }
  31020. repaint();
  31021. }
  31022. else
  31023. {
  31024. delete this;
  31025. }
  31026. }
  31027. juce_UseDebuggingNewOperator
  31028. private:
  31029. Image* image;
  31030. uint32 lastTime;
  31031. float alpha, alphaChangePerMs;
  31032. float centreX, xChangePerMs;
  31033. float centreY, yChangePerMs;
  31034. float scale, scaleChangePerMs;
  31035. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31036. FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31037. };
  31038. void Component::fadeOutComponent (const int millisecondsToFade,
  31039. const int deltaXToMove,
  31040. const int deltaYToMove,
  31041. const float scaleFactorAtEnd)
  31042. {
  31043. //xxx won't work for comps without parents
  31044. if (isShowing() && millisecondsToFade > 0)
  31045. new FadeOutProxyComponent (this, millisecondsToFade,
  31046. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31047. setVisible (false);
  31048. }
  31049. bool Component::isValidComponent() const
  31050. {
  31051. return (this != 0) && isValidMessageListener();
  31052. }
  31053. void* Component::getWindowHandle() const
  31054. {
  31055. const ComponentPeer* const peer = getPeer();
  31056. if (peer != 0)
  31057. return peer->getNativeHandle();
  31058. return 0;
  31059. }
  31060. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31061. {
  31062. // if component methods are being called from threads other than the message
  31063. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31064. checkMessageManagerIsLocked
  31065. if (isOpaque())
  31066. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31067. else
  31068. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31069. int currentStyleFlags = 0;
  31070. // don't use getPeer(), so that we only get the peer that's specifically
  31071. // for this comp, and not for one of its parents.
  31072. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31073. if (peer != 0)
  31074. currentStyleFlags = peer->getStyleFlags();
  31075. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31076. {
  31077. SafePointer<Component> safePointer (this);
  31078. #if JUCE_LINUX
  31079. // it's wise to give the component a non-zero size before
  31080. // putting it on the desktop, as X windows get confused by this, and
  31081. // a (1, 1) minimum size is enforced here.
  31082. setSize (jmax (1, getWidth()),
  31083. jmax (1, getHeight()));
  31084. #endif
  31085. const Point<int> topLeft (relativePositionToGlobal (Point<int> (0, 0)));
  31086. bool wasFullscreen = false;
  31087. bool wasMinimised = false;
  31088. ComponentBoundsConstrainer* currentConstainer = 0;
  31089. Rectangle<int> oldNonFullScreenBounds;
  31090. if (peer != 0)
  31091. {
  31092. wasFullscreen = peer->isFullScreen();
  31093. wasMinimised = peer->isMinimised();
  31094. currentConstainer = peer->getConstrainer();
  31095. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31096. removeFromDesktop();
  31097. setTopLeftPosition (topLeft.getX(), topLeft.getY());
  31098. }
  31099. if (parentComponent_ != 0)
  31100. parentComponent_->removeChildComponent (this);
  31101. if (safePointer != 0)
  31102. {
  31103. flags.hasHeavyweightPeerFlag = true;
  31104. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31105. Desktop::getInstance().addDesktopComponent (this);
  31106. bounds_.setPosition (topLeft);
  31107. peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false);
  31108. peer->setVisible (isVisible());
  31109. if (wasFullscreen)
  31110. {
  31111. peer->setFullScreen (true);
  31112. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31113. }
  31114. if (wasMinimised)
  31115. peer->setMinimised (true);
  31116. if (isAlwaysOnTop())
  31117. peer->setAlwaysOnTop (true);
  31118. peer->setConstrainer (currentConstainer);
  31119. repaint();
  31120. }
  31121. internalHierarchyChanged();
  31122. }
  31123. }
  31124. void Component::removeFromDesktop()
  31125. {
  31126. // if component methods are being called from threads other than the message
  31127. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31128. checkMessageManagerIsLocked
  31129. if (flags.hasHeavyweightPeerFlag)
  31130. {
  31131. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31132. flags.hasHeavyweightPeerFlag = false;
  31133. jassert (peer != 0);
  31134. delete peer;
  31135. Desktop::getInstance().removeDesktopComponent (this);
  31136. }
  31137. }
  31138. bool Component::isOnDesktop() const throw()
  31139. {
  31140. return flags.hasHeavyweightPeerFlag;
  31141. }
  31142. void Component::userTriedToCloseWindow()
  31143. {
  31144. /* This means that the user's trying to get rid of your window with the 'close window' system
  31145. menu option (on windows) or possibly the task manager - you should really handle this
  31146. and delete or hide your component in an appropriate way.
  31147. If you want to ignore the event and don't want to trigger this assertion, just override
  31148. this method and do nothing.
  31149. */
  31150. jassertfalse
  31151. }
  31152. void Component::minimisationStateChanged (bool)
  31153. {
  31154. }
  31155. void Component::setOpaque (const bool shouldBeOpaque)
  31156. {
  31157. if (shouldBeOpaque != flags.opaqueFlag)
  31158. {
  31159. flags.opaqueFlag = shouldBeOpaque;
  31160. if (flags.hasHeavyweightPeerFlag)
  31161. {
  31162. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31163. if (peer != 0)
  31164. {
  31165. // to make it recreate the heavyweight window
  31166. addToDesktop (peer->getStyleFlags());
  31167. }
  31168. }
  31169. repaint();
  31170. }
  31171. }
  31172. bool Component::isOpaque() const throw()
  31173. {
  31174. return flags.opaqueFlag;
  31175. }
  31176. void Component::setBufferedToImage (const bool shouldBeBuffered)
  31177. {
  31178. if (shouldBeBuffered != flags.bufferToImageFlag)
  31179. {
  31180. deleteAndZero (bufferedImage_);
  31181. flags.bufferToImageFlag = shouldBeBuffered;
  31182. }
  31183. }
  31184. void Component::toFront (const bool setAsForeground)
  31185. {
  31186. // if component methods are being called from threads other than the message
  31187. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31188. checkMessageManagerIsLocked
  31189. if (flags.hasHeavyweightPeerFlag)
  31190. {
  31191. ComponentPeer* const peer = getPeer();
  31192. if (peer != 0)
  31193. {
  31194. peer->toFront (setAsForeground);
  31195. if (setAsForeground && ! hasKeyboardFocus (true))
  31196. grabKeyboardFocus();
  31197. }
  31198. }
  31199. else if (parentComponent_ != 0)
  31200. {
  31201. if (parentComponent_->childComponentList_.getLast() != this)
  31202. {
  31203. const int index = parentComponent_->childComponentList_.indexOf (this);
  31204. if (index >= 0)
  31205. {
  31206. int insertIndex = -1;
  31207. if (! flags.alwaysOnTopFlag)
  31208. {
  31209. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31210. while (insertIndex > 0
  31211. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31212. {
  31213. --insertIndex;
  31214. }
  31215. }
  31216. if (index != insertIndex)
  31217. {
  31218. parentComponent_->childComponentList_.move (index, insertIndex);
  31219. sendFakeMouseMove();
  31220. repaintParent();
  31221. }
  31222. }
  31223. }
  31224. if (setAsForeground)
  31225. {
  31226. internalBroughtToFront();
  31227. grabKeyboardFocus();
  31228. }
  31229. }
  31230. }
  31231. void Component::toBehind (Component* const other)
  31232. {
  31233. if (other != 0)
  31234. {
  31235. // the two components must belong to the same parent..
  31236. jassert (parentComponent_ == other->parentComponent_);
  31237. if (parentComponent_ != 0)
  31238. {
  31239. const int index = parentComponent_->childComponentList_.indexOf (this);
  31240. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31241. if (index >= 0
  31242. && otherIndex >= 0
  31243. && index != otherIndex - 1
  31244. && other != this)
  31245. {
  31246. if (index < otherIndex)
  31247. --otherIndex;
  31248. parentComponent_->childComponentList_.move (index, otherIndex);
  31249. sendFakeMouseMove();
  31250. repaintParent();
  31251. }
  31252. }
  31253. else if (isOnDesktop())
  31254. {
  31255. jassert (other->isOnDesktop());
  31256. if (other->isOnDesktop())
  31257. {
  31258. ComponentPeer* const us = getPeer();
  31259. ComponentPeer* const them = other->getPeer();
  31260. jassert (us != 0 && them != 0);
  31261. if (us != 0 && them != 0)
  31262. us->toBehind (them);
  31263. }
  31264. }
  31265. }
  31266. }
  31267. void Component::toBack()
  31268. {
  31269. if (isOnDesktop())
  31270. {
  31271. jassertfalse //xxx need to add this to native window
  31272. }
  31273. else if (parentComponent_ != 0
  31274. && parentComponent_->childComponentList_.getFirst() != this)
  31275. {
  31276. const int index = parentComponent_->childComponentList_.indexOf (this);
  31277. if (index > 0)
  31278. {
  31279. int insertIndex = 0;
  31280. if (flags.alwaysOnTopFlag)
  31281. {
  31282. while (insertIndex < parentComponent_->childComponentList_.size()
  31283. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31284. {
  31285. ++insertIndex;
  31286. }
  31287. }
  31288. if (index != insertIndex)
  31289. {
  31290. parentComponent_->childComponentList_.move (index, insertIndex);
  31291. sendFakeMouseMove();
  31292. repaintParent();
  31293. }
  31294. }
  31295. }
  31296. }
  31297. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31298. {
  31299. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31300. {
  31301. flags.alwaysOnTopFlag = shouldStayOnTop;
  31302. if (isOnDesktop())
  31303. {
  31304. ComponentPeer* const peer = getPeer();
  31305. jassert (peer != 0);
  31306. if (peer != 0)
  31307. {
  31308. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31309. {
  31310. // some kinds of peer can't change their always-on-top status, so
  31311. // for these, we'll need to create a new window
  31312. const int oldFlags = peer->getStyleFlags();
  31313. removeFromDesktop();
  31314. addToDesktop (oldFlags);
  31315. }
  31316. }
  31317. }
  31318. if (shouldStayOnTop)
  31319. toFront (false);
  31320. internalHierarchyChanged();
  31321. }
  31322. }
  31323. bool Component::isAlwaysOnTop() const throw()
  31324. {
  31325. return flags.alwaysOnTopFlag;
  31326. }
  31327. int Component::proportionOfWidth (const float proportion) const throw()
  31328. {
  31329. return roundToInt (proportion * bounds_.getWidth());
  31330. }
  31331. int Component::proportionOfHeight (const float proportion) const throw()
  31332. {
  31333. return roundToInt (proportion * bounds_.getHeight());
  31334. }
  31335. int Component::getParentWidth() const throw()
  31336. {
  31337. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31338. : getParentMonitorArea().getWidth();
  31339. }
  31340. int Component::getParentHeight() const throw()
  31341. {
  31342. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31343. : getParentMonitorArea().getHeight();
  31344. }
  31345. int Component::getScreenX() const
  31346. {
  31347. return getScreenPosition().getX();
  31348. }
  31349. int Component::getScreenY() const
  31350. {
  31351. return getScreenPosition().getY();
  31352. }
  31353. const Point<int> Component::getScreenPosition() const
  31354. {
  31355. return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition()
  31356. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition()
  31357. : getPosition());
  31358. }
  31359. const Rectangle<int> Component::getScreenBounds() const
  31360. {
  31361. return bounds_.withPosition (getScreenPosition());
  31362. }
  31363. const Point<int> Component::relativePositionToGlobal (const Point<int>& relativePosition) const
  31364. {
  31365. const Component* c = this;
  31366. Point<int> p (relativePosition);
  31367. do
  31368. {
  31369. if (c->flags.hasHeavyweightPeerFlag)
  31370. return c->getPeer()->relativePositionToGlobal (p);
  31371. p += c->getPosition();
  31372. c = c->parentComponent_;
  31373. }
  31374. while (c != 0);
  31375. return p;
  31376. }
  31377. const Point<int> Component::globalPositionToRelative (const Point<int>& screenPosition) const
  31378. {
  31379. if (flags.hasHeavyweightPeerFlag)
  31380. {
  31381. return getPeer()->globalPositionToRelative (screenPosition);
  31382. }
  31383. else
  31384. {
  31385. if (parentComponent_ != 0)
  31386. return parentComponent_->globalPositionToRelative (screenPosition) - getPosition();
  31387. return screenPosition - getPosition();
  31388. }
  31389. }
  31390. const Point<int> Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point<int>& positionRelativeToThis) const
  31391. {
  31392. Point<int> p (positionRelativeToThis);
  31393. if (targetComponent != 0)
  31394. {
  31395. const Component* c = this;
  31396. do
  31397. {
  31398. if (c == targetComponent)
  31399. return p;
  31400. if (c->flags.hasHeavyweightPeerFlag)
  31401. {
  31402. p = c->getPeer()->relativePositionToGlobal (p);
  31403. break;
  31404. }
  31405. p += c->getPosition();
  31406. c = c->parentComponent_;
  31407. }
  31408. while (c != 0);
  31409. p = targetComponent->globalPositionToRelative (p);
  31410. }
  31411. return p;
  31412. }
  31413. void Component::setBounds (int x, int y, int w, int h)
  31414. {
  31415. // if component methods are being called from threads other than the message
  31416. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31417. checkMessageManagerIsLocked
  31418. if (w < 0) w = 0;
  31419. if (h < 0) h = 0;
  31420. const bool wasResized = (getWidth() != w || getHeight() != h);
  31421. const bool wasMoved = (getX() != x || getY() != y);
  31422. #ifdef JUCE_DEBUG
  31423. // It's a very bad idea to try to resize a window during its paint() method!
  31424. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31425. #endif
  31426. if (wasMoved || wasResized)
  31427. {
  31428. if (flags.visibleFlag)
  31429. {
  31430. // send a fake mouse move to trigger enter/exit messages if needed..
  31431. sendFakeMouseMove();
  31432. if (! flags.hasHeavyweightPeerFlag)
  31433. repaintParent();
  31434. }
  31435. bounds_.setBounds (x, y, w, h);
  31436. if (wasResized)
  31437. repaint();
  31438. else if (! flags.hasHeavyweightPeerFlag)
  31439. repaintParent();
  31440. if (flags.hasHeavyweightPeerFlag)
  31441. {
  31442. ComponentPeer* const peer = getPeer();
  31443. if (peer != 0)
  31444. {
  31445. if (wasMoved && wasResized)
  31446. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31447. else if (wasMoved)
  31448. peer->setPosition (getX(), getY());
  31449. else if (wasResized)
  31450. peer->setSize (getWidth(), getHeight());
  31451. }
  31452. }
  31453. sendMovedResizedMessages (wasMoved, wasResized);
  31454. }
  31455. }
  31456. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31457. {
  31458. JUCE_TRY
  31459. {
  31460. if (wasMoved)
  31461. moved();
  31462. if (wasResized)
  31463. {
  31464. resized();
  31465. for (int i = childComponentList_.size(); --i >= 0;)
  31466. {
  31467. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31468. i = jmin (i, childComponentList_.size());
  31469. }
  31470. }
  31471. BailOutChecker checker (this);
  31472. if (parentComponent_ != 0)
  31473. parentComponent_->childBoundsChanged (this);
  31474. if (! checker.shouldBailOut())
  31475. componentListeners.callChecked (checker, &ComponentListener::componentMovedOrResized,
  31476. *this, wasMoved, wasResized);
  31477. }
  31478. JUCE_CATCH_EXCEPTION
  31479. }
  31480. void Component::setSize (const int w, const int h)
  31481. {
  31482. setBounds (getX(), getY(), w, h);
  31483. }
  31484. void Component::setTopLeftPosition (const int x, const int y)
  31485. {
  31486. setBounds (x, y, getWidth(), getHeight());
  31487. }
  31488. void Component::setTopRightPosition (const int x, const int y)
  31489. {
  31490. setTopLeftPosition (x - getWidth(), y);
  31491. }
  31492. void Component::setBounds (const Rectangle<int>& r)
  31493. {
  31494. setBounds (r.getX(),
  31495. r.getY(),
  31496. r.getWidth(),
  31497. r.getHeight());
  31498. }
  31499. void Component::setBoundsRelative (const float x, const float y,
  31500. const float w, const float h)
  31501. {
  31502. const int pw = getParentWidth();
  31503. const int ph = getParentHeight();
  31504. setBounds (roundToInt (x * pw),
  31505. roundToInt (y * ph),
  31506. roundToInt (w * pw),
  31507. roundToInt (h * ph));
  31508. }
  31509. void Component::setCentrePosition (const int x, const int y)
  31510. {
  31511. setTopLeftPosition (x - getWidth() / 2,
  31512. y - getHeight() / 2);
  31513. }
  31514. void Component::setCentreRelative (const float x, const float y)
  31515. {
  31516. setCentrePosition (roundToInt (getParentWidth() * x),
  31517. roundToInt (getParentHeight() * y));
  31518. }
  31519. void Component::centreWithSize (const int width, const int height)
  31520. {
  31521. setBounds ((getParentWidth() - width) / 2,
  31522. (getParentHeight() - height) / 2,
  31523. width,
  31524. height);
  31525. }
  31526. void Component::setBoundsInset (const BorderSize& borders)
  31527. {
  31528. setBounds (borders.getLeft(),
  31529. borders.getTop(),
  31530. getParentWidth() - (borders.getLeftAndRight()),
  31531. getParentHeight() - (borders.getTopAndBottom()));
  31532. }
  31533. void Component::setBoundsToFit (int x, int y, int width, int height,
  31534. const Justification& justification,
  31535. const bool onlyReduceInSize)
  31536. {
  31537. // it's no good calling this method unless both the component and
  31538. // target rectangle have a finite size.
  31539. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31540. if (getWidth() > 0 && getHeight() > 0
  31541. && width > 0 && height > 0)
  31542. {
  31543. int newW, newH;
  31544. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31545. {
  31546. newW = getWidth();
  31547. newH = getHeight();
  31548. }
  31549. else
  31550. {
  31551. const double imageRatio = getHeight() / (double) getWidth();
  31552. const double targetRatio = height / (double) width;
  31553. if (imageRatio <= targetRatio)
  31554. {
  31555. newW = width;
  31556. newH = jmin (height, roundToInt (newW * imageRatio));
  31557. }
  31558. else
  31559. {
  31560. newH = height;
  31561. newW = jmin (width, roundToInt (newH / imageRatio));
  31562. }
  31563. }
  31564. if (newW > 0 && newH > 0)
  31565. {
  31566. int newX, newY;
  31567. justification.applyToRectangle (newX, newY, newW, newH,
  31568. x, y, width, height);
  31569. setBounds (newX, newY, newW, newH);
  31570. }
  31571. }
  31572. }
  31573. bool Component::hitTest (int x, int y)
  31574. {
  31575. if (! flags.ignoresMouseClicksFlag)
  31576. return true;
  31577. if (flags.allowChildMouseClicksFlag)
  31578. {
  31579. for (int i = getNumChildComponents(); --i >= 0;)
  31580. {
  31581. Component* const c = getChildComponent (i);
  31582. if (c->isVisible()
  31583. && c->bounds_.contains (x, y)
  31584. && c->hitTest (x - c->getX(),
  31585. y - c->getY()))
  31586. {
  31587. return true;
  31588. }
  31589. }
  31590. }
  31591. return false;
  31592. }
  31593. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31594. const bool allowClicksOnChildComponents) throw()
  31595. {
  31596. flags.ignoresMouseClicksFlag = ! allowClicks;
  31597. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31598. }
  31599. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31600. bool& allowsClicksOnChildComponents) const throw()
  31601. {
  31602. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31603. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31604. }
  31605. bool Component::contains (const int x, const int y)
  31606. {
  31607. if (((unsigned int) x) < (unsigned int) getWidth()
  31608. && ((unsigned int) y) < (unsigned int) getHeight()
  31609. && hitTest (x, y))
  31610. {
  31611. if (parentComponent_ != 0)
  31612. {
  31613. return parentComponent_->contains (x + getX(),
  31614. y + getY());
  31615. }
  31616. else if (flags.hasHeavyweightPeerFlag)
  31617. {
  31618. const ComponentPeer* const peer = getPeer();
  31619. if (peer != 0)
  31620. return peer->contains (Point<int> (x, y), true);
  31621. }
  31622. }
  31623. return false;
  31624. }
  31625. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31626. {
  31627. if (! contains (x, y))
  31628. return false;
  31629. Component* p = this;
  31630. while (p->parentComponent_ != 0)
  31631. {
  31632. x += p->getX();
  31633. y += p->getY();
  31634. p = p->parentComponent_;
  31635. }
  31636. const Component* const c = p->getComponentAt (x, y);
  31637. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31638. }
  31639. Component* Component::getComponentAt (const Point<int>& position)
  31640. {
  31641. return getComponentAt (position.getX(), position.getY());
  31642. }
  31643. Component* Component::getComponentAt (const int x, const int y)
  31644. {
  31645. if (flags.visibleFlag
  31646. && ((unsigned int) x) < (unsigned int) getWidth()
  31647. && ((unsigned int) y) < (unsigned int) getHeight()
  31648. && hitTest (x, y))
  31649. {
  31650. for (int i = childComponentList_.size(); --i >= 0;)
  31651. {
  31652. Component* const child = childComponentList_.getUnchecked(i);
  31653. Component* const c = child->getComponentAt (x - child->getX(),
  31654. y - child->getY());
  31655. if (c != 0)
  31656. return c;
  31657. }
  31658. return this;
  31659. }
  31660. return 0;
  31661. }
  31662. void Component::addChildComponent (Component* const child, int zOrder)
  31663. {
  31664. // if component methods are being called from threads other than the message
  31665. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31666. checkMessageManagerIsLocked
  31667. if (child != 0 && child->parentComponent_ != this)
  31668. {
  31669. if (child->parentComponent_ != 0)
  31670. child->parentComponent_->removeChildComponent (child);
  31671. else
  31672. child->removeFromDesktop();
  31673. child->parentComponent_ = this;
  31674. if (child->isVisible())
  31675. child->repaintParent();
  31676. if (! child->isAlwaysOnTop())
  31677. {
  31678. if (zOrder < 0 || zOrder > childComponentList_.size())
  31679. zOrder = childComponentList_.size();
  31680. while (zOrder > 0)
  31681. {
  31682. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31683. break;
  31684. --zOrder;
  31685. }
  31686. }
  31687. childComponentList_.insert (zOrder, child);
  31688. child->internalHierarchyChanged();
  31689. internalChildrenChanged();
  31690. }
  31691. }
  31692. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31693. {
  31694. if (child != 0)
  31695. {
  31696. child->setVisible (true);
  31697. addChildComponent (child, zOrder);
  31698. }
  31699. }
  31700. void Component::removeChildComponent (Component* const child)
  31701. {
  31702. removeChildComponent (childComponentList_.indexOf (child));
  31703. }
  31704. Component* Component::removeChildComponent (const int index)
  31705. {
  31706. // if component methods are being called from threads other than the message
  31707. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31708. checkMessageManagerIsLocked
  31709. Component* const child = childComponentList_ [index];
  31710. if (child != 0)
  31711. {
  31712. sendFakeMouseMove();
  31713. child->repaintParent();
  31714. childComponentList_.remove (index);
  31715. child->parentComponent_ = 0;
  31716. JUCE_TRY
  31717. {
  31718. if ((currentlyFocusedComponent == child)
  31719. || child->isParentOf (currentlyFocusedComponent))
  31720. {
  31721. // get rid first to force the grabKeyboardFocus to change to us.
  31722. giveAwayFocus();
  31723. grabKeyboardFocus();
  31724. }
  31725. }
  31726. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31727. catch (const std::exception& e)
  31728. {
  31729. currentlyFocusedComponent = 0;
  31730. Desktop::getInstance().triggerFocusCallback();
  31731. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31732. }
  31733. catch (...)
  31734. {
  31735. currentlyFocusedComponent = 0;
  31736. Desktop::getInstance().triggerFocusCallback();
  31737. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31738. }
  31739. #endif
  31740. child->internalHierarchyChanged();
  31741. internalChildrenChanged();
  31742. }
  31743. return child;
  31744. }
  31745. void Component::removeAllChildren()
  31746. {
  31747. for (int i = childComponentList_.size(); --i >= 0;)
  31748. removeChildComponent (i);
  31749. }
  31750. void Component::deleteAllChildren()
  31751. {
  31752. for (int i = childComponentList_.size(); --i >= 0;)
  31753. delete (removeChildComponent (i));
  31754. }
  31755. int Component::getNumChildComponents() const throw()
  31756. {
  31757. return childComponentList_.size();
  31758. }
  31759. Component* Component::getChildComponent (const int index) const throw()
  31760. {
  31761. return childComponentList_ [index];
  31762. }
  31763. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  31764. {
  31765. return childComponentList_.indexOf (const_cast <Component*> (child));
  31766. }
  31767. Component* Component::getTopLevelComponent() const throw()
  31768. {
  31769. const Component* comp = this;
  31770. while (comp->parentComponent_ != 0)
  31771. comp = comp->parentComponent_;
  31772. return const_cast <Component*> (comp);
  31773. }
  31774. bool Component::isParentOf (const Component* possibleChild) const throw()
  31775. {
  31776. if (! possibleChild->isValidComponent())
  31777. {
  31778. jassert (possibleChild == 0);
  31779. return false;
  31780. }
  31781. while (possibleChild != 0)
  31782. {
  31783. possibleChild = possibleChild->parentComponent_;
  31784. if (possibleChild == this)
  31785. return true;
  31786. }
  31787. return false;
  31788. }
  31789. void Component::parentHierarchyChanged()
  31790. {
  31791. }
  31792. void Component::childrenChanged()
  31793. {
  31794. }
  31795. void Component::internalChildrenChanged()
  31796. {
  31797. if (componentListeners.isEmpty())
  31798. {
  31799. childrenChanged();
  31800. }
  31801. else
  31802. {
  31803. BailOutChecker checker (this);
  31804. childrenChanged();
  31805. if (! checker.shouldBailOut())
  31806. componentListeners.callChecked (checker, &ComponentListener::componentChildrenChanged, *this);
  31807. }
  31808. }
  31809. void Component::internalHierarchyChanged()
  31810. {
  31811. BailOutChecker checker (this);
  31812. parentHierarchyChanged();
  31813. if (checker.shouldBailOut())
  31814. return;
  31815. componentListeners.callChecked (checker, &ComponentListener::componentParentHierarchyChanged, *this);
  31816. if (checker.shouldBailOut())
  31817. return;
  31818. for (int i = childComponentList_.size(); --i >= 0;)
  31819. {
  31820. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  31821. if (checker.shouldBailOut())
  31822. {
  31823. // you really shouldn't delete the parent component during a callback telling you
  31824. // that it's changed..
  31825. jassertfalse;
  31826. return;
  31827. }
  31828. i = jmin (i, childComponentList_.size());
  31829. }
  31830. }
  31831. void* Component::runModalLoopCallback (void* userData)
  31832. {
  31833. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  31834. }
  31835. int Component::runModalLoop()
  31836. {
  31837. if (! MessageManager::getInstance()->isThisTheMessageThread())
  31838. {
  31839. // use a callback so this can be called from non-gui threads
  31840. return (int) (pointer_sized_int)
  31841. MessageManager::getInstance()
  31842. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  31843. }
  31844. SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  31845. if (! isCurrentlyModal())
  31846. enterModalState();
  31847. JUCE_TRY
  31848. {
  31849. while (flags.currentlyModalFlag && flags.visibleFlag)
  31850. {
  31851. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  31852. break;
  31853. // check whether this component was deleted during the last message
  31854. if (! isValidMessageListener())
  31855. break;
  31856. }
  31857. }
  31858. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31859. catch (const std::exception& e)
  31860. {
  31861. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31862. return 0;
  31863. }
  31864. catch (...)
  31865. {
  31866. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31867. return 0;
  31868. }
  31869. #endif
  31870. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31871. int returnValue = 0;
  31872. if (modalIndex >= 0)
  31873. {
  31874. modalComponentReturnValueKeys.remove (modalIndex);
  31875. returnValue = modalReturnValues.remove (modalIndex);
  31876. }
  31877. modalComponentStack.removeValue (this);
  31878. if (prevFocused != 0)
  31879. prevFocused->grabKeyboardFocus();
  31880. return returnValue;
  31881. }
  31882. void Component::enterModalState (const bool takeKeyboardFocus_)
  31883. {
  31884. // if component methods are being called from threads other than the message
  31885. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31886. checkMessageManagerIsLocked
  31887. // Check for an attempt to make a component modal when it already is!
  31888. // This can cause nasty problems..
  31889. jassert (! flags.currentlyModalFlag);
  31890. if (! isCurrentlyModal())
  31891. {
  31892. modalComponentStack.add (this);
  31893. modalComponentReturnValueKeys.add (this);
  31894. modalReturnValues.add (0);
  31895. flags.currentlyModalFlag = true;
  31896. setVisible (true);
  31897. if (takeKeyboardFocus_)
  31898. grabKeyboardFocus();
  31899. }
  31900. }
  31901. void Component::exitModalState (const int returnValue)
  31902. {
  31903. if (isCurrentlyModal())
  31904. {
  31905. if (MessageManager::getInstance()->isThisTheMessageThread())
  31906. {
  31907. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31908. if (modalIndex >= 0)
  31909. {
  31910. modalReturnValues.set (modalIndex, returnValue);
  31911. }
  31912. else
  31913. {
  31914. modalComponentReturnValueKeys.add (this);
  31915. modalReturnValues.add (returnValue);
  31916. }
  31917. modalComponentStack.removeValue (this);
  31918. flags.currentlyModalFlag = false;
  31919. bringModalComponentToFront();
  31920. }
  31921. else
  31922. {
  31923. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  31924. }
  31925. }
  31926. }
  31927. bool Component::isCurrentlyModal() const throw()
  31928. {
  31929. return flags.currentlyModalFlag
  31930. && getCurrentlyModalComponent() == this;
  31931. }
  31932. bool Component::isCurrentlyBlockedByAnotherModalComponent() const
  31933. {
  31934. Component* const mc = getCurrentlyModalComponent();
  31935. return mc != 0
  31936. && mc != this
  31937. && (! mc->isParentOf (this))
  31938. && ! mc->canModalEventBeSentToComponent (this);
  31939. }
  31940. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  31941. {
  31942. return modalComponentStack.size();
  31943. }
  31944. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  31945. {
  31946. Component* const c = static_cast <Component*> (modalComponentStack [modalComponentStack.size() - index - 1]);
  31947. return c->isValidComponent() ? c : 0;
  31948. }
  31949. void Component::bringModalComponentToFront()
  31950. {
  31951. ComponentPeer* lastOne = 0;
  31952. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  31953. {
  31954. Component* const c = getCurrentlyModalComponent (i);
  31955. if (c == 0)
  31956. break;
  31957. ComponentPeer* peer = c->getPeer();
  31958. if (peer != 0 && peer != lastOne)
  31959. {
  31960. if (lastOne == 0)
  31961. {
  31962. peer->toFront (true);
  31963. peer->grabFocus();
  31964. }
  31965. else
  31966. peer->toBehind (lastOne);
  31967. lastOne = peer;
  31968. }
  31969. }
  31970. }
  31971. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  31972. {
  31973. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  31974. }
  31975. bool Component::isBroughtToFrontOnMouseClick() const throw()
  31976. {
  31977. return flags.bringToFrontOnClickFlag;
  31978. }
  31979. void Component::setMouseCursor (const MouseCursor& cursor)
  31980. {
  31981. if (cursor_ != cursor)
  31982. {
  31983. cursor_ = cursor;
  31984. if (flags.visibleFlag)
  31985. updateMouseCursor();
  31986. }
  31987. }
  31988. const MouseCursor Component::getMouseCursor()
  31989. {
  31990. return cursor_;
  31991. }
  31992. void Component::updateMouseCursor() const
  31993. {
  31994. sendFakeMouseMove();
  31995. }
  31996. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  31997. {
  31998. flags.repaintOnMouseActivityFlag = shouldRepaint;
  31999. }
  32000. void Component::repaintParent()
  32001. {
  32002. if (flags.visibleFlag)
  32003. internalRepaint (0, 0, getWidth(), getHeight());
  32004. }
  32005. void Component::repaint()
  32006. {
  32007. repaint (0, 0, getWidth(), getHeight());
  32008. }
  32009. void Component::repaint (const int x, const int y,
  32010. const int w, const int h)
  32011. {
  32012. deleteAndZero (bufferedImage_);
  32013. if (flags.visibleFlag)
  32014. internalRepaint (x, y, w, h);
  32015. }
  32016. void Component::internalRepaint (int x, int y, int w, int h)
  32017. {
  32018. // if component methods are being called from threads other than the message
  32019. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32020. checkMessageManagerIsLocked
  32021. if (x < 0)
  32022. {
  32023. w += x;
  32024. x = 0;
  32025. }
  32026. if (x + w > getWidth())
  32027. w = getWidth() - x;
  32028. if (w > 0)
  32029. {
  32030. if (y < 0)
  32031. {
  32032. h += y;
  32033. y = 0;
  32034. }
  32035. if (y + h > getHeight())
  32036. h = getHeight() - y;
  32037. if (h > 0)
  32038. {
  32039. if (parentComponent_ != 0)
  32040. {
  32041. x += getX();
  32042. y += getY();
  32043. if (parentComponent_->flags.visibleFlag)
  32044. parentComponent_->internalRepaint (x, y, w, h);
  32045. }
  32046. else if (flags.hasHeavyweightPeerFlag)
  32047. {
  32048. ComponentPeer* const peer = getPeer();
  32049. if (peer != 0)
  32050. peer->repaint (x, y, w, h);
  32051. }
  32052. }
  32053. }
  32054. }
  32055. void Component::renderComponent (Graphics& g)
  32056. {
  32057. const Rectangle<int> clipBounds (g.getClipBounds());
  32058. g.saveState();
  32059. clipObscuredRegions (g, clipBounds, 0, 0);
  32060. if (! g.isClipEmpty())
  32061. {
  32062. if (flags.bufferToImageFlag)
  32063. {
  32064. if (bufferedImage_ == 0)
  32065. {
  32066. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32067. getWidth(), getHeight(), ! flags.opaqueFlag);
  32068. Graphics imG (*bufferedImage_);
  32069. paint (imG);
  32070. }
  32071. g.setColour (Colours::black);
  32072. g.drawImageAt (bufferedImage_, 0, 0);
  32073. }
  32074. else
  32075. {
  32076. paint (g);
  32077. }
  32078. }
  32079. g.restoreState();
  32080. for (int i = 0; i < childComponentList_.size(); ++i)
  32081. {
  32082. Component* const child = childComponentList_.getUnchecked (i);
  32083. if (child->isVisible() && clipBounds.intersects (child->getBounds()))
  32084. {
  32085. g.saveState();
  32086. if (g.reduceClipRegion (child->getX(), child->getY(),
  32087. child->getWidth(), child->getHeight()))
  32088. {
  32089. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32090. {
  32091. const Component* const sibling = childComponentList_.getUnchecked (j);
  32092. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32093. g.excludeClipRegion (sibling->getBounds());
  32094. }
  32095. if (! g.isClipEmpty())
  32096. {
  32097. g.setOrigin (child->getX(), child->getY());
  32098. child->paintEntireComponent (g);
  32099. }
  32100. }
  32101. g.restoreState();
  32102. }
  32103. }
  32104. g.saveState();
  32105. paintOverChildren (g);
  32106. g.restoreState();
  32107. }
  32108. void Component::paintEntireComponent (Graphics& g)
  32109. {
  32110. jassert (! g.isClipEmpty());
  32111. #ifdef JUCE_DEBUG
  32112. flags.isInsidePaintCall = true;
  32113. #endif
  32114. if (effect_ != 0)
  32115. {
  32116. ScopedPointer<Image> effectImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32117. getWidth(), getHeight(),
  32118. ! flags.opaqueFlag));
  32119. {
  32120. Graphics g2 (*effectImage);
  32121. renderComponent (g2);
  32122. }
  32123. effect_->applyEffect (*effectImage, g);
  32124. }
  32125. else
  32126. {
  32127. renderComponent (g);
  32128. }
  32129. #ifdef JUCE_DEBUG
  32130. flags.isInsidePaintCall = false;
  32131. #endif
  32132. }
  32133. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32134. const bool clipImageToComponentBounds)
  32135. {
  32136. Rectangle<int> r (areaToGrab);
  32137. if (clipImageToComponentBounds)
  32138. r = r.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  32139. ScopedPointer<Image> componentImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32140. jmax (1, r.getWidth()),
  32141. jmax (1, r.getHeight()),
  32142. true));
  32143. Graphics imageContext (*componentImage);
  32144. imageContext.setOrigin (-r.getX(), -r.getY());
  32145. paintEntireComponent (imageContext);
  32146. return componentImage.release();
  32147. }
  32148. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32149. {
  32150. if (effect_ != effect)
  32151. {
  32152. effect_ = effect;
  32153. repaint();
  32154. }
  32155. }
  32156. LookAndFeel& Component::getLookAndFeel() const throw()
  32157. {
  32158. const Component* c = this;
  32159. do
  32160. {
  32161. if (c->lookAndFeel_ != 0)
  32162. return *(c->lookAndFeel_);
  32163. c = c->parentComponent_;
  32164. }
  32165. while (c != 0);
  32166. return LookAndFeel::getDefaultLookAndFeel();
  32167. }
  32168. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32169. {
  32170. if (lookAndFeel_ != newLookAndFeel)
  32171. {
  32172. lookAndFeel_ = newLookAndFeel;
  32173. sendLookAndFeelChange();
  32174. }
  32175. }
  32176. void Component::lookAndFeelChanged()
  32177. {
  32178. }
  32179. void Component::sendLookAndFeelChange()
  32180. {
  32181. repaint();
  32182. lookAndFeelChanged();
  32183. // (it's not a great idea to do anything that would delete this component
  32184. // during the lookAndFeelChanged() callback)
  32185. jassert (isValidComponent());
  32186. SafePointer<Component> safePointer (this);
  32187. for (int i = childComponentList_.size(); --i >= 0;)
  32188. {
  32189. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32190. if (safePointer == 0)
  32191. return;
  32192. i = jmin (i, childComponentList_.size());
  32193. }
  32194. }
  32195. static const var::identifier getColourPropertyId (const int colourId)
  32196. {
  32197. String s;
  32198. s.preallocateStorage (18);
  32199. s << T("jcclr_") << String::toHexString (colourId);
  32200. return s;
  32201. }
  32202. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const
  32203. {
  32204. var* v = properties.getItem (getColourPropertyId (colourId));
  32205. if (v != 0)
  32206. return Colour ((int) *v);
  32207. if (inheritFromParent && parentComponent_ != 0)
  32208. return parentComponent_->findColour (colourId, true);
  32209. return getLookAndFeel().findColour (colourId);
  32210. }
  32211. bool Component::isColourSpecified (const int colourId) const
  32212. {
  32213. return properties.contains (getColourPropertyId (colourId));
  32214. }
  32215. void Component::removeColour (const int colourId)
  32216. {
  32217. if (properties.remove (getColourPropertyId (colourId)))
  32218. colourChanged();
  32219. }
  32220. void Component::setColour (const int colourId, const Colour& colour)
  32221. {
  32222. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32223. colourChanged();
  32224. }
  32225. void Component::copyAllExplicitColoursTo (Component& target) const
  32226. {
  32227. bool changed = false;
  32228. for (int i = properties.size(); --i >= 0;)
  32229. {
  32230. const var::identifier name (properties.getName(i));
  32231. if (name.name.startsWith (T("jcclr_")))
  32232. if (target.properties.set (name, properties [name]))
  32233. changed = true;
  32234. }
  32235. if (changed)
  32236. target.colourChanged();
  32237. }
  32238. void Component::colourChanged()
  32239. {
  32240. }
  32241. const Rectangle<int> Component::getUnclippedArea() const
  32242. {
  32243. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32244. Component* p = parentComponent_;
  32245. int px = getX();
  32246. int py = getY();
  32247. while (p != 0)
  32248. {
  32249. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32250. return Rectangle<int>();
  32251. px += p->getX();
  32252. py += p->getY();
  32253. p = p->parentComponent_;
  32254. }
  32255. return Rectangle<int> (x, y, w, h);
  32256. }
  32257. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32258. const int deltaX, const int deltaY) const
  32259. {
  32260. for (int i = childComponentList_.size(); --i >= 0;)
  32261. {
  32262. const Component* const c = childComponentList_.getUnchecked(i);
  32263. if (c->isVisible())
  32264. {
  32265. const Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32266. if (! newClip.isEmpty())
  32267. {
  32268. if (c->isOpaque())
  32269. {
  32270. g.excludeClipRegion (newClip.translated (deltaX, deltaY));
  32271. }
  32272. else
  32273. {
  32274. c->clipObscuredRegions (g, newClip.translated (-c->getX(), -c->getY()),
  32275. c->getX() + deltaX,
  32276. c->getY() + deltaY);
  32277. }
  32278. }
  32279. }
  32280. }
  32281. }
  32282. void Component::getVisibleArea (RectangleList& result,
  32283. const bool includeSiblings) const
  32284. {
  32285. result.clear();
  32286. const Rectangle<int> unclipped (getUnclippedArea());
  32287. if (! unclipped.isEmpty())
  32288. {
  32289. result.add (unclipped);
  32290. if (includeSiblings)
  32291. {
  32292. const Component* const c = getTopLevelComponent();
  32293. c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point<int>()),
  32294. Rectangle<int> (0, 0, c->getWidth(), c->getHeight()),
  32295. this);
  32296. }
  32297. subtractObscuredRegions (result, Point<int>(), unclipped, 0);
  32298. result.consolidate();
  32299. }
  32300. }
  32301. void Component::subtractObscuredRegions (RectangleList& result,
  32302. const Point<int>& delta,
  32303. const Rectangle<int>& clipRect,
  32304. const Component* const compToAvoid) const
  32305. {
  32306. for (int i = childComponentList_.size(); --i >= 0;)
  32307. {
  32308. const Component* const c = childComponentList_.getUnchecked(i);
  32309. if (c != compToAvoid && c->isVisible())
  32310. {
  32311. if (c->isOpaque())
  32312. {
  32313. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32314. childBounds.translate (delta.getX(), delta.getY());
  32315. result.subtract (childBounds);
  32316. }
  32317. else
  32318. {
  32319. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32320. newClip.translate (-c->getX(), -c->getY());
  32321. c->subtractObscuredRegions (result, c->getPosition() + delta,
  32322. newClip, compToAvoid);
  32323. }
  32324. }
  32325. }
  32326. }
  32327. void Component::mouseEnter (const MouseEvent&)
  32328. {
  32329. // base class does nothing
  32330. }
  32331. void Component::mouseExit (const MouseEvent&)
  32332. {
  32333. // base class does nothing
  32334. }
  32335. void Component::mouseDown (const MouseEvent&)
  32336. {
  32337. // base class does nothing
  32338. }
  32339. void Component::mouseUp (const MouseEvent&)
  32340. {
  32341. // base class does nothing
  32342. }
  32343. void Component::mouseDrag (const MouseEvent&)
  32344. {
  32345. // base class does nothing
  32346. }
  32347. void Component::mouseMove (const MouseEvent&)
  32348. {
  32349. // base class does nothing
  32350. }
  32351. void Component::mouseDoubleClick (const MouseEvent&)
  32352. {
  32353. // base class does nothing
  32354. }
  32355. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32356. {
  32357. // the base class just passes this event up to its parent..
  32358. if (parentComponent_ != 0)
  32359. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32360. wheelIncrementX, wheelIncrementY);
  32361. }
  32362. void Component::resized()
  32363. {
  32364. // base class does nothing
  32365. }
  32366. void Component::moved()
  32367. {
  32368. // base class does nothing
  32369. }
  32370. void Component::childBoundsChanged (Component*)
  32371. {
  32372. // base class does nothing
  32373. }
  32374. void Component::parentSizeChanged()
  32375. {
  32376. // base class does nothing
  32377. }
  32378. void Component::addComponentListener (ComponentListener* const newListener)
  32379. {
  32380. componentListeners.add (newListener);
  32381. }
  32382. void Component::removeComponentListener (ComponentListener* const listenerToRemove)
  32383. {
  32384. jassert (isValidComponent());
  32385. componentListeners.remove (listenerToRemove);
  32386. }
  32387. void Component::inputAttemptWhenModal()
  32388. {
  32389. bringModalComponentToFront();
  32390. getLookAndFeel().playAlertSound();
  32391. }
  32392. bool Component::canModalEventBeSentToComponent (const Component*)
  32393. {
  32394. return false;
  32395. }
  32396. void Component::internalModalInputAttempt()
  32397. {
  32398. Component* const current = getCurrentlyModalComponent();
  32399. if (current != 0)
  32400. current->inputAttemptWhenModal();
  32401. }
  32402. void Component::paint (Graphics&)
  32403. {
  32404. // all painting is done in the subclasses
  32405. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32406. }
  32407. void Component::paintOverChildren (Graphics&)
  32408. {
  32409. // all painting is done in the subclasses
  32410. }
  32411. void Component::handleMessage (const Message& message)
  32412. {
  32413. if (message.intParameter1 == exitModalStateMessage)
  32414. {
  32415. exitModalState (message.intParameter2);
  32416. }
  32417. else if (message.intParameter1 == customCommandMessage)
  32418. {
  32419. handleCommandMessage (message.intParameter2);
  32420. }
  32421. }
  32422. void Component::postCommandMessage (const int commandId)
  32423. {
  32424. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32425. }
  32426. void Component::handleCommandMessage (int)
  32427. {
  32428. // used by subclasses
  32429. }
  32430. void Component::addMouseListener (MouseListener* const newListener,
  32431. const bool wantsEventsForAllNestedChildComponents)
  32432. {
  32433. // if component methods are being called from threads other than the message
  32434. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32435. checkMessageManagerIsLocked
  32436. if (mouseListeners_ == 0)
  32437. mouseListeners_ = new VoidArray();
  32438. if (! mouseListeners_->contains (newListener))
  32439. {
  32440. if (wantsEventsForAllNestedChildComponents)
  32441. {
  32442. mouseListeners_->insert (0, newListener);
  32443. ++numDeepMouseListeners;
  32444. }
  32445. else
  32446. {
  32447. mouseListeners_->add (newListener);
  32448. }
  32449. }
  32450. }
  32451. void Component::removeMouseListener (MouseListener* const listenerToRemove)
  32452. {
  32453. // if component methods are being called from threads other than the message
  32454. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32455. checkMessageManagerIsLocked
  32456. if (mouseListeners_ != 0)
  32457. {
  32458. const int index = mouseListeners_->indexOf (listenerToRemove);
  32459. if (index >= 0)
  32460. {
  32461. if (index < numDeepMouseListeners)
  32462. --numDeepMouseListeners;
  32463. mouseListeners_->remove (index);
  32464. }
  32465. }
  32466. }
  32467. void Component::internalMouseEnter (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32468. {
  32469. if (isCurrentlyBlockedByAnotherModalComponent())
  32470. {
  32471. // if something else is modal, always just show a normal mouse cursor
  32472. source.showMouseCursor (MouseCursor::NormalCursor);
  32473. return;
  32474. }
  32475. if (! flags.mouseInsideFlag)
  32476. {
  32477. flags.mouseInsideFlag = true;
  32478. flags.mouseOverFlag = true;
  32479. flags.draggingFlag = false;
  32480. BailOutChecker checker (this);
  32481. if (flags.repaintOnMouseActivityFlag)
  32482. repaint();
  32483. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32484. this, time, relativePos,
  32485. time, 0, false);
  32486. mouseEnter (me);
  32487. if (checker.shouldBailOut())
  32488. return;
  32489. Desktop::getInstance().resetTimer();
  32490. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseEnter, me);
  32491. if (checker.shouldBailOut())
  32492. return;
  32493. if (mouseListeners_ != 0)
  32494. {
  32495. for (int i = mouseListeners_->size(); --i >= 0;)
  32496. {
  32497. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32498. if (checker.shouldBailOut())
  32499. return;
  32500. i = jmin (i, mouseListeners_->size());
  32501. }
  32502. }
  32503. Component* p = parentComponent_;
  32504. while (p != 0)
  32505. {
  32506. if (p->numDeepMouseListeners > 0)
  32507. {
  32508. BailOutChecker checker (this, p);
  32509. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32510. {
  32511. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32512. if (checker.shouldBailOut())
  32513. return;
  32514. i = jmin (i, p->numDeepMouseListeners);
  32515. }
  32516. }
  32517. p = p->parentComponent_;
  32518. }
  32519. }
  32520. }
  32521. void Component::internalMouseExit (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32522. {
  32523. BailOutChecker checker (this);
  32524. if (flags.draggingFlag)
  32525. {
  32526. internalMouseUp (source, relativePos, time, source.getCurrentModifiers().getRawFlags());
  32527. if (checker.shouldBailOut())
  32528. return;
  32529. }
  32530. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32531. {
  32532. flags.mouseInsideFlag = false;
  32533. flags.mouseOverFlag = false;
  32534. flags.draggingFlag = false;
  32535. if (flags.repaintOnMouseActivityFlag)
  32536. repaint();
  32537. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32538. this, time, relativePos,
  32539. time, 0, false);
  32540. mouseExit (me);
  32541. if (checker.shouldBailOut())
  32542. return;
  32543. Desktop::getInstance().resetTimer();
  32544. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseExit, me);
  32545. if (checker.shouldBailOut())
  32546. return;
  32547. if (mouseListeners_ != 0)
  32548. {
  32549. for (int i = mouseListeners_->size(); --i >= 0;)
  32550. {
  32551. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32552. if (checker.shouldBailOut())
  32553. return;
  32554. i = jmin (i, mouseListeners_->size());
  32555. }
  32556. }
  32557. Component* p = parentComponent_;
  32558. while (p != 0)
  32559. {
  32560. if (p->numDeepMouseListeners > 0)
  32561. {
  32562. BailOutChecker checker (this, p);
  32563. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32564. {
  32565. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32566. if (checker.shouldBailOut())
  32567. return;
  32568. i = jmin (i, p->numDeepMouseListeners);
  32569. }
  32570. }
  32571. p = p->parentComponent_;
  32572. }
  32573. }
  32574. }
  32575. class InternalDragRepeater : public Timer
  32576. {
  32577. public:
  32578. InternalDragRepeater()
  32579. {}
  32580. ~InternalDragRepeater()
  32581. {
  32582. clearSingletonInstance();
  32583. }
  32584. juce_DeclareSingleton_SingleThreaded_Minimal (InternalDragRepeater)
  32585. void timerCallback()
  32586. {
  32587. Desktop& desktop = Desktop::getInstance();
  32588. int numMiceDown = 0;
  32589. for (int i = desktop.getNumMouseSources(); --i >= 0;)
  32590. {
  32591. MouseInputSource* const source = desktop.getMouseSource(i);
  32592. if (source->isDragging())
  32593. {
  32594. source->triggerFakeMove();
  32595. ++numMiceDown;
  32596. }
  32597. }
  32598. if (numMiceDown == 0)
  32599. deleteInstance();
  32600. }
  32601. juce_UseDebuggingNewOperator
  32602. private:
  32603. InternalDragRepeater (const InternalDragRepeater&);
  32604. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32605. };
  32606. juce_ImplementSingleton_SingleThreaded (InternalDragRepeater)
  32607. void Component::beginDragAutoRepeat (const int interval)
  32608. {
  32609. if (interval > 0)
  32610. {
  32611. if (InternalDragRepeater::getInstance()->getTimerInterval() != interval)
  32612. InternalDragRepeater::getInstance()->startTimer (interval);
  32613. }
  32614. else
  32615. {
  32616. InternalDragRepeater::deleteInstance();
  32617. }
  32618. }
  32619. void Component::internalMouseDown (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32620. {
  32621. Desktop& desktop = Desktop::getInstance();
  32622. BailOutChecker checker (this);
  32623. if (isCurrentlyBlockedByAnotherModalComponent())
  32624. {
  32625. internalModalInputAttempt();
  32626. if (checker.shouldBailOut())
  32627. return;
  32628. // If processing the input attempt has exited the modal loop, we'll allow the event
  32629. // to be delivered..
  32630. if (isCurrentlyBlockedByAnotherModalComponent())
  32631. {
  32632. // allow blocked mouse-events to go to global listeners..
  32633. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32634. this, time, relativePos, time,
  32635. source.getNumberOfMultipleClicks(), false);
  32636. desktop.resetTimer();
  32637. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32638. return;
  32639. }
  32640. }
  32641. {
  32642. Component* c = this;
  32643. while (c != 0)
  32644. {
  32645. if (c->isBroughtToFrontOnMouseClick())
  32646. {
  32647. c->toFront (true);
  32648. if (checker.shouldBailOut())
  32649. return;
  32650. }
  32651. c = c->parentComponent_;
  32652. }
  32653. }
  32654. if (! flags.dontFocusOnMouseClickFlag)
  32655. {
  32656. grabFocusInternal (focusChangedByMouseClick);
  32657. if (checker.shouldBailOut())
  32658. return;
  32659. }
  32660. flags.draggingFlag = true;
  32661. flags.mouseOverFlag = true;
  32662. if (flags.repaintOnMouseActivityFlag)
  32663. repaint();
  32664. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32665. this, time, relativePos, time,
  32666. source.getNumberOfMultipleClicks(), false);
  32667. mouseDown (me);
  32668. if (checker.shouldBailOut())
  32669. return;
  32670. desktop.resetTimer();
  32671. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32672. if (checker.shouldBailOut())
  32673. return;
  32674. if (mouseListeners_ != 0)
  32675. {
  32676. for (int i = mouseListeners_->size(); --i >= 0;)
  32677. {
  32678. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  32679. if (checker.shouldBailOut())
  32680. return;
  32681. i = jmin (i, mouseListeners_->size());
  32682. }
  32683. }
  32684. Component* p = parentComponent_;
  32685. while (p != 0)
  32686. {
  32687. if (p->numDeepMouseListeners > 0)
  32688. {
  32689. BailOutChecker checker (this, p);
  32690. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32691. {
  32692. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  32693. if (checker.shouldBailOut())
  32694. return;
  32695. i = jmin (i, p->numDeepMouseListeners);
  32696. }
  32697. }
  32698. p = p->parentComponent_;
  32699. }
  32700. }
  32701. void Component::internalMouseUp (MouseInputSource& source, const Point<int>& relativePos, const Time& time, const ModifierKeys& oldModifiers)
  32702. {
  32703. if (flags.draggingFlag)
  32704. {
  32705. Desktop& desktop = Desktop::getInstance();
  32706. flags.draggingFlag = false;
  32707. BailOutChecker checker (this);
  32708. if (flags.repaintOnMouseActivityFlag)
  32709. repaint();
  32710. const MouseEvent me (source, relativePos,
  32711. oldModifiers, this, time,
  32712. globalPositionToRelative (source.getLastMouseDownPosition()),
  32713. source.getLastMouseDownTime(),
  32714. source.getNumberOfMultipleClicks(),
  32715. source.hasMouseMovedSignificantlySincePressed());
  32716. mouseUp (me);
  32717. if (checker.shouldBailOut())
  32718. return;
  32719. desktop.resetTimer();
  32720. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseUp, me);
  32721. if (checker.shouldBailOut())
  32722. return;
  32723. if (mouseListeners_ != 0)
  32724. {
  32725. for (int i = mouseListeners_->size(); --i >= 0;)
  32726. {
  32727. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  32728. if (checker.shouldBailOut())
  32729. return;
  32730. i = jmin (i, mouseListeners_->size());
  32731. }
  32732. }
  32733. {
  32734. Component* p = parentComponent_;
  32735. while (p != 0)
  32736. {
  32737. if (p->numDeepMouseListeners > 0)
  32738. {
  32739. BailOutChecker checker (this, p);
  32740. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32741. {
  32742. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  32743. if (checker.shouldBailOut())
  32744. return;
  32745. i = jmin (i, p->numDeepMouseListeners);
  32746. }
  32747. }
  32748. p = p->parentComponent_;
  32749. }
  32750. }
  32751. // check for double-click
  32752. if (me.getNumberOfClicks() >= 2)
  32753. {
  32754. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  32755. mouseDoubleClick (me);
  32756. if (checker.shouldBailOut())
  32757. return;
  32758. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDoubleClick, me);
  32759. if (checker.shouldBailOut())
  32760. return;
  32761. for (int i = numListeners; --i >= 0;)
  32762. {
  32763. if (checker.shouldBailOut())
  32764. return;
  32765. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  32766. if (ml != 0)
  32767. ml->mouseDoubleClick (me);
  32768. }
  32769. if (checker.shouldBailOut())
  32770. return;
  32771. Component* p = parentComponent_;
  32772. while (p != 0)
  32773. {
  32774. if (p->numDeepMouseListeners > 0)
  32775. {
  32776. BailOutChecker checker (this, p);
  32777. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32778. {
  32779. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  32780. if (checker.shouldBailOut())
  32781. return;
  32782. i = jmin (i, p->numDeepMouseListeners);
  32783. }
  32784. }
  32785. p = p->parentComponent_;
  32786. }
  32787. }
  32788. }
  32789. }
  32790. void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32791. {
  32792. if (flags.draggingFlag)
  32793. {
  32794. Desktop& desktop = Desktop::getInstance();
  32795. flags.mouseOverFlag = reallyContains (relativePos.getX(), relativePos.getY(), false);
  32796. BailOutChecker checker (this);
  32797. const MouseEvent me (source, relativePos,
  32798. source.getCurrentModifiers(), this, time,
  32799. globalPositionToRelative (source.getLastMouseDownPosition()),
  32800. source.getLastMouseDownTime(),
  32801. source.getNumberOfMultipleClicks(),
  32802. source.hasMouseMovedSignificantlySincePressed());
  32803. mouseDrag (me);
  32804. if (checker.shouldBailOut())
  32805. return;
  32806. desktop.resetTimer();
  32807. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  32808. if (checker.shouldBailOut())
  32809. return;
  32810. if (mouseListeners_ != 0)
  32811. {
  32812. for (int i = mouseListeners_->size(); --i >= 0;)
  32813. {
  32814. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  32815. if (checker.shouldBailOut())
  32816. return;
  32817. i = jmin (i, mouseListeners_->size());
  32818. }
  32819. }
  32820. Component* p = parentComponent_;
  32821. while (p != 0)
  32822. {
  32823. if (p->numDeepMouseListeners > 0)
  32824. {
  32825. BailOutChecker checker (this, p);
  32826. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32827. {
  32828. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  32829. if (checker.shouldBailOut())
  32830. return;
  32831. i = jmin (i, p->numDeepMouseListeners);
  32832. }
  32833. }
  32834. p = p->parentComponent_;
  32835. }
  32836. }
  32837. }
  32838. void Component::internalMouseMove (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32839. {
  32840. Desktop& desktop = Desktop::getInstance();
  32841. BailOutChecker checker (this);
  32842. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32843. this, time, relativePos,
  32844. time, 0, false);
  32845. if (isCurrentlyBlockedByAnotherModalComponent())
  32846. {
  32847. // allow blocked mouse-events to go to global listeners..
  32848. desktop.sendMouseMove();
  32849. }
  32850. else
  32851. {
  32852. flags.mouseOverFlag = true;
  32853. mouseMove (me);
  32854. if (checker.shouldBailOut())
  32855. return;
  32856. desktop.resetTimer();
  32857. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  32858. if (checker.shouldBailOut())
  32859. return;
  32860. if (mouseListeners_ != 0)
  32861. {
  32862. for (int i = mouseListeners_->size(); --i >= 0;)
  32863. {
  32864. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  32865. if (checker.shouldBailOut())
  32866. return;
  32867. i = jmin (i, mouseListeners_->size());
  32868. }
  32869. }
  32870. Component* p = parentComponent_;
  32871. while (p != 0)
  32872. {
  32873. if (p->numDeepMouseListeners > 0)
  32874. {
  32875. BailOutChecker checker (this, p);
  32876. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32877. {
  32878. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  32879. if (checker.shouldBailOut())
  32880. return;
  32881. i = jmin (i, p->numDeepMouseListeners);
  32882. }
  32883. }
  32884. p = p->parentComponent_;
  32885. }
  32886. }
  32887. }
  32888. void Component::internalMouseWheel (MouseInputSource& source, const Point<int>& relativePos,
  32889. const Time& time, const float amountX, const float amountY)
  32890. {
  32891. Desktop& desktop = Desktop::getInstance();
  32892. BailOutChecker checker (this);
  32893. const float wheelIncrementX = amountX * (1.0f / 256.0f);
  32894. const float wheelIncrementY = amountY * (1.0f / 256.0f);
  32895. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32896. this, time, relativePos, time, 0, false);
  32897. if (isCurrentlyBlockedByAnotherModalComponent())
  32898. {
  32899. // allow blocked mouse-events to go to global listeners..
  32900. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32901. }
  32902. else
  32903. {
  32904. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32905. if (checker.shouldBailOut())
  32906. return;
  32907. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32908. if (checker.shouldBailOut())
  32909. return;
  32910. if (mouseListeners_ != 0)
  32911. {
  32912. for (int i = mouseListeners_->size(); --i >= 0;)
  32913. {
  32914. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32915. if (checker.shouldBailOut())
  32916. return;
  32917. i = jmin (i, mouseListeners_->size());
  32918. }
  32919. }
  32920. Component* p = parentComponent_;
  32921. while (p != 0)
  32922. {
  32923. if (p->numDeepMouseListeners > 0)
  32924. {
  32925. BailOutChecker checker (this, p);
  32926. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32927. {
  32928. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32929. if (checker.shouldBailOut())
  32930. return;
  32931. i = jmin (i, p->numDeepMouseListeners);
  32932. }
  32933. }
  32934. p = p->parentComponent_;
  32935. }
  32936. }
  32937. }
  32938. void Component::sendFakeMouseMove() const
  32939. {
  32940. Desktop::getInstance().getMainMouseSource().triggerFakeMove();
  32941. }
  32942. void Component::broughtToFront()
  32943. {
  32944. }
  32945. void Component::internalBroughtToFront()
  32946. {
  32947. if (! isValidComponent())
  32948. return;
  32949. if (flags.hasHeavyweightPeerFlag)
  32950. Desktop::getInstance().componentBroughtToFront (this);
  32951. BailOutChecker checker (this);
  32952. broughtToFront();
  32953. if (checker.shouldBailOut())
  32954. return;
  32955. componentListeners.callChecked (checker, &ComponentListener::componentBroughtToFront, *this);
  32956. if (checker.shouldBailOut())
  32957. return;
  32958. // When brought to the front and there's a modal component blocking this one,
  32959. // we need to bring the modal one to the front instead..
  32960. Component* const cm = getCurrentlyModalComponent();
  32961. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  32962. bringModalComponentToFront();
  32963. }
  32964. void Component::focusGained (FocusChangeType)
  32965. {
  32966. // base class does nothing
  32967. }
  32968. void Component::internalFocusGain (const FocusChangeType cause)
  32969. {
  32970. SafePointer<Component> safePointer (this);
  32971. focusGained (cause);
  32972. if (safePointer != 0)
  32973. internalChildFocusChange (cause);
  32974. }
  32975. void Component::focusLost (FocusChangeType)
  32976. {
  32977. // base class does nothing
  32978. }
  32979. void Component::internalFocusLoss (const FocusChangeType cause)
  32980. {
  32981. SafePointer<Component> safePointer (this);
  32982. focusLost (focusChangedDirectly);
  32983. if (safePointer != 0)
  32984. internalChildFocusChange (cause);
  32985. }
  32986. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  32987. {
  32988. // base class does nothing
  32989. }
  32990. void Component::internalChildFocusChange (FocusChangeType cause)
  32991. {
  32992. const bool childIsNowFocused = hasKeyboardFocus (true);
  32993. if (flags.childCompFocusedFlag != childIsNowFocused)
  32994. {
  32995. flags.childCompFocusedFlag = childIsNowFocused;
  32996. SafePointer<Component> safePointer (this);
  32997. focusOfChildComponentChanged (cause);
  32998. if (safePointer == 0)
  32999. return;
  33000. }
  33001. if (parentComponent_ != 0)
  33002. parentComponent_->internalChildFocusChange (cause);
  33003. }
  33004. bool Component::isEnabled() const throw()
  33005. {
  33006. return (! flags.isDisabledFlag)
  33007. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33008. }
  33009. void Component::setEnabled (const bool shouldBeEnabled)
  33010. {
  33011. if (flags.isDisabledFlag == shouldBeEnabled)
  33012. {
  33013. flags.isDisabledFlag = ! shouldBeEnabled;
  33014. // if any parent components are disabled, setting our flag won't make a difference,
  33015. // so no need to send a change message
  33016. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33017. sendEnablementChangeMessage();
  33018. }
  33019. }
  33020. void Component::sendEnablementChangeMessage()
  33021. {
  33022. SafePointer<Component> safePointer (this);
  33023. enablementChanged();
  33024. if (safePointer == 0)
  33025. return;
  33026. for (int i = getNumChildComponents(); --i >= 0;)
  33027. {
  33028. Component* const c = getChildComponent (i);
  33029. if (c != 0)
  33030. {
  33031. c->sendEnablementChangeMessage();
  33032. if (safePointer == 0)
  33033. return;
  33034. }
  33035. }
  33036. }
  33037. void Component::enablementChanged()
  33038. {
  33039. }
  33040. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33041. {
  33042. flags.wantsFocusFlag = wantsFocus;
  33043. }
  33044. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33045. {
  33046. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33047. }
  33048. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33049. {
  33050. return ! flags.dontFocusOnMouseClickFlag;
  33051. }
  33052. bool Component::getWantsKeyboardFocus() const throw()
  33053. {
  33054. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33055. }
  33056. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33057. {
  33058. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33059. }
  33060. bool Component::isFocusContainer() const throw()
  33061. {
  33062. return flags.isFocusContainerFlag;
  33063. }
  33064. int Component::getExplicitFocusOrder() const
  33065. {
  33066. return properties ["_jexfo"];
  33067. }
  33068. void Component::setExplicitFocusOrder (const int newFocusOrderIndex)
  33069. {
  33070. properties.set ("_jexfo", newFocusOrderIndex);
  33071. }
  33072. KeyboardFocusTraverser* Component::createFocusTraverser()
  33073. {
  33074. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33075. return new KeyboardFocusTraverser();
  33076. return parentComponent_->createFocusTraverser();
  33077. }
  33078. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33079. {
  33080. // give the focus to this component
  33081. if (currentlyFocusedComponent != this)
  33082. {
  33083. JUCE_TRY
  33084. {
  33085. // get the focus onto our desktop window
  33086. ComponentPeer* const peer = getPeer();
  33087. if (peer != 0)
  33088. {
  33089. SafePointer<Component> safePointer (this);
  33090. peer->grabFocus();
  33091. if (peer->isFocused() && currentlyFocusedComponent != this)
  33092. {
  33093. Component* const componentLosingFocus = currentlyFocusedComponent;
  33094. currentlyFocusedComponent = this;
  33095. Desktop::getInstance().triggerFocusCallback();
  33096. // call this after setting currentlyFocusedComponent so that the one that's
  33097. // losing it has a chance to see where focus is going
  33098. if (componentLosingFocus->isValidComponent())
  33099. componentLosingFocus->internalFocusLoss (cause);
  33100. if (currentlyFocusedComponent == this)
  33101. {
  33102. focusGained (cause);
  33103. if (safePointer != 0)
  33104. internalChildFocusChange (cause);
  33105. }
  33106. }
  33107. }
  33108. }
  33109. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33110. catch (const std::exception& e)
  33111. {
  33112. currentlyFocusedComponent = 0;
  33113. Desktop::getInstance().triggerFocusCallback();
  33114. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33115. }
  33116. catch (...)
  33117. {
  33118. currentlyFocusedComponent = 0;
  33119. Desktop::getInstance().triggerFocusCallback();
  33120. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33121. }
  33122. #endif
  33123. }
  33124. }
  33125. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33126. {
  33127. if (isShowing())
  33128. {
  33129. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33130. {
  33131. takeKeyboardFocus (cause);
  33132. }
  33133. else
  33134. {
  33135. if (isParentOf (currentlyFocusedComponent)
  33136. && currentlyFocusedComponent->isShowing())
  33137. {
  33138. // do nothing if the focused component is actually a child of ours..
  33139. }
  33140. else
  33141. {
  33142. // find the default child component..
  33143. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33144. if (traverser != 0)
  33145. {
  33146. Component* const defaultComp = traverser->getDefaultComponent (this);
  33147. traverser = 0;
  33148. if (defaultComp != 0)
  33149. {
  33150. defaultComp->grabFocusInternal (cause, false);
  33151. return;
  33152. }
  33153. }
  33154. if (canTryParent && parentComponent_ != 0)
  33155. {
  33156. // if no children want it and we're allowed to try our parent comp,
  33157. // then pass up to parent, which will try our siblings.
  33158. parentComponent_->grabFocusInternal (cause, true);
  33159. }
  33160. }
  33161. }
  33162. }
  33163. }
  33164. void Component::grabKeyboardFocus()
  33165. {
  33166. // if component methods are being called from threads other than the message
  33167. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33168. checkMessageManagerIsLocked
  33169. grabFocusInternal (focusChangedDirectly);
  33170. }
  33171. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33172. {
  33173. // if component methods are being called from threads other than the message
  33174. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33175. checkMessageManagerIsLocked
  33176. if (parentComponent_ != 0)
  33177. {
  33178. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33179. if (traverser != 0)
  33180. {
  33181. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33182. : traverser->getPreviousComponent (this);
  33183. traverser = 0;
  33184. if (nextComp != 0)
  33185. {
  33186. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33187. {
  33188. SafePointer<Component> safePointer (this);
  33189. internalModalInputAttempt();
  33190. if (safePointer == 0 || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33191. return;
  33192. }
  33193. nextComp->grabFocusInternal (focusChangedByTabKey);
  33194. return;
  33195. }
  33196. }
  33197. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33198. }
  33199. }
  33200. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const
  33201. {
  33202. return (currentlyFocusedComponent == this)
  33203. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33204. }
  33205. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33206. {
  33207. return currentlyFocusedComponent;
  33208. }
  33209. void Component::giveAwayFocus()
  33210. {
  33211. // use a copy so we can clear the value before the call
  33212. Component* const componentLosingFocus = currentlyFocusedComponent;
  33213. currentlyFocusedComponent = 0;
  33214. Desktop::getInstance().triggerFocusCallback();
  33215. if (componentLosingFocus->isValidComponent())
  33216. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33217. }
  33218. bool Component::isMouseOver() const throw()
  33219. {
  33220. return flags.mouseOverFlag;
  33221. }
  33222. bool Component::isMouseButtonDown() const throw()
  33223. {
  33224. return flags.draggingFlag;
  33225. }
  33226. bool Component::isMouseOverOrDragging() const throw()
  33227. {
  33228. return flags.mouseOverFlag || flags.draggingFlag;
  33229. }
  33230. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33231. {
  33232. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33233. }
  33234. const Point<int> Component::getMouseXYRelative() const
  33235. {
  33236. return globalPositionToRelative (Desktop::getMousePosition());
  33237. }
  33238. const Rectangle<int> Component::getParentMonitorArea() const
  33239. {
  33240. return Desktop::getInstance()
  33241. .getMonitorAreaContaining (relativePositionToGlobal (Point<int> (getWidth() / 2,
  33242. getHeight() / 2)));
  33243. }
  33244. void Component::addKeyListener (KeyListener* const newListener)
  33245. {
  33246. if (keyListeners_ == 0)
  33247. keyListeners_ = new VoidArray();
  33248. keyListeners_->addIfNotAlreadyThere (newListener);
  33249. }
  33250. void Component::removeKeyListener (KeyListener* const listenerToRemove)
  33251. {
  33252. if (keyListeners_ != 0)
  33253. keyListeners_->removeValue (listenerToRemove);
  33254. }
  33255. bool Component::keyPressed (const KeyPress&)
  33256. {
  33257. return false;
  33258. }
  33259. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33260. {
  33261. return false;
  33262. }
  33263. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33264. {
  33265. if (parentComponent_ != 0)
  33266. parentComponent_->modifierKeysChanged (modifiers);
  33267. }
  33268. void Component::internalModifierKeysChanged()
  33269. {
  33270. sendFakeMouseMove();
  33271. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33272. }
  33273. ComponentPeer* Component::getPeer() const
  33274. {
  33275. if (flags.hasHeavyweightPeerFlag)
  33276. return ComponentPeer::getPeerFor (this);
  33277. else if (parentComponent_ != 0)
  33278. return parentComponent_->getPeer();
  33279. else
  33280. return 0;
  33281. }
  33282. Component::BailOutChecker::BailOutChecker (Component* const component1, Component* const component2_)
  33283. : safePointer1 (component1), safePointer2 (component2_), component2 (component2_)
  33284. {
  33285. jassert (component1 != 0);
  33286. }
  33287. bool Component::BailOutChecker::shouldBailOut() const throw()
  33288. {
  33289. return safePointer1 == 0 || safePointer2.getComponent() != component2;
  33290. }
  33291. END_JUCE_NAMESPACE
  33292. /*** End of inlined file: juce_Component.cpp ***/
  33293. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33294. BEGIN_JUCE_NAMESPACE
  33295. void ComponentListener::componentMovedOrResized (Component&, bool, bool) {}
  33296. void ComponentListener::componentBroughtToFront (Component&) {}
  33297. void ComponentListener::componentVisibilityChanged (Component&) {}
  33298. void ComponentListener::componentChildrenChanged (Component&) {}
  33299. void ComponentListener::componentParentHierarchyChanged (Component&) {}
  33300. void ComponentListener::componentNameChanged (Component&) {}
  33301. void ComponentListener::componentBeingDeleted (Component&) {}
  33302. END_JUCE_NAMESPACE
  33303. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33304. /*** Start of inlined file: juce_Desktop.cpp ***/
  33305. BEGIN_JUCE_NAMESPACE
  33306. Desktop::Desktop()
  33307. : mouseClickCounter (0),
  33308. kioskModeComponent (0)
  33309. {
  33310. createMouseInputSources();
  33311. refreshMonitorSizes();
  33312. }
  33313. Desktop::~Desktop()
  33314. {
  33315. jassert (instance == this);
  33316. instance = 0;
  33317. // doh! If you don't delete all your windows before exiting, you're going to
  33318. // be leaking memory!
  33319. jassert (desktopComponents.size() == 0);
  33320. }
  33321. Desktop& JUCE_CALLTYPE Desktop::getInstance()
  33322. {
  33323. if (instance == 0)
  33324. instance = new Desktop();
  33325. return *instance;
  33326. }
  33327. Desktop* Desktop::instance = 0;
  33328. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33329. const bool clipToWorkArea);
  33330. void Desktop::refreshMonitorSizes()
  33331. {
  33332. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33333. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33334. monitorCoordsClipped.clear();
  33335. monitorCoordsUnclipped.clear();
  33336. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33337. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33338. jassert (monitorCoordsClipped.size() > 0
  33339. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33340. if (oldClipped != monitorCoordsClipped
  33341. || oldUnclipped != monitorCoordsUnclipped)
  33342. {
  33343. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33344. {
  33345. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33346. if (p != 0)
  33347. p->handleScreenSizeChange();
  33348. }
  33349. }
  33350. }
  33351. int Desktop::getNumDisplayMonitors() const throw()
  33352. {
  33353. return monitorCoordsClipped.size();
  33354. }
  33355. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33356. {
  33357. return clippedToWorkArea ? monitorCoordsClipped [index]
  33358. : monitorCoordsUnclipped [index];
  33359. }
  33360. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33361. {
  33362. RectangleList rl;
  33363. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33364. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33365. return rl;
  33366. }
  33367. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33368. {
  33369. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33370. }
  33371. const Rectangle<int> Desktop::getMonitorAreaContaining (const Point<int>& position, const bool clippedToWorkArea) const
  33372. {
  33373. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33374. double bestDistance = 1.0e10;
  33375. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33376. {
  33377. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33378. if (rect.contains (position))
  33379. return rect;
  33380. const double distance = rect.getCentre().getDistanceFrom (position);
  33381. if (distance < bestDistance)
  33382. {
  33383. bestDistance = distance;
  33384. best = rect;
  33385. }
  33386. }
  33387. return best;
  33388. }
  33389. int Desktop::getNumComponents() const throw()
  33390. {
  33391. return desktopComponents.size();
  33392. }
  33393. Component* Desktop::getComponent (const int index) const throw()
  33394. {
  33395. return desktopComponents [index];
  33396. }
  33397. Component* Desktop::findComponentAt (const Point<int>& screenPosition) const
  33398. {
  33399. for (int i = desktopComponents.size(); --i >= 0;)
  33400. {
  33401. Component* const c = desktopComponents.getUnchecked(i);
  33402. const Point<int> relative (c->globalPositionToRelative (screenPosition));
  33403. if (c->contains (relative.getX(), relative.getY()))
  33404. return c->getComponentAt (relative.getX(), relative.getY());
  33405. }
  33406. return 0;
  33407. }
  33408. void Desktop::addDesktopComponent (Component* const c)
  33409. {
  33410. jassert (c != 0);
  33411. jassert (! desktopComponents.contains (c));
  33412. desktopComponents.addIfNotAlreadyThere (c);
  33413. }
  33414. void Desktop::removeDesktopComponent (Component* const c)
  33415. {
  33416. desktopComponents.removeValue (c);
  33417. }
  33418. void Desktop::componentBroughtToFront (Component* const c)
  33419. {
  33420. const int index = desktopComponents.indexOf (c);
  33421. jassert (index >= 0);
  33422. if (index >= 0)
  33423. {
  33424. int newIndex = -1;
  33425. if (! c->isAlwaysOnTop())
  33426. {
  33427. newIndex = desktopComponents.size();
  33428. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33429. --newIndex;
  33430. --newIndex;
  33431. }
  33432. desktopComponents.move (index, newIndex);
  33433. }
  33434. }
  33435. const Point<int> Desktop::getLastMouseDownPosition() throw()
  33436. {
  33437. return getInstance().getMainMouseSource().getLastMouseDownPosition();
  33438. }
  33439. int Desktop::getMouseButtonClickCounter() throw()
  33440. {
  33441. return getInstance().mouseClickCounter;
  33442. }
  33443. void Desktop::incrementMouseClickCounter() throw()
  33444. {
  33445. ++mouseClickCounter;
  33446. }
  33447. int Desktop::getNumDraggingMouseSources() const throw()
  33448. {
  33449. int num = 0;
  33450. for (int i = mouseSources.size(); --i >= 0;)
  33451. if (mouseSources.getUnchecked(i)->isDragging())
  33452. ++num;
  33453. return num;
  33454. }
  33455. MouseInputSource* Desktop::getDraggingMouseSource (int index) const throw()
  33456. {
  33457. int num = 0;
  33458. for (int i = mouseSources.size(); --i >= 0;)
  33459. {
  33460. MouseInputSource* const mi = mouseSources.getUnchecked(i);
  33461. if (mi->isDragging())
  33462. {
  33463. if (index == num)
  33464. return mi;
  33465. ++num;
  33466. }
  33467. }
  33468. return 0;
  33469. }
  33470. void Desktop::addFocusChangeListener (FocusChangeListener* const listener)
  33471. {
  33472. focusListeners.add (listener);
  33473. }
  33474. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener)
  33475. {
  33476. focusListeners.remove (listener);
  33477. }
  33478. void Desktop::triggerFocusCallback()
  33479. {
  33480. triggerAsyncUpdate();
  33481. }
  33482. void Desktop::handleAsyncUpdate()
  33483. {
  33484. Component* currentFocus = Component::getCurrentlyFocusedComponent();
  33485. focusListeners.call (&FocusChangeListener::globalFocusChanged, currentFocus);
  33486. }
  33487. void Desktop::addGlobalMouseListener (MouseListener* const listener)
  33488. {
  33489. mouseListeners.add (listener);
  33490. resetTimer();
  33491. }
  33492. void Desktop::removeGlobalMouseListener (MouseListener* const listener)
  33493. {
  33494. mouseListeners.remove (listener);
  33495. resetTimer();
  33496. }
  33497. void Desktop::timerCallback()
  33498. {
  33499. if (lastFakeMouseMove != getMousePosition())
  33500. sendMouseMove();
  33501. }
  33502. void Desktop::sendMouseMove()
  33503. {
  33504. if (! mouseListeners.isEmpty())
  33505. {
  33506. startTimer (20);
  33507. lastFakeMouseMove = getMousePosition();
  33508. Component* const target = findComponentAt (lastFakeMouseMove);
  33509. if (target != 0)
  33510. {
  33511. Component::BailOutChecker checker (target);
  33512. const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
  33513. const Time now (Time::getCurrentTime());
  33514. const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(),
  33515. target, now, pos, now, 0, false);
  33516. if (me.mods.isAnyMouseButtonDown())
  33517. mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  33518. else
  33519. mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  33520. }
  33521. }
  33522. }
  33523. void Desktop::resetTimer()
  33524. {
  33525. if (mouseListeners.size() == 0)
  33526. stopTimer();
  33527. else
  33528. startTimer (100);
  33529. lastFakeMouseMove = getMousePosition();
  33530. }
  33531. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  33532. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  33533. {
  33534. if (kioskModeComponent != componentToUse)
  33535. {
  33536. // agh! Don't delete a component without first stopping it being the kiosk comp
  33537. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  33538. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  33539. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  33540. if (kioskModeComponent->isValidComponent())
  33541. {
  33542. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  33543. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  33544. }
  33545. kioskModeComponent = componentToUse;
  33546. if (kioskModeComponent != 0)
  33547. {
  33548. jassert (kioskModeComponent->isValidComponent());
  33549. // Only components that are already on the desktop can be put into kiosk mode!
  33550. jassert (kioskModeComponent->isOnDesktop());
  33551. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  33552. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  33553. }
  33554. }
  33555. }
  33556. END_JUCE_NAMESPACE
  33557. /*** End of inlined file: juce_Desktop.cpp ***/
  33558. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  33559. BEGIN_JUCE_NAMESPACE
  33560. ArrowButton::ArrowButton (const String& name,
  33561. float arrowDirectionInRadians,
  33562. const Colour& arrowColour)
  33563. : Button (name),
  33564. colour (arrowColour)
  33565. {
  33566. path.lineTo (0.0f, 1.0f);
  33567. path.lineTo (1.0f, 0.5f);
  33568. path.closeSubPath();
  33569. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  33570. 0.5f, 0.5f));
  33571. setComponentEffect (&shadow);
  33572. buttonStateChanged();
  33573. }
  33574. ArrowButton::~ArrowButton()
  33575. {
  33576. }
  33577. void ArrowButton::paintButton (Graphics& g,
  33578. bool /*isMouseOverButton*/,
  33579. bool /*isButtonDown*/)
  33580. {
  33581. g.setColour (colour);
  33582. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  33583. (float) offset,
  33584. (float) (getWidth() - 3),
  33585. (float) (getHeight() - 3),
  33586. false));
  33587. }
  33588. void ArrowButton::buttonStateChanged()
  33589. {
  33590. offset = (isDown()) ? 1 : 0;
  33591. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  33592. 0.3f, -1, 0);
  33593. }
  33594. END_JUCE_NAMESPACE
  33595. /*** End of inlined file: juce_ArrowButton.cpp ***/
  33596. /*** Start of inlined file: juce_Button.cpp ***/
  33597. BEGIN_JUCE_NAMESPACE
  33598. class Button::RepeatTimer : public Timer
  33599. {
  33600. public:
  33601. RepeatTimer (Button& owner_) : owner (owner_) {}
  33602. void timerCallback() { owner.repeatTimerCallback(); }
  33603. juce_UseDebuggingNewOperator
  33604. private:
  33605. Button& owner;
  33606. RepeatTimer (const RepeatTimer&);
  33607. RepeatTimer& operator= (const RepeatTimer&);
  33608. };
  33609. Button::Button (const String& name)
  33610. : Component (name),
  33611. text (name),
  33612. buttonPressTime (0),
  33613. lastTimeCallbackTime (0),
  33614. commandManagerToUse (0),
  33615. autoRepeatDelay (-1),
  33616. autoRepeatSpeed (0),
  33617. autoRepeatMinimumDelay (-1),
  33618. radioGroupId (0),
  33619. commandID (0),
  33620. connectedEdgeFlags (0),
  33621. buttonState (buttonNormal),
  33622. lastToggleState (false),
  33623. clickTogglesState (false),
  33624. needsToRelease (false),
  33625. needsRepainting (false),
  33626. isKeyDown (false),
  33627. triggerOnMouseDown (false),
  33628. generateTooltip (false)
  33629. {
  33630. setWantsKeyboardFocus (true);
  33631. isOn.addListener (this);
  33632. }
  33633. Button::~Button()
  33634. {
  33635. isOn.removeListener (this);
  33636. if (commandManagerToUse != 0)
  33637. commandManagerToUse->removeListener (this);
  33638. repeatTimer = 0;
  33639. clearShortcuts();
  33640. }
  33641. void Button::setButtonText (const String& newText)
  33642. {
  33643. if (text != newText)
  33644. {
  33645. text = newText;
  33646. repaint();
  33647. }
  33648. }
  33649. void Button::setTooltip (const String& newTooltip)
  33650. {
  33651. SettableTooltipClient::setTooltip (newTooltip);
  33652. generateTooltip = false;
  33653. }
  33654. const String Button::getTooltip()
  33655. {
  33656. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  33657. {
  33658. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  33659. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  33660. for (int i = 0; i < keyPresses.size(); ++i)
  33661. {
  33662. const String key (keyPresses.getReference(i).getTextDescription());
  33663. tt << " [";
  33664. if (key.length() == 1)
  33665. tt << TRANS("shortcut") << ": '" << key << "']";
  33666. else
  33667. tt << key << ']';
  33668. }
  33669. return tt;
  33670. }
  33671. return SettableTooltipClient::getTooltip();
  33672. }
  33673. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  33674. {
  33675. if (connectedEdgeFlags != connectedEdgeFlags_)
  33676. {
  33677. connectedEdgeFlags = connectedEdgeFlags_;
  33678. repaint();
  33679. }
  33680. }
  33681. void Button::setToggleState (const bool shouldBeOn,
  33682. const bool sendChangeNotification)
  33683. {
  33684. if (shouldBeOn != lastToggleState)
  33685. {
  33686. isOn = shouldBeOn;
  33687. lastToggleState = shouldBeOn;
  33688. repaint();
  33689. if (sendChangeNotification)
  33690. {
  33691. Component::SafePointer<Component> deletionWatcher (this);
  33692. sendClickMessage (ModifierKeys());
  33693. if (deletionWatcher == 0)
  33694. return;
  33695. }
  33696. if (lastToggleState)
  33697. turnOffOtherButtonsInGroup (sendChangeNotification);
  33698. }
  33699. }
  33700. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  33701. {
  33702. clickTogglesState = shouldToggle;
  33703. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33704. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33705. // it is that this button represents, and the button will update its state to reflect this
  33706. // in the applicationCommandListChanged() method.
  33707. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33708. }
  33709. bool Button::getClickingTogglesState() const throw()
  33710. {
  33711. return clickTogglesState;
  33712. }
  33713. void Button::valueChanged (Value& value)
  33714. {
  33715. if (value.refersToSameSourceAs (isOn))
  33716. setToggleState (isOn.getValue(), true);
  33717. }
  33718. void Button::setRadioGroupId (const int newGroupId)
  33719. {
  33720. if (radioGroupId != newGroupId)
  33721. {
  33722. radioGroupId = newGroupId;
  33723. if (lastToggleState)
  33724. turnOffOtherButtonsInGroup (true);
  33725. }
  33726. }
  33727. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  33728. {
  33729. Component* const p = getParentComponent();
  33730. if (p != 0 && radioGroupId != 0)
  33731. {
  33732. Component::SafePointer<Component> deletionWatcher (this);
  33733. for (int i = p->getNumChildComponents(); --i >= 0;)
  33734. {
  33735. Component* const c = p->getChildComponent (i);
  33736. if (c != this)
  33737. {
  33738. Button* const b = dynamic_cast <Button*> (c);
  33739. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  33740. {
  33741. b->setToggleState (false, sendChangeNotification);
  33742. if (deletionWatcher == 0)
  33743. return;
  33744. }
  33745. }
  33746. }
  33747. }
  33748. }
  33749. void Button::enablementChanged()
  33750. {
  33751. updateState (0);
  33752. repaint();
  33753. }
  33754. Button::ButtonState Button::updateState (const MouseEvent* const e)
  33755. {
  33756. ButtonState state = buttonNormal;
  33757. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  33758. {
  33759. Point<int> mousePos;
  33760. if (e == 0)
  33761. mousePos = getMouseXYRelative();
  33762. else
  33763. mousePos = e->getEventRelativeTo (this).getPosition();
  33764. const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true);
  33765. const bool down = isMouseButtonDown();
  33766. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  33767. state = buttonDown;
  33768. else if (over)
  33769. state = buttonOver;
  33770. }
  33771. setState (state);
  33772. return state;
  33773. }
  33774. void Button::setState (const ButtonState newState)
  33775. {
  33776. if (buttonState != newState)
  33777. {
  33778. buttonState = newState;
  33779. repaint();
  33780. if (buttonState == buttonDown)
  33781. {
  33782. buttonPressTime = Time::getApproximateMillisecondCounter();
  33783. lastTimeCallbackTime = buttonPressTime;
  33784. }
  33785. sendStateMessage();
  33786. }
  33787. }
  33788. bool Button::isDown() const throw()
  33789. {
  33790. return buttonState == buttonDown;
  33791. }
  33792. bool Button::isOver() const throw()
  33793. {
  33794. return buttonState != buttonNormal;
  33795. }
  33796. void Button::buttonStateChanged()
  33797. {
  33798. }
  33799. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  33800. {
  33801. const uint32 now = Time::getApproximateMillisecondCounter();
  33802. return now > buttonPressTime ? now - buttonPressTime : 0;
  33803. }
  33804. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  33805. {
  33806. triggerOnMouseDown = isTriggeredOnMouseDown;
  33807. }
  33808. void Button::clicked()
  33809. {
  33810. }
  33811. void Button::clicked (const ModifierKeys& /*modifiers*/)
  33812. {
  33813. clicked();
  33814. }
  33815. static const int clickMessageId = 0x2f3f4f99;
  33816. void Button::triggerClick()
  33817. {
  33818. postCommandMessage (clickMessageId);
  33819. }
  33820. void Button::internalClickCallback (const ModifierKeys& modifiers)
  33821. {
  33822. if (clickTogglesState)
  33823. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  33824. sendClickMessage (modifiers);
  33825. }
  33826. void Button::flashButtonState()
  33827. {
  33828. if (isEnabled())
  33829. {
  33830. needsToRelease = true;
  33831. setState (buttonDown);
  33832. getRepeatTimer().startTimer (100);
  33833. }
  33834. }
  33835. void Button::handleCommandMessage (int commandId)
  33836. {
  33837. if (commandId == clickMessageId)
  33838. {
  33839. if (isEnabled())
  33840. {
  33841. flashButtonState();
  33842. internalClickCallback (ModifierKeys::getCurrentModifiers());
  33843. }
  33844. }
  33845. else
  33846. {
  33847. Component::handleCommandMessage (commandId);
  33848. }
  33849. }
  33850. void Button::addButtonListener (ButtonListener* const newListener)
  33851. {
  33852. buttonListeners.add (newListener);
  33853. }
  33854. void Button::removeButtonListener (ButtonListener* const listener)
  33855. {
  33856. buttonListeners.remove (listener);
  33857. }
  33858. void Button::sendClickMessage (const ModifierKeys& modifiers)
  33859. {
  33860. Component::BailOutChecker checker (this);
  33861. if (commandManagerToUse != 0 && commandID != 0)
  33862. {
  33863. ApplicationCommandTarget::InvocationInfo info (commandID);
  33864. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  33865. info.originatingComponent = this;
  33866. commandManagerToUse->invoke (info, true);
  33867. }
  33868. clicked (modifiers);
  33869. if (! checker.shouldBailOut())
  33870. buttonListeners.callChecked (checker, &ButtonListener::buttonClicked, this);
  33871. }
  33872. void Button::sendStateMessage()
  33873. {
  33874. Component::BailOutChecker checker (this);
  33875. buttonStateChanged();
  33876. if (! checker.shouldBailOut())
  33877. buttonListeners.callChecked (checker, &ButtonListener::buttonStateChanged, this);
  33878. }
  33879. void Button::paint (Graphics& g)
  33880. {
  33881. if (needsToRelease && isEnabled())
  33882. {
  33883. needsToRelease = false;
  33884. needsRepainting = true;
  33885. }
  33886. paintButton (g, isOver(), isDown());
  33887. }
  33888. void Button::mouseEnter (const MouseEvent& e)
  33889. {
  33890. updateState (&e);
  33891. }
  33892. void Button::mouseExit (const MouseEvent& e)
  33893. {
  33894. updateState (&e);
  33895. }
  33896. void Button::mouseDown (const MouseEvent& e)
  33897. {
  33898. updateState (&e);
  33899. if (isDown())
  33900. {
  33901. if (autoRepeatDelay >= 0)
  33902. getRepeatTimer().startTimer (autoRepeatDelay);
  33903. if (triggerOnMouseDown)
  33904. internalClickCallback (e.mods);
  33905. }
  33906. }
  33907. void Button::mouseUp (const MouseEvent& e)
  33908. {
  33909. const bool wasDown = isDown();
  33910. updateState (&e);
  33911. if (wasDown && isOver() && ! triggerOnMouseDown)
  33912. internalClickCallback (e.mods);
  33913. }
  33914. void Button::mouseDrag (const MouseEvent& e)
  33915. {
  33916. const ButtonState oldState = buttonState;
  33917. updateState (&e);
  33918. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  33919. getRepeatTimer().startTimer (autoRepeatSpeed);
  33920. }
  33921. void Button::focusGained (FocusChangeType)
  33922. {
  33923. updateState (0);
  33924. repaint();
  33925. }
  33926. void Button::focusLost (FocusChangeType)
  33927. {
  33928. updateState (0);
  33929. repaint();
  33930. }
  33931. void Button::setVisible (bool shouldBeVisible)
  33932. {
  33933. if (shouldBeVisible != isVisible())
  33934. {
  33935. Component::setVisible (shouldBeVisible);
  33936. if (! shouldBeVisible)
  33937. needsToRelease = false;
  33938. updateState (0);
  33939. }
  33940. else
  33941. {
  33942. Component::setVisible (shouldBeVisible);
  33943. }
  33944. }
  33945. void Button::parentHierarchyChanged()
  33946. {
  33947. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  33948. if (newKeySource != keySource.getComponent())
  33949. {
  33950. if (keySource != 0)
  33951. keySource->removeKeyListener (this);
  33952. keySource = newKeySource;
  33953. if (keySource != 0)
  33954. keySource->addKeyListener (this);
  33955. }
  33956. }
  33957. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  33958. const int commandID_,
  33959. const bool generateTooltip_)
  33960. {
  33961. commandID = commandID_;
  33962. generateTooltip = generateTooltip_;
  33963. if (commandManagerToUse != commandManagerToUse_)
  33964. {
  33965. if (commandManagerToUse != 0)
  33966. commandManagerToUse->removeListener (this);
  33967. commandManagerToUse = commandManagerToUse_;
  33968. if (commandManagerToUse != 0)
  33969. commandManagerToUse->addListener (this);
  33970. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33971. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33972. // it is that this button represents, and the button will update its state to reflect this
  33973. // in the applicationCommandListChanged() method.
  33974. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33975. }
  33976. if (commandManagerToUse != 0)
  33977. applicationCommandListChanged();
  33978. else
  33979. setEnabled (true);
  33980. }
  33981. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  33982. {
  33983. if (info.commandID == commandID
  33984. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  33985. {
  33986. flashButtonState();
  33987. }
  33988. }
  33989. void Button::applicationCommandListChanged()
  33990. {
  33991. if (commandManagerToUse != 0)
  33992. {
  33993. ApplicationCommandInfo info (0);
  33994. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  33995. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  33996. if (target != 0)
  33997. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  33998. }
  33999. }
  34000. void Button::addShortcut (const KeyPress& key)
  34001. {
  34002. if (key.isValid())
  34003. {
  34004. jassert (! isRegisteredForShortcut (key)); // already registered!
  34005. shortcuts.add (key);
  34006. parentHierarchyChanged();
  34007. }
  34008. }
  34009. void Button::clearShortcuts()
  34010. {
  34011. shortcuts.clear();
  34012. parentHierarchyChanged();
  34013. }
  34014. bool Button::isShortcutPressed() const
  34015. {
  34016. if (! isCurrentlyBlockedByAnotherModalComponent())
  34017. {
  34018. for (int i = shortcuts.size(); --i >= 0;)
  34019. if (shortcuts.getReference(i).isCurrentlyDown())
  34020. return true;
  34021. }
  34022. return false;
  34023. }
  34024. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34025. {
  34026. for (int i = shortcuts.size(); --i >= 0;)
  34027. if (key == shortcuts.getReference(i))
  34028. return true;
  34029. return false;
  34030. }
  34031. bool Button::keyStateChanged (const bool, Component*)
  34032. {
  34033. if (! isEnabled())
  34034. return false;
  34035. const bool wasDown = isKeyDown;
  34036. isKeyDown = isShortcutPressed();
  34037. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34038. getRepeatTimer().startTimer (autoRepeatDelay);
  34039. updateState (0);
  34040. if (isEnabled() && wasDown && ! isKeyDown)
  34041. {
  34042. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34043. // (return immediately - this button may now have been deleted)
  34044. return true;
  34045. }
  34046. return wasDown || isKeyDown;
  34047. }
  34048. bool Button::keyPressed (const KeyPress&, Component*)
  34049. {
  34050. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34051. return isShortcutPressed();
  34052. }
  34053. bool Button::keyPressed (const KeyPress& key)
  34054. {
  34055. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34056. {
  34057. triggerClick();
  34058. return true;
  34059. }
  34060. return false;
  34061. }
  34062. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34063. const int repeatMillisecs,
  34064. const int minimumDelayInMillisecs) throw()
  34065. {
  34066. autoRepeatDelay = initialDelayMillisecs;
  34067. autoRepeatSpeed = repeatMillisecs;
  34068. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34069. }
  34070. void Button::repeatTimerCallback()
  34071. {
  34072. if (needsRepainting)
  34073. {
  34074. getRepeatTimer().stopTimer();
  34075. updateState (0);
  34076. needsRepainting = false;
  34077. }
  34078. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34079. {
  34080. int repeatSpeed = autoRepeatSpeed;
  34081. if (autoRepeatMinimumDelay >= 0)
  34082. {
  34083. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34084. timeHeldDown *= timeHeldDown;
  34085. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34086. }
  34087. repeatSpeed = jmax (1, repeatSpeed);
  34088. getRepeatTimer().startTimer (repeatSpeed);
  34089. const uint32 now = Time::getApproximateMillisecondCounter();
  34090. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34091. lastTimeCallbackTime = now;
  34092. Component::SafePointer<Component> deletionWatcher (this);
  34093. for (int i = numTimesToCallback; --i >= 0;)
  34094. {
  34095. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34096. if (deletionWatcher == 0 || ! isDown())
  34097. return;
  34098. }
  34099. }
  34100. else if (! needsToRelease)
  34101. {
  34102. getRepeatTimer().stopTimer();
  34103. }
  34104. }
  34105. Button::RepeatTimer& Button::getRepeatTimer()
  34106. {
  34107. if (repeatTimer == 0)
  34108. repeatTimer = new RepeatTimer (*this);
  34109. return *repeatTimer;
  34110. }
  34111. END_JUCE_NAMESPACE
  34112. /*** End of inlined file: juce_Button.cpp ***/
  34113. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34114. BEGIN_JUCE_NAMESPACE
  34115. DrawableButton::DrawableButton (const String& name,
  34116. const DrawableButton::ButtonStyle buttonStyle)
  34117. : Button (name),
  34118. style (buttonStyle),
  34119. edgeIndent (3)
  34120. {
  34121. if (buttonStyle == ImageOnButtonBackground)
  34122. {
  34123. backgroundOff = Colour (0xffbbbbff);
  34124. backgroundOn = Colour (0xff3333ff);
  34125. }
  34126. else
  34127. {
  34128. backgroundOff = Colours::transparentBlack;
  34129. backgroundOn = Colour (0xaabbbbff);
  34130. }
  34131. }
  34132. DrawableButton::~DrawableButton()
  34133. {
  34134. deleteImages();
  34135. }
  34136. void DrawableButton::deleteImages()
  34137. {
  34138. }
  34139. void DrawableButton::setImages (const Drawable* normal,
  34140. const Drawable* over,
  34141. const Drawable* down,
  34142. const Drawable* disabled,
  34143. const Drawable* normalOn,
  34144. const Drawable* overOn,
  34145. const Drawable* downOn,
  34146. const Drawable* disabledOn)
  34147. {
  34148. deleteImages();
  34149. jassert (normal != 0); // you really need to give it at least a normal image..
  34150. if (normal != 0)
  34151. normalImage = normal->createCopy();
  34152. if (over != 0)
  34153. overImage = over->createCopy();
  34154. if (down != 0)
  34155. downImage = down->createCopy();
  34156. if (disabled != 0)
  34157. disabledImage = disabled->createCopy();
  34158. if (normalOn != 0)
  34159. normalImageOn = normalOn->createCopy();
  34160. if (overOn != 0)
  34161. overImageOn = overOn->createCopy();
  34162. if (downOn != 0)
  34163. downImageOn = downOn->createCopy();
  34164. if (disabledOn != 0)
  34165. disabledImageOn = disabledOn->createCopy();
  34166. repaint();
  34167. }
  34168. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34169. {
  34170. if (style != newStyle)
  34171. {
  34172. style = newStyle;
  34173. repaint();
  34174. }
  34175. }
  34176. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34177. const Colour& toggledOnColour)
  34178. {
  34179. if (backgroundOff != toggledOffColour
  34180. || backgroundOn != toggledOnColour)
  34181. {
  34182. backgroundOff = toggledOffColour;
  34183. backgroundOn = toggledOnColour;
  34184. repaint();
  34185. }
  34186. }
  34187. const Colour& DrawableButton::getBackgroundColour() const throw()
  34188. {
  34189. return getToggleState() ? backgroundOn
  34190. : backgroundOff;
  34191. }
  34192. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34193. {
  34194. edgeIndent = numPixelsIndent;
  34195. repaint();
  34196. }
  34197. void DrawableButton::paintButton (Graphics& g,
  34198. bool isMouseOverButton,
  34199. bool isButtonDown)
  34200. {
  34201. Rectangle<int> imageSpace;
  34202. if (style == ImageOnButtonBackground)
  34203. {
  34204. const int insetX = getWidth() / 4;
  34205. const int insetY = getHeight() / 4;
  34206. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34207. getLookAndFeel().drawButtonBackground (g, *this,
  34208. getBackgroundColour(),
  34209. isMouseOverButton,
  34210. isButtonDown);
  34211. }
  34212. else
  34213. {
  34214. g.fillAll (getBackgroundColour());
  34215. const int textH = (style == ImageAboveTextLabel)
  34216. ? jmin (16, proportionOfHeight (0.25f))
  34217. : 0;
  34218. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34219. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34220. imageSpace.setBounds (indentX, indentY,
  34221. getWidth() - indentX * 2,
  34222. getHeight() - indentY * 2 - textH);
  34223. if (textH > 0)
  34224. {
  34225. g.setFont ((float) textH);
  34226. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34227. g.drawFittedText (getButtonText(),
  34228. 2, getHeight() - textH - 1,
  34229. getWidth() - 4, textH,
  34230. Justification::centred, 1);
  34231. }
  34232. }
  34233. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34234. g.setOpacity (1.0f);
  34235. const Drawable* imageToDraw = 0;
  34236. if (isEnabled())
  34237. {
  34238. imageToDraw = getCurrentImage();
  34239. }
  34240. else
  34241. {
  34242. imageToDraw = getToggleState() ? disabledImageOn
  34243. : disabledImage;
  34244. if (imageToDraw == 0)
  34245. {
  34246. g.setOpacity (0.4f);
  34247. imageToDraw = getNormalImage();
  34248. }
  34249. }
  34250. if (imageToDraw != 0)
  34251. {
  34252. if (style == ImageRaw)
  34253. {
  34254. imageToDraw->draw (g, 1.0f);
  34255. }
  34256. else
  34257. {
  34258. imageToDraw->drawWithin (g,
  34259. imageSpace.getX(),
  34260. imageSpace.getY(),
  34261. imageSpace.getWidth(),
  34262. imageSpace.getHeight(),
  34263. RectanglePlacement::centred,
  34264. 1.0f);
  34265. }
  34266. }
  34267. }
  34268. const Drawable* DrawableButton::getCurrentImage() const throw()
  34269. {
  34270. if (isDown())
  34271. return getDownImage();
  34272. if (isOver())
  34273. return getOverImage();
  34274. return getNormalImage();
  34275. }
  34276. const Drawable* DrawableButton::getNormalImage() const throw()
  34277. {
  34278. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34279. : normalImage;
  34280. }
  34281. const Drawable* DrawableButton::getOverImage() const throw()
  34282. {
  34283. const Drawable* d = normalImage;
  34284. if (getToggleState())
  34285. {
  34286. if (overImageOn != 0)
  34287. d = overImageOn;
  34288. else if (normalImageOn != 0)
  34289. d = normalImageOn;
  34290. else if (overImage != 0)
  34291. d = overImage;
  34292. }
  34293. else
  34294. {
  34295. if (overImage != 0)
  34296. d = overImage;
  34297. }
  34298. return d;
  34299. }
  34300. const Drawable* DrawableButton::getDownImage() const throw()
  34301. {
  34302. const Drawable* d = normalImage;
  34303. if (getToggleState())
  34304. {
  34305. if (downImageOn != 0)
  34306. d = downImageOn;
  34307. else if (overImageOn != 0)
  34308. d = overImageOn;
  34309. else if (normalImageOn != 0)
  34310. d = normalImageOn;
  34311. else if (downImage != 0)
  34312. d = downImage;
  34313. else
  34314. d = getOverImage();
  34315. }
  34316. else
  34317. {
  34318. if (downImage != 0)
  34319. d = downImage;
  34320. else
  34321. d = getOverImage();
  34322. }
  34323. return d;
  34324. }
  34325. END_JUCE_NAMESPACE
  34326. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34327. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34328. BEGIN_JUCE_NAMESPACE
  34329. HyperlinkButton::HyperlinkButton (const String& linkText,
  34330. const URL& linkURL)
  34331. : Button (linkText),
  34332. url (linkURL),
  34333. font (14.0f, Font::underlined),
  34334. resizeFont (true),
  34335. justification (Justification::centred)
  34336. {
  34337. setMouseCursor (MouseCursor::PointingHandCursor);
  34338. setTooltip (linkURL.toString (false));
  34339. }
  34340. HyperlinkButton::~HyperlinkButton()
  34341. {
  34342. }
  34343. void HyperlinkButton::setFont (const Font& newFont,
  34344. const bool resizeToMatchComponentHeight,
  34345. const Justification& justificationType)
  34346. {
  34347. font = newFont;
  34348. resizeFont = resizeToMatchComponentHeight;
  34349. justification = justificationType;
  34350. repaint();
  34351. }
  34352. void HyperlinkButton::setURL (const URL& newURL) throw()
  34353. {
  34354. url = newURL;
  34355. setTooltip (newURL.toString (false));
  34356. }
  34357. const Font HyperlinkButton::getFontToUse() const
  34358. {
  34359. Font f (font);
  34360. if (resizeFont)
  34361. f.setHeight (getHeight() * 0.7f);
  34362. return f;
  34363. }
  34364. void HyperlinkButton::changeWidthToFitText()
  34365. {
  34366. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34367. }
  34368. void HyperlinkButton::colourChanged()
  34369. {
  34370. repaint();
  34371. }
  34372. void HyperlinkButton::clicked()
  34373. {
  34374. if (url.isWellFormed())
  34375. url.launchInDefaultBrowser();
  34376. }
  34377. void HyperlinkButton::paintButton (Graphics& g,
  34378. bool isMouseOverButton,
  34379. bool isButtonDown)
  34380. {
  34381. const Colour textColour (findColour (textColourId));
  34382. if (isEnabled())
  34383. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34384. : textColour);
  34385. else
  34386. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34387. g.setFont (getFontToUse());
  34388. g.drawText (getButtonText(),
  34389. 2, 0, getWidth() - 2, getHeight(),
  34390. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34391. true);
  34392. }
  34393. END_JUCE_NAMESPACE
  34394. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34395. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34396. BEGIN_JUCE_NAMESPACE
  34397. ImageButton::ImageButton (const String& text_)
  34398. : Button (text_),
  34399. scaleImageToFit (true),
  34400. preserveProportions (true),
  34401. alphaThreshold (0),
  34402. imageX (0),
  34403. imageY (0),
  34404. imageW (0),
  34405. imageH (0),
  34406. normalImage (0),
  34407. overImage (0),
  34408. downImage (0)
  34409. {
  34410. }
  34411. ImageButton::~ImageButton()
  34412. {
  34413. deleteImages();
  34414. }
  34415. void ImageButton::deleteImages()
  34416. {
  34417. ImageCache::releaseOrDelete (normalImage);
  34418. ImageCache::releaseOrDelete (overImage);
  34419. ImageCache::releaseOrDelete (downImage);
  34420. }
  34421. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34422. const bool rescaleImagesWhenButtonSizeChanges,
  34423. const bool preserveImageProportions,
  34424. Image* const normalImage_,
  34425. const float imageOpacityWhenNormal,
  34426. const Colour& overlayColourWhenNormal,
  34427. Image* const overImage_,
  34428. const float imageOpacityWhenOver,
  34429. const Colour& overlayColourWhenOver,
  34430. Image* const downImage_,
  34431. const float imageOpacityWhenDown,
  34432. const Colour& overlayColourWhenDown,
  34433. const float hitTestAlphaThreshold)
  34434. {
  34435. deleteImages();
  34436. normalImage = normalImage_;
  34437. overImage = overImage_;
  34438. downImage = downImage_;
  34439. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34440. {
  34441. imageW = normalImage->getWidth();
  34442. imageH = normalImage->getHeight();
  34443. setSize (imageW, imageH);
  34444. }
  34445. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34446. preserveProportions = preserveImageProportions;
  34447. normalOpacity = imageOpacityWhenNormal;
  34448. normalOverlay = overlayColourWhenNormal;
  34449. overOpacity = imageOpacityWhenOver;
  34450. overOverlay = overlayColourWhenOver;
  34451. downOpacity = imageOpacityWhenDown;
  34452. downOverlay = overlayColourWhenDown;
  34453. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34454. repaint();
  34455. }
  34456. Image* ImageButton::getCurrentImage() const
  34457. {
  34458. if (isDown() || getToggleState())
  34459. return getDownImage();
  34460. if (isOver())
  34461. return getOverImage();
  34462. return getNormalImage();
  34463. }
  34464. Image* ImageButton::getNormalImage() const throw()
  34465. {
  34466. return normalImage;
  34467. }
  34468. Image* ImageButton::getOverImage() const throw()
  34469. {
  34470. return (overImage != 0) ? overImage
  34471. : normalImage;
  34472. }
  34473. Image* ImageButton::getDownImage() const throw()
  34474. {
  34475. return (downImage != 0) ? downImage
  34476. : getOverImage();
  34477. }
  34478. void ImageButton::paintButton (Graphics& g,
  34479. bool isMouseOverButton,
  34480. bool isButtonDown)
  34481. {
  34482. if (! isEnabled())
  34483. {
  34484. isMouseOverButton = false;
  34485. isButtonDown = false;
  34486. }
  34487. Image* const im = getCurrentImage();
  34488. if (im != 0)
  34489. {
  34490. const int iw = im->getWidth();
  34491. const int ih = im->getHeight();
  34492. imageW = getWidth();
  34493. imageH = getHeight();
  34494. imageX = (imageW - iw) >> 1;
  34495. imageY = (imageH - ih) >> 1;
  34496. if (scaleImageToFit)
  34497. {
  34498. if (preserveProportions)
  34499. {
  34500. int newW, newH;
  34501. const float imRatio = ih / (float)iw;
  34502. const float destRatio = imageH / (float)imageW;
  34503. if (imRatio > destRatio)
  34504. {
  34505. newW = roundToInt (imageH / imRatio);
  34506. newH = imageH;
  34507. }
  34508. else
  34509. {
  34510. newW = imageW;
  34511. newH = roundToInt (imageW * imRatio);
  34512. }
  34513. imageX = (imageW - newW) / 2;
  34514. imageY = (imageH - newH) / 2;
  34515. imageW = newW;
  34516. imageH = newH;
  34517. }
  34518. else
  34519. {
  34520. imageX = 0;
  34521. imageY = 0;
  34522. }
  34523. }
  34524. if (! scaleImageToFit)
  34525. {
  34526. imageW = iw;
  34527. imageH = ih;
  34528. }
  34529. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  34530. isButtonDown ? downOverlay
  34531. : (isMouseOverButton ? overOverlay
  34532. : normalOverlay),
  34533. isButtonDown ? downOpacity
  34534. : (isMouseOverButton ? overOpacity
  34535. : normalOpacity),
  34536. *this);
  34537. }
  34538. }
  34539. bool ImageButton::hitTest (int x, int y)
  34540. {
  34541. if (alphaThreshold == 0)
  34542. return true;
  34543. Image* const im = getCurrentImage();
  34544. return im == 0
  34545. || (imageW > 0 && imageH > 0
  34546. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  34547. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  34548. }
  34549. END_JUCE_NAMESPACE
  34550. /*** End of inlined file: juce_ImageButton.cpp ***/
  34551. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  34552. BEGIN_JUCE_NAMESPACE
  34553. ShapeButton::ShapeButton (const String& text_,
  34554. const Colour& normalColour_,
  34555. const Colour& overColour_,
  34556. const Colour& downColour_)
  34557. : Button (text_),
  34558. normalColour (normalColour_),
  34559. overColour (overColour_),
  34560. downColour (downColour_),
  34561. maintainShapeProportions (false),
  34562. outlineWidth (0.0f)
  34563. {
  34564. }
  34565. ShapeButton::~ShapeButton()
  34566. {
  34567. }
  34568. void ShapeButton::setColours (const Colour& newNormalColour,
  34569. const Colour& newOverColour,
  34570. const Colour& newDownColour)
  34571. {
  34572. normalColour = newNormalColour;
  34573. overColour = newOverColour;
  34574. downColour = newDownColour;
  34575. }
  34576. void ShapeButton::setOutline (const Colour& newOutlineColour,
  34577. const float newOutlineWidth)
  34578. {
  34579. outlineColour = newOutlineColour;
  34580. outlineWidth = newOutlineWidth;
  34581. }
  34582. void ShapeButton::setShape (const Path& newShape,
  34583. const bool resizeNowToFitThisShape,
  34584. const bool maintainShapeProportions_,
  34585. const bool hasShadow)
  34586. {
  34587. shape = newShape;
  34588. maintainShapeProportions = maintainShapeProportions_;
  34589. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  34590. setComponentEffect ((hasShadow) ? &shadow : 0);
  34591. if (resizeNowToFitThisShape)
  34592. {
  34593. Rectangle<float> bounds (shape.getBounds());
  34594. if (hasShadow)
  34595. bounds.expand (4.0f, 4.0f);
  34596. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  34597. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  34598. 1 + (int) (bounds.getHeight() + outlineWidth));
  34599. }
  34600. }
  34601. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  34602. {
  34603. if (! isEnabled())
  34604. {
  34605. isMouseOverButton = false;
  34606. isButtonDown = false;
  34607. }
  34608. g.setColour ((isButtonDown) ? downColour
  34609. : (isMouseOverButton) ? overColour
  34610. : normalColour);
  34611. int w = getWidth();
  34612. int h = getHeight();
  34613. if (getComponentEffect() != 0)
  34614. {
  34615. w -= 4;
  34616. h -= 4;
  34617. }
  34618. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  34619. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  34620. w - offset - outlineWidth,
  34621. h - offset - outlineWidth,
  34622. maintainShapeProportions));
  34623. g.fillPath (shape, trans);
  34624. if (outlineWidth > 0.0f)
  34625. {
  34626. g.setColour (outlineColour);
  34627. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  34628. }
  34629. }
  34630. END_JUCE_NAMESPACE
  34631. /*** End of inlined file: juce_ShapeButton.cpp ***/
  34632. /*** Start of inlined file: juce_TextButton.cpp ***/
  34633. BEGIN_JUCE_NAMESPACE
  34634. TextButton::TextButton (const String& name,
  34635. const String& toolTip)
  34636. : Button (name)
  34637. {
  34638. setTooltip (toolTip);
  34639. }
  34640. TextButton::~TextButton()
  34641. {
  34642. }
  34643. void TextButton::paintButton (Graphics& g,
  34644. bool isMouseOverButton,
  34645. bool isButtonDown)
  34646. {
  34647. getLookAndFeel().drawButtonBackground (g, *this,
  34648. findColour (getToggleState() ? buttonOnColourId
  34649. : buttonColourId),
  34650. isMouseOverButton,
  34651. isButtonDown);
  34652. getLookAndFeel().drawButtonText (g, *this,
  34653. isMouseOverButton,
  34654. isButtonDown);
  34655. }
  34656. void TextButton::colourChanged()
  34657. {
  34658. repaint();
  34659. }
  34660. const Font TextButton::getFont()
  34661. {
  34662. return Font (jmin (15.0f, getHeight() * 0.6f));
  34663. }
  34664. void TextButton::changeWidthToFitText (const int newHeight)
  34665. {
  34666. if (newHeight >= 0)
  34667. setSize (jmax (1, getWidth()), newHeight);
  34668. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  34669. getHeight());
  34670. }
  34671. END_JUCE_NAMESPACE
  34672. /*** End of inlined file: juce_TextButton.cpp ***/
  34673. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  34674. BEGIN_JUCE_NAMESPACE
  34675. ToggleButton::ToggleButton (const String& buttonText)
  34676. : Button (buttonText)
  34677. {
  34678. setClickingTogglesState (true);
  34679. }
  34680. ToggleButton::~ToggleButton()
  34681. {
  34682. }
  34683. void ToggleButton::paintButton (Graphics& g,
  34684. bool isMouseOverButton,
  34685. bool isButtonDown)
  34686. {
  34687. getLookAndFeel().drawToggleButton (g, *this,
  34688. isMouseOverButton,
  34689. isButtonDown);
  34690. }
  34691. void ToggleButton::changeWidthToFitText()
  34692. {
  34693. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  34694. }
  34695. void ToggleButton::colourChanged()
  34696. {
  34697. repaint();
  34698. }
  34699. END_JUCE_NAMESPACE
  34700. /*** End of inlined file: juce_ToggleButton.cpp ***/
  34701. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  34702. BEGIN_JUCE_NAMESPACE
  34703. ToolbarButton::ToolbarButton (const int itemId_,
  34704. const String& buttonText,
  34705. Drawable* const normalImage_,
  34706. Drawable* const toggledOnImage_)
  34707. : ToolbarItemComponent (itemId_, buttonText, true),
  34708. normalImage (normalImage_),
  34709. toggledOnImage (toggledOnImage_)
  34710. {
  34711. }
  34712. ToolbarButton::~ToolbarButton()
  34713. {
  34714. }
  34715. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  34716. bool /*isToolbarVertical*/,
  34717. int& preferredSize,
  34718. int& minSize, int& maxSize)
  34719. {
  34720. preferredSize = minSize = maxSize = toolbarDepth;
  34721. return true;
  34722. }
  34723. void ToolbarButton::paintButtonArea (Graphics& g,
  34724. int width, int height,
  34725. bool /*isMouseOver*/,
  34726. bool /*isMouseDown*/)
  34727. {
  34728. Drawable* d = normalImage;
  34729. if (getToggleState() && toggledOnImage != 0)
  34730. d = toggledOnImage;
  34731. if (! isEnabled())
  34732. {
  34733. Image im (Image::ARGB, width, height, true);
  34734. Graphics g2 (im);
  34735. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34736. im.desaturate();
  34737. g.drawImageAt (&im, 0, 0);
  34738. }
  34739. else
  34740. {
  34741. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34742. }
  34743. }
  34744. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  34745. {
  34746. }
  34747. END_JUCE_NAMESPACE
  34748. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  34749. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  34750. BEGIN_JUCE_NAMESPACE
  34751. class CodeDocumentLine
  34752. {
  34753. public:
  34754. CodeDocumentLine (const tchar* const line_,
  34755. const int lineLength_,
  34756. const int numNewLineChars,
  34757. const int lineStartInFile_)
  34758. : line (line_, lineLength_),
  34759. lineStartInFile (lineStartInFile_),
  34760. lineLength (lineLength_),
  34761. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  34762. {
  34763. }
  34764. ~CodeDocumentLine()
  34765. {
  34766. }
  34767. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  34768. {
  34769. const tchar* const t = (const tchar*) text;
  34770. int pos = 0;
  34771. while (t [pos] != 0)
  34772. {
  34773. const int startOfLine = pos;
  34774. int numNewLineChars = 0;
  34775. while (t[pos] != 0)
  34776. {
  34777. if (t[pos] == T('\r'))
  34778. {
  34779. ++numNewLineChars;
  34780. ++pos;
  34781. if (t[pos] == T('\n'))
  34782. {
  34783. ++numNewLineChars;
  34784. ++pos;
  34785. }
  34786. break;
  34787. }
  34788. if (t[pos] == T('\n'))
  34789. {
  34790. ++numNewLineChars;
  34791. ++pos;
  34792. break;
  34793. }
  34794. ++pos;
  34795. }
  34796. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  34797. numNewLineChars, startOfLine));
  34798. }
  34799. jassert (pos == text.length());
  34800. }
  34801. bool endsWithLineBreak() const throw()
  34802. {
  34803. return lineLengthWithoutNewLines != lineLength;
  34804. }
  34805. void updateLength() throw()
  34806. {
  34807. lineLengthWithoutNewLines = lineLength = line.length();
  34808. while (lineLengthWithoutNewLines > 0
  34809. && (line [lineLengthWithoutNewLines - 1] == '\n'
  34810. || line [lineLengthWithoutNewLines - 1] == '\r'))
  34811. {
  34812. --lineLengthWithoutNewLines;
  34813. }
  34814. }
  34815. String line;
  34816. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  34817. };
  34818. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  34819. : document (document_),
  34820. currentLine (document_->lines[0]),
  34821. line (0),
  34822. position (0)
  34823. {
  34824. }
  34825. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  34826. : document (other.document),
  34827. currentLine (other.currentLine),
  34828. line (other.line),
  34829. position (other.position)
  34830. {
  34831. }
  34832. CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  34833. {
  34834. document = other.document;
  34835. currentLine = other.currentLine;
  34836. line = other.line;
  34837. position = other.position;
  34838. return *this;
  34839. }
  34840. CodeDocument::Iterator::~Iterator() throw()
  34841. {
  34842. }
  34843. juce_wchar CodeDocument::Iterator::nextChar()
  34844. {
  34845. if (currentLine == 0)
  34846. return 0;
  34847. jassert (currentLine == document->lines.getUnchecked (line));
  34848. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  34849. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34850. {
  34851. ++line;
  34852. currentLine = document->lines [line];
  34853. }
  34854. return result;
  34855. }
  34856. void CodeDocument::Iterator::skip()
  34857. {
  34858. if (currentLine != 0)
  34859. {
  34860. jassert (currentLine == document->lines.getUnchecked (line));
  34861. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34862. {
  34863. ++line;
  34864. currentLine = document->lines [line];
  34865. }
  34866. }
  34867. }
  34868. void CodeDocument::Iterator::skipToEndOfLine()
  34869. {
  34870. if (currentLine != 0)
  34871. {
  34872. jassert (currentLine == document->lines.getUnchecked (line));
  34873. ++line;
  34874. currentLine = document->lines [line];
  34875. if (currentLine != 0)
  34876. position = currentLine->lineStartInFile;
  34877. else
  34878. position = document->getNumCharacters();
  34879. }
  34880. }
  34881. juce_wchar CodeDocument::Iterator::peekNextChar() const
  34882. {
  34883. if (currentLine == 0)
  34884. return 0;
  34885. jassert (currentLine == document->lines.getUnchecked (line));
  34886. return const_cast <const String&> (currentLine->line) [position - currentLine->lineStartInFile];
  34887. }
  34888. void CodeDocument::Iterator::skipWhitespace()
  34889. {
  34890. while (CharacterFunctions::isWhitespace (peekNextChar()))
  34891. skip();
  34892. }
  34893. bool CodeDocument::Iterator::isEOF() const throw()
  34894. {
  34895. return currentLine == 0;
  34896. }
  34897. CodeDocument::Position::Position() throw()
  34898. : owner (0), characterPos (0), line (0),
  34899. indexInLine (0), positionMaintained (false)
  34900. {
  34901. }
  34902. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34903. const int line_, const int indexInLine_) throw()
  34904. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34905. characterPos (0), line (line_),
  34906. indexInLine (indexInLine_), positionMaintained (false)
  34907. {
  34908. setLineAndIndex (line_, indexInLine_);
  34909. }
  34910. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34911. const int characterPos_) throw()
  34912. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34913. positionMaintained (false)
  34914. {
  34915. setPosition (characterPos_);
  34916. }
  34917. CodeDocument::Position::Position (const Position& other) throw()
  34918. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  34919. indexInLine (other.indexInLine), positionMaintained (false)
  34920. {
  34921. jassert (*this == other);
  34922. }
  34923. CodeDocument::Position::~Position() throw()
  34924. {
  34925. setPositionMaintained (false);
  34926. }
  34927. CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  34928. {
  34929. if (this != &other)
  34930. {
  34931. const bool wasPositionMaintained = positionMaintained;
  34932. if (owner != other.owner)
  34933. setPositionMaintained (false);
  34934. owner = other.owner;
  34935. line = other.line;
  34936. indexInLine = other.indexInLine;
  34937. characterPos = other.characterPos;
  34938. setPositionMaintained (wasPositionMaintained);
  34939. jassert (*this == other);
  34940. }
  34941. return *this;
  34942. }
  34943. bool CodeDocument::Position::operator== (const Position& other) const throw()
  34944. {
  34945. jassert ((characterPos == other.characterPos)
  34946. == (line == other.line && indexInLine == other.indexInLine));
  34947. return characterPos == other.characterPos
  34948. && line == other.line
  34949. && indexInLine == other.indexInLine
  34950. && owner == other.owner;
  34951. }
  34952. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  34953. {
  34954. return ! operator== (other);
  34955. }
  34956. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  34957. {
  34958. jassert (owner != 0);
  34959. if (owner->lines.size() == 0)
  34960. {
  34961. line = 0;
  34962. indexInLine = 0;
  34963. characterPos = 0;
  34964. }
  34965. else
  34966. {
  34967. if (newLine >= owner->lines.size())
  34968. {
  34969. line = owner->lines.size() - 1;
  34970. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34971. jassert (l != 0);
  34972. indexInLine = l->lineLengthWithoutNewLines;
  34973. characterPos = l->lineStartInFile + indexInLine;
  34974. }
  34975. else
  34976. {
  34977. line = jmax (0, newLine);
  34978. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34979. jassert (l != 0);
  34980. if (l->lineLengthWithoutNewLines > 0)
  34981. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  34982. else
  34983. indexInLine = 0;
  34984. characterPos = l->lineStartInFile + indexInLine;
  34985. }
  34986. }
  34987. }
  34988. void CodeDocument::Position::setPosition (const int newPosition) throw()
  34989. {
  34990. jassert (owner != 0);
  34991. line = 0;
  34992. indexInLine = 0;
  34993. characterPos = 0;
  34994. if (newPosition > 0)
  34995. {
  34996. int lineStart = 0;
  34997. int lineEnd = owner->lines.size();
  34998. for (;;)
  34999. {
  35000. if (lineEnd - lineStart < 4)
  35001. {
  35002. for (int i = lineStart; i < lineEnd; ++i)
  35003. {
  35004. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35005. int index = newPosition - l->lineStartInFile;
  35006. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35007. {
  35008. line = i;
  35009. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35010. characterPos = l->lineStartInFile + indexInLine;
  35011. }
  35012. }
  35013. break;
  35014. }
  35015. else
  35016. {
  35017. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35018. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35019. if (newPosition >= mid->lineStartInFile)
  35020. lineStart = midIndex;
  35021. else
  35022. lineEnd = midIndex;
  35023. }
  35024. }
  35025. }
  35026. }
  35027. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35028. {
  35029. jassert (owner != 0);
  35030. if (characterDelta == 1)
  35031. {
  35032. setPosition (getPosition());
  35033. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35034. if (line < owner->lines.size())
  35035. {
  35036. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35037. if (indexInLine + characterDelta < l->lineLength
  35038. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35039. ++characterDelta;
  35040. }
  35041. }
  35042. setPosition (characterPos + characterDelta);
  35043. }
  35044. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35045. {
  35046. CodeDocument::Position p (*this);
  35047. p.moveBy (characterDelta);
  35048. return p;
  35049. }
  35050. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35051. {
  35052. CodeDocument::Position p (*this);
  35053. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35054. return p;
  35055. }
  35056. const tchar CodeDocument::Position::getCharacter() const throw()
  35057. {
  35058. const CodeDocumentLine* const l = owner->lines [line];
  35059. return l == 0 ? 0 : l->line [getIndexInLine()];
  35060. }
  35061. const String CodeDocument::Position::getLineText() const throw()
  35062. {
  35063. const CodeDocumentLine* const l = owner->lines [line];
  35064. return l == 0 ? String::empty : l->line;
  35065. }
  35066. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35067. {
  35068. if (isMaintained != positionMaintained)
  35069. {
  35070. positionMaintained = isMaintained;
  35071. if (owner != 0)
  35072. {
  35073. if (isMaintained)
  35074. {
  35075. jassert (! owner->positionsToMaintain.contains (this));
  35076. owner->positionsToMaintain.add (this);
  35077. }
  35078. else
  35079. {
  35080. jassert (owner->positionsToMaintain.contains (this));
  35081. owner->positionsToMaintain.removeValue (this);
  35082. }
  35083. }
  35084. }
  35085. }
  35086. CodeDocument::CodeDocument()
  35087. : undoManager (std::numeric_limits<int>::max(), 10000),
  35088. currentActionIndex (0),
  35089. indexOfSavedState (-1),
  35090. maximumLineLength (-1),
  35091. newLineChars ("\r\n")
  35092. {
  35093. }
  35094. CodeDocument::~CodeDocument()
  35095. {
  35096. }
  35097. const String CodeDocument::getAllContent() const throw()
  35098. {
  35099. return getTextBetween (Position (this, 0),
  35100. Position (this, lines.size(), 0));
  35101. }
  35102. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35103. {
  35104. if (end.getPosition() <= start.getPosition())
  35105. return String::empty;
  35106. const int startLine = start.getLineNumber();
  35107. const int endLine = end.getLineNumber();
  35108. if (startLine == endLine)
  35109. {
  35110. CodeDocumentLine* const line = lines [startLine];
  35111. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35112. }
  35113. String result;
  35114. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35115. String::Concatenator concatenator (result);
  35116. const int maxLine = jmin (lines.size() - 1, endLine);
  35117. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35118. {
  35119. const CodeDocumentLine* line = lines.getUnchecked(i);
  35120. int len = line->lineLength;
  35121. if (i == startLine)
  35122. {
  35123. const int index = start.getIndexInLine();
  35124. concatenator.append (line->line.substring (index, len));
  35125. }
  35126. else if (i == endLine)
  35127. {
  35128. len = end.getIndexInLine();
  35129. concatenator.append (line->line.substring (0, len));
  35130. }
  35131. else
  35132. {
  35133. concatenator.append (line->line);
  35134. }
  35135. }
  35136. return result;
  35137. }
  35138. int CodeDocument::getNumCharacters() const throw()
  35139. {
  35140. const CodeDocumentLine* const lastLine = lines.getLast();
  35141. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35142. }
  35143. const String CodeDocument::getLine (const int lineIndex) const throw()
  35144. {
  35145. const CodeDocumentLine* const line = lines [lineIndex];
  35146. return (line == 0) ? String::empty : line->line;
  35147. }
  35148. int CodeDocument::getMaximumLineLength() throw()
  35149. {
  35150. if (maximumLineLength < 0)
  35151. {
  35152. maximumLineLength = 0;
  35153. for (int i = lines.size(); --i >= 0;)
  35154. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35155. }
  35156. return maximumLineLength;
  35157. }
  35158. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35159. {
  35160. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35161. }
  35162. void CodeDocument::insertText (const Position& position, const String& text)
  35163. {
  35164. insert (text, position.getPosition(), true);
  35165. }
  35166. void CodeDocument::replaceAllContent (const String& newContent)
  35167. {
  35168. remove (0, getNumCharacters(), true);
  35169. insert (newContent, 0, true);
  35170. }
  35171. bool CodeDocument::loadFromStream (InputStream& stream)
  35172. {
  35173. replaceAllContent (stream.readEntireStreamAsString());
  35174. setSavePoint();
  35175. clearUndoHistory();
  35176. return true;
  35177. }
  35178. bool CodeDocument::writeToStream (OutputStream& stream)
  35179. {
  35180. for (int i = 0; i < lines.size(); ++i)
  35181. {
  35182. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35183. const char* utf8 = temp.toUTF8();
  35184. if (! stream.write (utf8, (int) strlen (utf8)))
  35185. return false;
  35186. }
  35187. return true;
  35188. }
  35189. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35190. {
  35191. jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));
  35192. newLineChars = newLine;
  35193. }
  35194. void CodeDocument::newTransaction()
  35195. {
  35196. undoManager.beginNewTransaction (String::empty);
  35197. }
  35198. void CodeDocument::undo()
  35199. {
  35200. newTransaction();
  35201. undoManager.undo();
  35202. }
  35203. void CodeDocument::redo()
  35204. {
  35205. undoManager.redo();
  35206. }
  35207. void CodeDocument::clearUndoHistory()
  35208. {
  35209. undoManager.clearUndoHistory();
  35210. }
  35211. void CodeDocument::setSavePoint() throw()
  35212. {
  35213. indexOfSavedState = currentActionIndex;
  35214. }
  35215. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35216. {
  35217. return currentActionIndex != indexOfSavedState;
  35218. }
  35219. static int getCodeCharacterCategory (const tchar character) throw()
  35220. {
  35221. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35222. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35223. }
  35224. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35225. {
  35226. Position p (position);
  35227. const int maxDistance = 256;
  35228. int i = 0;
  35229. while (i < maxDistance
  35230. && CharacterFunctions::isWhitespace (p.getCharacter())
  35231. && (i == 0 || (p.getCharacter() != T('\n')
  35232. && p.getCharacter() != T('\r'))))
  35233. {
  35234. ++i;
  35235. p.moveBy (1);
  35236. }
  35237. if (i == 0)
  35238. {
  35239. const int type = getCodeCharacterCategory (p.getCharacter());
  35240. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35241. {
  35242. ++i;
  35243. p.moveBy (1);
  35244. }
  35245. while (i < maxDistance
  35246. && CharacterFunctions::isWhitespace (p.getCharacter())
  35247. && (i == 0 || (p.getCharacter() != T('\n')
  35248. && p.getCharacter() != T('\r'))))
  35249. {
  35250. ++i;
  35251. p.moveBy (1);
  35252. }
  35253. }
  35254. return p;
  35255. }
  35256. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35257. {
  35258. Position p (position);
  35259. const int maxDistance = 256;
  35260. int i = 0;
  35261. bool stoppedAtLineStart = false;
  35262. while (i < maxDistance)
  35263. {
  35264. const tchar c = p.movedBy (-1).getCharacter();
  35265. if (c == T('\r') || c == T('\n'))
  35266. {
  35267. stoppedAtLineStart = true;
  35268. if (i > 0)
  35269. break;
  35270. }
  35271. if (! CharacterFunctions::isWhitespace (c))
  35272. break;
  35273. p.moveBy (-1);
  35274. ++i;
  35275. }
  35276. if (i < maxDistance && ! stoppedAtLineStart)
  35277. {
  35278. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35279. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35280. {
  35281. p.moveBy (-1);
  35282. ++i;
  35283. }
  35284. }
  35285. return p;
  35286. }
  35287. void CodeDocument::checkLastLineStatus()
  35288. {
  35289. while (lines.size() > 0
  35290. && lines.getLast()->lineLength == 0
  35291. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35292. {
  35293. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35294. lines.removeLast();
  35295. }
  35296. const CodeDocumentLine* const lastLine = lines.getLast();
  35297. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35298. {
  35299. // check that there's an empty line at the end if the preceding one ends in a newline..
  35300. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35301. }
  35302. }
  35303. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35304. {
  35305. listeners.addIfNotAlreadyThere (listener);
  35306. }
  35307. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35308. {
  35309. listeners.removeValue (listener);
  35310. }
  35311. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35312. {
  35313. const Position startPos (this, startLine, 0);
  35314. const Position endPos (this, endLine, 0);
  35315. for (int i = listeners.size(); --i >= 0;)
  35316. {
  35317. Listener* const l = (Listener*) listeners[i];
  35318. if (l != 0)
  35319. l->codeDocumentChanged (startPos, endPos);
  35320. }
  35321. }
  35322. class CodeDocumentInsertAction : public UndoableAction
  35323. {
  35324. CodeDocument& owner;
  35325. const String text;
  35326. int insertPos;
  35327. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35328. CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35329. public:
  35330. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35331. : owner (owner_),
  35332. text (text_),
  35333. insertPos (insertPos_)
  35334. {
  35335. }
  35336. ~CodeDocumentInsertAction() {}
  35337. bool perform()
  35338. {
  35339. owner.currentActionIndex++;
  35340. owner.insert (text, insertPos, false);
  35341. return true;
  35342. }
  35343. bool undo()
  35344. {
  35345. owner.currentActionIndex--;
  35346. owner.remove (insertPos, insertPos + text.length(), false);
  35347. return true;
  35348. }
  35349. int getSizeInUnits() { return text.length() + 32; }
  35350. };
  35351. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35352. {
  35353. if (text.isEmpty())
  35354. return;
  35355. if (undoable)
  35356. {
  35357. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35358. }
  35359. else
  35360. {
  35361. Position pos (this, insertPos);
  35362. const int firstAffectedLine = pos.getLineNumber();
  35363. int lastAffectedLine = firstAffectedLine + 1;
  35364. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35365. String textInsideOriginalLine (text);
  35366. if (firstLine != 0)
  35367. {
  35368. const int index = pos.getIndexInLine();
  35369. textInsideOriginalLine = firstLine->line.substring (0, index)
  35370. + textInsideOriginalLine
  35371. + firstLine->line.substring (index);
  35372. }
  35373. maximumLineLength = -1;
  35374. Array <CodeDocumentLine*> newLines;
  35375. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35376. jassert (newLines.size() > 0);
  35377. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35378. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35379. lines.set (firstAffectedLine, newFirstLine);
  35380. if (newLines.size() > 1)
  35381. {
  35382. for (int i = 1; i < newLines.size(); ++i)
  35383. {
  35384. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35385. lines.insert (firstAffectedLine + i, l);
  35386. }
  35387. lastAffectedLine = lines.size();
  35388. }
  35389. int i, lineStart = newFirstLine->lineStartInFile;
  35390. for (i = firstAffectedLine; i < lines.size(); ++i)
  35391. {
  35392. CodeDocumentLine* const l = lines.getUnchecked (i);
  35393. l->lineStartInFile = lineStart;
  35394. lineStart += l->lineLength;
  35395. }
  35396. checkLastLineStatus();
  35397. const int newTextLength = text.length();
  35398. for (i = 0; i < positionsToMaintain.size(); ++i)
  35399. {
  35400. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35401. if (p->getPosition() >= insertPos)
  35402. p->setPosition (p->getPosition() + newTextLength);
  35403. }
  35404. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35405. }
  35406. }
  35407. class CodeDocumentDeleteAction : public UndoableAction
  35408. {
  35409. CodeDocument& owner;
  35410. int startPos, endPos;
  35411. String removedText;
  35412. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35413. CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35414. public:
  35415. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35416. : owner (owner_),
  35417. startPos (startPos_),
  35418. endPos (endPos_)
  35419. {
  35420. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35421. CodeDocument::Position (&owner, endPos));
  35422. }
  35423. ~CodeDocumentDeleteAction() {}
  35424. bool perform()
  35425. {
  35426. owner.currentActionIndex++;
  35427. owner.remove (startPos, endPos, false);
  35428. return true;
  35429. }
  35430. bool undo()
  35431. {
  35432. owner.currentActionIndex--;
  35433. owner.insert (removedText, startPos, false);
  35434. return true;
  35435. }
  35436. int getSizeInUnits() { return removedText.length() + 32; }
  35437. };
  35438. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35439. {
  35440. if (endPos <= startPos)
  35441. return;
  35442. if (undoable)
  35443. {
  35444. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35445. }
  35446. else
  35447. {
  35448. Position startPosition (this, startPos);
  35449. Position endPosition (this, endPos);
  35450. maximumLineLength = -1;
  35451. const int firstAffectedLine = startPosition.getLineNumber();
  35452. const int endLine = endPosition.getLineNumber();
  35453. int lastAffectedLine = firstAffectedLine + 1;
  35454. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35455. if (firstAffectedLine == endLine)
  35456. {
  35457. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35458. + firstLine->line.substring (endPosition.getIndexInLine());
  35459. firstLine->updateLength();
  35460. }
  35461. else
  35462. {
  35463. lastAffectedLine = lines.size();
  35464. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35465. jassert (lastLine != 0);
  35466. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35467. + lastLine->line.substring (endPosition.getIndexInLine());
  35468. firstLine->updateLength();
  35469. int numLinesToRemove = endLine - firstAffectedLine;
  35470. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  35471. }
  35472. int i;
  35473. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  35474. {
  35475. CodeDocumentLine* const l = lines.getUnchecked (i);
  35476. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  35477. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  35478. }
  35479. checkLastLineStatus();
  35480. const int totalChars = getNumCharacters();
  35481. for (i = 0; i < positionsToMaintain.size(); ++i)
  35482. {
  35483. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  35484. if (p->getPosition() > startPosition.getPosition())
  35485. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  35486. if (p->getPosition() > totalChars)
  35487. p->setPosition (totalChars);
  35488. }
  35489. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35490. }
  35491. }
  35492. END_JUCE_NAMESPACE
  35493. /*** End of inlined file: juce_CodeDocument.cpp ***/
  35494. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  35495. BEGIN_JUCE_NAMESPACE
  35496. class CaretComponent : public Component,
  35497. public Timer
  35498. {
  35499. public:
  35500. CaretComponent()
  35501. {
  35502. setAlwaysOnTop (true);
  35503. setInterceptsMouseClicks (false, false);
  35504. }
  35505. ~CaretComponent()
  35506. {
  35507. }
  35508. void paint (Graphics& g)
  35509. {
  35510. if (getParentComponent()->hasKeyboardFocus (true))
  35511. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  35512. }
  35513. void timerCallback()
  35514. {
  35515. setVisible (! isVisible());
  35516. }
  35517. void updatePosition (CodeEditorComponent& owner)
  35518. {
  35519. startTimer (400);
  35520. setVisible (true);
  35521. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  35522. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  35523. }
  35524. };
  35525. class CodeEditorComponent::CodeEditorLine
  35526. {
  35527. public:
  35528. CodeEditorLine() throw()
  35529. {
  35530. }
  35531. ~CodeEditorLine() throw()
  35532. {
  35533. }
  35534. bool update (CodeDocument& document, int lineNum,
  35535. CodeDocument::Iterator& source,
  35536. CodeTokeniser* analyser, const int spacesPerTab,
  35537. const CodeDocument::Position& selectionStart,
  35538. const CodeDocument::Position& selectionEnd)
  35539. {
  35540. Array <SyntaxToken> newTokens;
  35541. newTokens.ensureStorageAllocated (8);
  35542. if (analyser == 0)
  35543. {
  35544. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  35545. }
  35546. else if (lineNum < document.getNumLines())
  35547. {
  35548. const CodeDocument::Position pos (&document, lineNum, 0);
  35549. createTokens (pos.getPosition(), pos.getLineText(),
  35550. source, analyser, newTokens);
  35551. }
  35552. replaceTabsWithSpaces (newTokens, spacesPerTab);
  35553. int newHighlightStart = 0;
  35554. int newHighlightEnd = 0;
  35555. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  35556. {
  35557. const String line (document.getLine (lineNum));
  35558. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  35559. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  35560. line, spacesPerTab);
  35561. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  35562. line, spacesPerTab);
  35563. }
  35564. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  35565. {
  35566. highlightColumnStart = newHighlightStart;
  35567. highlightColumnEnd = newHighlightEnd;
  35568. }
  35569. else
  35570. {
  35571. if (tokens.size() == newTokens.size())
  35572. {
  35573. bool allTheSame = true;
  35574. for (int i = newTokens.size(); --i >= 0;)
  35575. {
  35576. if (tokens.getReference(i) != newTokens.getReference(i))
  35577. {
  35578. allTheSame = false;
  35579. break;
  35580. }
  35581. }
  35582. if (allTheSame)
  35583. return false;
  35584. }
  35585. }
  35586. tokens.swapWithArray (newTokens);
  35587. return true;
  35588. }
  35589. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  35590. float x, const int y, const int baselineOffset, const int lineHeight,
  35591. const Colour& highlightColour) const throw()
  35592. {
  35593. if (highlightColumnStart < highlightColumnEnd)
  35594. {
  35595. g.setColour (highlightColour);
  35596. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  35597. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  35598. }
  35599. int lastType = std::numeric_limits<int>::min();
  35600. for (int i = 0; i < tokens.size(); ++i)
  35601. {
  35602. SyntaxToken& token = tokens.getReference(i);
  35603. if (lastType != token.tokenType)
  35604. {
  35605. lastType = token.tokenType;
  35606. g.setColour (owner.getColourForTokenType (lastType));
  35607. }
  35608. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  35609. if (i < tokens.size() - 1)
  35610. {
  35611. if (token.width < 0)
  35612. token.width = font.getStringWidthFloat (token.text);
  35613. x += token.width;
  35614. }
  35615. }
  35616. }
  35617. private:
  35618. struct SyntaxToken
  35619. {
  35620. String text;
  35621. int tokenType;
  35622. float width;
  35623. SyntaxToken (const String& text_, const int type) throw()
  35624. : text (text_), tokenType (type), width (-1.0f)
  35625. {
  35626. }
  35627. bool operator!= (const SyntaxToken& other) const throw()
  35628. {
  35629. return text != other.text || tokenType != other.tokenType;
  35630. }
  35631. };
  35632. Array <SyntaxToken> tokens;
  35633. int highlightColumnStart, highlightColumnEnd;
  35634. static void createTokens (int startPosition, const String& lineText,
  35635. CodeDocument::Iterator& source,
  35636. CodeTokeniser* analyser,
  35637. Array <SyntaxToken>& newTokens)
  35638. {
  35639. CodeDocument::Iterator lastIterator (source);
  35640. const int lineLength = lineText.length();
  35641. for (;;)
  35642. {
  35643. int tokenType = analyser->readNextToken (source);
  35644. int tokenStart = lastIterator.getPosition();
  35645. int tokenEnd = source.getPosition();
  35646. if (tokenEnd <= tokenStart)
  35647. break;
  35648. tokenEnd -= startPosition;
  35649. if (tokenEnd > 0)
  35650. {
  35651. tokenStart -= startPosition;
  35652. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  35653. tokenType));
  35654. if (tokenEnd >= lineLength)
  35655. break;
  35656. }
  35657. lastIterator = source;
  35658. }
  35659. source = lastIterator;
  35660. }
  35661. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  35662. {
  35663. int x = 0;
  35664. for (int i = 0; i < tokens.size(); ++i)
  35665. {
  35666. SyntaxToken& t = tokens.getReference(i);
  35667. for (;;)
  35668. {
  35669. int tabPos = t.text.indexOfChar (T('\t'));
  35670. if (tabPos < 0)
  35671. break;
  35672. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  35673. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (T(" "), spacesNeeded));
  35674. }
  35675. x += t.text.length();
  35676. }
  35677. }
  35678. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  35679. {
  35680. jassert (index <= line.length());
  35681. int col = 0;
  35682. for (int i = 0; i < index; ++i)
  35683. {
  35684. if (line[i] != T('\t'))
  35685. ++col;
  35686. else
  35687. col += spacesPerTab - (col % spacesPerTab);
  35688. }
  35689. return col;
  35690. }
  35691. };
  35692. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  35693. CodeTokeniser* const codeTokeniser_)
  35694. : document (document_),
  35695. firstLineOnScreen (0),
  35696. gutter (5),
  35697. spacesPerTab (4),
  35698. lineHeight (0),
  35699. linesOnScreen (0),
  35700. columnsOnScreen (0),
  35701. scrollbarThickness (16),
  35702. columnToTryToMaintain (-1),
  35703. useSpacesForTabs (false),
  35704. xOffset (0),
  35705. codeTokeniser (codeTokeniser_)
  35706. {
  35707. caretPos = CodeDocument::Position (&document_, 0, 0);
  35708. caretPos.setPositionMaintained (true);
  35709. selectionStart = CodeDocument::Position (&document_, 0, 0);
  35710. selectionStart.setPositionMaintained (true);
  35711. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  35712. selectionEnd.setPositionMaintained (true);
  35713. setOpaque (true);
  35714. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  35715. setWantsKeyboardFocus (true);
  35716. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  35717. verticalScrollBar->setSingleStepSize (1.0);
  35718. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  35719. horizontalScrollBar->setSingleStepSize (1.0);
  35720. addAndMakeVisible (caret = new CaretComponent());
  35721. Font f (12.0f);
  35722. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  35723. setFont (f);
  35724. resetToDefaultColours();
  35725. verticalScrollBar->addListener (this);
  35726. horizontalScrollBar->addListener (this);
  35727. document.addListener (this);
  35728. }
  35729. CodeEditorComponent::~CodeEditorComponent()
  35730. {
  35731. document.removeListener (this);
  35732. deleteAllChildren();
  35733. }
  35734. void CodeEditorComponent::loadContent (const String& newContent)
  35735. {
  35736. clearCachedIterators (0);
  35737. document.replaceAllContent (newContent);
  35738. document.clearUndoHistory();
  35739. document.setSavePoint();
  35740. caretPos.setPosition (0);
  35741. selectionStart.setPosition (0);
  35742. selectionEnd.setPosition (0);
  35743. scrollToLine (0);
  35744. }
  35745. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  35746. const CodeDocument::Position& affectedTextEnd)
  35747. {
  35748. clearCachedIterators (affectedTextStart.getLineNumber());
  35749. triggerAsyncUpdate();
  35750. ((CaretComponent*) caret)->updatePosition (*this);
  35751. columnToTryToMaintain = -1;
  35752. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  35753. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  35754. deselectAll();
  35755. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  35756. || caretPos.getPosition() < affectedTextStart.getPosition())
  35757. moveCaretTo (affectedTextStart, false);
  35758. updateScrollBars();
  35759. }
  35760. void CodeEditorComponent::resized()
  35761. {
  35762. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  35763. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  35764. lines.clear();
  35765. rebuildLineTokens();
  35766. ((CaretComponent*) caret)->updatePosition (*this);
  35767. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  35768. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  35769. updateScrollBars();
  35770. }
  35771. void CodeEditorComponent::paint (Graphics& g)
  35772. {
  35773. handleUpdateNowIfNeeded();
  35774. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  35775. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  35776. g.setFont (font);
  35777. const int baselineOffset = (int) font.getAscent();
  35778. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  35779. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  35780. const Rectangle<int> clip (g.getClipBounds());
  35781. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  35782. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  35783. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  35784. {
  35785. lines.getUnchecked(j)->draw (*this, g, font,
  35786. (float) (gutter - xOffset * charWidth),
  35787. lineHeight * j, baselineOffset, lineHeight,
  35788. highlightColour);
  35789. }
  35790. }
  35791. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  35792. {
  35793. if (scrollbarThickness != thickness)
  35794. {
  35795. scrollbarThickness = thickness;
  35796. resized();
  35797. }
  35798. }
  35799. void CodeEditorComponent::handleAsyncUpdate()
  35800. {
  35801. rebuildLineTokens();
  35802. }
  35803. void CodeEditorComponent::rebuildLineTokens()
  35804. {
  35805. cancelPendingUpdate();
  35806. const int numNeeded = linesOnScreen + 1;
  35807. int minLineToRepaint = numNeeded;
  35808. int maxLineToRepaint = 0;
  35809. if (numNeeded != lines.size())
  35810. {
  35811. lines.clear();
  35812. for (int i = numNeeded; --i >= 0;)
  35813. lines.add (new CodeEditorLine());
  35814. minLineToRepaint = 0;
  35815. maxLineToRepaint = numNeeded;
  35816. }
  35817. jassert (numNeeded == lines.size());
  35818. CodeDocument::Iterator source (&document);
  35819. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  35820. for (int i = 0; i < numNeeded; ++i)
  35821. {
  35822. CodeEditorLine* const line = lines.getUnchecked(i);
  35823. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  35824. selectionStart, selectionEnd))
  35825. {
  35826. minLineToRepaint = jmin (minLineToRepaint, i);
  35827. maxLineToRepaint = jmax (maxLineToRepaint, i);
  35828. }
  35829. }
  35830. if (minLineToRepaint <= maxLineToRepaint)
  35831. {
  35832. repaint (gutter, lineHeight * minLineToRepaint - 1,
  35833. verticalScrollBar->getX() - gutter,
  35834. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  35835. }
  35836. }
  35837. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  35838. {
  35839. caretPos = newPos;
  35840. columnToTryToMaintain = -1;
  35841. if (highlighting)
  35842. {
  35843. if (dragType == notDragging)
  35844. {
  35845. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  35846. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  35847. dragType = draggingSelectionStart;
  35848. else
  35849. dragType = draggingSelectionEnd;
  35850. }
  35851. if (dragType == draggingSelectionStart)
  35852. {
  35853. selectionStart = caretPos;
  35854. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35855. {
  35856. const CodeDocument::Position temp (selectionStart);
  35857. selectionStart = selectionEnd;
  35858. selectionEnd = temp;
  35859. dragType = draggingSelectionEnd;
  35860. }
  35861. }
  35862. else
  35863. {
  35864. selectionEnd = caretPos;
  35865. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35866. {
  35867. const CodeDocument::Position temp (selectionStart);
  35868. selectionStart = selectionEnd;
  35869. selectionEnd = temp;
  35870. dragType = draggingSelectionStart;
  35871. }
  35872. }
  35873. triggerAsyncUpdate();
  35874. }
  35875. else
  35876. {
  35877. deselectAll();
  35878. }
  35879. ((CaretComponent*) caret)->updatePosition (*this);
  35880. scrollToKeepCaretOnScreen();
  35881. updateScrollBars();
  35882. }
  35883. void CodeEditorComponent::deselectAll()
  35884. {
  35885. if (selectionStart != selectionEnd)
  35886. triggerAsyncUpdate();
  35887. selectionStart = caretPos;
  35888. selectionEnd = caretPos;
  35889. }
  35890. void CodeEditorComponent::updateScrollBars()
  35891. {
  35892. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  35893. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  35894. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  35895. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  35896. }
  35897. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  35898. {
  35899. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  35900. newFirstLineOnScreen);
  35901. if (newFirstLineOnScreen != firstLineOnScreen)
  35902. {
  35903. firstLineOnScreen = newFirstLineOnScreen;
  35904. ((CaretComponent*) caret)->updatePosition (*this);
  35905. updateCachedIterators (firstLineOnScreen);
  35906. triggerAsyncUpdate();
  35907. }
  35908. }
  35909. void CodeEditorComponent::scrollToColumnInternal (double column)
  35910. {
  35911. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  35912. if (xOffset != newOffset)
  35913. {
  35914. xOffset = newOffset;
  35915. ((CaretComponent*) caret)->updatePosition (*this);
  35916. repaint();
  35917. }
  35918. }
  35919. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  35920. {
  35921. scrollToLineInternal (newFirstLineOnScreen);
  35922. updateScrollBars();
  35923. }
  35924. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  35925. {
  35926. scrollToColumnInternal (newFirstColumnOnScreen);
  35927. updateScrollBars();
  35928. }
  35929. void CodeEditorComponent::scrollBy (int deltaLines)
  35930. {
  35931. scrollToLine (firstLineOnScreen + deltaLines);
  35932. }
  35933. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  35934. {
  35935. if (caretPos.getLineNumber() < firstLineOnScreen)
  35936. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  35937. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  35938. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  35939. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35940. if (column >= xOffset + columnsOnScreen - 1)
  35941. scrollToColumn (column + 1 - columnsOnScreen);
  35942. else if (column < xOffset)
  35943. scrollToColumn (column);
  35944. }
  35945. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  35946. {
  35947. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  35948. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  35949. roundToInt (charWidth),
  35950. lineHeight);
  35951. }
  35952. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  35953. {
  35954. const int line = y / lineHeight + firstLineOnScreen;
  35955. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  35956. const int index = columnToIndex (line, column);
  35957. return CodeDocument::Position (&document, line, index);
  35958. }
  35959. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  35960. {
  35961. document.deleteSection (selectionStart, selectionEnd);
  35962. if (newText.isNotEmpty())
  35963. document.insertText (caretPos, newText);
  35964. scrollToKeepCaretOnScreen();
  35965. }
  35966. void CodeEditorComponent::insertTabAtCaret()
  35967. {
  35968. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  35969. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  35970. {
  35971. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  35972. }
  35973. if (useSpacesForTabs)
  35974. {
  35975. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35976. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  35977. insertTextAtCaret (String::repeatedString (T(" "), spacesNeeded));
  35978. }
  35979. else
  35980. {
  35981. insertTextAtCaret (T("\t"));
  35982. }
  35983. }
  35984. void CodeEditorComponent::cut()
  35985. {
  35986. insertTextAtCaret (String::empty);
  35987. }
  35988. void CodeEditorComponent::copy()
  35989. {
  35990. newTransaction();
  35991. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  35992. if (selection.isNotEmpty())
  35993. SystemClipboard::copyTextToClipboard (selection);
  35994. }
  35995. void CodeEditorComponent::copyThenCut()
  35996. {
  35997. copy();
  35998. cut();
  35999. newTransaction();
  36000. }
  36001. void CodeEditorComponent::paste()
  36002. {
  36003. newTransaction();
  36004. const String clip (SystemClipboard::getTextFromClipboard());
  36005. if (clip.isNotEmpty())
  36006. insertTextAtCaret (clip);
  36007. newTransaction();
  36008. }
  36009. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36010. {
  36011. newTransaction();
  36012. if (moveInWholeWordSteps)
  36013. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36014. else
  36015. moveCaretTo (caretPos.movedBy (-1), selecting);
  36016. }
  36017. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36018. {
  36019. newTransaction();
  36020. if (moveInWholeWordSteps)
  36021. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36022. else
  36023. moveCaretTo (caretPos.movedBy (1), selecting);
  36024. }
  36025. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36026. {
  36027. CodeDocument::Position pos (caretPos);
  36028. const int newLineNum = pos.getLineNumber() + delta;
  36029. if (columnToTryToMaintain < 0)
  36030. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36031. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36032. const int colToMaintain = columnToTryToMaintain;
  36033. moveCaretTo (pos, selecting);
  36034. columnToTryToMaintain = colToMaintain;
  36035. }
  36036. void CodeEditorComponent::cursorDown (const bool selecting)
  36037. {
  36038. newTransaction();
  36039. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36040. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36041. else
  36042. moveLineDelta (1, selecting);
  36043. }
  36044. void CodeEditorComponent::cursorUp (const bool selecting)
  36045. {
  36046. newTransaction();
  36047. if (caretPos.getLineNumber() == 0)
  36048. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36049. else
  36050. moveLineDelta (-1, selecting);
  36051. }
  36052. void CodeEditorComponent::pageDown (const bool selecting)
  36053. {
  36054. newTransaction();
  36055. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36056. moveLineDelta (linesOnScreen, selecting);
  36057. }
  36058. void CodeEditorComponent::pageUp (const bool selecting)
  36059. {
  36060. newTransaction();
  36061. scrollBy (-linesOnScreen);
  36062. moveLineDelta (-linesOnScreen, selecting);
  36063. }
  36064. void CodeEditorComponent::scrollUp()
  36065. {
  36066. newTransaction();
  36067. scrollBy (1);
  36068. if (caretPos.getLineNumber() < firstLineOnScreen)
  36069. moveLineDelta (1, false);
  36070. }
  36071. void CodeEditorComponent::scrollDown()
  36072. {
  36073. newTransaction();
  36074. scrollBy (-1);
  36075. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36076. moveLineDelta (-1, false);
  36077. }
  36078. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36079. {
  36080. newTransaction();
  36081. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36082. }
  36083. static int findFirstNonWhitespaceChar (const String& line) throw()
  36084. {
  36085. const int len = line.length();
  36086. for (int i = 0; i < len; ++i)
  36087. if (! CharacterFunctions::isWhitespace (line [i]))
  36088. return i;
  36089. return 0;
  36090. }
  36091. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36092. {
  36093. newTransaction();
  36094. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36095. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36096. index = 0;
  36097. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36098. }
  36099. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36100. {
  36101. newTransaction();
  36102. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36103. }
  36104. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36105. {
  36106. newTransaction();
  36107. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36108. }
  36109. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36110. {
  36111. if (moveInWholeWordSteps)
  36112. {
  36113. cut(); // in case something is already highlighted
  36114. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36115. }
  36116. else
  36117. {
  36118. if (selectionStart == selectionEnd)
  36119. selectionStart.moveBy (-1);
  36120. }
  36121. cut();
  36122. }
  36123. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36124. {
  36125. if (moveInWholeWordSteps)
  36126. {
  36127. cut(); // in case something is already highlighted
  36128. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36129. }
  36130. else
  36131. {
  36132. if (selectionStart == selectionEnd)
  36133. selectionEnd.moveBy (1);
  36134. else
  36135. newTransaction();
  36136. }
  36137. cut();
  36138. }
  36139. void CodeEditorComponent::selectAll()
  36140. {
  36141. newTransaction();
  36142. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36143. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36144. }
  36145. void CodeEditorComponent::undo()
  36146. {
  36147. document.undo();
  36148. scrollToKeepCaretOnScreen();
  36149. }
  36150. void CodeEditorComponent::redo()
  36151. {
  36152. document.redo();
  36153. scrollToKeepCaretOnScreen();
  36154. }
  36155. void CodeEditorComponent::newTransaction()
  36156. {
  36157. document.newTransaction();
  36158. startTimer (600);
  36159. }
  36160. void CodeEditorComponent::timerCallback()
  36161. {
  36162. newTransaction();
  36163. }
  36164. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36165. {
  36166. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36167. }
  36168. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36169. {
  36170. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36171. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36172. }
  36173. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36174. {
  36175. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36176. CodeDocument::Position (&document, range.getEnd()));
  36177. }
  36178. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36179. {
  36180. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36181. const bool shiftDown = key.getModifiers().isShiftDown();
  36182. if (key.isKeyCode (KeyPress::leftKey))
  36183. {
  36184. cursorLeft (moveInWholeWordSteps, shiftDown);
  36185. }
  36186. else if (key.isKeyCode (KeyPress::rightKey))
  36187. {
  36188. cursorRight (moveInWholeWordSteps, shiftDown);
  36189. }
  36190. else if (key.isKeyCode (KeyPress::upKey))
  36191. {
  36192. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36193. scrollDown();
  36194. #if JUCE_MAC
  36195. else if (key.getModifiers().isCommandDown())
  36196. goToStartOfDocument (shiftDown);
  36197. #endif
  36198. else
  36199. cursorUp (shiftDown);
  36200. }
  36201. else if (key.isKeyCode (KeyPress::downKey))
  36202. {
  36203. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36204. scrollUp();
  36205. #if JUCE_MAC
  36206. else if (key.getModifiers().isCommandDown())
  36207. goToEndOfDocument (shiftDown);
  36208. #endif
  36209. else
  36210. cursorDown (shiftDown);
  36211. }
  36212. else if (key.isKeyCode (KeyPress::pageDownKey))
  36213. {
  36214. pageDown (shiftDown);
  36215. }
  36216. else if (key.isKeyCode (KeyPress::pageUpKey))
  36217. {
  36218. pageUp (shiftDown);
  36219. }
  36220. else if (key.isKeyCode (KeyPress::homeKey))
  36221. {
  36222. if (moveInWholeWordSteps)
  36223. goToStartOfDocument (shiftDown);
  36224. else
  36225. goToStartOfLine (shiftDown);
  36226. }
  36227. else if (key.isKeyCode (KeyPress::endKey))
  36228. {
  36229. if (moveInWholeWordSteps)
  36230. goToEndOfDocument (shiftDown);
  36231. else
  36232. goToEndOfLine (shiftDown);
  36233. }
  36234. else if (key.isKeyCode (KeyPress::backspaceKey))
  36235. {
  36236. backspace (moveInWholeWordSteps);
  36237. }
  36238. else if (key.isKeyCode (KeyPress::deleteKey))
  36239. {
  36240. deleteForward (moveInWholeWordSteps);
  36241. }
  36242. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  36243. {
  36244. copy();
  36245. }
  36246. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  36247. {
  36248. copyThenCut();
  36249. }
  36250. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0))
  36251. {
  36252. paste();
  36253. }
  36254. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  36255. {
  36256. undo();
  36257. }
  36258. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0)
  36259. || key == KeyPress (T('z'), ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36260. {
  36261. redo();
  36262. }
  36263. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  36264. {
  36265. selectAll();
  36266. }
  36267. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36268. {
  36269. insertTabAtCaret();
  36270. }
  36271. else if (key == KeyPress::returnKey)
  36272. {
  36273. newTransaction();
  36274. insertTextAtCaret (document.getNewLineCharacters());
  36275. }
  36276. else if (key.isKeyCode (KeyPress::escapeKey))
  36277. {
  36278. newTransaction();
  36279. }
  36280. else if (key.getTextCharacter() >= ' ')
  36281. {
  36282. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36283. }
  36284. else
  36285. {
  36286. return false;
  36287. }
  36288. return true;
  36289. }
  36290. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36291. {
  36292. newTransaction();
  36293. dragType = notDragging;
  36294. if (! e.mods.isPopupMenu())
  36295. {
  36296. beginDragAutoRepeat (100);
  36297. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36298. }
  36299. else
  36300. {
  36301. }
  36302. }
  36303. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36304. {
  36305. if (! e.mods.isPopupMenu())
  36306. moveCaretTo (getPositionAt (e.x, e.y), true);
  36307. }
  36308. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36309. {
  36310. newTransaction();
  36311. beginDragAutoRepeat (0);
  36312. dragType = notDragging;
  36313. }
  36314. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36315. {
  36316. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36317. CodeDocument::Position tokenEnd (tokenStart);
  36318. if (e.getNumberOfClicks() > 2)
  36319. {
  36320. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36321. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36322. }
  36323. else
  36324. {
  36325. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36326. tokenEnd.moveBy (1);
  36327. tokenStart = tokenEnd;
  36328. while (tokenStart.getIndexInLine() > 0
  36329. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36330. tokenStart.moveBy (-1);
  36331. }
  36332. moveCaretTo (tokenEnd, false);
  36333. moveCaretTo (tokenStart, true);
  36334. }
  36335. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36336. {
  36337. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36338. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36339. }
  36340. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  36341. {
  36342. if (scrollBarThatHasMoved == verticalScrollBar)
  36343. scrollToLineInternal ((int) newRangeStart);
  36344. else
  36345. scrollToColumnInternal (newRangeStart);
  36346. }
  36347. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36348. {
  36349. useSpacesForTabs = insertSpaces;
  36350. if (spacesPerTab != numSpaces)
  36351. {
  36352. spacesPerTab = numSpaces;
  36353. triggerAsyncUpdate();
  36354. }
  36355. }
  36356. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36357. {
  36358. const String line (document.getLine (lineNum));
  36359. jassert (index <= line.length());
  36360. int col = 0;
  36361. for (int i = 0; i < index; ++i)
  36362. {
  36363. if (line[i] != T('\t'))
  36364. ++col;
  36365. else
  36366. col += getTabSize() - (col % getTabSize());
  36367. }
  36368. return col;
  36369. }
  36370. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36371. {
  36372. const String line (document.getLine (lineNum));
  36373. const int lineLength = line.length();
  36374. int i, col = 0;
  36375. for (i = 0; i < lineLength; ++i)
  36376. {
  36377. if (line[i] != T('\t'))
  36378. ++col;
  36379. else
  36380. col += getTabSize() - (col % getTabSize());
  36381. if (col > column)
  36382. break;
  36383. }
  36384. return i;
  36385. }
  36386. void CodeEditorComponent::setFont (const Font& newFont)
  36387. {
  36388. font = newFont;
  36389. charWidth = font.getStringWidthFloat (T("0"));
  36390. lineHeight = roundToInt (font.getHeight());
  36391. resized();
  36392. }
  36393. void CodeEditorComponent::resetToDefaultColours()
  36394. {
  36395. coloursForTokenCategories.clear();
  36396. if (codeTokeniser != 0)
  36397. {
  36398. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36399. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36400. }
  36401. }
  36402. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36403. {
  36404. jassert (tokenType < 256);
  36405. while (coloursForTokenCategories.size() < tokenType)
  36406. coloursForTokenCategories.add (Colours::black);
  36407. coloursForTokenCategories.set (tokenType, colour);
  36408. repaint();
  36409. }
  36410. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36411. {
  36412. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36413. return findColour (CodeEditorComponent::defaultTextColourId);
  36414. return coloursForTokenCategories.getReference (tokenType);
  36415. }
  36416. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36417. {
  36418. int i;
  36419. for (i = cachedIterators.size(); --i >= 0;)
  36420. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36421. break;
  36422. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36423. }
  36424. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36425. {
  36426. const int maxNumCachedPositions = 5000;
  36427. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36428. if (cachedIterators.size() == 0)
  36429. cachedIterators.add (new CodeDocument::Iterator (&document));
  36430. if (codeTokeniser == 0)
  36431. return;
  36432. for (;;)
  36433. {
  36434. CodeDocument::Iterator* last = cachedIterators.getLast();
  36435. if (last->getLine() >= maxLineNum)
  36436. break;
  36437. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36438. cachedIterators.add (t);
  36439. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36440. for (;;)
  36441. {
  36442. codeTokeniser->readNextToken (*t);
  36443. if (t->getLine() >= targetLine)
  36444. break;
  36445. if (t->isEOF())
  36446. return;
  36447. }
  36448. }
  36449. }
  36450. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36451. {
  36452. if (codeTokeniser == 0)
  36453. return;
  36454. for (int i = cachedIterators.size(); --i >= 0;)
  36455. {
  36456. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36457. if (t->getPosition() <= position)
  36458. {
  36459. source = *t;
  36460. break;
  36461. }
  36462. }
  36463. while (source.getPosition() < position)
  36464. {
  36465. const CodeDocument::Iterator original (source);
  36466. codeTokeniser->readNextToken (source);
  36467. if (source.getPosition() > position || source.isEOF())
  36468. {
  36469. source = original;
  36470. break;
  36471. }
  36472. }
  36473. }
  36474. END_JUCE_NAMESPACE
  36475. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  36476. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36477. BEGIN_JUCE_NAMESPACE
  36478. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36479. {
  36480. }
  36481. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36482. {
  36483. }
  36484. namespace CppTokeniser
  36485. {
  36486. static bool isIdentifierStart (const tchar c) throw()
  36487. {
  36488. return CharacterFunctions::isLetter (c)
  36489. || c == T('_') || c == T('@');
  36490. }
  36491. static bool isIdentifierBody (const tchar c) throw()
  36492. {
  36493. return CharacterFunctions::isLetter (c)
  36494. || CharacterFunctions::isDigit (c)
  36495. || c == T('_') || c == T('@');
  36496. }
  36497. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  36498. {
  36499. static const tchar* keywords2Char[] =
  36500. { T("if"), T("do"), T("or"), 0 };
  36501. static const tchar* keywords3Char[] =
  36502. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  36503. static const tchar* keywords4Char[] =
  36504. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  36505. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  36506. static const tchar* keywords5Char[] =
  36507. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  36508. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  36509. static const tchar* keywords6Char[] =
  36510. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  36511. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  36512. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  36513. static const tchar* keywordsOther[] =
  36514. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  36515. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  36516. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  36517. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  36518. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  36519. int tokenLength = 0;
  36520. tchar possibleIdentifier [19];
  36521. while (isIdentifierBody (source.peekNextChar()))
  36522. {
  36523. const tchar c = source.nextChar();
  36524. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  36525. possibleIdentifier [tokenLength] = c;
  36526. ++tokenLength;
  36527. }
  36528. if (tokenLength > 1 && tokenLength <= 16)
  36529. {
  36530. possibleIdentifier [tokenLength] = 0;
  36531. const tchar** k;
  36532. switch (tokenLength)
  36533. {
  36534. case 2: k = keywords2Char; break;
  36535. case 3: k = keywords3Char; break;
  36536. case 4: k = keywords4Char; break;
  36537. case 5: k = keywords5Char; break;
  36538. case 6: k = keywords6Char; break;
  36539. default: k = keywordsOther; break;
  36540. }
  36541. int i = 0;
  36542. while (k[i] != 0)
  36543. {
  36544. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  36545. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  36546. ++i;
  36547. }
  36548. }
  36549. return CPlusPlusCodeTokeniser::tokenType_identifier;
  36550. }
  36551. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  36552. {
  36553. const juce_wchar c = source.peekNextChar();
  36554. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  36555. source.skip();
  36556. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  36557. return false;
  36558. return true;
  36559. }
  36560. static bool isHexDigit (const juce_wchar c) throw()
  36561. {
  36562. return (c >= '0' && c <= '9')
  36563. || (c >= 'a' && c <= 'f')
  36564. || (c >= 'A' && c <= 'F');
  36565. }
  36566. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  36567. {
  36568. if (source.nextChar() != '0')
  36569. return false;
  36570. juce_wchar c = source.nextChar();
  36571. if (c != 'x' && c != 'X')
  36572. return false;
  36573. int numDigits = 0;
  36574. while (isHexDigit (source.peekNextChar()))
  36575. {
  36576. ++numDigits;
  36577. source.skip();
  36578. }
  36579. if (numDigits == 0)
  36580. return false;
  36581. return skipNumberSuffix (source);
  36582. }
  36583. static bool isOctalDigit (const juce_wchar c) throw()
  36584. {
  36585. return c >= '0' && c <= '7';
  36586. }
  36587. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  36588. {
  36589. if (source.nextChar() != '0')
  36590. return false;
  36591. if (! isOctalDigit (source.nextChar()))
  36592. return false;
  36593. while (isOctalDigit (source.peekNextChar()))
  36594. source.skip();
  36595. return skipNumberSuffix (source);
  36596. }
  36597. static bool isDecimalDigit (const juce_wchar c) throw()
  36598. {
  36599. return c >= '0' && c <= '9';
  36600. }
  36601. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  36602. {
  36603. int numChars = 0;
  36604. while (isDecimalDigit (source.peekNextChar()))
  36605. {
  36606. ++numChars;
  36607. source.skip();
  36608. }
  36609. if (numChars == 0)
  36610. return false;
  36611. return skipNumberSuffix (source);
  36612. }
  36613. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  36614. {
  36615. int numDigits = 0;
  36616. while (isDecimalDigit (source.peekNextChar()))
  36617. {
  36618. source.skip();
  36619. ++numDigits;
  36620. }
  36621. const bool hasPoint = (source.peekNextChar() == '.');
  36622. if (hasPoint)
  36623. {
  36624. source.skip();
  36625. while (isDecimalDigit (source.peekNextChar()))
  36626. {
  36627. source.skip();
  36628. ++numDigits;
  36629. }
  36630. }
  36631. if (numDigits == 0)
  36632. return false;
  36633. juce_wchar c = source.peekNextChar();
  36634. const bool hasExponent = (c == 'e' || c == 'E');
  36635. if (hasExponent)
  36636. {
  36637. source.skip();
  36638. c = source.peekNextChar();
  36639. if (c == '+' || c == '-')
  36640. source.skip();
  36641. int numExpDigits = 0;
  36642. while (isDecimalDigit (source.peekNextChar()))
  36643. {
  36644. source.skip();
  36645. ++numExpDigits;
  36646. }
  36647. if (numExpDigits == 0)
  36648. return false;
  36649. }
  36650. c = source.peekNextChar();
  36651. if (c == 'f' || c == 'F')
  36652. source.skip();
  36653. else if (! (hasExponent || hasPoint))
  36654. return false;
  36655. return true;
  36656. }
  36657. static int parseNumber (CodeDocument::Iterator& source)
  36658. {
  36659. const CodeDocument::Iterator original (source);
  36660. if (parseFloatLiteral (source))
  36661. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  36662. source = original;
  36663. if (parseHexLiteral (source))
  36664. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36665. source = original;
  36666. if (parseOctalLiteral (source))
  36667. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36668. source = original;
  36669. if (parseDecimalLiteral (source))
  36670. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36671. source = original;
  36672. source.skip();
  36673. return CPlusPlusCodeTokeniser::tokenType_error;
  36674. }
  36675. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  36676. {
  36677. const juce_wchar quote = source.nextChar();
  36678. for (;;)
  36679. {
  36680. const juce_wchar c = source.nextChar();
  36681. if (c == quote || c == 0)
  36682. break;
  36683. if (c == '\\')
  36684. source.skip();
  36685. }
  36686. }
  36687. static void skipComment (CodeDocument::Iterator& source) throw()
  36688. {
  36689. bool lastWasStar = false;
  36690. for (;;)
  36691. {
  36692. const juce_wchar c = source.nextChar();
  36693. if (c == 0 || (c == T('/') && lastWasStar))
  36694. break;
  36695. lastWasStar = (c == '*');
  36696. }
  36697. }
  36698. }
  36699. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  36700. {
  36701. int result = tokenType_error;
  36702. source.skipWhitespace();
  36703. tchar firstChar = source.peekNextChar();
  36704. switch (firstChar)
  36705. {
  36706. case 0:
  36707. source.skip();
  36708. break;
  36709. case T('0'):
  36710. case T('1'):
  36711. case T('2'):
  36712. case T('3'):
  36713. case T('4'):
  36714. case T('5'):
  36715. case T('6'):
  36716. case T('7'):
  36717. case T('8'):
  36718. case T('9'):
  36719. result = CppTokeniser::parseNumber (source);
  36720. break;
  36721. case T('.'):
  36722. result = CppTokeniser::parseNumber (source);
  36723. if (result == tokenType_error)
  36724. result = tokenType_punctuation;
  36725. break;
  36726. case T(','):
  36727. case T(';'):
  36728. case T(':'):
  36729. source.skip();
  36730. result = tokenType_punctuation;
  36731. break;
  36732. case T('('):
  36733. case T(')'):
  36734. case T('{'):
  36735. case T('}'):
  36736. case T('['):
  36737. case T(']'):
  36738. source.skip();
  36739. result = tokenType_bracket;
  36740. break;
  36741. case T('"'):
  36742. case T('\''):
  36743. CppTokeniser::skipQuotedString (source);
  36744. result = tokenType_stringLiteral;
  36745. break;
  36746. case T('+'):
  36747. result = tokenType_operator;
  36748. source.skip();
  36749. if (source.peekNextChar() == T('+'))
  36750. source.skip();
  36751. else if (source.peekNextChar() == T('='))
  36752. source.skip();
  36753. break;
  36754. case T('-'):
  36755. source.skip();
  36756. result = CppTokeniser::parseNumber (source);
  36757. if (result == tokenType_error)
  36758. {
  36759. result = tokenType_operator;
  36760. if (source.peekNextChar() == T('-'))
  36761. source.skip();
  36762. else if (source.peekNextChar() == T('='))
  36763. source.skip();
  36764. }
  36765. break;
  36766. case T('*'):
  36767. case T('%'):
  36768. case T('='):
  36769. case T('!'):
  36770. result = tokenType_operator;
  36771. source.skip();
  36772. if (source.peekNextChar() == T('='))
  36773. source.skip();
  36774. break;
  36775. case T('/'):
  36776. result = tokenType_operator;
  36777. source.skip();
  36778. if (source.peekNextChar() == T('='))
  36779. {
  36780. source.skip();
  36781. }
  36782. else if (source.peekNextChar() == T('/'))
  36783. {
  36784. result = tokenType_comment;
  36785. source.skipToEndOfLine();
  36786. }
  36787. else if (source.peekNextChar() == T('*'))
  36788. {
  36789. source.skip();
  36790. result = tokenType_comment;
  36791. CppTokeniser::skipComment (source);
  36792. }
  36793. break;
  36794. case T('?'):
  36795. case T('~'):
  36796. source.skip();
  36797. result = tokenType_operator;
  36798. break;
  36799. case T('<'):
  36800. source.skip();
  36801. result = tokenType_operator;
  36802. if (source.peekNextChar() == T('='))
  36803. {
  36804. source.skip();
  36805. }
  36806. else if (source.peekNextChar() == T('<'))
  36807. {
  36808. source.skip();
  36809. if (source.peekNextChar() == T('='))
  36810. source.skip();
  36811. }
  36812. break;
  36813. case T('>'):
  36814. source.skip();
  36815. result = tokenType_operator;
  36816. if (source.peekNextChar() == T('='))
  36817. {
  36818. source.skip();
  36819. }
  36820. else if (source.peekNextChar() == T('<'))
  36821. {
  36822. source.skip();
  36823. if (source.peekNextChar() == T('='))
  36824. source.skip();
  36825. }
  36826. break;
  36827. case T('|'):
  36828. source.skip();
  36829. result = tokenType_operator;
  36830. if (source.peekNextChar() == T('='))
  36831. {
  36832. source.skip();
  36833. }
  36834. else if (source.peekNextChar() == T('|'))
  36835. {
  36836. source.skip();
  36837. if (source.peekNextChar() == T('='))
  36838. source.skip();
  36839. }
  36840. break;
  36841. case T('&'):
  36842. source.skip();
  36843. result = tokenType_operator;
  36844. if (source.peekNextChar() == T('='))
  36845. {
  36846. source.skip();
  36847. }
  36848. else if (source.peekNextChar() == T('&'))
  36849. {
  36850. source.skip();
  36851. if (source.peekNextChar() == T('='))
  36852. source.skip();
  36853. }
  36854. break;
  36855. case T('^'):
  36856. source.skip();
  36857. result = tokenType_operator;
  36858. if (source.peekNextChar() == T('='))
  36859. {
  36860. source.skip();
  36861. }
  36862. else if (source.peekNextChar() == T('^'))
  36863. {
  36864. source.skip();
  36865. if (source.peekNextChar() == T('='))
  36866. source.skip();
  36867. }
  36868. break;
  36869. case T('#'):
  36870. result = tokenType_preprocessor;
  36871. source.skipToEndOfLine();
  36872. break;
  36873. default:
  36874. if (CppTokeniser::isIdentifierStart (firstChar))
  36875. result = CppTokeniser::parseIdentifier (source);
  36876. else
  36877. source.skip();
  36878. break;
  36879. }
  36880. //jassert (result != tokenType_unknown);
  36881. return result;
  36882. }
  36883. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  36884. {
  36885. StringArray s;
  36886. s.add ("Error");
  36887. s.add ("Comment");
  36888. s.add ("C++ keyword");
  36889. s.add ("Identifier");
  36890. s.add ("Integer literal");
  36891. s.add ("Float literal");
  36892. s.add ("String literal");
  36893. s.add ("Operator");
  36894. s.add ("Bracket");
  36895. s.add ("Punctuation");
  36896. s.add ("Preprocessor line");
  36897. return s;
  36898. }
  36899. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  36900. {
  36901. const uint32 colours[] =
  36902. {
  36903. 0xffcc0000, // error
  36904. 0xff00aa00, // comment
  36905. 0xff0000cc, // keyword
  36906. 0xff000000, // identifier
  36907. 0xff880000, // int literal
  36908. 0xff885500, // float literal
  36909. 0xff990099, // string literal
  36910. 0xff225500, // operator
  36911. 0xff000055, // bracket
  36912. 0xff004400, // punctuation
  36913. 0xff660000 // preprocessor
  36914. };
  36915. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  36916. return Colour (colours [tokenType]);
  36917. return Colours::black;
  36918. }
  36919. END_JUCE_NAMESPACE
  36920. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36921. /*** Start of inlined file: juce_ComboBox.cpp ***/
  36922. BEGIN_JUCE_NAMESPACE
  36923. ComboBox::ComboBox (const String& name)
  36924. : Component (name),
  36925. lastCurrentId (0),
  36926. isButtonDown (false),
  36927. separatorPending (false),
  36928. menuActive (false),
  36929. label (0)
  36930. {
  36931. noChoicesMessage = TRANS("(no choices)");
  36932. setRepaintsOnMouseActivity (true);
  36933. lookAndFeelChanged();
  36934. currentId.addListener (this);
  36935. }
  36936. ComboBox::~ComboBox()
  36937. {
  36938. currentId.removeListener (this);
  36939. if (menuActive)
  36940. PopupMenu::dismissAllActiveMenus();
  36941. label = 0;
  36942. deleteAllChildren();
  36943. }
  36944. void ComboBox::setEditableText (const bool isEditable)
  36945. {
  36946. label->setEditable (isEditable, isEditable, false);
  36947. setWantsKeyboardFocus (! isEditable);
  36948. resized();
  36949. }
  36950. bool ComboBox::isTextEditable() const throw()
  36951. {
  36952. return label->isEditable();
  36953. }
  36954. void ComboBox::setJustificationType (const Justification& justification) throw()
  36955. {
  36956. label->setJustificationType (justification);
  36957. }
  36958. const Justification ComboBox::getJustificationType() const throw()
  36959. {
  36960. return label->getJustificationType();
  36961. }
  36962. void ComboBox::setTooltip (const String& newTooltip)
  36963. {
  36964. SettableTooltipClient::setTooltip (newTooltip);
  36965. label->setTooltip (newTooltip);
  36966. }
  36967. void ComboBox::addItem (const String& newItemText,
  36968. const int newItemId) throw()
  36969. {
  36970. // you can't add empty strings to the list..
  36971. jassert (newItemText.isNotEmpty());
  36972. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  36973. jassert (newItemId != 0);
  36974. // you shouldn't use duplicate item IDs!
  36975. jassert (getItemForId (newItemId) == 0);
  36976. if (newItemText.isNotEmpty() && newItemId != 0)
  36977. {
  36978. if (separatorPending)
  36979. {
  36980. separatorPending = false;
  36981. ItemInfo* const item = new ItemInfo();
  36982. item->itemId = 0;
  36983. item->isEnabled = false;
  36984. item->isHeading = false;
  36985. items.add (item);
  36986. }
  36987. ItemInfo* const item = new ItemInfo();
  36988. item->name = newItemText;
  36989. item->itemId = newItemId;
  36990. item->isEnabled = true;
  36991. item->isHeading = false;
  36992. items.add (item);
  36993. }
  36994. }
  36995. void ComboBox::addSeparator() throw()
  36996. {
  36997. separatorPending = (items.size() > 0);
  36998. }
  36999. void ComboBox::addSectionHeading (const String& headingName) throw()
  37000. {
  37001. // you can't add empty strings to the list..
  37002. jassert (headingName.isNotEmpty());
  37003. if (headingName.isNotEmpty())
  37004. {
  37005. if (separatorPending)
  37006. {
  37007. separatorPending = false;
  37008. ItemInfo* const item = new ItemInfo();
  37009. item->itemId = 0;
  37010. item->isEnabled = false;
  37011. item->isHeading = false;
  37012. items.add (item);
  37013. }
  37014. ItemInfo* const item = new ItemInfo();
  37015. item->name = headingName;
  37016. item->itemId = 0;
  37017. item->isEnabled = true;
  37018. item->isHeading = true;
  37019. items.add (item);
  37020. }
  37021. }
  37022. void ComboBox::setItemEnabled (const int itemId,
  37023. const bool shouldBeEnabled) throw()
  37024. {
  37025. ItemInfo* const item = getItemForId (itemId);
  37026. if (item != 0)
  37027. item->isEnabled = shouldBeEnabled;
  37028. }
  37029. void ComboBox::changeItemText (const int itemId,
  37030. const String& newText) throw()
  37031. {
  37032. ItemInfo* const item = getItemForId (itemId);
  37033. jassert (item != 0);
  37034. if (item != 0)
  37035. item->name = newText;
  37036. }
  37037. void ComboBox::clear (const bool dontSendChangeMessage)
  37038. {
  37039. items.clear();
  37040. separatorPending = false;
  37041. if (! label->isEditable())
  37042. setSelectedItemIndex (-1, dontSendChangeMessage);
  37043. }
  37044. bool ComboBox::ItemInfo::isSeparator() const throw()
  37045. {
  37046. return name.isEmpty();
  37047. }
  37048. bool ComboBox::ItemInfo::isRealItem() const throw()
  37049. {
  37050. return ! (isHeading || name.isEmpty());
  37051. }
  37052. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37053. {
  37054. if (itemId != 0)
  37055. {
  37056. for (int i = items.size(); --i >= 0;)
  37057. if (items.getUnchecked(i)->itemId == itemId)
  37058. return items.getUnchecked(i);
  37059. }
  37060. return 0;
  37061. }
  37062. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37063. {
  37064. int n = 0;
  37065. for (int i = 0; i < items.size(); ++i)
  37066. {
  37067. ItemInfo* const item = items.getUnchecked(i);
  37068. if (item->isRealItem())
  37069. if (n++ == index)
  37070. return item;
  37071. }
  37072. return 0;
  37073. }
  37074. int ComboBox::getNumItems() const throw()
  37075. {
  37076. int n = 0;
  37077. for (int i = items.size(); --i >= 0;)
  37078. if (items.getUnchecked(i)->isRealItem())
  37079. ++n;
  37080. return n;
  37081. }
  37082. const String ComboBox::getItemText (const int index) const throw()
  37083. {
  37084. const ItemInfo* const item = getItemForIndex (index);
  37085. if (item != 0)
  37086. return item->name;
  37087. return String::empty;
  37088. }
  37089. int ComboBox::getItemId (const int index) const throw()
  37090. {
  37091. const ItemInfo* const item = getItemForIndex (index);
  37092. return (item != 0) ? item->itemId : 0;
  37093. }
  37094. int ComboBox::indexOfItemId (const int itemId) const throw()
  37095. {
  37096. int n = 0;
  37097. for (int i = 0; i < items.size(); ++i)
  37098. {
  37099. const ItemInfo* const item = items.getUnchecked(i);
  37100. if (item->isRealItem())
  37101. {
  37102. if (item->itemId == itemId)
  37103. return n;
  37104. ++n;
  37105. }
  37106. }
  37107. return -1;
  37108. }
  37109. int ComboBox::getSelectedItemIndex() const throw()
  37110. {
  37111. int index = indexOfItemId (currentId.getValue());
  37112. if (getText() != getItemText (index))
  37113. index = -1;
  37114. return index;
  37115. }
  37116. void ComboBox::setSelectedItemIndex (const int index,
  37117. const bool dontSendChangeMessage) throw()
  37118. {
  37119. setSelectedId (getItemId (index), dontSendChangeMessage);
  37120. }
  37121. int ComboBox::getSelectedId() const throw()
  37122. {
  37123. const ItemInfo* const item = getItemForId (currentId.getValue());
  37124. return (item != 0 && getText() == item->name)
  37125. ? item->itemId
  37126. : 0;
  37127. }
  37128. void ComboBox::setSelectedId (const int newItemId,
  37129. const bool dontSendChangeMessage) throw()
  37130. {
  37131. const ItemInfo* const item = getItemForId (newItemId);
  37132. const String newItemText (item != 0 ? item->name : String::empty);
  37133. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37134. {
  37135. if (! dontSendChangeMessage)
  37136. triggerAsyncUpdate();
  37137. label->setText (newItemText, false);
  37138. lastCurrentId = newItemId;
  37139. currentId = newItemId;
  37140. repaint(); // for the benefit of the 'none selected' text
  37141. }
  37142. }
  37143. void ComboBox::valueChanged (Value&)
  37144. {
  37145. if (lastCurrentId != (int) currentId.getValue())
  37146. setSelectedId (currentId.getValue(), false);
  37147. }
  37148. const String ComboBox::getText() const throw()
  37149. {
  37150. return label->getText();
  37151. }
  37152. void ComboBox::setText (const String& newText,
  37153. const bool dontSendChangeMessage) throw()
  37154. {
  37155. for (int i = items.size(); --i >= 0;)
  37156. {
  37157. const ItemInfo* const item = items.getUnchecked(i);
  37158. if (item->isRealItem()
  37159. && item->name == newText)
  37160. {
  37161. setSelectedId (item->itemId, dontSendChangeMessage);
  37162. return;
  37163. }
  37164. }
  37165. lastCurrentId = 0;
  37166. currentId = 0;
  37167. if (label->getText() != newText)
  37168. {
  37169. label->setText (newText, false);
  37170. if (! dontSendChangeMessage)
  37171. triggerAsyncUpdate();
  37172. }
  37173. repaint();
  37174. }
  37175. void ComboBox::showEditor()
  37176. {
  37177. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37178. label->showEditor();
  37179. }
  37180. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37181. {
  37182. textWhenNothingSelected = newMessage;
  37183. repaint();
  37184. }
  37185. const String ComboBox::getTextWhenNothingSelected() const throw()
  37186. {
  37187. return textWhenNothingSelected;
  37188. }
  37189. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37190. {
  37191. noChoicesMessage = newMessage;
  37192. }
  37193. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37194. {
  37195. return noChoicesMessage;
  37196. }
  37197. void ComboBox::paint (Graphics& g)
  37198. {
  37199. getLookAndFeel().drawComboBox (g,
  37200. getWidth(),
  37201. getHeight(),
  37202. isButtonDown,
  37203. label->getRight(),
  37204. 0,
  37205. getWidth() - label->getRight(),
  37206. getHeight(),
  37207. *this);
  37208. if (textWhenNothingSelected.isNotEmpty()
  37209. && label->getText().isEmpty()
  37210. && ! label->isBeingEdited())
  37211. {
  37212. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37213. g.setFont (label->getFont());
  37214. g.drawFittedText (textWhenNothingSelected,
  37215. label->getX() + 2, label->getY() + 1,
  37216. label->getWidth() - 4, label->getHeight() - 2,
  37217. label->getJustificationType(),
  37218. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37219. }
  37220. }
  37221. void ComboBox::resized()
  37222. {
  37223. if (getHeight() > 0 && getWidth() > 0)
  37224. getLookAndFeel().positionComboBoxText (*this, *label);
  37225. }
  37226. void ComboBox::enablementChanged()
  37227. {
  37228. repaint();
  37229. }
  37230. void ComboBox::lookAndFeelChanged()
  37231. {
  37232. repaint();
  37233. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37234. if (label != 0)
  37235. {
  37236. newLabel->setEditable (label->isEditable());
  37237. newLabel->setJustificationType (label->getJustificationType());
  37238. newLabel->setTooltip (label->getTooltip());
  37239. newLabel->setText (label->getText(), false);
  37240. }
  37241. label = newLabel;
  37242. addAndMakeVisible (newLabel);
  37243. newLabel->addListener (this);
  37244. newLabel->addMouseListener (this, false);
  37245. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37246. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37247. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37248. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37249. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37250. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37251. resized();
  37252. }
  37253. void ComboBox::colourChanged()
  37254. {
  37255. lookAndFeelChanged();
  37256. }
  37257. bool ComboBox::keyPressed (const KeyPress& key)
  37258. {
  37259. bool used = false;
  37260. if (key.isKeyCode (KeyPress::upKey)
  37261. || key.isKeyCode (KeyPress::leftKey))
  37262. {
  37263. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37264. used = true;
  37265. }
  37266. else if (key.isKeyCode (KeyPress::downKey)
  37267. || key.isKeyCode (KeyPress::rightKey))
  37268. {
  37269. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37270. used = true;
  37271. }
  37272. else if (key.isKeyCode (KeyPress::returnKey))
  37273. {
  37274. showPopup();
  37275. used = true;
  37276. }
  37277. return used;
  37278. }
  37279. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37280. {
  37281. // only forward key events that aren't used by this component
  37282. return isKeyDown
  37283. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37284. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37285. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37286. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37287. }
  37288. void ComboBox::focusGained (FocusChangeType)
  37289. {
  37290. repaint();
  37291. }
  37292. void ComboBox::focusLost (FocusChangeType)
  37293. {
  37294. repaint();
  37295. }
  37296. void ComboBox::labelTextChanged (Label*)
  37297. {
  37298. triggerAsyncUpdate();
  37299. }
  37300. void ComboBox::showPopup()
  37301. {
  37302. if (! menuActive)
  37303. {
  37304. const int selectedId = getSelectedId();
  37305. Component::SafePointer<Component> deletionWatcher (this);
  37306. PopupMenu menu;
  37307. menu.setLookAndFeel (&getLookAndFeel());
  37308. for (int i = 0; i < items.size(); ++i)
  37309. {
  37310. const ItemInfo* const item = items.getUnchecked(i);
  37311. if (item->isSeparator())
  37312. menu.addSeparator();
  37313. else if (item->isHeading)
  37314. menu.addSectionHeader (item->name);
  37315. else
  37316. menu.addItem (item->itemId, item->name,
  37317. item->isEnabled, item->itemId == selectedId);
  37318. }
  37319. if (items.size() == 0)
  37320. menu.addItem (1, noChoicesMessage, false);
  37321. const int itemHeight = jlimit (12, 24, getHeight());
  37322. menuActive = true;
  37323. const int resultId = menu.showAt (this, selectedId,
  37324. getWidth(), 1, itemHeight);
  37325. if (deletionWatcher == 0)
  37326. return;
  37327. menuActive = false;
  37328. if (resultId != 0)
  37329. setSelectedId (resultId);
  37330. }
  37331. }
  37332. void ComboBox::mouseDown (const MouseEvent& e)
  37333. {
  37334. beginDragAutoRepeat (300);
  37335. isButtonDown = isEnabled();
  37336. if (isButtonDown
  37337. && (e.eventComponent == this || ! label->isEditable()))
  37338. {
  37339. showPopup();
  37340. }
  37341. }
  37342. void ComboBox::mouseDrag (const MouseEvent& e)
  37343. {
  37344. beginDragAutoRepeat (50);
  37345. if (isButtonDown && ! e.mouseWasClicked())
  37346. showPopup();
  37347. }
  37348. void ComboBox::mouseUp (const MouseEvent& e2)
  37349. {
  37350. if (isButtonDown)
  37351. {
  37352. isButtonDown = false;
  37353. repaint();
  37354. const MouseEvent e (e2.getEventRelativeTo (this));
  37355. if (reallyContains (e.x, e.y, true)
  37356. && (e2.eventComponent == this || ! label->isEditable()))
  37357. {
  37358. showPopup();
  37359. }
  37360. }
  37361. }
  37362. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37363. {
  37364. listeners.add (listener);
  37365. }
  37366. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37367. {
  37368. listeners.remove (listener);
  37369. }
  37370. void ComboBox::handleAsyncUpdate()
  37371. {
  37372. Component::BailOutChecker checker (this);
  37373. listeners.callChecked (checker, &ComboBoxListener::comboBoxChanged, this);
  37374. }
  37375. END_JUCE_NAMESPACE
  37376. /*** End of inlined file: juce_ComboBox.cpp ***/
  37377. /*** Start of inlined file: juce_Label.cpp ***/
  37378. BEGIN_JUCE_NAMESPACE
  37379. Label::Label (const String& componentName,
  37380. const String& labelText)
  37381. : Component (componentName),
  37382. textValue (labelText),
  37383. lastTextValue (labelText),
  37384. font (15.0f),
  37385. justification (Justification::centredLeft),
  37386. ownerComponent (0),
  37387. horizontalBorderSize (5),
  37388. verticalBorderSize (1),
  37389. minimumHorizontalScale (0.7f),
  37390. editSingleClick (false),
  37391. editDoubleClick (false),
  37392. lossOfFocusDiscardsChanges (false)
  37393. {
  37394. setColour (TextEditor::textColourId, Colours::black);
  37395. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37396. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37397. textValue.addListener (this);
  37398. }
  37399. Label::~Label()
  37400. {
  37401. textValue.removeListener (this);
  37402. if (ownerComponent != 0)
  37403. ownerComponent->removeComponentListener (this);
  37404. editor = 0;
  37405. }
  37406. void Label::setText (const String& newText,
  37407. const bool broadcastChangeMessage)
  37408. {
  37409. hideEditor (true);
  37410. if (lastTextValue != newText)
  37411. {
  37412. lastTextValue = newText;
  37413. textValue = newText;
  37414. repaint();
  37415. textWasChanged();
  37416. if (ownerComponent != 0)
  37417. componentMovedOrResized (*ownerComponent, true, true);
  37418. if (broadcastChangeMessage)
  37419. callChangeListeners();
  37420. }
  37421. }
  37422. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37423. {
  37424. return (returnActiveEditorContents && isBeingEdited())
  37425. ? editor->getText()
  37426. : textValue.toString();
  37427. }
  37428. void Label::valueChanged (Value&)
  37429. {
  37430. if (lastTextValue != textValue.toString())
  37431. setText (textValue.toString(), true);
  37432. }
  37433. void Label::setFont (const Font& newFont) throw()
  37434. {
  37435. font = newFont;
  37436. repaint();
  37437. }
  37438. const Font& Label::getFont() const throw()
  37439. {
  37440. return font;
  37441. }
  37442. void Label::setEditable (const bool editOnSingleClick,
  37443. const bool editOnDoubleClick,
  37444. const bool lossOfFocusDiscardsChanges_) throw()
  37445. {
  37446. editSingleClick = editOnSingleClick;
  37447. editDoubleClick = editOnDoubleClick;
  37448. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37449. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37450. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37451. }
  37452. void Label::setJustificationType (const Justification& justification_) throw()
  37453. {
  37454. justification = justification_;
  37455. repaint();
  37456. }
  37457. void Label::setBorderSize (int h, int v)
  37458. {
  37459. horizontalBorderSize = h;
  37460. verticalBorderSize = v;
  37461. repaint();
  37462. }
  37463. Component* Label::getAttachedComponent() const
  37464. {
  37465. return static_cast<Component*> (ownerComponent);
  37466. }
  37467. void Label::attachToComponent (Component* owner,
  37468. const bool onLeft)
  37469. {
  37470. if (ownerComponent != 0)
  37471. ownerComponent->removeComponentListener (this);
  37472. ownerComponent = owner;
  37473. leftOfOwnerComp = onLeft;
  37474. if (ownerComponent != 0)
  37475. {
  37476. setVisible (owner->isVisible());
  37477. ownerComponent->addComponentListener (this);
  37478. componentParentHierarchyChanged (*ownerComponent);
  37479. componentMovedOrResized (*ownerComponent, true, true);
  37480. }
  37481. }
  37482. void Label::componentMovedOrResized (Component& component,
  37483. bool /*wasMoved*/,
  37484. bool /*wasResized*/)
  37485. {
  37486. if (leftOfOwnerComp)
  37487. {
  37488. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  37489. component.getHeight());
  37490. setTopRightPosition (component.getX(), component.getY());
  37491. }
  37492. else
  37493. {
  37494. setSize (component.getWidth(),
  37495. 8 + roundToInt (getFont().getHeight()));
  37496. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  37497. }
  37498. }
  37499. void Label::componentParentHierarchyChanged (Component& component)
  37500. {
  37501. if (component.getParentComponent() != 0)
  37502. component.getParentComponent()->addChildComponent (this);
  37503. }
  37504. void Label::componentVisibilityChanged (Component& component)
  37505. {
  37506. setVisible (component.isVisible());
  37507. }
  37508. void Label::textWasEdited()
  37509. {
  37510. }
  37511. void Label::textWasChanged()
  37512. {
  37513. }
  37514. void Label::showEditor()
  37515. {
  37516. if (editor == 0)
  37517. {
  37518. addAndMakeVisible (editor = createEditorComponent());
  37519. editor->setText (getText(), false);
  37520. editor->addListener (this);
  37521. editor->grabKeyboardFocus();
  37522. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  37523. editor->addListener (this);
  37524. resized();
  37525. repaint();
  37526. editorShown (editor);
  37527. enterModalState();
  37528. editor->grabKeyboardFocus();
  37529. }
  37530. }
  37531. void Label::editorShown (TextEditor* /*editorComponent*/)
  37532. {
  37533. }
  37534. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  37535. {
  37536. }
  37537. bool Label::updateFromTextEditorContents()
  37538. {
  37539. jassert (editor != 0);
  37540. const String newText (editor->getText());
  37541. if (textValue.toString() != newText)
  37542. {
  37543. lastTextValue = newText;
  37544. textValue = newText;
  37545. repaint();
  37546. textWasChanged();
  37547. if (ownerComponent != 0)
  37548. componentMovedOrResized (*ownerComponent, true, true);
  37549. return true;
  37550. }
  37551. return false;
  37552. }
  37553. void Label::hideEditor (const bool discardCurrentEditorContents)
  37554. {
  37555. if (editor != 0)
  37556. {
  37557. Component::SafePointer<Component> deletionChecker (this);
  37558. editorAboutToBeHidden (editor);
  37559. const bool changed = (! discardCurrentEditorContents)
  37560. && updateFromTextEditorContents();
  37561. editor = 0;
  37562. repaint();
  37563. if (changed)
  37564. textWasEdited();
  37565. if (deletionChecker != 0)
  37566. exitModalState (0);
  37567. if (changed && deletionChecker != 0)
  37568. callChangeListeners();
  37569. }
  37570. }
  37571. void Label::inputAttemptWhenModal()
  37572. {
  37573. if (editor != 0)
  37574. {
  37575. if (lossOfFocusDiscardsChanges)
  37576. textEditorEscapeKeyPressed (*editor);
  37577. else
  37578. textEditorReturnKeyPressed (*editor);
  37579. }
  37580. }
  37581. bool Label::isBeingEdited() const throw()
  37582. {
  37583. return editor != 0;
  37584. }
  37585. TextEditor* Label::createEditorComponent()
  37586. {
  37587. TextEditor* const ed = new TextEditor (getName());
  37588. ed->setFont (font);
  37589. // copy these colours from our own settings..
  37590. const int cols[] = { TextEditor::backgroundColourId,
  37591. TextEditor::textColourId,
  37592. TextEditor::highlightColourId,
  37593. TextEditor::highlightedTextColourId,
  37594. TextEditor::caretColourId,
  37595. TextEditor::outlineColourId,
  37596. TextEditor::focusedOutlineColourId,
  37597. TextEditor::shadowColourId };
  37598. for (int i = 0; i < numElementsInArray (cols); ++i)
  37599. ed->setColour (cols[i], findColour (cols[i]));
  37600. return ed;
  37601. }
  37602. void Label::paint (Graphics& g)
  37603. {
  37604. getLookAndFeel().drawLabel (g, *this);
  37605. }
  37606. void Label::mouseUp (const MouseEvent& e)
  37607. {
  37608. if (editSingleClick
  37609. && e.mouseWasClicked()
  37610. && contains (e.x, e.y)
  37611. && ! e.mods.isPopupMenu())
  37612. {
  37613. showEditor();
  37614. }
  37615. }
  37616. void Label::mouseDoubleClick (const MouseEvent& e)
  37617. {
  37618. if (editDoubleClick && ! e.mods.isPopupMenu())
  37619. showEditor();
  37620. }
  37621. void Label::resized()
  37622. {
  37623. if (editor != 0)
  37624. editor->setBoundsInset (BorderSize (0));
  37625. }
  37626. void Label::focusGained (FocusChangeType cause)
  37627. {
  37628. if (editSingleClick && cause == focusChangedByTabKey)
  37629. showEditor();
  37630. }
  37631. void Label::enablementChanged()
  37632. {
  37633. repaint();
  37634. }
  37635. void Label::colourChanged()
  37636. {
  37637. repaint();
  37638. }
  37639. void Label::setMinimumHorizontalScale (const float newScale)
  37640. {
  37641. if (minimumHorizontalScale != newScale)
  37642. {
  37643. minimumHorizontalScale = newScale;
  37644. repaint();
  37645. }
  37646. }
  37647. // We'll use a custom focus traverser here to make sure focus goes from the
  37648. // text editor to another component rather than back to the label itself.
  37649. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  37650. {
  37651. public:
  37652. LabelKeyboardFocusTraverser() {}
  37653. Component* getNextComponent (Component* current)
  37654. {
  37655. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  37656. ? current->getParentComponent() : current);
  37657. }
  37658. Component* getPreviousComponent (Component* current)
  37659. {
  37660. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  37661. ? current->getParentComponent() : current);
  37662. }
  37663. };
  37664. KeyboardFocusTraverser* Label::createFocusTraverser()
  37665. {
  37666. return new LabelKeyboardFocusTraverser();
  37667. }
  37668. void Label::addListener (LabelListener* const listener) throw()
  37669. {
  37670. listeners.add (listener);
  37671. }
  37672. void Label::removeListener (LabelListener* const listener) throw()
  37673. {
  37674. listeners.remove (listener);
  37675. }
  37676. void Label::callChangeListeners()
  37677. {
  37678. Component::BailOutChecker checker (this);
  37679. listeners.callChecked (checker, &LabelListener::labelTextChanged, this);
  37680. }
  37681. void Label::textEditorTextChanged (TextEditor& ed)
  37682. {
  37683. if (editor != 0)
  37684. {
  37685. jassert (&ed == editor);
  37686. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  37687. {
  37688. if (lossOfFocusDiscardsChanges)
  37689. textEditorEscapeKeyPressed (ed);
  37690. else
  37691. textEditorReturnKeyPressed (ed);
  37692. }
  37693. }
  37694. }
  37695. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  37696. {
  37697. if (editor != 0)
  37698. {
  37699. jassert (&ed == editor);
  37700. (void) ed;
  37701. const bool changed = updateFromTextEditorContents();
  37702. hideEditor (true);
  37703. if (changed)
  37704. {
  37705. Component::SafePointer<Component> deletionChecker (this);
  37706. textWasEdited();
  37707. if (deletionChecker != 0)
  37708. callChangeListeners();
  37709. }
  37710. }
  37711. }
  37712. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  37713. {
  37714. if (editor != 0)
  37715. {
  37716. jassert (&ed == editor);
  37717. (void) ed;
  37718. editor->setText (textValue.toString(), false);
  37719. hideEditor (true);
  37720. }
  37721. }
  37722. void Label::textEditorFocusLost (TextEditor& ed)
  37723. {
  37724. textEditorTextChanged (ed);
  37725. }
  37726. END_JUCE_NAMESPACE
  37727. /*** End of inlined file: juce_Label.cpp ***/
  37728. /*** Start of inlined file: juce_ListBox.cpp ***/
  37729. BEGIN_JUCE_NAMESPACE
  37730. class ListBoxRowComponent : public Component,
  37731. public TooltipClient
  37732. {
  37733. public:
  37734. ListBoxRowComponent (ListBox& owner_)
  37735. : owner (owner_),
  37736. row (-1),
  37737. selected (false),
  37738. isDragging (false)
  37739. {
  37740. }
  37741. ~ListBoxRowComponent()
  37742. {
  37743. deleteAllChildren();
  37744. }
  37745. void paint (Graphics& g)
  37746. {
  37747. if (owner.getModel() != 0)
  37748. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  37749. }
  37750. void update (const int row_, const bool selected_)
  37751. {
  37752. if (row != row_ || selected != selected_)
  37753. {
  37754. repaint();
  37755. row = row_;
  37756. selected = selected_;
  37757. }
  37758. if (owner.getModel() != 0)
  37759. {
  37760. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  37761. if (customComp != 0)
  37762. {
  37763. addAndMakeVisible (customComp);
  37764. customComp->setBounds (0, 0, getWidth(), getHeight());
  37765. for (int i = getNumChildComponents(); --i >= 0;)
  37766. if (getChildComponent (i) != customComp)
  37767. delete getChildComponent (i);
  37768. }
  37769. else
  37770. {
  37771. deleteAllChildren();
  37772. }
  37773. }
  37774. }
  37775. void mouseDown (const MouseEvent& e)
  37776. {
  37777. isDragging = false;
  37778. selectRowOnMouseUp = false;
  37779. if (isEnabled())
  37780. {
  37781. if (! selected)
  37782. {
  37783. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37784. if (owner.getModel() != 0)
  37785. owner.getModel()->listBoxItemClicked (row, e);
  37786. }
  37787. else
  37788. {
  37789. selectRowOnMouseUp = true;
  37790. }
  37791. }
  37792. }
  37793. void mouseUp (const MouseEvent& e)
  37794. {
  37795. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  37796. {
  37797. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37798. if (owner.getModel() != 0)
  37799. owner.getModel()->listBoxItemClicked (row, e);
  37800. }
  37801. }
  37802. void mouseDoubleClick (const MouseEvent& e)
  37803. {
  37804. if (owner.getModel() != 0 && isEnabled())
  37805. owner.getModel()->listBoxItemDoubleClicked (row, e);
  37806. }
  37807. void mouseDrag (const MouseEvent& e)
  37808. {
  37809. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  37810. {
  37811. const SparseSet <int> selectedRows (owner.getSelectedRows());
  37812. if (selectedRows.size() > 0)
  37813. {
  37814. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  37815. if (dragDescription.isNotEmpty())
  37816. {
  37817. isDragging = true;
  37818. owner.startDragAndDrop (e, dragDescription);
  37819. }
  37820. }
  37821. }
  37822. }
  37823. void resized()
  37824. {
  37825. if (getNumChildComponents() > 0)
  37826. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  37827. }
  37828. const String getTooltip()
  37829. {
  37830. if (owner.getModel() != 0)
  37831. return owner.getModel()->getTooltipForRow (row);
  37832. return String::empty;
  37833. }
  37834. juce_UseDebuggingNewOperator
  37835. bool neededFlag;
  37836. private:
  37837. ListBox& owner;
  37838. int row;
  37839. bool selected, isDragging, selectRowOnMouseUp;
  37840. ListBoxRowComponent (const ListBoxRowComponent&);
  37841. ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  37842. };
  37843. class ListViewport : public Viewport
  37844. {
  37845. public:
  37846. int firstIndex, firstWholeIndex, lastWholeIndex;
  37847. bool hasUpdated;
  37848. ListViewport (ListBox& owner_)
  37849. : owner (owner_)
  37850. {
  37851. setWantsKeyboardFocus (false);
  37852. setViewedComponent (new Component());
  37853. getViewedComponent()->addMouseListener (this, false);
  37854. getViewedComponent()->setWantsKeyboardFocus (false);
  37855. }
  37856. ~ListViewport()
  37857. {
  37858. getViewedComponent()->removeMouseListener (this);
  37859. getViewedComponent()->deleteAllChildren();
  37860. }
  37861. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  37862. {
  37863. return (ListBoxRowComponent*) getViewedComponent()
  37864. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  37865. }
  37866. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  37867. {
  37868. const int index = getIndexOfChildComponent (rowComponent);
  37869. const int num = getViewedComponent()->getNumChildComponents();
  37870. for (int i = num; --i >= 0;)
  37871. if (((firstIndex + i) % jmax (1, num)) == index)
  37872. return firstIndex + i;
  37873. return -1;
  37874. }
  37875. Component* getComponentForRowIfOnscreen (const int row) const throw()
  37876. {
  37877. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  37878. ? getComponentForRow (row) : 0;
  37879. }
  37880. void visibleAreaChanged (int, int, int, int)
  37881. {
  37882. updateVisibleArea (true);
  37883. if (owner.getModel() != 0)
  37884. owner.getModel()->listWasScrolled();
  37885. }
  37886. void updateVisibleArea (const bool makeSureItUpdatesContent)
  37887. {
  37888. hasUpdated = false;
  37889. const int newX = getViewedComponent()->getX();
  37890. int newY = getViewedComponent()->getY();
  37891. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  37892. const int newH = owner.totalItems * owner.getRowHeight();
  37893. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  37894. newY = getMaximumVisibleHeight() - newH;
  37895. getViewedComponent()->setBounds (newX, newY, newW, newH);
  37896. if (makeSureItUpdatesContent && ! hasUpdated)
  37897. updateContents();
  37898. }
  37899. void updateContents()
  37900. {
  37901. hasUpdated = true;
  37902. const int rowHeight = owner.getRowHeight();
  37903. if (rowHeight > 0)
  37904. {
  37905. const int y = getViewPositionY();
  37906. const int w = getViewedComponent()->getWidth();
  37907. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  37908. while (numNeeded > getViewedComponent()->getNumChildComponents())
  37909. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  37910. jassert (numNeeded >= 0);
  37911. while (numNeeded < getViewedComponent()->getNumChildComponents())
  37912. {
  37913. Component* const rowToRemove
  37914. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  37915. delete rowToRemove;
  37916. }
  37917. firstIndex = y / rowHeight;
  37918. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  37919. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  37920. for (int i = 0; i < numNeeded; ++i)
  37921. {
  37922. const int row = i + firstIndex;
  37923. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  37924. if (rowComp != 0)
  37925. {
  37926. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  37927. rowComp->update (row, owner.isRowSelected (row));
  37928. }
  37929. }
  37930. }
  37931. if (owner.headerComponent != 0)
  37932. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  37933. owner.outlineThickness,
  37934. jmax (owner.getWidth() - owner.outlineThickness * 2,
  37935. getViewedComponent()->getWidth()),
  37936. owner.headerComponent->getHeight());
  37937. }
  37938. void paint (Graphics& g)
  37939. {
  37940. if (isOpaque())
  37941. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  37942. }
  37943. bool keyPressed (const KeyPress& key)
  37944. {
  37945. if (key.isKeyCode (KeyPress::upKey)
  37946. || key.isKeyCode (KeyPress::downKey)
  37947. || key.isKeyCode (KeyPress::pageUpKey)
  37948. || key.isKeyCode (KeyPress::pageDownKey)
  37949. || key.isKeyCode (KeyPress::homeKey)
  37950. || key.isKeyCode (KeyPress::endKey))
  37951. {
  37952. // we want to avoid these keypresses going to the viewport, and instead allow
  37953. // them to pass up to our listbox..
  37954. return false;
  37955. }
  37956. return Viewport::keyPressed (key);
  37957. }
  37958. juce_UseDebuggingNewOperator
  37959. private:
  37960. ListBox& owner;
  37961. ListViewport (const ListViewport&);
  37962. ListViewport& operator= (const ListViewport&);
  37963. };
  37964. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  37965. : Component (name),
  37966. model (model_),
  37967. headerComponent (0),
  37968. totalItems (0),
  37969. rowHeight (22),
  37970. minimumRowWidth (0),
  37971. outlineThickness (0),
  37972. lastRowSelected (-1),
  37973. mouseMoveSelects (false),
  37974. multipleSelection (false),
  37975. hasDoneInitialUpdate (false)
  37976. {
  37977. addAndMakeVisible (viewport = new ListViewport (*this));
  37978. setWantsKeyboardFocus (true);
  37979. colourChanged();
  37980. }
  37981. ListBox::~ListBox()
  37982. {
  37983. deleteAllChildren();
  37984. }
  37985. void ListBox::setModel (ListBoxModel* const newModel)
  37986. {
  37987. if (model != newModel)
  37988. {
  37989. model = newModel;
  37990. updateContent();
  37991. }
  37992. }
  37993. void ListBox::setMultipleSelectionEnabled (bool b)
  37994. {
  37995. multipleSelection = b;
  37996. }
  37997. void ListBox::setMouseMoveSelectsRows (bool b)
  37998. {
  37999. mouseMoveSelects = b;
  38000. if (b)
  38001. addMouseListener (this, true);
  38002. }
  38003. void ListBox::paint (Graphics& g)
  38004. {
  38005. if (! hasDoneInitialUpdate)
  38006. updateContent();
  38007. g.fillAll (findColour (backgroundColourId));
  38008. }
  38009. void ListBox::paintOverChildren (Graphics& g)
  38010. {
  38011. if (outlineThickness > 0)
  38012. {
  38013. g.setColour (findColour (outlineColourId));
  38014. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38015. }
  38016. }
  38017. void ListBox::resized()
  38018. {
  38019. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38020. outlineThickness,
  38021. outlineThickness,
  38022. outlineThickness));
  38023. viewport->setSingleStepSizes (20, getRowHeight());
  38024. viewport->updateVisibleArea (false);
  38025. }
  38026. void ListBox::visibilityChanged()
  38027. {
  38028. viewport->updateVisibleArea (true);
  38029. }
  38030. Viewport* ListBox::getViewport() const throw()
  38031. {
  38032. return viewport;
  38033. }
  38034. void ListBox::updateContent()
  38035. {
  38036. hasDoneInitialUpdate = true;
  38037. totalItems = (model != 0) ? model->getNumRows() : 0;
  38038. bool selectionChanged = false;
  38039. if (selected [selected.size() - 1] >= totalItems)
  38040. {
  38041. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38042. lastRowSelected = getSelectedRow (0);
  38043. selectionChanged = true;
  38044. }
  38045. viewport->updateVisibleArea (isVisible());
  38046. viewport->resized();
  38047. if (selectionChanged && model != 0)
  38048. model->selectedRowsChanged (lastRowSelected);
  38049. }
  38050. void ListBox::selectRow (const int row,
  38051. bool dontScroll,
  38052. bool deselectOthersFirst)
  38053. {
  38054. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38055. }
  38056. void ListBox::selectRowInternal (const int row,
  38057. bool dontScroll,
  38058. bool deselectOthersFirst,
  38059. bool isMouseClick)
  38060. {
  38061. if (! multipleSelection)
  38062. deselectOthersFirst = true;
  38063. if ((! isRowSelected (row))
  38064. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38065. {
  38066. if (((unsigned int) row) < (unsigned int) totalItems)
  38067. {
  38068. if (deselectOthersFirst)
  38069. selected.clear();
  38070. selected.addRange (row, 1);
  38071. if (getHeight() == 0 || getWidth() == 0)
  38072. dontScroll = true;
  38073. viewport->hasUpdated = false;
  38074. if (row < viewport->firstWholeIndex && ! dontScroll)
  38075. {
  38076. viewport->setViewPosition (viewport->getViewPositionX(),
  38077. row * getRowHeight());
  38078. }
  38079. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38080. {
  38081. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38082. if (row >= lastRowSelected + rowsOnScreen
  38083. && rowsOnScreen < totalItems - 1
  38084. && ! isMouseClick)
  38085. {
  38086. viewport->setViewPosition (viewport->getViewPositionX(),
  38087. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38088. * getRowHeight());
  38089. }
  38090. else
  38091. {
  38092. viewport->setViewPosition (viewport->getViewPositionX(),
  38093. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38094. }
  38095. }
  38096. if (! viewport->hasUpdated)
  38097. viewport->updateContents();
  38098. lastRowSelected = row;
  38099. model->selectedRowsChanged (row);
  38100. }
  38101. else
  38102. {
  38103. if (deselectOthersFirst)
  38104. deselectAllRows();
  38105. }
  38106. }
  38107. }
  38108. void ListBox::deselectRow (const int row)
  38109. {
  38110. if (selected.contains (row))
  38111. {
  38112. selected.removeRange (row, 1);
  38113. if (row == lastRowSelected)
  38114. lastRowSelected = getSelectedRow (0);
  38115. viewport->updateContents();
  38116. model->selectedRowsChanged (lastRowSelected);
  38117. }
  38118. }
  38119. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38120. const bool sendNotificationEventToModel)
  38121. {
  38122. selected = setOfRowsToBeSelected;
  38123. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38124. if (! isRowSelected (lastRowSelected))
  38125. lastRowSelected = getSelectedRow (0);
  38126. viewport->updateContents();
  38127. if ((model != 0) && sendNotificationEventToModel)
  38128. model->selectedRowsChanged (lastRowSelected);
  38129. }
  38130. const SparseSet<int> ListBox::getSelectedRows() const
  38131. {
  38132. return selected;
  38133. }
  38134. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38135. {
  38136. if (multipleSelection && (firstRow != lastRow))
  38137. {
  38138. const int numRows = totalItems - 1;
  38139. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38140. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38141. selected.addRange (jmin (firstRow, lastRow),
  38142. abs (firstRow - lastRow) + 1);
  38143. selected.removeRange (lastRow, 1);
  38144. }
  38145. selectRowInternal (lastRow, false, false, true);
  38146. }
  38147. void ListBox::flipRowSelection (const int row)
  38148. {
  38149. if (isRowSelected (row))
  38150. deselectRow (row);
  38151. else
  38152. selectRowInternal (row, false, false, true);
  38153. }
  38154. void ListBox::deselectAllRows()
  38155. {
  38156. if (! selected.isEmpty())
  38157. {
  38158. selected.clear();
  38159. lastRowSelected = -1;
  38160. viewport->updateContents();
  38161. if (model != 0)
  38162. model->selectedRowsChanged (lastRowSelected);
  38163. }
  38164. }
  38165. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38166. const ModifierKeys& mods)
  38167. {
  38168. if (multipleSelection && mods.isCommandDown())
  38169. {
  38170. flipRowSelection (row);
  38171. }
  38172. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38173. {
  38174. selectRangeOfRows (lastRowSelected, row);
  38175. }
  38176. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38177. {
  38178. selectRowInternal (row, false, true, true);
  38179. }
  38180. }
  38181. int ListBox::getNumSelectedRows() const
  38182. {
  38183. return selected.size();
  38184. }
  38185. int ListBox::getSelectedRow (const int index) const
  38186. {
  38187. return (((unsigned int) index) < (unsigned int) selected.size())
  38188. ? selected [index] : -1;
  38189. }
  38190. bool ListBox::isRowSelected (const int row) const
  38191. {
  38192. return selected.contains (row);
  38193. }
  38194. int ListBox::getLastRowSelected() const
  38195. {
  38196. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38197. }
  38198. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38199. {
  38200. if (((unsigned int) x) < (unsigned int) getWidth())
  38201. {
  38202. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38203. if (((unsigned int) row) < (unsigned int) totalItems)
  38204. return row;
  38205. }
  38206. return -1;
  38207. }
  38208. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38209. {
  38210. if (((unsigned int) x) < (unsigned int) getWidth())
  38211. {
  38212. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38213. return jlimit (0, totalItems, row);
  38214. }
  38215. return -1;
  38216. }
  38217. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38218. {
  38219. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38220. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38221. }
  38222. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38223. {
  38224. return viewport->getRowNumberOfComponent (rowComponent);
  38225. }
  38226. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38227. const bool relativeToComponentTopLeft) const throw()
  38228. {
  38229. const int rowHeight = getRowHeight();
  38230. int y = viewport->getY() + rowHeight * rowNumber;
  38231. if (relativeToComponentTopLeft)
  38232. y -= viewport->getViewPositionY();
  38233. return Rectangle<int> (viewport->getX(), y,
  38234. viewport->getViewedComponent()->getWidth(), rowHeight);
  38235. }
  38236. void ListBox::setVerticalPosition (const double proportion)
  38237. {
  38238. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38239. viewport->setViewPosition (viewport->getViewPositionX(),
  38240. jmax (0, roundToInt (proportion * offscreen)));
  38241. }
  38242. double ListBox::getVerticalPosition() const
  38243. {
  38244. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38245. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38246. : 0;
  38247. }
  38248. int ListBox::getVisibleRowWidth() const throw()
  38249. {
  38250. return viewport->getViewWidth();
  38251. }
  38252. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38253. {
  38254. if (row < viewport->firstWholeIndex)
  38255. {
  38256. viewport->setViewPosition (viewport->getViewPositionX(),
  38257. row * getRowHeight());
  38258. }
  38259. else if (row >= viewport->lastWholeIndex)
  38260. {
  38261. viewport->setViewPosition (viewport->getViewPositionX(),
  38262. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38263. }
  38264. }
  38265. bool ListBox::keyPressed (const KeyPress& key)
  38266. {
  38267. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38268. const bool multiple = multipleSelection
  38269. && (lastRowSelected >= 0)
  38270. && (key.getModifiers().isShiftDown()
  38271. || key.getModifiers().isCtrlDown()
  38272. || key.getModifiers().isCommandDown());
  38273. if (key.isKeyCode (KeyPress::upKey))
  38274. {
  38275. if (multiple)
  38276. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38277. else
  38278. selectRow (jmax (0, lastRowSelected - 1));
  38279. }
  38280. else if (key.isKeyCode (KeyPress::returnKey)
  38281. && isRowSelected (lastRowSelected))
  38282. {
  38283. if (model != 0)
  38284. model->returnKeyPressed (lastRowSelected);
  38285. }
  38286. else if (key.isKeyCode (KeyPress::pageUpKey))
  38287. {
  38288. if (multiple)
  38289. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38290. else
  38291. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38292. }
  38293. else if (key.isKeyCode (KeyPress::pageDownKey))
  38294. {
  38295. if (multiple)
  38296. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38297. else
  38298. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38299. }
  38300. else if (key.isKeyCode (KeyPress::homeKey))
  38301. {
  38302. if (multiple && key.getModifiers().isShiftDown())
  38303. selectRangeOfRows (lastRowSelected, 0);
  38304. else
  38305. selectRow (0);
  38306. }
  38307. else if (key.isKeyCode (KeyPress::endKey))
  38308. {
  38309. if (multiple && key.getModifiers().isShiftDown())
  38310. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38311. else
  38312. selectRow (totalItems - 1);
  38313. }
  38314. else if (key.isKeyCode (KeyPress::downKey))
  38315. {
  38316. if (multiple)
  38317. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38318. else
  38319. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38320. }
  38321. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38322. && isRowSelected (lastRowSelected))
  38323. {
  38324. if (model != 0)
  38325. model->deleteKeyPressed (lastRowSelected);
  38326. }
  38327. else if (multiple && key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  38328. {
  38329. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38330. }
  38331. else
  38332. {
  38333. return false;
  38334. }
  38335. return true;
  38336. }
  38337. bool ListBox::keyStateChanged (const bool isKeyDown)
  38338. {
  38339. return isKeyDown
  38340. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38341. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38342. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38343. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38344. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38345. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38346. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38347. }
  38348. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38349. {
  38350. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38351. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38352. }
  38353. void ListBox::mouseMove (const MouseEvent& e)
  38354. {
  38355. if (mouseMoveSelects)
  38356. {
  38357. const MouseEvent e2 (e.getEventRelativeTo (this));
  38358. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38359. }
  38360. }
  38361. void ListBox::mouseExit (const MouseEvent& e)
  38362. {
  38363. mouseMove (e);
  38364. }
  38365. void ListBox::mouseUp (const MouseEvent& e)
  38366. {
  38367. if (e.mouseWasClicked() && model != 0)
  38368. model->backgroundClicked();
  38369. }
  38370. void ListBox::setRowHeight (const int newHeight)
  38371. {
  38372. rowHeight = jmax (1, newHeight);
  38373. viewport->setSingleStepSizes (20, rowHeight);
  38374. updateContent();
  38375. }
  38376. int ListBox::getNumRowsOnScreen() const throw()
  38377. {
  38378. return viewport->getMaximumVisibleHeight() / rowHeight;
  38379. }
  38380. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38381. {
  38382. minimumRowWidth = newMinimumWidth;
  38383. updateContent();
  38384. }
  38385. int ListBox::getVisibleContentWidth() const throw()
  38386. {
  38387. return viewport->getMaximumVisibleWidth();
  38388. }
  38389. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38390. {
  38391. return viewport->getVerticalScrollBar();
  38392. }
  38393. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38394. {
  38395. return viewport->getHorizontalScrollBar();
  38396. }
  38397. void ListBox::colourChanged()
  38398. {
  38399. setOpaque (findColour (backgroundColourId).isOpaque());
  38400. viewport->setOpaque (isOpaque());
  38401. repaint();
  38402. }
  38403. void ListBox::setOutlineThickness (const int outlineThickness_)
  38404. {
  38405. outlineThickness = outlineThickness_;
  38406. resized();
  38407. }
  38408. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38409. {
  38410. if (headerComponent != newHeaderComponent)
  38411. {
  38412. delete headerComponent;
  38413. headerComponent = newHeaderComponent;
  38414. addAndMakeVisible (newHeaderComponent);
  38415. ListBox::resized();
  38416. }
  38417. }
  38418. void ListBox::repaintRow (const int rowNumber) throw()
  38419. {
  38420. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38421. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38422. }
  38423. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38424. {
  38425. Rectangle<int> imageArea;
  38426. const int firstRow = getRowContainingPosition (0, 0);
  38427. int i;
  38428. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38429. {
  38430. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38431. if (rowComp != 0 && isRowSelected (firstRow + i))
  38432. {
  38433. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38434. const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
  38435. if (imageArea.isEmpty())
  38436. imageArea = rowRect;
  38437. else
  38438. imageArea = imageArea.getUnion (rowRect);
  38439. }
  38440. }
  38441. imageArea = imageArea.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  38442. imageX = imageArea.getX();
  38443. imageY = imageArea.getY();
  38444. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38445. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38446. {
  38447. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38448. if (rowComp != 0 && isRowSelected (firstRow + i))
  38449. {
  38450. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38451. Graphics g (*snapshot);
  38452. g.setOrigin (pos.getX() - imageX, pos.getY() - imageY);
  38453. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38454. rowComp->paintEntireComponent (g);
  38455. }
  38456. }
  38457. return snapshot;
  38458. }
  38459. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38460. {
  38461. DragAndDropContainer* const dragContainer
  38462. = DragAndDropContainer::findParentDragContainerFor (this);
  38463. if (dragContainer != 0)
  38464. {
  38465. int x, y;
  38466. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38467. dragImage->multiplyAllAlphas (0.6f);
  38468. MouseEvent e2 (e.getEventRelativeTo (this));
  38469. const Point<int> p (x - e2.x, y - e2.y);
  38470. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38471. }
  38472. else
  38473. {
  38474. // to be able to do a drag-and-drop operation, the listbox needs to
  38475. // be inside a component which is also a DragAndDropContainer.
  38476. jassertfalse
  38477. }
  38478. }
  38479. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  38480. {
  38481. (void) existingComponentToUpdate;
  38482. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  38483. return 0;
  38484. }
  38485. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  38486. {
  38487. }
  38488. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  38489. {
  38490. }
  38491. void ListBoxModel::backgroundClicked()
  38492. {
  38493. }
  38494. void ListBoxModel::selectedRowsChanged (int)
  38495. {
  38496. }
  38497. void ListBoxModel::deleteKeyPressed (int)
  38498. {
  38499. }
  38500. void ListBoxModel::returnKeyPressed (int)
  38501. {
  38502. }
  38503. void ListBoxModel::listWasScrolled()
  38504. {
  38505. }
  38506. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  38507. {
  38508. return String::empty;
  38509. }
  38510. const String ListBoxModel::getTooltipForRow (int)
  38511. {
  38512. return String::empty;
  38513. }
  38514. END_JUCE_NAMESPACE
  38515. /*** End of inlined file: juce_ListBox.cpp ***/
  38516. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  38517. BEGIN_JUCE_NAMESPACE
  38518. ProgressBar::ProgressBar (double& progress_)
  38519. : progress (progress_),
  38520. displayPercentage (true),
  38521. lastCallbackTime (0)
  38522. {
  38523. currentValue = jlimit (0.0, 1.0, progress);
  38524. }
  38525. ProgressBar::~ProgressBar()
  38526. {
  38527. }
  38528. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  38529. {
  38530. displayPercentage = shouldDisplayPercentage;
  38531. repaint();
  38532. }
  38533. void ProgressBar::setTextToDisplay (const String& text)
  38534. {
  38535. displayPercentage = false;
  38536. displayedMessage = text;
  38537. }
  38538. void ProgressBar::lookAndFeelChanged()
  38539. {
  38540. setOpaque (findColour (backgroundColourId).isOpaque());
  38541. }
  38542. void ProgressBar::colourChanged()
  38543. {
  38544. lookAndFeelChanged();
  38545. }
  38546. void ProgressBar::paint (Graphics& g)
  38547. {
  38548. String text;
  38549. if (displayPercentage)
  38550. {
  38551. if (currentValue >= 0 && currentValue <= 1.0)
  38552. text << roundToInt (currentValue * 100.0) << T("%");
  38553. }
  38554. else
  38555. {
  38556. text = displayedMessage;
  38557. }
  38558. getLookAndFeel().drawProgressBar (g, *this,
  38559. getWidth(), getHeight(),
  38560. currentValue, text);
  38561. }
  38562. void ProgressBar::visibilityChanged()
  38563. {
  38564. if (isVisible())
  38565. startTimer (30);
  38566. else
  38567. stopTimer();
  38568. }
  38569. void ProgressBar::timerCallback()
  38570. {
  38571. double newProgress = progress;
  38572. const uint32 now = Time::getMillisecondCounter();
  38573. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  38574. lastCallbackTime = now;
  38575. if (currentValue != newProgress
  38576. || newProgress < 0 || newProgress >= 1.0
  38577. || currentMessage != displayedMessage)
  38578. {
  38579. if (currentValue < newProgress
  38580. && newProgress >= 0 && newProgress < 1.0
  38581. && currentValue >= 0 && currentValue < 1.0)
  38582. {
  38583. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  38584. newProgress);
  38585. }
  38586. currentValue = newProgress;
  38587. currentMessage = displayedMessage;
  38588. repaint();
  38589. }
  38590. }
  38591. END_JUCE_NAMESPACE
  38592. /*** End of inlined file: juce_ProgressBar.cpp ***/
  38593. /*** Start of inlined file: juce_Slider.cpp ***/
  38594. BEGIN_JUCE_NAMESPACE
  38595. class SliderPopupDisplayComponent : public BubbleComponent
  38596. {
  38597. public:
  38598. SliderPopupDisplayComponent (Slider* const owner_)
  38599. : owner (owner_),
  38600. font (15.0f, Font::bold)
  38601. {
  38602. setAlwaysOnTop (true);
  38603. }
  38604. ~SliderPopupDisplayComponent()
  38605. {
  38606. }
  38607. void paintContent (Graphics& g, int w, int h)
  38608. {
  38609. g.setFont (font);
  38610. g.setColour (Colours::black);
  38611. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  38612. }
  38613. void getContentSize (int& w, int& h)
  38614. {
  38615. w = font.getStringWidth (text) + 18;
  38616. h = (int) (font.getHeight() * 1.6f);
  38617. }
  38618. void updatePosition (const String& newText)
  38619. {
  38620. if (text != newText)
  38621. {
  38622. text = newText;
  38623. repaint();
  38624. }
  38625. BubbleComponent::setPosition (owner);
  38626. }
  38627. juce_UseDebuggingNewOperator
  38628. private:
  38629. Slider* owner;
  38630. Font font;
  38631. String text;
  38632. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  38633. SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  38634. };
  38635. Slider::Slider (const String& name)
  38636. : Component (name),
  38637. lastCurrentValue (0),
  38638. lastValueMin (0),
  38639. lastValueMax (0),
  38640. minimum (0),
  38641. maximum (10),
  38642. interval (0),
  38643. skewFactor (1.0),
  38644. velocityModeSensitivity (1.0),
  38645. velocityModeOffset (0.0),
  38646. velocityModeThreshold (1),
  38647. rotaryStart (float_Pi * 1.2f),
  38648. rotaryEnd (float_Pi * 2.8f),
  38649. numDecimalPlaces (7),
  38650. sliderRegionStart (0),
  38651. sliderRegionSize (1),
  38652. sliderBeingDragged (-1),
  38653. pixelsForFullDragExtent (250),
  38654. style (LinearHorizontal),
  38655. textBoxPos (TextBoxLeft),
  38656. textBoxWidth (80),
  38657. textBoxHeight (20),
  38658. incDecButtonMode (incDecButtonsNotDraggable),
  38659. editableText (true),
  38660. doubleClickToValue (false),
  38661. isVelocityBased (false),
  38662. userKeyOverridesVelocity (true),
  38663. rotaryStop (true),
  38664. incDecButtonsSideBySide (false),
  38665. sendChangeOnlyOnRelease (false),
  38666. popupDisplayEnabled (false),
  38667. menuEnabled (false),
  38668. menuShown (false),
  38669. scrollWheelEnabled (true),
  38670. snapsToMousePos (true),
  38671. valueBox (0),
  38672. incButton (0),
  38673. decButton (0),
  38674. popupDisplay (0),
  38675. parentForPopupDisplay (0)
  38676. {
  38677. setWantsKeyboardFocus (false);
  38678. setRepaintsOnMouseActivity (true);
  38679. lookAndFeelChanged();
  38680. updateText();
  38681. currentValue.addListener (this);
  38682. valueMin.addListener (this);
  38683. valueMax.addListener (this);
  38684. }
  38685. Slider::~Slider()
  38686. {
  38687. currentValue.removeListener (this);
  38688. valueMin.removeListener (this);
  38689. valueMax.removeListener (this);
  38690. popupDisplay = 0;
  38691. deleteAllChildren();
  38692. }
  38693. void Slider::handleAsyncUpdate()
  38694. {
  38695. cancelPendingUpdate();
  38696. Component::BailOutChecker checker (this);
  38697. listeners.callChecked (checker, &SliderListener::sliderValueChanged, this);
  38698. }
  38699. void Slider::sendDragStart()
  38700. {
  38701. startedDragging();
  38702. Component::BailOutChecker checker (this);
  38703. listeners.callChecked (checker, &SliderListener::sliderDragStarted, this);
  38704. }
  38705. void Slider::sendDragEnd()
  38706. {
  38707. stoppedDragging();
  38708. sliderBeingDragged = -1;
  38709. Component::BailOutChecker checker (this);
  38710. listeners.callChecked (checker, &SliderListener::sliderDragEnded, this);
  38711. }
  38712. void Slider::addListener (SliderListener* const listener)
  38713. {
  38714. listeners.add (listener);
  38715. }
  38716. void Slider::removeListener (SliderListener* const listener)
  38717. {
  38718. listeners.remove (listener);
  38719. }
  38720. void Slider::setSliderStyle (const SliderStyle newStyle)
  38721. {
  38722. if (style != newStyle)
  38723. {
  38724. style = newStyle;
  38725. repaint();
  38726. lookAndFeelChanged();
  38727. }
  38728. }
  38729. void Slider::setRotaryParameters (const float startAngleRadians,
  38730. const float endAngleRadians,
  38731. const bool stopAtEnd)
  38732. {
  38733. // make sure the values are sensible..
  38734. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  38735. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  38736. jassert (rotaryStart < rotaryEnd);
  38737. rotaryStart = startAngleRadians;
  38738. rotaryEnd = endAngleRadians;
  38739. rotaryStop = stopAtEnd;
  38740. }
  38741. void Slider::setVelocityBasedMode (const bool velBased)
  38742. {
  38743. isVelocityBased = velBased;
  38744. }
  38745. void Slider::setVelocityModeParameters (const double sensitivity,
  38746. const int threshold,
  38747. const double offset,
  38748. const bool userCanPressKeyToSwapMode)
  38749. {
  38750. jassert (threshold >= 0);
  38751. jassert (sensitivity > 0);
  38752. jassert (offset >= 0);
  38753. velocityModeSensitivity = sensitivity;
  38754. velocityModeOffset = offset;
  38755. velocityModeThreshold = threshold;
  38756. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  38757. }
  38758. void Slider::setSkewFactor (const double factor)
  38759. {
  38760. skewFactor = factor;
  38761. }
  38762. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  38763. {
  38764. if (maximum > minimum)
  38765. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  38766. / (maximum - minimum));
  38767. }
  38768. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  38769. {
  38770. jassert (distanceForFullScaleDrag > 0);
  38771. pixelsForFullDragExtent = distanceForFullScaleDrag;
  38772. }
  38773. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  38774. {
  38775. if (incDecButtonMode != mode)
  38776. {
  38777. incDecButtonMode = mode;
  38778. lookAndFeelChanged();
  38779. }
  38780. }
  38781. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  38782. const bool isReadOnly,
  38783. const int textEntryBoxWidth,
  38784. const int textEntryBoxHeight)
  38785. {
  38786. textBoxPos = newPosition;
  38787. editableText = ! isReadOnly;
  38788. textBoxWidth = textEntryBoxWidth;
  38789. textBoxHeight = textEntryBoxHeight;
  38790. repaint();
  38791. lookAndFeelChanged();
  38792. }
  38793. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  38794. {
  38795. editableText = shouldBeEditable;
  38796. if (valueBox != 0)
  38797. valueBox->setEditable (shouldBeEditable && isEnabled());
  38798. }
  38799. void Slider::showTextBox()
  38800. {
  38801. jassert (editableText); // this should probably be avoided in read-only sliders.
  38802. if (valueBox != 0)
  38803. valueBox->showEditor();
  38804. }
  38805. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  38806. {
  38807. if (valueBox != 0)
  38808. {
  38809. valueBox->hideEditor (discardCurrentEditorContents);
  38810. if (discardCurrentEditorContents)
  38811. updateText();
  38812. }
  38813. }
  38814. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  38815. {
  38816. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  38817. }
  38818. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  38819. {
  38820. snapsToMousePos = shouldSnapToMouse;
  38821. }
  38822. void Slider::setPopupDisplayEnabled (const bool enabled,
  38823. Component* const parentComponentToUse)
  38824. {
  38825. popupDisplayEnabled = enabled;
  38826. parentForPopupDisplay = parentComponentToUse;
  38827. }
  38828. void Slider::colourChanged()
  38829. {
  38830. lookAndFeelChanged();
  38831. }
  38832. void Slider::lookAndFeelChanged()
  38833. {
  38834. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  38835. : getTextFromValue (currentValue.getValue()));
  38836. deleteAllChildren();
  38837. valueBox = 0;
  38838. LookAndFeel& lf = getLookAndFeel();
  38839. if (textBoxPos != NoTextBox)
  38840. {
  38841. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  38842. valueBox->setWantsKeyboardFocus (false);
  38843. valueBox->setText (previousTextBoxContent, false);
  38844. valueBox->setEditable (editableText && isEnabled());
  38845. valueBox->addListener (this);
  38846. if (style == LinearBar)
  38847. valueBox->addMouseListener (this, false);
  38848. valueBox->setTooltip (getTooltip());
  38849. }
  38850. if (style == IncDecButtons)
  38851. {
  38852. addAndMakeVisible (incButton = lf.createSliderButton (true));
  38853. incButton->addButtonListener (this);
  38854. addAndMakeVisible (decButton = lf.createSliderButton (false));
  38855. decButton->addButtonListener (this);
  38856. if (incDecButtonMode != incDecButtonsNotDraggable)
  38857. {
  38858. incButton->addMouseListener (this, false);
  38859. decButton->addMouseListener (this, false);
  38860. }
  38861. else
  38862. {
  38863. incButton->setRepeatSpeed (300, 100, 20);
  38864. incButton->addMouseListener (decButton, false);
  38865. decButton->setRepeatSpeed (300, 100, 20);
  38866. decButton->addMouseListener (incButton, false);
  38867. }
  38868. incButton->setTooltip (getTooltip());
  38869. decButton->setTooltip (getTooltip());
  38870. }
  38871. setComponentEffect (lf.getSliderEffect());
  38872. resized();
  38873. repaint();
  38874. }
  38875. void Slider::setRange (const double newMin,
  38876. const double newMax,
  38877. const double newInt)
  38878. {
  38879. if (minimum != newMin
  38880. || maximum != newMax
  38881. || interval != newInt)
  38882. {
  38883. minimum = newMin;
  38884. maximum = newMax;
  38885. interval = newInt;
  38886. // figure out the number of DPs needed to display all values at this
  38887. // interval setting.
  38888. numDecimalPlaces = 7;
  38889. if (newInt != 0)
  38890. {
  38891. int v = abs ((int) (newInt * 10000000));
  38892. while ((v % 10) == 0)
  38893. {
  38894. --numDecimalPlaces;
  38895. v /= 10;
  38896. }
  38897. }
  38898. // keep the current values inside the new range..
  38899. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38900. {
  38901. setValue (getValue(), false, false);
  38902. }
  38903. else
  38904. {
  38905. setMinValue (getMinValue(), false, false);
  38906. setMaxValue (getMaxValue(), false, false);
  38907. }
  38908. updateText();
  38909. }
  38910. }
  38911. void Slider::triggerChangeMessage (const bool synchronous)
  38912. {
  38913. if (synchronous)
  38914. handleAsyncUpdate();
  38915. else
  38916. triggerAsyncUpdate();
  38917. valueChanged();
  38918. }
  38919. void Slider::valueChanged (Value& value)
  38920. {
  38921. if (value.refersToSameSourceAs (currentValue))
  38922. {
  38923. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38924. setValue (currentValue.getValue(), false, false);
  38925. }
  38926. else if (value.refersToSameSourceAs (valueMin))
  38927. setMinValue (valueMin.getValue(), false, false, true);
  38928. else if (value.refersToSameSourceAs (valueMax))
  38929. setMaxValue (valueMax.getValue(), false, false, true);
  38930. }
  38931. double Slider::getValue() const
  38932. {
  38933. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  38934. // methods to get the two values.
  38935. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38936. return currentValue.getValue();
  38937. }
  38938. void Slider::setValue (double newValue,
  38939. const bool sendUpdateMessage,
  38940. const bool sendMessageSynchronously)
  38941. {
  38942. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  38943. // methods to set the two values.
  38944. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38945. newValue = constrainedValue (newValue);
  38946. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  38947. {
  38948. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  38949. newValue = jlimit ((double) valueMin.getValue(),
  38950. (double) valueMax.getValue(),
  38951. newValue);
  38952. }
  38953. if (newValue != lastCurrentValue)
  38954. {
  38955. if (valueBox != 0)
  38956. valueBox->hideEditor (true);
  38957. lastCurrentValue = newValue;
  38958. currentValue = newValue;
  38959. updateText();
  38960. repaint();
  38961. if (popupDisplay != 0)
  38962. {
  38963. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  38964. ->updatePosition (getTextFromValue (newValue));
  38965. popupDisplay->repaint();
  38966. }
  38967. if (sendUpdateMessage)
  38968. triggerChangeMessage (sendMessageSynchronously);
  38969. }
  38970. }
  38971. double Slider::getMinValue() const
  38972. {
  38973. // The minimum value only applies to sliders that are in two- or three-value mode.
  38974. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38975. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38976. return valueMin.getValue();
  38977. }
  38978. double Slider::getMaxValue() const
  38979. {
  38980. // The maximum value only applies to sliders that are in two- or three-value mode.
  38981. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38982. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38983. return valueMax.getValue();
  38984. }
  38985. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  38986. {
  38987. // The minimum value only applies to sliders that are in two- or three-value mode.
  38988. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38989. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38990. newValue = constrainedValue (newValue);
  38991. if (style == TwoValueHorizontal || style == TwoValueVertical)
  38992. {
  38993. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  38994. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  38995. newValue = jmin ((double) valueMax.getValue(), newValue);
  38996. }
  38997. else
  38998. {
  38999. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39000. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39001. newValue = jmin (lastCurrentValue, newValue);
  39002. }
  39003. if (lastValueMin != newValue)
  39004. {
  39005. lastValueMin = newValue;
  39006. valueMin = newValue;
  39007. repaint();
  39008. if (popupDisplay != 0)
  39009. {
  39010. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39011. ->updatePosition (getTextFromValue (newValue));
  39012. popupDisplay->repaint();
  39013. }
  39014. if (sendUpdateMessage)
  39015. triggerChangeMessage (sendMessageSynchronously);
  39016. }
  39017. }
  39018. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39019. {
  39020. // The maximum value only applies to sliders that are in two- or three-value mode.
  39021. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39022. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39023. newValue = constrainedValue (newValue);
  39024. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39025. {
  39026. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39027. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39028. newValue = jmax ((double) valueMin.getValue(), newValue);
  39029. }
  39030. else
  39031. {
  39032. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39033. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39034. newValue = jmax (lastCurrentValue, newValue);
  39035. }
  39036. if (lastValueMax != newValue)
  39037. {
  39038. lastValueMax = newValue;
  39039. valueMax = newValue;
  39040. repaint();
  39041. if (popupDisplay != 0)
  39042. {
  39043. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39044. ->updatePosition (getTextFromValue (valueMax.getValue()));
  39045. popupDisplay->repaint();
  39046. }
  39047. if (sendUpdateMessage)
  39048. triggerChangeMessage (sendMessageSynchronously);
  39049. }
  39050. }
  39051. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39052. const double valueToSetOnDoubleClick)
  39053. {
  39054. doubleClickToValue = isDoubleClickEnabled;
  39055. doubleClickReturnValue = valueToSetOnDoubleClick;
  39056. }
  39057. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39058. {
  39059. isEnabled_ = doubleClickToValue;
  39060. return doubleClickReturnValue;
  39061. }
  39062. void Slider::updateText()
  39063. {
  39064. if (valueBox != 0)
  39065. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39066. }
  39067. void Slider::setTextValueSuffix (const String& suffix)
  39068. {
  39069. if (textSuffix != suffix)
  39070. {
  39071. textSuffix = suffix;
  39072. updateText();
  39073. }
  39074. }
  39075. const String Slider::getTextFromValue (double v)
  39076. {
  39077. if (numDecimalPlaces > 0)
  39078. return String (v, numDecimalPlaces) + textSuffix;
  39079. else
  39080. return String (roundToInt (v)) + textSuffix;
  39081. }
  39082. double Slider::getValueFromText (const String& text)
  39083. {
  39084. String t (text.trimStart());
  39085. if (t.endsWith (textSuffix))
  39086. t = t.substring (0, t.length() - textSuffix.length());
  39087. while (t.startsWithChar (T('+')))
  39088. t = t.substring (1).trimStart();
  39089. return t.initialSectionContainingOnly (T("0123456789.,-"))
  39090. .getDoubleValue();
  39091. }
  39092. double Slider::proportionOfLengthToValue (double proportion)
  39093. {
  39094. if (skewFactor != 1.0 && proportion > 0.0)
  39095. proportion = exp (log (proportion) / skewFactor);
  39096. return minimum + (maximum - minimum) * proportion;
  39097. }
  39098. double Slider::valueToProportionOfLength (double value)
  39099. {
  39100. const double n = (value - minimum) / (maximum - minimum);
  39101. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39102. }
  39103. double Slider::snapValue (double attemptedValue, const bool)
  39104. {
  39105. return attemptedValue;
  39106. }
  39107. void Slider::startedDragging()
  39108. {
  39109. }
  39110. void Slider::stoppedDragging()
  39111. {
  39112. }
  39113. void Slider::valueChanged()
  39114. {
  39115. }
  39116. void Slider::enablementChanged()
  39117. {
  39118. repaint();
  39119. }
  39120. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39121. {
  39122. menuEnabled = menuEnabled_;
  39123. }
  39124. void Slider::setScrollWheelEnabled (const bool enabled)
  39125. {
  39126. scrollWheelEnabled = enabled;
  39127. }
  39128. void Slider::labelTextChanged (Label* label)
  39129. {
  39130. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39131. if (newValue != (double) currentValue.getValue())
  39132. {
  39133. sendDragStart();
  39134. setValue (newValue, true, true);
  39135. sendDragEnd();
  39136. }
  39137. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39138. }
  39139. void Slider::buttonClicked (Button* button)
  39140. {
  39141. if (style == IncDecButtons)
  39142. {
  39143. sendDragStart();
  39144. if (button == incButton)
  39145. setValue (snapValue (getValue() + interval, false), true, true);
  39146. else if (button == decButton)
  39147. setValue (snapValue (getValue() - interval, false), true, true);
  39148. sendDragEnd();
  39149. }
  39150. }
  39151. double Slider::constrainedValue (double value) const
  39152. {
  39153. if (interval > 0)
  39154. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39155. if (value <= minimum || maximum <= minimum)
  39156. value = minimum;
  39157. else if (value >= maximum)
  39158. value = maximum;
  39159. return value;
  39160. }
  39161. float Slider::getLinearSliderPos (const double value)
  39162. {
  39163. double sliderPosProportional;
  39164. if (maximum > minimum)
  39165. {
  39166. if (value < minimum)
  39167. {
  39168. sliderPosProportional = 0.0;
  39169. }
  39170. else if (value > maximum)
  39171. {
  39172. sliderPosProportional = 1.0;
  39173. }
  39174. else
  39175. {
  39176. sliderPosProportional = valueToProportionOfLength (value);
  39177. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39178. }
  39179. }
  39180. else
  39181. {
  39182. sliderPosProportional = 0.5;
  39183. }
  39184. if (isVertical() || style == IncDecButtons)
  39185. sliderPosProportional = 1.0 - sliderPosProportional;
  39186. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39187. }
  39188. bool Slider::isHorizontal() const
  39189. {
  39190. return style == LinearHorizontal
  39191. || style == LinearBar
  39192. || style == TwoValueHorizontal
  39193. || style == ThreeValueHorizontal;
  39194. }
  39195. bool Slider::isVertical() const
  39196. {
  39197. return style == LinearVertical
  39198. || style == TwoValueVertical
  39199. || style == ThreeValueVertical;
  39200. }
  39201. bool Slider::incDecDragDirectionIsHorizontal() const
  39202. {
  39203. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39204. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39205. }
  39206. float Slider::getPositionOfValue (const double value)
  39207. {
  39208. if (isHorizontal() || isVertical())
  39209. {
  39210. return getLinearSliderPos (value);
  39211. }
  39212. else
  39213. {
  39214. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39215. return 0.0f;
  39216. }
  39217. }
  39218. void Slider::paint (Graphics& g)
  39219. {
  39220. if (style != IncDecButtons)
  39221. {
  39222. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39223. {
  39224. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39225. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39226. getLookAndFeel().drawRotarySlider (g,
  39227. sliderRect.getX(),
  39228. sliderRect.getY(),
  39229. sliderRect.getWidth(),
  39230. sliderRect.getHeight(),
  39231. sliderPos,
  39232. rotaryStart, rotaryEnd,
  39233. *this);
  39234. }
  39235. else
  39236. {
  39237. getLookAndFeel().drawLinearSlider (g,
  39238. sliderRect.getX(),
  39239. sliderRect.getY(),
  39240. sliderRect.getWidth(),
  39241. sliderRect.getHeight(),
  39242. getLinearSliderPos (lastCurrentValue),
  39243. getLinearSliderPos (lastValueMin),
  39244. getLinearSliderPos (lastValueMax),
  39245. style,
  39246. *this);
  39247. }
  39248. if (style == LinearBar && valueBox == 0)
  39249. {
  39250. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39251. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39252. }
  39253. }
  39254. }
  39255. void Slider::resized()
  39256. {
  39257. int minXSpace = 0;
  39258. int minYSpace = 0;
  39259. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39260. minXSpace = 30;
  39261. else
  39262. minYSpace = 15;
  39263. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39264. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39265. if (style == LinearBar)
  39266. {
  39267. if (valueBox != 0)
  39268. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39269. }
  39270. else
  39271. {
  39272. if (textBoxPos == NoTextBox)
  39273. {
  39274. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39275. }
  39276. else if (textBoxPos == TextBoxLeft)
  39277. {
  39278. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39279. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39280. }
  39281. else if (textBoxPos == TextBoxRight)
  39282. {
  39283. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39284. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39285. }
  39286. else if (textBoxPos == TextBoxAbove)
  39287. {
  39288. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39289. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39290. }
  39291. else if (textBoxPos == TextBoxBelow)
  39292. {
  39293. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39294. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39295. }
  39296. }
  39297. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39298. if (style == LinearBar)
  39299. {
  39300. const int barIndent = 1;
  39301. sliderRegionStart = barIndent;
  39302. sliderRegionSize = getWidth() - barIndent * 2;
  39303. sliderRect.setBounds (sliderRegionStart, barIndent,
  39304. sliderRegionSize, getHeight() - barIndent * 2);
  39305. }
  39306. else if (isHorizontal())
  39307. {
  39308. sliderRegionStart = sliderRect.getX() + indent;
  39309. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39310. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39311. sliderRegionSize, sliderRect.getHeight());
  39312. }
  39313. else if (isVertical())
  39314. {
  39315. sliderRegionStart = sliderRect.getY() + indent;
  39316. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39317. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39318. sliderRect.getWidth(), sliderRegionSize);
  39319. }
  39320. else
  39321. {
  39322. sliderRegionStart = 0;
  39323. sliderRegionSize = 100;
  39324. }
  39325. if (style == IncDecButtons)
  39326. {
  39327. Rectangle<int> buttonRect (sliderRect);
  39328. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39329. buttonRect.expand (-2, 0);
  39330. else
  39331. buttonRect.expand (0, -2);
  39332. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39333. if (incDecButtonsSideBySide)
  39334. {
  39335. decButton->setBounds (buttonRect.getX(),
  39336. buttonRect.getY(),
  39337. buttonRect.getWidth() / 2,
  39338. buttonRect.getHeight());
  39339. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39340. incButton->setBounds (buttonRect.getCentreX(),
  39341. buttonRect.getY(),
  39342. buttonRect.getWidth() / 2,
  39343. buttonRect.getHeight());
  39344. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39345. }
  39346. else
  39347. {
  39348. incButton->setBounds (buttonRect.getX(),
  39349. buttonRect.getY(),
  39350. buttonRect.getWidth(),
  39351. buttonRect.getHeight() / 2);
  39352. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39353. decButton->setBounds (buttonRect.getX(),
  39354. buttonRect.getCentreY(),
  39355. buttonRect.getWidth(),
  39356. buttonRect.getHeight() / 2);
  39357. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39358. }
  39359. }
  39360. }
  39361. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39362. {
  39363. repaint();
  39364. }
  39365. void Slider::mouseDown (const MouseEvent& e)
  39366. {
  39367. mouseWasHidden = false;
  39368. incDecDragged = false;
  39369. mouseXWhenLastDragged = e.x;
  39370. mouseYWhenLastDragged = e.y;
  39371. mouseDragStartX = e.getMouseDownX();
  39372. mouseDragStartY = e.getMouseDownY();
  39373. if (isEnabled())
  39374. {
  39375. if (e.mods.isPopupMenu() && menuEnabled)
  39376. {
  39377. menuShown = true;
  39378. PopupMenu m;
  39379. m.setLookAndFeel (&getLookAndFeel());
  39380. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39381. m.addSeparator();
  39382. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39383. {
  39384. PopupMenu rotaryMenu;
  39385. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39386. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39387. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39388. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39389. }
  39390. const int r = m.show();
  39391. if (r == 1)
  39392. {
  39393. setVelocityBasedMode (! isVelocityBased);
  39394. }
  39395. else if (r == 2)
  39396. {
  39397. setSliderStyle (Rotary);
  39398. }
  39399. else if (r == 3)
  39400. {
  39401. setSliderStyle (RotaryHorizontalDrag);
  39402. }
  39403. else if (r == 4)
  39404. {
  39405. setSliderStyle (RotaryVerticalDrag);
  39406. }
  39407. }
  39408. else if (maximum > minimum)
  39409. {
  39410. menuShown = false;
  39411. if (valueBox != 0)
  39412. valueBox->hideEditor (true);
  39413. sliderBeingDragged = 0;
  39414. if (style == TwoValueHorizontal
  39415. || style == TwoValueVertical
  39416. || style == ThreeValueHorizontal
  39417. || style == ThreeValueVertical)
  39418. {
  39419. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39420. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39421. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39422. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39423. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39424. {
  39425. if (maxPosDistance <= minPosDistance)
  39426. sliderBeingDragged = 2;
  39427. else
  39428. sliderBeingDragged = 1;
  39429. }
  39430. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39431. {
  39432. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39433. sliderBeingDragged = 1;
  39434. else if (normalPosDistance >= maxPosDistance)
  39435. sliderBeingDragged = 2;
  39436. }
  39437. }
  39438. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39439. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39440. * valueToProportionOfLength (currentValue.getValue());
  39441. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39442. : ((sliderBeingDragged == 1) ? valueMin
  39443. : currentValue)).getValue();
  39444. valueOnMouseDown = valueWhenLastDragged;
  39445. if (popupDisplayEnabled)
  39446. {
  39447. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39448. popupDisplay = popup;
  39449. if (parentForPopupDisplay != 0)
  39450. {
  39451. parentForPopupDisplay->addChildComponent (popup);
  39452. }
  39453. else
  39454. {
  39455. popup->addToDesktop (0);
  39456. }
  39457. popup->setVisible (true);
  39458. }
  39459. sendDragStart();
  39460. mouseDrag (e);
  39461. }
  39462. }
  39463. }
  39464. void Slider::mouseUp (const MouseEvent&)
  39465. {
  39466. if (isEnabled()
  39467. && (! menuShown)
  39468. && (maximum > minimum)
  39469. && (style != IncDecButtons || incDecDragged))
  39470. {
  39471. restoreMouseIfHidden();
  39472. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  39473. triggerChangeMessage (false);
  39474. sendDragEnd();
  39475. popupDisplay = 0;
  39476. if (style == IncDecButtons)
  39477. {
  39478. incButton->setState (Button::buttonNormal);
  39479. decButton->setState (Button::buttonNormal);
  39480. }
  39481. }
  39482. }
  39483. void Slider::restoreMouseIfHidden()
  39484. {
  39485. if (mouseWasHidden)
  39486. {
  39487. mouseWasHidden = false;
  39488. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  39489. Desktop::getInstance().getMouseSource(i)->enableUnboundedMouseMovement (false);
  39490. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  39491. : ((sliderBeingDragged == 1) ? getMinValue()
  39492. : (double) currentValue.getValue());
  39493. Point<int> mousePos;
  39494. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39495. {
  39496. mousePos = Desktop::getLastMouseDownPosition();
  39497. if (style == RotaryHorizontalDrag)
  39498. {
  39499. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  39500. mousePos += Point<int> (roundToInt (pixelsForFullDragExtent * posDiff), 0);
  39501. }
  39502. else
  39503. {
  39504. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  39505. mousePos += Point<int> (0, roundToInt (pixelsForFullDragExtent * posDiff));
  39506. }
  39507. }
  39508. else
  39509. {
  39510. const int pixelPos = (int) getLinearSliderPos (pos);
  39511. mousePos = relativePositionToGlobal (Point<int> (isHorizontal() ? pixelPos : (getWidth() / 2),
  39512. isVertical() ? pixelPos : (getHeight() / 2)));
  39513. }
  39514. Desktop::setMousePosition (mousePos);
  39515. }
  39516. }
  39517. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  39518. {
  39519. if (isEnabled()
  39520. && style != IncDecButtons
  39521. && style != Rotary
  39522. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  39523. {
  39524. restoreMouseIfHidden();
  39525. }
  39526. }
  39527. static double smallestAngleBetween (double a1, double a2)
  39528. {
  39529. return jmin (fabs (a1 - a2),
  39530. fabs (a1 + double_Pi * 2.0 - a2),
  39531. fabs (a2 + double_Pi * 2.0 - a1));
  39532. }
  39533. void Slider::mouseDrag (const MouseEvent& e)
  39534. {
  39535. if (isEnabled()
  39536. && (! menuShown)
  39537. && (maximum > minimum))
  39538. {
  39539. if (style == Rotary)
  39540. {
  39541. int dx = e.x - sliderRect.getCentreX();
  39542. int dy = e.y - sliderRect.getCentreY();
  39543. if (dx * dx + dy * dy > 25)
  39544. {
  39545. double angle = atan2 ((double) dx, (double) -dy);
  39546. while (angle < 0.0)
  39547. angle += double_Pi * 2.0;
  39548. if (rotaryStop && ! e.mouseWasClicked())
  39549. {
  39550. if (fabs (angle - lastAngle) > double_Pi)
  39551. {
  39552. if (angle >= lastAngle)
  39553. angle -= double_Pi * 2.0;
  39554. else
  39555. angle += double_Pi * 2.0;
  39556. }
  39557. if (angle >= lastAngle)
  39558. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  39559. else
  39560. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  39561. }
  39562. else
  39563. {
  39564. while (angle < rotaryStart)
  39565. angle += double_Pi * 2.0;
  39566. if (angle > rotaryEnd)
  39567. {
  39568. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  39569. angle = rotaryStart;
  39570. else
  39571. angle = rotaryEnd;
  39572. }
  39573. }
  39574. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  39575. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  39576. lastAngle = angle;
  39577. }
  39578. }
  39579. else
  39580. {
  39581. if (style == LinearBar && e.mouseWasClicked()
  39582. && valueBox != 0 && valueBox->isEditable())
  39583. return;
  39584. if (style == IncDecButtons && ! incDecDragged)
  39585. {
  39586. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  39587. return;
  39588. incDecDragged = true;
  39589. mouseDragStartX = e.x;
  39590. mouseDragStartY = e.y;
  39591. }
  39592. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  39593. : false))
  39594. || ((maximum - minimum) / sliderRegionSize < interval))
  39595. {
  39596. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  39597. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  39598. if (style == RotaryHorizontalDrag
  39599. || style == RotaryVerticalDrag
  39600. || style == IncDecButtons
  39601. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  39602. && ! snapsToMousePos))
  39603. {
  39604. const int mouseDiff = (style == RotaryHorizontalDrag
  39605. || style == LinearHorizontal
  39606. || style == LinearBar
  39607. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39608. ? e.x - mouseDragStartX
  39609. : mouseDragStartY - e.y;
  39610. double newPos = valueToProportionOfLength (valueOnMouseDown)
  39611. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  39612. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  39613. if (style == IncDecButtons)
  39614. {
  39615. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  39616. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  39617. }
  39618. }
  39619. else
  39620. {
  39621. if (isVertical())
  39622. scaledMousePos = 1.0 - scaledMousePos;
  39623. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  39624. }
  39625. }
  39626. else
  39627. {
  39628. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  39629. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39630. ? e.x - mouseXWhenLastDragged
  39631. : e.y - mouseYWhenLastDragged;
  39632. const double maxSpeed = jmax (200, sliderRegionSize);
  39633. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  39634. if (speed != 0)
  39635. {
  39636. speed = 0.2 * velocityModeSensitivity
  39637. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  39638. + jmax (0.0, (double) (speed - velocityModeThreshold))
  39639. / maxSpeed))));
  39640. if (mouseDiff < 0)
  39641. speed = -speed;
  39642. if (isVertical() || style == RotaryVerticalDrag
  39643. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  39644. speed = -speed;
  39645. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  39646. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  39647. e.source.enableUnboundedMouseMovement (true, false);
  39648. mouseWasHidden = true;
  39649. }
  39650. }
  39651. }
  39652. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  39653. if (sliderBeingDragged == 0)
  39654. {
  39655. setValue (snapValue (valueWhenLastDragged, true),
  39656. ! sendChangeOnlyOnRelease, true);
  39657. }
  39658. else if (sliderBeingDragged == 1)
  39659. {
  39660. setMinValue (snapValue (valueWhenLastDragged, true),
  39661. ! sendChangeOnlyOnRelease, false, true);
  39662. if (e.mods.isShiftDown())
  39663. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  39664. else
  39665. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39666. }
  39667. else
  39668. {
  39669. jassert (sliderBeingDragged == 2);
  39670. setMaxValue (snapValue (valueWhenLastDragged, true),
  39671. ! sendChangeOnlyOnRelease, false, true);
  39672. if (e.mods.isShiftDown())
  39673. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  39674. else
  39675. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39676. }
  39677. mouseXWhenLastDragged = e.x;
  39678. mouseYWhenLastDragged = e.y;
  39679. }
  39680. }
  39681. void Slider::mouseDoubleClick (const MouseEvent&)
  39682. {
  39683. if (doubleClickToValue
  39684. && isEnabled()
  39685. && style != IncDecButtons
  39686. && minimum <= doubleClickReturnValue
  39687. && maximum >= doubleClickReturnValue)
  39688. {
  39689. sendDragStart();
  39690. setValue (doubleClickReturnValue, true, true);
  39691. sendDragEnd();
  39692. }
  39693. }
  39694. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  39695. {
  39696. if (scrollWheelEnabled && isEnabled()
  39697. && style != TwoValueHorizontal
  39698. && style != TwoValueVertical)
  39699. {
  39700. if (maximum > minimum && ! e.mods.isAnyMouseButtonDown())
  39701. {
  39702. if (valueBox != 0)
  39703. valueBox->hideEditor (false);
  39704. const double value = (double) currentValue.getValue();
  39705. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  39706. const double currentPos = valueToProportionOfLength (value);
  39707. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  39708. double delta = (newValue != value)
  39709. ? jmax (fabs (newValue - value), interval) : 0;
  39710. if (value > newValue)
  39711. delta = -delta;
  39712. sendDragStart();
  39713. setValue (snapValue (value + delta, false), true, true);
  39714. sendDragEnd();
  39715. }
  39716. }
  39717. else
  39718. {
  39719. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  39720. }
  39721. }
  39722. void SliderListener::sliderDragStarted (Slider*)
  39723. {
  39724. }
  39725. void SliderListener::sliderDragEnded (Slider*)
  39726. {
  39727. }
  39728. END_JUCE_NAMESPACE
  39729. /*** End of inlined file: juce_Slider.cpp ***/
  39730. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  39731. BEGIN_JUCE_NAMESPACE
  39732. class DragOverlayComp : public Component
  39733. {
  39734. public:
  39735. DragOverlayComp (Image* const image_)
  39736. : image (image_)
  39737. {
  39738. image->multiplyAllAlphas (0.8f);
  39739. setAlwaysOnTop (true);
  39740. }
  39741. ~DragOverlayComp()
  39742. {
  39743. }
  39744. void paint (Graphics& g)
  39745. {
  39746. g.drawImageAt (image, 0, 0);
  39747. }
  39748. private:
  39749. ScopedPointer <Image> image;
  39750. DragOverlayComp (const DragOverlayComp&);
  39751. DragOverlayComp& operator= (const DragOverlayComp&);
  39752. };
  39753. TableHeaderComponent::TableHeaderComponent()
  39754. : columnsChanged (false),
  39755. columnsResized (false),
  39756. sortChanged (false),
  39757. menuActive (true),
  39758. stretchToFit (false),
  39759. columnIdBeingResized (0),
  39760. columnIdBeingDragged (0),
  39761. columnIdUnderMouse (0),
  39762. lastDeliberateWidth (0)
  39763. {
  39764. }
  39765. TableHeaderComponent::~TableHeaderComponent()
  39766. {
  39767. dragOverlayComp = 0;
  39768. }
  39769. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  39770. {
  39771. menuActive = hasMenu;
  39772. }
  39773. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  39774. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  39775. {
  39776. if (onlyCountVisibleColumns)
  39777. {
  39778. int num = 0;
  39779. for (int i = columns.size(); --i >= 0;)
  39780. if (columns.getUnchecked(i)->isVisible())
  39781. ++num;
  39782. return num;
  39783. }
  39784. else
  39785. {
  39786. return columns.size();
  39787. }
  39788. }
  39789. const String TableHeaderComponent::getColumnName (const int columnId) const
  39790. {
  39791. const ColumnInfo* const ci = getInfoForId (columnId);
  39792. return ci != 0 ? ci->name : String::empty;
  39793. }
  39794. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  39795. {
  39796. ColumnInfo* const ci = getInfoForId (columnId);
  39797. if (ci != 0 && ci->name != newName)
  39798. {
  39799. ci->name = newName;
  39800. sendColumnsChanged();
  39801. }
  39802. }
  39803. void TableHeaderComponent::addColumn (const String& columnName,
  39804. const int columnId,
  39805. const int width,
  39806. const int minimumWidth,
  39807. const int maximumWidth,
  39808. const int propertyFlags,
  39809. const int insertIndex)
  39810. {
  39811. // can't have a duplicate or null ID!
  39812. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  39813. jassert (width > 0);
  39814. ColumnInfo* const ci = new ColumnInfo();
  39815. ci->name = columnName;
  39816. ci->id = columnId;
  39817. ci->width = width;
  39818. ci->lastDeliberateWidth = width;
  39819. ci->minimumWidth = minimumWidth;
  39820. ci->maximumWidth = maximumWidth;
  39821. if (ci->maximumWidth < 0)
  39822. ci->maximumWidth = std::numeric_limits<int>::max();
  39823. jassert (ci->maximumWidth >= ci->minimumWidth);
  39824. ci->propertyFlags = propertyFlags;
  39825. columns.insert (insertIndex, ci);
  39826. sendColumnsChanged();
  39827. }
  39828. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  39829. {
  39830. const int index = getIndexOfColumnId (columnIdToRemove, false);
  39831. if (index >= 0)
  39832. {
  39833. columns.remove (index);
  39834. sortChanged = true;
  39835. sendColumnsChanged();
  39836. }
  39837. }
  39838. void TableHeaderComponent::removeAllColumns()
  39839. {
  39840. if (columns.size() > 0)
  39841. {
  39842. columns.clear();
  39843. sendColumnsChanged();
  39844. }
  39845. }
  39846. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  39847. {
  39848. const int currentIndex = getIndexOfColumnId (columnId, false);
  39849. newIndex = visibleIndexToTotalIndex (newIndex);
  39850. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  39851. {
  39852. columns.move (currentIndex, newIndex);
  39853. sendColumnsChanged();
  39854. }
  39855. }
  39856. int TableHeaderComponent::getColumnWidth (const int columnId) const
  39857. {
  39858. const ColumnInfo* const ci = getInfoForId (columnId);
  39859. return ci != 0 ? ci->width : 0;
  39860. }
  39861. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  39862. {
  39863. ColumnInfo* const ci = getInfoForId (columnId);
  39864. if (ci != 0 && ci->width != newWidth)
  39865. {
  39866. const int numColumns = getNumColumns (true);
  39867. ci->lastDeliberateWidth = ci->width
  39868. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  39869. if (stretchToFit)
  39870. {
  39871. const int index = getIndexOfColumnId (columnId, true) + 1;
  39872. if (((unsigned int) index) < (unsigned int) numColumns)
  39873. {
  39874. const int x = getColumnPosition (index).getX();
  39875. if (lastDeliberateWidth == 0)
  39876. lastDeliberateWidth = getTotalWidth();
  39877. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  39878. }
  39879. }
  39880. repaint();
  39881. columnsResized = true;
  39882. triggerAsyncUpdate();
  39883. }
  39884. }
  39885. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  39886. {
  39887. int n = 0;
  39888. for (int i = 0; i < columns.size(); ++i)
  39889. {
  39890. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  39891. {
  39892. if (columns.getUnchecked(i)->id == columnId)
  39893. return n;
  39894. ++n;
  39895. }
  39896. }
  39897. return -1;
  39898. }
  39899. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  39900. {
  39901. if (onlyCountVisibleColumns)
  39902. index = visibleIndexToTotalIndex (index);
  39903. const ColumnInfo* const ci = columns [index];
  39904. return (ci != 0) ? ci->id : 0;
  39905. }
  39906. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  39907. {
  39908. int x = 0, width = 0, n = 0;
  39909. for (int i = 0; i < columns.size(); ++i)
  39910. {
  39911. x += width;
  39912. if (columns.getUnchecked(i)->isVisible())
  39913. {
  39914. width = columns.getUnchecked(i)->width;
  39915. if (n++ == index)
  39916. break;
  39917. }
  39918. else
  39919. {
  39920. width = 0;
  39921. }
  39922. }
  39923. return Rectangle<int> (x, 0, width, getHeight());
  39924. }
  39925. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  39926. {
  39927. if (xToFind >= 0)
  39928. {
  39929. int x = 0;
  39930. for (int i = 0; i < columns.size(); ++i)
  39931. {
  39932. const ColumnInfo* const ci = columns.getUnchecked(i);
  39933. if (ci->isVisible())
  39934. {
  39935. x += ci->width;
  39936. if (xToFind < x)
  39937. return ci->id;
  39938. }
  39939. }
  39940. }
  39941. return 0;
  39942. }
  39943. int TableHeaderComponent::getTotalWidth() const
  39944. {
  39945. int w = 0;
  39946. for (int i = columns.size(); --i >= 0;)
  39947. if (columns.getUnchecked(i)->isVisible())
  39948. w += columns.getUnchecked(i)->width;
  39949. return w;
  39950. }
  39951. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  39952. {
  39953. stretchToFit = shouldStretchToFit;
  39954. lastDeliberateWidth = getTotalWidth();
  39955. resized();
  39956. }
  39957. bool TableHeaderComponent::isStretchToFitActive() const
  39958. {
  39959. return stretchToFit;
  39960. }
  39961. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  39962. {
  39963. if (stretchToFit && getWidth() > 0
  39964. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  39965. {
  39966. lastDeliberateWidth = targetTotalWidth;
  39967. resizeColumnsToFit (0, targetTotalWidth);
  39968. }
  39969. }
  39970. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  39971. {
  39972. targetTotalWidth = jmax (targetTotalWidth, 0);
  39973. StretchableObjectResizer sor;
  39974. int i;
  39975. for (i = firstColumnIndex; i < columns.size(); ++i)
  39976. {
  39977. ColumnInfo* const ci = columns.getUnchecked(i);
  39978. if (ci->isVisible())
  39979. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  39980. }
  39981. sor.resizeToFit (targetTotalWidth);
  39982. int visIndex = 0;
  39983. for (i = firstColumnIndex; i < columns.size(); ++i)
  39984. {
  39985. ColumnInfo* const ci = columns.getUnchecked(i);
  39986. if (ci->isVisible())
  39987. {
  39988. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  39989. (int) floor (sor.getItemSize (visIndex++)));
  39990. if (newWidth != ci->width)
  39991. {
  39992. ci->width = newWidth;
  39993. repaint();
  39994. columnsResized = true;
  39995. triggerAsyncUpdate();
  39996. }
  39997. }
  39998. }
  39999. }
  40000. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40001. {
  40002. ColumnInfo* const ci = getInfoForId (columnId);
  40003. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40004. {
  40005. if (shouldBeVisible)
  40006. ci->propertyFlags |= visible;
  40007. else
  40008. ci->propertyFlags &= ~visible;
  40009. sendColumnsChanged();
  40010. resized();
  40011. }
  40012. }
  40013. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40014. {
  40015. const ColumnInfo* const ci = getInfoForId (columnId);
  40016. return ci != 0 && ci->isVisible();
  40017. }
  40018. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40019. {
  40020. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40021. {
  40022. for (int i = columns.size(); --i >= 0;)
  40023. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40024. ColumnInfo* const ci = getInfoForId (columnId);
  40025. if (ci != 0)
  40026. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40027. reSortTable();
  40028. }
  40029. }
  40030. int TableHeaderComponent::getSortColumnId() const
  40031. {
  40032. for (int i = columns.size(); --i >= 0;)
  40033. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40034. return columns.getUnchecked(i)->id;
  40035. return 0;
  40036. }
  40037. bool TableHeaderComponent::isSortedForwards() const
  40038. {
  40039. for (int i = columns.size(); --i >= 0;)
  40040. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40041. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40042. return true;
  40043. }
  40044. void TableHeaderComponent::reSortTable()
  40045. {
  40046. sortChanged = true;
  40047. repaint();
  40048. triggerAsyncUpdate();
  40049. }
  40050. const String TableHeaderComponent::toString() const
  40051. {
  40052. String s;
  40053. XmlElement doc ("TABLELAYOUT");
  40054. doc.setAttribute ("sortedCol", getSortColumnId());
  40055. doc.setAttribute ("sortForwards", isSortedForwards());
  40056. for (int i = 0; i < columns.size(); ++i)
  40057. {
  40058. const ColumnInfo* const ci = columns.getUnchecked (i);
  40059. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40060. e->setAttribute ("id", ci->id);
  40061. e->setAttribute ("visible", ci->isVisible());
  40062. e->setAttribute ("width", ci->width);
  40063. }
  40064. return doc.createDocument (String::empty, true, false);
  40065. }
  40066. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40067. {
  40068. XmlDocument doc (storedVersion);
  40069. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40070. int index = 0;
  40071. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40072. {
  40073. forEachXmlChildElement (*storedXml, col)
  40074. {
  40075. const int tabId = col->getIntAttribute ("id");
  40076. ColumnInfo* const ci = getInfoForId (tabId);
  40077. if (ci != 0)
  40078. {
  40079. columns.move (columns.indexOf (ci), index);
  40080. ci->width = col->getIntAttribute ("width");
  40081. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40082. }
  40083. ++index;
  40084. }
  40085. columnsResized = true;
  40086. sendColumnsChanged();
  40087. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40088. storedXml->getBoolAttribute ("sortForwards", true));
  40089. }
  40090. }
  40091. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40092. {
  40093. listeners.addIfNotAlreadyThere (newListener);
  40094. }
  40095. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40096. {
  40097. listeners.removeValue (listenerToRemove);
  40098. }
  40099. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40100. {
  40101. const ColumnInfo* const ci = getInfoForId (columnId);
  40102. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40103. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40104. }
  40105. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40106. {
  40107. for (int i = 0; i < columns.size(); ++i)
  40108. {
  40109. const ColumnInfo* const ci = columns.getUnchecked(i);
  40110. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40111. menu.addItem (ci->id, ci->name,
  40112. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40113. isColumnVisible (ci->id));
  40114. }
  40115. }
  40116. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40117. {
  40118. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40119. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40120. }
  40121. void TableHeaderComponent::paint (Graphics& g)
  40122. {
  40123. LookAndFeel& lf = getLookAndFeel();
  40124. lf.drawTableHeaderBackground (g, *this);
  40125. const Rectangle<int> clip (g.getClipBounds());
  40126. int x = 0;
  40127. for (int i = 0; i < columns.size(); ++i)
  40128. {
  40129. const ColumnInfo* const ci = columns.getUnchecked(i);
  40130. if (ci->isVisible())
  40131. {
  40132. if (x + ci->width > clip.getX()
  40133. && (ci->id != columnIdBeingDragged
  40134. || dragOverlayComp == 0
  40135. || ! dragOverlayComp->isVisible()))
  40136. {
  40137. g.saveState();
  40138. g.setOrigin (x, 0);
  40139. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40140. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40141. ci->id == columnIdUnderMouse,
  40142. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40143. ci->propertyFlags);
  40144. g.restoreState();
  40145. }
  40146. x += ci->width;
  40147. if (x >= clip.getRight())
  40148. break;
  40149. }
  40150. }
  40151. }
  40152. void TableHeaderComponent::resized()
  40153. {
  40154. }
  40155. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40156. {
  40157. updateColumnUnderMouse (e.x, e.y);
  40158. }
  40159. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40160. {
  40161. updateColumnUnderMouse (e.x, e.y);
  40162. }
  40163. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40164. {
  40165. updateColumnUnderMouse (e.x, e.y);
  40166. }
  40167. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40168. {
  40169. repaint();
  40170. columnIdBeingResized = 0;
  40171. columnIdBeingDragged = 0;
  40172. if (columnIdUnderMouse != 0)
  40173. {
  40174. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40175. if (e.mods.isPopupMenu())
  40176. columnClicked (columnIdUnderMouse, e.mods);
  40177. }
  40178. if (menuActive && e.mods.isPopupMenu())
  40179. showColumnChooserMenu (columnIdUnderMouse);
  40180. }
  40181. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40182. {
  40183. if (columnIdBeingResized == 0
  40184. && columnIdBeingDragged == 0
  40185. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40186. {
  40187. dragOverlayComp = 0;
  40188. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40189. if (columnIdBeingResized != 0)
  40190. {
  40191. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40192. initialColumnWidth = ci->width;
  40193. }
  40194. else
  40195. {
  40196. beginDrag (e);
  40197. }
  40198. }
  40199. if (columnIdBeingResized != 0)
  40200. {
  40201. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40202. if (ci != 0)
  40203. {
  40204. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40205. initialColumnWidth + e.getDistanceFromDragStartX());
  40206. if (stretchToFit)
  40207. {
  40208. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40209. int minWidthOnRight = 0;
  40210. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40211. if (columns.getUnchecked (i)->isVisible())
  40212. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40213. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40214. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40215. }
  40216. setColumnWidth (columnIdBeingResized, w);
  40217. }
  40218. }
  40219. else if (columnIdBeingDragged != 0)
  40220. {
  40221. if (e.y >= -50 && e.y < getHeight() + 50)
  40222. {
  40223. if (dragOverlayComp != 0)
  40224. {
  40225. dragOverlayComp->setVisible (true);
  40226. dragOverlayComp->setBounds (jlimit (0,
  40227. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40228. e.x - draggingColumnOffset),
  40229. 0,
  40230. dragOverlayComp->getWidth(),
  40231. getHeight());
  40232. for (int i = columns.size(); --i >= 0;)
  40233. {
  40234. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40235. int newIndex = currentIndex;
  40236. if (newIndex > 0)
  40237. {
  40238. // if the previous column isn't draggable, we can't move our column
  40239. // past it, because that'd change the undraggable column's position..
  40240. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40241. if ((previous->propertyFlags & draggable) != 0)
  40242. {
  40243. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40244. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40245. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40246. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40247. {
  40248. --newIndex;
  40249. }
  40250. }
  40251. }
  40252. if (newIndex < columns.size() - 1)
  40253. {
  40254. // if the next column isn't draggable, we can't move our column
  40255. // past it, because that'd change the undraggable column's position..
  40256. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40257. if ((nextCol->propertyFlags & draggable) != 0)
  40258. {
  40259. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40260. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40261. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40262. > abs (dragOverlayComp->getRight() - rightOfNext))
  40263. {
  40264. ++newIndex;
  40265. }
  40266. }
  40267. }
  40268. if (newIndex != currentIndex)
  40269. moveColumn (columnIdBeingDragged, newIndex);
  40270. else
  40271. break;
  40272. }
  40273. }
  40274. }
  40275. else
  40276. {
  40277. endDrag (draggingColumnOriginalIndex);
  40278. }
  40279. }
  40280. }
  40281. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40282. {
  40283. if (columnIdBeingDragged == 0)
  40284. {
  40285. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40286. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40287. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40288. {
  40289. columnIdBeingDragged = 0;
  40290. }
  40291. else
  40292. {
  40293. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40294. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40295. const int temp = columnIdBeingDragged;
  40296. columnIdBeingDragged = 0;
  40297. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40298. columnIdBeingDragged = temp;
  40299. dragOverlayComp->setBounds (columnRect);
  40300. for (int i = listeners.size(); --i >= 0;)
  40301. {
  40302. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40303. i = jmin (i, listeners.size() - 1);
  40304. }
  40305. }
  40306. }
  40307. }
  40308. void TableHeaderComponent::endDrag (const int finalIndex)
  40309. {
  40310. if (columnIdBeingDragged != 0)
  40311. {
  40312. moveColumn (columnIdBeingDragged, finalIndex);
  40313. columnIdBeingDragged = 0;
  40314. repaint();
  40315. for (int i = listeners.size(); --i >= 0;)
  40316. {
  40317. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40318. i = jmin (i, listeners.size() - 1);
  40319. }
  40320. }
  40321. }
  40322. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40323. {
  40324. mouseDrag (e);
  40325. for (int i = columns.size(); --i >= 0;)
  40326. if (columns.getUnchecked (i)->isVisible())
  40327. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40328. columnIdBeingResized = 0;
  40329. repaint();
  40330. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40331. updateColumnUnderMouse (e.x, e.y);
  40332. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40333. columnClicked (columnIdUnderMouse, e.mods);
  40334. dragOverlayComp = 0;
  40335. }
  40336. const MouseCursor TableHeaderComponent::getMouseCursor()
  40337. {
  40338. if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown()))
  40339. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40340. return Component::getMouseCursor();
  40341. }
  40342. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40343. {
  40344. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40345. }
  40346. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40347. {
  40348. for (int i = columns.size(); --i >= 0;)
  40349. if (columns.getUnchecked(i)->id == id)
  40350. return columns.getUnchecked(i);
  40351. return 0;
  40352. }
  40353. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40354. {
  40355. int n = 0;
  40356. for (int i = 0; i < columns.size(); ++i)
  40357. {
  40358. if (columns.getUnchecked(i)->isVisible())
  40359. {
  40360. if (n == visibleIndex)
  40361. return i;
  40362. ++n;
  40363. }
  40364. }
  40365. return -1;
  40366. }
  40367. void TableHeaderComponent::sendColumnsChanged()
  40368. {
  40369. if (stretchToFit && lastDeliberateWidth > 0)
  40370. resizeAllColumnsToFit (lastDeliberateWidth);
  40371. repaint();
  40372. columnsChanged = true;
  40373. triggerAsyncUpdate();
  40374. }
  40375. void TableHeaderComponent::handleAsyncUpdate()
  40376. {
  40377. const bool changed = columnsChanged || sortChanged;
  40378. const bool sized = columnsResized || changed;
  40379. const bool sorted = sortChanged;
  40380. columnsChanged = false;
  40381. columnsResized = false;
  40382. sortChanged = false;
  40383. if (sorted)
  40384. {
  40385. for (int i = listeners.size(); --i >= 0;)
  40386. {
  40387. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40388. i = jmin (i, listeners.size() - 1);
  40389. }
  40390. }
  40391. if (changed)
  40392. {
  40393. for (int i = listeners.size(); --i >= 0;)
  40394. {
  40395. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40396. i = jmin (i, listeners.size() - 1);
  40397. }
  40398. }
  40399. if (sized)
  40400. {
  40401. for (int i = listeners.size(); --i >= 0;)
  40402. {
  40403. listeners.getUnchecked(i)->tableColumnsResized (this);
  40404. i = jmin (i, listeners.size() - 1);
  40405. }
  40406. }
  40407. }
  40408. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40409. {
  40410. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40411. {
  40412. const int draggableDistance = 3;
  40413. int x = 0;
  40414. for (int i = 0; i < columns.size(); ++i)
  40415. {
  40416. const ColumnInfo* const ci = columns.getUnchecked(i);
  40417. if (ci->isVisible())
  40418. {
  40419. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40420. && (ci->propertyFlags & resizable) != 0)
  40421. return ci->id;
  40422. x += ci->width;
  40423. }
  40424. }
  40425. }
  40426. return 0;
  40427. }
  40428. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40429. {
  40430. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40431. ? getColumnIdAtX (x) : 0;
  40432. if (newCol != columnIdUnderMouse)
  40433. {
  40434. columnIdUnderMouse = newCol;
  40435. repaint();
  40436. }
  40437. }
  40438. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40439. {
  40440. PopupMenu m;
  40441. addMenuItems (m, columnIdClicked);
  40442. if (m.getNumItems() > 0)
  40443. {
  40444. m.setLookAndFeel (&getLookAndFeel());
  40445. const int result = m.show();
  40446. if (result != 0)
  40447. reactToMenuItem (result, columnIdClicked);
  40448. }
  40449. }
  40450. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40451. {
  40452. }
  40453. END_JUCE_NAMESPACE
  40454. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  40455. /*** Start of inlined file: juce_TableListBox.cpp ***/
  40456. BEGIN_JUCE_NAMESPACE
  40457. static const char* const tableColumnPropertyTag = "_tableColumnID";
  40458. class TableListRowComp : public Component,
  40459. public TooltipClient
  40460. {
  40461. public:
  40462. TableListRowComp (TableListBox& owner_)
  40463. : owner (owner_),
  40464. row (-1),
  40465. isSelected (false)
  40466. {
  40467. }
  40468. ~TableListRowComp()
  40469. {
  40470. deleteAllChildren();
  40471. }
  40472. void paint (Graphics& g)
  40473. {
  40474. TableListBoxModel* const model = owner.getModel();
  40475. if (model != 0)
  40476. {
  40477. const TableHeaderComponent* const header = owner.getHeader();
  40478. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  40479. const int numColumns = header->getNumColumns (true);
  40480. for (int i = 0; i < numColumns; ++i)
  40481. {
  40482. if (! columnsWithComponents [i])
  40483. {
  40484. const int columnId = header->getColumnIdOfIndex (i, true);
  40485. Rectangle<int> columnRect (header->getColumnPosition (i));
  40486. columnRect.setSize (columnRect.getWidth(), getHeight());
  40487. g.saveState();
  40488. g.reduceClipRegion (columnRect);
  40489. g.setOrigin (columnRect.getX(), 0);
  40490. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  40491. g.restoreState();
  40492. }
  40493. }
  40494. }
  40495. }
  40496. void update (const int newRow, const bool isNowSelected)
  40497. {
  40498. if (newRow != row || isNowSelected != isSelected)
  40499. {
  40500. row = newRow;
  40501. isSelected = isNowSelected;
  40502. repaint();
  40503. }
  40504. if (row < owner.getNumRows())
  40505. {
  40506. jassert (row >= 0);
  40507. const var::identifier tagPropertyName ("_tableLastUseNum");
  40508. const int newTag = Random::getSystemRandom().nextInt();
  40509. const TableHeaderComponent* const header = owner.getHeader();
  40510. const int numColumns = header->getNumColumns (true);
  40511. int i;
  40512. columnsWithComponents.clear();
  40513. if (owner.getModel() != 0)
  40514. {
  40515. for (i = 0; i < numColumns; ++i)
  40516. {
  40517. const int columnId = header->getColumnIdOfIndex (i, true);
  40518. Component* const newComp
  40519. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  40520. findChildComponentForColumn (columnId));
  40521. if (newComp != 0)
  40522. {
  40523. addAndMakeVisible (newComp);
  40524. newComp->getProperties().set (tagPropertyName, newTag);
  40525. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  40526. const Rectangle<int> columnRect (header->getColumnPosition (i));
  40527. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40528. columnsWithComponents.setBit (i);
  40529. }
  40530. }
  40531. }
  40532. for (i = getNumChildComponents(); --i >= 0;)
  40533. {
  40534. Component* const c = getChildComponent (i);
  40535. if ((int) c->getProperties() [tagPropertyName] != newTag)
  40536. delete c;
  40537. }
  40538. }
  40539. else
  40540. {
  40541. columnsWithComponents.clear();
  40542. deleteAllChildren();
  40543. }
  40544. }
  40545. void resized()
  40546. {
  40547. for (int i = getNumChildComponents(); --i >= 0;)
  40548. {
  40549. Component* const c = getChildComponent (i);
  40550. const int columnId = c->getProperties() [tableColumnPropertyTag];
  40551. if (columnId != 0)
  40552. {
  40553. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  40554. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40555. }
  40556. }
  40557. }
  40558. void mouseDown (const MouseEvent& e)
  40559. {
  40560. isDragging = false;
  40561. selectRowOnMouseUp = false;
  40562. if (isEnabled())
  40563. {
  40564. if (! isSelected)
  40565. {
  40566. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40567. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40568. if (columnId != 0 && owner.getModel() != 0)
  40569. owner.getModel()->cellClicked (row, columnId, e);
  40570. }
  40571. else
  40572. {
  40573. selectRowOnMouseUp = true;
  40574. }
  40575. }
  40576. }
  40577. void mouseDrag (const MouseEvent& e)
  40578. {
  40579. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  40580. {
  40581. const SparseSet <int> selectedRows (owner.getSelectedRows());
  40582. if (selectedRows.size() > 0)
  40583. {
  40584. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  40585. if (dragDescription.isNotEmpty())
  40586. {
  40587. isDragging = true;
  40588. owner.startDragAndDrop (e, dragDescription);
  40589. }
  40590. }
  40591. }
  40592. }
  40593. void mouseUp (const MouseEvent& e)
  40594. {
  40595. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  40596. {
  40597. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40598. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40599. if (columnId != 0 && owner.getModel() != 0)
  40600. owner.getModel()->cellClicked (row, columnId, e);
  40601. }
  40602. }
  40603. void mouseDoubleClick (const MouseEvent& e)
  40604. {
  40605. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40606. if (columnId != 0 && owner.getModel() != 0)
  40607. owner.getModel()->cellDoubleClicked (row, columnId, e);
  40608. }
  40609. const String getTooltip()
  40610. {
  40611. const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX());
  40612. if (columnId != 0 && owner.getModel() != 0)
  40613. return owner.getModel()->getCellTooltip (row, columnId);
  40614. return String::empty;
  40615. }
  40616. juce_UseDebuggingNewOperator
  40617. private:
  40618. TableListBox& owner;
  40619. int row;
  40620. bool isSelected, isDragging, selectRowOnMouseUp;
  40621. BigInteger columnsWithComponents;
  40622. Component* findChildComponentForColumn (const int columnId) const
  40623. {
  40624. for (int i = getNumChildComponents(); --i >= 0;)
  40625. {
  40626. Component* const c = getChildComponent (i);
  40627. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  40628. return c;
  40629. }
  40630. return 0;
  40631. }
  40632. TableListRowComp (const TableListRowComp&);
  40633. TableListRowComp& operator= (const TableListRowComp&);
  40634. };
  40635. class TableListBoxHeader : public TableHeaderComponent
  40636. {
  40637. public:
  40638. TableListBoxHeader (TableListBox& owner_)
  40639. : owner (owner_)
  40640. {
  40641. }
  40642. ~TableListBoxHeader()
  40643. {
  40644. }
  40645. void addMenuItems (PopupMenu& menu, const int columnIdClicked)
  40646. {
  40647. if (owner.isAutoSizeMenuOptionShown())
  40648. {
  40649. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  40650. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  40651. menu.addSeparator();
  40652. }
  40653. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  40654. }
  40655. void reactToMenuItem (const int menuReturnId, const int columnIdClicked)
  40656. {
  40657. if (menuReturnId == 0xf836743)
  40658. {
  40659. owner.autoSizeColumn (columnIdClicked);
  40660. }
  40661. else if (menuReturnId == 0xf836744)
  40662. {
  40663. owner.autoSizeAllColumns();
  40664. }
  40665. else
  40666. {
  40667. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  40668. }
  40669. }
  40670. juce_UseDebuggingNewOperator
  40671. private:
  40672. TableListBox& owner;
  40673. TableListBoxHeader (const TableListBoxHeader&);
  40674. TableListBoxHeader& operator= (const TableListBoxHeader&);
  40675. };
  40676. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  40677. : ListBox (name, 0),
  40678. model (model_),
  40679. autoSizeOptionsShown (true)
  40680. {
  40681. ListBox::model = this;
  40682. header = new TableListBoxHeader (*this);
  40683. header->setSize (100, 28);
  40684. header->addListener (this);
  40685. setHeaderComponent (header);
  40686. }
  40687. TableListBox::~TableListBox()
  40688. {
  40689. deleteAllChildren();
  40690. }
  40691. void TableListBox::setModel (TableListBoxModel* const newModel)
  40692. {
  40693. if (model != newModel)
  40694. {
  40695. model = newModel;
  40696. updateContent();
  40697. }
  40698. }
  40699. int TableListBox::getHeaderHeight() const
  40700. {
  40701. return header->getHeight();
  40702. }
  40703. void TableListBox::setHeaderHeight (const int newHeight)
  40704. {
  40705. header->setSize (header->getWidth(), newHeight);
  40706. resized();
  40707. }
  40708. void TableListBox::autoSizeColumn (const int columnId)
  40709. {
  40710. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  40711. if (width > 0)
  40712. header->setColumnWidth (columnId, width);
  40713. }
  40714. void TableListBox::autoSizeAllColumns()
  40715. {
  40716. for (int i = 0; i < header->getNumColumns (true); ++i)
  40717. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  40718. }
  40719. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  40720. {
  40721. autoSizeOptionsShown = shouldBeShown;
  40722. }
  40723. bool TableListBox::isAutoSizeMenuOptionShown() const
  40724. {
  40725. return autoSizeOptionsShown;
  40726. }
  40727. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  40728. const int rowNumber,
  40729. const bool relativeToComponentTopLeft) const
  40730. {
  40731. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40732. if (relativeToComponentTopLeft)
  40733. headerCell.translate (header->getX(), 0);
  40734. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  40735. return Rectangle<int> (headerCell.getX(), row.getY(),
  40736. headerCell.getWidth(), row.getHeight());
  40737. }
  40738. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  40739. {
  40740. ScrollBar* const scrollbar = getHorizontalScrollBar();
  40741. if (scrollbar != 0)
  40742. {
  40743. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40744. double x = scrollbar->getCurrentRangeStart();
  40745. const double w = scrollbar->getCurrentRangeSize();
  40746. if (pos.getX() < x)
  40747. x = pos.getX();
  40748. else if (pos.getRight() > x + w)
  40749. x += jmax (0.0, pos.getRight() - (x + w));
  40750. scrollbar->setCurrentRangeStart (x);
  40751. }
  40752. }
  40753. int TableListBox::getNumRows()
  40754. {
  40755. return model != 0 ? model->getNumRows() : 0;
  40756. }
  40757. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  40758. {
  40759. }
  40760. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  40761. {
  40762. if (existingComponentToUpdate == 0)
  40763. existingComponentToUpdate = new TableListRowComp (*this);
  40764. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  40765. return existingComponentToUpdate;
  40766. }
  40767. void TableListBox::selectedRowsChanged (int row)
  40768. {
  40769. if (model != 0)
  40770. model->selectedRowsChanged (row);
  40771. }
  40772. void TableListBox::deleteKeyPressed (int row)
  40773. {
  40774. if (model != 0)
  40775. model->deleteKeyPressed (row);
  40776. }
  40777. void TableListBox::returnKeyPressed (int row)
  40778. {
  40779. if (model != 0)
  40780. model->returnKeyPressed (row);
  40781. }
  40782. void TableListBox::backgroundClicked()
  40783. {
  40784. if (model != 0)
  40785. model->backgroundClicked();
  40786. }
  40787. void TableListBox::listWasScrolled()
  40788. {
  40789. if (model != 0)
  40790. model->listWasScrolled();
  40791. }
  40792. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  40793. {
  40794. setMinimumContentWidth (header->getTotalWidth());
  40795. repaint();
  40796. updateColumnComponents();
  40797. }
  40798. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  40799. {
  40800. setMinimumContentWidth (header->getTotalWidth());
  40801. repaint();
  40802. updateColumnComponents();
  40803. }
  40804. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  40805. {
  40806. if (model != 0)
  40807. model->sortOrderChanged (header->getSortColumnId(),
  40808. header->isSortedForwards());
  40809. }
  40810. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  40811. {
  40812. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  40813. repaint();
  40814. }
  40815. void TableListBox::resized()
  40816. {
  40817. ListBox::resized();
  40818. header->resizeAllColumnsToFit (getVisibleContentWidth());
  40819. setMinimumContentWidth (header->getTotalWidth());
  40820. }
  40821. void TableListBox::updateColumnComponents() const
  40822. {
  40823. const int firstRow = getRowContainingPosition (0, 0);
  40824. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  40825. {
  40826. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  40827. if (rowComp != 0)
  40828. rowComp->resized();
  40829. }
  40830. }
  40831. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  40832. {
  40833. }
  40834. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  40835. {
  40836. }
  40837. void TableListBoxModel::backgroundClicked()
  40838. {
  40839. }
  40840. void TableListBoxModel::sortOrderChanged (int, const bool)
  40841. {
  40842. }
  40843. int TableListBoxModel::getColumnAutoSizeWidth (int)
  40844. {
  40845. return 0;
  40846. }
  40847. void TableListBoxModel::selectedRowsChanged (int)
  40848. {
  40849. }
  40850. void TableListBoxModel::deleteKeyPressed (int)
  40851. {
  40852. }
  40853. void TableListBoxModel::returnKeyPressed (int)
  40854. {
  40855. }
  40856. void TableListBoxModel::listWasScrolled()
  40857. {
  40858. }
  40859. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  40860. {
  40861. return String::empty;
  40862. }
  40863. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  40864. {
  40865. return String::empty;
  40866. }
  40867. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  40868. {
  40869. (void) existingComponentToUpdate;
  40870. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  40871. return 0;
  40872. }
  40873. END_JUCE_NAMESPACE
  40874. /*** End of inlined file: juce_TableListBox.cpp ***/
  40875. /*** Start of inlined file: juce_TextEditor.cpp ***/
  40876. BEGIN_JUCE_NAMESPACE
  40877. // a word or space that can't be broken down any further
  40878. struct TextAtom
  40879. {
  40880. String atomText;
  40881. float width;
  40882. uint16 numChars;
  40883. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  40884. bool isNewLine() const { return atomText[0] == T('\r') || atomText[0] == T('\n'); }
  40885. const String getText (const tchar passwordCharacter) const
  40886. {
  40887. if (passwordCharacter == 0)
  40888. return atomText;
  40889. else
  40890. return String::repeatedString (String::charToString (passwordCharacter),
  40891. atomText.length());
  40892. }
  40893. const String getTrimmedText (const tchar passwordCharacter) const
  40894. {
  40895. if (passwordCharacter == 0)
  40896. return atomText.substring (0, numChars);
  40897. else if (isNewLine())
  40898. return String::empty;
  40899. else
  40900. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  40901. }
  40902. };
  40903. // a run of text with a single font and colour
  40904. class UniformTextSection
  40905. {
  40906. public:
  40907. UniformTextSection (const String& text,
  40908. const Font& font_,
  40909. const Colour& colour_,
  40910. const tchar passwordCharacter)
  40911. : font (font_),
  40912. colour (colour_)
  40913. {
  40914. initialiseAtoms (text, passwordCharacter);
  40915. }
  40916. UniformTextSection (const UniformTextSection& other)
  40917. : font (other.font),
  40918. colour (other.colour)
  40919. {
  40920. atoms.ensureStorageAllocated (other.atoms.size());
  40921. for (int i = 0; i < other.atoms.size(); ++i)
  40922. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  40923. }
  40924. ~UniformTextSection()
  40925. {
  40926. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  40927. }
  40928. void clear()
  40929. {
  40930. for (int i = atoms.size(); --i >= 0;)
  40931. delete getAtom(i);
  40932. atoms.clear();
  40933. }
  40934. int getNumAtoms() const
  40935. {
  40936. return atoms.size();
  40937. }
  40938. TextAtom* getAtom (const int index) const
  40939. {
  40940. return (TextAtom*) atoms.getUnchecked (index);
  40941. }
  40942. void append (const UniformTextSection& other, const tchar passwordCharacter)
  40943. {
  40944. if (other.atoms.size() > 0)
  40945. {
  40946. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  40947. int i = 0;
  40948. if (lastAtom != 0)
  40949. {
  40950. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  40951. {
  40952. TextAtom* const first = other.getAtom(0);
  40953. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  40954. {
  40955. lastAtom->atomText += first->atomText;
  40956. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  40957. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  40958. delete first;
  40959. ++i;
  40960. }
  40961. }
  40962. }
  40963. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  40964. while (i < other.atoms.size())
  40965. {
  40966. atoms.add (other.getAtom(i));
  40967. ++i;
  40968. }
  40969. }
  40970. }
  40971. UniformTextSection* split (const int indexToBreakAt,
  40972. const tchar passwordCharacter)
  40973. {
  40974. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  40975. font, colour,
  40976. passwordCharacter);
  40977. int index = 0;
  40978. for (int i = 0; i < atoms.size(); ++i)
  40979. {
  40980. TextAtom* const atom = getAtom(i);
  40981. const int nextIndex = index + atom->numChars;
  40982. if (index == indexToBreakAt)
  40983. {
  40984. int j;
  40985. for (j = i; j < atoms.size(); ++j)
  40986. section2->atoms.add (getAtom (j));
  40987. for (j = atoms.size(); --j >= i;)
  40988. atoms.remove (j);
  40989. break;
  40990. }
  40991. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  40992. {
  40993. TextAtom* const secondAtom = new TextAtom();
  40994. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  40995. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  40996. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  40997. section2->atoms.add (secondAtom);
  40998. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  40999. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41000. atom->numChars = (uint16) (indexToBreakAt - index);
  41001. int j;
  41002. for (j = i + 1; j < atoms.size(); ++j)
  41003. section2->atoms.add (getAtom (j));
  41004. for (j = atoms.size(); --j > i;)
  41005. atoms.remove (j);
  41006. break;
  41007. }
  41008. index = nextIndex;
  41009. }
  41010. return section2;
  41011. }
  41012. void appendAllText (String::Concatenator& concatenator) const
  41013. {
  41014. for (int i = 0; i < atoms.size(); ++i)
  41015. concatenator.append (getAtom(i)->atomText);
  41016. }
  41017. void appendSubstring (String::Concatenator& concatenator,
  41018. const Range<int>& range) const
  41019. {
  41020. int index = 0;
  41021. for (int i = 0; i < atoms.size(); ++i)
  41022. {
  41023. const TextAtom* const atom = getAtom (i);
  41024. const int nextIndex = index + atom->numChars;
  41025. if (range.getStart() < nextIndex)
  41026. {
  41027. if (range.getEnd() <= index)
  41028. break;
  41029. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  41030. if (! r.isEmpty())
  41031. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  41032. }
  41033. index = nextIndex;
  41034. }
  41035. }
  41036. int getTotalLength() const
  41037. {
  41038. int total = 0;
  41039. for (int i = atoms.size(); --i >= 0;)
  41040. total += getAtom(i)->numChars;
  41041. return total;
  41042. }
  41043. void setFont (const Font& newFont,
  41044. const tchar passwordCharacter)
  41045. {
  41046. if (font != newFont)
  41047. {
  41048. font = newFont;
  41049. for (int i = atoms.size(); --i >= 0;)
  41050. {
  41051. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41052. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41053. }
  41054. }
  41055. }
  41056. juce_UseDebuggingNewOperator
  41057. Font font;
  41058. Colour colour;
  41059. private:
  41060. VoidArray atoms;
  41061. void initialiseAtoms (const String& textToParse,
  41062. const tchar passwordCharacter)
  41063. {
  41064. int i = 0;
  41065. const int len = textToParse.length();
  41066. const tchar* const text = (const tchar*) textToParse;
  41067. while (i < len)
  41068. {
  41069. int start = i;
  41070. // create a whitespace atom unless it starts with non-ws
  41071. if (CharacterFunctions::isWhitespace (text[i])
  41072. && text[i] != T('\r')
  41073. && text[i] != T('\n'))
  41074. {
  41075. while (i < len
  41076. && CharacterFunctions::isWhitespace (text[i])
  41077. && text[i] != T('\r')
  41078. && text[i] != T('\n'))
  41079. {
  41080. ++i;
  41081. }
  41082. }
  41083. else
  41084. {
  41085. if (text[i] == T('\r'))
  41086. {
  41087. ++i;
  41088. if ((i < len) && (text[i] == T('\n')))
  41089. {
  41090. ++start;
  41091. ++i;
  41092. }
  41093. }
  41094. else if (text[i] == T('\n'))
  41095. {
  41096. ++i;
  41097. }
  41098. else
  41099. {
  41100. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41101. ++i;
  41102. }
  41103. }
  41104. TextAtom* const atom = new TextAtom();
  41105. atom->atomText = String (text + start, i - start);
  41106. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41107. atom->numChars = (uint16) (i - start);
  41108. atoms.add (atom);
  41109. }
  41110. }
  41111. UniformTextSection& operator= (const UniformTextSection& other);
  41112. };
  41113. class TextEditorIterator
  41114. {
  41115. public:
  41116. TextEditorIterator (const VoidArray& sections_,
  41117. const float wordWrapWidth_,
  41118. const tchar passwordCharacter_)
  41119. : indexInText (0),
  41120. lineY (0),
  41121. lineHeight (0),
  41122. maxDescent (0),
  41123. atomX (0),
  41124. atomRight (0),
  41125. atom (0),
  41126. currentSection (0),
  41127. sections (sections_),
  41128. sectionIndex (0),
  41129. atomIndex (0),
  41130. wordWrapWidth (wordWrapWidth_),
  41131. passwordCharacter (passwordCharacter_)
  41132. {
  41133. jassert (wordWrapWidth_ > 0);
  41134. if (sections.size() > 0)
  41135. {
  41136. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41137. if (currentSection != 0)
  41138. beginNewLine();
  41139. }
  41140. }
  41141. TextEditorIterator (const TextEditorIterator& other)
  41142. : indexInText (other.indexInText),
  41143. lineY (other.lineY),
  41144. lineHeight (other.lineHeight),
  41145. maxDescent (other.maxDescent),
  41146. atomX (other.atomX),
  41147. atomRight (other.atomRight),
  41148. atom (other.atom),
  41149. currentSection (other.currentSection),
  41150. sections (other.sections),
  41151. sectionIndex (other.sectionIndex),
  41152. atomIndex (other.atomIndex),
  41153. wordWrapWidth (other.wordWrapWidth),
  41154. passwordCharacter (other.passwordCharacter),
  41155. tempAtom (other.tempAtom)
  41156. {
  41157. }
  41158. ~TextEditorIterator()
  41159. {
  41160. }
  41161. bool next()
  41162. {
  41163. if (atom == &tempAtom)
  41164. {
  41165. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41166. if (numRemaining > 0)
  41167. {
  41168. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41169. atomX = 0;
  41170. if (tempAtom.numChars > 0)
  41171. lineY += lineHeight;
  41172. indexInText += tempAtom.numChars;
  41173. GlyphArrangement g;
  41174. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41175. int split;
  41176. for (split = 0; split < g.getNumGlyphs(); ++split)
  41177. if (shouldWrap (g.getGlyph (split).getRight()))
  41178. break;
  41179. if (split > 0 && split <= numRemaining)
  41180. {
  41181. tempAtom.numChars = (uint16) split;
  41182. tempAtom.width = g.getGlyph (split - 1).getRight();
  41183. atomRight = atomX + tempAtom.width;
  41184. return true;
  41185. }
  41186. }
  41187. }
  41188. bool forceNewLine = false;
  41189. if (sectionIndex >= sections.size())
  41190. {
  41191. moveToEndOfLastAtom();
  41192. return false;
  41193. }
  41194. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41195. {
  41196. if (atomIndex >= currentSection->getNumAtoms())
  41197. {
  41198. if (++sectionIndex >= sections.size())
  41199. {
  41200. moveToEndOfLastAtom();
  41201. return false;
  41202. }
  41203. atomIndex = 0;
  41204. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41205. }
  41206. else
  41207. {
  41208. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41209. if (! lastAtom->isWhitespace())
  41210. {
  41211. // handle the case where the last atom in a section is actually part of the same
  41212. // word as the first atom of the next section...
  41213. float right = atomRight + lastAtom->width;
  41214. float lineHeight2 = lineHeight;
  41215. float maxDescent2 = maxDescent;
  41216. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41217. {
  41218. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41219. if (s->getNumAtoms() == 0)
  41220. break;
  41221. const TextAtom* const nextAtom = s->getAtom (0);
  41222. if (nextAtom->isWhitespace())
  41223. break;
  41224. right += nextAtom->width;
  41225. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41226. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41227. if (shouldWrap (right))
  41228. {
  41229. lineHeight = lineHeight2;
  41230. maxDescent = maxDescent2;
  41231. forceNewLine = true;
  41232. break;
  41233. }
  41234. if (s->getNumAtoms() > 1)
  41235. break;
  41236. }
  41237. }
  41238. }
  41239. }
  41240. if (atom != 0)
  41241. {
  41242. atomX = atomRight;
  41243. indexInText += atom->numChars;
  41244. if (atom->isNewLine())
  41245. beginNewLine();
  41246. }
  41247. atom = currentSection->getAtom (atomIndex);
  41248. atomRight = atomX + atom->width;
  41249. ++atomIndex;
  41250. if (shouldWrap (atomRight) || forceNewLine)
  41251. {
  41252. if (atom->isWhitespace())
  41253. {
  41254. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41255. atomRight = jmin (atomRight, wordWrapWidth);
  41256. }
  41257. else
  41258. {
  41259. atomRight = atom->width;
  41260. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41261. {
  41262. tempAtom = *atom;
  41263. tempAtom.width = 0;
  41264. tempAtom.numChars = 0;
  41265. atom = &tempAtom;
  41266. if (atomX > 0)
  41267. beginNewLine();
  41268. return next();
  41269. }
  41270. beginNewLine();
  41271. return true;
  41272. }
  41273. }
  41274. return true;
  41275. }
  41276. void beginNewLine()
  41277. {
  41278. atomX = 0;
  41279. lineY += lineHeight;
  41280. int tempSectionIndex = sectionIndex;
  41281. int tempAtomIndex = atomIndex;
  41282. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41283. lineHeight = section->font.getHeight();
  41284. maxDescent = section->font.getDescent();
  41285. float x = (atom != 0) ? atom->width : 0;
  41286. while (! shouldWrap (x))
  41287. {
  41288. if (tempSectionIndex >= sections.size())
  41289. break;
  41290. bool checkSize = false;
  41291. if (tempAtomIndex >= section->getNumAtoms())
  41292. {
  41293. if (++tempSectionIndex >= sections.size())
  41294. break;
  41295. tempAtomIndex = 0;
  41296. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41297. checkSize = true;
  41298. }
  41299. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41300. if (nextAtom == 0)
  41301. break;
  41302. x += nextAtom->width;
  41303. if (shouldWrap (x) || nextAtom->isNewLine())
  41304. break;
  41305. if (checkSize)
  41306. {
  41307. lineHeight = jmax (lineHeight, section->font.getHeight());
  41308. maxDescent = jmax (maxDescent, section->font.getDescent());
  41309. }
  41310. ++tempAtomIndex;
  41311. }
  41312. }
  41313. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41314. {
  41315. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41316. {
  41317. if (lastSection != currentSection)
  41318. {
  41319. lastSection = currentSection;
  41320. g.setColour (currentSection->colour);
  41321. g.setFont (currentSection->font);
  41322. }
  41323. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41324. GlyphArrangement ga;
  41325. ga.addLineOfText (currentSection->font,
  41326. atom->getTrimmedText (passwordCharacter),
  41327. atomX,
  41328. (float) roundToInt (lineY + lineHeight - maxDescent));
  41329. ga.draw (g);
  41330. }
  41331. }
  41332. void drawSelection (Graphics& g,
  41333. const Range<int>& selection) const
  41334. {
  41335. const int startX = roundToInt (indexToX (selection.getStart()));
  41336. const int endX = roundToInt (indexToX (selection.getEnd()));
  41337. const int y = roundToInt (lineY);
  41338. const int nextY = roundToInt (lineY + lineHeight);
  41339. g.fillRect (startX, y, endX - startX, nextY - y);
  41340. }
  41341. void drawSelectedText (Graphics& g,
  41342. const Range<int>& selection,
  41343. const Colour& selectedTextColour) const
  41344. {
  41345. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41346. {
  41347. GlyphArrangement ga;
  41348. ga.addLineOfText (currentSection->font,
  41349. atom->getTrimmedText (passwordCharacter),
  41350. atomX,
  41351. (float) roundToInt (lineY + lineHeight - maxDescent));
  41352. if (selection.getEnd() < indexInText + atom->numChars)
  41353. {
  41354. GlyphArrangement ga2 (ga);
  41355. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41356. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41357. g.setColour (currentSection->colour);
  41358. ga2.draw (g);
  41359. }
  41360. if (selection.getStart() > indexInText)
  41361. {
  41362. GlyphArrangement ga2 (ga);
  41363. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41364. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41365. g.setColour (currentSection->colour);
  41366. ga2.draw (g);
  41367. }
  41368. g.setColour (selectedTextColour);
  41369. ga.draw (g);
  41370. }
  41371. }
  41372. float indexToX (const int indexToFind) const
  41373. {
  41374. if (indexToFind <= indexInText)
  41375. return atomX;
  41376. if (indexToFind >= indexInText + atom->numChars)
  41377. return atomRight;
  41378. GlyphArrangement g;
  41379. g.addLineOfText (currentSection->font,
  41380. atom->getText (passwordCharacter),
  41381. atomX, 0.0f);
  41382. if (indexToFind - indexInText >= g.getNumGlyphs())
  41383. return atomRight;
  41384. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41385. }
  41386. int xToIndex (const float xToFind) const
  41387. {
  41388. if (xToFind <= atomX || atom->isNewLine())
  41389. return indexInText;
  41390. if (xToFind >= atomRight)
  41391. return indexInText + atom->numChars;
  41392. GlyphArrangement g;
  41393. g.addLineOfText (currentSection->font,
  41394. atom->getText (passwordCharacter),
  41395. atomX, 0.0f);
  41396. int j;
  41397. for (j = 0; j < g.getNumGlyphs(); ++j)
  41398. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41399. break;
  41400. return indexInText + j;
  41401. }
  41402. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41403. {
  41404. while (next())
  41405. {
  41406. if (indexInText + atom->numChars > index)
  41407. {
  41408. cx = indexToX (index);
  41409. cy = lineY;
  41410. lineHeight_ = lineHeight;
  41411. return true;
  41412. }
  41413. }
  41414. cx = atomX;
  41415. cy = lineY;
  41416. lineHeight_ = lineHeight;
  41417. return false;
  41418. }
  41419. juce_UseDebuggingNewOperator
  41420. int indexInText;
  41421. float lineY, lineHeight, maxDescent;
  41422. float atomX, atomRight;
  41423. const TextAtom* atom;
  41424. const UniformTextSection* currentSection;
  41425. private:
  41426. const VoidArray& sections;
  41427. int sectionIndex, atomIndex;
  41428. const float wordWrapWidth;
  41429. const tchar passwordCharacter;
  41430. TextAtom tempAtom;
  41431. TextEditorIterator& operator= (const TextEditorIterator&);
  41432. void moveToEndOfLastAtom()
  41433. {
  41434. if (atom != 0)
  41435. {
  41436. atomX = atomRight;
  41437. if (atom->isNewLine())
  41438. {
  41439. atomX = 0.0f;
  41440. lineY += lineHeight;
  41441. }
  41442. }
  41443. }
  41444. bool shouldWrap (const float x) const
  41445. {
  41446. return (x - 0.0001f) >= wordWrapWidth;
  41447. }
  41448. };
  41449. class TextEditorInsertAction : public UndoableAction
  41450. {
  41451. TextEditor& owner;
  41452. const String text;
  41453. const int insertIndex, oldCaretPos, newCaretPos;
  41454. const Font font;
  41455. const Colour colour;
  41456. TextEditorInsertAction (const TextEditorInsertAction&);
  41457. TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  41458. public:
  41459. TextEditorInsertAction (TextEditor& owner_,
  41460. const String& text_,
  41461. const int insertIndex_,
  41462. const Font& font_,
  41463. const Colour& colour_,
  41464. const int oldCaretPos_,
  41465. const int newCaretPos_)
  41466. : owner (owner_),
  41467. text (text_),
  41468. insertIndex (insertIndex_),
  41469. oldCaretPos (oldCaretPos_),
  41470. newCaretPos (newCaretPos_),
  41471. font (font_),
  41472. colour (colour_)
  41473. {
  41474. }
  41475. ~TextEditorInsertAction()
  41476. {
  41477. }
  41478. bool perform()
  41479. {
  41480. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  41481. return true;
  41482. }
  41483. bool undo()
  41484. {
  41485. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  41486. return true;
  41487. }
  41488. int getSizeInUnits()
  41489. {
  41490. return text.length() + 16;
  41491. }
  41492. };
  41493. class TextEditorRemoveAction : public UndoableAction
  41494. {
  41495. TextEditor& owner;
  41496. const Range<int> range;
  41497. const int oldCaretPos, newCaretPos;
  41498. VoidArray removedSections;
  41499. TextEditorRemoveAction (const TextEditorRemoveAction&);
  41500. TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  41501. public:
  41502. TextEditorRemoveAction (TextEditor& owner_,
  41503. const Range<int> range_,
  41504. const int oldCaretPos_,
  41505. const int newCaretPos_,
  41506. const VoidArray& removedSections_)
  41507. : owner (owner_),
  41508. range (range_),
  41509. oldCaretPos (oldCaretPos_),
  41510. newCaretPos (newCaretPos_),
  41511. removedSections (removedSections_)
  41512. {
  41513. }
  41514. ~TextEditorRemoveAction()
  41515. {
  41516. for (int i = removedSections.size(); --i >= 0;)
  41517. {
  41518. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41519. section->clear();
  41520. delete section;
  41521. }
  41522. }
  41523. bool perform()
  41524. {
  41525. owner.remove (range, 0, newCaretPos);
  41526. return true;
  41527. }
  41528. bool undo()
  41529. {
  41530. owner.reinsert (range.getStart(), removedSections);
  41531. owner.moveCursorTo (oldCaretPos, false);
  41532. return true;
  41533. }
  41534. int getSizeInUnits()
  41535. {
  41536. int n = 0;
  41537. for (int i = removedSections.size(); --i >= 0;)
  41538. {
  41539. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  41540. n += section->getTotalLength();
  41541. }
  41542. return n + 16;
  41543. }
  41544. };
  41545. class TextHolderComponent : public Component,
  41546. public Timer,
  41547. public Value::Listener
  41548. {
  41549. TextEditor& owner;
  41550. TextHolderComponent (const TextHolderComponent&);
  41551. TextHolderComponent& operator= (const TextHolderComponent&);
  41552. public:
  41553. TextHolderComponent (TextEditor& owner_)
  41554. : owner (owner_)
  41555. {
  41556. setWantsKeyboardFocus (false);
  41557. setInterceptsMouseClicks (false, true);
  41558. owner.getTextValue().addListener (this);
  41559. }
  41560. ~TextHolderComponent()
  41561. {
  41562. owner.getTextValue().removeListener (this);
  41563. }
  41564. void paint (Graphics& g)
  41565. {
  41566. owner.drawContent (g);
  41567. }
  41568. void timerCallback()
  41569. {
  41570. owner.timerCallbackInt();
  41571. }
  41572. const MouseCursor getMouseCursor()
  41573. {
  41574. return owner.getMouseCursor();
  41575. }
  41576. void valueChanged (Value&)
  41577. {
  41578. owner.textWasChangedByValue();
  41579. }
  41580. };
  41581. class TextEditorViewport : public Viewport
  41582. {
  41583. TextEditor* const owner;
  41584. float lastWordWrapWidth;
  41585. TextEditorViewport (const TextEditorViewport&);
  41586. TextEditorViewport& operator= (const TextEditorViewport&);
  41587. public:
  41588. TextEditorViewport (TextEditor* const owner_)
  41589. : owner (owner_),
  41590. lastWordWrapWidth (0)
  41591. {
  41592. }
  41593. ~TextEditorViewport()
  41594. {
  41595. }
  41596. void visibleAreaChanged (int, int, int, int)
  41597. {
  41598. const float wordWrapWidth = owner->getWordWrapWidth();
  41599. if (wordWrapWidth != lastWordWrapWidth)
  41600. {
  41601. lastWordWrapWidth = wordWrapWidth;
  41602. owner->updateTextHolderSize();
  41603. }
  41604. }
  41605. };
  41606. namespace TextEditorDefs
  41607. {
  41608. const int flashSpeedIntervalMs = 380;
  41609. const int textChangeMessageId = 0x10003001;
  41610. const int returnKeyMessageId = 0x10003002;
  41611. const int escapeKeyMessageId = 0x10003003;
  41612. const int focusLossMessageId = 0x10003004;
  41613. const int maxActionsPerTransaction = 100;
  41614. }
  41615. TextEditor::TextEditor (const String& name,
  41616. const tchar passwordCharacter_)
  41617. : Component (name),
  41618. borderSize (1, 1, 1, 3),
  41619. readOnly (false),
  41620. multiline (false),
  41621. wordWrap (false),
  41622. returnKeyStartsNewLine (false),
  41623. caretVisible (true),
  41624. popupMenuEnabled (true),
  41625. selectAllTextWhenFocused (false),
  41626. scrollbarVisible (true),
  41627. wasFocused (false),
  41628. caretFlashState (true),
  41629. keepCursorOnScreen (true),
  41630. tabKeyUsed (false),
  41631. menuActive (false),
  41632. valueTextNeedsUpdating (false),
  41633. cursorX (0),
  41634. cursorY (0),
  41635. cursorHeight (0),
  41636. maxTextLength (0),
  41637. leftIndent (4),
  41638. topIndent (4),
  41639. lastTransactionTime (0),
  41640. currentFont (14.0f),
  41641. totalNumChars (0),
  41642. caretPosition (0),
  41643. passwordCharacter (passwordCharacter_),
  41644. dragType (notDragging)
  41645. {
  41646. setOpaque (true);
  41647. addAndMakeVisible (viewport = new TextEditorViewport (this));
  41648. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  41649. viewport->setWantsKeyboardFocus (false);
  41650. viewport->setScrollBarsShown (false, false);
  41651. setMouseCursor (MouseCursor::IBeamCursor);
  41652. setWantsKeyboardFocus (true);
  41653. }
  41654. TextEditor::~TextEditor()
  41655. {
  41656. textValue.referTo (Value());
  41657. clearInternal (0);
  41658. viewport = 0;
  41659. textHolder = 0;
  41660. }
  41661. void TextEditor::newTransaction()
  41662. {
  41663. lastTransactionTime = Time::getApproximateMillisecondCounter();
  41664. undoManager.beginNewTransaction();
  41665. }
  41666. void TextEditor::doUndoRedo (const bool isRedo)
  41667. {
  41668. if (! isReadOnly())
  41669. {
  41670. if (isRedo ? undoManager.redo()
  41671. : undoManager.undo())
  41672. {
  41673. scrollToMakeSureCursorIsVisible();
  41674. repaint();
  41675. textChanged();
  41676. }
  41677. }
  41678. }
  41679. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  41680. const bool shouldWordWrap)
  41681. {
  41682. multiline = shouldBeMultiLine;
  41683. wordWrap = shouldWordWrap && shouldBeMultiLine;
  41684. setScrollbarsShown (scrollbarVisible);
  41685. viewport->setViewPosition (0, 0);
  41686. resized();
  41687. scrollToMakeSureCursorIsVisible();
  41688. }
  41689. bool TextEditor::isMultiLine() const
  41690. {
  41691. return multiline;
  41692. }
  41693. void TextEditor::setScrollbarsShown (bool enabled)
  41694. {
  41695. scrollbarVisible = enabled;
  41696. enabled = enabled && isMultiLine();
  41697. viewport->setScrollBarsShown (enabled, enabled);
  41698. }
  41699. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  41700. {
  41701. readOnly = shouldBeReadOnly;
  41702. enablementChanged();
  41703. }
  41704. bool TextEditor::isReadOnly() const
  41705. {
  41706. return readOnly || ! isEnabled();
  41707. }
  41708. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  41709. {
  41710. returnKeyStartsNewLine = shouldStartNewLine;
  41711. }
  41712. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  41713. {
  41714. tabKeyUsed = shouldTabKeyBeUsed;
  41715. }
  41716. void TextEditor::setPopupMenuEnabled (const bool b)
  41717. {
  41718. popupMenuEnabled = b;
  41719. }
  41720. void TextEditor::setSelectAllWhenFocused (const bool b)
  41721. {
  41722. selectAllTextWhenFocused = b;
  41723. }
  41724. const Font TextEditor::getFont() const
  41725. {
  41726. return currentFont;
  41727. }
  41728. void TextEditor::setFont (const Font& newFont)
  41729. {
  41730. currentFont = newFont;
  41731. scrollToMakeSureCursorIsVisible();
  41732. }
  41733. void TextEditor::applyFontToAllText (const Font& newFont)
  41734. {
  41735. currentFont = newFont;
  41736. const Colour overallColour (findColour (textColourId));
  41737. for (int i = sections.size(); --i >= 0;)
  41738. {
  41739. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  41740. uts->setFont (newFont, passwordCharacter);
  41741. uts->colour = overallColour;
  41742. }
  41743. coalesceSimilarSections();
  41744. updateTextHolderSize();
  41745. scrollToMakeSureCursorIsVisible();
  41746. repaint();
  41747. }
  41748. void TextEditor::colourChanged()
  41749. {
  41750. setOpaque (findColour (backgroundColourId).isOpaque());
  41751. repaint();
  41752. }
  41753. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  41754. {
  41755. caretVisible = shouldCaretBeVisible;
  41756. if (shouldCaretBeVisible)
  41757. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41758. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  41759. : MouseCursor::NormalCursor);
  41760. }
  41761. void TextEditor::setInputRestrictions (const int maxLen,
  41762. const String& chars)
  41763. {
  41764. maxTextLength = jmax (0, maxLen);
  41765. allowedCharacters = chars;
  41766. }
  41767. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  41768. {
  41769. textToShowWhenEmpty = text;
  41770. colourForTextWhenEmpty = colourToUse;
  41771. }
  41772. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  41773. {
  41774. if (passwordCharacter != newPasswordCharacter)
  41775. {
  41776. passwordCharacter = newPasswordCharacter;
  41777. resized();
  41778. repaint();
  41779. }
  41780. }
  41781. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  41782. {
  41783. viewport->setScrollBarThickness (newThicknessPixels);
  41784. }
  41785. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  41786. {
  41787. viewport->setScrollBarButtonVisibility (buttonsVisible);
  41788. }
  41789. void TextEditor::clear()
  41790. {
  41791. clearInternal (0);
  41792. updateTextHolderSize();
  41793. undoManager.clearUndoHistory();
  41794. }
  41795. void TextEditor::setText (const String& newText,
  41796. const bool sendTextChangeMessage)
  41797. {
  41798. const int newLength = newText.length();
  41799. if (newLength != getTotalNumChars() || getText() != newText)
  41800. {
  41801. const int oldCursorPos = caretPosition;
  41802. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  41803. clearInternal (0);
  41804. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  41805. // if you're adding text with line-feeds to a single-line text editor, it
  41806. // ain't gonna look right!
  41807. jassert (multiline || ! newText.containsAnyOf (T("\r\n")));
  41808. if (cursorWasAtEnd && ! isMultiLine())
  41809. moveCursorTo (getTotalNumChars(), false);
  41810. else
  41811. moveCursorTo (oldCursorPos, false);
  41812. if (sendTextChangeMessage)
  41813. textChanged();
  41814. repaint();
  41815. }
  41816. updateTextHolderSize();
  41817. scrollToMakeSureCursorIsVisible();
  41818. undoManager.clearUndoHistory();
  41819. }
  41820. Value& TextEditor::getTextValue()
  41821. {
  41822. if (valueTextNeedsUpdating)
  41823. {
  41824. valueTextNeedsUpdating = false;
  41825. textValue = getText();
  41826. }
  41827. return textValue;
  41828. }
  41829. void TextEditor::textWasChangedByValue()
  41830. {
  41831. if (textValue.getValueSource().getReferenceCount() > 1)
  41832. setText (textValue.getValue());
  41833. }
  41834. void TextEditor::textChanged()
  41835. {
  41836. updateTextHolderSize();
  41837. postCommandMessage (TextEditorDefs::textChangeMessageId);
  41838. if (textValue.getValueSource().getReferenceCount() > 1)
  41839. {
  41840. valueTextNeedsUpdating = false;
  41841. textValue = getText();
  41842. }
  41843. }
  41844. void TextEditor::returnPressed()
  41845. {
  41846. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  41847. }
  41848. void TextEditor::escapePressed()
  41849. {
  41850. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  41851. }
  41852. void TextEditor::addListener (TextEditorListener* const newListener)
  41853. {
  41854. listeners.add (newListener);
  41855. }
  41856. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  41857. {
  41858. listeners.remove (listenerToRemove);
  41859. }
  41860. void TextEditor::timerCallbackInt()
  41861. {
  41862. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  41863. if (caretFlashState != newState)
  41864. {
  41865. caretFlashState = newState;
  41866. if (caretFlashState)
  41867. wasFocused = true;
  41868. if (caretVisible
  41869. && hasKeyboardFocus (false)
  41870. && ! isReadOnly())
  41871. {
  41872. repaintCaret();
  41873. }
  41874. }
  41875. const unsigned int now = Time::getApproximateMillisecondCounter();
  41876. if (now > lastTransactionTime + 200)
  41877. newTransaction();
  41878. }
  41879. void TextEditor::repaintCaret()
  41880. {
  41881. if (! findColour (caretColourId).isTransparent())
  41882. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  41883. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  41884. 4,
  41885. roundToInt (cursorHeight) + 2);
  41886. }
  41887. void TextEditor::repaintText (const Range<int>& range)
  41888. {
  41889. if (! range.isEmpty())
  41890. {
  41891. float x = 0, y = 0, lh = currentFont.getHeight();
  41892. const float wordWrapWidth = getWordWrapWidth();
  41893. if (wordWrapWidth > 0)
  41894. {
  41895. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  41896. i.getCharPosition (range.getStart(), x, y, lh);
  41897. const int y1 = (int) y;
  41898. int y2;
  41899. if (range.getEnd() >= getTotalNumChars())
  41900. {
  41901. y2 = textHolder->getHeight();
  41902. }
  41903. else
  41904. {
  41905. i.getCharPosition (range.getEnd(), x, y, lh);
  41906. y2 = (int) (y + lh * 2.0f);
  41907. }
  41908. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  41909. }
  41910. }
  41911. }
  41912. void TextEditor::moveCaret (int newCaretPos)
  41913. {
  41914. if (newCaretPos < 0)
  41915. newCaretPos = 0;
  41916. else if (newCaretPos > getTotalNumChars())
  41917. newCaretPos = getTotalNumChars();
  41918. if (newCaretPos != getCaretPosition())
  41919. {
  41920. repaintCaret();
  41921. caretFlashState = true;
  41922. caretPosition = newCaretPos;
  41923. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41924. scrollToMakeSureCursorIsVisible();
  41925. repaintCaret();
  41926. }
  41927. }
  41928. void TextEditor::setCaretPosition (const int newIndex)
  41929. {
  41930. moveCursorTo (newIndex, false);
  41931. }
  41932. int TextEditor::getCaretPosition() const
  41933. {
  41934. return caretPosition;
  41935. }
  41936. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  41937. const int desiredCaretY)
  41938. {
  41939. updateCaretPosition();
  41940. int vx = roundToInt (cursorX) - desiredCaretX;
  41941. int vy = roundToInt (cursorY) - desiredCaretY;
  41942. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  41943. {
  41944. vx += desiredCaretX - proportionOfWidth (0.2f);
  41945. }
  41946. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  41947. {
  41948. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  41949. }
  41950. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  41951. if (! isMultiLine())
  41952. {
  41953. vy = viewport->getViewPositionY();
  41954. }
  41955. else
  41956. {
  41957. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  41958. const int curH = roundToInt (cursorHeight);
  41959. if (desiredCaretY < 0)
  41960. {
  41961. vy = jmax (0, desiredCaretY + vy);
  41962. }
  41963. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  41964. {
  41965. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  41966. }
  41967. }
  41968. viewport->setViewPosition (vx, vy);
  41969. }
  41970. const Rectangle<int> TextEditor::getCaretRectangle()
  41971. {
  41972. updateCaretPosition();
  41973. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  41974. roundToInt (cursorY) - viewport->getY(),
  41975. 1, roundToInt (cursorHeight));
  41976. }
  41977. float TextEditor::getWordWrapWidth() const
  41978. {
  41979. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  41980. : 1.0e10f;
  41981. }
  41982. void TextEditor::updateTextHolderSize()
  41983. {
  41984. const float wordWrapWidth = getWordWrapWidth();
  41985. if (wordWrapWidth > 0)
  41986. {
  41987. float maxWidth = 0.0f;
  41988. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  41989. while (i.next())
  41990. maxWidth = jmax (maxWidth, i.atomRight);
  41991. const int w = leftIndent + roundToInt (maxWidth);
  41992. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  41993. currentFont.getHeight()));
  41994. textHolder->setSize (w + 1, h + 1);
  41995. }
  41996. }
  41997. int TextEditor::getTextWidth() const
  41998. {
  41999. return textHolder->getWidth();
  42000. }
  42001. int TextEditor::getTextHeight() const
  42002. {
  42003. return textHolder->getHeight();
  42004. }
  42005. void TextEditor::setIndents (const int newLeftIndent,
  42006. const int newTopIndent)
  42007. {
  42008. leftIndent = newLeftIndent;
  42009. topIndent = newTopIndent;
  42010. }
  42011. void TextEditor::setBorder (const BorderSize& border)
  42012. {
  42013. borderSize = border;
  42014. resized();
  42015. }
  42016. const BorderSize TextEditor::getBorder() const
  42017. {
  42018. return borderSize;
  42019. }
  42020. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42021. {
  42022. keepCursorOnScreen = shouldScrollToShowCursor;
  42023. }
  42024. void TextEditor::updateCaretPosition()
  42025. {
  42026. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42027. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42028. }
  42029. void TextEditor::scrollToMakeSureCursorIsVisible()
  42030. {
  42031. updateCaretPosition();
  42032. if (keepCursorOnScreen)
  42033. {
  42034. int x = viewport->getViewPositionX();
  42035. int y = viewport->getViewPositionY();
  42036. const int relativeCursorX = roundToInt (cursorX) - x;
  42037. const int relativeCursorY = roundToInt (cursorY) - y;
  42038. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42039. {
  42040. x += relativeCursorX - proportionOfWidth (0.2f);
  42041. }
  42042. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42043. {
  42044. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42045. }
  42046. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42047. if (! isMultiLine())
  42048. {
  42049. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42050. }
  42051. else
  42052. {
  42053. const int curH = roundToInt (cursorHeight);
  42054. if (relativeCursorY < 0)
  42055. {
  42056. y = jmax (0, relativeCursorY + y);
  42057. }
  42058. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42059. {
  42060. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42061. }
  42062. }
  42063. viewport->setViewPosition (x, y);
  42064. }
  42065. }
  42066. void TextEditor::moveCursorTo (const int newPosition,
  42067. const bool isSelecting)
  42068. {
  42069. if (isSelecting)
  42070. {
  42071. moveCaret (newPosition);
  42072. const Range<int> oldSelection (selection);
  42073. if (dragType == notDragging)
  42074. {
  42075. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42076. dragType = draggingSelectionStart;
  42077. else
  42078. dragType = draggingSelectionEnd;
  42079. }
  42080. if (dragType == draggingSelectionStart)
  42081. {
  42082. if (getCaretPosition() >= selection.getEnd())
  42083. dragType = draggingSelectionEnd;
  42084. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42085. }
  42086. else
  42087. {
  42088. if (getCaretPosition() < selection.getStart())
  42089. dragType = draggingSelectionStart;
  42090. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42091. }
  42092. repaintText (selection.getUnionWith (oldSelection));
  42093. }
  42094. else
  42095. {
  42096. dragType = notDragging;
  42097. repaintText (selection);
  42098. moveCaret (newPosition);
  42099. selection = Range<int>::emptyRange (getCaretPosition());
  42100. }
  42101. }
  42102. int TextEditor::getTextIndexAt (const int x,
  42103. const int y)
  42104. {
  42105. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42106. (float) (y + viewport->getViewPositionY() - topIndent));
  42107. }
  42108. void TextEditor::insertTextAtCaret (const String& newText_)
  42109. {
  42110. String newText (newText_);
  42111. if (allowedCharacters.isNotEmpty())
  42112. newText = newText.retainCharacters (allowedCharacters);
  42113. if ((! returnKeyStartsNewLine) && newText == T("\n"))
  42114. {
  42115. returnPressed();
  42116. return;
  42117. }
  42118. if (! isMultiLine())
  42119. newText = newText.replaceCharacters (T("\r\n"), T(" "));
  42120. else
  42121. newText = newText.replace (T("\r\n"), T("\n"));
  42122. const int newCaretPos = selection.getStart() + newText.length();
  42123. const int insertIndex = selection.getStart();
  42124. remove (selection, getUndoManager(),
  42125. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42126. if (maxTextLength > 0)
  42127. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42128. if (newText.isNotEmpty())
  42129. insert (newText,
  42130. insertIndex,
  42131. currentFont,
  42132. findColour (textColourId),
  42133. getUndoManager(),
  42134. newCaretPos);
  42135. textChanged();
  42136. }
  42137. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42138. {
  42139. moveCursorTo (newSelection.getStart(), false);
  42140. moveCursorTo (newSelection.getEnd(), true);
  42141. }
  42142. void TextEditor::copy()
  42143. {
  42144. if (passwordCharacter == 0)
  42145. {
  42146. const String selection (getHighlightedText());
  42147. if (selection.isNotEmpty())
  42148. SystemClipboard::copyTextToClipboard (selection);
  42149. }
  42150. }
  42151. void TextEditor::paste()
  42152. {
  42153. if (! isReadOnly())
  42154. {
  42155. const String clip (SystemClipboard::getTextFromClipboard());
  42156. if (clip.isNotEmpty())
  42157. insertTextAtCaret (clip);
  42158. }
  42159. }
  42160. void TextEditor::cut()
  42161. {
  42162. if (! isReadOnly())
  42163. {
  42164. moveCaret (selection.getEnd());
  42165. insertTextAtCaret (String::empty);
  42166. }
  42167. }
  42168. void TextEditor::drawContent (Graphics& g)
  42169. {
  42170. const float wordWrapWidth = getWordWrapWidth();
  42171. if (wordWrapWidth > 0)
  42172. {
  42173. g.setOrigin (leftIndent, topIndent);
  42174. const Rectangle<int> clip (g.getClipBounds());
  42175. Colour selectedTextColour;
  42176. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42177. while (i.lineY + 200.0 < clip.getY() && i.next())
  42178. {}
  42179. if (! selection.isEmpty())
  42180. {
  42181. g.setColour (findColour (highlightColourId)
  42182. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42183. selectedTextColour = findColour (highlightedTextColourId);
  42184. TextEditorIterator i2 (i);
  42185. while (i2.next() && i2.lineY < clip.getBottom())
  42186. {
  42187. if (i2.lineY + i2.lineHeight >= clip.getY()
  42188. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42189. {
  42190. i2.drawSelection (g, selection);
  42191. }
  42192. }
  42193. }
  42194. const UniformTextSection* lastSection = 0;
  42195. while (i.next() && i.lineY < clip.getBottom())
  42196. {
  42197. if (i.lineY + i.lineHeight >= clip.getY())
  42198. {
  42199. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42200. {
  42201. i.drawSelectedText (g, selection, selectedTextColour);
  42202. lastSection = 0;
  42203. }
  42204. else
  42205. {
  42206. i.draw (g, lastSection);
  42207. }
  42208. }
  42209. }
  42210. }
  42211. }
  42212. void TextEditor::paint (Graphics& g)
  42213. {
  42214. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42215. }
  42216. void TextEditor::paintOverChildren (Graphics& g)
  42217. {
  42218. if (caretFlashState
  42219. && hasKeyboardFocus (false)
  42220. && caretVisible
  42221. && ! isReadOnly())
  42222. {
  42223. g.setColour (findColour (caretColourId));
  42224. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42225. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42226. 2.0f, cursorHeight);
  42227. }
  42228. if (textToShowWhenEmpty.isNotEmpty()
  42229. && (! hasKeyboardFocus (false))
  42230. && getTotalNumChars() == 0)
  42231. {
  42232. g.setColour (colourForTextWhenEmpty);
  42233. g.setFont (getFont());
  42234. if (isMultiLine())
  42235. {
  42236. g.drawText (textToShowWhenEmpty,
  42237. 0, 0, getWidth(), getHeight(),
  42238. Justification::centred, true);
  42239. }
  42240. else
  42241. {
  42242. g.drawText (textToShowWhenEmpty,
  42243. leftIndent, topIndent,
  42244. viewport->getWidth() - leftIndent,
  42245. viewport->getHeight() - topIndent,
  42246. Justification::centredLeft, true);
  42247. }
  42248. }
  42249. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42250. }
  42251. void TextEditor::mouseDown (const MouseEvent& e)
  42252. {
  42253. beginDragAutoRepeat (100);
  42254. newTransaction();
  42255. if (wasFocused || ! selectAllTextWhenFocused)
  42256. {
  42257. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42258. {
  42259. moveCursorTo (getTextIndexAt (e.x, e.y),
  42260. e.mods.isShiftDown());
  42261. }
  42262. else
  42263. {
  42264. PopupMenu m;
  42265. m.setLookAndFeel (&getLookAndFeel());
  42266. addPopupMenuItems (m, &e);
  42267. menuActive = true;
  42268. const int result = m.show();
  42269. menuActive = false;
  42270. if (result != 0)
  42271. performPopupMenuAction (result);
  42272. }
  42273. }
  42274. }
  42275. void TextEditor::mouseDrag (const MouseEvent& e)
  42276. {
  42277. if (wasFocused || ! selectAllTextWhenFocused)
  42278. {
  42279. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42280. {
  42281. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42282. }
  42283. }
  42284. }
  42285. void TextEditor::mouseUp (const MouseEvent& e)
  42286. {
  42287. newTransaction();
  42288. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42289. if (wasFocused || ! selectAllTextWhenFocused)
  42290. {
  42291. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42292. {
  42293. moveCaret (getTextIndexAt (e.x, e.y));
  42294. }
  42295. }
  42296. wasFocused = true;
  42297. }
  42298. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42299. {
  42300. int tokenEnd = getTextIndexAt (e.x, e.y);
  42301. int tokenStart = tokenEnd;
  42302. if (e.getNumberOfClicks() > 3)
  42303. {
  42304. tokenStart = 0;
  42305. tokenEnd = getTotalNumChars();
  42306. }
  42307. else
  42308. {
  42309. const String t (getText());
  42310. const int totalLength = getTotalNumChars();
  42311. while (tokenEnd < totalLength)
  42312. {
  42313. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42314. ++tokenEnd;
  42315. else
  42316. break;
  42317. }
  42318. tokenStart = tokenEnd;
  42319. while (tokenStart > 0)
  42320. {
  42321. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42322. --tokenStart;
  42323. else
  42324. break;
  42325. }
  42326. if (e.getNumberOfClicks() > 2)
  42327. {
  42328. while (tokenEnd < totalLength)
  42329. {
  42330. if (t [tokenEnd] != T('\r') && t [tokenEnd] != T('\n'))
  42331. ++tokenEnd;
  42332. else
  42333. break;
  42334. }
  42335. while (tokenStart > 0)
  42336. {
  42337. if (t [tokenStart - 1] != T('\r') && t [tokenStart - 1] != T('\n'))
  42338. --tokenStart;
  42339. else
  42340. break;
  42341. }
  42342. }
  42343. }
  42344. moveCursorTo (tokenEnd, false);
  42345. moveCursorTo (tokenStart, true);
  42346. }
  42347. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42348. {
  42349. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42350. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42351. }
  42352. bool TextEditor::keyPressed (const KeyPress& key)
  42353. {
  42354. if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  42355. return false;
  42356. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42357. if (key.isKeyCode (KeyPress::leftKey)
  42358. || key.isKeyCode (KeyPress::upKey))
  42359. {
  42360. newTransaction();
  42361. int newPos;
  42362. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42363. newPos = indexAtPosition (cursorX, cursorY - 1);
  42364. else if (moveInWholeWordSteps)
  42365. newPos = findWordBreakBefore (getCaretPosition());
  42366. else
  42367. newPos = getCaretPosition() - 1;
  42368. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42369. }
  42370. else if (key.isKeyCode (KeyPress::rightKey)
  42371. || key.isKeyCode (KeyPress::downKey))
  42372. {
  42373. newTransaction();
  42374. int newPos;
  42375. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42376. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42377. else if (moveInWholeWordSteps)
  42378. newPos = findWordBreakAfter (getCaretPosition());
  42379. else
  42380. newPos = getCaretPosition() + 1;
  42381. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42382. }
  42383. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42384. {
  42385. newTransaction();
  42386. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42387. key.getModifiers().isShiftDown());
  42388. }
  42389. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42390. {
  42391. newTransaction();
  42392. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42393. key.getModifiers().isShiftDown());
  42394. }
  42395. else if (key.isKeyCode (KeyPress::homeKey))
  42396. {
  42397. newTransaction();
  42398. if (isMultiLine() && ! moveInWholeWordSteps)
  42399. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42400. key.getModifiers().isShiftDown());
  42401. else
  42402. moveCursorTo (0, key.getModifiers().isShiftDown());
  42403. }
  42404. else if (key.isKeyCode (KeyPress::endKey))
  42405. {
  42406. newTransaction();
  42407. if (isMultiLine() && ! moveInWholeWordSteps)
  42408. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42409. key.getModifiers().isShiftDown());
  42410. else
  42411. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42412. }
  42413. else if (key.isKeyCode (KeyPress::backspaceKey))
  42414. {
  42415. if (moveInWholeWordSteps)
  42416. {
  42417. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42418. }
  42419. else
  42420. {
  42421. if (selection.isEmpty() && selection.getStart() > 0)
  42422. selection.setStart (selection.getEnd() - 1);
  42423. }
  42424. cut();
  42425. }
  42426. else if (key.isKeyCode (KeyPress::deleteKey))
  42427. {
  42428. if (key.getModifiers().isShiftDown())
  42429. copy();
  42430. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  42431. selection.setEnd (selection.getStart() + 1);
  42432. cut();
  42433. }
  42434. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0)
  42435. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42436. {
  42437. newTransaction();
  42438. copy();
  42439. }
  42440. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  42441. {
  42442. newTransaction();
  42443. copy();
  42444. cut();
  42445. }
  42446. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0)
  42447. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  42448. {
  42449. newTransaction();
  42450. paste();
  42451. }
  42452. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  42453. {
  42454. newTransaction();
  42455. doUndoRedo (false);
  42456. }
  42457. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0))
  42458. {
  42459. newTransaction();
  42460. doUndoRedo (true);
  42461. }
  42462. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  42463. {
  42464. newTransaction();
  42465. moveCursorTo (getTotalNumChars(), false);
  42466. moveCursorTo (0, true);
  42467. }
  42468. else if (key == KeyPress::returnKey)
  42469. {
  42470. newTransaction();
  42471. insertTextAtCaret (T("\n"));
  42472. }
  42473. else if (key.isKeyCode (KeyPress::escapeKey))
  42474. {
  42475. newTransaction();
  42476. moveCursorTo (getCaretPosition(), false);
  42477. escapePressed();
  42478. }
  42479. else if (key.getTextCharacter() >= ' '
  42480. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  42481. {
  42482. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  42483. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42484. }
  42485. else
  42486. {
  42487. return false;
  42488. }
  42489. return true;
  42490. }
  42491. bool TextEditor::keyStateChanged (const bool isKeyDown)
  42492. {
  42493. if (! isKeyDown)
  42494. return false;
  42495. #if JUCE_WIN32
  42496. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  42497. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  42498. #endif
  42499. // (overridden to avoid forwarding key events to the parent)
  42500. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  42501. }
  42502. const int baseMenuItemID = 0x7fff0000;
  42503. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  42504. {
  42505. const bool writable = ! isReadOnly();
  42506. if (passwordCharacter == 0)
  42507. {
  42508. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  42509. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  42510. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  42511. }
  42512. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  42513. m.addSeparator();
  42514. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  42515. m.addSeparator();
  42516. if (getUndoManager() != 0)
  42517. {
  42518. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  42519. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  42520. }
  42521. }
  42522. void TextEditor::performPopupMenuAction (const int menuItemID)
  42523. {
  42524. switch (menuItemID)
  42525. {
  42526. case baseMenuItemID + 1:
  42527. copy();
  42528. cut();
  42529. break;
  42530. case baseMenuItemID + 2:
  42531. copy();
  42532. break;
  42533. case baseMenuItemID + 3:
  42534. paste();
  42535. break;
  42536. case baseMenuItemID + 4:
  42537. cut();
  42538. break;
  42539. case baseMenuItemID + 5:
  42540. moveCursorTo (getTotalNumChars(), false);
  42541. moveCursorTo (0, true);
  42542. break;
  42543. case baseMenuItemID + 6:
  42544. doUndoRedo (false);
  42545. break;
  42546. case baseMenuItemID + 7:
  42547. doUndoRedo (true);
  42548. break;
  42549. default:
  42550. break;
  42551. }
  42552. }
  42553. void TextEditor::focusGained (FocusChangeType)
  42554. {
  42555. newTransaction();
  42556. caretFlashState = true;
  42557. if (selectAllTextWhenFocused)
  42558. {
  42559. moveCursorTo (0, false);
  42560. moveCursorTo (getTotalNumChars(), true);
  42561. }
  42562. repaint();
  42563. if (caretVisible)
  42564. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42565. ComponentPeer* const peer = getPeer();
  42566. if (peer != 0 && ! isReadOnly())
  42567. peer->textInputRequired (getScreenPosition() - peer->getScreenPosition());
  42568. }
  42569. void TextEditor::focusLost (FocusChangeType)
  42570. {
  42571. newTransaction();
  42572. wasFocused = false;
  42573. textHolder->stopTimer();
  42574. caretFlashState = false;
  42575. postCommandMessage (TextEditorDefs::focusLossMessageId);
  42576. repaint();
  42577. }
  42578. void TextEditor::resized()
  42579. {
  42580. viewport->setBoundsInset (borderSize);
  42581. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  42582. updateTextHolderSize();
  42583. if (! isMultiLine())
  42584. {
  42585. scrollToMakeSureCursorIsVisible();
  42586. }
  42587. else
  42588. {
  42589. updateCaretPosition();
  42590. }
  42591. }
  42592. void TextEditor::handleCommandMessage (const int commandId)
  42593. {
  42594. Component::BailOutChecker checker (this);
  42595. switch (commandId)
  42596. {
  42597. case TextEditorDefs::textChangeMessageId:
  42598. listeners.callChecked (checker, &TextEditorListener::textEditorTextChanged, (TextEditor&) *this);
  42599. break;
  42600. case TextEditorDefs::returnKeyMessageId:
  42601. listeners.callChecked (checker, &TextEditorListener::textEditorReturnKeyPressed, (TextEditor&) *this);
  42602. break;
  42603. case TextEditorDefs::escapeKeyMessageId:
  42604. listeners.callChecked (checker, &TextEditorListener::textEditorEscapeKeyPressed, (TextEditor&) *this);
  42605. break;
  42606. case TextEditorDefs::focusLossMessageId:
  42607. listeners.callChecked (checker, &TextEditorListener::textEditorFocusLost, (TextEditor&) *this);
  42608. break;
  42609. default:
  42610. jassertfalse
  42611. break;
  42612. }
  42613. }
  42614. void TextEditor::enablementChanged()
  42615. {
  42616. setMouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  42617. : MouseCursor::IBeamCursor);
  42618. repaint();
  42619. }
  42620. UndoManager* TextEditor::getUndoManager() throw()
  42621. {
  42622. return isReadOnly() ? &undoManager : 0;
  42623. }
  42624. void TextEditor::clearInternal (UndoManager* const um)
  42625. {
  42626. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  42627. }
  42628. void TextEditor::insert (const String& text,
  42629. const int insertIndex,
  42630. const Font& font,
  42631. const Colour& colour,
  42632. UndoManager* const um,
  42633. const int caretPositionToMoveTo)
  42634. {
  42635. if (text.isNotEmpty())
  42636. {
  42637. if (um != 0)
  42638. {
  42639. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42640. newTransaction();
  42641. um->perform (new TextEditorInsertAction (*this,
  42642. text,
  42643. insertIndex,
  42644. font,
  42645. colour,
  42646. caretPosition,
  42647. caretPositionToMoveTo));
  42648. }
  42649. else
  42650. {
  42651. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  42652. // a line gets moved due to word wrap
  42653. int index = 0;
  42654. int nextIndex = 0;
  42655. for (int i = 0; i < sections.size(); ++i)
  42656. {
  42657. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42658. if (insertIndex == index)
  42659. {
  42660. sections.insert (i, new UniformTextSection (text,
  42661. font, colour,
  42662. passwordCharacter));
  42663. break;
  42664. }
  42665. else if (insertIndex > index && insertIndex < nextIndex)
  42666. {
  42667. splitSection (i, insertIndex - index);
  42668. sections.insert (i + 1, new UniformTextSection (text,
  42669. font, colour,
  42670. passwordCharacter));
  42671. break;
  42672. }
  42673. index = nextIndex;
  42674. }
  42675. if (nextIndex == insertIndex)
  42676. sections.add (new UniformTextSection (text,
  42677. font, colour,
  42678. passwordCharacter));
  42679. coalesceSimilarSections();
  42680. totalNumChars = -1;
  42681. valueTextNeedsUpdating = true;
  42682. moveCursorTo (caretPositionToMoveTo, false);
  42683. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  42684. }
  42685. }
  42686. }
  42687. void TextEditor::reinsert (const int insertIndex,
  42688. const VoidArray& sectionsToInsert)
  42689. {
  42690. int index = 0;
  42691. int nextIndex = 0;
  42692. for (int i = 0; i < sections.size(); ++i)
  42693. {
  42694. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42695. if (insertIndex == index)
  42696. {
  42697. for (int j = sectionsToInsert.size(); --j >= 0;)
  42698. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42699. break;
  42700. }
  42701. else if (insertIndex > index && insertIndex < nextIndex)
  42702. {
  42703. splitSection (i, insertIndex - index);
  42704. for (int j = sectionsToInsert.size(); --j >= 0;)
  42705. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42706. break;
  42707. }
  42708. index = nextIndex;
  42709. }
  42710. if (nextIndex == insertIndex)
  42711. {
  42712. for (int j = 0; j < sectionsToInsert.size(); ++j)
  42713. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  42714. }
  42715. coalesceSimilarSections();
  42716. totalNumChars = -1;
  42717. valueTextNeedsUpdating = true;
  42718. }
  42719. void TextEditor::remove (const Range<int>& range,
  42720. UndoManager* const um,
  42721. const int caretPositionToMoveTo)
  42722. {
  42723. if (! range.isEmpty())
  42724. {
  42725. int index = 0;
  42726. for (int i = 0; i < sections.size(); ++i)
  42727. {
  42728. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  42729. if (range.getStart() > index && range.getStart() < nextIndex)
  42730. {
  42731. splitSection (i, range.getStart() - index);
  42732. --i;
  42733. }
  42734. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  42735. {
  42736. splitSection (i, range.getEnd() - index);
  42737. --i;
  42738. }
  42739. else
  42740. {
  42741. index = nextIndex;
  42742. if (index > range.getEnd())
  42743. break;
  42744. }
  42745. }
  42746. index = 0;
  42747. if (um != 0)
  42748. {
  42749. VoidArray removedSections;
  42750. for (int i = 0; i < sections.size(); ++i)
  42751. {
  42752. if (range.getEnd() <= range.getStart())
  42753. break;
  42754. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42755. const int nextIndex = index + section->getTotalLength();
  42756. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  42757. removedSections.add (new UniformTextSection (*section));
  42758. index = nextIndex;
  42759. }
  42760. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42761. newTransaction();
  42762. um->perform (new TextEditorRemoveAction (*this,
  42763. range,
  42764. caretPosition,
  42765. caretPositionToMoveTo,
  42766. removedSections));
  42767. }
  42768. else
  42769. {
  42770. Range<int> remainingRange (range);
  42771. for (int i = 0; i < sections.size(); ++i)
  42772. {
  42773. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  42774. const int nextIndex = index + section->getTotalLength();
  42775. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  42776. {
  42777. sections.remove(i);
  42778. section->clear();
  42779. delete section;
  42780. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  42781. if (remainingRange.isEmpty())
  42782. break;
  42783. --i;
  42784. }
  42785. else
  42786. {
  42787. index = nextIndex;
  42788. }
  42789. }
  42790. coalesceSimilarSections();
  42791. totalNumChars = -1;
  42792. valueTextNeedsUpdating = true;
  42793. moveCursorTo (caretPositionToMoveTo, false);
  42794. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  42795. }
  42796. }
  42797. }
  42798. const String TextEditor::getText() const
  42799. {
  42800. String t;
  42801. t.preallocateStorage (getTotalNumChars());
  42802. String::Concatenator concatenator (t);
  42803. for (int i = 0; i < sections.size(); ++i)
  42804. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  42805. return t;
  42806. }
  42807. const String TextEditor::getTextInRange (const Range<int>& range) const
  42808. {
  42809. String t;
  42810. if (! range.isEmpty())
  42811. {
  42812. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  42813. String::Concatenator concatenator (t);
  42814. int index = 0;
  42815. for (int i = 0; i < sections.size(); ++i)
  42816. {
  42817. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  42818. const int nextIndex = index + s->getTotalLength();
  42819. if (range.getStart() < nextIndex)
  42820. {
  42821. if (range.getEnd() <= index)
  42822. break;
  42823. s->appendSubstring (concatenator, range - index);
  42824. }
  42825. index = nextIndex;
  42826. }
  42827. }
  42828. return t;
  42829. }
  42830. const String TextEditor::getHighlightedText() const
  42831. {
  42832. return getTextInRange (selection);
  42833. }
  42834. int TextEditor::getTotalNumChars() const
  42835. {
  42836. if (totalNumChars < 0)
  42837. {
  42838. totalNumChars = 0;
  42839. for (int i = sections.size(); --i >= 0;)
  42840. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  42841. }
  42842. return totalNumChars;
  42843. }
  42844. bool TextEditor::isEmpty() const
  42845. {
  42846. return getTotalNumChars() == 0;
  42847. }
  42848. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  42849. {
  42850. const float wordWrapWidth = getWordWrapWidth();
  42851. if (wordWrapWidth > 0 && sections.size() > 0)
  42852. {
  42853. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42854. i.getCharPosition (index, cx, cy, lineHeight);
  42855. }
  42856. else
  42857. {
  42858. cx = cy = 0;
  42859. lineHeight = currentFont.getHeight();
  42860. }
  42861. }
  42862. int TextEditor::indexAtPosition (const float x, const float y)
  42863. {
  42864. const float wordWrapWidth = getWordWrapWidth();
  42865. if (wordWrapWidth > 0)
  42866. {
  42867. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42868. while (i.next())
  42869. {
  42870. if (i.lineY + i.lineHeight > y)
  42871. {
  42872. if (i.lineY > y)
  42873. return jmax (0, i.indexInText - 1);
  42874. if (i.atomX >= x)
  42875. return i.indexInText;
  42876. if (x < i.atomRight)
  42877. return i.xToIndex (x);
  42878. }
  42879. }
  42880. }
  42881. return getTotalNumChars();
  42882. }
  42883. static int getCharacterCategory (const tchar character)
  42884. {
  42885. return CharacterFunctions::isLetterOrDigit (character)
  42886. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  42887. }
  42888. int TextEditor::findWordBreakAfter (const int position) const
  42889. {
  42890. const String t (getTextInRange (Range<int> (position, position + 512)));
  42891. const int totalLength = t.length();
  42892. int i = 0;
  42893. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42894. ++i;
  42895. const int type = getCharacterCategory (t[i]);
  42896. while (i < totalLength && type == getCharacterCategory (t[i]))
  42897. ++i;
  42898. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42899. ++i;
  42900. return position + i;
  42901. }
  42902. int TextEditor::findWordBreakBefore (const int position) const
  42903. {
  42904. if (position <= 0)
  42905. return 0;
  42906. const int startOfBuffer = jmax (0, position - 512);
  42907. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  42908. int i = position - startOfBuffer;
  42909. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  42910. --i;
  42911. if (i > 0)
  42912. {
  42913. const int type = getCharacterCategory (t [i - 1]);
  42914. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  42915. --i;
  42916. }
  42917. jassert (startOfBuffer + i >= 0);
  42918. return startOfBuffer + i;
  42919. }
  42920. void TextEditor::splitSection (const int sectionIndex,
  42921. const int charToSplitAt)
  42922. {
  42923. jassert (sections[sectionIndex] != 0);
  42924. sections.insert (sectionIndex + 1,
  42925. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  42926. ->split (charToSplitAt, passwordCharacter));
  42927. }
  42928. void TextEditor::coalesceSimilarSections()
  42929. {
  42930. for (int i = 0; i < sections.size() - 1; ++i)
  42931. {
  42932. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  42933. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  42934. if (s1->font == s2->font
  42935. && s1->colour == s2->colour)
  42936. {
  42937. s1->append (*s2, passwordCharacter);
  42938. sections.remove (i + 1);
  42939. delete s2;
  42940. --i;
  42941. }
  42942. }
  42943. }
  42944. END_JUCE_NAMESPACE
  42945. /*** End of inlined file: juce_TextEditor.cpp ***/
  42946. /*** Start of inlined file: juce_Toolbar.cpp ***/
  42947. BEGIN_JUCE_NAMESPACE
  42948. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  42949. class ToolbarSpacerComp : public ToolbarItemComponent
  42950. {
  42951. public:
  42952. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  42953. : ToolbarItemComponent (itemId_, String::empty, false),
  42954. fixedSize (fixedSize_),
  42955. drawBar (drawBar_)
  42956. {
  42957. }
  42958. ~ToolbarSpacerComp()
  42959. {
  42960. }
  42961. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  42962. int& preferredSize, int& minSize, int& maxSize)
  42963. {
  42964. if (fixedSize <= 0)
  42965. {
  42966. preferredSize = toolbarThickness * 2;
  42967. minSize = 4;
  42968. maxSize = 32768;
  42969. }
  42970. else
  42971. {
  42972. maxSize = roundToInt (toolbarThickness * fixedSize);
  42973. minSize = drawBar ? maxSize : jmin (4, maxSize);
  42974. preferredSize = maxSize;
  42975. if (getEditingMode() == editableOnPalette)
  42976. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  42977. }
  42978. return true;
  42979. }
  42980. void paintButtonArea (Graphics&, int, int, bool, bool)
  42981. {
  42982. }
  42983. void contentAreaChanged (const Rectangle<int>&)
  42984. {
  42985. }
  42986. int getResizeOrder() const throw()
  42987. {
  42988. return fixedSize <= 0 ? 0 : 1;
  42989. }
  42990. void paint (Graphics& g)
  42991. {
  42992. const int w = getWidth();
  42993. const int h = getHeight();
  42994. if (drawBar)
  42995. {
  42996. g.setColour (findColour (Toolbar::separatorColourId, true));
  42997. const float thickness = 0.2f;
  42998. if (isToolbarVertical())
  42999. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43000. else
  43001. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43002. }
  43003. if (getEditingMode() != normalMode && ! drawBar)
  43004. {
  43005. g.setColour (findColour (Toolbar::separatorColourId, true));
  43006. const int indentX = jmin (2, (w - 3) / 2);
  43007. const int indentY = jmin (2, (h - 3) / 2);
  43008. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43009. if (fixedSize <= 0)
  43010. {
  43011. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43012. if (isToolbarVertical())
  43013. {
  43014. x1 = w * 0.5f;
  43015. y1 = h * 0.4f;
  43016. x2 = x1;
  43017. y2 = indentX * 2.0f;
  43018. x3 = x1;
  43019. y3 = h * 0.6f;
  43020. x4 = x1;
  43021. y4 = h - y2;
  43022. hw = w * 0.15f;
  43023. hl = w * 0.2f;
  43024. }
  43025. else
  43026. {
  43027. x1 = w * 0.4f;
  43028. y1 = h * 0.5f;
  43029. x2 = indentX * 2.0f;
  43030. y2 = y1;
  43031. x3 = w * 0.6f;
  43032. y3 = y1;
  43033. x4 = w - x2;
  43034. y4 = y1;
  43035. hw = h * 0.15f;
  43036. hl = h * 0.2f;
  43037. }
  43038. Path p;
  43039. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43040. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43041. g.fillPath (p);
  43042. }
  43043. }
  43044. }
  43045. juce_UseDebuggingNewOperator
  43046. private:
  43047. const float fixedSize;
  43048. const bool drawBar;
  43049. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43050. ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43051. };
  43052. class MissingItemsComponent : public PopupMenuCustomComponent
  43053. {
  43054. public:
  43055. MissingItemsComponent (Toolbar& owner_, const int height_)
  43056. : PopupMenuCustomComponent (true),
  43057. owner (owner_),
  43058. height (height_)
  43059. {
  43060. for (int i = owner_.items.size(); --i >= 0;)
  43061. {
  43062. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43063. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43064. {
  43065. oldIndexes.insert (0, i);
  43066. addAndMakeVisible (tc, 0);
  43067. }
  43068. }
  43069. layout (400);
  43070. }
  43071. ~MissingItemsComponent()
  43072. {
  43073. // deleting the toolbar while its menu it open??
  43074. jassert (owner.isValidComponent());
  43075. for (int i = 0; i < getNumChildComponents(); ++i)
  43076. {
  43077. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43078. if (tc != 0)
  43079. {
  43080. tc->setVisible (false);
  43081. const int index = oldIndexes.remove (i);
  43082. owner.addChildComponent (tc, index);
  43083. --i;
  43084. }
  43085. }
  43086. owner.resized();
  43087. }
  43088. void layout (const int preferredWidth)
  43089. {
  43090. const int indent = 8;
  43091. int x = indent;
  43092. int y = indent;
  43093. int maxX = 0;
  43094. for (int i = 0; i < getNumChildComponents(); ++i)
  43095. {
  43096. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43097. if (tc != 0)
  43098. {
  43099. int preferredSize = 1, minSize = 1, maxSize = 1;
  43100. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43101. {
  43102. if (x + preferredSize > preferredWidth && x > indent)
  43103. {
  43104. x = indent;
  43105. y += height;
  43106. }
  43107. tc->setBounds (x, y, preferredSize, height);
  43108. x += preferredSize;
  43109. maxX = jmax (maxX, x);
  43110. }
  43111. }
  43112. }
  43113. setSize (maxX + 8, y + height + 8);
  43114. }
  43115. void getIdealSize (int& idealWidth, int& idealHeight)
  43116. {
  43117. idealWidth = getWidth();
  43118. idealHeight = getHeight();
  43119. }
  43120. juce_UseDebuggingNewOperator
  43121. private:
  43122. Toolbar& owner;
  43123. const int height;
  43124. Array <int> oldIndexes;
  43125. MissingItemsComponent (const MissingItemsComponent&);
  43126. MissingItemsComponent& operator= (const MissingItemsComponent&);
  43127. };
  43128. Toolbar::Toolbar()
  43129. : vertical (false),
  43130. isEditingActive (false),
  43131. toolbarStyle (Toolbar::iconsOnly)
  43132. {
  43133. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43134. missingItemsButton->setAlwaysOnTop (true);
  43135. missingItemsButton->addButtonListener (this);
  43136. }
  43137. Toolbar::~Toolbar()
  43138. {
  43139. animator.cancelAllAnimations (true);
  43140. deleteAllChildren();
  43141. }
  43142. void Toolbar::setVertical (const bool shouldBeVertical)
  43143. {
  43144. if (vertical != shouldBeVertical)
  43145. {
  43146. vertical = shouldBeVertical;
  43147. resized();
  43148. }
  43149. }
  43150. void Toolbar::clear()
  43151. {
  43152. for (int i = items.size(); --i >= 0;)
  43153. {
  43154. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43155. items.remove (i);
  43156. delete tc;
  43157. }
  43158. resized();
  43159. }
  43160. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43161. {
  43162. if (itemId == ToolbarItemFactory::separatorBarId)
  43163. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43164. else if (itemId == ToolbarItemFactory::spacerId)
  43165. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43166. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43167. return new ToolbarSpacerComp (itemId, 0, false);
  43168. return factory.createItem (itemId);
  43169. }
  43170. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43171. const int itemId,
  43172. const int insertIndex)
  43173. {
  43174. // An ID can't be zero - this might indicate a mistake somewhere?
  43175. jassert (itemId != 0);
  43176. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43177. if (tc != 0)
  43178. {
  43179. #ifdef JUCE_DEBUG
  43180. Array <int> allowedIds;
  43181. factory.getAllToolbarItemIds (allowedIds);
  43182. // If your factory can create an item for a given ID, it must also return
  43183. // that ID from its getAllToolbarItemIds() method!
  43184. jassert (allowedIds.contains (itemId));
  43185. #endif
  43186. items.insert (insertIndex, tc);
  43187. addAndMakeVisible (tc, insertIndex);
  43188. }
  43189. }
  43190. void Toolbar::addItem (ToolbarItemFactory& factory,
  43191. const int itemId,
  43192. const int insertIndex)
  43193. {
  43194. addItemInternal (factory, itemId, insertIndex);
  43195. resized();
  43196. }
  43197. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43198. {
  43199. Array <int> ids;
  43200. factoryToUse.getDefaultItemSet (ids);
  43201. clear();
  43202. for (int i = 0; i < ids.size(); ++i)
  43203. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43204. resized();
  43205. }
  43206. void Toolbar::removeToolbarItem (const int itemIndex)
  43207. {
  43208. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43209. if (tc != 0)
  43210. {
  43211. items.removeValue (tc);
  43212. delete tc;
  43213. resized();
  43214. }
  43215. }
  43216. int Toolbar::getNumItems() const throw()
  43217. {
  43218. return items.size();
  43219. }
  43220. int Toolbar::getItemId (const int itemIndex) const throw()
  43221. {
  43222. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43223. return tc != 0 ? tc->getItemId() : 0;
  43224. }
  43225. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43226. {
  43227. return items [itemIndex];
  43228. }
  43229. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43230. {
  43231. for (;;)
  43232. {
  43233. index += delta;
  43234. ToolbarItemComponent* const tc = getItemComponent (index);
  43235. if (tc == 0)
  43236. break;
  43237. if (tc->isActive)
  43238. return tc;
  43239. }
  43240. return 0;
  43241. }
  43242. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43243. {
  43244. if (toolbarStyle != newStyle)
  43245. {
  43246. toolbarStyle = newStyle;
  43247. updateAllItemPositions (false);
  43248. }
  43249. }
  43250. const String Toolbar::toString() const
  43251. {
  43252. String s (T("TB:"));
  43253. for (int i = 0; i < getNumItems(); ++i)
  43254. s << getItemId(i) << T(' ');
  43255. return s.trimEnd();
  43256. }
  43257. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43258. const String& savedVersion)
  43259. {
  43260. if (! savedVersion.startsWith (T("TB:")))
  43261. return false;
  43262. StringArray tokens;
  43263. tokens.addTokens (savedVersion.substring (3), false);
  43264. clear();
  43265. for (int i = 0; i < tokens.size(); ++i)
  43266. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43267. resized();
  43268. return true;
  43269. }
  43270. void Toolbar::paint (Graphics& g)
  43271. {
  43272. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43273. }
  43274. int Toolbar::getThickness() const throw()
  43275. {
  43276. return vertical ? getWidth() : getHeight();
  43277. }
  43278. int Toolbar::getLength() const throw()
  43279. {
  43280. return vertical ? getHeight() : getWidth();
  43281. }
  43282. void Toolbar::setEditingActive (const bool active)
  43283. {
  43284. if (isEditingActive != active)
  43285. {
  43286. isEditingActive = active;
  43287. updateAllItemPositions (false);
  43288. }
  43289. }
  43290. void Toolbar::resized()
  43291. {
  43292. updateAllItemPositions (false);
  43293. }
  43294. void Toolbar::updateAllItemPositions (const bool animate)
  43295. {
  43296. if (getWidth() > 0 && getHeight() > 0)
  43297. {
  43298. StretchableObjectResizer resizer;
  43299. int i;
  43300. for (i = 0; i < items.size(); ++i)
  43301. {
  43302. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43303. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43304. : ToolbarItemComponent::normalMode);
  43305. tc->setStyle (toolbarStyle);
  43306. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43307. int preferredSize = 1, minSize = 1, maxSize = 1;
  43308. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43309. preferredSize, minSize, maxSize))
  43310. {
  43311. tc->isActive = true;
  43312. resizer.addItem (preferredSize, minSize, maxSize,
  43313. spacer != 0 ? spacer->getResizeOrder() : 2);
  43314. }
  43315. else
  43316. {
  43317. tc->isActive = false;
  43318. tc->setVisible (false);
  43319. }
  43320. }
  43321. resizer.resizeToFit (getLength());
  43322. int totalLength = 0;
  43323. for (i = 0; i < resizer.getNumItems(); ++i)
  43324. totalLength += (int) resizer.getItemSize (i);
  43325. const bool itemsOffTheEnd = totalLength > getLength();
  43326. const int extrasButtonSize = getThickness() / 2;
  43327. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43328. missingItemsButton->setVisible (itemsOffTheEnd);
  43329. missingItemsButton->setEnabled (! isEditingActive);
  43330. if (vertical)
  43331. missingItemsButton->setCentrePosition (getWidth() / 2,
  43332. getHeight() - 4 - extrasButtonSize / 2);
  43333. else
  43334. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43335. getHeight() / 2);
  43336. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43337. : missingItemsButton->getX()) - 4
  43338. : getLength();
  43339. int pos = 0, activeIndex = 0;
  43340. for (i = 0; i < items.size(); ++i)
  43341. {
  43342. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43343. if (tc->isActive)
  43344. {
  43345. const int size = (int) resizer.getItemSize (activeIndex++);
  43346. Rectangle<int> newBounds;
  43347. if (vertical)
  43348. newBounds.setBounds (0, pos, getWidth(), size);
  43349. else
  43350. newBounds.setBounds (pos, 0, size, getHeight());
  43351. if (animate)
  43352. {
  43353. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43354. }
  43355. else
  43356. {
  43357. animator.cancelAnimation (tc, false);
  43358. tc->setBounds (newBounds);
  43359. }
  43360. pos += size;
  43361. tc->setVisible (pos <= maxLength
  43362. && ((! tc->isBeingDragged)
  43363. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43364. }
  43365. }
  43366. }
  43367. }
  43368. void Toolbar::buttonClicked (Button*)
  43369. {
  43370. jassert (missingItemsButton->isShowing());
  43371. if (missingItemsButton->isShowing())
  43372. {
  43373. PopupMenu m;
  43374. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43375. m.showAt (missingItemsButton);
  43376. }
  43377. }
  43378. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43379. Component* /*sourceComponent*/)
  43380. {
  43381. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43382. }
  43383. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43384. {
  43385. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43386. if (tc != 0)
  43387. {
  43388. if (getNumItems() == 0)
  43389. {
  43390. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43391. {
  43392. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43393. if (palette != 0)
  43394. palette->replaceComponent (tc);
  43395. }
  43396. else
  43397. {
  43398. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43399. }
  43400. items.add (tc);
  43401. addChildComponent (tc);
  43402. updateAllItemPositions (false);
  43403. }
  43404. else
  43405. {
  43406. for (int i = getNumItems(); --i >= 0;)
  43407. {
  43408. int currentIndex = getIndexOfChildComponent (tc);
  43409. if (currentIndex < 0)
  43410. {
  43411. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43412. {
  43413. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43414. if (palette != 0)
  43415. palette->replaceComponent (tc);
  43416. }
  43417. else
  43418. {
  43419. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43420. }
  43421. items.add (tc);
  43422. addChildComponent (tc);
  43423. currentIndex = getIndexOfChildComponent (tc);
  43424. updateAllItemPositions (true);
  43425. }
  43426. int newIndex = currentIndex;
  43427. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43428. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43429. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  43430. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43431. if (prev != 0)
  43432. {
  43433. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  43434. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43435. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43436. {
  43437. newIndex = getIndexOfChildComponent (prev);
  43438. }
  43439. }
  43440. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  43441. if (next != 0)
  43442. {
  43443. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  43444. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  43445. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  43446. {
  43447. newIndex = getIndexOfChildComponent (next) + 1;
  43448. }
  43449. }
  43450. if (newIndex != currentIndex)
  43451. {
  43452. items.removeValue (tc);
  43453. removeChildComponent (tc);
  43454. addChildComponent (tc, newIndex);
  43455. items.insert (newIndex, tc);
  43456. updateAllItemPositions (true);
  43457. }
  43458. else
  43459. {
  43460. break;
  43461. }
  43462. }
  43463. }
  43464. }
  43465. }
  43466. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  43467. {
  43468. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43469. if (tc != 0)
  43470. {
  43471. if (isParentOf (tc))
  43472. {
  43473. items.removeValue (tc);
  43474. removeChildComponent (tc);
  43475. updateAllItemPositions (true);
  43476. }
  43477. }
  43478. }
  43479. void Toolbar::itemDropped (const String&, Component*, int, int)
  43480. {
  43481. }
  43482. void Toolbar::mouseDown (const MouseEvent& e)
  43483. {
  43484. if (e.mods.isPopupMenu())
  43485. {
  43486. }
  43487. }
  43488. class ToolbarCustomisationDialog : public DialogWindow
  43489. {
  43490. public:
  43491. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  43492. Toolbar* const toolbar_,
  43493. const int optionFlags)
  43494. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  43495. toolbar (toolbar_)
  43496. {
  43497. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  43498. setResizable (true, true);
  43499. setResizeLimits (400, 300, 1500, 1000);
  43500. positionNearBar();
  43501. }
  43502. ~ToolbarCustomisationDialog()
  43503. {
  43504. setContentComponent (0, true);
  43505. }
  43506. void closeButtonPressed()
  43507. {
  43508. setVisible (false);
  43509. }
  43510. bool canModalEventBeSentToComponent (const Component* comp)
  43511. {
  43512. return toolbar->isParentOf (comp);
  43513. }
  43514. void positionNearBar()
  43515. {
  43516. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  43517. const int tbx = toolbar->getScreenX();
  43518. const int tby = toolbar->getScreenY();
  43519. const int gap = 8;
  43520. int x, y;
  43521. if (toolbar->isVertical())
  43522. {
  43523. y = tby;
  43524. if (tbx > screenSize.getCentreX())
  43525. x = tbx - getWidth() - gap;
  43526. else
  43527. x = tbx + toolbar->getWidth() + gap;
  43528. }
  43529. else
  43530. {
  43531. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  43532. if (tby > screenSize.getCentreY())
  43533. y = tby - getHeight() - gap;
  43534. else
  43535. y = tby + toolbar->getHeight() + gap;
  43536. }
  43537. setTopLeftPosition (x, y);
  43538. }
  43539. private:
  43540. Toolbar* const toolbar;
  43541. class CustomiserPanel : public Component,
  43542. private ComboBoxListener,
  43543. private ButtonListener
  43544. {
  43545. public:
  43546. CustomiserPanel (ToolbarItemFactory& factory_,
  43547. Toolbar* const toolbar_,
  43548. const int optionFlags)
  43549. : factory (factory_),
  43550. toolbar (toolbar_),
  43551. styleBox (0),
  43552. defaultButton (0)
  43553. {
  43554. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  43555. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  43556. | Toolbar::allowIconsWithTextChoice
  43557. | Toolbar::allowTextOnlyChoice)) != 0)
  43558. {
  43559. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  43560. styleBox->setEditableText (false);
  43561. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  43562. styleBox->addItem (TRANS("Show icons only"), 1);
  43563. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  43564. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  43565. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  43566. styleBox->addItem (TRANS("Show descriptions only"), 3);
  43567. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  43568. styleBox->setSelectedId (1);
  43569. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  43570. styleBox->setSelectedId (2);
  43571. else if (toolbar_->getStyle() == Toolbar::textOnly)
  43572. styleBox->setSelectedId (3);
  43573. styleBox->addListener (this);
  43574. }
  43575. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  43576. {
  43577. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  43578. defaultButton->addButtonListener (this);
  43579. }
  43580. addAndMakeVisible (instructions = new Label (String::empty,
  43581. 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.")));
  43582. instructions->setFont (Font (13.0f));
  43583. setSize (500, 300);
  43584. }
  43585. ~CustomiserPanel()
  43586. {
  43587. deleteAllChildren();
  43588. }
  43589. void comboBoxChanged (ComboBox*)
  43590. {
  43591. if (styleBox->getSelectedId() == 1)
  43592. toolbar->setStyle (Toolbar::iconsOnly);
  43593. else if (styleBox->getSelectedId() == 2)
  43594. toolbar->setStyle (Toolbar::iconsWithText);
  43595. else if (styleBox->getSelectedId() == 3)
  43596. toolbar->setStyle (Toolbar::textOnly);
  43597. palette->resized(); // to make it update the styles
  43598. }
  43599. void buttonClicked (Button*)
  43600. {
  43601. toolbar->addDefaultItems (factory);
  43602. }
  43603. void paint (Graphics& g)
  43604. {
  43605. Colour background;
  43606. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  43607. if (dw != 0)
  43608. background = dw->getBackgroundColour();
  43609. g.setColour (background.contrasting().withAlpha (0.3f));
  43610. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  43611. }
  43612. void resized()
  43613. {
  43614. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  43615. if (styleBox != 0)
  43616. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  43617. if (defaultButton != 0)
  43618. {
  43619. defaultButton->changeWidthToFitText (22);
  43620. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  43621. }
  43622. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  43623. }
  43624. private:
  43625. ToolbarItemFactory& factory;
  43626. Toolbar* const toolbar;
  43627. Label* instructions;
  43628. ToolbarItemPalette* palette;
  43629. ComboBox* styleBox;
  43630. TextButton* defaultButton;
  43631. };
  43632. };
  43633. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  43634. {
  43635. setEditingActive (true);
  43636. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  43637. dw.runModalLoop();
  43638. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  43639. setEditingActive (false);
  43640. }
  43641. END_JUCE_NAMESPACE
  43642. /*** End of inlined file: juce_Toolbar.cpp ***/
  43643. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  43644. BEGIN_JUCE_NAMESPACE
  43645. ToolbarItemFactory::ToolbarItemFactory()
  43646. {
  43647. }
  43648. ToolbarItemFactory::~ToolbarItemFactory()
  43649. {
  43650. }
  43651. class ItemDragAndDropOverlayComponent : public Component
  43652. {
  43653. public:
  43654. ItemDragAndDropOverlayComponent()
  43655. : isDragging (false)
  43656. {
  43657. setAlwaysOnTop (true);
  43658. setRepaintsOnMouseActivity (true);
  43659. setMouseCursor (MouseCursor::DraggingHandCursor);
  43660. }
  43661. ~ItemDragAndDropOverlayComponent()
  43662. {
  43663. }
  43664. void paint (Graphics& g)
  43665. {
  43666. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43667. if (isMouseOverOrDragging()
  43668. && tc != 0
  43669. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43670. {
  43671. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  43672. g.drawRect (0, 0, getWidth(), getHeight(),
  43673. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  43674. }
  43675. }
  43676. void mouseDown (const MouseEvent& e)
  43677. {
  43678. isDragging = false;
  43679. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43680. if (tc != 0)
  43681. {
  43682. tc->dragOffsetX = e.x;
  43683. tc->dragOffsetY = e.y;
  43684. }
  43685. }
  43686. void mouseDrag (const MouseEvent& e)
  43687. {
  43688. if (! (isDragging || e.mouseWasClicked()))
  43689. {
  43690. isDragging = true;
  43691. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  43692. if (dnd != 0)
  43693. {
  43694. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  43695. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43696. if (tc != 0)
  43697. {
  43698. tc->isBeingDragged = true;
  43699. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43700. tc->setVisible (false);
  43701. }
  43702. }
  43703. }
  43704. }
  43705. void mouseUp (const MouseEvent&)
  43706. {
  43707. isDragging = false;
  43708. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43709. if (tc != 0)
  43710. {
  43711. tc->isBeingDragged = false;
  43712. Toolbar* const tb = tc->getToolbar();
  43713. if (tb != 0)
  43714. tb->updateAllItemPositions (true);
  43715. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43716. delete tc;
  43717. }
  43718. }
  43719. void parentSizeChanged()
  43720. {
  43721. setBounds (0, 0, getParentWidth(), getParentHeight());
  43722. }
  43723. juce_UseDebuggingNewOperator
  43724. private:
  43725. bool isDragging;
  43726. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  43727. ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  43728. };
  43729. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  43730. const String& labelText,
  43731. const bool isBeingUsedAsAButton_)
  43732. : Button (labelText),
  43733. itemId (itemId_),
  43734. mode (normalMode),
  43735. toolbarStyle (Toolbar::iconsOnly),
  43736. dragOffsetX (0),
  43737. dragOffsetY (0),
  43738. isActive (true),
  43739. isBeingDragged (false),
  43740. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  43741. {
  43742. // Your item ID can't be 0!
  43743. jassert (itemId_ != 0);
  43744. }
  43745. ToolbarItemComponent::~ToolbarItemComponent()
  43746. {
  43747. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43748. overlayComp = 0;
  43749. }
  43750. Toolbar* ToolbarItemComponent::getToolbar() const
  43751. {
  43752. return dynamic_cast <Toolbar*> (getParentComponent());
  43753. }
  43754. bool ToolbarItemComponent::isToolbarVertical() const
  43755. {
  43756. const Toolbar* const t = getToolbar();
  43757. return t != 0 && t->isVertical();
  43758. }
  43759. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  43760. {
  43761. if (toolbarStyle != newStyle)
  43762. {
  43763. toolbarStyle = newStyle;
  43764. repaint();
  43765. resized();
  43766. }
  43767. }
  43768. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  43769. {
  43770. if (isBeingUsedAsAButton)
  43771. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  43772. isMouseOver, isMouseDown, *this);
  43773. if (toolbarStyle != Toolbar::iconsOnly)
  43774. {
  43775. const int indent = contentArea.getX();
  43776. int y = indent;
  43777. int h = getHeight() - indent * 2;
  43778. if (toolbarStyle == Toolbar::iconsWithText)
  43779. {
  43780. y = contentArea.getBottom() + indent / 2;
  43781. h -= contentArea.getHeight();
  43782. }
  43783. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  43784. getButtonText(), *this);
  43785. }
  43786. if (! contentArea.isEmpty())
  43787. {
  43788. g.saveState();
  43789. g.setOrigin (contentArea.getX(), contentArea.getY());
  43790. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  43791. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  43792. g.restoreState();
  43793. }
  43794. }
  43795. void ToolbarItemComponent::resized()
  43796. {
  43797. if (toolbarStyle != Toolbar::textOnly)
  43798. {
  43799. const int indent = jmin (proportionOfWidth (0.08f),
  43800. proportionOfHeight (0.08f));
  43801. contentArea = Rectangle<int> (indent, indent,
  43802. getWidth() - indent * 2,
  43803. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  43804. : (getHeight() - indent * 2));
  43805. }
  43806. else
  43807. {
  43808. contentArea = Rectangle<int>();
  43809. }
  43810. contentAreaChanged (contentArea);
  43811. }
  43812. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  43813. {
  43814. if (mode != newMode)
  43815. {
  43816. mode = newMode;
  43817. repaint();
  43818. if (mode == normalMode)
  43819. {
  43820. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43821. overlayComp = 0;
  43822. }
  43823. else if (overlayComp == 0)
  43824. {
  43825. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  43826. overlayComp->parentSizeChanged();
  43827. }
  43828. resized();
  43829. }
  43830. }
  43831. END_JUCE_NAMESPACE
  43832. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  43833. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  43834. BEGIN_JUCE_NAMESPACE
  43835. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  43836. Toolbar* const toolbar_)
  43837. : factory (factory_),
  43838. toolbar (toolbar_)
  43839. {
  43840. Component* const itemHolder = new Component();
  43841. Array <int> allIds;
  43842. factory_.getAllToolbarItemIds (allIds);
  43843. for (int i = 0; i < allIds.size(); ++i)
  43844. {
  43845. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  43846. jassert (tc != 0);
  43847. if (tc != 0)
  43848. {
  43849. itemHolder->addAndMakeVisible (tc);
  43850. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  43851. }
  43852. }
  43853. viewport = new Viewport();
  43854. viewport->setViewedComponent (itemHolder);
  43855. addAndMakeVisible (viewport);
  43856. }
  43857. ToolbarItemPalette::~ToolbarItemPalette()
  43858. {
  43859. viewport->getViewedComponent()->deleteAllChildren();
  43860. deleteAllChildren();
  43861. }
  43862. void ToolbarItemPalette::resized()
  43863. {
  43864. viewport->setBoundsInset (BorderSize (1));
  43865. Component* const itemHolder = viewport->getViewedComponent();
  43866. const int indent = 8;
  43867. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  43868. const int height = toolbar->getThickness();
  43869. int x = indent;
  43870. int y = indent;
  43871. int maxX = 0;
  43872. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  43873. {
  43874. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  43875. if (tc != 0)
  43876. {
  43877. tc->setStyle (toolbar->getStyle());
  43878. int preferredSize = 1, minSize = 1, maxSize = 1;
  43879. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43880. {
  43881. if (x + preferredSize > preferredWidth && x > indent)
  43882. {
  43883. x = indent;
  43884. y += height;
  43885. }
  43886. tc->setBounds (x, y, preferredSize, height);
  43887. x += preferredSize + 8;
  43888. maxX = jmax (maxX, x);
  43889. }
  43890. }
  43891. }
  43892. itemHolder->setSize (maxX, y + height + 8);
  43893. }
  43894. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  43895. {
  43896. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  43897. jassert (tc != 0);
  43898. if (tc != 0)
  43899. {
  43900. tc->setBounds (comp->getBounds());
  43901. tc->setStyle (toolbar->getStyle());
  43902. tc->setEditingMode (comp->getEditingMode());
  43903. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  43904. }
  43905. }
  43906. END_JUCE_NAMESPACE
  43907. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  43908. /*** Start of inlined file: juce_TreeView.cpp ***/
  43909. BEGIN_JUCE_NAMESPACE
  43910. class TreeViewContentComponent : public Component,
  43911. public TooltipClient
  43912. {
  43913. public:
  43914. TreeViewContentComponent (TreeView* const owner_)
  43915. : owner (owner_),
  43916. buttonUnderMouse (0),
  43917. isDragging (false)
  43918. {
  43919. }
  43920. ~TreeViewContentComponent()
  43921. {
  43922. deleteAllChildren();
  43923. }
  43924. void mouseDown (const MouseEvent& e)
  43925. {
  43926. updateButtonUnderMouse (e);
  43927. isDragging = false;
  43928. needSelectionOnMouseUp = false;
  43929. Rectangle<int> pos;
  43930. TreeViewItem* const item = findItemAt (e.y, pos);
  43931. if (item == 0)
  43932. return;
  43933. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  43934. // as selection clicks)
  43935. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  43936. {
  43937. if (e.x >= pos.getX() - owner->getIndentSize())
  43938. item->setOpen (! item->isOpen());
  43939. // (clicks to the left of an open/close button are ignored)
  43940. }
  43941. else
  43942. {
  43943. // mouse-down inside the body of the item..
  43944. if (! owner->isMultiSelectEnabled())
  43945. item->setSelected (true, true);
  43946. else if (item->isSelected())
  43947. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  43948. else
  43949. selectBasedOnModifiers (item, e.mods);
  43950. if (e.x >= pos.getX())
  43951. item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43952. }
  43953. }
  43954. void mouseUp (const MouseEvent& e)
  43955. {
  43956. updateButtonUnderMouse (e);
  43957. if (needSelectionOnMouseUp && e.mouseWasClicked())
  43958. {
  43959. Rectangle<int> pos;
  43960. TreeViewItem* const item = findItemAt (e.y, pos);
  43961. if (item != 0)
  43962. selectBasedOnModifiers (item, e.mods);
  43963. }
  43964. }
  43965. void mouseDoubleClick (const MouseEvent& e)
  43966. {
  43967. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  43968. {
  43969. Rectangle<int> pos;
  43970. TreeViewItem* const item = findItemAt (e.y, pos);
  43971. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  43972. item->itemDoubleClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43973. }
  43974. }
  43975. void mouseDrag (const MouseEvent& e)
  43976. {
  43977. if (isEnabled()
  43978. && ! (isDragging || e.mouseWasClicked()
  43979. || e.getDistanceFromDragStart() < 5
  43980. || e.mods.isPopupMenu()))
  43981. {
  43982. isDragging = true;
  43983. Rectangle<int> pos;
  43984. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  43985. if (item != 0 && e.getMouseDownX() >= pos.getX())
  43986. {
  43987. const String dragDescription (item->getDragSourceDescription());
  43988. if (dragDescription.isNotEmpty())
  43989. {
  43990. DragAndDropContainer* const dragContainer
  43991. = DragAndDropContainer::findParentDragContainerFor (this);
  43992. if (dragContainer != 0)
  43993. {
  43994. pos.setSize (pos.getWidth(), item->itemHeight);
  43995. Image* dragImage = Component::createComponentSnapshot (pos, true);
  43996. dragImage->multiplyAllAlphas (0.6f);
  43997. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  43998. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  43999. }
  44000. else
  44001. {
  44002. // to be able to do a drag-and-drop operation, the treeview needs to
  44003. // be inside a component which is also a DragAndDropContainer.
  44004. jassertfalse
  44005. }
  44006. }
  44007. }
  44008. }
  44009. }
  44010. void mouseMove (const MouseEvent& e)
  44011. {
  44012. updateButtonUnderMouse (e);
  44013. }
  44014. void mouseExit (const MouseEvent& e)
  44015. {
  44016. updateButtonUnderMouse (e);
  44017. }
  44018. void paint (Graphics& g);
  44019. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  44020. static bool isMouseDraggingInChildCompOf (Component* const comp)
  44021. {
  44022. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  44023. {
  44024. MouseInputSource* source = Desktop::getInstance().getMouseSource(i);
  44025. if (source->isDragging())
  44026. {
  44027. Component* const underMouse = source->getComponentUnderMouse();
  44028. if (underMouse != 0 && (comp == underMouse || comp->isParentOf (underMouse)))
  44029. return true;
  44030. }
  44031. }
  44032. return false;
  44033. }
  44034. void updateComponents()
  44035. {
  44036. const int visibleTop = -getY();
  44037. const int visibleBottom = visibleTop + getParentHeight();
  44038. BigInteger itemsToKeep;
  44039. TreeViewItem* item = owner->rootItem;
  44040. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44041. while (item != 0 && y < visibleBottom)
  44042. {
  44043. y += item->itemHeight;
  44044. if (y >= visibleTop)
  44045. {
  44046. const int index = rowComponentIds.indexOf (item->uid);
  44047. if (index < 0)
  44048. {
  44049. Component* const comp = item->createItemComponent();
  44050. if (comp != 0)
  44051. {
  44052. addAndMakeVisible (comp);
  44053. itemsToKeep.setBit (rowComponentItems.size());
  44054. rowComponentItems.add (item);
  44055. rowComponentIds.add (item->uid);
  44056. rowComponents.add (comp);
  44057. }
  44058. }
  44059. else
  44060. {
  44061. itemsToKeep.setBit (index);
  44062. }
  44063. }
  44064. item = item->getNextVisibleItem (true);
  44065. }
  44066. for (int i = rowComponentItems.size(); --i >= 0;)
  44067. {
  44068. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44069. bool keep = false;
  44070. if (isParentOf (comp))
  44071. {
  44072. if (itemsToKeep[i])
  44073. {
  44074. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44075. Rectangle<int> pos (item->getItemPosition (false));
  44076. pos.setSize (pos.getWidth(), item->itemHeight);
  44077. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44078. {
  44079. keep = true;
  44080. comp->setBounds (pos);
  44081. }
  44082. }
  44083. if ((! keep) && isMouseDraggingInChildCompOf (comp))
  44084. {
  44085. keep = true;
  44086. comp->setSize (0, 0);
  44087. }
  44088. }
  44089. if (! keep)
  44090. {
  44091. delete comp;
  44092. rowComponents.remove (i);
  44093. rowComponentIds.remove (i);
  44094. rowComponentItems.remove (i);
  44095. }
  44096. }
  44097. }
  44098. void updateButtonUnderMouse (const MouseEvent& e)
  44099. {
  44100. TreeViewItem* newItem = 0;
  44101. if (owner->openCloseButtonsVisible)
  44102. {
  44103. Rectangle<int> pos;
  44104. TreeViewItem* item = findItemAt (e.y, pos);
  44105. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44106. {
  44107. newItem = item;
  44108. if (! newItem->mightContainSubItems())
  44109. newItem = 0;
  44110. }
  44111. }
  44112. if (buttonUnderMouse != newItem)
  44113. {
  44114. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44115. {
  44116. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44117. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44118. }
  44119. buttonUnderMouse = newItem;
  44120. if (buttonUnderMouse != 0)
  44121. {
  44122. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44123. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44124. }
  44125. }
  44126. }
  44127. bool isMouseOverButton (TreeViewItem* item) const throw()
  44128. {
  44129. return item == buttonUnderMouse;
  44130. }
  44131. void resized()
  44132. {
  44133. owner->itemsChanged();
  44134. }
  44135. const String getTooltip()
  44136. {
  44137. Rectangle<int> pos;
  44138. TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos);
  44139. if (item != 0)
  44140. return item->getTooltip();
  44141. return owner->getTooltip();
  44142. }
  44143. juce_UseDebuggingNewOperator
  44144. private:
  44145. TreeView* const owner;
  44146. VoidArray rowComponentItems;
  44147. Array <int> rowComponentIds;
  44148. VoidArray rowComponents;
  44149. TreeViewItem* buttonUnderMouse;
  44150. bool isDragging, needSelectionOnMouseUp;
  44151. TreeViewContentComponent (const TreeViewContentComponent&);
  44152. TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44153. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44154. {
  44155. TreeViewItem* firstSelected = 0;
  44156. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44157. {
  44158. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44159. jassert (lastSelected != 0);
  44160. int rowStart = firstSelected->getRowNumberInTree();
  44161. int rowEnd = lastSelected->getRowNumberInTree();
  44162. if (rowStart > rowEnd)
  44163. swapVariables (rowStart, rowEnd);
  44164. int ourRow = item->getRowNumberInTree();
  44165. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44166. if (ourRow > otherEnd)
  44167. swapVariables (ourRow, otherEnd);
  44168. for (int i = ourRow; i <= otherEnd; ++i)
  44169. owner->getItemOnRow (i)->setSelected (true, false);
  44170. }
  44171. else
  44172. {
  44173. const bool cmd = modifiers.isCommandDown();
  44174. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44175. }
  44176. }
  44177. bool containsItem (TreeViewItem* const item) const
  44178. {
  44179. for (int i = rowComponentItems.size(); --i >= 0;)
  44180. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44181. return true;
  44182. return false;
  44183. }
  44184. };
  44185. class TreeViewport : public Viewport
  44186. {
  44187. public:
  44188. TreeViewport() throw() {}
  44189. ~TreeViewport() throw() {}
  44190. void updateComponents()
  44191. {
  44192. if (getViewedComponent() != 0)
  44193. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44194. repaint();
  44195. }
  44196. void visibleAreaChanged (int, int, int, int)
  44197. {
  44198. updateComponents();
  44199. }
  44200. juce_UseDebuggingNewOperator
  44201. private:
  44202. TreeViewport (const TreeViewport&);
  44203. TreeViewport& operator= (const TreeViewport&);
  44204. };
  44205. TreeView::TreeView (const String& componentName)
  44206. : Component (componentName),
  44207. rootItem (0),
  44208. dragInsertPointHighlight (0),
  44209. dragTargetGroupHighlight (0),
  44210. indentSize (24),
  44211. defaultOpenness (false),
  44212. needsRecalculating (true),
  44213. rootItemVisible (true),
  44214. multiSelectEnabled (false),
  44215. openCloseButtonsVisible (true)
  44216. {
  44217. addAndMakeVisible (viewport = new TreeViewport());
  44218. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44219. viewport->setWantsKeyboardFocus (false);
  44220. setWantsKeyboardFocus (true);
  44221. }
  44222. TreeView::~TreeView()
  44223. {
  44224. if (rootItem != 0)
  44225. rootItem->setOwnerView (0);
  44226. deleteAllChildren();
  44227. }
  44228. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44229. {
  44230. if (rootItem != newRootItem)
  44231. {
  44232. if (newRootItem != 0)
  44233. {
  44234. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44235. if (newRootItem->ownerView != 0)
  44236. newRootItem->ownerView->setRootItem (0);
  44237. }
  44238. if (rootItem != 0)
  44239. rootItem->setOwnerView (0);
  44240. rootItem = newRootItem;
  44241. if (newRootItem != 0)
  44242. newRootItem->setOwnerView (this);
  44243. needsRecalculating = true;
  44244. handleAsyncUpdate();
  44245. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44246. {
  44247. rootItem->setOpen (false); // force a re-open
  44248. rootItem->setOpen (true);
  44249. }
  44250. }
  44251. }
  44252. void TreeView::deleteRootItem()
  44253. {
  44254. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44255. setRootItem (0);
  44256. }
  44257. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44258. {
  44259. rootItemVisible = shouldBeVisible;
  44260. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44261. {
  44262. rootItem->setOpen (false); // force a re-open
  44263. rootItem->setOpen (true);
  44264. }
  44265. itemsChanged();
  44266. }
  44267. void TreeView::colourChanged()
  44268. {
  44269. setOpaque (findColour (backgroundColourId).isOpaque());
  44270. repaint();
  44271. }
  44272. void TreeView::setIndentSize (const int newIndentSize)
  44273. {
  44274. if (indentSize != newIndentSize)
  44275. {
  44276. indentSize = newIndentSize;
  44277. resized();
  44278. }
  44279. }
  44280. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44281. {
  44282. if (defaultOpenness != isOpenByDefault)
  44283. {
  44284. defaultOpenness = isOpenByDefault;
  44285. itemsChanged();
  44286. }
  44287. }
  44288. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44289. {
  44290. multiSelectEnabled = canMultiSelect;
  44291. }
  44292. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44293. {
  44294. if (openCloseButtonsVisible != shouldBeVisible)
  44295. {
  44296. openCloseButtonsVisible = shouldBeVisible;
  44297. itemsChanged();
  44298. }
  44299. }
  44300. void TreeView::clearSelectedItems()
  44301. {
  44302. if (rootItem != 0)
  44303. rootItem->deselectAllRecursively();
  44304. }
  44305. int TreeView::getNumSelectedItems() const throw()
  44306. {
  44307. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44308. }
  44309. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44310. {
  44311. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44312. }
  44313. int TreeView::getNumRowsInTree() const
  44314. {
  44315. if (rootItem != 0)
  44316. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44317. return 0;
  44318. }
  44319. TreeViewItem* TreeView::getItemOnRow (int index) const
  44320. {
  44321. if (! rootItemVisible)
  44322. ++index;
  44323. if (rootItem != 0 && index >= 0)
  44324. return rootItem->getItemOnRow (index);
  44325. return 0;
  44326. }
  44327. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44328. {
  44329. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44330. Rectangle<int> pos;
  44331. return tc->findItemAt (relativePositionToOtherComponent (tc, Point<int> (0, y)).getY(), pos);
  44332. }
  44333. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44334. {
  44335. if (rootItem == 0)
  44336. return 0;
  44337. return rootItem->findItemFromIdentifierString (identifierString);
  44338. }
  44339. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44340. {
  44341. XmlElement* e = 0;
  44342. if (rootItem != 0)
  44343. {
  44344. e = rootItem->getOpennessState();
  44345. if (e != 0 && alsoIncludeScrollPosition)
  44346. e->setAttribute (T("scrollPos"), viewport->getViewPositionY());
  44347. }
  44348. return e;
  44349. }
  44350. void TreeView::restoreOpennessState (const XmlElement& newState)
  44351. {
  44352. if (rootItem != 0)
  44353. {
  44354. rootItem->restoreOpennessState (newState);
  44355. if (newState.hasAttribute (T("scrollPos")))
  44356. viewport->setViewPosition (viewport->getViewPositionX(),
  44357. newState.getIntAttribute (T("scrollPos")));
  44358. }
  44359. }
  44360. void TreeView::paint (Graphics& g)
  44361. {
  44362. g.fillAll (findColour (backgroundColourId));
  44363. }
  44364. void TreeView::resized()
  44365. {
  44366. viewport->setBounds (0, 0, getWidth(), getHeight());
  44367. itemsChanged();
  44368. handleAsyncUpdate();
  44369. }
  44370. void TreeView::enablementChanged()
  44371. {
  44372. repaint();
  44373. }
  44374. void TreeView::moveSelectedRow (int delta)
  44375. {
  44376. if (delta == 0)
  44377. return;
  44378. int rowSelected = 0;
  44379. TreeViewItem* const firstSelected = getSelectedItem (0);
  44380. if (firstSelected != 0)
  44381. rowSelected = firstSelected->getRowNumberInTree();
  44382. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44383. for (;;)
  44384. {
  44385. TreeViewItem* item = getItemOnRow (rowSelected);
  44386. if (item != 0)
  44387. {
  44388. if (! item->canBeSelected())
  44389. {
  44390. // if the row we want to highlight doesn't allow it, try skipping
  44391. // to the next item..
  44392. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44393. rowSelected + (delta < 0 ? -1 : 1));
  44394. if (rowSelected != nextRowToTry)
  44395. {
  44396. rowSelected = nextRowToTry;
  44397. continue;
  44398. }
  44399. else
  44400. {
  44401. break;
  44402. }
  44403. }
  44404. item->setSelected (true, true);
  44405. scrollToKeepItemVisible (item);
  44406. }
  44407. break;
  44408. }
  44409. }
  44410. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44411. {
  44412. if (item != 0 && item->ownerView == this)
  44413. {
  44414. handleAsyncUpdate();
  44415. item = item->getDeepestOpenParentItem();
  44416. int y = item->y;
  44417. int viewTop = viewport->getViewPositionY();
  44418. if (y < viewTop)
  44419. {
  44420. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44421. }
  44422. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44423. {
  44424. viewport->setViewPosition (viewport->getViewPositionX(),
  44425. (y + item->itemHeight) - viewport->getViewHeight());
  44426. }
  44427. }
  44428. }
  44429. bool TreeView::keyPressed (const KeyPress& key)
  44430. {
  44431. if (key.isKeyCode (KeyPress::upKey))
  44432. {
  44433. moveSelectedRow (-1);
  44434. }
  44435. else if (key.isKeyCode (KeyPress::downKey))
  44436. {
  44437. moveSelectedRow (1);
  44438. }
  44439. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  44440. {
  44441. if (rootItem != 0)
  44442. {
  44443. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  44444. if (key.isKeyCode (KeyPress::pageUpKey))
  44445. rowsOnScreen = -rowsOnScreen;
  44446. moveSelectedRow (rowsOnScreen);
  44447. }
  44448. }
  44449. else if (key.isKeyCode (KeyPress::homeKey))
  44450. {
  44451. moveSelectedRow (-0x3fffffff);
  44452. }
  44453. else if (key.isKeyCode (KeyPress::endKey))
  44454. {
  44455. moveSelectedRow (0x3fffffff);
  44456. }
  44457. else if (key.isKeyCode (KeyPress::returnKey))
  44458. {
  44459. TreeViewItem* const firstSelected = getSelectedItem (0);
  44460. if (firstSelected != 0)
  44461. firstSelected->setOpen (! firstSelected->isOpen());
  44462. }
  44463. else if (key.isKeyCode (KeyPress::leftKey))
  44464. {
  44465. TreeViewItem* const firstSelected = getSelectedItem (0);
  44466. if (firstSelected != 0)
  44467. {
  44468. if (firstSelected->isOpen())
  44469. {
  44470. firstSelected->setOpen (false);
  44471. }
  44472. else
  44473. {
  44474. TreeViewItem* parent = firstSelected->parentItem;
  44475. if ((! rootItemVisible) && parent == rootItem)
  44476. parent = 0;
  44477. if (parent != 0)
  44478. {
  44479. parent->setSelected (true, true);
  44480. scrollToKeepItemVisible (parent);
  44481. }
  44482. }
  44483. }
  44484. }
  44485. else if (key.isKeyCode (KeyPress::rightKey))
  44486. {
  44487. TreeViewItem* const firstSelected = getSelectedItem (0);
  44488. if (firstSelected != 0)
  44489. {
  44490. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  44491. moveSelectedRow (1);
  44492. else
  44493. firstSelected->setOpen (true);
  44494. }
  44495. }
  44496. else
  44497. {
  44498. return false;
  44499. }
  44500. return true;
  44501. }
  44502. void TreeView::itemsChanged() throw()
  44503. {
  44504. needsRecalculating = true;
  44505. repaint();
  44506. triggerAsyncUpdate();
  44507. }
  44508. void TreeView::handleAsyncUpdate()
  44509. {
  44510. if (needsRecalculating)
  44511. {
  44512. needsRecalculating = false;
  44513. const ScopedLock sl (nodeAlterationLock);
  44514. if (rootItem != 0)
  44515. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  44516. ((TreeViewport*) viewport)->updateComponents();
  44517. if (rootItem != 0)
  44518. {
  44519. viewport->getViewedComponent()
  44520. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  44521. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  44522. }
  44523. else
  44524. {
  44525. viewport->getViewedComponent()->setSize (0, 0);
  44526. }
  44527. }
  44528. }
  44529. class TreeViewDragInsertPointHighlight : public Component
  44530. {
  44531. public:
  44532. TreeViewDragInsertPointHighlight()
  44533. : lastItem (0)
  44534. {
  44535. setSize (100, 12);
  44536. setAlwaysOnTop (true);
  44537. setInterceptsMouseClicks (false, false);
  44538. }
  44539. ~TreeViewDragInsertPointHighlight() {}
  44540. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  44541. {
  44542. lastItem = item;
  44543. lastIndex = insertIndex;
  44544. const int offset = getHeight() / 2;
  44545. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  44546. }
  44547. void paint (Graphics& g)
  44548. {
  44549. Path p;
  44550. const float h = (float) getHeight();
  44551. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  44552. p.startNewSubPath (h - 2.0f, h / 2.0f);
  44553. p.lineTo ((float) getWidth(), h / 2.0f);
  44554. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44555. g.strokePath (p, PathStrokeType (2.0f));
  44556. }
  44557. TreeViewItem* lastItem;
  44558. int lastIndex;
  44559. };
  44560. class TreeViewDragTargetGroupHighlight : public Component
  44561. {
  44562. public:
  44563. TreeViewDragTargetGroupHighlight()
  44564. {
  44565. setAlwaysOnTop (true);
  44566. setInterceptsMouseClicks (false, false);
  44567. }
  44568. ~TreeViewDragTargetGroupHighlight() {}
  44569. void setTargetPosition (TreeViewItem* const item) throw()
  44570. {
  44571. Rectangle<int> r (item->getItemPosition (true));
  44572. r.setHeight (item->getItemHeight());
  44573. setBounds (r);
  44574. }
  44575. void paint (Graphics& g)
  44576. {
  44577. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44578. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  44579. }
  44580. };
  44581. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  44582. {
  44583. beginDragAutoRepeat (1000 / 30);
  44584. if (dragInsertPointHighlight == 0)
  44585. {
  44586. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  44587. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  44588. }
  44589. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  44590. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  44591. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  44592. ->setTargetPosition (item);
  44593. }
  44594. void TreeView::hideDragHighlight() throw()
  44595. {
  44596. deleteAndZero (dragInsertPointHighlight);
  44597. deleteAndZero (dragTargetGroupHighlight);
  44598. }
  44599. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  44600. const StringArray& files, const String& sourceDescription,
  44601. Component* sourceComponent) const throw()
  44602. {
  44603. insertIndex = 0;
  44604. TreeViewItem* item = getItemAt (y);
  44605. if (item == 0)
  44606. return 0;
  44607. Rectangle<int> itemPos (item->getItemPosition (true));
  44608. insertIndex = item->getIndexInParent();
  44609. const int oldY = y;
  44610. y = itemPos.getY();
  44611. if (item->getNumSubItems() == 0 || ! item->isOpen())
  44612. {
  44613. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44614. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44615. {
  44616. // Check if we're trying to drag into an empty group item..
  44617. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  44618. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  44619. {
  44620. insertIndex = 0;
  44621. x = itemPos.getX() + getIndentSize();
  44622. y = itemPos.getBottom();
  44623. return item;
  44624. }
  44625. }
  44626. }
  44627. if (oldY > itemPos.getCentreY())
  44628. {
  44629. y += item->getItemHeight();
  44630. while (item->isLastOfSiblings() && item->parentItem != 0
  44631. && item->parentItem->parentItem != 0)
  44632. {
  44633. if (x > itemPos.getX())
  44634. break;
  44635. item = item->parentItem;
  44636. itemPos = item->getItemPosition (true);
  44637. insertIndex = item->getIndexInParent();
  44638. }
  44639. ++insertIndex;
  44640. }
  44641. x = itemPos.getX();
  44642. return item->parentItem;
  44643. }
  44644. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44645. {
  44646. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  44647. int insertIndex;
  44648. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44649. if (item != 0)
  44650. {
  44651. if (scrolled || dragInsertPointHighlight == 0
  44652. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  44653. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  44654. {
  44655. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44656. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44657. showDragHighlight (item, insertIndex, x, y);
  44658. else
  44659. hideDragHighlight();
  44660. }
  44661. }
  44662. else
  44663. {
  44664. hideDragHighlight();
  44665. }
  44666. }
  44667. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44668. {
  44669. hideDragHighlight();
  44670. int insertIndex;
  44671. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44672. if (item != 0)
  44673. {
  44674. if (files.size() > 0)
  44675. {
  44676. if (item->isInterestedInFileDrag (files))
  44677. item->filesDropped (files, insertIndex);
  44678. }
  44679. else
  44680. {
  44681. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44682. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  44683. }
  44684. }
  44685. }
  44686. bool TreeView::isInterestedInFileDrag (const StringArray&)
  44687. {
  44688. return true;
  44689. }
  44690. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  44691. {
  44692. fileDragMove (files, x, y);
  44693. }
  44694. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  44695. {
  44696. handleDrag (files, String::empty, 0, x, y);
  44697. }
  44698. void TreeView::fileDragExit (const StringArray&)
  44699. {
  44700. hideDragHighlight();
  44701. }
  44702. void TreeView::filesDropped (const StringArray& files, int x, int y)
  44703. {
  44704. handleDrop (files, String::empty, 0, x, y);
  44705. }
  44706. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44707. {
  44708. return true;
  44709. }
  44710. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44711. {
  44712. itemDragMove (sourceDescription, sourceComponent, x, y);
  44713. }
  44714. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44715. {
  44716. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  44717. }
  44718. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44719. {
  44720. hideDragHighlight();
  44721. }
  44722. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44723. {
  44724. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  44725. }
  44726. void TreeViewContentComponent::paint (Graphics& g)
  44727. {
  44728. if (owner->rootItem != 0)
  44729. {
  44730. owner->handleAsyncUpdate();
  44731. if (! owner->rootItemVisible)
  44732. g.setOrigin (0, -owner->rootItem->itemHeight);
  44733. owner->rootItem->paintRecursively (g, getWidth());
  44734. }
  44735. }
  44736. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  44737. {
  44738. if (owner->rootItem != 0)
  44739. {
  44740. owner->handleAsyncUpdate();
  44741. if (! owner->rootItemVisible)
  44742. y += owner->rootItem->itemHeight;
  44743. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  44744. if (ti != 0)
  44745. itemPosition = ti->getItemPosition (false);
  44746. return ti;
  44747. }
  44748. return 0;
  44749. }
  44750. enum TreeViewOpenness
  44751. {
  44752. opennessDefault = 0,
  44753. opennessClosed = 1,
  44754. opennessOpen = 2
  44755. };
  44756. TreeViewItem::TreeViewItem()
  44757. : ownerView (0),
  44758. parentItem (0),
  44759. y (0),
  44760. itemHeight (0),
  44761. totalHeight (0),
  44762. selected (false),
  44763. redrawNeeded (true),
  44764. drawLinesInside (true),
  44765. drawsInLeftMargin (false),
  44766. openness (opennessDefault)
  44767. {
  44768. static int nextUID = 0;
  44769. uid = nextUID++;
  44770. }
  44771. TreeViewItem::~TreeViewItem()
  44772. {
  44773. }
  44774. const String TreeViewItem::getUniqueName() const
  44775. {
  44776. return String::empty;
  44777. }
  44778. void TreeViewItem::itemOpennessChanged (bool)
  44779. {
  44780. }
  44781. int TreeViewItem::getNumSubItems() const throw()
  44782. {
  44783. return subItems.size();
  44784. }
  44785. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  44786. {
  44787. return subItems [index];
  44788. }
  44789. void TreeViewItem::clearSubItems()
  44790. {
  44791. if (subItems.size() > 0)
  44792. {
  44793. if (ownerView != 0)
  44794. {
  44795. const ScopedLock sl (ownerView->nodeAlterationLock);
  44796. subItems.clear();
  44797. treeHasChanged();
  44798. }
  44799. else
  44800. {
  44801. subItems.clear();
  44802. }
  44803. }
  44804. }
  44805. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  44806. {
  44807. if (newItem != 0)
  44808. {
  44809. newItem->parentItem = this;
  44810. newItem->setOwnerView (ownerView);
  44811. newItem->y = 0;
  44812. newItem->itemHeight = newItem->getItemHeight();
  44813. newItem->totalHeight = 0;
  44814. newItem->itemWidth = newItem->getItemWidth();
  44815. newItem->totalWidth = 0;
  44816. if (ownerView != 0)
  44817. {
  44818. const ScopedLock sl (ownerView->nodeAlterationLock);
  44819. subItems.insert (insertPosition, newItem);
  44820. treeHasChanged();
  44821. if (newItem->isOpen())
  44822. newItem->itemOpennessChanged (true);
  44823. }
  44824. else
  44825. {
  44826. subItems.insert (insertPosition, newItem);
  44827. if (newItem->isOpen())
  44828. newItem->itemOpennessChanged (true);
  44829. }
  44830. }
  44831. }
  44832. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  44833. {
  44834. if (ownerView != 0)
  44835. {
  44836. const ScopedLock sl (ownerView->nodeAlterationLock);
  44837. if (((unsigned int) index) < (unsigned int) subItems.size())
  44838. {
  44839. subItems.remove (index, deleteItem);
  44840. treeHasChanged();
  44841. }
  44842. }
  44843. else
  44844. {
  44845. subItems.remove (index, deleteItem);
  44846. }
  44847. }
  44848. bool TreeViewItem::isOpen() const throw()
  44849. {
  44850. if (openness == opennessDefault)
  44851. return ownerView != 0 && ownerView->defaultOpenness;
  44852. else
  44853. return openness == opennessOpen;
  44854. }
  44855. void TreeViewItem::setOpen (const bool shouldBeOpen)
  44856. {
  44857. if (isOpen() != shouldBeOpen)
  44858. {
  44859. openness = shouldBeOpen ? opennessOpen
  44860. : opennessClosed;
  44861. treeHasChanged();
  44862. itemOpennessChanged (isOpen());
  44863. }
  44864. }
  44865. bool TreeViewItem::isSelected() const throw()
  44866. {
  44867. return selected;
  44868. }
  44869. void TreeViewItem::deselectAllRecursively()
  44870. {
  44871. setSelected (false, false);
  44872. for (int i = 0; i < subItems.size(); ++i)
  44873. subItems.getUnchecked(i)->deselectAllRecursively();
  44874. }
  44875. void TreeViewItem::setSelected (const bool shouldBeSelected,
  44876. const bool deselectOtherItemsFirst)
  44877. {
  44878. if (shouldBeSelected && ! canBeSelected())
  44879. return;
  44880. if (deselectOtherItemsFirst)
  44881. getTopLevelItem()->deselectAllRecursively();
  44882. if (shouldBeSelected != selected)
  44883. {
  44884. selected = shouldBeSelected;
  44885. if (ownerView != 0)
  44886. ownerView->repaint();
  44887. itemSelectionChanged (shouldBeSelected);
  44888. }
  44889. }
  44890. void TreeViewItem::paintItem (Graphics&, int, int)
  44891. {
  44892. }
  44893. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  44894. {
  44895. ownerView->getLookAndFeel()
  44896. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  44897. }
  44898. void TreeViewItem::itemClicked (const MouseEvent&)
  44899. {
  44900. }
  44901. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  44902. {
  44903. if (mightContainSubItems())
  44904. setOpen (! isOpen());
  44905. }
  44906. void TreeViewItem::itemSelectionChanged (bool)
  44907. {
  44908. }
  44909. const String TreeViewItem::getTooltip()
  44910. {
  44911. return String::empty;
  44912. }
  44913. const String TreeViewItem::getDragSourceDescription()
  44914. {
  44915. return String::empty;
  44916. }
  44917. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  44918. {
  44919. return false;
  44920. }
  44921. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  44922. {
  44923. }
  44924. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44925. {
  44926. return false;
  44927. }
  44928. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  44929. {
  44930. }
  44931. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  44932. {
  44933. const int indentX = getIndentX();
  44934. int width = itemWidth;
  44935. if (ownerView != 0 && width < 0)
  44936. width = ownerView->viewport->getViewWidth() - indentX;
  44937. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  44938. if (relativeToTreeViewTopLeft)
  44939. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  44940. r.getY() - ownerView->viewport->getViewPositionY());
  44941. return r;
  44942. }
  44943. void TreeViewItem::treeHasChanged() const throw()
  44944. {
  44945. if (ownerView != 0)
  44946. ownerView->itemsChanged();
  44947. }
  44948. void TreeViewItem::repaintItem() const
  44949. {
  44950. if (ownerView != 0 && areAllParentsOpen())
  44951. {
  44952. const Rectangle<int> r (getItemPosition (true));
  44953. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  44954. }
  44955. }
  44956. bool TreeViewItem::areAllParentsOpen() const throw()
  44957. {
  44958. return parentItem == 0
  44959. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  44960. }
  44961. void TreeViewItem::updatePositions (int newY)
  44962. {
  44963. y = newY;
  44964. itemHeight = getItemHeight();
  44965. totalHeight = itemHeight;
  44966. itemWidth = getItemWidth();
  44967. totalWidth = jmax (itemWidth, 0) + getIndentX();
  44968. if (isOpen())
  44969. {
  44970. newY += totalHeight;
  44971. for (int i = 0; i < subItems.size(); ++i)
  44972. {
  44973. TreeViewItem* const ti = subItems.getUnchecked(i);
  44974. ti->updatePositions (newY);
  44975. newY += ti->totalHeight;
  44976. totalHeight += ti->totalHeight;
  44977. totalWidth = jmax (totalWidth, ti->totalWidth);
  44978. }
  44979. }
  44980. }
  44981. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  44982. {
  44983. TreeViewItem* result = this;
  44984. TreeViewItem* item = this;
  44985. while (item->parentItem != 0)
  44986. {
  44987. item = item->parentItem;
  44988. if (! item->isOpen())
  44989. result = item;
  44990. }
  44991. return result;
  44992. }
  44993. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  44994. {
  44995. ownerView = newOwner;
  44996. for (int i = subItems.size(); --i >= 0;)
  44997. subItems.getUnchecked(i)->setOwnerView (newOwner);
  44998. }
  44999. int TreeViewItem::getIndentX() const throw()
  45000. {
  45001. const int indentWidth = ownerView->getIndentSize();
  45002. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45003. if (! ownerView->openCloseButtonsVisible)
  45004. x -= indentWidth;
  45005. TreeViewItem* p = parentItem;
  45006. while (p != 0)
  45007. {
  45008. x += indentWidth;
  45009. p = p->parentItem;
  45010. }
  45011. return x;
  45012. }
  45013. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45014. {
  45015. drawsInLeftMargin = canDrawInLeftMargin;
  45016. }
  45017. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45018. {
  45019. jassert (ownerView != 0);
  45020. if (ownerView == 0)
  45021. return;
  45022. const int indent = getIndentX();
  45023. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45024. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45025. const float halfH = itemHeight * 0.5f;
  45026. int depth = 0;
  45027. TreeViewItem* p = parentItem;
  45028. while (p != 0)
  45029. {
  45030. ++depth;
  45031. p = p->parentItem;
  45032. }
  45033. if (! ownerView->rootItemVisible)
  45034. --depth;
  45035. const int indentWidth = ownerView->getIndentSize();
  45036. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45037. {
  45038. float x = (depth + 0.5f) * indentWidth;
  45039. if (depth >= 0)
  45040. {
  45041. if (parentItem != 0 && parentItem->drawLinesInside)
  45042. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45043. if ((parentItem != 0 && parentItem->drawLinesInside)
  45044. || (parentItem == 0 && drawLinesInside))
  45045. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45046. }
  45047. p = parentItem;
  45048. int d = depth;
  45049. while (p != 0 && --d >= 0)
  45050. {
  45051. x -= (float) indentWidth;
  45052. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45053. && ! p->isLastOfSiblings())
  45054. {
  45055. g.drawLine (x, 0, x, (float) itemHeight);
  45056. }
  45057. p = p->parentItem;
  45058. }
  45059. if (mightContainSubItems())
  45060. {
  45061. g.saveState();
  45062. g.setOrigin (depth * indentWidth, 0);
  45063. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45064. paintOpenCloseButton (g, indentWidth, itemHeight,
  45065. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45066. ->isMouseOverButton (this));
  45067. g.restoreState();
  45068. }
  45069. }
  45070. {
  45071. g.saveState();
  45072. g.setOrigin (indent, 0);
  45073. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45074. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45075. paintItem (g, itemW, itemHeight);
  45076. g.restoreState();
  45077. }
  45078. if (isOpen())
  45079. {
  45080. const Rectangle<int> clip (g.getClipBounds());
  45081. for (int i = 0; i < subItems.size(); ++i)
  45082. {
  45083. TreeViewItem* const ti = subItems.getUnchecked(i);
  45084. const int relY = ti->y - y;
  45085. if (relY >= clip.getBottom())
  45086. break;
  45087. if (relY + ti->totalHeight >= clip.getY())
  45088. {
  45089. g.saveState();
  45090. g.setOrigin (0, relY);
  45091. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45092. ti->paintRecursively (g, width);
  45093. g.restoreState();
  45094. }
  45095. }
  45096. }
  45097. }
  45098. bool TreeViewItem::isLastOfSiblings() const throw()
  45099. {
  45100. return parentItem == 0
  45101. || parentItem->subItems.getLast() == this;
  45102. }
  45103. int TreeViewItem::getIndexInParent() const throw()
  45104. {
  45105. if (parentItem == 0)
  45106. return 0;
  45107. return parentItem->subItems.indexOf (this);
  45108. }
  45109. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45110. {
  45111. return (parentItem == 0) ? this
  45112. : parentItem->getTopLevelItem();
  45113. }
  45114. int TreeViewItem::getNumRows() const throw()
  45115. {
  45116. int num = 1;
  45117. if (isOpen())
  45118. {
  45119. for (int i = subItems.size(); --i >= 0;)
  45120. num += subItems.getUnchecked(i)->getNumRows();
  45121. }
  45122. return num;
  45123. }
  45124. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45125. {
  45126. if (index == 0)
  45127. return this;
  45128. if (index > 0 && isOpen())
  45129. {
  45130. --index;
  45131. for (int i = 0; i < subItems.size(); ++i)
  45132. {
  45133. TreeViewItem* const item = subItems.getUnchecked(i);
  45134. if (index == 0)
  45135. return item;
  45136. const int numRows = item->getNumRows();
  45137. if (numRows > index)
  45138. return item->getItemOnRow (index);
  45139. index -= numRows;
  45140. }
  45141. }
  45142. return 0;
  45143. }
  45144. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45145. {
  45146. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45147. {
  45148. const int h = itemHeight;
  45149. if (targetY < h)
  45150. return this;
  45151. if (isOpen())
  45152. {
  45153. targetY -= h;
  45154. for (int i = 0; i < subItems.size(); ++i)
  45155. {
  45156. TreeViewItem* const ti = subItems.getUnchecked(i);
  45157. if (targetY < ti->totalHeight)
  45158. return ti->findItemRecursively (targetY);
  45159. targetY -= ti->totalHeight;
  45160. }
  45161. }
  45162. }
  45163. return 0;
  45164. }
  45165. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45166. {
  45167. int total = 0;
  45168. if (isSelected())
  45169. ++total;
  45170. for (int i = subItems.size(); --i >= 0;)
  45171. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45172. return total;
  45173. }
  45174. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45175. {
  45176. if (isSelected())
  45177. {
  45178. if (index == 0)
  45179. return this;
  45180. --index;
  45181. }
  45182. if (index >= 0)
  45183. {
  45184. for (int i = 0; i < subItems.size(); ++i)
  45185. {
  45186. TreeViewItem* const item = subItems.getUnchecked(i);
  45187. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45188. if (found != 0)
  45189. return found;
  45190. index -= item->countSelectedItemsRecursively();
  45191. }
  45192. }
  45193. return 0;
  45194. }
  45195. int TreeViewItem::getRowNumberInTree() const throw()
  45196. {
  45197. if (parentItem != 0 && ownerView != 0)
  45198. {
  45199. int n = 1 + parentItem->getRowNumberInTree();
  45200. int ourIndex = parentItem->subItems.indexOf (this);
  45201. jassert (ourIndex >= 0);
  45202. while (--ourIndex >= 0)
  45203. n += parentItem->subItems [ourIndex]->getNumRows();
  45204. if (parentItem->parentItem == 0
  45205. && ! ownerView->rootItemVisible)
  45206. --n;
  45207. return n;
  45208. }
  45209. else
  45210. {
  45211. return 0;
  45212. }
  45213. }
  45214. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45215. {
  45216. drawLinesInside = drawLines;
  45217. }
  45218. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45219. {
  45220. if (recurse && isOpen() && subItems.size() > 0)
  45221. return subItems [0];
  45222. if (parentItem != 0)
  45223. {
  45224. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45225. if (nextIndex >= parentItem->subItems.size())
  45226. return parentItem->getNextVisibleItem (false);
  45227. return parentItem->subItems [nextIndex];
  45228. }
  45229. return 0;
  45230. }
  45231. const String TreeViewItem::getItemIdentifierString() const
  45232. {
  45233. String s;
  45234. if (parentItem != 0)
  45235. s = parentItem->getItemIdentifierString();
  45236. return s + T("/") + getUniqueName().replaceCharacter (T('/'), T('\\'));
  45237. }
  45238. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45239. {
  45240. const String uid (getUniqueName());
  45241. if (uid == identifierString)
  45242. return this;
  45243. if (identifierString.startsWith (uid + T("/")))
  45244. {
  45245. const String remainingPath (identifierString.substring (uid.length() + 1));
  45246. bool wasOpen = isOpen();
  45247. setOpen (true);
  45248. for (int i = subItems.size(); --i >= 0;)
  45249. {
  45250. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45251. if (item != 0)
  45252. return item;
  45253. }
  45254. setOpen (wasOpen);
  45255. }
  45256. return 0;
  45257. }
  45258. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45259. {
  45260. if (e.hasTagName (T("CLOSED")))
  45261. {
  45262. setOpen (false);
  45263. }
  45264. else if (e.hasTagName (T("OPEN")))
  45265. {
  45266. setOpen (true);
  45267. forEachXmlChildElement (e, n)
  45268. {
  45269. const String id (n->getStringAttribute (T("id")));
  45270. for (int i = 0; i < subItems.size(); ++i)
  45271. {
  45272. TreeViewItem* const ti = subItems.getUnchecked(i);
  45273. if (ti->getUniqueName() == id)
  45274. {
  45275. ti->restoreOpennessState (*n);
  45276. break;
  45277. }
  45278. }
  45279. }
  45280. }
  45281. }
  45282. XmlElement* TreeViewItem::getOpennessState() const throw()
  45283. {
  45284. const String name (getUniqueName());
  45285. if (name.isNotEmpty())
  45286. {
  45287. XmlElement* e;
  45288. if (isOpen())
  45289. {
  45290. e = new XmlElement (T("OPEN"));
  45291. for (int i = 0; i < subItems.size(); ++i)
  45292. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45293. }
  45294. else
  45295. {
  45296. e = new XmlElement (T("CLOSED"));
  45297. }
  45298. e->setAttribute (T("id"), name);
  45299. return e;
  45300. }
  45301. else
  45302. {
  45303. // trying to save the openness for an element that has no name - this won't
  45304. // work because it needs the names to identify what to open.
  45305. jassertfalse
  45306. }
  45307. return 0;
  45308. }
  45309. END_JUCE_NAMESPACE
  45310. /*** End of inlined file: juce_TreeView.cpp ***/
  45311. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45312. BEGIN_JUCE_NAMESPACE
  45313. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45314. : fileList (listToShow)
  45315. {
  45316. }
  45317. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45318. {
  45319. }
  45320. FileBrowserListener::~FileBrowserListener()
  45321. {
  45322. }
  45323. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45324. {
  45325. listeners.add (listener);
  45326. }
  45327. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45328. {
  45329. listeners.remove (listener);
  45330. }
  45331. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45332. {
  45333. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45334. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45335. }
  45336. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45337. {
  45338. if (fileList.getDirectory().exists())
  45339. {
  45340. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45341. listeners.callChecked (checker, &FileBrowserListener::fileClicked, file, e);
  45342. }
  45343. }
  45344. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45345. {
  45346. if (fileList.getDirectory().exists())
  45347. {
  45348. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45349. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, file);
  45350. }
  45351. }
  45352. END_JUCE_NAMESPACE
  45353. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45354. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45355. BEGIN_JUCE_NAMESPACE
  45356. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45357. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45358. Time* creationTime, bool* isReadOnly);
  45359. bool juce_findFileNext (void* handle, String& resultFile,
  45360. bool* isDirectory, bool* isHidden, int64* fileSize,
  45361. Time* modTime, Time* creationTime, bool* isReadOnly);
  45362. void juce_findFileClose (void* handle);
  45363. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45364. TimeSliceThread& thread_)
  45365. : fileFilter (fileFilter_),
  45366. thread (thread_),
  45367. includeDirectories (false),
  45368. includeFiles (false),
  45369. ignoreHiddenFiles (true),
  45370. fileFindHandle (0),
  45371. shouldStop (true)
  45372. {
  45373. }
  45374. DirectoryContentsList::~DirectoryContentsList()
  45375. {
  45376. clear();
  45377. }
  45378. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45379. {
  45380. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45381. }
  45382. const File& DirectoryContentsList::getDirectory() const
  45383. {
  45384. return root;
  45385. }
  45386. void DirectoryContentsList::setDirectory (const File& directory,
  45387. const bool includeDirectories_,
  45388. const bool includeFiles_)
  45389. {
  45390. if (directory != root
  45391. || includeDirectories != includeDirectories_
  45392. || includeFiles != includeFiles_)
  45393. {
  45394. clear();
  45395. root = directory;
  45396. includeDirectories = includeDirectories_;
  45397. includeFiles = includeFiles_;
  45398. refresh();
  45399. }
  45400. }
  45401. void DirectoryContentsList::clear()
  45402. {
  45403. shouldStop = true;
  45404. thread.removeTimeSliceClient (this);
  45405. if (fileFindHandle != 0)
  45406. {
  45407. juce_findFileClose (fileFindHandle);
  45408. fileFindHandle = 0;
  45409. }
  45410. if (files.size() > 0)
  45411. {
  45412. files.clear();
  45413. changed();
  45414. }
  45415. }
  45416. void DirectoryContentsList::refresh()
  45417. {
  45418. clear();
  45419. if (root.isDirectory())
  45420. {
  45421. String fileFound;
  45422. bool fileFoundIsDir, isHidden, isReadOnly;
  45423. int64 fileSize;
  45424. Time modTime, creationTime;
  45425. String path (root.getFullPathName());
  45426. if (! path.endsWithChar (File::separator))
  45427. path += File::separator;
  45428. jassert (fileFindHandle == 0);
  45429. fileFindHandle = juce_findFileStart (path, T("*"), fileFound,
  45430. &fileFoundIsDir,
  45431. &isHidden,
  45432. &fileSize,
  45433. &modTime,
  45434. &creationTime,
  45435. &isReadOnly);
  45436. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  45437. {
  45438. if (addFile (fileFound, fileFoundIsDir, isHidden,
  45439. fileSize, modTime, creationTime, isReadOnly))
  45440. {
  45441. changed();
  45442. }
  45443. }
  45444. shouldStop = false;
  45445. thread.addTimeSliceClient (this);
  45446. }
  45447. }
  45448. int DirectoryContentsList::getNumFiles() const
  45449. {
  45450. return files.size();
  45451. }
  45452. bool DirectoryContentsList::getFileInfo (const int index,
  45453. FileInfo& result) const
  45454. {
  45455. const ScopedLock sl (fileListLock);
  45456. const FileInfo* const info = files [index];
  45457. if (info != 0)
  45458. {
  45459. result = *info;
  45460. return true;
  45461. }
  45462. return false;
  45463. }
  45464. const File DirectoryContentsList::getFile (const int index) const
  45465. {
  45466. const ScopedLock sl (fileListLock);
  45467. const FileInfo* const info = files [index];
  45468. if (info != 0)
  45469. return root.getChildFile (info->filename);
  45470. return File::nonexistent;
  45471. }
  45472. bool DirectoryContentsList::isStillLoading() const
  45473. {
  45474. return fileFindHandle != 0;
  45475. }
  45476. void DirectoryContentsList::changed()
  45477. {
  45478. sendChangeMessage (this);
  45479. }
  45480. bool DirectoryContentsList::useTimeSlice()
  45481. {
  45482. const uint32 startTime = Time::getApproximateMillisecondCounter();
  45483. bool hasChanged = false;
  45484. for (int i = 100; --i >= 0;)
  45485. {
  45486. if (! checkNextFile (hasChanged))
  45487. {
  45488. if (hasChanged)
  45489. changed();
  45490. return false;
  45491. }
  45492. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  45493. break;
  45494. }
  45495. if (hasChanged)
  45496. changed();
  45497. return true;
  45498. }
  45499. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  45500. {
  45501. if (fileFindHandle != 0)
  45502. {
  45503. String fileFound;
  45504. bool fileFoundIsDir, isHidden, isReadOnly;
  45505. int64 fileSize;
  45506. Time modTime, creationTime;
  45507. if (juce_findFileNext (fileFindHandle, fileFound,
  45508. &fileFoundIsDir, &isHidden,
  45509. &fileSize,
  45510. &modTime,
  45511. &creationTime,
  45512. &isReadOnly))
  45513. {
  45514. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  45515. modTime, creationTime, isReadOnly))
  45516. {
  45517. hasChanged = true;
  45518. }
  45519. return true;
  45520. }
  45521. else
  45522. {
  45523. juce_findFileClose (fileFindHandle);
  45524. fileFindHandle = 0;
  45525. }
  45526. }
  45527. return false;
  45528. }
  45529. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  45530. const DirectoryContentsList::FileInfo* const second)
  45531. {
  45532. #if JUCE_WINDOWS
  45533. if (first->isDirectory != second->isDirectory)
  45534. return first->isDirectory ? -1 : 1;
  45535. #endif
  45536. return first->filename.compareIgnoreCase (second->filename);
  45537. }
  45538. bool DirectoryContentsList::addFile (const String& filename,
  45539. const bool isDir,
  45540. const bool isHidden,
  45541. const int64 fileSize,
  45542. const Time& modTime,
  45543. const Time& creationTime,
  45544. const bool isReadOnly)
  45545. {
  45546. if (filename == T("..")
  45547. || filename == T(".")
  45548. || (ignoreHiddenFiles && isHidden))
  45549. return false;
  45550. const File file (root.getChildFile (filename));
  45551. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  45552. && (fileFilter == 0
  45553. || ((! isDir) && fileFilter->isFileSuitable (file))
  45554. || (isDir && fileFilter->isDirectorySuitable (file))))
  45555. {
  45556. ScopedPointer <FileInfo> info (new FileInfo());
  45557. info->filename = filename;
  45558. info->fileSize = fileSize;
  45559. info->modificationTime = modTime;
  45560. info->creationTime = creationTime;
  45561. info->isDirectory = isDir;
  45562. info->isReadOnly = isReadOnly;
  45563. const ScopedLock sl (fileListLock);
  45564. for (int i = files.size(); --i >= 0;)
  45565. if (files.getUnchecked(i)->filename == info->filename)
  45566. return false;
  45567. files.addSorted (*this, info.release());
  45568. return true;
  45569. }
  45570. return false;
  45571. }
  45572. END_JUCE_NAMESPACE
  45573. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  45574. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  45575. BEGIN_JUCE_NAMESPACE
  45576. FileBrowserComponent::FileBrowserComponent (int flags_,
  45577. const File& initialFileOrDirectory,
  45578. const FileFilter* fileFilter_,
  45579. FilePreviewComponent* previewComp_)
  45580. : FileFilter (String::empty),
  45581. fileFilter (fileFilter_),
  45582. flags (flags_),
  45583. previewComp (previewComp_),
  45584. thread ("Juce FileBrowser")
  45585. {
  45586. // You need to specify one or other of the open/save flags..
  45587. jassert ((flags & (saveMode | openMode)) != 0);
  45588. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  45589. // You need to specify at least one of these flags..
  45590. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  45591. String filename;
  45592. if (initialFileOrDirectory == File::nonexistent)
  45593. {
  45594. currentRoot = File::getCurrentWorkingDirectory();
  45595. }
  45596. else if (initialFileOrDirectory.isDirectory())
  45597. {
  45598. currentRoot = initialFileOrDirectory;
  45599. }
  45600. else
  45601. {
  45602. chosenFiles.add (initialFileOrDirectory);
  45603. currentRoot = initialFileOrDirectory.getParentDirectory();
  45604. filename = initialFileOrDirectory.getFileName();
  45605. }
  45606. fileList = new DirectoryContentsList (this, thread);
  45607. if ((flags & useTreeView) != 0)
  45608. {
  45609. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  45610. if ((flags & canSelectMultipleItems) != 0)
  45611. tree->setMultiSelectEnabled (true);
  45612. addAndMakeVisible (tree);
  45613. fileListComponent = tree;
  45614. }
  45615. else
  45616. {
  45617. FileListComponent* const list = new FileListComponent (*fileList);
  45618. list->setOutlineThickness (1);
  45619. if ((flags & canSelectMultipleItems) != 0)
  45620. list->setMultipleSelectionEnabled (true);
  45621. addAndMakeVisible (list);
  45622. fileListComponent = list;
  45623. }
  45624. fileListComponent->addListener (this);
  45625. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  45626. currentPathBox->setEditableText (true);
  45627. StringArray rootNames, rootPaths;
  45628. const BigInteger separators (getRoots (rootNames, rootPaths));
  45629. for (int i = 0; i < rootNames.size(); ++i)
  45630. {
  45631. if (separators [i])
  45632. currentPathBox->addSeparator();
  45633. currentPathBox->addItem (rootNames[i], i + 1);
  45634. }
  45635. currentPathBox->addSeparator();
  45636. currentPathBox->addListener (this);
  45637. addAndMakeVisible (filenameBox = new TextEditor());
  45638. filenameBox->setMultiLine (false);
  45639. filenameBox->setSelectAllWhenFocused (true);
  45640. filenameBox->setText (filename, false);
  45641. filenameBox->addListener (this);
  45642. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  45643. Label* label = new Label ("f", TRANS("file:"));
  45644. addAndMakeVisible (label);
  45645. label->attachToComponent (filenameBox, true);
  45646. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  45647. goUpButton->addButtonListener (this);
  45648. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  45649. if (previewComp != 0)
  45650. addAndMakeVisible (previewComp);
  45651. setRoot (currentRoot);
  45652. thread.startThread (4);
  45653. }
  45654. FileBrowserComponent::~FileBrowserComponent()
  45655. {
  45656. if (previewComp != 0)
  45657. removeChildComponent (previewComp);
  45658. deleteAllChildren();
  45659. fileList = 0;
  45660. thread.stopThread (10000);
  45661. }
  45662. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  45663. {
  45664. listeners.add (newListener);
  45665. }
  45666. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  45667. {
  45668. listeners.remove (listener);
  45669. }
  45670. bool FileBrowserComponent::isSaveMode() const throw()
  45671. {
  45672. return (flags & saveMode) != 0;
  45673. }
  45674. int FileBrowserComponent::getNumSelectedFiles() const throw()
  45675. {
  45676. if (chosenFiles.size() == 0 && currentFileIsValid())
  45677. return 1;
  45678. return chosenFiles.size();
  45679. }
  45680. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  45681. {
  45682. if (! filenameBox->isReadOnly())
  45683. return currentRoot.getChildFile (filenameBox->getText());
  45684. else
  45685. return chosenFiles[index];
  45686. }
  45687. bool FileBrowserComponent::currentFileIsValid() const
  45688. {
  45689. if (isSaveMode())
  45690. return ! getSelectedFile (0).isDirectory();
  45691. else
  45692. return getSelectedFile (0).exists();
  45693. }
  45694. const File FileBrowserComponent::getHighlightedFile() const throw()
  45695. {
  45696. return fileListComponent->getSelectedFile (0);
  45697. }
  45698. bool FileBrowserComponent::isFileSuitable (const File& file) const
  45699. {
  45700. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  45701. : false;
  45702. }
  45703. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  45704. {
  45705. return true;
  45706. }
  45707. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  45708. {
  45709. if (f.isDirectory())
  45710. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  45711. return (flags & canSelectFiles) != 0 && f.exists()
  45712. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  45713. }
  45714. const File FileBrowserComponent::getRoot() const
  45715. {
  45716. return currentRoot;
  45717. }
  45718. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  45719. {
  45720. if (currentRoot != newRootDirectory)
  45721. {
  45722. fileListComponent->scrollToTop();
  45723. String path (newRootDirectory.getFullPathName());
  45724. if (path.isEmpty())
  45725. path += File::separator;
  45726. StringArray rootNames, rootPaths;
  45727. getRoots (rootNames, rootPaths);
  45728. if (! rootPaths.contains (path, true))
  45729. {
  45730. bool alreadyListed = false;
  45731. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  45732. {
  45733. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  45734. {
  45735. alreadyListed = true;
  45736. break;
  45737. }
  45738. }
  45739. if (! alreadyListed)
  45740. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  45741. }
  45742. }
  45743. currentRoot = newRootDirectory;
  45744. fileList->setDirectory (currentRoot, true, true);
  45745. String currentRootName (currentRoot.getFullPathName());
  45746. if (currentRootName.isEmpty())
  45747. currentRootName += File::separator;
  45748. currentPathBox->setText (currentRootName, true);
  45749. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  45750. && currentRoot.getParentDirectory() != currentRoot);
  45751. }
  45752. void FileBrowserComponent::goUp()
  45753. {
  45754. setRoot (getRoot().getParentDirectory());
  45755. }
  45756. void FileBrowserComponent::refresh()
  45757. {
  45758. fileList->refresh();
  45759. }
  45760. const String FileBrowserComponent::getActionVerb() const
  45761. {
  45762. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  45763. }
  45764. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  45765. {
  45766. return previewComp;
  45767. }
  45768. void FileBrowserComponent::resized()
  45769. {
  45770. getLookAndFeel()
  45771. .layoutFileBrowserComponent (*this, fileListComponent,
  45772. previewComp, currentPathBox,
  45773. filenameBox, goUpButton);
  45774. }
  45775. void FileBrowserComponent::sendListenerChangeMessage()
  45776. {
  45777. Component::BailOutChecker checker (this);
  45778. if (previewComp != 0)
  45779. previewComp->selectedFileChanged (getSelectedFile (0));
  45780. // You shouldn't delete the browser when the file gets changed!
  45781. jassert (! checker.shouldBailOut());
  45782. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45783. }
  45784. void FileBrowserComponent::selectionChanged()
  45785. {
  45786. StringArray newFilenames;
  45787. bool resetChosenFiles = true;
  45788. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  45789. {
  45790. const File f (fileListComponent->getSelectedFile (i));
  45791. if (isFileOrDirSuitable (f))
  45792. {
  45793. if (resetChosenFiles)
  45794. {
  45795. chosenFiles.clear();
  45796. resetChosenFiles = false;
  45797. }
  45798. chosenFiles.add (f);
  45799. newFilenames.add (f.getRelativePathFrom (getRoot()));
  45800. }
  45801. }
  45802. if (newFilenames.size() > 0)
  45803. filenameBox->setText (newFilenames.joinIntoString (T(", ")), false);
  45804. sendListenerChangeMessage();
  45805. }
  45806. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  45807. {
  45808. Component::BailOutChecker checker (this);
  45809. listeners.callChecked (checker, &FileBrowserListener::fileClicked, f, e);
  45810. }
  45811. void FileBrowserComponent::fileDoubleClicked (const File& f)
  45812. {
  45813. if (f.isDirectory())
  45814. {
  45815. setRoot (f);
  45816. }
  45817. else
  45818. {
  45819. Component::BailOutChecker checker (this);
  45820. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, f);
  45821. }
  45822. }
  45823. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  45824. {
  45825. #if JUCE_LINUX || JUCE_WINDOWS
  45826. if (key.getModifiers().isCommandDown()
  45827. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  45828. {
  45829. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  45830. fileList->refresh();
  45831. return true;
  45832. }
  45833. #endif
  45834. return false;
  45835. }
  45836. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  45837. {
  45838. sendListenerChangeMessage();
  45839. }
  45840. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  45841. {
  45842. if (filenameBox->getText().containsChar (File::separator))
  45843. {
  45844. const File f (currentRoot.getChildFile (filenameBox->getText()));
  45845. if (f.isDirectory())
  45846. {
  45847. setRoot (f);
  45848. chosenFiles.clear();
  45849. filenameBox->setText (String::empty);
  45850. }
  45851. else
  45852. {
  45853. setRoot (f.getParentDirectory());
  45854. chosenFiles.clear();
  45855. chosenFiles.add (f);
  45856. filenameBox->setText (f.getFileName());
  45857. }
  45858. }
  45859. else
  45860. {
  45861. fileDoubleClicked (getSelectedFile (0));
  45862. }
  45863. }
  45864. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  45865. {
  45866. }
  45867. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  45868. {
  45869. if (! isSaveMode())
  45870. selectionChanged();
  45871. }
  45872. void FileBrowserComponent::buttonClicked (Button*)
  45873. {
  45874. goUp();
  45875. }
  45876. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  45877. {
  45878. const String newText (currentPathBox->getText().trim().unquoted());
  45879. if (newText.isNotEmpty())
  45880. {
  45881. const int index = currentPathBox->getSelectedId() - 1;
  45882. StringArray rootNames, rootPaths;
  45883. getRoots (rootNames, rootPaths);
  45884. if (rootPaths [index].isNotEmpty())
  45885. {
  45886. setRoot (File (rootPaths [index]));
  45887. }
  45888. else
  45889. {
  45890. File f (newText);
  45891. for (;;)
  45892. {
  45893. if (f.isDirectory())
  45894. {
  45895. setRoot (f);
  45896. break;
  45897. }
  45898. if (f.getParentDirectory() == f)
  45899. break;
  45900. f = f.getParentDirectory();
  45901. }
  45902. }
  45903. }
  45904. }
  45905. const BigInteger FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  45906. {
  45907. BigInteger separators;
  45908. #if JUCE_WINDOWS
  45909. Array<File> roots;
  45910. File::findFileSystemRoots (roots);
  45911. rootPaths.clear();
  45912. for (int i = 0; i < roots.size(); ++i)
  45913. {
  45914. const File& drive = roots.getReference(i);
  45915. String name (drive.getFullPathName());
  45916. rootPaths.add (name);
  45917. if (drive.isOnHardDisk())
  45918. {
  45919. String volume (drive.getVolumeLabel());
  45920. if (volume.isEmpty())
  45921. volume = TRANS("Hard Drive");
  45922. name << " [" << drive.getVolumeLabel() << ']';
  45923. }
  45924. else if (drive.isOnCDRomDrive())
  45925. {
  45926. name << TRANS(" [CD/DVD drive]");
  45927. }
  45928. rootNames.add (name);
  45929. }
  45930. separators.setBit (rootPaths.size());
  45931. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45932. rootNames.add ("Documents");
  45933. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45934. rootNames.add ("Desktop");
  45935. #endif
  45936. #if JUCE_MAC
  45937. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45938. rootNames.add ("Home folder");
  45939. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45940. rootNames.add ("Documents");
  45941. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45942. rootNames.add ("Desktop");
  45943. separators.setBit (rootPaths.size());
  45944. Array <File> volumes;
  45945. File vol ("/Volumes");
  45946. vol.findChildFiles (volumes, File::findDirectories, false);
  45947. for (int i = 0; i < volumes.size(); ++i)
  45948. {
  45949. const File& volume = volumes.getReference(i);
  45950. if (volume.isDirectory() && ! volume.getFileName().startsWithChar (T('.')))
  45951. {
  45952. rootPaths.add (volume.getFullPathName());
  45953. rootNames.add (volume.getFileName());
  45954. }
  45955. }
  45956. #endif
  45957. #if JUCE_LINUX
  45958. rootPaths.add ("/");
  45959. rootNames.add ("/");
  45960. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45961. rootNames.add ("Home folder");
  45962. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45963. rootNames.add ("Desktop");
  45964. #endif
  45965. return separators;
  45966. }
  45967. END_JUCE_NAMESPACE
  45968. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  45969. /*** Start of inlined file: juce_FileChooser.cpp ***/
  45970. BEGIN_JUCE_NAMESPACE
  45971. FileChooser::FileChooser (const String& chooserBoxTitle,
  45972. const File& currentFileOrDirectory,
  45973. const String& fileFilters,
  45974. const bool useNativeDialogBox_)
  45975. : title (chooserBoxTitle),
  45976. filters (fileFilters),
  45977. startingFile (currentFileOrDirectory),
  45978. useNativeDialogBox (useNativeDialogBox_)
  45979. {
  45980. #if JUCE_LINUX
  45981. useNativeDialogBox = false;
  45982. #endif
  45983. if (! fileFilters.containsNonWhitespaceChars())
  45984. filters = T("*");
  45985. }
  45986. FileChooser::~FileChooser()
  45987. {
  45988. }
  45989. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  45990. {
  45991. return showDialog (false, true, false, false, false, previewComponent);
  45992. }
  45993. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  45994. {
  45995. return showDialog (false, true, false, false, true, previewComponent);
  45996. }
  45997. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  45998. {
  45999. return showDialog (true, true, false, false, true, previewComponent);
  46000. }
  46001. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46002. {
  46003. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46004. }
  46005. bool FileChooser::browseForDirectory()
  46006. {
  46007. return showDialog (true, false, false, false, false, 0);
  46008. }
  46009. const File FileChooser::getResult() const
  46010. {
  46011. // if you've used a multiple-file select, you should use the getResults() method
  46012. // to retrieve all the files that were chosen.
  46013. jassert (results.size() <= 1);
  46014. return results.getFirst();
  46015. }
  46016. const Array<File>& FileChooser::getResults() const
  46017. {
  46018. return results;
  46019. }
  46020. bool FileChooser::showDialog (const bool selectsDirectories,
  46021. const bool selectsFiles,
  46022. const bool isSave,
  46023. const bool warnAboutOverwritingExistingFiles,
  46024. const bool selectMultipleFiles,
  46025. FilePreviewComponent* const previewComponent)
  46026. {
  46027. Component::SafePointer<Component> previouslyFocused (Component::getCurrentlyFocusedComponent());
  46028. results.clear();
  46029. // the preview component needs to be the right size before you pass it in here..
  46030. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46031. && previewComponent->getHeight() > 10));
  46032. #if JUCE_WINDOWS
  46033. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46034. #elif JUCE_MAC
  46035. if (useNativeDialogBox && (previewComponent == 0))
  46036. #else
  46037. if (false)
  46038. #endif
  46039. {
  46040. showPlatformDialog (results, title, startingFile, filters,
  46041. selectsDirectories, selectsFiles, isSave,
  46042. warnAboutOverwritingExistingFiles,
  46043. selectMultipleFiles,
  46044. previewComponent);
  46045. }
  46046. else
  46047. {
  46048. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46049. selectsDirectories ? "*" : String::empty,
  46050. String::empty);
  46051. int flags = isSave ? FileBrowserComponent::saveMode
  46052. : FileBrowserComponent::openMode;
  46053. if (selectsFiles)
  46054. flags |= FileBrowserComponent::canSelectFiles;
  46055. if (selectsDirectories)
  46056. flags |= FileBrowserComponent::canSelectDirectories;
  46057. if (selectMultipleFiles)
  46058. flags |= FileBrowserComponent::canSelectMultipleItems;
  46059. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46060. FileChooserDialogBox box (title, String::empty,
  46061. browserComponent,
  46062. warnAboutOverwritingExistingFiles,
  46063. browserComponent.findColour (AlertWindow::backgroundColourId));
  46064. if (box.show())
  46065. {
  46066. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46067. results.add (browserComponent.getSelectedFile (i));
  46068. }
  46069. }
  46070. if (previouslyFocused != 0)
  46071. previouslyFocused->grabKeyboardFocus();
  46072. return results.size() > 0;
  46073. }
  46074. FilePreviewComponent::FilePreviewComponent()
  46075. {
  46076. }
  46077. FilePreviewComponent::~FilePreviewComponent()
  46078. {
  46079. }
  46080. END_JUCE_NAMESPACE
  46081. /*** End of inlined file: juce_FileChooser.cpp ***/
  46082. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46083. BEGIN_JUCE_NAMESPACE
  46084. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46085. const String& instructions,
  46086. FileBrowserComponent& chooserComponent,
  46087. const bool warnAboutOverwritingExistingFiles_,
  46088. const Colour& backgroundColour)
  46089. : ResizableWindow (name, backgroundColour, true),
  46090. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46091. {
  46092. content = new ContentComponent();
  46093. content->setName (name);
  46094. content->instructions = instructions;
  46095. content->chooserComponent = &chooserComponent;
  46096. content->addAndMakeVisible (&chooserComponent);
  46097. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46098. content->addAndMakeVisible (content->okButton);
  46099. content->okButton->addButtonListener (this);
  46100. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46101. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46102. content->cancelButton = new TextButton (TRANS("Cancel"));
  46103. content->addAndMakeVisible (content->cancelButton);
  46104. content->cancelButton->addButtonListener (this);
  46105. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46106. setContentComponent (content);
  46107. setResizable (true, true);
  46108. setResizeLimits (300, 300, 1200, 1000);
  46109. content->chooserComponent->addListener (this);
  46110. }
  46111. FileChooserDialogBox::~FileChooserDialogBox()
  46112. {
  46113. content->chooserComponent->removeListener (this);
  46114. }
  46115. bool FileChooserDialogBox::show (int w, int h)
  46116. {
  46117. if (w <= 0)
  46118. {
  46119. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46120. if (previewComp != 0)
  46121. w = 400 + previewComp->getWidth();
  46122. else
  46123. w = 600;
  46124. }
  46125. if (h <= 0)
  46126. h = 500;
  46127. centreWithSize (w, h);
  46128. const bool ok = (runModalLoop() != 0);
  46129. setVisible (false);
  46130. return ok;
  46131. }
  46132. void FileChooserDialogBox::buttonClicked (Button* button)
  46133. {
  46134. if (button == content->okButton)
  46135. {
  46136. if (warnAboutOverwritingExistingFiles
  46137. && content->chooserComponent->isSaveMode()
  46138. && content->chooserComponent->getSelectedFile(0).exists())
  46139. {
  46140. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46141. TRANS("File already exists"),
  46142. TRANS("There's already a file called:\n\n")
  46143. + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46144. + T("\n\nAre you sure you want to overwrite it?"),
  46145. TRANS("overwrite"),
  46146. TRANS("cancel")))
  46147. {
  46148. return;
  46149. }
  46150. }
  46151. exitModalState (1);
  46152. }
  46153. else if (button == content->cancelButton)
  46154. closeButtonPressed();
  46155. }
  46156. void FileChooserDialogBox::closeButtonPressed()
  46157. {
  46158. setVisible (false);
  46159. }
  46160. void FileChooserDialogBox::selectionChanged()
  46161. {
  46162. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46163. }
  46164. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46165. {
  46166. }
  46167. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46168. {
  46169. selectionChanged();
  46170. content->okButton->triggerClick();
  46171. }
  46172. FileChooserDialogBox::ContentComponent::ContentComponent()
  46173. {
  46174. setInterceptsMouseClicks (false, true);
  46175. }
  46176. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46177. {
  46178. delete okButton;
  46179. delete cancelButton;
  46180. }
  46181. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46182. {
  46183. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46184. text.draw (g);
  46185. }
  46186. void FileChooserDialogBox::ContentComponent::resized()
  46187. {
  46188. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46189. float left, top, right, bottom;
  46190. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46191. const int y = roundToInt (bottom) + 10;
  46192. const int buttonHeight = 26;
  46193. const int buttonY = getHeight() - buttonHeight - 8;
  46194. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46195. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46196. proportionOfWidth (0.2f), buttonHeight);
  46197. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46198. proportionOfWidth (0.2f), buttonHeight);
  46199. }
  46200. END_JUCE_NAMESPACE
  46201. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46202. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46203. BEGIN_JUCE_NAMESPACE
  46204. FileFilter::FileFilter (const String& filterDescription)
  46205. : description (filterDescription)
  46206. {
  46207. }
  46208. FileFilter::~FileFilter()
  46209. {
  46210. }
  46211. const String& FileFilter::getDescription() const throw()
  46212. {
  46213. return description;
  46214. }
  46215. END_JUCE_NAMESPACE
  46216. /*** End of inlined file: juce_FileFilter.cpp ***/
  46217. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46218. BEGIN_JUCE_NAMESPACE
  46219. Image* juce_createIconForFile (const File& file);
  46220. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46221. : ListBox (String::empty, 0),
  46222. DirectoryContentsDisplayComponent (listToShow)
  46223. {
  46224. setModel (this);
  46225. fileList.addChangeListener (this);
  46226. }
  46227. FileListComponent::~FileListComponent()
  46228. {
  46229. fileList.removeChangeListener (this);
  46230. deleteAllChildren();
  46231. }
  46232. int FileListComponent::getNumSelectedFiles() const
  46233. {
  46234. return getNumSelectedRows();
  46235. }
  46236. const File FileListComponent::getSelectedFile (int index) const
  46237. {
  46238. return fileList.getFile (getSelectedRow (index));
  46239. }
  46240. void FileListComponent::scrollToTop()
  46241. {
  46242. getVerticalScrollBar()->setCurrentRangeStart (0);
  46243. }
  46244. void FileListComponent::changeListenerCallback (void*)
  46245. {
  46246. updateContent();
  46247. if (lastDirectory != fileList.getDirectory())
  46248. {
  46249. lastDirectory = fileList.getDirectory();
  46250. deselectAllRows();
  46251. }
  46252. }
  46253. class FileListItemComponent : public Component,
  46254. public TimeSliceClient,
  46255. public AsyncUpdater
  46256. {
  46257. public:
  46258. FileListItemComponent (FileListComponent& owner_,
  46259. TimeSliceThread& thread_) throw()
  46260. : owner (owner_),
  46261. thread (thread_),
  46262. icon (0)
  46263. {
  46264. }
  46265. ~FileListItemComponent() throw()
  46266. {
  46267. thread.removeTimeSliceClient (this);
  46268. clearIcon();
  46269. }
  46270. void paint (Graphics& g)
  46271. {
  46272. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46273. file.getFileName(),
  46274. icon,
  46275. fileSize, modTime,
  46276. isDirectory, highlighted,
  46277. index);
  46278. }
  46279. void mouseDown (const MouseEvent& e)
  46280. {
  46281. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46282. owner.sendMouseClickMessage (file, e);
  46283. }
  46284. void mouseDoubleClick (const MouseEvent&)
  46285. {
  46286. owner.sendDoubleClickMessage (file);
  46287. }
  46288. void update (const File& root,
  46289. const DirectoryContentsList::FileInfo* const fileInfo,
  46290. const int index_,
  46291. const bool highlighted_) throw()
  46292. {
  46293. thread.removeTimeSliceClient (this);
  46294. if (highlighted_ != highlighted
  46295. || index_ != index)
  46296. {
  46297. index = index_;
  46298. highlighted = highlighted_;
  46299. repaint();
  46300. }
  46301. File newFile;
  46302. String newFileSize;
  46303. String newModTime;
  46304. if (fileInfo != 0)
  46305. {
  46306. newFile = root.getChildFile (fileInfo->filename);
  46307. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46308. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46309. }
  46310. if (newFile != file
  46311. || fileSize != newFileSize
  46312. || modTime != newModTime)
  46313. {
  46314. file = newFile;
  46315. fileSize = newFileSize;
  46316. modTime = newModTime;
  46317. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46318. repaint();
  46319. clearIcon();
  46320. }
  46321. if (file != File::nonexistent
  46322. && icon == 0 && ! isDirectory)
  46323. {
  46324. updateIcon (true);
  46325. if (icon == 0)
  46326. thread.addTimeSliceClient (this);
  46327. }
  46328. }
  46329. bool useTimeSlice()
  46330. {
  46331. updateIcon (false);
  46332. return false;
  46333. }
  46334. void handleAsyncUpdate()
  46335. {
  46336. repaint();
  46337. }
  46338. juce_UseDebuggingNewOperator
  46339. private:
  46340. FileListComponent& owner;
  46341. TimeSliceThread& thread;
  46342. bool highlighted;
  46343. int index;
  46344. File file;
  46345. String fileSize;
  46346. String modTime;
  46347. Image* icon;
  46348. bool isDirectory;
  46349. void clearIcon() throw()
  46350. {
  46351. ImageCache::release (icon);
  46352. icon = 0;
  46353. }
  46354. void updateIcon (const bool onlyUpdateIfCached) throw()
  46355. {
  46356. if (icon == 0)
  46357. {
  46358. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  46359. Image* im = ImageCache::getFromHashCode (hashCode);
  46360. if (im == 0 && ! onlyUpdateIfCached)
  46361. {
  46362. im = juce_createIconForFile (file);
  46363. if (im != 0)
  46364. ImageCache::addImageToCache (im, hashCode);
  46365. }
  46366. if (im != 0)
  46367. {
  46368. icon = im;
  46369. triggerAsyncUpdate();
  46370. }
  46371. }
  46372. }
  46373. };
  46374. int FileListComponent::getNumRows()
  46375. {
  46376. return fileList.getNumFiles();
  46377. }
  46378. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46379. {
  46380. }
  46381. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46382. {
  46383. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46384. if (comp == 0)
  46385. {
  46386. delete existingComponentToUpdate;
  46387. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46388. }
  46389. DirectoryContentsList::FileInfo fileInfo;
  46390. if (fileList.getFileInfo (row, fileInfo))
  46391. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46392. else
  46393. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46394. return comp;
  46395. }
  46396. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46397. {
  46398. sendSelectionChangeMessage();
  46399. }
  46400. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  46401. {
  46402. }
  46403. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  46404. {
  46405. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  46406. }
  46407. END_JUCE_NAMESPACE
  46408. /*** End of inlined file: juce_FileListComponent.cpp ***/
  46409. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  46410. BEGIN_JUCE_NAMESPACE
  46411. FilenameComponent::FilenameComponent (const String& name,
  46412. const File& currentFile,
  46413. const bool canEditFilename,
  46414. const bool isDirectory,
  46415. const bool isForSaving,
  46416. const String& fileBrowserWildcard,
  46417. const String& enforcedSuffix_,
  46418. const String& textWhenNothingSelected)
  46419. : Component (name),
  46420. maxRecentFiles (30),
  46421. isDir (isDirectory),
  46422. isSaving (isForSaving),
  46423. isFileDragOver (false),
  46424. wildcard (fileBrowserWildcard),
  46425. enforcedSuffix (enforcedSuffix_)
  46426. {
  46427. addAndMakeVisible (filenameBox = new ComboBox (T("fn")));
  46428. filenameBox->setEditableText (canEditFilename);
  46429. filenameBox->addListener (this);
  46430. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  46431. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  46432. browseButton = 0;
  46433. setBrowseButtonText (T("..."));
  46434. setCurrentFile (currentFile, true);
  46435. }
  46436. FilenameComponent::~FilenameComponent()
  46437. {
  46438. deleteAllChildren();
  46439. }
  46440. void FilenameComponent::paintOverChildren (Graphics& g)
  46441. {
  46442. if (isFileDragOver)
  46443. {
  46444. g.setColour (Colours::red.withAlpha (0.2f));
  46445. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  46446. }
  46447. }
  46448. void FilenameComponent::resized()
  46449. {
  46450. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  46451. }
  46452. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  46453. {
  46454. browseButtonText = newBrowseButtonText;
  46455. lookAndFeelChanged();
  46456. }
  46457. void FilenameComponent::lookAndFeelChanged()
  46458. {
  46459. deleteAndZero (browseButton);
  46460. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  46461. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  46462. resized();
  46463. browseButton->addButtonListener (this);
  46464. }
  46465. void FilenameComponent::setTooltip (const String& newTooltip)
  46466. {
  46467. SettableTooltipClient::setTooltip (newTooltip);
  46468. filenameBox->setTooltip (newTooltip);
  46469. }
  46470. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  46471. {
  46472. defaultBrowseFile = newDefaultDirectory;
  46473. }
  46474. void FilenameComponent::buttonClicked (Button*)
  46475. {
  46476. FileChooser fc (TRANS("Choose a new file"),
  46477. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  46478. : getCurrentFile(),
  46479. wildcard);
  46480. if (isDir ? fc.browseForDirectory()
  46481. : (isSaving ? fc.browseForFileToSave (false)
  46482. : fc.browseForFileToOpen()))
  46483. {
  46484. setCurrentFile (fc.getResult(), true);
  46485. }
  46486. }
  46487. void FilenameComponent::comboBoxChanged (ComboBox*)
  46488. {
  46489. setCurrentFile (getCurrentFile(), true);
  46490. }
  46491. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  46492. {
  46493. return true;
  46494. }
  46495. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  46496. {
  46497. isFileDragOver = false;
  46498. repaint();
  46499. const File f (filenames[0]);
  46500. if (f.exists() && (f.isDirectory() == isDir))
  46501. setCurrentFile (f, true);
  46502. }
  46503. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  46504. {
  46505. isFileDragOver = true;
  46506. repaint();
  46507. }
  46508. void FilenameComponent::fileDragExit (const StringArray&)
  46509. {
  46510. isFileDragOver = false;
  46511. repaint();
  46512. }
  46513. const File FilenameComponent::getCurrentFile() const
  46514. {
  46515. File f (filenameBox->getText());
  46516. if (enforcedSuffix.isNotEmpty())
  46517. f = f.withFileExtension (enforcedSuffix);
  46518. return f;
  46519. }
  46520. void FilenameComponent::setCurrentFile (File newFile,
  46521. const bool addToRecentlyUsedList,
  46522. const bool sendChangeNotification)
  46523. {
  46524. if (enforcedSuffix.isNotEmpty())
  46525. newFile = newFile.withFileExtension (enforcedSuffix);
  46526. if (newFile.getFullPathName() != lastFilename)
  46527. {
  46528. lastFilename = newFile.getFullPathName();
  46529. if (addToRecentlyUsedList)
  46530. addRecentlyUsedFile (newFile);
  46531. filenameBox->setText (lastFilename, true);
  46532. if (sendChangeNotification)
  46533. triggerAsyncUpdate();
  46534. }
  46535. }
  46536. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  46537. {
  46538. filenameBox->setEditableText (shouldBeEditable);
  46539. }
  46540. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  46541. {
  46542. StringArray names;
  46543. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  46544. names.add (filenameBox->getItemText (i));
  46545. return names;
  46546. }
  46547. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  46548. {
  46549. if (filenames != getRecentlyUsedFilenames())
  46550. {
  46551. filenameBox->clear();
  46552. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  46553. filenameBox->addItem (filenames[i], i + 1);
  46554. }
  46555. }
  46556. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  46557. {
  46558. maxRecentFiles = jmax (1, newMaximum);
  46559. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  46560. }
  46561. void FilenameComponent::addRecentlyUsedFile (const File& file)
  46562. {
  46563. StringArray files (getRecentlyUsedFilenames());
  46564. if (file.getFullPathName().isNotEmpty())
  46565. {
  46566. files.removeString (file.getFullPathName(), true);
  46567. files.insert (0, file.getFullPathName());
  46568. setRecentlyUsedFilenames (files);
  46569. }
  46570. }
  46571. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  46572. {
  46573. listeners.add (listener);
  46574. }
  46575. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  46576. {
  46577. listeners.remove (listener);
  46578. }
  46579. void FilenameComponent::handleAsyncUpdate()
  46580. {
  46581. Component::BailOutChecker checker (this);
  46582. listeners.callChecked (checker, &FilenameComponentListener::filenameComponentChanged, this);
  46583. }
  46584. END_JUCE_NAMESPACE
  46585. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  46586. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46587. BEGIN_JUCE_NAMESPACE
  46588. FileSearchPathListComponent::FileSearchPathListComponent()
  46589. {
  46590. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  46591. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  46592. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  46593. listBox->setOutlineThickness (1);
  46594. addAndMakeVisible (addButton = new TextButton ("+"));
  46595. addButton->addButtonListener (this);
  46596. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46597. addAndMakeVisible (removeButton = new TextButton ("-"));
  46598. removeButton->addButtonListener (this);
  46599. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46600. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  46601. changeButton->addButtonListener (this);
  46602. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46603. upButton->addButtonListener (this);
  46604. {
  46605. Path arrowPath;
  46606. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  46607. DrawablePath arrowImage;
  46608. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46609. arrowImage.setPath (arrowPath);
  46610. ((DrawableButton*) upButton)->setImages (&arrowImage);
  46611. }
  46612. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46613. downButton->addButtonListener (this);
  46614. {
  46615. Path arrowPath;
  46616. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  46617. DrawablePath arrowImage;
  46618. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46619. arrowImage.setPath (arrowPath);
  46620. ((DrawableButton*) downButton)->setImages (&arrowImage);
  46621. }
  46622. updateButtons();
  46623. }
  46624. FileSearchPathListComponent::~FileSearchPathListComponent()
  46625. {
  46626. deleteAllChildren();
  46627. }
  46628. void FileSearchPathListComponent::updateButtons() throw()
  46629. {
  46630. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  46631. removeButton->setEnabled (anythingSelected);
  46632. changeButton->setEnabled (anythingSelected);
  46633. upButton->setEnabled (anythingSelected);
  46634. downButton->setEnabled (anythingSelected);
  46635. }
  46636. void FileSearchPathListComponent::changed() throw()
  46637. {
  46638. listBox->updateContent();
  46639. listBox->repaint();
  46640. updateButtons();
  46641. }
  46642. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  46643. {
  46644. if (newPath.toString() != path.toString())
  46645. {
  46646. path = newPath;
  46647. changed();
  46648. }
  46649. }
  46650. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  46651. {
  46652. defaultBrowseTarget = newDefaultDirectory;
  46653. }
  46654. int FileSearchPathListComponent::getNumRows()
  46655. {
  46656. return path.getNumPaths();
  46657. }
  46658. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  46659. {
  46660. if (rowIsSelected)
  46661. g.fillAll (findColour (TextEditor::highlightColourId));
  46662. g.setColour (findColour (ListBox::textColourId));
  46663. Font f (height * 0.7f);
  46664. f.setHorizontalScale (0.9f);
  46665. g.setFont (f);
  46666. g.drawText (path [rowNumber].getFullPathName(),
  46667. 4, 0, width - 6, height,
  46668. Justification::centredLeft, true);
  46669. }
  46670. void FileSearchPathListComponent::deleteKeyPressed (int row)
  46671. {
  46672. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  46673. {
  46674. path.remove (row);
  46675. changed();
  46676. }
  46677. }
  46678. void FileSearchPathListComponent::returnKeyPressed (int row)
  46679. {
  46680. FileChooser chooser (TRANS("Change folder..."), path [row], T("*"));
  46681. if (chooser.browseForDirectory())
  46682. {
  46683. path.remove (row);
  46684. path.add (chooser.getResult(), row);
  46685. changed();
  46686. }
  46687. }
  46688. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  46689. {
  46690. returnKeyPressed (row);
  46691. }
  46692. void FileSearchPathListComponent::selectedRowsChanged (int)
  46693. {
  46694. updateButtons();
  46695. }
  46696. void FileSearchPathListComponent::paint (Graphics& g)
  46697. {
  46698. g.fillAll (findColour (backgroundColourId));
  46699. }
  46700. void FileSearchPathListComponent::resized()
  46701. {
  46702. const int buttonH = 22;
  46703. const int buttonY = getHeight() - buttonH - 4;
  46704. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  46705. addButton->setBounds (2, buttonY, buttonH, buttonH);
  46706. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  46707. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  46708. downButton->setSize (buttonH * 2, buttonH);
  46709. upButton->setSize (buttonH * 2, buttonH);
  46710. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  46711. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  46712. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  46713. }
  46714. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  46715. {
  46716. return true;
  46717. }
  46718. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  46719. {
  46720. for (int i = filenames.size(); --i >= 0;)
  46721. {
  46722. const File f (filenames[i]);
  46723. if (f.isDirectory())
  46724. {
  46725. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  46726. path.add (f, row);
  46727. changed();
  46728. }
  46729. }
  46730. }
  46731. void FileSearchPathListComponent::buttonClicked (Button* button)
  46732. {
  46733. const int currentRow = listBox->getSelectedRow();
  46734. if (button == removeButton)
  46735. {
  46736. deleteKeyPressed (currentRow);
  46737. }
  46738. else if (button == addButton)
  46739. {
  46740. File start (defaultBrowseTarget);
  46741. if (start == File::nonexistent)
  46742. start = path [0];
  46743. if (start == File::nonexistent)
  46744. start = File::getCurrentWorkingDirectory();
  46745. FileChooser chooser (TRANS("Add a folder..."), start, T("*"));
  46746. if (chooser.browseForDirectory())
  46747. {
  46748. path.add (chooser.getResult(), currentRow);
  46749. }
  46750. }
  46751. else if (button == changeButton)
  46752. {
  46753. returnKeyPressed (currentRow);
  46754. }
  46755. else if (button == upButton)
  46756. {
  46757. if (currentRow > 0 && currentRow < path.getNumPaths())
  46758. {
  46759. const File f (path[currentRow]);
  46760. path.remove (currentRow);
  46761. path.add (f, currentRow - 1);
  46762. listBox->selectRow (currentRow - 1);
  46763. }
  46764. }
  46765. else if (button == downButton)
  46766. {
  46767. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  46768. {
  46769. const File f (path[currentRow]);
  46770. path.remove (currentRow);
  46771. path.add (f, currentRow + 1);
  46772. listBox->selectRow (currentRow + 1);
  46773. }
  46774. }
  46775. changed();
  46776. }
  46777. END_JUCE_NAMESPACE
  46778. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46779. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  46780. BEGIN_JUCE_NAMESPACE
  46781. Image* juce_createIconForFile (const File& file);
  46782. class FileListTreeItem : public TreeViewItem,
  46783. public TimeSliceClient,
  46784. public AsyncUpdater,
  46785. public ChangeListener
  46786. {
  46787. public:
  46788. FileListTreeItem (FileTreeComponent& owner_,
  46789. DirectoryContentsList* const parentContentsList_,
  46790. const int indexInContentsList_,
  46791. const File& file_,
  46792. TimeSliceThread& thread_) throw()
  46793. : file (file_),
  46794. owner (owner_),
  46795. parentContentsList (parentContentsList_),
  46796. indexInContentsList (indexInContentsList_),
  46797. subContentsList (0),
  46798. canDeleteSubContentsList (false),
  46799. thread (thread_),
  46800. icon (0)
  46801. {
  46802. DirectoryContentsList::FileInfo fileInfo;
  46803. if (parentContentsList_ != 0
  46804. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  46805. {
  46806. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  46807. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  46808. isDirectory = fileInfo.isDirectory;
  46809. }
  46810. else
  46811. {
  46812. isDirectory = true;
  46813. }
  46814. }
  46815. ~FileListTreeItem() throw()
  46816. {
  46817. thread.removeTimeSliceClient (this);
  46818. clearSubItems();
  46819. ImageCache::release (icon);
  46820. if (canDeleteSubContentsList)
  46821. delete subContentsList;
  46822. }
  46823. bool mightContainSubItems() { return isDirectory; }
  46824. const String getUniqueName() const { return file.getFullPathName(); }
  46825. int getItemHeight() const { return 22; }
  46826. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  46827. void itemOpennessChanged (bool isNowOpen)
  46828. {
  46829. if (isNowOpen)
  46830. {
  46831. clearSubItems();
  46832. isDirectory = file.isDirectory();
  46833. if (isDirectory)
  46834. {
  46835. if (subContentsList == 0)
  46836. {
  46837. jassert (parentContentsList != 0);
  46838. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  46839. l->setDirectory (file, true, true);
  46840. setSubContentsList (l);
  46841. canDeleteSubContentsList = true;
  46842. }
  46843. changeListenerCallback (0);
  46844. }
  46845. }
  46846. }
  46847. void setSubContentsList (DirectoryContentsList* newList) throw()
  46848. {
  46849. jassert (subContentsList == 0);
  46850. subContentsList = newList;
  46851. newList->addChangeListener (this);
  46852. }
  46853. void changeListenerCallback (void*)
  46854. {
  46855. clearSubItems();
  46856. if (isOpen() && subContentsList != 0)
  46857. {
  46858. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  46859. {
  46860. FileListTreeItem* const item
  46861. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  46862. addSubItem (item);
  46863. }
  46864. }
  46865. }
  46866. void paintItem (Graphics& g, int width, int height)
  46867. {
  46868. if (file != File::nonexistent)
  46869. {
  46870. updateIcon (true);
  46871. if (icon == 0)
  46872. thread.addTimeSliceClient (this);
  46873. }
  46874. owner.getLookAndFeel()
  46875. .drawFileBrowserRow (g, width, height,
  46876. file.getFileName(),
  46877. icon,
  46878. fileSize, modTime,
  46879. isDirectory, isSelected(),
  46880. indexInContentsList);
  46881. }
  46882. void itemClicked (const MouseEvent& e)
  46883. {
  46884. owner.sendMouseClickMessage (file, e);
  46885. }
  46886. void itemDoubleClicked (const MouseEvent& e)
  46887. {
  46888. TreeViewItem::itemDoubleClicked (e);
  46889. owner.sendDoubleClickMessage (file);
  46890. }
  46891. void itemSelectionChanged (bool)
  46892. {
  46893. owner.sendSelectionChangeMessage();
  46894. }
  46895. bool useTimeSlice()
  46896. {
  46897. updateIcon (false);
  46898. thread.removeTimeSliceClient (this);
  46899. return false;
  46900. }
  46901. void handleAsyncUpdate()
  46902. {
  46903. owner.repaint();
  46904. }
  46905. const File file;
  46906. juce_UseDebuggingNewOperator
  46907. private:
  46908. FileTreeComponent& owner;
  46909. DirectoryContentsList* parentContentsList;
  46910. int indexInContentsList;
  46911. DirectoryContentsList* subContentsList;
  46912. bool isDirectory, canDeleteSubContentsList;
  46913. TimeSliceThread& thread;
  46914. Image* icon;
  46915. String fileSize;
  46916. String modTime;
  46917. void updateIcon (const bool onlyUpdateIfCached) throw()
  46918. {
  46919. if (icon == 0)
  46920. {
  46921. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  46922. Image* im = ImageCache::getFromHashCode (hashCode);
  46923. if (im == 0 && ! onlyUpdateIfCached)
  46924. {
  46925. im = juce_createIconForFile (file);
  46926. if (im != 0)
  46927. ImageCache::addImageToCache (im, hashCode);
  46928. }
  46929. if (im != 0)
  46930. {
  46931. icon = im;
  46932. triggerAsyncUpdate();
  46933. }
  46934. }
  46935. }
  46936. };
  46937. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  46938. : DirectoryContentsDisplayComponent (listToShow)
  46939. {
  46940. FileListTreeItem* const root
  46941. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  46942. listToShow.getTimeSliceThread());
  46943. root->setSubContentsList (&listToShow);
  46944. setRootItemVisible (false);
  46945. setRootItem (root);
  46946. }
  46947. FileTreeComponent::~FileTreeComponent()
  46948. {
  46949. deleteRootItem();
  46950. }
  46951. const File FileTreeComponent::getSelectedFile (const int index) const
  46952. {
  46953. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  46954. if (item != 0)
  46955. return item->file;
  46956. return File::nonexistent;
  46957. }
  46958. void FileTreeComponent::scrollToTop()
  46959. {
  46960. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  46961. }
  46962. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  46963. {
  46964. dragAndDropDescription = description;
  46965. }
  46966. END_JUCE_NAMESPACE
  46967. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  46968. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  46969. BEGIN_JUCE_NAMESPACE
  46970. ImagePreviewComponent::ImagePreviewComponent()
  46971. {
  46972. }
  46973. ImagePreviewComponent::~ImagePreviewComponent()
  46974. {
  46975. }
  46976. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  46977. {
  46978. const int availableW = proportionOfWidth (0.97f);
  46979. const int availableH = getHeight() - 13 * 4;
  46980. const double scale = jmin (1.0,
  46981. availableW / (double) w,
  46982. availableH / (double) h);
  46983. w = roundToInt (scale * w);
  46984. h = roundToInt (scale * h);
  46985. }
  46986. void ImagePreviewComponent::selectedFileChanged (const File& file)
  46987. {
  46988. if (fileToLoad != file)
  46989. {
  46990. fileToLoad = file;
  46991. startTimer (100);
  46992. }
  46993. }
  46994. void ImagePreviewComponent::timerCallback()
  46995. {
  46996. stopTimer();
  46997. currentThumbnail = 0;
  46998. currentDetails = String::empty;
  46999. repaint();
  47000. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47001. if (in != 0)
  47002. {
  47003. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47004. if (format != 0)
  47005. {
  47006. currentThumbnail = format->decodeImage (*in);
  47007. if (currentThumbnail != 0)
  47008. {
  47009. int w = currentThumbnail->getWidth();
  47010. int h = currentThumbnail->getHeight();
  47011. currentDetails
  47012. << fileToLoad.getFileName() << "\n"
  47013. << format->getFormatName() << "\n"
  47014. << w << " x " << h << " pixels\n"
  47015. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47016. getThumbSize (w, h);
  47017. currentThumbnail = currentThumbnail->createCopy (w, h);
  47018. }
  47019. }
  47020. }
  47021. }
  47022. void ImagePreviewComponent::paint (Graphics& g)
  47023. {
  47024. if (currentThumbnail != 0)
  47025. {
  47026. g.setFont (13.0f);
  47027. int w = currentThumbnail->getWidth();
  47028. int h = currentThumbnail->getHeight();
  47029. getThumbSize (w, h);
  47030. const int numLines = 4;
  47031. const int totalH = 13 * numLines + h + 4;
  47032. const int y = (getHeight() - totalH) / 2;
  47033. g.drawImageWithin (currentThumbnail,
  47034. (getWidth() - w) / 2, y, w, h,
  47035. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47036. false);
  47037. g.drawFittedText (currentDetails,
  47038. 0, y + h + 4, getWidth(), 100,
  47039. Justification::centredTop, numLines);
  47040. }
  47041. }
  47042. END_JUCE_NAMESPACE
  47043. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47044. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47045. BEGIN_JUCE_NAMESPACE
  47046. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47047. const String& directoryWildcardPatterns,
  47048. const String& description_)
  47049. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47050. : (description_ + T(" (") + fileWildcardPatterns + T(")")))
  47051. {
  47052. parse (fileWildcardPatterns, fileWildcards);
  47053. parse (directoryWildcardPatterns, directoryWildcards);
  47054. }
  47055. WildcardFileFilter::~WildcardFileFilter()
  47056. {
  47057. }
  47058. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47059. {
  47060. return match (file, fileWildcards);
  47061. }
  47062. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47063. {
  47064. return match (file, directoryWildcards);
  47065. }
  47066. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47067. {
  47068. result.addTokens (pattern.toLowerCase(), T(";,"), T("\"'"));
  47069. result.trim();
  47070. result.removeEmptyStrings();
  47071. // special case for *.*, because people use it to mean "any file", but it
  47072. // would actually ignore files with no extension.
  47073. for (int i = result.size(); --i >= 0;)
  47074. if (result[i] == T("*.*"))
  47075. result.set (i, T("*"));
  47076. }
  47077. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47078. {
  47079. const String filename (file.getFileName());
  47080. for (int i = wildcards.size(); --i >= 0;)
  47081. if (filename.matchesWildcard (wildcards[i], true))
  47082. return true;
  47083. return false;
  47084. }
  47085. END_JUCE_NAMESPACE
  47086. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47087. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47088. BEGIN_JUCE_NAMESPACE
  47089. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47090. {
  47091. }
  47092. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47093. {
  47094. }
  47095. namespace KeyboardFocusHelpers
  47096. {
  47097. // This will sort a set of components, so that they are ordered in terms of
  47098. // left-to-right and then top-to-bottom.
  47099. class ScreenPositionComparator
  47100. {
  47101. public:
  47102. ScreenPositionComparator() {}
  47103. static int compareElements (const Component* const first, const Component* const second) throw()
  47104. {
  47105. int explicitOrder1 = first->getExplicitFocusOrder();
  47106. if (explicitOrder1 <= 0)
  47107. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47108. int explicitOrder2 = second->getExplicitFocusOrder();
  47109. if (explicitOrder2 <= 0)
  47110. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47111. if (explicitOrder1 != explicitOrder2)
  47112. return explicitOrder1 - explicitOrder2;
  47113. const int diff = first->getY() - second->getY();
  47114. return (diff == 0) ? first->getX() - second->getX()
  47115. : diff;
  47116. }
  47117. };
  47118. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47119. {
  47120. if (parent->getNumChildComponents() > 0)
  47121. {
  47122. Array <Component*> localComps;
  47123. ScreenPositionComparator comparator;
  47124. int i;
  47125. for (i = parent->getNumChildComponents(); --i >= 0;)
  47126. {
  47127. Component* const c = parent->getChildComponent (i);
  47128. if (c->isVisible() && c->isEnabled())
  47129. localComps.addSorted (comparator, c);
  47130. }
  47131. for (i = 0; i < localComps.size(); ++i)
  47132. {
  47133. Component* const c = localComps.getUnchecked (i);
  47134. if (c->getWantsKeyboardFocus())
  47135. comps.add (c);
  47136. if (! c->isFocusContainer())
  47137. findAllFocusableComponents (c, comps);
  47138. }
  47139. }
  47140. }
  47141. }
  47142. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47143. {
  47144. Component* focusContainer = current->getParentComponent();
  47145. if (focusContainer != 0)
  47146. {
  47147. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47148. focusContainer = focusContainer->getParentComponent();
  47149. if (focusContainer != 0)
  47150. {
  47151. Array <Component*> comps;
  47152. KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps);
  47153. if (comps.size() > 0)
  47154. {
  47155. const int index = comps.indexOf (current);
  47156. return comps [(index + comps.size() + delta) % comps.size()];
  47157. }
  47158. }
  47159. }
  47160. return 0;
  47161. }
  47162. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47163. {
  47164. return getIncrementedComponent (current, 1);
  47165. }
  47166. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47167. {
  47168. return getIncrementedComponent (current, -1);
  47169. }
  47170. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47171. {
  47172. Array <Component*> comps;
  47173. if (parentComponent != 0)
  47174. KeyboardFocusHelpers::findAllFocusableComponents (parentComponent, comps);
  47175. return comps.getFirst();
  47176. }
  47177. END_JUCE_NAMESPACE
  47178. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47179. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47180. BEGIN_JUCE_NAMESPACE
  47181. bool KeyListener::keyStateChanged (const bool, Component*)
  47182. {
  47183. return false;
  47184. }
  47185. END_JUCE_NAMESPACE
  47186. /*** End of inlined file: juce_KeyListener.cpp ***/
  47187. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47188. BEGIN_JUCE_NAMESPACE
  47189. // N.B. these two includes are put here deliberately to avoid problems with
  47190. // old GCCs failing on long include paths
  47191. const int maxKeys = 3;
  47192. class KeyMappingChangeButton : public Button
  47193. {
  47194. public:
  47195. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47196. const CommandID commandID_,
  47197. const String& keyName,
  47198. const int keyNum_)
  47199. : Button (keyName),
  47200. owner (owner_),
  47201. commandID (commandID_),
  47202. keyNum (keyNum_)
  47203. {
  47204. setWantsKeyboardFocus (false);
  47205. setTriggeredOnMouseDown (keyNum >= 0);
  47206. if (keyNum_ < 0)
  47207. setTooltip (TRANS("adds a new key-mapping"));
  47208. else
  47209. setTooltip (TRANS("click to change this key-mapping"));
  47210. }
  47211. ~KeyMappingChangeButton()
  47212. {
  47213. }
  47214. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47215. {
  47216. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47217. keyNum >= 0 ? getName() : String::empty);
  47218. }
  47219. void clicked()
  47220. {
  47221. if (keyNum >= 0)
  47222. {
  47223. // existing key clicked..
  47224. PopupMenu m;
  47225. m.addItem (1, TRANS("change this key-mapping"));
  47226. m.addSeparator();
  47227. m.addItem (2, TRANS("remove this key-mapping"));
  47228. const int res = m.show();
  47229. if (res == 1)
  47230. {
  47231. owner->assignNewKey (commandID, keyNum);
  47232. }
  47233. else if (res == 2)
  47234. {
  47235. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47236. }
  47237. }
  47238. else
  47239. {
  47240. // + button pressed..
  47241. owner->assignNewKey (commandID, -1);
  47242. }
  47243. }
  47244. void fitToContent (const int h) throw()
  47245. {
  47246. if (keyNum < 0)
  47247. {
  47248. setSize (h, h);
  47249. }
  47250. else
  47251. {
  47252. Font f (h * 0.6f);
  47253. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47254. }
  47255. }
  47256. juce_UseDebuggingNewOperator
  47257. private:
  47258. KeyMappingEditorComponent* const owner;
  47259. const CommandID commandID;
  47260. const int keyNum;
  47261. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47262. KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47263. };
  47264. class KeyMappingItemComponent : public Component
  47265. {
  47266. public:
  47267. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47268. const CommandID commandID_)
  47269. : owner (owner_),
  47270. commandID (commandID_)
  47271. {
  47272. setInterceptsMouseClicks (false, true);
  47273. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47274. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47275. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47276. {
  47277. KeyMappingChangeButton* const kb
  47278. = new KeyMappingChangeButton (owner_, commandID,
  47279. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47280. kb->setEnabled (! isReadOnly);
  47281. addAndMakeVisible (kb);
  47282. }
  47283. KeyMappingChangeButton* const kb
  47284. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47285. addChildComponent (kb);
  47286. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47287. }
  47288. ~KeyMappingItemComponent()
  47289. {
  47290. deleteAllChildren();
  47291. }
  47292. void paint (Graphics& g)
  47293. {
  47294. g.setFont (getHeight() * 0.7f);
  47295. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47296. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47297. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47298. Justification::centredLeft, true);
  47299. }
  47300. void resized()
  47301. {
  47302. int x = getWidth() - 4;
  47303. for (int i = getNumChildComponents(); --i >= 0;)
  47304. {
  47305. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47306. kb->fitToContent (getHeight() - 2);
  47307. kb->setTopRightPosition (x, 1);
  47308. x -= kb->getWidth() + 5;
  47309. }
  47310. }
  47311. juce_UseDebuggingNewOperator
  47312. private:
  47313. KeyMappingEditorComponent* const owner;
  47314. const CommandID commandID;
  47315. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47316. KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47317. };
  47318. class KeyMappingTreeViewItem : public TreeViewItem
  47319. {
  47320. public:
  47321. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47322. const CommandID commandID_)
  47323. : owner (owner_),
  47324. commandID (commandID_)
  47325. {
  47326. }
  47327. ~KeyMappingTreeViewItem()
  47328. {
  47329. }
  47330. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47331. bool mightContainSubItems() { return false; }
  47332. int getItemHeight() const { return 20; }
  47333. Component* createItemComponent()
  47334. {
  47335. return new KeyMappingItemComponent (owner, commandID);
  47336. }
  47337. juce_UseDebuggingNewOperator
  47338. private:
  47339. KeyMappingEditorComponent* const owner;
  47340. const CommandID commandID;
  47341. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47342. KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47343. };
  47344. class KeyCategoryTreeViewItem : public TreeViewItem
  47345. {
  47346. public:
  47347. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47348. const String& name)
  47349. : owner (owner_),
  47350. categoryName (name)
  47351. {
  47352. }
  47353. ~KeyCategoryTreeViewItem()
  47354. {
  47355. }
  47356. const String getUniqueName() const { return categoryName + "_cat"; }
  47357. bool mightContainSubItems() { return true; }
  47358. int getItemHeight() const { return 28; }
  47359. void paintItem (Graphics& g, int width, int height)
  47360. {
  47361. g.setFont (height * 0.6f, Font::bold);
  47362. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47363. g.drawText (categoryName,
  47364. 2, 0, width - 2, height,
  47365. Justification::centredLeft, true);
  47366. }
  47367. void itemOpennessChanged (bool isNowOpen)
  47368. {
  47369. if (isNowOpen)
  47370. {
  47371. if (getNumSubItems() == 0)
  47372. {
  47373. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47374. for (int i = 0; i < commands.size(); ++i)
  47375. {
  47376. if (owner->shouldCommandBeIncluded (commands[i]))
  47377. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47378. }
  47379. }
  47380. }
  47381. else
  47382. {
  47383. clearSubItems();
  47384. }
  47385. }
  47386. juce_UseDebuggingNewOperator
  47387. private:
  47388. KeyMappingEditorComponent* owner;
  47389. String categoryName;
  47390. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47391. KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47392. };
  47393. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47394. const bool showResetToDefaultButton)
  47395. : mappings (mappingManager)
  47396. {
  47397. jassert (mappingManager != 0); // can't be null!
  47398. mappingManager->addChangeListener (this);
  47399. setLinesDrawnForSubItems (false);
  47400. resetButton = 0;
  47401. if (showResetToDefaultButton)
  47402. {
  47403. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  47404. resetButton->addButtonListener (this);
  47405. }
  47406. addAndMakeVisible (tree = new TreeView());
  47407. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  47408. tree->setRootItemVisible (false);
  47409. tree->setDefaultOpenness (true);
  47410. tree->setRootItem (this);
  47411. }
  47412. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  47413. {
  47414. mappings->removeChangeListener (this);
  47415. deleteAllChildren();
  47416. }
  47417. bool KeyMappingEditorComponent::mightContainSubItems()
  47418. {
  47419. return true;
  47420. }
  47421. const String KeyMappingEditorComponent::getUniqueName() const
  47422. {
  47423. return T("keys");
  47424. }
  47425. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  47426. const Colour& textColour)
  47427. {
  47428. setColour (backgroundColourId, mainBackground);
  47429. setColour (textColourId, textColour);
  47430. tree->setColour (TreeView::backgroundColourId, mainBackground);
  47431. }
  47432. void KeyMappingEditorComponent::parentHierarchyChanged()
  47433. {
  47434. changeListenerCallback (0);
  47435. }
  47436. void KeyMappingEditorComponent::resized()
  47437. {
  47438. int h = getHeight();
  47439. if (resetButton != 0)
  47440. {
  47441. const int buttonHeight = 20;
  47442. h -= buttonHeight + 8;
  47443. int x = getWidth() - 8;
  47444. const int y = h + 6;
  47445. resetButton->changeWidthToFitText (buttonHeight);
  47446. resetButton->setTopRightPosition (x, y);
  47447. }
  47448. tree->setBounds (0, 0, getWidth(), h);
  47449. }
  47450. void KeyMappingEditorComponent::buttonClicked (Button* button)
  47451. {
  47452. if (button == resetButton)
  47453. {
  47454. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  47455. TRANS("Reset to defaults"),
  47456. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  47457. TRANS("Reset")))
  47458. {
  47459. mappings->resetToDefaultMappings();
  47460. }
  47461. }
  47462. }
  47463. void KeyMappingEditorComponent::changeListenerCallback (void*)
  47464. {
  47465. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  47466. clearSubItems();
  47467. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  47468. for (int i = 0; i < categories.size(); ++i)
  47469. {
  47470. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  47471. int count = 0;
  47472. for (int j = 0; j < commands.size(); ++j)
  47473. if (shouldCommandBeIncluded (commands[j]))
  47474. ++count;
  47475. if (count > 0)
  47476. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  47477. }
  47478. if (openness != 0)
  47479. tree->restoreOpennessState (*openness);
  47480. }
  47481. class KeyEntryWindow : public AlertWindow
  47482. {
  47483. public:
  47484. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  47485. : AlertWindow (TRANS("New key-mapping"),
  47486. TRANS("Please press a key combination now..."),
  47487. AlertWindow::NoIcon),
  47488. owner (owner_)
  47489. {
  47490. addButton (TRANS("ok"), 1);
  47491. addButton (TRANS("cancel"), 0);
  47492. // (avoid return + escape keys getting processed by the buttons..)
  47493. for (int i = getNumChildComponents(); --i >= 0;)
  47494. getChildComponent (i)->setWantsKeyboardFocus (false);
  47495. setWantsKeyboardFocus (true);
  47496. grabKeyboardFocus();
  47497. }
  47498. ~KeyEntryWindow()
  47499. {
  47500. }
  47501. bool keyPressed (const KeyPress& key)
  47502. {
  47503. lastPress = key;
  47504. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  47505. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  47506. if (previousCommand != 0)
  47507. {
  47508. message << "\n\n"
  47509. << TRANS("(Currently assigned to \"")
  47510. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  47511. << "\")";
  47512. }
  47513. setMessage (message);
  47514. return true;
  47515. }
  47516. bool keyStateChanged (const bool)
  47517. {
  47518. return true;
  47519. }
  47520. KeyPress lastPress;
  47521. juce_UseDebuggingNewOperator
  47522. private:
  47523. KeyMappingEditorComponent* owner;
  47524. KeyEntryWindow (const KeyEntryWindow&);
  47525. KeyEntryWindow& operator= (const KeyEntryWindow&);
  47526. };
  47527. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  47528. {
  47529. KeyEntryWindow entryWindow (this);
  47530. if (entryWindow.runModalLoop() != 0)
  47531. {
  47532. entryWindow.setVisible (false);
  47533. if (entryWindow.lastPress.isValid())
  47534. {
  47535. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  47536. if (previousCommand != 0)
  47537. {
  47538. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  47539. TRANS("Change key-mapping"),
  47540. TRANS("This key is already assigned to the command \"")
  47541. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  47542. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  47543. TRANS("re-assign"),
  47544. TRANS("cancel")))
  47545. {
  47546. return;
  47547. }
  47548. }
  47549. mappings->removeKeyPress (entryWindow.lastPress);
  47550. if (index >= 0)
  47551. mappings->removeKeyPress (commandID, index);
  47552. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  47553. }
  47554. }
  47555. }
  47556. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  47557. {
  47558. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47559. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  47560. }
  47561. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  47562. {
  47563. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47564. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  47565. }
  47566. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  47567. {
  47568. return key.getTextDescription();
  47569. }
  47570. END_JUCE_NAMESPACE
  47571. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47572. /*** Start of inlined file: juce_KeyPress.cpp ***/
  47573. BEGIN_JUCE_NAMESPACE
  47574. KeyPress::KeyPress() throw()
  47575. : keyCode (0),
  47576. mods (0),
  47577. textCharacter (0)
  47578. {
  47579. }
  47580. KeyPress::KeyPress (const int keyCode_,
  47581. const ModifierKeys& mods_,
  47582. const juce_wchar textCharacter_) throw()
  47583. : keyCode (keyCode_),
  47584. mods (mods_),
  47585. textCharacter (textCharacter_)
  47586. {
  47587. }
  47588. KeyPress::KeyPress (const int keyCode_) throw()
  47589. : keyCode (keyCode_),
  47590. textCharacter (0)
  47591. {
  47592. }
  47593. KeyPress::KeyPress (const KeyPress& other) throw()
  47594. : keyCode (other.keyCode),
  47595. mods (other.mods),
  47596. textCharacter (other.textCharacter)
  47597. {
  47598. }
  47599. KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  47600. {
  47601. keyCode = other.keyCode;
  47602. mods = other.mods;
  47603. textCharacter = other.textCharacter;
  47604. return *this;
  47605. }
  47606. bool KeyPress::operator== (const KeyPress& other) const throw()
  47607. {
  47608. return mods.getRawFlags() == other.mods.getRawFlags()
  47609. && (textCharacter == other.textCharacter
  47610. || textCharacter == 0
  47611. || other.textCharacter == 0)
  47612. && (keyCode == other.keyCode
  47613. || (keyCode < 256
  47614. && other.keyCode < 256
  47615. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  47616. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  47617. }
  47618. bool KeyPress::operator!= (const KeyPress& other) const throw()
  47619. {
  47620. return ! operator== (other);
  47621. }
  47622. bool KeyPress::isCurrentlyDown() const throw()
  47623. {
  47624. return isKeyCurrentlyDown (keyCode)
  47625. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  47626. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  47627. }
  47628. struct KeyNameAndCode
  47629. {
  47630. const char* name;
  47631. int code;
  47632. };
  47633. static const KeyNameAndCode keyNameTranslations[] =
  47634. {
  47635. { "spacebar", KeyPress::spaceKey },
  47636. { "return", KeyPress::returnKey },
  47637. { "escape", KeyPress::escapeKey },
  47638. { "backspace", KeyPress::backspaceKey },
  47639. { "cursor left", KeyPress::leftKey },
  47640. { "cursor right", KeyPress::rightKey },
  47641. { "cursor up", KeyPress::upKey },
  47642. { "cursor down", KeyPress::downKey },
  47643. { "page up", KeyPress::pageUpKey },
  47644. { "page down", KeyPress::pageDownKey },
  47645. { "home", KeyPress::homeKey },
  47646. { "end", KeyPress::endKey },
  47647. { "delete", KeyPress::deleteKey },
  47648. { "insert", KeyPress::insertKey },
  47649. { "tab", KeyPress::tabKey },
  47650. { "play", KeyPress::playKey },
  47651. { "stop", KeyPress::stopKey },
  47652. { "fast forward", KeyPress::fastForwardKey },
  47653. { "rewind", KeyPress::rewindKey }
  47654. };
  47655. static const tchar* const numberPadPrefix = T("numpad ");
  47656. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  47657. {
  47658. int modifiers = 0;
  47659. if (desc.containsWholeWordIgnoreCase (T("ctrl"))
  47660. || desc.containsWholeWordIgnoreCase (T("control"))
  47661. || desc.containsWholeWordIgnoreCase (T("ctl")))
  47662. modifiers |= ModifierKeys::ctrlModifier;
  47663. if (desc.containsWholeWordIgnoreCase (T("shift"))
  47664. || desc.containsWholeWordIgnoreCase (T("shft")))
  47665. modifiers |= ModifierKeys::shiftModifier;
  47666. if (desc.containsWholeWordIgnoreCase (T("alt"))
  47667. || desc.containsWholeWordIgnoreCase (T("option")))
  47668. modifiers |= ModifierKeys::altModifier;
  47669. if (desc.containsWholeWordIgnoreCase (T("command"))
  47670. || desc.containsWholeWordIgnoreCase (T("cmd")))
  47671. modifiers |= ModifierKeys::commandModifier;
  47672. int key = 0;
  47673. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  47674. {
  47675. if (desc.containsWholeWordIgnoreCase (String (keyNameTranslations[i].name)))
  47676. {
  47677. key = keyNameTranslations[i].code;
  47678. break;
  47679. }
  47680. }
  47681. if (key == 0)
  47682. {
  47683. // see if it's a numpad key..
  47684. if (desc.containsIgnoreCase (numberPadPrefix))
  47685. {
  47686. const tchar lastChar = desc.trimEnd().getLastCharacter();
  47687. if (lastChar >= T('0') && lastChar <= T('9'))
  47688. key = numberPad0 + lastChar - T('0');
  47689. else if (lastChar == T('+'))
  47690. key = numberPadAdd;
  47691. else if (lastChar == T('-'))
  47692. key = numberPadSubtract;
  47693. else if (lastChar == T('*'))
  47694. key = numberPadMultiply;
  47695. else if (lastChar == T('/'))
  47696. key = numberPadDivide;
  47697. else if (lastChar == T('.'))
  47698. key = numberPadDecimalPoint;
  47699. else if (lastChar == T('='))
  47700. key = numberPadEquals;
  47701. else if (desc.endsWith (T("separator")))
  47702. key = numberPadSeparator;
  47703. else if (desc.endsWith (T("delete")))
  47704. key = numberPadDelete;
  47705. }
  47706. if (key == 0)
  47707. {
  47708. // see if it's a function key..
  47709. for (int i = 1; i <= 12; ++i)
  47710. if (desc.containsWholeWordIgnoreCase (T("f") + String (i)))
  47711. key = F1Key + i - 1;
  47712. if (key == 0)
  47713. {
  47714. // give up and use the hex code..
  47715. const int hexCode = desc.fromFirstOccurrenceOf (T("#"), false, false)
  47716. .toLowerCase()
  47717. .retainCharacters (T("0123456789abcdef"))
  47718. .getHexValue32();
  47719. if (hexCode > 0)
  47720. key = hexCode;
  47721. else
  47722. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  47723. }
  47724. }
  47725. }
  47726. return KeyPress (key, ModifierKeys (modifiers), 0);
  47727. }
  47728. const String KeyPress::getTextDescription() const throw()
  47729. {
  47730. String desc;
  47731. if (keyCode > 0)
  47732. {
  47733. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  47734. // want to store it as being a slash, not shift+whatever.
  47735. if (textCharacter == T('/'))
  47736. return "/";
  47737. if (mods.isCtrlDown())
  47738. desc << "ctrl + ";
  47739. if (mods.isShiftDown())
  47740. desc << "shift + ";
  47741. #if JUCE_MAC
  47742. // only do this on the mac, because on Windows ctrl and command are the same,
  47743. // and this would get confusing
  47744. if (mods.isCommandDown())
  47745. desc << "command + ";
  47746. if (mods.isAltDown())
  47747. desc << "option + ";
  47748. #else
  47749. if (mods.isAltDown())
  47750. desc << "alt + ";
  47751. #endif
  47752. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  47753. if (keyCode == keyNameTranslations[i].code)
  47754. return desc + keyNameTranslations[i].name;
  47755. if (keyCode >= F1Key && keyCode <= F16Key)
  47756. desc << 'F' << (1 + keyCode - F1Key);
  47757. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  47758. desc << numberPadPrefix << (keyCode - numberPad0);
  47759. else if (keyCode >= 33 && keyCode < 176)
  47760. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  47761. else if (keyCode == numberPadAdd)
  47762. desc << numberPadPrefix << '+';
  47763. else if (keyCode == numberPadSubtract)
  47764. desc << numberPadPrefix << '-';
  47765. else if (keyCode == numberPadMultiply)
  47766. desc << numberPadPrefix << '*';
  47767. else if (keyCode == numberPadDivide)
  47768. desc << numberPadPrefix << '/';
  47769. else if (keyCode == numberPadSeparator)
  47770. desc << numberPadPrefix << "separator";
  47771. else if (keyCode == numberPadDecimalPoint)
  47772. desc << numberPadPrefix << '.';
  47773. else if (keyCode == numberPadDelete)
  47774. desc << numberPadPrefix << "delete";
  47775. else
  47776. desc << '#' << String::toHexString (keyCode);
  47777. }
  47778. return desc;
  47779. }
  47780. END_JUCE_NAMESPACE
  47781. /*** End of inlined file: juce_KeyPress.cpp ***/
  47782. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  47783. BEGIN_JUCE_NAMESPACE
  47784. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  47785. : commandManager (commandManager_)
  47786. {
  47787. // A manager is needed to get the descriptions of commands, and will be called when
  47788. // a command is invoked. So you can't leave this null..
  47789. jassert (commandManager_ != 0);
  47790. Desktop::getInstance().addFocusChangeListener (this);
  47791. }
  47792. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  47793. : commandManager (other.commandManager)
  47794. {
  47795. Desktop::getInstance().addFocusChangeListener (this);
  47796. }
  47797. KeyPressMappingSet::~KeyPressMappingSet()
  47798. {
  47799. Desktop::getInstance().removeFocusChangeListener (this);
  47800. }
  47801. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  47802. {
  47803. for (int i = 0; i < mappings.size(); ++i)
  47804. if (mappings.getUnchecked(i)->commandID == commandID)
  47805. return mappings.getUnchecked (i)->keypresses;
  47806. return Array <KeyPress> ();
  47807. }
  47808. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  47809. const KeyPress& newKeyPress,
  47810. int insertIndex) throw()
  47811. {
  47812. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  47813. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  47814. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  47815. && ! newKeyPress.getModifiers().isShiftDown()));
  47816. if (findCommandForKeyPress (newKeyPress) != commandID)
  47817. {
  47818. removeKeyPress (newKeyPress);
  47819. if (newKeyPress.isValid())
  47820. {
  47821. for (int i = mappings.size(); --i >= 0;)
  47822. {
  47823. if (mappings.getUnchecked(i)->commandID == commandID)
  47824. {
  47825. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  47826. sendChangeMessage (this);
  47827. return;
  47828. }
  47829. }
  47830. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47831. if (ci != 0)
  47832. {
  47833. CommandMapping* const cm = new CommandMapping();
  47834. cm->commandID = commandID;
  47835. cm->keypresses.add (newKeyPress);
  47836. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  47837. mappings.add (cm);
  47838. sendChangeMessage (this);
  47839. }
  47840. }
  47841. }
  47842. }
  47843. void KeyPressMappingSet::resetToDefaultMappings() throw()
  47844. {
  47845. mappings.clear();
  47846. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  47847. {
  47848. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  47849. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47850. {
  47851. addKeyPress (ci->commandID,
  47852. ci->defaultKeypresses.getReference (j));
  47853. }
  47854. }
  47855. sendChangeMessage (this);
  47856. }
  47857. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  47858. {
  47859. clearAllKeyPresses (commandID);
  47860. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47861. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47862. {
  47863. addKeyPress (ci->commandID,
  47864. ci->defaultKeypresses.getReference (j));
  47865. }
  47866. }
  47867. void KeyPressMappingSet::clearAllKeyPresses() throw()
  47868. {
  47869. if (mappings.size() > 0)
  47870. {
  47871. sendChangeMessage (this);
  47872. mappings.clear();
  47873. }
  47874. }
  47875. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  47876. {
  47877. for (int i = mappings.size(); --i >= 0;)
  47878. {
  47879. if (mappings.getUnchecked(i)->commandID == commandID)
  47880. {
  47881. mappings.remove (i);
  47882. sendChangeMessage (this);
  47883. }
  47884. }
  47885. }
  47886. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  47887. {
  47888. if (keypress.isValid())
  47889. {
  47890. for (int i = mappings.size(); --i >= 0;)
  47891. {
  47892. CommandMapping* const cm = mappings.getUnchecked(i);
  47893. for (int j = cm->keypresses.size(); --j >= 0;)
  47894. {
  47895. if (keypress == cm->keypresses [j])
  47896. {
  47897. cm->keypresses.remove (j);
  47898. sendChangeMessage (this);
  47899. }
  47900. }
  47901. }
  47902. }
  47903. }
  47904. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  47905. const int keyPressIndex) throw()
  47906. {
  47907. for (int i = mappings.size(); --i >= 0;)
  47908. {
  47909. if (mappings.getUnchecked(i)->commandID == commandID)
  47910. {
  47911. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  47912. sendChangeMessage (this);
  47913. break;
  47914. }
  47915. }
  47916. }
  47917. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  47918. {
  47919. for (int i = 0; i < mappings.size(); ++i)
  47920. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  47921. return mappings.getUnchecked(i)->commandID;
  47922. return 0;
  47923. }
  47924. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  47925. const KeyPress& keyPress) const throw()
  47926. {
  47927. for (int i = mappings.size(); --i >= 0;)
  47928. if (mappings.getUnchecked(i)->commandID == commandID)
  47929. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  47930. return false;
  47931. }
  47932. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  47933. const KeyPress& key,
  47934. const bool isKeyDown,
  47935. const int millisecsSinceKeyPressed,
  47936. Component* const originatingComponent) const
  47937. {
  47938. ApplicationCommandTarget::InvocationInfo info (commandID);
  47939. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  47940. info.isKeyDown = isKeyDown;
  47941. info.keyPress = key;
  47942. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  47943. info.originatingComponent = originatingComponent;
  47944. commandManager->invoke (info, false);
  47945. }
  47946. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  47947. {
  47948. if (xmlVersion.hasTagName (T("KEYMAPPINGS")))
  47949. {
  47950. if (xmlVersion.getBoolAttribute (T("basedOnDefaults"), true))
  47951. {
  47952. // if the XML was created as a set of differences from the default mappings,
  47953. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  47954. resetToDefaultMappings();
  47955. }
  47956. else
  47957. {
  47958. // if the XML was created calling createXml (false), then we need to clear all
  47959. // the keys and treat the xml as describing the entire set of mappings.
  47960. clearAllKeyPresses();
  47961. }
  47962. forEachXmlChildElement (xmlVersion, map)
  47963. {
  47964. const CommandID commandId = map->getStringAttribute (T("commandId")).getHexValue32();
  47965. if (commandId != 0)
  47966. {
  47967. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute (T("key"))));
  47968. if (map->hasTagName (T("MAPPING")))
  47969. {
  47970. addKeyPress (commandId, key);
  47971. }
  47972. else if (map->hasTagName (T("UNMAPPING")))
  47973. {
  47974. if (containsMapping (commandId, key))
  47975. removeKeyPress (key);
  47976. }
  47977. }
  47978. }
  47979. return true;
  47980. }
  47981. return false;
  47982. }
  47983. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  47984. {
  47985. ScopedPointer <KeyPressMappingSet> defaultSet;
  47986. if (saveDifferencesFromDefaultSet)
  47987. {
  47988. defaultSet = new KeyPressMappingSet (commandManager);
  47989. defaultSet->resetToDefaultMappings();
  47990. }
  47991. XmlElement* const doc = new XmlElement (T("KEYMAPPINGS"));
  47992. doc->setAttribute (T("basedOnDefaults"), saveDifferencesFromDefaultSet);
  47993. int i;
  47994. for (i = 0; i < mappings.size(); ++i)
  47995. {
  47996. const CommandMapping* const cm = mappings.getUnchecked(i);
  47997. for (int j = 0; j < cm->keypresses.size(); ++j)
  47998. {
  47999. if (defaultSet == 0
  48000. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48001. {
  48002. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  48003. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48004. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48005. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48006. }
  48007. }
  48008. }
  48009. if (defaultSet != 0)
  48010. {
  48011. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48012. {
  48013. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48014. for (int j = 0; j < cm->keypresses.size(); ++j)
  48015. {
  48016. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48017. {
  48018. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  48019. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48020. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48021. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48022. }
  48023. }
  48024. }
  48025. }
  48026. return doc;
  48027. }
  48028. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48029. Component* originatingComponent)
  48030. {
  48031. bool used = false;
  48032. const CommandID commandID = findCommandForKeyPress (key);
  48033. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48034. if (ci != 0
  48035. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48036. {
  48037. ApplicationCommandInfo info (0);
  48038. if (commandManager->getTargetForCommand (commandID, info) != 0
  48039. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48040. {
  48041. invokeCommand (commandID, key, true, 0, originatingComponent);
  48042. used = true;
  48043. }
  48044. else
  48045. {
  48046. if (originatingComponent != 0)
  48047. originatingComponent->getLookAndFeel().playAlertSound();
  48048. }
  48049. }
  48050. return used;
  48051. }
  48052. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48053. {
  48054. bool used = false;
  48055. const uint32 now = Time::getMillisecondCounter();
  48056. for (int i = mappings.size(); --i >= 0;)
  48057. {
  48058. CommandMapping* const cm = mappings.getUnchecked(i);
  48059. if (cm->wantsKeyUpDownCallbacks)
  48060. {
  48061. for (int j = cm->keypresses.size(); --j >= 0;)
  48062. {
  48063. const KeyPress key (cm->keypresses.getReference (j));
  48064. const bool isDown = key.isCurrentlyDown();
  48065. int keyPressEntryIndex = 0;
  48066. bool wasDown = false;
  48067. for (int k = keysDown.size(); --k >= 0;)
  48068. {
  48069. if (key == keysDown.getUnchecked(k)->key)
  48070. {
  48071. keyPressEntryIndex = k;
  48072. wasDown = true;
  48073. used = true;
  48074. break;
  48075. }
  48076. }
  48077. if (isDown != wasDown)
  48078. {
  48079. int millisecs = 0;
  48080. if (isDown)
  48081. {
  48082. KeyPressTime* const k = new KeyPressTime();
  48083. k->key = key;
  48084. k->timeWhenPressed = now;
  48085. keysDown.add (k);
  48086. }
  48087. else
  48088. {
  48089. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48090. if (now > pressTime)
  48091. millisecs = now - pressTime;
  48092. keysDown.remove (keyPressEntryIndex);
  48093. }
  48094. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48095. used = true;
  48096. }
  48097. }
  48098. }
  48099. }
  48100. return used;
  48101. }
  48102. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48103. {
  48104. if (focusedComponent != 0)
  48105. focusedComponent->keyStateChanged (false);
  48106. }
  48107. END_JUCE_NAMESPACE
  48108. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48109. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48110. BEGIN_JUCE_NAMESPACE
  48111. ModifierKeys::ModifierKeys (const int flags_) throw()
  48112. : flags (flags_)
  48113. {
  48114. }
  48115. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48116. : flags (other.flags)
  48117. {
  48118. }
  48119. ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48120. {
  48121. flags = other.flags;
  48122. return *this;
  48123. }
  48124. ModifierKeys ModifierKeys::currentModifiers;
  48125. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48126. {
  48127. return currentModifiers;
  48128. }
  48129. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48130. {
  48131. int num = 0;
  48132. if (isLeftButtonDown()) ++num;
  48133. if (isRightButtonDown()) ++num;
  48134. if (isMiddleButtonDown()) ++num;
  48135. return num;
  48136. }
  48137. END_JUCE_NAMESPACE
  48138. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48139. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48140. BEGIN_JUCE_NAMESPACE
  48141. struct AnimationTask
  48142. {
  48143. AnimationTask (Component* const comp)
  48144. : component (comp)
  48145. {
  48146. }
  48147. Component::SafePointer<Component> component;
  48148. Rectangle<int> destination;
  48149. int msElapsed, msTotal;
  48150. double startSpeed, midSpeed, endSpeed, lastProgress;
  48151. double left, top, right, bottom;
  48152. bool useTimeslice (const int elapsed)
  48153. {
  48154. if (component == 0)
  48155. return false;
  48156. msElapsed += elapsed;
  48157. double newProgress = msElapsed / (double) msTotal;
  48158. if (newProgress >= 0 && newProgress < 1.0)
  48159. {
  48160. newProgress = timeToDistance (newProgress);
  48161. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48162. jassert (newProgress >= lastProgress);
  48163. lastProgress = newProgress;
  48164. left += (destination.getX() - left) * delta;
  48165. top += (destination.getY() - top) * delta;
  48166. right += (destination.getRight() - right) * delta;
  48167. bottom += (destination.getBottom() - bottom) * delta;
  48168. if (delta < 1.0)
  48169. {
  48170. const Rectangle<int> newBounds (roundToInt (left),
  48171. roundToInt (top),
  48172. roundToInt (right - left),
  48173. roundToInt (bottom - top));
  48174. if (newBounds != destination)
  48175. {
  48176. component->setBounds (newBounds);
  48177. return true;
  48178. }
  48179. }
  48180. }
  48181. component->setBounds (destination);
  48182. return false;
  48183. }
  48184. void moveToFinalDestination()
  48185. {
  48186. if (component != 0)
  48187. component->setBounds (destination);
  48188. }
  48189. private:
  48190. inline double timeToDistance (const double time) const
  48191. {
  48192. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48193. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48194. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48195. }
  48196. };
  48197. ComponentAnimator::ComponentAnimator()
  48198. : lastTime (0)
  48199. {
  48200. }
  48201. ComponentAnimator::~ComponentAnimator()
  48202. {
  48203. cancelAllAnimations (false);
  48204. jassert (tasks.size() == 0);
  48205. }
  48206. void* ComponentAnimator::findTaskFor (Component* const component) const
  48207. {
  48208. for (int i = tasks.size(); --i >= 0;)
  48209. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component.getComponent())
  48210. return tasks.getUnchecked(i);
  48211. return 0;
  48212. }
  48213. void ComponentAnimator::animateComponent (Component* const component,
  48214. const Rectangle<int>& finalPosition,
  48215. const int millisecondsToSpendMoving,
  48216. const double startSpeed,
  48217. const double endSpeed)
  48218. {
  48219. if (component != 0)
  48220. {
  48221. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48222. if (at == 0)
  48223. {
  48224. at = new AnimationTask (component);
  48225. tasks.add (at);
  48226. sendChangeMessage (this);
  48227. }
  48228. at->msElapsed = 0;
  48229. at->lastProgress = 0;
  48230. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48231. at->destination = finalPosition;
  48232. // the speeds must be 0 or greater!
  48233. jassert (startSpeed >= 0 && endSpeed >= 0)
  48234. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48235. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48236. at->midSpeed = invTotalDistance;
  48237. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48238. at->left = component->getX();
  48239. at->top = component->getY();
  48240. at->right = component->getRight();
  48241. at->bottom = component->getBottom();
  48242. if (! isTimerRunning())
  48243. {
  48244. lastTime = Time::getMillisecondCounter();
  48245. startTimer (1000 / 50);
  48246. }
  48247. }
  48248. }
  48249. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48250. {
  48251. for (int i = tasks.size(); --i >= 0;)
  48252. {
  48253. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48254. if (moveComponentsToTheirFinalPositions)
  48255. at->moveToFinalDestination();
  48256. delete at;
  48257. tasks.remove (i);
  48258. sendChangeMessage (this);
  48259. }
  48260. }
  48261. void ComponentAnimator::cancelAnimation (Component* const component,
  48262. const bool moveComponentToItsFinalPosition)
  48263. {
  48264. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48265. if (at != 0)
  48266. {
  48267. if (moveComponentToItsFinalPosition)
  48268. at->moveToFinalDestination();
  48269. tasks.removeValue (at);
  48270. delete at;
  48271. sendChangeMessage (this);
  48272. }
  48273. }
  48274. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48275. {
  48276. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48277. if (at != 0)
  48278. return at->destination;
  48279. else if (component != 0)
  48280. return component->getBounds();
  48281. return Rectangle<int>();
  48282. }
  48283. bool ComponentAnimator::isAnimating (Component* component) const
  48284. {
  48285. return findTaskFor (component) != 0;
  48286. }
  48287. void ComponentAnimator::timerCallback()
  48288. {
  48289. const uint32 timeNow = Time::getMillisecondCounter();
  48290. if (lastTime == 0 || lastTime == timeNow)
  48291. lastTime = timeNow;
  48292. const int elapsed = timeNow - lastTime;
  48293. for (int i = tasks.size(); --i >= 0;)
  48294. {
  48295. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48296. if (! at->useTimeslice (elapsed))
  48297. {
  48298. tasks.remove (i);
  48299. delete at;
  48300. sendChangeMessage (this);
  48301. }
  48302. }
  48303. lastTime = timeNow;
  48304. if (tasks.size() == 0)
  48305. stopTimer();
  48306. }
  48307. END_JUCE_NAMESPACE
  48308. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48309. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48310. BEGIN_JUCE_NAMESPACE
  48311. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48312. : minW (0),
  48313. maxW (0x3fffffff),
  48314. minH (0),
  48315. maxH (0x3fffffff),
  48316. minOffTop (0),
  48317. minOffLeft (0),
  48318. minOffBottom (0),
  48319. minOffRight (0),
  48320. aspectRatio (0.0)
  48321. {
  48322. }
  48323. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48324. {
  48325. }
  48326. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48327. {
  48328. minW = minimumWidth;
  48329. }
  48330. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48331. {
  48332. maxW = maximumWidth;
  48333. }
  48334. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48335. {
  48336. minH = minimumHeight;
  48337. }
  48338. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48339. {
  48340. maxH = maximumHeight;
  48341. }
  48342. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48343. {
  48344. jassert (maxW >= minimumWidth);
  48345. jassert (maxH >= minimumHeight);
  48346. jassert (minimumWidth > 0 && minimumHeight > 0);
  48347. minW = minimumWidth;
  48348. minH = minimumHeight;
  48349. if (minW > maxW)
  48350. maxW = minW;
  48351. if (minH > maxH)
  48352. maxH = minH;
  48353. }
  48354. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48355. {
  48356. jassert (maximumWidth >= minW);
  48357. jassert (maximumHeight >= minH);
  48358. jassert (maximumWidth > 0 && maximumHeight > 0);
  48359. maxW = jmax (minW, maximumWidth);
  48360. maxH = jmax (minH, maximumHeight);
  48361. }
  48362. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48363. const int minimumHeight,
  48364. const int maximumWidth,
  48365. const int maximumHeight) throw()
  48366. {
  48367. jassert (maximumWidth >= minimumWidth);
  48368. jassert (maximumHeight >= minimumHeight);
  48369. jassert (maximumWidth > 0 && maximumHeight > 0);
  48370. jassert (minimumWidth > 0 && minimumHeight > 0);
  48371. minW = jmax (0, minimumWidth);
  48372. minH = jmax (0, minimumHeight);
  48373. maxW = jmax (minW, maximumWidth);
  48374. maxH = jmax (minH, maximumHeight);
  48375. }
  48376. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48377. const int minimumWhenOffTheLeft,
  48378. const int minimumWhenOffTheBottom,
  48379. const int minimumWhenOffTheRight) throw()
  48380. {
  48381. minOffTop = minimumWhenOffTheTop;
  48382. minOffLeft = minimumWhenOffTheLeft;
  48383. minOffBottom = minimumWhenOffTheBottom;
  48384. minOffRight = minimumWhenOffTheRight;
  48385. }
  48386. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48387. {
  48388. aspectRatio = jmax (0.0, widthOverHeight);
  48389. }
  48390. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48391. {
  48392. return aspectRatio;
  48393. }
  48394. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48395. const Rectangle<int>& targetBounds,
  48396. const bool isStretchingTop,
  48397. const bool isStretchingLeft,
  48398. const bool isStretchingBottom,
  48399. const bool isStretchingRight)
  48400. {
  48401. jassert (component != 0);
  48402. Rectangle<int> limits, bounds (targetBounds);
  48403. BorderSize border;
  48404. Component* const parent = component->getParentComponent();
  48405. if (parent == 0)
  48406. {
  48407. ComponentPeer* peer = component->getPeer();
  48408. if (peer != 0)
  48409. border = peer->getFrameSize();
  48410. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre());
  48411. }
  48412. else
  48413. {
  48414. limits.setSize (parent->getWidth(), parent->getHeight());
  48415. }
  48416. border.addTo (bounds);
  48417. checkBounds (bounds,
  48418. border.addedTo (component->getBounds()), limits,
  48419. isStretchingTop, isStretchingLeft,
  48420. isStretchingBottom, isStretchingRight);
  48421. border.subtractFrom (bounds);
  48422. applyBoundsToComponent (component, bounds);
  48423. }
  48424. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  48425. {
  48426. setBoundsForComponent (component, component->getBounds(),
  48427. false, false, false, false);
  48428. }
  48429. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  48430. const Rectangle<int>& bounds)
  48431. {
  48432. component->setBounds (bounds);
  48433. }
  48434. void ComponentBoundsConstrainer::resizeStart()
  48435. {
  48436. }
  48437. void ComponentBoundsConstrainer::resizeEnd()
  48438. {
  48439. }
  48440. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  48441. const Rectangle<int>& old,
  48442. const Rectangle<int>& limits,
  48443. const bool isStretchingTop,
  48444. const bool isStretchingLeft,
  48445. const bool isStretchingBottom,
  48446. const bool isStretchingRight)
  48447. {
  48448. int x = bounds.getX();
  48449. int y = bounds.getY();
  48450. int w = bounds.getWidth();
  48451. int h = bounds.getHeight();
  48452. // constrain the size if it's being stretched..
  48453. if (isStretchingLeft)
  48454. {
  48455. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  48456. w = old.getRight() - x;
  48457. }
  48458. if (isStretchingRight)
  48459. {
  48460. w = jlimit (minW, maxW, w);
  48461. }
  48462. if (isStretchingTop)
  48463. {
  48464. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  48465. h = old.getBottom() - y;
  48466. }
  48467. if (isStretchingBottom)
  48468. {
  48469. h = jlimit (minH, maxH, h);
  48470. }
  48471. // constrain the aspect ratio if one has been specified..
  48472. if (aspectRatio > 0.0 && w > 0 && h > 0)
  48473. {
  48474. bool adjustWidth;
  48475. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48476. {
  48477. adjustWidth = true;
  48478. }
  48479. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48480. {
  48481. adjustWidth = false;
  48482. }
  48483. else
  48484. {
  48485. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  48486. const double newRatio = fabs (w / (double) h);
  48487. adjustWidth = (oldRatio > newRatio);
  48488. }
  48489. if (adjustWidth)
  48490. {
  48491. w = roundToInt (h * aspectRatio);
  48492. if (w > maxW || w < minW)
  48493. {
  48494. w = jlimit (minW, maxW, w);
  48495. h = roundToInt (w / aspectRatio);
  48496. }
  48497. }
  48498. else
  48499. {
  48500. h = roundToInt (w / aspectRatio);
  48501. if (h > maxH || h < minH)
  48502. {
  48503. h = jlimit (minH, maxH, h);
  48504. w = roundToInt (h * aspectRatio);
  48505. }
  48506. }
  48507. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48508. {
  48509. x = old.getX() + (old.getWidth() - w) / 2;
  48510. }
  48511. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48512. {
  48513. y = old.getY() + (old.getHeight() - h) / 2;
  48514. }
  48515. else
  48516. {
  48517. if (isStretchingLeft)
  48518. x = old.getRight() - w;
  48519. if (isStretchingTop)
  48520. y = old.getBottom() - h;
  48521. }
  48522. }
  48523. // ...and constrain the position if limits have been set for that.
  48524. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  48525. {
  48526. if (minOffTop > 0)
  48527. {
  48528. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  48529. if (y < limit)
  48530. {
  48531. if (isStretchingTop)
  48532. h -= (limit - y);
  48533. y = limit;
  48534. }
  48535. }
  48536. if (minOffLeft > 0)
  48537. {
  48538. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  48539. if (x < limit)
  48540. {
  48541. if (isStretchingLeft)
  48542. w -= (limit - x);
  48543. x = limit;
  48544. }
  48545. }
  48546. if (minOffBottom > 0)
  48547. {
  48548. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  48549. if (y > limit)
  48550. {
  48551. if (isStretchingBottom)
  48552. h += (limit - y);
  48553. else
  48554. y = limit;
  48555. }
  48556. }
  48557. if (minOffRight > 0)
  48558. {
  48559. const int limit = limits.getRight() - jmin (minOffRight, w);
  48560. if (x > limit)
  48561. {
  48562. if (isStretchingRight)
  48563. w += (limit - x);
  48564. else
  48565. x = limit;
  48566. }
  48567. }
  48568. }
  48569. jassert (w >= 0 && h >= 0);
  48570. bounds = Rectangle<int> (x, y, w, h);
  48571. }
  48572. END_JUCE_NAMESPACE
  48573. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48574. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48575. BEGIN_JUCE_NAMESPACE
  48576. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  48577. : component (component_),
  48578. lastPeer (0),
  48579. reentrant (false)
  48580. {
  48581. jassert (component != 0); // can't use this with a null pointer..
  48582. component->addComponentListener (this);
  48583. registerWithParentComps();
  48584. }
  48585. ComponentMovementWatcher::~ComponentMovementWatcher()
  48586. {
  48587. component->removeComponentListener (this);
  48588. unregister();
  48589. }
  48590. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  48591. {
  48592. // agh! don't delete the target component without deleting this object first!
  48593. jassert (component != 0);
  48594. if (! reentrant)
  48595. {
  48596. reentrant = true;
  48597. ComponentPeer* const peer = component->getPeer();
  48598. if (peer != lastPeer)
  48599. {
  48600. componentPeerChanged();
  48601. if (component == 0)
  48602. return;
  48603. lastPeer = peer;
  48604. }
  48605. unregister();
  48606. registerWithParentComps();
  48607. reentrant = false;
  48608. componentMovedOrResized (*component, true, true);
  48609. }
  48610. }
  48611. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  48612. {
  48613. // agh! don't delete the target component without deleting this object first!
  48614. jassert (component != 0);
  48615. if (wasMoved)
  48616. {
  48617. const Point<int> pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point<int>()));
  48618. wasMoved = lastBounds.getPosition() != pos;
  48619. lastBounds.setPosition (pos);
  48620. }
  48621. wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
  48622. lastBounds.setSize (component->getWidth(), component->getHeight());
  48623. if (wasMoved || wasResized)
  48624. componentMovedOrResized (wasMoved, wasResized);
  48625. }
  48626. void ComponentMovementWatcher::registerWithParentComps() throw()
  48627. {
  48628. Component* p = component->getParentComponent();
  48629. while (p != 0)
  48630. {
  48631. p->addComponentListener (this);
  48632. registeredParentComps.add (p);
  48633. p = p->getParentComponent();
  48634. }
  48635. }
  48636. void ComponentMovementWatcher::unregister() throw()
  48637. {
  48638. for (int i = registeredParentComps.size(); --i >= 0;)
  48639. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  48640. registeredParentComps.clear();
  48641. }
  48642. END_JUCE_NAMESPACE
  48643. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48644. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  48645. BEGIN_JUCE_NAMESPACE
  48646. GroupComponent::GroupComponent (const String& componentName,
  48647. const String& labelText)
  48648. : Component (componentName),
  48649. text (labelText),
  48650. justification (Justification::left)
  48651. {
  48652. setInterceptsMouseClicks (false, true);
  48653. }
  48654. GroupComponent::~GroupComponent()
  48655. {
  48656. }
  48657. void GroupComponent::setText (const String& newText) throw()
  48658. {
  48659. if (text != newText)
  48660. {
  48661. text = newText;
  48662. repaint();
  48663. }
  48664. }
  48665. const String GroupComponent::getText() const throw()
  48666. {
  48667. return text;
  48668. }
  48669. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  48670. {
  48671. if (justification.getFlags() != newJustification.getFlags())
  48672. {
  48673. justification = newJustification;
  48674. repaint();
  48675. }
  48676. }
  48677. void GroupComponent::paint (Graphics& g)
  48678. {
  48679. getLookAndFeel()
  48680. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  48681. text, justification,
  48682. *this);
  48683. }
  48684. void GroupComponent::enablementChanged()
  48685. {
  48686. repaint();
  48687. }
  48688. void GroupComponent::colourChanged()
  48689. {
  48690. repaint();
  48691. }
  48692. END_JUCE_NAMESPACE
  48693. /*** End of inlined file: juce_GroupComponent.cpp ***/
  48694. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  48695. BEGIN_JUCE_NAMESPACE
  48696. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  48697. : DocumentWindow (String::empty, backgroundColour,
  48698. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  48699. {
  48700. }
  48701. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  48702. {
  48703. }
  48704. void MultiDocumentPanelWindow::maximiseButtonPressed()
  48705. {
  48706. MultiDocumentPanel* const owner = getOwner();
  48707. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48708. if (owner != 0)
  48709. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  48710. }
  48711. void MultiDocumentPanelWindow::closeButtonPressed()
  48712. {
  48713. MultiDocumentPanel* const owner = getOwner();
  48714. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48715. if (owner != 0)
  48716. owner->closeDocument (getContentComponent(), true);
  48717. }
  48718. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  48719. {
  48720. DocumentWindow::activeWindowStatusChanged();
  48721. updateOrder();
  48722. }
  48723. void MultiDocumentPanelWindow::broughtToFront()
  48724. {
  48725. DocumentWindow::broughtToFront();
  48726. updateOrder();
  48727. }
  48728. void MultiDocumentPanelWindow::updateOrder()
  48729. {
  48730. MultiDocumentPanel* const owner = getOwner();
  48731. if (owner != 0)
  48732. owner->updateOrder();
  48733. }
  48734. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  48735. {
  48736. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48737. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48738. }
  48739. class MDITabbedComponentInternal : public TabbedComponent
  48740. {
  48741. public:
  48742. MDITabbedComponentInternal()
  48743. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  48744. {
  48745. }
  48746. ~MDITabbedComponentInternal()
  48747. {
  48748. }
  48749. void currentTabChanged (const int, const String&)
  48750. {
  48751. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48752. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48753. if (owner != 0)
  48754. owner->updateOrder();
  48755. }
  48756. };
  48757. MultiDocumentPanel::MultiDocumentPanel()
  48758. : mode (MaximisedWindowsWithTabs),
  48759. tabComponent (0),
  48760. backgroundColour (Colours::lightblue),
  48761. maximumNumDocuments (0),
  48762. numDocsBeforeTabsUsed (0)
  48763. {
  48764. setOpaque (true);
  48765. }
  48766. MultiDocumentPanel::~MultiDocumentPanel()
  48767. {
  48768. closeAllDocuments (false);
  48769. }
  48770. static bool shouldDeleteComp (Component* const c)
  48771. {
  48772. return c->getProperties() ["mdiDocumentDelete_"];
  48773. }
  48774. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  48775. {
  48776. while (components.size() > 0)
  48777. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  48778. return false;
  48779. return true;
  48780. }
  48781. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  48782. {
  48783. return new MultiDocumentPanelWindow (backgroundColour);
  48784. }
  48785. void MultiDocumentPanel::addWindow (Component* component)
  48786. {
  48787. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  48788. dw->setResizable (true, false);
  48789. dw->setContentComponent (component, false, true);
  48790. dw->setName (component->getName());
  48791. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  48792. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  48793. int x = 4;
  48794. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  48795. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  48796. x += 16;
  48797. dw->setTopLeftPosition (x, x);
  48798. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  48799. if (pos.toString().isNotEmpty())
  48800. dw->restoreWindowStateFromString (pos.toString());
  48801. addAndMakeVisible (dw);
  48802. dw->toFront (true);
  48803. }
  48804. bool MultiDocumentPanel::addDocument (Component* const component,
  48805. const Colour& docColour,
  48806. const bool deleteWhenRemoved)
  48807. {
  48808. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  48809. // with a frame-within-a-frame! Just pass in the bare content component.
  48810. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  48811. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  48812. return false;
  48813. components.add (component);
  48814. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  48815. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  48816. component->addComponentListener (this);
  48817. if (mode == FloatingWindows)
  48818. {
  48819. if (isFullscreenWhenOneDocument())
  48820. {
  48821. if (components.size() == 1)
  48822. {
  48823. addAndMakeVisible (component);
  48824. }
  48825. else
  48826. {
  48827. if (components.size() == 2)
  48828. addWindow (components.getFirst());
  48829. addWindow (component);
  48830. }
  48831. }
  48832. else
  48833. {
  48834. addWindow (component);
  48835. }
  48836. }
  48837. else
  48838. {
  48839. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  48840. {
  48841. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  48842. Array <Component*> temp (components);
  48843. for (int i = 0; i < temp.size(); ++i)
  48844. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  48845. resized();
  48846. }
  48847. else
  48848. {
  48849. if (tabComponent != 0)
  48850. tabComponent->addTab (component->getName(), docColour, component, false);
  48851. else
  48852. addAndMakeVisible (component);
  48853. }
  48854. setActiveDocument (component);
  48855. }
  48856. resized();
  48857. activeDocumentChanged();
  48858. return true;
  48859. }
  48860. bool MultiDocumentPanel::closeDocument (Component* component,
  48861. const bool checkItsOkToCloseFirst)
  48862. {
  48863. if (components.contains (component))
  48864. {
  48865. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  48866. return false;
  48867. component->removeComponentListener (this);
  48868. const bool shouldDelete = shouldDeleteComp (component);
  48869. component->getProperties().remove ("mdiDocumentDelete_");
  48870. component->getProperties().remove ("mdiDocumentBkg_");
  48871. if (mode == FloatingWindows)
  48872. {
  48873. for (int i = getNumChildComponents(); --i >= 0;)
  48874. {
  48875. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48876. if (dw != 0 && dw->getContentComponent() == component)
  48877. {
  48878. dw->setContentComponent (0, false);
  48879. delete dw;
  48880. break;
  48881. }
  48882. }
  48883. if (shouldDelete)
  48884. delete component;
  48885. components.removeValue (component);
  48886. if (isFullscreenWhenOneDocument() && components.size() == 1)
  48887. {
  48888. for (int i = getNumChildComponents(); --i >= 0;)
  48889. {
  48890. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48891. if (dw != 0)
  48892. {
  48893. dw->setContentComponent (0, false);
  48894. delete dw;
  48895. }
  48896. }
  48897. addAndMakeVisible (components.getFirst());
  48898. }
  48899. }
  48900. else
  48901. {
  48902. jassert (components.indexOf (component) >= 0);
  48903. if (tabComponent != 0)
  48904. {
  48905. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48906. if (tabComponent->getTabContentComponent (i) == component)
  48907. tabComponent->removeTab (i);
  48908. }
  48909. else
  48910. {
  48911. removeChildComponent (component);
  48912. }
  48913. if (shouldDelete)
  48914. delete component;
  48915. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  48916. deleteAndZero (tabComponent);
  48917. components.removeValue (component);
  48918. if (components.size() > 0 && tabComponent == 0)
  48919. addAndMakeVisible (components.getFirst());
  48920. }
  48921. resized();
  48922. activeDocumentChanged();
  48923. }
  48924. else
  48925. {
  48926. jassertfalse
  48927. }
  48928. return true;
  48929. }
  48930. int MultiDocumentPanel::getNumDocuments() const throw()
  48931. {
  48932. return components.size();
  48933. }
  48934. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  48935. {
  48936. return components [index];
  48937. }
  48938. Component* MultiDocumentPanel::getActiveDocument() const throw()
  48939. {
  48940. if (mode == FloatingWindows)
  48941. {
  48942. for (int i = getNumChildComponents(); --i >= 0;)
  48943. {
  48944. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48945. if (dw != 0 && dw->isActiveWindow())
  48946. return dw->getContentComponent();
  48947. }
  48948. }
  48949. return components.getLast();
  48950. }
  48951. void MultiDocumentPanel::setActiveDocument (Component* component)
  48952. {
  48953. if (mode == FloatingWindows)
  48954. {
  48955. component = getContainerComp (component);
  48956. if (component != 0)
  48957. component->toFront (true);
  48958. }
  48959. else if (tabComponent != 0)
  48960. {
  48961. jassert (components.indexOf (component) >= 0);
  48962. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48963. {
  48964. if (tabComponent->getTabContentComponent (i) == component)
  48965. {
  48966. tabComponent->setCurrentTabIndex (i);
  48967. break;
  48968. }
  48969. }
  48970. }
  48971. else
  48972. {
  48973. component->grabKeyboardFocus();
  48974. }
  48975. }
  48976. void MultiDocumentPanel::activeDocumentChanged()
  48977. {
  48978. }
  48979. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  48980. {
  48981. maximumNumDocuments = newNumber;
  48982. }
  48983. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  48984. {
  48985. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  48986. }
  48987. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  48988. {
  48989. return numDocsBeforeTabsUsed != 0;
  48990. }
  48991. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  48992. {
  48993. if (mode != newLayoutMode)
  48994. {
  48995. mode = newLayoutMode;
  48996. if (mode == FloatingWindows)
  48997. {
  48998. deleteAndZero (tabComponent);
  48999. }
  49000. else
  49001. {
  49002. for (int i = getNumChildComponents(); --i >= 0;)
  49003. {
  49004. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49005. if (dw != 0)
  49006. {
  49007. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  49008. dw->setContentComponent (0, false);
  49009. delete dw;
  49010. }
  49011. }
  49012. }
  49013. resized();
  49014. const Array <Component*> tempComps (components);
  49015. components.clear();
  49016. for (int i = 0; i < tempComps.size(); ++i)
  49017. {
  49018. Component* const c = tempComps.getUnchecked(i);
  49019. addDocument (c,
  49020. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49021. shouldDeleteComp (c));
  49022. }
  49023. }
  49024. }
  49025. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49026. {
  49027. if (backgroundColour != newBackgroundColour)
  49028. {
  49029. backgroundColour = newBackgroundColour;
  49030. setOpaque (newBackgroundColour.isOpaque());
  49031. repaint();
  49032. }
  49033. }
  49034. void MultiDocumentPanel::paint (Graphics& g)
  49035. {
  49036. g.fillAll (backgroundColour);
  49037. }
  49038. void MultiDocumentPanel::resized()
  49039. {
  49040. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49041. {
  49042. for (int i = getNumChildComponents(); --i >= 0;)
  49043. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49044. }
  49045. setWantsKeyboardFocus (components.size() == 0);
  49046. }
  49047. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49048. {
  49049. if (mode == FloatingWindows)
  49050. {
  49051. for (int i = 0; i < getNumChildComponents(); ++i)
  49052. {
  49053. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49054. if (dw != 0 && dw->getContentComponent() == c)
  49055. {
  49056. c = dw;
  49057. break;
  49058. }
  49059. }
  49060. }
  49061. return c;
  49062. }
  49063. void MultiDocumentPanel::componentNameChanged (Component&)
  49064. {
  49065. if (mode == FloatingWindows)
  49066. {
  49067. for (int i = 0; i < getNumChildComponents(); ++i)
  49068. {
  49069. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49070. if (dw != 0)
  49071. dw->setName (dw->getContentComponent()->getName());
  49072. }
  49073. }
  49074. else if (tabComponent != 0)
  49075. {
  49076. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49077. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49078. }
  49079. }
  49080. void MultiDocumentPanel::updateOrder()
  49081. {
  49082. const Array <Component*> oldList (components);
  49083. if (mode == FloatingWindows)
  49084. {
  49085. components.clear();
  49086. for (int i = 0; i < getNumChildComponents(); ++i)
  49087. {
  49088. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49089. if (dw != 0)
  49090. components.add (dw->getContentComponent());
  49091. }
  49092. }
  49093. else
  49094. {
  49095. if (tabComponent != 0)
  49096. {
  49097. Component* const current = tabComponent->getCurrentContentComponent();
  49098. if (current != 0)
  49099. {
  49100. components.removeValue (current);
  49101. components.add (current);
  49102. }
  49103. }
  49104. }
  49105. if (components != oldList)
  49106. activeDocumentChanged();
  49107. }
  49108. END_JUCE_NAMESPACE
  49109. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49110. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49111. BEGIN_JUCE_NAMESPACE
  49112. enum ResizableBorderComponentZones
  49113. {
  49114. zoneL = 1,
  49115. zoneR = 2,
  49116. zoneT = 4,
  49117. zoneB = 8
  49118. };
  49119. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49120. ComponentBoundsConstrainer* const constrainer_)
  49121. : component (componentToResize),
  49122. constrainer (constrainer_),
  49123. borderSize (5),
  49124. mouseZone (0)
  49125. {
  49126. }
  49127. ResizableBorderComponent::~ResizableBorderComponent()
  49128. {
  49129. }
  49130. void ResizableBorderComponent::paint (Graphics& g)
  49131. {
  49132. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49133. }
  49134. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49135. {
  49136. updateMouseZone (e);
  49137. }
  49138. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49139. {
  49140. updateMouseZone (e);
  49141. }
  49142. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49143. {
  49144. if (component == 0)
  49145. {
  49146. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49147. return;
  49148. }
  49149. updateMouseZone (e);
  49150. originalBounds = component->getBounds();
  49151. if (constrainer != 0)
  49152. constrainer->resizeStart();
  49153. }
  49154. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49155. {
  49156. if (component == 0)
  49157. {
  49158. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49159. return;
  49160. }
  49161. Rectangle<int> bounds (originalBounds);
  49162. if ((mouseZone & zoneL) != 0)
  49163. bounds.setLeft (bounds.getX() + e.getDistanceFromDragStartX());
  49164. if ((mouseZone & zoneT) != 0)
  49165. bounds.setTop (bounds.getY() + e.getDistanceFromDragStartY());
  49166. if ((mouseZone & zoneR) != 0)
  49167. bounds.setWidth (bounds.getWidth() + e.getDistanceFromDragStartX());
  49168. if ((mouseZone & zoneB) != 0)
  49169. bounds.setHeight (bounds.getHeight() + e.getDistanceFromDragStartY());
  49170. if (constrainer != 0)
  49171. constrainer->setBoundsForComponent (component, bounds,
  49172. (mouseZone & zoneT) != 0,
  49173. (mouseZone & zoneL) != 0,
  49174. (mouseZone & zoneB) != 0,
  49175. (mouseZone & zoneR) != 0);
  49176. else
  49177. component->setBounds (bounds);
  49178. }
  49179. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49180. {
  49181. if (constrainer != 0)
  49182. constrainer->resizeEnd();
  49183. }
  49184. bool ResizableBorderComponent::hitTest (int x, int y)
  49185. {
  49186. return x < borderSize.getLeft()
  49187. || x >= getWidth() - borderSize.getRight()
  49188. || y < borderSize.getTop()
  49189. || y >= getHeight() - borderSize.getBottom();
  49190. }
  49191. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize)
  49192. {
  49193. if (borderSize != newBorderSize)
  49194. {
  49195. borderSize = newBorderSize;
  49196. repaint();
  49197. }
  49198. }
  49199. const BorderSize ResizableBorderComponent::getBorderThickness() const
  49200. {
  49201. return borderSize;
  49202. }
  49203. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e)
  49204. {
  49205. int newZone = 0;
  49206. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49207. {
  49208. if (e.x < jmax (borderSize.getLeft(),
  49209. proportionOfWidth (0.1f),
  49210. jmin (10, proportionOfWidth (0.33f))))
  49211. newZone |= zoneL;
  49212. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49213. proportionOfWidth (0.9f),
  49214. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49215. newZone |= zoneR;
  49216. if (e.y < jmax (borderSize.getTop(),
  49217. proportionOfHeight (0.1f),
  49218. jmin (10, proportionOfHeight (0.33f))))
  49219. newZone |= zoneT;
  49220. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49221. proportionOfHeight (0.9f),
  49222. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49223. newZone |= zoneB;
  49224. }
  49225. if (mouseZone != newZone)
  49226. {
  49227. mouseZone = newZone;
  49228. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49229. switch (newZone)
  49230. {
  49231. case (zoneL | zoneT): mc = MouseCursor::TopLeftCornerResizeCursor; break;
  49232. case zoneT: mc = MouseCursor::TopEdgeResizeCursor; break;
  49233. case (zoneR | zoneT): mc = MouseCursor::TopRightCornerResizeCursor; break;
  49234. case zoneL: mc = MouseCursor::LeftEdgeResizeCursor; break;
  49235. case zoneR: mc = MouseCursor::RightEdgeResizeCursor; break;
  49236. case (zoneL | zoneB): mc = MouseCursor::BottomLeftCornerResizeCursor; break;
  49237. case zoneB: mc = MouseCursor::BottomEdgeResizeCursor; break;
  49238. case (zoneR | zoneB): mc = MouseCursor::BottomRightCornerResizeCursor; break;
  49239. default: break;
  49240. }
  49241. setMouseCursor (mc);
  49242. }
  49243. }
  49244. END_JUCE_NAMESPACE
  49245. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49246. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49247. BEGIN_JUCE_NAMESPACE
  49248. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49249. ComponentBoundsConstrainer* const constrainer_)
  49250. : component (componentToResize),
  49251. constrainer (constrainer_)
  49252. {
  49253. setRepaintsOnMouseActivity (true);
  49254. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49255. }
  49256. ResizableCornerComponent::~ResizableCornerComponent()
  49257. {
  49258. }
  49259. void ResizableCornerComponent::paint (Graphics& g)
  49260. {
  49261. getLookAndFeel()
  49262. .drawCornerResizer (g, getWidth(), getHeight(),
  49263. isMouseOverOrDragging(),
  49264. isMouseButtonDown());
  49265. }
  49266. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49267. {
  49268. if (component == 0)
  49269. {
  49270. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49271. return;
  49272. }
  49273. originalBounds = component->getBounds();
  49274. if (constrainer != 0)
  49275. constrainer->resizeStart();
  49276. }
  49277. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49278. {
  49279. if (component == 0)
  49280. {
  49281. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49282. return;
  49283. }
  49284. Rectangle<int> r (originalBounds.withSize (originalBounds.getWidth() + e.getDistanceFromDragStartX(),
  49285. originalBounds.getHeight() + e.getDistanceFromDragStartY()));
  49286. if (constrainer != 0)
  49287. constrainer->setBoundsForComponent (component, r, false, false, true, true);
  49288. else
  49289. component->setBounds (r);
  49290. }
  49291. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49292. {
  49293. if (constrainer != 0)
  49294. constrainer->resizeStart();
  49295. }
  49296. bool ResizableCornerComponent::hitTest (int x, int y)
  49297. {
  49298. if (getWidth() <= 0)
  49299. return false;
  49300. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49301. return y >= yAtX - getHeight() / 4;
  49302. }
  49303. END_JUCE_NAMESPACE
  49304. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49305. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49306. BEGIN_JUCE_NAMESPACE
  49307. class ScrollbarButton : public Button
  49308. {
  49309. public:
  49310. int direction;
  49311. ScrollbarButton (const int direction_,
  49312. ScrollBar& owner_) throw()
  49313. : Button (String::empty),
  49314. direction (direction_),
  49315. owner (owner_)
  49316. {
  49317. setWantsKeyboardFocus (false);
  49318. }
  49319. ~ScrollbarButton()
  49320. {
  49321. }
  49322. void paintButton (Graphics& g,
  49323. bool isMouseOver,
  49324. bool isMouseDown)
  49325. {
  49326. getLookAndFeel()
  49327. .drawScrollbarButton (g, owner,
  49328. getWidth(), getHeight(),
  49329. direction,
  49330. owner.isVertical(),
  49331. isMouseOver, isMouseDown);
  49332. }
  49333. void clicked()
  49334. {
  49335. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49336. }
  49337. juce_UseDebuggingNewOperator
  49338. private:
  49339. ScrollBar& owner;
  49340. ScrollbarButton (const ScrollbarButton&);
  49341. ScrollbarButton& operator= (const ScrollbarButton&);
  49342. };
  49343. ScrollBar::ScrollBar (const bool vertical_,
  49344. const bool buttonsAreVisible)
  49345. : minimum (0.0),
  49346. maximum (1.0),
  49347. rangeStart (0.0),
  49348. rangeSize (0.1),
  49349. singleStepSize (0.1),
  49350. thumbAreaStart (0),
  49351. thumbAreaSize (0),
  49352. thumbStart (0),
  49353. thumbSize (0),
  49354. initialDelayInMillisecs (100),
  49355. repeatDelayInMillisecs (50),
  49356. minimumDelayInMillisecs (10),
  49357. vertical (vertical_),
  49358. isDraggingThumb (false),
  49359. alwaysVisible (false),
  49360. upButton (0),
  49361. downButton (0)
  49362. {
  49363. setButtonVisibility (buttonsAreVisible);
  49364. setRepaintsOnMouseActivity (true);
  49365. setFocusContainer (true);
  49366. }
  49367. ScrollBar::~ScrollBar()
  49368. {
  49369. deleteAllChildren();
  49370. }
  49371. void ScrollBar::setRangeLimits (const double newMinimum,
  49372. const double newMaximum) throw()
  49373. {
  49374. minimum = newMinimum;
  49375. maximum = newMaximum;
  49376. jassert (maximum >= minimum); // these can't be the wrong way round!
  49377. setCurrentRangeStart (rangeStart);
  49378. updateThumbPosition();
  49379. }
  49380. void ScrollBar::setCurrentRange (double newStart,
  49381. double newSize) throw()
  49382. {
  49383. newSize = jlimit (0.0, maximum - minimum, newSize);
  49384. newStart = jlimit (minimum, maximum - newSize, newStart);
  49385. if (rangeStart != newStart
  49386. || rangeSize != newSize)
  49387. {
  49388. rangeStart = newStart;
  49389. rangeSize = newSize;
  49390. updateThumbPosition();
  49391. triggerAsyncUpdate();
  49392. }
  49393. }
  49394. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  49395. {
  49396. setCurrentRange (newStart, rangeSize);
  49397. }
  49398. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  49399. {
  49400. singleStepSize = newSingleStepSize;
  49401. }
  49402. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  49403. {
  49404. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  49405. }
  49406. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  49407. {
  49408. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  49409. }
  49410. void ScrollBar::scrollToTop() throw()
  49411. {
  49412. setCurrentRangeStart (minimum);
  49413. }
  49414. void ScrollBar::scrollToBottom() throw()
  49415. {
  49416. setCurrentRangeStart (maximum - rangeSize);
  49417. }
  49418. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  49419. const int repeatDelayInMillisecs_,
  49420. const int minimumDelayInMillisecs_) throw()
  49421. {
  49422. initialDelayInMillisecs = initialDelayInMillisecs_;
  49423. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  49424. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  49425. if (upButton != 0)
  49426. {
  49427. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49428. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49429. }
  49430. }
  49431. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  49432. {
  49433. listeners.add (listener);
  49434. }
  49435. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  49436. {
  49437. listeners.remove (listener);
  49438. }
  49439. void ScrollBar::handleAsyncUpdate()
  49440. {
  49441. listeners.call (&ScrollBarListener::scrollBarMoved, this, rangeStart);
  49442. }
  49443. void ScrollBar::updateThumbPosition() throw()
  49444. {
  49445. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  49446. : thumbAreaSize);
  49447. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49448. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  49449. if (newThumbSize > thumbAreaSize)
  49450. newThumbSize = thumbAreaSize;
  49451. int newThumbStart = thumbAreaStart;
  49452. if (maximum - minimum > rangeSize)
  49453. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  49454. / ((maximum - minimum) - rangeSize));
  49455. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  49456. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  49457. {
  49458. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  49459. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  49460. if (vertical)
  49461. repaint (0, repaintStart, getWidth(), repaintSize);
  49462. else
  49463. repaint (repaintStart, 0, repaintSize, getHeight());
  49464. thumbStart = newThumbStart;
  49465. thumbSize = newThumbSize;
  49466. }
  49467. }
  49468. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  49469. {
  49470. if (vertical != shouldBeVertical)
  49471. {
  49472. vertical = shouldBeVertical;
  49473. if (upButton != 0)
  49474. {
  49475. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  49476. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  49477. }
  49478. updateThumbPosition();
  49479. }
  49480. }
  49481. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  49482. {
  49483. deleteAndZero (upButton);
  49484. deleteAndZero (downButton);
  49485. if (buttonsAreVisible)
  49486. {
  49487. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  49488. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  49489. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49490. }
  49491. updateThumbPosition();
  49492. }
  49493. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  49494. {
  49495. alwaysVisible = ! shouldHideWhenFullRange;
  49496. updateThumbPosition();
  49497. }
  49498. void ScrollBar::paint (Graphics& g)
  49499. {
  49500. if (thumbAreaSize > 0)
  49501. {
  49502. LookAndFeel& lf = getLookAndFeel();
  49503. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  49504. ? thumbSize : 0;
  49505. if (vertical)
  49506. {
  49507. lf.drawScrollbar (g, *this,
  49508. 0, thumbAreaStart,
  49509. getWidth(), thumbAreaSize,
  49510. vertical,
  49511. thumbStart, thumb,
  49512. isMouseOver(), isMouseButtonDown());
  49513. }
  49514. else
  49515. {
  49516. lf.drawScrollbar (g, *this,
  49517. thumbAreaStart, 0,
  49518. thumbAreaSize, getHeight(),
  49519. vertical,
  49520. thumbStart, thumb,
  49521. isMouseOver(), isMouseButtonDown());
  49522. }
  49523. }
  49524. }
  49525. void ScrollBar::lookAndFeelChanged()
  49526. {
  49527. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  49528. }
  49529. void ScrollBar::resized()
  49530. {
  49531. const int length = ((vertical) ? getHeight() : getWidth());
  49532. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  49533. : 0;
  49534. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49535. {
  49536. thumbAreaStart = length >> 1;
  49537. thumbAreaSize = 0;
  49538. }
  49539. else
  49540. {
  49541. thumbAreaStart = buttonSize;
  49542. thumbAreaSize = length - (buttonSize << 1);
  49543. }
  49544. if (upButton != 0)
  49545. {
  49546. if (vertical)
  49547. {
  49548. upButton->setBounds (0, 0, getWidth(), buttonSize);
  49549. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  49550. }
  49551. else
  49552. {
  49553. upButton->setBounds (0, 0, buttonSize, getHeight());
  49554. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  49555. }
  49556. }
  49557. updateThumbPosition();
  49558. }
  49559. void ScrollBar::mouseDown (const MouseEvent& e)
  49560. {
  49561. isDraggingThumb = false;
  49562. lastMousePos = vertical ? e.y : e.x;
  49563. dragStartMousePos = lastMousePos;
  49564. dragStartRange = rangeStart;
  49565. if (dragStartMousePos < thumbStart)
  49566. {
  49567. moveScrollbarInPages (-1);
  49568. startTimer (400);
  49569. }
  49570. else if (dragStartMousePos >= thumbStart + thumbSize)
  49571. {
  49572. moveScrollbarInPages (1);
  49573. startTimer (400);
  49574. }
  49575. else
  49576. {
  49577. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49578. && (thumbAreaSize > thumbSize);
  49579. }
  49580. }
  49581. void ScrollBar::mouseDrag (const MouseEvent& e)
  49582. {
  49583. if (isDraggingThumb)
  49584. {
  49585. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  49586. setCurrentRangeStart (dragStartRange
  49587. + deltaPixels * ((maximum - minimum) - rangeSize)
  49588. / (thumbAreaSize - thumbSize));
  49589. }
  49590. else
  49591. {
  49592. lastMousePos = (vertical) ? e.y : e.x;
  49593. }
  49594. }
  49595. void ScrollBar::mouseUp (const MouseEvent&)
  49596. {
  49597. isDraggingThumb = false;
  49598. stopTimer();
  49599. repaint();
  49600. }
  49601. void ScrollBar::mouseWheelMove (const MouseEvent&,
  49602. float wheelIncrementX,
  49603. float wheelIncrementY)
  49604. {
  49605. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  49606. if (increment < 0)
  49607. increment = jmin (increment * 10.0f, -1.0f);
  49608. else if (increment > 0)
  49609. increment = jmax (increment * 10.0f, 1.0f);
  49610. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  49611. }
  49612. void ScrollBar::timerCallback()
  49613. {
  49614. if (isMouseButtonDown())
  49615. {
  49616. startTimer (40);
  49617. if (lastMousePos < thumbStart)
  49618. setCurrentRangeStart (rangeStart - rangeSize);
  49619. else if (lastMousePos > thumbStart + thumbSize)
  49620. setCurrentRangeStart (rangeStart + rangeSize);
  49621. }
  49622. else
  49623. {
  49624. stopTimer();
  49625. }
  49626. }
  49627. bool ScrollBar::keyPressed (const KeyPress& key)
  49628. {
  49629. if (! isVisible())
  49630. return false;
  49631. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  49632. moveScrollbarInSteps (-1);
  49633. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  49634. moveScrollbarInSteps (1);
  49635. else if (key.isKeyCode (KeyPress::pageUpKey))
  49636. moveScrollbarInPages (-1);
  49637. else if (key.isKeyCode (KeyPress::pageDownKey))
  49638. moveScrollbarInPages (1);
  49639. else if (key.isKeyCode (KeyPress::homeKey))
  49640. scrollToTop();
  49641. else if (key.isKeyCode (KeyPress::endKey))
  49642. scrollToBottom();
  49643. else
  49644. return false;
  49645. return true;
  49646. }
  49647. END_JUCE_NAMESPACE
  49648. /*** End of inlined file: juce_ScrollBar.cpp ***/
  49649. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  49650. BEGIN_JUCE_NAMESPACE
  49651. StretchableLayoutManager::StretchableLayoutManager()
  49652. : totalSize (0)
  49653. {
  49654. }
  49655. StretchableLayoutManager::~StretchableLayoutManager()
  49656. {
  49657. }
  49658. void StretchableLayoutManager::clearAllItems()
  49659. {
  49660. items.clear();
  49661. totalSize = 0;
  49662. }
  49663. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  49664. const double minimumSize,
  49665. const double maximumSize,
  49666. const double preferredSize)
  49667. {
  49668. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  49669. if (layout == 0)
  49670. {
  49671. layout = new ItemLayoutProperties();
  49672. layout->itemIndex = itemIndex;
  49673. int i;
  49674. for (i = 0; i < items.size(); ++i)
  49675. if (items.getUnchecked (i)->itemIndex > itemIndex)
  49676. break;
  49677. items.insert (i, layout);
  49678. }
  49679. layout->minSize = minimumSize;
  49680. layout->maxSize = maximumSize;
  49681. layout->preferredSize = preferredSize;
  49682. layout->currentSize = 0;
  49683. }
  49684. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  49685. double& minimumSize,
  49686. double& maximumSize,
  49687. double& preferredSize) const
  49688. {
  49689. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49690. if (layout != 0)
  49691. {
  49692. minimumSize = layout->minSize;
  49693. maximumSize = layout->maxSize;
  49694. preferredSize = layout->preferredSize;
  49695. return true;
  49696. }
  49697. return false;
  49698. }
  49699. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  49700. {
  49701. totalSize = newTotalSize;
  49702. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  49703. }
  49704. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  49705. {
  49706. int pos = 0;
  49707. for (int i = 0; i < itemIndex; ++i)
  49708. {
  49709. const ItemLayoutProperties* const layout = getInfoFor (i);
  49710. if (layout != 0)
  49711. pos += layout->currentSize;
  49712. }
  49713. return pos;
  49714. }
  49715. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  49716. {
  49717. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49718. if (layout != 0)
  49719. return layout->currentSize;
  49720. return 0;
  49721. }
  49722. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  49723. {
  49724. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49725. if (layout != 0)
  49726. return -layout->currentSize / (double) totalSize;
  49727. return 0;
  49728. }
  49729. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  49730. int newPosition)
  49731. {
  49732. for (int i = items.size(); --i >= 0;)
  49733. {
  49734. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  49735. if (layout->itemIndex == itemIndex)
  49736. {
  49737. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  49738. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  49739. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  49740. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  49741. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  49742. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  49743. endPos += layout->currentSize;
  49744. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  49745. updatePrefSizesToMatchCurrentPositions();
  49746. break;
  49747. }
  49748. }
  49749. }
  49750. void StretchableLayoutManager::layOutComponents (Component** const components,
  49751. int numComponents,
  49752. int x, int y, int w, int h,
  49753. const bool vertically,
  49754. const bool resizeOtherDimension)
  49755. {
  49756. setTotalSize (vertically ? h : w);
  49757. int pos = vertically ? y : x;
  49758. for (int i = 0; i < numComponents; ++i)
  49759. {
  49760. const ItemLayoutProperties* const layout = getInfoFor (i);
  49761. if (layout != 0)
  49762. {
  49763. Component* const c = components[i];
  49764. if (c != 0)
  49765. {
  49766. if (i == numComponents - 1)
  49767. {
  49768. // if it's the last item, crop it to exactly fit the available space..
  49769. if (resizeOtherDimension)
  49770. {
  49771. if (vertically)
  49772. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  49773. else
  49774. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  49775. }
  49776. else
  49777. {
  49778. if (vertically)
  49779. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  49780. else
  49781. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  49782. }
  49783. }
  49784. else
  49785. {
  49786. if (resizeOtherDimension)
  49787. {
  49788. if (vertically)
  49789. c->setBounds (x, pos, w, layout->currentSize);
  49790. else
  49791. c->setBounds (pos, y, layout->currentSize, h);
  49792. }
  49793. else
  49794. {
  49795. if (vertically)
  49796. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  49797. else
  49798. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  49799. }
  49800. }
  49801. }
  49802. pos += layout->currentSize;
  49803. }
  49804. }
  49805. }
  49806. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  49807. {
  49808. for (int i = items.size(); --i >= 0;)
  49809. if (items.getUnchecked(i)->itemIndex == itemIndex)
  49810. return items.getUnchecked(i);
  49811. return 0;
  49812. }
  49813. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  49814. const int endIndex,
  49815. const int availableSpace,
  49816. int startPos)
  49817. {
  49818. // calculate the total sizes
  49819. int i;
  49820. double totalIdealSize = 0.0;
  49821. int totalMinimums = 0;
  49822. for (i = startIndex; i < endIndex; ++i)
  49823. {
  49824. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49825. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  49826. totalMinimums += layout->currentSize;
  49827. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  49828. }
  49829. if (totalIdealSize <= 0)
  49830. totalIdealSize = 1.0;
  49831. // now calc the best sizes..
  49832. int extraSpace = availableSpace - totalMinimums;
  49833. while (extraSpace > 0)
  49834. {
  49835. int numWantingMoreSpace = 0;
  49836. int numHavingTakenExtraSpace = 0;
  49837. // first figure out how many comps want a slice of the extra space..
  49838. for (i = startIndex; i < endIndex; ++i)
  49839. {
  49840. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49841. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49842. const int bestSize = jlimit (layout->currentSize,
  49843. jmax (layout->currentSize,
  49844. sizeToRealSize (layout->maxSize, totalSize)),
  49845. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49846. if (bestSize > layout->currentSize)
  49847. ++numWantingMoreSpace;
  49848. }
  49849. // ..share out the extra space..
  49850. for (i = startIndex; i < endIndex; ++i)
  49851. {
  49852. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49853. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49854. int bestSize = jlimit (layout->currentSize,
  49855. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  49856. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49857. const int extraWanted = bestSize - layout->currentSize;
  49858. if (extraWanted > 0)
  49859. {
  49860. const int extraAllowed = jmin (extraWanted,
  49861. extraSpace / jmax (1, numWantingMoreSpace));
  49862. if (extraAllowed > 0)
  49863. {
  49864. ++numHavingTakenExtraSpace;
  49865. --numWantingMoreSpace;
  49866. layout->currentSize += extraAllowed;
  49867. extraSpace -= extraAllowed;
  49868. }
  49869. }
  49870. }
  49871. if (numHavingTakenExtraSpace <= 0)
  49872. break;
  49873. }
  49874. // ..and calculate the end position
  49875. for (i = startIndex; i < endIndex; ++i)
  49876. {
  49877. ItemLayoutProperties* const layout = items.getUnchecked(i);
  49878. startPos += layout->currentSize;
  49879. }
  49880. return startPos;
  49881. }
  49882. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  49883. const int endIndex) const
  49884. {
  49885. int totalMinimums = 0;
  49886. for (int i = startIndex; i < endIndex; ++i)
  49887. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  49888. return totalMinimums;
  49889. }
  49890. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  49891. {
  49892. int totalMaximums = 0;
  49893. for (int i = startIndex; i < endIndex; ++i)
  49894. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  49895. return totalMaximums;
  49896. }
  49897. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  49898. {
  49899. for (int i = 0; i < items.size(); ++i)
  49900. {
  49901. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49902. layout->preferredSize
  49903. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  49904. : getItemCurrentAbsoluteSize (i);
  49905. }
  49906. }
  49907. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  49908. {
  49909. if (size < 0)
  49910. size *= -totalSpace;
  49911. return roundToInt (size);
  49912. }
  49913. END_JUCE_NAMESPACE
  49914. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  49915. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49916. BEGIN_JUCE_NAMESPACE
  49917. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  49918. const int itemIndex_,
  49919. const bool isVertical_)
  49920. : layout (layout_),
  49921. itemIndex (itemIndex_),
  49922. isVertical (isVertical_)
  49923. {
  49924. setRepaintsOnMouseActivity (true);
  49925. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  49926. : MouseCursor::UpDownResizeCursor));
  49927. }
  49928. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  49929. {
  49930. }
  49931. void StretchableLayoutResizerBar::paint (Graphics& g)
  49932. {
  49933. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  49934. getWidth(), getHeight(),
  49935. isVertical,
  49936. isMouseOver(),
  49937. isMouseButtonDown());
  49938. }
  49939. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  49940. {
  49941. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  49942. }
  49943. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  49944. {
  49945. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  49946. : e.getDistanceFromDragStartY());
  49947. layout->setItemPosition (itemIndex, desiredPos);
  49948. hasBeenMoved();
  49949. }
  49950. void StretchableLayoutResizerBar::hasBeenMoved()
  49951. {
  49952. if (getParentComponent() != 0)
  49953. getParentComponent()->resized();
  49954. }
  49955. END_JUCE_NAMESPACE
  49956. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49957. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  49958. BEGIN_JUCE_NAMESPACE
  49959. StretchableObjectResizer::StretchableObjectResizer()
  49960. {
  49961. }
  49962. StretchableObjectResizer::~StretchableObjectResizer()
  49963. {
  49964. }
  49965. void StretchableObjectResizer::addItem (const double size,
  49966. const double minSize, const double maxSize,
  49967. const int order)
  49968. {
  49969. // the order must be >= 0 but less than the maximum integer value.
  49970. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  49971. Item* const item = new Item();
  49972. item->size = size;
  49973. item->minSize = minSize;
  49974. item->maxSize = maxSize;
  49975. item->order = order;
  49976. items.add (item);
  49977. }
  49978. double StretchableObjectResizer::getItemSize (const int index) const throw()
  49979. {
  49980. const Item* const it = items [index];
  49981. return it != 0 ? it->size : 0;
  49982. }
  49983. void StretchableObjectResizer::resizeToFit (const double targetSize)
  49984. {
  49985. int order = 0;
  49986. for (;;)
  49987. {
  49988. double currentSize = 0;
  49989. double minSize = 0;
  49990. double maxSize = 0;
  49991. int nextHighestOrder = std::numeric_limits<int>::max();
  49992. for (int i = 0; i < items.size(); ++i)
  49993. {
  49994. const Item* const it = items.getUnchecked(i);
  49995. currentSize += it->size;
  49996. if (it->order <= order)
  49997. {
  49998. minSize += it->minSize;
  49999. maxSize += it->maxSize;
  50000. }
  50001. else
  50002. {
  50003. minSize += it->size;
  50004. maxSize += it->size;
  50005. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50006. }
  50007. }
  50008. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50009. if (thisIterationTarget >= currentSize)
  50010. {
  50011. const double availableExtraSpace = maxSize - currentSize;
  50012. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50013. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50014. for (int i = 0; i < items.size(); ++i)
  50015. {
  50016. Item* const it = items.getUnchecked(i);
  50017. if (it->order <= order)
  50018. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50019. }
  50020. }
  50021. else
  50022. {
  50023. const double amountOfSlack = currentSize - minSize;
  50024. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50025. const double scale = targetAmountOfSlack / amountOfSlack;
  50026. for (int i = 0; i < items.size(); ++i)
  50027. {
  50028. Item* const it = items.getUnchecked(i);
  50029. if (it->order <= order)
  50030. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50031. }
  50032. }
  50033. if (nextHighestOrder < std::numeric_limits<int>::max())
  50034. order = nextHighestOrder;
  50035. else
  50036. break;
  50037. }
  50038. }
  50039. END_JUCE_NAMESPACE
  50040. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50041. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50042. BEGIN_JUCE_NAMESPACE
  50043. TabBarButton::TabBarButton (const String& name,
  50044. TabbedButtonBar* const owner_,
  50045. const int index)
  50046. : Button (name),
  50047. owner (owner_),
  50048. tabIndex (index),
  50049. overlapPixels (0)
  50050. {
  50051. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50052. setComponentEffect (&shadow);
  50053. setWantsKeyboardFocus (false);
  50054. }
  50055. TabBarButton::~TabBarButton()
  50056. {
  50057. }
  50058. void TabBarButton::paintButton (Graphics& g,
  50059. bool isMouseOverButton,
  50060. bool isButtonDown)
  50061. {
  50062. int x, y, w, h;
  50063. getActiveArea (x, y, w, h);
  50064. g.setOrigin (x, y);
  50065. getLookAndFeel()
  50066. .drawTabButton (g, w, h,
  50067. owner->getTabBackgroundColour (tabIndex),
  50068. tabIndex, getButtonText(), *this,
  50069. owner->getOrientation(),
  50070. isMouseOverButton, isButtonDown,
  50071. getToggleState());
  50072. }
  50073. void TabBarButton::clicked (const ModifierKeys& mods)
  50074. {
  50075. if (mods.isPopupMenu())
  50076. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50077. else
  50078. owner->setCurrentTabIndex (tabIndex);
  50079. }
  50080. bool TabBarButton::hitTest (int mx, int my)
  50081. {
  50082. int x, y, w, h;
  50083. getActiveArea (x, y, w, h);
  50084. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50085. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50086. {
  50087. if (((unsigned int) mx) < (unsigned int) getWidth()
  50088. && my >= y + overlapPixels
  50089. && my < y + h - overlapPixels)
  50090. return true;
  50091. }
  50092. else
  50093. {
  50094. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50095. && ((unsigned int) my) < (unsigned int) getHeight())
  50096. return true;
  50097. }
  50098. Path p;
  50099. getLookAndFeel()
  50100. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50101. owner->getOrientation(),
  50102. false, false, getToggleState());
  50103. return p.contains ((float) (mx - x),
  50104. (float) (my - y));
  50105. }
  50106. int TabBarButton::getBestTabLength (const int depth)
  50107. {
  50108. return jlimit (depth * 2,
  50109. depth * 7,
  50110. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50111. }
  50112. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50113. {
  50114. x = 0;
  50115. y = 0;
  50116. int r = getWidth();
  50117. int b = getHeight();
  50118. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50119. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50120. r -= spaceAroundImage;
  50121. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50122. x += spaceAroundImage;
  50123. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50124. y += spaceAroundImage;
  50125. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50126. b -= spaceAroundImage;
  50127. w = r - x;
  50128. h = b - y;
  50129. }
  50130. class TabAreaBehindFrontButtonComponent : public Component
  50131. {
  50132. public:
  50133. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50134. : owner (owner_)
  50135. {
  50136. setInterceptsMouseClicks (false, false);
  50137. }
  50138. ~TabAreaBehindFrontButtonComponent()
  50139. {
  50140. }
  50141. void paint (Graphics& g)
  50142. {
  50143. getLookAndFeel()
  50144. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50145. *owner, owner->getOrientation());
  50146. }
  50147. void enablementChanged()
  50148. {
  50149. repaint();
  50150. }
  50151. private:
  50152. TabbedButtonBar* const owner;
  50153. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50154. TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50155. };
  50156. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50157. : orientation (orientation_),
  50158. currentTabIndex (-1),
  50159. extraTabsButton (0)
  50160. {
  50161. setInterceptsMouseClicks (false, true);
  50162. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50163. setFocusContainer (true);
  50164. }
  50165. TabbedButtonBar::~TabbedButtonBar()
  50166. {
  50167. deleteAllChildren();
  50168. }
  50169. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50170. {
  50171. orientation = newOrientation;
  50172. for (int i = getNumChildComponents(); --i >= 0;)
  50173. getChildComponent (i)->resized();
  50174. resized();
  50175. }
  50176. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50177. {
  50178. return new TabBarButton (name, this, index);
  50179. }
  50180. void TabbedButtonBar::clearTabs()
  50181. {
  50182. tabs.clear();
  50183. tabColours.clear();
  50184. currentTabIndex = -1;
  50185. deleteAndZero (extraTabsButton);
  50186. removeChildComponent (behindFrontTab);
  50187. deleteAllChildren();
  50188. addChildComponent (behindFrontTab);
  50189. setCurrentTabIndex (-1);
  50190. }
  50191. void TabbedButtonBar::addTab (const String& tabName,
  50192. const Colour& tabBackgroundColour,
  50193. int insertIndex)
  50194. {
  50195. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50196. if (tabName.isNotEmpty())
  50197. {
  50198. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50199. insertIndex = tabs.size();
  50200. for (int i = tabs.size(); --i >= insertIndex;)
  50201. {
  50202. TabBarButton* const tb = getTabButton (i);
  50203. if (tb != 0)
  50204. tb->tabIndex++;
  50205. }
  50206. tabs.insert (insertIndex, tabName);
  50207. tabColours.insert (insertIndex, tabBackgroundColour);
  50208. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50209. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50210. addAndMakeVisible (tb, insertIndex);
  50211. resized();
  50212. if (currentTabIndex < 0)
  50213. setCurrentTabIndex (0);
  50214. }
  50215. }
  50216. void TabbedButtonBar::setTabName (const int tabIndex,
  50217. const String& newName)
  50218. {
  50219. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50220. && tabs[tabIndex] != newName)
  50221. {
  50222. tabs.set (tabIndex, newName);
  50223. TabBarButton* const tb = getTabButton (tabIndex);
  50224. if (tb != 0)
  50225. tb->setButtonText (newName);
  50226. resized();
  50227. }
  50228. }
  50229. void TabbedButtonBar::removeTab (const int tabIndex)
  50230. {
  50231. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50232. {
  50233. const int oldTabIndex = currentTabIndex;
  50234. if (currentTabIndex == tabIndex)
  50235. currentTabIndex = -1;
  50236. tabs.remove (tabIndex);
  50237. tabColours.remove (tabIndex);
  50238. delete getTabButton (tabIndex);
  50239. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50240. {
  50241. TabBarButton* const tb = getTabButton (i);
  50242. if (tb != 0)
  50243. tb->tabIndex--;
  50244. }
  50245. resized();
  50246. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50247. }
  50248. }
  50249. void TabbedButtonBar::moveTab (const int currentIndex,
  50250. const int newIndex)
  50251. {
  50252. tabs.move (currentIndex, newIndex);
  50253. tabColours.move (currentIndex, newIndex);
  50254. resized();
  50255. }
  50256. int TabbedButtonBar::getNumTabs() const
  50257. {
  50258. return tabs.size();
  50259. }
  50260. const StringArray TabbedButtonBar::getTabNames() const
  50261. {
  50262. return tabs;
  50263. }
  50264. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50265. {
  50266. if (currentTabIndex != newIndex)
  50267. {
  50268. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50269. newIndex = -1;
  50270. currentTabIndex = newIndex;
  50271. for (int i = 0; i < getNumChildComponents(); ++i)
  50272. {
  50273. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50274. if (tb != 0)
  50275. tb->setToggleState (tb->tabIndex == newIndex, false);
  50276. }
  50277. resized();
  50278. if (sendChangeMessage_)
  50279. sendChangeMessage (this);
  50280. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50281. }
  50282. }
  50283. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50284. {
  50285. for (int i = getNumChildComponents(); --i >= 0;)
  50286. {
  50287. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50288. if (tb != 0 && tb->tabIndex == index)
  50289. return tb;
  50290. }
  50291. return 0;
  50292. }
  50293. void TabbedButtonBar::lookAndFeelChanged()
  50294. {
  50295. deleteAndZero (extraTabsButton);
  50296. resized();
  50297. }
  50298. void TabbedButtonBar::resized()
  50299. {
  50300. const double minimumScale = 0.7;
  50301. int depth = getWidth();
  50302. int length = getHeight();
  50303. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50304. swapVariables (depth, length);
  50305. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50306. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50307. int i, totalLength = overlap;
  50308. int numVisibleButtons = tabs.size();
  50309. for (i = 0; i < getNumChildComponents(); ++i)
  50310. {
  50311. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50312. if (tb != 0)
  50313. {
  50314. totalLength += tb->getBestTabLength (depth) - overlap;
  50315. tb->overlapPixels = overlap / 2;
  50316. }
  50317. }
  50318. double scale = 1.0;
  50319. if (totalLength > length)
  50320. scale = jmax (minimumScale, length / (double) totalLength);
  50321. const bool isTooBig = totalLength * scale > length;
  50322. int tabsButtonPos = 0;
  50323. if (isTooBig)
  50324. {
  50325. if (extraTabsButton == 0)
  50326. {
  50327. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50328. extraTabsButton->addButtonListener (this);
  50329. extraTabsButton->setAlwaysOnTop (true);
  50330. extraTabsButton->setTriggeredOnMouseDown (true);
  50331. }
  50332. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50333. extraTabsButton->setSize (buttonSize, buttonSize);
  50334. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50335. {
  50336. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50337. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50338. }
  50339. else
  50340. {
  50341. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  50342. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  50343. }
  50344. totalLength = 0;
  50345. for (i = 0; i < tabs.size(); ++i)
  50346. {
  50347. TabBarButton* const tb = getTabButton (i);
  50348. if (tb != 0)
  50349. {
  50350. const int newLength = totalLength + tb->getBestTabLength (depth);
  50351. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  50352. {
  50353. totalLength += overlap;
  50354. break;
  50355. }
  50356. numVisibleButtons = i + 1;
  50357. totalLength = newLength - overlap;
  50358. }
  50359. }
  50360. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  50361. }
  50362. else
  50363. {
  50364. deleteAndZero (extraTabsButton);
  50365. }
  50366. int pos = 0;
  50367. TabBarButton* frontTab = 0;
  50368. for (i = 0; i < tabs.size(); ++i)
  50369. {
  50370. TabBarButton* const tb = getTabButton (i);
  50371. if (tb != 0)
  50372. {
  50373. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  50374. if (i < numVisibleButtons)
  50375. {
  50376. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50377. tb->setBounds (pos, 0, bestLength, getHeight());
  50378. else
  50379. tb->setBounds (0, pos, getWidth(), bestLength);
  50380. tb->toBack();
  50381. if (tb->tabIndex == currentTabIndex)
  50382. frontTab = tb;
  50383. tb->setVisible (true);
  50384. }
  50385. else
  50386. {
  50387. tb->setVisible (false);
  50388. }
  50389. pos += bestLength - overlap;
  50390. }
  50391. }
  50392. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  50393. if (frontTab != 0)
  50394. {
  50395. frontTab->toFront (false);
  50396. behindFrontTab->toBehind (frontTab);
  50397. }
  50398. }
  50399. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  50400. {
  50401. return tabColours [tabIndex];
  50402. }
  50403. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50404. {
  50405. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  50406. && tabColours [tabIndex] != newColour)
  50407. {
  50408. tabColours.set (tabIndex, newColour);
  50409. repaint();
  50410. }
  50411. }
  50412. void TabbedButtonBar::buttonClicked (Button* button)
  50413. {
  50414. if (extraTabsButton == button)
  50415. {
  50416. PopupMenu m;
  50417. for (int i = 0; i < tabs.size(); ++i)
  50418. {
  50419. TabBarButton* const tb = getTabButton (i);
  50420. if (tb != 0 && ! tb->isVisible())
  50421. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  50422. }
  50423. const int res = m.showAt (extraTabsButton);
  50424. if (res != 0)
  50425. setCurrentTabIndex (res - 1);
  50426. }
  50427. }
  50428. void TabbedButtonBar::currentTabChanged (const int, const String&)
  50429. {
  50430. }
  50431. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  50432. {
  50433. }
  50434. END_JUCE_NAMESPACE
  50435. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  50436. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  50437. BEGIN_JUCE_NAMESPACE
  50438. class TabCompButtonBar : public TabbedButtonBar
  50439. {
  50440. public:
  50441. TabCompButtonBar (TabbedComponent* const owner_,
  50442. const TabbedButtonBar::Orientation orientation)
  50443. : TabbedButtonBar (orientation),
  50444. owner (owner_)
  50445. {
  50446. }
  50447. ~TabCompButtonBar()
  50448. {
  50449. }
  50450. void currentTabChanged (const int newCurrentTabIndex,
  50451. const String& newTabName)
  50452. {
  50453. owner->changeCallback (newCurrentTabIndex, newTabName);
  50454. }
  50455. void popupMenuClickOnTab (const int tabIndex,
  50456. const String& tabName)
  50457. {
  50458. owner->popupMenuClickOnTab (tabIndex, tabName);
  50459. }
  50460. const Colour getTabBackgroundColour (const int tabIndex)
  50461. {
  50462. return owner->tabs->getTabBackgroundColour (tabIndex);
  50463. }
  50464. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  50465. {
  50466. return owner->createTabButton (tabName, tabIndex);
  50467. }
  50468. juce_UseDebuggingNewOperator
  50469. private:
  50470. TabbedComponent* const owner;
  50471. TabCompButtonBar (const TabCompButtonBar&);
  50472. TabCompButtonBar& operator= (const TabCompButtonBar&);
  50473. };
  50474. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  50475. : panelComponent (0),
  50476. tabDepth (30),
  50477. outlineThickness (1),
  50478. edgeIndent (0)
  50479. {
  50480. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  50481. }
  50482. TabbedComponent::~TabbedComponent()
  50483. {
  50484. clearTabs();
  50485. delete tabs;
  50486. }
  50487. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  50488. {
  50489. tabs->setOrientation (orientation);
  50490. resized();
  50491. }
  50492. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  50493. {
  50494. return tabs->getOrientation();
  50495. }
  50496. void TabbedComponent::setTabBarDepth (const int newDepth)
  50497. {
  50498. if (tabDepth != newDepth)
  50499. {
  50500. tabDepth = newDepth;
  50501. resized();
  50502. }
  50503. }
  50504. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  50505. {
  50506. return new TabBarButton (tabName, tabs, tabIndex);
  50507. }
  50508. void TabbedComponent::clearTabs()
  50509. {
  50510. if (panelComponent != 0)
  50511. {
  50512. panelComponent->setVisible (false);
  50513. removeChildComponent (panelComponent);
  50514. panelComponent = 0;
  50515. }
  50516. tabs->clearTabs();
  50517. for (int i = contentComponents.size(); --i >= 0;)
  50518. {
  50519. Component* const c = contentComponents.getUnchecked(i);
  50520. // be careful not to delete these components until they've been removed from the tab component
  50521. jassert (c == 0 || c->isValidComponent());
  50522. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50523. delete c;
  50524. }
  50525. contentComponents.clear();
  50526. }
  50527. void TabbedComponent::addTab (const String& tabName,
  50528. const Colour& tabBackgroundColour,
  50529. Component* const contentComponent,
  50530. const bool deleteComponentWhenNotNeeded,
  50531. const int insertIndex)
  50532. {
  50533. contentComponents.insert (insertIndex, contentComponent);
  50534. if (contentComponent != 0)
  50535. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  50536. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  50537. }
  50538. void TabbedComponent::setTabName (const int tabIndex,
  50539. const String& newName)
  50540. {
  50541. tabs->setTabName (tabIndex, newName);
  50542. }
  50543. void TabbedComponent::removeTab (const int tabIndex)
  50544. {
  50545. Component* const c = contentComponents [tabIndex];
  50546. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50547. {
  50548. if (c == panelComponent)
  50549. panelComponent = 0;
  50550. delete c;
  50551. }
  50552. contentComponents.remove (tabIndex);
  50553. tabs->removeTab (tabIndex);
  50554. }
  50555. int TabbedComponent::getNumTabs() const
  50556. {
  50557. return tabs->getNumTabs();
  50558. }
  50559. const StringArray TabbedComponent::getTabNames() const
  50560. {
  50561. return tabs->getTabNames();
  50562. }
  50563. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  50564. {
  50565. return contentComponents [tabIndex];
  50566. }
  50567. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  50568. {
  50569. return tabs->getTabBackgroundColour (tabIndex);
  50570. }
  50571. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50572. {
  50573. tabs->setTabBackgroundColour (tabIndex, newColour);
  50574. if (getCurrentTabIndex() == tabIndex)
  50575. repaint();
  50576. }
  50577. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  50578. {
  50579. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  50580. }
  50581. int TabbedComponent::getCurrentTabIndex() const
  50582. {
  50583. return tabs->getCurrentTabIndex();
  50584. }
  50585. const String& TabbedComponent::getCurrentTabName() const
  50586. {
  50587. return tabs->getCurrentTabName();
  50588. }
  50589. void TabbedComponent::setOutline (int thickness)
  50590. {
  50591. outlineThickness = thickness;
  50592. repaint();
  50593. }
  50594. void TabbedComponent::setIndent (const int indentThickness)
  50595. {
  50596. edgeIndent = indentThickness;
  50597. }
  50598. void TabbedComponent::paint (Graphics& g)
  50599. {
  50600. g.fillAll (findColour (backgroundColourId));
  50601. const TabbedButtonBar::Orientation o = getOrientation();
  50602. int x = 0;
  50603. int y = 0;
  50604. int r = getWidth();
  50605. int b = getHeight();
  50606. if (o == TabbedButtonBar::TabsAtTop)
  50607. y += tabDepth;
  50608. else if (o == TabbedButtonBar::TabsAtBottom)
  50609. b -= tabDepth;
  50610. else if (o == TabbedButtonBar::TabsAtLeft)
  50611. x += tabDepth;
  50612. else if (o == TabbedButtonBar::TabsAtRight)
  50613. r -= tabDepth;
  50614. g.reduceClipRegion (x, y, r - x, b - y);
  50615. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  50616. if (outlineThickness > 0)
  50617. {
  50618. if (o == TabbedButtonBar::TabsAtTop)
  50619. --y;
  50620. else if (o == TabbedButtonBar::TabsAtBottom)
  50621. ++b;
  50622. else if (o == TabbedButtonBar::TabsAtLeft)
  50623. --x;
  50624. else if (o == TabbedButtonBar::TabsAtRight)
  50625. ++r;
  50626. g.setColour (findColour (outlineColourId));
  50627. g.drawRect (x, y, r - x, b - y, outlineThickness);
  50628. }
  50629. }
  50630. void TabbedComponent::resized()
  50631. {
  50632. const TabbedButtonBar::Orientation o = getOrientation();
  50633. const int indent = edgeIndent + outlineThickness;
  50634. BorderSize indents (indent);
  50635. if (o == TabbedButtonBar::TabsAtTop)
  50636. {
  50637. tabs->setBounds (0, 0, getWidth(), tabDepth);
  50638. indents.setTop (tabDepth + edgeIndent);
  50639. }
  50640. else if (o == TabbedButtonBar::TabsAtBottom)
  50641. {
  50642. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  50643. indents.setBottom (tabDepth + edgeIndent);
  50644. }
  50645. else if (o == TabbedButtonBar::TabsAtLeft)
  50646. {
  50647. tabs->setBounds (0, 0, tabDepth, getHeight());
  50648. indents.setLeft (tabDepth + edgeIndent);
  50649. }
  50650. else if (o == TabbedButtonBar::TabsAtRight)
  50651. {
  50652. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  50653. indents.setRight (tabDepth + edgeIndent);
  50654. }
  50655. const Rectangle<int> bounds (indents.subtractedFrom (Rectangle<int> (0, 0, getWidth(), getHeight())));
  50656. for (int i = contentComponents.size(); --i >= 0;)
  50657. if (contentComponents.getUnchecked (i) != 0)
  50658. contentComponents.getUnchecked (i)->setBounds (bounds);
  50659. }
  50660. void TabbedComponent::lookAndFeelChanged()
  50661. {
  50662. for (int i = contentComponents.size(); --i >= 0;)
  50663. if (contentComponents.getUnchecked (i) != 0)
  50664. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  50665. }
  50666. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  50667. const String& newTabName)
  50668. {
  50669. if (panelComponent != 0)
  50670. {
  50671. panelComponent->setVisible (false);
  50672. removeChildComponent (panelComponent);
  50673. panelComponent = 0;
  50674. }
  50675. if (getCurrentTabIndex() >= 0)
  50676. {
  50677. panelComponent = contentComponents [getCurrentTabIndex()];
  50678. if (panelComponent != 0)
  50679. {
  50680. // do these ops as two stages instead of addAndMakeVisible() so that the
  50681. // component has always got a parent when it gets the visibilityChanged() callback
  50682. addChildComponent (panelComponent);
  50683. panelComponent->setVisible (true);
  50684. panelComponent->toFront (true);
  50685. }
  50686. repaint();
  50687. }
  50688. resized();
  50689. currentTabChanged (newCurrentTabIndex, newTabName);
  50690. }
  50691. void TabbedComponent::currentTabChanged (const int, const String&)
  50692. {
  50693. }
  50694. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  50695. {
  50696. }
  50697. END_JUCE_NAMESPACE
  50698. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  50699. /*** Start of inlined file: juce_Viewport.cpp ***/
  50700. BEGIN_JUCE_NAMESPACE
  50701. Viewport::Viewport (const String& componentName)
  50702. : Component (componentName),
  50703. contentComp (0),
  50704. lastVX (0),
  50705. lastVY (0),
  50706. lastVW (0),
  50707. lastVH (0),
  50708. scrollBarThickness (0),
  50709. singleStepX (16),
  50710. singleStepY (16),
  50711. showHScrollbar (true),
  50712. showVScrollbar (true)
  50713. {
  50714. // content holder is used to clip the contents so they don't overlap the scrollbars
  50715. addAndMakeVisible (contentHolder = new Component());
  50716. contentHolder->setInterceptsMouseClicks (false, true);
  50717. verticalScrollBar = new ScrollBar (true);
  50718. horizontalScrollBar = new ScrollBar (false);
  50719. addChildComponent (verticalScrollBar);
  50720. addChildComponent (horizontalScrollBar);
  50721. verticalScrollBar->addListener (this);
  50722. horizontalScrollBar->addListener (this);
  50723. setInterceptsMouseClicks (false, true);
  50724. setWantsKeyboardFocus (true);
  50725. }
  50726. Viewport::~Viewport()
  50727. {
  50728. contentHolder->deleteAllChildren();
  50729. deleteAllChildren();
  50730. }
  50731. void Viewport::visibleAreaChanged (int, int, int, int)
  50732. {
  50733. }
  50734. void Viewport::setViewedComponent (Component* const newViewedComponent)
  50735. {
  50736. if (contentComp.getComponent() != newViewedComponent)
  50737. {
  50738. {
  50739. ScopedPointer<Component> oldCompDeleter (contentComp);
  50740. contentComp = 0;
  50741. }
  50742. contentComp = newViewedComponent;
  50743. if (contentComp != 0)
  50744. {
  50745. contentComp->setTopLeftPosition (0, 0);
  50746. contentHolder->addAndMakeVisible (contentComp);
  50747. contentComp->addComponentListener (this);
  50748. }
  50749. updateVisibleRegion();
  50750. }
  50751. }
  50752. int Viewport::getMaximumVisibleWidth() const throw()
  50753. {
  50754. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50755. }
  50756. int Viewport::getMaximumVisibleHeight() const throw()
  50757. {
  50758. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50759. }
  50760. void Viewport::setViewPosition (const int xPixelsOffset,
  50761. const int yPixelsOffset)
  50762. {
  50763. if (contentComp != 0)
  50764. contentComp->setTopLeftPosition (-xPixelsOffset,
  50765. -yPixelsOffset);
  50766. }
  50767. void Viewport::setViewPositionProportionately (const double x,
  50768. const double y)
  50769. {
  50770. if (contentComp != 0)
  50771. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  50772. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  50773. }
  50774. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  50775. {
  50776. if (contentComp != 0)
  50777. {
  50778. int dx = 0, dy = 0;
  50779. if (mouseX < activeBorderThickness)
  50780. dx = activeBorderThickness - mouseX;
  50781. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  50782. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  50783. if (dx < 0)
  50784. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  50785. else
  50786. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  50787. if (mouseY < activeBorderThickness)
  50788. dy = activeBorderThickness - mouseY;
  50789. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  50790. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  50791. if (dy < 0)
  50792. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  50793. else
  50794. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  50795. if (dx != 0 || dy != 0)
  50796. {
  50797. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  50798. contentComp->getY() + dy);
  50799. return true;
  50800. }
  50801. }
  50802. return false;
  50803. }
  50804. void Viewport::componentMovedOrResized (Component&, bool, bool)
  50805. {
  50806. updateVisibleRegion();
  50807. }
  50808. void Viewport::resized()
  50809. {
  50810. updateVisibleRegion();
  50811. }
  50812. void Viewport::updateVisibleRegion()
  50813. {
  50814. if (contentComp != 0)
  50815. {
  50816. const int newVX = -contentComp->getX();
  50817. const int newVY = -contentComp->getY();
  50818. if (newVX == 0 && newVY == 0
  50819. && contentComp->getWidth() <= getWidth()
  50820. && contentComp->getHeight() <= getHeight())
  50821. {
  50822. horizontalScrollBar->setVisible (false);
  50823. verticalScrollBar->setVisible (false);
  50824. }
  50825. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  50826. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50827. horizontalScrollBar->setSingleStepSize (singleStepX);
  50828. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  50829. horizontalScrollBar->setVisible (false);
  50830. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  50831. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50832. verticalScrollBar->setSingleStepSize (singleStepY);
  50833. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  50834. verticalScrollBar->setVisible (false);
  50835. if (verticalScrollBar->isVisible())
  50836. {
  50837. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50838. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50839. verticalScrollBar
  50840. ->setBounds (getMaximumVisibleWidth(), 0,
  50841. getScrollBarThickness(), getMaximumVisibleHeight());
  50842. }
  50843. if (horizontalScrollBar->isVisible())
  50844. {
  50845. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50846. horizontalScrollBar
  50847. ->setBounds (0, getMaximumVisibleHeight(),
  50848. getMaximumVisibleWidth(), getScrollBarThickness());
  50849. }
  50850. contentHolder->setSize (getMaximumVisibleWidth(),
  50851. getMaximumVisibleHeight());
  50852. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  50853. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  50854. if (newVX != lastVX
  50855. || newVY != lastVY
  50856. || newVW != lastVW
  50857. || newVH != lastVH)
  50858. {
  50859. lastVX = newVX;
  50860. lastVY = newVY;
  50861. lastVW = newVW;
  50862. lastVH = newVH;
  50863. visibleAreaChanged (newVX, newVY, newVW, newVH);
  50864. }
  50865. horizontalScrollBar->handleUpdateNowIfNeeded();
  50866. verticalScrollBar->handleUpdateNowIfNeeded();
  50867. }
  50868. else
  50869. {
  50870. horizontalScrollBar->setVisible (false);
  50871. verticalScrollBar->setVisible (false);
  50872. }
  50873. }
  50874. void Viewport::setSingleStepSizes (const int stepX,
  50875. const int stepY)
  50876. {
  50877. singleStepX = stepX;
  50878. singleStepY = stepY;
  50879. updateVisibleRegion();
  50880. }
  50881. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  50882. const bool showHorizontalScrollbarIfNeeded)
  50883. {
  50884. showVScrollbar = showVerticalScrollbarIfNeeded;
  50885. showHScrollbar = showHorizontalScrollbarIfNeeded;
  50886. updateVisibleRegion();
  50887. }
  50888. void Viewport::setScrollBarThickness (const int thickness)
  50889. {
  50890. scrollBarThickness = thickness;
  50891. updateVisibleRegion();
  50892. }
  50893. int Viewport::getScrollBarThickness() const throw()
  50894. {
  50895. return (scrollBarThickness > 0) ? scrollBarThickness
  50896. : getLookAndFeel().getDefaultScrollbarWidth();
  50897. }
  50898. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  50899. {
  50900. verticalScrollBar->setButtonVisibility (buttonsVisible);
  50901. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  50902. }
  50903. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  50904. {
  50905. if (scrollBarThatHasMoved == horizontalScrollBar)
  50906. {
  50907. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  50908. }
  50909. else if (scrollBarThatHasMoved == verticalScrollBar)
  50910. {
  50911. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  50912. }
  50913. }
  50914. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50915. {
  50916. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  50917. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  50918. }
  50919. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50920. {
  50921. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  50922. {
  50923. const bool hasVertBar = verticalScrollBar->isVisible();
  50924. const bool hasHorzBar = horizontalScrollBar->isVisible();
  50925. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  50926. {
  50927. if (wheelIncrementX == 0 && ! hasVertBar)
  50928. wheelIncrementX = wheelIncrementY;
  50929. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  50930. wheelIncrementX, wheelIncrementY);
  50931. return true;
  50932. }
  50933. else if (hasVertBar && wheelIncrementY != 0)
  50934. {
  50935. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  50936. wheelIncrementX, wheelIncrementY);
  50937. return true;
  50938. }
  50939. }
  50940. return false;
  50941. }
  50942. bool Viewport::keyPressed (const KeyPress& key)
  50943. {
  50944. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  50945. || key.isKeyCode (KeyPress::downKey)
  50946. || key.isKeyCode (KeyPress::pageUpKey)
  50947. || key.isKeyCode (KeyPress::pageDownKey)
  50948. || key.isKeyCode (KeyPress::homeKey)
  50949. || key.isKeyCode (KeyPress::endKey);
  50950. if (verticalScrollBar->isVisible() && isUpDownKey)
  50951. return verticalScrollBar->keyPressed (key);
  50952. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  50953. || key.isKeyCode (KeyPress::rightKey);
  50954. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  50955. return horizontalScrollBar->keyPressed (key);
  50956. return false;
  50957. }
  50958. END_JUCE_NAMESPACE
  50959. /*** End of inlined file: juce_Viewport.cpp ***/
  50960. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  50961. BEGIN_JUCE_NAMESPACE
  50962. static const Colour createBaseColour (const Colour& buttonColour,
  50963. const bool hasKeyboardFocus,
  50964. const bool isMouseOverButton,
  50965. const bool isButtonDown) throw()
  50966. {
  50967. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  50968. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  50969. if (isButtonDown)
  50970. return baseColour.contrasting (0.2f);
  50971. else if (isMouseOverButton)
  50972. return baseColour.contrasting (0.1f);
  50973. return baseColour;
  50974. }
  50975. static String defaultSansName, defaultSerifName, defaultFixedName;
  50976. void clearUpDefaultFontNames() throw()
  50977. {
  50978. defaultSansName = String::empty;
  50979. defaultSerifName = String::empty;
  50980. defaultFixedName = String::empty;
  50981. }
  50982. LookAndFeel::LookAndFeel()
  50983. {
  50984. /* if this fails it means you're trying to create a LookAndFeel object before
  50985. the static Colours have been initialised. That ain't gonna work. It probably
  50986. means that you're using a static LookAndFeel object and that your compiler has
  50987. decided to intialise it before the Colours class.
  50988. */
  50989. jassert (Colours::white == Colour (0xffffffff));
  50990. // set up the standard set of colours..
  50991. const int textButtonColour = 0xffbbbbff;
  50992. const int textHighlightColour = 0x401111ee;
  50993. const int standardOutlineColour = 0xb2808080;
  50994. static const int standardColours[] =
  50995. {
  50996. TextButton::buttonColourId, textButtonColour,
  50997. TextButton::buttonOnColourId, 0xff4444ff,
  50998. TextButton::textColourOnId, 0xff000000,
  50999. TextButton::textColourOffId, 0xff000000,
  51000. ComboBox::buttonColourId, 0xffbbbbff,
  51001. ComboBox::outlineColourId, standardOutlineColour,
  51002. ToggleButton::textColourId, 0xff000000,
  51003. TextEditor::backgroundColourId, 0xffffffff,
  51004. TextEditor::textColourId, 0xff000000,
  51005. TextEditor::highlightColourId, textHighlightColour,
  51006. TextEditor::highlightedTextColourId, 0xff000000,
  51007. TextEditor::caretColourId, 0xff000000,
  51008. TextEditor::outlineColourId, 0x00000000,
  51009. TextEditor::focusedOutlineColourId, textButtonColour,
  51010. TextEditor::shadowColourId, 0x38000000,
  51011. Label::backgroundColourId, 0x00000000,
  51012. Label::textColourId, 0xff000000,
  51013. Label::outlineColourId, 0x00000000,
  51014. ScrollBar::backgroundColourId, 0x00000000,
  51015. ScrollBar::thumbColourId, 0xffffffff,
  51016. ScrollBar::trackColourId, 0xffffffff,
  51017. TreeView::linesColourId, 0x4c000000,
  51018. TreeView::backgroundColourId, 0x00000000,
  51019. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51020. PopupMenu::backgroundColourId, 0xffffffff,
  51021. PopupMenu::textColourId, 0xff000000,
  51022. PopupMenu::headerTextColourId, 0xff000000,
  51023. PopupMenu::highlightedTextColourId, 0xffffffff,
  51024. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51025. ComboBox::textColourId, 0xff000000,
  51026. ComboBox::backgroundColourId, 0xffffffff,
  51027. ComboBox::arrowColourId, 0x99000000,
  51028. ListBox::backgroundColourId, 0xffffffff,
  51029. ListBox::outlineColourId, standardOutlineColour,
  51030. ListBox::textColourId, 0xff000000,
  51031. Slider::backgroundColourId, 0x00000000,
  51032. Slider::thumbColourId, textButtonColour,
  51033. Slider::trackColourId, 0x7fffffff,
  51034. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51035. Slider::rotarySliderOutlineColourId, 0x66000000,
  51036. Slider::textBoxTextColourId, 0xff000000,
  51037. Slider::textBoxBackgroundColourId, 0xffffffff,
  51038. Slider::textBoxHighlightColourId, textHighlightColour,
  51039. Slider::textBoxOutlineColourId, standardOutlineColour,
  51040. ResizableWindow::backgroundColourId, 0xff777777,
  51041. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51042. AlertWindow::backgroundColourId, 0xffededed,
  51043. AlertWindow::textColourId, 0xff000000,
  51044. AlertWindow::outlineColourId, 0xff666666,
  51045. ProgressBar::backgroundColourId, 0xffeeeeee,
  51046. ProgressBar::foregroundColourId, 0xffaaaaee,
  51047. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51048. TooltipWindow::textColourId, 0xff000000,
  51049. TooltipWindow::outlineColourId, 0x4c000000,
  51050. TabbedComponent::backgroundColourId, 0x00000000,
  51051. TabbedComponent::outlineColourId, 0xff777777,
  51052. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51053. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51054. Toolbar::backgroundColourId, 0xfff6f8f9,
  51055. Toolbar::separatorColourId, 0x4c000000,
  51056. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51057. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51058. Toolbar::labelTextColourId, 0xff000000,
  51059. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51060. HyperlinkButton::textColourId, 0xcc1111ee,
  51061. GroupComponent::outlineColourId, 0x66000000,
  51062. GroupComponent::textColourId, 0xff000000,
  51063. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51064. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51065. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51066. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51067. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51068. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51069. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51070. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51071. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51072. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51073. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51074. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51075. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51076. CodeEditorComponent::caretColourId, 0xff000000,
  51077. CodeEditorComponent::highlightColourId, textHighlightColour,
  51078. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51079. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51080. ColourSelector::labelTextColourId, 0xff000000,
  51081. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51082. KeyMappingEditorComponent::textColourId, 0xff000000,
  51083. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51084. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51085. };
  51086. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51087. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51088. if (defaultSansName.isEmpty())
  51089. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51090. defaultSans = defaultSansName;
  51091. defaultSerif = defaultSerifName;
  51092. defaultFixed = defaultFixedName;
  51093. }
  51094. LookAndFeel::~LookAndFeel()
  51095. {
  51096. }
  51097. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51098. {
  51099. const int index = colourIds.indexOf (colourId);
  51100. if (index >= 0)
  51101. return colours [index];
  51102. jassertfalse
  51103. return Colours::black;
  51104. }
  51105. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51106. {
  51107. const int index = colourIds.indexOf (colourId);
  51108. if (index >= 0)
  51109. colours.set (index, colour);
  51110. colourIds.add (colourId);
  51111. colours.add (colour);
  51112. }
  51113. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51114. {
  51115. return colourIds.contains (colourId);
  51116. }
  51117. static LookAndFeel* defaultLF = 0;
  51118. static LookAndFeel* currentDefaultLF = 0;
  51119. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51120. {
  51121. // if this happens, your app hasn't initialised itself properly.. if you're
  51122. // trying to hack your own main() function, have a look at
  51123. // JUCEApplication::initialiseForGUI()
  51124. jassert (currentDefaultLF != 0);
  51125. return *currentDefaultLF;
  51126. }
  51127. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51128. {
  51129. if (newDefaultLookAndFeel == 0)
  51130. {
  51131. if (defaultLF == 0)
  51132. defaultLF = new LookAndFeel();
  51133. newDefaultLookAndFeel = defaultLF;
  51134. }
  51135. currentDefaultLF = newDefaultLookAndFeel;
  51136. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51137. {
  51138. Component* const c = Desktop::getInstance().getComponent (i);
  51139. if (c != 0)
  51140. c->sendLookAndFeelChange();
  51141. }
  51142. }
  51143. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51144. {
  51145. if (currentDefaultLF == defaultLF)
  51146. currentDefaultLF = 0;
  51147. deleteAndZero (defaultLF);
  51148. }
  51149. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51150. {
  51151. String faceName (font.getTypefaceName());
  51152. if (faceName == Font::getDefaultSansSerifFontName())
  51153. faceName = defaultSans;
  51154. else if (faceName == Font::getDefaultSerifFontName())
  51155. faceName = defaultSerif;
  51156. else if (faceName == Font::getDefaultMonospacedFontName())
  51157. faceName = defaultFixed;
  51158. Font f (font);
  51159. f.setTypefaceName (faceName);
  51160. return Typeface::createSystemTypefaceFor (f);
  51161. }
  51162. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51163. {
  51164. defaultSans = newName;
  51165. }
  51166. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51167. {
  51168. return component.getMouseCursor();
  51169. }
  51170. void LookAndFeel::drawButtonBackground (Graphics& g,
  51171. Button& button,
  51172. const Colour& backgroundColour,
  51173. bool isMouseOverButton,
  51174. bool isButtonDown)
  51175. {
  51176. const int width = button.getWidth();
  51177. const int height = button.getHeight();
  51178. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51179. const float halfThickness = outlineThickness * 0.5f;
  51180. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51181. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51182. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51183. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51184. const Colour baseColour (createBaseColour (backgroundColour,
  51185. button.hasKeyboardFocus (true),
  51186. isMouseOverButton, isButtonDown)
  51187. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51188. drawGlassLozenge (g,
  51189. indentL,
  51190. indentT,
  51191. width - indentL - indentR,
  51192. height - indentT - indentB,
  51193. baseColour, outlineThickness, -1.0f,
  51194. button.isConnectedOnLeft(),
  51195. button.isConnectedOnRight(),
  51196. button.isConnectedOnTop(),
  51197. button.isConnectedOnBottom());
  51198. }
  51199. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51200. {
  51201. return button.getFont();
  51202. }
  51203. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51204. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51205. {
  51206. Font font (getFontForTextButton (button));
  51207. g.setFont (font);
  51208. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51209. : TextButton::textColourOffId)
  51210. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51211. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51212. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51213. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51214. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51215. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51216. g.drawFittedText (button.getButtonText(),
  51217. leftIndent,
  51218. yIndent,
  51219. button.getWidth() - leftIndent - rightIndent,
  51220. button.getHeight() - yIndent * 2,
  51221. Justification::centred, 2);
  51222. }
  51223. void LookAndFeel::drawTickBox (Graphics& g,
  51224. Component& component,
  51225. float x, float y, float w, float h,
  51226. const bool ticked,
  51227. const bool isEnabled,
  51228. const bool isMouseOverButton,
  51229. const bool isButtonDown)
  51230. {
  51231. const float boxSize = w * 0.7f;
  51232. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51233. createBaseColour (component.findColour (TextButton::buttonColourId)
  51234. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51235. true,
  51236. isMouseOverButton,
  51237. isButtonDown),
  51238. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51239. if (ticked)
  51240. {
  51241. Path tick;
  51242. tick.startNewSubPath (1.5f, 3.0f);
  51243. tick.lineTo (3.0f, 6.0f);
  51244. tick.lineTo (6.0f, 0.0f);
  51245. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51246. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51247. .translated (x, y));
  51248. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51249. }
  51250. }
  51251. void LookAndFeel::drawToggleButton (Graphics& g,
  51252. ToggleButton& button,
  51253. bool isMouseOverButton,
  51254. bool isButtonDown)
  51255. {
  51256. if (button.hasKeyboardFocus (true))
  51257. {
  51258. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51259. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51260. }
  51261. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51262. const float tickWidth = fontSize * 1.1f;
  51263. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51264. tickWidth, tickWidth,
  51265. button.getToggleState(),
  51266. button.isEnabled(),
  51267. isMouseOverButton,
  51268. isButtonDown);
  51269. g.setColour (button.findColour (ToggleButton::textColourId));
  51270. g.setFont (fontSize);
  51271. if (! button.isEnabled())
  51272. g.setOpacity (0.5f);
  51273. const int textX = (int) tickWidth + 5;
  51274. g.drawFittedText (button.getButtonText(),
  51275. textX, 0,
  51276. button.getWidth() - textX - 2, button.getHeight(),
  51277. Justification::centredLeft, 10);
  51278. }
  51279. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51280. {
  51281. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51282. const int tickWidth = jmin (24, button.getHeight());
  51283. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51284. button.getHeight());
  51285. }
  51286. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51287. const String& message,
  51288. const String& button1,
  51289. const String& button2,
  51290. const String& button3,
  51291. AlertWindow::AlertIconType iconType,
  51292. int numButtons,
  51293. Component* associatedComponent)
  51294. {
  51295. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51296. if (numButtons == 1)
  51297. {
  51298. aw->addButton (button1, 0,
  51299. KeyPress (KeyPress::escapeKey, 0, 0),
  51300. KeyPress (KeyPress::returnKey, 0, 0));
  51301. }
  51302. else
  51303. {
  51304. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51305. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51306. if (button1ShortCut == button2ShortCut)
  51307. button2ShortCut = KeyPress();
  51308. if (numButtons == 2)
  51309. {
  51310. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51311. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51312. }
  51313. else if (numButtons == 3)
  51314. {
  51315. aw->addButton (button1, 1, button1ShortCut);
  51316. aw->addButton (button2, 2, button2ShortCut);
  51317. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51318. }
  51319. }
  51320. return aw;
  51321. }
  51322. void LookAndFeel::drawAlertBox (Graphics& g,
  51323. AlertWindow& alert,
  51324. const Rectangle<int>& textArea,
  51325. TextLayout& textLayout)
  51326. {
  51327. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51328. int iconSpaceUsed = 0;
  51329. Justification alignment (Justification::horizontallyCentred);
  51330. const int iconWidth = 80;
  51331. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51332. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51333. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51334. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  51335. iconSize, iconSize);
  51336. if (alert.getAlertType() != AlertWindow::NoIcon)
  51337. {
  51338. Path icon;
  51339. uint32 colour;
  51340. char character;
  51341. if (alert.getAlertType() == AlertWindow::WarningIcon)
  51342. {
  51343. colour = 0x55ff5555;
  51344. character = '!';
  51345. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  51346. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  51347. (float) iconRect.getX(), (float) iconRect.getBottom());
  51348. icon = icon.createPathWithRoundedCorners (5.0f);
  51349. }
  51350. else
  51351. {
  51352. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  51353. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  51354. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  51355. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  51356. }
  51357. GlyphArrangement ga;
  51358. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  51359. String::charToString (character),
  51360. (float) iconRect.getX(), (float) iconRect.getY(),
  51361. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  51362. Justification::centred, false);
  51363. ga.createPath (icon);
  51364. icon.setUsingNonZeroWinding (false);
  51365. g.setColour (Colour (colour));
  51366. g.fillPath (icon);
  51367. iconSpaceUsed = iconWidth;
  51368. alignment = Justification::left;
  51369. }
  51370. g.setColour (alert.findColour (AlertWindow::textColourId));
  51371. textLayout.drawWithin (g,
  51372. textArea.getX() + iconSpaceUsed, textArea.getY(),
  51373. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  51374. alignment.getFlags() | Justification::top);
  51375. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  51376. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  51377. }
  51378. int LookAndFeel::getAlertBoxWindowFlags()
  51379. {
  51380. return ComponentPeer::windowAppearsOnTaskbar
  51381. | ComponentPeer::windowHasDropShadow;
  51382. }
  51383. int LookAndFeel::getAlertWindowButtonHeight()
  51384. {
  51385. return 28;
  51386. }
  51387. const Font LookAndFeel::getAlertWindowFont()
  51388. {
  51389. return Font (12.0f);
  51390. }
  51391. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  51392. int width, int height,
  51393. double progress, const String& textToShow)
  51394. {
  51395. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  51396. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  51397. g.fillAll (background);
  51398. if (progress >= 0.0f && progress < 1.0f)
  51399. {
  51400. drawGlassLozenge (g, 1.0f, 1.0f,
  51401. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  51402. (float) (height - 2),
  51403. foreground,
  51404. 0.5f, 0.0f,
  51405. true, true, true, true);
  51406. }
  51407. else
  51408. {
  51409. // spinning bar..
  51410. g.setColour (foreground);
  51411. const int stripeWidth = height * 2;
  51412. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  51413. Path p;
  51414. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  51415. p.addQuadrilateral (x, 0.0f,
  51416. x + stripeWidth * 0.5f, 0.0f,
  51417. x, (float) height,
  51418. x - stripeWidth * 0.5f, (float) height);
  51419. Image im (Image::ARGB, width, height, true);
  51420. {
  51421. Graphics g2 (im);
  51422. drawGlassLozenge (g2, 1.0f, 1.0f,
  51423. (float) (width - 2),
  51424. (float) (height - 2),
  51425. foreground,
  51426. 0.5f, 0.0f,
  51427. true, true, true, true);
  51428. }
  51429. g.setTiledImageFill (im, 0, 0, 0.85f);
  51430. g.fillPath (p);
  51431. }
  51432. if (textToShow.isNotEmpty())
  51433. {
  51434. g.setColour (Colour::contrasting (background, foreground));
  51435. g.setFont (height * 0.6f);
  51436. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  51437. }
  51438. }
  51439. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  51440. {
  51441. const float radius = jmin (w, h) * 0.4f;
  51442. const float thickness = radius * 0.15f;
  51443. Path p;
  51444. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  51445. radius * 0.6f, thickness,
  51446. thickness * 0.5f);
  51447. const float cx = x + w * 0.5f;
  51448. const float cy = y + h * 0.5f;
  51449. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  51450. for (int i = 0; i < 12; ++i)
  51451. {
  51452. const int n = (i + 12 - animationIndex) % 12;
  51453. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  51454. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  51455. .translated (cx, cy));
  51456. }
  51457. }
  51458. void LookAndFeel::drawScrollbarButton (Graphics& g,
  51459. ScrollBar& scrollbar,
  51460. int width, int height,
  51461. int buttonDirection,
  51462. bool /*isScrollbarVertical*/,
  51463. bool /*isMouseOverButton*/,
  51464. bool isButtonDown)
  51465. {
  51466. Path p;
  51467. if (buttonDirection == 0)
  51468. p.addTriangle (width * 0.5f, height * 0.2f,
  51469. width * 0.1f, height * 0.7f,
  51470. width * 0.9f, height * 0.7f);
  51471. else if (buttonDirection == 1)
  51472. p.addTriangle (width * 0.8f, height * 0.5f,
  51473. width * 0.3f, height * 0.1f,
  51474. width * 0.3f, height * 0.9f);
  51475. else if (buttonDirection == 2)
  51476. p.addTriangle (width * 0.5f, height * 0.8f,
  51477. width * 0.1f, height * 0.3f,
  51478. width * 0.9f, height * 0.3f);
  51479. else if (buttonDirection == 3)
  51480. p.addTriangle (width * 0.2f, height * 0.5f,
  51481. width * 0.7f, height * 0.1f,
  51482. width * 0.7f, height * 0.9f);
  51483. if (isButtonDown)
  51484. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  51485. else
  51486. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51487. g.fillPath (p);
  51488. g.setColour (Colour (0x80000000));
  51489. g.strokePath (p, PathStrokeType (0.5f));
  51490. }
  51491. void LookAndFeel::drawScrollbar (Graphics& g,
  51492. ScrollBar& scrollbar,
  51493. int x, int y,
  51494. int width, int height,
  51495. bool isScrollbarVertical,
  51496. int thumbStartPosition,
  51497. int thumbSize,
  51498. bool /*isMouseOver*/,
  51499. bool /*isMouseDown*/)
  51500. {
  51501. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  51502. Path slotPath, thumbPath;
  51503. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  51504. const float slotIndentx2 = slotIndent * 2.0f;
  51505. const float thumbIndent = slotIndent + 1.0f;
  51506. const float thumbIndentx2 = thumbIndent * 2.0f;
  51507. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  51508. if (isScrollbarVertical)
  51509. {
  51510. slotPath.addRoundedRectangle (x + slotIndent,
  51511. y + slotIndent,
  51512. width - slotIndentx2,
  51513. height - slotIndentx2,
  51514. (width - slotIndentx2) * 0.5f);
  51515. if (thumbSize > 0)
  51516. thumbPath.addRoundedRectangle (x + thumbIndent,
  51517. thumbStartPosition + thumbIndent,
  51518. width - thumbIndentx2,
  51519. thumbSize - thumbIndentx2,
  51520. (width - thumbIndentx2) * 0.5f);
  51521. gx1 = (float) x;
  51522. gx2 = x + width * 0.7f;
  51523. }
  51524. else
  51525. {
  51526. slotPath.addRoundedRectangle (x + slotIndent,
  51527. y + slotIndent,
  51528. width - slotIndentx2,
  51529. height - slotIndentx2,
  51530. (height - slotIndentx2) * 0.5f);
  51531. if (thumbSize > 0)
  51532. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  51533. y + thumbIndent,
  51534. thumbSize - thumbIndentx2,
  51535. height - thumbIndentx2,
  51536. (height - thumbIndentx2) * 0.5f);
  51537. gy1 = (float) y;
  51538. gy2 = y + height * 0.7f;
  51539. }
  51540. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51541. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  51542. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  51543. g.fillPath (slotPath);
  51544. if (isScrollbarVertical)
  51545. {
  51546. gx1 = x + width * 0.6f;
  51547. gx2 = (float) x + width;
  51548. }
  51549. else
  51550. {
  51551. gy1 = y + height * 0.6f;
  51552. gy2 = (float) y + height;
  51553. }
  51554. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  51555. Colour (0x19000000), gx2, gy2, false));
  51556. g.fillPath (slotPath);
  51557. g.setColour (thumbColour);
  51558. g.fillPath (thumbPath);
  51559. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  51560. Colours::transparentBlack, gx2, gy2, false));
  51561. g.saveState();
  51562. if (isScrollbarVertical)
  51563. g.reduceClipRegion (x + width / 2, y, width, height);
  51564. else
  51565. g.reduceClipRegion (x, y + height / 2, width, height);
  51566. g.fillPath (thumbPath);
  51567. g.restoreState();
  51568. g.setColour (Colour (0x4c000000));
  51569. g.strokePath (thumbPath, PathStrokeType (0.4f));
  51570. }
  51571. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  51572. {
  51573. return 0;
  51574. }
  51575. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  51576. {
  51577. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  51578. }
  51579. int LookAndFeel::getDefaultScrollbarWidth()
  51580. {
  51581. return 18;
  51582. }
  51583. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  51584. {
  51585. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  51586. : scrollbar.getHeight());
  51587. }
  51588. const Path LookAndFeel::getTickShape (const float height)
  51589. {
  51590. static const unsigned char tickShapeData[] =
  51591. {
  51592. 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,
  51593. 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,
  51594. 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,
  51595. 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,
  51596. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  51597. };
  51598. Path p;
  51599. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  51600. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51601. return p;
  51602. }
  51603. const Path LookAndFeel::getCrossShape (const float height)
  51604. {
  51605. static const unsigned char crossShapeData[] =
  51606. {
  51607. 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,
  51608. 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,
  51609. 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,
  51610. 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,
  51611. 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,
  51612. 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,
  51613. 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
  51614. };
  51615. Path p;
  51616. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  51617. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51618. return p;
  51619. }
  51620. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  51621. {
  51622. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  51623. x += (w - boxSize) >> 1;
  51624. y += (h - boxSize) >> 1;
  51625. w = boxSize;
  51626. h = boxSize;
  51627. g.setColour (Colour (0xe5ffffff));
  51628. g.fillRect (x, y, w, h);
  51629. g.setColour (Colour (0x80000000));
  51630. g.drawRect (x, y, w, h);
  51631. const float size = boxSize / 2 + 1.0f;
  51632. const float centre = (float) (boxSize / 2);
  51633. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  51634. if (isPlus)
  51635. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  51636. }
  51637. void LookAndFeel::drawBubble (Graphics& g,
  51638. float tipX, float tipY,
  51639. float boxX, float boxY,
  51640. float boxW, float boxH)
  51641. {
  51642. int side = 0;
  51643. if (tipX < boxX)
  51644. side = 1;
  51645. else if (tipX > boxX + boxW)
  51646. side = 3;
  51647. else if (tipY > boxY + boxH)
  51648. side = 2;
  51649. const float indent = 2.0f;
  51650. Path p;
  51651. p.addBubble (boxX + indent,
  51652. boxY + indent,
  51653. boxW - indent * 2.0f,
  51654. boxH - indent * 2.0f,
  51655. 5.0f,
  51656. tipX, tipY,
  51657. side,
  51658. 0.5f,
  51659. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  51660. //xxx need to take comp as param for colour
  51661. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  51662. g.fillPath (p);
  51663. //xxx as above
  51664. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  51665. g.strokePath (p, PathStrokeType (1.33f));
  51666. }
  51667. const Font LookAndFeel::getPopupMenuFont()
  51668. {
  51669. return Font (17.0f);
  51670. }
  51671. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  51672. const bool isSeparator,
  51673. int standardMenuItemHeight,
  51674. int& idealWidth,
  51675. int& idealHeight)
  51676. {
  51677. if (isSeparator)
  51678. {
  51679. idealWidth = 50;
  51680. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  51681. }
  51682. else
  51683. {
  51684. Font font (getPopupMenuFont());
  51685. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  51686. font.setHeight (standardMenuItemHeight / 1.3f);
  51687. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  51688. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  51689. }
  51690. }
  51691. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  51692. {
  51693. const Colour background (findColour (PopupMenu::backgroundColourId));
  51694. g.fillAll (background);
  51695. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  51696. for (int i = 0; i < height; i += 3)
  51697. g.fillRect (0, i, width, 1);
  51698. #if ! JUCE_MAC
  51699. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  51700. g.drawRect (0, 0, width, height);
  51701. #endif
  51702. }
  51703. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  51704. int width, int height,
  51705. bool isScrollUpArrow)
  51706. {
  51707. const Colour background (findColour (PopupMenu::backgroundColourId));
  51708. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  51709. background.withAlpha (0.0f),
  51710. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  51711. false));
  51712. g.fillRect (1, 1, width - 2, height - 2);
  51713. const float hw = width * 0.5f;
  51714. const float arrowW = height * 0.3f;
  51715. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  51716. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  51717. Path p;
  51718. p.addTriangle (hw - arrowW, y1,
  51719. hw + arrowW, y1,
  51720. hw, y2);
  51721. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  51722. g.fillPath (p);
  51723. }
  51724. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  51725. int width, int height,
  51726. const bool isSeparator,
  51727. const bool isActive,
  51728. const bool isHighlighted,
  51729. const bool isTicked,
  51730. const bool hasSubMenu,
  51731. const String& text,
  51732. const String& shortcutKeyText,
  51733. Image* image,
  51734. const Colour* const textColourToUse)
  51735. {
  51736. const float halfH = height * 0.5f;
  51737. if (isSeparator)
  51738. {
  51739. const float separatorIndent = 5.5f;
  51740. g.setColour (Colour (0x33000000));
  51741. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  51742. g.setColour (Colour (0x66ffffff));
  51743. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  51744. }
  51745. else
  51746. {
  51747. Colour textColour (findColour (PopupMenu::textColourId));
  51748. if (textColourToUse != 0)
  51749. textColour = *textColourToUse;
  51750. if (isHighlighted)
  51751. {
  51752. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  51753. g.fillRect (1, 1, width - 2, height - 2);
  51754. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  51755. }
  51756. else
  51757. {
  51758. g.setColour (textColour);
  51759. }
  51760. if (! isActive)
  51761. g.setOpacity (0.3f);
  51762. Font font (getPopupMenuFont());
  51763. if (font.getHeight() > height / 1.3f)
  51764. font.setHeight (height / 1.3f);
  51765. g.setFont (font);
  51766. const int leftBorder = (height * 5) / 4;
  51767. const int rightBorder = 4;
  51768. if (image != 0)
  51769. {
  51770. g.drawImageWithin (image,
  51771. 2, 1, leftBorder - 4, height - 2,
  51772. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  51773. }
  51774. else if (isTicked)
  51775. {
  51776. const Path tick (getTickShape (1.0f));
  51777. const float th = font.getAscent();
  51778. const float ty = halfH - th * 0.5f;
  51779. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  51780. th, true));
  51781. }
  51782. g.drawFittedText (text,
  51783. leftBorder, 0,
  51784. width - (leftBorder + rightBorder), height,
  51785. Justification::centredLeft, 1);
  51786. if (shortcutKeyText.isNotEmpty())
  51787. {
  51788. Font f2 (font);
  51789. f2.setHeight (f2.getHeight() * 0.75f);
  51790. f2.setHorizontalScale (0.95f);
  51791. g.setFont (f2);
  51792. g.drawText (shortcutKeyText,
  51793. leftBorder,
  51794. 0,
  51795. width - (leftBorder + rightBorder + 4),
  51796. height,
  51797. Justification::centredRight,
  51798. true);
  51799. }
  51800. if (hasSubMenu)
  51801. {
  51802. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  51803. const float x = width - height * 0.6f;
  51804. Path p;
  51805. p.addTriangle (x, halfH - arrowH * 0.5f,
  51806. x, halfH + arrowH * 0.5f,
  51807. x + arrowH * 0.6f, halfH);
  51808. g.fillPath (p);
  51809. }
  51810. }
  51811. }
  51812. int LookAndFeel::getMenuWindowFlags()
  51813. {
  51814. return ComponentPeer::windowHasDropShadow;
  51815. }
  51816. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  51817. bool, MenuBarComponent& menuBar)
  51818. {
  51819. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  51820. if (menuBar.isEnabled())
  51821. {
  51822. drawShinyButtonShape (g,
  51823. -4.0f, 0.0f,
  51824. width + 8.0f, (float) height,
  51825. 0.0f,
  51826. baseColour,
  51827. 0.4f,
  51828. true, true, true, true);
  51829. }
  51830. else
  51831. {
  51832. g.fillAll (baseColour);
  51833. }
  51834. }
  51835. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  51836. {
  51837. return Font (menuBar.getHeight() * 0.7f);
  51838. }
  51839. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  51840. {
  51841. return getMenuBarFont (menuBar, itemIndex, itemText)
  51842. .getStringWidth (itemText) + menuBar.getHeight();
  51843. }
  51844. void LookAndFeel::drawMenuBarItem (Graphics& g,
  51845. int width, int height,
  51846. int itemIndex,
  51847. const String& itemText,
  51848. bool isMouseOverItem,
  51849. bool isMenuOpen,
  51850. bool /*isMouseOverBar*/,
  51851. MenuBarComponent& menuBar)
  51852. {
  51853. if (! menuBar.isEnabled())
  51854. {
  51855. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  51856. .withMultipliedAlpha (0.5f));
  51857. }
  51858. else if (isMenuOpen || isMouseOverItem)
  51859. {
  51860. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  51861. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  51862. }
  51863. else
  51864. {
  51865. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  51866. }
  51867. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  51868. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  51869. }
  51870. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  51871. TextEditor& textEditor)
  51872. {
  51873. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  51874. }
  51875. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  51876. {
  51877. if (textEditor.isEnabled())
  51878. {
  51879. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  51880. {
  51881. const int border = 2;
  51882. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  51883. g.drawRect (0, 0, width, height, border);
  51884. g.setOpacity (1.0f);
  51885. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  51886. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  51887. }
  51888. else
  51889. {
  51890. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  51891. g.drawRect (0, 0, width, height);
  51892. g.setOpacity (1.0f);
  51893. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  51894. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  51895. }
  51896. }
  51897. }
  51898. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  51899. const bool isButtonDown,
  51900. int buttonX, int buttonY,
  51901. int buttonW, int buttonH,
  51902. ComboBox& box)
  51903. {
  51904. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  51905. if (box.isEnabled() && box.hasKeyboardFocus (false))
  51906. {
  51907. g.setColour (box.findColour (TextButton::buttonColourId));
  51908. g.drawRect (0, 0, width, height, 2);
  51909. }
  51910. else
  51911. {
  51912. g.setColour (box.findColour (ComboBox::outlineColourId));
  51913. g.drawRect (0, 0, width, height);
  51914. }
  51915. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  51916. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  51917. box.hasKeyboardFocus (true),
  51918. false, isButtonDown)
  51919. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  51920. drawGlassLozenge (g,
  51921. buttonX + outlineThickness, buttonY + outlineThickness,
  51922. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  51923. baseColour, outlineThickness, -1.0f,
  51924. true, true, true, true);
  51925. if (box.isEnabled())
  51926. {
  51927. const float arrowX = 0.3f;
  51928. const float arrowH = 0.2f;
  51929. Path p;
  51930. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  51931. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  51932. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  51933. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  51934. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  51935. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  51936. g.setColour (box.findColour (ComboBox::arrowColourId));
  51937. g.fillPath (p);
  51938. }
  51939. }
  51940. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  51941. {
  51942. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  51943. }
  51944. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  51945. {
  51946. return new Label (String::empty, String::empty);
  51947. }
  51948. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  51949. {
  51950. label.setBounds (1, 1,
  51951. box.getWidth() + 3 - box.getHeight(),
  51952. box.getHeight() - 2);
  51953. label.setFont (getComboBoxFont (box));
  51954. }
  51955. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  51956. {
  51957. g.fillAll (label.findColour (Label::backgroundColourId));
  51958. if (! label.isBeingEdited())
  51959. {
  51960. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  51961. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  51962. g.setFont (label.getFont());
  51963. g.drawFittedText (label.getText(),
  51964. label.getHorizontalBorderSize(),
  51965. label.getVerticalBorderSize(),
  51966. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  51967. label.getHeight() - 2 * label.getVerticalBorderSize(),
  51968. label.getJustificationType(),
  51969. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  51970. label.getMinimumHorizontalScale());
  51971. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  51972. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  51973. }
  51974. else if (label.isEnabled())
  51975. {
  51976. g.setColour (label.findColour (Label::outlineColourId));
  51977. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  51978. }
  51979. }
  51980. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  51981. int x, int y,
  51982. int width, int height,
  51983. float /*sliderPos*/,
  51984. float /*minSliderPos*/,
  51985. float /*maxSliderPos*/,
  51986. const Slider::SliderStyle /*style*/,
  51987. Slider& slider)
  51988. {
  51989. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  51990. const Colour trackColour (slider.findColour (Slider::trackColourId));
  51991. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  51992. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  51993. Path indent;
  51994. if (slider.isHorizontal())
  51995. {
  51996. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  51997. const float ih = sliderRadius;
  51998. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  51999. gradCol2, 0.0f, iy + ih, false));
  52000. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52001. width + sliderRadius, ih,
  52002. 5.0f);
  52003. g.fillPath (indent);
  52004. }
  52005. else
  52006. {
  52007. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52008. const float iw = sliderRadius;
  52009. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52010. gradCol2, ix + iw, 0.0f, false));
  52011. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52012. iw, height + sliderRadius,
  52013. 5.0f);
  52014. g.fillPath (indent);
  52015. }
  52016. g.setColour (Colour (0x4c000000));
  52017. g.strokePath (indent, PathStrokeType (0.5f));
  52018. }
  52019. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52020. int x, int y,
  52021. int width, int height,
  52022. float sliderPos,
  52023. float minSliderPos,
  52024. float maxSliderPos,
  52025. const Slider::SliderStyle style,
  52026. Slider& slider)
  52027. {
  52028. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52029. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52030. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52031. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52032. slider.isMouseButtonDown() && slider.isEnabled()));
  52033. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52034. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52035. {
  52036. float kx, ky;
  52037. if (style == Slider::LinearVertical)
  52038. {
  52039. kx = x + width * 0.5f;
  52040. ky = sliderPos;
  52041. }
  52042. else
  52043. {
  52044. kx = sliderPos;
  52045. ky = y + height * 0.5f;
  52046. }
  52047. drawGlassSphere (g,
  52048. kx - sliderRadius,
  52049. ky - sliderRadius,
  52050. sliderRadius * 2.0f,
  52051. knobColour, outlineThickness);
  52052. }
  52053. else
  52054. {
  52055. if (style == Slider::ThreeValueVertical)
  52056. {
  52057. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52058. sliderPos - sliderRadius,
  52059. sliderRadius * 2.0f,
  52060. knobColour, outlineThickness);
  52061. }
  52062. else if (style == Slider::ThreeValueHorizontal)
  52063. {
  52064. drawGlassSphere (g,sliderPos - sliderRadius,
  52065. y + height * 0.5f - sliderRadius,
  52066. sliderRadius * 2.0f,
  52067. knobColour, outlineThickness);
  52068. }
  52069. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52070. {
  52071. const float sr = jmin (sliderRadius, width * 0.4f);
  52072. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52073. minSliderPos - sliderRadius,
  52074. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52075. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52076. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52077. }
  52078. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52079. {
  52080. const float sr = jmin (sliderRadius, height * 0.4f);
  52081. drawGlassPointer (g, minSliderPos - sr,
  52082. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52083. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52084. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52085. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52086. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52087. }
  52088. }
  52089. }
  52090. void LookAndFeel::drawLinearSlider (Graphics& g,
  52091. int x, int y,
  52092. int width, int height,
  52093. float sliderPos,
  52094. float minSliderPos,
  52095. float maxSliderPos,
  52096. const Slider::SliderStyle style,
  52097. Slider& slider)
  52098. {
  52099. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52100. if (style == Slider::LinearBar)
  52101. {
  52102. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52103. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52104. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52105. false,
  52106. isMouseOver,
  52107. isMouseOver || slider.isMouseButtonDown()));
  52108. drawShinyButtonShape (g,
  52109. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52110. baseColour,
  52111. slider.isEnabled() ? 0.9f : 0.3f,
  52112. true, true, true, true);
  52113. }
  52114. else
  52115. {
  52116. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52117. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52118. }
  52119. }
  52120. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52121. {
  52122. return jmin (7,
  52123. slider.getHeight() / 2,
  52124. slider.getWidth() / 2) + 2;
  52125. }
  52126. void LookAndFeel::drawRotarySlider (Graphics& g,
  52127. int x, int y,
  52128. int width, int height,
  52129. float sliderPos,
  52130. const float rotaryStartAngle,
  52131. const float rotaryEndAngle,
  52132. Slider& slider)
  52133. {
  52134. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52135. const float centreX = x + width * 0.5f;
  52136. const float centreY = y + height * 0.5f;
  52137. const float rx = centreX - radius;
  52138. const float ry = centreY - radius;
  52139. const float rw = radius * 2.0f;
  52140. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52141. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52142. if (radius > 12.0f)
  52143. {
  52144. if (slider.isEnabled())
  52145. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52146. else
  52147. g.setColour (Colour (0x80808080));
  52148. const float thickness = 0.7f;
  52149. {
  52150. Path filledArc;
  52151. filledArc.addPieSegment (rx, ry, rw, rw,
  52152. rotaryStartAngle,
  52153. angle,
  52154. thickness);
  52155. g.fillPath (filledArc);
  52156. }
  52157. if (thickness > 0)
  52158. {
  52159. const float innerRadius = radius * 0.2f;
  52160. Path p;
  52161. p.addTriangle (-innerRadius, 0.0f,
  52162. 0.0f, -radius * thickness * 1.1f,
  52163. innerRadius, 0.0f);
  52164. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52165. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52166. }
  52167. if (slider.isEnabled())
  52168. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52169. else
  52170. g.setColour (Colour (0x80808080));
  52171. Path outlineArc;
  52172. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52173. outlineArc.closeSubPath();
  52174. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52175. }
  52176. else
  52177. {
  52178. if (slider.isEnabled())
  52179. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52180. else
  52181. g.setColour (Colour (0x80808080));
  52182. Path p;
  52183. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52184. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52185. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52186. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52187. }
  52188. }
  52189. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52190. {
  52191. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52192. }
  52193. class SliderLabelComp : public Label
  52194. {
  52195. public:
  52196. SliderLabelComp() : Label (String::empty, String::empty) {}
  52197. ~SliderLabelComp() {}
  52198. void mouseWheelMove (const MouseEvent&, float, float) {}
  52199. };
  52200. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52201. {
  52202. Label* const l = new SliderLabelComp();
  52203. l->setJustificationType (Justification::centred);
  52204. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52205. l->setColour (Label::backgroundColourId,
  52206. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52207. : slider.findColour (Slider::textBoxBackgroundColourId));
  52208. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52209. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52210. l->setColour (TextEditor::backgroundColourId,
  52211. slider.findColour (Slider::textBoxBackgroundColourId)
  52212. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52213. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52214. return l;
  52215. }
  52216. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52217. {
  52218. return 0;
  52219. }
  52220. static const TextLayout layoutTooltipText (const String& text) throw()
  52221. {
  52222. const float tooltipFontSize = 12.0f;
  52223. const int maxToolTipWidth = 400;
  52224. const Font f (tooltipFontSize, Font::bold);
  52225. TextLayout tl (text, f);
  52226. tl.layout (maxToolTipWidth, Justification::left, true);
  52227. return tl;
  52228. }
  52229. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52230. {
  52231. const TextLayout tl (layoutTooltipText (tipText));
  52232. width = tl.getWidth() + 14;
  52233. height = tl.getHeight() + 6;
  52234. }
  52235. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52236. {
  52237. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52238. const Colour textCol (findColour (TooltipWindow::textColourId));
  52239. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52240. g.setColour (findColour (TooltipWindow::outlineColourId));
  52241. g.drawRect (0, 0, width, height, 1);
  52242. #endif
  52243. const TextLayout tl (layoutTooltipText (text));
  52244. g.setColour (findColour (TooltipWindow::textColourId));
  52245. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52246. }
  52247. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52248. {
  52249. return new TextButton (text, TRANS("click to browse for a different file"));
  52250. }
  52251. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52252. ComboBox* filenameBox,
  52253. Button* browseButton)
  52254. {
  52255. browseButton->setSize (80, filenameComp.getHeight());
  52256. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52257. if (tb != 0)
  52258. tb->changeWidthToFitText();
  52259. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52260. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52261. }
  52262. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52263. int imageX, int imageY, int imageW, int imageH,
  52264. const Colour& overlayColour,
  52265. float imageOpacity,
  52266. ImageButton& button)
  52267. {
  52268. if (! button.isEnabled())
  52269. imageOpacity *= 0.3f;
  52270. if (! overlayColour.isOpaque())
  52271. {
  52272. g.setOpacity (imageOpacity);
  52273. g.drawImage (image, imageX, imageY, imageW, imageH,
  52274. 0, 0, image->getWidth(), image->getHeight(), false);
  52275. }
  52276. if (! overlayColour.isTransparent())
  52277. {
  52278. g.setColour (overlayColour);
  52279. g.drawImage (image, imageX, imageY, imageW, imageH,
  52280. 0, 0, image->getWidth(), image->getHeight(), true);
  52281. }
  52282. }
  52283. void LookAndFeel::drawCornerResizer (Graphics& g,
  52284. int w, int h,
  52285. bool /*isMouseOver*/,
  52286. bool /*isMouseDragging*/)
  52287. {
  52288. const float lineThickness = jmin (w, h) * 0.075f;
  52289. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52290. {
  52291. g.setColour (Colours::lightgrey);
  52292. g.drawLine (w * i,
  52293. h + 1.0f,
  52294. w + 1.0f,
  52295. h * i,
  52296. lineThickness);
  52297. g.setColour (Colours::darkgrey);
  52298. g.drawLine (w * i + lineThickness,
  52299. h + 1.0f,
  52300. w + 1.0f,
  52301. h * i + lineThickness,
  52302. lineThickness);
  52303. }
  52304. }
  52305. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52306. const BorderSize& /*borders*/)
  52307. {
  52308. }
  52309. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52310. const BorderSize& /*border*/, ResizableWindow& window)
  52311. {
  52312. g.fillAll (window.getBackgroundColour());
  52313. }
  52314. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52315. const BorderSize& border, ResizableWindow&)
  52316. {
  52317. g.setColour (Colour (0x80000000));
  52318. g.drawRect (0, 0, w, h);
  52319. g.setColour (Colour (0x19000000));
  52320. g.drawRect (border.getLeft() - 1,
  52321. border.getTop() - 1,
  52322. w + 2 - border.getLeftAndRight(),
  52323. h + 2 - border.getTopAndBottom());
  52324. }
  52325. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52326. Graphics& g, int w, int h,
  52327. int titleSpaceX, int titleSpaceW,
  52328. const Image* icon,
  52329. bool drawTitleTextOnLeft)
  52330. {
  52331. const bool isActive = window.isActiveWindow();
  52332. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52333. 0.0f, 0.0f,
  52334. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52335. 0.0f, (float) h, false));
  52336. g.fillAll();
  52337. Font font (h * 0.65f, Font::bold);
  52338. g.setFont (font);
  52339. int textW = font.getStringWidth (window.getName());
  52340. int iconW = 0;
  52341. int iconH = 0;
  52342. if (icon != 0)
  52343. {
  52344. iconH = (int) font.getHeight();
  52345. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  52346. }
  52347. textW = jmin (titleSpaceW, textW + iconW);
  52348. int textX = drawTitleTextOnLeft ? titleSpaceX
  52349. : jmax (titleSpaceX, (w - textW) / 2);
  52350. if (textX + textW > titleSpaceX + titleSpaceW)
  52351. textX = titleSpaceX + titleSpaceW - textW;
  52352. if (icon != 0)
  52353. {
  52354. g.setOpacity (isActive ? 1.0f : 0.6f);
  52355. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  52356. RectanglePlacement::centred, false);
  52357. textX += iconW;
  52358. textW -= iconW;
  52359. }
  52360. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  52361. g.setColour (findColour (DocumentWindow::textColourId));
  52362. else
  52363. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  52364. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  52365. }
  52366. class GlassWindowButton : public Button
  52367. {
  52368. public:
  52369. GlassWindowButton (const String& name, const Colour& col,
  52370. const Path& normalShape_,
  52371. const Path& toggledShape_) throw()
  52372. : Button (name),
  52373. colour (col),
  52374. normalShape (normalShape_),
  52375. toggledShape (toggledShape_)
  52376. {
  52377. }
  52378. ~GlassWindowButton()
  52379. {
  52380. }
  52381. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  52382. {
  52383. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  52384. if (! isEnabled())
  52385. alpha *= 0.5f;
  52386. float x = 0, y = 0, diam;
  52387. if (getWidth() < getHeight())
  52388. {
  52389. diam = (float) getWidth();
  52390. y = (getHeight() - getWidth()) * 0.5f;
  52391. }
  52392. else
  52393. {
  52394. diam = (float) getHeight();
  52395. y = (getWidth() - getHeight()) * 0.5f;
  52396. }
  52397. x += diam * 0.05f;
  52398. y += diam * 0.05f;
  52399. diam *= 0.9f;
  52400. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  52401. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  52402. g.fillEllipse (x, y, diam, diam);
  52403. x += 2.0f;
  52404. y += 2.0f;
  52405. diam -= 4.0f;
  52406. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  52407. Path& p = getToggleState() ? toggledShape : normalShape;
  52408. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  52409. diam * 0.4f, diam * 0.4f, true));
  52410. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  52411. g.fillPath (p, t);
  52412. }
  52413. juce_UseDebuggingNewOperator
  52414. private:
  52415. Colour colour;
  52416. Path normalShape, toggledShape;
  52417. GlassWindowButton (const GlassWindowButton&);
  52418. GlassWindowButton& operator= (const GlassWindowButton&);
  52419. };
  52420. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  52421. {
  52422. Path shape;
  52423. const float crossThickness = 0.25f;
  52424. if (buttonType == DocumentWindow::closeButton)
  52425. {
  52426. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  52427. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  52428. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  52429. }
  52430. else if (buttonType == DocumentWindow::minimiseButton)
  52431. {
  52432. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52433. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  52434. }
  52435. else if (buttonType == DocumentWindow::maximiseButton)
  52436. {
  52437. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  52438. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52439. Path fullscreenShape;
  52440. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  52441. fullscreenShape.lineTo (0.0f, 100.0f);
  52442. fullscreenShape.lineTo (0.0f, 0.0f);
  52443. fullscreenShape.lineTo (100.0f, 0.0f);
  52444. fullscreenShape.lineTo (100.0f, 45.0f);
  52445. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  52446. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  52447. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  52448. }
  52449. jassertfalse
  52450. return 0;
  52451. }
  52452. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  52453. int titleBarX,
  52454. int titleBarY,
  52455. int titleBarW,
  52456. int titleBarH,
  52457. Button* minimiseButton,
  52458. Button* maximiseButton,
  52459. Button* closeButton,
  52460. bool positionTitleBarButtonsOnLeft)
  52461. {
  52462. const int buttonW = titleBarH - titleBarH / 8;
  52463. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  52464. : titleBarX + titleBarW - buttonW - buttonW / 4;
  52465. if (closeButton != 0)
  52466. {
  52467. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52468. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  52469. }
  52470. if (positionTitleBarButtonsOnLeft)
  52471. swapVariables (minimiseButton, maximiseButton);
  52472. if (maximiseButton != 0)
  52473. {
  52474. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52475. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  52476. }
  52477. if (minimiseButton != 0)
  52478. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52479. }
  52480. int LookAndFeel::getDefaultMenuBarHeight()
  52481. {
  52482. return 24;
  52483. }
  52484. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  52485. {
  52486. return new DropShadower (0.4f, 1, 5, 10);
  52487. }
  52488. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  52489. int w, int h,
  52490. bool /*isVerticalBar*/,
  52491. bool isMouseOver,
  52492. bool isMouseDragging)
  52493. {
  52494. float alpha = 0.5f;
  52495. if (isMouseOver || isMouseDragging)
  52496. {
  52497. g.fillAll (Colour (0x190000ff));
  52498. alpha = 1.0f;
  52499. }
  52500. const float cx = w * 0.5f;
  52501. const float cy = h * 0.5f;
  52502. const float cr = jmin (w, h) * 0.4f;
  52503. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  52504. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  52505. true));
  52506. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  52507. }
  52508. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  52509. const String& text,
  52510. const Justification& position,
  52511. GroupComponent& group)
  52512. {
  52513. const float textH = 15.0f;
  52514. const float indent = 3.0f;
  52515. const float textEdgeGap = 4.0f;
  52516. float cs = 5.0f;
  52517. Font f (textH);
  52518. Path p;
  52519. float x = indent;
  52520. float y = f.getAscent() - 3.0f;
  52521. float w = jmax (0.0f, width - x * 2.0f);
  52522. float h = jmax (0.0f, height - y - indent);
  52523. cs = jmin (cs, w * 0.5f, h * 0.5f);
  52524. const float cs2 = 2.0f * cs;
  52525. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  52526. float textX = cs + textEdgeGap;
  52527. if (position.testFlags (Justification::horizontallyCentred))
  52528. textX = cs + (w - cs2 - textW) * 0.5f;
  52529. else if (position.testFlags (Justification::right))
  52530. textX = w - cs - textW - textEdgeGap;
  52531. p.startNewSubPath (x + textX + textW, y);
  52532. p.lineTo (x + w - cs, y);
  52533. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  52534. p.lineTo (x + w, y + h - cs);
  52535. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  52536. p.lineTo (x + cs, y + h);
  52537. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  52538. p.lineTo (x, y + cs);
  52539. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  52540. p.lineTo (x + textX, y);
  52541. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  52542. g.setColour (group.findColour (GroupComponent::outlineColourId)
  52543. .withMultipliedAlpha (alpha));
  52544. g.strokePath (p, PathStrokeType (2.0f));
  52545. g.setColour (group.findColour (GroupComponent::textColourId)
  52546. .withMultipliedAlpha (alpha));
  52547. g.setFont (f);
  52548. g.drawText (text,
  52549. roundToInt (x + textX), 0,
  52550. roundToInt (textW),
  52551. roundToInt (textH),
  52552. Justification::centred, true);
  52553. }
  52554. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  52555. {
  52556. return 1 + tabDepth / 3;
  52557. }
  52558. int LookAndFeel::getTabButtonSpaceAroundImage()
  52559. {
  52560. return 4;
  52561. }
  52562. void LookAndFeel::createTabButtonShape (Path& p,
  52563. int width, int height,
  52564. int /*tabIndex*/,
  52565. const String& /*text*/,
  52566. Button& /*button*/,
  52567. TabbedButtonBar::Orientation orientation,
  52568. const bool /*isMouseOver*/,
  52569. const bool /*isMouseDown*/,
  52570. const bool /*isFrontTab*/)
  52571. {
  52572. const float w = (float) width;
  52573. const float h = (float) height;
  52574. float length = w;
  52575. float depth = h;
  52576. if (orientation == TabbedButtonBar::TabsAtLeft
  52577. || orientation == TabbedButtonBar::TabsAtRight)
  52578. {
  52579. swapVariables (length, depth);
  52580. }
  52581. const float indent = (float) getTabButtonOverlap ((int) depth);
  52582. const float overhang = 4.0f;
  52583. if (orientation == TabbedButtonBar::TabsAtLeft)
  52584. {
  52585. p.startNewSubPath (w, 0.0f);
  52586. p.lineTo (0.0f, indent);
  52587. p.lineTo (0.0f, h - indent);
  52588. p.lineTo (w, h);
  52589. p.lineTo (w + overhang, h + overhang);
  52590. p.lineTo (w + overhang, -overhang);
  52591. }
  52592. else if (orientation == TabbedButtonBar::TabsAtRight)
  52593. {
  52594. p.startNewSubPath (0.0f, 0.0f);
  52595. p.lineTo (w, indent);
  52596. p.lineTo (w, h - indent);
  52597. p.lineTo (0.0f, h);
  52598. p.lineTo (-overhang, h + overhang);
  52599. p.lineTo (-overhang, -overhang);
  52600. }
  52601. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52602. {
  52603. p.startNewSubPath (0.0f, 0.0f);
  52604. p.lineTo (indent, h);
  52605. p.lineTo (w - indent, h);
  52606. p.lineTo (w, 0.0f);
  52607. p.lineTo (w + overhang, -overhang);
  52608. p.lineTo (-overhang, -overhang);
  52609. }
  52610. else
  52611. {
  52612. p.startNewSubPath (0.0f, h);
  52613. p.lineTo (indent, 0.0f);
  52614. p.lineTo (w - indent, 0.0f);
  52615. p.lineTo (w, h);
  52616. p.lineTo (w + overhang, h + overhang);
  52617. p.lineTo (-overhang, h + overhang);
  52618. }
  52619. p.closeSubPath();
  52620. p = p.createPathWithRoundedCorners (3.0f);
  52621. }
  52622. void LookAndFeel::fillTabButtonShape (Graphics& g,
  52623. const Path& path,
  52624. const Colour& preferredColour,
  52625. int /*tabIndex*/,
  52626. const String& /*text*/,
  52627. Button& button,
  52628. TabbedButtonBar::Orientation /*orientation*/,
  52629. const bool /*isMouseOver*/,
  52630. const bool /*isMouseDown*/,
  52631. const bool isFrontTab)
  52632. {
  52633. g.setColour (isFrontTab ? preferredColour
  52634. : preferredColour.withMultipliedAlpha (0.9f));
  52635. g.fillPath (path);
  52636. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  52637. : TabbedButtonBar::tabOutlineColourId, false)
  52638. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  52639. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  52640. }
  52641. void LookAndFeel::drawTabButtonText (Graphics& g,
  52642. int x, int y, int w, int h,
  52643. const Colour& preferredBackgroundColour,
  52644. int /*tabIndex*/,
  52645. const String& text,
  52646. Button& button,
  52647. TabbedButtonBar::Orientation orientation,
  52648. const bool isMouseOver,
  52649. const bool isMouseDown,
  52650. const bool isFrontTab)
  52651. {
  52652. int length = w;
  52653. int depth = h;
  52654. if (orientation == TabbedButtonBar::TabsAtLeft
  52655. || orientation == TabbedButtonBar::TabsAtRight)
  52656. {
  52657. swapVariables (length, depth);
  52658. }
  52659. Font font (depth * 0.6f);
  52660. font.setUnderline (button.hasKeyboardFocus (false));
  52661. GlyphArrangement textLayout;
  52662. textLayout.addFittedText (font, text.trim(),
  52663. 0.0f, 0.0f, (float) length, (float) depth,
  52664. Justification::centred,
  52665. jmax (1, depth / 12));
  52666. AffineTransform transform;
  52667. if (orientation == TabbedButtonBar::TabsAtLeft)
  52668. {
  52669. transform = transform.rotated (float_Pi * -0.5f)
  52670. .translated ((float) x, (float) (y + h));
  52671. }
  52672. else if (orientation == TabbedButtonBar::TabsAtRight)
  52673. {
  52674. transform = transform.rotated (float_Pi * 0.5f)
  52675. .translated ((float) (x + w), (float) y);
  52676. }
  52677. else
  52678. {
  52679. transform = transform.translated ((float) x, (float) y);
  52680. }
  52681. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  52682. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  52683. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  52684. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  52685. else
  52686. g.setColour (preferredBackgroundColour.contrasting());
  52687. if (! (isMouseOver || isMouseDown))
  52688. g.setOpacity (0.8f);
  52689. if (! button.isEnabled())
  52690. g.setOpacity (0.3f);
  52691. textLayout.draw (g, transform);
  52692. }
  52693. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  52694. const String& text,
  52695. int tabDepth,
  52696. Button&)
  52697. {
  52698. Font f (tabDepth * 0.6f);
  52699. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  52700. }
  52701. void LookAndFeel::drawTabButton (Graphics& g,
  52702. int w, int h,
  52703. const Colour& preferredColour,
  52704. int tabIndex,
  52705. const String& text,
  52706. Button& button,
  52707. TabbedButtonBar::Orientation orientation,
  52708. const bool isMouseOver,
  52709. const bool isMouseDown,
  52710. const bool isFrontTab)
  52711. {
  52712. int length = w;
  52713. int depth = h;
  52714. if (orientation == TabbedButtonBar::TabsAtLeft
  52715. || orientation == TabbedButtonBar::TabsAtRight)
  52716. {
  52717. swapVariables (length, depth);
  52718. }
  52719. Path tabShape;
  52720. createTabButtonShape (tabShape, w, h,
  52721. tabIndex, text, button, orientation,
  52722. isMouseOver, isMouseDown, isFrontTab);
  52723. fillTabButtonShape (g, tabShape, preferredColour,
  52724. tabIndex, text, button, orientation,
  52725. isMouseOver, isMouseDown, isFrontTab);
  52726. const int indent = getTabButtonOverlap (depth);
  52727. int x = 0, y = 0;
  52728. if (orientation == TabbedButtonBar::TabsAtLeft
  52729. || orientation == TabbedButtonBar::TabsAtRight)
  52730. {
  52731. y += indent;
  52732. h -= indent * 2;
  52733. }
  52734. else
  52735. {
  52736. x += indent;
  52737. w -= indent * 2;
  52738. }
  52739. drawTabButtonText (g, x, y, w, h, preferredColour,
  52740. tabIndex, text, button, orientation,
  52741. isMouseOver, isMouseDown, isFrontTab);
  52742. }
  52743. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  52744. int w, int h,
  52745. TabbedButtonBar& tabBar,
  52746. TabbedButtonBar::Orientation orientation)
  52747. {
  52748. const float shadowSize = 0.2f;
  52749. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  52750. Rectangle<int> shadowRect;
  52751. if (orientation == TabbedButtonBar::TabsAtLeft)
  52752. {
  52753. x1 = (float) w;
  52754. x2 = w * (1.0f - shadowSize);
  52755. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  52756. }
  52757. else if (orientation == TabbedButtonBar::TabsAtRight)
  52758. {
  52759. x2 = w * shadowSize;
  52760. shadowRect.setBounds (0, 0, (int) x2, h);
  52761. }
  52762. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52763. {
  52764. y2 = h * shadowSize;
  52765. shadowRect.setBounds (0, 0, w, (int) y2);
  52766. }
  52767. else
  52768. {
  52769. y1 = (float) h;
  52770. y2 = h * (1.0f - shadowSize);
  52771. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  52772. }
  52773. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  52774. Colours::transparentBlack, x2, y2, false));
  52775. shadowRect.expand (2, 2);
  52776. g.fillRect (shadowRect);
  52777. g.setColour (Colour (0x80000000));
  52778. if (orientation == TabbedButtonBar::TabsAtLeft)
  52779. {
  52780. g.fillRect (w - 1, 0, 1, h);
  52781. }
  52782. else if (orientation == TabbedButtonBar::TabsAtRight)
  52783. {
  52784. g.fillRect (0, 0, 1, h);
  52785. }
  52786. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52787. {
  52788. g.fillRect (0, 0, w, 1);
  52789. }
  52790. else
  52791. {
  52792. g.fillRect (0, h - 1, w, 1);
  52793. }
  52794. }
  52795. Button* LookAndFeel::createTabBarExtrasButton()
  52796. {
  52797. const float thickness = 7.0f;
  52798. const float indent = 22.0f;
  52799. Path p;
  52800. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  52801. DrawablePath ellipse;
  52802. ellipse.setPath (p);
  52803. ellipse.setFill (Colour (0x99ffffff));
  52804. p.clear();
  52805. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  52806. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  52807. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  52808. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  52809. p.setUsingNonZeroWinding (false);
  52810. DrawablePath dp;
  52811. dp.setPath (p);
  52812. dp.setFill (Colour (0x59000000));
  52813. DrawableComposite normalImage;
  52814. normalImage.insertDrawable (ellipse);
  52815. normalImage.insertDrawable (dp);
  52816. dp.setFill (Colour (0xcc000000));
  52817. DrawableComposite overImage;
  52818. overImage.insertDrawable (ellipse);
  52819. overImage.insertDrawable (dp);
  52820. DrawableButton* db = new DrawableButton (T("tabs"), DrawableButton::ImageFitted);
  52821. db->setImages (&normalImage, &overImage, 0);
  52822. return db;
  52823. }
  52824. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  52825. {
  52826. g.fillAll (Colours::white);
  52827. const int w = header.getWidth();
  52828. const int h = header.getHeight();
  52829. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  52830. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  52831. false));
  52832. g.fillRect (0, h / 2, w, h);
  52833. g.setColour (Colour (0x33000000));
  52834. g.fillRect (0, h - 1, w, 1);
  52835. for (int i = header.getNumColumns (true); --i >= 0;)
  52836. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  52837. }
  52838. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  52839. int width, int height,
  52840. bool isMouseOver, bool isMouseDown,
  52841. int columnFlags)
  52842. {
  52843. if (isMouseDown)
  52844. g.fillAll (Colour (0x8899aadd));
  52845. else if (isMouseOver)
  52846. g.fillAll (Colour (0x5599aadd));
  52847. int rightOfText = width - 4;
  52848. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  52849. {
  52850. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  52851. const float bottom = height - top;
  52852. const float w = height * 0.5f;
  52853. const float x = rightOfText - (w * 1.25f);
  52854. rightOfText = (int) x;
  52855. Path sortArrow;
  52856. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  52857. g.setColour (Colour (0x99000000));
  52858. g.fillPath (sortArrow);
  52859. }
  52860. g.setColour (Colours::black);
  52861. g.setFont (height * 0.5f, Font::bold);
  52862. const int textX = 4;
  52863. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  52864. }
  52865. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  52866. {
  52867. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  52868. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  52869. background.darker (0.1f),
  52870. toolbar.isVertical() ? w - 1.0f : 0.0f,
  52871. toolbar.isVertical() ? 0.0f : h - 1.0f,
  52872. false));
  52873. g.fillAll();
  52874. }
  52875. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  52876. {
  52877. return createTabBarExtrasButton();
  52878. }
  52879. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  52880. bool isMouseOver, bool isMouseDown,
  52881. ToolbarItemComponent& component)
  52882. {
  52883. if (isMouseDown)
  52884. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  52885. else if (isMouseOver)
  52886. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  52887. }
  52888. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  52889. const String& text, ToolbarItemComponent& component)
  52890. {
  52891. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  52892. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  52893. const float fontHeight = jmin (14.0f, height * 0.85f);
  52894. g.setFont (fontHeight);
  52895. g.drawFittedText (text,
  52896. x, y, width, height,
  52897. Justification::centred,
  52898. jmax (1, height / (int) fontHeight));
  52899. }
  52900. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  52901. bool isOpen, int width, int height)
  52902. {
  52903. const int buttonSize = (height * 3) / 4;
  52904. const int buttonIndent = (height - buttonSize) / 2;
  52905. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  52906. const int textX = buttonIndent * 2 + buttonSize + 2;
  52907. g.setColour (Colours::black);
  52908. g.setFont (height * 0.7f, Font::bold);
  52909. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  52910. }
  52911. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  52912. PropertyComponent&)
  52913. {
  52914. g.setColour (Colour (0x66ffffff));
  52915. g.fillRect (0, 0, width, height - 1);
  52916. }
  52917. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  52918. PropertyComponent& component)
  52919. {
  52920. g.setColour (Colours::black);
  52921. if (! component.isEnabled())
  52922. g.setOpacity (0.6f);
  52923. g.setFont (jmin (height, 24) * 0.65f);
  52924. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  52925. g.drawFittedText (component.getName(),
  52926. 3, r.getY(), r.getX() - 5, r.getHeight(),
  52927. Justification::centredLeft, 2);
  52928. }
  52929. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  52930. {
  52931. return Rectangle<int> (component.getWidth() / 3, 1,
  52932. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  52933. }
  52934. void LookAndFeel::createFileChooserHeaderText (const String& title,
  52935. const String& instructions,
  52936. GlyphArrangement& text,
  52937. int width)
  52938. {
  52939. text.clear();
  52940. text.addJustifiedText (Font (17.0f, Font::bold), title,
  52941. 8.0f, 22.0f, width - 16.0f,
  52942. Justification::centred);
  52943. text.addJustifiedText (Font (14.0f), instructions,
  52944. 8.0f, 24.0f + 16.0f, width - 16.0f,
  52945. Justification::centred);
  52946. }
  52947. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  52948. const String& filename, Image* icon,
  52949. const String& fileSizeDescription,
  52950. const String& fileTimeDescription,
  52951. const bool isDirectory,
  52952. const bool isItemSelected,
  52953. const int /*itemIndex*/)
  52954. {
  52955. if (isItemSelected)
  52956. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  52957. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  52958. g.setFont (height * 0.7f);
  52959. Image* im = icon;
  52960. Image* toRelease = 0;
  52961. if (im == 0)
  52962. {
  52963. toRelease = im = (isDirectory ? getDefaultFolderImage()
  52964. : getDefaultDocumentFileImage());
  52965. }
  52966. const int x = 32;
  52967. if (im != 0)
  52968. {
  52969. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  52970. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  52971. false);
  52972. ImageCache::release (toRelease);
  52973. }
  52974. if (width > 450 && ! isDirectory)
  52975. {
  52976. const int sizeX = roundToInt (width * 0.7f);
  52977. const int dateX = roundToInt (width * 0.8f);
  52978. g.drawFittedText (filename,
  52979. x, 0, sizeX - x, height,
  52980. Justification::centredLeft, 1);
  52981. g.setFont (height * 0.5f);
  52982. g.setColour (Colours::darkgrey);
  52983. if (! isDirectory)
  52984. {
  52985. g.drawFittedText (fileSizeDescription,
  52986. sizeX, 0, dateX - sizeX - 8, height,
  52987. Justification::centredRight, 1);
  52988. g.drawFittedText (fileTimeDescription,
  52989. dateX, 0, width - 8 - dateX, height,
  52990. Justification::centredRight, 1);
  52991. }
  52992. }
  52993. else
  52994. {
  52995. g.drawFittedText (filename,
  52996. x, 0, width - x, height,
  52997. Justification::centredLeft, 1);
  52998. }
  52999. }
  53000. Button* LookAndFeel::createFileBrowserGoUpButton()
  53001. {
  53002. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53003. Path arrowPath;
  53004. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53005. DrawablePath arrowImage;
  53006. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53007. arrowImage.setPath (arrowPath);
  53008. goUpButton->setImages (&arrowImage);
  53009. return goUpButton;
  53010. }
  53011. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53012. DirectoryContentsDisplayComponent* fileListComponent,
  53013. FilePreviewComponent* previewComp,
  53014. ComboBox* currentPathBox,
  53015. TextEditor* filenameBox,
  53016. Button* goUpButton)
  53017. {
  53018. const int x = 8;
  53019. int w = browserComp.getWidth() - x - x;
  53020. if (previewComp != 0)
  53021. {
  53022. const int previewWidth = w / 3;
  53023. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53024. w -= previewWidth + 4;
  53025. }
  53026. int y = 4;
  53027. const int controlsHeight = 22;
  53028. const int bottomSectionHeight = controlsHeight + 8;
  53029. const int upButtonWidth = 50;
  53030. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53031. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53032. y += controlsHeight + 4;
  53033. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53034. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53035. y = listAsComp->getBottom() + 4;
  53036. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53037. }
  53038. Image* LookAndFeel::getDefaultFolderImage()
  53039. {
  53040. 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,
  53041. 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,
  53042. 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,
  53043. 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,
  53044. 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,
  53045. 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,
  53046. 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,
  53047. 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,
  53048. 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,
  53049. 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,
  53050. 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,
  53051. 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,
  53052. 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,
  53053. 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,
  53054. 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,
  53055. 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,
  53056. 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,
  53057. 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,
  53058. 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,
  53059. 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,
  53060. 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,
  53061. 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,
  53062. 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,
  53063. 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,
  53064. 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,
  53065. 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,
  53066. 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,
  53067. 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,
  53068. 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,
  53069. 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,
  53070. 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,
  53071. 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,
  53072. 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,
  53073. 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,
  53074. 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,
  53075. 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,
  53076. 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,
  53077. 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,
  53078. 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,
  53079. 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,
  53080. 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,
  53081. 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,
  53082. 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,
  53083. 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};
  53084. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53085. }
  53086. Image* LookAndFeel::getDefaultDocumentFileImage()
  53087. {
  53088. 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,
  53089. 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,
  53090. 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,
  53091. 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,
  53092. 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,
  53093. 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,
  53094. 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,
  53095. 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,
  53096. 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,
  53097. 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,
  53098. 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,
  53099. 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,
  53100. 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,
  53101. 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,
  53102. 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,
  53103. 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,
  53104. 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,
  53105. 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,
  53106. 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,
  53107. 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,
  53108. 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,
  53109. 174,66,96,130,0,0};
  53110. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53111. }
  53112. void LookAndFeel::playAlertSound()
  53113. {
  53114. PlatformUtilities::beep();
  53115. }
  53116. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53117. {
  53118. g.setColour (Colours::white.withAlpha (0.7f));
  53119. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53120. g.setColour (Colours::black.withAlpha (0.2f));
  53121. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53122. const int totalBlocks = 7;
  53123. const int numBlocks = roundToInt (totalBlocks * level);
  53124. const float w = (width - 6.0f) / (float) totalBlocks;
  53125. for (int i = 0; i < totalBlocks; ++i)
  53126. {
  53127. if (i >= numBlocks)
  53128. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53129. else
  53130. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53131. : Colours::red);
  53132. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53133. }
  53134. }
  53135. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53136. {
  53137. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53138. if (keyDescription.isNotEmpty())
  53139. {
  53140. if (button.isEnabled())
  53141. {
  53142. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53143. g.fillAll (textColour.withAlpha (alpha));
  53144. g.setOpacity (0.3f);
  53145. g.drawBevel (0, 0, width, height, 2);
  53146. }
  53147. g.setColour (textColour);
  53148. g.setFont (height * 0.6f);
  53149. g.drawFittedText (keyDescription,
  53150. 3, 0, width - 6, height,
  53151. Justification::centred, 1);
  53152. }
  53153. else
  53154. {
  53155. const float thickness = 7.0f;
  53156. const float indent = 22.0f;
  53157. Path p;
  53158. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53159. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53160. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53161. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53162. p.setUsingNonZeroWinding (false);
  53163. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53164. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53165. }
  53166. if (button.hasKeyboardFocus (false))
  53167. {
  53168. g.setColour (textColour.withAlpha (0.4f));
  53169. g.drawRect (0, 0, width, height);
  53170. }
  53171. }
  53172. static void createRoundedPath (Path& p,
  53173. const float x, const float y,
  53174. const float w, const float h,
  53175. const float cs,
  53176. const bool curveTopLeft, const bool curveTopRight,
  53177. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53178. {
  53179. const float cs2 = 2.0f * cs;
  53180. if (curveTopLeft)
  53181. {
  53182. p.startNewSubPath (x, y + cs);
  53183. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53184. }
  53185. else
  53186. {
  53187. p.startNewSubPath (x, y);
  53188. }
  53189. if (curveTopRight)
  53190. {
  53191. p.lineTo (x + w - cs, y);
  53192. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53193. }
  53194. else
  53195. {
  53196. p.lineTo (x + w, y);
  53197. }
  53198. if (curveBottomRight)
  53199. {
  53200. p.lineTo (x + w, y + h - cs);
  53201. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53202. }
  53203. else
  53204. {
  53205. p.lineTo (x + w, y + h);
  53206. }
  53207. if (curveBottomLeft)
  53208. {
  53209. p.lineTo (x + cs, y + h);
  53210. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53211. }
  53212. else
  53213. {
  53214. p.lineTo (x, y + h);
  53215. }
  53216. p.closeSubPath();
  53217. }
  53218. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53219. float x, float y, float w, float h,
  53220. float maxCornerSize,
  53221. const Colour& baseColour,
  53222. const float strokeWidth,
  53223. const bool flatOnLeft,
  53224. const bool flatOnRight,
  53225. const bool flatOnTop,
  53226. const bool flatOnBottom) throw()
  53227. {
  53228. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53229. return;
  53230. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53231. Path outline;
  53232. createRoundedPath (outline, x, y, w, h, cs,
  53233. ! (flatOnLeft || flatOnTop),
  53234. ! (flatOnRight || flatOnTop),
  53235. ! (flatOnLeft || flatOnBottom),
  53236. ! (flatOnRight || flatOnBottom));
  53237. ColourGradient cg (baseColour, 0.0f, y,
  53238. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53239. false);
  53240. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53241. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53242. g.setGradientFill (cg);
  53243. g.fillPath (outline);
  53244. g.setColour (Colour (0x80000000));
  53245. g.strokePath (outline, PathStrokeType (strokeWidth));
  53246. }
  53247. void LookAndFeel::drawGlassSphere (Graphics& g,
  53248. const float x, const float y,
  53249. const float diameter,
  53250. const Colour& colour,
  53251. const float outlineThickness) throw()
  53252. {
  53253. if (diameter <= outlineThickness)
  53254. return;
  53255. Path p;
  53256. p.addEllipse (x, y, diameter, diameter);
  53257. {
  53258. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53259. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53260. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53261. g.setGradientFill (cg);
  53262. g.fillPath (p);
  53263. }
  53264. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53265. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53266. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53267. ColourGradient cg (Colours::transparentBlack,
  53268. x + diameter * 0.5f, y + diameter * 0.5f,
  53269. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53270. x, y + diameter * 0.5f, true);
  53271. cg.addColour (0.7, Colours::transparentBlack);
  53272. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53273. g.setGradientFill (cg);
  53274. g.fillPath (p);
  53275. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53276. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53277. }
  53278. void LookAndFeel::drawGlassPointer (Graphics& g,
  53279. const float x, const float y,
  53280. const float diameter,
  53281. const Colour& colour, const float outlineThickness,
  53282. const int direction) throw()
  53283. {
  53284. if (diameter <= outlineThickness)
  53285. return;
  53286. Path p;
  53287. p.startNewSubPath (x + diameter * 0.5f, y);
  53288. p.lineTo (x + diameter, y + diameter * 0.6f);
  53289. p.lineTo (x + diameter, y + diameter);
  53290. p.lineTo (x, y + diameter);
  53291. p.lineTo (x, y + diameter * 0.6f);
  53292. p.closeSubPath();
  53293. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53294. {
  53295. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53296. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53297. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53298. g.setGradientFill (cg);
  53299. g.fillPath (p);
  53300. }
  53301. ColourGradient cg (Colours::transparentBlack,
  53302. x + diameter * 0.5f, y + diameter * 0.5f,
  53303. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53304. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53305. cg.addColour (0.5, Colours::transparentBlack);
  53306. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53307. g.setGradientFill (cg);
  53308. g.fillPath (p);
  53309. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53310. g.strokePath (p, PathStrokeType (outlineThickness));
  53311. }
  53312. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53313. const float x, const float y,
  53314. const float width, const float height,
  53315. const Colour& colour,
  53316. const float outlineThickness,
  53317. const float cornerSize,
  53318. const bool flatOnLeft,
  53319. const bool flatOnRight,
  53320. const bool flatOnTop,
  53321. const bool flatOnBottom) throw()
  53322. {
  53323. if (width <= outlineThickness || height <= outlineThickness)
  53324. return;
  53325. const int intX = (int) x;
  53326. const int intY = (int) y;
  53327. const int intW = (int) width;
  53328. const int intH = (int) height;
  53329. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53330. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53331. const int intEdge = (int) edgeBlurRadius;
  53332. Path outline;
  53333. createRoundedPath (outline, x, y, width, height, cs,
  53334. ! (flatOnLeft || flatOnTop),
  53335. ! (flatOnRight || flatOnTop),
  53336. ! (flatOnLeft || flatOnBottom),
  53337. ! (flatOnRight || flatOnBottom));
  53338. {
  53339. ColourGradient cg (colour.darker (0.2f), 0, y,
  53340. colour.darker (0.2f), 0, y + height, false);
  53341. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  53342. cg.addColour (0.4, colour);
  53343. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  53344. g.setGradientFill (cg);
  53345. g.fillPath (outline);
  53346. }
  53347. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  53348. colour.darker (0.2f), x, y + height * 0.5f, true);
  53349. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  53350. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  53351. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  53352. {
  53353. g.saveState();
  53354. g.setGradientFill (cg);
  53355. g.reduceClipRegion (intX, intY, intEdge, intH);
  53356. g.fillPath (outline);
  53357. g.restoreState();
  53358. }
  53359. if (! (flatOnRight || flatOnTop || flatOnBottom))
  53360. {
  53361. cg.x1 = x + width - edgeBlurRadius;
  53362. cg.x2 = x + width;
  53363. g.saveState();
  53364. g.setGradientFill (cg);
  53365. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  53366. g.fillPath (outline);
  53367. g.restoreState();
  53368. }
  53369. {
  53370. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  53371. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  53372. Path highlight;
  53373. createRoundedPath (highlight,
  53374. x + leftIndent,
  53375. y + cs * 0.1f,
  53376. width - (leftIndent + rightIndent),
  53377. height * 0.4f, cs * 0.4f,
  53378. ! (flatOnLeft || flatOnTop),
  53379. ! (flatOnRight || flatOnTop),
  53380. ! (flatOnLeft || flatOnBottom),
  53381. ! (flatOnRight || flatOnBottom));
  53382. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  53383. Colours::transparentWhite, 0, y + height * 0.4f, false));
  53384. g.fillPath (highlight);
  53385. }
  53386. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  53387. g.strokePath (outline, PathStrokeType (outlineThickness));
  53388. }
  53389. END_JUCE_NAMESPACE
  53390. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  53391. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53392. BEGIN_JUCE_NAMESPACE
  53393. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  53394. {
  53395. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  53396. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  53397. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  53398. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  53399. setColour (Slider::thumbColourId, Colours::white);
  53400. setColour (Slider::trackColourId, Colour (0x7f000000));
  53401. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  53402. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  53403. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  53404. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  53405. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  53406. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  53407. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  53408. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  53409. }
  53410. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  53411. {
  53412. }
  53413. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  53414. Button& button,
  53415. const Colour& backgroundColour,
  53416. bool isMouseOverButton,
  53417. bool isButtonDown)
  53418. {
  53419. const int width = button.getWidth();
  53420. const int height = button.getHeight();
  53421. const float indent = 2.0f;
  53422. const int cornerSize = jmin (roundToInt (width * 0.4f),
  53423. roundToInt (height * 0.4f));
  53424. Path p;
  53425. p.addRoundedRectangle (indent, indent,
  53426. width - indent * 2.0f,
  53427. height - indent * 2.0f,
  53428. (float) cornerSize);
  53429. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  53430. if (isMouseOverButton)
  53431. {
  53432. if (isButtonDown)
  53433. bc = bc.brighter();
  53434. else if (bc.getBrightness() > 0.5f)
  53435. bc = bc.darker (0.1f);
  53436. else
  53437. bc = bc.brighter (0.1f);
  53438. }
  53439. g.setColour (bc);
  53440. g.fillPath (p);
  53441. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  53442. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  53443. }
  53444. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  53445. Component& /*component*/,
  53446. float x, float y, float w, float h,
  53447. const bool ticked,
  53448. const bool isEnabled,
  53449. const bool /*isMouseOverButton*/,
  53450. const bool isButtonDown)
  53451. {
  53452. Path box;
  53453. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  53454. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  53455. : Colours::lightgrey.withAlpha (0.1f));
  53456. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  53457. g.fillPath (box, trans);
  53458. g.setColour (Colours::black.withAlpha (0.6f));
  53459. g.strokePath (box, PathStrokeType (0.9f), trans);
  53460. if (ticked)
  53461. {
  53462. Path tick;
  53463. tick.startNewSubPath (1.5f, 3.0f);
  53464. tick.lineTo (3.0f, 6.0f);
  53465. tick.lineTo (6.0f, 0.0f);
  53466. g.setColour (isEnabled ? Colours::black : Colours::grey);
  53467. g.strokePath (tick, PathStrokeType (2.5f), trans);
  53468. }
  53469. }
  53470. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  53471. ToggleButton& button,
  53472. bool isMouseOverButton,
  53473. bool isButtonDown)
  53474. {
  53475. if (button.hasKeyboardFocus (true))
  53476. {
  53477. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  53478. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  53479. }
  53480. const int tickWidth = jmin (20, button.getHeight() - 4);
  53481. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  53482. (float) tickWidth, (float) tickWidth,
  53483. button.getToggleState(),
  53484. button.isEnabled(),
  53485. isMouseOverButton,
  53486. isButtonDown);
  53487. g.setColour (button.findColour (ToggleButton::textColourId));
  53488. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  53489. if (! button.isEnabled())
  53490. g.setOpacity (0.5f);
  53491. const int textX = tickWidth + 5;
  53492. g.drawFittedText (button.getButtonText(),
  53493. textX, 4,
  53494. button.getWidth() - textX - 2, button.getHeight() - 8,
  53495. Justification::centredLeft, 10);
  53496. }
  53497. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  53498. int width, int height,
  53499. double progress, const String& textToShow)
  53500. {
  53501. if (progress < 0 || progress >= 1.0)
  53502. {
  53503. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  53504. }
  53505. else
  53506. {
  53507. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  53508. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  53509. g.fillAll (background);
  53510. g.setColour (foreground);
  53511. g.fillRect (1, 1,
  53512. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  53513. height - 2);
  53514. if (textToShow.isNotEmpty())
  53515. {
  53516. g.setColour (Colour::contrasting (background, foreground));
  53517. g.setFont (height * 0.6f);
  53518. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  53519. }
  53520. }
  53521. }
  53522. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  53523. ScrollBar& bar,
  53524. int width, int height,
  53525. int buttonDirection,
  53526. bool isScrollbarVertical,
  53527. bool isMouseOverButton,
  53528. bool isButtonDown)
  53529. {
  53530. if (isScrollbarVertical)
  53531. width -= 2;
  53532. else
  53533. height -= 2;
  53534. Path p;
  53535. if (buttonDirection == 0)
  53536. p.addTriangle (width * 0.5f, height * 0.2f,
  53537. width * 0.1f, height * 0.7f,
  53538. width * 0.9f, height * 0.7f);
  53539. else if (buttonDirection == 1)
  53540. p.addTriangle (width * 0.8f, height * 0.5f,
  53541. width * 0.3f, height * 0.1f,
  53542. width * 0.3f, height * 0.9f);
  53543. else if (buttonDirection == 2)
  53544. p.addTriangle (width * 0.5f, height * 0.8f,
  53545. width * 0.1f, height * 0.3f,
  53546. width * 0.9f, height * 0.3f);
  53547. else if (buttonDirection == 3)
  53548. p.addTriangle (width * 0.2f, height * 0.5f,
  53549. width * 0.7f, height * 0.1f,
  53550. width * 0.7f, height * 0.9f);
  53551. if (isButtonDown)
  53552. g.setColour (Colours::white);
  53553. else if (isMouseOverButton)
  53554. g.setColour (Colours::white.withAlpha (0.7f));
  53555. else
  53556. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  53557. g.fillPath (p);
  53558. g.setColour (Colours::black.withAlpha (0.5f));
  53559. g.strokePath (p, PathStrokeType (0.5f));
  53560. }
  53561. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  53562. ScrollBar& bar,
  53563. int x, int y,
  53564. int width, int height,
  53565. bool isScrollbarVertical,
  53566. int thumbStartPosition,
  53567. int thumbSize,
  53568. bool isMouseOver,
  53569. bool isMouseDown)
  53570. {
  53571. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  53572. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53573. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  53574. if (thumbSize > 0.0f)
  53575. {
  53576. Rectangle<int> thumb;
  53577. if (isScrollbarVertical)
  53578. {
  53579. width -= 2;
  53580. g.fillRect (x + roundToInt (width * 0.35f), y,
  53581. roundToInt (width * 0.3f), height);
  53582. thumb.setBounds (x + 1, thumbStartPosition,
  53583. width - 2, thumbSize);
  53584. }
  53585. else
  53586. {
  53587. height -= 2;
  53588. g.fillRect (x, y + roundToInt (height * 0.35f),
  53589. width, roundToInt (height * 0.3f));
  53590. thumb.setBounds (thumbStartPosition, y + 1,
  53591. thumbSize, height - 2);
  53592. }
  53593. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53594. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  53595. g.fillRect (thumb);
  53596. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  53597. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  53598. if (thumbSize > 16)
  53599. {
  53600. for (int i = 3; --i >= 0;)
  53601. {
  53602. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  53603. g.setColour (Colours::black.withAlpha (0.15f));
  53604. if (isScrollbarVertical)
  53605. {
  53606. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  53607. g.setColour (Colours::white.withAlpha (0.15f));
  53608. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  53609. }
  53610. else
  53611. {
  53612. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  53613. g.setColour (Colours::white.withAlpha (0.15f));
  53614. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  53615. }
  53616. }
  53617. }
  53618. }
  53619. }
  53620. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  53621. {
  53622. return &scrollbarShadow;
  53623. }
  53624. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  53625. {
  53626. g.fillAll (findColour (PopupMenu::backgroundColourId));
  53627. g.setColour (Colours::black.withAlpha (0.6f));
  53628. g.drawRect (0, 0, width, height);
  53629. }
  53630. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  53631. bool, MenuBarComponent& menuBar)
  53632. {
  53633. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  53634. }
  53635. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  53636. {
  53637. if (textEditor.isEnabled())
  53638. {
  53639. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  53640. g.drawRect (0, 0, width, height);
  53641. }
  53642. }
  53643. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  53644. const bool isButtonDown,
  53645. int buttonX, int buttonY,
  53646. int buttonW, int buttonH,
  53647. ComboBox& box)
  53648. {
  53649. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  53650. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  53651. : ComboBox::backgroundColourId));
  53652. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  53653. g.setColour (box.findColour (ComboBox::outlineColourId));
  53654. g.drawRect (0, 0, width, height);
  53655. const float arrowX = 0.2f;
  53656. const float arrowH = 0.3f;
  53657. if (box.isEnabled())
  53658. {
  53659. Path p;
  53660. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  53661. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  53662. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  53663. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  53664. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  53665. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  53666. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  53667. : ComboBox::buttonColourId));
  53668. g.fillPath (p);
  53669. }
  53670. }
  53671. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  53672. {
  53673. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  53674. f.setHorizontalScale (0.9f);
  53675. return f;
  53676. }
  53677. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  53678. {
  53679. Path p;
  53680. p.addTriangle (x1, y1, x2, y2, x3, y3);
  53681. g.setColour (fill);
  53682. g.fillPath (p);
  53683. g.setColour (outline);
  53684. g.strokePath (p, PathStrokeType (0.3f));
  53685. }
  53686. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  53687. int x, int y,
  53688. int w, int h,
  53689. float sliderPos,
  53690. float minSliderPos,
  53691. float maxSliderPos,
  53692. const Slider::SliderStyle style,
  53693. Slider& slider)
  53694. {
  53695. g.fillAll (slider.findColour (Slider::backgroundColourId));
  53696. if (style == Slider::LinearBar)
  53697. {
  53698. g.setColour (slider.findColour (Slider::thumbColourId));
  53699. g.fillRect (x, y, (int) sliderPos - x, h);
  53700. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  53701. g.drawRect (x, y, (int) sliderPos - x, h);
  53702. }
  53703. else
  53704. {
  53705. g.setColour (slider.findColour (Slider::trackColourId)
  53706. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  53707. if (slider.isHorizontal())
  53708. {
  53709. g.fillRect (x, y + roundToInt (h * 0.6f),
  53710. w, roundToInt (h * 0.2f));
  53711. }
  53712. else
  53713. {
  53714. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  53715. jmin (4, roundToInt (w * 0.2f)), h);
  53716. }
  53717. float alpha = 0.35f;
  53718. if (slider.isEnabled())
  53719. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  53720. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  53721. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  53722. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  53723. {
  53724. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  53725. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  53726. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  53727. fill, outline);
  53728. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  53729. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  53730. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  53731. fill, outline);
  53732. }
  53733. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  53734. {
  53735. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53736. minSliderPos - 7.0f, y + h * 0.9f ,
  53737. minSliderPos, y + h * 0.9f,
  53738. fill, outline);
  53739. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53740. maxSliderPos, y + h * 0.9f,
  53741. maxSliderPos + 7.0f, y + h * 0.9f,
  53742. fill, outline);
  53743. }
  53744. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  53745. {
  53746. drawTriangle (g, sliderPos, y + h * 0.9f,
  53747. sliderPos - 7.0f, y + h * 0.2f,
  53748. sliderPos + 7.0f, y + h * 0.2f,
  53749. fill, outline);
  53750. }
  53751. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  53752. {
  53753. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  53754. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  53755. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  53756. fill, outline);
  53757. }
  53758. }
  53759. }
  53760. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  53761. {
  53762. if (isIncrement)
  53763. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  53764. else
  53765. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  53766. }
  53767. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  53768. {
  53769. return &scrollbarShadow;
  53770. }
  53771. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  53772. {
  53773. return 8;
  53774. }
  53775. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  53776. int w, int h,
  53777. bool isMouseOver,
  53778. bool isMouseDragging)
  53779. {
  53780. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  53781. : Colours::darkgrey);
  53782. const float lineThickness = jmin (w, h) * 0.1f;
  53783. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  53784. {
  53785. g.drawLine (w * i,
  53786. h + 1.0f,
  53787. w + 1.0f,
  53788. h * i,
  53789. lineThickness);
  53790. }
  53791. }
  53792. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  53793. {
  53794. Path shape;
  53795. if (buttonType == DocumentWindow::closeButton)
  53796. {
  53797. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  53798. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  53799. ShapeButton* const b = new ShapeButton ("close",
  53800. Colour (0x7fff3333),
  53801. Colour (0xd7ff3333),
  53802. Colour (0xf7ff3333));
  53803. b->setShape (shape, true, true, true);
  53804. return b;
  53805. }
  53806. else if (buttonType == DocumentWindow::minimiseButton)
  53807. {
  53808. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53809. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  53810. DrawablePath dp;
  53811. dp.setPath (shape);
  53812. dp.setFill (Colours::black.withAlpha (0.3f));
  53813. b->setImages (&dp);
  53814. return b;
  53815. }
  53816. else if (buttonType == DocumentWindow::maximiseButton)
  53817. {
  53818. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  53819. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53820. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  53821. DrawablePath dp;
  53822. dp.setPath (shape);
  53823. dp.setFill (Colours::black.withAlpha (0.3f));
  53824. b->setImages (&dp);
  53825. return b;
  53826. }
  53827. jassertfalse
  53828. return 0;
  53829. }
  53830. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53831. int titleBarX,
  53832. int titleBarY,
  53833. int titleBarW,
  53834. int titleBarH,
  53835. Button* minimiseButton,
  53836. Button* maximiseButton,
  53837. Button* closeButton,
  53838. bool positionTitleBarButtonsOnLeft)
  53839. {
  53840. titleBarY += titleBarH / 8;
  53841. titleBarH -= titleBarH / 4;
  53842. const int buttonW = titleBarH;
  53843. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53844. : titleBarX + titleBarW - buttonW - 4;
  53845. if (closeButton != 0)
  53846. {
  53847. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53848. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  53849. : -(buttonW + buttonW / 5);
  53850. }
  53851. if (positionTitleBarButtonsOnLeft)
  53852. swapVariables (minimiseButton, maximiseButton);
  53853. if (maximiseButton != 0)
  53854. {
  53855. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53856. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53857. }
  53858. if (minimiseButton != 0)
  53859. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53860. }
  53861. END_JUCE_NAMESPACE
  53862. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53863. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  53864. BEGIN_JUCE_NAMESPACE
  53865. class DummyMenuComponent : public Component
  53866. {
  53867. DummyMenuComponent (const DummyMenuComponent&);
  53868. DummyMenuComponent& operator= (const DummyMenuComponent&);
  53869. public:
  53870. DummyMenuComponent() {}
  53871. ~DummyMenuComponent() {}
  53872. void inputAttemptWhenModal()
  53873. {
  53874. exitModalState (0);
  53875. }
  53876. };
  53877. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  53878. : model (0),
  53879. itemUnderMouse (-1),
  53880. currentPopupIndex (-1),
  53881. indexToShowAgain (-1),
  53882. lastMouseX (0),
  53883. lastMouseY (0),
  53884. inModalState (false)
  53885. {
  53886. setRepaintsOnMouseActivity (true);
  53887. setWantsKeyboardFocus (false);
  53888. setMouseClickGrabsKeyboardFocus (false);
  53889. setModel (model_);
  53890. }
  53891. MenuBarComponent::~MenuBarComponent()
  53892. {
  53893. setModel (0);
  53894. Desktop::getInstance().removeGlobalMouseListener (this);
  53895. currentPopup = 0;
  53896. }
  53897. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  53898. {
  53899. if (model != newModel)
  53900. {
  53901. if (model != 0)
  53902. model->removeListener (this);
  53903. model = newModel;
  53904. if (model != 0)
  53905. model->addListener (this);
  53906. repaint();
  53907. menuBarItemsChanged (0);
  53908. }
  53909. }
  53910. void MenuBarComponent::paint (Graphics& g)
  53911. {
  53912. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  53913. getLookAndFeel().drawMenuBarBackground (g,
  53914. getWidth(),
  53915. getHeight(),
  53916. isMouseOverBar,
  53917. *this);
  53918. if (model != 0)
  53919. {
  53920. for (int i = 0; i < menuNames.size(); ++i)
  53921. {
  53922. g.saveState();
  53923. g.setOrigin (xPositions [i], 0);
  53924. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  53925. getLookAndFeel().drawMenuBarItem (g,
  53926. xPositions[i + 1] - xPositions[i],
  53927. getHeight(),
  53928. i,
  53929. menuNames[i],
  53930. i == itemUnderMouse,
  53931. i == currentPopupIndex,
  53932. isMouseOverBar,
  53933. *this);
  53934. g.restoreState();
  53935. }
  53936. }
  53937. }
  53938. void MenuBarComponent::resized()
  53939. {
  53940. xPositions.clear();
  53941. int x = 2;
  53942. xPositions.add (x);
  53943. for (int i = 0; i < menuNames.size(); ++i)
  53944. {
  53945. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  53946. xPositions.add (x);
  53947. }
  53948. }
  53949. int MenuBarComponent::getItemAt (const int x, const int y)
  53950. {
  53951. for (int i = 0; i < xPositions.size(); ++i)
  53952. if (x >= xPositions[i] && x < xPositions[i + 1])
  53953. return reallyContains (x, y, true) ? i : -1;
  53954. return -1;
  53955. }
  53956. void MenuBarComponent::repaintMenuItem (int index)
  53957. {
  53958. if (((unsigned int) index) < (unsigned int) xPositions.size())
  53959. {
  53960. const int x1 = xPositions [index];
  53961. const int x2 = xPositions [index + 1];
  53962. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  53963. }
  53964. }
  53965. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  53966. {
  53967. const int newItem = getItemAt (x, y);
  53968. if (itemUnderMouse != newItem)
  53969. {
  53970. repaintMenuItem (itemUnderMouse);
  53971. itemUnderMouse = newItem;
  53972. repaintMenuItem (itemUnderMouse);
  53973. }
  53974. }
  53975. void MenuBarComponent::hideCurrentMenu()
  53976. {
  53977. currentPopup = 0;
  53978. repaint();
  53979. }
  53980. void MenuBarComponent::showMenu (int index)
  53981. {
  53982. if (index != currentPopupIndex)
  53983. {
  53984. if (inModalState)
  53985. {
  53986. hideCurrentMenu();
  53987. indexToShowAgain = index;
  53988. return;
  53989. }
  53990. indexToShowAgain = -1;
  53991. currentPopupIndex = -1;
  53992. itemUnderMouse = index;
  53993. currentPopup = 0;
  53994. menuBarItemsChanged (0);
  53995. Component::SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  53996. Component::SafePointer<Component> deletionChecker (this);
  53997. enterModalState (false);
  53998. inModalState = true;
  53999. int result = 0;
  54000. ApplicationCommandManager* managerOfChosenCommand = 0;
  54001. Desktop::getInstance().addGlobalMouseListener (this);
  54002. for (;;)
  54003. {
  54004. const int x = getScreenX() + xPositions [itemUnderMouse];
  54005. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54006. currentPopupIndex = itemUnderMouse;
  54007. indexToShowAgain = -1;
  54008. repaint();
  54009. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54010. {
  54011. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54012. menuNames [itemUnderMouse]));
  54013. if (m.lookAndFeel == 0)
  54014. m.setLookAndFeel (&getLookAndFeel());
  54015. currentPopup = m.createMenuComponent (x, getScreenY(),
  54016. w, getHeight(),
  54017. 0, w, 0, 0,
  54018. true, this,
  54019. &managerOfChosenCommand,
  54020. this);
  54021. }
  54022. if (currentPopup == 0)
  54023. {
  54024. currentPopup = new DummyMenuComponent();
  54025. addAndMakeVisible (currentPopup);
  54026. }
  54027. currentPopup->enterModalState (false);
  54028. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54029. // be stuck behind other comps that are already modal..
  54030. result = currentPopup->runModalLoop();
  54031. if (deletionChecker == 0)
  54032. return;
  54033. const int lastPopupIndex = currentPopupIndex;
  54034. currentPopup = 0;
  54035. currentPopupIndex = -1;
  54036. if (result != 0)
  54037. {
  54038. topLevelIndexClicked = lastPopupIndex;
  54039. break;
  54040. }
  54041. else if (indexToShowAgain >= 0)
  54042. {
  54043. menuBarItemsChanged (0);
  54044. repaint();
  54045. itemUnderMouse = indexToShowAgain;
  54046. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54047. break;
  54048. }
  54049. else
  54050. {
  54051. break;
  54052. }
  54053. }
  54054. Desktop::getInstance().removeGlobalMouseListener (this);
  54055. inModalState = false;
  54056. exitModalState (0);
  54057. if (prevFocused != 0)
  54058. prevFocused->grabKeyboardFocus();
  54059. const Point<int> mousePos (getMouseXYRelative());
  54060. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54061. repaint();
  54062. if (result != 0)
  54063. {
  54064. if (managerOfChosenCommand != 0)
  54065. {
  54066. ApplicationCommandTarget::InvocationInfo info (result);
  54067. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54068. managerOfChosenCommand->invoke (info, true);
  54069. }
  54070. postCommandMessage (result);
  54071. }
  54072. }
  54073. }
  54074. void MenuBarComponent::handleCommandMessage (int commandId)
  54075. {
  54076. if (model != 0)
  54077. model->menuItemSelected (commandId, topLevelIndexClicked);
  54078. }
  54079. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54080. {
  54081. if (e.eventComponent == this)
  54082. updateItemUnderMouse (e.x, e.y);
  54083. }
  54084. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54085. {
  54086. if (e.eventComponent == this)
  54087. updateItemUnderMouse (e.x, e.y);
  54088. }
  54089. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54090. {
  54091. if (currentPopupIndex < 0)
  54092. {
  54093. const MouseEvent e2 (e.getEventRelativeTo (this));
  54094. updateItemUnderMouse (e2.x, e2.y);
  54095. currentPopupIndex = -2;
  54096. showMenu (itemUnderMouse);
  54097. }
  54098. }
  54099. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54100. {
  54101. const MouseEvent e2 (e.getEventRelativeTo (this));
  54102. const int item = getItemAt (e2.x, e2.y);
  54103. if (item >= 0)
  54104. showMenu (item);
  54105. }
  54106. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54107. {
  54108. const MouseEvent e2 (e.getEventRelativeTo (this));
  54109. updateItemUnderMouse (e2.x, e2.y);
  54110. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54111. hideCurrentMenu();
  54112. }
  54113. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54114. {
  54115. const MouseEvent e2 (e.getEventRelativeTo (this));
  54116. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54117. {
  54118. if (currentPopupIndex >= 0)
  54119. {
  54120. const int item = getItemAt (e2.x, e2.y);
  54121. if (item >= 0)
  54122. showMenu (item);
  54123. }
  54124. else
  54125. {
  54126. updateItemUnderMouse (e2.x, e2.y);
  54127. }
  54128. lastMouseX = e2.x;
  54129. lastMouseY = e2.y;
  54130. }
  54131. }
  54132. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54133. {
  54134. bool used = false;
  54135. const int numMenus = menuNames.size();
  54136. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54137. if (key.isKeyCode (KeyPress::leftKey))
  54138. {
  54139. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54140. used = true;
  54141. }
  54142. else if (key.isKeyCode (KeyPress::rightKey))
  54143. {
  54144. showMenu ((currentIndex + 1) % numMenus);
  54145. used = true;
  54146. }
  54147. return used;
  54148. }
  54149. void MenuBarComponent::inputAttemptWhenModal()
  54150. {
  54151. hideCurrentMenu();
  54152. }
  54153. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54154. {
  54155. StringArray newNames;
  54156. if (model != 0)
  54157. newNames = model->getMenuBarNames();
  54158. if (newNames != menuNames)
  54159. {
  54160. menuNames = newNames;
  54161. repaint();
  54162. resized();
  54163. }
  54164. }
  54165. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54166. const ApplicationCommandTarget::InvocationInfo& info)
  54167. {
  54168. if (model == 0
  54169. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54170. return;
  54171. for (int i = 0; i < menuNames.size(); ++i)
  54172. {
  54173. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54174. if (menu.containsCommandItem (info.commandID))
  54175. {
  54176. itemUnderMouse = i;
  54177. repaintMenuItem (i);
  54178. startTimer (200);
  54179. break;
  54180. }
  54181. }
  54182. }
  54183. void MenuBarComponent::timerCallback()
  54184. {
  54185. stopTimer();
  54186. const Point<int> mousePos (getMouseXYRelative());
  54187. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54188. }
  54189. END_JUCE_NAMESPACE
  54190. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54191. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54192. BEGIN_JUCE_NAMESPACE
  54193. MenuBarModel::MenuBarModel() throw()
  54194. : manager (0)
  54195. {
  54196. }
  54197. MenuBarModel::~MenuBarModel()
  54198. {
  54199. setApplicationCommandManagerToWatch (0);
  54200. }
  54201. void MenuBarModel::menuItemsChanged()
  54202. {
  54203. triggerAsyncUpdate();
  54204. }
  54205. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54206. {
  54207. if (manager != newManager)
  54208. {
  54209. if (manager != 0)
  54210. manager->removeListener (this);
  54211. manager = newManager;
  54212. if (manager != 0)
  54213. manager->addListener (this);
  54214. }
  54215. }
  54216. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54217. {
  54218. listeners.add (newListener);
  54219. }
  54220. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54221. {
  54222. // Trying to remove a listener that isn't on the list!
  54223. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54224. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54225. jassert (listeners.contains (listenerToRemove));
  54226. listeners.remove (listenerToRemove);
  54227. }
  54228. void MenuBarModel::handleAsyncUpdate()
  54229. {
  54230. listeners.call (&MenuBarModelListener::menuBarItemsChanged, this);
  54231. }
  54232. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54233. {
  54234. listeners.call (&MenuBarModelListener::menuCommandInvoked, this, info);
  54235. }
  54236. void MenuBarModel::applicationCommandListChanged()
  54237. {
  54238. menuItemsChanged();
  54239. }
  54240. END_JUCE_NAMESPACE
  54241. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54242. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54243. BEGIN_JUCE_NAMESPACE
  54244. class PopupMenu::Item
  54245. {
  54246. public:
  54247. Item()
  54248. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54249. usesColour (false), customComp (0), commandManager (0)
  54250. {
  54251. }
  54252. Item (const int itemId_,
  54253. const String& text_,
  54254. const bool active_,
  54255. const bool isTicked_,
  54256. const Image* im,
  54257. const Colour& textColour_,
  54258. const bool usesColour_,
  54259. PopupMenuCustomComponent* const customComp_,
  54260. const PopupMenu* const subMenu_,
  54261. ApplicationCommandManager* const commandManager_)
  54262. : itemId (itemId_), text (text_), textColour (textColour_),
  54263. active (active_), isSeparator (false), isTicked (isTicked_),
  54264. usesColour (usesColour_), customComp (customComp_),
  54265. commandManager (commandManager_)
  54266. {
  54267. if (subMenu_ != 0)
  54268. subMenu = new PopupMenu (*subMenu_);
  54269. if (im != 0)
  54270. image = im->createCopy();
  54271. if (commandManager_ != 0 && itemId_ != 0)
  54272. {
  54273. String shortcutKey;
  54274. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54275. ->getKeyPressesAssignedToCommand (itemId_));
  54276. for (int i = 0; i < keyPresses.size(); ++i)
  54277. {
  54278. const String key (keyPresses.getReference(i).getTextDescription());
  54279. if (shortcutKey.isNotEmpty())
  54280. shortcutKey << ", ";
  54281. if (key.length() == 1)
  54282. shortcutKey << "shortcut: '" << key << '\'';
  54283. else
  54284. shortcutKey << key;
  54285. }
  54286. shortcutKey = shortcutKey.trim();
  54287. if (shortcutKey.isNotEmpty())
  54288. text << "<end>" << shortcutKey;
  54289. }
  54290. }
  54291. Item (const Item& other)
  54292. : itemId (other.itemId),
  54293. text (other.text),
  54294. textColour (other.textColour),
  54295. active (other.active),
  54296. isSeparator (other.isSeparator),
  54297. isTicked (other.isTicked),
  54298. usesColour (other.usesColour),
  54299. customComp (other.customComp),
  54300. commandManager (other.commandManager)
  54301. {
  54302. if (other.subMenu != 0)
  54303. subMenu = new PopupMenu (*(other.subMenu));
  54304. if (other.image != 0)
  54305. image = other.image->createCopy();
  54306. }
  54307. ~Item()
  54308. {
  54309. customComp = 0;
  54310. }
  54311. bool canBeTriggered() const throw()
  54312. {
  54313. return active && ! (isSeparator || (subMenu != 0));
  54314. }
  54315. bool hasActiveSubMenu() const throw()
  54316. {
  54317. return active && (subMenu != 0);
  54318. }
  54319. const int itemId;
  54320. String text;
  54321. const Colour textColour;
  54322. const bool active, isSeparator, isTicked, usesColour;
  54323. ScopedPointer <Image> image;
  54324. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  54325. ScopedPointer <PopupMenu> subMenu;
  54326. ApplicationCommandManager* const commandManager;
  54327. juce_UseDebuggingNewOperator
  54328. private:
  54329. Item& operator= (const Item&);
  54330. };
  54331. class PopupMenu::ItemComponent : public Component
  54332. {
  54333. public:
  54334. ItemComponent (const PopupMenu::Item& itemInfo_)
  54335. : itemInfo (itemInfo_),
  54336. isHighlighted (false)
  54337. {
  54338. if (itemInfo.customComp != 0)
  54339. addAndMakeVisible (itemInfo.customComp);
  54340. }
  54341. ~ItemComponent()
  54342. {
  54343. if (itemInfo.customComp != 0)
  54344. removeChildComponent (itemInfo.customComp);
  54345. }
  54346. void getIdealSize (int& idealWidth,
  54347. int& idealHeight,
  54348. const int standardItemHeight)
  54349. {
  54350. if (itemInfo.customComp != 0)
  54351. {
  54352. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  54353. }
  54354. else
  54355. {
  54356. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  54357. itemInfo.isSeparator,
  54358. standardItemHeight,
  54359. idealWidth,
  54360. idealHeight);
  54361. }
  54362. }
  54363. void paint (Graphics& g)
  54364. {
  54365. if (itemInfo.customComp == 0)
  54366. {
  54367. String mainText (itemInfo.text);
  54368. String endText;
  54369. const int endIndex = mainText.indexOf (T("<end>"));
  54370. if (endIndex >= 0)
  54371. {
  54372. endText = mainText.substring (endIndex + 5).trim();
  54373. mainText = mainText.substring (0, endIndex);
  54374. }
  54375. getLookAndFeel()
  54376. .drawPopupMenuItem (g, getWidth(), getHeight(),
  54377. itemInfo.isSeparator,
  54378. itemInfo.active,
  54379. isHighlighted,
  54380. itemInfo.isTicked,
  54381. itemInfo.subMenu != 0,
  54382. mainText, endText,
  54383. itemInfo.image,
  54384. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  54385. }
  54386. }
  54387. void resized()
  54388. {
  54389. if (getNumChildComponents() > 0)
  54390. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  54391. }
  54392. void setHighlighted (bool shouldBeHighlighted)
  54393. {
  54394. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  54395. if (isHighlighted != shouldBeHighlighted)
  54396. {
  54397. isHighlighted = shouldBeHighlighted;
  54398. if (itemInfo.customComp != 0)
  54399. {
  54400. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  54401. itemInfo.customComp->repaint();
  54402. }
  54403. repaint();
  54404. }
  54405. }
  54406. PopupMenu::Item itemInfo;
  54407. juce_UseDebuggingNewOperator
  54408. private:
  54409. bool isHighlighted;
  54410. ItemComponent (const ItemComponent&);
  54411. ItemComponent& operator= (const ItemComponent&);
  54412. };
  54413. namespace PopupMenuSettings
  54414. {
  54415. static const int scrollZone = 24;
  54416. static const int borderSize = 2;
  54417. static const int timerInterval = 50;
  54418. static const int dismissCommandId = 0x6287345f;
  54419. }
  54420. class PopupMenu::Window : public Component,
  54421. private Timer
  54422. {
  54423. public:
  54424. Window()
  54425. : Component (T("menu")),
  54426. owner (0),
  54427. currentChild (0),
  54428. activeSubMenu (0),
  54429. menuBarComponent (0),
  54430. managerOfChosenCommand (0),
  54431. minimumWidth (0),
  54432. maximumNumColumns (7),
  54433. standardItemHeight (0),
  54434. isOver (false),
  54435. hasBeenOver (false),
  54436. isDown (false),
  54437. needsToScroll (false),
  54438. hideOnExit (false),
  54439. disableMouseMoves (false),
  54440. hasAnyJuceCompHadFocus (false),
  54441. numColumns (0),
  54442. contentHeight (0),
  54443. childYOffset (0),
  54444. timeEnteredCurrentChildComp (0),
  54445. scrollAcceleration (1.0)
  54446. {
  54447. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  54448. setWantsKeyboardFocus (true);
  54449. setMouseClickGrabsKeyboardFocus (false);
  54450. setOpaque (true);
  54451. setAlwaysOnTop (true);
  54452. Desktop::getInstance().addGlobalMouseListener (this);
  54453. getActiveWindows().add (this);
  54454. }
  54455. ~Window()
  54456. {
  54457. getActiveWindows().removeValue (this);
  54458. Desktop::getInstance().removeGlobalMouseListener (this);
  54459. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54460. activeSubMenu = 0;
  54461. deleteAllChildren();
  54462. }
  54463. static Window* create (const PopupMenu& menu,
  54464. const bool dismissOnMouseUp,
  54465. Window* const owner_,
  54466. const int minX, const int maxX,
  54467. const int minY, const int maxY,
  54468. const int minimumWidth,
  54469. const int maximumNumColumns,
  54470. const int standardItemHeight,
  54471. const bool alignToRectangle,
  54472. const int itemIdThatMustBeVisible,
  54473. Component* const menuBarComponent,
  54474. ApplicationCommandManager** managerOfChosenCommand,
  54475. Component* const componentAttachedTo)
  54476. {
  54477. if (menu.items.size() > 0)
  54478. {
  54479. int totalItems = 0;
  54480. ScopedPointer <Window> mw (new Window());
  54481. mw->setLookAndFeel (menu.lookAndFeel);
  54482. mw->setWantsKeyboardFocus (false);
  54483. mw->minimumWidth = minimumWidth;
  54484. mw->maximumNumColumns = maximumNumColumns;
  54485. mw->standardItemHeight = standardItemHeight;
  54486. mw->dismissOnMouseUp = dismissOnMouseUp;
  54487. for (int i = 0; i < menu.items.size(); ++i)
  54488. {
  54489. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  54490. mw->addItem (*item);
  54491. ++totalItems;
  54492. }
  54493. if (totalItems > 0)
  54494. {
  54495. mw->owner = owner_;
  54496. mw->menuBarComponent = menuBarComponent;
  54497. mw->managerOfChosenCommand = managerOfChosenCommand;
  54498. mw->componentAttachedTo = componentAttachedTo;
  54499. mw->componentAttachedToOriginal = componentAttachedTo;
  54500. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  54501. mw->setTopLeftPosition (mw->windowPos.getX(),
  54502. mw->windowPos.getY());
  54503. mw->updateYPositions();
  54504. if (itemIdThatMustBeVisible != 0)
  54505. {
  54506. const int y = minY - mw->windowPos.getY();
  54507. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  54508. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  54509. }
  54510. mw->resizeToBestWindowPos();
  54511. mw->addToDesktop (ComponentPeer::windowIsTemporary
  54512. | mw->getLookAndFeel().getMenuWindowFlags());
  54513. return mw.release();
  54514. }
  54515. }
  54516. return 0;
  54517. }
  54518. void paint (Graphics& g)
  54519. {
  54520. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  54521. }
  54522. void paintOverChildren (Graphics& g)
  54523. {
  54524. if (isScrolling())
  54525. {
  54526. LookAndFeel& lf = getLookAndFeel();
  54527. if (isScrollZoneActive (false))
  54528. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  54529. if (isScrollZoneActive (true))
  54530. {
  54531. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  54532. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  54533. }
  54534. }
  54535. }
  54536. bool isScrollZoneActive (bool bottomOne) const
  54537. {
  54538. return isScrolling()
  54539. && (bottomOne
  54540. ? childYOffset < contentHeight - windowPos.getHeight()
  54541. : childYOffset > 0);
  54542. }
  54543. void addItem (const PopupMenu::Item& item)
  54544. {
  54545. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  54546. addAndMakeVisible (mic);
  54547. int itemW = 80;
  54548. int itemH = 16;
  54549. mic->getIdealSize (itemW, itemH, standardItemHeight);
  54550. mic->setSize (itemW, jlimit (2, 600, itemH));
  54551. mic->addMouseListener (this, false);
  54552. }
  54553. // hide this and all sub-comps
  54554. void hide (const PopupMenu::Item* const item)
  54555. {
  54556. if (isVisible())
  54557. {
  54558. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54559. activeSubMenu = 0;
  54560. currentChild = 0;
  54561. exitModalState (item != 0 ? item->itemId : 0);
  54562. setVisible (false);
  54563. if (item != 0
  54564. && item->commandManager != 0
  54565. && item->itemId != 0)
  54566. {
  54567. *managerOfChosenCommand = item->commandManager;
  54568. }
  54569. }
  54570. }
  54571. void dismissMenu (const PopupMenu::Item* const item)
  54572. {
  54573. if (owner != 0)
  54574. {
  54575. owner->dismissMenu (item);
  54576. }
  54577. else
  54578. {
  54579. if (item != 0)
  54580. {
  54581. // need a copy of this on the stack as the one passed in will get deleted during this call
  54582. const PopupMenu::Item mi (*item);
  54583. hide (&mi);
  54584. }
  54585. else
  54586. {
  54587. hide (0);
  54588. }
  54589. }
  54590. }
  54591. void mouseMove (const MouseEvent&)
  54592. {
  54593. timerCallback();
  54594. }
  54595. void mouseDown (const MouseEvent&)
  54596. {
  54597. timerCallback();
  54598. }
  54599. void mouseDrag (const MouseEvent&)
  54600. {
  54601. timerCallback();
  54602. }
  54603. void mouseUp (const MouseEvent&)
  54604. {
  54605. timerCallback();
  54606. }
  54607. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  54608. {
  54609. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  54610. lastMouse = Point<int> (-1, -1);
  54611. }
  54612. bool keyPressed (const KeyPress& key)
  54613. {
  54614. if (key.isKeyCode (KeyPress::downKey))
  54615. {
  54616. selectNextItem (1);
  54617. }
  54618. else if (key.isKeyCode (KeyPress::upKey))
  54619. {
  54620. selectNextItem (-1);
  54621. }
  54622. else if (key.isKeyCode (KeyPress::leftKey))
  54623. {
  54624. if (owner != 0)
  54625. {
  54626. Component::SafePointer<Window> parentWindow (owner);
  54627. PopupMenu::ItemComponent* currentChildOfParent = parentWindow->currentChild;
  54628. hide (0);
  54629. if (parentWindow != 0)
  54630. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  54631. disableTimerUntilMouseMoves();
  54632. }
  54633. else if (menuBarComponent != 0)
  54634. {
  54635. menuBarComponent->keyPressed (key);
  54636. }
  54637. }
  54638. else if (key.isKeyCode (KeyPress::rightKey))
  54639. {
  54640. disableTimerUntilMouseMoves();
  54641. if (showSubMenuFor (currentChild))
  54642. {
  54643. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54644. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  54645. activeSubMenu->selectNextItem (1);
  54646. }
  54647. else if (menuBarComponent != 0)
  54648. {
  54649. menuBarComponent->keyPressed (key);
  54650. }
  54651. }
  54652. else if (key.isKeyCode (KeyPress::returnKey))
  54653. {
  54654. triggerCurrentlyHighlightedItem();
  54655. }
  54656. else if (key.isKeyCode (KeyPress::escapeKey))
  54657. {
  54658. dismissMenu (0);
  54659. }
  54660. else
  54661. {
  54662. return false;
  54663. }
  54664. return true;
  54665. }
  54666. void inputAttemptWhenModal()
  54667. {
  54668. timerCallback();
  54669. if (! isOverAnyMenu())
  54670. {
  54671. if (componentAttachedTo != 0)
  54672. {
  54673. // we want to dismiss the menu, but if we do it synchronously, then
  54674. // the mouse-click will be allowed to pass through. That's good, except
  54675. // when the user clicks on the button that orginally popped the menu up,
  54676. // as they'll expect the menu to go away, and in fact it'll just
  54677. // come back. So only dismiss synchronously if they're not on the original
  54678. // comp that we're attached to.
  54679. const Point<int> mousePos (componentAttachedTo->getMouseXYRelative());
  54680. if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true))
  54681. {
  54682. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  54683. return;
  54684. }
  54685. }
  54686. dismissMenu (0);
  54687. }
  54688. }
  54689. void handleCommandMessage (int commandId)
  54690. {
  54691. Component::handleCommandMessage (commandId);
  54692. if (commandId == PopupMenuSettings::dismissCommandId)
  54693. dismissMenu (0);
  54694. }
  54695. void timerCallback()
  54696. {
  54697. if (! isVisible())
  54698. return;
  54699. if (componentAttachedTo != componentAttachedToOriginal)
  54700. {
  54701. dismissMenu (0);
  54702. return;
  54703. }
  54704. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  54705. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  54706. return;
  54707. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  54708. // move rather than a real timer callback
  54709. const Point<int> globalMousePos (Desktop::getMousePosition());
  54710. const Point<int> localMousePos (globalPositionToRelative (globalMousePos));
  54711. const uint32 now = Time::getMillisecondCounter();
  54712. if (now > timeEnteredCurrentChildComp + 100
  54713. && reallyContains (localMousePos.getX(), localMousePos.getY(), true)
  54714. && currentChild->isValidComponent()
  54715. && (! disableMouseMoves)
  54716. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  54717. {
  54718. showSubMenuFor (currentChild);
  54719. }
  54720. if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350)
  54721. {
  54722. highlightItemUnderMouse (globalMousePos, localMousePos);
  54723. }
  54724. bool overScrollArea = false;
  54725. if (isScrolling()
  54726. && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth()))
  54727. && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone)
  54728. || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone)))
  54729. {
  54730. if (now > lastScroll + 20)
  54731. {
  54732. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  54733. int amount = 0;
  54734. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  54735. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  54736. alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount);
  54737. lastScroll = now;
  54738. }
  54739. overScrollArea = true;
  54740. lastMouse = Point<int> (-1, -1); // trigger a mouse-move
  54741. }
  54742. else
  54743. {
  54744. scrollAcceleration = 1.0;
  54745. }
  54746. const bool wasDown = isDown;
  54747. bool isOverAny = isOverAnyMenu();
  54748. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  54749. {
  54750. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54751. isOverAny = isOverAnyMenu();
  54752. }
  54753. if (hideOnExit && hasBeenOver && ! isOverAny)
  54754. {
  54755. hide (0);
  54756. }
  54757. else
  54758. {
  54759. isDown = hasBeenOver
  54760. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  54761. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  54762. bool anyFocused = Process::isForegroundProcess();
  54763. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  54764. {
  54765. // because no component at all may have focus, our test here will
  54766. // only be triggered when something has focus and then loses it.
  54767. anyFocused = ! hasAnyJuceCompHadFocus;
  54768. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  54769. {
  54770. if (ComponentPeer::getPeer (i)->isFocused())
  54771. {
  54772. anyFocused = true;
  54773. hasAnyJuceCompHadFocus = true;
  54774. break;
  54775. }
  54776. }
  54777. }
  54778. if (! anyFocused)
  54779. {
  54780. if (now > lastFocused + 10)
  54781. {
  54782. wasHiddenBecauseOfAppChange() = true;
  54783. dismissMenu (0);
  54784. return; // may have been deleted by the previous call..
  54785. }
  54786. }
  54787. else if (wasDown && now > menuCreationTime + 250
  54788. && ! (isDown || overScrollArea))
  54789. {
  54790. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  54791. if (isOver)
  54792. {
  54793. triggerCurrentlyHighlightedItem();
  54794. }
  54795. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  54796. {
  54797. dismissMenu (0);
  54798. }
  54799. return; // may have been deleted by the previous calls..
  54800. }
  54801. else
  54802. {
  54803. lastFocused = now;
  54804. }
  54805. }
  54806. }
  54807. static Array<Window*>& getActiveWindows()
  54808. {
  54809. static Array<Window*> activeMenuWindows;
  54810. return activeMenuWindows;
  54811. }
  54812. static bool& wasHiddenBecauseOfAppChange() throw()
  54813. {
  54814. static bool b = false;
  54815. return b;
  54816. }
  54817. juce_UseDebuggingNewOperator
  54818. private:
  54819. Window* owner;
  54820. PopupMenu::ItemComponent* currentChild;
  54821. ScopedPointer <Window> activeSubMenu;
  54822. Component* menuBarComponent;
  54823. ApplicationCommandManager** managerOfChosenCommand;
  54824. Component::SafePointer<Component> componentAttachedTo;
  54825. Component* componentAttachedToOriginal;
  54826. Rectangle<int> windowPos;
  54827. Point<int> lastMouse;
  54828. int minimumWidth, maximumNumColumns, standardItemHeight;
  54829. bool isOver, hasBeenOver, isDown, needsToScroll;
  54830. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  54831. int numColumns, contentHeight, childYOffset;
  54832. Array <int> columnWidths;
  54833. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  54834. double scrollAcceleration;
  54835. bool overlaps (const Rectangle<int>& r) const
  54836. {
  54837. return r.intersects (getBounds())
  54838. || (owner != 0 && owner->overlaps (r));
  54839. }
  54840. bool isOverAnyMenu() const
  54841. {
  54842. return (owner != 0) ? owner->isOverAnyMenu()
  54843. : isOverChildren();
  54844. }
  54845. bool isOverChildren() const
  54846. {
  54847. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54848. return isVisible()
  54849. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  54850. }
  54851. void updateMouseOverStatus (const Point<int>& globalMousePos)
  54852. {
  54853. const Point<int> relPos (globalPositionToRelative (globalMousePos));
  54854. isOver = reallyContains (relPos.getX(), relPos.getY(), true);
  54855. if (activeSubMenu != 0)
  54856. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54857. }
  54858. bool treeContains (const Window* const window) const throw()
  54859. {
  54860. const Window* mw = this;
  54861. while (mw->owner != 0)
  54862. mw = mw->owner;
  54863. while (mw != 0)
  54864. {
  54865. if (mw == window)
  54866. return true;
  54867. mw = mw->activeSubMenu;
  54868. }
  54869. return false;
  54870. }
  54871. void calculateWindowPos (const int minX, const int maxX,
  54872. const int minY, const int maxY,
  54873. const bool alignToRectangle)
  54874. {
  54875. const Rectangle<int> mon (Desktop::getInstance()
  54876. .getMonitorAreaContaining (Point<int> ((minX + maxX) / 2,
  54877. (minY + maxY) / 2),
  54878. #if JUCE_MAC
  54879. true));
  54880. #else
  54881. false)); // on windows, don't stop the menu overlapping the taskbar
  54882. #endif
  54883. int x, y, widthToUse, heightToUse;
  54884. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  54885. if (alignToRectangle)
  54886. {
  54887. x = minX;
  54888. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  54889. const int spaceOver = minY - mon.getY();
  54890. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  54891. y = maxY;
  54892. else
  54893. y = minY - heightToUse;
  54894. }
  54895. else
  54896. {
  54897. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  54898. if (owner != 0)
  54899. {
  54900. if (owner->owner != 0)
  54901. {
  54902. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  54903. > owner->owner->getX() + owner->owner->getWidth() / 2);
  54904. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  54905. tendTowardsRight = true;
  54906. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  54907. tendTowardsRight = false;
  54908. }
  54909. else if (maxX + widthToUse < mon.getRight() - 32)
  54910. {
  54911. tendTowardsRight = true;
  54912. }
  54913. }
  54914. const int biggestSpace = jmax (mon.getRight() - maxX,
  54915. minX - mon.getX()) - 32;
  54916. if (biggestSpace < widthToUse)
  54917. {
  54918. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  54919. if (numColumns > 1)
  54920. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  54921. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  54922. }
  54923. if (tendTowardsRight)
  54924. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  54925. else
  54926. x = jmax (mon.getX() + 4, minX - widthToUse);
  54927. y = minY;
  54928. if ((minY + maxY) / 2 > mon.getCentreY())
  54929. y = jmax (mon.getY(), maxY - heightToUse);
  54930. }
  54931. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  54932. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  54933. windowPos.setBounds (x, y, widthToUse, heightToUse);
  54934. // sets this flag if it's big enough to obscure any of its parent menus
  54935. hideOnExit = (owner != 0)
  54936. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  54937. }
  54938. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  54939. {
  54940. numColumns = 0;
  54941. contentHeight = 0;
  54942. const int maxMenuH = getParentHeight() - 24;
  54943. int totalW;
  54944. do
  54945. {
  54946. ++numColumns;
  54947. totalW = workOutBestSize (maxMenuW);
  54948. if (totalW > maxMenuW)
  54949. {
  54950. numColumns = jmax (1, numColumns - 1);
  54951. totalW = workOutBestSize (maxMenuW); // to update col widths
  54952. break;
  54953. }
  54954. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  54955. {
  54956. break;
  54957. }
  54958. } while (numColumns < maximumNumColumns);
  54959. const int actualH = jmin (contentHeight, maxMenuH);
  54960. needsToScroll = contentHeight > actualH;
  54961. width = updateYPositions();
  54962. height = actualH + PopupMenuSettings::borderSize * 2;
  54963. }
  54964. int workOutBestSize (const int maxMenuW)
  54965. {
  54966. int totalW = 0;
  54967. contentHeight = 0;
  54968. int childNum = 0;
  54969. for (int col = 0; col < numColumns; ++col)
  54970. {
  54971. int i, colW = 50, colH = 0;
  54972. const int numChildren = jmin (getNumChildComponents() - childNum,
  54973. (getNumChildComponents() + numColumns - 1) / numColumns);
  54974. for (i = numChildren; --i >= 0;)
  54975. {
  54976. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  54977. colH += getChildComponent (childNum + i)->getHeight();
  54978. }
  54979. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  54980. columnWidths.set (col, colW);
  54981. totalW += colW;
  54982. contentHeight = jmax (contentHeight, colH);
  54983. childNum += numChildren;
  54984. }
  54985. if (totalW < minimumWidth)
  54986. {
  54987. totalW = minimumWidth;
  54988. for (int col = 0; col < numColumns; ++col)
  54989. columnWidths.set (0, totalW / numColumns);
  54990. }
  54991. return totalW;
  54992. }
  54993. void ensureItemIsVisible (const int itemId, int wantedY)
  54994. {
  54995. jassert (itemId != 0)
  54996. for (int i = getNumChildComponents(); --i >= 0;)
  54997. {
  54998. PopupMenu::ItemComponent* const m = (PopupMenu::ItemComponent*) getChildComponent (i);
  54999. if (m != 0
  55000. && m->itemInfo.itemId == itemId
  55001. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  55002. {
  55003. const int currentY = m->getY();
  55004. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55005. {
  55006. if (wantedY < 0)
  55007. wantedY = jlimit (PopupMenuSettings::scrollZone,
  55008. jmax (PopupMenuSettings::scrollZone,
  55009. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55010. currentY);
  55011. const Rectangle<int> mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true));
  55012. int deltaY = wantedY - currentY;
  55013. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  55014. jmin (windowPos.getHeight(), mon.getHeight()));
  55015. const int newY = jlimit (mon.getY(),
  55016. mon.getBottom() - windowPos.getHeight(),
  55017. windowPos.getY() + deltaY);
  55018. deltaY -= newY - windowPos.getY();
  55019. childYOffset -= deltaY;
  55020. windowPos.setPosition (windowPos.getX(), newY);
  55021. updateYPositions();
  55022. }
  55023. break;
  55024. }
  55025. }
  55026. }
  55027. void resizeToBestWindowPos()
  55028. {
  55029. Rectangle<int> r (windowPos);
  55030. if (childYOffset < 0)
  55031. {
  55032. r.setBounds (r.getX(), r.getY() - childYOffset,
  55033. r.getWidth(), r.getHeight() + childYOffset);
  55034. }
  55035. else if (childYOffset > 0)
  55036. {
  55037. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55038. if (spaceAtBottom > 0)
  55039. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55040. }
  55041. setBounds (r);
  55042. updateYPositions();
  55043. }
  55044. void alterChildYPos (const int delta)
  55045. {
  55046. if (isScrolling())
  55047. {
  55048. childYOffset += delta;
  55049. if (delta < 0)
  55050. {
  55051. childYOffset = jmax (childYOffset, 0);
  55052. }
  55053. else if (delta > 0)
  55054. {
  55055. childYOffset = jmin (childYOffset,
  55056. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55057. }
  55058. updateYPositions();
  55059. }
  55060. else
  55061. {
  55062. childYOffset = 0;
  55063. }
  55064. resizeToBestWindowPos();
  55065. repaint();
  55066. }
  55067. int updateYPositions()
  55068. {
  55069. int x = 0;
  55070. int childNum = 0;
  55071. for (int col = 0; col < numColumns; ++col)
  55072. {
  55073. const int numChildren = jmin (getNumChildComponents() - childNum,
  55074. (getNumChildComponents() + numColumns - 1) / numColumns);
  55075. const int colW = columnWidths [col];
  55076. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55077. for (int i = 0; i < numChildren; ++i)
  55078. {
  55079. Component* const c = getChildComponent (childNum + i);
  55080. c->setBounds (x, y, colW, c->getHeight());
  55081. y += c->getHeight();
  55082. }
  55083. x += colW;
  55084. childNum += numChildren;
  55085. }
  55086. return x;
  55087. }
  55088. bool isScrolling() const throw()
  55089. {
  55090. return childYOffset != 0 || needsToScroll;
  55091. }
  55092. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55093. {
  55094. if (currentChild->isValidComponent())
  55095. currentChild->setHighlighted (false);
  55096. currentChild = child;
  55097. if (currentChild != 0)
  55098. {
  55099. currentChild->setHighlighted (true);
  55100. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55101. }
  55102. }
  55103. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55104. {
  55105. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55106. activeSubMenu = 0;
  55107. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55108. {
  55109. const Point<int> topLeft (childComp->relativePositionToGlobal (Point<int>()));
  55110. const Point<int> bottomRight (childComp->relativePositionToGlobal (Point<int> (childComp->getWidth(), childComp->getHeight())));
  55111. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55112. dismissOnMouseUp,
  55113. this,
  55114. topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(),
  55115. 0, maximumNumColumns,
  55116. standardItemHeight,
  55117. false, 0, menuBarComponent,
  55118. managerOfChosenCommand,
  55119. componentAttachedTo);
  55120. if (activeSubMenu != 0)
  55121. {
  55122. activeSubMenu->setVisible (true);
  55123. activeSubMenu->enterModalState (false);
  55124. activeSubMenu->toFront (false);
  55125. return true;
  55126. }
  55127. }
  55128. return false;
  55129. }
  55130. void highlightItemUnderMouse (const Point<int>& globalMousePos, const Point<int>& localMousePos)
  55131. {
  55132. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55133. if (isOver)
  55134. hasBeenOver = true;
  55135. if (lastMouse.getDistanceFrom (globalMousePos) > 2)
  55136. {
  55137. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55138. if (disableMouseMoves && isOver)
  55139. disableMouseMoves = false;
  55140. }
  55141. if (disableMouseMoves)
  55142. return;
  55143. bool isMovingTowardsMenu = false;
  55144. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55145. if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse)
  55146. {
  55147. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55148. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55149. // extends from the last mouse pos to the submenu's rectangle..
  55150. float subX = (float) activeSubMenu->getScreenX();
  55151. if (activeSubMenu->getX() > getX())
  55152. {
  55153. lastMouse -= Point<int> (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55154. }
  55155. else
  55156. {
  55157. lastMouse += Point<int> (2, 0);
  55158. subX += activeSubMenu->getWidth();
  55159. }
  55160. Path areaTowardsSubMenu;
  55161. areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(),
  55162. (float) lastMouse.getY(),
  55163. subX,
  55164. (float) activeSubMenu->getScreenY(),
  55165. subX,
  55166. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55167. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY());
  55168. }
  55169. lastMouse = globalMousePos;
  55170. if (! isMovingTowardsMenu)
  55171. {
  55172. Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY());
  55173. if (c == this)
  55174. c = 0;
  55175. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55176. if (mic == 0 && c != 0)
  55177. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55178. if (mic != currentChild
  55179. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55180. {
  55181. if (isOver && (c != 0) && (activeSubMenu != 0))
  55182. {
  55183. activeSubMenu->hide (0);
  55184. }
  55185. if (! isOver)
  55186. mic = 0;
  55187. setCurrentlyHighlightedChild (mic);
  55188. }
  55189. }
  55190. }
  55191. void triggerCurrentlyHighlightedItem()
  55192. {
  55193. if (currentChild->isValidComponent()
  55194. && currentChild->itemInfo.canBeTriggered()
  55195. && (currentChild->itemInfo.customComp == 0
  55196. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55197. {
  55198. dismissMenu (&currentChild->itemInfo);
  55199. }
  55200. }
  55201. void selectNextItem (const int delta)
  55202. {
  55203. disableTimerUntilMouseMoves();
  55204. PopupMenu::ItemComponent* mic = 0;
  55205. bool wasLastOne = (currentChild == 0);
  55206. const int numItems = getNumChildComponents();
  55207. for (int i = 0; i < numItems + 1; ++i)
  55208. {
  55209. int index = (delta > 0) ? i : (numItems - 1 - i);
  55210. index = (index + numItems) % numItems;
  55211. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55212. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55213. && wasLastOne)
  55214. break;
  55215. if (mic == currentChild)
  55216. wasLastOne = true;
  55217. }
  55218. setCurrentlyHighlightedChild (mic);
  55219. }
  55220. void disableTimerUntilMouseMoves()
  55221. {
  55222. disableMouseMoves = true;
  55223. if (owner != 0)
  55224. owner->disableTimerUntilMouseMoves();
  55225. }
  55226. Window (const Window&);
  55227. Window& operator= (const Window&);
  55228. };
  55229. PopupMenu::PopupMenu()
  55230. : lookAndFeel (0),
  55231. separatorPending (false)
  55232. {
  55233. }
  55234. PopupMenu::PopupMenu (const PopupMenu& other)
  55235. : lookAndFeel (other.lookAndFeel),
  55236. separatorPending (false)
  55237. {
  55238. items.ensureStorageAllocated (other.items.size());
  55239. for (int i = 0; i < other.items.size(); ++i)
  55240. items.add (new Item (*other.items.getUnchecked(i)));
  55241. }
  55242. PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55243. {
  55244. if (this != &other)
  55245. {
  55246. lookAndFeel = other.lookAndFeel;
  55247. clear();
  55248. items.ensureStorageAllocated (other.items.size());
  55249. for (int i = 0; i < other.items.size(); ++i)
  55250. items.add (new Item (*other.items.getUnchecked(i)));
  55251. }
  55252. return *this;
  55253. }
  55254. PopupMenu::~PopupMenu()
  55255. {
  55256. clear();
  55257. }
  55258. void PopupMenu::clear()
  55259. {
  55260. items.clear();
  55261. separatorPending = false;
  55262. }
  55263. void PopupMenu::addSeparatorIfPending()
  55264. {
  55265. if (separatorPending)
  55266. {
  55267. separatorPending = false;
  55268. if (items.size() > 0)
  55269. items.add (new Item());
  55270. }
  55271. }
  55272. void PopupMenu::addItem (const int itemResultId,
  55273. const String& itemText,
  55274. const bool isActive,
  55275. const bool isTicked,
  55276. const Image* const iconToUse)
  55277. {
  55278. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55279. // didn't pick anything, so you shouldn't use it as the id
  55280. // for an item..
  55281. addSeparatorIfPending();
  55282. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55283. iconToUse, Colours::black, false, 0, 0, 0));
  55284. }
  55285. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55286. const int commandID,
  55287. const String& displayName)
  55288. {
  55289. jassert (commandManager != 0 && commandID != 0);
  55290. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55291. if (registeredInfo != 0)
  55292. {
  55293. ApplicationCommandInfo info (*registeredInfo);
  55294. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55295. addSeparatorIfPending();
  55296. items.add (new Item (commandID,
  55297. displayName.isNotEmpty() ? displayName
  55298. : info.shortName,
  55299. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  55300. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  55301. 0,
  55302. Colours::black,
  55303. false,
  55304. 0, 0,
  55305. commandManager));
  55306. }
  55307. }
  55308. void PopupMenu::addColouredItem (const int itemResultId,
  55309. const String& itemText,
  55310. const Colour& itemTextColour,
  55311. const bool isActive,
  55312. const bool isTicked,
  55313. const Image* const iconToUse)
  55314. {
  55315. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55316. // didn't pick anything, so you shouldn't use it as the id
  55317. // for an item..
  55318. addSeparatorIfPending();
  55319. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55320. iconToUse, itemTextColour, true, 0, 0, 0));
  55321. }
  55322. void PopupMenu::addCustomItem (const int itemResultId,
  55323. PopupMenuCustomComponent* const customComponent)
  55324. {
  55325. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55326. // didn't pick anything, so you shouldn't use it as the id
  55327. // for an item..
  55328. addSeparatorIfPending();
  55329. items.add (new Item (itemResultId, String::empty, true, false, 0,
  55330. Colours::black, false, customComponent, 0, 0));
  55331. }
  55332. class NormalComponentWrapper : public PopupMenuCustomComponent
  55333. {
  55334. public:
  55335. NormalComponentWrapper (Component* const comp,
  55336. const int w, const int h,
  55337. const bool triggerMenuItemAutomaticallyWhenClicked)
  55338. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  55339. width (w),
  55340. height (h)
  55341. {
  55342. addAndMakeVisible (comp);
  55343. }
  55344. ~NormalComponentWrapper() {}
  55345. void getIdealSize (int& idealWidth, int& idealHeight)
  55346. {
  55347. idealWidth = width;
  55348. idealHeight = height;
  55349. }
  55350. void resized()
  55351. {
  55352. if (getChildComponent(0) != 0)
  55353. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  55354. }
  55355. juce_UseDebuggingNewOperator
  55356. private:
  55357. const int width, height;
  55358. NormalComponentWrapper (const NormalComponentWrapper&);
  55359. NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  55360. };
  55361. void PopupMenu::addCustomItem (const int itemResultId,
  55362. Component* customComponent,
  55363. int idealWidth, int idealHeight,
  55364. const bool triggerMenuItemAutomaticallyWhenClicked)
  55365. {
  55366. addCustomItem (itemResultId,
  55367. new NormalComponentWrapper (customComponent,
  55368. idealWidth, idealHeight,
  55369. triggerMenuItemAutomaticallyWhenClicked));
  55370. }
  55371. void PopupMenu::addSubMenu (const String& subMenuName,
  55372. const PopupMenu& subMenu,
  55373. const bool isActive,
  55374. Image* const iconToUse,
  55375. const bool isTicked)
  55376. {
  55377. addSeparatorIfPending();
  55378. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  55379. iconToUse, Colours::black, false, 0, &subMenu, 0));
  55380. }
  55381. void PopupMenu::addSeparator()
  55382. {
  55383. separatorPending = true;
  55384. }
  55385. class HeaderItemComponent : public PopupMenuCustomComponent
  55386. {
  55387. public:
  55388. HeaderItemComponent (const String& name)
  55389. : PopupMenuCustomComponent (false)
  55390. {
  55391. setName (name);
  55392. }
  55393. ~HeaderItemComponent()
  55394. {
  55395. }
  55396. void paint (Graphics& g)
  55397. {
  55398. Font f (getLookAndFeel().getPopupMenuFont());
  55399. f.setBold (true);
  55400. g.setFont (f);
  55401. g.setColour (findColour (PopupMenu::headerTextColourId));
  55402. g.drawFittedText (getName(),
  55403. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  55404. Justification::bottomLeft, 1);
  55405. }
  55406. void getIdealSize (int& idealWidth,
  55407. int& idealHeight)
  55408. {
  55409. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  55410. idealHeight += idealHeight / 2;
  55411. idealWidth += idealWidth / 4;
  55412. }
  55413. juce_UseDebuggingNewOperator
  55414. };
  55415. void PopupMenu::addSectionHeader (const String& title)
  55416. {
  55417. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  55418. }
  55419. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  55420. const int itemIdThatMustBeVisible,
  55421. const int minimumWidth,
  55422. const int maximumNumColumns,
  55423. const int standardItemHeight,
  55424. const bool alignToRectangle,
  55425. Component* menuBarComponent,
  55426. ApplicationCommandManager** managerOfChosenCommand,
  55427. Component* const componentAttachedTo)
  55428. {
  55429. Window* const pw
  55430. = Window::create (*this,
  55431. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  55432. 0,
  55433. x, x + w,
  55434. y, y + h,
  55435. minimumWidth,
  55436. maximumNumColumns,
  55437. standardItemHeight,
  55438. alignToRectangle,
  55439. itemIdThatMustBeVisible,
  55440. menuBarComponent,
  55441. managerOfChosenCommand,
  55442. componentAttachedTo);
  55443. if (pw != 0)
  55444. pw->setVisible (true);
  55445. return pw;
  55446. }
  55447. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  55448. const int itemIdThatMustBeVisible,
  55449. const int minimumWidth,
  55450. const int maximumNumColumns,
  55451. const int standardItemHeight,
  55452. const bool alignToRectangle,
  55453. Component* const componentAttachedTo)
  55454. {
  55455. Component::SafePointer<Component> prevFocused (Component::getCurrentlyFocusedComponent());
  55456. Component::SafePointer<Component> prevTopLevel ((prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0);
  55457. Window::wasHiddenBecauseOfAppChange() = false;
  55458. int result = 0;
  55459. ApplicationCommandManager* managerOfChosenCommand = 0;
  55460. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  55461. itemIdThatMustBeVisible,
  55462. minimumWidth,
  55463. maximumNumColumns > 0 ? maximumNumColumns : 7,
  55464. standardItemHeight,
  55465. alignToRectangle, 0,
  55466. &managerOfChosenCommand,
  55467. componentAttachedTo));
  55468. if (popupComp != 0)
  55469. {
  55470. popupComp->enterModalState (false);
  55471. popupComp->toFront (false); // need to do this after making it modal, or it could
  55472. // be stuck behind other comps that are already modal..
  55473. result = popupComp->runModalLoop();
  55474. popupComp = 0;
  55475. if (! Window::wasHiddenBecauseOfAppChange())
  55476. {
  55477. if (prevTopLevel != 0)
  55478. prevTopLevel->toFront (true);
  55479. if (prevFocused != 0)
  55480. prevFocused->grabKeyboardFocus();
  55481. }
  55482. }
  55483. if (managerOfChosenCommand != 0 && result != 0)
  55484. {
  55485. ApplicationCommandTarget::InvocationInfo info (result);
  55486. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  55487. managerOfChosenCommand->invoke (info, true);
  55488. }
  55489. return result;
  55490. }
  55491. int PopupMenu::show (const int itemIdThatMustBeVisible,
  55492. const int minimumWidth,
  55493. const int maximumNumColumns,
  55494. const int standardItemHeight)
  55495. {
  55496. const Point<int> mousePos (Desktop::getMousePosition());
  55497. return showAt (mousePos.getX(), mousePos.getY(),
  55498. itemIdThatMustBeVisible,
  55499. minimumWidth,
  55500. maximumNumColumns,
  55501. standardItemHeight);
  55502. }
  55503. int PopupMenu::showAt (const int screenX,
  55504. const int screenY,
  55505. const int itemIdThatMustBeVisible,
  55506. const int minimumWidth,
  55507. const int maximumNumColumns,
  55508. const int standardItemHeight)
  55509. {
  55510. return showMenu (screenX, screenY, 1, 1,
  55511. itemIdThatMustBeVisible,
  55512. minimumWidth, maximumNumColumns,
  55513. standardItemHeight,
  55514. false, 0);
  55515. }
  55516. int PopupMenu::showAt (Component* componentToAttachTo,
  55517. const int itemIdThatMustBeVisible,
  55518. const int minimumWidth,
  55519. const int maximumNumColumns,
  55520. const int standardItemHeight)
  55521. {
  55522. if (componentToAttachTo != 0)
  55523. {
  55524. return showMenu (componentToAttachTo->getScreenX(),
  55525. componentToAttachTo->getScreenY(),
  55526. componentToAttachTo->getWidth(),
  55527. componentToAttachTo->getHeight(),
  55528. itemIdThatMustBeVisible,
  55529. minimumWidth,
  55530. maximumNumColumns,
  55531. standardItemHeight,
  55532. true, componentToAttachTo);
  55533. }
  55534. else
  55535. {
  55536. return show (itemIdThatMustBeVisible,
  55537. minimumWidth,
  55538. maximumNumColumns,
  55539. standardItemHeight);
  55540. }
  55541. }
  55542. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  55543. {
  55544. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  55545. {
  55546. Window* const pmw = Window::getActiveWindows()[i];
  55547. if (pmw != 0)
  55548. pmw->dismissMenu (0);
  55549. }
  55550. }
  55551. int PopupMenu::getNumItems() const throw()
  55552. {
  55553. int num = 0;
  55554. for (int i = items.size(); --i >= 0;)
  55555. if (! (items.getUnchecked(i))->isSeparator)
  55556. ++num;
  55557. return num;
  55558. }
  55559. bool PopupMenu::containsCommandItem (const int commandID) const
  55560. {
  55561. for (int i = items.size(); --i >= 0;)
  55562. {
  55563. const Item* mi = items.getUnchecked (i);
  55564. if ((mi->itemId == commandID && mi->commandManager != 0)
  55565. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  55566. {
  55567. return true;
  55568. }
  55569. }
  55570. return false;
  55571. }
  55572. bool PopupMenu::containsAnyActiveItems() const throw()
  55573. {
  55574. for (int i = items.size(); --i >= 0;)
  55575. {
  55576. const Item* const mi = items.getUnchecked (i);
  55577. if (mi->subMenu != 0)
  55578. {
  55579. if (mi->subMenu->containsAnyActiveItems())
  55580. return true;
  55581. }
  55582. else if (mi->active)
  55583. {
  55584. return true;
  55585. }
  55586. }
  55587. return false;
  55588. }
  55589. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  55590. {
  55591. lookAndFeel = newLookAndFeel;
  55592. }
  55593. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  55594. : isHighlighted (false),
  55595. isTriggeredAutomatically (isTriggeredAutomatically_)
  55596. {
  55597. }
  55598. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  55599. {
  55600. }
  55601. void PopupMenuCustomComponent::triggerMenuItem()
  55602. {
  55603. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  55604. if (mic != 0)
  55605. {
  55606. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  55607. if (pmw != 0)
  55608. {
  55609. pmw->dismissMenu (&mic->itemInfo);
  55610. }
  55611. else
  55612. {
  55613. // something must have gone wrong with the component hierarchy if this happens..
  55614. jassertfalse
  55615. }
  55616. }
  55617. else
  55618. {
  55619. // why isn't this component inside a menu? Not much point triggering the item if
  55620. // there's no menu.
  55621. jassertfalse
  55622. }
  55623. }
  55624. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  55625. : subMenu (0),
  55626. itemId (0),
  55627. isSeparator (false),
  55628. isTicked (false),
  55629. isEnabled (false),
  55630. isCustomComponent (false),
  55631. isSectionHeader (false),
  55632. customColour (0),
  55633. customImage (0),
  55634. menu (menu_),
  55635. index (0)
  55636. {
  55637. }
  55638. PopupMenu::MenuItemIterator::~MenuItemIterator()
  55639. {
  55640. }
  55641. bool PopupMenu::MenuItemIterator::next()
  55642. {
  55643. if (index >= menu.items.size())
  55644. return false;
  55645. const Item* const item = menu.items.getUnchecked (index);
  55646. ++index;
  55647. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  55648. subMenu = item->subMenu;
  55649. itemId = item->itemId;
  55650. isSeparator = item->isSeparator;
  55651. isTicked = item->isTicked;
  55652. isEnabled = item->active;
  55653. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  55654. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  55655. customColour = item->usesColour ? &(item->textColour) : 0;
  55656. customImage = item->image;
  55657. commandManager = item->commandManager;
  55658. return true;
  55659. }
  55660. END_JUCE_NAMESPACE
  55661. /*** End of inlined file: juce_PopupMenu.cpp ***/
  55662. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  55663. BEGIN_JUCE_NAMESPACE
  55664. ComponentDragger::ComponentDragger()
  55665. : constrainer (0)
  55666. {
  55667. }
  55668. ComponentDragger::~ComponentDragger()
  55669. {
  55670. }
  55671. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  55672. ComponentBoundsConstrainer* const constrainer_)
  55673. {
  55674. jassert (componentToDrag->isValidComponent());
  55675. if (componentToDrag != 0)
  55676. {
  55677. constrainer = constrainer_;
  55678. originalPos = componentToDrag->relativePositionToGlobal (Point<int>());
  55679. }
  55680. }
  55681. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  55682. {
  55683. jassert (componentToDrag->isValidComponent());
  55684. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  55685. if (componentToDrag != 0)
  55686. {
  55687. Rectangle<int> bounds (componentToDrag->getBounds().withPosition (originalPos));
  55688. const Component* const parentComp = componentToDrag->getParentComponent();
  55689. if (parentComp != 0)
  55690. bounds.setPosition (parentComp->globalPositionToRelative (originalPos));
  55691. bounds.setPosition (bounds.getPosition() + e.getOffsetFromDragStart());
  55692. if (constrainer != 0)
  55693. constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false);
  55694. else
  55695. componentToDrag->setBounds (bounds);
  55696. }
  55697. }
  55698. END_JUCE_NAMESPACE
  55699. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  55700. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  55701. BEGIN_JUCE_NAMESPACE
  55702. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  55703. bool juce_performDragDropText (const String& text, bool& shouldStop);
  55704. class DragImageComponent : public Component,
  55705. public Timer
  55706. {
  55707. public:
  55708. DragImageComponent (Image* const im,
  55709. const String& desc,
  55710. Component* const sourceComponent,
  55711. Component* const mouseDragSource_,
  55712. DragAndDropContainer* const o,
  55713. const Point<int>& imageOffset_)
  55714. : image (im),
  55715. source (sourceComponent),
  55716. mouseDragSource (mouseDragSource_),
  55717. owner (o),
  55718. dragDesc (desc),
  55719. imageOffset (imageOffset_),
  55720. hasCheckedForExternalDrag (false),
  55721. drawImage (true)
  55722. {
  55723. setSize (im->getWidth(), im->getHeight());
  55724. if (mouseDragSource == 0)
  55725. mouseDragSource = source;
  55726. mouseDragSource->addMouseListener (this, false);
  55727. startTimer (200);
  55728. setInterceptsMouseClicks (false, false);
  55729. setAlwaysOnTop (true);
  55730. }
  55731. ~DragImageComponent()
  55732. {
  55733. if (owner->dragImageComponent == this)
  55734. owner->dragImageComponent.release();
  55735. if (mouseDragSource != 0)
  55736. {
  55737. mouseDragSource->removeMouseListener (this);
  55738. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDesc, source))
  55739. getCurrentlyOver()->itemDragExit (dragDesc, source);
  55740. }
  55741. }
  55742. void paint (Graphics& g)
  55743. {
  55744. if (isOpaque())
  55745. g.fillAll (Colours::white);
  55746. if (drawImage)
  55747. {
  55748. g.setOpacity (1.0f);
  55749. g.drawImageAt (image, 0, 0);
  55750. }
  55751. }
  55752. DragAndDropTarget* findTarget (const Point<int>& screenPos, Point<int>& relativePos)
  55753. {
  55754. Component* hit = getParentComponent();
  55755. if (hit == 0)
  55756. {
  55757. hit = Desktop::getInstance().findComponentAt (screenPos);
  55758. }
  55759. else
  55760. {
  55761. const Point<int> relPos (hit->globalPositionToRelative (screenPos));
  55762. hit = hit->getComponentAt (relPos.getX(), relPos.getY());
  55763. }
  55764. // (note: use a local copy of the dragDesc member in case the callback runs
  55765. // a modal loop and deletes this object before the method completes)
  55766. const String dragDescLocal (dragDesc);
  55767. while (hit != 0)
  55768. {
  55769. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  55770. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55771. {
  55772. relativePos = hit->globalPositionToRelative (screenPos);
  55773. return ddt;
  55774. }
  55775. hit = hit->getParentComponent();
  55776. }
  55777. return 0;
  55778. }
  55779. void mouseUp (const MouseEvent& e)
  55780. {
  55781. if (e.originalComponent != this)
  55782. {
  55783. if (mouseDragSource != 0)
  55784. mouseDragSource->removeMouseListener (this);
  55785. bool dropAccepted = false;
  55786. DragAndDropTarget* ddt = 0;
  55787. Point<int> relPos;
  55788. if (isVisible())
  55789. {
  55790. setVisible (false);
  55791. ddt = findTarget (e.getScreenPosition(), relPos);
  55792. // fade this component and remove it - it'll be deleted later by the timer callback
  55793. dropAccepted = ddt != 0;
  55794. setVisible (true);
  55795. if (dropAccepted || source == 0)
  55796. {
  55797. fadeOutComponent (120);
  55798. }
  55799. else
  55800. {
  55801. const Point<int> target (source->relativePositionToGlobal (Point<int> (source->getWidth() / 2,
  55802. source->getHeight() / 2)));
  55803. const Point<int> ourCentre (relativePositionToGlobal (Point<int> (getWidth() / 2,
  55804. getHeight() / 2)));
  55805. fadeOutComponent (120,
  55806. target.getX() - ourCentre.getX(),
  55807. target.getY() - ourCentre.getY());
  55808. }
  55809. }
  55810. if (getParentComponent() != 0)
  55811. getParentComponent()->removeChildComponent (this);
  55812. if (dropAccepted && ddt != 0)
  55813. {
  55814. // (note: use a local copy of the dragDesc member in case the callback runs
  55815. // a modal loop and deletes this object before the method completes)
  55816. const String dragDescLocal (dragDesc);
  55817. currentlyOverComp = 0;
  55818. ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
  55819. }
  55820. // careful - this object could now be deleted..
  55821. }
  55822. }
  55823. void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
  55824. {
  55825. // (note: use a local copy of the dragDesc member in case the callback runs
  55826. // a modal loop and deletes this object before it returns)
  55827. const String dragDescLocal (dragDesc);
  55828. Point<int> newPos (screenPos + imageOffset);
  55829. if (getParentComponent() != 0)
  55830. newPos = getParentComponent()->globalPositionToRelative (newPos);
  55831. //if (newX != getX() || newY != getY())
  55832. {
  55833. setTopLeftPosition (newPos.getX(), newPos.getY());
  55834. Point<int> relPos;
  55835. DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
  55836. Component* ddtComp = dynamic_cast <Component*> (ddt);
  55837. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  55838. if (ddtComp != currentlyOverComp)
  55839. {
  55840. if (currentlyOverComp != 0 && source != 0
  55841. && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55842. {
  55843. getCurrentlyOver()->itemDragExit (dragDescLocal, source);
  55844. }
  55845. currentlyOverComp = ddtComp;
  55846. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55847. ddt->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
  55848. }
  55849. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55850. getCurrentlyOver()->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
  55851. if (getCurrentlyOver() == 0
  55852. && canDoExternalDrag
  55853. && ! hasCheckedForExternalDrag)
  55854. {
  55855. if (Desktop::getInstance().findComponentAt (screenPos) == 0)
  55856. {
  55857. hasCheckedForExternalDrag = true;
  55858. StringArray files;
  55859. bool canMoveFiles = false;
  55860. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  55861. && files.size() > 0)
  55862. {
  55863. Component::SafePointer<Component> cdw (this);
  55864. setVisible (false);
  55865. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  55866. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  55867. if (cdw != 0)
  55868. delete this;
  55869. return;
  55870. }
  55871. }
  55872. }
  55873. }
  55874. }
  55875. void mouseDrag (const MouseEvent& e)
  55876. {
  55877. if (e.originalComponent != this)
  55878. updateLocation (true, e.getScreenPosition());
  55879. }
  55880. void timerCallback()
  55881. {
  55882. if (source == 0)
  55883. {
  55884. delete this;
  55885. }
  55886. else if (! isMouseButtonDownAnywhere())
  55887. {
  55888. if (mouseDragSource != 0)
  55889. mouseDragSource->removeMouseListener (this);
  55890. delete this;
  55891. }
  55892. }
  55893. private:
  55894. ScopedPointer<Image> image;
  55895. Component::SafePointer<Component> source;
  55896. Component::SafePointer<Component> mouseDragSource;
  55897. DragAndDropContainer* const owner;
  55898. Component::SafePointer<Component> currentlyOverComp;
  55899. DragAndDropTarget* getCurrentlyOver()
  55900. {
  55901. return dynamic_cast <DragAndDropTarget*> (static_cast <Component*> (currentlyOverComp));
  55902. }
  55903. String dragDesc;
  55904. const Point<int> imageOffset;
  55905. bool hasCheckedForExternalDrag, drawImage;
  55906. DragImageComponent (const DragImageComponent&);
  55907. DragImageComponent& operator= (const DragImageComponent&);
  55908. };
  55909. DragAndDropContainer::DragAndDropContainer()
  55910. {
  55911. }
  55912. DragAndDropContainer::~DragAndDropContainer()
  55913. {
  55914. dragImageComponent = 0;
  55915. }
  55916. void DragAndDropContainer::startDragging (const String& sourceDescription,
  55917. Component* sourceComponent,
  55918. Image* dragImage_,
  55919. const bool allowDraggingToExternalWindows,
  55920. const Point<int>* imageOffsetFromMouse)
  55921. {
  55922. ScopedPointer <Image> dragImage (dragImage_);
  55923. if (dragImageComponent == 0)
  55924. {
  55925. Component* const thisComp = dynamic_cast <Component*> (this);
  55926. if (thisComp == 0)
  55927. {
  55928. jassertfalse; // Your DragAndDropContainer needs to be a Component!
  55929. return;
  55930. }
  55931. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0);
  55932. if (draggingSource == 0 || ! draggingSource->isDragging())
  55933. {
  55934. jassertfalse; // You must call startDragging() from within a mouseDown or mouseDrag callback!
  55935. return;
  55936. }
  55937. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  55938. Point<int> imageOffset;
  55939. if (dragImage == 0)
  55940. {
  55941. dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  55942. if (dragImage->getFormat() != Image::ARGB)
  55943. {
  55944. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  55945. Graphics g2 (*newIm);
  55946. g2.drawImageAt (dragImage, 0, 0);
  55947. dragImage = newIm;
  55948. }
  55949. dragImage->multiplyAllAlphas (0.6f);
  55950. const int lo = 150;
  55951. const int hi = 400;
  55952. Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
  55953. Point<int> clipped (Rectangle<int> (0, 0, dragImage->getWidth(), dragImage->getHeight())
  55954. .getConstrainedPoint (relPos));
  55955. for (int y = dragImage->getHeight(); --y >= 0;)
  55956. {
  55957. const double dy = (y - clipped.getY()) * (y - clipped.getY());
  55958. for (int x = dragImage->getWidth(); --x >= 0;)
  55959. {
  55960. const int dx = x - clipped.getX();
  55961. const int distance = roundToInt (sqrt (dx * dx + dy));
  55962. if (distance > lo)
  55963. {
  55964. const float alpha = (distance > hi) ? 0
  55965. : (hi - distance) / (float) (hi - lo)
  55966. + Random::getSystemRandom().nextFloat() * 0.008f;
  55967. dragImage->multiplyAlphaAt (x, y, alpha);
  55968. }
  55969. }
  55970. }
  55971. imageOffset = -clipped;
  55972. }
  55973. else
  55974. {
  55975. if (imageOffsetFromMouse == 0)
  55976. imageOffset = Point<int> (dragImage->getWidth() / -2,
  55977. dragImage->getHeight() / -2);
  55978. else
  55979. imageOffset = *imageOffsetFromMouse;
  55980. }
  55981. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  55982. draggingSource->getComponentUnderMouse(), this, imageOffset);
  55983. currentDragDesc = sourceDescription;
  55984. if (allowDraggingToExternalWindows)
  55985. {
  55986. if (! Desktop::canUseSemiTransparentWindows())
  55987. dragImageComponent->setOpaque (true);
  55988. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  55989. | ComponentPeer::windowIsTemporary
  55990. | ComponentPeer::windowIgnoresKeyPresses);
  55991. }
  55992. else
  55993. thisComp->addChildComponent (dragImageComponent);
  55994. static_cast <DragImageComponent*> (static_cast <Component*> (dragImageComponent))->updateLocation (false, lastMouseDown);
  55995. dragImageComponent->setVisible (true);
  55996. }
  55997. }
  55998. bool DragAndDropContainer::isDragAndDropActive() const
  55999. {
  56000. return dragImageComponent != 0;
  56001. }
  56002. const String DragAndDropContainer::getCurrentDragDescription() const
  56003. {
  56004. return (dragImageComponent != 0) ? currentDragDesc
  56005. : String::empty;
  56006. }
  56007. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56008. {
  56009. if (c == 0)
  56010. return 0;
  56011. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56012. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56013. }
  56014. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56015. {
  56016. return false;
  56017. }
  56018. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56019. {
  56020. }
  56021. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56022. {
  56023. }
  56024. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56025. {
  56026. }
  56027. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56028. {
  56029. return true;
  56030. }
  56031. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56032. {
  56033. }
  56034. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56035. {
  56036. }
  56037. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56038. {
  56039. }
  56040. END_JUCE_NAMESPACE
  56041. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56042. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56043. BEGIN_JUCE_NAMESPACE
  56044. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56045. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56046. // isStandard set depending on which interface was used to create the cursor
  56047. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56048. static CriticalSection activeCursorListLock;
  56049. static VoidArray activeCursors;
  56050. class SharedMouseCursorInternal : public ReferenceCountedObject
  56051. {
  56052. public:
  56053. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56054. : standardType (type),
  56055. isStandard (true)
  56056. {
  56057. handle = juce_createStandardMouseCursor (standardType);
  56058. activeCursors.add (this);
  56059. }
  56060. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56061. : standardType (MouseCursor::NormalCursor),
  56062. isStandard (false)
  56063. {
  56064. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56065. }
  56066. ~SharedMouseCursorInternal() throw()
  56067. {
  56068. juce_deleteMouseCursor (handle, isStandard);
  56069. activeCursors.removeValue (this);
  56070. }
  56071. void* getHandle() const throw()
  56072. {
  56073. return handle;
  56074. }
  56075. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56076. {
  56077. for (int i = activeCursors.size(); --i >= 0;)
  56078. {
  56079. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56080. if (r->standardType == type)
  56081. return r;
  56082. }
  56083. return new SharedMouseCursorInternal (type);
  56084. }
  56085. juce_UseDebuggingNewOperator
  56086. private:
  56087. void* handle;
  56088. const MouseCursor::StandardCursorType standardType;
  56089. const bool isStandard;
  56090. SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56091. };
  56092. MouseCursor::MouseCursor() throw()
  56093. {
  56094. const ScopedLock sl (activeCursorListLock);
  56095. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56096. }
  56097. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56098. {
  56099. const ScopedLock sl (activeCursorListLock);
  56100. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56101. }
  56102. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56103. {
  56104. const ScopedLock sl (activeCursorListLock);
  56105. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56106. }
  56107. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56108. : cursorHandle (other.cursorHandle)
  56109. {
  56110. }
  56111. MouseCursor::~MouseCursor() throw()
  56112. {
  56113. }
  56114. MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56115. {
  56116. cursorHandle = other.cursorHandle;
  56117. return *this;
  56118. }
  56119. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56120. {
  56121. return cursorHandle == other.cursorHandle;
  56122. }
  56123. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56124. {
  56125. return cursorHandle != other.cursorHandle;
  56126. }
  56127. void* MouseCursor::getHandle() const throw()
  56128. {
  56129. return cursorHandle->getHandle();
  56130. }
  56131. void MouseCursor::showWaitCursor() throw()
  56132. {
  56133. Desktop::getInstance().getMainMouseSource().showMouseCursor (MouseCursor::WaitCursor);
  56134. }
  56135. void MouseCursor::hideWaitCursor() throw()
  56136. {
  56137. Desktop::getInstance().getMainMouseSource().revealCursor();
  56138. }
  56139. END_JUCE_NAMESPACE
  56140. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56141. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56142. BEGIN_JUCE_NAMESPACE
  56143. MouseEvent::MouseEvent (MouseInputSource& source_,
  56144. const Point<int>& position,
  56145. const ModifierKeys& mods_,
  56146. Component* const originator,
  56147. const Time& eventTime_,
  56148. const Point<int> mouseDownPos_,
  56149. const Time& mouseDownTime_,
  56150. const int numberOfClicks_,
  56151. const bool mouseWasDragged) throw()
  56152. : x (position.getX()),
  56153. y (position.getY()),
  56154. mods (mods_),
  56155. eventComponent (originator),
  56156. originalComponent (originator),
  56157. eventTime (eventTime_),
  56158. source (source_),
  56159. mouseDownPos (mouseDownPos_),
  56160. mouseDownTime (mouseDownTime_),
  56161. numberOfClicks (numberOfClicks_),
  56162. wasMovedSinceMouseDown (mouseWasDragged)
  56163. {
  56164. }
  56165. MouseEvent::~MouseEvent() throw()
  56166. {
  56167. }
  56168. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56169. {
  56170. if (otherComponent == 0)
  56171. {
  56172. jassertfalse
  56173. return *this;
  56174. }
  56175. return MouseEvent (source, eventComponent->relativePositionToOtherComponent (otherComponent, getPosition()),
  56176. mods, originalComponent, eventTime,
  56177. eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos),
  56178. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown);
  56179. }
  56180. const MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const throw()
  56181. {
  56182. return MouseEvent (source, newPosition, mods, originalComponent,
  56183. eventTime, mouseDownPos, mouseDownTime,
  56184. numberOfClicks, wasMovedSinceMouseDown);
  56185. }
  56186. bool MouseEvent::mouseWasClicked() const throw()
  56187. {
  56188. return ! wasMovedSinceMouseDown;
  56189. }
  56190. int MouseEvent::getMouseDownX() const throw()
  56191. {
  56192. return mouseDownPos.getX();
  56193. }
  56194. int MouseEvent::getMouseDownY() const throw()
  56195. {
  56196. return mouseDownPos.getY();
  56197. }
  56198. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  56199. {
  56200. return mouseDownPos;
  56201. }
  56202. int MouseEvent::getDistanceFromDragStartX() const throw()
  56203. {
  56204. return x - mouseDownPos.getX();
  56205. }
  56206. int MouseEvent::getDistanceFromDragStartY() const throw()
  56207. {
  56208. return y - mouseDownPos.getY();
  56209. }
  56210. int MouseEvent::getDistanceFromDragStart() const throw()
  56211. {
  56212. return mouseDownPos.getDistanceFrom (getPosition());
  56213. }
  56214. const Point<int> MouseEvent::getOffsetFromDragStart() const throw()
  56215. {
  56216. return getPosition() - mouseDownPos;
  56217. }
  56218. int MouseEvent::getLengthOfMousePress() const throw()
  56219. {
  56220. if (mouseDownTime.toMilliseconds() > 0)
  56221. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56222. return 0;
  56223. }
  56224. const Point<int> MouseEvent::getPosition() const throw()
  56225. {
  56226. return Point<int> (x, y);
  56227. }
  56228. int MouseEvent::getScreenX() const
  56229. {
  56230. return getScreenPosition().getX();
  56231. }
  56232. int MouseEvent::getScreenY() const
  56233. {
  56234. return getScreenPosition().getY();
  56235. }
  56236. const Point<int> MouseEvent::getScreenPosition() const
  56237. {
  56238. return eventComponent->relativePositionToGlobal (Point<int> (x, y));
  56239. }
  56240. int MouseEvent::getMouseDownScreenX() const
  56241. {
  56242. return getMouseDownScreenPosition().getX();
  56243. }
  56244. int MouseEvent::getMouseDownScreenY() const
  56245. {
  56246. return getMouseDownScreenPosition().getY();
  56247. }
  56248. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  56249. {
  56250. return eventComponent->relativePositionToGlobal (mouseDownPos);
  56251. }
  56252. static int doubleClickTimeOutMs = 400;
  56253. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  56254. {
  56255. doubleClickTimeOutMs = newTime;
  56256. }
  56257. int MouseEvent::getDoubleClickTimeout() throw()
  56258. {
  56259. return doubleClickTimeOutMs;
  56260. }
  56261. END_JUCE_NAMESPACE
  56262. /*** End of inlined file: juce_MouseEvent.cpp ***/
  56263. /*** Start of inlined file: juce_MouseInputSource.cpp ***/
  56264. BEGIN_JUCE_NAMESPACE
  56265. class MouseInputSourceInternal : public AsyncUpdater
  56266. {
  56267. public:
  56268. MouseInputSourceInternal (MouseInputSource& source_, const int index_, const bool isMouseDevice_)
  56269. : index (index_), isMouseDevice (isMouseDevice_), source (source_), lastPeer (0), lastTime (0),
  56270. isUnboundedMouseModeOn (false), isCursorVisibleUntilOffscreen (false), currentCursorHandle (0)
  56271. {
  56272. zerostruct (mouseDowns);
  56273. }
  56274. ~MouseInputSourceInternal()
  56275. {
  56276. }
  56277. bool isDragging() const throw()
  56278. {
  56279. return buttonState.isAnyMouseButtonDown();
  56280. }
  56281. Component* getComponentUnderMouse() const
  56282. {
  56283. return static_cast <Component*> (componentUnderMouse);
  56284. }
  56285. const ModifierKeys getCurrentModifiers() const
  56286. {
  56287. return ModifierKeys::getCurrentModifiers().withoutMouseButtons().withFlags (buttonState.getRawFlags());
  56288. }
  56289. ComponentPeer* getPeer()
  56290. {
  56291. if (! ComponentPeer::isValidPeer (lastPeer))
  56292. lastPeer = 0;
  56293. return lastPeer;
  56294. }
  56295. Component* findComponentAt (const Point<int>& screenPos)
  56296. {
  56297. ComponentPeer* const peer = getPeer();
  56298. if (peer != 0)
  56299. {
  56300. Component* const comp = peer->getComponent();
  56301. const Point<int> relativePos (comp->globalPositionToRelative (screenPos));
  56302. // (the contains() call is needed to test for overlapping desktop windows)
  56303. if (comp->contains (relativePos.getX(), relativePos.getY()))
  56304. return comp->getComponentAt (relativePos);
  56305. }
  56306. return 0;
  56307. }
  56308. const Point<int> getScreenPosition() const throw()
  56309. {
  56310. return lastScreenPos + unboundedMouseOffset;
  56311. }
  56312. void sendMouseEnter (Component* const comp, const Point<int>& screenPos, const int64 time)
  56313. {
  56314. //DBG ("Mouse " + String (source.getIndex()) + " enter: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56315. comp->internalMouseEnter (source, comp->globalPositionToRelative (screenPos), time);
  56316. }
  56317. void sendMouseExit (Component* const comp, const Point<int>& screenPos, const int64 time)
  56318. {
  56319. //DBG ("Mouse " + String (source.getIndex()) + " exit: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56320. comp->internalMouseExit (source, comp->globalPositionToRelative (screenPos), time);
  56321. }
  56322. void sendMouseMove (Component* const comp, const Point<int>& screenPos, const int64 time)
  56323. {
  56324. //DBG ("Mouse " + String (source.getIndex()) + " move: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56325. comp->internalMouseMove (source, comp->globalPositionToRelative (screenPos), time);
  56326. }
  56327. void sendMouseDown (Component* const comp, const Point<int>& screenPos, const int64 time)
  56328. {
  56329. //DBG ("Mouse " + String (source.getIndex()) + " down: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56330. comp->internalMouseDown (source, comp->globalPositionToRelative (screenPos), time);
  56331. }
  56332. void sendMouseDrag (Component* const comp, const Point<int>& screenPos, const int64 time)
  56333. {
  56334. //DBG ("Mouse " + String (source.getIndex()) + " drag: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56335. comp->internalMouseDrag (source, comp->globalPositionToRelative (screenPos), time);
  56336. }
  56337. void sendMouseUp (Component* const comp, const Point<int>& screenPos, const int64 time)
  56338. {
  56339. //DBG ("Mouse " + String (source.getIndex()) + " up: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56340. comp->internalMouseUp (source, comp->globalPositionToRelative (screenPos), time, getCurrentModifiers());
  56341. }
  56342. void sendMouseWheel (Component* const comp, const Point<int>& screenPos, const int64 time, float x, float y)
  56343. {
  56344. //DBG ("Mouse " + String (source.getIndex()) + " wheel: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56345. comp->internalMouseWheel (source, comp->globalPositionToRelative (screenPos), time, x, y);
  56346. }
  56347. void setButtons (const Point<int>& screenPos, const int64 time, const ModifierKeys& newButtonState)
  56348. {
  56349. if (buttonState != newButtonState)
  56350. {
  56351. // (ignore secondary clicks when there's already a button down)
  56352. if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown())
  56353. {
  56354. buttonState = newButtonState;
  56355. return;
  56356. }
  56357. if (buttonState.isAnyMouseButtonDown())
  56358. {
  56359. Component* const current = getComponentUnderMouse();
  56360. if (current != 0)
  56361. sendMouseUp (current, screenPos + unboundedMouseOffset, time);
  56362. enableUnboundedMouseMovement (false, false);
  56363. }
  56364. buttonState = newButtonState;
  56365. if (buttonState.isAnyMouseButtonDown())
  56366. {
  56367. Desktop::getInstance().incrementMouseClickCounter();
  56368. Component* const current = getComponentUnderMouse();
  56369. if (current != 0)
  56370. {
  56371. registerMouseDown (screenPos, time, current);
  56372. sendMouseDown (current, screenPos, time);
  56373. }
  56374. }
  56375. }
  56376. }
  56377. void setComponentUnderMouse (Component* const newComponent, const Point<int>& screenPos, const int64 time)
  56378. {
  56379. Component* current = getComponentUnderMouse();
  56380. if (newComponent != current)
  56381. {
  56382. Component::SafePointer<Component> safeNewComp (newComponent);
  56383. const ModifierKeys originalButtonState (buttonState);
  56384. if (current != 0)
  56385. {
  56386. setButtons (screenPos, time, ModifierKeys());
  56387. sendMouseExit (current, screenPos, time);
  56388. buttonState = originalButtonState;
  56389. }
  56390. componentUnderMouse = safeNewComp;
  56391. current = getComponentUnderMouse();
  56392. if (current != 0)
  56393. sendMouseEnter (current, screenPos, time);
  56394. revealCursor (false);
  56395. setButtons (screenPos, time, originalButtonState);
  56396. }
  56397. }
  56398. void setPeer (ComponentPeer* const newPeer, const Point<int>& screenPos, const int64 time)
  56399. {
  56400. ModifierKeys::updateCurrentModifiers();
  56401. if (newPeer != lastPeer)
  56402. {
  56403. setComponentUnderMouse (0, screenPos, time);
  56404. lastPeer = newPeer;
  56405. setComponentUnderMouse (findComponentAt (screenPos), screenPos, time);
  56406. }
  56407. }
  56408. void setScreenPos (const Point<int>& newScreenPos, const int64 time, const bool forceUpdate)
  56409. {
  56410. if (! isDragging())
  56411. setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
  56412. if (newScreenPos != lastScreenPos || forceUpdate)
  56413. {
  56414. cancelPendingUpdate();
  56415. lastScreenPos = newScreenPos;
  56416. Component* const current = getComponentUnderMouse();
  56417. if (current != 0)
  56418. {
  56419. if (isDragging())
  56420. {
  56421. registerMouseDrag (newScreenPos);
  56422. sendMouseDrag (current, newScreenPos + unboundedMouseOffset, time);
  56423. if (isUnboundedMouseModeOn)
  56424. handleUnboundedDrag (current);
  56425. }
  56426. else
  56427. {
  56428. sendMouseMove (current, newScreenPos, time);
  56429. }
  56430. }
  56431. revealCursor (false);
  56432. }
  56433. }
  56434. void handleEvent (ComponentPeer* const newPeer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& newMods)
  56435. {
  56436. jassert (newPeer != 0);
  56437. lastTime = time;
  56438. const Point<int> screenPos (newPeer->relativePositionToGlobal (positionWithinPeer));
  56439. if (isDragging() && newMods.isAnyMouseButtonDown())
  56440. {
  56441. setScreenPos (screenPos, time, false);
  56442. }
  56443. else
  56444. {
  56445. setPeer (newPeer, screenPos, time);
  56446. ComponentPeer* peer = getPeer();
  56447. if (peer != 0)
  56448. {
  56449. setButtons (screenPos, time, newMods);
  56450. peer = getPeer();
  56451. if (peer != 0)
  56452. setScreenPos (peer->relativePositionToGlobal (positionWithinPeer), time, false);
  56453. }
  56454. }
  56455. }
  56456. void handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, int64 time, float x, float y)
  56457. {
  56458. jassert (peer != 0);
  56459. lastTime = time;
  56460. const Point<int> screenPos (peer->relativePositionToGlobal (positionWithinPeer));
  56461. setPeer (peer, screenPos, time);
  56462. setScreenPos (screenPos, time, false);
  56463. triggerFakeMove();
  56464. if (! isDragging())
  56465. {
  56466. Component* current = getComponentUnderMouse();
  56467. if (current != 0)
  56468. sendMouseWheel (current, screenPos, time, x, y);
  56469. }
  56470. }
  56471. const Time getLastMouseDownTime() const throw()
  56472. {
  56473. return Time (mouseDowns[0].time);
  56474. }
  56475. const Point<int> getLastMouseDownPosition() const throw()
  56476. {
  56477. return mouseDowns[0].position;
  56478. }
  56479. int getNumberOfMultipleClicks() const throw()
  56480. {
  56481. int numClicks = 0;
  56482. if (mouseDowns[0].time != 0)
  56483. {
  56484. if (! mouseMovedSignificantlySincePressed)
  56485. ++numClicks;
  56486. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  56487. {
  56488. if (mouseDowns[0].time - mouseDowns[i].time < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  56489. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  56490. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  56491. && mouseDowns[0].component == mouseDowns[i].component)
  56492. {
  56493. ++numClicks;
  56494. }
  56495. else
  56496. {
  56497. break;
  56498. }
  56499. }
  56500. }
  56501. return numClicks;
  56502. }
  56503. bool hasMouseMovedSignificantlySincePressed() const throw()
  56504. {
  56505. return mouseMovedSignificantlySincePressed
  56506. || lastTime > mouseDowns[0].time + 300;
  56507. }
  56508. void triggerFakeMove()
  56509. {
  56510. triggerAsyncUpdate();
  56511. }
  56512. void handleAsyncUpdate()
  56513. {
  56514. if (! isDragging())
  56515. setScreenPos (Desktop::getMousePosition(), jmax (lastTime, Time::currentTimeMillis()), true);
  56516. }
  56517. void enableUnboundedMouseMovement (bool enable, bool keepCursorVisibleUntilOffscreen)
  56518. {
  56519. enable = enable && isDragging();
  56520. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  56521. if (enable != isUnboundedMouseModeOn)
  56522. {
  56523. if ((! enable) && ((! isCursorVisibleUntilOffscreen) || ! unboundedMouseOffset.isOrigin()))
  56524. {
  56525. // when released, return the mouse to within the component's bounds
  56526. Component* current = getComponentUnderMouse();
  56527. if (current != 0)
  56528. Desktop::setMousePosition (current->getScreenBounds()
  56529. .getConstrainedPoint (current->getMouseXYRelative()));
  56530. }
  56531. isUnboundedMouseModeOn = enable;
  56532. unboundedMouseOffset = Point<int>();
  56533. revealCursor (true);
  56534. }
  56535. }
  56536. void handleUnboundedDrag (Component* current)
  56537. {
  56538. const Rectangle<int> screenArea (current->getParentMonitorArea().expanded (-2, -2));
  56539. if (! screenArea.contains (lastScreenPos))
  56540. {
  56541. const Point<int> componentCentre (current->getScreenBounds().getCentre());
  56542. unboundedMouseOffset += (lastScreenPos - componentCentre);
  56543. Desktop::setMousePosition (componentCentre);
  56544. }
  56545. else if (isCursorVisibleUntilOffscreen
  56546. && (! unboundedMouseOffset.isOrigin())
  56547. && screenArea.contains (lastScreenPos + unboundedMouseOffset))
  56548. {
  56549. Desktop::setMousePosition (lastScreenPos + unboundedMouseOffset);
  56550. unboundedMouseOffset = Point<int>();
  56551. }
  56552. }
  56553. void showMouseCursor (MouseCursor cursor, bool forcedUpdate)
  56554. {
  56555. if (isUnboundedMouseModeOn && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  56556. {
  56557. cursor = MouseCursor::NoCursor;
  56558. forcedUpdate = true;
  56559. }
  56560. if (forcedUpdate || cursor.getHandle() != currentCursorHandle)
  56561. {
  56562. currentCursorHandle = cursor.getHandle();
  56563. cursor.showInWindow (getPeer());
  56564. }
  56565. }
  56566. void hideCursor()
  56567. {
  56568. showMouseCursor (MouseCursor::NoCursor, true);
  56569. }
  56570. void revealCursor (bool forcedUpdate)
  56571. {
  56572. MouseCursor mc (MouseCursor::NormalCursor);
  56573. Component* current = getComponentUnderMouse();
  56574. if (current != 0)
  56575. mc = current->getLookAndFeel().getMouseCursorFor (*current);
  56576. showMouseCursor (mc, forcedUpdate);
  56577. }
  56578. int index;
  56579. bool isMouseDevice;
  56580. Point<int> lastScreenPos;
  56581. ModifierKeys buttonState;
  56582. private:
  56583. MouseInputSource& source;
  56584. Component::SafePointer<Component> componentUnderMouse;
  56585. ComponentPeer* lastPeer;
  56586. Point<int> unboundedMouseOffset;
  56587. bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen;
  56588. void* currentCursorHandle;
  56589. struct RecentMouseDown
  56590. {
  56591. Point<int> position;
  56592. int64 time;
  56593. Component* component;
  56594. };
  56595. RecentMouseDown mouseDowns[4];
  56596. bool mouseMovedSignificantlySincePressed;
  56597. int64 lastTime;
  56598. void registerMouseDown (const Point<int>& screenPos, const int64 time, Component* const component) throw()
  56599. {
  56600. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  56601. mouseDowns[i] = mouseDowns[i - 1];
  56602. mouseDowns[0].position = screenPos;
  56603. mouseDowns[0].time = time;
  56604. mouseDowns[0].component = component;
  56605. mouseMovedSignificantlySincePressed = false;
  56606. }
  56607. void registerMouseDrag (const Point<int>& screenPos) throw()
  56608. {
  56609. mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed
  56610. || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4;
  56611. }
  56612. };
  56613. MouseInputSource::MouseInputSource (const int index, const bool isMouseDevice)
  56614. {
  56615. pimpl = new MouseInputSourceInternal (*this, index, isMouseDevice);
  56616. }
  56617. MouseInputSource::~MouseInputSource()
  56618. {
  56619. }
  56620. bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
  56621. bool MouseInputSource::isTouch() const { return ! isMouse(); }
  56622. bool MouseInputSource::canHover() const { return isMouse(); }
  56623. bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
  56624. int MouseInputSource::getIndex() const { return pimpl->index; }
  56625. bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
  56626. const Point<int> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
  56627. const ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
  56628. Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); }
  56629. void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); }
  56630. int MouseInputSource::getNumberOfMultipleClicks() const throw() { return pimpl->getNumberOfMultipleClicks(); }
  56631. const Time MouseInputSource::getLastMouseDownTime() const throw() { return pimpl->getLastMouseDownTime(); }
  56632. const Point<int> MouseInputSource::getLastMouseDownPosition() const throw() { return pimpl->getLastMouseDownPosition(); }
  56633. bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const throw() { return pimpl->hasMouseMovedSignificantlySincePressed(); }
  56634. bool MouseInputSource::canDoUnboundedMovement() const throw() { return isMouse(); }
  56635. void MouseInputSource::enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen) { pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); }
  56636. bool MouseInputSource::hasMouseCursor() const throw() { return isMouse(); }
  56637. void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); }
  56638. void MouseInputSource::hideCursor() { pimpl->hideCursor(); }
  56639. void MouseInputSource::revealCursor() { pimpl->revealCursor (false); }
  56640. void MouseInputSource::forceMouseCursorUpdate() { pimpl->revealCursor (true); }
  56641. void MouseInputSource::handleEvent (ComponentPeer* peer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& mods)
  56642. {
  56643. pimpl->handleEvent (peer, positionWithinPeer, time, mods.withOnlyMouseButtons());
  56644. }
  56645. void MouseInputSource::handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  56646. {
  56647. pimpl->handleWheel (peer, positionWithinPeer, time, x, y);
  56648. }
  56649. END_JUCE_NAMESPACE
  56650. /*** End of inlined file: juce_MouseInputSource.cpp ***/
  56651. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  56652. BEGIN_JUCE_NAMESPACE
  56653. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  56654. : source (0),
  56655. hoverTimeMillisecs (hoverTimeMillisecs_),
  56656. hasJustHovered (false)
  56657. {
  56658. internalTimer.owner = this;
  56659. }
  56660. MouseHoverDetector::~MouseHoverDetector()
  56661. {
  56662. setHoverComponent (0);
  56663. }
  56664. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  56665. {
  56666. hoverTimeMillisecs = newTimeInMillisecs;
  56667. }
  56668. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  56669. {
  56670. if (source != newSourceComponent)
  56671. {
  56672. internalTimer.stopTimer();
  56673. hasJustHovered = false;
  56674. if (source != 0)
  56675. {
  56676. // ! you need to delete the hover detector before deleting its component
  56677. jassert (source->isValidComponent());
  56678. source->removeMouseListener (&internalTimer);
  56679. }
  56680. source = newSourceComponent;
  56681. if (newSourceComponent != 0)
  56682. newSourceComponent->addMouseListener (&internalTimer, false);
  56683. }
  56684. }
  56685. void MouseHoverDetector::hoverTimerCallback()
  56686. {
  56687. internalTimer.stopTimer();
  56688. if (source != 0)
  56689. {
  56690. const Point<int> pos (source->getMouseXYRelative());
  56691. if (source->reallyContains (pos.getX(), pos.getY(), false))
  56692. {
  56693. hasJustHovered = true;
  56694. mouseHovered (pos.getX(), pos.getY());
  56695. }
  56696. }
  56697. }
  56698. void MouseHoverDetector::checkJustHoveredCallback()
  56699. {
  56700. if (hasJustHovered)
  56701. {
  56702. hasJustHovered = false;
  56703. mouseMovedAfterHover();
  56704. }
  56705. }
  56706. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  56707. {
  56708. owner->hoverTimerCallback();
  56709. }
  56710. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  56711. {
  56712. stopTimer();
  56713. owner->checkJustHoveredCallback();
  56714. }
  56715. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  56716. {
  56717. stopTimer();
  56718. owner->checkJustHoveredCallback();
  56719. }
  56720. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  56721. {
  56722. stopTimer();
  56723. owner->checkJustHoveredCallback();
  56724. }
  56725. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  56726. {
  56727. stopTimer();
  56728. owner->checkJustHoveredCallback();
  56729. }
  56730. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  56731. {
  56732. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  56733. {
  56734. lastX = e.x;
  56735. lastY = e.y;
  56736. if (owner->source != 0)
  56737. startTimer (owner->hoverTimeMillisecs);
  56738. owner->checkJustHoveredCallback();
  56739. }
  56740. }
  56741. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  56742. {
  56743. stopTimer();
  56744. owner->checkJustHoveredCallback();
  56745. }
  56746. END_JUCE_NAMESPACE
  56747. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  56748. /*** Start of inlined file: juce_MouseListener.cpp ***/
  56749. BEGIN_JUCE_NAMESPACE
  56750. void MouseListener::mouseEnter (const MouseEvent&)
  56751. {
  56752. }
  56753. void MouseListener::mouseExit (const MouseEvent&)
  56754. {
  56755. }
  56756. void MouseListener::mouseDown (const MouseEvent&)
  56757. {
  56758. }
  56759. void MouseListener::mouseUp (const MouseEvent&)
  56760. {
  56761. }
  56762. void MouseListener::mouseDrag (const MouseEvent&)
  56763. {
  56764. }
  56765. void MouseListener::mouseMove (const MouseEvent&)
  56766. {
  56767. }
  56768. void MouseListener::mouseDoubleClick (const MouseEvent&)
  56769. {
  56770. }
  56771. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  56772. {
  56773. }
  56774. END_JUCE_NAMESPACE
  56775. /*** End of inlined file: juce_MouseListener.cpp ***/
  56776. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56777. BEGIN_JUCE_NAMESPACE
  56778. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  56779. const String& buttonTextWhenTrue,
  56780. const String& buttonTextWhenFalse)
  56781. : PropertyComponent (name),
  56782. onText (buttonTextWhenTrue),
  56783. offText (buttonTextWhenFalse)
  56784. {
  56785. createButton();
  56786. button->addButtonListener (this);
  56787. }
  56788. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  56789. const String& name,
  56790. const String& buttonText)
  56791. : PropertyComponent (name),
  56792. onText (buttonText),
  56793. offText (buttonText)
  56794. {
  56795. createButton();
  56796. button->setButtonText (buttonText);
  56797. button->getToggleStateValue().referTo (valueToControl);
  56798. button->setClickingTogglesState (true);
  56799. }
  56800. BooleanPropertyComponent::~BooleanPropertyComponent()
  56801. {
  56802. deleteAllChildren();
  56803. }
  56804. void BooleanPropertyComponent::createButton()
  56805. {
  56806. addAndMakeVisible (button = new ToggleButton (String::empty));
  56807. button->setClickingTogglesState (false);
  56808. }
  56809. void BooleanPropertyComponent::setState (const bool newState)
  56810. {
  56811. button->setToggleState (newState, true);
  56812. }
  56813. bool BooleanPropertyComponent::getState() const
  56814. {
  56815. return button->getToggleState();
  56816. }
  56817. void BooleanPropertyComponent::paint (Graphics& g)
  56818. {
  56819. PropertyComponent::paint (g);
  56820. const Rectangle<int> r (button->getBounds());
  56821. g.setColour (Colours::white);
  56822. g.fillRect (r);
  56823. g.setColour (findColour (ComboBox::outlineColourId));
  56824. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  56825. }
  56826. void BooleanPropertyComponent::refresh()
  56827. {
  56828. button->setToggleState (getState(), false);
  56829. button->setButtonText (button->getToggleState() ? onText : offText);
  56830. }
  56831. void BooleanPropertyComponent::buttonClicked (Button*)
  56832. {
  56833. setState (! getState());
  56834. }
  56835. END_JUCE_NAMESPACE
  56836. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56837. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56838. BEGIN_JUCE_NAMESPACE
  56839. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  56840. const bool triggerOnMouseDown)
  56841. : PropertyComponent (name)
  56842. {
  56843. addAndMakeVisible (button = new TextButton (String::empty));
  56844. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  56845. button->addButtonListener (this);
  56846. }
  56847. ButtonPropertyComponent::~ButtonPropertyComponent()
  56848. {
  56849. deleteAllChildren();
  56850. }
  56851. void ButtonPropertyComponent::refresh()
  56852. {
  56853. button->setButtonText (getButtonText());
  56854. }
  56855. void ButtonPropertyComponent::buttonClicked (Button*)
  56856. {
  56857. buttonClicked();
  56858. }
  56859. END_JUCE_NAMESPACE
  56860. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56861. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56862. BEGIN_JUCE_NAMESPACE
  56863. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  56864. : PropertyComponent (name),
  56865. comboBox (0)
  56866. {
  56867. }
  56868. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  56869. const String& name,
  56870. const StringArray& choices_,
  56871. const Array <int>* choiceIDs)
  56872. : PropertyComponent (name),
  56873. choices (choices_),
  56874. comboBox (0)
  56875. {
  56876. createComboBox (choiceIDs);
  56877. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  56878. }
  56879. ChoicePropertyComponent::~ChoicePropertyComponent()
  56880. {
  56881. deleteAllChildren();
  56882. }
  56883. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  56884. {
  56885. // The array of IDs must contain the same number of values as the choices list!
  56886. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  56887. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  56888. for (int i = 0; i < choices.size(); ++i)
  56889. {
  56890. if (choices[i].isNotEmpty())
  56891. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  56892. : ((*choiceIDs)[i]));
  56893. else
  56894. comboBox->addSeparator();
  56895. }
  56896. comboBox->setEditableText (false);
  56897. }
  56898. void ChoicePropertyComponent::setIndex (const int newIndex)
  56899. {
  56900. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  56901. }
  56902. int ChoicePropertyComponent::getIndex() const
  56903. {
  56904. return comboBox->getSelectedItemIndex();
  56905. }
  56906. const StringArray& ChoicePropertyComponent::getChoices() const
  56907. {
  56908. return choices;
  56909. }
  56910. void ChoicePropertyComponent::refresh()
  56911. {
  56912. if (comboBox == 0)
  56913. {
  56914. createComboBox (0);
  56915. comboBox->addListener (this);
  56916. }
  56917. comboBox->setSelectedId (getIndex() + 1, true);
  56918. }
  56919. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  56920. {
  56921. const int newIndex = comboBox->getSelectedId() - 1;
  56922. if (newIndex != getIndex())
  56923. setIndex (newIndex);
  56924. }
  56925. END_JUCE_NAMESPACE
  56926. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56927. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  56928. BEGIN_JUCE_NAMESPACE
  56929. PropertyComponent::PropertyComponent (const String& name,
  56930. const int preferredHeight_)
  56931. : Component (name),
  56932. preferredHeight (preferredHeight_)
  56933. {
  56934. jassert (name.isNotEmpty());
  56935. }
  56936. PropertyComponent::~PropertyComponent()
  56937. {
  56938. }
  56939. void PropertyComponent::paint (Graphics& g)
  56940. {
  56941. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  56942. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  56943. }
  56944. void PropertyComponent::resized()
  56945. {
  56946. if (getNumChildComponents() > 0)
  56947. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  56948. }
  56949. void PropertyComponent::enablementChanged()
  56950. {
  56951. repaint();
  56952. }
  56953. END_JUCE_NAMESPACE
  56954. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  56955. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  56956. BEGIN_JUCE_NAMESPACE
  56957. class PropertyHolderComponent : public Component
  56958. {
  56959. public:
  56960. PropertyHolderComponent()
  56961. {
  56962. }
  56963. ~PropertyHolderComponent()
  56964. {
  56965. deleteAllChildren();
  56966. }
  56967. void paint (Graphics&)
  56968. {
  56969. }
  56970. void updateLayout (const int width);
  56971. void refreshAll() const;
  56972. };
  56973. class PropertySectionComponent : public Component
  56974. {
  56975. public:
  56976. PropertySectionComponent (const String& sectionTitle,
  56977. const Array <PropertyComponent*>& newProperties,
  56978. const bool open)
  56979. : Component (sectionTitle),
  56980. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  56981. isOpen_ (open)
  56982. {
  56983. for (int i = newProperties.size(); --i >= 0;)
  56984. {
  56985. addAndMakeVisible (newProperties.getUnchecked(i));
  56986. newProperties.getUnchecked(i)->refresh();
  56987. }
  56988. }
  56989. ~PropertySectionComponent()
  56990. {
  56991. deleteAllChildren();
  56992. }
  56993. void paint (Graphics& g)
  56994. {
  56995. if (titleHeight > 0)
  56996. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  56997. }
  56998. void resized()
  56999. {
  57000. int y = titleHeight;
  57001. for (int i = getNumChildComponents(); --i >= 0;)
  57002. {
  57003. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57004. if (pec != 0)
  57005. {
  57006. const int prefH = pec->getPreferredHeight();
  57007. pec->setBounds (1, y, getWidth() - 2, prefH);
  57008. y += prefH;
  57009. }
  57010. }
  57011. }
  57012. int getPreferredHeight() const
  57013. {
  57014. int y = titleHeight;
  57015. if (isOpen())
  57016. {
  57017. for (int i = 0; i < getNumChildComponents(); ++i)
  57018. {
  57019. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57020. if (pec != 0)
  57021. y += pec->getPreferredHeight();
  57022. }
  57023. }
  57024. return y;
  57025. }
  57026. void setOpen (const bool open)
  57027. {
  57028. if (isOpen_ != open)
  57029. {
  57030. isOpen_ = open;
  57031. for (int i = 0; i < getNumChildComponents(); ++i)
  57032. {
  57033. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57034. if (pec != 0)
  57035. pec->setVisible (open);
  57036. }
  57037. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57038. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57039. if (pp != 0)
  57040. pp->resized();
  57041. }
  57042. }
  57043. bool isOpen() const
  57044. {
  57045. return isOpen_;
  57046. }
  57047. void refreshAll() const
  57048. {
  57049. for (int i = 0; i < getNumChildComponents(); ++i)
  57050. {
  57051. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57052. if (pec != 0)
  57053. pec->refresh();
  57054. }
  57055. }
  57056. void mouseDown (const MouseEvent&)
  57057. {
  57058. }
  57059. void mouseUp (const MouseEvent& e)
  57060. {
  57061. if (e.getMouseDownX() < titleHeight
  57062. && e.x < titleHeight
  57063. && e.y < titleHeight
  57064. && e.getNumberOfClicks() != 2)
  57065. {
  57066. setOpen (! isOpen());
  57067. }
  57068. }
  57069. void mouseDoubleClick (const MouseEvent& e)
  57070. {
  57071. if (e.y < titleHeight)
  57072. setOpen (! isOpen());
  57073. }
  57074. private:
  57075. int titleHeight;
  57076. bool isOpen_;
  57077. };
  57078. void PropertyHolderComponent::updateLayout (const int width)
  57079. {
  57080. int y = 0;
  57081. for (int i = getNumChildComponents(); --i >= 0;)
  57082. {
  57083. PropertySectionComponent* const section
  57084. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57085. if (section != 0)
  57086. {
  57087. const int prefH = section->getPreferredHeight();
  57088. section->setBounds (0, y, width, prefH);
  57089. y += prefH;
  57090. }
  57091. }
  57092. setSize (width, y);
  57093. repaint();
  57094. }
  57095. void PropertyHolderComponent::refreshAll() const
  57096. {
  57097. for (int i = getNumChildComponents(); --i >= 0;)
  57098. {
  57099. PropertySectionComponent* const section
  57100. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57101. if (section != 0)
  57102. section->refreshAll();
  57103. }
  57104. }
  57105. PropertyPanel::PropertyPanel()
  57106. {
  57107. messageWhenEmpty = TRANS("(nothing selected)");
  57108. addAndMakeVisible (viewport = new Viewport());
  57109. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57110. viewport->setFocusContainer (true);
  57111. }
  57112. PropertyPanel::~PropertyPanel()
  57113. {
  57114. clear();
  57115. deleteAllChildren();
  57116. }
  57117. void PropertyPanel::paint (Graphics& g)
  57118. {
  57119. if (propertyHolderComponent->getNumChildComponents() == 0)
  57120. {
  57121. g.setColour (Colours::black.withAlpha (0.5f));
  57122. g.setFont (14.0f);
  57123. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57124. Justification::centred, true);
  57125. }
  57126. }
  57127. void PropertyPanel::resized()
  57128. {
  57129. viewport->setBounds (0, 0, getWidth(), getHeight());
  57130. updatePropHolderLayout();
  57131. }
  57132. void PropertyPanel::clear()
  57133. {
  57134. if (propertyHolderComponent->getNumChildComponents() > 0)
  57135. {
  57136. propertyHolderComponent->deleteAllChildren();
  57137. repaint();
  57138. }
  57139. }
  57140. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57141. {
  57142. if (propertyHolderComponent->getNumChildComponents() == 0)
  57143. repaint();
  57144. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57145. newProperties,
  57146. true), 0);
  57147. updatePropHolderLayout();
  57148. }
  57149. void PropertyPanel::addSection (const String& sectionTitle,
  57150. const Array <PropertyComponent*>& newProperties,
  57151. const bool shouldBeOpen)
  57152. {
  57153. jassert (sectionTitle.isNotEmpty());
  57154. if (propertyHolderComponent->getNumChildComponents() == 0)
  57155. repaint();
  57156. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57157. newProperties,
  57158. shouldBeOpen), 0);
  57159. updatePropHolderLayout();
  57160. }
  57161. void PropertyPanel::updatePropHolderLayout() const
  57162. {
  57163. const int maxWidth = viewport->getMaximumVisibleWidth();
  57164. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57165. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57166. if (maxWidth != newMaxWidth)
  57167. {
  57168. // need to do this twice because of scrollbars changing the size, etc.
  57169. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57170. }
  57171. }
  57172. void PropertyPanel::refreshAll() const
  57173. {
  57174. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57175. }
  57176. const StringArray PropertyPanel::getSectionNames() const
  57177. {
  57178. StringArray s;
  57179. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57180. {
  57181. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57182. if (section != 0 && section->getName().isNotEmpty())
  57183. s.add (section->getName());
  57184. }
  57185. return s;
  57186. }
  57187. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57188. {
  57189. int index = 0;
  57190. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57191. {
  57192. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57193. if (section != 0 && section->getName().isNotEmpty())
  57194. {
  57195. if (index == sectionIndex)
  57196. return section->isOpen();
  57197. ++index;
  57198. }
  57199. }
  57200. return false;
  57201. }
  57202. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57203. {
  57204. int index = 0;
  57205. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57206. {
  57207. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57208. if (section != 0 && section->getName().isNotEmpty())
  57209. {
  57210. if (index == sectionIndex)
  57211. {
  57212. section->setOpen (shouldBeOpen);
  57213. break;
  57214. }
  57215. ++index;
  57216. }
  57217. }
  57218. }
  57219. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57220. {
  57221. int index = 0;
  57222. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57223. {
  57224. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57225. if (section != 0 && section->getName().isNotEmpty())
  57226. {
  57227. if (index == sectionIndex)
  57228. {
  57229. section->setEnabled (shouldBeEnabled);
  57230. break;
  57231. }
  57232. ++index;
  57233. }
  57234. }
  57235. }
  57236. XmlElement* PropertyPanel::getOpennessState() const
  57237. {
  57238. XmlElement* const xml = new XmlElement (T("PROPERTYPANELSTATE"));
  57239. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57240. const StringArray sections (getSectionNames());
  57241. for (int i = 0; i < sections.size(); ++i)
  57242. {
  57243. if (sections[i].isNotEmpty())
  57244. {
  57245. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57246. e->setAttribute ("name", sections[i]);
  57247. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57248. }
  57249. }
  57250. return xml;
  57251. }
  57252. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57253. {
  57254. if (xml.hasTagName (T("PROPERTYPANELSTATE")))
  57255. {
  57256. const StringArray sections (getSectionNames());
  57257. forEachXmlChildElementWithTagName (xml, e, T("SECTION"))
  57258. {
  57259. setSectionOpen (sections.indexOf (e->getStringAttribute (T("name"))),
  57260. e->getBoolAttribute (T("open")));
  57261. }
  57262. viewport->setViewPosition (viewport->getViewPositionX(),
  57263. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57264. }
  57265. }
  57266. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57267. {
  57268. if (messageWhenEmpty != newMessage)
  57269. {
  57270. messageWhenEmpty = newMessage;
  57271. repaint();
  57272. }
  57273. }
  57274. const String& PropertyPanel::getMessageWhenEmpty() const
  57275. {
  57276. return messageWhenEmpty;
  57277. }
  57278. END_JUCE_NAMESPACE
  57279. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57280. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57281. BEGIN_JUCE_NAMESPACE
  57282. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57283. const double rangeMin,
  57284. const double rangeMax,
  57285. const double interval,
  57286. const double skewFactor)
  57287. : PropertyComponent (name)
  57288. {
  57289. addAndMakeVisible (slider = new Slider (name));
  57290. slider->setRange (rangeMin, rangeMax, interval);
  57291. slider->setSkewFactor (skewFactor);
  57292. slider->setSliderStyle (Slider::LinearBar);
  57293. slider->addListener (this);
  57294. }
  57295. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57296. const String& name,
  57297. const double rangeMin,
  57298. const double rangeMax,
  57299. const double interval,
  57300. const double skewFactor)
  57301. : PropertyComponent (name)
  57302. {
  57303. addAndMakeVisible (slider = new Slider (name));
  57304. slider->setRange (rangeMin, rangeMax, interval);
  57305. slider->setSkewFactor (skewFactor);
  57306. slider->setSliderStyle (Slider::LinearBar);
  57307. slider->getValueObject().referTo (valueToControl);
  57308. }
  57309. SliderPropertyComponent::~SliderPropertyComponent()
  57310. {
  57311. deleteAllChildren();
  57312. }
  57313. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57314. {
  57315. }
  57316. double SliderPropertyComponent::getValue() const
  57317. {
  57318. return slider->getValue();
  57319. }
  57320. void SliderPropertyComponent::refresh()
  57321. {
  57322. slider->setValue (getValue(), false);
  57323. }
  57324. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57325. {
  57326. if (getValue() != slider->getValue())
  57327. setValue (slider->getValue());
  57328. }
  57329. END_JUCE_NAMESPACE
  57330. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57331. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57332. BEGIN_JUCE_NAMESPACE
  57333. class TextPropLabel : public Label
  57334. {
  57335. TextPropertyComponent& owner;
  57336. int maxChars;
  57337. bool isMultiline;
  57338. public:
  57339. TextPropLabel (TextPropertyComponent& owner_,
  57340. const int maxChars_, const bool isMultiline_)
  57341. : Label (String::empty, String::empty),
  57342. owner (owner_),
  57343. maxChars (maxChars_),
  57344. isMultiline (isMultiline_)
  57345. {
  57346. setEditable (true, true, false);
  57347. setColour (backgroundColourId, Colours::white);
  57348. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57349. }
  57350. ~TextPropLabel()
  57351. {
  57352. }
  57353. TextEditor* createEditorComponent()
  57354. {
  57355. TextEditor* const textEditor = Label::createEditorComponent();
  57356. textEditor->setInputRestrictions (maxChars);
  57357. if (isMultiline)
  57358. {
  57359. textEditor->setMultiLine (true, true);
  57360. textEditor->setReturnKeyStartsNewLine (true);
  57361. }
  57362. return textEditor;
  57363. }
  57364. void textWasEdited()
  57365. {
  57366. owner.textWasEdited();
  57367. }
  57368. };
  57369. TextPropertyComponent::TextPropertyComponent (const String& name,
  57370. const int maxNumChars,
  57371. const bool isMultiLine)
  57372. : PropertyComponent (name)
  57373. {
  57374. createEditor (maxNumChars, isMultiLine);
  57375. }
  57376. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57377. const String& name,
  57378. const int maxNumChars,
  57379. const bool isMultiLine)
  57380. : PropertyComponent (name)
  57381. {
  57382. createEditor (maxNumChars, isMultiLine);
  57383. textEditor->getTextValue().referTo (valueToControl);
  57384. }
  57385. TextPropertyComponent::~TextPropertyComponent()
  57386. {
  57387. deleteAllChildren();
  57388. }
  57389. void TextPropertyComponent::setText (const String& newText)
  57390. {
  57391. textEditor->setText (newText, true);
  57392. }
  57393. const String TextPropertyComponent::getText() const
  57394. {
  57395. return textEditor->getText();
  57396. }
  57397. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57398. {
  57399. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57400. if (isMultiLine)
  57401. {
  57402. textEditor->setJustificationType (Justification::topLeft);
  57403. preferredHeight = 120;
  57404. }
  57405. }
  57406. void TextPropertyComponent::refresh()
  57407. {
  57408. textEditor->setText (getText(), false);
  57409. }
  57410. void TextPropertyComponent::textWasEdited()
  57411. {
  57412. const String newText (textEditor->getText());
  57413. if (getText() != newText)
  57414. setText (newText);
  57415. }
  57416. END_JUCE_NAMESPACE
  57417. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57418. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57419. BEGIN_JUCE_NAMESPACE
  57420. class SimpleDeviceManagerInputLevelMeter : public Component,
  57421. public Timer
  57422. {
  57423. public:
  57424. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57425. : manager (manager_),
  57426. level (0)
  57427. {
  57428. startTimer (50);
  57429. manager->enableInputLevelMeasurement (true);
  57430. }
  57431. ~SimpleDeviceManagerInputLevelMeter()
  57432. {
  57433. manager->enableInputLevelMeasurement (false);
  57434. }
  57435. void timerCallback()
  57436. {
  57437. const float newLevel = (float) manager->getCurrentInputLevel();
  57438. if (fabsf (level - newLevel) > 0.005f)
  57439. {
  57440. level = newLevel;
  57441. repaint();
  57442. }
  57443. }
  57444. void paint (Graphics& g)
  57445. {
  57446. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57447. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57448. }
  57449. private:
  57450. AudioDeviceManager* const manager;
  57451. float level;
  57452. SimpleDeviceManagerInputLevelMeter (const SimpleDeviceManagerInputLevelMeter&);
  57453. SimpleDeviceManagerInputLevelMeter& operator= (const SimpleDeviceManagerInputLevelMeter&);
  57454. };
  57455. class MidiInputSelectorComponentListBox : public ListBox,
  57456. public ListBoxModel
  57457. {
  57458. public:
  57459. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57460. const String& noItemsMessage_,
  57461. const int minNumber_,
  57462. const int maxNumber_)
  57463. : ListBox (String::empty, 0),
  57464. deviceManager (deviceManager_),
  57465. noItemsMessage (noItemsMessage_),
  57466. minNumber (minNumber_),
  57467. maxNumber (maxNumber_)
  57468. {
  57469. items = MidiInput::getDevices();
  57470. setModel (this);
  57471. setOutlineThickness (1);
  57472. }
  57473. ~MidiInputSelectorComponentListBox()
  57474. {
  57475. }
  57476. int getNumRows()
  57477. {
  57478. return items.size();
  57479. }
  57480. void paintListBoxItem (int row,
  57481. Graphics& g,
  57482. int width, int height,
  57483. bool rowIsSelected)
  57484. {
  57485. if (((unsigned int) row) < (unsigned int) items.size())
  57486. {
  57487. if (rowIsSelected)
  57488. g.fillAll (findColour (TextEditor::highlightColourId)
  57489. .withMultipliedAlpha (0.3f));
  57490. const String item (items [row]);
  57491. bool enabled = deviceManager.isMidiInputEnabled (item);
  57492. const int x = getTickX();
  57493. const float tickW = height * 0.75f;
  57494. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57495. enabled, true, true, false);
  57496. g.setFont (height * 0.6f);
  57497. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57498. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57499. }
  57500. }
  57501. void listBoxItemClicked (int row, const MouseEvent& e)
  57502. {
  57503. selectRow (row);
  57504. if (e.x < getTickX())
  57505. flipEnablement (row);
  57506. }
  57507. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57508. {
  57509. flipEnablement (row);
  57510. }
  57511. void returnKeyPressed (int row)
  57512. {
  57513. flipEnablement (row);
  57514. }
  57515. void paint (Graphics& g)
  57516. {
  57517. ListBox::paint (g);
  57518. if (items.size() == 0)
  57519. {
  57520. g.setColour (Colours::grey);
  57521. g.setFont (13.0f);
  57522. g.drawText (noItemsMessage,
  57523. 0, 0, getWidth(), getHeight() / 2,
  57524. Justification::centred, true);
  57525. }
  57526. }
  57527. int getBestHeight (const int preferredHeight)
  57528. {
  57529. const int extra = getOutlineThickness() * 2;
  57530. return jmax (getRowHeight() * 2 + extra,
  57531. jmin (getRowHeight() * getNumRows() + extra,
  57532. preferredHeight));
  57533. }
  57534. juce_UseDebuggingNewOperator
  57535. private:
  57536. AudioDeviceManager& deviceManager;
  57537. const String noItemsMessage;
  57538. StringArray items;
  57539. int minNumber, maxNumber;
  57540. void flipEnablement (const int row)
  57541. {
  57542. if (((unsigned int) row) < (unsigned int) items.size())
  57543. {
  57544. const String item (items [row]);
  57545. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57546. }
  57547. }
  57548. int getTickX() const
  57549. {
  57550. return getRowHeight() + 5;
  57551. }
  57552. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57553. MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57554. };
  57555. class AudioDeviceSettingsPanel : public Component,
  57556. public ComboBoxListener,
  57557. public ChangeListener,
  57558. public ButtonListener
  57559. {
  57560. public:
  57561. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57562. AudioIODeviceType::DeviceSetupDetails& setup_,
  57563. const bool hideAdvancedOptionsWithButton)
  57564. : type (type_),
  57565. setup (setup_)
  57566. {
  57567. sampleRateDropDown = 0;
  57568. sampleRateLabel = 0;
  57569. bufferSizeDropDown = 0;
  57570. bufferSizeLabel = 0;
  57571. outputDeviceDropDown = 0;
  57572. outputDeviceLabel = 0;
  57573. inputDeviceDropDown = 0;
  57574. inputDeviceLabel = 0;
  57575. testButton = 0;
  57576. inputLevelMeter = 0;
  57577. showUIButton = 0;
  57578. inputChanList = 0;
  57579. outputChanList = 0;
  57580. inputChanLabel = 0;
  57581. outputChanLabel = 0;
  57582. showAdvancedSettingsButton = 0;
  57583. if (hideAdvancedOptionsWithButton)
  57584. {
  57585. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57586. showAdvancedSettingsButton->addButtonListener (this);
  57587. }
  57588. type->scanForDevices();
  57589. setup.manager->addChangeListener (this);
  57590. changeListenerCallback (0);
  57591. }
  57592. ~AudioDeviceSettingsPanel()
  57593. {
  57594. setup.manager->removeChangeListener (this);
  57595. deleteAndZero (outputDeviceLabel);
  57596. deleteAndZero (inputDeviceLabel);
  57597. deleteAndZero (sampleRateLabel);
  57598. deleteAndZero (bufferSizeLabel);
  57599. deleteAndZero (showUIButton);
  57600. deleteAndZero (inputChanLabel);
  57601. deleteAndZero (outputChanLabel);
  57602. deleteAndZero (showAdvancedSettingsButton);
  57603. deleteAllChildren();
  57604. }
  57605. void resized()
  57606. {
  57607. const int lx = proportionOfWidth (0.35f);
  57608. const int w = proportionOfWidth (0.4f);
  57609. const int h = 24;
  57610. const int space = 6;
  57611. const int dh = h + space;
  57612. int y = 0;
  57613. if (outputDeviceDropDown != 0)
  57614. {
  57615. outputDeviceDropDown->setBounds (lx, y, w, h);
  57616. if (testButton != 0)
  57617. testButton->setBounds (proportionOfWidth (0.77f),
  57618. outputDeviceDropDown->getY(),
  57619. proportionOfWidth (0.18f),
  57620. h);
  57621. y += dh;
  57622. }
  57623. if (inputDeviceDropDown != 0)
  57624. {
  57625. inputDeviceDropDown->setBounds (lx, y, w, h);
  57626. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57627. inputDeviceDropDown->getY(),
  57628. proportionOfWidth (0.18f),
  57629. h);
  57630. y += dh;
  57631. }
  57632. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  57633. if (outputChanList != 0)
  57634. {
  57635. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  57636. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57637. y += bh + space;
  57638. }
  57639. if (inputChanList != 0)
  57640. {
  57641. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  57642. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57643. y += bh + space;
  57644. }
  57645. y += space * 2;
  57646. if (showAdvancedSettingsButton != 0)
  57647. {
  57648. showAdvancedSettingsButton->changeWidthToFitText (h);
  57649. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  57650. }
  57651. if (sampleRateDropDown != 0)
  57652. {
  57653. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  57654. || ! showAdvancedSettingsButton->isVisible());
  57655. sampleRateDropDown->setBounds (lx, y, w, h);
  57656. y += dh;
  57657. }
  57658. if (bufferSizeDropDown != 0)
  57659. {
  57660. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  57661. || ! showAdvancedSettingsButton->isVisible());
  57662. bufferSizeDropDown->setBounds (lx, y, w, h);
  57663. y += dh;
  57664. }
  57665. if (showUIButton != 0)
  57666. {
  57667. showUIButton->setVisible (showAdvancedSettingsButton == 0
  57668. || ! showAdvancedSettingsButton->isVisible());
  57669. showUIButton->changeWidthToFitText (h);
  57670. showUIButton->setTopLeftPosition (lx, y);
  57671. }
  57672. }
  57673. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  57674. {
  57675. if (comboBoxThatHasChanged == 0)
  57676. return;
  57677. AudioDeviceManager::AudioDeviceSetup config;
  57678. setup.manager->getAudioDeviceSetup (config);
  57679. String error;
  57680. if (comboBoxThatHasChanged == outputDeviceDropDown
  57681. || comboBoxThatHasChanged == inputDeviceDropDown)
  57682. {
  57683. if (outputDeviceDropDown != 0)
  57684. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57685. : outputDeviceDropDown->getText();
  57686. if (inputDeviceDropDown != 0)
  57687. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57688. : inputDeviceDropDown->getText();
  57689. if (! type->hasSeparateInputsAndOutputs())
  57690. config.inputDeviceName = config.outputDeviceName;
  57691. if (comboBoxThatHasChanged == inputDeviceDropDown)
  57692. config.useDefaultInputChannels = true;
  57693. else
  57694. config.useDefaultOutputChannels = true;
  57695. error = setup.manager->setAudioDeviceSetup (config, true);
  57696. showCorrectDeviceName (inputDeviceDropDown, true);
  57697. showCorrectDeviceName (outputDeviceDropDown, false);
  57698. updateControlPanelButton();
  57699. resized();
  57700. }
  57701. else if (comboBoxThatHasChanged == sampleRateDropDown)
  57702. {
  57703. if (sampleRateDropDown->getSelectedId() > 0)
  57704. {
  57705. config.sampleRate = sampleRateDropDown->getSelectedId();
  57706. error = setup.manager->setAudioDeviceSetup (config, true);
  57707. }
  57708. }
  57709. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  57710. {
  57711. if (bufferSizeDropDown->getSelectedId() > 0)
  57712. {
  57713. config.bufferSize = bufferSizeDropDown->getSelectedId();
  57714. error = setup.manager->setAudioDeviceSetup (config, true);
  57715. }
  57716. }
  57717. if (error.isNotEmpty())
  57718. {
  57719. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  57720. T("Error when trying to open audio device!"),
  57721. error);
  57722. }
  57723. }
  57724. void buttonClicked (Button* button)
  57725. {
  57726. if (button == showAdvancedSettingsButton)
  57727. {
  57728. showAdvancedSettingsButton->setVisible (false);
  57729. resized();
  57730. }
  57731. else if (button == showUIButton)
  57732. {
  57733. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  57734. if (device != 0 && device->showControlPanel())
  57735. {
  57736. setup.manager->closeAudioDevice();
  57737. setup.manager->restartLastAudioDevice();
  57738. getTopLevelComponent()->toFront (true);
  57739. }
  57740. }
  57741. else if (button == testButton && testButton != 0)
  57742. {
  57743. setup.manager->playTestSound();
  57744. }
  57745. }
  57746. void updateControlPanelButton()
  57747. {
  57748. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57749. deleteAndZero (showUIButton);
  57750. if (currentDevice != 0 && currentDevice->hasControlPanel())
  57751. {
  57752. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  57753. TRANS ("opens the device's own control panel")));
  57754. showUIButton->addButtonListener (this);
  57755. }
  57756. resized();
  57757. }
  57758. void changeListenerCallback (void*)
  57759. {
  57760. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57761. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  57762. {
  57763. if (outputDeviceDropDown == 0)
  57764. {
  57765. outputDeviceDropDown = new ComboBox (String::empty);
  57766. outputDeviceDropDown->addListener (this);
  57767. addAndMakeVisible (outputDeviceDropDown);
  57768. outputDeviceLabel = new Label (String::empty,
  57769. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  57770. : TRANS ("device:"));
  57771. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  57772. if (setup.maxNumOutputChannels > 0)
  57773. {
  57774. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  57775. testButton->addButtonListener (this);
  57776. }
  57777. }
  57778. addNamesToDeviceBox (*outputDeviceDropDown, false);
  57779. }
  57780. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  57781. {
  57782. if (inputDeviceDropDown == 0)
  57783. {
  57784. inputDeviceDropDown = new ComboBox (String::empty);
  57785. inputDeviceDropDown->addListener (this);
  57786. addAndMakeVisible (inputDeviceDropDown);
  57787. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  57788. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  57789. addAndMakeVisible (inputLevelMeter
  57790. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  57791. }
  57792. addNamesToDeviceBox (*inputDeviceDropDown, true);
  57793. }
  57794. updateControlPanelButton();
  57795. showCorrectDeviceName (inputDeviceDropDown, true);
  57796. showCorrectDeviceName (outputDeviceDropDown, false);
  57797. if (currentDevice != 0)
  57798. {
  57799. if (setup.maxNumOutputChannels > 0
  57800. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  57801. {
  57802. if (outputChanList == 0)
  57803. {
  57804. addAndMakeVisible (outputChanList
  57805. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  57806. TRANS ("(no audio output channels found)")));
  57807. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  57808. outputChanLabel->attachToComponent (outputChanList, true);
  57809. }
  57810. outputChanList->refresh();
  57811. }
  57812. else
  57813. {
  57814. deleteAndZero (outputChanLabel);
  57815. deleteAndZero (outputChanList);
  57816. }
  57817. if (setup.maxNumInputChannels > 0
  57818. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  57819. {
  57820. if (inputChanList == 0)
  57821. {
  57822. addAndMakeVisible (inputChanList
  57823. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  57824. TRANS ("(no audio input channels found)")));
  57825. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  57826. inputChanLabel->attachToComponent (inputChanList, true);
  57827. }
  57828. inputChanList->refresh();
  57829. }
  57830. else
  57831. {
  57832. deleteAndZero (inputChanLabel);
  57833. deleteAndZero (inputChanList);
  57834. }
  57835. // sample rate..
  57836. {
  57837. if (sampleRateDropDown == 0)
  57838. {
  57839. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  57840. sampleRateDropDown->addListener (this);
  57841. delete sampleRateLabel;
  57842. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  57843. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  57844. }
  57845. else
  57846. {
  57847. sampleRateDropDown->clear();
  57848. sampleRateDropDown->removeListener (this);
  57849. }
  57850. const int numRates = currentDevice->getNumSampleRates();
  57851. for (int i = 0; i < numRates; ++i)
  57852. {
  57853. const int rate = roundToInt (currentDevice->getSampleRate (i));
  57854. sampleRateDropDown->addItem (String (rate) + T(" Hz"), rate);
  57855. }
  57856. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  57857. sampleRateDropDown->addListener (this);
  57858. }
  57859. // buffer size
  57860. {
  57861. if (bufferSizeDropDown == 0)
  57862. {
  57863. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  57864. bufferSizeDropDown->addListener (this);
  57865. delete bufferSizeLabel;
  57866. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  57867. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  57868. }
  57869. else
  57870. {
  57871. bufferSizeDropDown->clear();
  57872. }
  57873. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  57874. double currentRate = currentDevice->getCurrentSampleRate();
  57875. if (currentRate == 0)
  57876. currentRate = 48000.0;
  57877. for (int i = 0; i < numBufferSizes; ++i)
  57878. {
  57879. const int bs = currentDevice->getBufferSizeSamples (i);
  57880. bufferSizeDropDown->addItem (String (bs)
  57881. + T(" samples (")
  57882. + String (bs * 1000.0 / currentRate, 1)
  57883. + T(" ms)"),
  57884. bs);
  57885. }
  57886. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  57887. }
  57888. }
  57889. else
  57890. {
  57891. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  57892. deleteAndZero (sampleRateLabel);
  57893. deleteAndZero (bufferSizeLabel);
  57894. deleteAndZero (sampleRateDropDown);
  57895. deleteAndZero (bufferSizeDropDown);
  57896. if (outputDeviceDropDown != 0)
  57897. outputDeviceDropDown->setSelectedId (-1, true);
  57898. if (inputDeviceDropDown != 0)
  57899. inputDeviceDropDown->setSelectedId (-1, true);
  57900. }
  57901. resized();
  57902. setSize (getWidth(), getLowestY() + 4);
  57903. }
  57904. private:
  57905. AudioIODeviceType* const type;
  57906. const AudioIODeviceType::DeviceSetupDetails setup;
  57907. ComboBox* outputDeviceDropDown;
  57908. ComboBox* inputDeviceDropDown;
  57909. ComboBox* sampleRateDropDown;
  57910. ComboBox* bufferSizeDropDown;
  57911. Label* outputDeviceLabel;
  57912. Label* inputDeviceLabel;
  57913. Label* sampleRateLabel;
  57914. Label* bufferSizeLabel;
  57915. Label* inputChanLabel;
  57916. Label* outputChanLabel;
  57917. TextButton* testButton;
  57918. Component* inputLevelMeter;
  57919. TextButton* showUIButton;
  57920. TextButton* showAdvancedSettingsButton;
  57921. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  57922. {
  57923. if (box != 0)
  57924. {
  57925. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  57926. const int index = type->getIndexOfDevice (currentDevice, isInput);
  57927. box->setSelectedId (index + 1, true);
  57928. if (testButton != 0 && ! isInput)
  57929. testButton->setEnabled (index >= 0);
  57930. }
  57931. }
  57932. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  57933. {
  57934. const StringArray devs (type->getDeviceNames (isInputs));
  57935. combo.clear (true);
  57936. for (int i = 0; i < devs.size(); ++i)
  57937. combo.addItem (devs[i], i + 1);
  57938. combo.addItem (TRANS("<< none >>"), -1);
  57939. combo.setSelectedId (-1, true);
  57940. }
  57941. int getLowestY() const
  57942. {
  57943. int y = 0;
  57944. for (int i = getNumChildComponents(); --i >= 0;)
  57945. y = jmax (y, getChildComponent (i)->getBottom());
  57946. return y;
  57947. }
  57948. public:
  57949. class ChannelSelectorListBox : public ListBox,
  57950. public ListBoxModel
  57951. {
  57952. public:
  57953. enum BoxType
  57954. {
  57955. audioInputType,
  57956. audioOutputType
  57957. };
  57958. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  57959. const BoxType type_,
  57960. const String& noItemsMessage_)
  57961. : ListBox (String::empty, 0),
  57962. setup (setup_),
  57963. type (type_),
  57964. noItemsMessage (noItemsMessage_)
  57965. {
  57966. refresh();
  57967. setModel (this);
  57968. setOutlineThickness (1);
  57969. }
  57970. ~ChannelSelectorListBox()
  57971. {
  57972. }
  57973. void refresh()
  57974. {
  57975. items.clear();
  57976. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57977. if (currentDevice != 0)
  57978. {
  57979. if (type == audioInputType)
  57980. items = currentDevice->getInputChannelNames();
  57981. else if (type == audioOutputType)
  57982. items = currentDevice->getOutputChannelNames();
  57983. if (setup.useStereoPairs)
  57984. {
  57985. StringArray pairs;
  57986. for (int i = 0; i < items.size(); i += 2)
  57987. {
  57988. String name (items[i]);
  57989. String name2 (items[i + 1]);
  57990. String commonBit;
  57991. for (int j = 0; j < name.length(); ++j)
  57992. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  57993. commonBit = name.substring (0, j);
  57994. pairs.add (name.trim()
  57995. + " + "
  57996. + name2.substring (commonBit.length()).trim());
  57997. }
  57998. items = pairs;
  57999. }
  58000. }
  58001. updateContent();
  58002. repaint();
  58003. }
  58004. int getNumRows()
  58005. {
  58006. return items.size();
  58007. }
  58008. void paintListBoxItem (int row,
  58009. Graphics& g,
  58010. int width, int height,
  58011. bool rowIsSelected)
  58012. {
  58013. if (((unsigned int) row) < (unsigned int) items.size())
  58014. {
  58015. if (rowIsSelected)
  58016. g.fillAll (findColour (TextEditor::highlightColourId)
  58017. .withMultipliedAlpha (0.3f));
  58018. const String item (items [row]);
  58019. bool enabled = false;
  58020. AudioDeviceManager::AudioDeviceSetup config;
  58021. setup.manager->getAudioDeviceSetup (config);
  58022. if (setup.useStereoPairs)
  58023. {
  58024. if (type == audioInputType)
  58025. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58026. else if (type == audioOutputType)
  58027. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58028. }
  58029. else
  58030. {
  58031. if (type == audioInputType)
  58032. enabled = config.inputChannels [row];
  58033. else if (type == audioOutputType)
  58034. enabled = config.outputChannels [row];
  58035. }
  58036. const int x = getTickX();
  58037. const float tickW = height * 0.75f;
  58038. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58039. enabled, true, true, false);
  58040. g.setFont (height * 0.6f);
  58041. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58042. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58043. }
  58044. }
  58045. void listBoxItemClicked (int row, const MouseEvent& e)
  58046. {
  58047. selectRow (row);
  58048. if (e.x < getTickX())
  58049. flipEnablement (row);
  58050. }
  58051. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58052. {
  58053. flipEnablement (row);
  58054. }
  58055. void returnKeyPressed (int row)
  58056. {
  58057. flipEnablement (row);
  58058. }
  58059. void paint (Graphics& g)
  58060. {
  58061. ListBox::paint (g);
  58062. if (items.size() == 0)
  58063. {
  58064. g.setColour (Colours::grey);
  58065. g.setFont (13.0f);
  58066. g.drawText (noItemsMessage,
  58067. 0, 0, getWidth(), getHeight() / 2,
  58068. Justification::centred, true);
  58069. }
  58070. }
  58071. int getBestHeight (int maxHeight)
  58072. {
  58073. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58074. getNumRows())
  58075. + getOutlineThickness() * 2;
  58076. }
  58077. juce_UseDebuggingNewOperator
  58078. private:
  58079. const AudioIODeviceType::DeviceSetupDetails setup;
  58080. const BoxType type;
  58081. const String noItemsMessage;
  58082. StringArray items;
  58083. void flipEnablement (const int row)
  58084. {
  58085. jassert (type == audioInputType || type == audioOutputType);
  58086. if (((unsigned int) row) < (unsigned int) items.size())
  58087. {
  58088. AudioDeviceManager::AudioDeviceSetup config;
  58089. setup.manager->getAudioDeviceSetup (config);
  58090. if (setup.useStereoPairs)
  58091. {
  58092. BigInteger bits;
  58093. BigInteger& original = (type == audioInputType ? config.inputChannels
  58094. : config.outputChannels);
  58095. int i;
  58096. for (i = 0; i < 256; i += 2)
  58097. bits.setBit (i / 2, original [i] || original [i + 1]);
  58098. if (type == audioInputType)
  58099. {
  58100. config.useDefaultInputChannels = false;
  58101. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58102. }
  58103. else
  58104. {
  58105. config.useDefaultOutputChannels = false;
  58106. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58107. }
  58108. for (i = 0; i < 256; ++i)
  58109. original.setBit (i, bits [i / 2]);
  58110. }
  58111. else
  58112. {
  58113. if (type == audioInputType)
  58114. {
  58115. config.useDefaultInputChannels = false;
  58116. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58117. }
  58118. else
  58119. {
  58120. config.useDefaultOutputChannels = false;
  58121. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58122. }
  58123. }
  58124. String error (setup.manager->setAudioDeviceSetup (config, true));
  58125. if (! error.isEmpty())
  58126. {
  58127. //xxx
  58128. }
  58129. }
  58130. }
  58131. static void flipBit (BigInteger& chans, int index, int minNumber, int maxNumber)
  58132. {
  58133. const int numActive = chans.countNumberOfSetBits();
  58134. if (chans [index])
  58135. {
  58136. if (numActive > minNumber)
  58137. chans.setBit (index, false);
  58138. }
  58139. else
  58140. {
  58141. if (numActive >= maxNumber)
  58142. {
  58143. const int firstActiveChan = chans.findNextSetBit();
  58144. chans.setBit (index > firstActiveChan
  58145. ? firstActiveChan : chans.getHighestBit(),
  58146. false);
  58147. }
  58148. chans.setBit (index, true);
  58149. }
  58150. }
  58151. int getTickX() const
  58152. {
  58153. return getRowHeight() + 5;
  58154. }
  58155. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58156. ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58157. };
  58158. private:
  58159. ChannelSelectorListBox* inputChanList;
  58160. ChannelSelectorListBox* outputChanList;
  58161. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58162. AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58163. };
  58164. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58165. const int minInputChannels_,
  58166. const int maxInputChannels_,
  58167. const int minOutputChannels_,
  58168. const int maxOutputChannels_,
  58169. const bool showMidiInputOptions,
  58170. const bool showMidiOutputSelector,
  58171. const bool showChannelsAsStereoPairs_,
  58172. const bool hideAdvancedOptionsWithButton_)
  58173. : deviceManager (deviceManager_),
  58174. deviceTypeDropDown (0),
  58175. deviceTypeDropDownLabel (0),
  58176. audioDeviceSettingsComp (0),
  58177. minOutputChannels (minOutputChannels_),
  58178. maxOutputChannels (maxOutputChannels_),
  58179. minInputChannels (minInputChannels_),
  58180. maxInputChannels (maxInputChannels_),
  58181. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58182. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58183. {
  58184. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58185. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58186. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58187. {
  58188. deviceTypeDropDown = new ComboBox (String::empty);
  58189. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58190. {
  58191. deviceTypeDropDown
  58192. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58193. i + 1);
  58194. }
  58195. addAndMakeVisible (deviceTypeDropDown);
  58196. deviceTypeDropDown->addListener (this);
  58197. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58198. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58199. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58200. }
  58201. if (showMidiInputOptions)
  58202. {
  58203. addAndMakeVisible (midiInputsList
  58204. = new MidiInputSelectorComponentListBox (deviceManager,
  58205. TRANS("(no midi inputs available)"),
  58206. 0, 0));
  58207. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58208. midiInputsLabel->setJustificationType (Justification::topRight);
  58209. midiInputsLabel->attachToComponent (midiInputsList, true);
  58210. }
  58211. else
  58212. {
  58213. midiInputsList = 0;
  58214. midiInputsLabel = 0;
  58215. }
  58216. if (showMidiOutputSelector)
  58217. {
  58218. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58219. midiOutputSelector->addListener (this);
  58220. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58221. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58222. }
  58223. else
  58224. {
  58225. midiOutputSelector = 0;
  58226. midiOutputLabel = 0;
  58227. }
  58228. deviceManager_.addChangeListener (this);
  58229. changeListenerCallback (0);
  58230. }
  58231. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58232. {
  58233. deviceManager.removeChangeListener (this);
  58234. deleteAllChildren();
  58235. }
  58236. void AudioDeviceSelectorComponent::resized()
  58237. {
  58238. const int lx = proportionOfWidth (0.35f);
  58239. const int w = proportionOfWidth (0.4f);
  58240. const int h = 24;
  58241. const int space = 6;
  58242. const int dh = h + space;
  58243. int y = 15;
  58244. if (deviceTypeDropDown != 0)
  58245. {
  58246. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58247. y += dh + space * 2;
  58248. }
  58249. if (audioDeviceSettingsComp != 0)
  58250. {
  58251. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58252. y += audioDeviceSettingsComp->getHeight() + space;
  58253. }
  58254. if (midiInputsList != 0)
  58255. {
  58256. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58257. midiInputsList->setBounds (lx, y, w, bh);
  58258. y += bh + space;
  58259. }
  58260. if (midiOutputSelector != 0)
  58261. midiOutputSelector->setBounds (lx, y, w, h);
  58262. }
  58263. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58264. {
  58265. if (child == audioDeviceSettingsComp)
  58266. resized();
  58267. }
  58268. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58269. {
  58270. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58271. if (device != 0 && device->hasControlPanel())
  58272. {
  58273. if (device->showControlPanel())
  58274. deviceManager.restartLastAudioDevice();
  58275. getTopLevelComponent()->toFront (true);
  58276. }
  58277. }
  58278. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58279. {
  58280. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58281. {
  58282. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58283. if (type != 0)
  58284. {
  58285. deleteAndZero (audioDeviceSettingsComp);
  58286. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58287. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58288. }
  58289. }
  58290. else if (comboBoxThatHasChanged == midiOutputSelector)
  58291. {
  58292. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58293. }
  58294. }
  58295. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58296. {
  58297. if (deviceTypeDropDown != 0)
  58298. {
  58299. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58300. }
  58301. if (audioDeviceSettingsComp == 0
  58302. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58303. {
  58304. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58305. deleteAndZero (audioDeviceSettingsComp);
  58306. AudioIODeviceType* const type
  58307. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58308. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58309. if (type != 0)
  58310. {
  58311. AudioIODeviceType::DeviceSetupDetails details;
  58312. details.manager = &deviceManager;
  58313. details.minNumInputChannels = minInputChannels;
  58314. details.maxNumInputChannels = maxInputChannels;
  58315. details.minNumOutputChannels = minOutputChannels;
  58316. details.maxNumOutputChannels = maxOutputChannels;
  58317. details.useStereoPairs = showChannelsAsStereoPairs;
  58318. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58319. if (audioDeviceSettingsComp != 0)
  58320. {
  58321. addAndMakeVisible (audioDeviceSettingsComp);
  58322. audioDeviceSettingsComp->resized();
  58323. }
  58324. }
  58325. }
  58326. if (midiInputsList != 0)
  58327. {
  58328. midiInputsList->updateContent();
  58329. midiInputsList->repaint();
  58330. }
  58331. if (midiOutputSelector != 0)
  58332. {
  58333. midiOutputSelector->clear();
  58334. const StringArray midiOuts (MidiOutput::getDevices());
  58335. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58336. midiOutputSelector->addSeparator();
  58337. for (int i = 0; i < midiOuts.size(); ++i)
  58338. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58339. int current = -1;
  58340. if (deviceManager.getDefaultMidiOutput() != 0)
  58341. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58342. midiOutputSelector->setSelectedId (current, true);
  58343. }
  58344. resized();
  58345. }
  58346. END_JUCE_NAMESPACE
  58347. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58348. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58349. BEGIN_JUCE_NAMESPACE
  58350. BubbleComponent::BubbleComponent()
  58351. : side (0),
  58352. allowablePlacements (above | below | left | right),
  58353. arrowTipX (0.0f),
  58354. arrowTipY (0.0f)
  58355. {
  58356. setInterceptsMouseClicks (false, false);
  58357. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58358. setComponentEffect (&shadow);
  58359. }
  58360. BubbleComponent::~BubbleComponent()
  58361. {
  58362. }
  58363. void BubbleComponent::paint (Graphics& g)
  58364. {
  58365. int x = content.getX();
  58366. int y = content.getY();
  58367. int w = content.getWidth();
  58368. int h = content.getHeight();
  58369. int cw, ch;
  58370. getContentSize (cw, ch);
  58371. if (side == 3)
  58372. x += w - cw;
  58373. else if (side != 1)
  58374. x += (w - cw) / 2;
  58375. w = cw;
  58376. if (side == 2)
  58377. y += h - ch;
  58378. else if (side != 0)
  58379. y += (h - ch) / 2;
  58380. h = ch;
  58381. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58382. (float) x, (float) y,
  58383. (float) w, (float) h);
  58384. const int cx = x + (w - cw) / 2;
  58385. const int cy = y + (h - ch) / 2;
  58386. const int indent = 3;
  58387. g.setOrigin (cx + indent, cy + indent);
  58388. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58389. paintContent (g, cw - indent * 2, ch - indent * 2);
  58390. }
  58391. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58392. {
  58393. allowablePlacements = newPlacement;
  58394. }
  58395. void BubbleComponent::setPosition (Component* componentToPointTo)
  58396. {
  58397. jassert (componentToPointTo->isValidComponent());
  58398. Point<int> pos;
  58399. if (getParentComponent() != 0)
  58400. pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos);
  58401. else
  58402. pos = componentToPointTo->relativePositionToGlobal (pos);
  58403. setPosition (Rectangle<int> (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58404. }
  58405. void BubbleComponent::setPosition (const int arrowTipX_,
  58406. const int arrowTipY_)
  58407. {
  58408. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58409. }
  58410. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58411. {
  58412. Rectangle<int> availableSpace;
  58413. if (getParentComponent() != 0)
  58414. {
  58415. availableSpace.setSize (getParentComponent()->getWidth(),
  58416. getParentComponent()->getHeight());
  58417. }
  58418. else
  58419. {
  58420. availableSpace = getParentMonitorArea();
  58421. }
  58422. int x = 0;
  58423. int y = 0;
  58424. int w = 150;
  58425. int h = 30;
  58426. getContentSize (w, h);
  58427. w += 30;
  58428. h += 30;
  58429. const float edgeIndent = 2.0f;
  58430. const int arrowLength = jmin (10, h / 3, w / 3);
  58431. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58432. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58433. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58434. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58435. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58436. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58437. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58438. {
  58439. spaceLeft = spaceRight = 0;
  58440. }
  58441. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58442. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58443. {
  58444. spaceAbove = spaceBelow = 0;
  58445. }
  58446. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58447. {
  58448. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58449. arrowTipX = w * 0.5f;
  58450. content.setSize (w, h - arrowLength);
  58451. if (spaceAbove >= spaceBelow)
  58452. {
  58453. // above
  58454. y = rectangleToPointTo.getY() - h;
  58455. content.setPosition (0, 0);
  58456. arrowTipY = h - edgeIndent;
  58457. side = 2;
  58458. }
  58459. else
  58460. {
  58461. // below
  58462. y = rectangleToPointTo.getBottom();
  58463. content.setPosition (0, arrowLength);
  58464. arrowTipY = edgeIndent;
  58465. side = 0;
  58466. }
  58467. }
  58468. else
  58469. {
  58470. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58471. arrowTipY = h * 0.5f;
  58472. content.setSize (w - arrowLength, h);
  58473. if (spaceLeft > spaceRight)
  58474. {
  58475. // on the left
  58476. x = rectangleToPointTo.getX() - w;
  58477. content.setPosition (0, 0);
  58478. arrowTipX = w - edgeIndent;
  58479. side = 3;
  58480. }
  58481. else
  58482. {
  58483. // on the right
  58484. x = rectangleToPointTo.getRight();
  58485. content.setPosition (arrowLength, 0);
  58486. arrowTipX = edgeIndent;
  58487. side = 1;
  58488. }
  58489. }
  58490. setBounds (x, y, w, h);
  58491. }
  58492. END_JUCE_NAMESPACE
  58493. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58494. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58495. BEGIN_JUCE_NAMESPACE
  58496. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58497. : fadeOutLength (fadeOutLengthMs),
  58498. deleteAfterUse (false)
  58499. {
  58500. }
  58501. BubbleMessageComponent::~BubbleMessageComponent()
  58502. {
  58503. fadeOutComponent (fadeOutLength);
  58504. }
  58505. void BubbleMessageComponent::showAt (int x, int y,
  58506. const String& text,
  58507. const int numMillisecondsBeforeRemoving,
  58508. const bool removeWhenMouseClicked,
  58509. const bool deleteSelfAfterUse)
  58510. {
  58511. textLayout.clear();
  58512. textLayout.setText (text, Font (14.0f));
  58513. textLayout.layout (256, Justification::centredLeft, true);
  58514. setPosition (x, y);
  58515. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58516. }
  58517. void BubbleMessageComponent::showAt (Component* const component,
  58518. const String& text,
  58519. const int numMillisecondsBeforeRemoving,
  58520. const bool removeWhenMouseClicked,
  58521. const bool deleteSelfAfterUse)
  58522. {
  58523. textLayout.clear();
  58524. textLayout.setText (text, Font (14.0f));
  58525. textLayout.layout (256, Justification::centredLeft, true);
  58526. setPosition (component);
  58527. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58528. }
  58529. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58530. const bool removeWhenMouseClicked,
  58531. const bool deleteSelfAfterUse)
  58532. {
  58533. setVisible (true);
  58534. deleteAfterUse = deleteSelfAfterUse;
  58535. if (numMillisecondsBeforeRemoving > 0)
  58536. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58537. else
  58538. expiryTime = 0;
  58539. startTimer (77);
  58540. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58541. if (! (removeWhenMouseClicked && isShowing()))
  58542. mouseClickCounter += 0xfffff;
  58543. repaint();
  58544. }
  58545. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58546. {
  58547. w = textLayout.getWidth() + 16;
  58548. h = textLayout.getHeight() + 16;
  58549. }
  58550. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58551. {
  58552. g.setColour (findColour (TooltipWindow::textColourId));
  58553. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58554. }
  58555. void BubbleMessageComponent::timerCallback()
  58556. {
  58557. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58558. {
  58559. stopTimer();
  58560. setVisible (false);
  58561. if (deleteAfterUse)
  58562. delete this;
  58563. }
  58564. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58565. {
  58566. stopTimer();
  58567. fadeOutComponent (fadeOutLength);
  58568. if (deleteAfterUse)
  58569. delete this;
  58570. }
  58571. }
  58572. END_JUCE_NAMESPACE
  58573. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58574. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58575. BEGIN_JUCE_NAMESPACE
  58576. static const int swatchesPerRow = 8;
  58577. static const int swatchHeight = 22;
  58578. class ColourComponentSlider : public Slider
  58579. {
  58580. public:
  58581. ColourComponentSlider (const String& name)
  58582. : Slider (name)
  58583. {
  58584. setRange (0.0, 255.0, 1.0);
  58585. }
  58586. ~ColourComponentSlider()
  58587. {
  58588. }
  58589. const String getTextFromValue (double value)
  58590. {
  58591. return String::toHexString ((int) value).toUpperCase().paddedLeft ('0', 2);
  58592. }
  58593. double getValueFromText (const String& text)
  58594. {
  58595. return (double) text.getHexValue32();
  58596. }
  58597. private:
  58598. ColourComponentSlider (const ColourComponentSlider&);
  58599. ColourComponentSlider& operator= (const ColourComponentSlider&);
  58600. };
  58601. class ColourSpaceMarker : public Component
  58602. {
  58603. public:
  58604. ColourSpaceMarker()
  58605. {
  58606. setInterceptsMouseClicks (false, false);
  58607. }
  58608. ~ColourSpaceMarker()
  58609. {
  58610. }
  58611. void paint (Graphics& g)
  58612. {
  58613. g.setColour (Colour::greyLevel (0.1f));
  58614. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58615. g.setColour (Colour::greyLevel (0.9f));
  58616. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58617. }
  58618. private:
  58619. ColourSpaceMarker (const ColourSpaceMarker&);
  58620. ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58621. };
  58622. class ColourSpaceView : public Component
  58623. {
  58624. ColourSelector* const owner;
  58625. float& h;
  58626. float& s;
  58627. float& v;
  58628. float lastHue;
  58629. ColourSpaceMarker* marker;
  58630. const int edge;
  58631. public:
  58632. ColourSpaceView (ColourSelector* owner_,
  58633. float& h_, float& s_, float& v_,
  58634. const int edgeSize)
  58635. : owner (owner_),
  58636. h (h_), s (s_), v (v_),
  58637. lastHue (0.0f),
  58638. edge (edgeSize)
  58639. {
  58640. addAndMakeVisible (marker = new ColourSpaceMarker());
  58641. setMouseCursor (MouseCursor::CrosshairCursor);
  58642. }
  58643. ~ColourSpaceView()
  58644. {
  58645. deleteAllChildren();
  58646. }
  58647. void paint (Graphics& g)
  58648. {
  58649. if (colours == 0)
  58650. {
  58651. const int width = getWidth() / 2;
  58652. const int height = getHeight() / 2;
  58653. colours = new Image (Image::RGB, width, height, false);
  58654. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  58655. for (int y = 0; y < height; ++y)
  58656. {
  58657. const float v = 1.0f - y / (float) height;
  58658. for (int x = 0; x < width; ++x)
  58659. {
  58660. const float s = x / (float) width;
  58661. const Colour col (h, s, v, 1.0f);
  58662. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  58663. pix->set (col.getPixelARGB());
  58664. }
  58665. }
  58666. }
  58667. g.setOpacity (1.0f);
  58668. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  58669. 0, 0, colours->getWidth(), colours->getHeight());
  58670. }
  58671. void mouseDown (const MouseEvent& e)
  58672. {
  58673. mouseDrag (e);
  58674. }
  58675. void mouseDrag (const MouseEvent& e)
  58676. {
  58677. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  58678. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  58679. owner->setSV (s, v);
  58680. }
  58681. void updateIfNeeded()
  58682. {
  58683. if (lastHue != h)
  58684. {
  58685. lastHue = h;
  58686. colours = 0;
  58687. repaint();
  58688. }
  58689. updateMarker();
  58690. }
  58691. void resized()
  58692. {
  58693. colours = 0;
  58694. updateMarker();
  58695. }
  58696. private:
  58697. ScopedPointer <Image> colours;
  58698. void updateMarker() const throw()
  58699. {
  58700. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  58701. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  58702. edge * 2, edge * 2);
  58703. }
  58704. ColourSpaceView (const ColourSpaceView&);
  58705. ColourSpaceView& operator= (const ColourSpaceView&);
  58706. };
  58707. class HueSelectorMarker : public Component
  58708. {
  58709. public:
  58710. HueSelectorMarker()
  58711. {
  58712. setInterceptsMouseClicks (false, false);
  58713. }
  58714. ~HueSelectorMarker()
  58715. {
  58716. }
  58717. void paint (Graphics& g)
  58718. {
  58719. Path p;
  58720. p.addTriangle (1.0f, 1.0f,
  58721. getWidth() * 0.3f, getHeight() * 0.5f,
  58722. 1.0f, getHeight() - 1.0f);
  58723. p.addTriangle (getWidth() - 1.0f, 1.0f,
  58724. getWidth() * 0.7f, getHeight() * 0.5f,
  58725. getWidth() - 1.0f, getHeight() - 1.0f);
  58726. g.setColour (Colours::white.withAlpha (0.75f));
  58727. g.fillPath (p);
  58728. g.setColour (Colours::black.withAlpha (0.75f));
  58729. g.strokePath (p, PathStrokeType (1.2f));
  58730. }
  58731. private:
  58732. HueSelectorMarker (const HueSelectorMarker&);
  58733. HueSelectorMarker& operator= (const HueSelectorMarker&);
  58734. };
  58735. class HueSelectorComp : public Component
  58736. {
  58737. public:
  58738. HueSelectorComp (ColourSelector* owner_,
  58739. float& h_, float& s_, float& v_,
  58740. const int edgeSize)
  58741. : owner (owner_),
  58742. h (h_), s (s_), v (v_),
  58743. lastHue (0.0f),
  58744. edge (edgeSize)
  58745. {
  58746. addAndMakeVisible (marker = new HueSelectorMarker());
  58747. }
  58748. ~HueSelectorComp()
  58749. {
  58750. deleteAllChildren();
  58751. }
  58752. void paint (Graphics& g)
  58753. {
  58754. const float yScale = 1.0f / (getHeight() - edge * 2);
  58755. const Rectangle<int> clip (g.getClipBounds());
  58756. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  58757. {
  58758. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  58759. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  58760. }
  58761. }
  58762. void resized()
  58763. {
  58764. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  58765. getWidth(), edge * 2);
  58766. }
  58767. void mouseDown (const MouseEvent& e)
  58768. {
  58769. mouseDrag (e);
  58770. }
  58771. void mouseDrag (const MouseEvent& e)
  58772. {
  58773. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  58774. owner->setHue (hue);
  58775. }
  58776. void updateIfNeeded()
  58777. {
  58778. resized();
  58779. }
  58780. private:
  58781. ColourSelector* const owner;
  58782. float& h;
  58783. float& s;
  58784. float& v;
  58785. float lastHue;
  58786. HueSelectorMarker* marker;
  58787. const int edge;
  58788. HueSelectorComp (const HueSelectorComp&);
  58789. HueSelectorComp& operator= (const HueSelectorComp&);
  58790. };
  58791. class ColourSelector::SwatchComponent : public Component
  58792. {
  58793. public:
  58794. SwatchComponent (ColourSelector* owner_, int index_)
  58795. : owner (owner_),
  58796. index (index_)
  58797. {
  58798. }
  58799. ~SwatchComponent()
  58800. {
  58801. }
  58802. void paint (Graphics& g)
  58803. {
  58804. const Colour colour (owner->getSwatchColour (index));
  58805. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  58806. 6, 6,
  58807. Colour (0xffdddddd).overlaidWith (colour),
  58808. Colour (0xffffffff).overlaidWith (colour));
  58809. }
  58810. void mouseDown (const MouseEvent&)
  58811. {
  58812. PopupMenu m;
  58813. m.addItem (1, TRANS("Use this swatch as the current colour"));
  58814. m.addSeparator();
  58815. m.addItem (2, TRANS("Set this swatch to the current colour"));
  58816. const int r = m.showAt (this);
  58817. if (r == 1)
  58818. {
  58819. owner->setCurrentColour (owner->getSwatchColour (index));
  58820. }
  58821. else if (r == 2)
  58822. {
  58823. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  58824. {
  58825. owner->setSwatchColour (index, owner->getCurrentColour());
  58826. repaint();
  58827. }
  58828. }
  58829. }
  58830. private:
  58831. ColourSelector* const owner;
  58832. const int index;
  58833. SwatchComponent (const SwatchComponent&);
  58834. SwatchComponent& operator= (const SwatchComponent&);
  58835. };
  58836. ColourSelector::ColourSelector (const int flags_,
  58837. const int edgeGap_,
  58838. const int gapAroundColourSpaceComponent)
  58839. : colour (Colours::white),
  58840. flags (flags_),
  58841. topSpace (0),
  58842. edgeGap (edgeGap_)
  58843. {
  58844. // not much point having a selector with no components in it!
  58845. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  58846. updateHSV();
  58847. if ((flags & showSliders) != 0)
  58848. {
  58849. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  58850. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  58851. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  58852. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  58853. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  58854. for (int i = 4; --i >= 0;)
  58855. sliders[i]->addListener (this);
  58856. }
  58857. else
  58858. {
  58859. zeromem (sliders, sizeof (sliders));
  58860. }
  58861. if ((flags & showColourspace) != 0)
  58862. {
  58863. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  58864. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  58865. }
  58866. else
  58867. {
  58868. colourSpace = 0;
  58869. hueSelector = 0;
  58870. }
  58871. update();
  58872. }
  58873. ColourSelector::~ColourSelector()
  58874. {
  58875. dispatchPendingMessages();
  58876. swatchComponents.clear();
  58877. deleteAllChildren();
  58878. }
  58879. const Colour ColourSelector::getCurrentColour() const
  58880. {
  58881. return ((flags & showAlphaChannel) != 0) ? colour
  58882. : colour.withAlpha ((uint8) 0xff);
  58883. }
  58884. void ColourSelector::setCurrentColour (const Colour& c)
  58885. {
  58886. if (c != colour)
  58887. {
  58888. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  58889. updateHSV();
  58890. update();
  58891. }
  58892. }
  58893. void ColourSelector::setHue (float newH)
  58894. {
  58895. newH = jlimit (0.0f, 1.0f, newH);
  58896. if (h != newH)
  58897. {
  58898. h = newH;
  58899. colour = Colour (h, s, v, colour.getFloatAlpha());
  58900. update();
  58901. }
  58902. }
  58903. void ColourSelector::setSV (float newS, float newV)
  58904. {
  58905. newS = jlimit (0.0f, 1.0f, newS);
  58906. newV = jlimit (0.0f, 1.0f, newV);
  58907. if (s != newS || v != newV)
  58908. {
  58909. s = newS;
  58910. v = newV;
  58911. colour = Colour (h, s, v, colour.getFloatAlpha());
  58912. update();
  58913. }
  58914. }
  58915. void ColourSelector::updateHSV()
  58916. {
  58917. colour.getHSB (h, s, v);
  58918. }
  58919. void ColourSelector::update()
  58920. {
  58921. if (sliders[0] != 0)
  58922. {
  58923. sliders[0]->setValue ((int) colour.getRed());
  58924. sliders[1]->setValue ((int) colour.getGreen());
  58925. sliders[2]->setValue ((int) colour.getBlue());
  58926. sliders[3]->setValue ((int) colour.getAlpha());
  58927. }
  58928. if (colourSpace != 0)
  58929. {
  58930. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  58931. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  58932. }
  58933. if ((flags & showColourAtTop) != 0)
  58934. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  58935. sendChangeMessage (this);
  58936. }
  58937. void ColourSelector::paint (Graphics& g)
  58938. {
  58939. g.fillAll (findColour (backgroundColourId));
  58940. if ((flags & showColourAtTop) != 0)
  58941. {
  58942. const Colour colour (getCurrentColour());
  58943. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  58944. 10, 10,
  58945. Colour (0xffdddddd).overlaidWith (colour),
  58946. Colour (0xffffffff).overlaidWith (colour));
  58947. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  58948. g.setFont (14.0f, true);
  58949. g.drawText (colour.toDisplayString ((flags & showAlphaChannel) != 0),
  58950. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  58951. Justification::centred, false);
  58952. }
  58953. if ((flags & showSliders) != 0)
  58954. {
  58955. g.setColour (findColour (labelTextColourId));
  58956. g.setFont (11.0f);
  58957. for (int i = 4; --i >= 0;)
  58958. {
  58959. if (sliders[i]->isVisible())
  58960. g.drawText (sliders[i]->getName() + T(":"),
  58961. 0, sliders[i]->getY(),
  58962. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  58963. Justification::centredRight, false);
  58964. }
  58965. }
  58966. }
  58967. void ColourSelector::resized()
  58968. {
  58969. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  58970. const int numSwatches = getNumSwatches();
  58971. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  58972. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  58973. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  58974. int y = topSpace;
  58975. if ((flags & showColourspace) != 0)
  58976. {
  58977. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  58978. colourSpace->setBounds (edgeGap, y,
  58979. getWidth() - hueWidth - edgeGap - 4,
  58980. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  58981. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  58982. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  58983. colourSpace->getHeight());
  58984. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  58985. }
  58986. if ((flags & showSliders) != 0)
  58987. {
  58988. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  58989. for (int i = 0; i < numSliders; ++i)
  58990. {
  58991. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  58992. proportionOfWidth (0.72f), sliderHeight - 2);
  58993. y += sliderHeight;
  58994. }
  58995. }
  58996. if (numSwatches > 0)
  58997. {
  58998. const int startX = 8;
  58999. const int xGap = 4;
  59000. const int yGap = 4;
  59001. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59002. y += edgeGap;
  59003. if (swatchComponents.size() != numSwatches)
  59004. {
  59005. swatchComponents.clear();
  59006. for (int i = 0; i < numSwatches; ++i)
  59007. {
  59008. SwatchComponent* const sc = new SwatchComponent (this, i);
  59009. swatchComponents.add (sc);
  59010. addAndMakeVisible (sc);
  59011. }
  59012. }
  59013. int x = startX;
  59014. for (int i = 0; i < swatchComponents.size(); ++i)
  59015. {
  59016. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59017. sc->setBounds (x + xGap / 2,
  59018. y + yGap / 2,
  59019. swatchWidth - xGap,
  59020. swatchHeight - yGap);
  59021. if (((i + 1) % swatchesPerRow) == 0)
  59022. {
  59023. x = startX;
  59024. y += swatchHeight;
  59025. }
  59026. else
  59027. {
  59028. x += swatchWidth;
  59029. }
  59030. }
  59031. }
  59032. }
  59033. void ColourSelector::sliderValueChanged (Slider*)
  59034. {
  59035. if (sliders[0] != 0)
  59036. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59037. (uint8) sliders[1]->getValue(),
  59038. (uint8) sliders[2]->getValue(),
  59039. (uint8) sliders[3]->getValue()));
  59040. }
  59041. int ColourSelector::getNumSwatches() const
  59042. {
  59043. return 0;
  59044. }
  59045. const Colour ColourSelector::getSwatchColour (const int) const
  59046. {
  59047. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59048. return Colours::black;
  59049. }
  59050. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59051. {
  59052. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59053. }
  59054. END_JUCE_NAMESPACE
  59055. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59056. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59057. BEGIN_JUCE_NAMESPACE
  59058. class ShadowWindow : public Component
  59059. {
  59060. Component* owner;
  59061. Image** shadowImageSections;
  59062. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59063. public:
  59064. ShadowWindow (Component* const owner_,
  59065. const int type_,
  59066. Image** const shadowImageSections_)
  59067. : owner (owner_),
  59068. shadowImageSections (shadowImageSections_),
  59069. type (type_)
  59070. {
  59071. setInterceptsMouseClicks (false, false);
  59072. if (owner_->isOnDesktop())
  59073. {
  59074. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59075. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59076. | ComponentPeer::windowIsTemporary
  59077. | ComponentPeer::windowIgnoresKeyPresses);
  59078. }
  59079. else if (owner_->getParentComponent() != 0)
  59080. {
  59081. owner_->getParentComponent()->addChildComponent (this);
  59082. }
  59083. }
  59084. ~ShadowWindow()
  59085. {
  59086. }
  59087. void paint (Graphics& g)
  59088. {
  59089. Image* const topLeft = shadowImageSections [type * 3];
  59090. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59091. Image* const filler = shadowImageSections [type * 3 + 2];
  59092. g.setOpacity (1.0f);
  59093. if (type < 2)
  59094. {
  59095. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59096. g.drawImage (topLeft,
  59097. 0, 0, topLeft->getWidth(), imH,
  59098. 0, 0, topLeft->getWidth(), imH);
  59099. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59100. g.drawImage (bottomRight,
  59101. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59102. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59103. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59104. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59105. }
  59106. else
  59107. {
  59108. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59109. g.drawImage (topLeft,
  59110. 0, 0, imW, topLeft->getHeight(),
  59111. 0, 0, imW, topLeft->getHeight());
  59112. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59113. g.drawImage (bottomRight,
  59114. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59115. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59116. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59117. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59118. }
  59119. }
  59120. void resized()
  59121. {
  59122. repaint(); // (needed for correct repainting)
  59123. }
  59124. private:
  59125. ShadowWindow (const ShadowWindow&);
  59126. ShadowWindow& operator= (const ShadowWindow&);
  59127. };
  59128. DropShadower::DropShadower (const float alpha_,
  59129. const int xOffset_,
  59130. const int yOffset_,
  59131. const float blurRadius_)
  59132. : owner (0),
  59133. numShadows (0),
  59134. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59135. xOffset (xOffset_),
  59136. yOffset (yOffset_),
  59137. alpha (alpha_),
  59138. blurRadius (blurRadius_),
  59139. inDestructor (false),
  59140. reentrant (false)
  59141. {
  59142. }
  59143. DropShadower::~DropShadower()
  59144. {
  59145. if (owner != 0)
  59146. owner->removeComponentListener (this);
  59147. inDestructor = true;
  59148. deleteShadowWindows();
  59149. }
  59150. void DropShadower::deleteShadowWindows()
  59151. {
  59152. if (numShadows > 0)
  59153. {
  59154. int i;
  59155. for (i = numShadows; --i >= 0;)
  59156. delete shadowWindows[i];
  59157. for (i = 12; --i >= 0;)
  59158. delete shadowImageSections[i];
  59159. numShadows = 0;
  59160. }
  59161. }
  59162. void DropShadower::setOwner (Component* componentToFollow)
  59163. {
  59164. if (componentToFollow != owner)
  59165. {
  59166. if (owner != 0)
  59167. owner->removeComponentListener (this);
  59168. // (the component can't be null)
  59169. jassert (componentToFollow != 0);
  59170. owner = componentToFollow;
  59171. jassert (owner != 0);
  59172. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59173. owner->addComponentListener (this);
  59174. updateShadows();
  59175. }
  59176. }
  59177. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59178. {
  59179. updateShadows();
  59180. }
  59181. void DropShadower::componentBroughtToFront (Component&)
  59182. {
  59183. bringShadowWindowsToFront();
  59184. }
  59185. void DropShadower::componentChildrenChanged (Component&)
  59186. {
  59187. }
  59188. void DropShadower::componentParentHierarchyChanged (Component&)
  59189. {
  59190. deleteShadowWindows();
  59191. updateShadows();
  59192. }
  59193. void DropShadower::componentVisibilityChanged (Component&)
  59194. {
  59195. updateShadows();
  59196. }
  59197. void DropShadower::updateShadows()
  59198. {
  59199. if (reentrant || inDestructor || (owner == 0))
  59200. return;
  59201. reentrant = true;
  59202. ComponentPeer* const nw = owner->getPeer();
  59203. const bool isOwnerVisible = owner->isVisible()
  59204. && (nw == 0 || ! nw->isMinimised());
  59205. const bool createShadowWindows = numShadows == 0
  59206. && owner->getWidth() > 0
  59207. && owner->getHeight() > 0
  59208. && isOwnerVisible
  59209. && (Desktop::canUseSemiTransparentWindows()
  59210. || owner->getParentComponent() != 0);
  59211. if (createShadowWindows)
  59212. {
  59213. // keep a cached version of the image to save doing the gaussian too often
  59214. String imageId;
  59215. imageId << shadowEdge << T(',')
  59216. << xOffset << T(',')
  59217. << yOffset << T(',')
  59218. << alpha;
  59219. const int hash = imageId.hashCode();
  59220. Image* bigIm = ImageCache::getFromHashCode (hash);
  59221. if (bigIm == 0)
  59222. {
  59223. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59224. Graphics bigG (*bigIm);
  59225. bigG.setColour (Colours::black.withAlpha (alpha));
  59226. bigG.fillRect (shadowEdge + xOffset,
  59227. shadowEdge + yOffset,
  59228. bigIm->getWidth() - (shadowEdge * 2),
  59229. bigIm->getHeight() - (shadowEdge * 2));
  59230. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59231. blurKernel.createGaussianBlur (blurRadius);
  59232. blurKernel.applyToImage (*bigIm, 0,
  59233. xOffset,
  59234. yOffset,
  59235. bigIm->getWidth(),
  59236. bigIm->getHeight());
  59237. ImageCache::addImageToCache (bigIm, hash);
  59238. }
  59239. const int iw = bigIm->getWidth();
  59240. const int ih = bigIm->getHeight();
  59241. const int shadowEdge2 = shadowEdge * 2;
  59242. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59243. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59244. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59245. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59246. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59247. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59248. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59249. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59250. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59251. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59252. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59253. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59254. ImageCache::release (bigIm);
  59255. for (int i = 0; i < 4; ++i)
  59256. {
  59257. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59258. ++numShadows;
  59259. }
  59260. }
  59261. if (numShadows > 0)
  59262. {
  59263. for (int i = numShadows; --i >= 0;)
  59264. {
  59265. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59266. shadowWindows[i]->setVisible (isOwnerVisible);
  59267. }
  59268. const int x = owner->getX();
  59269. const int y = owner->getY() - shadowEdge;
  59270. const int w = owner->getWidth();
  59271. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59272. shadowWindows[0]->setBounds (x - shadowEdge,
  59273. y,
  59274. shadowEdge,
  59275. h);
  59276. shadowWindows[1]->setBounds (x + w,
  59277. y,
  59278. shadowEdge,
  59279. h);
  59280. shadowWindows[2]->setBounds (x,
  59281. y,
  59282. w,
  59283. shadowEdge);
  59284. shadowWindows[3]->setBounds (x,
  59285. owner->getBottom(),
  59286. w,
  59287. shadowEdge);
  59288. }
  59289. reentrant = false;
  59290. if (createShadowWindows)
  59291. bringShadowWindowsToFront();
  59292. }
  59293. void DropShadower::setShadowImage (Image* const src,
  59294. const int num,
  59295. const int w,
  59296. const int h,
  59297. const int sx,
  59298. const int sy)
  59299. {
  59300. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59301. Graphics g (*shadowImageSections[num]);
  59302. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59303. }
  59304. void DropShadower::bringShadowWindowsToFront()
  59305. {
  59306. if (! (inDestructor || reentrant))
  59307. {
  59308. updateShadows();
  59309. reentrant = true;
  59310. for (int i = numShadows; --i >= 0;)
  59311. shadowWindows[i]->toBehind (owner);
  59312. reentrant = false;
  59313. }
  59314. }
  59315. END_JUCE_NAMESPACE
  59316. /*** End of inlined file: juce_DropShadower.cpp ***/
  59317. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59318. BEGIN_JUCE_NAMESPACE
  59319. class MagnifyingPeer : public ComponentPeer
  59320. {
  59321. public:
  59322. MagnifyingPeer (Component* const component_,
  59323. MagnifierComponent* const magnifierComp_)
  59324. : ComponentPeer (component_, 0),
  59325. magnifierComp (magnifierComp_)
  59326. {
  59327. }
  59328. ~MagnifyingPeer()
  59329. {
  59330. }
  59331. void* getNativeHandle() const { return 0; }
  59332. void setVisible (bool) {}
  59333. void setTitle (const String&) {}
  59334. void setPosition (int, int) {}
  59335. void setSize (int, int) {}
  59336. void setBounds (int, int, int, int, const bool) {}
  59337. void setMinimised (bool) {}
  59338. bool isMinimised() const { return false; }
  59339. void setFullScreen (bool) {}
  59340. bool isFullScreen() const { return false; }
  59341. const BorderSize getFrameSize() const { return BorderSize (0); }
  59342. bool setAlwaysOnTop (bool) { return true; }
  59343. void toFront (bool) {}
  59344. void toBehind (ComponentPeer*) {}
  59345. void setIcon (const Image&) {}
  59346. bool isFocused() const
  59347. {
  59348. return magnifierComp->hasKeyboardFocus (true);
  59349. }
  59350. void grabFocus()
  59351. {
  59352. ComponentPeer* peer = magnifierComp->getPeer();
  59353. if (peer != 0)
  59354. peer->grabFocus();
  59355. }
  59356. void textInputRequired (const Point<int>& position)
  59357. {
  59358. ComponentPeer* peer = magnifierComp->getPeer();
  59359. if (peer != 0)
  59360. peer->textInputRequired (position);
  59361. }
  59362. const Rectangle<int> getBounds() const
  59363. {
  59364. return Rectangle<int> (magnifierComp->getScreenX(), magnifierComp->getScreenY(),
  59365. component->getWidth(), component->getHeight());
  59366. }
  59367. const Point<int> getScreenPosition() const
  59368. {
  59369. return magnifierComp->getScreenPosition();
  59370. }
  59371. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  59372. {
  59373. const double zoom = magnifierComp->getScaleFactor();
  59374. return magnifierComp->relativePositionToGlobal (Point<int> (roundToInt (relativePosition.getX() * zoom),
  59375. roundToInt (relativePosition.getY() * zoom)));
  59376. }
  59377. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  59378. {
  59379. const Point<int> p (magnifierComp->globalPositionToRelative (screenPosition));
  59380. const double zoom = magnifierComp->getScaleFactor();
  59381. return Point<int> (roundToInt (p.getX() / zoom),
  59382. roundToInt (p.getY() / zoom));
  59383. }
  59384. bool contains (const Point<int>& position, bool) const
  59385. {
  59386. return ((unsigned int) position.getX()) < (unsigned int) magnifierComp->getWidth()
  59387. && ((unsigned int) position.getY()) < (unsigned int) magnifierComp->getHeight();
  59388. }
  59389. void repaint (int x, int y, int w, int h)
  59390. {
  59391. const double zoom = magnifierComp->getScaleFactor();
  59392. magnifierComp->repaint ((int) (x * zoom),
  59393. (int) (y * zoom),
  59394. roundToInt (w * zoom) + 1,
  59395. roundToInt (h * zoom) + 1);
  59396. }
  59397. void performAnyPendingRepaintsNow()
  59398. {
  59399. }
  59400. juce_UseDebuggingNewOperator
  59401. private:
  59402. MagnifierComponent* const magnifierComp;
  59403. MagnifyingPeer (const MagnifyingPeer&);
  59404. MagnifyingPeer& operator= (const MagnifyingPeer&);
  59405. };
  59406. class PeerHolderComp : public Component
  59407. {
  59408. public:
  59409. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59410. : magnifierComp (magnifierComp_)
  59411. {
  59412. setVisible (true);
  59413. }
  59414. ~PeerHolderComp()
  59415. {
  59416. }
  59417. ComponentPeer* createNewPeer (int, void*)
  59418. {
  59419. return new MagnifyingPeer (this, magnifierComp);
  59420. }
  59421. void childBoundsChanged (Component* c)
  59422. {
  59423. if (c != 0)
  59424. {
  59425. setSize (c->getWidth(), c->getHeight());
  59426. magnifierComp->childBoundsChanged (this);
  59427. }
  59428. }
  59429. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59430. {
  59431. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59432. Component* const p = magnifierComp->getParentComponent();
  59433. if (p != 0)
  59434. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59435. }
  59436. private:
  59437. MagnifierComponent* const magnifierComp;
  59438. PeerHolderComp (const PeerHolderComp&);
  59439. PeerHolderComp& operator= (const PeerHolderComp&);
  59440. };
  59441. MagnifierComponent::MagnifierComponent (Component* const content_,
  59442. const bool deleteContentCompWhenNoLongerNeeded)
  59443. : content (content_),
  59444. scaleFactor (0.0),
  59445. peer (0),
  59446. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59447. quality (Graphics::lowResamplingQuality),
  59448. mouseSource (0, true)
  59449. {
  59450. holderComp = new PeerHolderComp (this);
  59451. setScaleFactor (1.0);
  59452. }
  59453. MagnifierComponent::~MagnifierComponent()
  59454. {
  59455. delete holderComp;
  59456. if (deleteContent)
  59457. delete content;
  59458. }
  59459. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59460. {
  59461. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59462. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59463. if (scaleFactor != newScaleFactor)
  59464. {
  59465. scaleFactor = newScaleFactor;
  59466. if (scaleFactor == 1.0)
  59467. {
  59468. holderComp->removeFromDesktop();
  59469. peer = 0;
  59470. addChildComponent (content);
  59471. childBoundsChanged (content);
  59472. }
  59473. else
  59474. {
  59475. holderComp->addAndMakeVisible (content);
  59476. holderComp->childBoundsChanged (content);
  59477. childBoundsChanged (holderComp);
  59478. holderComp->addToDesktop (0);
  59479. peer = holderComp->getPeer();
  59480. }
  59481. repaint();
  59482. }
  59483. }
  59484. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59485. {
  59486. quality = newQuality;
  59487. }
  59488. void MagnifierComponent::paint (Graphics& g)
  59489. {
  59490. const int w = holderComp->getWidth();
  59491. const int h = holderComp->getHeight();
  59492. if (w == 0 || h == 0)
  59493. return;
  59494. const Rectangle<int> r (g.getClipBounds());
  59495. const int srcX = (int) (r.getX() / scaleFactor);
  59496. const int srcY = (int) (r.getY() / scaleFactor);
  59497. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59498. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59499. if (scaleFactor >= 1.0)
  59500. {
  59501. ++srcW;
  59502. ++srcH;
  59503. }
  59504. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59505. temp.clear (srcX, srcY, srcW, srcH);
  59506. {
  59507. Graphics g2 (temp);
  59508. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59509. holderComp->paintEntireComponent (g2);
  59510. }
  59511. g.setImageResamplingQuality (quality);
  59512. g.drawImageTransformed (&temp, temp.getBounds(),
  59513. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59514. false);
  59515. }
  59516. void MagnifierComponent::childBoundsChanged (Component* c)
  59517. {
  59518. if (c != 0)
  59519. setSize (roundToInt (c->getWidth() * scaleFactor),
  59520. roundToInt (c->getHeight() * scaleFactor));
  59521. }
  59522. void MagnifierComponent::passOnMouseEventToPeer (const MouseEvent& e)
  59523. {
  59524. if (peer != 0)
  59525. mouseSource.handleEvent (peer, Point<int> (scaleInt (e.x), scaleInt (e.y)),
  59526. e.eventTime.toMilliseconds(), ModifierKeys::getCurrentModifiers());
  59527. }
  59528. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59529. {
  59530. passOnMouseEventToPeer (e);
  59531. }
  59532. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59533. {
  59534. passOnMouseEventToPeer (e);
  59535. }
  59536. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59537. {
  59538. passOnMouseEventToPeer (e);
  59539. }
  59540. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59541. {
  59542. passOnMouseEventToPeer (e);
  59543. }
  59544. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59545. {
  59546. passOnMouseEventToPeer (e);
  59547. }
  59548. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59549. {
  59550. passOnMouseEventToPeer (e);
  59551. }
  59552. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59553. {
  59554. if (peer != 0)
  59555. peer->handleMouseWheel (e.source.getIndex(),
  59556. Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds(),
  59557. ix * 256.0f, iy * 256.0f);
  59558. else
  59559. Component::mouseWheelMove (e, ix, iy);
  59560. }
  59561. int MagnifierComponent::scaleInt (const int n) const
  59562. {
  59563. return roundToInt (n / scaleFactor);
  59564. }
  59565. END_JUCE_NAMESPACE
  59566. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59567. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59568. BEGIN_JUCE_NAMESPACE
  59569. class MidiKeyboardUpDownButton : public Button
  59570. {
  59571. public:
  59572. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59573. const int delta_)
  59574. : Button (String::empty),
  59575. owner (owner_),
  59576. delta (delta_)
  59577. {
  59578. setOpaque (true);
  59579. }
  59580. ~MidiKeyboardUpDownButton()
  59581. {
  59582. }
  59583. void clicked()
  59584. {
  59585. int note = owner->getLowestVisibleKey();
  59586. if (delta < 0)
  59587. note = (note - 1) / 12;
  59588. else
  59589. note = note / 12 + 1;
  59590. owner->setLowestVisibleKey (note * 12);
  59591. }
  59592. void paintButton (Graphics& g,
  59593. bool isMouseOverButton,
  59594. bool isButtonDown)
  59595. {
  59596. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59597. isMouseOverButton, isButtonDown,
  59598. delta > 0);
  59599. }
  59600. private:
  59601. MidiKeyboardComponent* const owner;
  59602. const int delta;
  59603. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59604. MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59605. };
  59606. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59607. const Orientation orientation_)
  59608. : state (state_),
  59609. xOffset (0),
  59610. blackNoteLength (1),
  59611. keyWidth (16.0f),
  59612. orientation (orientation_),
  59613. midiChannel (1),
  59614. midiInChannelMask (0xffff),
  59615. velocity (1.0f),
  59616. noteUnderMouse (-1),
  59617. mouseDownNote (-1),
  59618. rangeStart (0),
  59619. rangeEnd (127),
  59620. firstKey (12 * 4),
  59621. canScroll (true),
  59622. mouseDragging (false),
  59623. useMousePositionForVelocity (true),
  59624. keyMappingOctave (6),
  59625. octaveNumForMiddleC (3)
  59626. {
  59627. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  59628. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  59629. // initialise with a default set of querty key-mappings..
  59630. const char* const keymap = "awsedftgyhujkolp;";
  59631. for (int i = String (keymap).length(); --i >= 0;)
  59632. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  59633. setOpaque (true);
  59634. setWantsKeyboardFocus (true);
  59635. state.addListener (this);
  59636. }
  59637. MidiKeyboardComponent::~MidiKeyboardComponent()
  59638. {
  59639. state.removeListener (this);
  59640. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  59641. deleteAllChildren();
  59642. }
  59643. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  59644. {
  59645. keyWidth = widthInPixels;
  59646. resized();
  59647. }
  59648. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  59649. {
  59650. if (orientation != newOrientation)
  59651. {
  59652. orientation = newOrientation;
  59653. resized();
  59654. }
  59655. }
  59656. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  59657. const int highestNote)
  59658. {
  59659. jassert (lowestNote >= 0 && lowestNote <= 127);
  59660. jassert (highestNote >= 0 && highestNote <= 127);
  59661. jassert (lowestNote <= highestNote);
  59662. if (rangeStart != lowestNote || rangeEnd != highestNote)
  59663. {
  59664. rangeStart = jlimit (0, 127, lowestNote);
  59665. rangeEnd = jlimit (0, 127, highestNote);
  59666. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  59667. resized();
  59668. }
  59669. }
  59670. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  59671. {
  59672. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  59673. if (noteNumber != firstKey)
  59674. {
  59675. firstKey = noteNumber;
  59676. sendChangeMessage (this);
  59677. resized();
  59678. }
  59679. }
  59680. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  59681. {
  59682. if (canScroll != canScroll_)
  59683. {
  59684. canScroll = canScroll_;
  59685. resized();
  59686. }
  59687. }
  59688. void MidiKeyboardComponent::colourChanged()
  59689. {
  59690. repaint();
  59691. }
  59692. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  59693. {
  59694. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  59695. if (midiChannel != midiChannelNumber)
  59696. {
  59697. resetAnyKeysInUse();
  59698. midiChannel = jlimit (1, 16, midiChannelNumber);
  59699. }
  59700. }
  59701. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  59702. {
  59703. midiInChannelMask = midiChannelMask;
  59704. triggerAsyncUpdate();
  59705. }
  59706. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  59707. {
  59708. velocity = jlimit (0.0f, 1.0f, velocity_);
  59709. useMousePositionForVelocity = useMousePositionForVelocity_;
  59710. }
  59711. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  59712. {
  59713. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  59714. static const float blackNoteWidth = 0.7f;
  59715. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  59716. 1.0f, 2 - blackNoteWidth * 0.4f,
  59717. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  59718. 4.0f, 5 - blackNoteWidth * 0.5f,
  59719. 5.0f, 6 - blackNoteWidth * 0.3f,
  59720. 6.0f };
  59721. static const float widths[] = { 1.0f, blackNoteWidth,
  59722. 1.0f, blackNoteWidth,
  59723. 1.0f, 1.0f, blackNoteWidth,
  59724. 1.0f, blackNoteWidth,
  59725. 1.0f, blackNoteWidth,
  59726. 1.0f };
  59727. const int octave = midiNoteNumber / 12;
  59728. const int note = midiNoteNumber % 12;
  59729. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  59730. w = roundToInt (widths [note] * keyWidth);
  59731. }
  59732. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  59733. {
  59734. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  59735. int rx, rw;
  59736. getKeyPosition (rangeStart, keyWidth, rx, rw);
  59737. x -= xOffset + rx;
  59738. }
  59739. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  59740. {
  59741. int x, y;
  59742. getKeyPos (midiNoteNumber, x, y);
  59743. return x;
  59744. }
  59745. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  59746. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  59747. int MidiKeyboardComponent::xyToNote (const Point<int>& pos, float& mousePositionVelocity)
  59748. {
  59749. if (! reallyContains (pos.getX(), pos.getY(), false))
  59750. return -1;
  59751. Point<int> p (pos);
  59752. if (orientation != horizontalKeyboard)
  59753. {
  59754. p = Point<int> (p.getY(), p.getX());
  59755. if (orientation == verticalKeyboardFacingLeft)
  59756. p = Point<int> (p.getX(), getWidth() - p.getY());
  59757. else
  59758. p = Point<int> (getHeight() - p.getX(), p.getY());
  59759. }
  59760. return remappedXYToNote (p + Point<int> (xOffset, 0), mousePositionVelocity);
  59761. }
  59762. int MidiKeyboardComponent::remappedXYToNote (const Point<int>& pos, float& mousePositionVelocity) const
  59763. {
  59764. if (pos.getY() < blackNoteLength)
  59765. {
  59766. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59767. {
  59768. for (int i = 0; i < 5; ++i)
  59769. {
  59770. const int note = octaveStart + blackNotes [i];
  59771. if (note >= rangeStart && note <= rangeEnd)
  59772. {
  59773. int kx, kw;
  59774. getKeyPos (note, kx, kw);
  59775. kx += xOffset;
  59776. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59777. {
  59778. mousePositionVelocity = pos.getY() / (float) blackNoteLength;
  59779. return note;
  59780. }
  59781. }
  59782. }
  59783. }
  59784. }
  59785. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59786. {
  59787. for (int i = 0; i < 7; ++i)
  59788. {
  59789. const int note = octaveStart + whiteNotes [i];
  59790. if (note >= rangeStart && note <= rangeEnd)
  59791. {
  59792. int kx, kw;
  59793. getKeyPos (note, kx, kw);
  59794. kx += xOffset;
  59795. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59796. {
  59797. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  59798. mousePositionVelocity = pos.getY() / (float) whiteNoteLength;
  59799. return note;
  59800. }
  59801. }
  59802. }
  59803. }
  59804. mousePositionVelocity = 0;
  59805. return -1;
  59806. }
  59807. void MidiKeyboardComponent::repaintNote (const int noteNum)
  59808. {
  59809. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59810. {
  59811. int x, w;
  59812. getKeyPos (noteNum, x, w);
  59813. if (orientation == horizontalKeyboard)
  59814. repaint (x, 0, w, getHeight());
  59815. else if (orientation == verticalKeyboardFacingLeft)
  59816. repaint (0, x, getWidth(), w);
  59817. else if (orientation == verticalKeyboardFacingRight)
  59818. repaint (0, getHeight() - x - w, getWidth(), w);
  59819. }
  59820. }
  59821. void MidiKeyboardComponent::paint (Graphics& g)
  59822. {
  59823. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  59824. const Colour lineColour (findColour (keySeparatorLineColourId));
  59825. const Colour textColour (findColour (textLabelColourId));
  59826. int x, w, octave;
  59827. for (octave = 0; octave < 128; octave += 12)
  59828. {
  59829. for (int white = 0; white < 7; ++white)
  59830. {
  59831. const int noteNum = octave + whiteNotes [white];
  59832. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59833. {
  59834. getKeyPos (noteNum, x, w);
  59835. if (orientation == horizontalKeyboard)
  59836. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  59837. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59838. noteUnderMouse == noteNum,
  59839. lineColour, textColour);
  59840. else if (orientation == verticalKeyboardFacingLeft)
  59841. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  59842. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59843. noteUnderMouse == noteNum,
  59844. lineColour, textColour);
  59845. else if (orientation == verticalKeyboardFacingRight)
  59846. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  59847. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59848. noteUnderMouse == noteNum,
  59849. lineColour, textColour);
  59850. }
  59851. }
  59852. }
  59853. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  59854. if (orientation == verticalKeyboardFacingLeft)
  59855. {
  59856. x1 = getWidth() - 1.0f;
  59857. x2 = getWidth() - 5.0f;
  59858. }
  59859. else if (orientation == verticalKeyboardFacingRight)
  59860. x2 = 5.0f;
  59861. else
  59862. y2 = 5.0f;
  59863. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  59864. Colours::transparentBlack, x2, y2, false));
  59865. getKeyPos (rangeEnd, x, w);
  59866. x += w;
  59867. if (orientation == verticalKeyboardFacingLeft)
  59868. g.fillRect (getWidth() - 5, 0, 5, x);
  59869. else if (orientation == verticalKeyboardFacingRight)
  59870. g.fillRect (0, 0, 5, x);
  59871. else
  59872. g.fillRect (0, 0, x, 5);
  59873. g.setColour (lineColour);
  59874. if (orientation == verticalKeyboardFacingLeft)
  59875. g.fillRect (0, 0, 1, x);
  59876. else if (orientation == verticalKeyboardFacingRight)
  59877. g.fillRect (getWidth() - 1, 0, 1, x);
  59878. else
  59879. g.fillRect (0, getHeight() - 1, x, 1);
  59880. const Colour blackNoteColour (findColour (blackNoteColourId));
  59881. for (octave = 0; octave < 128; octave += 12)
  59882. {
  59883. for (int black = 0; black < 5; ++black)
  59884. {
  59885. const int noteNum = octave + blackNotes [black];
  59886. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59887. {
  59888. getKeyPos (noteNum, x, w);
  59889. if (orientation == horizontalKeyboard)
  59890. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  59891. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59892. noteUnderMouse == noteNum,
  59893. blackNoteColour);
  59894. else if (orientation == verticalKeyboardFacingLeft)
  59895. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  59896. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59897. noteUnderMouse == noteNum,
  59898. blackNoteColour);
  59899. else if (orientation == verticalKeyboardFacingRight)
  59900. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  59901. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59902. noteUnderMouse == noteNum,
  59903. blackNoteColour);
  59904. }
  59905. }
  59906. }
  59907. }
  59908. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  59909. Graphics& g, int x, int y, int w, int h,
  59910. bool isDown, bool isOver,
  59911. const Colour& lineColour,
  59912. const Colour& textColour)
  59913. {
  59914. Colour c (Colours::transparentWhite);
  59915. if (isDown)
  59916. c = findColour (keyDownOverlayColourId);
  59917. if (isOver)
  59918. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  59919. g.setColour (c);
  59920. g.fillRect (x, y, w, h);
  59921. const String text (getWhiteNoteText (midiNoteNumber));
  59922. if (! text.isEmpty())
  59923. {
  59924. g.setColour (textColour);
  59925. Font f (jmin (12.0f, keyWidth * 0.9f));
  59926. f.setHorizontalScale (0.8f);
  59927. g.setFont (f);
  59928. Justification justification (Justification::centredBottom);
  59929. if (orientation == verticalKeyboardFacingLeft)
  59930. justification = Justification::centredLeft;
  59931. else if (orientation == verticalKeyboardFacingRight)
  59932. justification = Justification::centredRight;
  59933. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  59934. }
  59935. g.setColour (lineColour);
  59936. if (orientation == horizontalKeyboard)
  59937. g.fillRect (x, y, 1, h);
  59938. else if (orientation == verticalKeyboardFacingLeft)
  59939. g.fillRect (x, y, w, 1);
  59940. else if (orientation == verticalKeyboardFacingRight)
  59941. g.fillRect (x, y + h - 1, w, 1);
  59942. if (midiNoteNumber == rangeEnd)
  59943. {
  59944. if (orientation == horizontalKeyboard)
  59945. g.fillRect (x + w, y, 1, h);
  59946. else if (orientation == verticalKeyboardFacingLeft)
  59947. g.fillRect (x, y + h, w, 1);
  59948. else if (orientation == verticalKeyboardFacingRight)
  59949. g.fillRect (x, y - 1, w, 1);
  59950. }
  59951. }
  59952. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  59953. Graphics& g, int x, int y, int w, int h,
  59954. bool isDown, bool isOver,
  59955. const Colour& noteFillColour)
  59956. {
  59957. Colour c (noteFillColour);
  59958. if (isDown)
  59959. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  59960. if (isOver)
  59961. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  59962. g.setColour (c);
  59963. g.fillRect (x, y, w, h);
  59964. if (isDown)
  59965. {
  59966. g.setColour (noteFillColour);
  59967. g.drawRect (x, y, w, h);
  59968. }
  59969. else
  59970. {
  59971. const int xIndent = jmax (1, jmin (w, h) / 8);
  59972. g.setColour (c.brighter());
  59973. if (orientation == horizontalKeyboard)
  59974. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  59975. else if (orientation == verticalKeyboardFacingLeft)
  59976. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  59977. else if (orientation == verticalKeyboardFacingRight)
  59978. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  59979. }
  59980. }
  59981. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  59982. {
  59983. octaveNumForMiddleC = octaveNumForMiddleC_;
  59984. repaint();
  59985. }
  59986. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  59987. {
  59988. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  59989. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  59990. return String::empty;
  59991. }
  59992. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  59993. const bool isMouseOver,
  59994. const bool isButtonDown,
  59995. const bool movesOctavesUp)
  59996. {
  59997. g.fillAll (findColour (upDownButtonBackgroundColourId));
  59998. float angle;
  59999. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60000. angle = movesOctavesUp ? 0.0f : 0.5f;
  60001. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60002. angle = movesOctavesUp ? 0.25f : 0.75f;
  60003. else
  60004. angle = movesOctavesUp ? 0.75f : 0.25f;
  60005. Path path;
  60006. path.lineTo (0.0f, 1.0f);
  60007. path.lineTo (1.0f, 0.5f);
  60008. path.closeSubPath();
  60009. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60010. g.setColour (findColour (upDownButtonArrowColourId)
  60011. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60012. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60013. w - 2.0f,
  60014. h - 2.0f,
  60015. true));
  60016. }
  60017. void MidiKeyboardComponent::resized()
  60018. {
  60019. int w = getWidth();
  60020. int h = getHeight();
  60021. if (w > 0 && h > 0)
  60022. {
  60023. if (orientation != horizontalKeyboard)
  60024. swapVariables (w, h);
  60025. blackNoteLength = roundToInt (h * 0.7f);
  60026. int kx2, kw2;
  60027. getKeyPos (rangeEnd, kx2, kw2);
  60028. kx2 += kw2;
  60029. if (firstKey != rangeStart)
  60030. {
  60031. int kx1, kw1;
  60032. getKeyPos (rangeStart, kx1, kw1);
  60033. if (kx2 - kx1 <= w)
  60034. {
  60035. firstKey = rangeStart;
  60036. sendChangeMessage (this);
  60037. repaint();
  60038. }
  60039. }
  60040. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60041. scrollDown->setVisible (showScrollButtons);
  60042. scrollUp->setVisible (showScrollButtons);
  60043. xOffset = 0;
  60044. if (showScrollButtons)
  60045. {
  60046. const int scrollButtonW = jmin (12, w / 2);
  60047. if (orientation == horizontalKeyboard)
  60048. {
  60049. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60050. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60051. }
  60052. else if (orientation == verticalKeyboardFacingLeft)
  60053. {
  60054. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60055. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60056. }
  60057. else if (orientation == verticalKeyboardFacingRight)
  60058. {
  60059. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60060. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60061. }
  60062. int endOfLastKey, kw;
  60063. getKeyPos (rangeEnd, endOfLastKey, kw);
  60064. endOfLastKey += kw;
  60065. float mousePositionVelocity;
  60066. const int spaceAvailable = w - scrollButtonW * 2;
  60067. const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1;
  60068. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60069. {
  60070. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60071. sendChangeMessage (this);
  60072. }
  60073. int newOffset = 0;
  60074. getKeyPos (firstKey, newOffset, kw);
  60075. xOffset = newOffset - scrollButtonW;
  60076. }
  60077. else
  60078. {
  60079. firstKey = rangeStart;
  60080. }
  60081. timerCallback();
  60082. repaint();
  60083. }
  60084. }
  60085. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60086. {
  60087. triggerAsyncUpdate();
  60088. }
  60089. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60090. {
  60091. triggerAsyncUpdate();
  60092. }
  60093. void MidiKeyboardComponent::handleAsyncUpdate()
  60094. {
  60095. for (int i = rangeStart; i <= rangeEnd; ++i)
  60096. {
  60097. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60098. {
  60099. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60100. repaintNote (i);
  60101. }
  60102. }
  60103. }
  60104. void MidiKeyboardComponent::resetAnyKeysInUse()
  60105. {
  60106. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60107. {
  60108. state.allNotesOff (midiChannel);
  60109. keysPressed.clear();
  60110. mouseDownNote = -1;
  60111. }
  60112. }
  60113. void MidiKeyboardComponent::updateNoteUnderMouse (const Point<int>& pos)
  60114. {
  60115. float mousePositionVelocity = 0.0f;
  60116. const int newNote = (mouseDragging || isMouseOver())
  60117. ? xyToNote (pos, mousePositionVelocity) : -1;
  60118. if (noteUnderMouse != newNote)
  60119. {
  60120. if (mouseDownNote >= 0)
  60121. {
  60122. state.noteOff (midiChannel, mouseDownNote);
  60123. mouseDownNote = -1;
  60124. }
  60125. if (mouseDragging && newNote >= 0)
  60126. {
  60127. if (! useMousePositionForVelocity)
  60128. mousePositionVelocity = 1.0f;
  60129. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60130. mouseDownNote = newNote;
  60131. }
  60132. repaintNote (noteUnderMouse);
  60133. noteUnderMouse = newNote;
  60134. repaintNote (noteUnderMouse);
  60135. }
  60136. else if (mouseDownNote >= 0 && ! mouseDragging)
  60137. {
  60138. state.noteOff (midiChannel, mouseDownNote);
  60139. mouseDownNote = -1;
  60140. }
  60141. }
  60142. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60143. {
  60144. updateNoteUnderMouse (e.getPosition());
  60145. stopTimer();
  60146. }
  60147. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60148. {
  60149. float mousePositionVelocity;
  60150. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60151. if (newNote >= 0)
  60152. mouseDraggedToKey (newNote, e);
  60153. updateNoteUnderMouse (e.getPosition());
  60154. }
  60155. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60156. {
  60157. return true;
  60158. }
  60159. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60160. {
  60161. }
  60162. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60163. {
  60164. float mousePositionVelocity;
  60165. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60166. mouseDragging = false;
  60167. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60168. {
  60169. repaintNote (noteUnderMouse);
  60170. noteUnderMouse = -1;
  60171. mouseDragging = true;
  60172. updateNoteUnderMouse (e.getPosition());
  60173. startTimer (500);
  60174. }
  60175. }
  60176. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60177. {
  60178. mouseDragging = false;
  60179. updateNoteUnderMouse (e.getPosition());
  60180. stopTimer();
  60181. }
  60182. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60183. {
  60184. updateNoteUnderMouse (e.getPosition());
  60185. }
  60186. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60187. {
  60188. updateNoteUnderMouse (e.getPosition());
  60189. }
  60190. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60191. {
  60192. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60193. }
  60194. void MidiKeyboardComponent::timerCallback()
  60195. {
  60196. updateNoteUnderMouse (getMouseXYRelative());
  60197. }
  60198. void MidiKeyboardComponent::clearKeyMappings()
  60199. {
  60200. resetAnyKeysInUse();
  60201. keyPressNotes.clear();
  60202. keyPresses.clear();
  60203. }
  60204. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60205. const int midiNoteOffsetFromC)
  60206. {
  60207. removeKeyPressForNote (midiNoteOffsetFromC);
  60208. keyPressNotes.add (midiNoteOffsetFromC);
  60209. keyPresses.add (key);
  60210. }
  60211. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60212. {
  60213. for (int i = keyPressNotes.size(); --i >= 0;)
  60214. {
  60215. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60216. {
  60217. keyPressNotes.remove (i);
  60218. keyPresses.remove (i);
  60219. }
  60220. }
  60221. }
  60222. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60223. {
  60224. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60225. keyMappingOctave = newOctaveNumber;
  60226. }
  60227. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60228. {
  60229. bool keyPressUsed = false;
  60230. for (int i = keyPresses.size(); --i >= 0;)
  60231. {
  60232. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60233. if (keyPresses.getReference(i).isCurrentlyDown())
  60234. {
  60235. if (! keysPressed [note])
  60236. {
  60237. keysPressed.setBit (note);
  60238. state.noteOn (midiChannel, note, velocity);
  60239. keyPressUsed = true;
  60240. }
  60241. }
  60242. else
  60243. {
  60244. if (keysPressed [note])
  60245. {
  60246. keysPressed.clearBit (note);
  60247. state.noteOff (midiChannel, note);
  60248. keyPressUsed = true;
  60249. }
  60250. }
  60251. }
  60252. return keyPressUsed;
  60253. }
  60254. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60255. {
  60256. resetAnyKeysInUse();
  60257. }
  60258. END_JUCE_NAMESPACE
  60259. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60260. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60261. #if JUCE_OPENGL
  60262. BEGIN_JUCE_NAMESPACE
  60263. extern void juce_glViewport (const int w, const int h);
  60264. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60265. const int alphaBits_,
  60266. const int depthBufferBits_,
  60267. const int stencilBufferBits_)
  60268. : redBits (bitsPerRGBComponent),
  60269. greenBits (bitsPerRGBComponent),
  60270. blueBits (bitsPerRGBComponent),
  60271. alphaBits (alphaBits_),
  60272. depthBufferBits (depthBufferBits_),
  60273. stencilBufferBits (stencilBufferBits_),
  60274. accumulationBufferRedBits (0),
  60275. accumulationBufferGreenBits (0),
  60276. accumulationBufferBlueBits (0),
  60277. accumulationBufferAlphaBits (0),
  60278. fullSceneAntiAliasingNumSamples (0)
  60279. {
  60280. }
  60281. OpenGLPixelFormat::OpenGLPixelFormat (const OpenGLPixelFormat& other)
  60282. : redBits (other.redBits),
  60283. greenBits (other.greenBits),
  60284. blueBits (other.blueBits),
  60285. alphaBits (other.alphaBits),
  60286. depthBufferBits (other.depthBufferBits),
  60287. stencilBufferBits (other.stencilBufferBits),
  60288. accumulationBufferRedBits (other.accumulationBufferRedBits),
  60289. accumulationBufferGreenBits (other.accumulationBufferGreenBits),
  60290. accumulationBufferBlueBits (other.accumulationBufferBlueBits),
  60291. accumulationBufferAlphaBits (other.accumulationBufferAlphaBits),
  60292. fullSceneAntiAliasingNumSamples (other.fullSceneAntiAliasingNumSamples)
  60293. {
  60294. }
  60295. OpenGLPixelFormat& OpenGLPixelFormat::operator= (const OpenGLPixelFormat& other)
  60296. {
  60297. redBits = other.redBits;
  60298. greenBits = other.greenBits;
  60299. blueBits = other.blueBits;
  60300. alphaBits = other.alphaBits;
  60301. depthBufferBits = other.depthBufferBits;
  60302. stencilBufferBits = other.stencilBufferBits;
  60303. accumulationBufferRedBits = other.accumulationBufferRedBits;
  60304. accumulationBufferGreenBits = other.accumulationBufferGreenBits;
  60305. accumulationBufferBlueBits = other.accumulationBufferBlueBits;
  60306. accumulationBufferAlphaBits = other.accumulationBufferAlphaBits;
  60307. fullSceneAntiAliasingNumSamples = other.fullSceneAntiAliasingNumSamples;
  60308. return *this;
  60309. }
  60310. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const
  60311. {
  60312. return redBits == other.redBits
  60313. && greenBits == other.greenBits
  60314. && blueBits == other.blueBits
  60315. && alphaBits == other.alphaBits
  60316. && depthBufferBits == other.depthBufferBits
  60317. && stencilBufferBits == other.stencilBufferBits
  60318. && accumulationBufferRedBits == other.accumulationBufferRedBits
  60319. && accumulationBufferGreenBits == other.accumulationBufferGreenBits
  60320. && accumulationBufferBlueBits == other.accumulationBufferBlueBits
  60321. && accumulationBufferAlphaBits == other.accumulationBufferAlphaBits
  60322. && fullSceneAntiAliasingNumSamples == other.fullSceneAntiAliasingNumSamples;
  60323. }
  60324. static VoidArray knownContexts;
  60325. OpenGLContext::OpenGLContext() throw()
  60326. {
  60327. knownContexts.add (this);
  60328. }
  60329. OpenGLContext::~OpenGLContext()
  60330. {
  60331. knownContexts.removeValue (this);
  60332. }
  60333. OpenGLContext* OpenGLContext::getCurrentContext()
  60334. {
  60335. for (int i = knownContexts.size(); --i >= 0;)
  60336. {
  60337. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60338. if (oglc->isActive())
  60339. return oglc;
  60340. }
  60341. return 0;
  60342. }
  60343. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60344. {
  60345. public:
  60346. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60347. : ComponentMovementWatcher (owner_),
  60348. owner (owner_),
  60349. wasShowing (false)
  60350. {
  60351. }
  60352. ~OpenGLComponentWatcher() {}
  60353. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60354. {
  60355. owner->updateContextPosition();
  60356. }
  60357. void componentPeerChanged()
  60358. {
  60359. const ScopedLock sl (owner->getContextLock());
  60360. owner->deleteContext();
  60361. }
  60362. void componentVisibilityChanged (Component&)
  60363. {
  60364. const bool isShowingNow = owner->isShowing();
  60365. if (wasShowing != isShowingNow)
  60366. {
  60367. wasShowing = isShowingNow;
  60368. owner->updateContextPosition();
  60369. }
  60370. }
  60371. juce_UseDebuggingNewOperator
  60372. private:
  60373. OpenGLComponent* const owner;
  60374. bool wasShowing;
  60375. };
  60376. OpenGLComponent::OpenGLComponent (const OpenGLType type_)
  60377. : type (type_),
  60378. contextToShareListsWith (0),
  60379. needToUpdateViewport (true)
  60380. {
  60381. setOpaque (true);
  60382. componentWatcher = new OpenGLComponentWatcher (this);
  60383. }
  60384. OpenGLComponent::~OpenGLComponent()
  60385. {
  60386. deleteContext();
  60387. componentWatcher = 0;
  60388. }
  60389. void OpenGLComponent::deleteContext()
  60390. {
  60391. const ScopedLock sl (contextLock);
  60392. context = 0;
  60393. }
  60394. void OpenGLComponent::updateContextPosition()
  60395. {
  60396. needToUpdateViewport = true;
  60397. if (getWidth() > 0 && getHeight() > 0)
  60398. {
  60399. Component* const topComp = getTopLevelComponent();
  60400. if (topComp->getPeer() != 0)
  60401. {
  60402. const ScopedLock sl (contextLock);
  60403. if (context != 0)
  60404. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60405. getScreenY() - topComp->getScreenY(),
  60406. getWidth(),
  60407. getHeight(),
  60408. topComp->getHeight());
  60409. }
  60410. }
  60411. }
  60412. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60413. {
  60414. OpenGLPixelFormat pf;
  60415. const ScopedLock sl (contextLock);
  60416. if (context != 0)
  60417. pf = context->getPixelFormat();
  60418. return pf;
  60419. }
  60420. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60421. {
  60422. if (! (preferredPixelFormat == formatToUse))
  60423. {
  60424. const ScopedLock sl (contextLock);
  60425. deleteContext();
  60426. preferredPixelFormat = formatToUse;
  60427. }
  60428. }
  60429. void OpenGLComponent::shareWith (OpenGLContext* c)
  60430. {
  60431. if (contextToShareListsWith != c)
  60432. {
  60433. const ScopedLock sl (contextLock);
  60434. deleteContext();
  60435. contextToShareListsWith = c;
  60436. }
  60437. }
  60438. bool OpenGLComponent::makeCurrentContextActive()
  60439. {
  60440. if (context == 0)
  60441. {
  60442. const ScopedLock sl (contextLock);
  60443. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60444. {
  60445. context = createContext();
  60446. if (context != 0)
  60447. {
  60448. updateContextPosition();
  60449. if (context->makeActive())
  60450. newOpenGLContextCreated();
  60451. }
  60452. }
  60453. }
  60454. return context != 0 && context->makeActive();
  60455. }
  60456. void OpenGLComponent::makeCurrentContextInactive()
  60457. {
  60458. if (context != 0)
  60459. context->makeInactive();
  60460. }
  60461. bool OpenGLComponent::isActiveContext() const throw()
  60462. {
  60463. return context != 0 && context->isActive();
  60464. }
  60465. void OpenGLComponent::swapBuffers()
  60466. {
  60467. if (context != 0)
  60468. context->swapBuffers();
  60469. }
  60470. void OpenGLComponent::paint (Graphics&)
  60471. {
  60472. if (renderAndSwapBuffers())
  60473. {
  60474. ComponentPeer* const peer = getPeer();
  60475. if (peer != 0)
  60476. {
  60477. const Point<int> topLeft (getScreenPosition() - peer->getScreenPosition());
  60478. peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight());
  60479. }
  60480. }
  60481. }
  60482. bool OpenGLComponent::renderAndSwapBuffers()
  60483. {
  60484. const ScopedLock sl (contextLock);
  60485. if (! makeCurrentContextActive())
  60486. return false;
  60487. if (needToUpdateViewport)
  60488. {
  60489. needToUpdateViewport = false;
  60490. juce_glViewport (getWidth(), getHeight());
  60491. }
  60492. renderOpenGL();
  60493. swapBuffers();
  60494. return true;
  60495. }
  60496. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60497. {
  60498. Component::internalRepaint (x, y, w, h);
  60499. if (context != 0)
  60500. context->repaint();
  60501. }
  60502. END_JUCE_NAMESPACE
  60503. #endif
  60504. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60505. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60506. BEGIN_JUCE_NAMESPACE
  60507. PreferencesPanel::PreferencesPanel()
  60508. : buttonSize (70)
  60509. {
  60510. }
  60511. PreferencesPanel::~PreferencesPanel()
  60512. {
  60513. currentPage = 0;
  60514. deleteAllChildren();
  60515. }
  60516. void PreferencesPanel::addSettingsPage (const String& title,
  60517. const Drawable* icon,
  60518. const Drawable* overIcon,
  60519. const Drawable* downIcon)
  60520. {
  60521. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60522. button->setImages (icon, overIcon, downIcon);
  60523. button->setRadioGroupId (1);
  60524. button->addButtonListener (this);
  60525. button->setClickingTogglesState (true);
  60526. button->setWantsKeyboardFocus (false);
  60527. addAndMakeVisible (button);
  60528. resized();
  60529. if (currentPage == 0)
  60530. setCurrentPage (title);
  60531. }
  60532. void PreferencesPanel::addSettingsPage (const String& title,
  60533. const char* imageData,
  60534. const int imageDataSize)
  60535. {
  60536. DrawableImage icon, iconOver, iconDown;
  60537. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60538. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60539. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60540. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60541. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60542. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60543. }
  60544. class PrefsDialogWindow : public DialogWindow
  60545. {
  60546. public:
  60547. PrefsDialogWindow (const String& dialogtitle,
  60548. const Colour& backgroundColour)
  60549. : DialogWindow (dialogtitle, backgroundColour, true)
  60550. {
  60551. }
  60552. ~PrefsDialogWindow()
  60553. {
  60554. }
  60555. void closeButtonPressed()
  60556. {
  60557. exitModalState (0);
  60558. }
  60559. private:
  60560. PrefsDialogWindow (const PrefsDialogWindow&);
  60561. PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60562. };
  60563. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60564. int dialogWidth,
  60565. int dialogHeight,
  60566. const Colour& backgroundColour)
  60567. {
  60568. setSize (dialogWidth, dialogHeight);
  60569. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60570. dw.setContentComponent (this, true, true);
  60571. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60572. dw.runModalLoop();
  60573. dw.setContentComponent (0, false, false);
  60574. }
  60575. void PreferencesPanel::resized()
  60576. {
  60577. int x = 0;
  60578. for (int i = 0; i < getNumChildComponents(); ++i)
  60579. {
  60580. Component* c = getChildComponent (i);
  60581. if (dynamic_cast <DrawableButton*> (c) == 0)
  60582. {
  60583. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60584. }
  60585. else
  60586. {
  60587. c->setBounds (x, 0, buttonSize, buttonSize);
  60588. x += buttonSize;
  60589. }
  60590. }
  60591. }
  60592. void PreferencesPanel::paint (Graphics& g)
  60593. {
  60594. g.setColour (Colours::grey);
  60595. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60596. }
  60597. void PreferencesPanel::setCurrentPage (const String& pageName)
  60598. {
  60599. if (currentPageName != pageName)
  60600. {
  60601. currentPageName = pageName;
  60602. currentPage = 0;
  60603. currentPage = createComponentForPage (pageName);
  60604. if (currentPage != 0)
  60605. {
  60606. addAndMakeVisible (currentPage);
  60607. currentPage->toBack();
  60608. resized();
  60609. }
  60610. for (int i = 0; i < getNumChildComponents(); ++i)
  60611. {
  60612. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60613. if (db != 0 && db->getName() == pageName)
  60614. {
  60615. db->setToggleState (true, false);
  60616. break;
  60617. }
  60618. }
  60619. }
  60620. }
  60621. void PreferencesPanel::buttonClicked (Button*)
  60622. {
  60623. for (int i = 0; i < getNumChildComponents(); ++i)
  60624. {
  60625. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60626. if (db != 0 && db->getToggleState())
  60627. {
  60628. setCurrentPage (db->getName());
  60629. break;
  60630. }
  60631. }
  60632. }
  60633. END_JUCE_NAMESPACE
  60634. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  60635. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60636. #if JUCE_WINDOWS || JUCE_LINUX
  60637. BEGIN_JUCE_NAMESPACE
  60638. SystemTrayIconComponent::SystemTrayIconComponent()
  60639. {
  60640. addToDesktop (0);
  60641. }
  60642. SystemTrayIconComponent::~SystemTrayIconComponent()
  60643. {
  60644. }
  60645. END_JUCE_NAMESPACE
  60646. #endif
  60647. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60648. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  60649. BEGIN_JUCE_NAMESPACE
  60650. static const int titleH = 24;
  60651. static const int iconWidth = 80;
  60652. class AlertWindowTextEditor : public TextEditor
  60653. {
  60654. public:
  60655. static const tchar passwordChar;
  60656. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  60657. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  60658. {
  60659. setSelectAllWhenFocused (true);
  60660. }
  60661. ~AlertWindowTextEditor()
  60662. {
  60663. }
  60664. void returnPressed()
  60665. {
  60666. // pass these up the component hierarchy to be trigger the buttons
  60667. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, T('\n')));
  60668. }
  60669. void escapePressed()
  60670. {
  60671. // pass these up the component hierarchy to be trigger the buttons
  60672. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  60673. }
  60674. private:
  60675. AlertWindowTextEditor (const AlertWindowTextEditor&);
  60676. AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  60677. };
  60678. #if JUCE_LINUX
  60679. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  60680. #else
  60681. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  60682. #endif
  60683. AlertWindow::AlertWindow (const String& title,
  60684. const String& message,
  60685. AlertIconType iconType,
  60686. Component* associatedComponent_)
  60687. : TopLevelWindow (title, true),
  60688. alertIconType (iconType),
  60689. associatedComponent (associatedComponent_)
  60690. {
  60691. if (message.isEmpty())
  60692. text = T(" "); // to force an update if the message is empty
  60693. setMessage (message);
  60694. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  60695. {
  60696. Component* const c = Desktop::getInstance().getComponent (i);
  60697. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  60698. {
  60699. setAlwaysOnTop (true);
  60700. break;
  60701. }
  60702. }
  60703. if (JUCEApplication::getInstance() == 0)
  60704. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  60705. lookAndFeelChanged();
  60706. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  60707. }
  60708. AlertWindow::~AlertWindow()
  60709. {
  60710. for (int i = customComps.size(); --i >= 0;)
  60711. removeChildComponent ((Component*) customComps[i]);
  60712. deleteAllChildren();
  60713. }
  60714. void AlertWindow::userTriedToCloseWindow()
  60715. {
  60716. exitModalState (0);
  60717. }
  60718. void AlertWindow::setMessage (const String& message)
  60719. {
  60720. const String newMessage (message.substring (0, 2048));
  60721. if (text != newMessage)
  60722. {
  60723. text = newMessage;
  60724. font.setHeight (15.0f);
  60725. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  60726. textLayout.setText (getName() + T("\n\n"), titleFont);
  60727. textLayout.appendText (text, font);
  60728. updateLayout (true);
  60729. repaint();
  60730. }
  60731. }
  60732. void AlertWindow::buttonClicked (Button* button)
  60733. {
  60734. for (int i = 0; i < buttons.size(); i++)
  60735. {
  60736. TextButton* const c = (TextButton*) buttons[i];
  60737. if (button->getName() == c->getName())
  60738. {
  60739. if (c->getParentComponent() != 0)
  60740. c->getParentComponent()->exitModalState (c->getCommandID());
  60741. break;
  60742. }
  60743. }
  60744. }
  60745. void AlertWindow::addButton (const String& name,
  60746. const int returnValue,
  60747. const KeyPress& shortcutKey1,
  60748. const KeyPress& shortcutKey2)
  60749. {
  60750. TextButton* const b = new TextButton (name, String::empty);
  60751. b->setWantsKeyboardFocus (true);
  60752. b->setMouseClickGrabsKeyboardFocus (false);
  60753. b->setCommandToTrigger (0, returnValue, false);
  60754. b->addShortcut (shortcutKey1);
  60755. b->addShortcut (shortcutKey2);
  60756. b->addButtonListener (this);
  60757. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  60758. addAndMakeVisible (b, 0);
  60759. buttons.add (b);
  60760. updateLayout (false);
  60761. }
  60762. int AlertWindow::getNumButtons() const
  60763. {
  60764. return buttons.size();
  60765. }
  60766. void AlertWindow::addTextEditor (const String& name,
  60767. const String& initialContents,
  60768. const String& onScreenLabel,
  60769. const bool isPasswordBox)
  60770. {
  60771. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  60772. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  60773. tc->setFont (font);
  60774. tc->setText (initialContents);
  60775. tc->setCaretPosition (initialContents.length());
  60776. addAndMakeVisible (tc);
  60777. textBoxes.add (tc);
  60778. allComps.add (tc);
  60779. textboxNames.add (onScreenLabel);
  60780. updateLayout (false);
  60781. }
  60782. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  60783. {
  60784. for (int i = textBoxes.size(); --i >= 0;)
  60785. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  60786. return ((TextEditor*)textBoxes[i])->getText();
  60787. return String::empty;
  60788. }
  60789. void AlertWindow::addComboBox (const String& name,
  60790. const StringArray& items,
  60791. const String& onScreenLabel)
  60792. {
  60793. ComboBox* const cb = new ComboBox (name);
  60794. for (int i = 0; i < items.size(); ++i)
  60795. cb->addItem (items[i], i + 1);
  60796. addAndMakeVisible (cb);
  60797. cb->setSelectedItemIndex (0);
  60798. comboBoxes.add (cb);
  60799. allComps.add (cb);
  60800. comboBoxNames.add (onScreenLabel);
  60801. updateLayout (false);
  60802. }
  60803. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  60804. {
  60805. for (int i = comboBoxes.size(); --i >= 0;)
  60806. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  60807. return (ComboBox*) comboBoxes[i];
  60808. return 0;
  60809. }
  60810. class AlertTextComp : public TextEditor
  60811. {
  60812. public:
  60813. AlertTextComp (const String& message,
  60814. const Font& font)
  60815. {
  60816. setReadOnly (true);
  60817. setMultiLine (true, true);
  60818. setCaretVisible (false);
  60819. setScrollbarsShown (true);
  60820. lookAndFeelChanged();
  60821. setWantsKeyboardFocus (false);
  60822. setFont (font);
  60823. setText (message, false);
  60824. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  60825. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  60826. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  60827. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  60828. }
  60829. ~AlertTextComp()
  60830. {
  60831. }
  60832. int getPreferredWidth() const throw() { return bestWidth; }
  60833. void updateLayout (const int width)
  60834. {
  60835. TextLayout text;
  60836. text.appendText (getText(), getFont());
  60837. text.layout (width - 8, Justification::topLeft, true);
  60838. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  60839. }
  60840. private:
  60841. int bestWidth;
  60842. AlertTextComp (const AlertTextComp&);
  60843. AlertTextComp& operator= (const AlertTextComp&);
  60844. };
  60845. void AlertWindow::addTextBlock (const String& text)
  60846. {
  60847. AlertTextComp* const c = new AlertTextComp (text, font);
  60848. textBlocks.add (c);
  60849. allComps.add (c);
  60850. addAndMakeVisible (c);
  60851. updateLayout (false);
  60852. }
  60853. void AlertWindow::addProgressBarComponent (double& progressValue)
  60854. {
  60855. ProgressBar* const pb = new ProgressBar (progressValue);
  60856. progressBars.add (pb);
  60857. allComps.add (pb);
  60858. addAndMakeVisible (pb);
  60859. updateLayout (false);
  60860. }
  60861. void AlertWindow::addCustomComponent (Component* const component)
  60862. {
  60863. customComps.add (component);
  60864. allComps.add (component);
  60865. addAndMakeVisible (component);
  60866. updateLayout (false);
  60867. }
  60868. int AlertWindow::getNumCustomComponents() const
  60869. {
  60870. return customComps.size();
  60871. }
  60872. Component* AlertWindow::getCustomComponent (const int index) const
  60873. {
  60874. return (Component*) customComps [index];
  60875. }
  60876. Component* AlertWindow::removeCustomComponent (const int index)
  60877. {
  60878. Component* const c = getCustomComponent (index);
  60879. if (c != 0)
  60880. {
  60881. customComps.removeValue (c);
  60882. allComps.removeValue (c);
  60883. removeChildComponent (c);
  60884. updateLayout (false);
  60885. }
  60886. return c;
  60887. }
  60888. void AlertWindow::paint (Graphics& g)
  60889. {
  60890. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  60891. g.setColour (findColour (textColourId));
  60892. g.setFont (getLookAndFeel().getAlertWindowFont());
  60893. int i;
  60894. for (i = textBoxes.size(); --i >= 0;)
  60895. {
  60896. const TextEditor* const te = (TextEditor*) textBoxes[i];
  60897. g.drawFittedText (textboxNames[i],
  60898. te->getX(), te->getY() - 14,
  60899. te->getWidth(), 14,
  60900. Justification::centredLeft, 1);
  60901. }
  60902. for (i = comboBoxNames.size(); --i >= 0;)
  60903. {
  60904. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  60905. g.drawFittedText (comboBoxNames[i],
  60906. cb->getX(), cb->getY() - 14,
  60907. cb->getWidth(), 14,
  60908. Justification::centredLeft, 1);
  60909. }
  60910. for (i = customComps.size(); --i >= 0;)
  60911. {
  60912. const Component* const c = (Component*) customComps[i];
  60913. g.drawFittedText (c->getName(),
  60914. c->getX(), c->getY() - 14,
  60915. c->getWidth(), 14,
  60916. Justification::centredLeft, 1);
  60917. }
  60918. }
  60919. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  60920. {
  60921. const int wid = jmax (font.getStringWidth (text),
  60922. font.getStringWidth (getName()));
  60923. const int sw = (int) sqrt (font.getHeight() * wid);
  60924. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  60925. const int edgeGap = 10;
  60926. const int labelHeight = 18;
  60927. int iconSpace;
  60928. if (alertIconType == NoIcon)
  60929. {
  60930. textLayout.layout (w, Justification::horizontallyCentred, true);
  60931. iconSpace = 0;
  60932. }
  60933. else
  60934. {
  60935. textLayout.layout (w, Justification::left, true);
  60936. iconSpace = iconWidth;
  60937. }
  60938. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  60939. w = jmin (w, (int) (getParentWidth() * 0.7f));
  60940. const int textLayoutH = textLayout.getHeight();
  60941. const int textBottom = 16 + titleH + textLayoutH;
  60942. int h = textBottom;
  60943. int buttonW = 40;
  60944. int i;
  60945. for (i = 0; i < buttons.size(); ++i)
  60946. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  60947. w = jmax (buttonW, w);
  60948. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  60949. if (buttons.size() > 0)
  60950. h += 20 + ((TextButton*) buttons[0])->getHeight();
  60951. for (i = customComps.size(); --i >= 0;)
  60952. {
  60953. Component* c = (Component*) customComps[i];
  60954. w = jmax (w, (c->getWidth() * 100) / 80);
  60955. h += 10 + c->getHeight();
  60956. if (c->getName().isNotEmpty())
  60957. h += labelHeight;
  60958. }
  60959. for (i = textBlocks.size(); --i >= 0;)
  60960. {
  60961. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  60962. w = jmax (w, ac->getPreferredWidth());
  60963. }
  60964. w = jmin (w, (int) (getParentWidth() * 0.7f));
  60965. for (i = textBlocks.size(); --i >= 0;)
  60966. {
  60967. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  60968. ac->updateLayout ((int) (w * 0.8f));
  60969. h += ac->getHeight() + 10;
  60970. }
  60971. h = jmin (getParentHeight() - 50, h);
  60972. if (onlyIncreaseSize)
  60973. {
  60974. w = jmax (w, getWidth());
  60975. h = jmax (h, getHeight());
  60976. }
  60977. if (! isVisible())
  60978. {
  60979. centreAroundComponent (associatedComponent, w, h);
  60980. }
  60981. else
  60982. {
  60983. const int cx = getX() + getWidth() / 2;
  60984. const int cy = getY() + getHeight() / 2;
  60985. setBounds (cx - w / 2,
  60986. cy - h / 2,
  60987. w, h);
  60988. }
  60989. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  60990. const int spacer = 16;
  60991. int totalWidth = -spacer;
  60992. for (i = buttons.size(); --i >= 0;)
  60993. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  60994. int x = (w - totalWidth) / 2;
  60995. int y = (int) (getHeight() * 0.95f);
  60996. for (i = 0; i < buttons.size(); ++i)
  60997. {
  60998. TextButton* const c = (TextButton*) buttons[i];
  60999. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61000. c->setTopLeftPosition (x, ny);
  61001. if (ny < y)
  61002. y = ny;
  61003. x += c->getWidth() + spacer;
  61004. c->toFront (false);
  61005. }
  61006. y = textBottom;
  61007. for (i = 0; i < allComps.size(); ++i)
  61008. {
  61009. Component* const c = (Component*) allComps[i];
  61010. int h = 22;
  61011. const int comboIndex = comboBoxes.indexOf (c);
  61012. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61013. y += labelHeight;
  61014. const int tbIndex = textBoxes.indexOf (c);
  61015. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61016. y += labelHeight;
  61017. if (customComps.contains (c))
  61018. {
  61019. if (c->getName().isNotEmpty())
  61020. y += labelHeight;
  61021. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61022. h = c->getHeight();
  61023. }
  61024. else if (textBlocks.contains (c))
  61025. {
  61026. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61027. h = c->getHeight();
  61028. }
  61029. else
  61030. {
  61031. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61032. }
  61033. y += h + 10;
  61034. }
  61035. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61036. }
  61037. bool AlertWindow::containsAnyExtraComponents() const
  61038. {
  61039. return textBoxes.size()
  61040. + comboBoxes.size()
  61041. + progressBars.size()
  61042. + customComps.size() > 0;
  61043. }
  61044. void AlertWindow::mouseDown (const MouseEvent&)
  61045. {
  61046. dragger.startDraggingComponent (this, &constrainer);
  61047. }
  61048. void AlertWindow::mouseDrag (const MouseEvent& e)
  61049. {
  61050. dragger.dragComponent (this, e);
  61051. }
  61052. bool AlertWindow::keyPressed (const KeyPress& key)
  61053. {
  61054. for (int i = buttons.size(); --i >= 0;)
  61055. {
  61056. TextButton* const b = (TextButton*) buttons[i];
  61057. if (b->isRegisteredForShortcut (key))
  61058. {
  61059. b->triggerClick();
  61060. return true;
  61061. }
  61062. }
  61063. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61064. {
  61065. exitModalState (0);
  61066. return true;
  61067. }
  61068. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61069. {
  61070. ((TextButton*) buttons.getFirst())->triggerClick();
  61071. return true;
  61072. }
  61073. return false;
  61074. }
  61075. void AlertWindow::lookAndFeelChanged()
  61076. {
  61077. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61078. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61079. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61080. }
  61081. int AlertWindow::getDesktopWindowStyleFlags() const
  61082. {
  61083. return getLookAndFeel().getAlertBoxWindowFlags();
  61084. }
  61085. struct AlertWindowInfo
  61086. {
  61087. String title, message, button1, button2, button3;
  61088. AlertWindow::AlertIconType iconType;
  61089. int numButtons;
  61090. Component::SafePointer<Component> associatedComponent;
  61091. int run() const
  61092. {
  61093. return (int) (pointer_sized_int)
  61094. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61095. }
  61096. private:
  61097. int show() const
  61098. {
  61099. LookAndFeel& lf = associatedComponent != 0 ? associatedComponent->getLookAndFeel()
  61100. : LookAndFeel::getDefaultLookAndFeel();
  61101. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61102. iconType, numButtons, associatedComponent));
  61103. jassert (alertBox != 0); // you have to return one of these!
  61104. return alertBox->runModalLoop();
  61105. }
  61106. static void* showCallback (void* userData)
  61107. {
  61108. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61109. }
  61110. };
  61111. void AlertWindow::showMessageBox (AlertIconType iconType,
  61112. const String& title,
  61113. const String& message,
  61114. const String& buttonText,
  61115. Component* associatedComponent)
  61116. {
  61117. AlertWindowInfo info;
  61118. info.title = title;
  61119. info.message = message;
  61120. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61121. info.iconType = iconType;
  61122. info.numButtons = 1;
  61123. info.associatedComponent = associatedComponent;
  61124. info.run();
  61125. }
  61126. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61127. const String& title,
  61128. const String& message,
  61129. const String& button1Text,
  61130. const String& button2Text,
  61131. Component* associatedComponent)
  61132. {
  61133. AlertWindowInfo info;
  61134. info.title = title;
  61135. info.message = message;
  61136. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61137. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61138. info.iconType = iconType;
  61139. info.numButtons = 2;
  61140. info.associatedComponent = associatedComponent;
  61141. return info.run() != 0;
  61142. }
  61143. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61144. const String& title,
  61145. const String& message,
  61146. const String& button1Text,
  61147. const String& button2Text,
  61148. const String& button3Text,
  61149. Component* associatedComponent)
  61150. {
  61151. AlertWindowInfo info;
  61152. info.title = title;
  61153. info.message = message;
  61154. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61155. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61156. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61157. info.iconType = iconType;
  61158. info.numButtons = 3;
  61159. info.associatedComponent = associatedComponent;
  61160. return info.run();
  61161. }
  61162. END_JUCE_NAMESPACE
  61163. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61164. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61165. BEGIN_JUCE_NAMESPACE
  61166. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61167. static VoidArray heavyweightPeers;
  61168. ComponentPeer::ComponentPeer (Component* const component_,
  61169. const int styleFlags_) throw()
  61170. : component (component_),
  61171. styleFlags (styleFlags_),
  61172. lastPaintTime (0),
  61173. constrainer (0),
  61174. lastDragAndDropCompUnderMouse (0),
  61175. fakeMouseMessageSent (false),
  61176. isWindowMinimised (false)
  61177. {
  61178. heavyweightPeers.add (this);
  61179. }
  61180. ComponentPeer::~ComponentPeer()
  61181. {
  61182. heavyweightPeers.removeValue (this);
  61183. Desktop::getInstance().triggerFocusCallback();
  61184. }
  61185. int ComponentPeer::getNumPeers() throw()
  61186. {
  61187. return heavyweightPeers.size();
  61188. }
  61189. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61190. {
  61191. return (ComponentPeer*) heavyweightPeers [index];
  61192. }
  61193. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61194. {
  61195. for (int i = heavyweightPeers.size(); --i >= 0;)
  61196. {
  61197. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61198. if (peer->getComponent() == component)
  61199. return peer;
  61200. }
  61201. return 0;
  61202. }
  61203. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61204. {
  61205. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61206. }
  61207. void ComponentPeer::updateCurrentModifiers() throw()
  61208. {
  61209. ModifierKeys::updateCurrentModifiers();
  61210. }
  61211. void ComponentPeer::handleMouseEvent (const int touchIndex, const Point<int>& positionWithinPeer, const ModifierKeys& newMods, const int64 time)
  61212. {
  61213. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61214. jassert (mouse != 0); // not enough sources!
  61215. mouse->handleEvent (this, positionWithinPeer, time, newMods);
  61216. }
  61217. void ComponentPeer::handleMouseWheel (const int touchIndex, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  61218. {
  61219. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61220. jassert (mouse != 0); // not enough sources!
  61221. mouse->handleWheel (this, positionWithinPeer, time, x, y);
  61222. }
  61223. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61224. {
  61225. Graphics g (&contextToPaintTo);
  61226. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61227. g.saveState();
  61228. #endif
  61229. JUCE_TRY
  61230. {
  61231. component->paintEntireComponent (g);
  61232. }
  61233. JUCE_CATCH_EXCEPTION
  61234. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61235. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61236. // clearly when things are being repainted.
  61237. {
  61238. g.restoreState();
  61239. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61240. (uint8) Random::getSystemRandom().nextInt (255),
  61241. (uint8) Random::getSystemRandom().nextInt (255),
  61242. (uint8) 0x50));
  61243. }
  61244. #endif
  61245. }
  61246. bool ComponentPeer::handleKeyPress (const int keyCode,
  61247. const juce_wchar textCharacter)
  61248. {
  61249. updateCurrentModifiers();
  61250. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61251. ? Component::getCurrentlyFocusedComponent()
  61252. : component;
  61253. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61254. {
  61255. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61256. if (currentModalComp != 0)
  61257. target = currentModalComp;
  61258. }
  61259. const KeyPress keyInfo (keyCode,
  61260. ModifierKeys::getCurrentModifiers().getRawFlags()
  61261. & ModifierKeys::allKeyboardModifiers,
  61262. textCharacter);
  61263. bool keyWasUsed = false;
  61264. while (target != 0)
  61265. {
  61266. const Component::SafePointer<Component> deletionChecker (target);
  61267. if (target->keyListeners_ != 0)
  61268. {
  61269. for (int i = target->keyListeners_->size(); --i >= 0;)
  61270. {
  61271. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61272. if (keyWasUsed || deletionChecker == 0)
  61273. return keyWasUsed;
  61274. i = jmin (i, target->keyListeners_->size());
  61275. }
  61276. }
  61277. keyWasUsed = target->keyPressed (keyInfo);
  61278. if (keyWasUsed || deletionChecker == 0)
  61279. break;
  61280. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61281. {
  61282. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61283. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61284. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61285. break;
  61286. }
  61287. target = target->parentComponent_;
  61288. }
  61289. return keyWasUsed;
  61290. }
  61291. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61292. {
  61293. updateCurrentModifiers();
  61294. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61295. ? Component::getCurrentlyFocusedComponent()
  61296. : component;
  61297. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61298. {
  61299. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61300. if (currentModalComp != 0)
  61301. target = currentModalComp;
  61302. }
  61303. bool keyWasUsed = false;
  61304. while (target != 0)
  61305. {
  61306. const Component::SafePointer<Component> deletionChecker (target);
  61307. keyWasUsed = target->keyStateChanged (isKeyDown);
  61308. if (keyWasUsed || deletionChecker == 0)
  61309. break;
  61310. if (target->keyListeners_ != 0)
  61311. {
  61312. for (int i = target->keyListeners_->size(); --i >= 0;)
  61313. {
  61314. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61315. if (keyWasUsed || deletionChecker == 0)
  61316. return keyWasUsed;
  61317. i = jmin (i, target->keyListeners_->size());
  61318. }
  61319. }
  61320. target = target->parentComponent_;
  61321. }
  61322. return keyWasUsed;
  61323. }
  61324. void ComponentPeer::handleModifierKeysChange()
  61325. {
  61326. updateCurrentModifiers();
  61327. Component* target = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  61328. if (target == 0)
  61329. target = Component::getCurrentlyFocusedComponent();
  61330. if (target == 0)
  61331. target = component;
  61332. if (target != 0)
  61333. target->internalModifierKeysChanged();
  61334. }
  61335. TextInputTarget* ComponentPeer::findCurrentTextInputTarget()
  61336. {
  61337. Component* const c = Component::getCurrentlyFocusedComponent();
  61338. if (component->isParentOf (c))
  61339. return dynamic_cast <TextInputTarget*> (c);
  61340. return 0;
  61341. }
  61342. void ComponentPeer::handleBroughtToFront()
  61343. {
  61344. updateCurrentModifiers();
  61345. if (component != 0)
  61346. component->internalBroughtToFront();
  61347. }
  61348. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61349. {
  61350. constrainer = newConstrainer;
  61351. }
  61352. void ComponentPeer::handleMovedOrResized()
  61353. {
  61354. jassert (component->isValidComponent());
  61355. updateCurrentModifiers();
  61356. const bool nowMinimised = isMinimised();
  61357. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61358. {
  61359. const Component::SafePointer<Component> deletionChecker (component);
  61360. const Rectangle<int> newBounds (getBounds());
  61361. const bool wasMoved = (component->getPosition() != newBounds.getPosition());
  61362. const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight());
  61363. if (wasMoved || wasResized)
  61364. {
  61365. component->bounds_ = newBounds;
  61366. if (wasResized)
  61367. component->repaint();
  61368. component->sendMovedResizedMessages (wasMoved, wasResized);
  61369. if (deletionChecker == 0)
  61370. return;
  61371. }
  61372. }
  61373. if (isWindowMinimised != nowMinimised)
  61374. {
  61375. isWindowMinimised = nowMinimised;
  61376. component->minimisationStateChanged (nowMinimised);
  61377. component->sendVisibilityChangeMessage();
  61378. }
  61379. if (! isFullScreen())
  61380. lastNonFullscreenBounds = component->getBounds();
  61381. }
  61382. void ComponentPeer::handleFocusGain()
  61383. {
  61384. updateCurrentModifiers();
  61385. if (component->isParentOf (lastFocusedComponent))
  61386. {
  61387. Component::currentlyFocusedComponent = lastFocusedComponent;
  61388. Desktop::getInstance().triggerFocusCallback();
  61389. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61390. }
  61391. else
  61392. {
  61393. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61394. component->grabKeyboardFocus();
  61395. else
  61396. Component::bringModalComponentToFront();
  61397. }
  61398. }
  61399. void ComponentPeer::handleFocusLoss()
  61400. {
  61401. updateCurrentModifiers();
  61402. if (component->hasKeyboardFocus (true))
  61403. {
  61404. lastFocusedComponent = Component::currentlyFocusedComponent;
  61405. if (lastFocusedComponent != 0)
  61406. {
  61407. Component::currentlyFocusedComponent = 0;
  61408. Desktop::getInstance().triggerFocusCallback();
  61409. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61410. }
  61411. }
  61412. }
  61413. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61414. {
  61415. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61416. ? static_cast <Component*> (lastFocusedComponent)
  61417. : component;
  61418. }
  61419. void ComponentPeer::handleScreenSizeChange()
  61420. {
  61421. updateCurrentModifiers();
  61422. component->parentSizeChanged();
  61423. handleMovedOrResized();
  61424. }
  61425. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61426. {
  61427. lastNonFullscreenBounds = newBounds;
  61428. }
  61429. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61430. {
  61431. return lastNonFullscreenBounds;
  61432. }
  61433. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61434. const StringArray& files,
  61435. FileDragAndDropTarget* const lastOne)
  61436. {
  61437. while (c != 0)
  61438. {
  61439. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61440. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61441. return t;
  61442. c = c->getParentComponent();
  61443. }
  61444. return 0;
  61445. }
  61446. void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<int>& position)
  61447. {
  61448. updateCurrentModifiers();
  61449. FileDragAndDropTarget* lastTarget
  61450. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61451. FileDragAndDropTarget* newTarget = 0;
  61452. Component* const compUnderMouse = component->getComponentAt (position);
  61453. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61454. {
  61455. lastDragAndDropCompUnderMouse = compUnderMouse;
  61456. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61457. if (newTarget != lastTarget)
  61458. {
  61459. if (lastTarget != 0)
  61460. lastTarget->fileDragExit (files);
  61461. dragAndDropTargetComponent = 0;
  61462. if (newTarget != 0)
  61463. {
  61464. dragAndDropTargetComponent = dynamic_cast <Component*> (newTarget);
  61465. const Point<int> pos (component->relativePositionToOtherComponent (dragAndDropTargetComponent, position));
  61466. newTarget->fileDragEnter (files, pos.getX(), pos.getY());
  61467. }
  61468. }
  61469. }
  61470. else
  61471. {
  61472. newTarget = lastTarget;
  61473. }
  61474. if (newTarget != 0)
  61475. {
  61476. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61477. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61478. newTarget->fileDragMove (files, pos.getX(), pos.getY());
  61479. }
  61480. }
  61481. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61482. {
  61483. handleFileDragMove (files, Point<int> (-1, -1));
  61484. jassert (dragAndDropTargetComponent == 0);
  61485. lastDragAndDropCompUnderMouse = 0;
  61486. }
  61487. void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
  61488. {
  61489. handleFileDragMove (files, position);
  61490. if (dragAndDropTargetComponent != 0)
  61491. {
  61492. FileDragAndDropTarget* const target
  61493. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61494. dragAndDropTargetComponent = 0;
  61495. lastDragAndDropCompUnderMouse = 0;
  61496. if (target != 0)
  61497. {
  61498. Component* const targetComp = dynamic_cast <Component*> (target);
  61499. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61500. {
  61501. targetComp->internalModalInputAttempt();
  61502. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61503. return;
  61504. }
  61505. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61506. target->filesDropped (files, pos.getX(), pos.getY());
  61507. }
  61508. }
  61509. }
  61510. void ComponentPeer::handleUserClosingWindow()
  61511. {
  61512. updateCurrentModifiers();
  61513. component->userTriedToCloseWindow();
  61514. }
  61515. void ComponentPeer::bringModalComponentToFront()
  61516. {
  61517. Component::bringModalComponentToFront();
  61518. }
  61519. void ComponentPeer::clearMaskedRegion() throw()
  61520. {
  61521. maskedRegion.clear();
  61522. }
  61523. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  61524. {
  61525. maskedRegion.add (x, y, w, h);
  61526. }
  61527. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  61528. {
  61529. StringArray s;
  61530. s.add ("Software Renderer");
  61531. return s;
  61532. }
  61533. int ComponentPeer::getCurrentRenderingEngine() throw()
  61534. {
  61535. return 0;
  61536. }
  61537. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  61538. {
  61539. }
  61540. END_JUCE_NAMESPACE
  61541. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  61542. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  61543. BEGIN_JUCE_NAMESPACE
  61544. DialogWindow::DialogWindow (const String& name,
  61545. const Colour& backgroundColour_,
  61546. const bool escapeKeyTriggersCloseButton_,
  61547. const bool addToDesktop_)
  61548. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  61549. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  61550. {
  61551. }
  61552. DialogWindow::~DialogWindow()
  61553. {
  61554. }
  61555. void DialogWindow::resized()
  61556. {
  61557. DocumentWindow::resized();
  61558. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  61559. if (escapeKeyTriggersCloseButton
  61560. && getCloseButton() != 0
  61561. && ! getCloseButton()->isRegisteredForShortcut (esc))
  61562. {
  61563. getCloseButton()->addShortcut (esc);
  61564. }
  61565. }
  61566. class TempDialogWindow : public DialogWindow
  61567. {
  61568. public:
  61569. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  61570. : DialogWindow (title, colour, escapeCloses, true)
  61571. {
  61572. }
  61573. ~TempDialogWindow()
  61574. {
  61575. }
  61576. void closeButtonPressed()
  61577. {
  61578. setVisible (false);
  61579. }
  61580. private:
  61581. TempDialogWindow (const TempDialogWindow&);
  61582. TempDialogWindow& operator= (const TempDialogWindow&);
  61583. };
  61584. int DialogWindow::showModalDialog (const String& dialogTitle,
  61585. Component* contentComponent,
  61586. Component* componentToCentreAround,
  61587. const Colour& colour,
  61588. const bool escapeKeyTriggersCloseButton,
  61589. const bool shouldBeResizable,
  61590. const bool useBottomRightCornerResizer)
  61591. {
  61592. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  61593. dw.setContentComponent (contentComponent, true, true);
  61594. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  61595. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  61596. const int result = dw.runModalLoop();
  61597. dw.setContentComponent (0, false);
  61598. return result;
  61599. }
  61600. END_JUCE_NAMESPACE
  61601. /*** End of inlined file: juce_DialogWindow.cpp ***/
  61602. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  61603. BEGIN_JUCE_NAMESPACE
  61604. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  61605. {
  61606. public:
  61607. ButtonListenerProxy (DocumentWindow& owner_)
  61608. : owner (owner_)
  61609. {
  61610. }
  61611. void buttonClicked (Button* button)
  61612. {
  61613. if (button == owner.getMinimiseButton())
  61614. owner.minimiseButtonPressed();
  61615. else if (button == owner.getMaximiseButton())
  61616. owner.maximiseButtonPressed();
  61617. else if (button == owner.getCloseButton())
  61618. owner.closeButtonPressed();
  61619. }
  61620. juce_UseDebuggingNewOperator
  61621. private:
  61622. DocumentWindow& owner;
  61623. ButtonListenerProxy (const ButtonListenerProxy&);
  61624. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  61625. };
  61626. DocumentWindow::DocumentWindow (const String& title,
  61627. const Colour& backgroundColour,
  61628. const int requiredButtons_,
  61629. const bool addToDesktop_)
  61630. : ResizableWindow (title, backgroundColour, addToDesktop_),
  61631. titleBarHeight (26),
  61632. menuBarHeight (24),
  61633. requiredButtons (requiredButtons_),
  61634. #if JUCE_MAC
  61635. positionTitleBarButtonsOnLeft (true),
  61636. #else
  61637. positionTitleBarButtonsOnLeft (false),
  61638. #endif
  61639. drawTitleTextCentred (true),
  61640. menuBarModel (0)
  61641. {
  61642. setResizeLimits (128, 128, 32768, 32768);
  61643. lookAndFeelChanged();
  61644. }
  61645. DocumentWindow::~DocumentWindow()
  61646. {
  61647. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61648. titleBarButtons[i] = 0;
  61649. menuBar = 0;
  61650. }
  61651. void DocumentWindow::repaintTitleBar()
  61652. {
  61653. const Rectangle<int> titleBarArea (getTitleBarArea());
  61654. repaint (titleBarArea.getX(), titleBarArea.getY(),
  61655. titleBarArea.getWidth(), titleBarArea.getHeight());
  61656. }
  61657. void DocumentWindow::setName (const String& newName)
  61658. {
  61659. if (newName != getName())
  61660. {
  61661. Component::setName (newName);
  61662. repaintTitleBar();
  61663. }
  61664. }
  61665. void DocumentWindow::setIcon (const Image* imageToUse)
  61666. {
  61667. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  61668. repaintTitleBar();
  61669. }
  61670. void DocumentWindow::setTitleBarHeight (const int newHeight)
  61671. {
  61672. titleBarHeight = newHeight;
  61673. resized();
  61674. repaintTitleBar();
  61675. }
  61676. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  61677. const bool positionTitleBarButtonsOnLeft_)
  61678. {
  61679. requiredButtons = requiredButtons_;
  61680. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  61681. lookAndFeelChanged();
  61682. }
  61683. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  61684. {
  61685. drawTitleTextCentred = textShouldBeCentred;
  61686. repaintTitleBar();
  61687. }
  61688. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  61689. const int menuBarHeight_)
  61690. {
  61691. if (menuBarModel != menuBarModel_)
  61692. {
  61693. menuBar = 0;
  61694. menuBarModel = menuBarModel_;
  61695. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  61696. : getLookAndFeel().getDefaultMenuBarHeight();
  61697. if (menuBarModel != 0)
  61698. {
  61699. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61700. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  61701. menuBar->setEnabled (isActiveWindow());
  61702. }
  61703. resized();
  61704. }
  61705. }
  61706. void DocumentWindow::closeButtonPressed()
  61707. {
  61708. /* If you've got a close button, you have to override this method to get
  61709. rid of your window!
  61710. If the window is just a pop-up, you should override this method and make
  61711. it delete the window in whatever way is appropriate for your app. E.g. you
  61712. might just want to call "delete this".
  61713. If your app is centred around this window such that the whole app should quit when
  61714. the window is closed, then you will probably want to use this method as an opportunity
  61715. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  61716. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  61717. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  61718. or closing it via the taskbar icon on Windows).
  61719. */
  61720. jassertfalse
  61721. }
  61722. void DocumentWindow::minimiseButtonPressed()
  61723. {
  61724. setMinimised (true);
  61725. }
  61726. void DocumentWindow::maximiseButtonPressed()
  61727. {
  61728. setFullScreen (! isFullScreen());
  61729. }
  61730. void DocumentWindow::paint (Graphics& g)
  61731. {
  61732. ResizableWindow::paint (g);
  61733. if (resizableBorder == 0)
  61734. {
  61735. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  61736. const BorderSize border (getBorderThickness());
  61737. g.fillRect (0, 0, getWidth(), border.getTop());
  61738. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  61739. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  61740. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  61741. }
  61742. const Rectangle<int> titleBarArea (getTitleBarArea());
  61743. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  61744. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  61745. int titleSpaceX1 = 6;
  61746. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  61747. for (int i = 0; i < 3; ++i)
  61748. {
  61749. if (titleBarButtons[i] != 0)
  61750. {
  61751. if (positionTitleBarButtonsOnLeft)
  61752. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  61753. else
  61754. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  61755. }
  61756. }
  61757. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  61758. titleBarArea.getWidth(),
  61759. titleBarArea.getHeight(),
  61760. titleSpaceX1,
  61761. jmax (1, titleSpaceX2 - titleSpaceX1),
  61762. titleBarIcon,
  61763. ! drawTitleTextCentred);
  61764. }
  61765. void DocumentWindow::resized()
  61766. {
  61767. ResizableWindow::resized();
  61768. if (titleBarButtons[1] != 0)
  61769. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  61770. const Rectangle<int> titleBarArea (getTitleBarArea());
  61771. getLookAndFeel()
  61772. .positionDocumentWindowButtons (*this,
  61773. titleBarArea.getX(), titleBarArea.getY(),
  61774. titleBarArea.getWidth(), titleBarArea.getHeight(),
  61775. titleBarButtons[0],
  61776. titleBarButtons[1],
  61777. titleBarButtons[2],
  61778. positionTitleBarButtonsOnLeft);
  61779. if (menuBar != 0)
  61780. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  61781. titleBarArea.getWidth(), menuBarHeight);
  61782. }
  61783. const BorderSize DocumentWindow::getBorderThickness()
  61784. {
  61785. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  61786. ? 0 : (resizableBorder != 0 ? 4 : 1));
  61787. }
  61788. const BorderSize DocumentWindow::getContentComponentBorder()
  61789. {
  61790. BorderSize border (getBorderThickness());
  61791. border.setTop (border.getTop()
  61792. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  61793. + (menuBar != 0 ? menuBarHeight : 0));
  61794. return border;
  61795. }
  61796. int DocumentWindow::getTitleBarHeight() const
  61797. {
  61798. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  61799. }
  61800. const Rectangle<int> DocumentWindow::getTitleBarArea()
  61801. {
  61802. const BorderSize border (getBorderThickness());
  61803. return Rectangle<int> (border.getLeft(), border.getTop(),
  61804. getWidth() - border.getLeftAndRight(),
  61805. getTitleBarHeight());
  61806. }
  61807. Button* DocumentWindow::getCloseButton() const throw()
  61808. {
  61809. return titleBarButtons[2];
  61810. }
  61811. Button* DocumentWindow::getMinimiseButton() const throw()
  61812. {
  61813. return titleBarButtons[0];
  61814. }
  61815. Button* DocumentWindow::getMaximiseButton() const throw()
  61816. {
  61817. return titleBarButtons[1];
  61818. }
  61819. int DocumentWindow::getDesktopWindowStyleFlags() const
  61820. {
  61821. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  61822. if ((requiredButtons & minimiseButton) != 0)
  61823. flags |= ComponentPeer::windowHasMinimiseButton;
  61824. if ((requiredButtons & maximiseButton) != 0)
  61825. flags |= ComponentPeer::windowHasMaximiseButton;
  61826. if ((requiredButtons & closeButton) != 0)
  61827. flags |= ComponentPeer::windowHasCloseButton;
  61828. return flags;
  61829. }
  61830. void DocumentWindow::lookAndFeelChanged()
  61831. {
  61832. int i;
  61833. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  61834. titleBarButtons[i] = 0;
  61835. if (! isUsingNativeTitleBar())
  61836. {
  61837. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  61838. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  61839. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  61840. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  61841. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  61842. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  61843. for (i = 0; i < 3; ++i)
  61844. {
  61845. if (titleBarButtons[i] != 0)
  61846. {
  61847. if (buttonListener == 0)
  61848. buttonListener = new ButtonListenerProxy (*this);
  61849. titleBarButtons[i]->addButtonListener (buttonListener);
  61850. titleBarButtons[i]->setWantsKeyboardFocus (false);
  61851. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61852. Component::addAndMakeVisible (titleBarButtons[i]);
  61853. }
  61854. }
  61855. if (getCloseButton() != 0)
  61856. {
  61857. #if JUCE_MAC
  61858. getCloseButton()->addShortcut (KeyPress (T('w'), ModifierKeys::commandModifier, 0));
  61859. #else
  61860. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  61861. #endif
  61862. }
  61863. }
  61864. activeWindowStatusChanged();
  61865. ResizableWindow::lookAndFeelChanged();
  61866. }
  61867. void DocumentWindow::parentHierarchyChanged()
  61868. {
  61869. lookAndFeelChanged();
  61870. }
  61871. void DocumentWindow::activeWindowStatusChanged()
  61872. {
  61873. ResizableWindow::activeWindowStatusChanged();
  61874. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61875. if (titleBarButtons[i] != 0)
  61876. titleBarButtons[i]->setEnabled (isActiveWindow());
  61877. if (menuBar != 0)
  61878. menuBar->setEnabled (isActiveWindow());
  61879. }
  61880. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  61881. {
  61882. if (getTitleBarArea().contains (e.x, e.y)
  61883. && getMaximiseButton() != 0)
  61884. {
  61885. getMaximiseButton()->triggerClick();
  61886. }
  61887. }
  61888. void DocumentWindow::userTriedToCloseWindow()
  61889. {
  61890. closeButtonPressed();
  61891. }
  61892. END_JUCE_NAMESPACE
  61893. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  61894. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  61895. BEGIN_JUCE_NAMESPACE
  61896. ResizableWindow::ResizableWindow (const String& name,
  61897. const bool addToDesktop_)
  61898. : TopLevelWindow (name, addToDesktop_),
  61899. resizeToFitContent (false),
  61900. fullscreen (false),
  61901. lastNonFullScreenPos (50, 50, 256, 256),
  61902. constrainer (0)
  61903. #ifdef JUCE_DEBUG
  61904. , hasBeenResized (false)
  61905. #endif
  61906. {
  61907. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61908. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  61909. if (addToDesktop_)
  61910. Component::addToDesktop (getDesktopWindowStyleFlags());
  61911. }
  61912. ResizableWindow::ResizableWindow (const String& name,
  61913. const Colour& backgroundColour_,
  61914. const bool addToDesktop_)
  61915. : TopLevelWindow (name, addToDesktop_),
  61916. resizeToFitContent (false),
  61917. fullscreen (false),
  61918. lastNonFullScreenPos (50, 50, 256, 256),
  61919. constrainer (0)
  61920. #ifdef JUCE_DEBUG
  61921. , hasBeenResized (false)
  61922. #endif
  61923. {
  61924. setBackgroundColour (backgroundColour_);
  61925. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61926. if (addToDesktop_)
  61927. Component::addToDesktop (getDesktopWindowStyleFlags());
  61928. }
  61929. ResizableWindow::~ResizableWindow()
  61930. {
  61931. resizableCorner = 0;
  61932. resizableBorder = 0;
  61933. contentComponent = 0;
  61934. // have you been adding your own components directly to this window..? tut tut tut.
  61935. // Read the instructions for using a ResizableWindow!
  61936. jassert (getNumChildComponents() == 0);
  61937. }
  61938. int ResizableWindow::getDesktopWindowStyleFlags() const
  61939. {
  61940. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  61941. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  61942. flags |= ComponentPeer::windowIsResizable;
  61943. return flags;
  61944. }
  61945. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  61946. const bool deleteOldOne,
  61947. const bool resizeToFit)
  61948. {
  61949. resizeToFitContent = resizeToFit;
  61950. if (newContentComponent != (Component*) contentComponent)
  61951. {
  61952. if (! deleteOldOne)
  61953. removeChildComponent (contentComponent.release());
  61954. contentComponent = newContentComponent;
  61955. Component::addAndMakeVisible (contentComponent);
  61956. }
  61957. if (resizeToFit)
  61958. childBoundsChanged (contentComponent);
  61959. resized(); // must always be called to position the new content comp
  61960. }
  61961. void ResizableWindow::setContentComponentSize (int width, int height)
  61962. {
  61963. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  61964. const BorderSize border (getContentComponentBorder());
  61965. setSize (width + border.getLeftAndRight(),
  61966. height + border.getTopAndBottom());
  61967. }
  61968. const BorderSize ResizableWindow::getBorderThickness()
  61969. {
  61970. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  61971. }
  61972. const BorderSize ResizableWindow::getContentComponentBorder()
  61973. {
  61974. return getBorderThickness();
  61975. }
  61976. void ResizableWindow::moved()
  61977. {
  61978. updateLastPos();
  61979. }
  61980. void ResizableWindow::visibilityChanged()
  61981. {
  61982. TopLevelWindow::visibilityChanged();
  61983. updateLastPos();
  61984. }
  61985. void ResizableWindow::resized()
  61986. {
  61987. if (resizableBorder != 0)
  61988. {
  61989. resizableBorder->setVisible (! isFullScreen());
  61990. resizableBorder->setBorderThickness (getBorderThickness());
  61991. resizableBorder->setSize (getWidth(), getHeight());
  61992. resizableBorder->toBack();
  61993. }
  61994. if (resizableCorner != 0)
  61995. {
  61996. resizableCorner->setVisible (! isFullScreen());
  61997. const int resizerSize = 18;
  61998. resizableCorner->setBounds (getWidth() - resizerSize,
  61999. getHeight() - resizerSize,
  62000. resizerSize, resizerSize);
  62001. }
  62002. if (contentComponent != 0)
  62003. contentComponent->setBoundsInset (getContentComponentBorder());
  62004. updateLastPos();
  62005. #ifdef JUCE_DEBUG
  62006. hasBeenResized = true;
  62007. #endif
  62008. }
  62009. void ResizableWindow::childBoundsChanged (Component* child)
  62010. {
  62011. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62012. {
  62013. // not going to look very good if this component has a zero size..
  62014. jassert (child->getWidth() > 0);
  62015. jassert (child->getHeight() > 0);
  62016. const BorderSize borders (getContentComponentBorder());
  62017. setSize (child->getWidth() + borders.getLeftAndRight(),
  62018. child->getHeight() + borders.getTopAndBottom());
  62019. }
  62020. }
  62021. void ResizableWindow::activeWindowStatusChanged()
  62022. {
  62023. const BorderSize borders (getContentComponentBorder());
  62024. repaint (0, 0, getWidth(), borders.getTop());
  62025. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62026. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62027. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62028. }
  62029. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62030. const bool useBottomRightCornerResizer)
  62031. {
  62032. if (shouldBeResizable)
  62033. {
  62034. if (useBottomRightCornerResizer)
  62035. {
  62036. resizableBorder = 0;
  62037. if (resizableCorner == 0)
  62038. {
  62039. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62040. resizableCorner->setAlwaysOnTop (true);
  62041. }
  62042. }
  62043. else
  62044. {
  62045. resizableCorner = 0;
  62046. if (resizableBorder == 0)
  62047. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62048. }
  62049. }
  62050. else
  62051. {
  62052. resizableCorner = 0;
  62053. resizableBorder = 0;
  62054. }
  62055. if (isUsingNativeTitleBar())
  62056. recreateDesktopWindow();
  62057. childBoundsChanged (contentComponent);
  62058. resized();
  62059. }
  62060. bool ResizableWindow::isResizable() const throw()
  62061. {
  62062. return resizableCorner != 0
  62063. || resizableBorder != 0;
  62064. }
  62065. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62066. const int newMinimumHeight,
  62067. const int newMaximumWidth,
  62068. const int newMaximumHeight) throw()
  62069. {
  62070. // if you've set up a custom constrainer then these settings won't have any effect..
  62071. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62072. if (constrainer == 0)
  62073. setConstrainer (&defaultConstrainer);
  62074. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62075. newMaximumWidth, newMaximumHeight);
  62076. setBoundsConstrained (getBounds());
  62077. }
  62078. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62079. {
  62080. if (constrainer != newConstrainer)
  62081. {
  62082. constrainer = newConstrainer;
  62083. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62084. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62085. resizableCorner = 0;
  62086. resizableBorder = 0;
  62087. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62088. ComponentPeer* const peer = getPeer();
  62089. if (peer != 0)
  62090. peer->setConstrainer (newConstrainer);
  62091. }
  62092. }
  62093. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62094. {
  62095. if (constrainer != 0)
  62096. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62097. else
  62098. setBounds (bounds);
  62099. }
  62100. void ResizableWindow::paint (Graphics& g)
  62101. {
  62102. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62103. getBorderThickness(), *this);
  62104. if (! isFullScreen())
  62105. {
  62106. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62107. getBorderThickness(), *this);
  62108. }
  62109. #ifdef JUCE_DEBUG
  62110. /* If this fails, then you've probably written a subclass with a resized()
  62111. callback but forgotten to make it call its parent class's resized() method.
  62112. It's important when you override methods like resized(), moved(),
  62113. etc., that you make sure the base class methods also get called.
  62114. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62115. because your content should all be inside the content component - and it's the
  62116. content component's resized() method that you should be using to do your
  62117. layout.
  62118. */
  62119. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62120. #endif
  62121. }
  62122. void ResizableWindow::lookAndFeelChanged()
  62123. {
  62124. resized();
  62125. if (isOnDesktop())
  62126. {
  62127. Component::addToDesktop (getDesktopWindowStyleFlags());
  62128. ComponentPeer* const peer = getPeer();
  62129. if (peer != 0)
  62130. peer->setConstrainer (constrainer);
  62131. }
  62132. }
  62133. const Colour ResizableWindow::getBackgroundColour() const throw()
  62134. {
  62135. return findColour (backgroundColourId, false);
  62136. }
  62137. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62138. {
  62139. Colour backgroundColour (newColour);
  62140. if (! Desktop::canUseSemiTransparentWindows())
  62141. backgroundColour = newColour.withAlpha (1.0f);
  62142. setColour (backgroundColourId, backgroundColour);
  62143. setOpaque (backgroundColour.isOpaque());
  62144. repaint();
  62145. }
  62146. bool ResizableWindow::isFullScreen() const
  62147. {
  62148. if (isOnDesktop())
  62149. {
  62150. ComponentPeer* const peer = getPeer();
  62151. return peer != 0 && peer->isFullScreen();
  62152. }
  62153. return fullscreen;
  62154. }
  62155. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62156. {
  62157. if (shouldBeFullScreen != isFullScreen())
  62158. {
  62159. updateLastPos();
  62160. fullscreen = shouldBeFullScreen;
  62161. if (isOnDesktop())
  62162. {
  62163. ComponentPeer* const peer = getPeer();
  62164. if (peer != 0)
  62165. {
  62166. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62167. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62168. peer->setFullScreen (shouldBeFullScreen);
  62169. if (! shouldBeFullScreen)
  62170. setBounds (lastPos);
  62171. }
  62172. else
  62173. {
  62174. jassertfalse
  62175. }
  62176. }
  62177. else
  62178. {
  62179. if (shouldBeFullScreen)
  62180. setBounds (0, 0, getParentWidth(), getParentHeight());
  62181. else
  62182. setBounds (lastNonFullScreenPos);
  62183. }
  62184. resized();
  62185. }
  62186. }
  62187. bool ResizableWindow::isMinimised() const
  62188. {
  62189. ComponentPeer* const peer = getPeer();
  62190. return (peer != 0) && peer->isMinimised();
  62191. }
  62192. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62193. {
  62194. if (shouldMinimise != isMinimised())
  62195. {
  62196. ComponentPeer* const peer = getPeer();
  62197. if (peer != 0)
  62198. {
  62199. updateLastPos();
  62200. peer->setMinimised (shouldMinimise);
  62201. }
  62202. else
  62203. {
  62204. jassertfalse
  62205. }
  62206. }
  62207. }
  62208. void ResizableWindow::updateLastPos()
  62209. {
  62210. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62211. {
  62212. lastNonFullScreenPos = getBounds();
  62213. }
  62214. }
  62215. void ResizableWindow::parentSizeChanged()
  62216. {
  62217. if (isFullScreen() && getParentComponent() != 0)
  62218. {
  62219. setBounds (0, 0, getParentWidth(), getParentHeight());
  62220. }
  62221. }
  62222. const String ResizableWindow::getWindowStateAsString()
  62223. {
  62224. updateLastPos();
  62225. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62226. }
  62227. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62228. {
  62229. StringArray tokens;
  62230. tokens.addTokens (s, false);
  62231. tokens.removeEmptyStrings();
  62232. tokens.trim();
  62233. const bool fs = tokens[0].startsWithIgnoreCase (T("fs"));
  62234. const int firstCoord = fs ? 1 : 0;
  62235. if (tokens.size() != firstCoord + 4)
  62236. return false;
  62237. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62238. tokens[firstCoord + 1].getIntValue(),
  62239. tokens[firstCoord + 2].getIntValue(),
  62240. tokens[firstCoord + 3].getIntValue());
  62241. if (newPos.isEmpty())
  62242. return false;
  62243. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre()));
  62244. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62245. if (peer != 0)
  62246. peer->getFrameSize().addTo (newPos);
  62247. if (! screen.contains (newPos))
  62248. {
  62249. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62250. jmin (newPos.getHeight(), screen.getHeight()));
  62251. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62252. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62253. }
  62254. if (peer != 0)
  62255. {
  62256. peer->getFrameSize().subtractFrom (newPos);
  62257. peer->setNonFullScreenBounds (newPos);
  62258. }
  62259. lastNonFullScreenPos = newPos;
  62260. setFullScreen (fs);
  62261. if (! fs)
  62262. setBoundsConstrained (newPos);
  62263. return true;
  62264. }
  62265. void ResizableWindow::mouseDown (const MouseEvent&)
  62266. {
  62267. if (! isFullScreen())
  62268. dragger.startDraggingComponent (this, constrainer);
  62269. }
  62270. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62271. {
  62272. if (! isFullScreen())
  62273. dragger.dragComponent (this, e);
  62274. }
  62275. #ifdef JUCE_DEBUG
  62276. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62277. {
  62278. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62279. manages its child components automatically, and if you add your own it'll cause
  62280. trouble. Instead, use setContentComponent() to give it a component which
  62281. will be automatically resized and kept in the right place - then you can add
  62282. subcomponents to the content comp. See the notes for the ResizableWindow class
  62283. for more info.
  62284. If you really know what you're doing and want to avoid this assertion, just call
  62285. Component::addChildComponent directly.
  62286. */
  62287. jassertfalse
  62288. Component::addChildComponent (child, zOrder);
  62289. }
  62290. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62291. {
  62292. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62293. manages its child components automatically, and if you add your own it'll cause
  62294. trouble. Instead, use setContentComponent() to give it a component which
  62295. will be automatically resized and kept in the right place - then you can add
  62296. subcomponents to the content comp. See the notes for the ResizableWindow class
  62297. for more info.
  62298. If you really know what you're doing and want to avoid this assertion, just call
  62299. Component::addAndMakeVisible directly.
  62300. */
  62301. jassertfalse
  62302. Component::addAndMakeVisible (child, zOrder);
  62303. }
  62304. #endif
  62305. END_JUCE_NAMESPACE
  62306. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62307. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62308. BEGIN_JUCE_NAMESPACE
  62309. SplashScreen::SplashScreen()
  62310. : backgroundImage (0)
  62311. {
  62312. setOpaque (true);
  62313. }
  62314. SplashScreen::~SplashScreen()
  62315. {
  62316. ImageCache::releaseOrDelete (backgroundImage);
  62317. }
  62318. void SplashScreen::show (const String& title,
  62319. Image* const backgroundImage_,
  62320. const int minimumTimeToDisplayFor,
  62321. const bool useDropShadow,
  62322. const bool removeOnMouseClick)
  62323. {
  62324. backgroundImage = backgroundImage_;
  62325. jassert (backgroundImage_ != 0);
  62326. if (backgroundImage_ != 0)
  62327. {
  62328. setOpaque (! backgroundImage_->hasAlphaChannel());
  62329. show (title,
  62330. backgroundImage_->getWidth(),
  62331. backgroundImage_->getHeight(),
  62332. minimumTimeToDisplayFor,
  62333. useDropShadow,
  62334. removeOnMouseClick);
  62335. }
  62336. }
  62337. void SplashScreen::show (const String& title,
  62338. const int width,
  62339. const int height,
  62340. const int minimumTimeToDisplayFor,
  62341. const bool useDropShadow,
  62342. const bool removeOnMouseClick)
  62343. {
  62344. setName (title);
  62345. setAlwaysOnTop (true);
  62346. setVisible (true);
  62347. centreWithSize (width, height);
  62348. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62349. toFront (false);
  62350. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62351. repaint();
  62352. originalClickCounter = removeOnMouseClick
  62353. ? Desktop::getMouseButtonClickCounter()
  62354. : std::numeric_limits<int>::max();
  62355. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62356. startTimer (50);
  62357. }
  62358. void SplashScreen::paint (Graphics& g)
  62359. {
  62360. if (backgroundImage != 0)
  62361. {
  62362. g.setOpacity (1.0f);
  62363. g.drawImage (backgroundImage,
  62364. 0, 0, getWidth(), getHeight(),
  62365. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62366. }
  62367. }
  62368. void SplashScreen::timerCallback()
  62369. {
  62370. if (Time::getCurrentTime() > earliestTimeToDelete
  62371. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62372. {
  62373. delete this;
  62374. }
  62375. }
  62376. END_JUCE_NAMESPACE
  62377. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62378. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62379. BEGIN_JUCE_NAMESPACE
  62380. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62381. const bool hasProgressBar,
  62382. const bool hasCancelButton,
  62383. const int timeOutMsWhenCancelling_,
  62384. const String& cancelButtonText)
  62385. : Thread ("Juce Progress Window"),
  62386. progress (0.0),
  62387. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62388. {
  62389. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62390. .createAlertWindow (title, String::empty, cancelButtonText,
  62391. String::empty, String::empty,
  62392. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62393. if (hasProgressBar)
  62394. alertWindow->addProgressBarComponent (progress);
  62395. }
  62396. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62397. {
  62398. stopThread (timeOutMsWhenCancelling);
  62399. }
  62400. bool ThreadWithProgressWindow::runThread (const int priority)
  62401. {
  62402. startThread (priority);
  62403. startTimer (100);
  62404. {
  62405. const ScopedLock sl (messageLock);
  62406. alertWindow->setMessage (message);
  62407. }
  62408. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62409. stopThread (timeOutMsWhenCancelling);
  62410. alertWindow->setVisible (false);
  62411. return finishedNaturally;
  62412. }
  62413. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62414. {
  62415. progress = newProgress;
  62416. }
  62417. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62418. {
  62419. const ScopedLock sl (messageLock);
  62420. message = newStatusMessage;
  62421. }
  62422. void ThreadWithProgressWindow::timerCallback()
  62423. {
  62424. if (! isThreadRunning())
  62425. {
  62426. // thread has finished normally..
  62427. alertWindow->exitModalState (1);
  62428. alertWindow->setVisible (false);
  62429. }
  62430. else
  62431. {
  62432. const ScopedLock sl (messageLock);
  62433. alertWindow->setMessage (message);
  62434. }
  62435. }
  62436. END_JUCE_NAMESPACE
  62437. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62438. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62439. BEGIN_JUCE_NAMESPACE
  62440. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62441. const int millisecondsBeforeTipAppears_)
  62442. : Component ("tooltip"),
  62443. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  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 (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) throw()
  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() throw()
  64349. {
  64350. }
  64351. void Graphics::resetToDefaultState() throw()
  64352. {
  64353. saveStateIfPending();
  64354. context->setFill (FillType());
  64355. context->setFont (Font());
  64356. context->setInterpolationQuality (defaultQuality);
  64357. }
  64358. bool Graphics::isVectorDevice() const throw()
  64359. {
  64360. return context->isVectorDevice();
  64361. }
  64362. bool Graphics::reduceClipRegion (const int x, const int y,
  64363. const int w, const int h) throw()
  64364. {
  64365. saveStateIfPending();
  64366. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64367. }
  64368. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64369. {
  64370. saveStateIfPending();
  64371. return context->clipToRectangleList (clipRegion);
  64372. }
  64373. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64374. {
  64375. saveStateIfPending();
  64376. context->clipToPath (path, transform);
  64377. return ! context->isClipEmpty();
  64378. }
  64379. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform) throw()
  64380. {
  64381. saveStateIfPending();
  64382. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64383. return ! context->isClipEmpty();
  64384. }
  64385. void Graphics::excludeClipRegion (const Rectangle<int>& rectangleToExclude) throw()
  64386. {
  64387. saveStateIfPending();
  64388. context->excludeClipRectangle (rectangleToExclude);
  64389. }
  64390. bool Graphics::isClipEmpty() const throw()
  64391. {
  64392. return context->isClipEmpty();
  64393. }
  64394. const Rectangle<int> Graphics::getClipBounds() const throw()
  64395. {
  64396. return context->getClipBounds();
  64397. }
  64398. void Graphics::saveState() throw()
  64399. {
  64400. saveStateIfPending();
  64401. saveStatePending = true;
  64402. }
  64403. void Graphics::restoreState() throw()
  64404. {
  64405. if (saveStatePending)
  64406. saveStatePending = false;
  64407. else
  64408. context->restoreState();
  64409. }
  64410. void Graphics::saveStateIfPending() throw()
  64411. {
  64412. if (saveStatePending)
  64413. {
  64414. saveStatePending = false;
  64415. context->saveState();
  64416. }
  64417. }
  64418. void Graphics::setOrigin (const int newOriginX,
  64419. const int newOriginY) throw()
  64420. {
  64421. saveStateIfPending();
  64422. context->setOrigin (newOriginX, newOriginY);
  64423. }
  64424. bool Graphics::clipRegionIntersects (const int x, const int y,
  64425. const int w, const int h) const throw()
  64426. {
  64427. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64428. }
  64429. void Graphics::setColour (const Colour& newColour) throw()
  64430. {
  64431. saveStateIfPending();
  64432. context->setFill (FillType (newColour));
  64433. }
  64434. void Graphics::setOpacity (const float newOpacity) throw()
  64435. {
  64436. saveStateIfPending();
  64437. context->setOpacity (newOpacity);
  64438. }
  64439. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64440. {
  64441. saveStateIfPending();
  64442. context->setFill (FillType (gradient));
  64443. }
  64444. void Graphics::setTiledImageFill (const Image& imageToUse,
  64445. const int anchorX,
  64446. const int anchorY,
  64447. const float opacity) throw()
  64448. {
  64449. saveStateIfPending();
  64450. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64451. context->setOpacity (opacity);
  64452. }
  64453. void Graphics::setFillType (const FillType& newFill) throw()
  64454. {
  64455. saveStateIfPending();
  64456. context->setFill (newFill);
  64457. }
  64458. void Graphics::setFont (const Font& newFont) throw()
  64459. {
  64460. saveStateIfPending();
  64461. context->setFont (newFont);
  64462. }
  64463. void Graphics::setFont (const float newFontHeight,
  64464. const int newFontStyleFlags) throw()
  64465. {
  64466. saveStateIfPending();
  64467. Font f (context->getFont());
  64468. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64469. context->setFont (f);
  64470. }
  64471. void Graphics::drawSingleLineText (const String& text,
  64472. const int startX,
  64473. const int baselineY) const throw()
  64474. {
  64475. if (text.isNotEmpty()
  64476. && startX < context->getClipBounds().getRight())
  64477. {
  64478. GlyphArrangement arr;
  64479. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64480. arr.draw (*this);
  64481. }
  64482. }
  64483. void Graphics::drawTextAsPath (const String& text,
  64484. const AffineTransform& transform) const throw()
  64485. {
  64486. if (text.isNotEmpty())
  64487. {
  64488. GlyphArrangement arr;
  64489. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64490. arr.draw (*this, transform);
  64491. }
  64492. }
  64493. void Graphics::drawMultiLineText (const String& text,
  64494. const int startX,
  64495. const int baselineY,
  64496. const int maximumLineWidth) const throw()
  64497. {
  64498. if (text.isNotEmpty()
  64499. && startX < context->getClipBounds().getRight())
  64500. {
  64501. GlyphArrangement arr;
  64502. arr.addJustifiedText (context->getFont(), text,
  64503. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64504. Justification::left);
  64505. arr.draw (*this);
  64506. }
  64507. }
  64508. void Graphics::drawText (const String& text,
  64509. const int x,
  64510. const int y,
  64511. const int width,
  64512. const int height,
  64513. const Justification& justificationType,
  64514. const bool useEllipsesIfTooBig) const throw()
  64515. {
  64516. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64517. {
  64518. GlyphArrangement arr;
  64519. arr.addCurtailedLineOfText (context->getFont(), text,
  64520. 0.0f, 0.0f, (float)width,
  64521. useEllipsesIfTooBig);
  64522. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  64523. (float) x, (float) y,
  64524. (float) width, (float) height,
  64525. justificationType);
  64526. arr.draw (*this);
  64527. }
  64528. }
  64529. void Graphics::drawFittedText (const String& text,
  64530. const int x,
  64531. const int y,
  64532. const int width,
  64533. const int height,
  64534. const Justification& justification,
  64535. const int maximumNumberOfLines,
  64536. const float minimumHorizontalScale) const throw()
  64537. {
  64538. if (text.isNotEmpty()
  64539. && width > 0 && height > 0
  64540. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64541. {
  64542. GlyphArrangement arr;
  64543. arr.addFittedText (context->getFont(), text,
  64544. (float) x, (float) y,
  64545. (float) width, (float) height,
  64546. justification,
  64547. maximumNumberOfLines,
  64548. minimumHorizontalScale);
  64549. arr.draw (*this);
  64550. }
  64551. }
  64552. void Graphics::fillRect (int x,
  64553. int y,
  64554. int width,
  64555. int height) const throw()
  64556. {
  64557. // passing in a silly number can cause maths problems in rendering!
  64558. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64559. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64560. }
  64561. void Graphics::fillRect (const Rectangle<int>& r) const throw()
  64562. {
  64563. context->fillRect (r, false);
  64564. }
  64565. void Graphics::fillRect (const float x,
  64566. const float y,
  64567. const float width,
  64568. const float height) const throw()
  64569. {
  64570. // passing in a silly number can cause maths problems in rendering!
  64571. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64572. Path p;
  64573. p.addRectangle (x, y, width, height);
  64574. fillPath (p);
  64575. }
  64576. void Graphics::setPixel (int x, int y) const throw()
  64577. {
  64578. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  64579. }
  64580. void Graphics::fillAll() const throw()
  64581. {
  64582. fillRect (context->getClipBounds());
  64583. }
  64584. void Graphics::fillAll (const Colour& colourToUse) const throw()
  64585. {
  64586. if (! colourToUse.isTransparent())
  64587. {
  64588. const Rectangle<int> clip (context->getClipBounds());
  64589. context->saveState();
  64590. context->setFill (FillType (colourToUse));
  64591. context->fillRect (clip, false);
  64592. context->restoreState();
  64593. }
  64594. }
  64595. void Graphics::fillPath (const Path& path,
  64596. const AffineTransform& transform) const throw()
  64597. {
  64598. if ((! context->isClipEmpty()) && ! path.isEmpty())
  64599. context->fillPath (path, transform);
  64600. }
  64601. void Graphics::strokePath (const Path& path,
  64602. const PathStrokeType& strokeType,
  64603. const AffineTransform& transform) const throw()
  64604. {
  64605. Path stroke;
  64606. strokeType.createStrokedPath (stroke, path, transform);
  64607. fillPath (stroke);
  64608. }
  64609. void Graphics::drawRect (const int x,
  64610. const int y,
  64611. const int width,
  64612. const int height,
  64613. const int lineThickness) const throw()
  64614. {
  64615. // passing in a silly number can cause maths problems in rendering!
  64616. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64617. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  64618. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64619. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64620. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  64621. }
  64622. void Graphics::drawRect (const float x,
  64623. const float y,
  64624. const float width,
  64625. const float height,
  64626. const float lineThickness) const throw()
  64627. {
  64628. // passing in a silly number can cause maths problems in rendering!
  64629. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64630. Path p;
  64631. p.addRectangle (x, y, width, lineThickness);
  64632. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64633. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64634. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  64635. fillPath (p);
  64636. }
  64637. void Graphics::drawRect (const Rectangle<int>& r,
  64638. const int lineThickness) const throw()
  64639. {
  64640. drawRect (r.getX(), r.getY(),
  64641. r.getWidth(), r.getHeight(),
  64642. lineThickness);
  64643. }
  64644. void Graphics::drawBevel (const int x,
  64645. const int y,
  64646. const int width,
  64647. const int height,
  64648. const int bevelThickness,
  64649. const Colour& topLeftColour,
  64650. const Colour& bottomRightColour,
  64651. const bool useGradient,
  64652. const bool sharpEdgeOnOutside) const throw()
  64653. {
  64654. // passing in a silly number can cause maths problems in rendering!
  64655. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64656. if (clipRegionIntersects (x, y, width, height))
  64657. {
  64658. context->saveState();
  64659. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  64660. const float ramp = oldOpacity / bevelThickness;
  64661. for (int i = bevelThickness; --i >= 0;)
  64662. {
  64663. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  64664. : oldOpacity;
  64665. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  64666. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  64667. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  64668. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  64669. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  64670. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  64671. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  64672. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  64673. }
  64674. context->restoreState();
  64675. }
  64676. }
  64677. void Graphics::fillEllipse (const float x,
  64678. const float y,
  64679. const float width,
  64680. const float height) const throw()
  64681. {
  64682. // passing in a silly number can cause maths problems in rendering!
  64683. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64684. Path p;
  64685. p.addEllipse (x, y, width, height);
  64686. fillPath (p);
  64687. }
  64688. void Graphics::drawEllipse (const float x,
  64689. const float y,
  64690. const float width,
  64691. const float height,
  64692. const float lineThickness) const throw()
  64693. {
  64694. // passing in a silly number can cause maths problems in rendering!
  64695. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64696. Path p;
  64697. p.addEllipse (x, y, width, height);
  64698. strokePath (p, PathStrokeType (lineThickness));
  64699. }
  64700. void Graphics::fillRoundedRectangle (const float x,
  64701. const float y,
  64702. const float width,
  64703. const float height,
  64704. const float cornerSize) const throw()
  64705. {
  64706. // passing in a silly number can cause maths problems in rendering!
  64707. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64708. Path p;
  64709. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64710. fillPath (p);
  64711. }
  64712. void Graphics::fillRoundedRectangle (const Rectangle<int>& r,
  64713. const float cornerSize) const throw()
  64714. {
  64715. fillRoundedRectangle ((float) r.getX(),
  64716. (float) r.getY(),
  64717. (float) r.getWidth(),
  64718. (float) r.getHeight(),
  64719. cornerSize);
  64720. }
  64721. void Graphics::drawRoundedRectangle (const float x,
  64722. const float y,
  64723. const float width,
  64724. const float height,
  64725. const float cornerSize,
  64726. const float lineThickness) const throw()
  64727. {
  64728. // passing in a silly number can cause maths problems in rendering!
  64729. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64730. Path p;
  64731. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64732. strokePath (p, PathStrokeType (lineThickness));
  64733. }
  64734. void Graphics::drawRoundedRectangle (const Rectangle<int>& r,
  64735. const float cornerSize,
  64736. const float lineThickness) const throw()
  64737. {
  64738. drawRoundedRectangle ((float) r.getX(),
  64739. (float) r.getY(),
  64740. (float) r.getWidth(),
  64741. (float) r.getHeight(),
  64742. cornerSize, lineThickness);
  64743. }
  64744. void Graphics::drawArrow (const float startX,
  64745. const float startY,
  64746. const float endX,
  64747. const float endY,
  64748. const float lineThickness,
  64749. const float arrowheadWidth,
  64750. const float arrowheadLength) const throw()
  64751. {
  64752. Path p;
  64753. p.addArrow (startX, startY, endX, endY,
  64754. lineThickness, arrowheadWidth, arrowheadLength);
  64755. fillPath (p);
  64756. }
  64757. void Graphics::fillCheckerBoard (int x, int y,
  64758. int width, int height,
  64759. const int checkWidth,
  64760. const int checkHeight,
  64761. const Colour& colour1,
  64762. const Colour& colour2) const throw()
  64763. {
  64764. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  64765. if (checkWidth > 0 && checkHeight > 0)
  64766. {
  64767. context->saveState();
  64768. if (colour1 == colour2)
  64769. {
  64770. context->setFill (FillType (colour1));
  64771. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64772. }
  64773. else
  64774. {
  64775. const Rectangle<int> clip (context->getClipBounds());
  64776. const int right = jmin (x + width, clip.getRight());
  64777. const int bottom = jmin (y + height, clip.getBottom());
  64778. int cy = 0;
  64779. while (y < bottom)
  64780. {
  64781. int cx = cy;
  64782. for (int xx = x; xx < right; xx += checkWidth)
  64783. {
  64784. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  64785. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  64786. false);
  64787. }
  64788. ++cy;
  64789. y += checkHeight;
  64790. }
  64791. }
  64792. context->restoreState();
  64793. }
  64794. }
  64795. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  64796. {
  64797. context->drawVerticalLine (x, top, bottom);
  64798. }
  64799. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  64800. {
  64801. context->drawHorizontalLine (y, left, right);
  64802. }
  64803. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  64804. {
  64805. context->drawLine (x1, y1, x2, y2);
  64806. }
  64807. void Graphics::drawLine (const float startX,
  64808. const float startY,
  64809. const float endX,
  64810. const float endY,
  64811. const float lineThickness) const throw()
  64812. {
  64813. Path p;
  64814. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  64815. fillPath (p);
  64816. }
  64817. void Graphics::drawLine (const Line& line) const throw()
  64818. {
  64819. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  64820. }
  64821. void Graphics::drawLine (const Line& line,
  64822. const float lineThickness) const throw()
  64823. {
  64824. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  64825. }
  64826. void Graphics::drawDashedLine (const float startX,
  64827. const float startY,
  64828. const float endX,
  64829. const float endY,
  64830. const float* const dashLengths,
  64831. const int numDashLengths,
  64832. const float lineThickness) const throw()
  64833. {
  64834. const double dx = endX - startX;
  64835. const double dy = endY - startY;
  64836. const double totalLen = juce_hypot (dx, dy);
  64837. if (totalLen >= 0.5)
  64838. {
  64839. const double onePixAlpha = 1.0 / totalLen;
  64840. double alpha = 0.0;
  64841. float x = startX;
  64842. float y = startY;
  64843. int n = 0;
  64844. while (alpha < 1.0f)
  64845. {
  64846. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  64847. n = n % numDashLengths;
  64848. const float oldX = x;
  64849. const float oldY = y;
  64850. x = (float) (startX + dx * alpha);
  64851. y = (float) (startY + dy * alpha);
  64852. if ((n & 1) != 0)
  64853. {
  64854. if (lineThickness != 1.0f)
  64855. drawLine (oldX, oldY, x, y, lineThickness);
  64856. else
  64857. drawLine (oldX, oldY, x, y);
  64858. }
  64859. }
  64860. }
  64861. }
  64862. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  64863. {
  64864. saveStateIfPending();
  64865. context->setInterpolationQuality (newQuality);
  64866. }
  64867. void Graphics::drawImageAt (const Image* const imageToDraw,
  64868. const int topLeftX,
  64869. const int topLeftY,
  64870. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64871. {
  64872. if (imageToDraw != 0)
  64873. {
  64874. const int imageW = imageToDraw->getWidth();
  64875. const int imageH = imageToDraw->getHeight();
  64876. drawImage (imageToDraw,
  64877. topLeftX, topLeftY, imageW, imageH,
  64878. 0, 0, imageW, imageH,
  64879. fillAlphaChannelWithCurrentBrush);
  64880. }
  64881. }
  64882. void Graphics::drawImageWithin (const Image* const imageToDraw,
  64883. const int destX,
  64884. const int destY,
  64885. const int destW,
  64886. const int destH,
  64887. const RectanglePlacement& placementWithinTarget,
  64888. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64889. {
  64890. // passing in a silly number can cause maths problems in rendering!
  64891. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  64892. if (imageToDraw != 0)
  64893. {
  64894. const int imageW = imageToDraw->getWidth();
  64895. const int imageH = imageToDraw->getHeight();
  64896. if (imageW > 0 && imageH > 0)
  64897. {
  64898. double newX = 0.0, newY = 0.0;
  64899. double newW = imageW;
  64900. double newH = imageH;
  64901. placementWithinTarget.applyTo (newX, newY, newW, newH,
  64902. destX, destY, destW, destH);
  64903. if (newW > 0 && newH > 0)
  64904. {
  64905. drawImage (imageToDraw,
  64906. roundToInt (newX), roundToInt (newY),
  64907. roundToInt (newW), roundToInt (newH),
  64908. 0, 0, imageW, imageH,
  64909. fillAlphaChannelWithCurrentBrush);
  64910. }
  64911. }
  64912. }
  64913. }
  64914. void Graphics::drawImage (const Image* const imageToDraw,
  64915. int dx, int dy, int dw, int dh,
  64916. int sx, int sy, int sw, int sh,
  64917. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64918. {
  64919. // passing in a silly number can cause maths problems in rendering!
  64920. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  64921. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  64922. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  64923. {
  64924. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  64925. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  64926. .translated ((float) dx, (float) dy),
  64927. fillAlphaChannelWithCurrentBrush);
  64928. }
  64929. }
  64930. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  64931. const Rectangle<int>& imageSubRegion,
  64932. const AffineTransform& transform,
  64933. const bool fillAlphaChannelWithCurrentBrush) const throw()
  64934. {
  64935. if (imageToDraw != 0 && ! context->isClipEmpty())
  64936. {
  64937. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  64938. if (fillAlphaChannelWithCurrentBrush)
  64939. {
  64940. context->saveState();
  64941. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  64942. fillAll();
  64943. context->restoreState();
  64944. }
  64945. else
  64946. {
  64947. context->drawImage (*imageToDraw, srcClip, transform, false);
  64948. }
  64949. }
  64950. }
  64951. END_JUCE_NAMESPACE
  64952. /*** End of inlined file: juce_Graphics.cpp ***/
  64953. /*** Start of inlined file: juce_Justification.cpp ***/
  64954. BEGIN_JUCE_NAMESPACE
  64955. Justification::Justification (const Justification& other) throw()
  64956. : flags (other.flags)
  64957. {
  64958. }
  64959. Justification& Justification::operator= (const Justification& other) throw()
  64960. {
  64961. flags = other.flags;
  64962. return *this;
  64963. }
  64964. int Justification::getOnlyVerticalFlags() const throw()
  64965. {
  64966. return flags & (top | bottom | verticallyCentred);
  64967. }
  64968. int Justification::getOnlyHorizontalFlags() const throw()
  64969. {
  64970. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  64971. }
  64972. void Justification::applyToRectangle (int& x, int& y,
  64973. const int w, const int h,
  64974. const int spaceX, const int spaceY,
  64975. const int spaceW, const int spaceH) const throw()
  64976. {
  64977. if ((flags & horizontallyCentred) != 0)
  64978. {
  64979. x = spaceX + ((spaceW - w) >> 1);
  64980. }
  64981. else if ((flags & right) != 0)
  64982. {
  64983. x = spaceX + spaceW - w;
  64984. }
  64985. else
  64986. {
  64987. x = spaceX;
  64988. }
  64989. if ((flags & verticallyCentred) != 0)
  64990. {
  64991. y = spaceY + ((spaceH - h) >> 1);
  64992. }
  64993. else if ((flags & bottom) != 0)
  64994. {
  64995. y = spaceY + spaceH - h;
  64996. }
  64997. else
  64998. {
  64999. y = spaceY;
  65000. }
  65001. }
  65002. END_JUCE_NAMESPACE
  65003. /*** End of inlined file: juce_Justification.cpp ***/
  65004. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65005. BEGIN_JUCE_NAMESPACE
  65006. // this will throw an assertion if you try to draw something that's not
  65007. // possible in postscript
  65008. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65009. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65010. #define notPossibleInPostscriptAssert jassertfalse
  65011. #else
  65012. #define notPossibleInPostscriptAssert
  65013. #endif
  65014. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65015. const String& documentTitle,
  65016. const int totalWidth_,
  65017. const int totalHeight_)
  65018. : out (resultingPostScript),
  65019. totalWidth (totalWidth_),
  65020. totalHeight (totalHeight_),
  65021. needToClip (true)
  65022. {
  65023. stateStack.add (new SavedState());
  65024. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  65025. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65026. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65027. "\n%%BoundingBox: 0 0 600 824"
  65028. "\n%%Pages: 0"
  65029. "\n%%Creator: Raw Material Software JUCE"
  65030. "\n%%Title: " << documentTitle <<
  65031. "\n%%CreationDate: none"
  65032. "\n%%LanguageLevel: 2"
  65033. "\n%%EndComments"
  65034. "\n%%BeginProlog"
  65035. "\n%%BeginResource: JRes"
  65036. "\n/bd {bind def} bind def"
  65037. "\n/c {setrgbcolor} bd"
  65038. "\n/m {moveto} bd"
  65039. "\n/l {lineto} bd"
  65040. "\n/rl {rlineto} bd"
  65041. "\n/ct {curveto} bd"
  65042. "\n/cp {closepath} bd"
  65043. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65044. "\n/doclip {initclip newpath} bd"
  65045. "\n/endclip {clip newpath} bd"
  65046. "\n%%EndResource"
  65047. "\n%%EndProlog"
  65048. "\n%%BeginSetup"
  65049. "\n%%EndSetup"
  65050. "\n%%Page: 1 1"
  65051. "\n%%BeginPageSetup"
  65052. "\n%%EndPageSetup\n\n"
  65053. << "40 800 translate\n"
  65054. << scale << ' ' << scale << " scale\n\n";
  65055. }
  65056. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65057. {
  65058. }
  65059. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65060. {
  65061. return true;
  65062. }
  65063. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65064. {
  65065. if (x != 0 || y != 0)
  65066. {
  65067. stateStack.getLast()->xOffset += x;
  65068. stateStack.getLast()->yOffset += y;
  65069. needToClip = true;
  65070. }
  65071. }
  65072. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65073. {
  65074. needToClip = true;
  65075. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65076. }
  65077. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65078. {
  65079. needToClip = true;
  65080. return stateStack.getLast()->clip.clipTo (clipRegion);
  65081. }
  65082. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65083. {
  65084. needToClip = true;
  65085. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65086. }
  65087. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65088. {
  65089. writeClip();
  65090. Path p (path);
  65091. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65092. writePath (p);
  65093. out << "clip\n";
  65094. }
  65095. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65096. {
  65097. needToClip = true;
  65098. jassertfalse // xxx
  65099. }
  65100. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65101. {
  65102. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65103. }
  65104. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65105. {
  65106. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65107. -stateStack.getLast()->yOffset);
  65108. }
  65109. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65110. {
  65111. return stateStack.getLast()->clip.isEmpty();
  65112. }
  65113. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65114. : xOffset (0),
  65115. yOffset (0)
  65116. {
  65117. }
  65118. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65119. {
  65120. }
  65121. void LowLevelGraphicsPostScriptRenderer::saveState()
  65122. {
  65123. stateStack.add (new SavedState (*stateStack.getLast()));
  65124. }
  65125. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65126. {
  65127. jassert (stateStack.size() > 0);
  65128. if (stateStack.size() > 0)
  65129. stateStack.removeLast();
  65130. }
  65131. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65132. {
  65133. if (needToClip)
  65134. {
  65135. needToClip = false;
  65136. out << "doclip ";
  65137. int itemsOnLine = 0;
  65138. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65139. {
  65140. if (++itemsOnLine == 6)
  65141. {
  65142. itemsOnLine = 0;
  65143. out << '\n';
  65144. }
  65145. const Rectangle<int>& r = *i.getRectangle();
  65146. out << r.getX() << ' ' << -r.getY() << ' '
  65147. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65148. }
  65149. out << "endclip\n";
  65150. }
  65151. }
  65152. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65153. {
  65154. Colour c (Colours::white.overlaidWith (colour));
  65155. if (lastColour != c)
  65156. {
  65157. lastColour = c;
  65158. out << String (c.getFloatRed(), 3) << ' '
  65159. << String (c.getFloatGreen(), 3) << ' '
  65160. << String (c.getFloatBlue(), 3) << " c\n";
  65161. }
  65162. }
  65163. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65164. {
  65165. out << String (x, 2) << ' '
  65166. << String (-y, 2) << ' ';
  65167. }
  65168. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65169. {
  65170. out << "newpath ";
  65171. float lastX = 0.0f;
  65172. float lastY = 0.0f;
  65173. int itemsOnLine = 0;
  65174. Path::Iterator i (path);
  65175. while (i.next())
  65176. {
  65177. if (++itemsOnLine == 4)
  65178. {
  65179. itemsOnLine = 0;
  65180. out << '\n';
  65181. }
  65182. switch (i.elementType)
  65183. {
  65184. case Path::Iterator::startNewSubPath:
  65185. writeXY (i.x1, i.y1);
  65186. lastX = i.x1;
  65187. lastY = i.y1;
  65188. out << "m ";
  65189. break;
  65190. case Path::Iterator::lineTo:
  65191. writeXY (i.x1, i.y1);
  65192. lastX = i.x1;
  65193. lastY = i.y1;
  65194. out << "l ";
  65195. break;
  65196. case Path::Iterator::quadraticTo:
  65197. {
  65198. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65199. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65200. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65201. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65202. writeXY (cp1x, cp1y);
  65203. writeXY (cp2x, cp2y);
  65204. writeXY (i.x2, i.y2);
  65205. out << "ct ";
  65206. lastX = i.x2;
  65207. lastY = i.y2;
  65208. }
  65209. break;
  65210. case Path::Iterator::cubicTo:
  65211. writeXY (i.x1, i.y1);
  65212. writeXY (i.x2, i.y2);
  65213. writeXY (i.x3, i.y3);
  65214. out << "ct ";
  65215. lastX = i.x3;
  65216. lastY = i.y3;
  65217. break;
  65218. case Path::Iterator::closePath:
  65219. out << "cp ";
  65220. break;
  65221. default:
  65222. jassertfalse
  65223. break;
  65224. }
  65225. }
  65226. out << '\n';
  65227. }
  65228. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65229. {
  65230. out << "[ "
  65231. << trans.mat00 << ' '
  65232. << trans.mat10 << ' '
  65233. << trans.mat01 << ' '
  65234. << trans.mat11 << ' '
  65235. << trans.mat02 << ' '
  65236. << trans.mat12 << " ] concat ";
  65237. }
  65238. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65239. {
  65240. stateStack.getLast()->fillType = fillType;
  65241. }
  65242. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65243. {
  65244. }
  65245. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65246. {
  65247. }
  65248. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65249. {
  65250. if (stateStack.getLast()->fillType.isColour())
  65251. {
  65252. writeClip();
  65253. writeColour (stateStack.getLast()->fillType.colour);
  65254. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65255. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65256. }
  65257. else
  65258. {
  65259. Path p;
  65260. p.addRectangle (r);
  65261. fillPath (p, AffineTransform::identity);
  65262. }
  65263. }
  65264. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65265. {
  65266. if (stateStack.getLast()->fillType.isColour())
  65267. {
  65268. writeClip();
  65269. Path p (path);
  65270. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65271. (float) stateStack.getLast()->yOffset));
  65272. writePath (p);
  65273. writeColour (stateStack.getLast()->fillType.colour);
  65274. out << "fill\n";
  65275. }
  65276. else if (stateStack.getLast()->fillType.isGradient())
  65277. {
  65278. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65279. // postscript can't do semi-transparent ones.
  65280. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65281. writeClip();
  65282. out << "gsave ";
  65283. {
  65284. Path p (path);
  65285. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65286. writePath (p);
  65287. out << "clip\n";
  65288. }
  65289. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65290. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65291. // time-being, this just fills it with the average colour..
  65292. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65293. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65294. out << "grestore\n";
  65295. }
  65296. }
  65297. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65298. const int sx, const int sy,
  65299. const int maxW, const int maxH) const
  65300. {
  65301. out << "{<\n";
  65302. const int w = jmin (maxW, im.getWidth());
  65303. const int h = jmin (maxH, im.getHeight());
  65304. int charsOnLine = 0;
  65305. const Image::BitmapData srcData (im, 0, 0, w, h);
  65306. Colour pixel;
  65307. for (int y = h; --y >= 0;)
  65308. {
  65309. for (int x = 0; x < w; ++x)
  65310. {
  65311. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65312. if (x >= sx && y >= sy)
  65313. {
  65314. if (im.isARGB())
  65315. {
  65316. PixelARGB p (*(const PixelARGB*) pixelData);
  65317. p.unpremultiply();
  65318. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65319. }
  65320. else if (im.isRGB())
  65321. {
  65322. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65323. }
  65324. else
  65325. {
  65326. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65327. }
  65328. }
  65329. else
  65330. {
  65331. pixel = Colours::transparentWhite;
  65332. }
  65333. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65334. out << String::toHexString (pixelValues, 3, 0);
  65335. charsOnLine += 3;
  65336. if (charsOnLine > 100)
  65337. {
  65338. out << '\n';
  65339. charsOnLine = 0;
  65340. }
  65341. }
  65342. }
  65343. out << "\n>}\n";
  65344. }
  65345. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65346. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65347. {
  65348. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65349. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65350. writeClip();
  65351. out << "gsave ";
  65352. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65353. .scaled (1.0f, -1.0f));
  65354. RectangleList imageClip;
  65355. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65356. imageClip.clipTo (srcClip);
  65357. out << "newpath ";
  65358. int itemsOnLine = 0;
  65359. for (RectangleList::Iterator i (imageClip); i.next();)
  65360. {
  65361. if (++itemsOnLine == 6)
  65362. {
  65363. out << '\n';
  65364. itemsOnLine = 0;
  65365. }
  65366. const Rectangle<int>& r = *i.getRectangle();
  65367. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65368. }
  65369. out << " clip newpath\n";
  65370. out << w << ' ' << h << " scale\n";
  65371. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65372. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65373. out << "false 3 colorimage grestore\n";
  65374. needToClip = true;
  65375. }
  65376. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65377. {
  65378. Path p;
  65379. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65380. fillPath (p, AffineTransform::identity);
  65381. }
  65382. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65383. {
  65384. drawLine (x, top, x, bottom);
  65385. }
  65386. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65387. {
  65388. drawLine (left, y, right, y);
  65389. }
  65390. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65391. {
  65392. stateStack.getLast()->font = newFont;
  65393. }
  65394. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65395. {
  65396. return stateStack.getLast()->font;
  65397. }
  65398. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65399. {
  65400. Path p;
  65401. Font& font = stateStack.getLast()->font;
  65402. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65403. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65404. }
  65405. END_JUCE_NAMESPACE
  65406. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65407. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65408. BEGIN_JUCE_NAMESPACE
  65409. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65410. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65411. #endif
  65412. #if JUCE_MSVC && JUCE_DEBUG
  65413. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65414. #endif
  65415. #if JUCE_MSVC
  65416. #pragma warning (push)
  65417. #pragma warning (disable: 4127) // "expression is constant" warning
  65418. #endif
  65419. template <class PixelType, bool replaceExisting = false>
  65420. class SolidColourEdgeTableRenderer
  65421. {
  65422. public:
  65423. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65424. : data (data_),
  65425. sourceColour (colour)
  65426. {
  65427. if (sizeof (PixelType) == 3)
  65428. {
  65429. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65430. && sourceColour.getGreen() == sourceColour.getBlue();
  65431. filler[0].set (sourceColour);
  65432. filler[1].set (sourceColour);
  65433. filler[2].set (sourceColour);
  65434. filler[3].set (sourceColour);
  65435. }
  65436. }
  65437. forcedinline void setEdgeTableYPos (const int y) throw()
  65438. {
  65439. linePixels = (PixelType*) data.getLinePointer (y);
  65440. }
  65441. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65442. {
  65443. if (replaceExisting)
  65444. linePixels[x].set (sourceColour);
  65445. else
  65446. linePixels[x].blend (sourceColour, alphaLevel);
  65447. }
  65448. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65449. {
  65450. PixelARGB p (sourceColour);
  65451. p.multiplyAlpha (alphaLevel);
  65452. PixelType* dest = linePixels + x;
  65453. if (replaceExisting || p.getAlpha() >= 0xff)
  65454. replaceLine (dest, p, width);
  65455. else
  65456. blendLine (dest, p, width);
  65457. }
  65458. private:
  65459. const Image::BitmapData& data;
  65460. PixelType* linePixels;
  65461. PixelARGB sourceColour;
  65462. PixelRGB filler [4];
  65463. bool areRGBComponentsEqual;
  65464. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const throw()
  65465. {
  65466. do
  65467. {
  65468. dest->blend (colour);
  65469. ++dest;
  65470. } while (--width > 0);
  65471. }
  65472. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65473. {
  65474. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65475. {
  65476. memset (dest, colour.getRed(), width * 3);
  65477. }
  65478. else
  65479. {
  65480. if (width >> 5)
  65481. {
  65482. const int* const intFiller = (const int*) filler;
  65483. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65484. {
  65485. dest->set (colour);
  65486. ++dest;
  65487. --width;
  65488. }
  65489. while (width > 4)
  65490. {
  65491. ((int*) dest) [0] = intFiller[0];
  65492. ((int*) dest) [1] = intFiller[1];
  65493. ((int*) dest) [2] = intFiller[2];
  65494. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65495. width -= 4;
  65496. }
  65497. }
  65498. while (--width >= 0)
  65499. {
  65500. dest->set (colour);
  65501. ++dest;
  65502. }
  65503. }
  65504. }
  65505. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65506. {
  65507. memset (dest, colour.getAlpha(), width);
  65508. }
  65509. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65510. {
  65511. do
  65512. {
  65513. dest->set (colour);
  65514. ++dest;
  65515. } while (--width > 0);
  65516. }
  65517. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  65518. SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  65519. };
  65520. class LinearGradientPixelGenerator
  65521. {
  65522. public:
  65523. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  65524. : lookupTable (lookupTable_), numEntries (numEntries_)
  65525. {
  65526. jassert (numEntries_ >= 0);
  65527. float x1 = gradient.x1;
  65528. float y1 = gradient.y1;
  65529. float x2 = gradient.x2;
  65530. float y2 = gradient.y2;
  65531. if (! transform.isIdentity())
  65532. {
  65533. const Line l (x2, y2, x1, y1);
  65534. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  65535. float x3 = p3.getX();
  65536. float y3 = p3.getY();
  65537. transform.transformPoint (x1, y1);
  65538. transform.transformPoint (x2, y2);
  65539. transform.transformPoint (x3, y3);
  65540. const Line l2 (x2, y2, x3, y3);
  65541. const float prop = l2.findNearestPointTo (x1, y1);
  65542. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  65543. x2 = newP2.getX();
  65544. y2 = newP2.getY();
  65545. }
  65546. vertical = fabs (x1 - x2) < 0.001f;
  65547. horizontal = fabs (y1 - y2) < 0.001f;
  65548. if (vertical)
  65549. {
  65550. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  65551. start = roundToInt (y1 * scale);
  65552. }
  65553. else if (horizontal)
  65554. {
  65555. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  65556. start = roundToInt (x1 * scale);
  65557. }
  65558. else
  65559. {
  65560. grad = (y2 - y1) / (double) (x1 - x2);
  65561. yTerm = y1 - x1 / grad;
  65562. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  65563. grad *= scale;
  65564. }
  65565. }
  65566. forcedinline void setY (const int y) throw()
  65567. {
  65568. if (vertical)
  65569. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  65570. else if (! horizontal)
  65571. start = roundToInt ((y - yTerm) * grad);
  65572. }
  65573. inline const PixelARGB getPixel (const int x) const throw()
  65574. {
  65575. return vertical ? linePix
  65576. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  65577. }
  65578. private:
  65579. const PixelARGB* const lookupTable;
  65580. const int numEntries;
  65581. PixelARGB linePix;
  65582. int start, scale;
  65583. double grad, yTerm;
  65584. bool vertical, horizontal;
  65585. enum { numScaleBits = 12 };
  65586. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  65587. LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  65588. };
  65589. class RadialGradientPixelGenerator
  65590. {
  65591. public:
  65592. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  65593. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65594. : lookupTable (lookupTable_),
  65595. numEntries (numEntries_),
  65596. gx1 (gradient.x1),
  65597. gy1 (gradient.y1)
  65598. {
  65599. jassert (numEntries_ >= 0);
  65600. const float gdx = gradient.x1 - gradient.x2;
  65601. const float gdy = gradient.y1 - gradient.y2;
  65602. maxDist = gdx * gdx + gdy * gdy;
  65603. invScale = numEntries / sqrt (maxDist);
  65604. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  65605. }
  65606. forcedinline void setY (const int y) throw()
  65607. {
  65608. dy = y - gy1;
  65609. dy *= dy;
  65610. }
  65611. inline const PixelARGB getPixel (const int px) const throw()
  65612. {
  65613. double x = px - gx1;
  65614. x *= x;
  65615. x += dy;
  65616. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  65617. }
  65618. protected:
  65619. const PixelARGB* const lookupTable;
  65620. const int numEntries;
  65621. const double gx1, gy1;
  65622. double maxDist, invScale, dy;
  65623. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  65624. RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  65625. };
  65626. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  65627. {
  65628. public:
  65629. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  65630. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65631. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  65632. inverseTransform (transform.inverted())
  65633. {
  65634. tM10 = inverseTransform.mat10;
  65635. tM00 = inverseTransform.mat00;
  65636. }
  65637. forcedinline void setY (const int y) throw()
  65638. {
  65639. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  65640. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  65641. }
  65642. inline const PixelARGB getPixel (const int px) const throw()
  65643. {
  65644. double x = px;
  65645. const double y = tM10 * x + lineYM11;
  65646. x = tM00 * x + lineYM01;
  65647. x *= x;
  65648. x += y * y;
  65649. if (x >= maxDist)
  65650. return lookupTable [numEntries];
  65651. else
  65652. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  65653. }
  65654. private:
  65655. double tM10, tM00, lineYM01, lineYM11;
  65656. const AffineTransform inverseTransform;
  65657. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  65658. TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  65659. };
  65660. template <class PixelType, class GradientType>
  65661. class GradientEdgeTableRenderer : public GradientType
  65662. {
  65663. public:
  65664. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  65665. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65666. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  65667. destData (destData_)
  65668. {
  65669. }
  65670. forcedinline void setEdgeTableYPos (const int y) throw()
  65671. {
  65672. linePixels = (PixelType*) destData.getLinePointer (y);
  65673. GradientType::setY (y);
  65674. }
  65675. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65676. {
  65677. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  65678. }
  65679. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  65680. {
  65681. PixelType* dest = linePixels + x;
  65682. if (alphaLevel < 0xff)
  65683. {
  65684. do
  65685. {
  65686. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  65687. } while (--width > 0);
  65688. }
  65689. else
  65690. {
  65691. do
  65692. {
  65693. (dest++)->blend (GradientType::getPixel (x++));
  65694. } while (--width > 0);
  65695. }
  65696. }
  65697. private:
  65698. const Image::BitmapData& destData;
  65699. PixelType* linePixels;
  65700. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  65701. GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  65702. };
  65703. static forcedinline int safeModulo (int n, const int divisor) throw()
  65704. {
  65705. jassert (divisor > 0);
  65706. n %= divisor;
  65707. return (n < 0) ? (n + divisor) : n;
  65708. }
  65709. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65710. class ImageFillEdgeTableRenderer
  65711. {
  65712. public:
  65713. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65714. const Image::BitmapData& srcData_,
  65715. const int extraAlpha_,
  65716. const int x, const int y) throw()
  65717. : destData (destData_),
  65718. srcData (srcData_),
  65719. extraAlpha (extraAlpha_ + 1),
  65720. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  65721. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  65722. {
  65723. }
  65724. forcedinline void setEdgeTableYPos (int y) throw()
  65725. {
  65726. linePixels = (DestPixelType*) destData.getLinePointer (y);
  65727. y -= yOffset;
  65728. if (repeatPattern)
  65729. {
  65730. jassert (y >= 0);
  65731. y %= srcData.height;
  65732. }
  65733. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  65734. }
  65735. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  65736. {
  65737. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65738. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  65739. }
  65740. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  65741. {
  65742. DestPixelType* dest = linePixels + x;
  65743. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65744. x -= xOffset;
  65745. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  65746. if (alphaLevel < 0xfe)
  65747. {
  65748. do
  65749. {
  65750. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  65751. } while (--width > 0);
  65752. }
  65753. else
  65754. {
  65755. if (repeatPattern)
  65756. {
  65757. do
  65758. {
  65759. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  65760. } while (--width > 0);
  65761. }
  65762. else
  65763. {
  65764. copyRow (dest, sourceLineStart + x, width);
  65765. }
  65766. }
  65767. }
  65768. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  65769. {
  65770. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  65771. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  65772. uint8* mask = (uint8*) (s + x - xOffset);
  65773. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65774. mask += PixelARGB::indexA;
  65775. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  65776. }
  65777. private:
  65778. const Image::BitmapData& destData;
  65779. const Image::BitmapData& srcData;
  65780. const int extraAlpha, xOffset, yOffset;
  65781. DestPixelType* linePixels;
  65782. SrcPixelType* sourceLineStart;
  65783. template <class PixelType1, class PixelType2>
  65784. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  65785. {
  65786. do
  65787. {
  65788. dest++ ->blend (*src++);
  65789. } while (--width > 0);
  65790. }
  65791. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  65792. {
  65793. memcpy (dest, src, width * sizeof (PixelRGB));
  65794. }
  65795. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  65796. ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  65797. };
  65798. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65799. class TransformedImageFillEdgeTableRenderer
  65800. {
  65801. public:
  65802. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65803. const Image::BitmapData& srcData_,
  65804. const AffineTransform& transform,
  65805. const int extraAlpha_,
  65806. const bool betterQuality_) throw()
  65807. : interpolator (transform),
  65808. destData (destData_),
  65809. srcData (srcData_),
  65810. extraAlpha (extraAlpha_ + 1),
  65811. betterQuality (betterQuality_),
  65812. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  65813. pixelOffsetInt (betterQuality_ ? -128 : 0),
  65814. maxX (srcData_.width - 1),
  65815. maxY (srcData_.height - 1),
  65816. scratchSize (2048)
  65817. {
  65818. scratchBuffer.malloc (scratchSize);
  65819. }
  65820. ~TransformedImageFillEdgeTableRenderer() throw()
  65821. {
  65822. }
  65823. forcedinline void setEdgeTableYPos (const int newY) throw()
  65824. {
  65825. y = newY;
  65826. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  65827. }
  65828. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  65829. {
  65830. alphaLevel *= extraAlpha;
  65831. alphaLevel >>= 8;
  65832. SrcPixelType p;
  65833. generate (&p, x, 1);
  65834. linePixels[x].blend (p, alphaLevel);
  65835. }
  65836. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  65837. {
  65838. if (width > scratchSize)
  65839. {
  65840. scratchSize = width;
  65841. scratchBuffer.malloc (scratchSize);
  65842. }
  65843. SrcPixelType* span = scratchBuffer;
  65844. generate (span, x, width);
  65845. DestPixelType* dest = linePixels + x;
  65846. alphaLevel *= extraAlpha;
  65847. alphaLevel >>= 8;
  65848. if (alphaLevel < 0xfe)
  65849. {
  65850. do
  65851. {
  65852. dest++ ->blend (*span++, alphaLevel);
  65853. } while (--width > 0);
  65854. }
  65855. else
  65856. {
  65857. do
  65858. {
  65859. dest++ ->blend (*span++);
  65860. } while (--width > 0);
  65861. }
  65862. }
  65863. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  65864. {
  65865. if (width > scratchSize)
  65866. {
  65867. scratchSize = width;
  65868. scratchBuffer.malloc (scratchSize);
  65869. }
  65870. y = y_;
  65871. generate (scratchBuffer, x, width);
  65872. const uint8* mask = reinterpret_cast <uint8*> (scratchBuffer.getData());
  65873. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65874. mask += PixelARGB::indexA;
  65875. et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width);
  65876. }
  65877. private:
  65878. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  65879. {
  65880. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65881. do
  65882. {
  65883. int hiResX, hiResY;
  65884. this->interpolator.next (hiResX, hiResY);
  65885. hiResX += pixelOffsetInt;
  65886. hiResY += pixelOffsetInt;
  65887. int loResX = hiResX >> 8;
  65888. int loResY = hiResY >> 8;
  65889. if (repeatPattern)
  65890. {
  65891. loResX = safeModulo (loResX, srcData.width);
  65892. loResY = safeModulo (loResY, srcData.height);
  65893. }
  65894. if (betterQuality
  65895. && ((unsigned int) loResX) < (unsigned int) maxX
  65896. && ((unsigned int) loResY) < (unsigned int) maxY)
  65897. {
  65898. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  65899. hiResX &= 255;
  65900. hiResY &= 255;
  65901. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65902. uint32 weight = (256 - hiResX) * (256 - hiResY);
  65903. c[0] += weight * src[0];
  65904. c[1] += weight * src[1];
  65905. c[2] += weight * src[2];
  65906. c[3] += weight * src[3];
  65907. weight = hiResX * (256 - hiResY);
  65908. c[0] += weight * src[4];
  65909. c[1] += weight * src[5];
  65910. c[2] += weight * src[6];
  65911. c[3] += weight * src[7];
  65912. src += this->srcData.lineStride;
  65913. weight = (256 - hiResX) * hiResY;
  65914. c[0] += weight * src[0];
  65915. c[1] += weight * src[1];
  65916. c[2] += weight * src[2];
  65917. c[3] += weight * src[3];
  65918. weight = hiResX * hiResY;
  65919. c[0] += weight * src[4];
  65920. c[1] += weight * src[5];
  65921. c[2] += weight * src[6];
  65922. c[3] += weight * src[7];
  65923. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  65924. (uint8) (c[PixelARGB::indexR] >> 16),
  65925. (uint8) (c[PixelARGB::indexG] >> 16),
  65926. (uint8) (c[PixelARGB::indexB] >> 16));
  65927. }
  65928. else
  65929. {
  65930. if (! repeatPattern)
  65931. {
  65932. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65933. if (loResX < 0) loResX = 0;
  65934. if (loResY < 0) loResY = 0;
  65935. if (loResX > maxX) loResX = maxX;
  65936. if (loResY > maxY) loResY = maxY;
  65937. }
  65938. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  65939. }
  65940. ++dest;
  65941. } while (--numPixels > 0);
  65942. }
  65943. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  65944. {
  65945. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65946. do
  65947. {
  65948. int hiResX, hiResY;
  65949. this->interpolator.next (hiResX, hiResY);
  65950. hiResX += pixelOffsetInt;
  65951. hiResY += pixelOffsetInt;
  65952. int loResX = hiResX >> 8;
  65953. int loResY = hiResY >> 8;
  65954. if (repeatPattern)
  65955. {
  65956. loResX = safeModulo (loResX, srcData.width);
  65957. loResY = safeModulo (loResY, srcData.height);
  65958. }
  65959. if (betterQuality
  65960. && ((unsigned int) loResX) < (unsigned int) maxX
  65961. && ((unsigned int) loResY) < (unsigned int) maxY)
  65962. {
  65963. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  65964. hiResX &= 255;
  65965. hiResY &= 255;
  65966. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65967. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  65968. c[0] += weight * src[0];
  65969. c[1] += weight * src[1];
  65970. c[2] += weight * src[2];
  65971. weight = hiResX * (256 - hiResY);
  65972. c[0] += weight * src[3];
  65973. c[1] += weight * src[4];
  65974. c[2] += weight * src[5];
  65975. src += this->srcData.lineStride;
  65976. weight = (256 - hiResX) * hiResY;
  65977. c[0] += weight * src[0];
  65978. c[1] += weight * src[1];
  65979. c[2] += weight * src[2];
  65980. weight = hiResX * hiResY;
  65981. c[0] += weight * src[3];
  65982. c[1] += weight * src[4];
  65983. c[2] += weight * src[5];
  65984. dest->setARGB ((uint8) 255,
  65985. (uint8) (c[PixelRGB::indexR] >> 16),
  65986. (uint8) (c[PixelRGB::indexG] >> 16),
  65987. (uint8) (c[PixelRGB::indexB] >> 16));
  65988. }
  65989. else
  65990. {
  65991. if (! repeatPattern)
  65992. {
  65993. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65994. if (loResX < 0) loResX = 0;
  65995. if (loResY < 0) loResY = 0;
  65996. if (loResX > maxX) loResX = maxX;
  65997. if (loResY > maxY) loResY = maxY;
  65998. }
  65999. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66000. }
  66001. ++dest;
  66002. } while (--numPixels > 0);
  66003. }
  66004. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66005. {
  66006. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66007. do
  66008. {
  66009. int hiResX, hiResY;
  66010. this->interpolator.next (hiResX, hiResY);
  66011. hiResX += pixelOffsetInt;
  66012. hiResY += pixelOffsetInt;
  66013. int loResX = hiResX >> 8;
  66014. int loResY = hiResY >> 8;
  66015. if (repeatPattern)
  66016. {
  66017. loResX = safeModulo (loResX, srcData.width);
  66018. loResY = safeModulo (loResY, srcData.height);
  66019. }
  66020. if (betterQuality
  66021. && ((unsigned int) loResX) < (unsigned int) maxX
  66022. && ((unsigned int) loResY) < (unsigned int) maxY)
  66023. {
  66024. hiResX &= 255;
  66025. hiResY &= 255;
  66026. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66027. uint32 c = 256 * 128;
  66028. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66029. c += src[1] * (hiResX * (256 - hiResY));
  66030. src += this->srcData.lineStride;
  66031. c += src[0] * ((256 - hiResX) * hiResY);
  66032. c += src[1] * (hiResX * hiResY);
  66033. *((uint8*) dest) = (uint8) c;
  66034. }
  66035. else
  66036. {
  66037. if (! repeatPattern)
  66038. {
  66039. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66040. if (loResX < 0) loResX = 0;
  66041. if (loResY < 0) loResY = 0;
  66042. if (loResX > maxX) loResX = maxX;
  66043. if (loResY > maxY) loResY = maxY;
  66044. }
  66045. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66046. }
  66047. ++dest;
  66048. } while (--numPixels > 0);
  66049. }
  66050. class TransformedImageSpanInterpolator
  66051. {
  66052. public:
  66053. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66054. : inverseTransform (transform.inverted())
  66055. {}
  66056. void setStartOfLine (float x, float y, const int numPixels) throw()
  66057. {
  66058. float x1 = x, y1 = y;
  66059. inverseTransform.transformPoint (x1, y1);
  66060. x += numPixels;
  66061. inverseTransform.transformPoint (x, y);
  66062. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66063. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66064. }
  66065. void next (int& x, int& y) throw()
  66066. {
  66067. x = xBresenham.n;
  66068. xBresenham.stepToNext();
  66069. y = yBresenham.n;
  66070. yBresenham.stepToNext();
  66071. }
  66072. private:
  66073. class BresenhamInterpolator
  66074. {
  66075. public:
  66076. BresenhamInterpolator() throw() {}
  66077. void set (const int n1, const int n2, const int numSteps_) throw()
  66078. {
  66079. numSteps = jmax (1, numSteps_);
  66080. step = (n2 - n1) / numSteps;
  66081. remainder = modulo = (n2 - n1) % numSteps;
  66082. n = n1;
  66083. if (modulo <= 0)
  66084. {
  66085. modulo += numSteps;
  66086. remainder += numSteps;
  66087. --step;
  66088. }
  66089. modulo -= numSteps;
  66090. }
  66091. forcedinline void stepToNext() throw()
  66092. {
  66093. modulo += remainder;
  66094. n += step;
  66095. if (modulo > 0)
  66096. {
  66097. modulo -= numSteps;
  66098. ++n;
  66099. }
  66100. }
  66101. int n;
  66102. private:
  66103. int numSteps, step, modulo, remainder;
  66104. };
  66105. const AffineTransform inverseTransform;
  66106. BresenhamInterpolator xBresenham, yBresenham;
  66107. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66108. TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66109. };
  66110. TransformedImageSpanInterpolator interpolator;
  66111. const Image::BitmapData& destData;
  66112. const Image::BitmapData& srcData;
  66113. const int extraAlpha;
  66114. const bool betterQuality;
  66115. const float pixelOffset;
  66116. const int pixelOffsetInt, maxX, maxY;
  66117. int y;
  66118. DestPixelType* linePixels;
  66119. HeapBlock <SrcPixelType> scratchBuffer;
  66120. int scratchSize;
  66121. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66122. TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66123. };
  66124. class LLGCSavedState
  66125. {
  66126. public:
  66127. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66128. const Font& font_, const FillType& fillType_,
  66129. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66130. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66131. xOffset (xOffset_), yOffset (yOffset_),
  66132. font (font_), fillType (fillType_),
  66133. interpolationQuality (interpolationQuality_)
  66134. {
  66135. }
  66136. LLGCSavedState (const LLGCSavedState& other) throw()
  66137. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66138. yOffset (other.yOffset), font (other.font),
  66139. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66140. {
  66141. }
  66142. ~LLGCSavedState() throw()
  66143. {
  66144. }
  66145. bool clipToRectangle (const Rectangle<int>& r) throw()
  66146. {
  66147. dupeEdgeTableIfMultiplyReferenced();
  66148. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66149. return ! edgeTable->edgeTable.isEmpty();
  66150. }
  66151. bool clipToRectangleList (const RectangleList& r) throw()
  66152. {
  66153. dupeEdgeTableIfMultiplyReferenced();
  66154. RectangleList offsetList (r);
  66155. offsetList.offsetAll (xOffset, yOffset);
  66156. EdgeTable e2 (offsetList);
  66157. edgeTable->edgeTable.clipToEdgeTable (e2);
  66158. return ! edgeTable->edgeTable.isEmpty();
  66159. }
  66160. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66161. {
  66162. dupeEdgeTableIfMultiplyReferenced();
  66163. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66164. return ! edgeTable->edgeTable.isEmpty();
  66165. }
  66166. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66167. {
  66168. dupeEdgeTableIfMultiplyReferenced();
  66169. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66170. edgeTable->edgeTable.clipToEdgeTable (et);
  66171. }
  66172. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66173. {
  66174. et.clipToEdgeTable (edgeTable->edgeTable);
  66175. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66176. if (fillType.isGradient())
  66177. {
  66178. jassert (! replaceContents); // that option is just for solid colours
  66179. ColourGradient g2 (*(fillType.gradient));
  66180. g2.multiplyOpacity (fillType.getOpacity());
  66181. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66182. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66183. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66184. const bool isIdentity = transform.isOnlyTranslation();
  66185. if (isIdentity)
  66186. {
  66187. // If our translation doesn't involve any distortion, we can speed it up..
  66188. transform.transformPoint (g2.x1, g2.y1);
  66189. transform.transformPoint (g2.x2, g2.y2);
  66190. transform = AffineTransform::identity;
  66191. }
  66192. HeapBlock <PixelARGB> lookupTable;
  66193. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66194. jassert (numLookupEntries > 0);
  66195. switch (image.getFormat())
  66196. {
  66197. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66198. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66199. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66200. }
  66201. }
  66202. else if (fillType.isTiledImage())
  66203. {
  66204. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66205. }
  66206. else
  66207. {
  66208. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66209. switch (image.getFormat())
  66210. {
  66211. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66212. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66213. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66214. }
  66215. }
  66216. }
  66217. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66218. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66219. {
  66220. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66221. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66222. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66223. const int alpha = fillType.colour.getAlpha();
  66224. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66225. if (transform.isOnlyTranslation())
  66226. {
  66227. // If our translation doesn't involve any distortion, just use a simple blit..
  66228. int tx = (int) (transform.getTranslationX() * 256.0f);
  66229. int ty = (int) (transform.getTranslationY() * 256.0f);
  66230. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66231. {
  66232. tx = ((tx + 128) >> 8);
  66233. ty = ((ty + 128) >> 8);
  66234. if (tiledFillClipRegion != 0)
  66235. {
  66236. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66237. }
  66238. else
  66239. {
  66240. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66241. et.clipToEdgeTable (edgeTable->edgeTable);
  66242. if (! et.isEmpty())
  66243. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66244. }
  66245. return;
  66246. }
  66247. }
  66248. if (transform.isSingularity())
  66249. return;
  66250. if (tiledFillClipRegion != 0)
  66251. {
  66252. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66253. }
  66254. else
  66255. {
  66256. Path p;
  66257. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66258. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66259. et.clipToEdgeTable (edgeTable->edgeTable);
  66260. if (! et.isEmpty())
  66261. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66262. }
  66263. }
  66264. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66265. {
  66266. if (! image.hasAlphaChannel())
  66267. {
  66268. Path p;
  66269. p.addRectangle (srcClip);
  66270. clipToPath (p, t);
  66271. return;
  66272. }
  66273. dupeEdgeTableIfMultiplyReferenced();
  66274. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66275. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66276. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66277. EdgeTable& et = edgeTable->edgeTable;
  66278. if (transform.isOnlyTranslation())
  66279. {
  66280. // If our translation doesn't involve any distortion, just use a simple blit..
  66281. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66282. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66283. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66284. {
  66285. const int imageX = ((tx + 128) >> 8);
  66286. const int imageY = ((ty + 128) >> 8);
  66287. if (image.getFormat() == Image::ARGB)
  66288. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66289. else
  66290. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66291. return;
  66292. }
  66293. }
  66294. if (transform.isSingularity())
  66295. {
  66296. et.clipToRectangle (Rectangle<int>());
  66297. return;
  66298. }
  66299. {
  66300. Path p;
  66301. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66302. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66303. et.clipToEdgeTable (et2);
  66304. }
  66305. if (! et.isEmpty())
  66306. {
  66307. if (image.getFormat() == Image::ARGB)
  66308. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66309. else
  66310. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66311. }
  66312. }
  66313. template <class SrcPixelType>
  66314. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66315. {
  66316. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66317. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66318. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66319. et.getMaximumBounds().getWidth());
  66320. }
  66321. template <class SrcPixelType>
  66322. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66323. {
  66324. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66325. et.clipToRectangle (r);
  66326. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66327. for (int y = 0; y < r.getHeight(); ++y)
  66328. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66329. }
  66330. class EdgeTableHolder : public ReferenceCountedObject
  66331. {
  66332. public:
  66333. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66334. EdgeTable edgeTable;
  66335. };
  66336. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66337. int xOffset, yOffset;
  66338. Font font;
  66339. FillType fillType;
  66340. Graphics::ResamplingQuality interpolationQuality;
  66341. private:
  66342. LLGCSavedState& operator= (const LLGCSavedState&);
  66343. void dupeEdgeTableIfMultiplyReferenced() throw()
  66344. {
  66345. if (edgeTable->getReferenceCount() > 1)
  66346. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66347. }
  66348. template <class DestPixelType>
  66349. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66350. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66351. {
  66352. jassert (destData.pixelStride == sizeof (DestPixelType));
  66353. if (g.isRadial)
  66354. {
  66355. if (isIdentity)
  66356. {
  66357. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66358. et.iterate (renderer);
  66359. }
  66360. else
  66361. {
  66362. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66363. et.iterate (renderer);
  66364. }
  66365. }
  66366. else
  66367. {
  66368. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66369. et.iterate (renderer);
  66370. }
  66371. }
  66372. template <class DestPixelType>
  66373. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66374. {
  66375. jassert (destData.pixelStride == sizeof (DestPixelType));
  66376. if (replaceContents)
  66377. {
  66378. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66379. et.iterate (r);
  66380. }
  66381. else
  66382. {
  66383. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66384. et.iterate (r);
  66385. }
  66386. }
  66387. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66388. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66389. {
  66390. switch (destImage.getFormat())
  66391. {
  66392. case Image::ARGB:
  66393. switch (srcImage.getFormat())
  66394. {
  66395. case Image::ARGB:
  66396. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66397. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66398. break;
  66399. case Image::RGB:
  66400. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66401. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66402. break;
  66403. default:
  66404. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66405. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66406. break;
  66407. }
  66408. break;
  66409. case Image::RGB:
  66410. switch (srcImage.getFormat())
  66411. {
  66412. case Image::ARGB:
  66413. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66414. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66415. break;
  66416. case Image::RGB:
  66417. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66418. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66419. break;
  66420. default:
  66421. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66422. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66423. break;
  66424. }
  66425. break;
  66426. default:
  66427. switch (srcImage.getFormat())
  66428. {
  66429. case Image::ARGB:
  66430. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66431. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66432. break;
  66433. case Image::RGB:
  66434. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66435. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66436. break;
  66437. default:
  66438. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66439. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66440. break;
  66441. }
  66442. break;
  66443. }
  66444. }
  66445. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66446. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66447. {
  66448. switch (destImage.getFormat())
  66449. {
  66450. case Image::ARGB:
  66451. switch (srcImage.getFormat())
  66452. {
  66453. case Image::ARGB:
  66454. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66455. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66456. break;
  66457. case Image::RGB:
  66458. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66459. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66460. break;
  66461. default:
  66462. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66463. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66464. break;
  66465. }
  66466. break;
  66467. case Image::RGB:
  66468. switch (srcImage.getFormat())
  66469. {
  66470. case Image::ARGB:
  66471. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66472. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66473. break;
  66474. case Image::RGB:
  66475. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66476. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66477. break;
  66478. default:
  66479. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66480. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66481. break;
  66482. }
  66483. break;
  66484. default:
  66485. switch (srcImage.getFormat())
  66486. {
  66487. case Image::ARGB:
  66488. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66489. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66490. break;
  66491. case Image::RGB:
  66492. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66493. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66494. break;
  66495. default:
  66496. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66497. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66498. break;
  66499. }
  66500. break;
  66501. }
  66502. }
  66503. };
  66504. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66505. : image (image_)
  66506. {
  66507. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66508. FillType(), Graphics::mediumResamplingQuality);
  66509. }
  66510. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66511. {
  66512. }
  66513. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  66514. {
  66515. return false;
  66516. }
  66517. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  66518. {
  66519. currentState->xOffset += x;
  66520. currentState->yOffset += y;
  66521. }
  66522. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  66523. {
  66524. return currentState->clipToRectangle (r);
  66525. }
  66526. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  66527. {
  66528. return currentState->clipToRectangleList (clipRegion);
  66529. }
  66530. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  66531. {
  66532. currentState->excludeClipRectangle (r);
  66533. }
  66534. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  66535. {
  66536. currentState->clipToPath (path, transform);
  66537. }
  66538. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  66539. {
  66540. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  66541. }
  66542. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  66543. {
  66544. return currentState->edgeTable->edgeTable.getMaximumBounds()
  66545. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  66546. }
  66547. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  66548. {
  66549. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  66550. }
  66551. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  66552. {
  66553. return currentState->edgeTable->edgeTable.isEmpty();
  66554. }
  66555. void LowLevelGraphicsSoftwareRenderer::saveState()
  66556. {
  66557. stateStack.add (new LLGCSavedState (*currentState));
  66558. }
  66559. void LowLevelGraphicsSoftwareRenderer::restoreState()
  66560. {
  66561. LLGCSavedState* const top = stateStack.getLast();
  66562. if (top != 0)
  66563. {
  66564. currentState = top;
  66565. stateStack.removeLast (1, false);
  66566. }
  66567. else
  66568. {
  66569. jassertfalse // trying to pop with an empty stack!
  66570. }
  66571. }
  66572. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  66573. {
  66574. currentState->fillType = fillType;
  66575. }
  66576. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  66577. {
  66578. currentState->fillType.setOpacity (newOpacity);
  66579. }
  66580. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  66581. {
  66582. currentState->interpolationQuality = quality;
  66583. }
  66584. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  66585. {
  66586. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  66587. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  66588. if (! clipped.isEmpty())
  66589. {
  66590. EdgeTable et (clipped);
  66591. currentState->fillEdgeTable (image, et, replaceExistingContents);
  66592. }
  66593. }
  66594. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  66595. {
  66596. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  66597. path, transform.translated ((float) currentState->xOffset,
  66598. (float) currentState->yOffset));
  66599. currentState->fillEdgeTable (image, et);
  66600. }
  66601. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  66602. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  66603. {
  66604. jassert (sourceImage.getBounds().contains (srcClip));
  66605. currentState->renderImage (image, sourceImage, srcClip, transform,
  66606. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  66607. }
  66608. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  66609. {
  66610. Path p;
  66611. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  66612. fillPath (p, AffineTransform::identity);
  66613. }
  66614. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  66615. {
  66616. if (bottom > top)
  66617. {
  66618. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  66619. currentState->fillEdgeTable (image, et);
  66620. }
  66621. }
  66622. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  66623. {
  66624. if (right > left)
  66625. {
  66626. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  66627. (float) (right - left), 1.0f);
  66628. currentState->fillEdgeTable (image, et);
  66629. }
  66630. }
  66631. class GlyphCache : private DeletedAtShutdown
  66632. {
  66633. public:
  66634. GlyphCache() throw()
  66635. : accessCounter (0), hits (0), misses (0)
  66636. {
  66637. for (int i = 120; --i >= 0;)
  66638. glyphs.add (new CachedGlyph());
  66639. }
  66640. ~GlyphCache() throw()
  66641. {
  66642. clearSingletonInstance();
  66643. }
  66644. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  66645. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  66646. {
  66647. ++accessCounter;
  66648. int oldestCounter = std::numeric_limits<int>::max();
  66649. CachedGlyph* oldest = 0;
  66650. for (int i = glyphs.size(); --i >= 0;)
  66651. {
  66652. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  66653. if (glyph->glyph == glyphNumber && glyph->font == font)
  66654. {
  66655. ++hits;
  66656. glyph->lastAccessCount = accessCounter;
  66657. glyph->draw (state, image, x, y);
  66658. return;
  66659. }
  66660. if (glyph->lastAccessCount <= oldestCounter)
  66661. {
  66662. oldestCounter = glyph->lastAccessCount;
  66663. oldest = glyph;
  66664. }
  66665. }
  66666. if (hits + ++misses > (glyphs.size() << 4))
  66667. {
  66668. if (misses * 2 > hits)
  66669. {
  66670. for (int i = 32; --i >= 0;)
  66671. glyphs.add (new CachedGlyph());
  66672. }
  66673. hits = misses = 0;
  66674. oldest = glyphs.getLast();
  66675. }
  66676. jassert (oldest != 0);
  66677. oldest->lastAccessCount = accessCounter;
  66678. oldest->generate (font, glyphNumber);
  66679. oldest->draw (state, image, x, y);
  66680. }
  66681. class CachedGlyph
  66682. {
  66683. public:
  66684. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  66685. ~CachedGlyph() {}
  66686. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  66687. {
  66688. if (edgeTable != 0)
  66689. {
  66690. EdgeTable et (*edgeTable);
  66691. et.translate (x, roundToInt (y));
  66692. state.fillEdgeTable (image, et, false);
  66693. }
  66694. }
  66695. void generate (const Font& newFont, const int glyphNumber) throw()
  66696. {
  66697. font = newFont;
  66698. glyph = glyphNumber;
  66699. edgeTable = 0;
  66700. Path glyphPath;
  66701. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  66702. if (! glyphPath.isEmpty())
  66703. {
  66704. const float fontHeight = font.getHeight();
  66705. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  66706. .translated (0.0f, -0.5f));
  66707. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  66708. glyphPath, transform);
  66709. }
  66710. }
  66711. int glyph, lastAccessCount;
  66712. Font font;
  66713. juce_UseDebuggingNewOperator
  66714. private:
  66715. ScopedPointer <EdgeTable> edgeTable;
  66716. CachedGlyph (const CachedGlyph&);
  66717. CachedGlyph& operator= (const CachedGlyph&);
  66718. };
  66719. juce_UseDebuggingNewOperator
  66720. private:
  66721. OwnedArray <CachedGlyph> glyphs;
  66722. int accessCounter, hits, misses;
  66723. GlyphCache (const GlyphCache&);
  66724. GlyphCache& operator= (const GlyphCache&);
  66725. };
  66726. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  66727. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  66728. {
  66729. currentState->font = newFont;
  66730. }
  66731. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  66732. {
  66733. return currentState->font;
  66734. }
  66735. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  66736. {
  66737. Font& f = currentState->font;
  66738. if (transform.isOnlyTranslation())
  66739. {
  66740. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  66741. transform.getTranslationX() + (float) currentState->xOffset,
  66742. transform.getTranslationY() + (float) currentState->yOffset);
  66743. }
  66744. else
  66745. {
  66746. Path p;
  66747. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  66748. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  66749. }
  66750. }
  66751. #if JUCE_MSVC
  66752. #pragma warning (pop)
  66753. #endif
  66754. END_JUCE_NAMESPACE
  66755. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  66756. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  66757. BEGIN_JUCE_NAMESPACE
  66758. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  66759. : flags (other.flags)
  66760. {
  66761. }
  66762. RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  66763. {
  66764. flags = other.flags;
  66765. return *this;
  66766. }
  66767. void RectanglePlacement::applyTo (double& x, double& y,
  66768. double& w, double& h,
  66769. const double dx, const double dy,
  66770. const double dw, const double dh) const throw()
  66771. {
  66772. if (w == 0 || h == 0)
  66773. return;
  66774. if ((flags & stretchToFit) != 0)
  66775. {
  66776. x = dx;
  66777. y = dy;
  66778. w = dw;
  66779. h = dh;
  66780. }
  66781. else
  66782. {
  66783. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  66784. : jmin (dw / w, dh / h);
  66785. if ((flags & onlyReduceInSize) != 0)
  66786. scale = jmin (scale, 1.0);
  66787. if ((flags & onlyIncreaseInSize) != 0)
  66788. scale = jmax (scale, 1.0);
  66789. w *= scale;
  66790. h *= scale;
  66791. if ((flags & xLeft) != 0)
  66792. x = dx;
  66793. else if ((flags & xRight) != 0)
  66794. x = dx + dw - w;
  66795. else
  66796. x = dx + (dw - w) * 0.5;
  66797. if ((flags & yTop) != 0)
  66798. y = dy;
  66799. else if ((flags & yBottom) != 0)
  66800. y = dy + dh - h;
  66801. else
  66802. y = dy + (dh - h) * 0.5;
  66803. }
  66804. }
  66805. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  66806. float w, float h,
  66807. const float dx, const float dy,
  66808. const float dw, const float dh) const throw()
  66809. {
  66810. if (w == 0 || h == 0)
  66811. return AffineTransform::identity;
  66812. const float scaleX = dw / w;
  66813. const float scaleY = dh / h;
  66814. if ((flags & stretchToFit) != 0)
  66815. return AffineTransform::translation (-x, -y)
  66816. .scaled (scaleX, scaleY)
  66817. .translated (dx, dy);
  66818. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  66819. : jmin (scaleX, scaleY);
  66820. if ((flags & onlyReduceInSize) != 0)
  66821. scale = jmin (scale, 1.0f);
  66822. if ((flags & onlyIncreaseInSize) != 0)
  66823. scale = jmax (scale, 1.0f);
  66824. w *= scale;
  66825. h *= scale;
  66826. float newX = dx;
  66827. if ((flags & xRight) != 0)
  66828. newX += dw - w; // right
  66829. else if ((flags & xLeft) == 0)
  66830. newX += (dw - w) / 2.0f; // centre
  66831. float newY = dy;
  66832. if ((flags & yBottom) != 0)
  66833. newY += dh - h; // bottom
  66834. else if ((flags & yTop) == 0)
  66835. newY += (dh - h) / 2.0f; // centre
  66836. return AffineTransform::translation (-x, -y)
  66837. .scaled (scale, scale)
  66838. .translated (newX, newY);
  66839. }
  66840. END_JUCE_NAMESPACE
  66841. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  66842. /*** Start of inlined file: juce_Drawable.cpp ***/
  66843. BEGIN_JUCE_NAMESPACE
  66844. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  66845. const AffineTransform& transform_,
  66846. const float opacity_) throw()
  66847. : g (g_),
  66848. transform (transform_),
  66849. opacity (opacity_)
  66850. {
  66851. }
  66852. Drawable::Drawable()
  66853. {
  66854. }
  66855. Drawable::~Drawable()
  66856. {
  66857. }
  66858. void Drawable::draw (Graphics& g, const float opacity,
  66859. const AffineTransform& transform) const
  66860. {
  66861. render (RenderingContext (g, transform, opacity));
  66862. }
  66863. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  66864. {
  66865. draw (g, opacity, AffineTransform::translation (x, y));
  66866. }
  66867. void Drawable::drawWithin (Graphics& g,
  66868. const int destX,
  66869. const int destY,
  66870. const int destW,
  66871. const int destH,
  66872. const RectanglePlacement& placement,
  66873. const float opacity) const
  66874. {
  66875. if (destW > 0 && destH > 0)
  66876. {
  66877. Rectangle<float> bounds (getBounds());
  66878. draw (g, opacity,
  66879. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  66880. (float) destX, (float) destY,
  66881. (float) destW, (float) destH));
  66882. }
  66883. }
  66884. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  66885. {
  66886. Drawable* result = 0;
  66887. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  66888. if (image != 0)
  66889. {
  66890. DrawableImage* const di = new DrawableImage();
  66891. di->setImage (image, true);
  66892. result = di;
  66893. }
  66894. else
  66895. {
  66896. const String asString (String::createStringFromData (data, (int) numBytes));
  66897. XmlDocument doc (asString);
  66898. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  66899. if (outer != 0 && outer->hasTagName (T("svg")))
  66900. {
  66901. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  66902. if (svg != 0)
  66903. result = Drawable::createFromSVG (*svg);
  66904. }
  66905. }
  66906. return result;
  66907. }
  66908. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  66909. {
  66910. MemoryBlock mb;
  66911. dataSource.readIntoMemoryBlock (mb);
  66912. return createFromImageData (mb.getData(), mb.getSize());
  66913. }
  66914. Drawable* Drawable::createFromImageFile (const File& file)
  66915. {
  66916. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  66917. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  66918. }
  66919. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  66920. {
  66921. Drawable* d = DrawablePath::createFromValueTree (tree);
  66922. if (d == 0)
  66923. {
  66924. d = DrawableComposite::createFromValueTree (tree);
  66925. if (d == 0)
  66926. {
  66927. d = DrawableImage::createFromValueTree (tree);
  66928. if (d == 0)
  66929. d = DrawableText::createFromValueTree (tree);
  66930. }
  66931. }
  66932. return d;
  66933. }
  66934. END_JUCE_NAMESPACE
  66935. /*** End of inlined file: juce_Drawable.cpp ***/
  66936. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  66937. BEGIN_JUCE_NAMESPACE
  66938. DrawableComposite::DrawableComposite()
  66939. {
  66940. }
  66941. DrawableComposite::~DrawableComposite()
  66942. {
  66943. }
  66944. void DrawableComposite::insertDrawable (Drawable* drawable,
  66945. const AffineTransform& transform,
  66946. const int index)
  66947. {
  66948. if (drawable != 0)
  66949. {
  66950. if (! drawables.contains (drawable))
  66951. {
  66952. drawables.insert (index, drawable);
  66953. if (transform.isIdentity())
  66954. transforms.insert (index, 0);
  66955. else
  66956. transforms.insert (index, new AffineTransform (transform));
  66957. }
  66958. else
  66959. {
  66960. jassertfalse // trying to add a drawable that's already in here!
  66961. }
  66962. }
  66963. }
  66964. void DrawableComposite::insertDrawable (const Drawable& drawable,
  66965. const AffineTransform& transform,
  66966. const int index)
  66967. {
  66968. insertDrawable (drawable.createCopy(), transform, index);
  66969. }
  66970. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  66971. {
  66972. drawables.remove (index, deleteDrawable);
  66973. transforms.remove (index);
  66974. }
  66975. void DrawableComposite::bringToFront (const int index)
  66976. {
  66977. if (index >= 0 && index < drawables.size() - 1)
  66978. {
  66979. drawables.move (index, -1);
  66980. transforms.move (index, -1);
  66981. }
  66982. }
  66983. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  66984. {
  66985. if (drawables.size() > 0 && context.opacity > 0)
  66986. {
  66987. if (context.opacity >= 1.0f || drawables.size() == 1)
  66988. {
  66989. Drawable::RenderingContext contextCopy (context);
  66990. for (int i = 0; i < drawables.size(); ++i)
  66991. {
  66992. const AffineTransform* const t = transforms.getUnchecked(i);
  66993. contextCopy.transform = (t == 0) ? context.transform
  66994. : t->followedBy (context.transform);
  66995. drawables.getUnchecked(i)->render (contextCopy);
  66996. }
  66997. }
  66998. else
  66999. {
  67000. // To correctly render a whole composite layer with an overall transparency,
  67001. // we need to render everything opaquely into a temp buffer, then blend that
  67002. // with the target opacity...
  67003. const Rectangle<int> clipBounds (context.g.getClipBounds());
  67004. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67005. {
  67006. Graphics tempG (tempImage);
  67007. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67008. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67009. render (tempContext);
  67010. }
  67011. context.g.setOpacity (context.opacity);
  67012. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67013. }
  67014. }
  67015. }
  67016. const Rectangle<float> DrawableComposite::getBounds() const
  67017. {
  67018. Rectangle<float> bounds;
  67019. for (int i = 0; i < drawables.size(); ++i)
  67020. {
  67021. const Drawable* const d = drawables.getUnchecked(i);
  67022. const AffineTransform* const t = transforms.getUnchecked(i);
  67023. const Rectangle<float> childBounds (t == 0 ? d->getBounds()
  67024. : d->getBounds().transformed (*t));
  67025. if (bounds.isEmpty())
  67026. bounds = childBounds;
  67027. else if (! childBounds.isEmpty())
  67028. bounds = bounds.getUnion (childBounds);
  67029. }
  67030. return bounds;
  67031. }
  67032. bool DrawableComposite::hitTest (float x, float y) const
  67033. {
  67034. for (int i = 0; i < drawables.size(); ++i)
  67035. {
  67036. float tx = x;
  67037. float ty = y;
  67038. const AffineTransform* const t = transforms.getUnchecked(i);
  67039. if (t != 0)
  67040. t->inverted().transformPoint (tx, ty);
  67041. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67042. return true;
  67043. }
  67044. return false;
  67045. }
  67046. Drawable* DrawableComposite::createCopy() const
  67047. {
  67048. DrawableComposite* const dc = new DrawableComposite();
  67049. for (int i = 0; i < drawables.size(); ++i)
  67050. {
  67051. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67052. const AffineTransform* const t = transforms.getUnchecked(i);
  67053. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67054. }
  67055. return dc;
  67056. }
  67057. ValueTree DrawableComposite::createValueTree() const throw()
  67058. {
  67059. ValueTree v (T("Group"));
  67060. if (getName().isNotEmpty())
  67061. v.setProperty ("id", getName(), 0);
  67062. for (int i = 0; i < drawables.size(); ++i)
  67063. {
  67064. Drawable* const d = drawables.getUnchecked(i);
  67065. ValueTree child (d->createValueTree());
  67066. AffineTransform* transform = transforms.getUnchecked(i);
  67067. if (transform != 0)
  67068. {
  67069. String t;
  67070. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67071. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67072. child.setProperty ("transform", t, 0);
  67073. }
  67074. v.addChild (child, -1, 0);
  67075. }
  67076. return v;
  67077. }
  67078. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67079. {
  67080. if (! tree.hasType ("Group"))
  67081. return 0;
  67082. DrawableComposite* dc = new DrawableComposite();
  67083. dc->setName (tree ["id"]);
  67084. for (int i = 0; i < tree.getNumChildren(); ++i)
  67085. {
  67086. ValueTree childTree (tree.getChild (i));
  67087. Drawable* d = Drawable::createFromValueTree (childTree);
  67088. if (d != 0)
  67089. {
  67090. AffineTransform transform;
  67091. const String transformAtt (childTree ["transform"].toString());
  67092. if (transformAtt.isNotEmpty())
  67093. {
  67094. StringArray tokens;
  67095. tokens.addTokens (transformAtt.trim(), false);
  67096. tokens.removeEmptyStrings (true);
  67097. if (tokens.size() == 6)
  67098. {
  67099. float f[6];
  67100. for (int j = 0; j < 6; ++j)
  67101. f[j] = (float) tokens[j].getDoubleValue();
  67102. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67103. }
  67104. }
  67105. dc->insertDrawable (d, transform);
  67106. }
  67107. }
  67108. return dc;
  67109. }
  67110. END_JUCE_NAMESPACE
  67111. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67112. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67113. BEGIN_JUCE_NAMESPACE
  67114. DrawableImage::DrawableImage()
  67115. : image (0),
  67116. canDeleteImage (false),
  67117. opacity (1.0f),
  67118. overlayColour (0x00000000)
  67119. {
  67120. }
  67121. DrawableImage::~DrawableImage()
  67122. {
  67123. clearImage();
  67124. }
  67125. void DrawableImage::clearImage()
  67126. {
  67127. if (canDeleteImage && image != 0)
  67128. ImageCache::releaseOrDelete (image);
  67129. image = 0;
  67130. }
  67131. void DrawableImage::setImage (const Image& imageToCopy)
  67132. {
  67133. clearImage();
  67134. image = new Image (imageToCopy);
  67135. canDeleteImage = true;
  67136. }
  67137. void DrawableImage::setImage (Image* imageToUse,
  67138. const bool releaseWhenNotNeeded)
  67139. {
  67140. clearImage();
  67141. image = imageToUse;
  67142. canDeleteImage = releaseWhenNotNeeded;
  67143. }
  67144. void DrawableImage::setOpacity (const float newOpacity)
  67145. {
  67146. opacity = newOpacity;
  67147. }
  67148. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67149. {
  67150. overlayColour = newOverlayColour;
  67151. }
  67152. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67153. {
  67154. if (image != 0)
  67155. {
  67156. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67157. {
  67158. context.g.setOpacity (context.opacity * opacity);
  67159. context.g.drawImageTransformed (image, image->getBounds(),
  67160. context.transform, false);
  67161. }
  67162. if (! overlayColour.isTransparent())
  67163. {
  67164. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67165. context.g.drawImageTransformed (image, image->getBounds(),
  67166. context.transform, true);
  67167. }
  67168. }
  67169. }
  67170. const Rectangle<float> DrawableImage::getBounds() const
  67171. {
  67172. if (image == 0)
  67173. return Rectangle<float>();
  67174. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67175. }
  67176. bool DrawableImage::hitTest (float x, float y) const
  67177. {
  67178. return image != 0
  67179. && x >= 0.0f
  67180. && y >= 0.0f
  67181. && x < image->getWidth()
  67182. && y < image->getHeight()
  67183. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67184. }
  67185. Drawable* DrawableImage::createCopy() const
  67186. {
  67187. DrawableImage* const di = new DrawableImage();
  67188. di->opacity = opacity;
  67189. di->overlayColour = overlayColour;
  67190. if (image != 0)
  67191. {
  67192. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67193. {
  67194. di->setImage (*image);
  67195. }
  67196. else
  67197. {
  67198. ImageCache::incReferenceCount (image);
  67199. di->setImage (image, true);
  67200. }
  67201. }
  67202. return di;
  67203. }
  67204. ValueTree DrawableImage::createValueTree() const throw()
  67205. {
  67206. ValueTree v (T("Image"));
  67207. if (getName().isNotEmpty())
  67208. v.setProperty ("id", getName(), 0);
  67209. if (opacity < 1.0f)
  67210. v.setProperty ("opacity", (double) opacity, 0);
  67211. if (! overlayColour.isTransparent())
  67212. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67213. if (image != 0)
  67214. {
  67215. MemoryOutputStream imageData;
  67216. PNGImageFormat pngFormat;
  67217. if (pngFormat.writeImageToStream (*image, imageData))
  67218. {
  67219. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67220. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67221. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67222. v.setProperty ("data", base64, 0);
  67223. }
  67224. }
  67225. return v;
  67226. }
  67227. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67228. {
  67229. if (! tree.hasType ("Image"))
  67230. return 0;
  67231. DrawableImage* di = new DrawableImage();
  67232. di->setName (tree ["id"]);
  67233. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67234. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67235. MemoryBlock imageData;
  67236. if (imageData.fromBase64Encoding (tree ["data"]))
  67237. {
  67238. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67239. if (im == 0)
  67240. return false;
  67241. di->setImage (im, true);
  67242. }
  67243. return di;
  67244. }
  67245. END_JUCE_NAMESPACE
  67246. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67247. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67248. BEGIN_JUCE_NAMESPACE
  67249. DrawablePath::DrawablePath()
  67250. : mainFill (FillType (Colours::black)),
  67251. strokeFill (FillType (Colours::transparentBlack)),
  67252. strokeType (0.0f)
  67253. {
  67254. }
  67255. DrawablePath::~DrawablePath()
  67256. {
  67257. }
  67258. void DrawablePath::setPath (const Path& newPath) throw()
  67259. {
  67260. path = newPath;
  67261. updateOutline();
  67262. }
  67263. void DrawablePath::setFill (const FillType& newFill) throw()
  67264. {
  67265. mainFill = newFill;
  67266. }
  67267. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67268. {
  67269. strokeFill = newFill;
  67270. }
  67271. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67272. {
  67273. strokeType = newStrokeType;
  67274. updateOutline();
  67275. }
  67276. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67277. {
  67278. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67279. }
  67280. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67281. {
  67282. {
  67283. FillType f (mainFill);
  67284. if (f.isGradient())
  67285. f.gradient->multiplyOpacity (context.opacity);
  67286. f.transform = f.transform.followedBy (context.transform);
  67287. context.g.setFillType (f);
  67288. context.g.fillPath (path, context.transform);
  67289. }
  67290. if (strokeType.getStrokeThickness() > 0.0f)
  67291. {
  67292. FillType f (strokeFill);
  67293. if (f.isGradient())
  67294. f.gradient->multiplyOpacity (context.opacity);
  67295. f.transform = f.transform.followedBy (context.transform);
  67296. context.g.setFillType (f);
  67297. context.g.fillPath (stroke, context.transform);
  67298. }
  67299. }
  67300. void DrawablePath::updateOutline()
  67301. {
  67302. stroke.clear();
  67303. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67304. }
  67305. const Rectangle<float> DrawablePath::getBounds() const
  67306. {
  67307. if (strokeType.getStrokeThickness() > 0.0f)
  67308. return stroke.getBounds();
  67309. else
  67310. return path.getBounds();
  67311. }
  67312. bool DrawablePath::hitTest (float x, float y) const
  67313. {
  67314. return path.contains (x, y)
  67315. || stroke.contains (x, y);
  67316. }
  67317. Drawable* DrawablePath::createCopy() const
  67318. {
  67319. DrawablePath* const dp = new DrawablePath();
  67320. dp->path = path;
  67321. dp->stroke = stroke;
  67322. dp->mainFill = mainFill;
  67323. dp->strokeFill = strokeFill;
  67324. dp->strokeType = strokeType;
  67325. return dp;
  67326. }
  67327. static const FillType readFillTypeFromTree (const ValueTree& v)
  67328. {
  67329. const String type (v["type"].toString());
  67330. if (type.equalsIgnoreCase (T("solid")))
  67331. {
  67332. const String colour (v ["colour"].toString());
  67333. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67334. : (uint32) colour.getHexValue32()));
  67335. }
  67336. else if (type.equalsIgnoreCase ("gradient"))
  67337. {
  67338. ColourGradient g;
  67339. g.x1 = v["x1"];
  67340. g.y1 = v["y1"];
  67341. g.x2 = v["x2"];
  67342. g.y2 = v["y2"];
  67343. g.isRadial = v["radial"];
  67344. StringArray colours;
  67345. colours.addTokens (v["colours"].toString(), false);
  67346. for (int i = 0; i < colours.size() / 2; ++i)
  67347. g.addColour (colours[i * 2].getDoubleValue(),
  67348. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67349. return FillType (g);
  67350. }
  67351. jassertfalse
  67352. return FillType();
  67353. }
  67354. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67355. {
  67356. ValueTree v (tagName);
  67357. if (fillType.isColour())
  67358. {
  67359. v.setProperty ("type", T("solid"), 0);
  67360. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67361. }
  67362. else if (fillType.isGradient())
  67363. {
  67364. v.setProperty ("type", T("gradient"), 0);
  67365. v.setProperty ("x1", fillType.gradient->x1, 0);
  67366. v.setProperty ("y1", fillType.gradient->y1, 0);
  67367. v.setProperty ("x2", fillType.gradient->x2, 0);
  67368. v.setProperty ("y2", fillType.gradient->y2, 0);
  67369. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67370. String s;
  67371. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67372. s << " " << fillType.gradient->getColourPosition (i)
  67373. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67374. v.setProperty ("colours", s.trimStart(), 0);
  67375. }
  67376. else
  67377. {
  67378. jassertfalse //xxx
  67379. }
  67380. return v;
  67381. }
  67382. ValueTree DrawablePath::createValueTree() const throw()
  67383. {
  67384. ValueTree v (T("Path"));
  67385. v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0);
  67386. v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0);
  67387. if (getName().isNotEmpty())
  67388. v.setProperty ("id", getName(), 0);
  67389. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67390. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67391. ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0);
  67392. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67393. ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0);
  67394. v.setProperty ("path", path.toString(), 0);
  67395. return v;
  67396. }
  67397. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67398. {
  67399. if (! tree.hasType ("Path"))
  67400. return 0;
  67401. DrawablePath* p = new DrawablePath();
  67402. p->setName (tree ["id"]);
  67403. p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill")));
  67404. p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke")));
  67405. const String jointStyle (tree ["jointStyle"].toString());
  67406. const String endStyle (tree ["capStyle"].toString());
  67407. p->strokeType
  67408. = PathStrokeType (tree ["strokeWidth"],
  67409. jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
  67410. : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
  67411. : PathStrokeType::mitered),
  67412. endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square
  67413. : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded
  67414. : PathStrokeType::butt));
  67415. p->path.clear();
  67416. p->path.restoreFromString (tree ["path"]);
  67417. p->updateOutline();
  67418. return p;
  67419. }
  67420. END_JUCE_NAMESPACE
  67421. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67422. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67423. BEGIN_JUCE_NAMESPACE
  67424. DrawableText::DrawableText()
  67425. : colour (Colours::white)
  67426. {
  67427. }
  67428. DrawableText::~DrawableText()
  67429. {
  67430. }
  67431. void DrawableText::setText (const GlyphArrangement& newText)
  67432. {
  67433. text = newText;
  67434. }
  67435. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67436. {
  67437. text.clear();
  67438. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67439. }
  67440. void DrawableText::setColour (const Colour& newColour)
  67441. {
  67442. colour = newColour;
  67443. }
  67444. void DrawableText::render (const Drawable::RenderingContext& context) const
  67445. {
  67446. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67447. text.draw (context.g, context.transform);
  67448. }
  67449. const Rectangle<float> DrawableText::getBounds() const
  67450. {
  67451. float x, y, w, h;
  67452. text.getBoundingBox (0, -1, x, y, w, h, false); // (really returns top, left, bottom, right)
  67453. w -= x;
  67454. h -= y;
  67455. return Rectangle<float> (x, y, w, h);
  67456. }
  67457. bool DrawableText::hitTest (float x, float y) const
  67458. {
  67459. return text.findGlyphIndexAt (x, y) >= 0;
  67460. }
  67461. Drawable* DrawableText::createCopy() const
  67462. {
  67463. DrawableText* const dt = new DrawableText();
  67464. dt->text = text;
  67465. dt->colour = colour;
  67466. return dt;
  67467. }
  67468. ValueTree DrawableText::createValueTree() const throw()
  67469. {
  67470. ValueTree v (T("Text"));
  67471. if (getName().isNotEmpty())
  67472. v.setProperty ("id", getName(), 0);
  67473. jassertfalse // xxx not finished!
  67474. return v;
  67475. }
  67476. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67477. {
  67478. if (! tree.hasType ("Text"))
  67479. return 0;
  67480. DrawableText* dt = new DrawableText();
  67481. dt->setName (tree ["id"]);
  67482. jassertfalse // xxx not finished!
  67483. return dt;
  67484. }
  67485. END_JUCE_NAMESPACE
  67486. /*** End of inlined file: juce_DrawableText.cpp ***/
  67487. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67488. BEGIN_JUCE_NAMESPACE
  67489. class SVGState
  67490. {
  67491. public:
  67492. SVGState (const XmlElement* const topLevel)
  67493. : topLevelXml (topLevel),
  67494. elementX (0), elementY (0),
  67495. width (512), height (512),
  67496. viewBoxW (0), viewBoxH (0)
  67497. {
  67498. }
  67499. ~SVGState()
  67500. {
  67501. }
  67502. Drawable* parseSVGElement (const XmlElement& xml)
  67503. {
  67504. if (! xml.hasTagName (T("svg")))
  67505. return 0;
  67506. DrawableComposite* const drawable = new DrawableComposite();
  67507. drawable->setName (xml.getStringAttribute (T("id")));
  67508. SVGState newState (*this);
  67509. if (xml.hasAttribute (T("transform")))
  67510. newState.addTransform (xml);
  67511. newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW);
  67512. newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH);
  67513. newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW);
  67514. newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH);
  67515. if (xml.hasAttribute (T("viewBox")))
  67516. {
  67517. const String viewParams (xml.getStringAttribute (T("viewBox")));
  67518. int i = 0;
  67519. float vx, vy, vw, vh;
  67520. if (parseCoords (viewParams, vx, vy, i, true)
  67521. && parseCoords (viewParams, vw, vh, i, true)
  67522. && vw > 0
  67523. && vh > 0)
  67524. {
  67525. newState.viewBoxW = vw;
  67526. newState.viewBoxH = vh;
  67527. int placementFlags = 0;
  67528. const String aspect (xml.getStringAttribute (T("preserveAspectRatio")));
  67529. if (aspect.containsIgnoreCase (T("none")))
  67530. {
  67531. placementFlags = RectanglePlacement::stretchToFit;
  67532. }
  67533. else
  67534. {
  67535. if (aspect.containsIgnoreCase (T("slice")))
  67536. placementFlags |= RectanglePlacement::fillDestination;
  67537. if (aspect.containsIgnoreCase (T("xMin")))
  67538. placementFlags |= RectanglePlacement::xLeft;
  67539. else if (aspect.containsIgnoreCase (T("xMax")))
  67540. placementFlags |= RectanglePlacement::xRight;
  67541. else
  67542. placementFlags |= RectanglePlacement::xMid;
  67543. if (aspect.containsIgnoreCase (T("yMin")))
  67544. placementFlags |= RectanglePlacement::yTop;
  67545. else if (aspect.containsIgnoreCase (T("yMax")))
  67546. placementFlags |= RectanglePlacement::yBottom;
  67547. else
  67548. placementFlags |= RectanglePlacement::yMid;
  67549. }
  67550. const RectanglePlacement placement (placementFlags);
  67551. newState.transform
  67552. = placement.getTransformToFit (vx, vy, vw, vh,
  67553. 0.0f, 0.0f, newState.width, newState.height)
  67554. .followedBy (newState.transform);
  67555. }
  67556. }
  67557. else
  67558. {
  67559. if (viewBoxW == 0)
  67560. newState.viewBoxW = newState.width;
  67561. if (viewBoxH == 0)
  67562. newState.viewBoxH = newState.height;
  67563. }
  67564. newState.parseSubElements (xml, drawable);
  67565. return drawable;
  67566. }
  67567. private:
  67568. const XmlElement* const topLevelXml;
  67569. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  67570. AffineTransform transform;
  67571. String cssStyleText;
  67572. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  67573. {
  67574. forEachXmlChildElement (xml, e)
  67575. {
  67576. Drawable* d = 0;
  67577. if (e->hasTagName (T("g")))
  67578. d = parseGroupElement (*e);
  67579. else if (e->hasTagName (T("svg")))
  67580. d = parseSVGElement (*e);
  67581. else if (e->hasTagName (T("path")))
  67582. d = parsePath (*e);
  67583. else if (e->hasTagName (T("rect")))
  67584. d = parseRect (*e);
  67585. else if (e->hasTagName (T("circle")))
  67586. d = parseCircle (*e);
  67587. else if (e->hasTagName (T("ellipse")))
  67588. d = parseEllipse (*e);
  67589. else if (e->hasTagName (T("line")))
  67590. d = parseLine (*e);
  67591. else if (e->hasTagName (T("polyline")))
  67592. d = parsePolygon (*e, true);
  67593. else if (e->hasTagName (T("polygon")))
  67594. d = parsePolygon (*e, false);
  67595. else if (e->hasTagName (T("text")))
  67596. d = parseText (*e);
  67597. else if (e->hasTagName (T("switch")))
  67598. d = parseSwitch (*e);
  67599. else if (e->hasTagName (T("style")))
  67600. parseCSSStyle (*e);
  67601. parentDrawable->insertDrawable (d);
  67602. }
  67603. }
  67604. DrawableComposite* parseSwitch (const XmlElement& xml)
  67605. {
  67606. const XmlElement* const group = xml.getChildByName (T("g"));
  67607. if (group != 0)
  67608. return parseGroupElement (*group);
  67609. return 0;
  67610. }
  67611. DrawableComposite* parseGroupElement (const XmlElement& xml)
  67612. {
  67613. DrawableComposite* const drawable = new DrawableComposite();
  67614. drawable->setName (xml.getStringAttribute (T("id")));
  67615. if (xml.hasAttribute (T("transform")))
  67616. {
  67617. SVGState newState (*this);
  67618. newState.addTransform (xml);
  67619. newState.parseSubElements (xml, drawable);
  67620. }
  67621. else
  67622. {
  67623. parseSubElements (xml, drawable);
  67624. }
  67625. return drawable;
  67626. }
  67627. Drawable* parsePath (const XmlElement& xml) const
  67628. {
  67629. const String d (xml.getStringAttribute (T("d")).trimStart());
  67630. Path path;
  67631. if (getStyleAttribute (&xml, T("fill-rule")).trim().equalsIgnoreCase (T("evenodd")))
  67632. path.setUsingNonZeroWinding (false);
  67633. int index = 0;
  67634. float lastX = 0, lastY = 0;
  67635. float lastX2 = 0, lastY2 = 0;
  67636. tchar lastCommandChar = 0;
  67637. bool isRelative = true;
  67638. bool carryOn = true;
  67639. const String validCommandChars (T("MmLlHhVvCcSsQqTtAaZz"));
  67640. for (;;)
  67641. {
  67642. float x, y, x2, y2, x3, y3;
  67643. if (validCommandChars.containsChar (d[index]))
  67644. {
  67645. lastCommandChar = d [index++];
  67646. isRelative = (lastCommandChar >= 'a' && lastCommandChar <= 'z');
  67647. }
  67648. switch (lastCommandChar)
  67649. {
  67650. case T('M'):
  67651. case T('m'):
  67652. case T('L'):
  67653. case T('l'):
  67654. if (parseCoords (d, x, y, index, false))
  67655. {
  67656. if (isRelative)
  67657. {
  67658. x += lastX;
  67659. y += lastY;
  67660. }
  67661. if (lastCommandChar == T('M') || lastCommandChar == T('m'))
  67662. path.startNewSubPath (x, y);
  67663. else
  67664. path.lineTo (x, y);
  67665. lastX2 = lastX;
  67666. lastY2 = lastY;
  67667. lastX = x;
  67668. lastY = y;
  67669. }
  67670. else
  67671. {
  67672. ++index;
  67673. }
  67674. break;
  67675. case T('H'):
  67676. case T('h'):
  67677. if (parseCoord (d, x, index, false, true))
  67678. {
  67679. if (isRelative)
  67680. x += lastX;
  67681. path.lineTo (x, lastY);
  67682. lastX2 = lastX;
  67683. lastX = x;
  67684. }
  67685. else
  67686. {
  67687. ++index;
  67688. }
  67689. break;
  67690. case T('V'):
  67691. case T('v'):
  67692. if (parseCoord (d, y, index, false, false))
  67693. {
  67694. if (isRelative)
  67695. y += lastY;
  67696. path.lineTo (lastX, y);
  67697. lastY2 = lastY;
  67698. lastY = y;
  67699. }
  67700. else
  67701. {
  67702. ++index;
  67703. }
  67704. break;
  67705. case T('C'):
  67706. case T('c'):
  67707. if (parseCoords (d, x, y, index, false)
  67708. && parseCoords (d, x2, y2, index, false)
  67709. && parseCoords (d, x3, y3, index, false))
  67710. {
  67711. if (isRelative)
  67712. {
  67713. x += lastX;
  67714. y += lastY;
  67715. x2 += lastX;
  67716. y2 += lastY;
  67717. x3 += lastX;
  67718. y3 += lastY;
  67719. }
  67720. path.cubicTo (x, y, x2, y2, x3, y3);
  67721. lastX2 = x2;
  67722. lastY2 = y2;
  67723. lastX = x3;
  67724. lastY = y3;
  67725. }
  67726. else
  67727. {
  67728. ++index;
  67729. }
  67730. break;
  67731. case T('S'):
  67732. case T('s'):
  67733. if (parseCoords (d, x, y, index, false)
  67734. && parseCoords (d, x3, y3, index, false))
  67735. {
  67736. if (isRelative)
  67737. {
  67738. x += lastX;
  67739. y += lastY;
  67740. x3 += lastX;
  67741. y3 += lastY;
  67742. }
  67743. x2 = lastX + (lastX - lastX2);
  67744. y2 = lastY + (lastY - lastY2);
  67745. path.cubicTo (x2, y2, x, y, x3, y3);
  67746. lastX2 = x;
  67747. lastY2 = y;
  67748. lastX = x3;
  67749. lastY = y3;
  67750. }
  67751. else
  67752. {
  67753. ++index;
  67754. }
  67755. break;
  67756. case T('Q'):
  67757. case T('q'):
  67758. if (parseCoords (d, x, y, index, false)
  67759. && parseCoords (d, x2, y2, index, false))
  67760. {
  67761. if (isRelative)
  67762. {
  67763. x += lastX;
  67764. y += lastY;
  67765. x2 += lastX;
  67766. y2 += lastY;
  67767. }
  67768. path.quadraticTo (x, y, x2, y2);
  67769. lastX2 = x;
  67770. lastY2 = y;
  67771. lastX = x2;
  67772. lastY = y2;
  67773. }
  67774. else
  67775. {
  67776. ++index;
  67777. }
  67778. break;
  67779. case T('T'):
  67780. case T('t'):
  67781. if (parseCoords (d, x, y, index, false))
  67782. {
  67783. if (isRelative)
  67784. {
  67785. x += lastX;
  67786. y += lastY;
  67787. }
  67788. x2 = lastX + (lastX - lastX2);
  67789. y2 = lastY + (lastY - lastY2);
  67790. path.quadraticTo (x2, y2, x, y);
  67791. lastX2 = x2;
  67792. lastY2 = y2;
  67793. lastX = x;
  67794. lastY = y;
  67795. }
  67796. else
  67797. {
  67798. ++index;
  67799. }
  67800. break;
  67801. case T('A'):
  67802. case T('a'):
  67803. if (parseCoords (d, x, y, index, false))
  67804. {
  67805. String num;
  67806. if (parseNextNumber (d, num, index, false))
  67807. {
  67808. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  67809. if (parseNextNumber (d, num, index, false))
  67810. {
  67811. const bool largeArc = num.getIntValue() != 0;
  67812. if (parseNextNumber (d, num, index, false))
  67813. {
  67814. const bool sweep = num.getIntValue() != 0;
  67815. if (parseCoords (d, x2, y2, index, false))
  67816. {
  67817. if (isRelative)
  67818. {
  67819. x2 += lastX;
  67820. y2 += lastY;
  67821. }
  67822. if (lastX != x2 || lastY != y2)
  67823. {
  67824. double centreX, centreY, startAngle, deltaAngle;
  67825. double rx = x, ry = y;
  67826. endpointToCentreParameters (lastX, lastY, x2, y2,
  67827. angle, largeArc, sweep,
  67828. rx, ry, centreX, centreY,
  67829. startAngle, deltaAngle);
  67830. path.addCentredArc ((float) centreX, (float) centreY,
  67831. (float) rx, (float) ry,
  67832. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  67833. false);
  67834. path.lineTo (x2, y2);
  67835. }
  67836. lastX2 = lastX;
  67837. lastY2 = lastY;
  67838. lastX = x2;
  67839. lastY = y2;
  67840. }
  67841. }
  67842. }
  67843. }
  67844. }
  67845. else
  67846. {
  67847. ++index;
  67848. }
  67849. break;
  67850. case T('Z'):
  67851. case T('z'):
  67852. path.closeSubPath();
  67853. while (CharacterFunctions::isWhitespace (d [index]))
  67854. ++index;
  67855. break;
  67856. default:
  67857. carryOn = false;
  67858. break;
  67859. }
  67860. if (! carryOn)
  67861. break;
  67862. }
  67863. return parseShape (xml, path);
  67864. }
  67865. Drawable* parseRect (const XmlElement& xml) const
  67866. {
  67867. Path rect;
  67868. const bool hasRX = xml.hasAttribute (T("rx"));
  67869. const bool hasRY = xml.hasAttribute (T("ry"));
  67870. if (hasRX || hasRY)
  67871. {
  67872. float rx = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  67873. float ry = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  67874. if (! hasRX)
  67875. rx = ry;
  67876. else if (! hasRY)
  67877. ry = rx;
  67878. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  67879. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  67880. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  67881. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH),
  67882. rx, ry);
  67883. }
  67884. else
  67885. {
  67886. rect.addRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  67887. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  67888. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  67889. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH));
  67890. }
  67891. return parseShape (xml, rect);
  67892. }
  67893. Drawable* parseCircle (const XmlElement& xml) const
  67894. {
  67895. Path circle;
  67896. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  67897. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  67898. const float radius = getCoordLength (xml.getStringAttribute (T("r")), viewBoxW);
  67899. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  67900. return parseShape (xml, circle);
  67901. }
  67902. Drawable* parseEllipse (const XmlElement& xml) const
  67903. {
  67904. Path ellipse;
  67905. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  67906. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  67907. const float radiusX = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  67908. const float radiusY = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  67909. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  67910. return parseShape (xml, ellipse);
  67911. }
  67912. Drawable* parseLine (const XmlElement& xml) const
  67913. {
  67914. Path line;
  67915. const float x1 = getCoordLength (xml.getStringAttribute (T("x1")), viewBoxW);
  67916. const float y1 = getCoordLength (xml.getStringAttribute (T("y1")), viewBoxH);
  67917. const float x2 = getCoordLength (xml.getStringAttribute (T("x2")), viewBoxW);
  67918. const float y2 = getCoordLength (xml.getStringAttribute (T("y2")), viewBoxH);
  67919. line.startNewSubPath (x1, y1);
  67920. line.lineTo (x2, y2);
  67921. return parseShape (xml, line);
  67922. }
  67923. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  67924. {
  67925. const String points (xml.getStringAttribute (T("points")));
  67926. Path path;
  67927. int index = 0;
  67928. float x, y;
  67929. if (parseCoords (points, x, y, index, true))
  67930. {
  67931. float firstX = x;
  67932. float firstY = y;
  67933. float lastX = 0, lastY = 0;
  67934. path.startNewSubPath (x, y);
  67935. while (parseCoords (points, x, y, index, true))
  67936. {
  67937. lastX = x;
  67938. lastY = y;
  67939. path.lineTo (x, y);
  67940. }
  67941. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  67942. path.closeSubPath();
  67943. }
  67944. return parseShape (xml, path);
  67945. }
  67946. Drawable* parseShape (const XmlElement& xml, Path& path,
  67947. const bool shouldParseTransform = true) const
  67948. {
  67949. if (shouldParseTransform && xml.hasAttribute (T("transform")))
  67950. {
  67951. SVGState newState (*this);
  67952. newState.addTransform (xml);
  67953. return newState.parseShape (xml, path, false);
  67954. }
  67955. DrawablePath* dp = new DrawablePath();
  67956. dp->setName (xml.getStringAttribute (T("id")));
  67957. dp->setFill (FillType (Colours::transparentBlack));
  67958. path.applyTransform (transform);
  67959. dp->setPath (path);
  67960. Path::Iterator iter (path);
  67961. bool containsClosedSubPath = false;
  67962. while (iter.next())
  67963. {
  67964. if (iter.elementType == Path::Iterator::closePath)
  67965. {
  67966. containsClosedSubPath = true;
  67967. break;
  67968. }
  67969. }
  67970. dp->setFill (getPathFillType (path,
  67971. getStyleAttribute (&xml, T("fill")),
  67972. getStyleAttribute (&xml, T("fill-opacity")),
  67973. getStyleAttribute (&xml, T("opacity")),
  67974. containsClosedSubPath ? Colours::black
  67975. : Colours::transparentBlack));
  67976. const String strokeType (getStyleAttribute (&xml, T("stroke")));
  67977. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase (T("none")))
  67978. {
  67979. dp->setStrokeFill (getPathFillType (path, strokeType,
  67980. getStyleAttribute (&xml, T("stroke-opacity")),
  67981. getStyleAttribute (&xml, T("opacity")),
  67982. Colours::transparentBlack));
  67983. dp->setStrokeType (getStrokeFor (&xml));
  67984. }
  67985. return dp;
  67986. }
  67987. const XmlElement* findLinkedElement (const XmlElement* e) const
  67988. {
  67989. const String id (e->getStringAttribute (T("xlink:href")));
  67990. if (! id.startsWithChar (T('#')))
  67991. return 0;
  67992. return findElementForId (topLevelXml, id.substring (1));
  67993. }
  67994. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  67995. {
  67996. if (fillXml == 0)
  67997. return;
  67998. forEachXmlChildElementWithTagName (*fillXml, e, T("stop"))
  67999. {
  68000. int index = 0;
  68001. Colour col (parseColour (getStyleAttribute (e, T("stop-color")), index, Colours::black));
  68002. const String opacity (getStyleAttribute (e, T("stop-opacity"), T("1")));
  68003. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68004. double offset = e->getDoubleAttribute (T("offset"));
  68005. if (e->getStringAttribute (T("offset")).containsChar (T('%')))
  68006. offset *= 0.01;
  68007. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68008. }
  68009. }
  68010. const FillType getPathFillType (const Path& path,
  68011. const String& fill,
  68012. const String& fillOpacity,
  68013. const String& overallOpacity,
  68014. const Colour& defaultColour) const
  68015. {
  68016. float opacity = 1.0f;
  68017. if (overallOpacity.isNotEmpty())
  68018. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68019. if (fillOpacity.isNotEmpty())
  68020. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68021. if (fill.startsWithIgnoreCase (T("url")))
  68022. {
  68023. const String id (fill.fromFirstOccurrenceOf (T("#"), false, false)
  68024. .upToLastOccurrenceOf (T(")"), false, false).trim());
  68025. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68026. if (fillXml != 0
  68027. && (fillXml->hasTagName (T("linearGradient"))
  68028. || fillXml->hasTagName (T("radialGradient"))))
  68029. {
  68030. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68031. ColourGradient gradient;
  68032. addGradientStopsIn (gradient, inheritedFrom);
  68033. addGradientStopsIn (gradient, fillXml);
  68034. if (gradient.getNumColours() > 0)
  68035. {
  68036. gradient.addColour (0.0, gradient.getColour (0));
  68037. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68038. }
  68039. else
  68040. {
  68041. gradient.addColour (0.0, Colours::black);
  68042. gradient.addColour (1.0, Colours::black);
  68043. }
  68044. if (overallOpacity.isNotEmpty())
  68045. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68046. jassert (gradient.getNumColours() > 0);
  68047. gradient.isRadial = fillXml->hasTagName (T("radialGradient"));
  68048. float width = viewBoxW;
  68049. float height = viewBoxH;
  68050. float dx = 0.0f;
  68051. float dy = 0.0f;
  68052. const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse"));
  68053. if (! userSpace)
  68054. {
  68055. const Rectangle<float> bounds (path.getBounds());
  68056. dx = bounds.getX();
  68057. dy = bounds.getY();
  68058. width = bounds.getWidth();
  68059. height = bounds.getHeight();
  68060. }
  68061. if (gradient.isRadial)
  68062. {
  68063. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("cx"), T("50%")), width);
  68064. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("cy"), T("50%")), height);
  68065. const float radius = getCoordLength (fillXml->getStringAttribute (T("r"), T("50%")), width);
  68066. gradient.x2 = gradient.x1 + radius;
  68067. gradient.y2 = gradient.y1;
  68068. //xxx (the fx, fy focal point isn't handled properly here..)
  68069. }
  68070. else
  68071. {
  68072. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("x1"), T("0%")), width);
  68073. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("y1"), T("0%")), height);
  68074. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute (T("x2"), T("100%")), width);
  68075. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute (T("y2"), T("0%")), height);
  68076. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68077. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68078. }
  68079. FillType type (gradient);
  68080. type.transform = parseTransform (fillXml->getStringAttribute (T("gradientTransform")))
  68081. .followedBy (transform);
  68082. return type;
  68083. }
  68084. }
  68085. if (fill.equalsIgnoreCase (T("none")))
  68086. return Colours::transparentBlack;
  68087. int i = 0;
  68088. const Colour colour (parseColour (fill, i, defaultColour));
  68089. return colour.withMultipliedAlpha (opacity);
  68090. }
  68091. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68092. {
  68093. const String width (getStyleAttribute (xml, T("stroke-width")));
  68094. const String cap (getStyleAttribute (xml, T("stroke-linecap")));
  68095. const String join (getStyleAttribute (xml, T("stroke-linejoin")));
  68096. //const String mitreLimit (getStyleAttribute (xml, T("stroke-miterlimit")));
  68097. //const String dashArray (getStyleAttribute (xml, T("stroke-dasharray")));
  68098. //const String dashOffset (getStyleAttribute (xml, T("stroke-dashoffset")));
  68099. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68100. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68101. if (join.equalsIgnoreCase (T("round")))
  68102. joinStyle = PathStrokeType::curved;
  68103. else if (join.equalsIgnoreCase (T("bevel")))
  68104. joinStyle = PathStrokeType::beveled;
  68105. if (cap.equalsIgnoreCase (T("round")))
  68106. capStyle = PathStrokeType::rounded;
  68107. else if (cap.equalsIgnoreCase (T("square")))
  68108. capStyle = PathStrokeType::square;
  68109. float ox = 0.0f, oy = 0.0f;
  68110. transform.transformPoint (ox, oy);
  68111. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68112. transform.transformPoint (x, y);
  68113. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68114. joinStyle, capStyle);
  68115. }
  68116. Drawable* parseText (const XmlElement& xml)
  68117. {
  68118. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68119. getCoordList (xCoords, getInheritedAttribute (&xml, T("x")), true, true);
  68120. getCoordList (yCoords, getInheritedAttribute (&xml, T("y")), true, false);
  68121. getCoordList (dxCoords, getInheritedAttribute (&xml, T("dx")), true, true);
  68122. getCoordList (dyCoords, getInheritedAttribute (&xml, T("dy")), true, false);
  68123. //xxx not done text yet!
  68124. forEachXmlChildElement (xml, e)
  68125. {
  68126. if (e->isTextElement())
  68127. {
  68128. const String text (e->getText());
  68129. Path path;
  68130. Drawable* s = parseShape (*e, path);
  68131. delete s;
  68132. }
  68133. else if (e->hasTagName (T("tspan")))
  68134. {
  68135. Drawable* s = parseText (*e);
  68136. delete s;
  68137. }
  68138. }
  68139. return 0;
  68140. }
  68141. void addTransform (const XmlElement& xml)
  68142. {
  68143. transform = parseTransform (xml.getStringAttribute (T("transform")))
  68144. .followedBy (transform);
  68145. }
  68146. bool parseCoord (const String& s, float& value, int& index,
  68147. const bool allowUnits, const bool isX) const
  68148. {
  68149. String number;
  68150. if (! parseNextNumber (s, number, index, allowUnits))
  68151. {
  68152. value = 0;
  68153. return false;
  68154. }
  68155. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68156. return true;
  68157. }
  68158. bool parseCoords (const String& s, float& x, float& y,
  68159. int& index, const bool allowUnits) const
  68160. {
  68161. return parseCoord (s, x, index, allowUnits, true)
  68162. && parseCoord (s, y, index, allowUnits, false);
  68163. }
  68164. float getCoordLength (const String& s, const float sizeForProportions) const
  68165. {
  68166. float n = s.getFloatValue();
  68167. const int len = s.length();
  68168. if (len > 2)
  68169. {
  68170. const float dpi = 96.0f;
  68171. const tchar n1 = s [len - 2];
  68172. const tchar n2 = s [len - 1];
  68173. if (n1 == T('i') && n2 == T('n'))
  68174. n *= dpi;
  68175. else if (n1 == T('m') && n2 == T('m'))
  68176. n *= dpi / 25.4f;
  68177. else if (n1 == T('c') && n2 == T('m'))
  68178. n *= dpi / 2.54f;
  68179. else if (n1 == T('p') && n2 == T('c'))
  68180. n *= 15.0f;
  68181. else if (n2 == T('%'))
  68182. n *= 0.01f * sizeForProportions;
  68183. }
  68184. return n;
  68185. }
  68186. void getCoordList (Array <float>& coords, const String& list,
  68187. const bool allowUnits, const bool isX) const
  68188. {
  68189. int index = 0;
  68190. float value;
  68191. while (parseCoord (list, value, index, allowUnits, isX))
  68192. coords.add (value);
  68193. }
  68194. void parseCSSStyle (const XmlElement& xml)
  68195. {
  68196. cssStyleText = xml.getAllSubText() + T("\n") + cssStyleText;
  68197. }
  68198. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68199. const String& defaultValue = String::empty) const
  68200. {
  68201. if (xml->hasAttribute (attributeName))
  68202. return xml->getStringAttribute (attributeName, defaultValue);
  68203. const String styleAtt (xml->getStringAttribute (T("style")));
  68204. if (styleAtt.isNotEmpty())
  68205. {
  68206. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68207. if (value.isNotEmpty())
  68208. return value;
  68209. }
  68210. else if (xml->hasAttribute (T("class")))
  68211. {
  68212. const String className (T(".") + xml->getStringAttribute (T("class")));
  68213. int index = cssStyleText.indexOfIgnoreCase (className + T(" "));
  68214. if (index < 0)
  68215. index = cssStyleText.indexOfIgnoreCase (className + T("{"));
  68216. if (index >= 0)
  68217. {
  68218. const int openBracket = cssStyleText.indexOfChar (index, T('{'));
  68219. if (openBracket > index)
  68220. {
  68221. const int closeBracket = cssStyleText.indexOfChar (openBracket, T('}'));
  68222. if (closeBracket > openBracket)
  68223. {
  68224. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68225. if (value.isNotEmpty())
  68226. return value;
  68227. }
  68228. }
  68229. }
  68230. }
  68231. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68232. if (xml != 0)
  68233. return getStyleAttribute (xml, attributeName, defaultValue);
  68234. return defaultValue;
  68235. }
  68236. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68237. {
  68238. if (xml->hasAttribute (attributeName))
  68239. return xml->getStringAttribute (attributeName);
  68240. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68241. if (xml != 0)
  68242. return getInheritedAttribute (xml, attributeName);
  68243. return String::empty;
  68244. }
  68245. static bool isIdentifierChar (const tchar c)
  68246. {
  68247. return CharacterFunctions::isLetter (c) || c == T('-');
  68248. }
  68249. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68250. {
  68251. int i = 0;
  68252. for (;;)
  68253. {
  68254. i = list.indexOf (i, attributeName);
  68255. if (i < 0)
  68256. break;
  68257. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68258. && ! isIdentifierChar (list [i + attributeName.length()]))
  68259. {
  68260. i = list.indexOfChar (i, T(':'));
  68261. if (i < 0)
  68262. break;
  68263. int end = list.indexOfChar (i, T(';'));
  68264. if (end < 0)
  68265. end = 0x7ffff;
  68266. return list.substring (i + 1, end).trim();
  68267. }
  68268. ++i;
  68269. }
  68270. return defaultValue;
  68271. }
  68272. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68273. {
  68274. const tchar* const s = (const tchar*) source;
  68275. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68276. ++index;
  68277. int start = index;
  68278. if (CharacterFunctions::isDigit (s[index]) || s[index] == T('.') || s[index] == T('-'))
  68279. ++index;
  68280. while (CharacterFunctions::isDigit (s[index]) || s[index] == T('.'))
  68281. ++index;
  68282. if ((s[index] == T('e') || s[index] == T('E'))
  68283. && (CharacterFunctions::isDigit (s[index + 1])
  68284. || s[index + 1] == T('-')
  68285. || s[index + 1] == T('+')))
  68286. {
  68287. index += 2;
  68288. while (CharacterFunctions::isDigit (s[index]))
  68289. ++index;
  68290. }
  68291. if (allowUnits)
  68292. {
  68293. while (CharacterFunctions::isLetter (s[index]))
  68294. ++index;
  68295. }
  68296. if (index == start)
  68297. return false;
  68298. value = String (s + start, index - start);
  68299. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68300. ++index;
  68301. return true;
  68302. }
  68303. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68304. {
  68305. if (s [index] == T('#'))
  68306. {
  68307. uint32 hex [6];
  68308. zeromem (hex, sizeof (hex));
  68309. int numChars = 0;
  68310. for (int i = 6; --i >= 0;)
  68311. {
  68312. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68313. if (hexValue >= 0)
  68314. hex [numChars++] = hexValue;
  68315. else
  68316. break;
  68317. }
  68318. if (numChars <= 3)
  68319. return Colour ((uint8) (hex [0] * 0x11),
  68320. (uint8) (hex [1] * 0x11),
  68321. (uint8) (hex [2] * 0x11));
  68322. else
  68323. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68324. (uint8) ((hex [2] << 4) + hex [3]),
  68325. (uint8) ((hex [4] << 4) + hex [5]));
  68326. }
  68327. else if (s [index] == T('r')
  68328. && s [index + 1] == T('g')
  68329. && s [index + 2] == T('b'))
  68330. {
  68331. const int openBracket = s.indexOfChar (index, T('('));
  68332. const int closeBracket = s.indexOfChar (openBracket, T(')'));
  68333. if (openBracket >= 3 && closeBracket > openBracket)
  68334. {
  68335. index = closeBracket;
  68336. StringArray tokens;
  68337. tokens.addTokens (s.substring (openBracket + 1, closeBracket), T(","), T(""));
  68338. tokens.trim();
  68339. tokens.removeEmptyStrings();
  68340. if (tokens[0].containsChar (T('%')))
  68341. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68342. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68343. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68344. else
  68345. return Colour ((uint8) tokens[0].getIntValue(),
  68346. (uint8) tokens[1].getIntValue(),
  68347. (uint8) tokens[2].getIntValue());
  68348. }
  68349. }
  68350. return Colours::findColourForName (s, defaultColour);
  68351. }
  68352. static const AffineTransform parseTransform (String t)
  68353. {
  68354. AffineTransform result;
  68355. while (t.isNotEmpty())
  68356. {
  68357. StringArray tokens;
  68358. tokens.addTokens (t.fromFirstOccurrenceOf (T("("), false, false)
  68359. .upToFirstOccurrenceOf (T(")"), false, false),
  68360. T(", "), String::empty);
  68361. tokens.removeEmptyStrings (true);
  68362. float numbers [6];
  68363. for (int i = 0; i < 6; ++i)
  68364. numbers[i] = tokens[i].getFloatValue();
  68365. AffineTransform trans;
  68366. if (t.startsWithIgnoreCase (T("matrix")))
  68367. {
  68368. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68369. numbers[1], numbers[3], numbers[5]);
  68370. }
  68371. else if (t.startsWithIgnoreCase (T("translate")))
  68372. {
  68373. jassert (tokens.size() == 2);
  68374. trans = AffineTransform::translation (numbers[0], numbers[1]);
  68375. }
  68376. else if (t.startsWithIgnoreCase (T("scale")))
  68377. {
  68378. if (tokens.size() == 1)
  68379. trans = AffineTransform::scale (numbers[0], numbers[0]);
  68380. else
  68381. trans = AffineTransform::scale (numbers[0], numbers[1]);
  68382. }
  68383. else if (t.startsWithIgnoreCase (T("rotate")))
  68384. {
  68385. if (tokens.size() != 3)
  68386. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi));
  68387. else
  68388. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi),
  68389. numbers[1], numbers[2]);
  68390. }
  68391. else if (t.startsWithIgnoreCase (T("skewX")))
  68392. {
  68393. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68394. 0.0f, 1.0f, 0.0f);
  68395. }
  68396. else if (t.startsWithIgnoreCase (T("skewY")))
  68397. {
  68398. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68399. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68400. }
  68401. result = trans.followedBy (result);
  68402. t = t.fromFirstOccurrenceOf (T(")"), false, false).trimStart();
  68403. }
  68404. return result;
  68405. }
  68406. static void endpointToCentreParameters (const double x1, const double y1,
  68407. const double x2, const double y2,
  68408. const double angle,
  68409. const bool largeArc, const bool sweep,
  68410. double& rx, double& ry,
  68411. double& centreX, double& centreY,
  68412. double& startAngle, double& deltaAngle)
  68413. {
  68414. const double midX = (x1 - x2) * 0.5;
  68415. const double midY = (y1 - y2) * 0.5;
  68416. const double cosAngle = cos (angle);
  68417. const double sinAngle = sin (angle);
  68418. const double xp = cosAngle * midX + sinAngle * midY;
  68419. const double yp = cosAngle * midY - sinAngle * midX;
  68420. const double xp2 = xp * xp;
  68421. const double yp2 = yp * yp;
  68422. double rx2 = rx * rx;
  68423. double ry2 = ry * ry;
  68424. const double s = (xp2 / rx2) + (yp2 / ry2);
  68425. double c;
  68426. if (s <= 1.0)
  68427. {
  68428. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68429. / (( rx2 * yp2) + (ry2 * xp2))));
  68430. if (largeArc == sweep)
  68431. c = -c;
  68432. }
  68433. else
  68434. {
  68435. const double s2 = sqrt (s);
  68436. rx *= s2;
  68437. ry *= s2;
  68438. rx2 = rx * rx;
  68439. ry2 = ry * ry;
  68440. c = 0;
  68441. }
  68442. const double cpx = ((rx * yp) / ry) * c;
  68443. const double cpy = ((-ry * xp) / rx) * c;
  68444. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68445. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68446. const double ux = (xp - cpx) / rx;
  68447. const double uy = (yp - cpy) / ry;
  68448. const double vx = (-xp - cpx) / rx;
  68449. const double vy = (-yp - cpy) / ry;
  68450. const double length = juce_hypot (ux, uy);
  68451. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68452. if (uy < 0)
  68453. startAngle = -startAngle;
  68454. startAngle += double_Pi * 0.5;
  68455. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68456. / (length * juce_hypot (vx, vy))));
  68457. if ((ux * vy) - (uy * vx) < 0)
  68458. deltaAngle = -deltaAngle;
  68459. if (sweep)
  68460. {
  68461. if (deltaAngle < 0)
  68462. deltaAngle += double_Pi * 2.0;
  68463. }
  68464. else
  68465. {
  68466. if (deltaAngle > 0)
  68467. deltaAngle -= double_Pi * 2.0;
  68468. }
  68469. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68470. }
  68471. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68472. {
  68473. forEachXmlChildElement (*parent, e)
  68474. {
  68475. if (e->compareAttribute (T("id"), id))
  68476. return e;
  68477. const XmlElement* const found = findElementForId (e, id);
  68478. if (found != 0)
  68479. return found;
  68480. }
  68481. return 0;
  68482. }
  68483. SVGState& operator= (const SVGState&);
  68484. };
  68485. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68486. {
  68487. SVGState state (&svgDocument);
  68488. return state.parseSVGElement (svgDocument);
  68489. }
  68490. END_JUCE_NAMESPACE
  68491. /*** End of inlined file: juce_SVGParser.cpp ***/
  68492. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68493. BEGIN_JUCE_NAMESPACE
  68494. #if JUCE_MSVC
  68495. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68496. #endif
  68497. DropShadowEffect::DropShadowEffect()
  68498. : offsetX (0),
  68499. offsetY (0),
  68500. radius (4),
  68501. opacity (0.6f)
  68502. {
  68503. }
  68504. DropShadowEffect::~DropShadowEffect()
  68505. {
  68506. }
  68507. void DropShadowEffect::setShadowProperties (const float newRadius,
  68508. const float newOpacity,
  68509. const int newShadowOffsetX,
  68510. const int newShadowOffsetY)
  68511. {
  68512. radius = jmax (1.1f, newRadius);
  68513. offsetX = newShadowOffsetX;
  68514. offsetY = newShadowOffsetY;
  68515. opacity = newOpacity;
  68516. }
  68517. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  68518. {
  68519. const int w = image.getWidth();
  68520. const int h = image.getHeight();
  68521. Image shadowImage (Image::SingleChannel, w, h, false);
  68522. const Image::BitmapData srcData (image, 0, 0, w, h);
  68523. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  68524. const int filter = roundToInt (63.0f / radius);
  68525. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  68526. for (int x = w; --x >= 0;)
  68527. {
  68528. int shadowAlpha = 0;
  68529. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  68530. uint8* shadowPix = destData.data + x;
  68531. for (int y = h; --y >= 0;)
  68532. {
  68533. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  68534. *shadowPix = (uint8) shadowAlpha;
  68535. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  68536. shadowPix += destData.lineStride;
  68537. }
  68538. }
  68539. for (int y = h; --y >= 0;)
  68540. {
  68541. int shadowAlpha = 0;
  68542. uint8* shadowPix = destData.getLinePointer (y);
  68543. for (int x = w; --x >= 0;)
  68544. {
  68545. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  68546. *shadowPix++ = (uint8) shadowAlpha;
  68547. }
  68548. }
  68549. g.setColour (Colours::black.withAlpha (opacity));
  68550. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  68551. g.setOpacity (1.0f);
  68552. g.drawImageAt (&image, 0, 0);
  68553. }
  68554. END_JUCE_NAMESPACE
  68555. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  68556. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  68557. BEGIN_JUCE_NAMESPACE
  68558. GlowEffect::GlowEffect()
  68559. : radius (2.0f),
  68560. colour (Colours::white)
  68561. {
  68562. }
  68563. GlowEffect::~GlowEffect()
  68564. {
  68565. }
  68566. void GlowEffect::setGlowProperties (const float newRadius,
  68567. const Colour& newColour)
  68568. {
  68569. radius = newRadius;
  68570. colour = newColour;
  68571. }
  68572. void GlowEffect::applyEffect (Image& image, Graphics& g)
  68573. {
  68574. const int w = image.getWidth();
  68575. const int h = image.getHeight();
  68576. Image temp (image.getFormat(), w, h, true);
  68577. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  68578. blurKernel.createGaussianBlur (radius);
  68579. blurKernel.rescaleAllValues (radius);
  68580. blurKernel.applyToImage (temp, &image, 0, 0, w, h);
  68581. g.setColour (colour);
  68582. g.drawImageAt (&temp, 0, 0, true);
  68583. g.setOpacity (1.0f);
  68584. g.drawImageAt (&image, 0, 0, false);
  68585. }
  68586. END_JUCE_NAMESPACE
  68587. /*** End of inlined file: juce_GlowEffect.cpp ***/
  68588. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68589. BEGIN_JUCE_NAMESPACE
  68590. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  68591. : opacity (opacity_)
  68592. {
  68593. }
  68594. ReduceOpacityEffect::~ReduceOpacityEffect()
  68595. {
  68596. }
  68597. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  68598. {
  68599. opacity = jlimit (0.0f, 1.0f, newOpacity);
  68600. }
  68601. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  68602. {
  68603. g.setOpacity (opacity);
  68604. g.drawImageAt (&image, 0, 0);
  68605. }
  68606. END_JUCE_NAMESPACE
  68607. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68608. /*** Start of inlined file: juce_Font.cpp ***/
  68609. BEGIN_JUCE_NAMESPACE
  68610. static const float minFontHeight = 0.1f;
  68611. static const float maxFontHeight = 10000.0f;
  68612. static const float defaultFontHeight = 14.0f;
  68613. static const tchar* const juce_defaultFontNameSans = T("<Sans-Serif>");
  68614. static const tchar* const juce_defaultFontNameSerif = T("<Serif>");
  68615. static const tchar* const juce_defaultFontNameMono = T("<Monospaced>");
  68616. void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp
  68617. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  68618. const float kerning_, const float ascent_, const int styleFlags_,
  68619. Typeface* const typeface_) throw()
  68620. : typefaceName (typefaceName_),
  68621. height (height_),
  68622. horizontalScale (horizontalScale_),
  68623. kerning (kerning_),
  68624. ascent (ascent_),
  68625. styleFlags (styleFlags_),
  68626. typeface (typeface_)
  68627. {
  68628. }
  68629. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  68630. : typefaceName (other.typefaceName),
  68631. height (other.height),
  68632. horizontalScale (other.horizontalScale),
  68633. kerning (other.kerning),
  68634. ascent (other.ascent),
  68635. styleFlags (other.styleFlags),
  68636. typeface (other.typeface)
  68637. {
  68638. }
  68639. Font::Font() throw()
  68640. : font (new SharedFontInternal (juce_defaultFontNameSans, defaultFontHeight,
  68641. 1.0f, 0, 0, Font::plain, 0))
  68642. {
  68643. }
  68644. Font::Font (const float fontHeight, const int styleFlags_) throw()
  68645. : font (new SharedFontInternal (juce_defaultFontNameSans, jlimit (minFontHeight, maxFontHeight, fontHeight),
  68646. 1.0f, 0, 0, styleFlags_, 0))
  68647. {
  68648. }
  68649. Font::Font (const String& typefaceName_,
  68650. const float fontHeight,
  68651. const int styleFlags_) throw()
  68652. : font (new SharedFontInternal (typefaceName_, jlimit (minFontHeight, maxFontHeight, fontHeight),
  68653. 1.0f, 0, 0, styleFlags_, 0))
  68654. {
  68655. }
  68656. Font::Font (const Font& other) throw()
  68657. : font (other.font)
  68658. {
  68659. }
  68660. Font& Font::operator= (const Font& other) throw()
  68661. {
  68662. font = other.font;
  68663. return *this;
  68664. }
  68665. Font::~Font() throw()
  68666. {
  68667. }
  68668. Font::Font (const Typeface::Ptr& typeface) throw()
  68669. : font (new SharedFontInternal (typeface->getName(), defaultFontHeight,
  68670. 1.0f, 0, 0, Font::plain, typeface))
  68671. {
  68672. }
  68673. bool Font::operator== (const Font& other) const throw()
  68674. {
  68675. return font == other.font
  68676. || (font->height == other.font->height
  68677. && font->styleFlags == other.font->styleFlags
  68678. && font->horizontalScale == other.font->horizontalScale
  68679. && font->kerning == other.font->kerning
  68680. && font->typefaceName == other.font->typefaceName);
  68681. }
  68682. bool Font::operator!= (const Font& other) const throw()
  68683. {
  68684. return ! operator== (other);
  68685. }
  68686. void Font::dupeInternalIfShared() throw()
  68687. {
  68688. if (font->getReferenceCount() > 1)
  68689. font = new SharedFontInternal (*font);
  68690. }
  68691. const String Font::getDefaultSansSerifFontName() throw()
  68692. {
  68693. return juce_defaultFontNameSans;
  68694. }
  68695. const String Font::getDefaultSerifFontName() throw()
  68696. {
  68697. return juce_defaultFontNameSerif;
  68698. }
  68699. const String Font::getDefaultMonospacedFontName() throw()
  68700. {
  68701. return juce_defaultFontNameMono;
  68702. }
  68703. void Font::setTypefaceName (const String& faceName) throw()
  68704. {
  68705. if (faceName != font->typefaceName)
  68706. {
  68707. dupeInternalIfShared();
  68708. font->typefaceName = faceName;
  68709. font->typeface = 0;
  68710. font->ascent = 0;
  68711. }
  68712. }
  68713. static String fallbackFont;
  68714. const String Font::getFallbackFontName() throw()
  68715. {
  68716. return fallbackFont;
  68717. }
  68718. void Font::setFallbackFontName (const String& name) throw()
  68719. {
  68720. fallbackFont = name;
  68721. }
  68722. void Font::setHeight (float newHeight) throw()
  68723. {
  68724. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  68725. if (font->height != newHeight)
  68726. {
  68727. dupeInternalIfShared();
  68728. font->height = newHeight;
  68729. }
  68730. }
  68731. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  68732. {
  68733. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  68734. if (font->height != newHeight)
  68735. {
  68736. dupeInternalIfShared();
  68737. font->horizontalScale *= (font->height / newHeight);
  68738. font->height = newHeight;
  68739. }
  68740. }
  68741. void Font::setStyleFlags (const int newFlags) throw()
  68742. {
  68743. if (font->styleFlags != newFlags)
  68744. {
  68745. dupeInternalIfShared();
  68746. font->styleFlags = newFlags;
  68747. font->typeface = 0;
  68748. font->ascent = 0;
  68749. }
  68750. }
  68751. void Font::setSizeAndStyle (float newHeight,
  68752. const int newStyleFlags,
  68753. const float newHorizontalScale,
  68754. const float newKerningAmount) throw()
  68755. {
  68756. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  68757. if (font->height != newHeight
  68758. || font->horizontalScale != newHorizontalScale
  68759. || font->kerning != newKerningAmount)
  68760. {
  68761. dupeInternalIfShared();
  68762. font->height = newHeight;
  68763. font->horizontalScale = newHorizontalScale;
  68764. font->kerning = newKerningAmount;
  68765. }
  68766. setStyleFlags (newStyleFlags);
  68767. }
  68768. void Font::setHorizontalScale (const float scaleFactor) throw()
  68769. {
  68770. dupeInternalIfShared();
  68771. font->horizontalScale = scaleFactor;
  68772. }
  68773. void Font::setExtraKerningFactor (const float extraKerning) throw()
  68774. {
  68775. dupeInternalIfShared();
  68776. font->kerning = extraKerning;
  68777. }
  68778. void Font::setBold (const bool shouldBeBold) throw()
  68779. {
  68780. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  68781. : (font->styleFlags & ~bold));
  68782. }
  68783. bool Font::isBold() const throw()
  68784. {
  68785. return (font->styleFlags & bold) != 0;
  68786. }
  68787. void Font::setItalic (const bool shouldBeItalic) throw()
  68788. {
  68789. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  68790. : (font->styleFlags & ~italic));
  68791. }
  68792. bool Font::isItalic() const throw()
  68793. {
  68794. return (font->styleFlags & italic) != 0;
  68795. }
  68796. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  68797. {
  68798. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  68799. : (font->styleFlags & ~underlined));
  68800. }
  68801. bool Font::isUnderlined() const throw()
  68802. {
  68803. return (font->styleFlags & underlined) != 0;
  68804. }
  68805. float Font::getAscent() const throw()
  68806. {
  68807. if (font->ascent == 0)
  68808. font->ascent = getTypeface()->getAscent();
  68809. return font->height * font->ascent;
  68810. }
  68811. float Font::getDescent() const throw()
  68812. {
  68813. return font->height - getAscent();
  68814. }
  68815. int Font::getStringWidth (const String& text) const throw()
  68816. {
  68817. return roundToInt (getStringWidthFloat (text));
  68818. }
  68819. float Font::getStringWidthFloat (const String& text) const throw()
  68820. {
  68821. float w = getTypeface()->getStringWidth (text);
  68822. if (font->kerning != 0)
  68823. w += font->kerning * text.length();
  68824. return w * font->height * font->horizontalScale;
  68825. }
  68826. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  68827. {
  68828. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  68829. const float scale = font->height * font->horizontalScale;
  68830. const int num = xOffsets.size();
  68831. if (num > 0)
  68832. {
  68833. float* const x = &(xOffsets.getReference(0));
  68834. if (font->kerning != 0)
  68835. {
  68836. for (int i = 0; i < num; ++i)
  68837. x[i] = (x[i] + i * font->kerning) * scale;
  68838. }
  68839. else
  68840. {
  68841. for (int i = 0; i < num; ++i)
  68842. x[i] *= scale;
  68843. }
  68844. }
  68845. }
  68846. void Font::findFonts (Array<Font>& destArray) throw()
  68847. {
  68848. const StringArray names (findAllTypefaceNames());
  68849. for (int i = 0; i < names.size(); ++i)
  68850. destArray.add (Font (names[i], defaultFontHeight, Font::plain));
  68851. }
  68852. class TypefaceCache : public DeletedAtShutdown
  68853. {
  68854. public:
  68855. TypefaceCache (int numToCache = 10) throw()
  68856. : counter (1)
  68857. {
  68858. while (--numToCache >= 0)
  68859. faces.add (new CachedFace());
  68860. }
  68861. ~TypefaceCache()
  68862. {
  68863. clearUpDefaultFontNames();
  68864. clearSingletonInstance();
  68865. }
  68866. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  68867. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  68868. {
  68869. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  68870. const String faceName (font.getTypefaceName());
  68871. int i;
  68872. for (i = faces.size(); --i >= 0;)
  68873. {
  68874. CachedFace* const face = faces.getUnchecked(i);
  68875. if (face->flags == flags
  68876. && face->typefaceName == faceName)
  68877. {
  68878. face->lastUsageCount = ++counter;
  68879. return face->typeFace;
  68880. }
  68881. }
  68882. int replaceIndex = 0;
  68883. int bestLastUsageCount = std::numeric_limits<int>::max();
  68884. for (i = faces.size(); --i >= 0;)
  68885. {
  68886. const int lu = faces.getUnchecked(i)->lastUsageCount;
  68887. if (bestLastUsageCount > lu)
  68888. {
  68889. bestLastUsageCount = lu;
  68890. replaceIndex = i;
  68891. }
  68892. }
  68893. CachedFace* const face = faces.getUnchecked (replaceIndex);
  68894. face->typefaceName = faceName;
  68895. face->flags = flags;
  68896. face->lastUsageCount = ++counter;
  68897. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  68898. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  68899. return face->typeFace;
  68900. }
  68901. juce_UseDebuggingNewOperator
  68902. private:
  68903. struct CachedFace
  68904. {
  68905. CachedFace() throw()
  68906. : lastUsageCount (0), flags (-1)
  68907. {
  68908. }
  68909. String typefaceName;
  68910. int lastUsageCount;
  68911. int flags;
  68912. Typeface::Ptr typeFace;
  68913. };
  68914. int counter;
  68915. OwnedArray <CachedFace> faces;
  68916. TypefaceCache (const TypefaceCache&);
  68917. TypefaceCache& operator= (const TypefaceCache&);
  68918. };
  68919. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  68920. Typeface* Font::getTypeface() const throw()
  68921. {
  68922. if (font->typeface == 0)
  68923. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  68924. return font->typeface;
  68925. }
  68926. END_JUCE_NAMESPACE
  68927. /*** End of inlined file: juce_Font.cpp ***/
  68928. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  68929. BEGIN_JUCE_NAMESPACE
  68930. PositionedGlyph::PositionedGlyph (const float x_, const float y_, const float w_, const Font& font_,
  68931. const juce_wchar character_, const int glyph_)
  68932. : x (x_),
  68933. y (y_),
  68934. w (w_),
  68935. font (font_),
  68936. character (character_),
  68937. glyph (glyph_)
  68938. {
  68939. }
  68940. PositionedGlyph::PositionedGlyph (const PositionedGlyph& other)
  68941. : x (other.x),
  68942. y (other.y),
  68943. w (other.w),
  68944. font (other.font),
  68945. character (other.character),
  68946. glyph (other.glyph)
  68947. {
  68948. }
  68949. void PositionedGlyph::draw (const Graphics& g) const
  68950. {
  68951. if (! isWhitespace())
  68952. {
  68953. g.getInternalContext()->setFont (font);
  68954. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  68955. }
  68956. }
  68957. void PositionedGlyph::draw (const Graphics& g,
  68958. const AffineTransform& transform) const
  68959. {
  68960. if (! isWhitespace())
  68961. {
  68962. g.getInternalContext()->setFont (font);
  68963. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  68964. .followedBy (transform));
  68965. }
  68966. }
  68967. void PositionedGlyph::createPath (Path& path) const
  68968. {
  68969. if (! isWhitespace())
  68970. {
  68971. Typeface* const t = font.getTypeface();
  68972. if (t != 0)
  68973. {
  68974. Path p;
  68975. t->getOutlineForGlyph (glyph, p);
  68976. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  68977. .translated (x, y));
  68978. }
  68979. }
  68980. }
  68981. bool PositionedGlyph::hitTest (float px, float py) const
  68982. {
  68983. if (px >= getLeft() && px < getRight()
  68984. && py >= getTop() && py < getBottom()
  68985. && ! isWhitespace())
  68986. {
  68987. Typeface* const t = font.getTypeface();
  68988. if (t != 0)
  68989. {
  68990. Path p;
  68991. t->getOutlineForGlyph (glyph, p);
  68992. AffineTransform::translation (-x, -y)
  68993. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  68994. .transformPoint (px, py);
  68995. return p.contains (px, py);
  68996. }
  68997. }
  68998. return false;
  68999. }
  69000. void PositionedGlyph::moveBy (const float deltaX,
  69001. const float deltaY)
  69002. {
  69003. x += deltaX;
  69004. y += deltaY;
  69005. }
  69006. GlyphArrangement::GlyphArrangement()
  69007. {
  69008. glyphs.ensureStorageAllocated (128);
  69009. }
  69010. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69011. {
  69012. addGlyphArrangement (other);
  69013. }
  69014. GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69015. {
  69016. if (this != &other)
  69017. {
  69018. clear();
  69019. addGlyphArrangement (other);
  69020. }
  69021. return *this;
  69022. }
  69023. GlyphArrangement::~GlyphArrangement()
  69024. {
  69025. }
  69026. void GlyphArrangement::clear()
  69027. {
  69028. glyphs.clear();
  69029. }
  69030. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69031. {
  69032. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69033. return *glyphs [index];
  69034. }
  69035. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69036. {
  69037. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69038. for (int i = 0; i < other.glyphs.size(); ++i)
  69039. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69040. }
  69041. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69042. {
  69043. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69044. }
  69045. void GlyphArrangement::addLineOfText (const Font& font,
  69046. const String& text,
  69047. const float xOffset,
  69048. const float yOffset)
  69049. {
  69050. addCurtailedLineOfText (font, text,
  69051. xOffset, yOffset,
  69052. 1.0e10f, false);
  69053. }
  69054. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69055. const String& text,
  69056. float xOffset,
  69057. const float yOffset,
  69058. const float maxWidthPixels,
  69059. const bool useEllipsis)
  69060. {
  69061. if (text.isNotEmpty())
  69062. {
  69063. Array <int> newGlyphs;
  69064. Array <float> xOffsets;
  69065. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69066. const int textLen = newGlyphs.size();
  69067. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69068. for (int i = 0; i < textLen; ++i)
  69069. {
  69070. const float thisX = xOffsets.getUnchecked (i);
  69071. const float nextX = xOffsets.getUnchecked (i + 1);
  69072. if (nextX > maxWidthPixels + 1.0f)
  69073. {
  69074. // curtail the string if it's too wide..
  69075. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69076. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69077. break;
  69078. }
  69079. else
  69080. {
  69081. glyphs.add (new PositionedGlyph (xOffset + thisX, yOffset, nextX - thisX,
  69082. font, unicodeText[i], newGlyphs.getUnchecked(i)));
  69083. }
  69084. }
  69085. }
  69086. }
  69087. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69088. const int startIndex, int endIndex)
  69089. {
  69090. int numDeleted = 0;
  69091. if (glyphs.size() > 0)
  69092. {
  69093. Array<int> dotGlyphs;
  69094. Array<float> dotXs;
  69095. font.getGlyphPositions (T(".."), dotGlyphs, dotXs);
  69096. const float dx = dotXs[1];
  69097. float xOffset = 0.0f, yOffset = 0.0f;
  69098. while (endIndex > startIndex)
  69099. {
  69100. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69101. xOffset = pg->x;
  69102. yOffset = pg->y;
  69103. glyphs.remove (endIndex);
  69104. ++numDeleted;
  69105. if (xOffset + dx * 3 <= maxXPos)
  69106. break;
  69107. }
  69108. for (int i = 3; --i >= 0;)
  69109. {
  69110. glyphs.insert (endIndex++, new PositionedGlyph (xOffset, yOffset, dx,
  69111. font, '.', dotGlyphs.getFirst()));
  69112. --numDeleted;
  69113. xOffset += dx;
  69114. if (xOffset > maxXPos)
  69115. break;
  69116. }
  69117. }
  69118. return numDeleted;
  69119. }
  69120. void GlyphArrangement::addJustifiedText (const Font& font,
  69121. const String& text,
  69122. float x, float y,
  69123. const float maxLineWidth,
  69124. const Justification& horizontalLayout)
  69125. {
  69126. int lineStartIndex = glyphs.size();
  69127. addLineOfText (font, text, x, y);
  69128. const float originalY = y;
  69129. while (lineStartIndex < glyphs.size())
  69130. {
  69131. int i = lineStartIndex;
  69132. if (glyphs.getUnchecked(i)->getCharacter() != T('\n')
  69133. && glyphs.getUnchecked(i)->getCharacter() != T('\r'))
  69134. ++i;
  69135. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69136. int lastWordBreakIndex = -1;
  69137. while (i < glyphs.size())
  69138. {
  69139. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69140. const juce_wchar c = pg->getCharacter();
  69141. if (c == T('\r') || c == T('\n'))
  69142. {
  69143. ++i;
  69144. if (c == T('\r') && i < glyphs.size()
  69145. && glyphs.getUnchecked(i)->getCharacter() == T('\n'))
  69146. ++i;
  69147. break;
  69148. }
  69149. else if (pg->isWhitespace())
  69150. {
  69151. lastWordBreakIndex = i + 1;
  69152. }
  69153. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69154. {
  69155. if (lastWordBreakIndex >= 0)
  69156. i = lastWordBreakIndex;
  69157. break;
  69158. }
  69159. ++i;
  69160. }
  69161. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69162. float currentLineEndX = currentLineStartX;
  69163. for (int j = i; --j >= lineStartIndex;)
  69164. {
  69165. if (! glyphs.getUnchecked (j)->isWhitespace())
  69166. {
  69167. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69168. break;
  69169. }
  69170. }
  69171. float deltaX = 0.0f;
  69172. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69173. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69174. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69175. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69176. else if (horizontalLayout.testFlags (Justification::right))
  69177. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69178. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69179. x + deltaX - currentLineStartX, y - originalY);
  69180. lineStartIndex = i;
  69181. y += font.getHeight();
  69182. }
  69183. }
  69184. void GlyphArrangement::addFittedText (const Font& f,
  69185. const String& text,
  69186. const float x, const float y,
  69187. const float width, const float height,
  69188. const Justification& layout,
  69189. int maximumLines,
  69190. const float minimumHorizontalScale)
  69191. {
  69192. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69193. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69194. if (text.containsAnyOf (T("\r\n")))
  69195. {
  69196. GlyphArrangement ga;
  69197. ga.addJustifiedText (f, text, x, y, width, layout);
  69198. float l, t, r, b;
  69199. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69200. float dy = y - t;
  69201. if (layout.testFlags (Justification::verticallyCentred))
  69202. dy += (height - (b - t)) * 0.5f;
  69203. else if (layout.testFlags (Justification::bottom))
  69204. dy += height - (b - t);
  69205. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69206. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69207. for (int i = 0; i < ga.glyphs.size(); ++i)
  69208. glyphs.add (ga.glyphs.getUnchecked (i));
  69209. ga.glyphs.clear (false);
  69210. return;
  69211. }
  69212. int startIndex = glyphs.size();
  69213. addLineOfText (f, text.trim(), x, y);
  69214. if (glyphs.size() > startIndex)
  69215. {
  69216. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69217. - glyphs.getUnchecked (startIndex)->getLeft();
  69218. if (lineWidth <= 0)
  69219. return;
  69220. if (lineWidth * minimumHorizontalScale < width)
  69221. {
  69222. if (lineWidth > width)
  69223. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69224. width / lineWidth);
  69225. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69226. x, y, width, height, layout);
  69227. }
  69228. else if (maximumLines <= 1)
  69229. {
  69230. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69231. x, y, width, height, f, layout, minimumHorizontalScale);
  69232. }
  69233. else
  69234. {
  69235. Font font (f);
  69236. String txt (text.trim());
  69237. const int length = txt.length();
  69238. const int originalStartIndex = startIndex;
  69239. int numLines = 1;
  69240. if (length <= 12 && ! txt.containsAnyOf (T(" -\t\r\n")))
  69241. maximumLines = 1;
  69242. maximumLines = jmin (maximumLines, length);
  69243. while (numLines < maximumLines)
  69244. {
  69245. ++numLines;
  69246. const float newFontHeight = height / (float) numLines;
  69247. if (newFontHeight < font.getHeight())
  69248. {
  69249. font.setHeight (jmax (8.0f, newFontHeight));
  69250. removeRangeOfGlyphs (startIndex, -1);
  69251. addLineOfText (font, txt, x, y);
  69252. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69253. - glyphs.getUnchecked (startIndex)->getLeft();
  69254. }
  69255. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69256. break;
  69257. }
  69258. if (numLines < 1)
  69259. numLines = 1;
  69260. float lineY = y;
  69261. float widthPerLine = lineWidth / numLines;
  69262. int lastLineStartIndex = 0;
  69263. for (int line = 0; line < numLines; ++line)
  69264. {
  69265. int i = startIndex;
  69266. lastLineStartIndex = i;
  69267. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69268. if (line == numLines - 1)
  69269. {
  69270. widthPerLine = width;
  69271. i = glyphs.size();
  69272. }
  69273. else
  69274. {
  69275. while (i < glyphs.size())
  69276. {
  69277. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69278. if (lineWidth > widthPerLine)
  69279. {
  69280. // got to a point where the line's too long, so skip forward to find a
  69281. // good place to break it..
  69282. const int searchStartIndex = i;
  69283. while (i < glyphs.size())
  69284. {
  69285. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69286. {
  69287. if (glyphs.getUnchecked (i)->isWhitespace()
  69288. || glyphs.getUnchecked (i)->getCharacter() == T('-'))
  69289. {
  69290. ++i;
  69291. break;
  69292. }
  69293. }
  69294. else
  69295. {
  69296. // can't find a suitable break, so try looking backwards..
  69297. i = searchStartIndex;
  69298. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69299. {
  69300. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69301. || glyphs.getUnchecked (i - back)->getCharacter() == T('-'))
  69302. {
  69303. i -= back - 1;
  69304. break;
  69305. }
  69306. }
  69307. break;
  69308. }
  69309. ++i;
  69310. }
  69311. break;
  69312. }
  69313. ++i;
  69314. }
  69315. int wsStart = i;
  69316. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69317. --wsStart;
  69318. int wsEnd = i;
  69319. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69320. ++wsEnd;
  69321. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69322. i = jmax (wsStart, startIndex + 1);
  69323. }
  69324. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69325. x, lineY, width, font.getHeight(), font,
  69326. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69327. minimumHorizontalScale);
  69328. startIndex = i;
  69329. lineY += font.getHeight();
  69330. if (startIndex >= glyphs.size())
  69331. break;
  69332. }
  69333. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69334. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69335. }
  69336. }
  69337. }
  69338. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69339. const float dx, const float dy)
  69340. {
  69341. jassert (startIndex >= 0);
  69342. if (dx != 0.0f || dy != 0.0f)
  69343. {
  69344. if (num < 0 || startIndex + num > glyphs.size())
  69345. num = glyphs.size() - startIndex;
  69346. while (--num >= 0)
  69347. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69348. }
  69349. }
  69350. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69351. const Justification& justification, float minimumHorizontalScale)
  69352. {
  69353. int numDeleted = 0;
  69354. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69355. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69356. if (lineWidth > w)
  69357. {
  69358. if (minimumHorizontalScale < 1.0f)
  69359. {
  69360. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69361. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69362. }
  69363. if (lineWidth > w)
  69364. {
  69365. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69366. numGlyphs -= numDeleted;
  69367. }
  69368. }
  69369. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69370. return numDeleted;
  69371. }
  69372. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69373. const float horizontalScaleFactor)
  69374. {
  69375. jassert (startIndex >= 0);
  69376. if (num < 0 || startIndex + num > glyphs.size())
  69377. num = glyphs.size() - startIndex;
  69378. if (num > 0)
  69379. {
  69380. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69381. while (--num >= 0)
  69382. {
  69383. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69384. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69385. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69386. pg->w *= horizontalScaleFactor;
  69387. }
  69388. }
  69389. }
  69390. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69391. float& left,
  69392. float& top,
  69393. float& right,
  69394. float& bottom,
  69395. const bool includeWhitespace) const
  69396. {
  69397. jassert (startIndex >= 0);
  69398. if (num < 0 || startIndex + num > glyphs.size())
  69399. num = glyphs.size() - startIndex;
  69400. left = 0.0f;
  69401. top = 0.0f;
  69402. right = 0.0f;
  69403. bottom = 0.0f;
  69404. bool isFirst = true;
  69405. while (--num >= 0)
  69406. {
  69407. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69408. if (includeWhitespace || ! pg->isWhitespace())
  69409. {
  69410. if (isFirst)
  69411. {
  69412. isFirst = false;
  69413. left = pg->getLeft();
  69414. top = pg->getTop();
  69415. right = pg->getRight();
  69416. bottom = pg->getBottom();
  69417. }
  69418. else
  69419. {
  69420. left = jmin (left, pg->getLeft());
  69421. top = jmin (top, pg->getTop());
  69422. right = jmax (right, pg->getRight());
  69423. bottom = jmax (bottom, pg->getBottom());
  69424. }
  69425. }
  69426. }
  69427. }
  69428. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69429. const int num,
  69430. const float x, const float y,
  69431. const float width, const float height,
  69432. const Justification& justification)
  69433. {
  69434. jassert (num >= 0 && startIndex >= 0);
  69435. if (glyphs.size() > 0 && num > 0)
  69436. {
  69437. float left, top, right, bottom;
  69438. getBoundingBox (startIndex, num, left, top, right, bottom,
  69439. ! justification.testFlags (Justification::horizontallyJustified
  69440. | Justification::horizontallyCentred));
  69441. float deltaX = 0.0f;
  69442. if (justification.testFlags (Justification::horizontallyJustified))
  69443. deltaX = x - left;
  69444. else if (justification.testFlags (Justification::horizontallyCentred))
  69445. deltaX = x + (width - (right - left)) * 0.5f - left;
  69446. else if (justification.testFlags (Justification::right))
  69447. deltaX = (x + width) - right;
  69448. else
  69449. deltaX = x - left;
  69450. float deltaY = 0.0f;
  69451. if (justification.testFlags (Justification::top))
  69452. deltaY = y - top;
  69453. else if (justification.testFlags (Justification::bottom))
  69454. deltaY = (y + height) - bottom;
  69455. else
  69456. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69457. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69458. if (justification.testFlags (Justification::horizontallyJustified))
  69459. {
  69460. int lineStart = 0;
  69461. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69462. int i;
  69463. for (i = 0; i < num; ++i)
  69464. {
  69465. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69466. if (glyphY != baseY)
  69467. {
  69468. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69469. lineStart = i;
  69470. baseY = glyphY;
  69471. }
  69472. }
  69473. if (i > lineStart)
  69474. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69475. }
  69476. }
  69477. }
  69478. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69479. {
  69480. if (start + num < glyphs.size()
  69481. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\r')
  69482. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\n'))
  69483. {
  69484. int numSpaces = 0;
  69485. int spacesAtEnd = 0;
  69486. for (int i = 0; i < num; ++i)
  69487. {
  69488. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69489. {
  69490. ++spacesAtEnd;
  69491. ++numSpaces;
  69492. }
  69493. else
  69494. {
  69495. spacesAtEnd = 0;
  69496. }
  69497. }
  69498. numSpaces -= spacesAtEnd;
  69499. if (numSpaces > 0)
  69500. {
  69501. const float startX = glyphs.getUnchecked (start)->getLeft();
  69502. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69503. const float extraPaddingBetweenWords
  69504. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69505. float deltaX = 0.0f;
  69506. for (int i = 0; i < num; ++i)
  69507. {
  69508. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69509. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69510. deltaX += extraPaddingBetweenWords;
  69511. }
  69512. }
  69513. }
  69514. }
  69515. void GlyphArrangement::draw (const Graphics& g) const
  69516. {
  69517. for (int i = 0; i < glyphs.size(); ++i)
  69518. {
  69519. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69520. if (pg->font.isUnderlined())
  69521. {
  69522. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69523. float nextX = pg->x + pg->w;
  69524. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69525. nextX = glyphs.getUnchecked (i + 1)->x;
  69526. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  69527. nextX - pg->x, lineThickness);
  69528. }
  69529. pg->draw (g);
  69530. }
  69531. }
  69532. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  69533. {
  69534. for (int i = 0; i < glyphs.size(); ++i)
  69535. {
  69536. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69537. if (pg->font.isUnderlined())
  69538. {
  69539. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69540. float nextX = pg->x + pg->w;
  69541. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69542. nextX = glyphs.getUnchecked (i + 1)->x;
  69543. Path p;
  69544. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  69545. nextX, pg->y + lineThickness * 2.0f,
  69546. lineThickness);
  69547. g.fillPath (p, transform);
  69548. }
  69549. pg->draw (g, transform);
  69550. }
  69551. }
  69552. void GlyphArrangement::createPath (Path& path) const
  69553. {
  69554. for (int i = 0; i < glyphs.size(); ++i)
  69555. glyphs.getUnchecked (i)->createPath (path);
  69556. }
  69557. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  69558. {
  69559. for (int i = 0; i < glyphs.size(); ++i)
  69560. if (glyphs.getUnchecked (i)->hitTest (x, y))
  69561. return i;
  69562. return -1;
  69563. }
  69564. END_JUCE_NAMESPACE
  69565. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  69566. /*** Start of inlined file: juce_TextLayout.cpp ***/
  69567. BEGIN_JUCE_NAMESPACE
  69568. class TextLayout::Token
  69569. {
  69570. public:
  69571. String text;
  69572. Font font;
  69573. int x, y, w, h;
  69574. int line, lineHeight;
  69575. bool isWhitespace, isNewLine;
  69576. Token (const String& t,
  69577. const Font& f,
  69578. const bool isWhitespace_) throw()
  69579. : text (t),
  69580. font (f),
  69581. x(0),
  69582. y(0),
  69583. isWhitespace (isWhitespace_)
  69584. {
  69585. w = font.getStringWidth (t);
  69586. h = roundToInt (f.getHeight());
  69587. isNewLine = t.containsAnyOf (T("\r\n"));
  69588. }
  69589. Token (const Token& other) throw()
  69590. : text (other.text),
  69591. font (other.font),
  69592. x (other.x),
  69593. y (other.y),
  69594. w (other.w),
  69595. h (other.h),
  69596. line (other.line),
  69597. lineHeight (other.lineHeight),
  69598. isWhitespace (other.isWhitespace),
  69599. isNewLine (other.isNewLine)
  69600. {
  69601. }
  69602. ~Token() throw()
  69603. {
  69604. }
  69605. void draw (Graphics& g,
  69606. const int xOffset,
  69607. const int yOffset) throw()
  69608. {
  69609. if (! isWhitespace)
  69610. {
  69611. g.setFont (font);
  69612. g.drawSingleLineText (text.trimEnd(),
  69613. xOffset + x,
  69614. yOffset + y + (lineHeight - h)
  69615. + roundToInt (font.getAscent()));
  69616. }
  69617. }
  69618. juce_UseDebuggingNewOperator
  69619. };
  69620. TextLayout::TextLayout() throw()
  69621. : totalLines (0)
  69622. {
  69623. tokens.ensureStorageAllocated (64);
  69624. }
  69625. TextLayout::TextLayout (const String& text,
  69626. const Font& font) throw()
  69627. : totalLines (0)
  69628. {
  69629. tokens.ensureStorageAllocated (64);
  69630. appendText (text, font);
  69631. }
  69632. TextLayout::TextLayout (const TextLayout& other) throw()
  69633. : totalLines (0)
  69634. {
  69635. *this = other;
  69636. }
  69637. TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  69638. {
  69639. if (this != &other)
  69640. {
  69641. clear();
  69642. totalLines = other.totalLines;
  69643. for (int i = 0; i < other.tokens.size(); ++i)
  69644. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  69645. }
  69646. return *this;
  69647. }
  69648. TextLayout::~TextLayout() throw()
  69649. {
  69650. clear();
  69651. }
  69652. void TextLayout::clear() throw()
  69653. {
  69654. tokens.clear();
  69655. totalLines = 0;
  69656. }
  69657. void TextLayout::appendText (const String& text,
  69658. const Font& font) throw()
  69659. {
  69660. const tchar* t = text;
  69661. String currentString;
  69662. int lastCharType = 0;
  69663. for (;;)
  69664. {
  69665. const tchar c = *t++;
  69666. if (c == 0)
  69667. break;
  69668. int charType;
  69669. if (c == T('\r') || c == T('\n'))
  69670. {
  69671. charType = 0;
  69672. }
  69673. else if (CharacterFunctions::isWhitespace (c))
  69674. {
  69675. charType = 2;
  69676. }
  69677. else
  69678. {
  69679. charType = 1;
  69680. }
  69681. if (charType == 0 || charType != lastCharType)
  69682. {
  69683. if (currentString.isNotEmpty())
  69684. {
  69685. tokens.add (new Token (currentString, font,
  69686. lastCharType == 2 || lastCharType == 0));
  69687. }
  69688. currentString = String::charToString (c);
  69689. if (c == T('\r') && *t == T('\n'))
  69690. currentString += *t++;
  69691. }
  69692. else
  69693. {
  69694. currentString += c;
  69695. }
  69696. lastCharType = charType;
  69697. }
  69698. if (currentString.isNotEmpty())
  69699. tokens.add (new Token (currentString, font, lastCharType == 2));
  69700. }
  69701. void TextLayout::setText (const String& text, const Font& font) throw()
  69702. {
  69703. clear();
  69704. appendText (text, font);
  69705. }
  69706. void TextLayout::layout (int maxWidth,
  69707. const Justification& justification,
  69708. const bool attemptToBalanceLineLengths) throw()
  69709. {
  69710. if (attemptToBalanceLineLengths)
  69711. {
  69712. const int originalW = maxWidth;
  69713. int bestWidth = maxWidth;
  69714. float bestLineProportion = 0.0f;
  69715. while (maxWidth > originalW / 2)
  69716. {
  69717. layout (maxWidth, justification, false);
  69718. if (getNumLines() <= 1)
  69719. return;
  69720. const int lastLineW = getLineWidth (getNumLines() - 1);
  69721. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  69722. const float prop = lastLineW / (float) lastButOneLineW;
  69723. if (prop > 0.9f)
  69724. return;
  69725. if (prop > bestLineProportion)
  69726. {
  69727. bestLineProportion = prop;
  69728. bestWidth = maxWidth;
  69729. }
  69730. maxWidth -= 10;
  69731. }
  69732. layout (bestWidth, justification, false);
  69733. }
  69734. else
  69735. {
  69736. int x = 0;
  69737. int y = 0;
  69738. int h = 0;
  69739. totalLines = 0;
  69740. int i;
  69741. for (i = 0; i < tokens.size(); ++i)
  69742. {
  69743. Token* const t = tokens.getUnchecked(i);
  69744. t->x = x;
  69745. t->y = y;
  69746. t->line = totalLines;
  69747. x += t->w;
  69748. h = jmax (h, t->h);
  69749. const Token* nextTok = tokens [i + 1];
  69750. if (nextTok == 0)
  69751. break;
  69752. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  69753. {
  69754. // finished a line, so go back and update the heights of the things on it
  69755. for (int j = i; j >= 0; --j)
  69756. {
  69757. Token* const tok = tokens.getUnchecked(j);
  69758. if (tok->line == totalLines)
  69759. tok->lineHeight = h;
  69760. else
  69761. break;
  69762. }
  69763. x = 0;
  69764. y += h;
  69765. h = 0;
  69766. ++totalLines;
  69767. }
  69768. }
  69769. // finished a line, so go back and update the heights of the things on it
  69770. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  69771. {
  69772. Token* const t = tokens.getUnchecked(j);
  69773. if (t->line == totalLines)
  69774. t->lineHeight = h;
  69775. else
  69776. break;
  69777. }
  69778. ++totalLines;
  69779. if (! justification.testFlags (Justification::left))
  69780. {
  69781. int totalW = getWidth();
  69782. for (i = totalLines; --i >= 0;)
  69783. {
  69784. const int lineW = getLineWidth (i);
  69785. int dx = 0;
  69786. if (justification.testFlags (Justification::horizontallyCentred))
  69787. dx = (totalW - lineW) / 2;
  69788. else if (justification.testFlags (Justification::right))
  69789. dx = totalW - lineW;
  69790. for (int j = tokens.size(); --j >= 0;)
  69791. {
  69792. Token* const t = tokens.getUnchecked(j);
  69793. if (t->line == i)
  69794. t->x += dx;
  69795. }
  69796. }
  69797. }
  69798. }
  69799. }
  69800. int TextLayout::getLineWidth (const int lineNumber) const throw()
  69801. {
  69802. int maxW = 0;
  69803. for (int i = tokens.size(); --i >= 0;)
  69804. {
  69805. const Token* const t = tokens.getUnchecked(i);
  69806. if (t->line == lineNumber && ! t->isWhitespace)
  69807. maxW = jmax (maxW, t->x + t->w);
  69808. }
  69809. return maxW;
  69810. }
  69811. int TextLayout::getWidth() const throw()
  69812. {
  69813. int maxW = 0;
  69814. for (int i = tokens.size(); --i >= 0;)
  69815. {
  69816. const Token* const t = tokens.getUnchecked(i);
  69817. if (! t->isWhitespace)
  69818. maxW = jmax (maxW, t->x + t->w);
  69819. }
  69820. return maxW;
  69821. }
  69822. int TextLayout::getHeight() const throw()
  69823. {
  69824. int maxH = 0;
  69825. for (int i = tokens.size(); --i >= 0;)
  69826. {
  69827. const Token* const t = tokens.getUnchecked(i);
  69828. if (! t->isWhitespace)
  69829. maxH = jmax (maxH, t->y + t->h);
  69830. }
  69831. return maxH;
  69832. }
  69833. void TextLayout::draw (Graphics& g,
  69834. const int xOffset,
  69835. const int yOffset) const throw()
  69836. {
  69837. for (int i = tokens.size(); --i >= 0;)
  69838. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  69839. }
  69840. void TextLayout::drawWithin (Graphics& g,
  69841. int x, int y, int w, int h,
  69842. const Justification& justification) const throw()
  69843. {
  69844. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  69845. x, y, w, h);
  69846. draw (g, x, y);
  69847. }
  69848. END_JUCE_NAMESPACE
  69849. /*** End of inlined file: juce_TextLayout.cpp ***/
  69850. /*** Start of inlined file: juce_Typeface.cpp ***/
  69851. BEGIN_JUCE_NAMESPACE
  69852. Typeface::Typeface (const String& name_) throw()
  69853. : name (name_)
  69854. {
  69855. }
  69856. Typeface::~Typeface()
  69857. {
  69858. }
  69859. class CustomTypeface::GlyphInfo
  69860. {
  69861. public:
  69862. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  69863. : character (character_), path (path_), width (width_)
  69864. {
  69865. }
  69866. ~GlyphInfo() throw()
  69867. {
  69868. }
  69869. struct KerningPair
  69870. {
  69871. juce_wchar character2;
  69872. float kerningAmount;
  69873. };
  69874. void addKerningPair (const juce_wchar subsequentCharacter,
  69875. const float extraKerningAmount) throw()
  69876. {
  69877. KerningPair kp;
  69878. kp.character2 = subsequentCharacter;
  69879. kp.kerningAmount = extraKerningAmount;
  69880. kerningPairs.add (kp);
  69881. }
  69882. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  69883. {
  69884. if (subsequentCharacter != 0)
  69885. {
  69886. for (int i = kerningPairs.size(); --i >= 0;)
  69887. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  69888. return width + kerningPairs.getReference(i).kerningAmount;
  69889. }
  69890. return width;
  69891. }
  69892. const juce_wchar character;
  69893. const Path path;
  69894. float width;
  69895. Array <KerningPair> kerningPairs;
  69896. juce_UseDebuggingNewOperator
  69897. private:
  69898. GlyphInfo (const GlyphInfo&);
  69899. GlyphInfo& operator= (const GlyphInfo&);
  69900. };
  69901. CustomTypeface::CustomTypeface()
  69902. : Typeface (String::empty)
  69903. {
  69904. clear();
  69905. }
  69906. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  69907. : Typeface (String::empty)
  69908. {
  69909. clear();
  69910. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  69911. BufferedInputStream in (&gzin, 32768, false);
  69912. name = in.readString();
  69913. isBold = in.readBool();
  69914. isItalic = in.readBool();
  69915. ascent = in.readFloat();
  69916. defaultCharacter = (juce_wchar) in.readShort();
  69917. int i, numChars = in.readInt();
  69918. for (i = 0; i < numChars; ++i)
  69919. {
  69920. const juce_wchar c = (juce_wchar) in.readShort();
  69921. const float width = in.readFloat();
  69922. Path p;
  69923. p.loadPathFromStream (in);
  69924. addGlyph (c, p, width);
  69925. }
  69926. const int numKerningPairs = in.readInt();
  69927. for (i = 0; i < numKerningPairs; ++i)
  69928. {
  69929. const juce_wchar char1 = (juce_wchar) in.readShort();
  69930. const juce_wchar char2 = (juce_wchar) in.readShort();
  69931. addKerningPair (char1, char2, in.readFloat());
  69932. }
  69933. }
  69934. CustomTypeface::~CustomTypeface()
  69935. {
  69936. }
  69937. void CustomTypeface::clear()
  69938. {
  69939. defaultCharacter = 0;
  69940. ascent = 1.0f;
  69941. isBold = isItalic = false;
  69942. zeromem (lookupTable, sizeof (lookupTable));
  69943. glyphs.clear();
  69944. }
  69945. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  69946. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  69947. {
  69948. name = name_;
  69949. defaultCharacter = defaultCharacter_;
  69950. ascent = ascent_;
  69951. isBold = isBold_;
  69952. isItalic = isItalic_;
  69953. }
  69954. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  69955. {
  69956. // Check that you're not trying to add the same character twice..
  69957. jassert (findGlyph (character, false) == 0);
  69958. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  69959. lookupTable [character] = (short) glyphs.size();
  69960. glyphs.add (new GlyphInfo (character, path, width));
  69961. }
  69962. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  69963. {
  69964. if (extraAmount != 0)
  69965. {
  69966. GlyphInfo* const g = findGlyph (char1, true);
  69967. jassert (g != 0); // can only add kerning pairs for characters that exist!
  69968. if (g != 0)
  69969. g->addKerningPair (char2, extraAmount);
  69970. }
  69971. }
  69972. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  69973. {
  69974. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  69975. return glyphs [(int) lookupTable [(int) character]];
  69976. for (int i = 0; i < glyphs.size(); ++i)
  69977. {
  69978. GlyphInfo* const g = glyphs.getUnchecked(i);
  69979. if (g->character == character)
  69980. return g;
  69981. }
  69982. if (loadIfNeeded && loadGlyphIfPossible (character))
  69983. return findGlyph (character, false);
  69984. return 0;
  69985. }
  69986. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  69987. {
  69988. GlyphInfo* glyph = findGlyph (character, true);
  69989. if (glyph == 0)
  69990. {
  69991. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  69992. glyph = findGlyph (L' ', true);
  69993. if (glyph == 0)
  69994. {
  69995. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  69996. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  69997. if (fallbackTypeface != 0 && fallbackTypeface != this)
  69998. {
  69999. //xxx
  70000. }
  70001. if (glyph == 0)
  70002. glyph = findGlyph (defaultCharacter, true);
  70003. }
  70004. }
  70005. return glyph;
  70006. }
  70007. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70008. {
  70009. return false;
  70010. }
  70011. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70012. {
  70013. for (int i = 0; i < numCharacters; ++i)
  70014. {
  70015. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70016. Array <int> glyphIndexes;
  70017. Array <float> offsets;
  70018. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70019. const int glyphIndex = glyphIndexes.getFirst();
  70020. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70021. {
  70022. const float glyphWidth = offsets[1];
  70023. Path p;
  70024. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70025. addGlyph (c, p, glyphWidth);
  70026. for (int j = glyphs.size() - 1; --j >= 0;)
  70027. {
  70028. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70029. glyphIndexes.clearQuick();
  70030. offsets.clearQuick();
  70031. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70032. if (offsets.size() > 1)
  70033. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70034. }
  70035. }
  70036. }
  70037. }
  70038. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70039. {
  70040. GZIPCompressorOutputStream out (&outputStream);
  70041. out.writeString (name);
  70042. out.writeBool (isBold);
  70043. out.writeBool (isItalic);
  70044. out.writeFloat (ascent);
  70045. out.writeShort ((short) (unsigned short) defaultCharacter);
  70046. out.writeInt (glyphs.size());
  70047. int i, numKerningPairs = 0;
  70048. for (i = 0; i < glyphs.size(); ++i)
  70049. {
  70050. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70051. out.writeShort ((short) (unsigned short) g->character);
  70052. out.writeFloat (g->width);
  70053. g->path.writePathToStream (out);
  70054. numKerningPairs += g->kerningPairs.size();
  70055. }
  70056. out.writeInt (numKerningPairs);
  70057. for (i = 0; i < glyphs.size(); ++i)
  70058. {
  70059. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70060. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70061. {
  70062. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70063. out.writeShort ((short) (unsigned short) g->character);
  70064. out.writeShort ((short) (unsigned short) p.character2);
  70065. out.writeFloat (p.kerningAmount);
  70066. }
  70067. }
  70068. return true;
  70069. }
  70070. float CustomTypeface::getAscent() const
  70071. {
  70072. return ascent;
  70073. }
  70074. float CustomTypeface::getDescent() const
  70075. {
  70076. return 1.0f - ascent;
  70077. }
  70078. float CustomTypeface::getStringWidth (const String& text)
  70079. {
  70080. float x = 0;
  70081. const juce_wchar* t = (const juce_wchar*) text;
  70082. while (*t != 0)
  70083. {
  70084. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70085. if (glyph != 0)
  70086. x += glyph->getHorizontalSpacing (*t);
  70087. }
  70088. return x;
  70089. }
  70090. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70091. {
  70092. xOffsets.add (0);
  70093. float x = 0;
  70094. const juce_wchar* t = (const juce_wchar*) text;
  70095. while (*t != 0)
  70096. {
  70097. const juce_wchar c = *t++;
  70098. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70099. if (glyph != 0)
  70100. {
  70101. x += glyph->getHorizontalSpacing (*t);
  70102. resultGlyphs.add ((int) glyph->character);
  70103. xOffsets.add (x);
  70104. }
  70105. }
  70106. }
  70107. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70108. {
  70109. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70110. if (glyph != 0)
  70111. {
  70112. path = glyph->path;
  70113. return true;
  70114. }
  70115. return false;
  70116. }
  70117. END_JUCE_NAMESPACE
  70118. /*** End of inlined file: juce_Typeface.cpp ***/
  70119. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70120. BEGIN_JUCE_NAMESPACE
  70121. AffineTransform::AffineTransform() throw()
  70122. : mat00 (1.0f),
  70123. mat01 (0),
  70124. mat02 (0),
  70125. mat10 (0),
  70126. mat11 (1.0f),
  70127. mat12 (0)
  70128. {
  70129. }
  70130. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70131. : mat00 (other.mat00),
  70132. mat01 (other.mat01),
  70133. mat02 (other.mat02),
  70134. mat10 (other.mat10),
  70135. mat11 (other.mat11),
  70136. mat12 (other.mat12)
  70137. {
  70138. }
  70139. AffineTransform::AffineTransform (const float mat00_,
  70140. const float mat01_,
  70141. const float mat02_,
  70142. const float mat10_,
  70143. const float mat11_,
  70144. const float mat12_) throw()
  70145. : mat00 (mat00_),
  70146. mat01 (mat01_),
  70147. mat02 (mat02_),
  70148. mat10 (mat10_),
  70149. mat11 (mat11_),
  70150. mat12 (mat12_)
  70151. {
  70152. }
  70153. AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70154. {
  70155. mat00 = other.mat00;
  70156. mat01 = other.mat01;
  70157. mat02 = other.mat02;
  70158. mat10 = other.mat10;
  70159. mat11 = other.mat11;
  70160. mat12 = other.mat12;
  70161. return *this;
  70162. }
  70163. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70164. {
  70165. return mat00 == other.mat00
  70166. && mat01 == other.mat01
  70167. && mat02 == other.mat02
  70168. && mat10 == other.mat10
  70169. && mat11 == other.mat11
  70170. && mat12 == other.mat12;
  70171. }
  70172. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70173. {
  70174. return ! operator== (other);
  70175. }
  70176. bool AffineTransform::isIdentity() const throw()
  70177. {
  70178. return (mat01 == 0)
  70179. && (mat02 == 0)
  70180. && (mat10 == 0)
  70181. && (mat12 == 0)
  70182. && (mat00 == 1.0f)
  70183. && (mat11 == 1.0f);
  70184. }
  70185. const AffineTransform AffineTransform::identity;
  70186. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70187. {
  70188. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70189. other.mat00 * mat01 + other.mat01 * mat11,
  70190. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70191. other.mat10 * mat00 + other.mat11 * mat10,
  70192. other.mat10 * mat01 + other.mat11 * mat11,
  70193. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70194. }
  70195. const AffineTransform AffineTransform::followedBy (const float omat00,
  70196. const float omat01,
  70197. const float omat02,
  70198. const float omat10,
  70199. const float omat11,
  70200. const float omat12) const throw()
  70201. {
  70202. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70203. omat00 * mat01 + omat01 * mat11,
  70204. omat00 * mat02 + omat01 * mat12 + omat02,
  70205. omat10 * mat00 + omat11 * mat10,
  70206. omat10 * mat01 + omat11 * mat11,
  70207. omat10 * mat02 + omat11 * mat12 + omat12);
  70208. }
  70209. const AffineTransform AffineTransform::translated (const float dx,
  70210. const float dy) const throw()
  70211. {
  70212. return AffineTransform (mat00, mat01, mat02 + dx,
  70213. mat10, mat11, mat12 + dy);
  70214. }
  70215. const AffineTransform AffineTransform::translation (const float dx,
  70216. const float dy) throw()
  70217. {
  70218. return AffineTransform (1.0f, 0, dx,
  70219. 0, 1.0f, dy);
  70220. }
  70221. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70222. {
  70223. const float cosRad = cosf (rad);
  70224. const float sinRad = sinf (rad);
  70225. return followedBy (cosRad, -sinRad, 0,
  70226. sinRad, cosRad, 0);
  70227. }
  70228. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70229. {
  70230. const float cosRad = cosf (rad);
  70231. const float sinRad = sinf (rad);
  70232. return AffineTransform (cosRad, -sinRad, 0,
  70233. sinRad, cosRad, 0);
  70234. }
  70235. const AffineTransform AffineTransform::rotated (const float angle,
  70236. const float pivotX,
  70237. const float pivotY) const throw()
  70238. {
  70239. return translated (-pivotX, -pivotY)
  70240. .rotated (angle)
  70241. .translated (pivotX, pivotY);
  70242. }
  70243. const AffineTransform AffineTransform::rotation (const float angle,
  70244. const float pivotX,
  70245. const float pivotY) throw()
  70246. {
  70247. return translation (-pivotX, -pivotY)
  70248. .rotated (angle)
  70249. .translated (pivotX, pivotY);
  70250. }
  70251. const AffineTransform AffineTransform::scaled (const float factorX,
  70252. const float factorY) const throw()
  70253. {
  70254. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70255. factorY * mat10, factorY * mat11, factorY * mat12);
  70256. }
  70257. const AffineTransform AffineTransform::scale (const float factorX,
  70258. const float factorY) throw()
  70259. {
  70260. return AffineTransform (factorX, 0, 0,
  70261. 0, factorY, 0);
  70262. }
  70263. const AffineTransform AffineTransform::sheared (const float shearX,
  70264. const float shearY) const throw()
  70265. {
  70266. return followedBy (1.0f, shearX, 0,
  70267. shearY, 1.0f, 0);
  70268. }
  70269. const AffineTransform AffineTransform::inverted() const throw()
  70270. {
  70271. double determinant = (mat00 * mat11 - mat10 * mat01);
  70272. if (determinant != 0.0)
  70273. {
  70274. determinant = 1.0 / determinant;
  70275. const float dst00 = (float) (mat11 * determinant);
  70276. const float dst10 = (float) (-mat10 * determinant);
  70277. const float dst01 = (float) (-mat01 * determinant);
  70278. const float dst11 = (float) (mat00 * determinant);
  70279. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70280. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70281. }
  70282. else
  70283. {
  70284. // singularity..
  70285. return *this;
  70286. }
  70287. }
  70288. bool AffineTransform::isSingularity() const throw()
  70289. {
  70290. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70291. }
  70292. bool AffineTransform::isOnlyTranslation() const throw()
  70293. {
  70294. return (mat01 == 0)
  70295. && (mat10 == 0)
  70296. && (mat00 == 1.0f)
  70297. && (mat11 == 1.0f);
  70298. }
  70299. void AffineTransform::transformPoint (float& x,
  70300. float& y) const throw()
  70301. {
  70302. const float oldX = x;
  70303. x = mat00 * oldX + mat01 * y + mat02;
  70304. y = mat10 * oldX + mat11 * y + mat12;
  70305. }
  70306. void AffineTransform::transformPoint (double& x,
  70307. double& y) const throw()
  70308. {
  70309. const double oldX = x;
  70310. x = mat00 * oldX + mat01 * y + mat02;
  70311. y = mat10 * oldX + mat11 * y + mat12;
  70312. }
  70313. END_JUCE_NAMESPACE
  70314. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70315. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70316. BEGIN_JUCE_NAMESPACE
  70317. BorderSize::BorderSize() throw()
  70318. : top (0),
  70319. left (0),
  70320. bottom (0),
  70321. right (0)
  70322. {
  70323. }
  70324. BorderSize::BorderSize (const BorderSize& other) throw()
  70325. : top (other.top),
  70326. left (other.left),
  70327. bottom (other.bottom),
  70328. right (other.right)
  70329. {
  70330. }
  70331. BorderSize::BorderSize (const int topGap,
  70332. const int leftGap,
  70333. const int bottomGap,
  70334. const int rightGap) throw()
  70335. : top (topGap),
  70336. left (leftGap),
  70337. bottom (bottomGap),
  70338. right (rightGap)
  70339. {
  70340. }
  70341. BorderSize::BorderSize (const int allGaps) throw()
  70342. : top (allGaps),
  70343. left (allGaps),
  70344. bottom (allGaps),
  70345. right (allGaps)
  70346. {
  70347. }
  70348. BorderSize::~BorderSize() throw()
  70349. {
  70350. }
  70351. void BorderSize::setTop (const int newTopGap) throw()
  70352. {
  70353. top = newTopGap;
  70354. }
  70355. void BorderSize::setLeft (const int newLeftGap) throw()
  70356. {
  70357. left = newLeftGap;
  70358. }
  70359. void BorderSize::setBottom (const int newBottomGap) throw()
  70360. {
  70361. bottom = newBottomGap;
  70362. }
  70363. void BorderSize::setRight (const int newRightGap) throw()
  70364. {
  70365. right = newRightGap;
  70366. }
  70367. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70368. {
  70369. return Rectangle<int> (r.getX() + left,
  70370. r.getY() + top,
  70371. r.getWidth() - (left + right),
  70372. r.getHeight() - (top + bottom));
  70373. }
  70374. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70375. {
  70376. r.setBounds (r.getX() + left,
  70377. r.getY() + top,
  70378. r.getWidth() - (left + right),
  70379. r.getHeight() - (top + bottom));
  70380. }
  70381. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70382. {
  70383. return Rectangle<int> (r.getX() - left,
  70384. r.getY() - top,
  70385. r.getWidth() + (left + right),
  70386. r.getHeight() + (top + bottom));
  70387. }
  70388. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70389. {
  70390. r.setBounds (r.getX() - left,
  70391. r.getY() - top,
  70392. r.getWidth() + (left + right),
  70393. r.getHeight() + (top + bottom));
  70394. }
  70395. bool BorderSize::operator== (const BorderSize& other) const throw()
  70396. {
  70397. return top == other.top
  70398. && left == other.left
  70399. && bottom == other.bottom
  70400. && right == other.right;
  70401. }
  70402. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70403. {
  70404. return ! operator== (other);
  70405. }
  70406. END_JUCE_NAMESPACE
  70407. /*** End of inlined file: juce_BorderSize.cpp ***/
  70408. /*** Start of inlined file: juce_Line.cpp ***/
  70409. BEGIN_JUCE_NAMESPACE
  70410. static bool juce_lineIntersection (const float x1, const float y1,
  70411. const float x2, const float y2,
  70412. const float x3, const float y3,
  70413. const float x4, const float y4,
  70414. float& intersectionX,
  70415. float& intersectionY) throw()
  70416. {
  70417. if (x2 != x3 || y2 != y3)
  70418. {
  70419. const float dx1 = x2 - x1;
  70420. const float dy1 = y2 - y1;
  70421. const float dx2 = x4 - x3;
  70422. const float dy2 = y4 - y3;
  70423. const float divisor = dx1 * dy2 - dx2 * dy1;
  70424. if (divisor == 0)
  70425. {
  70426. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70427. {
  70428. if (dy1 == 0 && dy2 != 0)
  70429. {
  70430. const float along = (y1 - y3) / dy2;
  70431. intersectionX = x3 + along * dx2;
  70432. intersectionY = y1;
  70433. return along >= 0 && along <= 1.0f;
  70434. }
  70435. else if (dy2 == 0 && dy1 != 0)
  70436. {
  70437. const float along = (y3 - y1) / dy1;
  70438. intersectionX = x1 + along * dx1;
  70439. intersectionY = y3;
  70440. return along >= 0 && along <= 1.0f;
  70441. }
  70442. else if (dx1 == 0 && dx2 != 0)
  70443. {
  70444. const float along = (x1 - x3) / dx2;
  70445. intersectionX = x1;
  70446. intersectionY = y3 + along * dy2;
  70447. return along >= 0 && along <= 1.0f;
  70448. }
  70449. else if (dx2 == 0 && dx1 != 0)
  70450. {
  70451. const float along = (x3 - x1) / dx1;
  70452. intersectionX = x3;
  70453. intersectionY = y1 + along * dy1;
  70454. return along >= 0 && along <= 1.0f;
  70455. }
  70456. }
  70457. intersectionX = 0.5f * (x2 + x3);
  70458. intersectionY = 0.5f * (y2 + y3);
  70459. return false;
  70460. }
  70461. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70462. intersectionX = x1 + along1 * dx1;
  70463. intersectionY = y1 + along1 * dy1;
  70464. if (along1 < 0 || along1 > 1.0f)
  70465. return false;
  70466. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70467. return along2 >= 0 && along2 <= 1.0f;
  70468. }
  70469. intersectionX = x2;
  70470. intersectionY = y2;
  70471. return true;
  70472. }
  70473. Line::Line() throw()
  70474. : startX (0.0f),
  70475. startY (0.0f),
  70476. endX (0.0f),
  70477. endY (0.0f)
  70478. {
  70479. }
  70480. Line::Line (const Line& other) throw()
  70481. : startX (other.startX),
  70482. startY (other.startY),
  70483. endX (other.endX),
  70484. endY (other.endY)
  70485. {
  70486. }
  70487. Line::Line (const float startX_, const float startY_,
  70488. const float endX_, const float endY_) throw()
  70489. : startX (startX_),
  70490. startY (startY_),
  70491. endX (endX_),
  70492. endY (endY_)
  70493. {
  70494. }
  70495. Line::Line (const Point<float>& start,
  70496. const Point<float>& end) throw()
  70497. : startX (start.getX()),
  70498. startY (start.getY()),
  70499. endX (end.getX()),
  70500. endY (end.getY())
  70501. {
  70502. }
  70503. Line& Line::operator= (const Line& other) throw()
  70504. {
  70505. startX = other.startX;
  70506. startY = other.startY;
  70507. endX = other.endX;
  70508. endY = other.endY;
  70509. return *this;
  70510. }
  70511. Line::~Line() throw()
  70512. {
  70513. }
  70514. const Point<float> Line::getStart() const throw()
  70515. {
  70516. return Point<float> (startX, startY);
  70517. }
  70518. const Point<float> Line::getEnd() const throw()
  70519. {
  70520. return Point<float> (endX, endY);
  70521. }
  70522. void Line::setStart (const float newStartX,
  70523. const float newStartY) throw()
  70524. {
  70525. startX = newStartX;
  70526. startY = newStartY;
  70527. }
  70528. void Line::setStart (const Point<float>& newStart) throw()
  70529. {
  70530. startX = newStart.getX();
  70531. startY = newStart.getY();
  70532. }
  70533. void Line::setEnd (const float newEndX,
  70534. const float newEndY) throw()
  70535. {
  70536. endX = newEndX;
  70537. endY = newEndY;
  70538. }
  70539. void Line::setEnd (const Point<float>& newEnd) throw()
  70540. {
  70541. endX = newEnd.getX();
  70542. endY = newEnd.getY();
  70543. }
  70544. bool Line::operator== (const Line& other) const throw()
  70545. {
  70546. return startX == other.startX
  70547. && startY == other.startY
  70548. && endX == other.endX
  70549. && endY == other.endY;
  70550. }
  70551. bool Line::operator!= (const Line& other) const throw()
  70552. {
  70553. return startX != other.startX
  70554. || startY != other.startY
  70555. || endX != other.endX
  70556. || endY != other.endY;
  70557. }
  70558. void Line::applyTransform (const AffineTransform& transform) throw()
  70559. {
  70560. transform.transformPoint (startX, startY);
  70561. transform.transformPoint (endX, endY);
  70562. }
  70563. float Line::getLength() const throw()
  70564. {
  70565. return (float) juce_hypot (startX - endX,
  70566. startY - endY);
  70567. }
  70568. float Line::getAngle() const throw()
  70569. {
  70570. return atan2f (endX - startX,
  70571. endY - startY);
  70572. }
  70573. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  70574. {
  70575. const float alpha = distanceFromStart / getLength();
  70576. return Point<float> (startX + (endX - startX) * alpha,
  70577. startY + (endY - startY) * alpha);
  70578. }
  70579. const Point<float> Line::getPointAlongLine (const float offsetX,
  70580. const float offsetY) const throw()
  70581. {
  70582. const float dx = endX - startX;
  70583. const float dy = endY - startY;
  70584. const double length = juce_hypot (dx, dy);
  70585. if (length == 0)
  70586. return Point<float> (startX, startY);
  70587. else
  70588. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  70589. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  70590. }
  70591. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  70592. {
  70593. return Point<float> (startX + (endX - startX) * alpha,
  70594. startY + (endY - startY) * alpha);
  70595. }
  70596. float Line::getDistanceFromLine (const float x,
  70597. const float y) const throw()
  70598. {
  70599. const double dx = endX - startX;
  70600. const double dy = endY - startY;
  70601. const double length = dx * dx + dy * dy;
  70602. if (length > 0)
  70603. {
  70604. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  70605. if (prop >= 0.0f && prop < 1.0f)
  70606. {
  70607. return (float) juce_hypot (x - (startX + prop * dx),
  70608. y - (startY + prop * dy));
  70609. }
  70610. }
  70611. return (float) jmin (juce_hypot (x - startX, y - startY),
  70612. juce_hypot (x - endX, y - endY));
  70613. }
  70614. float Line::findNearestPointTo (const float x,
  70615. const float y) const throw()
  70616. {
  70617. const double dx = endX - startX;
  70618. const double dy = endY - startY;
  70619. const double length = dx * dx + dy * dy;
  70620. if (length <= 0.0)
  70621. return 0.0f;
  70622. return jlimit (0.0f, 1.0f,
  70623. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  70624. }
  70625. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  70626. {
  70627. const float length = getLength();
  70628. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  70629. getEnd());
  70630. }
  70631. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  70632. {
  70633. const float length = getLength();
  70634. return Line (getStart(),
  70635. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  70636. }
  70637. bool Line::clipToPath (const Path& path,
  70638. const bool keepSectionOutsidePath) throw()
  70639. {
  70640. const bool startInside = path.contains (startX, startY);
  70641. const bool endInside = path.contains (endX, endY);
  70642. if (startInside == endInside)
  70643. {
  70644. if (keepSectionOutsidePath != startInside)
  70645. {
  70646. // entirely outside the path
  70647. return false;
  70648. }
  70649. else
  70650. {
  70651. // entirely inside the path
  70652. startX = 0.0f;
  70653. startY = 0.0f;
  70654. endX = 0.0f;
  70655. endY = 0.0f;
  70656. return true;
  70657. }
  70658. }
  70659. else
  70660. {
  70661. bool changed = false;
  70662. PathFlatteningIterator iter (path, AffineTransform::identity);
  70663. while (iter.next())
  70664. {
  70665. float ix, iy;
  70666. if (intersects (Line (iter.x1, iter.y1,
  70667. iter.x2, iter.y2),
  70668. ix, iy))
  70669. {
  70670. if ((startInside && keepSectionOutsidePath)
  70671. || (endInside && ! keepSectionOutsidePath))
  70672. {
  70673. setStart (ix, iy);
  70674. }
  70675. else
  70676. {
  70677. setEnd (ix, iy);
  70678. }
  70679. changed = true;
  70680. }
  70681. }
  70682. return changed;
  70683. }
  70684. }
  70685. bool Line::intersects (const Line& line,
  70686. float& intersectionX,
  70687. float& intersectionY) const throw()
  70688. {
  70689. return juce_lineIntersection (startX, startY,
  70690. endX, endY,
  70691. line.startX, line.startY,
  70692. line.endX, line.endY,
  70693. intersectionX,
  70694. intersectionY);
  70695. }
  70696. bool Line::isVertical() const throw()
  70697. {
  70698. return startX == endX;
  70699. }
  70700. bool Line::isHorizontal() const throw()
  70701. {
  70702. return startY == endY;
  70703. }
  70704. bool Line::isPointAbove (const float x, const float y) const throw()
  70705. {
  70706. return startX != endX
  70707. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  70708. }
  70709. END_JUCE_NAMESPACE
  70710. /*** End of inlined file: juce_Line.cpp ***/
  70711. /*** Start of inlined file: juce_Path.cpp ***/
  70712. BEGIN_JUCE_NAMESPACE
  70713. // tests that some co-ords aren't NaNs
  70714. #define CHECK_COORDS_ARE_VALID(x, y) \
  70715. jassert (x == x && y == y);
  70716. namespace PathHelpers
  70717. {
  70718. static const float ellipseAngularIncrement = 0.05f;
  70719. static void perpendicularOffset (const float x1, const float y1,
  70720. const float x2, const float y2,
  70721. const float offsetX, const float offsetY,
  70722. float& resultX, float& resultY) throw()
  70723. {
  70724. const float dx = x2 - x1;
  70725. const float dy = y2 - y1;
  70726. const float len = juce_hypotf (dx, dy);
  70727. if (len == 0)
  70728. {
  70729. resultX = x1;
  70730. resultY = y1;
  70731. }
  70732. else
  70733. {
  70734. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  70735. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  70736. }
  70737. }
  70738. static const String nextToken (const tchar*& t)
  70739. {
  70740. while (CharacterFunctions::isWhitespace (*t))
  70741. ++t;
  70742. const tchar* const start = t;
  70743. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  70744. ++t;
  70745. const int length = (int) (t - start);
  70746. while (CharacterFunctions::isWhitespace (*t))
  70747. ++t;
  70748. return String (start, length);
  70749. }
  70750. }
  70751. const float Path::lineMarker = 100001.0f;
  70752. const float Path::moveMarker = 100002.0f;
  70753. const float Path::quadMarker = 100003.0f;
  70754. const float Path::cubicMarker = 100004.0f;
  70755. const float Path::closeSubPathMarker = 100005.0f;
  70756. Path::Path()
  70757. : numElements (0),
  70758. pathXMin (0),
  70759. pathXMax (0),
  70760. pathYMin (0),
  70761. pathYMax (0),
  70762. useNonZeroWinding (true)
  70763. {
  70764. }
  70765. Path::~Path()
  70766. {
  70767. }
  70768. Path::Path (const Path& other)
  70769. : numElements (other.numElements),
  70770. pathXMin (other.pathXMin),
  70771. pathXMax (other.pathXMax),
  70772. pathYMin (other.pathYMin),
  70773. pathYMax (other.pathYMax),
  70774. useNonZeroWinding (other.useNonZeroWinding)
  70775. {
  70776. if (numElements > 0)
  70777. {
  70778. data.setAllocatedSize (numElements);
  70779. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70780. }
  70781. }
  70782. Path& Path::operator= (const Path& other)
  70783. {
  70784. if (this != &other)
  70785. {
  70786. data.ensureAllocatedSize (other.numElements);
  70787. numElements = other.numElements;
  70788. pathXMin = other.pathXMin;
  70789. pathXMax = other.pathXMax;
  70790. pathYMin = other.pathYMin;
  70791. pathYMax = other.pathYMax;
  70792. useNonZeroWinding = other.useNonZeroWinding;
  70793. if (numElements > 0)
  70794. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70795. }
  70796. return *this;
  70797. }
  70798. void Path::clear() throw()
  70799. {
  70800. numElements = 0;
  70801. pathXMin = 0;
  70802. pathYMin = 0;
  70803. pathYMax = 0;
  70804. pathXMax = 0;
  70805. }
  70806. void Path::swapWithPath (Path& other)
  70807. {
  70808. data.swapWith (other.data);
  70809. swapVariables <size_t> (numElements, other.numElements);
  70810. swapVariables <float> (pathXMin, other.pathXMin);
  70811. swapVariables <float> (pathXMax, other.pathXMax);
  70812. swapVariables <float> (pathYMin, other.pathYMin);
  70813. swapVariables <float> (pathYMax, other.pathYMax);
  70814. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  70815. }
  70816. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  70817. {
  70818. useNonZeroWinding = isNonZero;
  70819. }
  70820. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  70821. const bool preserveProportions) throw()
  70822. {
  70823. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  70824. }
  70825. bool Path::isEmpty() const throw()
  70826. {
  70827. size_t i = 0;
  70828. while (i < numElements)
  70829. {
  70830. const float type = data.elements [i++];
  70831. if (type == moveMarker)
  70832. {
  70833. i += 2;
  70834. }
  70835. else if (type == lineMarker
  70836. || type == quadMarker
  70837. || type == cubicMarker)
  70838. {
  70839. return false;
  70840. }
  70841. }
  70842. return true;
  70843. }
  70844. const Rectangle<float> Path::getBounds() const throw()
  70845. {
  70846. return Rectangle<float> (pathXMin, pathYMin,
  70847. pathXMax - pathXMin,
  70848. pathYMax - pathYMin);
  70849. }
  70850. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  70851. {
  70852. return getBounds().transformed (transform);
  70853. }
  70854. void Path::startNewSubPath (const float x, const float y)
  70855. {
  70856. CHECK_COORDS_ARE_VALID (x, y);
  70857. if (numElements == 0)
  70858. {
  70859. pathXMin = pathXMax = x;
  70860. pathYMin = pathYMax = y;
  70861. }
  70862. else
  70863. {
  70864. pathXMin = jmin (pathXMin, x);
  70865. pathXMax = jmax (pathXMax, x);
  70866. pathYMin = jmin (pathYMin, y);
  70867. pathYMax = jmax (pathYMax, y);
  70868. }
  70869. data.ensureAllocatedSize (numElements + 3);
  70870. data.elements [numElements++] = moveMarker;
  70871. data.elements [numElements++] = x;
  70872. data.elements [numElements++] = y;
  70873. }
  70874. void Path::lineTo (const float x, const float y)
  70875. {
  70876. CHECK_COORDS_ARE_VALID (x, y);
  70877. if (numElements == 0)
  70878. startNewSubPath (0, 0);
  70879. data.ensureAllocatedSize (numElements + 3);
  70880. data.elements [numElements++] = lineMarker;
  70881. data.elements [numElements++] = x;
  70882. data.elements [numElements++] = y;
  70883. pathXMin = jmin (pathXMin, x);
  70884. pathXMax = jmax (pathXMax, x);
  70885. pathYMin = jmin (pathYMin, y);
  70886. pathYMax = jmax (pathYMax, y);
  70887. }
  70888. void Path::quadraticTo (const float x1, const float y1,
  70889. const float x2, const float y2)
  70890. {
  70891. CHECK_COORDS_ARE_VALID (x1, y1);
  70892. CHECK_COORDS_ARE_VALID (x2, y2);
  70893. if (numElements == 0)
  70894. startNewSubPath (0, 0);
  70895. data.ensureAllocatedSize (numElements + 5);
  70896. data.elements [numElements++] = quadMarker;
  70897. data.elements [numElements++] = x1;
  70898. data.elements [numElements++] = y1;
  70899. data.elements [numElements++] = x2;
  70900. data.elements [numElements++] = y2;
  70901. pathXMin = jmin (pathXMin, x1, x2);
  70902. pathXMax = jmax (pathXMax, x1, x2);
  70903. pathYMin = jmin (pathYMin, y1, y2);
  70904. pathYMax = jmax (pathYMax, y1, y2);
  70905. }
  70906. void Path::cubicTo (const float x1, const float y1,
  70907. const float x2, const float y2,
  70908. const float x3, const float y3)
  70909. {
  70910. CHECK_COORDS_ARE_VALID (x1, y1);
  70911. CHECK_COORDS_ARE_VALID (x2, y2);
  70912. CHECK_COORDS_ARE_VALID (x3, y3);
  70913. if (numElements == 0)
  70914. startNewSubPath (0, 0);
  70915. data.ensureAllocatedSize (numElements + 7);
  70916. data.elements [numElements++] = cubicMarker;
  70917. data.elements [numElements++] = x1;
  70918. data.elements [numElements++] = y1;
  70919. data.elements [numElements++] = x2;
  70920. data.elements [numElements++] = y2;
  70921. data.elements [numElements++] = x3;
  70922. data.elements [numElements++] = y3;
  70923. pathXMin = jmin (pathXMin, x1, x2, x3);
  70924. pathXMax = jmax (pathXMax, x1, x2, x3);
  70925. pathYMin = jmin (pathYMin, y1, y2, y3);
  70926. pathYMax = jmax (pathYMax, y1, y2, y3);
  70927. }
  70928. void Path::closeSubPath()
  70929. {
  70930. if (numElements > 0
  70931. && data.elements [numElements - 1] != closeSubPathMarker)
  70932. {
  70933. data.ensureAllocatedSize (numElements + 1);
  70934. data.elements [numElements++] = closeSubPathMarker;
  70935. }
  70936. }
  70937. const Point<float> Path::getCurrentPosition() const
  70938. {
  70939. int i = numElements - 1;
  70940. if (i > 0 && data.elements[i] == closeSubPathMarker)
  70941. {
  70942. while (i >= 0)
  70943. {
  70944. if (data.elements[i] == moveMarker)
  70945. {
  70946. i += 2;
  70947. break;
  70948. }
  70949. --i;
  70950. }
  70951. }
  70952. if (i > 0)
  70953. return Point<float> (data.elements [i - 1], data.elements [i]);
  70954. return Point<float>();
  70955. }
  70956. void Path::addRectangle (const float x, const float y,
  70957. const float w, const float h)
  70958. {
  70959. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  70960. if (w < 0)
  70961. swapVariables (x1, x2);
  70962. if (h < 0)
  70963. swapVariables (y1, y2);
  70964. data.ensureAllocatedSize (numElements + 13);
  70965. if (numElements == 0)
  70966. {
  70967. pathXMin = x1;
  70968. pathXMax = x2;
  70969. pathYMin = y1;
  70970. pathYMax = y2;
  70971. }
  70972. else
  70973. {
  70974. pathXMin = jmin (pathXMin, x1);
  70975. pathXMax = jmax (pathXMax, x2);
  70976. pathYMin = jmin (pathYMin, y1);
  70977. pathYMax = jmax (pathYMax, y2);
  70978. }
  70979. data.elements [numElements++] = moveMarker;
  70980. data.elements [numElements++] = x1;
  70981. data.elements [numElements++] = y2;
  70982. data.elements [numElements++] = lineMarker;
  70983. data.elements [numElements++] = x1;
  70984. data.elements [numElements++] = y1;
  70985. data.elements [numElements++] = lineMarker;
  70986. data.elements [numElements++] = x2;
  70987. data.elements [numElements++] = y1;
  70988. data.elements [numElements++] = lineMarker;
  70989. data.elements [numElements++] = x2;
  70990. data.elements [numElements++] = y2;
  70991. data.elements [numElements++] = closeSubPathMarker;
  70992. }
  70993. void Path::addRectangle (const Rectangle<int>& rectangle)
  70994. {
  70995. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  70996. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  70997. }
  70998. void Path::addRoundedRectangle (const float x, const float y,
  70999. const float w, const float h,
  71000. float csx,
  71001. float csy)
  71002. {
  71003. csx = jmin (csx, w * 0.5f);
  71004. csy = jmin (csy, h * 0.5f);
  71005. const float cs45x = csx * 0.45f;
  71006. const float cs45y = csy * 0.45f;
  71007. const float x2 = x + w;
  71008. const float y2 = y + h;
  71009. startNewSubPath (x + csx, y);
  71010. lineTo (x2 - csx, y);
  71011. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71012. lineTo (x2, y2 - csy);
  71013. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71014. lineTo (x + csx, y2);
  71015. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71016. lineTo (x, y + csy);
  71017. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71018. closeSubPath();
  71019. }
  71020. void Path::addRoundedRectangle (const float x, const float y,
  71021. const float w, const float h,
  71022. float cs)
  71023. {
  71024. addRoundedRectangle (x, y, w, h, cs, cs);
  71025. }
  71026. void Path::addTriangle (const float x1, const float y1,
  71027. const float x2, const float y2,
  71028. const float x3, const float y3)
  71029. {
  71030. startNewSubPath (x1, y1);
  71031. lineTo (x2, y2);
  71032. lineTo (x3, y3);
  71033. closeSubPath();
  71034. }
  71035. void Path::addQuadrilateral (const float x1, const float y1,
  71036. const float x2, const float y2,
  71037. const float x3, const float y3,
  71038. const float x4, const float y4)
  71039. {
  71040. startNewSubPath (x1, y1);
  71041. lineTo (x2, y2);
  71042. lineTo (x3, y3);
  71043. lineTo (x4, y4);
  71044. closeSubPath();
  71045. }
  71046. void Path::addEllipse (const float x, const float y,
  71047. const float w, const float h)
  71048. {
  71049. const float hw = w * 0.5f;
  71050. const float hw55 = hw * 0.55f;
  71051. const float hh = h * 0.5f;
  71052. const float hh45 = hh * 0.55f;
  71053. const float cx = x + hw;
  71054. const float cy = y + hh;
  71055. startNewSubPath (cx, cy - hh);
  71056. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71057. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71058. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71059. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71060. closeSubPath();
  71061. }
  71062. void Path::addArc (const float x, const float y,
  71063. const float w, const float h,
  71064. const float fromRadians,
  71065. const float toRadians,
  71066. const bool startAsNewSubPath)
  71067. {
  71068. const float radiusX = w / 2.0f;
  71069. const float radiusY = h / 2.0f;
  71070. addCentredArc (x + radiusX,
  71071. y + radiusY,
  71072. radiusX, radiusY,
  71073. 0.0f,
  71074. fromRadians, toRadians,
  71075. startAsNewSubPath);
  71076. }
  71077. void Path::addCentredArc (const float centreX, const float centreY,
  71078. const float radiusX, const float radiusY,
  71079. const float rotationOfEllipse,
  71080. const float fromRadians,
  71081. const float toRadians,
  71082. const bool startAsNewSubPath)
  71083. {
  71084. if (radiusX > 0.0f && radiusY > 0.0f)
  71085. {
  71086. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71087. float angle = fromRadians;
  71088. if (startAsNewSubPath)
  71089. {
  71090. float x = centreX + radiusX * sinf (angle);
  71091. float y = centreY - radiusY * cosf (angle);
  71092. if (rotationOfEllipse != 0)
  71093. rotation.transformPoint (x, y);
  71094. startNewSubPath (x, y);
  71095. }
  71096. if (fromRadians < toRadians)
  71097. {
  71098. if (startAsNewSubPath)
  71099. angle += PathHelpers::ellipseAngularIncrement;
  71100. while (angle < toRadians)
  71101. {
  71102. float x = centreX + radiusX * sinf (angle);
  71103. float y = centreY - radiusY * cosf (angle);
  71104. if (rotationOfEllipse != 0)
  71105. rotation.transformPoint (x, y);
  71106. lineTo (x, y);
  71107. angle += PathHelpers::ellipseAngularIncrement;
  71108. }
  71109. }
  71110. else
  71111. {
  71112. if (startAsNewSubPath)
  71113. angle -= PathHelpers::ellipseAngularIncrement;
  71114. while (angle > toRadians)
  71115. {
  71116. float x = centreX + radiusX * sinf (angle);
  71117. float y = centreY - radiusY * cosf (angle);
  71118. if (rotationOfEllipse != 0)
  71119. rotation.transformPoint (x, y);
  71120. lineTo (x, y);
  71121. angle -= PathHelpers::ellipseAngularIncrement;
  71122. }
  71123. }
  71124. float x = centreX + radiusX * sinf (toRadians);
  71125. float y = centreY - radiusY * cosf (toRadians);
  71126. if (rotationOfEllipse != 0)
  71127. rotation.transformPoint (x, y);
  71128. lineTo (x, y);
  71129. }
  71130. }
  71131. void Path::addPieSegment (const float x, const float y,
  71132. const float width, const float height,
  71133. const float fromRadians,
  71134. const float toRadians,
  71135. const float innerCircleProportionalSize)
  71136. {
  71137. float hw = width * 0.5f;
  71138. float hh = height * 0.5f;
  71139. const float centreX = x + hw;
  71140. const float centreY = y + hh;
  71141. startNewSubPath (centreX + hw * sinf (fromRadians),
  71142. centreY - hh * cosf (fromRadians));
  71143. addArc (x, y, width, height, fromRadians, toRadians);
  71144. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71145. {
  71146. closeSubPath();
  71147. if (innerCircleProportionalSize > 0)
  71148. {
  71149. hw *= innerCircleProportionalSize;
  71150. hh *= innerCircleProportionalSize;
  71151. startNewSubPath (centreX + hw * sinf (toRadians),
  71152. centreY - hh * cosf (toRadians));
  71153. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71154. toRadians, fromRadians);
  71155. }
  71156. }
  71157. else
  71158. {
  71159. if (innerCircleProportionalSize > 0)
  71160. {
  71161. hw *= innerCircleProportionalSize;
  71162. hh *= innerCircleProportionalSize;
  71163. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71164. toRadians, fromRadians);
  71165. }
  71166. else
  71167. {
  71168. lineTo (centreX, centreY);
  71169. }
  71170. }
  71171. closeSubPath();
  71172. }
  71173. void Path::addLineSegment (const float startX, const float startY,
  71174. const float endX, const float endY,
  71175. float lineThickness)
  71176. {
  71177. lineThickness *= 0.5f;
  71178. float x, y;
  71179. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71180. 0, lineThickness, x, y);
  71181. startNewSubPath (x, y);
  71182. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71183. 0, -lineThickness, x, y);
  71184. lineTo (x, y);
  71185. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71186. 0, lineThickness, x, y);
  71187. lineTo (x, y);
  71188. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71189. 0, -lineThickness, x, y);
  71190. lineTo (x, y);
  71191. closeSubPath();
  71192. }
  71193. void Path::addArrow (const float startX, const float startY,
  71194. const float endX, const float endY,
  71195. float lineThickness,
  71196. float arrowheadWidth,
  71197. float arrowheadLength)
  71198. {
  71199. lineThickness *= 0.5f;
  71200. arrowheadWidth *= 0.5f;
  71201. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71202. startY - endY));
  71203. float x, y;
  71204. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71205. 0, lineThickness, x, y);
  71206. startNewSubPath (x, y);
  71207. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71208. 0, -lineThickness, x, y);
  71209. lineTo (x, y);
  71210. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71211. arrowheadLength, lineThickness, x, y);
  71212. lineTo (x, y);
  71213. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71214. arrowheadLength, arrowheadWidth, x, y);
  71215. lineTo (x, y);
  71216. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71217. 0, 0, x, y);
  71218. lineTo (x, y);
  71219. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71220. arrowheadLength, -arrowheadWidth, x, y);
  71221. lineTo (x, y);
  71222. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71223. arrowheadLength, -lineThickness, x, y);
  71224. lineTo (x, y);
  71225. closeSubPath();
  71226. }
  71227. void Path::addStar (const float centreX,
  71228. const float centreY,
  71229. const int numberOfPoints,
  71230. const float innerRadius,
  71231. const float outerRadius,
  71232. const float startAngle)
  71233. {
  71234. jassert (numberOfPoints > 1); // this would be silly.
  71235. if (numberOfPoints > 1)
  71236. {
  71237. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71238. for (int i = 0; i < numberOfPoints; ++i)
  71239. {
  71240. float angle = startAngle + i * angleBetweenPoints;
  71241. const float x = centreX + outerRadius * sinf (angle);
  71242. const float y = centreY - outerRadius * cosf (angle);
  71243. if (i == 0)
  71244. startNewSubPath (x, y);
  71245. else
  71246. lineTo (x, y);
  71247. angle += angleBetweenPoints * 0.5f;
  71248. lineTo (centreX + innerRadius * sinf (angle),
  71249. centreY - innerRadius * cosf (angle));
  71250. }
  71251. closeSubPath();
  71252. }
  71253. }
  71254. void Path::addBubble (float x, float y,
  71255. float w, float h,
  71256. float cs,
  71257. float tipX,
  71258. float tipY,
  71259. int whichSide,
  71260. float arrowPos,
  71261. float arrowWidth)
  71262. {
  71263. if (w > 1.0f && h > 1.0f)
  71264. {
  71265. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71266. const float cs2 = 2.0f * cs;
  71267. startNewSubPath (x + cs, y);
  71268. if (whichSide == 0)
  71269. {
  71270. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71271. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71272. lineTo (arrowX1, y);
  71273. lineTo (tipX, tipY);
  71274. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71275. }
  71276. lineTo (x + w - cs, y);
  71277. if (cs > 0.0f)
  71278. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71279. if (whichSide == 3)
  71280. {
  71281. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71282. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71283. lineTo (x + w, arrowY1);
  71284. lineTo (tipX, tipY);
  71285. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71286. }
  71287. lineTo (x + w, y + h - cs);
  71288. if (cs > 0.0f)
  71289. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71290. if (whichSide == 2)
  71291. {
  71292. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71293. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71294. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71295. lineTo (tipX, tipY);
  71296. lineTo (arrowX1, y + h);
  71297. }
  71298. lineTo (x + cs, y + h);
  71299. if (cs > 0.0f)
  71300. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71301. if (whichSide == 1)
  71302. {
  71303. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71304. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71305. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71306. lineTo (tipX, tipY);
  71307. lineTo (x, arrowY1);
  71308. }
  71309. lineTo (x, y + cs);
  71310. if (cs > 0.0f)
  71311. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - PathHelpers::ellipseAngularIncrement);
  71312. closeSubPath();
  71313. }
  71314. }
  71315. void Path::addPath (const Path& other)
  71316. {
  71317. size_t i = 0;
  71318. while (i < other.numElements)
  71319. {
  71320. const float type = other.data.elements [i++];
  71321. if (type == moveMarker)
  71322. {
  71323. startNewSubPath (other.data.elements [i],
  71324. other.data.elements [i + 1]);
  71325. i += 2;
  71326. }
  71327. else if (type == lineMarker)
  71328. {
  71329. lineTo (other.data.elements [i],
  71330. other.data.elements [i + 1]);
  71331. i += 2;
  71332. }
  71333. else if (type == quadMarker)
  71334. {
  71335. quadraticTo (other.data.elements [i],
  71336. other.data.elements [i + 1],
  71337. other.data.elements [i + 2],
  71338. other.data.elements [i + 3]);
  71339. i += 4;
  71340. }
  71341. else if (type == cubicMarker)
  71342. {
  71343. cubicTo (other.data.elements [i],
  71344. other.data.elements [i + 1],
  71345. other.data.elements [i + 2],
  71346. other.data.elements [i + 3],
  71347. other.data.elements [i + 4],
  71348. other.data.elements [i + 5]);
  71349. i += 6;
  71350. }
  71351. else if (type == closeSubPathMarker)
  71352. {
  71353. closeSubPath();
  71354. }
  71355. else
  71356. {
  71357. // something's gone wrong with the element list!
  71358. jassertfalse
  71359. }
  71360. }
  71361. }
  71362. void Path::addPath (const Path& other,
  71363. const AffineTransform& transformToApply)
  71364. {
  71365. size_t i = 0;
  71366. while (i < other.numElements)
  71367. {
  71368. const float type = other.data.elements [i++];
  71369. if (type == closeSubPathMarker)
  71370. {
  71371. closeSubPath();
  71372. }
  71373. else
  71374. {
  71375. float x = other.data.elements [i++];
  71376. float y = other.data.elements [i++];
  71377. transformToApply.transformPoint (x, y);
  71378. if (type == moveMarker)
  71379. {
  71380. startNewSubPath (x, y);
  71381. }
  71382. else if (type == lineMarker)
  71383. {
  71384. lineTo (x, y);
  71385. }
  71386. else if (type == quadMarker)
  71387. {
  71388. float x2 = other.data.elements [i++];
  71389. float y2 = other.data.elements [i++];
  71390. transformToApply.transformPoint (x2, y2);
  71391. quadraticTo (x, y, x2, y2);
  71392. }
  71393. else if (type == cubicMarker)
  71394. {
  71395. float x2 = other.data.elements [i++];
  71396. float y2 = other.data.elements [i++];
  71397. float x3 = other.data.elements [i++];
  71398. float y3 = other.data.elements [i++];
  71399. transformToApply.transformPoint (x2, y2);
  71400. transformToApply.transformPoint (x3, y3);
  71401. cubicTo (x, y, x2, y2, x3, y3);
  71402. }
  71403. else
  71404. {
  71405. // something's gone wrong with the element list!
  71406. jassertfalse
  71407. }
  71408. }
  71409. }
  71410. }
  71411. void Path::applyTransform (const AffineTransform& transform) throw()
  71412. {
  71413. size_t i = 0;
  71414. pathYMin = pathXMin = 0;
  71415. pathYMax = pathXMax = 0;
  71416. bool setMaxMin = false;
  71417. while (i < numElements)
  71418. {
  71419. const float type = data.elements [i++];
  71420. if (type == moveMarker)
  71421. {
  71422. transform.transformPoint (data.elements [i],
  71423. data.elements [i + 1]);
  71424. if (setMaxMin)
  71425. {
  71426. pathXMin = jmin (pathXMin, data.elements [i]);
  71427. pathXMax = jmax (pathXMax, data.elements [i]);
  71428. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71429. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71430. }
  71431. else
  71432. {
  71433. pathXMin = pathXMax = data.elements [i];
  71434. pathYMin = pathYMax = data.elements [i + 1];
  71435. setMaxMin = true;
  71436. }
  71437. i += 2;
  71438. }
  71439. else if (type == lineMarker)
  71440. {
  71441. transform.transformPoint (data.elements [i],
  71442. data.elements [i + 1]);
  71443. pathXMin = jmin (pathXMin, data.elements [i]);
  71444. pathXMax = jmax (pathXMax, data.elements [i]);
  71445. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71446. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71447. i += 2;
  71448. }
  71449. else if (type == quadMarker)
  71450. {
  71451. transform.transformPoint (data.elements [i],
  71452. data.elements [i + 1]);
  71453. transform.transformPoint (data.elements [i + 2],
  71454. data.elements [i + 3]);
  71455. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71456. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71457. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71458. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71459. i += 4;
  71460. }
  71461. else if (type == cubicMarker)
  71462. {
  71463. transform.transformPoint (data.elements [i],
  71464. data.elements [i + 1]);
  71465. transform.transformPoint (data.elements [i + 2],
  71466. data.elements [i + 3]);
  71467. transform.transformPoint (data.elements [i + 4],
  71468. data.elements [i + 5]);
  71469. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71470. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71471. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71472. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71473. i += 6;
  71474. }
  71475. }
  71476. }
  71477. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71478. const float w, const float h,
  71479. const bool preserveProportions,
  71480. const Justification& justification) const
  71481. {
  71482. Rectangle<float> bounds (getBounds());
  71483. if (preserveProportions)
  71484. {
  71485. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71486. return AffineTransform::identity;
  71487. float newW, newH;
  71488. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71489. if (srcRatio > h / w)
  71490. {
  71491. newW = h / srcRatio;
  71492. newH = h;
  71493. }
  71494. else
  71495. {
  71496. newW = w;
  71497. newH = w * srcRatio;
  71498. }
  71499. float newXCentre = x;
  71500. float newYCentre = y;
  71501. if (justification.testFlags (Justification::left))
  71502. newXCentre += newW * 0.5f;
  71503. else if (justification.testFlags (Justification::right))
  71504. newXCentre += w - newW * 0.5f;
  71505. else
  71506. newXCentre += w * 0.5f;
  71507. if (justification.testFlags (Justification::top))
  71508. newYCentre += newH * 0.5f;
  71509. else if (justification.testFlags (Justification::bottom))
  71510. newYCentre += h - newH * 0.5f;
  71511. else
  71512. newYCentre += h * 0.5f;
  71513. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71514. bounds.getHeight() * -0.5f - bounds.getY())
  71515. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71516. .translated (newXCentre, newYCentre);
  71517. }
  71518. else
  71519. {
  71520. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  71521. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  71522. .translated (x, y);
  71523. }
  71524. }
  71525. bool Path::contains (const float x, const float y, const float tolerence) const
  71526. {
  71527. if (x <= pathXMin || x >= pathXMax
  71528. || y <= pathYMin || y >= pathYMax)
  71529. return false;
  71530. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71531. int positiveCrossings = 0;
  71532. int negativeCrossings = 0;
  71533. while (i.next())
  71534. {
  71535. if ((i.y1 <= y && i.y2 > y)
  71536. || (i.y2 <= y && i.y1 > y))
  71537. {
  71538. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  71539. if (intersectX <= x)
  71540. {
  71541. if (i.y1 < i.y2)
  71542. ++positiveCrossings;
  71543. else
  71544. ++negativeCrossings;
  71545. }
  71546. }
  71547. }
  71548. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  71549. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  71550. }
  71551. bool Path::intersectsLine (const float x1, const float y1,
  71552. const float x2, const float y2,
  71553. const float tolerence)
  71554. {
  71555. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71556. const Line line1 (x1, y1, x2, y2);
  71557. while (i.next())
  71558. {
  71559. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  71560. float ix, iy;
  71561. if (line1.intersects (line2, ix, iy))
  71562. return true;
  71563. }
  71564. return false;
  71565. }
  71566. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const
  71567. {
  71568. if (cornerRadius <= 0.01f)
  71569. return *this;
  71570. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  71571. size_t n = 0;
  71572. bool lastWasLine = false, firstWasLine = false;
  71573. Path p;
  71574. while (n < numElements)
  71575. {
  71576. const float type = data.elements [n++];
  71577. if (type == moveMarker)
  71578. {
  71579. indexOfPathStart = p.numElements;
  71580. indexOfPathStartThis = n - 1;
  71581. const float x = data.elements [n++];
  71582. const float y = data.elements [n++];
  71583. p.startNewSubPath (x, y);
  71584. lastWasLine = false;
  71585. firstWasLine = (data.elements [n] == lineMarker);
  71586. }
  71587. else if (type == lineMarker || type == closeSubPathMarker)
  71588. {
  71589. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  71590. if (type == lineMarker)
  71591. {
  71592. endX = data.elements [n++];
  71593. endY = data.elements [n++];
  71594. if (n > 8)
  71595. {
  71596. startX = data.elements [n - 8];
  71597. startY = data.elements [n - 7];
  71598. joinX = data.elements [n - 5];
  71599. joinY = data.elements [n - 4];
  71600. }
  71601. }
  71602. else
  71603. {
  71604. endX = data.elements [indexOfPathStartThis + 1];
  71605. endY = data.elements [indexOfPathStartThis + 2];
  71606. if (n > 6)
  71607. {
  71608. startX = data.elements [n - 6];
  71609. startY = data.elements [n - 5];
  71610. joinX = data.elements [n - 3];
  71611. joinY = data.elements [n - 2];
  71612. }
  71613. }
  71614. if (lastWasLine)
  71615. {
  71616. const double len1 = juce_hypot (startX - joinX,
  71617. startY - joinY);
  71618. if (len1 > 0)
  71619. {
  71620. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71621. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71622. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71623. }
  71624. const double len2 = juce_hypot (endX - joinX,
  71625. endY - joinY);
  71626. if (len2 > 0)
  71627. {
  71628. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71629. p.quadraticTo (joinX, joinY,
  71630. (float) (joinX + (endX - joinX) * propNeeded),
  71631. (float) (joinY + (endY - joinY) * propNeeded));
  71632. }
  71633. p.lineTo (endX, endY);
  71634. }
  71635. else if (type == lineMarker)
  71636. {
  71637. p.lineTo (endX, endY);
  71638. lastWasLine = true;
  71639. }
  71640. if (type == closeSubPathMarker)
  71641. {
  71642. if (firstWasLine)
  71643. {
  71644. startX = data.elements [n - 3];
  71645. startY = data.elements [n - 2];
  71646. joinX = endX;
  71647. joinY = endY;
  71648. endX = data.elements [indexOfPathStartThis + 4];
  71649. endY = data.elements [indexOfPathStartThis + 5];
  71650. const double len1 = juce_hypot (startX - joinX,
  71651. startY - joinY);
  71652. if (len1 > 0)
  71653. {
  71654. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71655. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71656. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71657. }
  71658. const double len2 = juce_hypot (endX - joinX,
  71659. endY - joinY);
  71660. if (len2 > 0)
  71661. {
  71662. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71663. endX = (float) (joinX + (endX - joinX) * propNeeded);
  71664. endY = (float) (joinY + (endY - joinY) * propNeeded);
  71665. p.quadraticTo (joinX, joinY, endX, endY);
  71666. p.data.elements [indexOfPathStart + 1] = endX;
  71667. p.data.elements [indexOfPathStart + 2] = endY;
  71668. }
  71669. }
  71670. p.closeSubPath();
  71671. }
  71672. }
  71673. else if (type == quadMarker)
  71674. {
  71675. lastWasLine = false;
  71676. const float x1 = data.elements [n++];
  71677. const float y1 = data.elements [n++];
  71678. const float x2 = data.elements [n++];
  71679. const float y2 = data.elements [n++];
  71680. p.quadraticTo (x1, y1, x2, y2);
  71681. }
  71682. else if (type == cubicMarker)
  71683. {
  71684. lastWasLine = false;
  71685. const float x1 = data.elements [n++];
  71686. const float y1 = data.elements [n++];
  71687. const float x2 = data.elements [n++];
  71688. const float y2 = data.elements [n++];
  71689. const float x3 = data.elements [n++];
  71690. const float y3 = data.elements [n++];
  71691. p.cubicTo (x1, y1, x2, y2, x3, y3);
  71692. }
  71693. }
  71694. return p;
  71695. }
  71696. void Path::loadPathFromStream (InputStream& source)
  71697. {
  71698. while (! source.isExhausted())
  71699. {
  71700. switch (source.readByte())
  71701. {
  71702. case 'm':
  71703. {
  71704. const float x = source.readFloat();
  71705. const float y = source.readFloat();
  71706. startNewSubPath (x, y);
  71707. break;
  71708. }
  71709. case 'l':
  71710. {
  71711. const float x = source.readFloat();
  71712. const float y = source.readFloat();
  71713. lineTo (x, y);
  71714. break;
  71715. }
  71716. case 'q':
  71717. {
  71718. const float x1 = source.readFloat();
  71719. const float y1 = source.readFloat();
  71720. const float x2 = source.readFloat();
  71721. const float y2 = source.readFloat();
  71722. quadraticTo (x1, y1, x2, y2);
  71723. break;
  71724. }
  71725. case 'b':
  71726. {
  71727. const float x1 = source.readFloat();
  71728. const float y1 = source.readFloat();
  71729. const float x2 = source.readFloat();
  71730. const float y2 = source.readFloat();
  71731. const float x3 = source.readFloat();
  71732. const float y3 = source.readFloat();
  71733. cubicTo (x1, y1, x2, y2, x3, y3);
  71734. break;
  71735. }
  71736. case 'c':
  71737. closeSubPath();
  71738. break;
  71739. case 'n':
  71740. useNonZeroWinding = true;
  71741. break;
  71742. case 'z':
  71743. useNonZeroWinding = false;
  71744. break;
  71745. case 'e':
  71746. return; // end of path marker
  71747. default:
  71748. jassertfalse // illegal char in the stream
  71749. break;
  71750. }
  71751. }
  71752. }
  71753. void Path::loadPathFromData (const void* const data, const int numberOfBytes)
  71754. {
  71755. MemoryInputStream in (data, numberOfBytes, false);
  71756. loadPathFromStream (in);
  71757. }
  71758. void Path::writePathToStream (OutputStream& dest) const
  71759. {
  71760. dest.writeByte (useNonZeroWinding ? 'n' : 'z');
  71761. size_t i = 0;
  71762. while (i < numElements)
  71763. {
  71764. const float type = data.elements [i++];
  71765. if (type == moveMarker)
  71766. {
  71767. dest.writeByte ('m');
  71768. dest.writeFloat (data.elements [i++]);
  71769. dest.writeFloat (data.elements [i++]);
  71770. }
  71771. else if (type == lineMarker)
  71772. {
  71773. dest.writeByte ('l');
  71774. dest.writeFloat (data.elements [i++]);
  71775. dest.writeFloat (data.elements [i++]);
  71776. }
  71777. else if (type == quadMarker)
  71778. {
  71779. dest.writeByte ('q');
  71780. dest.writeFloat (data.elements [i++]);
  71781. dest.writeFloat (data.elements [i++]);
  71782. dest.writeFloat (data.elements [i++]);
  71783. dest.writeFloat (data.elements [i++]);
  71784. }
  71785. else if (type == cubicMarker)
  71786. {
  71787. dest.writeByte ('b');
  71788. dest.writeFloat (data.elements [i++]);
  71789. dest.writeFloat (data.elements [i++]);
  71790. dest.writeFloat (data.elements [i++]);
  71791. dest.writeFloat (data.elements [i++]);
  71792. dest.writeFloat (data.elements [i++]);
  71793. dest.writeFloat (data.elements [i++]);
  71794. }
  71795. else if (type == closeSubPathMarker)
  71796. {
  71797. dest.writeByte ('c');
  71798. }
  71799. }
  71800. dest.writeByte ('e'); // marks the end-of-path
  71801. }
  71802. const String Path::toString() const
  71803. {
  71804. MemoryOutputStream s (2048, 2048);
  71805. if (! useNonZeroWinding)
  71806. s << "a ";
  71807. size_t i = 0;
  71808. float lastMarker = 0.0f;
  71809. while (i < numElements)
  71810. {
  71811. const float marker = data.elements [i++];
  71812. char markerChar = 0;
  71813. int numCoords = 0;
  71814. if (marker == moveMarker)
  71815. {
  71816. markerChar = 'm';
  71817. numCoords = 2;
  71818. }
  71819. else if (marker == lineMarker)
  71820. {
  71821. markerChar = 'l';
  71822. numCoords = 2;
  71823. }
  71824. else if (marker == quadMarker)
  71825. {
  71826. markerChar = 'q';
  71827. numCoords = 4;
  71828. }
  71829. else if (marker == cubicMarker)
  71830. {
  71831. markerChar = 'c';
  71832. numCoords = 6;
  71833. }
  71834. else
  71835. {
  71836. jassert (marker == closeSubPathMarker);
  71837. markerChar = 'z';
  71838. }
  71839. if (marker != lastMarker)
  71840. {
  71841. s << markerChar << ' ';
  71842. lastMarker = marker;
  71843. }
  71844. while (--numCoords >= 0 && i < numElements)
  71845. {
  71846. String n (data.elements [i++], 3);
  71847. if (n.endsWithChar (T('0')))
  71848. {
  71849. do
  71850. {
  71851. n = n.dropLastCharacters (1);
  71852. } while (n.endsWithChar (T('0')));
  71853. if (n.endsWithChar (T('.')))
  71854. n = n.dropLastCharacters (1);
  71855. }
  71856. s << n << ' ';
  71857. }
  71858. }
  71859. const char* const result = (const char*) s.getData();
  71860. size_t len = s.getDataSize();
  71861. while (len > 0 && CharacterFunctions::isWhitespace (result [len - 1]))
  71862. --len;
  71863. return String (result, len);
  71864. }
  71865. void Path::restoreFromString (const String& stringVersion)
  71866. {
  71867. clear();
  71868. setUsingNonZeroWinding (true);
  71869. const tchar* t = stringVersion;
  71870. tchar marker = T('m');
  71871. int numValues = 2;
  71872. float values [6];
  71873. while (*t != 0)
  71874. {
  71875. const String token (PathHelpers::nextToken (t));
  71876. const tchar firstChar = token[0];
  71877. int startNum = 0;
  71878. if (firstChar == T('m') || firstChar == T('l'))
  71879. {
  71880. marker = firstChar;
  71881. numValues = 2;
  71882. }
  71883. else if (firstChar == T('q'))
  71884. {
  71885. marker = firstChar;
  71886. numValues = 4;
  71887. }
  71888. else if (firstChar == T('c'))
  71889. {
  71890. marker = firstChar;
  71891. numValues = 6;
  71892. }
  71893. else if (firstChar == T('z'))
  71894. {
  71895. marker = firstChar;
  71896. numValues = 0;
  71897. }
  71898. else if (firstChar == T('a'))
  71899. {
  71900. setUsingNonZeroWinding (false);
  71901. continue;
  71902. }
  71903. else
  71904. {
  71905. ++startNum;
  71906. values [0] = token.getFloatValue();
  71907. }
  71908. for (int i = startNum; i < numValues; ++i)
  71909. values [i] = PathHelpers::nextToken (t).getFloatValue();
  71910. switch (marker)
  71911. {
  71912. case T('m'):
  71913. startNewSubPath (values[0], values[1]);
  71914. break;
  71915. case T('l'):
  71916. lineTo (values[0], values[1]);
  71917. break;
  71918. case T('q'):
  71919. quadraticTo (values[0], values[1],
  71920. values[2], values[3]);
  71921. break;
  71922. case T('c'):
  71923. cubicTo (values[0], values[1],
  71924. values[2], values[3],
  71925. values[4], values[5]);
  71926. break;
  71927. case T('z'):
  71928. closeSubPath();
  71929. break;
  71930. default:
  71931. jassertfalse // illegal string format?
  71932. break;
  71933. }
  71934. }
  71935. }
  71936. Path::Iterator::Iterator (const Path& path_)
  71937. : path (path_),
  71938. index (0)
  71939. {
  71940. }
  71941. Path::Iterator::~Iterator()
  71942. {
  71943. }
  71944. bool Path::Iterator::next()
  71945. {
  71946. const float* const elements = path.data.elements;
  71947. if (index < path.numElements)
  71948. {
  71949. const float type = elements [index++];
  71950. if (type == moveMarker)
  71951. {
  71952. elementType = startNewSubPath;
  71953. x1 = elements [index++];
  71954. y1 = elements [index++];
  71955. }
  71956. else if (type == lineMarker)
  71957. {
  71958. elementType = lineTo;
  71959. x1 = elements [index++];
  71960. y1 = elements [index++];
  71961. }
  71962. else if (type == quadMarker)
  71963. {
  71964. elementType = quadraticTo;
  71965. x1 = elements [index++];
  71966. y1 = elements [index++];
  71967. x2 = elements [index++];
  71968. y2 = elements [index++];
  71969. }
  71970. else if (type == cubicMarker)
  71971. {
  71972. elementType = cubicTo;
  71973. x1 = elements [index++];
  71974. y1 = elements [index++];
  71975. x2 = elements [index++];
  71976. y2 = elements [index++];
  71977. x3 = elements [index++];
  71978. y3 = elements [index++];
  71979. }
  71980. else if (type == closeSubPathMarker)
  71981. {
  71982. elementType = closePath;
  71983. }
  71984. return true;
  71985. }
  71986. return false;
  71987. }
  71988. END_JUCE_NAMESPACE
  71989. /*** End of inlined file: juce_Path.cpp ***/
  71990. /*** Start of inlined file: juce_PathIterator.cpp ***/
  71991. BEGIN_JUCE_NAMESPACE
  71992. #if JUCE_MSVC
  71993. #pragma optimize ("t", on)
  71994. #endif
  71995. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  71996. const AffineTransform& transform_,
  71997. float tolerence_)
  71998. : x2 (0),
  71999. y2 (0),
  72000. closesSubPath (false),
  72001. subPathIndex (-1),
  72002. path (path_),
  72003. transform (transform_),
  72004. points (path_.data.elements),
  72005. tolerence (tolerence_ * tolerence_),
  72006. subPathCloseX (0),
  72007. subPathCloseY (0),
  72008. isIdentityTransform (transform_.isIdentity()),
  72009. stackBase (32),
  72010. index (0),
  72011. stackSize (32)
  72012. {
  72013. stackPos = stackBase;
  72014. }
  72015. PathFlatteningIterator::~PathFlatteningIterator()
  72016. {
  72017. }
  72018. bool PathFlatteningIterator::next()
  72019. {
  72020. x1 = x2;
  72021. y1 = y2;
  72022. float x3 = 0;
  72023. float y3 = 0;
  72024. float x4 = 0;
  72025. float y4 = 0;
  72026. float type;
  72027. for (;;)
  72028. {
  72029. if (stackPos == stackBase)
  72030. {
  72031. if (index >= path.numElements)
  72032. {
  72033. return false;
  72034. }
  72035. else
  72036. {
  72037. type = points [index++];
  72038. if (type != Path::closeSubPathMarker)
  72039. {
  72040. x2 = points [index++];
  72041. y2 = points [index++];
  72042. if (! isIdentityTransform)
  72043. transform.transformPoint (x2, y2);
  72044. if (type == Path::quadMarker)
  72045. {
  72046. x3 = points [index++];
  72047. y3 = points [index++];
  72048. if (! isIdentityTransform)
  72049. transform.transformPoint (x3, y3);
  72050. }
  72051. else if (type == Path::cubicMarker)
  72052. {
  72053. x3 = points [index++];
  72054. y3 = points [index++];
  72055. x4 = points [index++];
  72056. y4 = points [index++];
  72057. if (! isIdentityTransform)
  72058. {
  72059. transform.transformPoint (x3, y3);
  72060. transform.transformPoint (x4, y4);
  72061. }
  72062. }
  72063. }
  72064. }
  72065. }
  72066. else
  72067. {
  72068. type = *--stackPos;
  72069. if (type != Path::closeSubPathMarker)
  72070. {
  72071. x2 = *--stackPos;
  72072. y2 = *--stackPos;
  72073. if (type == Path::quadMarker)
  72074. {
  72075. x3 = *--stackPos;
  72076. y3 = *--stackPos;
  72077. }
  72078. else if (type == Path::cubicMarker)
  72079. {
  72080. x3 = *--stackPos;
  72081. y3 = *--stackPos;
  72082. x4 = *--stackPos;
  72083. y4 = *--stackPos;
  72084. }
  72085. }
  72086. }
  72087. if (type == Path::lineMarker)
  72088. {
  72089. ++subPathIndex;
  72090. closesSubPath = (stackPos == stackBase)
  72091. && (index < path.numElements)
  72092. && (points [index] == Path::closeSubPathMarker)
  72093. && x2 == subPathCloseX
  72094. && y2 == subPathCloseY;
  72095. return true;
  72096. }
  72097. else if (type == Path::quadMarker)
  72098. {
  72099. const size_t offset = (size_t) (stackPos - stackBase);
  72100. if (offset >= stackSize - 10)
  72101. {
  72102. stackSize <<= 1;
  72103. stackBase.realloc (stackSize);
  72104. stackPos = stackBase + offset;
  72105. }
  72106. const float dx1 = x1 - x2;
  72107. const float dy1 = y1 - y2;
  72108. const float dx2 = x2 - x3;
  72109. const float dy2 = y2 - y3;
  72110. const float m1x = (x1 + x2) * 0.5f;
  72111. const float m1y = (y1 + y2) * 0.5f;
  72112. const float m2x = (x2 + x3) * 0.5f;
  72113. const float m2y = (y2 + y3) * 0.5f;
  72114. const float m3x = (m1x + m2x) * 0.5f;
  72115. const float m3y = (m1y + m2y) * 0.5f;
  72116. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72117. {
  72118. *stackPos++ = y3;
  72119. *stackPos++ = x3;
  72120. *stackPos++ = m2y;
  72121. *stackPos++ = m2x;
  72122. *stackPos++ = Path::quadMarker;
  72123. *stackPos++ = m3y;
  72124. *stackPos++ = m3x;
  72125. *stackPos++ = m1y;
  72126. *stackPos++ = m1x;
  72127. *stackPos++ = Path::quadMarker;
  72128. }
  72129. else
  72130. {
  72131. *stackPos++ = y3;
  72132. *stackPos++ = x3;
  72133. *stackPos++ = Path::lineMarker;
  72134. *stackPos++ = m3y;
  72135. *stackPos++ = m3x;
  72136. *stackPos++ = Path::lineMarker;
  72137. }
  72138. jassert (stackPos < stackBase + stackSize);
  72139. }
  72140. else if (type == Path::cubicMarker)
  72141. {
  72142. const size_t offset = (size_t) (stackPos - stackBase);
  72143. if (offset >= stackSize - 16)
  72144. {
  72145. stackSize <<= 1;
  72146. stackBase.realloc (stackSize);
  72147. stackPos = stackBase + offset;
  72148. }
  72149. const float dx1 = x1 - x2;
  72150. const float dy1 = y1 - y2;
  72151. const float dx2 = x2 - x3;
  72152. const float dy2 = y2 - y3;
  72153. const float dx3 = x3 - x4;
  72154. const float dy3 = y3 - y4;
  72155. const float m1x = (x1 + x2) * 0.5f;
  72156. const float m1y = (y1 + y2) * 0.5f;
  72157. const float m2x = (x3 + x2) * 0.5f;
  72158. const float m2y = (y3 + y2) * 0.5f;
  72159. const float m3x = (x3 + x4) * 0.5f;
  72160. const float m3y = (y3 + y4) * 0.5f;
  72161. const float m4x = (m1x + m2x) * 0.5f;
  72162. const float m4y = (m1y + m2y) * 0.5f;
  72163. const float m5x = (m3x + m2x) * 0.5f;
  72164. const float m5y = (m3y + m2y) * 0.5f;
  72165. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72166. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72167. {
  72168. *stackPos++ = y4;
  72169. *stackPos++ = x4;
  72170. *stackPos++ = m3y;
  72171. *stackPos++ = m3x;
  72172. *stackPos++ = m5y;
  72173. *stackPos++ = m5x;
  72174. *stackPos++ = Path::cubicMarker;
  72175. *stackPos++ = (m4y + m5y) * 0.5f;
  72176. *stackPos++ = (m4x + m5x) * 0.5f;
  72177. *stackPos++ = m4y;
  72178. *stackPos++ = m4x;
  72179. *stackPos++ = m1y;
  72180. *stackPos++ = m1x;
  72181. *stackPos++ = Path::cubicMarker;
  72182. }
  72183. else
  72184. {
  72185. *stackPos++ = y4;
  72186. *stackPos++ = x4;
  72187. *stackPos++ = Path::lineMarker;
  72188. *stackPos++ = m5y;
  72189. *stackPos++ = m5x;
  72190. *stackPos++ = Path::lineMarker;
  72191. *stackPos++ = m4y;
  72192. *stackPos++ = m4x;
  72193. *stackPos++ = Path::lineMarker;
  72194. }
  72195. }
  72196. else if (type == Path::closeSubPathMarker)
  72197. {
  72198. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72199. {
  72200. x1 = x2;
  72201. y1 = y2;
  72202. x2 = subPathCloseX;
  72203. y2 = subPathCloseY;
  72204. closesSubPath = true;
  72205. return true;
  72206. }
  72207. }
  72208. else
  72209. {
  72210. jassert (type == Path::moveMarker);
  72211. subPathIndex = -1;
  72212. subPathCloseX = x1 = x2;
  72213. subPathCloseY = y1 = y2;
  72214. }
  72215. }
  72216. }
  72217. END_JUCE_NAMESPACE
  72218. /*** End of inlined file: juce_PathIterator.cpp ***/
  72219. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72220. BEGIN_JUCE_NAMESPACE
  72221. PathStrokeType::PathStrokeType (const float strokeThickness,
  72222. const JointStyle jointStyle_,
  72223. const EndCapStyle endStyle_) throw()
  72224. : thickness (strokeThickness),
  72225. jointStyle (jointStyle_),
  72226. endStyle (endStyle_)
  72227. {
  72228. }
  72229. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72230. : thickness (other.thickness),
  72231. jointStyle (other.jointStyle),
  72232. endStyle (other.endStyle)
  72233. {
  72234. }
  72235. PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72236. {
  72237. thickness = other.thickness;
  72238. jointStyle = other.jointStyle;
  72239. endStyle = other.endStyle;
  72240. return *this;
  72241. }
  72242. PathStrokeType::~PathStrokeType() throw()
  72243. {
  72244. }
  72245. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72246. {
  72247. return thickness == other.thickness
  72248. && jointStyle == other.jointStyle
  72249. && endStyle == other.endStyle;
  72250. }
  72251. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72252. {
  72253. return ! operator== (other);
  72254. }
  72255. static bool lineIntersection (const float x1, const float y1,
  72256. const float x2, const float y2,
  72257. const float x3, const float y3,
  72258. const float x4, const float y4,
  72259. float& intersectionX,
  72260. float& intersectionY,
  72261. float& distanceBeyondLine1EndSquared) throw()
  72262. {
  72263. if (x2 != x3 || y2 != y3)
  72264. {
  72265. const float dx1 = x2 - x1;
  72266. const float dy1 = y2 - y1;
  72267. const float dx2 = x4 - x3;
  72268. const float dy2 = y4 - y3;
  72269. const float divisor = dx1 * dy2 - dx2 * dy1;
  72270. if (divisor == 0)
  72271. {
  72272. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72273. {
  72274. if (dy1 == 0 && dy2 != 0)
  72275. {
  72276. const float along = (y1 - y3) / dy2;
  72277. intersectionX = x3 + along * dx2;
  72278. intersectionY = y1;
  72279. distanceBeyondLine1EndSquared = intersectionX - x2;
  72280. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72281. if ((x2 > x1) == (intersectionX < x2))
  72282. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72283. return along >= 0 && along <= 1.0f;
  72284. }
  72285. else if (dy2 == 0 && dy1 != 0)
  72286. {
  72287. const float along = (y3 - y1) / dy1;
  72288. intersectionX = x1 + along * dx1;
  72289. intersectionY = y3;
  72290. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72291. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72292. if (along < 1.0f)
  72293. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72294. return along >= 0 && along <= 1.0f;
  72295. }
  72296. else if (dx1 == 0 && dx2 != 0)
  72297. {
  72298. const float along = (x1 - x3) / dx2;
  72299. intersectionX = x1;
  72300. intersectionY = y3 + along * dy2;
  72301. distanceBeyondLine1EndSquared = intersectionY - y2;
  72302. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72303. if ((y2 > y1) == (intersectionY < y2))
  72304. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72305. return along >= 0 && along <= 1.0f;
  72306. }
  72307. else if (dx2 == 0 && dx1 != 0)
  72308. {
  72309. const float along = (x3 - x1) / dx1;
  72310. intersectionX = x3;
  72311. intersectionY = y1 + along * dy1;
  72312. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72313. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72314. if (along < 1.0f)
  72315. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72316. return along >= 0 && along <= 1.0f;
  72317. }
  72318. }
  72319. intersectionX = 0.5f * (x2 + x3);
  72320. intersectionY = 0.5f * (y2 + y3);
  72321. distanceBeyondLine1EndSquared = 0.0f;
  72322. return false;
  72323. }
  72324. else
  72325. {
  72326. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72327. intersectionX = x1 + along1 * dx1;
  72328. intersectionY = y1 + along1 * dy1;
  72329. if (along1 >= 0 && along1 <= 1.0f)
  72330. {
  72331. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72332. if (along2 >= 0 && along2 <= divisor)
  72333. {
  72334. distanceBeyondLine1EndSquared = 0.0f;
  72335. return true;
  72336. }
  72337. }
  72338. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72339. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72340. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72341. if (along1 < 1.0f)
  72342. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72343. return false;
  72344. }
  72345. }
  72346. intersectionX = x2;
  72347. intersectionY = y2;
  72348. distanceBeyondLine1EndSquared = 0.0f;
  72349. return true;
  72350. }
  72351. namespace PathFunctions
  72352. {
  72353. // part of stroke drawing stuff
  72354. static void addEdgeAndJoint (Path& destPath,
  72355. const PathStrokeType::JointStyle style,
  72356. const float maxMiterExtensionSquared, const float width,
  72357. const float x1, const float y1,
  72358. const float x2, const float y2,
  72359. const float x3, const float y3,
  72360. const float x4, const float y4,
  72361. const float midX, const float midY)
  72362. {
  72363. if (style == PathStrokeType::beveled
  72364. || (x3 == x4 && y3 == y4)
  72365. || (x1 == x2 && y1 == y2))
  72366. {
  72367. destPath.lineTo (x2, y2);
  72368. destPath.lineTo (x3, y3);
  72369. }
  72370. else
  72371. {
  72372. float jx, jy, distanceBeyondLine1EndSquared;
  72373. // if they intersect, use this point..
  72374. if (lineIntersection (x1, y1, x2, y2,
  72375. x3, y3, x4, y4,
  72376. jx, jy, distanceBeyondLine1EndSquared))
  72377. {
  72378. destPath.lineTo (jx, jy);
  72379. }
  72380. else
  72381. {
  72382. if (style == PathStrokeType::mitered)
  72383. {
  72384. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72385. && distanceBeyondLine1EndSquared > 0.0f)
  72386. {
  72387. destPath.lineTo (jx, jy);
  72388. }
  72389. else
  72390. {
  72391. // the end sticks out too far, so just use a blunt joint
  72392. destPath.lineTo (x2, y2);
  72393. destPath.lineTo (x3, y3);
  72394. }
  72395. }
  72396. else
  72397. {
  72398. // curved joints
  72399. float angle1 = atan2f (x2 - midX, y2 - midY);
  72400. float angle2 = atan2f (x3 - midX, y3 - midY);
  72401. const float angleIncrement = 0.1f;
  72402. destPath.lineTo (x2, y2);
  72403. if (fabs (angle1 - angle2) > angleIncrement)
  72404. {
  72405. if (angle2 > angle1 + float_Pi
  72406. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72407. {
  72408. if (angle2 > angle1)
  72409. angle2 -= float_Pi * 2.0f;
  72410. jassert (angle1 <= angle2 + float_Pi);
  72411. angle1 -= angleIncrement;
  72412. while (angle1 > angle2)
  72413. {
  72414. destPath.lineTo (midX + width * sinf (angle1),
  72415. midY + width * cosf (angle1));
  72416. angle1 -= angleIncrement;
  72417. }
  72418. }
  72419. else
  72420. {
  72421. if (angle1 > angle2)
  72422. angle1 -= float_Pi * 2.0f;
  72423. jassert (angle1 >= angle2 - float_Pi);
  72424. angle1 += angleIncrement;
  72425. while (angle1 < angle2)
  72426. {
  72427. destPath.lineTo (midX + width * sinf (angle1),
  72428. midY + width * cosf (angle1));
  72429. angle1 += angleIncrement;
  72430. }
  72431. }
  72432. }
  72433. destPath.lineTo (x3, y3);
  72434. }
  72435. }
  72436. }
  72437. }
  72438. static void addLineEnd (Path& destPath,
  72439. const PathStrokeType::EndCapStyle style,
  72440. const float x1, const float y1,
  72441. const float x2, const float y2,
  72442. const float width)
  72443. {
  72444. if (style == PathStrokeType::butt)
  72445. {
  72446. destPath.lineTo (x2, y2);
  72447. }
  72448. else
  72449. {
  72450. float offx1, offy1, offx2, offy2;
  72451. float dx = x2 - x1;
  72452. float dy = y2 - y1;
  72453. const float len = juce_hypotf (dx, dy);
  72454. if (len == 0)
  72455. {
  72456. offx1 = offx2 = x1;
  72457. offy1 = offy2 = y1;
  72458. }
  72459. else
  72460. {
  72461. const float offset = width / len;
  72462. dx *= offset;
  72463. dy *= offset;
  72464. offx1 = x1 + dy;
  72465. offy1 = y1 - dx;
  72466. offx2 = x2 + dy;
  72467. offy2 = y2 - dx;
  72468. }
  72469. if (style == PathStrokeType::square)
  72470. {
  72471. // sqaure ends
  72472. destPath.lineTo (offx1, offy1);
  72473. destPath.lineTo (offx2, offy2);
  72474. destPath.lineTo (x2, y2);
  72475. }
  72476. else
  72477. {
  72478. // rounded ends
  72479. const float midx = (offx1 + offx2) * 0.5f;
  72480. const float midy = (offy1 + offy2) * 0.5f;
  72481. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72482. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72483. midx, midy);
  72484. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72485. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72486. x2, y2);
  72487. }
  72488. }
  72489. }
  72490. struct LineSection
  72491. {
  72492. LineSection() {}
  72493. LineSection (int) {}
  72494. float x1, y1, x2, y2; // original line
  72495. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72496. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72497. };
  72498. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72499. const bool isClosed,
  72500. const float width, const float maxMiterExtensionSquared,
  72501. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle)
  72502. {
  72503. jassert (subPath.size() > 0);
  72504. const LineSection& firstLine = subPath.getReference (0);
  72505. float lastX1 = firstLine.lx1;
  72506. float lastY1 = firstLine.ly1;
  72507. float lastX2 = firstLine.lx2;
  72508. float lastY2 = firstLine.ly2;
  72509. if (isClosed)
  72510. {
  72511. destPath.startNewSubPath (lastX1, lastY1);
  72512. }
  72513. else
  72514. {
  72515. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  72516. addLineEnd (destPath, endStyle,
  72517. firstLine.rx2, firstLine.ry2,
  72518. lastX1, lastY1,
  72519. width);
  72520. }
  72521. int i;
  72522. for (i = 1; i < subPath.size(); ++i)
  72523. {
  72524. const LineSection& l = subPath.getReference (i);
  72525. addEdgeAndJoint (destPath, jointStyle,
  72526. maxMiterExtensionSquared, width,
  72527. lastX1, lastY1, lastX2, lastY2,
  72528. l.lx1, l.ly1, l.lx2, l.ly2,
  72529. l.x1, l.y1);
  72530. lastX1 = l.lx1;
  72531. lastY1 = l.ly1;
  72532. lastX2 = l.lx2;
  72533. lastY2 = l.ly2;
  72534. }
  72535. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  72536. if (isClosed)
  72537. {
  72538. const LineSection& l = subPath.getReference (0);
  72539. addEdgeAndJoint (destPath, jointStyle,
  72540. maxMiterExtensionSquared, width,
  72541. lastX1, lastY1, lastX2, lastY2,
  72542. l.lx1, l.ly1, l.lx2, l.ly2,
  72543. l.x1, l.y1);
  72544. destPath.closeSubPath();
  72545. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  72546. }
  72547. else
  72548. {
  72549. destPath.lineTo (lastX2, lastY2);
  72550. addLineEnd (destPath, endStyle,
  72551. lastX2, lastY2,
  72552. lastLine.rx1, lastLine.ry1,
  72553. width);
  72554. }
  72555. lastX1 = lastLine.rx1;
  72556. lastY1 = lastLine.ry1;
  72557. lastX2 = lastLine.rx2;
  72558. lastY2 = lastLine.ry2;
  72559. for (i = subPath.size() - 1; --i >= 0;)
  72560. {
  72561. const LineSection& l = subPath.getReference (i);
  72562. addEdgeAndJoint (destPath, jointStyle,
  72563. maxMiterExtensionSquared, width,
  72564. lastX1, lastY1, lastX2, lastY2,
  72565. l.rx1, l.ry1, l.rx2, l.ry2,
  72566. l.x2, l.y2);
  72567. lastX1 = l.rx1;
  72568. lastY1 = l.ry1;
  72569. lastX2 = l.rx2;
  72570. lastY2 = l.ry2;
  72571. }
  72572. if (isClosed)
  72573. {
  72574. addEdgeAndJoint (destPath, jointStyle,
  72575. maxMiterExtensionSquared, width,
  72576. lastX1, lastY1, lastX2, lastY2,
  72577. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  72578. lastLine.x2, lastLine.y2);
  72579. }
  72580. else
  72581. {
  72582. // do the last line
  72583. destPath.lineTo (lastX2, lastY2);
  72584. }
  72585. destPath.closeSubPath();
  72586. }
  72587. }
  72588. void PathStrokeType::createStrokedPath (Path& destPath,
  72589. const Path& source,
  72590. const AffineTransform& transform,
  72591. const float extraAccuracy) const
  72592. {
  72593. if (thickness <= 0)
  72594. {
  72595. destPath.clear();
  72596. return;
  72597. }
  72598. const Path* sourcePath = &source;
  72599. Path temp;
  72600. if (sourcePath == &destPath)
  72601. {
  72602. destPath.swapWithPath (temp);
  72603. sourcePath = &temp;
  72604. }
  72605. else
  72606. {
  72607. destPath.clear();
  72608. }
  72609. destPath.setUsingNonZeroWinding (true);
  72610. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  72611. const float width = 0.5f * thickness;
  72612. // Iterate the path, creating a list of the
  72613. // left/right-hand lines along either side of it...
  72614. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  72615. using namespace PathFunctions;
  72616. Array <LineSection> subPath;
  72617. LineSection l;
  72618. l.x1 = 0;
  72619. l.y1 = 0;
  72620. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  72621. while (it.next())
  72622. {
  72623. if (it.subPathIndex == 0)
  72624. {
  72625. if (subPath.size() > 0)
  72626. {
  72627. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72628. subPath.clearQuick();
  72629. }
  72630. l.x1 = it.x1;
  72631. l.y1 = it.y1;
  72632. }
  72633. l.x2 = it.x2;
  72634. l.y2 = it.y2;
  72635. float dx = l.x2 - l.x1;
  72636. float dy = l.y2 - l.y1;
  72637. const float hypotSquared = dx*dx + dy*dy;
  72638. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  72639. {
  72640. const float len = sqrtf (hypotSquared);
  72641. if (len == 0)
  72642. {
  72643. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  72644. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  72645. }
  72646. else
  72647. {
  72648. const float offset = width / len;
  72649. dx *= offset;
  72650. dy *= offset;
  72651. l.rx2 = l.x1 - dy;
  72652. l.ry2 = l.y1 + dx;
  72653. l.lx1 = l.x1 + dy;
  72654. l.ly1 = l.y1 - dx;
  72655. l.lx2 = l.x2 + dy;
  72656. l.ly2 = l.y2 - dx;
  72657. l.rx1 = l.x2 - dy;
  72658. l.ry1 = l.y2 + dx;
  72659. }
  72660. subPath.add (l);
  72661. if (it.closesSubPath)
  72662. {
  72663. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72664. subPath.clearQuick();
  72665. }
  72666. else
  72667. {
  72668. l.x1 = it.x2;
  72669. l.y1 = it.y2;
  72670. }
  72671. }
  72672. }
  72673. if (subPath.size() > 0)
  72674. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72675. }
  72676. void PathStrokeType::createDashedStroke (Path& destPath,
  72677. const Path& sourcePath,
  72678. const float* dashLengths,
  72679. int numDashLengths,
  72680. const AffineTransform& transform,
  72681. const float extraAccuracy) const
  72682. {
  72683. if (thickness <= 0)
  72684. return;
  72685. // this should really be an even number..
  72686. jassert ((numDashLengths & 1) == 0);
  72687. Path newDestPath;
  72688. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  72689. bool first = true;
  72690. int dashNum = 0;
  72691. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  72692. float dx = 0.0f, dy = 0.0f;
  72693. for (;;)
  72694. {
  72695. const bool isSolid = ((dashNum & 1) == 0);
  72696. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  72697. jassert (dashLen > 0); // must be a positive increment!
  72698. if (dashLen <= 0)
  72699. break;
  72700. pos += dashLen;
  72701. while (pos > lineEndPos)
  72702. {
  72703. if (! it.next())
  72704. {
  72705. if (isSolid && ! first)
  72706. newDestPath.lineTo (it.x2, it.y2);
  72707. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  72708. return;
  72709. }
  72710. if (isSolid && ! first)
  72711. newDestPath.lineTo (it.x1, it.y1);
  72712. else
  72713. newDestPath.startNewSubPath (it.x1, it.y1);
  72714. dx = it.x2 - it.x1;
  72715. dy = it.y2 - it.y1;
  72716. lineLen = juce_hypotf (dx, dy);
  72717. lineEndPos += lineLen;
  72718. first = it.closesSubPath;
  72719. }
  72720. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  72721. if (isSolid)
  72722. newDestPath.lineTo (it.x1 + dx * alpha,
  72723. it.y1 + dy * alpha);
  72724. else
  72725. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  72726. it.y1 + dy * alpha);
  72727. }
  72728. }
  72729. END_JUCE_NAMESPACE
  72730. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  72731. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  72732. BEGIN_JUCE_NAMESPACE
  72733. PositionedRectangle::PositionedRectangle() throw()
  72734. : x (0.0),
  72735. y (0.0),
  72736. w (0.0),
  72737. h (0.0),
  72738. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72739. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72740. wMode (absoluteSize),
  72741. hMode (absoluteSize)
  72742. {
  72743. }
  72744. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  72745. : x (other.x),
  72746. y (other.y),
  72747. w (other.w),
  72748. h (other.h),
  72749. xMode (other.xMode),
  72750. yMode (other.yMode),
  72751. wMode (other.wMode),
  72752. hMode (other.hMode)
  72753. {
  72754. }
  72755. PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  72756. {
  72757. x = other.x;
  72758. y = other.y;
  72759. w = other.w;
  72760. h = other.h;
  72761. xMode = other.xMode;
  72762. yMode = other.yMode;
  72763. wMode = other.wMode;
  72764. hMode = other.hMode;
  72765. return *this;
  72766. }
  72767. PositionedRectangle::~PositionedRectangle() throw()
  72768. {
  72769. }
  72770. bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  72771. {
  72772. return x == other.x
  72773. && y == other.y
  72774. && w == other.w
  72775. && h == other.h
  72776. && xMode == other.xMode
  72777. && yMode == other.yMode
  72778. && wMode == other.wMode
  72779. && hMode == other.hMode;
  72780. }
  72781. bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  72782. {
  72783. return ! operator== (other);
  72784. }
  72785. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  72786. {
  72787. StringArray tokens;
  72788. tokens.addTokens (stringVersion, false);
  72789. decodePosString (tokens [0], xMode, x);
  72790. decodePosString (tokens [1], yMode, y);
  72791. decodeSizeString (tokens [2], wMode, w);
  72792. decodeSizeString (tokens [3], hMode, h);
  72793. }
  72794. const String PositionedRectangle::toString() const throw()
  72795. {
  72796. String s;
  72797. s.preallocateStorage (12);
  72798. addPosDescription (s, xMode, x);
  72799. s << T(' ');
  72800. addPosDescription (s, yMode, y);
  72801. s << T(' ');
  72802. addSizeDescription (s, wMode, w);
  72803. s << T(' ');
  72804. addSizeDescription (s, hMode, h);
  72805. return s;
  72806. }
  72807. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  72808. {
  72809. jassert (! target.isEmpty());
  72810. double x_, y_, w_, h_;
  72811. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72812. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72813. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  72814. roundToInt (w_), roundToInt (h_));
  72815. }
  72816. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  72817. double& x_, double& y_,
  72818. double& w_, double& h_) const throw()
  72819. {
  72820. jassert (! target.isEmpty());
  72821. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72822. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72823. }
  72824. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  72825. {
  72826. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  72827. }
  72828. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  72829. const Rectangle<int>& target) throw()
  72830. {
  72831. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  72832. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  72833. }
  72834. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  72835. const double newW, const double newH,
  72836. const Rectangle<int>& target) throw()
  72837. {
  72838. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  72839. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  72840. }
  72841. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  72842. {
  72843. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  72844. updateFrom (comp.getBounds(), Rectangle<int>());
  72845. else
  72846. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  72847. }
  72848. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  72849. {
  72850. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72851. }
  72852. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  72853. {
  72854. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  72855. | absoluteFromParentBottomRight
  72856. | absoluteFromParentCentre
  72857. | proportionOfParentSize));
  72858. }
  72859. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  72860. {
  72861. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72862. }
  72863. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  72864. {
  72865. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  72866. | absoluteFromParentBottomRight
  72867. | absoluteFromParentCentre
  72868. | proportionOfParentSize));
  72869. }
  72870. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  72871. {
  72872. return (SizeMode) wMode;
  72873. }
  72874. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  72875. {
  72876. return (SizeMode) hMode;
  72877. }
  72878. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  72879. const PositionMode xMode_,
  72880. const AnchorPoint yAnchor,
  72881. const PositionMode yMode_,
  72882. const SizeMode widthMode,
  72883. const SizeMode heightMode,
  72884. const Rectangle<int>& target) throw()
  72885. {
  72886. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  72887. {
  72888. double tx, tw;
  72889. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  72890. xMode = (uint8) (xAnchor | xMode_);
  72891. wMode = (uint8) widthMode;
  72892. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  72893. }
  72894. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  72895. {
  72896. double ty, th;
  72897. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  72898. yMode = (uint8) (yAnchor | yMode_);
  72899. hMode = (uint8) heightMode;
  72900. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  72901. }
  72902. }
  72903. bool PositionedRectangle::isPositionAbsolute() const throw()
  72904. {
  72905. return xMode == absoluteFromParentTopLeft
  72906. && yMode == absoluteFromParentTopLeft
  72907. && wMode == absoluteSize
  72908. && hMode == absoluteSize;
  72909. }
  72910. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  72911. {
  72912. if ((mode & proportionOfParentSize) != 0)
  72913. {
  72914. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  72915. }
  72916. else
  72917. {
  72918. s << (roundToInt (value * 100.0) / 100.0);
  72919. if ((mode & absoluteFromParentBottomRight) != 0)
  72920. s << T('R');
  72921. else if ((mode & absoluteFromParentCentre) != 0)
  72922. s << T('C');
  72923. }
  72924. if ((mode & anchorAtRightOrBottom) != 0)
  72925. s << T('r');
  72926. else if ((mode & anchorAtCentre) != 0)
  72927. s << T('c');
  72928. }
  72929. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  72930. {
  72931. if (mode == proportionalSize)
  72932. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  72933. else if (mode == parentSizeMinusAbsolute)
  72934. s << (roundToInt (value * 100.0) / 100.0) << T('M');
  72935. else
  72936. s << (roundToInt (value * 100.0) / 100.0);
  72937. }
  72938. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  72939. {
  72940. if (s.containsChar (T('r')))
  72941. mode = anchorAtRightOrBottom;
  72942. else if (s.containsChar (T('c')))
  72943. mode = anchorAtCentre;
  72944. else
  72945. mode = anchorAtLeftOrTop;
  72946. if (s.containsChar (T('%')))
  72947. {
  72948. mode |= proportionOfParentSize;
  72949. value = s.removeCharacters (T("%rcRC")).getDoubleValue() / 100.0;
  72950. }
  72951. else
  72952. {
  72953. if (s.containsChar (T('R')))
  72954. mode |= absoluteFromParentBottomRight;
  72955. else if (s.containsChar (T('C')))
  72956. mode |= absoluteFromParentCentre;
  72957. else
  72958. mode |= absoluteFromParentTopLeft;
  72959. value = s.removeCharacters (T("rcRC")).getDoubleValue();
  72960. }
  72961. }
  72962. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  72963. {
  72964. if (s.containsChar (T('%')))
  72965. {
  72966. mode = proportionalSize;
  72967. value = s.upToFirstOccurrenceOf (T("%"), false, false).getDoubleValue() / 100.0;
  72968. }
  72969. else if (s.containsChar (T('M')))
  72970. {
  72971. mode = parentSizeMinusAbsolute;
  72972. value = s.getDoubleValue();
  72973. }
  72974. else
  72975. {
  72976. mode = absoluteSize;
  72977. value = s.getDoubleValue();
  72978. }
  72979. }
  72980. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  72981. const double x_, const double w_,
  72982. const uint8 xMode_, const uint8 wMode_,
  72983. const int parentPos,
  72984. const int parentSize) const throw()
  72985. {
  72986. if (wMode_ == proportionalSize)
  72987. wOut = roundToInt (w_ * parentSize);
  72988. else if (wMode_ == parentSizeMinusAbsolute)
  72989. wOut = jmax (0, parentSize - roundToInt (w_));
  72990. else
  72991. wOut = roundToInt (w_);
  72992. if ((xMode_ & proportionOfParentSize) != 0)
  72993. xOut = parentPos + x_ * parentSize;
  72994. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  72995. xOut = (parentPos + parentSize) - x_;
  72996. else if ((xMode_ & absoluteFromParentCentre) != 0)
  72997. xOut = x_ + (parentPos + parentSize / 2);
  72998. else
  72999. xOut = x_ + parentPos;
  73000. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73001. xOut -= wOut;
  73002. else if ((xMode_ & anchorAtCentre) != 0)
  73003. xOut -= wOut / 2;
  73004. }
  73005. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73006. double x_, const double w_,
  73007. const uint8 xMode_, const uint8 wMode_,
  73008. const int parentPos,
  73009. const int parentSize) const throw()
  73010. {
  73011. if (wMode_ == proportionalSize)
  73012. {
  73013. if (parentSize > 0)
  73014. wOut = w_ / parentSize;
  73015. }
  73016. else if (wMode_ == parentSizeMinusAbsolute)
  73017. wOut = parentSize - w_;
  73018. else
  73019. wOut = w_;
  73020. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73021. x_ += w_;
  73022. else if ((xMode_ & anchorAtCentre) != 0)
  73023. x_ += w_ / 2;
  73024. if ((xMode_ & proportionOfParentSize) != 0)
  73025. {
  73026. if (parentSize > 0)
  73027. xOut = (x_ - parentPos) / parentSize;
  73028. }
  73029. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73030. xOut = (parentPos + parentSize) - x_;
  73031. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73032. xOut = x_ - (parentPos + parentSize / 2);
  73033. else
  73034. xOut = x_ - parentPos;
  73035. }
  73036. END_JUCE_NAMESPACE
  73037. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  73038. /*** Start of inlined file: juce_RectangleList.cpp ***/
  73039. BEGIN_JUCE_NAMESPACE
  73040. RectangleList::RectangleList() throw()
  73041. {
  73042. }
  73043. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  73044. {
  73045. if (! rect.isEmpty())
  73046. rects.add (rect);
  73047. }
  73048. RectangleList::RectangleList (const RectangleList& other) throw()
  73049. : rects (other.rects)
  73050. {
  73051. }
  73052. RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73053. {
  73054. rects = other.rects;
  73055. return *this;
  73056. }
  73057. RectangleList::~RectangleList() throw()
  73058. {
  73059. }
  73060. void RectangleList::clear() throw()
  73061. {
  73062. rects.clearQuick();
  73063. }
  73064. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  73065. {
  73066. if (((unsigned int) index) < (unsigned int) rects.size())
  73067. return rects.getReference (index);
  73068. return Rectangle<int>();
  73069. }
  73070. bool RectangleList::isEmpty() const throw()
  73071. {
  73072. return rects.size() == 0;
  73073. }
  73074. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73075. : current (0),
  73076. owner (list),
  73077. index (list.rects.size())
  73078. {
  73079. }
  73080. RectangleList::Iterator::~Iterator() throw()
  73081. {
  73082. }
  73083. bool RectangleList::Iterator::next() throw()
  73084. {
  73085. if (--index >= 0)
  73086. {
  73087. current = & (owner.rects.getReference (index));
  73088. return true;
  73089. }
  73090. return false;
  73091. }
  73092. void RectangleList::add (const Rectangle<int>& rect) throw()
  73093. {
  73094. if (! rect.isEmpty())
  73095. {
  73096. if (rects.size() == 0)
  73097. {
  73098. rects.add (rect);
  73099. }
  73100. else
  73101. {
  73102. bool anyOverlaps = false;
  73103. int i;
  73104. for (i = rects.size(); --i >= 0;)
  73105. {
  73106. Rectangle<int>& ourRect = rects.getReference (i);
  73107. if (rect.intersects (ourRect))
  73108. {
  73109. if (rect.contains (ourRect))
  73110. rects.remove (i);
  73111. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73112. anyOverlaps = true;
  73113. }
  73114. }
  73115. if (anyOverlaps && rects.size() > 0)
  73116. {
  73117. RectangleList r (rect);
  73118. for (i = rects.size(); --i >= 0;)
  73119. {
  73120. const Rectangle<int>& ourRect = rects.getReference (i);
  73121. if (rect.intersects (ourRect))
  73122. {
  73123. r.subtract (ourRect);
  73124. if (r.rects.size() == 0)
  73125. return;
  73126. }
  73127. }
  73128. for (i = r.getNumRectangles(); --i >= 0;)
  73129. rects.add (r.rects.getReference (i));
  73130. }
  73131. else
  73132. {
  73133. rects.add (rect);
  73134. }
  73135. }
  73136. }
  73137. }
  73138. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73139. {
  73140. rects.add (rect);
  73141. }
  73142. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73143. {
  73144. if (rects.size() == 0)
  73145. {
  73146. if (w > 0 && h > 0)
  73147. rects.add (Rectangle<int> (x, y, w, h));
  73148. }
  73149. else
  73150. {
  73151. add (Rectangle<int> (x, y, w, h));
  73152. }
  73153. }
  73154. void RectangleList::add (const RectangleList& other) throw()
  73155. {
  73156. for (int i = 0; i < other.rects.size(); ++i)
  73157. add (other.rects.getReference (i));
  73158. }
  73159. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73160. {
  73161. const int originalNumRects = rects.size();
  73162. if (originalNumRects > 0)
  73163. {
  73164. const int x1 = rect.x;
  73165. const int y1 = rect.y;
  73166. const int x2 = x1 + rect.w;
  73167. const int y2 = y1 + rect.h;
  73168. for (int i = getNumRectangles(); --i >= 0;)
  73169. {
  73170. Rectangle<int>& r = rects.getReference (i);
  73171. const int rx1 = r.x;
  73172. const int ry1 = r.y;
  73173. const int rx2 = rx1 + r.w;
  73174. const int ry2 = ry1 + r.h;
  73175. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73176. {
  73177. if (x1 > rx1 && x1 < rx2)
  73178. {
  73179. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73180. {
  73181. r.w = x1 - rx1;
  73182. }
  73183. else
  73184. {
  73185. r.x = x1;
  73186. r.w = rx2 - x1;
  73187. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73188. i += 2;
  73189. }
  73190. }
  73191. else if (x2 > rx1 && x2 < rx2)
  73192. {
  73193. r.x = x2;
  73194. r.w = rx2 - x2;
  73195. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73196. {
  73197. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73198. i += 2;
  73199. }
  73200. }
  73201. else if (y1 > ry1 && y1 < ry2)
  73202. {
  73203. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73204. {
  73205. r.h = y1 - ry1;
  73206. }
  73207. else
  73208. {
  73209. r.y = y1;
  73210. r.h = ry2 - y1;
  73211. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73212. i += 2;
  73213. }
  73214. }
  73215. else if (y2 > ry1 && y2 < ry2)
  73216. {
  73217. r.y = y2;
  73218. r.h = ry2 - y2;
  73219. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73220. {
  73221. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73222. i += 2;
  73223. }
  73224. }
  73225. else
  73226. {
  73227. rects.remove (i);
  73228. }
  73229. }
  73230. }
  73231. if (rects.size() > originalNumRects + 10)
  73232. consolidate();
  73233. }
  73234. }
  73235. void RectangleList::subtract (const RectangleList& otherList) throw()
  73236. {
  73237. for (int i = otherList.rects.size(); --i >= 0;)
  73238. subtract (otherList.rects.getReference (i));
  73239. }
  73240. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73241. {
  73242. bool notEmpty = false;
  73243. if (rect.isEmpty())
  73244. {
  73245. clear();
  73246. }
  73247. else
  73248. {
  73249. for (int i = rects.size(); --i >= 0;)
  73250. {
  73251. Rectangle<int>& r = rects.getReference (i);
  73252. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73253. rects.remove (i);
  73254. else
  73255. notEmpty = true;
  73256. }
  73257. }
  73258. return notEmpty;
  73259. }
  73260. bool RectangleList::clipTo (const RectangleList& other) throw()
  73261. {
  73262. if (rects.size() == 0)
  73263. return false;
  73264. RectangleList result;
  73265. for (int j = 0; j < rects.size(); ++j)
  73266. {
  73267. const Rectangle<int>& rect = rects.getReference (j);
  73268. for (int i = other.rects.size(); --i >= 0;)
  73269. {
  73270. Rectangle<int> r (other.rects.getReference (i));
  73271. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73272. result.rects.add (r);
  73273. }
  73274. }
  73275. swapWith (result);
  73276. return ! isEmpty();
  73277. }
  73278. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73279. {
  73280. destRegion.clear();
  73281. if (! rect.isEmpty())
  73282. {
  73283. for (int i = rects.size(); --i >= 0;)
  73284. {
  73285. Rectangle<int> r (rects.getReference (i));
  73286. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73287. destRegion.rects.add (r);
  73288. }
  73289. }
  73290. return destRegion.rects.size() > 0;
  73291. }
  73292. void RectangleList::swapWith (RectangleList& otherList) throw()
  73293. {
  73294. rects.swapWithArray (otherList.rects);
  73295. }
  73296. void RectangleList::consolidate() throw()
  73297. {
  73298. int i;
  73299. for (i = 0; i < getNumRectangles() - 1; ++i)
  73300. {
  73301. Rectangle<int>& r = rects.getReference (i);
  73302. const int rx1 = r.x;
  73303. const int ry1 = r.y;
  73304. const int rx2 = rx1 + r.w;
  73305. const int ry2 = ry1 + r.h;
  73306. for (int j = rects.size(); --j > i;)
  73307. {
  73308. Rectangle<int>& r2 = rects.getReference (j);
  73309. const int jrx1 = r2.x;
  73310. const int jry1 = r2.y;
  73311. const int jrx2 = jrx1 + r2.w;
  73312. const int jry2 = jry1 + r2.h;
  73313. // if the vertical edges of any blocks are touching and their horizontals don't
  73314. // line up, split them horizontally..
  73315. if (jrx1 == rx2 || jrx2 == rx1)
  73316. {
  73317. if (jry1 > ry1 && jry1 < ry2)
  73318. {
  73319. r.h = jry1 - ry1;
  73320. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73321. i = -1;
  73322. break;
  73323. }
  73324. if (jry2 > ry1 && jry2 < ry2)
  73325. {
  73326. r.h = jry2 - ry1;
  73327. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73328. i = -1;
  73329. break;
  73330. }
  73331. else if (ry1 > jry1 && ry1 < jry2)
  73332. {
  73333. r2.h = ry1 - jry1;
  73334. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73335. i = -1;
  73336. break;
  73337. }
  73338. else if (ry2 > jry1 && ry2 < jry2)
  73339. {
  73340. r2.h = ry2 - jry1;
  73341. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73342. i = -1;
  73343. break;
  73344. }
  73345. }
  73346. }
  73347. }
  73348. for (i = 0; i < rects.size() - 1; ++i)
  73349. {
  73350. Rectangle<int>& r = rects.getReference (i);
  73351. for (int j = rects.size(); --j > i;)
  73352. {
  73353. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73354. {
  73355. rects.remove (j);
  73356. i = -1;
  73357. break;
  73358. }
  73359. }
  73360. }
  73361. }
  73362. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73363. {
  73364. for (int i = getNumRectangles(); --i >= 0;)
  73365. if (rects.getReference (i).contains (x, y))
  73366. return true;
  73367. return false;
  73368. }
  73369. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73370. {
  73371. if (rects.size() > 1)
  73372. {
  73373. RectangleList r (rectangleToCheck);
  73374. for (int i = rects.size(); --i >= 0;)
  73375. {
  73376. r.subtract (rects.getReference (i));
  73377. if (r.rects.size() == 0)
  73378. return true;
  73379. }
  73380. }
  73381. else if (rects.size() > 0)
  73382. {
  73383. return rects.getReference (0).contains (rectangleToCheck);
  73384. }
  73385. return false;
  73386. }
  73387. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73388. {
  73389. for (int i = rects.size(); --i >= 0;)
  73390. if (rects.getReference (i).intersects (rectangleToCheck))
  73391. return true;
  73392. return false;
  73393. }
  73394. bool RectangleList::intersects (const RectangleList& other) const throw()
  73395. {
  73396. for (int i = rects.size(); --i >= 0;)
  73397. if (other.intersectsRectangle (rects.getReference (i)))
  73398. return true;
  73399. return false;
  73400. }
  73401. const Rectangle<int> RectangleList::getBounds() const throw()
  73402. {
  73403. if (rects.size() <= 1)
  73404. {
  73405. if (rects.size() == 0)
  73406. return Rectangle<int>();
  73407. else
  73408. return rects.getReference (0);
  73409. }
  73410. else
  73411. {
  73412. const Rectangle<int>& r = rects.getReference (0);
  73413. int minX = r.x;
  73414. int minY = r.y;
  73415. int maxX = minX + r.w;
  73416. int maxY = minY + r.h;
  73417. for (int i = rects.size(); --i > 0;)
  73418. {
  73419. const Rectangle<int>& r2 = rects.getReference (i);
  73420. minX = jmin (minX, r2.x);
  73421. minY = jmin (minY, r2.y);
  73422. maxX = jmax (maxX, r2.getRight());
  73423. maxY = jmax (maxY, r2.getBottom());
  73424. }
  73425. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73426. }
  73427. }
  73428. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73429. {
  73430. for (int i = rects.size(); --i >= 0;)
  73431. {
  73432. Rectangle<int>& r = rects.getReference (i);
  73433. r.x += dx;
  73434. r.y += dy;
  73435. }
  73436. }
  73437. const Path RectangleList::toPath() const throw()
  73438. {
  73439. Path p;
  73440. for (int i = rects.size(); --i >= 0;)
  73441. {
  73442. const Rectangle<int>& r = rects.getReference (i);
  73443. p.addRectangle ((float) r.x,
  73444. (float) r.y,
  73445. (float) r.w,
  73446. (float) r.h);
  73447. }
  73448. return p;
  73449. }
  73450. END_JUCE_NAMESPACE
  73451. /*** End of inlined file: juce_RectangleList.cpp ***/
  73452. /*** Start of inlined file: juce_Image.cpp ***/
  73453. BEGIN_JUCE_NAMESPACE
  73454. static const int fullAlphaThreshold = 253;
  73455. Image::Image (const PixelFormat format_,
  73456. const int imageWidth_,
  73457. const int imageHeight_)
  73458. : format (format_),
  73459. imageWidth (imageWidth_),
  73460. imageHeight (imageHeight_),
  73461. imageData (0)
  73462. {
  73463. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73464. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73465. // actual image will be at least 1x1.
  73466. }
  73467. Image::Image (const PixelFormat format_,
  73468. const int imageWidth_,
  73469. const int imageHeight_,
  73470. const bool clearImage)
  73471. : format (format_),
  73472. imageWidth (imageWidth_),
  73473. imageHeight (imageHeight_)
  73474. {
  73475. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73476. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73477. // actual image will be at least 1x1.
  73478. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73479. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73480. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73481. imageData = imageDataAllocated;
  73482. }
  73483. Image::Image (const Image& other)
  73484. : format (other.format),
  73485. imageWidth (other.imageWidth),
  73486. imageHeight (other.imageHeight)
  73487. {
  73488. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73489. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73490. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73491. imageData = imageDataAllocated;
  73492. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73493. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73494. }
  73495. Image::~Image()
  73496. {
  73497. }
  73498. LowLevelGraphicsContext* Image::createLowLevelContext()
  73499. {
  73500. return new LowLevelGraphicsSoftwareRenderer (*this);
  73501. }
  73502. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73503. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73504. lineStride (image.lineStride),
  73505. pixelStride (image.pixelStride),
  73506. width (w),
  73507. height (h)
  73508. {
  73509. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73510. }
  73511. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  73512. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73513. lineStride (image.lineStride),
  73514. pixelStride (image.pixelStride),
  73515. width (w),
  73516. height (h)
  73517. {
  73518. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73519. }
  73520. Image::BitmapData::~BitmapData()
  73521. {
  73522. }
  73523. void Image::setPixelData (int x, int y, int w, int h,
  73524. const uint8* sourcePixelData, int sourceLineStride)
  73525. {
  73526. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  73527. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  73528. {
  73529. const BitmapData dest (*this, x, y, w, h, true);
  73530. for (int i = 0; i < h; ++i)
  73531. {
  73532. memcpy (dest.getLinePointer(i),
  73533. sourcePixelData + sourceLineStride * i,
  73534. w * dest.pixelStride);
  73535. }
  73536. }
  73537. }
  73538. void Image::clear (int dx, int dy, int dw, int dh, const Colour& colourToClearTo)
  73539. {
  73540. if (Rectangle<int>::intersectRectangles (dx, dy, dw, dh, 0, 0, imageWidth, imageHeight))
  73541. {
  73542. const PixelARGB col (colourToClearTo.getPixelARGB());
  73543. const BitmapData destData (*this, dx, dy, dw, dh, true);
  73544. uint8* dest = destData.data;
  73545. while (--dh >= 0)
  73546. {
  73547. uint8* line = dest;
  73548. dest += destData.lineStride;
  73549. if (isARGB())
  73550. {
  73551. for (int x = dw; --x >= 0;)
  73552. {
  73553. ((PixelARGB*) line)->set (col);
  73554. line += destData.pixelStride;
  73555. }
  73556. }
  73557. else if (isRGB())
  73558. {
  73559. for (int x = dw; --x >= 0;)
  73560. {
  73561. ((PixelRGB*) line)->set (col);
  73562. line += destData.pixelStride;
  73563. }
  73564. }
  73565. else
  73566. {
  73567. for (int x = dw; --x >= 0;)
  73568. {
  73569. *line = col.getAlpha();
  73570. line += destData.pixelStride;
  73571. }
  73572. }
  73573. }
  73574. }
  73575. }
  73576. Image* Image::createCopy (int newWidth, int newHeight,
  73577. const Graphics::ResamplingQuality quality) const
  73578. {
  73579. if (newWidth < 0)
  73580. newWidth = imageWidth;
  73581. if (newHeight < 0)
  73582. newHeight = imageHeight;
  73583. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  73584. Graphics g (*newImage);
  73585. g.setImageResamplingQuality (quality);
  73586. g.drawImage (this,
  73587. 0, 0, newWidth, newHeight,
  73588. 0, 0, imageWidth, imageHeight,
  73589. false);
  73590. return newImage;
  73591. }
  73592. Image* Image::createCopyOfAlphaChannel() const
  73593. {
  73594. jassert (format != SingleChannel);
  73595. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  73596. if (! hasAlphaChannel())
  73597. {
  73598. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  73599. }
  73600. else
  73601. {
  73602. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  73603. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  73604. for (int y = 0; y < imageHeight; ++y)
  73605. {
  73606. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  73607. uint8* dst = destData.getLinePointer (y);
  73608. for (int x = imageWidth; --x >= 0;)
  73609. {
  73610. *dst++ = src->getAlpha();
  73611. ++src;
  73612. }
  73613. }
  73614. }
  73615. return newImage;
  73616. }
  73617. const Colour Image::getPixelAt (const int x, const int y) const
  73618. {
  73619. Colour c;
  73620. if (((unsigned int) x) < (unsigned int) imageWidth
  73621. && ((unsigned int) y) < (unsigned int) imageHeight)
  73622. {
  73623. const BitmapData srcData (*this, x, y, 1, 1);
  73624. if (isARGB())
  73625. {
  73626. PixelARGB p (*(const PixelARGB*) srcData.data);
  73627. p.unpremultiply();
  73628. c = Colour (p.getARGB());
  73629. }
  73630. else if (isRGB())
  73631. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  73632. else
  73633. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  73634. }
  73635. return c;
  73636. }
  73637. void Image::setPixelAt (const int x, const int y,
  73638. const Colour& colour)
  73639. {
  73640. if (((unsigned int) x) < (unsigned int) imageWidth
  73641. && ((unsigned int) y) < (unsigned int) imageHeight)
  73642. {
  73643. const BitmapData destData (*this, x, y, 1, 1, true);
  73644. const PixelARGB col (colour.getPixelARGB());
  73645. if (isARGB())
  73646. ((PixelARGB*) destData.data)->set (col);
  73647. else if (isRGB())
  73648. ((PixelRGB*) destData.data)->set (col);
  73649. else
  73650. *(destData.data) = col.getAlpha();
  73651. }
  73652. }
  73653. void Image::multiplyAlphaAt (const int x, const int y,
  73654. const float multiplier)
  73655. {
  73656. if (((unsigned int) x) < (unsigned int) imageWidth
  73657. && ((unsigned int) y) < (unsigned int) imageHeight
  73658. && hasAlphaChannel())
  73659. {
  73660. const BitmapData destData (*this, x, y, 1, 1, true);
  73661. if (isARGB())
  73662. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  73663. else
  73664. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  73665. }
  73666. }
  73667. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  73668. {
  73669. if (hasAlphaChannel())
  73670. {
  73671. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73672. if (isARGB())
  73673. {
  73674. for (int y = 0; y < imageHeight; ++y)
  73675. {
  73676. uint8* p = destData.getLinePointer (y);
  73677. for (int x = 0; x < imageWidth; ++x)
  73678. {
  73679. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  73680. p += destData.pixelStride;
  73681. }
  73682. }
  73683. }
  73684. else
  73685. {
  73686. for (int y = 0; y < imageHeight; ++y)
  73687. {
  73688. uint8* p = destData.getLinePointer (y);
  73689. for (int x = 0; x < imageWidth; ++x)
  73690. {
  73691. *p = (uint8) (*p * amountToMultiplyBy);
  73692. p += destData.pixelStride;
  73693. }
  73694. }
  73695. }
  73696. }
  73697. else
  73698. {
  73699. jassertfalse // can't do this without an alpha-channel!
  73700. }
  73701. }
  73702. void Image::desaturate()
  73703. {
  73704. if (isARGB() || isRGB())
  73705. {
  73706. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73707. if (isARGB())
  73708. {
  73709. for (int y = 0; y < imageHeight; ++y)
  73710. {
  73711. uint8* p = destData.getLinePointer (y);
  73712. for (int x = 0; x < imageWidth; ++x)
  73713. {
  73714. ((PixelARGB*) p)->desaturate();
  73715. p += destData.pixelStride;
  73716. }
  73717. }
  73718. }
  73719. else
  73720. {
  73721. for (int y = 0; y < imageHeight; ++y)
  73722. {
  73723. uint8* p = destData.getLinePointer (y);
  73724. for (int x = 0; x < imageWidth; ++x)
  73725. {
  73726. ((PixelRGB*) p)->desaturate();
  73727. p += destData.pixelStride;
  73728. }
  73729. }
  73730. }
  73731. }
  73732. }
  73733. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  73734. {
  73735. if (hasAlphaChannel())
  73736. {
  73737. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  73738. SparseSet <int> pixelsOnRow;
  73739. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  73740. for (int y = 0; y < imageHeight; ++y)
  73741. {
  73742. pixelsOnRow.clear();
  73743. const uint8* lineData = srcData.getLinePointer (y);
  73744. if (isARGB())
  73745. {
  73746. for (int x = 0; x < imageWidth; ++x)
  73747. {
  73748. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  73749. pixelsOnRow.addRange (x, 1);
  73750. lineData += srcData.pixelStride;
  73751. }
  73752. }
  73753. else
  73754. {
  73755. for (int x = 0; x < imageWidth; ++x)
  73756. {
  73757. if (*lineData >= threshold)
  73758. pixelsOnRow.addRange (x, 1);
  73759. lineData += srcData.pixelStride;
  73760. }
  73761. }
  73762. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  73763. {
  73764. int x, w;
  73765. if (pixelsOnRow.getRange (i, x, w))
  73766. result.add (Rectangle<int> (x, y, w, 1));
  73767. }
  73768. result.consolidate();
  73769. }
  73770. }
  73771. else
  73772. {
  73773. result.add (0, 0, imageWidth, imageHeight);
  73774. }
  73775. }
  73776. void Image::moveImageSection (int dx, int dy,
  73777. int sx, int sy,
  73778. int w, int h)
  73779. {
  73780. if (dx < 0)
  73781. {
  73782. w += dx;
  73783. sx -= dx;
  73784. dx = 0;
  73785. }
  73786. if (dy < 0)
  73787. {
  73788. h += dy;
  73789. sy -= dy;
  73790. dy = 0;
  73791. }
  73792. if (sx < 0)
  73793. {
  73794. w += sx;
  73795. dx -= sx;
  73796. sx = 0;
  73797. }
  73798. if (sy < 0)
  73799. {
  73800. h += sy;
  73801. dy -= sy;
  73802. sy = 0;
  73803. }
  73804. const int minX = jmin (dx, sx);
  73805. const int minY = jmin (dy, sy);
  73806. w = jmin (w, getWidth() - jmax (sx, dx));
  73807. h = jmin (h, getHeight() - jmax (sy, dy));
  73808. if (w > 0 && h > 0)
  73809. {
  73810. const int maxX = jmax (dx, sx) + w;
  73811. const int maxY = jmax (dy, sy) + h;
  73812. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  73813. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  73814. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  73815. const int lineSize = destData.pixelStride * w;
  73816. if (dy > sy)
  73817. {
  73818. while (--h >= 0)
  73819. {
  73820. const int offset = h * destData.lineStride;
  73821. memmove (dst + offset, src + offset, lineSize);
  73822. }
  73823. }
  73824. else if (dst != src)
  73825. {
  73826. while (--h >= 0)
  73827. {
  73828. memmove (dst, src, lineSize);
  73829. dst += destData.lineStride;
  73830. src += destData.lineStride;
  73831. }
  73832. }
  73833. }
  73834. }
  73835. END_JUCE_NAMESPACE
  73836. /*** End of inlined file: juce_Image.cpp ***/
  73837. /*** Start of inlined file: juce_ImageCache.cpp ***/
  73838. BEGIN_JUCE_NAMESPACE
  73839. struct ImageCache::Item
  73840. {
  73841. ScopedPointer <Image> image;
  73842. int64 hashCode;
  73843. int refCount;
  73844. uint32 releaseTime;
  73845. juce_UseDebuggingNewOperator
  73846. };
  73847. ImageCache* ImageCache::instance = 0;
  73848. int ImageCache::cacheTimeout = 5000;
  73849. ImageCache::ImageCache()
  73850. {
  73851. }
  73852. ImageCache::~ImageCache()
  73853. {
  73854. jassert (instance == this);
  73855. instance = 0;
  73856. }
  73857. Image* ImageCache::getFromHashCode (const int64 hashCode)
  73858. {
  73859. if (instance != 0)
  73860. {
  73861. const ScopedLock sl (instance->lock);
  73862. for (int i = instance->images.size(); --i >= 0;)
  73863. {
  73864. Item* const ci = instance->images.getUnchecked(i);
  73865. if (ci->hashCode == hashCode)
  73866. {
  73867. ci->refCount++;
  73868. return ci->image;
  73869. }
  73870. }
  73871. }
  73872. return 0;
  73873. }
  73874. void ImageCache::addImageToCache (Image* const image, const int64 hashCode)
  73875. {
  73876. if (image != 0)
  73877. {
  73878. if (instance == 0)
  73879. instance = new ImageCache();
  73880. Item* const newC = new Item();
  73881. newC->hashCode = hashCode;
  73882. newC->image = image;
  73883. newC->refCount = 1;
  73884. newC->releaseTime = 0;
  73885. const ScopedLock sl (instance->lock);
  73886. instance->images.add (newC);
  73887. }
  73888. }
  73889. void ImageCache::release (Image* const imageToRelease)
  73890. {
  73891. if (imageToRelease != 0 && instance != 0)
  73892. {
  73893. const ScopedLock sl (instance->lock);
  73894. for (int i = instance->images.size(); --i >= 0;)
  73895. {
  73896. Item* const ci = instance->images.getUnchecked(i);
  73897. if (static_cast <Image*> (ci->image) == imageToRelease)
  73898. {
  73899. if (--(ci->refCount) == 0)
  73900. ci->releaseTime = Time::getApproximateMillisecondCounter();
  73901. if (! instance->isTimerRunning())
  73902. instance->startTimer (999);
  73903. break;
  73904. }
  73905. }
  73906. }
  73907. }
  73908. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  73909. {
  73910. if (isImageInCache (imageToRelease))
  73911. release (imageToRelease);
  73912. else
  73913. delete imageToRelease;
  73914. }
  73915. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  73916. {
  73917. if (instance != 0)
  73918. {
  73919. const ScopedLock sl (instance->lock);
  73920. for (int i = instance->images.size(); --i >= 0;)
  73921. if (static_cast <Image*> (instance->images.getUnchecked(i)->image) == imageToLookFor)
  73922. return true;
  73923. }
  73924. return false;
  73925. }
  73926. void ImageCache::incReferenceCount (Image* const image)
  73927. {
  73928. if (instance != 0)
  73929. {
  73930. const ScopedLock sl (instance->lock);
  73931. for (int i = instance->images.size(); --i >= 0;)
  73932. {
  73933. Item* const ci = instance->images.getUnchecked(i);
  73934. if (static_cast <Image*> (ci->image) == image)
  73935. {
  73936. ci->refCount++;
  73937. return;
  73938. }
  73939. }
  73940. }
  73941. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  73942. }
  73943. void ImageCache::timerCallback()
  73944. {
  73945. int numberStillNeedingReleasing = 0;
  73946. const uint32 now = Time::getApproximateMillisecondCounter();
  73947. const ScopedLock sl (lock);
  73948. for (int i = images.size(); --i >= 0;)
  73949. {
  73950. Item* const ci = images.getUnchecked(i);
  73951. if (ci->refCount <= 0)
  73952. {
  73953. if (now > ci->releaseTime + cacheTimeout
  73954. || now < ci->releaseTime - 1000)
  73955. {
  73956. images.remove (i);
  73957. }
  73958. else
  73959. {
  73960. ++numberStillNeedingReleasing;
  73961. }
  73962. }
  73963. }
  73964. if (numberStillNeedingReleasing == 0)
  73965. stopTimer();
  73966. }
  73967. Image* ImageCache::getFromFile (const File& file)
  73968. {
  73969. const int64 hashCode = file.hashCode64();
  73970. Image* image = getFromHashCode (hashCode);
  73971. if (image == 0)
  73972. {
  73973. image = ImageFileFormat::loadFrom (file);
  73974. addImageToCache (image, hashCode);
  73975. }
  73976. return image;
  73977. }
  73978. Image* ImageCache::getFromMemory (const void* imageData, const int dataSize)
  73979. {
  73980. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  73981. Image* image = getFromHashCode (hashCode);
  73982. if (image == 0)
  73983. {
  73984. image = ImageFileFormat::loadFrom (imageData, dataSize);
  73985. addImageToCache (image, hashCode);
  73986. }
  73987. return image;
  73988. }
  73989. void ImageCache::setCacheTimeout (const int millisecs)
  73990. {
  73991. cacheTimeout = millisecs;
  73992. }
  73993. END_JUCE_NAMESPACE
  73994. /*** End of inlined file: juce_ImageCache.cpp ***/
  73995. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  73996. BEGIN_JUCE_NAMESPACE
  73997. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  73998. : values (size_ * size_),
  73999. size (size_)
  74000. {
  74001. clear();
  74002. }
  74003. ImageConvolutionKernel::~ImageConvolutionKernel()
  74004. {
  74005. }
  74006. float ImageConvolutionKernel::getKernelValue (const int x, const int y) const throw()
  74007. {
  74008. if (((unsigned int) x) < (unsigned int) size
  74009. && ((unsigned int) y) < (unsigned int) size)
  74010. {
  74011. return values [x + y * size];
  74012. }
  74013. else
  74014. {
  74015. jassertfalse;
  74016. return 0;
  74017. }
  74018. }
  74019. void ImageConvolutionKernel::setKernelValue (const int x, const int y, const float value) throw()
  74020. {
  74021. if (((unsigned int) x) < (unsigned int) size
  74022. && ((unsigned int) y) < (unsigned int) size)
  74023. {
  74024. values [x + y * size] = value;
  74025. }
  74026. else
  74027. {
  74028. jassertfalse;
  74029. }
  74030. }
  74031. void ImageConvolutionKernel::clear()
  74032. {
  74033. for (int i = size * size; --i >= 0;)
  74034. values[i] = 0;
  74035. }
  74036. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74037. {
  74038. double currentTotal = 0.0;
  74039. for (int i = size * size; --i >= 0;)
  74040. currentTotal += values[i];
  74041. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74042. }
  74043. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74044. {
  74045. for (int i = size * size; --i >= 0;)
  74046. values[i] *= multiplier;
  74047. }
  74048. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74049. {
  74050. const double radiusFactor = -1.0 / (radius * radius * 2);
  74051. const int centre = size >> 1;
  74052. for (int y = size; --y >= 0;)
  74053. {
  74054. for (int x = size; --x >= 0;)
  74055. {
  74056. const int cx = x - centre;
  74057. const int cy = y - centre;
  74058. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74059. }
  74060. }
  74061. setOverallSum (1.0f);
  74062. }
  74063. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74064. const Image* sourceImage,
  74065. int dx,
  74066. int dy,
  74067. int dw,
  74068. int dh) const
  74069. {
  74070. ScopedPointer <Image> imageCreated;
  74071. if (sourceImage == 0)
  74072. {
  74073. sourceImage = imageCreated = destImage.createCopy();
  74074. }
  74075. else
  74076. {
  74077. jassert (sourceImage->getWidth() == destImage.getWidth()
  74078. && sourceImage->getHeight() == destImage.getHeight()
  74079. && sourceImage->getFormat() == destImage.getFormat());
  74080. if (sourceImage->getWidth() != destImage.getWidth()
  74081. || sourceImage->getHeight() != destImage.getHeight()
  74082. || sourceImage->getFormat() != destImage.getFormat())
  74083. return;
  74084. }
  74085. const int imageWidth = destImage.getWidth();
  74086. const int imageHeight = destImage.getHeight();
  74087. if (dx >= imageWidth || dy >= imageHeight)
  74088. return;
  74089. if (dx + dw > imageWidth)
  74090. dw = imageWidth - dx;
  74091. if (dy + dh > imageHeight)
  74092. dh = imageHeight - dy;
  74093. const int dx2 = dx + dw;
  74094. const int dy2 = dy + dh;
  74095. const Image::BitmapData destData (destImage, dx, dy, dw, dh, true);
  74096. uint8* line = destData.data;
  74097. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74098. if (destData.pixelStride == 4)
  74099. {
  74100. for (int y = dy; y < dy2; ++y)
  74101. {
  74102. uint8* dest = line;
  74103. line += destData.lineStride;
  74104. for (int x = dx; x < dx2; ++x)
  74105. {
  74106. float c1 = 0;
  74107. float c2 = 0;
  74108. float c3 = 0;
  74109. float c4 = 0;
  74110. for (int yy = 0; yy < size; ++yy)
  74111. {
  74112. const int sy = y + yy - (size >> 1);
  74113. if (sy >= imageHeight)
  74114. break;
  74115. if (sy >= 0)
  74116. {
  74117. int sx = x - (size >> 1);
  74118. const uint8* src = srcData.getPixelPointer (sx, sy);
  74119. for (int xx = 0; xx < size; ++xx)
  74120. {
  74121. if (sx >= imageWidth)
  74122. break;
  74123. if (sx >= 0)
  74124. {
  74125. const float kernelMult = values [xx + yy * size];
  74126. c1 += kernelMult * *src++;
  74127. c2 += kernelMult * *src++;
  74128. c3 += kernelMult * *src++;
  74129. c4 += kernelMult * *src++;
  74130. }
  74131. else
  74132. {
  74133. src += 4;
  74134. }
  74135. ++sx;
  74136. }
  74137. }
  74138. }
  74139. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74140. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74141. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74142. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74143. }
  74144. }
  74145. }
  74146. else if (destData.pixelStride == 3)
  74147. {
  74148. for (int y = dy; y < dy2; ++y)
  74149. {
  74150. uint8* dest = line;
  74151. line += destData.lineStride;
  74152. for (int x = dx; x < dx2; ++x)
  74153. {
  74154. float c1 = 0;
  74155. float c2 = 0;
  74156. float c3 = 0;
  74157. for (int yy = 0; yy < size; ++yy)
  74158. {
  74159. const int sy = y + yy - (size >> 1);
  74160. if (sy >= imageHeight)
  74161. break;
  74162. if (sy >= 0)
  74163. {
  74164. int sx = x - (size >> 1);
  74165. const uint8* src = srcData.getPixelPointer (sx, sy);
  74166. for (int xx = 0; xx < size; ++xx)
  74167. {
  74168. if (sx >= imageWidth)
  74169. break;
  74170. if (sx >= 0)
  74171. {
  74172. const float kernelMult = values [xx + yy * size];
  74173. c1 += kernelMult * *src++;
  74174. c2 += kernelMult * *src++;
  74175. c3 += kernelMult * *src++;
  74176. }
  74177. else
  74178. {
  74179. src += 3;
  74180. }
  74181. ++sx;
  74182. }
  74183. }
  74184. }
  74185. *dest++ = (uint8) roundToInt (c1);
  74186. *dest++ = (uint8) roundToInt (c2);
  74187. *dest++ = (uint8) roundToInt (c3);
  74188. }
  74189. }
  74190. }
  74191. }
  74192. END_JUCE_NAMESPACE
  74193. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74194. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74195. BEGIN_JUCE_NAMESPACE
  74196. /*** Start of inlined file: juce_GIFLoader.h ***/
  74197. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74198. #define __JUCE_GIFLOADER_JUCEHEADER__
  74199. #ifndef DOXYGEN
  74200. class GIFLoader
  74201. {
  74202. public:
  74203. GIFLoader (InputStream& in);
  74204. ~GIFLoader();
  74205. Image* getImage() const { return image; }
  74206. private:
  74207. Image* image;
  74208. InputStream& input;
  74209. uint8 buffer [300];
  74210. uint8 palette [256][4];
  74211. bool dataBlockIsZero, fresh, finished;
  74212. int currentBit, lastBit, lastByteIndex;
  74213. int codeSize, setCodeSize;
  74214. int maxCode, maxCodeSize;
  74215. int firstcode, oldcode;
  74216. int clearCode, end_code;
  74217. enum { maxGifCode = 1 << 12 };
  74218. int table [2] [maxGifCode];
  74219. int stack [2 * maxGifCode];
  74220. int *sp;
  74221. bool getSizeFromHeader (int& width, int& height);
  74222. bool readPalette (const int numCols);
  74223. int readDataBlock (unsigned char* dest);
  74224. int processExtension (int type, int& transparent);
  74225. int readLZWByte (bool initialise, int input_code_size);
  74226. int getCode (int code_size, bool initialise);
  74227. bool readImage (int width, int height, int interlace, int transparent);
  74228. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74229. GIFLoader (const GIFLoader&);
  74230. GIFLoader& operator= (const GIFLoader&);
  74231. };
  74232. #endif // DOXYGEN
  74233. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74234. /*** End of inlined file: juce_GIFLoader.h ***/
  74235. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74236. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74237. PNGImageFormat::PNGImageFormat() {}
  74238. PNGImageFormat::~PNGImageFormat() {}
  74239. const String PNGImageFormat::getFormatName()
  74240. {
  74241. return T("PNG");
  74242. }
  74243. bool PNGImageFormat::canUnderstand (InputStream& in)
  74244. {
  74245. const int bytesNeeded = 4;
  74246. char header [bytesNeeded];
  74247. return in.read (header, bytesNeeded) == bytesNeeded
  74248. && header[1] == 'P'
  74249. && header[2] == 'N'
  74250. && header[3] == 'G';
  74251. }
  74252. Image* PNGImageFormat::decodeImage (InputStream& in)
  74253. {
  74254. return juce_loadPNGImageFromStream (in);
  74255. }
  74256. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74257. OutputStream& destStream)
  74258. {
  74259. return juce_writePNGImageToStream (sourceImage, destStream);
  74260. }
  74261. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74262. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74263. JPEGImageFormat::JPEGImageFormat()
  74264. : quality (-1.0f)
  74265. {
  74266. }
  74267. JPEGImageFormat::~JPEGImageFormat() {}
  74268. void JPEGImageFormat::setQuality (const float newQuality)
  74269. {
  74270. quality = newQuality;
  74271. }
  74272. const String JPEGImageFormat::getFormatName()
  74273. {
  74274. return T("JPEG");
  74275. }
  74276. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74277. {
  74278. const int bytesNeeded = 10;
  74279. uint8 header [bytesNeeded];
  74280. if (in.read (header, bytesNeeded) == bytesNeeded)
  74281. {
  74282. return header[0] == 0xff
  74283. && header[1] == 0xd8
  74284. && header[2] == 0xff
  74285. && (header[3] == 0xe0 || header[3] == 0xe1);
  74286. }
  74287. return false;
  74288. }
  74289. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74290. {
  74291. return juce_loadJPEGImageFromStream (in);
  74292. }
  74293. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74294. OutputStream& destStream)
  74295. {
  74296. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74297. }
  74298. class GIFImageFormat : public ImageFileFormat
  74299. {
  74300. public:
  74301. GIFImageFormat() {}
  74302. ~GIFImageFormat() {}
  74303. const String getFormatName()
  74304. {
  74305. return T("GIF");
  74306. }
  74307. bool canUnderstand (InputStream& in)
  74308. {
  74309. const int bytesNeeded = 4;
  74310. char header [bytesNeeded];
  74311. return (in.read (header, bytesNeeded) == bytesNeeded)
  74312. && header[0] == 'G'
  74313. && header[1] == 'I'
  74314. && header[2] == 'F';
  74315. }
  74316. Image* decodeImage (InputStream& in)
  74317. {
  74318. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74319. return loader->getImage();
  74320. }
  74321. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74322. {
  74323. return false;
  74324. }
  74325. };
  74326. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74327. {
  74328. static PNGImageFormat png;
  74329. static JPEGImageFormat jpg;
  74330. static GIFImageFormat gif;
  74331. ImageFileFormat* formats[4];
  74332. int numFormats = 0;
  74333. formats [numFormats++] = &png;
  74334. formats [numFormats++] = &jpg;
  74335. formats [numFormats++] = &gif;
  74336. const int64 streamPos = input.getPosition();
  74337. for (int i = 0; i < numFormats; ++i)
  74338. {
  74339. const bool found = formats[i]->canUnderstand (input);
  74340. input.setPosition (streamPos);
  74341. if (found)
  74342. return formats[i];
  74343. }
  74344. return 0;
  74345. }
  74346. Image* ImageFileFormat::loadFrom (InputStream& input)
  74347. {
  74348. ImageFileFormat* const format = findImageFormatForStream (input);
  74349. if (format != 0)
  74350. return format->decodeImage (input);
  74351. return 0;
  74352. }
  74353. Image* ImageFileFormat::loadFrom (const File& file)
  74354. {
  74355. InputStream* const in = file.createInputStream();
  74356. if (in != 0)
  74357. {
  74358. BufferedInputStream b (in, 8192, true);
  74359. return loadFrom (b);
  74360. }
  74361. return 0;
  74362. }
  74363. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74364. {
  74365. if (rawData != 0 && numBytes > 4)
  74366. {
  74367. MemoryInputStream stream (rawData, numBytes, false);
  74368. return loadFrom (stream);
  74369. }
  74370. return 0;
  74371. }
  74372. END_JUCE_NAMESPACE
  74373. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74374. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74375. BEGIN_JUCE_NAMESPACE
  74376. GIFLoader::GIFLoader (InputStream& in)
  74377. : image (0),
  74378. input (in),
  74379. dataBlockIsZero (false),
  74380. fresh (false),
  74381. finished (false)
  74382. {
  74383. currentBit = lastBit = lastByteIndex = 0;
  74384. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74385. firstcode = oldcode = 0;
  74386. clearCode = end_code = 0;
  74387. int imageWidth, imageHeight;
  74388. int transparent = -1;
  74389. if (! getSizeFromHeader (imageWidth, imageHeight))
  74390. return;
  74391. if ((imageWidth <= 0) || (imageHeight <= 0))
  74392. return;
  74393. unsigned char buf [16];
  74394. if (in.read (buf, 3) != 3)
  74395. return;
  74396. int numColours = 2 << (buf[0] & 7);
  74397. if ((buf[0] & 0x80) != 0)
  74398. readPalette (numColours);
  74399. for (;;)
  74400. {
  74401. if (input.read (buf, 1) != 1)
  74402. break;
  74403. if (buf[0] == ';')
  74404. break;
  74405. if (buf[0] == '!')
  74406. {
  74407. if (input.read (buf, 1) != 1)
  74408. break;
  74409. if (processExtension (buf[0], transparent) < 0)
  74410. break;
  74411. continue;
  74412. }
  74413. if (buf[0] != ',')
  74414. continue;
  74415. if (input.read (buf, 9) != 9)
  74416. break;
  74417. imageWidth = makeWord (buf[4], buf[5]);
  74418. imageHeight = makeWord (buf[6], buf[7]);
  74419. numColours = 2 << (buf[8] & 7);
  74420. if ((buf[8] & 0x80) != 0)
  74421. if (! readPalette (numColours))
  74422. break;
  74423. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74424. imageWidth, imageHeight, (transparent >= 0));
  74425. readImage (imageWidth, imageHeight,
  74426. (buf[8] & 0x40) != 0,
  74427. transparent);
  74428. break;
  74429. }
  74430. }
  74431. GIFLoader::~GIFLoader()
  74432. {
  74433. }
  74434. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74435. {
  74436. unsigned char b [8];
  74437. if (input.read (b, 6) == 6)
  74438. {
  74439. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  74440. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  74441. {
  74442. if (input.read (b, 4) == 4)
  74443. {
  74444. w = makeWord (b[0], b[1]);
  74445. h = makeWord (b[2], b[3]);
  74446. return true;
  74447. }
  74448. }
  74449. }
  74450. return false;
  74451. }
  74452. bool GIFLoader::readPalette (const int numCols)
  74453. {
  74454. unsigned char rgb[4];
  74455. for (int i = 0; i < numCols; ++i)
  74456. {
  74457. input.read (rgb, 3);
  74458. palette [i][0] = rgb[0];
  74459. palette [i][1] = rgb[1];
  74460. palette [i][2] = rgb[2];
  74461. palette [i][3] = 0xff;
  74462. }
  74463. return true;
  74464. }
  74465. int GIFLoader::readDataBlock (unsigned char* const dest)
  74466. {
  74467. unsigned char n;
  74468. if (input.read (&n, 1) == 1)
  74469. {
  74470. dataBlockIsZero = (n == 0);
  74471. if (dataBlockIsZero || (input.read (dest, n) == n))
  74472. return n;
  74473. }
  74474. return -1;
  74475. }
  74476. int GIFLoader::processExtension (const int type, int& transparent)
  74477. {
  74478. unsigned char b [300];
  74479. int n = 0;
  74480. if (type == 0xf9)
  74481. {
  74482. n = readDataBlock (b);
  74483. if (n < 0)
  74484. return 1;
  74485. if ((b[0] & 0x1) != 0)
  74486. transparent = b[3];
  74487. }
  74488. do
  74489. {
  74490. n = readDataBlock (b);
  74491. }
  74492. while (n > 0);
  74493. return n;
  74494. }
  74495. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74496. {
  74497. if (initialise)
  74498. {
  74499. currentBit = 0;
  74500. lastBit = 0;
  74501. finished = false;
  74502. return 0;
  74503. }
  74504. if ((currentBit + codeSize_) >= lastBit)
  74505. {
  74506. if (finished)
  74507. return -1;
  74508. buffer[0] = buffer [lastByteIndex - 2];
  74509. buffer[1] = buffer [lastByteIndex - 1];
  74510. const int n = readDataBlock (&buffer[2]);
  74511. if (n == 0)
  74512. finished = true;
  74513. lastByteIndex = 2 + n;
  74514. currentBit = (currentBit - lastBit) + 16;
  74515. lastBit = (2 + n) * 8 ;
  74516. }
  74517. int result = 0;
  74518. int i = currentBit;
  74519. for (int j = 0; j < codeSize_; ++j)
  74520. {
  74521. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  74522. ++i;
  74523. }
  74524. currentBit += codeSize_;
  74525. return result;
  74526. }
  74527. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  74528. {
  74529. int code, incode, i;
  74530. if (initialise)
  74531. {
  74532. setCodeSize = inputCodeSize;
  74533. codeSize = setCodeSize + 1;
  74534. clearCode = 1 << setCodeSize;
  74535. end_code = clearCode + 1;
  74536. maxCodeSize = 2 * clearCode;
  74537. maxCode = clearCode + 2;
  74538. getCode (0, true);
  74539. fresh = true;
  74540. for (i = 0; i < clearCode; ++i)
  74541. {
  74542. table[0][i] = 0;
  74543. table[1][i] = i;
  74544. }
  74545. for (; i < maxGifCode; ++i)
  74546. {
  74547. table[0][i] = 0;
  74548. table[1][i] = 0;
  74549. }
  74550. sp = stack;
  74551. return 0;
  74552. }
  74553. else if (fresh)
  74554. {
  74555. fresh = false;
  74556. do
  74557. {
  74558. firstcode = oldcode
  74559. = getCode (codeSize, false);
  74560. }
  74561. while (firstcode == clearCode);
  74562. return firstcode;
  74563. }
  74564. if (sp > stack)
  74565. return *--sp;
  74566. while ((code = getCode (codeSize, false)) >= 0)
  74567. {
  74568. if (code == clearCode)
  74569. {
  74570. for (i = 0; i < clearCode; ++i)
  74571. {
  74572. table[0][i] = 0;
  74573. table[1][i] = i;
  74574. }
  74575. for (; i < maxGifCode; ++i)
  74576. {
  74577. table[0][i] = 0;
  74578. table[1][i] = 0;
  74579. }
  74580. codeSize = setCodeSize + 1;
  74581. maxCodeSize = 2 * clearCode;
  74582. maxCode = clearCode + 2;
  74583. sp = stack;
  74584. firstcode = oldcode = getCode (codeSize, false);
  74585. return firstcode;
  74586. }
  74587. else if (code == end_code)
  74588. {
  74589. if (dataBlockIsZero)
  74590. return -2;
  74591. unsigned char buf [260];
  74592. int n;
  74593. while ((n = readDataBlock (buf)) > 0)
  74594. {}
  74595. if (n != 0)
  74596. return -2;
  74597. }
  74598. incode = code;
  74599. if (code >= maxCode)
  74600. {
  74601. *sp++ = firstcode;
  74602. code = oldcode;
  74603. }
  74604. while (code >= clearCode)
  74605. {
  74606. *sp++ = table[1][code];
  74607. if (code == table[0][code])
  74608. return -2;
  74609. code = table[0][code];
  74610. }
  74611. *sp++ = firstcode = table[1][code];
  74612. if ((code = maxCode) < maxGifCode)
  74613. {
  74614. table[0][code] = oldcode;
  74615. table[1][code] = firstcode;
  74616. ++maxCode;
  74617. if ((maxCode >= maxCodeSize)
  74618. && (maxCodeSize < maxGifCode))
  74619. {
  74620. maxCodeSize <<= 1;
  74621. ++codeSize;
  74622. }
  74623. }
  74624. oldcode = incode;
  74625. if (sp > stack)
  74626. return *--sp;
  74627. }
  74628. return code;
  74629. }
  74630. bool GIFLoader::readImage (const int width, const int height,
  74631. const int interlace, const int transparent)
  74632. {
  74633. unsigned char c;
  74634. if (input.read (&c, 1) != 1
  74635. || readLZWByte (true, c) < 0)
  74636. return false;
  74637. if (transparent >= 0)
  74638. {
  74639. palette [transparent][0] = 0;
  74640. palette [transparent][1] = 0;
  74641. palette [transparent][2] = 0;
  74642. palette [transparent][3] = 0;
  74643. }
  74644. int index;
  74645. int xpos = 0, ypos = 0, pass = 0;
  74646. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  74647. uint8* p = destData.data;
  74648. const bool hasAlpha = image->hasAlphaChannel();
  74649. while ((index = readLZWByte (false, c)) >= 0)
  74650. {
  74651. const uint8* const paletteEntry = palette [index];
  74652. if (hasAlpha)
  74653. {
  74654. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  74655. paletteEntry[0],
  74656. paletteEntry[1],
  74657. paletteEntry[2]);
  74658. ((PixelARGB*) p)->premultiply();
  74659. }
  74660. else
  74661. {
  74662. ((PixelRGB*) p)->setARGB (0,
  74663. paletteEntry[0],
  74664. paletteEntry[1],
  74665. paletteEntry[2]);
  74666. }
  74667. p += destData.pixelStride;
  74668. ++xpos;
  74669. if (xpos == width)
  74670. {
  74671. xpos = 0;
  74672. if (interlace)
  74673. {
  74674. switch (pass)
  74675. {
  74676. case 0:
  74677. case 1:
  74678. ypos += 8;
  74679. break;
  74680. case 2:
  74681. ypos += 4;
  74682. break;
  74683. case 3:
  74684. ypos += 2;
  74685. break;
  74686. }
  74687. while (ypos >= height)
  74688. {
  74689. ++pass;
  74690. switch (pass)
  74691. {
  74692. case 1:
  74693. ypos = 4;
  74694. break;
  74695. case 2:
  74696. ypos = 2;
  74697. break;
  74698. case 3:
  74699. ypos = 1;
  74700. break;
  74701. default:
  74702. return true;
  74703. }
  74704. }
  74705. }
  74706. else
  74707. {
  74708. ++ypos;
  74709. }
  74710. p = destData.getPixelPointer (xpos, ypos);
  74711. }
  74712. if (ypos >= height)
  74713. break;
  74714. }
  74715. return true;
  74716. }
  74717. END_JUCE_NAMESPACE
  74718. /*** End of inlined file: juce_GIFLoader.cpp ***/
  74719. #endif
  74720. //==============================================================================
  74721. // some files include lots of library code, so leave them to the end to avoid cluttering
  74722. // up the build for the clean files.
  74723. #if JUCE_BUILD_CORE
  74724. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  74725. namespace zlibNamespace
  74726. {
  74727. #if JUCE_INCLUDE_ZLIB_CODE
  74728. #undef OS_CODE
  74729. #undef fdopen
  74730. /*** Start of inlined file: zlib.h ***/
  74731. #ifndef ZLIB_H
  74732. #define ZLIB_H
  74733. /*** Start of inlined file: zconf.h ***/
  74734. #ifndef ZCONF_H
  74735. #define ZCONF_H
  74736. // *** Just a few hacks here to make it compile nicely with Juce..
  74737. #define Z_PREFIX 1
  74738. #undef __MACTYPES__
  74739. #ifdef _MSC_VER
  74740. #pragma warning (disable : 4131 4127 4244 4267)
  74741. #endif
  74742. #ifdef Z_PREFIX
  74743. # define deflateInit_ z_deflateInit_
  74744. # define deflate z_deflate
  74745. # define deflateEnd z_deflateEnd
  74746. # define inflateInit_ z_inflateInit_
  74747. # define inflate z_inflate
  74748. # define inflateEnd z_inflateEnd
  74749. # define deflateInit2_ z_deflateInit2_
  74750. # define deflateSetDictionary z_deflateSetDictionary
  74751. # define deflateCopy z_deflateCopy
  74752. # define deflateReset z_deflateReset
  74753. # define deflateParams z_deflateParams
  74754. # define deflateBound z_deflateBound
  74755. # define deflatePrime z_deflatePrime
  74756. # define inflateInit2_ z_inflateInit2_
  74757. # define inflateSetDictionary z_inflateSetDictionary
  74758. # define inflateSync z_inflateSync
  74759. # define inflateSyncPoint z_inflateSyncPoint
  74760. # define inflateCopy z_inflateCopy
  74761. # define inflateReset z_inflateReset
  74762. # define inflateBack z_inflateBack
  74763. # define inflateBackEnd z_inflateBackEnd
  74764. # define compress z_compress
  74765. # define compress2 z_compress2
  74766. # define compressBound z_compressBound
  74767. # define uncompress z_uncompress
  74768. # define adler32 z_adler32
  74769. # define crc32 z_crc32
  74770. # define get_crc_table z_get_crc_table
  74771. # define zError z_zError
  74772. # define alloc_func z_alloc_func
  74773. # define free_func z_free_func
  74774. # define in_func z_in_func
  74775. # define out_func z_out_func
  74776. # define Byte z_Byte
  74777. # define uInt z_uInt
  74778. # define uLong z_uLong
  74779. # define Bytef z_Bytef
  74780. # define charf z_charf
  74781. # define intf z_intf
  74782. # define uIntf z_uIntf
  74783. # define uLongf z_uLongf
  74784. # define voidpf z_voidpf
  74785. # define voidp z_voidp
  74786. #endif
  74787. #if defined(__MSDOS__) && !defined(MSDOS)
  74788. # define MSDOS
  74789. #endif
  74790. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  74791. # define OS2
  74792. #endif
  74793. #if defined(_WINDOWS) && !defined(WINDOWS)
  74794. # define WINDOWS
  74795. #endif
  74796. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  74797. # ifndef WIN32
  74798. # define WIN32
  74799. # endif
  74800. #endif
  74801. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  74802. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  74803. # ifndef SYS16BIT
  74804. # define SYS16BIT
  74805. # endif
  74806. # endif
  74807. #endif
  74808. #ifdef SYS16BIT
  74809. # define MAXSEG_64K
  74810. #endif
  74811. #ifdef MSDOS
  74812. # define UNALIGNED_OK
  74813. #endif
  74814. #ifdef __STDC_VERSION__
  74815. # ifndef STDC
  74816. # define STDC
  74817. # endif
  74818. # if __STDC_VERSION__ >= 199901L
  74819. # ifndef STDC99
  74820. # define STDC99
  74821. # endif
  74822. # endif
  74823. #endif
  74824. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  74825. # define STDC
  74826. #endif
  74827. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  74828. # define STDC
  74829. #endif
  74830. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  74831. # define STDC
  74832. #endif
  74833. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  74834. # define STDC
  74835. #endif
  74836. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  74837. # define STDC
  74838. #endif
  74839. #ifndef STDC
  74840. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  74841. # define const /* note: need a more gentle solution here */
  74842. # endif
  74843. #endif
  74844. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  74845. # define NO_DUMMY_DECL
  74846. #endif
  74847. #ifndef MAX_MEM_LEVEL
  74848. # ifdef MAXSEG_64K
  74849. # define MAX_MEM_LEVEL 8
  74850. # else
  74851. # define MAX_MEM_LEVEL 9
  74852. # endif
  74853. #endif
  74854. #ifndef MAX_WBITS
  74855. # define MAX_WBITS 15 /* 32K LZ77 window */
  74856. #endif
  74857. #ifndef OF /* function prototypes */
  74858. # ifdef STDC
  74859. # define OF(args) args
  74860. # else
  74861. # define OF(args) ()
  74862. # endif
  74863. #endif
  74864. #ifdef SYS16BIT
  74865. # if defined(M_I86SM) || defined(M_I86MM)
  74866. # define SMALL_MEDIUM
  74867. # ifdef _MSC_VER
  74868. # define FAR _far
  74869. # else
  74870. # define FAR far
  74871. # endif
  74872. # endif
  74873. # if (defined(__SMALL__) || defined(__MEDIUM__))
  74874. # define SMALL_MEDIUM
  74875. # ifdef __BORLANDC__
  74876. # define FAR _far
  74877. # else
  74878. # define FAR far
  74879. # endif
  74880. # endif
  74881. #endif
  74882. #if defined(WINDOWS) || defined(WIN32)
  74883. # ifdef ZLIB_DLL
  74884. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  74885. # ifdef ZLIB_INTERNAL
  74886. # define ZEXTERN extern __declspec(dllexport)
  74887. # else
  74888. # define ZEXTERN extern __declspec(dllimport)
  74889. # endif
  74890. # endif
  74891. # endif /* ZLIB_DLL */
  74892. # ifdef ZLIB_WINAPI
  74893. # ifdef FAR
  74894. # undef FAR
  74895. # endif
  74896. # include <windows.h>
  74897. # define ZEXPORT WINAPI
  74898. # ifdef WIN32
  74899. # define ZEXPORTVA WINAPIV
  74900. # else
  74901. # define ZEXPORTVA FAR CDECL
  74902. # endif
  74903. # endif
  74904. #endif
  74905. #if defined (__BEOS__)
  74906. # ifdef ZLIB_DLL
  74907. # ifdef ZLIB_INTERNAL
  74908. # define ZEXPORT __declspec(dllexport)
  74909. # define ZEXPORTVA __declspec(dllexport)
  74910. # else
  74911. # define ZEXPORT __declspec(dllimport)
  74912. # define ZEXPORTVA __declspec(dllimport)
  74913. # endif
  74914. # endif
  74915. #endif
  74916. #ifndef ZEXTERN
  74917. # define ZEXTERN extern
  74918. #endif
  74919. #ifndef ZEXPORT
  74920. # define ZEXPORT
  74921. #endif
  74922. #ifndef ZEXPORTVA
  74923. # define ZEXPORTVA
  74924. #endif
  74925. #ifndef FAR
  74926. # define FAR
  74927. #endif
  74928. #if !defined(__MACTYPES__)
  74929. typedef unsigned char Byte; /* 8 bits */
  74930. #endif
  74931. typedef unsigned int uInt; /* 16 bits or more */
  74932. typedef unsigned long uLong; /* 32 bits or more */
  74933. #ifdef SMALL_MEDIUM
  74934. # define Bytef Byte FAR
  74935. #else
  74936. typedef Byte FAR Bytef;
  74937. #endif
  74938. typedef char FAR charf;
  74939. typedef int FAR intf;
  74940. typedef uInt FAR uIntf;
  74941. typedef uLong FAR uLongf;
  74942. #ifdef STDC
  74943. typedef void const *voidpc;
  74944. typedef void FAR *voidpf;
  74945. typedef void *voidp;
  74946. #else
  74947. typedef Byte const *voidpc;
  74948. typedef Byte FAR *voidpf;
  74949. typedef Byte *voidp;
  74950. #endif
  74951. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  74952. # include <sys/types.h> /* for off_t */
  74953. # include <unistd.h> /* for SEEK_* and off_t */
  74954. # ifdef VMS
  74955. # include <unixio.h> /* for off_t */
  74956. # endif
  74957. # define z_off_t off_t
  74958. #endif
  74959. #ifndef SEEK_SET
  74960. # define SEEK_SET 0 /* Seek from beginning of file. */
  74961. # define SEEK_CUR 1 /* Seek from current position. */
  74962. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  74963. #endif
  74964. #ifndef z_off_t
  74965. # define z_off_t long
  74966. #endif
  74967. #if defined(__OS400__)
  74968. # define NO_vsnprintf
  74969. #endif
  74970. #if defined(__MVS__)
  74971. # define NO_vsnprintf
  74972. # ifdef FAR
  74973. # undef FAR
  74974. # endif
  74975. #endif
  74976. #if defined(__MVS__)
  74977. # pragma map(deflateInit_,"DEIN")
  74978. # pragma map(deflateInit2_,"DEIN2")
  74979. # pragma map(deflateEnd,"DEEND")
  74980. # pragma map(deflateBound,"DEBND")
  74981. # pragma map(inflateInit_,"ININ")
  74982. # pragma map(inflateInit2_,"ININ2")
  74983. # pragma map(inflateEnd,"INEND")
  74984. # pragma map(inflateSync,"INSY")
  74985. # pragma map(inflateSetDictionary,"INSEDI")
  74986. # pragma map(compressBound,"CMBND")
  74987. # pragma map(inflate_table,"INTABL")
  74988. # pragma map(inflate_fast,"INFA")
  74989. # pragma map(inflate_copyright,"INCOPY")
  74990. #endif
  74991. #endif /* ZCONF_H */
  74992. /*** End of inlined file: zconf.h ***/
  74993. #ifdef __cplusplus
  74994. extern "C" {
  74995. #endif
  74996. #define ZLIB_VERSION "1.2.3"
  74997. #define ZLIB_VERNUM 0x1230
  74998. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  74999. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  75000. struct internal_state;
  75001. typedef struct z_stream_s {
  75002. Bytef *next_in; /* next input byte */
  75003. uInt avail_in; /* number of bytes available at next_in */
  75004. uLong total_in; /* total nb of input bytes read so far */
  75005. Bytef *next_out; /* next output byte should be put there */
  75006. uInt avail_out; /* remaining free space at next_out */
  75007. uLong total_out; /* total nb of bytes output so far */
  75008. char *msg; /* last error message, NULL if no error */
  75009. struct internal_state FAR *state; /* not visible by applications */
  75010. alloc_func zalloc; /* used to allocate the internal state */
  75011. free_func zfree; /* used to free the internal state */
  75012. voidpf opaque; /* private data object passed to zalloc and zfree */
  75013. int data_type; /* best guess about the data type: binary or text */
  75014. uLong adler; /* adler32 value of the uncompressed data */
  75015. uLong reserved; /* reserved for future use */
  75016. } z_stream;
  75017. typedef z_stream FAR *z_streamp;
  75018. typedef struct gz_header_s {
  75019. int text; /* true if compressed data believed to be text */
  75020. uLong time; /* modification time */
  75021. int xflags; /* extra flags (not used when writing a gzip file) */
  75022. int os; /* operating system */
  75023. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75024. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75025. uInt extra_max; /* space at extra (only when reading header) */
  75026. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75027. uInt name_max; /* space at name (only when reading header) */
  75028. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75029. uInt comm_max; /* space at comment (only when reading header) */
  75030. int hcrc; /* true if there was or will be a header crc */
  75031. int done; /* true when done reading gzip header (not used
  75032. when writing a gzip file) */
  75033. } gz_header;
  75034. typedef gz_header FAR *gz_headerp;
  75035. #define Z_NO_FLUSH 0
  75036. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75037. #define Z_SYNC_FLUSH 2
  75038. #define Z_FULL_FLUSH 3
  75039. #define Z_FINISH 4
  75040. #define Z_BLOCK 5
  75041. #define Z_OK 0
  75042. #define Z_STREAM_END 1
  75043. #define Z_NEED_DICT 2
  75044. #define Z_ERRNO (-1)
  75045. #define Z_STREAM_ERROR (-2)
  75046. #define Z_DATA_ERROR (-3)
  75047. #define Z_MEM_ERROR (-4)
  75048. #define Z_BUF_ERROR (-5)
  75049. #define Z_VERSION_ERROR (-6)
  75050. #define Z_NO_COMPRESSION 0
  75051. #define Z_BEST_SPEED 1
  75052. #define Z_BEST_COMPRESSION 9
  75053. #define Z_DEFAULT_COMPRESSION (-1)
  75054. #define Z_FILTERED 1
  75055. #define Z_HUFFMAN_ONLY 2
  75056. #define Z_RLE 3
  75057. #define Z_FIXED 4
  75058. #define Z_DEFAULT_STRATEGY 0
  75059. #define Z_BINARY 0
  75060. #define Z_TEXT 1
  75061. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75062. #define Z_UNKNOWN 2
  75063. #define Z_DEFLATED 8
  75064. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75065. #define zlib_version zlibVersion()
  75066. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75067. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75068. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75069. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75070. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75071. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75072. const Bytef *dictionary,
  75073. uInt dictLength));
  75074. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75075. z_streamp source));
  75076. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75077. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75078. int level,
  75079. int strategy));
  75080. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75081. int good_length,
  75082. int max_lazy,
  75083. int nice_length,
  75084. int max_chain));
  75085. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75086. uLong sourceLen));
  75087. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75088. int bits,
  75089. int value));
  75090. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75091. gz_headerp head));
  75092. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75093. const Bytef *dictionary,
  75094. uInt dictLength));
  75095. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75096. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75097. z_streamp source));
  75098. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75099. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75100. int bits,
  75101. int value));
  75102. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75103. gz_headerp head));
  75104. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75105. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75106. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75107. in_func in, void FAR *in_desc,
  75108. out_func out, void FAR *out_desc));
  75109. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75110. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75111. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75112. const Bytef *source, uLong sourceLen));
  75113. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75114. const Bytef *source, uLong sourceLen,
  75115. int level));
  75116. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75117. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75118. const Bytef *source, uLong sourceLen));
  75119. typedef voidp gzFile;
  75120. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75121. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75122. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75123. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75124. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75125. voidpc buf, unsigned len));
  75126. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75127. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75128. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75129. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75130. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75131. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75132. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75133. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75134. z_off_t offset, int whence));
  75135. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75136. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75137. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75138. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75139. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75140. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75141. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75142. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75143. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75144. z_off_t len2));
  75145. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75146. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75147. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75148. const char *version, int stream_size));
  75149. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75150. const char *version, int stream_size));
  75151. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75152. int windowBits, int memLevel,
  75153. int strategy, const char *version,
  75154. int stream_size));
  75155. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75156. const char *version, int stream_size));
  75157. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75158. unsigned char FAR *window,
  75159. const char *version,
  75160. int stream_size));
  75161. #define deflateInit(strm, level) \
  75162. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75163. #define inflateInit(strm) \
  75164. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75165. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75166. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75167. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75168. #define inflateInit2(strm, windowBits) \
  75169. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75170. #define inflateBackInit(strm, windowBits, window) \
  75171. inflateBackInit_((strm), (windowBits), (window), \
  75172. ZLIB_VERSION, sizeof(z_stream))
  75173. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75174. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75175. #endif
  75176. ZEXTERN const char * ZEXPORT zError OF((int));
  75177. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75178. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75179. #ifdef __cplusplus
  75180. }
  75181. #endif
  75182. #endif /* ZLIB_H */
  75183. /*** End of inlined file: zlib.h ***/
  75184. #undef OS_CODE
  75185. #else
  75186. #include <zlib.h>
  75187. #endif
  75188. }
  75189. BEGIN_JUCE_NAMESPACE
  75190. // internal helper object that holds the zlib structures so they don't have to be
  75191. // included publicly.
  75192. class GZIPCompressorHelper
  75193. {
  75194. public:
  75195. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75196. : data (0),
  75197. dataSize (0),
  75198. compLevel (compressionLevel),
  75199. strategy (0),
  75200. setParams (true),
  75201. streamIsValid (false),
  75202. finished (false),
  75203. shouldFinish (false)
  75204. {
  75205. using namespace zlibNamespace;
  75206. zerostruct (stream);
  75207. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75208. nowrap ? -MAX_WBITS : MAX_WBITS,
  75209. 8, strategy) == Z_OK);
  75210. }
  75211. ~GZIPCompressorHelper()
  75212. {
  75213. using namespace zlibNamespace;
  75214. if (streamIsValid)
  75215. deflateEnd (&stream);
  75216. }
  75217. bool needsInput() const throw()
  75218. {
  75219. return dataSize <= 0;
  75220. }
  75221. void setInput (uint8* const newData, const int size) throw()
  75222. {
  75223. data = newData;
  75224. dataSize = size;
  75225. }
  75226. int doNextBlock (uint8* const dest, const int destSize) throw()
  75227. {
  75228. using namespace zlibNamespace;
  75229. if (streamIsValid)
  75230. {
  75231. stream.next_in = data;
  75232. stream.next_out = dest;
  75233. stream.avail_in = dataSize;
  75234. stream.avail_out = destSize;
  75235. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75236. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75237. setParams = false;
  75238. switch (result)
  75239. {
  75240. case Z_STREAM_END:
  75241. finished = true;
  75242. // Deliberate fall-through..
  75243. case Z_OK:
  75244. data += dataSize - stream.avail_in;
  75245. dataSize = stream.avail_in;
  75246. return destSize - stream.avail_out;
  75247. default:
  75248. break;
  75249. }
  75250. }
  75251. return 0;
  75252. }
  75253. private:
  75254. zlibNamespace::z_stream stream;
  75255. uint8* data;
  75256. int dataSize, compLevel, strategy;
  75257. bool setParams, streamIsValid;
  75258. public:
  75259. bool finished, shouldFinish;
  75260. };
  75261. const int gzipCompBufferSize = 32768;
  75262. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75263. int compressionLevel,
  75264. const bool deleteDestStream,
  75265. const bool noWrap)
  75266. : destStream (destStream_),
  75267. streamToDelete (deleteDestStream ? destStream_ : 0),
  75268. buffer (gzipCompBufferSize)
  75269. {
  75270. if (compressionLevel < 1 || compressionLevel > 9)
  75271. compressionLevel = -1;
  75272. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75273. }
  75274. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75275. {
  75276. flush();
  75277. }
  75278. void GZIPCompressorOutputStream::flush()
  75279. {
  75280. if (! helper->finished)
  75281. {
  75282. helper->shouldFinish = true;
  75283. while (! helper->finished)
  75284. doNextBlock();
  75285. }
  75286. destStream->flush();
  75287. }
  75288. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75289. {
  75290. if (! helper->finished)
  75291. {
  75292. helper->setInput ((uint8*) destBuffer, howMany);
  75293. while (! helper->needsInput())
  75294. {
  75295. if (! doNextBlock())
  75296. return false;
  75297. }
  75298. }
  75299. return true;
  75300. }
  75301. bool GZIPCompressorOutputStream::doNextBlock()
  75302. {
  75303. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75304. if (len > 0)
  75305. return destStream->write (buffer, len);
  75306. else
  75307. return true;
  75308. }
  75309. int64 GZIPCompressorOutputStream::getPosition()
  75310. {
  75311. return destStream->getPosition();
  75312. }
  75313. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75314. {
  75315. jassertfalse // can't do it!
  75316. return false;
  75317. }
  75318. END_JUCE_NAMESPACE
  75319. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75320. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75321. #if JUCE_MSVC
  75322. #pragma warning (push)
  75323. #pragma warning (disable: 4309 4305)
  75324. #endif
  75325. namespace zlibNamespace
  75326. {
  75327. #if JUCE_INCLUDE_ZLIB_CODE
  75328. extern "C"
  75329. {
  75330. #undef OS_CODE
  75331. #undef fdopen
  75332. #define ZLIB_INTERNAL
  75333. #define NO_DUMMY_DECL
  75334. /*** Start of inlined file: adler32.c ***/
  75335. #define ZLIB_INTERNAL
  75336. #define BASE 65521UL /* largest prime smaller than 65536 */
  75337. #define NMAX 5552
  75338. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75339. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75340. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75341. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75342. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75343. #ifdef NO_DIVIDE
  75344. # define MOD(a) \
  75345. do { \
  75346. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75347. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75348. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75349. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75350. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75351. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75352. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75353. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75354. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75355. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75356. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75357. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75358. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75359. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75360. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75361. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75362. if (a >= BASE) a -= BASE; \
  75363. } while (0)
  75364. # define MOD4(a) \
  75365. do { \
  75366. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75367. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75368. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75369. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75370. if (a >= BASE) a -= BASE; \
  75371. } while (0)
  75372. #else
  75373. # define MOD(a) a %= BASE
  75374. # define MOD4(a) a %= BASE
  75375. #endif
  75376. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75377. {
  75378. unsigned long sum2;
  75379. unsigned n;
  75380. sum2 = (adler >> 16) & 0xffff;
  75381. adler &= 0xffff;
  75382. if (len == 1) {
  75383. adler += buf[0];
  75384. if (adler >= BASE)
  75385. adler -= BASE;
  75386. sum2 += adler;
  75387. if (sum2 >= BASE)
  75388. sum2 -= BASE;
  75389. return adler | (sum2 << 16);
  75390. }
  75391. if (buf == Z_NULL)
  75392. return 1L;
  75393. if (len < 16) {
  75394. while (len--) {
  75395. adler += *buf++;
  75396. sum2 += adler;
  75397. }
  75398. if (adler >= BASE)
  75399. adler -= BASE;
  75400. MOD4(sum2); /* only added so many BASE's */
  75401. return adler | (sum2 << 16);
  75402. }
  75403. while (len >= NMAX) {
  75404. len -= NMAX;
  75405. n = NMAX / 16; /* NMAX is divisible by 16 */
  75406. do {
  75407. DO16(buf); /* 16 sums unrolled */
  75408. buf += 16;
  75409. } while (--n);
  75410. MOD(adler);
  75411. MOD(sum2);
  75412. }
  75413. if (len) { /* avoid modulos if none remaining */
  75414. while (len >= 16) {
  75415. len -= 16;
  75416. DO16(buf);
  75417. buf += 16;
  75418. }
  75419. while (len--) {
  75420. adler += *buf++;
  75421. sum2 += adler;
  75422. }
  75423. MOD(adler);
  75424. MOD(sum2);
  75425. }
  75426. return adler | (sum2 << 16);
  75427. }
  75428. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75429. {
  75430. unsigned long sum1;
  75431. unsigned long sum2;
  75432. unsigned rem;
  75433. rem = (unsigned)(len2 % BASE);
  75434. sum1 = adler1 & 0xffff;
  75435. sum2 = rem * sum1;
  75436. MOD(sum2);
  75437. sum1 += (adler2 & 0xffff) + BASE - 1;
  75438. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75439. if (sum1 > BASE) sum1 -= BASE;
  75440. if (sum1 > BASE) sum1 -= BASE;
  75441. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75442. if (sum2 > BASE) sum2 -= BASE;
  75443. return sum1 | (sum2 << 16);
  75444. }
  75445. /*** End of inlined file: adler32.c ***/
  75446. /*** Start of inlined file: compress.c ***/
  75447. #define ZLIB_INTERNAL
  75448. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75449. uLong sourceLen, int level)
  75450. {
  75451. z_stream stream;
  75452. int err;
  75453. stream.next_in = (Bytef*)source;
  75454. stream.avail_in = (uInt)sourceLen;
  75455. #ifdef MAXSEG_64K
  75456. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75457. #endif
  75458. stream.next_out = dest;
  75459. stream.avail_out = (uInt)*destLen;
  75460. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75461. stream.zalloc = (alloc_func)0;
  75462. stream.zfree = (free_func)0;
  75463. stream.opaque = (voidpf)0;
  75464. err = deflateInit(&stream, level);
  75465. if (err != Z_OK) return err;
  75466. err = deflate(&stream, Z_FINISH);
  75467. if (err != Z_STREAM_END) {
  75468. deflateEnd(&stream);
  75469. return err == Z_OK ? Z_BUF_ERROR : err;
  75470. }
  75471. *destLen = stream.total_out;
  75472. err = deflateEnd(&stream);
  75473. return err;
  75474. }
  75475. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75476. {
  75477. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75478. }
  75479. uLong ZEXPORT compressBound (uLong sourceLen)
  75480. {
  75481. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75482. }
  75483. /*** End of inlined file: compress.c ***/
  75484. #undef DO1
  75485. #undef DO8
  75486. /*** Start of inlined file: crc32.c ***/
  75487. #ifdef MAKECRCH
  75488. # include <stdio.h>
  75489. # ifndef DYNAMIC_CRC_TABLE
  75490. # define DYNAMIC_CRC_TABLE
  75491. # endif /* !DYNAMIC_CRC_TABLE */
  75492. #endif /* MAKECRCH */
  75493. /*** Start of inlined file: zutil.h ***/
  75494. #ifndef ZUTIL_H
  75495. #define ZUTIL_H
  75496. #define ZLIB_INTERNAL
  75497. #ifdef STDC
  75498. # ifndef _WIN32_WCE
  75499. # include <stddef.h>
  75500. # endif
  75501. # include <string.h>
  75502. # include <stdlib.h>
  75503. #endif
  75504. #ifdef NO_ERRNO_H
  75505. # ifdef _WIN32_WCE
  75506. # define errno z_errno
  75507. # endif
  75508. extern int errno;
  75509. #else
  75510. # ifndef _WIN32_WCE
  75511. # include <errno.h>
  75512. # endif
  75513. #endif
  75514. #ifndef local
  75515. # define local static
  75516. #endif
  75517. typedef unsigned char uch;
  75518. typedef uch FAR uchf;
  75519. typedef unsigned short ush;
  75520. typedef ush FAR ushf;
  75521. typedef unsigned long ulg;
  75522. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  75523. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  75524. #define ERR_RETURN(strm,err) \
  75525. return (strm->msg = (char*)ERR_MSG(err), (err))
  75526. #ifndef DEF_WBITS
  75527. # define DEF_WBITS MAX_WBITS
  75528. #endif
  75529. #if MAX_MEM_LEVEL >= 8
  75530. # define DEF_MEM_LEVEL 8
  75531. #else
  75532. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  75533. #endif
  75534. #define STORED_BLOCK 0
  75535. #define STATIC_TREES 1
  75536. #define DYN_TREES 2
  75537. #define MIN_MATCH 3
  75538. #define MAX_MATCH 258
  75539. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  75540. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  75541. # define OS_CODE 0x00
  75542. # if defined(__TURBOC__) || defined(__BORLANDC__)
  75543. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  75544. void _Cdecl farfree( void *block );
  75545. void *_Cdecl farmalloc( unsigned long nbytes );
  75546. # else
  75547. # include <alloc.h>
  75548. # endif
  75549. # else /* MSC or DJGPP */
  75550. # include <malloc.h>
  75551. # endif
  75552. #endif
  75553. #ifdef AMIGA
  75554. # define OS_CODE 0x01
  75555. #endif
  75556. #if defined(VAXC) || defined(VMS)
  75557. # define OS_CODE 0x02
  75558. # define F_OPEN(name, mode) \
  75559. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  75560. #endif
  75561. #if defined(ATARI) || defined(atarist)
  75562. # define OS_CODE 0x05
  75563. #endif
  75564. #ifdef OS2
  75565. # define OS_CODE 0x06
  75566. # ifdef M_I86
  75567. #include <malloc.h>
  75568. # endif
  75569. #endif
  75570. #if defined(MACOS) || TARGET_OS_MAC
  75571. # define OS_CODE 0x07
  75572. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  75573. # include <unix.h> /* for fdopen */
  75574. # else
  75575. # ifndef fdopen
  75576. # define fdopen(fd,mode) NULL /* No fdopen() */
  75577. # endif
  75578. # endif
  75579. #endif
  75580. #ifdef TOPS20
  75581. # define OS_CODE 0x0a
  75582. #endif
  75583. #ifdef WIN32
  75584. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  75585. # define OS_CODE 0x0b
  75586. # endif
  75587. #endif
  75588. #ifdef __50SERIES /* Prime/PRIMOS */
  75589. # define OS_CODE 0x0f
  75590. #endif
  75591. #if defined(_BEOS_) || defined(RISCOS)
  75592. # define fdopen(fd,mode) NULL /* No fdopen() */
  75593. #endif
  75594. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  75595. # if defined(_WIN32_WCE)
  75596. # define fdopen(fd,mode) NULL /* No fdopen() */
  75597. # ifndef _PTRDIFF_T_DEFINED
  75598. typedef int ptrdiff_t;
  75599. # define _PTRDIFF_T_DEFINED
  75600. # endif
  75601. # else
  75602. # define fdopen(fd,type) _fdopen(fd,type)
  75603. # endif
  75604. #endif
  75605. #ifndef OS_CODE
  75606. # define OS_CODE 0x03 /* assume Unix */
  75607. #endif
  75608. #ifndef F_OPEN
  75609. # define F_OPEN(name, mode) fopen((name), (mode))
  75610. #endif
  75611. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  75612. # ifndef HAVE_VSNPRINTF
  75613. # define HAVE_VSNPRINTF
  75614. # endif
  75615. #endif
  75616. #if defined(__CYGWIN__)
  75617. # ifndef HAVE_VSNPRINTF
  75618. # define HAVE_VSNPRINTF
  75619. # endif
  75620. #endif
  75621. #ifndef HAVE_VSNPRINTF
  75622. # ifdef MSDOS
  75623. # define NO_vsnprintf
  75624. # endif
  75625. # ifdef __TURBOC__
  75626. # define NO_vsnprintf
  75627. # endif
  75628. # ifdef WIN32
  75629. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  75630. # define vsnprintf _vsnprintf
  75631. # endif
  75632. # endif
  75633. # ifdef __SASC
  75634. # define NO_vsnprintf
  75635. # endif
  75636. #endif
  75637. #ifdef VMS
  75638. # define NO_vsnprintf
  75639. #endif
  75640. #if defined(pyr)
  75641. # define NO_MEMCPY
  75642. #endif
  75643. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  75644. # define NO_MEMCPY
  75645. #endif
  75646. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  75647. # define HAVE_MEMCPY
  75648. #endif
  75649. #ifdef HAVE_MEMCPY
  75650. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  75651. # define zmemcpy _fmemcpy
  75652. # define zmemcmp _fmemcmp
  75653. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  75654. # else
  75655. # define zmemcpy memcpy
  75656. # define zmemcmp memcmp
  75657. # define zmemzero(dest, len) memset(dest, 0, len)
  75658. # endif
  75659. #else
  75660. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  75661. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  75662. extern void zmemzero OF((Bytef* dest, uInt len));
  75663. #endif
  75664. #ifdef DEBUG
  75665. # include <stdio.h>
  75666. extern int z_verbose;
  75667. extern void z_error OF((const char *m));
  75668. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  75669. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  75670. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  75671. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  75672. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  75673. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  75674. #else
  75675. # define Assert(cond,msg)
  75676. # define Trace(x)
  75677. # define Tracev(x)
  75678. # define Tracevv(x)
  75679. # define Tracec(c,x)
  75680. # define Tracecv(c,x)
  75681. #endif
  75682. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  75683. void zcfree OF((voidpf opaque, voidpf ptr));
  75684. #define ZALLOC(strm, items, size) \
  75685. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  75686. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  75687. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  75688. #endif /* ZUTIL_H */
  75689. /*** End of inlined file: zutil.h ***/
  75690. /* for STDC and FAR definitions */
  75691. #define local static
  75692. #ifndef NOBYFOUR
  75693. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  75694. # include <limits.h>
  75695. # define BYFOUR
  75696. # if (UINT_MAX == 0xffffffffUL)
  75697. typedef unsigned int u4;
  75698. # else
  75699. # if (ULONG_MAX == 0xffffffffUL)
  75700. typedef unsigned long u4;
  75701. # else
  75702. # if (USHRT_MAX == 0xffffffffUL)
  75703. typedef unsigned short u4;
  75704. # else
  75705. # undef BYFOUR /* can't find a four-byte integer type! */
  75706. # endif
  75707. # endif
  75708. # endif
  75709. # endif /* STDC */
  75710. #endif /* !NOBYFOUR */
  75711. #ifdef BYFOUR
  75712. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  75713. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  75714. local unsigned long crc32_little OF((unsigned long,
  75715. const unsigned char FAR *, unsigned));
  75716. local unsigned long crc32_big OF((unsigned long,
  75717. const unsigned char FAR *, unsigned));
  75718. # define TBLS 8
  75719. #else
  75720. # define TBLS 1
  75721. #endif /* BYFOUR */
  75722. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  75723. unsigned long vec));
  75724. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  75725. #ifdef DYNAMIC_CRC_TABLE
  75726. local volatile int crc_table_empty = 1;
  75727. local unsigned long FAR crc_table[TBLS][256];
  75728. local void make_crc_table OF((void));
  75729. #ifdef MAKECRCH
  75730. local void write_table OF((FILE *, const unsigned long FAR *));
  75731. #endif /* MAKECRCH */
  75732. local void make_crc_table()
  75733. {
  75734. unsigned long c;
  75735. int n, k;
  75736. unsigned long poly; /* polynomial exclusive-or pattern */
  75737. static volatile int first = 1; /* flag to limit concurrent making */
  75738. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  75739. if (first) {
  75740. first = 0;
  75741. poly = 0UL;
  75742. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  75743. poly |= 1UL << (31 - p[n]);
  75744. for (n = 0; n < 256; n++) {
  75745. c = (unsigned long)n;
  75746. for (k = 0; k < 8; k++)
  75747. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  75748. crc_table[0][n] = c;
  75749. }
  75750. #ifdef BYFOUR
  75751. for (n = 0; n < 256; n++) {
  75752. c = crc_table[0][n];
  75753. crc_table[4][n] = REV(c);
  75754. for (k = 1; k < 4; k++) {
  75755. c = crc_table[0][c & 0xff] ^ (c >> 8);
  75756. crc_table[k][n] = c;
  75757. crc_table[k + 4][n] = REV(c);
  75758. }
  75759. }
  75760. #endif /* BYFOUR */
  75761. crc_table_empty = 0;
  75762. }
  75763. else { /* not first */
  75764. while (crc_table_empty)
  75765. ;
  75766. }
  75767. #ifdef MAKECRCH
  75768. {
  75769. FILE *out;
  75770. out = fopen("crc32.h", "w");
  75771. if (out == NULL) return;
  75772. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  75773. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  75774. fprintf(out, "local const unsigned long FAR ");
  75775. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  75776. write_table(out, crc_table[0]);
  75777. # ifdef BYFOUR
  75778. fprintf(out, "#ifdef BYFOUR\n");
  75779. for (k = 1; k < 8; k++) {
  75780. fprintf(out, " },\n {\n");
  75781. write_table(out, crc_table[k]);
  75782. }
  75783. fprintf(out, "#endif\n");
  75784. # endif /* BYFOUR */
  75785. fprintf(out, " }\n};\n");
  75786. fclose(out);
  75787. }
  75788. #endif /* MAKECRCH */
  75789. }
  75790. #ifdef MAKECRCH
  75791. local void write_table(out, table)
  75792. FILE *out;
  75793. const unsigned long FAR *table;
  75794. {
  75795. int n;
  75796. for (n = 0; n < 256; n++)
  75797. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  75798. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  75799. }
  75800. #endif /* MAKECRCH */
  75801. #else /* !DYNAMIC_CRC_TABLE */
  75802. /*** Start of inlined file: crc32.h ***/
  75803. local const unsigned long FAR crc_table[TBLS][256] =
  75804. {
  75805. {
  75806. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  75807. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  75808. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  75809. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  75810. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  75811. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  75812. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  75813. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  75814. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  75815. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  75816. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  75817. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  75818. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  75819. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  75820. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  75821. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  75822. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  75823. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  75824. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  75825. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  75826. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  75827. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  75828. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  75829. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  75830. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  75831. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  75832. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  75833. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  75834. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  75835. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  75836. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  75837. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  75838. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  75839. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  75840. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  75841. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  75842. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  75843. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  75844. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  75845. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  75846. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  75847. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  75848. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  75849. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  75850. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  75851. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  75852. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  75853. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  75854. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  75855. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  75856. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  75857. 0x2d02ef8dUL
  75858. #ifdef BYFOUR
  75859. },
  75860. {
  75861. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  75862. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  75863. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  75864. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  75865. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  75866. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  75867. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  75868. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  75869. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  75870. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  75871. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  75872. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  75873. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  75874. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  75875. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  75876. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  75877. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  75878. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  75879. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  75880. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  75881. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  75882. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  75883. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  75884. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  75885. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  75886. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  75887. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  75888. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  75889. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  75890. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  75891. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  75892. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  75893. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  75894. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  75895. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  75896. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  75897. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  75898. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  75899. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  75900. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  75901. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  75902. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  75903. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  75904. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  75905. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  75906. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  75907. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  75908. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  75909. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  75910. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  75911. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  75912. 0x9324fd72UL
  75913. },
  75914. {
  75915. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  75916. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  75917. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  75918. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  75919. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  75920. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  75921. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  75922. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  75923. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  75924. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  75925. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  75926. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  75927. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  75928. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  75929. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  75930. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  75931. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  75932. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  75933. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  75934. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  75935. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  75936. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  75937. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  75938. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  75939. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  75940. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  75941. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  75942. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  75943. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  75944. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  75945. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  75946. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  75947. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  75948. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  75949. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  75950. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  75951. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  75952. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  75953. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  75954. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  75955. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  75956. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  75957. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  75958. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  75959. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  75960. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  75961. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  75962. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  75963. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  75964. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  75965. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  75966. 0xbe9834edUL
  75967. },
  75968. {
  75969. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  75970. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  75971. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  75972. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  75973. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  75974. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  75975. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  75976. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  75977. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  75978. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  75979. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  75980. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  75981. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  75982. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  75983. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  75984. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  75985. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  75986. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  75987. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  75988. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  75989. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  75990. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  75991. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  75992. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  75993. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  75994. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  75995. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  75996. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  75997. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  75998. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  75999. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  76000. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  76001. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  76002. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  76003. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  76004. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  76005. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  76006. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  76007. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  76008. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  76009. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  76010. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76011. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76012. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76013. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76014. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76015. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76016. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76017. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76018. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76019. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76020. 0xde0506f1UL
  76021. },
  76022. {
  76023. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76024. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76025. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76026. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76027. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76028. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76029. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76030. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76031. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76032. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76033. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76034. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76035. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76036. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76037. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76038. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76039. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76040. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76041. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76042. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76043. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76044. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76045. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76046. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76047. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76048. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76049. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76050. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76051. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76052. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76053. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76054. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76055. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76056. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76057. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76058. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76059. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76060. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76061. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76062. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76063. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76064. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76065. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76066. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76067. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76068. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76069. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76070. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76071. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76072. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76073. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76074. 0x8def022dUL
  76075. },
  76076. {
  76077. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76078. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76079. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76080. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76081. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76082. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76083. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76084. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76085. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76086. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76087. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76088. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76089. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76090. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76091. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76092. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76093. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76094. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76095. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76096. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76097. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76098. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76099. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76100. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76101. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76102. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76103. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76104. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76105. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76106. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76107. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76108. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76109. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76110. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76111. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76112. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76113. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76114. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76115. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76116. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76117. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76118. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76119. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76120. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76121. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76122. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76123. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76124. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76125. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76126. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76127. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76128. 0x72fd2493UL
  76129. },
  76130. {
  76131. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76132. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76133. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76134. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76135. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76136. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76137. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76138. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76139. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76140. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76141. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76142. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76143. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76144. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76145. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76146. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76147. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76148. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76149. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76150. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76151. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76152. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76153. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76154. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76155. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76156. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76157. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76158. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76159. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76160. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76161. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76162. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76163. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76164. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76165. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76166. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76167. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76168. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76169. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76170. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76171. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76172. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76173. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76174. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76175. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76176. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76177. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76178. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76179. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76180. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76181. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76182. 0xed3498beUL
  76183. },
  76184. {
  76185. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76186. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76187. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76188. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76189. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76190. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76191. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76192. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76193. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76194. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76195. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76196. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76197. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76198. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76199. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76200. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76201. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76202. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76203. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76204. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76205. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76206. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76207. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76208. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76209. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76210. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76211. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76212. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76213. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76214. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76215. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76216. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76217. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76218. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76219. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76220. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76221. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76222. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76223. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76224. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76225. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76226. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76227. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76228. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76229. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76230. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76231. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76232. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76233. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76234. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76235. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76236. 0xf10605deUL
  76237. #endif
  76238. }
  76239. };
  76240. /*** End of inlined file: crc32.h ***/
  76241. #endif /* DYNAMIC_CRC_TABLE */
  76242. const unsigned long FAR * ZEXPORT get_crc_table()
  76243. {
  76244. #ifdef DYNAMIC_CRC_TABLE
  76245. if (crc_table_empty)
  76246. make_crc_table();
  76247. #endif /* DYNAMIC_CRC_TABLE */
  76248. return (const unsigned long FAR *)crc_table;
  76249. }
  76250. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76251. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76252. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76253. {
  76254. if (buf == Z_NULL) return 0UL;
  76255. #ifdef DYNAMIC_CRC_TABLE
  76256. if (crc_table_empty)
  76257. make_crc_table();
  76258. #endif /* DYNAMIC_CRC_TABLE */
  76259. #ifdef BYFOUR
  76260. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76261. u4 endian;
  76262. endian = 1;
  76263. if (*((unsigned char *)(&endian)))
  76264. return crc32_little(crc, buf, len);
  76265. else
  76266. return crc32_big(crc, buf, len);
  76267. }
  76268. #endif /* BYFOUR */
  76269. crc = crc ^ 0xffffffffUL;
  76270. while (len >= 8) {
  76271. DO8;
  76272. len -= 8;
  76273. }
  76274. if (len) do {
  76275. DO1;
  76276. } while (--len);
  76277. return crc ^ 0xffffffffUL;
  76278. }
  76279. #ifdef BYFOUR
  76280. #define DOLIT4 c ^= *buf4++; \
  76281. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76282. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76283. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76284. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76285. {
  76286. register u4 c;
  76287. register const u4 FAR *buf4;
  76288. c = (u4)crc;
  76289. c = ~c;
  76290. while (len && ((ptrdiff_t)buf & 3)) {
  76291. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76292. len--;
  76293. }
  76294. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76295. while (len >= 32) {
  76296. DOLIT32;
  76297. len -= 32;
  76298. }
  76299. while (len >= 4) {
  76300. DOLIT4;
  76301. len -= 4;
  76302. }
  76303. buf = (const unsigned char FAR *)buf4;
  76304. if (len) do {
  76305. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76306. } while (--len);
  76307. c = ~c;
  76308. return (unsigned long)c;
  76309. }
  76310. #define DOBIG4 c ^= *++buf4; \
  76311. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76312. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76313. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76314. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76315. {
  76316. register u4 c;
  76317. register const u4 FAR *buf4;
  76318. c = REV((u4)crc);
  76319. c = ~c;
  76320. while (len && ((ptrdiff_t)buf & 3)) {
  76321. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76322. len--;
  76323. }
  76324. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76325. buf4--;
  76326. while (len >= 32) {
  76327. DOBIG32;
  76328. len -= 32;
  76329. }
  76330. while (len >= 4) {
  76331. DOBIG4;
  76332. len -= 4;
  76333. }
  76334. buf4++;
  76335. buf = (const unsigned char FAR *)buf4;
  76336. if (len) do {
  76337. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76338. } while (--len);
  76339. c = ~c;
  76340. return (unsigned long)(REV(c));
  76341. }
  76342. #endif /* BYFOUR */
  76343. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76344. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76345. {
  76346. unsigned long sum;
  76347. sum = 0;
  76348. while (vec) {
  76349. if (vec & 1)
  76350. sum ^= *mat;
  76351. vec >>= 1;
  76352. mat++;
  76353. }
  76354. return sum;
  76355. }
  76356. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76357. {
  76358. int n;
  76359. for (n = 0; n < GF2_DIM; n++)
  76360. square[n] = gf2_matrix_times(mat, mat[n]);
  76361. }
  76362. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76363. {
  76364. int n;
  76365. unsigned long row;
  76366. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76367. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76368. if (len2 == 0)
  76369. return crc1;
  76370. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76371. row = 1;
  76372. for (n = 1; n < GF2_DIM; n++) {
  76373. odd[n] = row;
  76374. row <<= 1;
  76375. }
  76376. gf2_matrix_square(even, odd);
  76377. gf2_matrix_square(odd, even);
  76378. do {
  76379. gf2_matrix_square(even, odd);
  76380. if (len2 & 1)
  76381. crc1 = gf2_matrix_times(even, crc1);
  76382. len2 >>= 1;
  76383. if (len2 == 0)
  76384. break;
  76385. gf2_matrix_square(odd, even);
  76386. if (len2 & 1)
  76387. crc1 = gf2_matrix_times(odd, crc1);
  76388. len2 >>= 1;
  76389. } while (len2 != 0);
  76390. crc1 ^= crc2;
  76391. return crc1;
  76392. }
  76393. /*** End of inlined file: crc32.c ***/
  76394. /*** Start of inlined file: deflate.c ***/
  76395. /*** Start of inlined file: deflate.h ***/
  76396. #ifndef DEFLATE_H
  76397. #define DEFLATE_H
  76398. #ifndef NO_GZIP
  76399. # define GZIP
  76400. #endif
  76401. #define NO_DUMMY_DECL
  76402. #define LENGTH_CODES 29
  76403. #define LITERALS 256
  76404. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76405. #define D_CODES 30
  76406. #define BL_CODES 19
  76407. #define HEAP_SIZE (2*L_CODES+1)
  76408. #define MAX_BITS 15
  76409. #define INIT_STATE 42
  76410. #define EXTRA_STATE 69
  76411. #define NAME_STATE 73
  76412. #define COMMENT_STATE 91
  76413. #define HCRC_STATE 103
  76414. #define BUSY_STATE 113
  76415. #define FINISH_STATE 666
  76416. typedef struct ct_data_s {
  76417. union {
  76418. ush freq; /* frequency count */
  76419. ush code; /* bit string */
  76420. } fc;
  76421. union {
  76422. ush dad; /* father node in Huffman tree */
  76423. ush len; /* length of bit string */
  76424. } dl;
  76425. } FAR ct_data;
  76426. #define Freq fc.freq
  76427. #define Code fc.code
  76428. #define Dad dl.dad
  76429. #define Len dl.len
  76430. typedef struct static_tree_desc_s static_tree_desc;
  76431. typedef struct tree_desc_s {
  76432. ct_data *dyn_tree; /* the dynamic tree */
  76433. int max_code; /* largest code with non zero frequency */
  76434. static_tree_desc *stat_desc; /* the corresponding static tree */
  76435. } FAR tree_desc;
  76436. typedef ush Pos;
  76437. typedef Pos FAR Posf;
  76438. typedef unsigned IPos;
  76439. typedef struct internal_state {
  76440. z_streamp strm; /* pointer back to this zlib stream */
  76441. int status; /* as the name implies */
  76442. Bytef *pending_buf; /* output still pending */
  76443. ulg pending_buf_size; /* size of pending_buf */
  76444. Bytef *pending_out; /* next pending byte to output to the stream */
  76445. uInt pending; /* nb of bytes in the pending buffer */
  76446. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76447. gz_headerp gzhead; /* gzip header information to write */
  76448. uInt gzindex; /* where in extra, name, or comment */
  76449. Byte method; /* STORED (for zip only) or DEFLATED */
  76450. int last_flush; /* value of flush param for previous deflate call */
  76451. uInt w_size; /* LZ77 window size (32K by default) */
  76452. uInt w_bits; /* log2(w_size) (8..16) */
  76453. uInt w_mask; /* w_size - 1 */
  76454. Bytef *window;
  76455. ulg window_size;
  76456. Posf *prev;
  76457. Posf *head; /* Heads of the hash chains or NIL. */
  76458. uInt ins_h; /* hash index of string to be inserted */
  76459. uInt hash_size; /* number of elements in hash table */
  76460. uInt hash_bits; /* log2(hash_size) */
  76461. uInt hash_mask; /* hash_size-1 */
  76462. uInt hash_shift;
  76463. long block_start;
  76464. uInt match_length; /* length of best match */
  76465. IPos prev_match; /* previous match */
  76466. int match_available; /* set if previous match exists */
  76467. uInt strstart; /* start of string to insert */
  76468. uInt match_start; /* start of matching string */
  76469. uInt lookahead; /* number of valid bytes ahead in window */
  76470. uInt prev_length;
  76471. uInt max_chain_length;
  76472. uInt max_lazy_match;
  76473. # define max_insert_length max_lazy_match
  76474. int level; /* compression level (1..9) */
  76475. int strategy; /* favor or force Huffman coding*/
  76476. uInt good_match;
  76477. int nice_match; /* Stop searching when current match exceeds this */
  76478. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76479. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76480. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76481. struct tree_desc_s l_desc; /* desc. for literal tree */
  76482. struct tree_desc_s d_desc; /* desc. for distance tree */
  76483. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76484. ush bl_count[MAX_BITS+1];
  76485. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76486. int heap_len; /* number of elements in the heap */
  76487. int heap_max; /* element of largest frequency */
  76488. uch depth[2*L_CODES+1];
  76489. uchf *l_buf; /* buffer for literals or lengths */
  76490. uInt lit_bufsize;
  76491. uInt last_lit; /* running index in l_buf */
  76492. ushf *d_buf;
  76493. ulg opt_len; /* bit length of current block with optimal trees */
  76494. ulg static_len; /* bit length of current block with static trees */
  76495. uInt matches; /* number of string matches in current block */
  76496. int last_eob_len; /* bit length of EOB code for last block */
  76497. #ifdef DEBUG
  76498. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76499. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76500. #endif
  76501. ush bi_buf;
  76502. int bi_valid;
  76503. } FAR deflate_state;
  76504. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76505. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76506. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76507. void _tr_init OF((deflate_state *s));
  76508. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76509. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76510. int eof));
  76511. void _tr_align OF((deflate_state *s));
  76512. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76513. int eof));
  76514. #define d_code(dist) \
  76515. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76516. #ifndef DEBUG
  76517. #if defined(GEN_TREES_H) || !defined(STDC)
  76518. extern uch _length_code[];
  76519. extern uch _dist_code[];
  76520. #else
  76521. extern const uch _length_code[];
  76522. extern const uch _dist_code[];
  76523. #endif
  76524. # define _tr_tally_lit(s, c, flush) \
  76525. { uch cc = (c); \
  76526. s->d_buf[s->last_lit] = 0; \
  76527. s->l_buf[s->last_lit++] = cc; \
  76528. s->dyn_ltree[cc].Freq++; \
  76529. flush = (s->last_lit == s->lit_bufsize-1); \
  76530. }
  76531. # define _tr_tally_dist(s, distance, length, flush) \
  76532. { uch len = (length); \
  76533. ush dist = (distance); \
  76534. s->d_buf[s->last_lit] = dist; \
  76535. s->l_buf[s->last_lit++] = len; \
  76536. dist--; \
  76537. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  76538. s->dyn_dtree[d_code(dist)].Freq++; \
  76539. flush = (s->last_lit == s->lit_bufsize-1); \
  76540. }
  76541. #else
  76542. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  76543. # define _tr_tally_dist(s, distance, length, flush) \
  76544. flush = _tr_tally(s, distance, length)
  76545. #endif
  76546. #endif /* DEFLATE_H */
  76547. /*** End of inlined file: deflate.h ***/
  76548. const char deflate_copyright[] =
  76549. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  76550. typedef enum {
  76551. need_more, /* block not completed, need more input or more output */
  76552. block_done, /* block flush performed */
  76553. finish_started, /* finish started, need only more output at next deflate */
  76554. finish_done /* finish done, accept no more input or output */
  76555. } block_state;
  76556. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  76557. local void fill_window OF((deflate_state *s));
  76558. local block_state deflate_stored OF((deflate_state *s, int flush));
  76559. local block_state deflate_fast OF((deflate_state *s, int flush));
  76560. #ifndef FASTEST
  76561. local block_state deflate_slow OF((deflate_state *s, int flush));
  76562. #endif
  76563. local void lm_init OF((deflate_state *s));
  76564. local void putShortMSB OF((deflate_state *s, uInt b));
  76565. local void flush_pending OF((z_streamp strm));
  76566. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  76567. #ifndef FASTEST
  76568. #ifdef ASMV
  76569. void match_init OF((void)); /* asm code initialization */
  76570. uInt longest_match OF((deflate_state *s, IPos cur_match));
  76571. #else
  76572. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  76573. #endif
  76574. #endif
  76575. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  76576. #ifdef DEBUG
  76577. local void check_match OF((deflate_state *s, IPos start, IPos match,
  76578. int length));
  76579. #endif
  76580. #define NIL 0
  76581. #ifndef TOO_FAR
  76582. # define TOO_FAR 4096
  76583. #endif
  76584. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76585. typedef struct config_s {
  76586. ush good_length; /* reduce lazy search above this match length */
  76587. ush max_lazy; /* do not perform lazy search above this match length */
  76588. ush nice_length; /* quit search above this match length */
  76589. ush max_chain;
  76590. compress_func func;
  76591. } config;
  76592. #ifdef FASTEST
  76593. local const config configuration_table[2] = {
  76594. {0, 0, 0, 0, deflate_stored}, /* store only */
  76595. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  76596. #else
  76597. local const config configuration_table[10] = {
  76598. {0, 0, 0, 0, deflate_stored}, /* store only */
  76599. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  76600. {4, 5, 16, 8, deflate_fast},
  76601. {4, 6, 32, 32, deflate_fast},
  76602. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  76603. {8, 16, 32, 32, deflate_slow},
  76604. {8, 16, 128, 128, deflate_slow},
  76605. {8, 32, 128, 256, deflate_slow},
  76606. {32, 128, 258, 1024, deflate_slow},
  76607. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  76608. #endif
  76609. #define EQUAL 0
  76610. #ifndef NO_DUMMY_DECL
  76611. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  76612. #endif
  76613. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  76614. #ifdef FASTEST
  76615. #define INSERT_STRING(s, str, match_head) \
  76616. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76617. match_head = s->head[s->ins_h], \
  76618. s->head[s->ins_h] = (Pos)(str))
  76619. #else
  76620. #define INSERT_STRING(s, str, match_head) \
  76621. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76622. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  76623. s->head[s->ins_h] = (Pos)(str))
  76624. #endif
  76625. #define CLEAR_HASH(s) \
  76626. s->head[s->hash_size-1] = NIL; \
  76627. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  76628. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  76629. {
  76630. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  76631. Z_DEFAULT_STRATEGY, version, stream_size);
  76632. }
  76633. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  76634. {
  76635. deflate_state *s;
  76636. int wrap = 1;
  76637. static const char my_version[] = ZLIB_VERSION;
  76638. ushf *overlay;
  76639. if (version == Z_NULL || version[0] != my_version[0] ||
  76640. stream_size != sizeof(z_stream)) {
  76641. return Z_VERSION_ERROR;
  76642. }
  76643. if (strm == Z_NULL) return Z_STREAM_ERROR;
  76644. strm->msg = Z_NULL;
  76645. if (strm->zalloc == (alloc_func)0) {
  76646. strm->zalloc = zcalloc;
  76647. strm->opaque = (voidpf)0;
  76648. }
  76649. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  76650. #ifdef FASTEST
  76651. if (level != 0) level = 1;
  76652. #else
  76653. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76654. #endif
  76655. if (windowBits < 0) { /* suppress zlib wrapper */
  76656. wrap = 0;
  76657. windowBits = -windowBits;
  76658. }
  76659. #ifdef GZIP
  76660. else if (windowBits > 15) {
  76661. wrap = 2; /* write gzip wrapper instead */
  76662. windowBits -= 16;
  76663. }
  76664. #endif
  76665. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  76666. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  76667. strategy < 0 || strategy > Z_FIXED) {
  76668. return Z_STREAM_ERROR;
  76669. }
  76670. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  76671. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  76672. if (s == Z_NULL) return Z_MEM_ERROR;
  76673. strm->state = (struct internal_state FAR *)s;
  76674. s->strm = strm;
  76675. s->wrap = wrap;
  76676. s->gzhead = Z_NULL;
  76677. s->w_bits = windowBits;
  76678. s->w_size = 1 << s->w_bits;
  76679. s->w_mask = s->w_size - 1;
  76680. s->hash_bits = memLevel + 7;
  76681. s->hash_size = 1 << s->hash_bits;
  76682. s->hash_mask = s->hash_size - 1;
  76683. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  76684. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  76685. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  76686. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  76687. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  76688. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  76689. s->pending_buf = (uchf *) overlay;
  76690. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  76691. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  76692. s->pending_buf == Z_NULL) {
  76693. s->status = FINISH_STATE;
  76694. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  76695. deflateEnd (strm);
  76696. return Z_MEM_ERROR;
  76697. }
  76698. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  76699. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  76700. s->level = level;
  76701. s->strategy = strategy;
  76702. s->method = (Byte)method;
  76703. return deflateReset(strm);
  76704. }
  76705. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  76706. {
  76707. deflate_state *s;
  76708. uInt length = dictLength;
  76709. uInt n;
  76710. IPos hash_head = 0;
  76711. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  76712. strm->state->wrap == 2 ||
  76713. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  76714. return Z_STREAM_ERROR;
  76715. s = strm->state;
  76716. if (s->wrap)
  76717. strm->adler = adler32(strm->adler, dictionary, dictLength);
  76718. if (length < MIN_MATCH) return Z_OK;
  76719. if (length > MAX_DIST(s)) {
  76720. length = MAX_DIST(s);
  76721. dictionary += dictLength - length; /* use the tail of the dictionary */
  76722. }
  76723. zmemcpy(s->window, dictionary, length);
  76724. s->strstart = length;
  76725. s->block_start = (long)length;
  76726. s->ins_h = s->window[0];
  76727. UPDATE_HASH(s, s->ins_h, s->window[1]);
  76728. for (n = 0; n <= length - MIN_MATCH; n++) {
  76729. INSERT_STRING(s, n, hash_head);
  76730. }
  76731. if (hash_head) hash_head = 0; /* to make compiler happy */
  76732. return Z_OK;
  76733. }
  76734. int ZEXPORT deflateReset (z_streamp strm)
  76735. {
  76736. deflate_state *s;
  76737. if (strm == Z_NULL || strm->state == Z_NULL ||
  76738. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  76739. return Z_STREAM_ERROR;
  76740. }
  76741. strm->total_in = strm->total_out = 0;
  76742. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  76743. strm->data_type = Z_UNKNOWN;
  76744. s = (deflate_state *)strm->state;
  76745. s->pending = 0;
  76746. s->pending_out = s->pending_buf;
  76747. if (s->wrap < 0) {
  76748. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  76749. }
  76750. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  76751. strm->adler =
  76752. #ifdef GZIP
  76753. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  76754. #endif
  76755. adler32(0L, Z_NULL, 0);
  76756. s->last_flush = Z_NO_FLUSH;
  76757. _tr_init(s);
  76758. lm_init(s);
  76759. return Z_OK;
  76760. }
  76761. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  76762. {
  76763. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76764. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  76765. strm->state->gzhead = head;
  76766. return Z_OK;
  76767. }
  76768. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  76769. {
  76770. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76771. strm->state->bi_valid = bits;
  76772. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  76773. return Z_OK;
  76774. }
  76775. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  76776. {
  76777. deflate_state *s;
  76778. compress_func func;
  76779. int err = Z_OK;
  76780. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76781. s = strm->state;
  76782. #ifdef FASTEST
  76783. if (level != 0) level = 1;
  76784. #else
  76785. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76786. #endif
  76787. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  76788. return Z_STREAM_ERROR;
  76789. }
  76790. func = configuration_table[s->level].func;
  76791. if (func != configuration_table[level].func && strm->total_in != 0) {
  76792. err = deflate(strm, Z_PARTIAL_FLUSH);
  76793. }
  76794. if (s->level != level) {
  76795. s->level = level;
  76796. s->max_lazy_match = configuration_table[level].max_lazy;
  76797. s->good_match = configuration_table[level].good_length;
  76798. s->nice_match = configuration_table[level].nice_length;
  76799. s->max_chain_length = configuration_table[level].max_chain;
  76800. }
  76801. s->strategy = strategy;
  76802. return err;
  76803. }
  76804. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  76805. {
  76806. deflate_state *s;
  76807. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76808. s = strm->state;
  76809. s->good_match = good_length;
  76810. s->max_lazy_match = max_lazy;
  76811. s->nice_match = nice_length;
  76812. s->max_chain_length = max_chain;
  76813. return Z_OK;
  76814. }
  76815. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  76816. {
  76817. deflate_state *s;
  76818. uLong destLen;
  76819. destLen = sourceLen +
  76820. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  76821. if (strm == Z_NULL || strm->state == Z_NULL)
  76822. return destLen;
  76823. s = strm->state;
  76824. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  76825. return destLen;
  76826. return compressBound(sourceLen);
  76827. }
  76828. local void putShortMSB (deflate_state *s, uInt b)
  76829. {
  76830. put_byte(s, (Byte)(b >> 8));
  76831. put_byte(s, (Byte)(b & 0xff));
  76832. }
  76833. local void flush_pending (z_streamp strm)
  76834. {
  76835. unsigned len = strm->state->pending;
  76836. if (len > strm->avail_out) len = strm->avail_out;
  76837. if (len == 0) return;
  76838. zmemcpy(strm->next_out, strm->state->pending_out, len);
  76839. strm->next_out += len;
  76840. strm->state->pending_out += len;
  76841. strm->total_out += len;
  76842. strm->avail_out -= len;
  76843. strm->state->pending -= len;
  76844. if (strm->state->pending == 0) {
  76845. strm->state->pending_out = strm->state->pending_buf;
  76846. }
  76847. }
  76848. int ZEXPORT deflate (z_streamp strm, int flush)
  76849. {
  76850. int old_flush; /* value of flush param for previous deflate call */
  76851. deflate_state *s;
  76852. if (strm == Z_NULL || strm->state == Z_NULL ||
  76853. flush > Z_FINISH || flush < 0) {
  76854. return Z_STREAM_ERROR;
  76855. }
  76856. s = strm->state;
  76857. if (strm->next_out == Z_NULL ||
  76858. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  76859. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  76860. ERR_RETURN(strm, Z_STREAM_ERROR);
  76861. }
  76862. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  76863. s->strm = strm; /* just in case */
  76864. old_flush = s->last_flush;
  76865. s->last_flush = flush;
  76866. if (s->status == INIT_STATE) {
  76867. #ifdef GZIP
  76868. if (s->wrap == 2) {
  76869. strm->adler = crc32(0L, Z_NULL, 0);
  76870. put_byte(s, 31);
  76871. put_byte(s, 139);
  76872. put_byte(s, 8);
  76873. if (s->gzhead == NULL) {
  76874. put_byte(s, 0);
  76875. put_byte(s, 0);
  76876. put_byte(s, 0);
  76877. put_byte(s, 0);
  76878. put_byte(s, 0);
  76879. put_byte(s, s->level == 9 ? 2 :
  76880. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76881. 4 : 0));
  76882. put_byte(s, OS_CODE);
  76883. s->status = BUSY_STATE;
  76884. }
  76885. else {
  76886. put_byte(s, (s->gzhead->text ? 1 : 0) +
  76887. (s->gzhead->hcrc ? 2 : 0) +
  76888. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  76889. (s->gzhead->name == Z_NULL ? 0 : 8) +
  76890. (s->gzhead->comment == Z_NULL ? 0 : 16)
  76891. );
  76892. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  76893. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  76894. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  76895. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  76896. put_byte(s, s->level == 9 ? 2 :
  76897. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76898. 4 : 0));
  76899. put_byte(s, s->gzhead->os & 0xff);
  76900. if (s->gzhead->extra != NULL) {
  76901. put_byte(s, s->gzhead->extra_len & 0xff);
  76902. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  76903. }
  76904. if (s->gzhead->hcrc)
  76905. strm->adler = crc32(strm->adler, s->pending_buf,
  76906. s->pending);
  76907. s->gzindex = 0;
  76908. s->status = EXTRA_STATE;
  76909. }
  76910. }
  76911. else
  76912. #endif
  76913. {
  76914. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  76915. uInt level_flags;
  76916. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  76917. level_flags = 0;
  76918. else if (s->level < 6)
  76919. level_flags = 1;
  76920. else if (s->level == 6)
  76921. level_flags = 2;
  76922. else
  76923. level_flags = 3;
  76924. header |= (level_flags << 6);
  76925. if (s->strstart != 0) header |= PRESET_DICT;
  76926. header += 31 - (header % 31);
  76927. s->status = BUSY_STATE;
  76928. putShortMSB(s, header);
  76929. if (s->strstart != 0) {
  76930. putShortMSB(s, (uInt)(strm->adler >> 16));
  76931. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  76932. }
  76933. strm->adler = adler32(0L, Z_NULL, 0);
  76934. }
  76935. }
  76936. #ifdef GZIP
  76937. if (s->status == EXTRA_STATE) {
  76938. if (s->gzhead->extra != NULL) {
  76939. uInt beg = s->pending; /* start of bytes to update crc */
  76940. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  76941. if (s->pending == s->pending_buf_size) {
  76942. if (s->gzhead->hcrc && s->pending > beg)
  76943. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76944. s->pending - beg);
  76945. flush_pending(strm);
  76946. beg = s->pending;
  76947. if (s->pending == s->pending_buf_size)
  76948. break;
  76949. }
  76950. put_byte(s, s->gzhead->extra[s->gzindex]);
  76951. s->gzindex++;
  76952. }
  76953. if (s->gzhead->hcrc && s->pending > beg)
  76954. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76955. s->pending - beg);
  76956. if (s->gzindex == s->gzhead->extra_len) {
  76957. s->gzindex = 0;
  76958. s->status = NAME_STATE;
  76959. }
  76960. }
  76961. else
  76962. s->status = NAME_STATE;
  76963. }
  76964. if (s->status == NAME_STATE) {
  76965. if (s->gzhead->name != NULL) {
  76966. uInt beg = s->pending; /* start of bytes to update crc */
  76967. int val;
  76968. do {
  76969. if (s->pending == s->pending_buf_size) {
  76970. if (s->gzhead->hcrc && s->pending > beg)
  76971. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76972. s->pending - beg);
  76973. flush_pending(strm);
  76974. beg = s->pending;
  76975. if (s->pending == s->pending_buf_size) {
  76976. val = 1;
  76977. break;
  76978. }
  76979. }
  76980. val = s->gzhead->name[s->gzindex++];
  76981. put_byte(s, val);
  76982. } while (val != 0);
  76983. if (s->gzhead->hcrc && s->pending > beg)
  76984. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76985. s->pending - beg);
  76986. if (val == 0) {
  76987. s->gzindex = 0;
  76988. s->status = COMMENT_STATE;
  76989. }
  76990. }
  76991. else
  76992. s->status = COMMENT_STATE;
  76993. }
  76994. if (s->status == COMMENT_STATE) {
  76995. if (s->gzhead->comment != NULL) {
  76996. uInt beg = s->pending; /* start of bytes to update crc */
  76997. int val;
  76998. do {
  76999. if (s->pending == s->pending_buf_size) {
  77000. if (s->gzhead->hcrc && s->pending > beg)
  77001. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77002. s->pending - beg);
  77003. flush_pending(strm);
  77004. beg = s->pending;
  77005. if (s->pending == s->pending_buf_size) {
  77006. val = 1;
  77007. break;
  77008. }
  77009. }
  77010. val = s->gzhead->comment[s->gzindex++];
  77011. put_byte(s, val);
  77012. } while (val != 0);
  77013. if (s->gzhead->hcrc && s->pending > beg)
  77014. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77015. s->pending - beg);
  77016. if (val == 0)
  77017. s->status = HCRC_STATE;
  77018. }
  77019. else
  77020. s->status = HCRC_STATE;
  77021. }
  77022. if (s->status == HCRC_STATE) {
  77023. if (s->gzhead->hcrc) {
  77024. if (s->pending + 2 > s->pending_buf_size)
  77025. flush_pending(strm);
  77026. if (s->pending + 2 <= s->pending_buf_size) {
  77027. put_byte(s, (Byte)(strm->adler & 0xff));
  77028. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77029. strm->adler = crc32(0L, Z_NULL, 0);
  77030. s->status = BUSY_STATE;
  77031. }
  77032. }
  77033. else
  77034. s->status = BUSY_STATE;
  77035. }
  77036. #endif
  77037. if (s->pending != 0) {
  77038. flush_pending(strm);
  77039. if (strm->avail_out == 0) {
  77040. s->last_flush = -1;
  77041. return Z_OK;
  77042. }
  77043. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77044. flush != Z_FINISH) {
  77045. ERR_RETURN(strm, Z_BUF_ERROR);
  77046. }
  77047. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77048. ERR_RETURN(strm, Z_BUF_ERROR);
  77049. }
  77050. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77051. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77052. block_state bstate;
  77053. bstate = (*(configuration_table[s->level].func))(s, flush);
  77054. if (bstate == finish_started || bstate == finish_done) {
  77055. s->status = FINISH_STATE;
  77056. }
  77057. if (bstate == need_more || bstate == finish_started) {
  77058. if (strm->avail_out == 0) {
  77059. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77060. }
  77061. return Z_OK;
  77062. }
  77063. if (bstate == block_done) {
  77064. if (flush == Z_PARTIAL_FLUSH) {
  77065. _tr_align(s);
  77066. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77067. _tr_stored_block(s, (char*)0, 0L, 0);
  77068. if (flush == Z_FULL_FLUSH) {
  77069. CLEAR_HASH(s); /* forget history */
  77070. }
  77071. }
  77072. flush_pending(strm);
  77073. if (strm->avail_out == 0) {
  77074. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77075. return Z_OK;
  77076. }
  77077. }
  77078. }
  77079. Assert(strm->avail_out > 0, "bug2");
  77080. if (flush != Z_FINISH) return Z_OK;
  77081. if (s->wrap <= 0) return Z_STREAM_END;
  77082. #ifdef GZIP
  77083. if (s->wrap == 2) {
  77084. put_byte(s, (Byte)(strm->adler & 0xff));
  77085. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77086. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77087. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77088. put_byte(s, (Byte)(strm->total_in & 0xff));
  77089. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77090. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77091. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77092. }
  77093. else
  77094. #endif
  77095. {
  77096. putShortMSB(s, (uInt)(strm->adler >> 16));
  77097. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77098. }
  77099. flush_pending(strm);
  77100. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77101. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77102. }
  77103. int ZEXPORT deflateEnd (z_streamp strm)
  77104. {
  77105. int status;
  77106. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77107. status = strm->state->status;
  77108. if (status != INIT_STATE &&
  77109. status != EXTRA_STATE &&
  77110. status != NAME_STATE &&
  77111. status != COMMENT_STATE &&
  77112. status != HCRC_STATE &&
  77113. status != BUSY_STATE &&
  77114. status != FINISH_STATE) {
  77115. return Z_STREAM_ERROR;
  77116. }
  77117. TRY_FREE(strm, strm->state->pending_buf);
  77118. TRY_FREE(strm, strm->state->head);
  77119. TRY_FREE(strm, strm->state->prev);
  77120. TRY_FREE(strm, strm->state->window);
  77121. ZFREE(strm, strm->state);
  77122. strm->state = Z_NULL;
  77123. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77124. }
  77125. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77126. {
  77127. #ifdef MAXSEG_64K
  77128. return Z_STREAM_ERROR;
  77129. #else
  77130. deflate_state *ds;
  77131. deflate_state *ss;
  77132. ushf *overlay;
  77133. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77134. return Z_STREAM_ERROR;
  77135. }
  77136. ss = source->state;
  77137. zmemcpy(dest, source, sizeof(z_stream));
  77138. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77139. if (ds == Z_NULL) return Z_MEM_ERROR;
  77140. dest->state = (struct internal_state FAR *) ds;
  77141. zmemcpy(ds, ss, sizeof(deflate_state));
  77142. ds->strm = dest;
  77143. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77144. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77145. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77146. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77147. ds->pending_buf = (uchf *) overlay;
  77148. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77149. ds->pending_buf == Z_NULL) {
  77150. deflateEnd (dest);
  77151. return Z_MEM_ERROR;
  77152. }
  77153. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77154. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77155. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77156. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77157. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77158. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77159. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77160. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77161. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77162. ds->bl_desc.dyn_tree = ds->bl_tree;
  77163. return Z_OK;
  77164. #endif /* MAXSEG_64K */
  77165. }
  77166. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77167. {
  77168. unsigned len = strm->avail_in;
  77169. if (len > size) len = size;
  77170. if (len == 0) return 0;
  77171. strm->avail_in -= len;
  77172. if (strm->state->wrap == 1) {
  77173. strm->adler = adler32(strm->adler, strm->next_in, len);
  77174. }
  77175. #ifdef GZIP
  77176. else if (strm->state->wrap == 2) {
  77177. strm->adler = crc32(strm->adler, strm->next_in, len);
  77178. }
  77179. #endif
  77180. zmemcpy(buf, strm->next_in, len);
  77181. strm->next_in += len;
  77182. strm->total_in += len;
  77183. return (int)len;
  77184. }
  77185. local void lm_init (deflate_state *s)
  77186. {
  77187. s->window_size = (ulg)2L*s->w_size;
  77188. CLEAR_HASH(s);
  77189. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77190. s->good_match = configuration_table[s->level].good_length;
  77191. s->nice_match = configuration_table[s->level].nice_length;
  77192. s->max_chain_length = configuration_table[s->level].max_chain;
  77193. s->strstart = 0;
  77194. s->block_start = 0L;
  77195. s->lookahead = 0;
  77196. s->match_length = s->prev_length = MIN_MATCH-1;
  77197. s->match_available = 0;
  77198. s->ins_h = 0;
  77199. #ifndef FASTEST
  77200. #ifdef ASMV
  77201. match_init(); /* initialize the asm code */
  77202. #endif
  77203. #endif
  77204. }
  77205. #ifndef FASTEST
  77206. #ifndef ASMV
  77207. local uInt longest_match(deflate_state *s, IPos cur_match)
  77208. {
  77209. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77210. register Bytef *scan = s->window + s->strstart; /* current string */
  77211. register Bytef *match; /* matched string */
  77212. register int len; /* length of current match */
  77213. int best_len = s->prev_length; /* best match length so far */
  77214. int nice_match = s->nice_match; /* stop if match long enough */
  77215. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77216. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77217. Posf *prev = s->prev;
  77218. uInt wmask = s->w_mask;
  77219. #ifdef UNALIGNED_OK
  77220. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77221. register ush scan_start = *(ushf*)scan;
  77222. register ush scan_end = *(ushf*)(scan+best_len-1);
  77223. #else
  77224. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77225. register Byte scan_end1 = scan[best_len-1];
  77226. register Byte scan_end = scan[best_len];
  77227. #endif
  77228. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77229. if (s->prev_length >= s->good_match) {
  77230. chain_length >>= 2;
  77231. }
  77232. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77233. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77234. do {
  77235. Assert(cur_match < s->strstart, "no future");
  77236. match = s->window + cur_match;
  77237. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77238. if (*(ushf*)(match+best_len-1) != scan_end ||
  77239. *(ushf*)match != scan_start) continue;
  77240. Assert(scan[2] == match[2], "scan[2]?");
  77241. scan++, match++;
  77242. do {
  77243. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77244. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77245. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77246. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77247. scan < strend);
  77248. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77249. if (*scan == *match) scan++;
  77250. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77251. scan = strend - (MAX_MATCH-1);
  77252. #else /* UNALIGNED_OK */
  77253. if (match[best_len] != scan_end ||
  77254. match[best_len-1] != scan_end1 ||
  77255. *match != *scan ||
  77256. *++match != scan[1]) continue;
  77257. scan += 2, match++;
  77258. Assert(*scan == *match, "match[2]?");
  77259. do {
  77260. } while (*++scan == *++match && *++scan == *++match &&
  77261. *++scan == *++match && *++scan == *++match &&
  77262. *++scan == *++match && *++scan == *++match &&
  77263. *++scan == *++match && *++scan == *++match &&
  77264. scan < strend);
  77265. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77266. len = MAX_MATCH - (int)(strend - scan);
  77267. scan = strend - MAX_MATCH;
  77268. #endif /* UNALIGNED_OK */
  77269. if (len > best_len) {
  77270. s->match_start = cur_match;
  77271. best_len = len;
  77272. if (len >= nice_match) break;
  77273. #ifdef UNALIGNED_OK
  77274. scan_end = *(ushf*)(scan+best_len-1);
  77275. #else
  77276. scan_end1 = scan[best_len-1];
  77277. scan_end = scan[best_len];
  77278. #endif
  77279. }
  77280. } while ((cur_match = prev[cur_match & wmask]) > limit
  77281. && --chain_length != 0);
  77282. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77283. return s->lookahead;
  77284. }
  77285. #endif /* ASMV */
  77286. #endif /* FASTEST */
  77287. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77288. {
  77289. register Bytef *scan = s->window + s->strstart; /* current string */
  77290. register Bytef *match; /* matched string */
  77291. register int len; /* length of current match */
  77292. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77293. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77294. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77295. Assert(cur_match < s->strstart, "no future");
  77296. match = s->window + cur_match;
  77297. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77298. scan += 2, match += 2;
  77299. Assert(*scan == *match, "match[2]?");
  77300. do {
  77301. } while (*++scan == *++match && *++scan == *++match &&
  77302. *++scan == *++match && *++scan == *++match &&
  77303. *++scan == *++match && *++scan == *++match &&
  77304. *++scan == *++match && *++scan == *++match &&
  77305. scan < strend);
  77306. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77307. len = MAX_MATCH - (int)(strend - scan);
  77308. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77309. s->match_start = cur_match;
  77310. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77311. }
  77312. #ifdef DEBUG
  77313. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77314. {
  77315. if (zmemcmp(s->window + match,
  77316. s->window + start, length) != EQUAL) {
  77317. fprintf(stderr, " start %u, match %u, length %d\n",
  77318. start, match, length);
  77319. do {
  77320. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77321. } while (--length != 0);
  77322. z_error("invalid match");
  77323. }
  77324. if (z_verbose > 1) {
  77325. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77326. do { putc(s->window[start++], stderr); } while (--length != 0);
  77327. }
  77328. }
  77329. #else
  77330. # define check_match(s, start, match, length)
  77331. #endif /* DEBUG */
  77332. local void fill_window (deflate_state *s)
  77333. {
  77334. register unsigned n, m;
  77335. register Posf *p;
  77336. unsigned more; /* Amount of free space at the end of the window. */
  77337. uInt wsize = s->w_size;
  77338. do {
  77339. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77340. if (sizeof(int) <= 2) {
  77341. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77342. more = wsize;
  77343. } else if (more == (unsigned)(-1)) {
  77344. more--;
  77345. }
  77346. }
  77347. if (s->strstart >= wsize+MAX_DIST(s)) {
  77348. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77349. s->match_start -= wsize;
  77350. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77351. s->block_start -= (long) wsize;
  77352. n = s->hash_size;
  77353. p = &s->head[n];
  77354. do {
  77355. m = *--p;
  77356. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77357. } while (--n);
  77358. n = wsize;
  77359. #ifndef FASTEST
  77360. p = &s->prev[n];
  77361. do {
  77362. m = *--p;
  77363. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77364. } while (--n);
  77365. #endif
  77366. more += wsize;
  77367. }
  77368. if (s->strm->avail_in == 0) return;
  77369. Assert(more >= 2, "more < 2");
  77370. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77371. s->lookahead += n;
  77372. if (s->lookahead >= MIN_MATCH) {
  77373. s->ins_h = s->window[s->strstart];
  77374. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77375. #if MIN_MATCH != 3
  77376. Call UPDATE_HASH() MIN_MATCH-3 more times
  77377. #endif
  77378. }
  77379. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77380. }
  77381. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77382. _tr_flush_block(s, (s->block_start >= 0L ? \
  77383. (charf *)&s->window[(unsigned)s->block_start] : \
  77384. (charf *)Z_NULL), \
  77385. (ulg)((long)s->strstart - s->block_start), \
  77386. (eof)); \
  77387. s->block_start = s->strstart; \
  77388. flush_pending(s->strm); \
  77389. Tracev((stderr,"[FLUSH]")); \
  77390. }
  77391. #define FLUSH_BLOCK(s, eof) { \
  77392. FLUSH_BLOCK_ONLY(s, eof); \
  77393. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77394. }
  77395. local block_state deflate_stored(deflate_state *s, int flush)
  77396. {
  77397. ulg max_block_size = 0xffff;
  77398. ulg max_start;
  77399. if (max_block_size > s->pending_buf_size - 5) {
  77400. max_block_size = s->pending_buf_size - 5;
  77401. }
  77402. for (;;) {
  77403. if (s->lookahead <= 1) {
  77404. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77405. s->block_start >= (long)s->w_size, "slide too late");
  77406. fill_window(s);
  77407. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77408. if (s->lookahead == 0) break; /* flush the current block */
  77409. }
  77410. Assert(s->block_start >= 0L, "block gone");
  77411. s->strstart += s->lookahead;
  77412. s->lookahead = 0;
  77413. max_start = s->block_start + max_block_size;
  77414. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77415. s->lookahead = (uInt)(s->strstart - max_start);
  77416. s->strstart = (uInt)max_start;
  77417. FLUSH_BLOCK(s, 0);
  77418. }
  77419. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77420. FLUSH_BLOCK(s, 0);
  77421. }
  77422. }
  77423. FLUSH_BLOCK(s, flush == Z_FINISH);
  77424. return flush == Z_FINISH ? finish_done : block_done;
  77425. }
  77426. local block_state deflate_fast(deflate_state *s, int flush)
  77427. {
  77428. IPos hash_head = NIL; /* head of the hash chain */
  77429. int bflush; /* set if current block must be flushed */
  77430. for (;;) {
  77431. if (s->lookahead < MIN_LOOKAHEAD) {
  77432. fill_window(s);
  77433. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77434. return need_more;
  77435. }
  77436. if (s->lookahead == 0) break; /* flush the current block */
  77437. }
  77438. if (s->lookahead >= MIN_MATCH) {
  77439. INSERT_STRING(s, s->strstart, hash_head);
  77440. }
  77441. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77442. #ifdef FASTEST
  77443. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77444. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77445. s->match_length = longest_match_fast (s, hash_head);
  77446. }
  77447. #else
  77448. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77449. s->match_length = longest_match (s, hash_head);
  77450. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77451. s->match_length = longest_match_fast (s, hash_head);
  77452. }
  77453. #endif
  77454. }
  77455. if (s->match_length >= MIN_MATCH) {
  77456. check_match(s, s->strstart, s->match_start, s->match_length);
  77457. _tr_tally_dist(s, s->strstart - s->match_start,
  77458. s->match_length - MIN_MATCH, bflush);
  77459. s->lookahead -= s->match_length;
  77460. #ifndef FASTEST
  77461. if (s->match_length <= s->max_insert_length &&
  77462. s->lookahead >= MIN_MATCH) {
  77463. s->match_length--; /* string at strstart already in table */
  77464. do {
  77465. s->strstart++;
  77466. INSERT_STRING(s, s->strstart, hash_head);
  77467. } while (--s->match_length != 0);
  77468. s->strstart++;
  77469. } else
  77470. #endif
  77471. {
  77472. s->strstart += s->match_length;
  77473. s->match_length = 0;
  77474. s->ins_h = s->window[s->strstart];
  77475. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77476. #if MIN_MATCH != 3
  77477. Call UPDATE_HASH() MIN_MATCH-3 more times
  77478. #endif
  77479. }
  77480. } else {
  77481. Tracevv((stderr,"%c", s->window[s->strstart]));
  77482. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77483. s->lookahead--;
  77484. s->strstart++;
  77485. }
  77486. if (bflush) FLUSH_BLOCK(s, 0);
  77487. }
  77488. FLUSH_BLOCK(s, flush == Z_FINISH);
  77489. return flush == Z_FINISH ? finish_done : block_done;
  77490. }
  77491. #ifndef FASTEST
  77492. local block_state deflate_slow(deflate_state *s, int flush)
  77493. {
  77494. IPos hash_head = NIL; /* head of hash chain */
  77495. int bflush; /* set if current block must be flushed */
  77496. for (;;) {
  77497. if (s->lookahead < MIN_LOOKAHEAD) {
  77498. fill_window(s);
  77499. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77500. return need_more;
  77501. }
  77502. if (s->lookahead == 0) break; /* flush the current block */
  77503. }
  77504. if (s->lookahead >= MIN_MATCH) {
  77505. INSERT_STRING(s, s->strstart, hash_head);
  77506. }
  77507. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77508. s->match_length = MIN_MATCH-1;
  77509. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77510. s->strstart - hash_head <= MAX_DIST(s)) {
  77511. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77512. s->match_length = longest_match (s, hash_head);
  77513. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77514. s->match_length = longest_match_fast (s, hash_head);
  77515. }
  77516. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77517. #if TOO_FAR <= 32767
  77518. || (s->match_length == MIN_MATCH &&
  77519. s->strstart - s->match_start > TOO_FAR)
  77520. #endif
  77521. )) {
  77522. s->match_length = MIN_MATCH-1;
  77523. }
  77524. }
  77525. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  77526. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  77527. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  77528. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  77529. s->prev_length - MIN_MATCH, bflush);
  77530. s->lookahead -= s->prev_length-1;
  77531. s->prev_length -= 2;
  77532. do {
  77533. if (++s->strstart <= max_insert) {
  77534. INSERT_STRING(s, s->strstart, hash_head);
  77535. }
  77536. } while (--s->prev_length != 0);
  77537. s->match_available = 0;
  77538. s->match_length = MIN_MATCH-1;
  77539. s->strstart++;
  77540. if (bflush) FLUSH_BLOCK(s, 0);
  77541. } else if (s->match_available) {
  77542. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77543. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77544. if (bflush) {
  77545. FLUSH_BLOCK_ONLY(s, 0);
  77546. }
  77547. s->strstart++;
  77548. s->lookahead--;
  77549. if (s->strm->avail_out == 0) return need_more;
  77550. } else {
  77551. s->match_available = 1;
  77552. s->strstart++;
  77553. s->lookahead--;
  77554. }
  77555. }
  77556. Assert (flush != Z_NO_FLUSH, "no flush?");
  77557. if (s->match_available) {
  77558. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77559. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77560. s->match_available = 0;
  77561. }
  77562. FLUSH_BLOCK(s, flush == Z_FINISH);
  77563. return flush == Z_FINISH ? finish_done : block_done;
  77564. }
  77565. #endif /* FASTEST */
  77566. #if 0
  77567. local block_state deflate_rle(s, flush)
  77568. deflate_state *s;
  77569. int flush;
  77570. {
  77571. int bflush; /* set if current block must be flushed */
  77572. uInt run; /* length of run */
  77573. uInt max; /* maximum length of run */
  77574. uInt prev; /* byte at distance one to match */
  77575. Bytef *scan; /* scan for end of run */
  77576. for (;;) {
  77577. if (s->lookahead < MAX_MATCH) {
  77578. fill_window(s);
  77579. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  77580. return need_more;
  77581. }
  77582. if (s->lookahead == 0) break; /* flush the current block */
  77583. }
  77584. run = 0;
  77585. if (s->strstart > 0) { /* if there is a previous byte, that is */
  77586. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  77587. scan = s->window + s->strstart - 1;
  77588. prev = *scan++;
  77589. do {
  77590. if (*scan++ != prev)
  77591. break;
  77592. } while (++run < max);
  77593. }
  77594. if (run >= MIN_MATCH) {
  77595. check_match(s, s->strstart, s->strstart - 1, run);
  77596. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  77597. s->lookahead -= run;
  77598. s->strstart += run;
  77599. } else {
  77600. Tracevv((stderr,"%c", s->window[s->strstart]));
  77601. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77602. s->lookahead--;
  77603. s->strstart++;
  77604. }
  77605. if (bflush) FLUSH_BLOCK(s, 0);
  77606. }
  77607. FLUSH_BLOCK(s, flush == Z_FINISH);
  77608. return flush == Z_FINISH ? finish_done : block_done;
  77609. }
  77610. #endif
  77611. /*** End of inlined file: deflate.c ***/
  77612. /*** Start of inlined file: inffast.c ***/
  77613. /*** Start of inlined file: inftrees.h ***/
  77614. #ifndef _INFTREES_H_
  77615. #define _INFTREES_H_
  77616. typedef struct {
  77617. unsigned char op; /* operation, extra bits, table bits */
  77618. unsigned char bits; /* bits in this part of the code */
  77619. unsigned short val; /* offset in table or code value */
  77620. } code;
  77621. #define ENOUGH 2048
  77622. #define MAXD 592
  77623. typedef enum {
  77624. CODES,
  77625. LENS,
  77626. DISTS
  77627. } codetype;
  77628. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  77629. unsigned codes, code FAR * FAR *table,
  77630. unsigned FAR *bits, unsigned short FAR *work));
  77631. #endif
  77632. /*** End of inlined file: inftrees.h ***/
  77633. /*** Start of inlined file: inflate.h ***/
  77634. #ifndef _INFLATE_H_
  77635. #define _INFLATE_H_
  77636. #ifndef NO_GZIP
  77637. # define GUNZIP
  77638. #endif
  77639. typedef enum {
  77640. HEAD, /* i: waiting for magic header */
  77641. FLAGS, /* i: waiting for method and flags (gzip) */
  77642. TIME, /* i: waiting for modification time (gzip) */
  77643. OS, /* i: waiting for extra flags and operating system (gzip) */
  77644. EXLEN, /* i: waiting for extra length (gzip) */
  77645. EXTRA, /* i: waiting for extra bytes (gzip) */
  77646. NAME, /* i: waiting for end of file name (gzip) */
  77647. COMMENT, /* i: waiting for end of comment (gzip) */
  77648. HCRC, /* i: waiting for header crc (gzip) */
  77649. DICTID, /* i: waiting for dictionary check value */
  77650. DICT, /* waiting for inflateSetDictionary() call */
  77651. TYPE, /* i: waiting for type bits, including last-flag bit */
  77652. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  77653. STORED, /* i: waiting for stored size (length and complement) */
  77654. COPY, /* i/o: waiting for input or output to copy stored block */
  77655. TABLE, /* i: waiting for dynamic block table lengths */
  77656. LENLENS, /* i: waiting for code length code lengths */
  77657. CODELENS, /* i: waiting for length/lit and distance code lengths */
  77658. LEN, /* i: waiting for length/lit code */
  77659. LENEXT, /* i: waiting for length extra bits */
  77660. DIST, /* i: waiting for distance code */
  77661. DISTEXT, /* i: waiting for distance extra bits */
  77662. MATCH, /* o: waiting for output space to copy string */
  77663. LIT, /* o: waiting for output space to write literal */
  77664. CHECK, /* i: waiting for 32-bit check value */
  77665. LENGTH, /* i: waiting for 32-bit length (gzip) */
  77666. DONE, /* finished check, done -- remain here until reset */
  77667. BAD, /* got a data error -- remain here until reset */
  77668. MEM, /* got an inflate() memory error -- remain here until reset */
  77669. SYNC /* looking for synchronization bytes to restart inflate() */
  77670. } inflate_mode;
  77671. struct inflate_state {
  77672. inflate_mode mode; /* current inflate mode */
  77673. int last; /* true if processing last block */
  77674. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  77675. int havedict; /* true if dictionary provided */
  77676. int flags; /* gzip header method and flags (0 if zlib) */
  77677. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  77678. unsigned long check; /* protected copy of check value */
  77679. unsigned long total; /* protected copy of output count */
  77680. gz_headerp head; /* where to save gzip header information */
  77681. unsigned wbits; /* log base 2 of requested window size */
  77682. unsigned wsize; /* window size or zero if not using window */
  77683. unsigned whave; /* valid bytes in the window */
  77684. unsigned write; /* window write index */
  77685. unsigned char FAR *window; /* allocated sliding window, if needed */
  77686. unsigned long hold; /* input bit accumulator */
  77687. unsigned bits; /* number of bits in "in" */
  77688. unsigned length; /* literal or length of data to copy */
  77689. unsigned offset; /* distance back to copy string from */
  77690. unsigned extra; /* extra bits needed */
  77691. code const FAR *lencode; /* starting table for length/literal codes */
  77692. code const FAR *distcode; /* starting table for distance codes */
  77693. unsigned lenbits; /* index bits for lencode */
  77694. unsigned distbits; /* index bits for distcode */
  77695. unsigned ncode; /* number of code length code lengths */
  77696. unsigned nlen; /* number of length code lengths */
  77697. unsigned ndist; /* number of distance code lengths */
  77698. unsigned have; /* number of code lengths in lens[] */
  77699. code FAR *next; /* next available space in codes[] */
  77700. unsigned short lens[320]; /* temporary storage for code lengths */
  77701. unsigned short work[288]; /* work area for code table building */
  77702. code codes[ENOUGH]; /* space for code tables */
  77703. };
  77704. #endif
  77705. /*** End of inlined file: inflate.h ***/
  77706. /*** Start of inlined file: inffast.h ***/
  77707. void inflate_fast OF((z_streamp strm, unsigned start));
  77708. /*** End of inlined file: inffast.h ***/
  77709. #ifndef ASMINF
  77710. #ifdef POSTINC
  77711. # define OFF 0
  77712. # define PUP(a) *(a)++
  77713. #else
  77714. # define OFF 1
  77715. # define PUP(a) *++(a)
  77716. #endif
  77717. void inflate_fast (z_streamp strm, unsigned start)
  77718. {
  77719. struct inflate_state FAR *state;
  77720. unsigned char FAR *in; /* local strm->next_in */
  77721. unsigned char FAR *last; /* while in < last, enough input available */
  77722. unsigned char FAR *out; /* local strm->next_out */
  77723. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  77724. unsigned char FAR *end; /* while out < end, enough space available */
  77725. #ifdef INFLATE_STRICT
  77726. unsigned dmax; /* maximum distance from zlib header */
  77727. #endif
  77728. unsigned wsize; /* window size or zero if not using window */
  77729. unsigned whave; /* valid bytes in the window */
  77730. unsigned write; /* window write index */
  77731. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  77732. unsigned long hold; /* local strm->hold */
  77733. unsigned bits; /* local strm->bits */
  77734. code const FAR *lcode; /* local strm->lencode */
  77735. code const FAR *dcode; /* local strm->distcode */
  77736. unsigned lmask; /* mask for first level of length codes */
  77737. unsigned dmask; /* mask for first level of distance codes */
  77738. code thisx; /* retrieved table entry */
  77739. unsigned op; /* code bits, operation, extra bits, or */
  77740. unsigned len; /* match length, unused bytes */
  77741. unsigned dist; /* match distance */
  77742. unsigned char FAR *from; /* where to copy match from */
  77743. state = (struct inflate_state FAR *)strm->state;
  77744. in = strm->next_in - OFF;
  77745. last = in + (strm->avail_in - 5);
  77746. out = strm->next_out - OFF;
  77747. beg = out - (start - strm->avail_out);
  77748. end = out + (strm->avail_out - 257);
  77749. #ifdef INFLATE_STRICT
  77750. dmax = state->dmax;
  77751. #endif
  77752. wsize = state->wsize;
  77753. whave = state->whave;
  77754. write = state->write;
  77755. window = state->window;
  77756. hold = state->hold;
  77757. bits = state->bits;
  77758. lcode = state->lencode;
  77759. dcode = state->distcode;
  77760. lmask = (1U << state->lenbits) - 1;
  77761. dmask = (1U << state->distbits) - 1;
  77762. do {
  77763. if (bits < 15) {
  77764. hold += (unsigned long)(PUP(in)) << bits;
  77765. bits += 8;
  77766. hold += (unsigned long)(PUP(in)) << bits;
  77767. bits += 8;
  77768. }
  77769. thisx = lcode[hold & lmask];
  77770. dolen:
  77771. op = (unsigned)(thisx.bits);
  77772. hold >>= op;
  77773. bits -= op;
  77774. op = (unsigned)(thisx.op);
  77775. if (op == 0) { /* literal */
  77776. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  77777. "inflate: literal '%c'\n" :
  77778. "inflate: literal 0x%02x\n", thisx.val));
  77779. PUP(out) = (unsigned char)(thisx.val);
  77780. }
  77781. else if (op & 16) { /* length base */
  77782. len = (unsigned)(thisx.val);
  77783. op &= 15; /* number of extra bits */
  77784. if (op) {
  77785. if (bits < op) {
  77786. hold += (unsigned long)(PUP(in)) << bits;
  77787. bits += 8;
  77788. }
  77789. len += (unsigned)hold & ((1U << op) - 1);
  77790. hold >>= op;
  77791. bits -= op;
  77792. }
  77793. Tracevv((stderr, "inflate: length %u\n", len));
  77794. if (bits < 15) {
  77795. hold += (unsigned long)(PUP(in)) << bits;
  77796. bits += 8;
  77797. hold += (unsigned long)(PUP(in)) << bits;
  77798. bits += 8;
  77799. }
  77800. thisx = dcode[hold & dmask];
  77801. dodist:
  77802. op = (unsigned)(thisx.bits);
  77803. hold >>= op;
  77804. bits -= op;
  77805. op = (unsigned)(thisx.op);
  77806. if (op & 16) { /* distance base */
  77807. dist = (unsigned)(thisx.val);
  77808. op &= 15; /* number of extra bits */
  77809. if (bits < op) {
  77810. hold += (unsigned long)(PUP(in)) << bits;
  77811. bits += 8;
  77812. if (bits < op) {
  77813. hold += (unsigned long)(PUP(in)) << bits;
  77814. bits += 8;
  77815. }
  77816. }
  77817. dist += (unsigned)hold & ((1U << op) - 1);
  77818. #ifdef INFLATE_STRICT
  77819. if (dist > dmax) {
  77820. strm->msg = (char *)"invalid distance too far back";
  77821. state->mode = BAD;
  77822. break;
  77823. }
  77824. #endif
  77825. hold >>= op;
  77826. bits -= op;
  77827. Tracevv((stderr, "inflate: distance %u\n", dist));
  77828. op = (unsigned)(out - beg); /* max distance in output */
  77829. if (dist > op) { /* see if copy from window */
  77830. op = dist - op; /* distance back in window */
  77831. if (op > whave) {
  77832. strm->msg = (char *)"invalid distance too far back";
  77833. state->mode = BAD;
  77834. break;
  77835. }
  77836. from = window - OFF;
  77837. if (write == 0) { /* very common case */
  77838. from += wsize - op;
  77839. if (op < len) { /* some from window */
  77840. len -= op;
  77841. do {
  77842. PUP(out) = PUP(from);
  77843. } while (--op);
  77844. from = out - dist; /* rest from output */
  77845. }
  77846. }
  77847. else if (write < op) { /* wrap around window */
  77848. from += wsize + write - op;
  77849. op -= write;
  77850. if (op < len) { /* some from end of window */
  77851. len -= op;
  77852. do {
  77853. PUP(out) = PUP(from);
  77854. } while (--op);
  77855. from = window - OFF;
  77856. if (write < len) { /* some from start of window */
  77857. op = write;
  77858. len -= op;
  77859. do {
  77860. PUP(out) = PUP(from);
  77861. } while (--op);
  77862. from = out - dist; /* rest from output */
  77863. }
  77864. }
  77865. }
  77866. else { /* contiguous in window */
  77867. from += write - op;
  77868. if (op < len) { /* some from window */
  77869. len -= op;
  77870. do {
  77871. PUP(out) = PUP(from);
  77872. } while (--op);
  77873. from = out - dist; /* rest from output */
  77874. }
  77875. }
  77876. while (len > 2) {
  77877. PUP(out) = PUP(from);
  77878. PUP(out) = PUP(from);
  77879. PUP(out) = PUP(from);
  77880. len -= 3;
  77881. }
  77882. if (len) {
  77883. PUP(out) = PUP(from);
  77884. if (len > 1)
  77885. PUP(out) = PUP(from);
  77886. }
  77887. }
  77888. else {
  77889. from = out - dist; /* copy direct from output */
  77890. do { /* minimum length is three */
  77891. PUP(out) = PUP(from);
  77892. PUP(out) = PUP(from);
  77893. PUP(out) = PUP(from);
  77894. len -= 3;
  77895. } while (len > 2);
  77896. if (len) {
  77897. PUP(out) = PUP(from);
  77898. if (len > 1)
  77899. PUP(out) = PUP(from);
  77900. }
  77901. }
  77902. }
  77903. else if ((op & 64) == 0) { /* 2nd level distance code */
  77904. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  77905. goto dodist;
  77906. }
  77907. else {
  77908. strm->msg = (char *)"invalid distance code";
  77909. state->mode = BAD;
  77910. break;
  77911. }
  77912. }
  77913. else if ((op & 64) == 0) { /* 2nd level length code */
  77914. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  77915. goto dolen;
  77916. }
  77917. else if (op & 32) { /* end-of-block */
  77918. Tracevv((stderr, "inflate: end of block\n"));
  77919. state->mode = TYPE;
  77920. break;
  77921. }
  77922. else {
  77923. strm->msg = (char *)"invalid literal/length code";
  77924. state->mode = BAD;
  77925. break;
  77926. }
  77927. } while (in < last && out < end);
  77928. len = bits >> 3;
  77929. in -= len;
  77930. bits -= len << 3;
  77931. hold &= (1U << bits) - 1;
  77932. strm->next_in = in + OFF;
  77933. strm->next_out = out + OFF;
  77934. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  77935. strm->avail_out = (unsigned)(out < end ?
  77936. 257 + (end - out) : 257 - (out - end));
  77937. state->hold = hold;
  77938. state->bits = bits;
  77939. return;
  77940. }
  77941. #endif /* !ASMINF */
  77942. /*** End of inlined file: inffast.c ***/
  77943. #undef PULLBYTE
  77944. #undef LOAD
  77945. #undef RESTORE
  77946. #undef INITBITS
  77947. #undef NEEDBITS
  77948. #undef DROPBITS
  77949. #undef BYTEBITS
  77950. /*** Start of inlined file: inflate.c ***/
  77951. /*** Start of inlined file: inffast.h ***/
  77952. void inflate_fast OF((z_streamp strm, unsigned start));
  77953. /*** End of inlined file: inffast.h ***/
  77954. #ifdef MAKEFIXED
  77955. # ifndef BUILDFIXED
  77956. # define BUILDFIXED
  77957. # endif
  77958. #endif
  77959. local void fixedtables OF((struct inflate_state FAR *state));
  77960. local int updatewindow OF((z_streamp strm, unsigned out));
  77961. #ifdef BUILDFIXED
  77962. void makefixed OF((void));
  77963. #endif
  77964. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  77965. unsigned len));
  77966. int ZEXPORT inflateReset (z_streamp strm)
  77967. {
  77968. struct inflate_state FAR *state;
  77969. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77970. state = (struct inflate_state FAR *)strm->state;
  77971. strm->total_in = strm->total_out = state->total = 0;
  77972. strm->msg = Z_NULL;
  77973. strm->adler = 1; /* to support ill-conceived Java test suite */
  77974. state->mode = HEAD;
  77975. state->last = 0;
  77976. state->havedict = 0;
  77977. state->dmax = 32768U;
  77978. state->head = Z_NULL;
  77979. state->wsize = 0;
  77980. state->whave = 0;
  77981. state->write = 0;
  77982. state->hold = 0;
  77983. state->bits = 0;
  77984. state->lencode = state->distcode = state->next = state->codes;
  77985. Tracev((stderr, "inflate: reset\n"));
  77986. return Z_OK;
  77987. }
  77988. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  77989. {
  77990. struct inflate_state FAR *state;
  77991. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77992. state = (struct inflate_state FAR *)strm->state;
  77993. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  77994. value &= (1L << bits) - 1;
  77995. state->hold += value << state->bits;
  77996. state->bits += bits;
  77997. return Z_OK;
  77998. }
  77999. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  78000. {
  78001. struct inflate_state FAR *state;
  78002. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  78003. stream_size != (int)(sizeof(z_stream)))
  78004. return Z_VERSION_ERROR;
  78005. if (strm == Z_NULL) return Z_STREAM_ERROR;
  78006. strm->msg = Z_NULL; /* in case we return an error */
  78007. if (strm->zalloc == (alloc_func)0) {
  78008. strm->zalloc = zcalloc;
  78009. strm->opaque = (voidpf)0;
  78010. }
  78011. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78012. state = (struct inflate_state FAR *)
  78013. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78014. if (state == Z_NULL) return Z_MEM_ERROR;
  78015. Tracev((stderr, "inflate: allocated\n"));
  78016. strm->state = (struct internal_state FAR *)state;
  78017. if (windowBits < 0) {
  78018. state->wrap = 0;
  78019. windowBits = -windowBits;
  78020. }
  78021. else {
  78022. state->wrap = (windowBits >> 4) + 1;
  78023. #ifdef GUNZIP
  78024. if (windowBits < 48) windowBits &= 15;
  78025. #endif
  78026. }
  78027. if (windowBits < 8 || windowBits > 15) {
  78028. ZFREE(strm, state);
  78029. strm->state = Z_NULL;
  78030. return Z_STREAM_ERROR;
  78031. }
  78032. state->wbits = (unsigned)windowBits;
  78033. state->window = Z_NULL;
  78034. return inflateReset(strm);
  78035. }
  78036. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78037. {
  78038. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78039. }
  78040. local void fixedtables (struct inflate_state FAR *state)
  78041. {
  78042. #ifdef BUILDFIXED
  78043. static int virgin = 1;
  78044. static code *lenfix, *distfix;
  78045. static code fixed[544];
  78046. if (virgin) {
  78047. unsigned sym, bits;
  78048. static code *next;
  78049. sym = 0;
  78050. while (sym < 144) state->lens[sym++] = 8;
  78051. while (sym < 256) state->lens[sym++] = 9;
  78052. while (sym < 280) state->lens[sym++] = 7;
  78053. while (sym < 288) state->lens[sym++] = 8;
  78054. next = fixed;
  78055. lenfix = next;
  78056. bits = 9;
  78057. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78058. sym = 0;
  78059. while (sym < 32) state->lens[sym++] = 5;
  78060. distfix = next;
  78061. bits = 5;
  78062. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78063. virgin = 0;
  78064. }
  78065. #else /* !BUILDFIXED */
  78066. /*** Start of inlined file: inffixed.h ***/
  78067. static const code lenfix[512] = {
  78068. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78069. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78070. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78071. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78072. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78073. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78074. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78075. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78076. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78077. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78078. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78079. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78080. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78081. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78082. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78083. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78084. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78085. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78086. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78087. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78088. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78089. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78090. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78091. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78092. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78093. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78094. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78095. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78096. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78097. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78098. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78099. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78100. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78101. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78102. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78103. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78104. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78105. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78106. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78107. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78108. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78109. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78110. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78111. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78112. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78113. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78114. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78115. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78116. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78117. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78118. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78119. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78120. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78121. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78122. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78123. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78124. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78125. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78126. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78127. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78128. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78129. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78130. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78131. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78132. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78133. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78134. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78135. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78136. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78137. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78138. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78139. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78140. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78141. {0,9,255}
  78142. };
  78143. static const code distfix[32] = {
  78144. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78145. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78146. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78147. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78148. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78149. {22,5,193},{64,5,0}
  78150. };
  78151. /*** End of inlined file: inffixed.h ***/
  78152. #endif /* BUILDFIXED */
  78153. state->lencode = lenfix;
  78154. state->lenbits = 9;
  78155. state->distcode = distfix;
  78156. state->distbits = 5;
  78157. }
  78158. #ifdef MAKEFIXED
  78159. #include <stdio.h>
  78160. void makefixed()
  78161. {
  78162. unsigned low, size;
  78163. struct inflate_state state;
  78164. fixedtables(&state);
  78165. puts(" /* inffixed.h -- table for decoding fixed codes");
  78166. puts(" * Generated automatically by makefixed().");
  78167. puts(" */");
  78168. puts("");
  78169. puts(" /* WARNING: this file should *not* be used by applications.");
  78170. puts(" It is part of the implementation of this library and is");
  78171. puts(" subject to change. Applications should only use zlib.h.");
  78172. puts(" */");
  78173. puts("");
  78174. size = 1U << 9;
  78175. printf(" static const code lenfix[%u] = {", size);
  78176. low = 0;
  78177. for (;;) {
  78178. if ((low % 7) == 0) printf("\n ");
  78179. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78180. state.lencode[low].val);
  78181. if (++low == size) break;
  78182. putchar(',');
  78183. }
  78184. puts("\n };");
  78185. size = 1U << 5;
  78186. printf("\n static const code distfix[%u] = {", size);
  78187. low = 0;
  78188. for (;;) {
  78189. if ((low % 6) == 0) printf("\n ");
  78190. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78191. state.distcode[low].val);
  78192. if (++low == size) break;
  78193. putchar(',');
  78194. }
  78195. puts("\n };");
  78196. }
  78197. #endif /* MAKEFIXED */
  78198. local int updatewindow (z_streamp strm, unsigned out)
  78199. {
  78200. struct inflate_state FAR *state;
  78201. unsigned copy, dist;
  78202. state = (struct inflate_state FAR *)strm->state;
  78203. if (state->window == Z_NULL) {
  78204. state->window = (unsigned char FAR *)
  78205. ZALLOC(strm, 1U << state->wbits,
  78206. sizeof(unsigned char));
  78207. if (state->window == Z_NULL) return 1;
  78208. }
  78209. if (state->wsize == 0) {
  78210. state->wsize = 1U << state->wbits;
  78211. state->write = 0;
  78212. state->whave = 0;
  78213. }
  78214. copy = out - strm->avail_out;
  78215. if (copy >= state->wsize) {
  78216. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78217. state->write = 0;
  78218. state->whave = state->wsize;
  78219. }
  78220. else {
  78221. dist = state->wsize - state->write;
  78222. if (dist > copy) dist = copy;
  78223. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78224. copy -= dist;
  78225. if (copy) {
  78226. zmemcpy(state->window, strm->next_out - copy, copy);
  78227. state->write = copy;
  78228. state->whave = state->wsize;
  78229. }
  78230. else {
  78231. state->write += dist;
  78232. if (state->write == state->wsize) state->write = 0;
  78233. if (state->whave < state->wsize) state->whave += dist;
  78234. }
  78235. }
  78236. return 0;
  78237. }
  78238. #ifdef GUNZIP
  78239. # define UPDATE(check, buf, len) \
  78240. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78241. #else
  78242. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78243. #endif
  78244. #ifdef GUNZIP
  78245. # define CRC2(check, word) \
  78246. do { \
  78247. hbuf[0] = (unsigned char)(word); \
  78248. hbuf[1] = (unsigned char)((word) >> 8); \
  78249. check = crc32(check, hbuf, 2); \
  78250. } while (0)
  78251. # define CRC4(check, word) \
  78252. do { \
  78253. hbuf[0] = (unsigned char)(word); \
  78254. hbuf[1] = (unsigned char)((word) >> 8); \
  78255. hbuf[2] = (unsigned char)((word) >> 16); \
  78256. hbuf[3] = (unsigned char)((word) >> 24); \
  78257. check = crc32(check, hbuf, 4); \
  78258. } while (0)
  78259. #endif
  78260. #define LOAD() \
  78261. do { \
  78262. put = strm->next_out; \
  78263. left = strm->avail_out; \
  78264. next = strm->next_in; \
  78265. have = strm->avail_in; \
  78266. hold = state->hold; \
  78267. bits = state->bits; \
  78268. } while (0)
  78269. #define RESTORE() \
  78270. do { \
  78271. strm->next_out = put; \
  78272. strm->avail_out = left; \
  78273. strm->next_in = next; \
  78274. strm->avail_in = have; \
  78275. state->hold = hold; \
  78276. state->bits = bits; \
  78277. } while (0)
  78278. #define INITBITS() \
  78279. do { \
  78280. hold = 0; \
  78281. bits = 0; \
  78282. } while (0)
  78283. #define PULLBYTE() \
  78284. do { \
  78285. if (have == 0) goto inf_leave; \
  78286. have--; \
  78287. hold += (unsigned long)(*next++) << bits; \
  78288. bits += 8; \
  78289. } while (0)
  78290. #define NEEDBITS(n) \
  78291. do { \
  78292. while (bits < (unsigned)(n)) \
  78293. PULLBYTE(); \
  78294. } while (0)
  78295. #define BITS(n) \
  78296. ((unsigned)hold & ((1U << (n)) - 1))
  78297. #define DROPBITS(n) \
  78298. do { \
  78299. hold >>= (n); \
  78300. bits -= (unsigned)(n); \
  78301. } while (0)
  78302. #define BYTEBITS() \
  78303. do { \
  78304. hold >>= bits & 7; \
  78305. bits -= bits & 7; \
  78306. } while (0)
  78307. #define REVERSE(q) \
  78308. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78309. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78310. int ZEXPORT inflate (z_streamp strm, int flush)
  78311. {
  78312. struct inflate_state FAR *state;
  78313. unsigned char FAR *next; /* next input */
  78314. unsigned char FAR *put; /* next output */
  78315. unsigned have, left; /* available input and output */
  78316. unsigned long hold; /* bit buffer */
  78317. unsigned bits; /* bits in bit buffer */
  78318. unsigned in, out; /* save starting available input and output */
  78319. unsigned copy; /* number of stored or match bytes to copy */
  78320. unsigned char FAR *from; /* where to copy match bytes from */
  78321. code thisx; /* current decoding table entry */
  78322. code last; /* parent table entry */
  78323. unsigned len; /* length to copy for repeats, bits to drop */
  78324. int ret; /* return code */
  78325. #ifdef GUNZIP
  78326. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78327. #endif
  78328. static const unsigned short order[19] = /* permutation of code lengths */
  78329. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78330. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78331. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78332. return Z_STREAM_ERROR;
  78333. state = (struct inflate_state FAR *)strm->state;
  78334. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78335. LOAD();
  78336. in = have;
  78337. out = left;
  78338. ret = Z_OK;
  78339. for (;;)
  78340. switch (state->mode) {
  78341. case HEAD:
  78342. if (state->wrap == 0) {
  78343. state->mode = TYPEDO;
  78344. break;
  78345. }
  78346. NEEDBITS(16);
  78347. #ifdef GUNZIP
  78348. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78349. state->check = crc32(0L, Z_NULL, 0);
  78350. CRC2(state->check, hold);
  78351. INITBITS();
  78352. state->mode = FLAGS;
  78353. break;
  78354. }
  78355. state->flags = 0; /* expect zlib header */
  78356. if (state->head != Z_NULL)
  78357. state->head->done = -1;
  78358. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78359. #else
  78360. if (
  78361. #endif
  78362. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78363. strm->msg = (char *)"incorrect header check";
  78364. state->mode = BAD;
  78365. break;
  78366. }
  78367. if (BITS(4) != Z_DEFLATED) {
  78368. strm->msg = (char *)"unknown compression method";
  78369. state->mode = BAD;
  78370. break;
  78371. }
  78372. DROPBITS(4);
  78373. len = BITS(4) + 8;
  78374. if (len > state->wbits) {
  78375. strm->msg = (char *)"invalid window size";
  78376. state->mode = BAD;
  78377. break;
  78378. }
  78379. state->dmax = 1U << len;
  78380. Tracev((stderr, "inflate: zlib header ok\n"));
  78381. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78382. state->mode = hold & 0x200 ? DICTID : TYPE;
  78383. INITBITS();
  78384. break;
  78385. #ifdef GUNZIP
  78386. case FLAGS:
  78387. NEEDBITS(16);
  78388. state->flags = (int)(hold);
  78389. if ((state->flags & 0xff) != Z_DEFLATED) {
  78390. strm->msg = (char *)"unknown compression method";
  78391. state->mode = BAD;
  78392. break;
  78393. }
  78394. if (state->flags & 0xe000) {
  78395. strm->msg = (char *)"unknown header flags set";
  78396. state->mode = BAD;
  78397. break;
  78398. }
  78399. if (state->head != Z_NULL)
  78400. state->head->text = (int)((hold >> 8) & 1);
  78401. if (state->flags & 0x0200) CRC2(state->check, hold);
  78402. INITBITS();
  78403. state->mode = TIME;
  78404. case TIME:
  78405. NEEDBITS(32);
  78406. if (state->head != Z_NULL)
  78407. state->head->time = hold;
  78408. if (state->flags & 0x0200) CRC4(state->check, hold);
  78409. INITBITS();
  78410. state->mode = OS;
  78411. case OS:
  78412. NEEDBITS(16);
  78413. if (state->head != Z_NULL) {
  78414. state->head->xflags = (int)(hold & 0xff);
  78415. state->head->os = (int)(hold >> 8);
  78416. }
  78417. if (state->flags & 0x0200) CRC2(state->check, hold);
  78418. INITBITS();
  78419. state->mode = EXLEN;
  78420. case EXLEN:
  78421. if (state->flags & 0x0400) {
  78422. NEEDBITS(16);
  78423. state->length = (unsigned)(hold);
  78424. if (state->head != Z_NULL)
  78425. state->head->extra_len = (unsigned)hold;
  78426. if (state->flags & 0x0200) CRC2(state->check, hold);
  78427. INITBITS();
  78428. }
  78429. else if (state->head != Z_NULL)
  78430. state->head->extra = Z_NULL;
  78431. state->mode = EXTRA;
  78432. case EXTRA:
  78433. if (state->flags & 0x0400) {
  78434. copy = state->length;
  78435. if (copy > have) copy = have;
  78436. if (copy) {
  78437. if (state->head != Z_NULL &&
  78438. state->head->extra != Z_NULL) {
  78439. len = state->head->extra_len - state->length;
  78440. zmemcpy(state->head->extra + len, next,
  78441. len + copy > state->head->extra_max ?
  78442. state->head->extra_max - len : copy);
  78443. }
  78444. if (state->flags & 0x0200)
  78445. state->check = crc32(state->check, next, copy);
  78446. have -= copy;
  78447. next += copy;
  78448. state->length -= copy;
  78449. }
  78450. if (state->length) goto inf_leave;
  78451. }
  78452. state->length = 0;
  78453. state->mode = NAME;
  78454. case NAME:
  78455. if (state->flags & 0x0800) {
  78456. if (have == 0) goto inf_leave;
  78457. copy = 0;
  78458. do {
  78459. len = (unsigned)(next[copy++]);
  78460. if (state->head != Z_NULL &&
  78461. state->head->name != Z_NULL &&
  78462. state->length < state->head->name_max)
  78463. state->head->name[state->length++] = len;
  78464. } while (len && copy < have);
  78465. if (state->flags & 0x0200)
  78466. state->check = crc32(state->check, next, copy);
  78467. have -= copy;
  78468. next += copy;
  78469. if (len) goto inf_leave;
  78470. }
  78471. else if (state->head != Z_NULL)
  78472. state->head->name = Z_NULL;
  78473. state->length = 0;
  78474. state->mode = COMMENT;
  78475. case COMMENT:
  78476. if (state->flags & 0x1000) {
  78477. if (have == 0) goto inf_leave;
  78478. copy = 0;
  78479. do {
  78480. len = (unsigned)(next[copy++]);
  78481. if (state->head != Z_NULL &&
  78482. state->head->comment != Z_NULL &&
  78483. state->length < state->head->comm_max)
  78484. state->head->comment[state->length++] = len;
  78485. } while (len && copy < have);
  78486. if (state->flags & 0x0200)
  78487. state->check = crc32(state->check, next, copy);
  78488. have -= copy;
  78489. next += copy;
  78490. if (len) goto inf_leave;
  78491. }
  78492. else if (state->head != Z_NULL)
  78493. state->head->comment = Z_NULL;
  78494. state->mode = HCRC;
  78495. case HCRC:
  78496. if (state->flags & 0x0200) {
  78497. NEEDBITS(16);
  78498. if (hold != (state->check & 0xffff)) {
  78499. strm->msg = (char *)"header crc mismatch";
  78500. state->mode = BAD;
  78501. break;
  78502. }
  78503. INITBITS();
  78504. }
  78505. if (state->head != Z_NULL) {
  78506. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78507. state->head->done = 1;
  78508. }
  78509. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78510. state->mode = TYPE;
  78511. break;
  78512. #endif
  78513. case DICTID:
  78514. NEEDBITS(32);
  78515. strm->adler = state->check = REVERSE(hold);
  78516. INITBITS();
  78517. state->mode = DICT;
  78518. case DICT:
  78519. if (state->havedict == 0) {
  78520. RESTORE();
  78521. return Z_NEED_DICT;
  78522. }
  78523. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78524. state->mode = TYPE;
  78525. case TYPE:
  78526. if (flush == Z_BLOCK) goto inf_leave;
  78527. case TYPEDO:
  78528. if (state->last) {
  78529. BYTEBITS();
  78530. state->mode = CHECK;
  78531. break;
  78532. }
  78533. NEEDBITS(3);
  78534. state->last = BITS(1);
  78535. DROPBITS(1);
  78536. switch (BITS(2)) {
  78537. case 0: /* stored block */
  78538. Tracev((stderr, "inflate: stored block%s\n",
  78539. state->last ? " (last)" : ""));
  78540. state->mode = STORED;
  78541. break;
  78542. case 1: /* fixed block */
  78543. fixedtables(state);
  78544. Tracev((stderr, "inflate: fixed codes block%s\n",
  78545. state->last ? " (last)" : ""));
  78546. state->mode = LEN; /* decode codes */
  78547. break;
  78548. case 2: /* dynamic block */
  78549. Tracev((stderr, "inflate: dynamic codes block%s\n",
  78550. state->last ? " (last)" : ""));
  78551. state->mode = TABLE;
  78552. break;
  78553. case 3:
  78554. strm->msg = (char *)"invalid block type";
  78555. state->mode = BAD;
  78556. }
  78557. DROPBITS(2);
  78558. break;
  78559. case STORED:
  78560. BYTEBITS(); /* go to byte boundary */
  78561. NEEDBITS(32);
  78562. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  78563. strm->msg = (char *)"invalid stored block lengths";
  78564. state->mode = BAD;
  78565. break;
  78566. }
  78567. state->length = (unsigned)hold & 0xffff;
  78568. Tracev((stderr, "inflate: stored length %u\n",
  78569. state->length));
  78570. INITBITS();
  78571. state->mode = COPY;
  78572. case COPY:
  78573. copy = state->length;
  78574. if (copy) {
  78575. if (copy > have) copy = have;
  78576. if (copy > left) copy = left;
  78577. if (copy == 0) goto inf_leave;
  78578. zmemcpy(put, next, copy);
  78579. have -= copy;
  78580. next += copy;
  78581. left -= copy;
  78582. put += copy;
  78583. state->length -= copy;
  78584. break;
  78585. }
  78586. Tracev((stderr, "inflate: stored end\n"));
  78587. state->mode = TYPE;
  78588. break;
  78589. case TABLE:
  78590. NEEDBITS(14);
  78591. state->nlen = BITS(5) + 257;
  78592. DROPBITS(5);
  78593. state->ndist = BITS(5) + 1;
  78594. DROPBITS(5);
  78595. state->ncode = BITS(4) + 4;
  78596. DROPBITS(4);
  78597. #ifndef PKZIP_BUG_WORKAROUND
  78598. if (state->nlen > 286 || state->ndist > 30) {
  78599. strm->msg = (char *)"too many length or distance symbols";
  78600. state->mode = BAD;
  78601. break;
  78602. }
  78603. #endif
  78604. Tracev((stderr, "inflate: table sizes ok\n"));
  78605. state->have = 0;
  78606. state->mode = LENLENS;
  78607. case LENLENS:
  78608. while (state->have < state->ncode) {
  78609. NEEDBITS(3);
  78610. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  78611. DROPBITS(3);
  78612. }
  78613. while (state->have < 19)
  78614. state->lens[order[state->have++]] = 0;
  78615. state->next = state->codes;
  78616. state->lencode = (code const FAR *)(state->next);
  78617. state->lenbits = 7;
  78618. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  78619. &(state->lenbits), state->work);
  78620. if (ret) {
  78621. strm->msg = (char *)"invalid code lengths set";
  78622. state->mode = BAD;
  78623. break;
  78624. }
  78625. Tracev((stderr, "inflate: code lengths ok\n"));
  78626. state->have = 0;
  78627. state->mode = CODELENS;
  78628. case CODELENS:
  78629. while (state->have < state->nlen + state->ndist) {
  78630. for (;;) {
  78631. thisx = state->lencode[BITS(state->lenbits)];
  78632. if ((unsigned)(thisx.bits) <= bits) break;
  78633. PULLBYTE();
  78634. }
  78635. if (thisx.val < 16) {
  78636. NEEDBITS(thisx.bits);
  78637. DROPBITS(thisx.bits);
  78638. state->lens[state->have++] = thisx.val;
  78639. }
  78640. else {
  78641. if (thisx.val == 16) {
  78642. NEEDBITS(thisx.bits + 2);
  78643. DROPBITS(thisx.bits);
  78644. if (state->have == 0) {
  78645. strm->msg = (char *)"invalid bit length repeat";
  78646. state->mode = BAD;
  78647. break;
  78648. }
  78649. len = state->lens[state->have - 1];
  78650. copy = 3 + BITS(2);
  78651. DROPBITS(2);
  78652. }
  78653. else if (thisx.val == 17) {
  78654. NEEDBITS(thisx.bits + 3);
  78655. DROPBITS(thisx.bits);
  78656. len = 0;
  78657. copy = 3 + BITS(3);
  78658. DROPBITS(3);
  78659. }
  78660. else {
  78661. NEEDBITS(thisx.bits + 7);
  78662. DROPBITS(thisx.bits);
  78663. len = 0;
  78664. copy = 11 + BITS(7);
  78665. DROPBITS(7);
  78666. }
  78667. if (state->have + copy > state->nlen + state->ndist) {
  78668. strm->msg = (char *)"invalid bit length repeat";
  78669. state->mode = BAD;
  78670. break;
  78671. }
  78672. while (copy--)
  78673. state->lens[state->have++] = (unsigned short)len;
  78674. }
  78675. }
  78676. if (state->mode == BAD) break;
  78677. state->next = state->codes;
  78678. state->lencode = (code const FAR *)(state->next);
  78679. state->lenbits = 9;
  78680. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  78681. &(state->lenbits), state->work);
  78682. if (ret) {
  78683. strm->msg = (char *)"invalid literal/lengths set";
  78684. state->mode = BAD;
  78685. break;
  78686. }
  78687. state->distcode = (code const FAR *)(state->next);
  78688. state->distbits = 6;
  78689. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  78690. &(state->next), &(state->distbits), state->work);
  78691. if (ret) {
  78692. strm->msg = (char *)"invalid distances set";
  78693. state->mode = BAD;
  78694. break;
  78695. }
  78696. Tracev((stderr, "inflate: codes ok\n"));
  78697. state->mode = LEN;
  78698. case LEN:
  78699. if (have >= 6 && left >= 258) {
  78700. RESTORE();
  78701. inflate_fast(strm, out);
  78702. LOAD();
  78703. break;
  78704. }
  78705. for (;;) {
  78706. thisx = state->lencode[BITS(state->lenbits)];
  78707. if ((unsigned)(thisx.bits) <= bits) break;
  78708. PULLBYTE();
  78709. }
  78710. if (thisx.op && (thisx.op & 0xf0) == 0) {
  78711. last = thisx;
  78712. for (;;) {
  78713. thisx = state->lencode[last.val +
  78714. (BITS(last.bits + last.op) >> last.bits)];
  78715. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78716. PULLBYTE();
  78717. }
  78718. DROPBITS(last.bits);
  78719. }
  78720. DROPBITS(thisx.bits);
  78721. state->length = (unsigned)thisx.val;
  78722. if ((int)(thisx.op) == 0) {
  78723. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78724. "inflate: literal '%c'\n" :
  78725. "inflate: literal 0x%02x\n", thisx.val));
  78726. state->mode = LIT;
  78727. break;
  78728. }
  78729. if (thisx.op & 32) {
  78730. Tracevv((stderr, "inflate: end of block\n"));
  78731. state->mode = TYPE;
  78732. break;
  78733. }
  78734. if (thisx.op & 64) {
  78735. strm->msg = (char *)"invalid literal/length code";
  78736. state->mode = BAD;
  78737. break;
  78738. }
  78739. state->extra = (unsigned)(thisx.op) & 15;
  78740. state->mode = LENEXT;
  78741. case LENEXT:
  78742. if (state->extra) {
  78743. NEEDBITS(state->extra);
  78744. state->length += BITS(state->extra);
  78745. DROPBITS(state->extra);
  78746. }
  78747. Tracevv((stderr, "inflate: length %u\n", state->length));
  78748. state->mode = DIST;
  78749. case DIST:
  78750. for (;;) {
  78751. thisx = state->distcode[BITS(state->distbits)];
  78752. if ((unsigned)(thisx.bits) <= bits) break;
  78753. PULLBYTE();
  78754. }
  78755. if ((thisx.op & 0xf0) == 0) {
  78756. last = thisx;
  78757. for (;;) {
  78758. thisx = state->distcode[last.val +
  78759. (BITS(last.bits + last.op) >> last.bits)];
  78760. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78761. PULLBYTE();
  78762. }
  78763. DROPBITS(last.bits);
  78764. }
  78765. DROPBITS(thisx.bits);
  78766. if (thisx.op & 64) {
  78767. strm->msg = (char *)"invalid distance code";
  78768. state->mode = BAD;
  78769. break;
  78770. }
  78771. state->offset = (unsigned)thisx.val;
  78772. state->extra = (unsigned)(thisx.op) & 15;
  78773. state->mode = DISTEXT;
  78774. case DISTEXT:
  78775. if (state->extra) {
  78776. NEEDBITS(state->extra);
  78777. state->offset += BITS(state->extra);
  78778. DROPBITS(state->extra);
  78779. }
  78780. #ifdef INFLATE_STRICT
  78781. if (state->offset > state->dmax) {
  78782. strm->msg = (char *)"invalid distance too far back";
  78783. state->mode = BAD;
  78784. break;
  78785. }
  78786. #endif
  78787. if (state->offset > state->whave + out - left) {
  78788. strm->msg = (char *)"invalid distance too far back";
  78789. state->mode = BAD;
  78790. break;
  78791. }
  78792. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  78793. state->mode = MATCH;
  78794. case MATCH:
  78795. if (left == 0) goto inf_leave;
  78796. copy = out - left;
  78797. if (state->offset > copy) { /* copy from window */
  78798. copy = state->offset - copy;
  78799. if (copy > state->write) {
  78800. copy -= state->write;
  78801. from = state->window + (state->wsize - copy);
  78802. }
  78803. else
  78804. from = state->window + (state->write - copy);
  78805. if (copy > state->length) copy = state->length;
  78806. }
  78807. else { /* copy from output */
  78808. from = put - state->offset;
  78809. copy = state->length;
  78810. }
  78811. if (copy > left) copy = left;
  78812. left -= copy;
  78813. state->length -= copy;
  78814. do {
  78815. *put++ = *from++;
  78816. } while (--copy);
  78817. if (state->length == 0) state->mode = LEN;
  78818. break;
  78819. case LIT:
  78820. if (left == 0) goto inf_leave;
  78821. *put++ = (unsigned char)(state->length);
  78822. left--;
  78823. state->mode = LEN;
  78824. break;
  78825. case CHECK:
  78826. if (state->wrap) {
  78827. NEEDBITS(32);
  78828. out -= left;
  78829. strm->total_out += out;
  78830. state->total += out;
  78831. if (out)
  78832. strm->adler = state->check =
  78833. UPDATE(state->check, put - out, out);
  78834. out = left;
  78835. if ((
  78836. #ifdef GUNZIP
  78837. state->flags ? hold :
  78838. #endif
  78839. REVERSE(hold)) != state->check) {
  78840. strm->msg = (char *)"incorrect data check";
  78841. state->mode = BAD;
  78842. break;
  78843. }
  78844. INITBITS();
  78845. Tracev((stderr, "inflate: check matches trailer\n"));
  78846. }
  78847. #ifdef GUNZIP
  78848. state->mode = LENGTH;
  78849. case LENGTH:
  78850. if (state->wrap && state->flags) {
  78851. NEEDBITS(32);
  78852. if (hold != (state->total & 0xffffffffUL)) {
  78853. strm->msg = (char *)"incorrect length check";
  78854. state->mode = BAD;
  78855. break;
  78856. }
  78857. INITBITS();
  78858. Tracev((stderr, "inflate: length matches trailer\n"));
  78859. }
  78860. #endif
  78861. state->mode = DONE;
  78862. case DONE:
  78863. ret = Z_STREAM_END;
  78864. goto inf_leave;
  78865. case BAD:
  78866. ret = Z_DATA_ERROR;
  78867. goto inf_leave;
  78868. case MEM:
  78869. return Z_MEM_ERROR;
  78870. case SYNC:
  78871. default:
  78872. return Z_STREAM_ERROR;
  78873. }
  78874. inf_leave:
  78875. RESTORE();
  78876. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  78877. if (updatewindow(strm, out)) {
  78878. state->mode = MEM;
  78879. return Z_MEM_ERROR;
  78880. }
  78881. in -= strm->avail_in;
  78882. out -= strm->avail_out;
  78883. strm->total_in += in;
  78884. strm->total_out += out;
  78885. state->total += out;
  78886. if (state->wrap && out)
  78887. strm->adler = state->check =
  78888. UPDATE(state->check, strm->next_out - out, out);
  78889. strm->data_type = state->bits + (state->last ? 64 : 0) +
  78890. (state->mode == TYPE ? 128 : 0);
  78891. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  78892. ret = Z_BUF_ERROR;
  78893. return ret;
  78894. }
  78895. int ZEXPORT inflateEnd (z_streamp strm)
  78896. {
  78897. struct inflate_state FAR *state;
  78898. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  78899. return Z_STREAM_ERROR;
  78900. state = (struct inflate_state FAR *)strm->state;
  78901. if (state->window != Z_NULL) ZFREE(strm, state->window);
  78902. ZFREE(strm, strm->state);
  78903. strm->state = Z_NULL;
  78904. Tracev((stderr, "inflate: end\n"));
  78905. return Z_OK;
  78906. }
  78907. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  78908. {
  78909. struct inflate_state FAR *state;
  78910. unsigned long id_;
  78911. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78912. state = (struct inflate_state FAR *)strm->state;
  78913. if (state->wrap != 0 && state->mode != DICT)
  78914. return Z_STREAM_ERROR;
  78915. if (state->mode == DICT) {
  78916. id_ = adler32(0L, Z_NULL, 0);
  78917. id_ = adler32(id_, dictionary, dictLength);
  78918. if (id_ != state->check)
  78919. return Z_DATA_ERROR;
  78920. }
  78921. if (updatewindow(strm, strm->avail_out)) {
  78922. state->mode = MEM;
  78923. return Z_MEM_ERROR;
  78924. }
  78925. if (dictLength > state->wsize) {
  78926. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  78927. state->wsize);
  78928. state->whave = state->wsize;
  78929. }
  78930. else {
  78931. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  78932. dictLength);
  78933. state->whave = dictLength;
  78934. }
  78935. state->havedict = 1;
  78936. Tracev((stderr, "inflate: dictionary set\n"));
  78937. return Z_OK;
  78938. }
  78939. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  78940. {
  78941. struct inflate_state FAR *state;
  78942. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78943. state = (struct inflate_state FAR *)strm->state;
  78944. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  78945. state->head = head;
  78946. head->done = 0;
  78947. return Z_OK;
  78948. }
  78949. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  78950. {
  78951. unsigned got;
  78952. unsigned next;
  78953. got = *have;
  78954. next = 0;
  78955. while (next < len && got < 4) {
  78956. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  78957. got++;
  78958. else if (buf[next])
  78959. got = 0;
  78960. else
  78961. got = 4 - got;
  78962. next++;
  78963. }
  78964. *have = got;
  78965. return next;
  78966. }
  78967. int ZEXPORT inflateSync (z_streamp strm)
  78968. {
  78969. unsigned len; /* number of bytes to look at or looked at */
  78970. unsigned long in, out; /* temporary to save total_in and total_out */
  78971. unsigned char buf[4]; /* to restore bit buffer to byte string */
  78972. struct inflate_state FAR *state;
  78973. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78974. state = (struct inflate_state FAR *)strm->state;
  78975. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  78976. if (state->mode != SYNC) {
  78977. state->mode = SYNC;
  78978. state->hold <<= state->bits & 7;
  78979. state->bits -= state->bits & 7;
  78980. len = 0;
  78981. while (state->bits >= 8) {
  78982. buf[len++] = (unsigned char)(state->hold);
  78983. state->hold >>= 8;
  78984. state->bits -= 8;
  78985. }
  78986. state->have = 0;
  78987. syncsearch(&(state->have), buf, len);
  78988. }
  78989. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  78990. strm->avail_in -= len;
  78991. strm->next_in += len;
  78992. strm->total_in += len;
  78993. if (state->have != 4) return Z_DATA_ERROR;
  78994. in = strm->total_in; out = strm->total_out;
  78995. inflateReset(strm);
  78996. strm->total_in = in; strm->total_out = out;
  78997. state->mode = TYPE;
  78998. return Z_OK;
  78999. }
  79000. int ZEXPORT inflateSyncPoint (z_streamp strm)
  79001. {
  79002. struct inflate_state FAR *state;
  79003. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79004. state = (struct inflate_state FAR *)strm->state;
  79005. return state->mode == STORED && state->bits == 0;
  79006. }
  79007. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  79008. {
  79009. struct inflate_state FAR *state;
  79010. struct inflate_state FAR *copy;
  79011. unsigned char FAR *window;
  79012. unsigned wsize;
  79013. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79014. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79015. return Z_STREAM_ERROR;
  79016. state = (struct inflate_state FAR *)source->state;
  79017. copy = (struct inflate_state FAR *)
  79018. ZALLOC(source, 1, sizeof(struct inflate_state));
  79019. if (copy == Z_NULL) return Z_MEM_ERROR;
  79020. window = Z_NULL;
  79021. if (state->window != Z_NULL) {
  79022. window = (unsigned char FAR *)
  79023. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79024. if (window == Z_NULL) {
  79025. ZFREE(source, copy);
  79026. return Z_MEM_ERROR;
  79027. }
  79028. }
  79029. zmemcpy(dest, source, sizeof(z_stream));
  79030. zmemcpy(copy, state, sizeof(struct inflate_state));
  79031. if (state->lencode >= state->codes &&
  79032. state->lencode <= state->codes + ENOUGH - 1) {
  79033. copy->lencode = copy->codes + (state->lencode - state->codes);
  79034. copy->distcode = copy->codes + (state->distcode - state->codes);
  79035. }
  79036. copy->next = copy->codes + (state->next - state->codes);
  79037. if (window != Z_NULL) {
  79038. wsize = 1U << state->wbits;
  79039. zmemcpy(window, state->window, wsize);
  79040. }
  79041. copy->window = window;
  79042. dest->state = (struct internal_state FAR *)copy;
  79043. return Z_OK;
  79044. }
  79045. /*** End of inlined file: inflate.c ***/
  79046. /*** Start of inlined file: inftrees.c ***/
  79047. #define MAXBITS 15
  79048. const char inflate_copyright[] =
  79049. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79050. int inflate_table (codetype type,
  79051. unsigned short FAR *lens,
  79052. unsigned codes,
  79053. code FAR * FAR *table,
  79054. unsigned FAR *bits,
  79055. unsigned short FAR *work)
  79056. {
  79057. unsigned len; /* a code's length in bits */
  79058. unsigned sym; /* index of code symbols */
  79059. unsigned min, max; /* minimum and maximum code lengths */
  79060. unsigned root; /* number of index bits for root table */
  79061. unsigned curr; /* number of index bits for current table */
  79062. unsigned drop; /* code bits to drop for sub-table */
  79063. int left; /* number of prefix codes available */
  79064. unsigned used; /* code entries in table used */
  79065. unsigned huff; /* Huffman code */
  79066. unsigned incr; /* for incrementing code, index */
  79067. unsigned fill; /* index for replicating entries */
  79068. unsigned low; /* low bits for current root entry */
  79069. unsigned mask; /* mask for low root bits */
  79070. code thisx; /* table entry for duplication */
  79071. code FAR *next; /* next available space in table */
  79072. const unsigned short FAR *base; /* base value table to use */
  79073. const unsigned short FAR *extra; /* extra bits table to use */
  79074. int end; /* use base and extra for symbol > end */
  79075. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79076. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79077. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79078. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79079. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79080. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79081. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79082. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79083. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79084. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79085. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79086. 8193, 12289, 16385, 24577, 0, 0};
  79087. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79088. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79089. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79090. 28, 28, 29, 29, 64, 64};
  79091. for (len = 0; len <= MAXBITS; len++)
  79092. count[len] = 0;
  79093. for (sym = 0; sym < codes; sym++)
  79094. count[lens[sym]]++;
  79095. root = *bits;
  79096. for (max = MAXBITS; max >= 1; max--)
  79097. if (count[max] != 0) break;
  79098. if (root > max) root = max;
  79099. if (max == 0) { /* no symbols to code at all */
  79100. thisx.op = (unsigned char)64; /* invalid code marker */
  79101. thisx.bits = (unsigned char)1;
  79102. thisx.val = (unsigned short)0;
  79103. *(*table)++ = thisx; /* make a table to force an error */
  79104. *(*table)++ = thisx;
  79105. *bits = 1;
  79106. return 0; /* no symbols, but wait for decoding to report error */
  79107. }
  79108. for (min = 1; min <= MAXBITS; min++)
  79109. if (count[min] != 0) break;
  79110. if (root < min) root = min;
  79111. left = 1;
  79112. for (len = 1; len <= MAXBITS; len++) {
  79113. left <<= 1;
  79114. left -= count[len];
  79115. if (left < 0) return -1; /* over-subscribed */
  79116. }
  79117. if (left > 0 && (type == CODES || max != 1))
  79118. return -1; /* incomplete set */
  79119. offs[1] = 0;
  79120. for (len = 1; len < MAXBITS; len++)
  79121. offs[len + 1] = offs[len] + count[len];
  79122. for (sym = 0; sym < codes; sym++)
  79123. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79124. switch (type) {
  79125. case CODES:
  79126. base = extra = work; /* dummy value--not used */
  79127. end = 19;
  79128. break;
  79129. case LENS:
  79130. base = lbase;
  79131. base -= 257;
  79132. extra = lext;
  79133. extra -= 257;
  79134. end = 256;
  79135. break;
  79136. default: /* DISTS */
  79137. base = dbase;
  79138. extra = dext;
  79139. end = -1;
  79140. }
  79141. huff = 0; /* starting code */
  79142. sym = 0; /* starting code symbol */
  79143. len = min; /* starting code length */
  79144. next = *table; /* current table to fill in */
  79145. curr = root; /* current table index bits */
  79146. drop = 0; /* current bits to drop from code for index */
  79147. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79148. used = 1U << root; /* use root table entries */
  79149. mask = used - 1; /* mask for comparing low */
  79150. if (type == LENS && used >= ENOUGH - MAXD)
  79151. return 1;
  79152. for (;;) {
  79153. thisx.bits = (unsigned char)(len - drop);
  79154. if ((int)(work[sym]) < end) {
  79155. thisx.op = (unsigned char)0;
  79156. thisx.val = work[sym];
  79157. }
  79158. else if ((int)(work[sym]) > end) {
  79159. thisx.op = (unsigned char)(extra[work[sym]]);
  79160. thisx.val = base[work[sym]];
  79161. }
  79162. else {
  79163. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79164. thisx.val = 0;
  79165. }
  79166. incr = 1U << (len - drop);
  79167. fill = 1U << curr;
  79168. min = fill; /* save offset to next table */
  79169. do {
  79170. fill -= incr;
  79171. next[(huff >> drop) + fill] = thisx;
  79172. } while (fill != 0);
  79173. incr = 1U << (len - 1);
  79174. while (huff & incr)
  79175. incr >>= 1;
  79176. if (incr != 0) {
  79177. huff &= incr - 1;
  79178. huff += incr;
  79179. }
  79180. else
  79181. huff = 0;
  79182. sym++;
  79183. if (--(count[len]) == 0) {
  79184. if (len == max) break;
  79185. len = lens[work[sym]];
  79186. }
  79187. if (len > root && (huff & mask) != low) {
  79188. if (drop == 0)
  79189. drop = root;
  79190. next += min; /* here min is 1 << curr */
  79191. curr = len - drop;
  79192. left = (int)(1 << curr);
  79193. while (curr + drop < max) {
  79194. left -= count[curr + drop];
  79195. if (left <= 0) break;
  79196. curr++;
  79197. left <<= 1;
  79198. }
  79199. used += 1U << curr;
  79200. if (type == LENS && used >= ENOUGH - MAXD)
  79201. return 1;
  79202. low = huff & mask;
  79203. (*table)[low].op = (unsigned char)curr;
  79204. (*table)[low].bits = (unsigned char)root;
  79205. (*table)[low].val = (unsigned short)(next - *table);
  79206. }
  79207. }
  79208. thisx.op = (unsigned char)64; /* invalid code marker */
  79209. thisx.bits = (unsigned char)(len - drop);
  79210. thisx.val = (unsigned short)0;
  79211. while (huff != 0) {
  79212. if (drop != 0 && (huff & mask) != low) {
  79213. drop = 0;
  79214. len = root;
  79215. next = *table;
  79216. thisx.bits = (unsigned char)len;
  79217. }
  79218. next[huff >> drop] = thisx;
  79219. incr = 1U << (len - 1);
  79220. while (huff & incr)
  79221. incr >>= 1;
  79222. if (incr != 0) {
  79223. huff &= incr - 1;
  79224. huff += incr;
  79225. }
  79226. else
  79227. huff = 0;
  79228. }
  79229. *table += used;
  79230. *bits = root;
  79231. return 0;
  79232. }
  79233. /*** End of inlined file: inftrees.c ***/
  79234. /*** Start of inlined file: trees.c ***/
  79235. #ifdef DEBUG
  79236. # include <ctype.h>
  79237. #endif
  79238. #define MAX_BL_BITS 7
  79239. #define END_BLOCK 256
  79240. #define REP_3_6 16
  79241. #define REPZ_3_10 17
  79242. #define REPZ_11_138 18
  79243. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79244. = {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};
  79245. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79246. = {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};
  79247. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79248. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79249. local const uch bl_order[BL_CODES]
  79250. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79251. #define Buf_size (8 * 2*sizeof(char))
  79252. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79253. #if defined(GEN_TREES_H) || !defined(STDC)
  79254. local ct_data static_ltree[L_CODES+2];
  79255. local ct_data static_dtree[D_CODES];
  79256. uch _dist_code[DIST_CODE_LEN];
  79257. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79258. local int base_length[LENGTH_CODES];
  79259. local int base_dist[D_CODES];
  79260. #else
  79261. /*** Start of inlined file: trees.h ***/
  79262. local const ct_data static_ltree[L_CODES+2] = {
  79263. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79264. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79265. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79266. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79267. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79268. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79269. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79270. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79271. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79272. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79273. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79274. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79275. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79276. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79277. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79278. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79279. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79280. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79281. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79282. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79283. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79284. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79285. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79286. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79287. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79288. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79289. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79290. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79291. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79292. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79293. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79294. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79295. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79296. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79297. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79298. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79299. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79300. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79301. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79302. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79303. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79304. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79305. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79306. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79307. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79308. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79309. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79310. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79311. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79312. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79313. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79314. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79315. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79316. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79317. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79318. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79319. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79320. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79321. };
  79322. local const ct_data static_dtree[D_CODES] = {
  79323. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79324. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79325. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79326. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79327. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79328. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79329. };
  79330. const uch _dist_code[DIST_CODE_LEN] = {
  79331. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79332. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79333. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79334. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79335. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79336. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79337. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79338. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79339. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79340. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79341. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79342. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79343. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79344. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79345. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79346. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79347. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79348. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79349. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79350. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79351. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79352. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79353. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79354. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79355. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79356. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79357. };
  79358. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79359. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79360. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79361. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79362. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79363. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79364. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79365. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79366. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79367. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79368. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79369. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79370. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79371. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79372. };
  79373. local const int base_length[LENGTH_CODES] = {
  79374. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79375. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79376. };
  79377. local const int base_dist[D_CODES] = {
  79378. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79379. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79380. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79381. };
  79382. /*** End of inlined file: trees.h ***/
  79383. #endif /* GEN_TREES_H */
  79384. struct static_tree_desc_s {
  79385. const ct_data *static_tree; /* static tree or NULL */
  79386. const intf *extra_bits; /* extra bits for each code or NULL */
  79387. int extra_base; /* base index for extra_bits */
  79388. int elems; /* max number of elements in the tree */
  79389. int max_length; /* max bit length for the codes */
  79390. };
  79391. local static_tree_desc static_l_desc =
  79392. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79393. local static_tree_desc static_d_desc =
  79394. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79395. local static_tree_desc static_bl_desc =
  79396. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79397. local void tr_static_init OF((void));
  79398. local void init_block OF((deflate_state *s));
  79399. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79400. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79401. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79402. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79403. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79404. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79405. local int build_bl_tree OF((deflate_state *s));
  79406. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79407. int blcodes));
  79408. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79409. ct_data *dtree));
  79410. local void set_data_type OF((deflate_state *s));
  79411. local unsigned bi_reverse OF((unsigned value, int length));
  79412. local void bi_windup OF((deflate_state *s));
  79413. local void bi_flush OF((deflate_state *s));
  79414. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79415. int header));
  79416. #ifdef GEN_TREES_H
  79417. local void gen_trees_header OF((void));
  79418. #endif
  79419. #ifndef DEBUG
  79420. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79421. #else /* DEBUG */
  79422. # define send_code(s, c, tree) \
  79423. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79424. send_bits(s, tree[c].Code, tree[c].Len); }
  79425. #endif
  79426. #define put_short(s, w) { \
  79427. put_byte(s, (uch)((w) & 0xff)); \
  79428. put_byte(s, (uch)((ush)(w) >> 8)); \
  79429. }
  79430. #ifdef DEBUG
  79431. local void send_bits OF((deflate_state *s, int value, int length));
  79432. local void send_bits (deflate_state *s, int value, int length)
  79433. {
  79434. Tracevv((stderr," l %2d v %4x ", length, value));
  79435. Assert(length > 0 && length <= 15, "invalid length");
  79436. s->bits_sent += (ulg)length;
  79437. if (s->bi_valid > (int)Buf_size - length) {
  79438. s->bi_buf |= (value << s->bi_valid);
  79439. put_short(s, s->bi_buf);
  79440. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79441. s->bi_valid += length - Buf_size;
  79442. } else {
  79443. s->bi_buf |= value << s->bi_valid;
  79444. s->bi_valid += length;
  79445. }
  79446. }
  79447. #else /* !DEBUG */
  79448. #define send_bits(s, value, length) \
  79449. { int len = length;\
  79450. if (s->bi_valid > (int)Buf_size - len) {\
  79451. int val = value;\
  79452. s->bi_buf |= (val << s->bi_valid);\
  79453. put_short(s, s->bi_buf);\
  79454. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79455. s->bi_valid += len - Buf_size;\
  79456. } else {\
  79457. s->bi_buf |= (value) << s->bi_valid;\
  79458. s->bi_valid += len;\
  79459. }\
  79460. }
  79461. #endif /* DEBUG */
  79462. local void tr_static_init()
  79463. {
  79464. #if defined(GEN_TREES_H) || !defined(STDC)
  79465. static int static_init_done = 0;
  79466. int n; /* iterates over tree elements */
  79467. int bits; /* bit counter */
  79468. int length; /* length value */
  79469. int code; /* code value */
  79470. int dist; /* distance index */
  79471. ush bl_count[MAX_BITS+1];
  79472. if (static_init_done) return;
  79473. static_l_desc.static_tree = static_ltree;
  79474. static_l_desc.extra_bits = extra_lbits;
  79475. static_d_desc.static_tree = static_dtree;
  79476. static_d_desc.extra_bits = extra_dbits;
  79477. static_bl_desc.extra_bits = extra_blbits;
  79478. length = 0;
  79479. for (code = 0; code < LENGTH_CODES-1; code++) {
  79480. base_length[code] = length;
  79481. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79482. _length_code[length++] = (uch)code;
  79483. }
  79484. }
  79485. Assert (length == 256, "tr_static_init: length != 256");
  79486. _length_code[length-1] = (uch)code;
  79487. dist = 0;
  79488. for (code = 0 ; code < 16; code++) {
  79489. base_dist[code] = dist;
  79490. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79491. _dist_code[dist++] = (uch)code;
  79492. }
  79493. }
  79494. Assert (dist == 256, "tr_static_init: dist != 256");
  79495. dist >>= 7; /* from now on, all distances are divided by 128 */
  79496. for ( ; code < D_CODES; code++) {
  79497. base_dist[code] = dist << 7;
  79498. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79499. _dist_code[256 + dist++] = (uch)code;
  79500. }
  79501. }
  79502. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79503. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79504. n = 0;
  79505. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79506. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79507. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79508. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79509. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79510. for (n = 0; n < D_CODES; n++) {
  79511. static_dtree[n].Len = 5;
  79512. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79513. }
  79514. static_init_done = 1;
  79515. # ifdef GEN_TREES_H
  79516. gen_trees_header();
  79517. # endif
  79518. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79519. }
  79520. #ifdef GEN_TREES_H
  79521. # ifndef DEBUG
  79522. # include <stdio.h>
  79523. # endif
  79524. # define SEPARATOR(i, last, width) \
  79525. ((i) == (last)? "\n};\n\n" : \
  79526. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  79527. void gen_trees_header()
  79528. {
  79529. FILE *header = fopen("trees.h", "w");
  79530. int i;
  79531. Assert (header != NULL, "Can't open trees.h");
  79532. fprintf(header,
  79533. "/* header created automatically with -DGEN_TREES_H */\n\n");
  79534. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  79535. for (i = 0; i < L_CODES+2; i++) {
  79536. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  79537. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  79538. }
  79539. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  79540. for (i = 0; i < D_CODES; i++) {
  79541. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  79542. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  79543. }
  79544. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  79545. for (i = 0; i < DIST_CODE_LEN; i++) {
  79546. fprintf(header, "%2u%s", _dist_code[i],
  79547. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  79548. }
  79549. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  79550. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  79551. fprintf(header, "%2u%s", _length_code[i],
  79552. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  79553. }
  79554. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  79555. for (i = 0; i < LENGTH_CODES; i++) {
  79556. fprintf(header, "%1u%s", base_length[i],
  79557. SEPARATOR(i, LENGTH_CODES-1, 20));
  79558. }
  79559. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  79560. for (i = 0; i < D_CODES; i++) {
  79561. fprintf(header, "%5u%s", base_dist[i],
  79562. SEPARATOR(i, D_CODES-1, 10));
  79563. }
  79564. fclose(header);
  79565. }
  79566. #endif /* GEN_TREES_H */
  79567. void _tr_init(deflate_state *s)
  79568. {
  79569. tr_static_init();
  79570. s->l_desc.dyn_tree = s->dyn_ltree;
  79571. s->l_desc.stat_desc = &static_l_desc;
  79572. s->d_desc.dyn_tree = s->dyn_dtree;
  79573. s->d_desc.stat_desc = &static_d_desc;
  79574. s->bl_desc.dyn_tree = s->bl_tree;
  79575. s->bl_desc.stat_desc = &static_bl_desc;
  79576. s->bi_buf = 0;
  79577. s->bi_valid = 0;
  79578. s->last_eob_len = 8; /* enough lookahead for inflate */
  79579. #ifdef DEBUG
  79580. s->compressed_len = 0L;
  79581. s->bits_sent = 0L;
  79582. #endif
  79583. init_block(s);
  79584. }
  79585. local void init_block (deflate_state *s)
  79586. {
  79587. int n; /* iterates over tree elements */
  79588. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  79589. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  79590. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  79591. s->dyn_ltree[END_BLOCK].Freq = 1;
  79592. s->opt_len = s->static_len = 0L;
  79593. s->last_lit = s->matches = 0;
  79594. }
  79595. #define SMALLEST 1
  79596. #define pqremove(s, tree, top) \
  79597. {\
  79598. top = s->heap[SMALLEST]; \
  79599. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  79600. pqdownheap(s, tree, SMALLEST); \
  79601. }
  79602. #define smaller(tree, n, m, depth) \
  79603. (tree[n].Freq < tree[m].Freq || \
  79604. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  79605. local void pqdownheap (deflate_state *s,
  79606. ct_data *tree, /* the tree to restore */
  79607. int k) /* node to move down */
  79608. {
  79609. int v = s->heap[k];
  79610. int j = k << 1; /* left son of k */
  79611. while (j <= s->heap_len) {
  79612. if (j < s->heap_len &&
  79613. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  79614. j++;
  79615. }
  79616. if (smaller(tree, v, s->heap[j], s->depth)) break;
  79617. s->heap[k] = s->heap[j]; k = j;
  79618. j <<= 1;
  79619. }
  79620. s->heap[k] = v;
  79621. }
  79622. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  79623. {
  79624. ct_data *tree = desc->dyn_tree;
  79625. int max_code = desc->max_code;
  79626. const ct_data *stree = desc->stat_desc->static_tree;
  79627. const intf *extra = desc->stat_desc->extra_bits;
  79628. int base = desc->stat_desc->extra_base;
  79629. int max_length = desc->stat_desc->max_length;
  79630. int h; /* heap index */
  79631. int n, m; /* iterate over the tree elements */
  79632. int bits; /* bit length */
  79633. int xbits; /* extra bits */
  79634. ush f; /* frequency */
  79635. int overflow = 0; /* number of elements with bit length too large */
  79636. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  79637. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  79638. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  79639. n = s->heap[h];
  79640. bits = tree[tree[n].Dad].Len + 1;
  79641. if (bits > max_length) bits = max_length, overflow++;
  79642. tree[n].Len = (ush)bits;
  79643. if (n > max_code) continue; /* not a leaf node */
  79644. s->bl_count[bits]++;
  79645. xbits = 0;
  79646. if (n >= base) xbits = extra[n-base];
  79647. f = tree[n].Freq;
  79648. s->opt_len += (ulg)f * (bits + xbits);
  79649. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  79650. }
  79651. if (overflow == 0) return;
  79652. Trace((stderr,"\nbit length overflow\n"));
  79653. do {
  79654. bits = max_length-1;
  79655. while (s->bl_count[bits] == 0) bits--;
  79656. s->bl_count[bits]--; /* move one leaf down the tree */
  79657. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  79658. s->bl_count[max_length]--;
  79659. overflow -= 2;
  79660. } while (overflow > 0);
  79661. for (bits = max_length; bits != 0; bits--) {
  79662. n = s->bl_count[bits];
  79663. while (n != 0) {
  79664. m = s->heap[--h];
  79665. if (m > max_code) continue;
  79666. if ((unsigned) tree[m].Len != (unsigned) bits) {
  79667. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  79668. s->opt_len += ((long)bits - (long)tree[m].Len)
  79669. *(long)tree[m].Freq;
  79670. tree[m].Len = (ush)bits;
  79671. }
  79672. n--;
  79673. }
  79674. }
  79675. }
  79676. local void gen_codes (ct_data *tree, /* the tree to decorate */
  79677. int max_code, /* largest code with non zero frequency */
  79678. ushf *bl_count) /* number of codes at each bit length */
  79679. {
  79680. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  79681. ush code = 0; /* running code value */
  79682. int bits; /* bit index */
  79683. int n; /* code index */
  79684. for (bits = 1; bits <= MAX_BITS; bits++) {
  79685. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  79686. }
  79687. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  79688. "inconsistent bit counts");
  79689. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  79690. for (n = 0; n <= max_code; n++) {
  79691. int len = tree[n].Len;
  79692. if (len == 0) continue;
  79693. tree[n].Code = bi_reverse(next_code[len]++, len);
  79694. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  79695. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  79696. }
  79697. }
  79698. local void build_tree (deflate_state *s,
  79699. tree_desc *desc) /* the tree descriptor */
  79700. {
  79701. ct_data *tree = desc->dyn_tree;
  79702. const ct_data *stree = desc->stat_desc->static_tree;
  79703. int elems = desc->stat_desc->elems;
  79704. int n, m; /* iterate over heap elements */
  79705. int max_code = -1; /* largest code with non zero frequency */
  79706. int node; /* new node being created */
  79707. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  79708. for (n = 0; n < elems; n++) {
  79709. if (tree[n].Freq != 0) {
  79710. s->heap[++(s->heap_len)] = max_code = n;
  79711. s->depth[n] = 0;
  79712. } else {
  79713. tree[n].Len = 0;
  79714. }
  79715. }
  79716. while (s->heap_len < 2) {
  79717. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  79718. tree[node].Freq = 1;
  79719. s->depth[node] = 0;
  79720. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  79721. }
  79722. desc->max_code = max_code;
  79723. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  79724. node = elems; /* next internal node of the tree */
  79725. do {
  79726. pqremove(s, tree, n); /* n = node of least frequency */
  79727. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  79728. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  79729. s->heap[--(s->heap_max)] = m;
  79730. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  79731. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  79732. s->depth[n] : s->depth[m]) + 1);
  79733. tree[n].Dad = tree[m].Dad = (ush)node;
  79734. #ifdef DUMP_BL_TREE
  79735. if (tree == s->bl_tree) {
  79736. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  79737. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  79738. }
  79739. #endif
  79740. s->heap[SMALLEST] = node++;
  79741. pqdownheap(s, tree, SMALLEST);
  79742. } while (s->heap_len >= 2);
  79743. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  79744. gen_bitlen(s, (tree_desc *)desc);
  79745. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  79746. }
  79747. local void scan_tree (deflate_state *s,
  79748. ct_data *tree, /* the tree to be scanned */
  79749. int max_code) /* and its largest code of non zero frequency */
  79750. {
  79751. int n; /* iterates over all tree elements */
  79752. int prevlen = -1; /* last emitted length */
  79753. int curlen; /* length of current code */
  79754. int nextlen = tree[0].Len; /* length of next code */
  79755. int count = 0; /* repeat count of the current code */
  79756. int max_count = 7; /* max repeat count */
  79757. int min_count = 4; /* min repeat count */
  79758. if (nextlen == 0) max_count = 138, min_count = 3;
  79759. tree[max_code+1].Len = (ush)0xffff; /* guard */
  79760. for (n = 0; n <= max_code; n++) {
  79761. curlen = nextlen; nextlen = tree[n+1].Len;
  79762. if (++count < max_count && curlen == nextlen) {
  79763. continue;
  79764. } else if (count < min_count) {
  79765. s->bl_tree[curlen].Freq += count;
  79766. } else if (curlen != 0) {
  79767. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  79768. s->bl_tree[REP_3_6].Freq++;
  79769. } else if (count <= 10) {
  79770. s->bl_tree[REPZ_3_10].Freq++;
  79771. } else {
  79772. s->bl_tree[REPZ_11_138].Freq++;
  79773. }
  79774. count = 0; prevlen = curlen;
  79775. if (nextlen == 0) {
  79776. max_count = 138, min_count = 3;
  79777. } else if (curlen == nextlen) {
  79778. max_count = 6, min_count = 3;
  79779. } else {
  79780. max_count = 7, min_count = 4;
  79781. }
  79782. }
  79783. }
  79784. local void send_tree (deflate_state *s,
  79785. ct_data *tree, /* the tree to be scanned */
  79786. int max_code) /* and its largest code of non zero frequency */
  79787. {
  79788. int n; /* iterates over all tree elements */
  79789. int prevlen = -1; /* last emitted length */
  79790. int curlen; /* length of current code */
  79791. int nextlen = tree[0].Len; /* length of next code */
  79792. int count = 0; /* repeat count of the current code */
  79793. int max_count = 7; /* max repeat count */
  79794. int min_count = 4; /* min repeat count */
  79795. /* guard already set */
  79796. if (nextlen == 0) max_count = 138, min_count = 3;
  79797. for (n = 0; n <= max_code; n++) {
  79798. curlen = nextlen; nextlen = tree[n+1].Len;
  79799. if (++count < max_count && curlen == nextlen) {
  79800. continue;
  79801. } else if (count < min_count) {
  79802. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  79803. } else if (curlen != 0) {
  79804. if (curlen != prevlen) {
  79805. send_code(s, curlen, s->bl_tree); count--;
  79806. }
  79807. Assert(count >= 3 && count <= 6, " 3_6?");
  79808. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  79809. } else if (count <= 10) {
  79810. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  79811. } else {
  79812. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  79813. }
  79814. count = 0; prevlen = curlen;
  79815. if (nextlen == 0) {
  79816. max_count = 138, min_count = 3;
  79817. } else if (curlen == nextlen) {
  79818. max_count = 6, min_count = 3;
  79819. } else {
  79820. max_count = 7, min_count = 4;
  79821. }
  79822. }
  79823. }
  79824. local int build_bl_tree (deflate_state *s)
  79825. {
  79826. int max_blindex; /* index of last bit length code of non zero freq */
  79827. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  79828. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  79829. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  79830. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  79831. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  79832. }
  79833. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  79834. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  79835. s->opt_len, s->static_len));
  79836. return max_blindex;
  79837. }
  79838. local void send_all_trees (deflate_state *s,
  79839. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  79840. {
  79841. int rank; /* index in bl_order */
  79842. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  79843. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  79844. "too many codes");
  79845. Tracev((stderr, "\nbl counts: "));
  79846. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  79847. send_bits(s, dcodes-1, 5);
  79848. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  79849. for (rank = 0; rank < blcodes; rank++) {
  79850. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  79851. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  79852. }
  79853. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  79854. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  79855. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  79856. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  79857. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  79858. }
  79859. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  79860. {
  79861. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  79862. #ifdef DEBUG
  79863. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  79864. s->compressed_len += (stored_len + 4) << 3;
  79865. #endif
  79866. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  79867. }
  79868. void _tr_align (deflate_state *s)
  79869. {
  79870. send_bits(s, STATIC_TREES<<1, 3);
  79871. send_code(s, END_BLOCK, static_ltree);
  79872. #ifdef DEBUG
  79873. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  79874. #endif
  79875. bi_flush(s);
  79876. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  79877. send_bits(s, STATIC_TREES<<1, 3);
  79878. send_code(s, END_BLOCK, static_ltree);
  79879. #ifdef DEBUG
  79880. s->compressed_len += 10L;
  79881. #endif
  79882. bi_flush(s);
  79883. }
  79884. s->last_eob_len = 7;
  79885. }
  79886. void _tr_flush_block (deflate_state *s,
  79887. charf *buf, /* input block, or NULL if too old */
  79888. ulg stored_len, /* length of input block */
  79889. int eof) /* true if this is the last block for a file */
  79890. {
  79891. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  79892. int max_blindex = 0; /* index of last bit length code of non zero freq */
  79893. if (s->level > 0) {
  79894. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  79895. set_data_type(s);
  79896. build_tree(s, (tree_desc *)(&(s->l_desc)));
  79897. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  79898. s->static_len));
  79899. build_tree(s, (tree_desc *)(&(s->d_desc)));
  79900. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  79901. s->static_len));
  79902. max_blindex = build_bl_tree(s);
  79903. opt_lenb = (s->opt_len+3+7)>>3;
  79904. static_lenb = (s->static_len+3+7)>>3;
  79905. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  79906. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  79907. s->last_lit));
  79908. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  79909. } else {
  79910. Assert(buf != (char*)0, "lost buf");
  79911. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  79912. }
  79913. #ifdef FORCE_STORED
  79914. if (buf != (char*)0) { /* force stored block */
  79915. #else
  79916. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  79917. #endif
  79918. _tr_stored_block(s, buf, stored_len, eof);
  79919. #ifdef FORCE_STATIC
  79920. } else if (static_lenb >= 0) { /* force static trees */
  79921. #else
  79922. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  79923. #endif
  79924. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  79925. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  79926. #ifdef DEBUG
  79927. s->compressed_len += 3 + s->static_len;
  79928. #endif
  79929. } else {
  79930. send_bits(s, (DYN_TREES<<1)+eof, 3);
  79931. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  79932. max_blindex+1);
  79933. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  79934. #ifdef DEBUG
  79935. s->compressed_len += 3 + s->opt_len;
  79936. #endif
  79937. }
  79938. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  79939. init_block(s);
  79940. if (eof) {
  79941. bi_windup(s);
  79942. #ifdef DEBUG
  79943. s->compressed_len += 7; /* align on byte boundary */
  79944. #endif
  79945. }
  79946. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  79947. s->compressed_len-7*eof));
  79948. }
  79949. int _tr_tally (deflate_state *s,
  79950. unsigned dist, /* distance of matched string */
  79951. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  79952. {
  79953. s->d_buf[s->last_lit] = (ush)dist;
  79954. s->l_buf[s->last_lit++] = (uch)lc;
  79955. if (dist == 0) {
  79956. s->dyn_ltree[lc].Freq++;
  79957. } else {
  79958. s->matches++;
  79959. dist--; /* dist = match distance - 1 */
  79960. Assert((ush)dist < (ush)MAX_DIST(s) &&
  79961. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  79962. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  79963. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  79964. s->dyn_dtree[d_code(dist)].Freq++;
  79965. }
  79966. #ifdef TRUNCATE_BLOCK
  79967. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  79968. ulg out_length = (ulg)s->last_lit*8L;
  79969. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  79970. int dcode;
  79971. for (dcode = 0; dcode < D_CODES; dcode++) {
  79972. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  79973. (5L+extra_dbits[dcode]);
  79974. }
  79975. out_length >>= 3;
  79976. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  79977. s->last_lit, in_length, out_length,
  79978. 100L - out_length*100L/in_length));
  79979. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  79980. }
  79981. #endif
  79982. return (s->last_lit == s->lit_bufsize-1);
  79983. }
  79984. local void compress_block (deflate_state *s,
  79985. ct_data *ltree, /* literal tree */
  79986. ct_data *dtree) /* distance tree */
  79987. {
  79988. unsigned dist; /* distance of matched string */
  79989. int lc; /* match length or unmatched char (if dist == 0) */
  79990. unsigned lx = 0; /* running index in l_buf */
  79991. unsigned code; /* the code to send */
  79992. int extra; /* number of extra bits to send */
  79993. if (s->last_lit != 0) do {
  79994. dist = s->d_buf[lx];
  79995. lc = s->l_buf[lx++];
  79996. if (dist == 0) {
  79997. send_code(s, lc, ltree); /* send a literal byte */
  79998. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  79999. } else {
  80000. code = _length_code[lc];
  80001. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  80002. extra = extra_lbits[code];
  80003. if (extra != 0) {
  80004. lc -= base_length[code];
  80005. send_bits(s, lc, extra); /* send the extra length bits */
  80006. }
  80007. dist--; /* dist is now the match distance - 1 */
  80008. code = d_code(dist);
  80009. Assert (code < D_CODES, "bad d_code");
  80010. send_code(s, code, dtree); /* send the distance code */
  80011. extra = extra_dbits[code];
  80012. if (extra != 0) {
  80013. dist -= base_dist[code];
  80014. send_bits(s, dist, extra); /* send the extra distance bits */
  80015. }
  80016. } /* literal or match pair ? */
  80017. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80018. "pendingBuf overflow");
  80019. } while (lx < s->last_lit);
  80020. send_code(s, END_BLOCK, ltree);
  80021. s->last_eob_len = ltree[END_BLOCK].Len;
  80022. }
  80023. local void set_data_type (deflate_state *s)
  80024. {
  80025. int n;
  80026. for (n = 0; n < 9; n++)
  80027. if (s->dyn_ltree[n].Freq != 0)
  80028. break;
  80029. if (n == 9)
  80030. for (n = 14; n < 32; n++)
  80031. if (s->dyn_ltree[n].Freq != 0)
  80032. break;
  80033. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80034. }
  80035. local unsigned bi_reverse (unsigned code, int len)
  80036. {
  80037. register unsigned res = 0;
  80038. do {
  80039. res |= code & 1;
  80040. code >>= 1, res <<= 1;
  80041. } while (--len > 0);
  80042. return res >> 1;
  80043. }
  80044. local void bi_flush (deflate_state *s)
  80045. {
  80046. if (s->bi_valid == 16) {
  80047. put_short(s, s->bi_buf);
  80048. s->bi_buf = 0;
  80049. s->bi_valid = 0;
  80050. } else if (s->bi_valid >= 8) {
  80051. put_byte(s, (Byte)s->bi_buf);
  80052. s->bi_buf >>= 8;
  80053. s->bi_valid -= 8;
  80054. }
  80055. }
  80056. local void bi_windup (deflate_state *s)
  80057. {
  80058. if (s->bi_valid > 8) {
  80059. put_short(s, s->bi_buf);
  80060. } else if (s->bi_valid > 0) {
  80061. put_byte(s, (Byte)s->bi_buf);
  80062. }
  80063. s->bi_buf = 0;
  80064. s->bi_valid = 0;
  80065. #ifdef DEBUG
  80066. s->bits_sent = (s->bits_sent+7) & ~7;
  80067. #endif
  80068. }
  80069. local void copy_block(deflate_state *s,
  80070. charf *buf, /* the input data */
  80071. unsigned len, /* its length */
  80072. int header) /* true if block header must be written */
  80073. {
  80074. bi_windup(s); /* align on byte boundary */
  80075. s->last_eob_len = 8; /* enough lookahead for inflate */
  80076. if (header) {
  80077. put_short(s, (ush)len);
  80078. put_short(s, (ush)~len);
  80079. #ifdef DEBUG
  80080. s->bits_sent += 2*16;
  80081. #endif
  80082. }
  80083. #ifdef DEBUG
  80084. s->bits_sent += (ulg)len<<3;
  80085. #endif
  80086. while (len--) {
  80087. put_byte(s, *buf++);
  80088. }
  80089. }
  80090. /*** End of inlined file: trees.c ***/
  80091. /*** Start of inlined file: zutil.c ***/
  80092. #ifndef NO_DUMMY_DECL
  80093. struct internal_state {int dummy;}; /* for buggy compilers */
  80094. #endif
  80095. const char * const z_errmsg[10] = {
  80096. "need dictionary", /* Z_NEED_DICT 2 */
  80097. "stream end", /* Z_STREAM_END 1 */
  80098. "", /* Z_OK 0 */
  80099. "file error", /* Z_ERRNO (-1) */
  80100. "stream error", /* Z_STREAM_ERROR (-2) */
  80101. "data error", /* Z_DATA_ERROR (-3) */
  80102. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80103. "buffer error", /* Z_BUF_ERROR (-5) */
  80104. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80105. ""};
  80106. #ifdef DEBUG
  80107. # ifndef verbose
  80108. # define verbose 0
  80109. # endif
  80110. int z_verbose = verbose;
  80111. void z_error (const char *m)
  80112. {
  80113. fprintf(stderr, "%s\n", m);
  80114. exit(1);
  80115. }
  80116. #endif
  80117. const char * ZEXPORT zError(int err)
  80118. {
  80119. return ERR_MSG(err);
  80120. }
  80121. #if defined(_WIN32_WCE)
  80122. int errno = 0;
  80123. #endif
  80124. #ifndef HAVE_MEMCPY
  80125. void zmemcpy(dest, source, len)
  80126. Bytef* dest;
  80127. const Bytef* source;
  80128. uInt len;
  80129. {
  80130. if (len == 0) return;
  80131. do {
  80132. *dest++ = *source++; /* ??? to be unrolled */
  80133. } while (--len != 0);
  80134. }
  80135. int zmemcmp(s1, s2, len)
  80136. const Bytef* s1;
  80137. const Bytef* s2;
  80138. uInt len;
  80139. {
  80140. uInt j;
  80141. for (j = 0; j < len; j++) {
  80142. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80143. }
  80144. return 0;
  80145. }
  80146. void zmemzero(dest, len)
  80147. Bytef* dest;
  80148. uInt len;
  80149. {
  80150. if (len == 0) return;
  80151. do {
  80152. *dest++ = 0; /* ??? to be unrolled */
  80153. } while (--len != 0);
  80154. }
  80155. #endif
  80156. #ifdef SYS16BIT
  80157. #ifdef __TURBOC__
  80158. # define MY_ZCALLOC
  80159. #define MAX_PTR 10
  80160. local int next_ptr = 0;
  80161. typedef struct ptr_table_s {
  80162. voidpf org_ptr;
  80163. voidpf new_ptr;
  80164. } ptr_table;
  80165. local ptr_table table[MAX_PTR];
  80166. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80167. {
  80168. voidpf buf = opaque; /* just to make some compilers happy */
  80169. ulg bsize = (ulg)items*size;
  80170. if (bsize < 65520L) {
  80171. buf = farmalloc(bsize);
  80172. if (*(ush*)&buf != 0) return buf;
  80173. } else {
  80174. buf = farmalloc(bsize + 16L);
  80175. }
  80176. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80177. table[next_ptr].org_ptr = buf;
  80178. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80179. *(ush*)&buf = 0;
  80180. table[next_ptr++].new_ptr = buf;
  80181. return buf;
  80182. }
  80183. void zcfree (voidpf opaque, voidpf ptr)
  80184. {
  80185. int n;
  80186. if (*(ush*)&ptr != 0) { /* object < 64K */
  80187. farfree(ptr);
  80188. return;
  80189. }
  80190. for (n = 0; n < next_ptr; n++) {
  80191. if (ptr != table[n].new_ptr) continue;
  80192. farfree(table[n].org_ptr);
  80193. while (++n < next_ptr) {
  80194. table[n-1] = table[n];
  80195. }
  80196. next_ptr--;
  80197. return;
  80198. }
  80199. ptr = opaque; /* just to make some compilers happy */
  80200. Assert(0, "zcfree: ptr not found");
  80201. }
  80202. #endif /* __TURBOC__ */
  80203. #ifdef M_I86
  80204. # define MY_ZCALLOC
  80205. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80206. # define _halloc halloc
  80207. # define _hfree hfree
  80208. #endif
  80209. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80210. {
  80211. if (opaque) opaque = 0; /* to make compiler happy */
  80212. return _halloc((long)items, size);
  80213. }
  80214. void zcfree (voidpf opaque, voidpf ptr)
  80215. {
  80216. if (opaque) opaque = 0; /* to make compiler happy */
  80217. _hfree(ptr);
  80218. }
  80219. #endif /* M_I86 */
  80220. #endif /* SYS16BIT */
  80221. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80222. #ifndef STDC
  80223. extern voidp malloc OF((uInt size));
  80224. extern voidp calloc OF((uInt items, uInt size));
  80225. extern void free OF((voidpf ptr));
  80226. #endif
  80227. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80228. {
  80229. if (opaque) items += size - size; /* make compiler happy */
  80230. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80231. (voidpf)calloc(items, size);
  80232. }
  80233. void zcfree (voidpf opaque, voidpf ptr)
  80234. {
  80235. free(ptr);
  80236. if (opaque) return; /* make compiler happy */
  80237. }
  80238. #endif /* MY_ZCALLOC */
  80239. /*** End of inlined file: zutil.c ***/
  80240. #undef Byte
  80241. }
  80242. #else
  80243. #include <zlib.h>
  80244. #endif
  80245. }
  80246. #if JUCE_MSVC
  80247. #pragma warning (pop)
  80248. #endif
  80249. BEGIN_JUCE_NAMESPACE
  80250. // internal helper object that holds the zlib structures so they don't have to be
  80251. // included publicly.
  80252. class GZIPDecompressHelper
  80253. {
  80254. public:
  80255. GZIPDecompressHelper (const bool noWrap)
  80256. : finished (true),
  80257. needsDictionary (false),
  80258. error (true),
  80259. streamIsValid (false),
  80260. data (0),
  80261. dataSize (0)
  80262. {
  80263. using namespace zlibNamespace;
  80264. zerostruct (stream);
  80265. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80266. finished = error = ! streamIsValid;
  80267. }
  80268. ~GZIPDecompressHelper()
  80269. {
  80270. using namespace zlibNamespace;
  80271. if (streamIsValid)
  80272. inflateEnd (&stream);
  80273. }
  80274. bool needsInput() const throw() { return dataSize <= 0; }
  80275. void setInput (uint8* const data_, const int size) throw()
  80276. {
  80277. data = data_;
  80278. dataSize = size;
  80279. }
  80280. int doNextBlock (uint8* const dest, const int destSize)
  80281. {
  80282. using namespace zlibNamespace;
  80283. if (streamIsValid && data != 0 && ! finished)
  80284. {
  80285. stream.next_in = data;
  80286. stream.next_out = dest;
  80287. stream.avail_in = dataSize;
  80288. stream.avail_out = destSize;
  80289. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80290. {
  80291. case Z_STREAM_END:
  80292. finished = true;
  80293. // deliberate fall-through
  80294. case Z_OK:
  80295. data += dataSize - stream.avail_in;
  80296. dataSize = stream.avail_in;
  80297. return destSize - stream.avail_out;
  80298. case Z_NEED_DICT:
  80299. needsDictionary = true;
  80300. data += dataSize - stream.avail_in;
  80301. dataSize = stream.avail_in;
  80302. break;
  80303. case Z_DATA_ERROR:
  80304. case Z_MEM_ERROR:
  80305. error = true;
  80306. default:
  80307. break;
  80308. }
  80309. }
  80310. return 0;
  80311. }
  80312. bool finished, needsDictionary, error, streamIsValid;
  80313. private:
  80314. zlibNamespace::z_stream stream;
  80315. uint8* data;
  80316. int dataSize;
  80317. GZIPDecompressHelper (const GZIPDecompressHelper&);
  80318. GZIPDecompressHelper& operator= (const GZIPDecompressHelper&);
  80319. };
  80320. const int gzipDecompBufferSize = 32768;
  80321. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80322. const bool deleteSourceWhenDestroyed,
  80323. const bool noWrap_,
  80324. const int64 uncompressedStreamLength_)
  80325. : sourceStream (sourceStream_),
  80326. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80327. uncompressedStreamLength (uncompressedStreamLength_),
  80328. noWrap (noWrap_),
  80329. isEof (false),
  80330. activeBufferSize (0),
  80331. originalSourcePos (sourceStream_->getPosition()),
  80332. currentPos (0),
  80333. buffer (gzipDecompBufferSize),
  80334. helper (new GZIPDecompressHelper (noWrap_))
  80335. {
  80336. }
  80337. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80338. {
  80339. }
  80340. int64 GZIPDecompressorInputStream::getTotalLength()
  80341. {
  80342. return uncompressedStreamLength;
  80343. }
  80344. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80345. {
  80346. if ((howMany > 0) && ! isEof)
  80347. {
  80348. jassert (destBuffer != 0);
  80349. if (destBuffer != 0)
  80350. {
  80351. int numRead = 0;
  80352. uint8* d = (uint8*) destBuffer;
  80353. while (! helper->error)
  80354. {
  80355. const int n = helper->doNextBlock (d, howMany);
  80356. currentPos += n;
  80357. if (n == 0)
  80358. {
  80359. if (helper->finished || helper->needsDictionary)
  80360. {
  80361. isEof = true;
  80362. return numRead;
  80363. }
  80364. if (helper->needsInput())
  80365. {
  80366. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80367. if (activeBufferSize > 0)
  80368. {
  80369. helper->setInput ((uint8*) buffer, activeBufferSize);
  80370. }
  80371. else
  80372. {
  80373. isEof = true;
  80374. return numRead;
  80375. }
  80376. }
  80377. }
  80378. else
  80379. {
  80380. numRead += n;
  80381. howMany -= n;
  80382. d += n;
  80383. if (howMany <= 0)
  80384. return numRead;
  80385. }
  80386. }
  80387. }
  80388. }
  80389. return 0;
  80390. }
  80391. bool GZIPDecompressorInputStream::isExhausted()
  80392. {
  80393. return helper->error || isEof;
  80394. }
  80395. int64 GZIPDecompressorInputStream::getPosition()
  80396. {
  80397. return currentPos;
  80398. }
  80399. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80400. {
  80401. if (newPos < currentPos)
  80402. {
  80403. // to go backwards, reset the stream and start again..
  80404. isEof = false;
  80405. activeBufferSize = 0;
  80406. currentPos = 0;
  80407. helper = new GZIPDecompressHelper (noWrap);
  80408. sourceStream->setPosition (originalSourcePos);
  80409. }
  80410. skipNextBytes (newPos - currentPos);
  80411. return true;
  80412. }
  80413. END_JUCE_NAMESPACE
  80414. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80415. #endif
  80416. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80417. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80418. #if JUCE_USE_FLAC
  80419. #if JUCE_WINDOWS
  80420. #include <windows.h>
  80421. #endif
  80422. #ifdef _MSC_VER
  80423. #pragma warning (disable : 4505)
  80424. #pragma warning (push)
  80425. #endif
  80426. namespace FlacNamespace
  80427. {
  80428. #if JUCE_INCLUDE_FLAC_CODE
  80429. #define FLAC__NO_DLL 1
  80430. #if ! defined (SIZE_MAX)
  80431. #define SIZE_MAX 0xffffffff
  80432. #endif
  80433. #define __STDC_LIMIT_MACROS 1
  80434. /*** Start of inlined file: all.h ***/
  80435. #ifndef FLAC__ALL_H
  80436. #define FLAC__ALL_H
  80437. /*** Start of inlined file: export.h ***/
  80438. #ifndef FLAC__EXPORT_H
  80439. #define FLAC__EXPORT_H
  80440. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80441. #define FLAC_API
  80442. #else
  80443. #ifdef FLAC_API_EXPORTS
  80444. #define FLAC_API _declspec(dllexport)
  80445. #else
  80446. #define FLAC_API _declspec(dllimport)
  80447. #endif
  80448. #endif
  80449. #define FLAC_API_VERSION_CURRENT 10
  80450. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80451. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80452. #ifdef __cplusplus
  80453. extern "C" {
  80454. #endif
  80455. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80456. #ifdef __cplusplus
  80457. }
  80458. #endif
  80459. #endif
  80460. /*** End of inlined file: export.h ***/
  80461. /*** Start of inlined file: assert.h ***/
  80462. #ifndef FLAC__ASSERT_H
  80463. #define FLAC__ASSERT_H
  80464. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80465. #ifdef DEBUG
  80466. #include <assert.h>
  80467. #define FLAC__ASSERT(x) assert(x)
  80468. #define FLAC__ASSERT_DECLARATION(x) x
  80469. #else
  80470. #define FLAC__ASSERT(x)
  80471. #define FLAC__ASSERT_DECLARATION(x)
  80472. #endif
  80473. #endif
  80474. /*** End of inlined file: assert.h ***/
  80475. /*** Start of inlined file: callback.h ***/
  80476. #ifndef FLAC__CALLBACK_H
  80477. #define FLAC__CALLBACK_H
  80478. /*** Start of inlined file: ordinals.h ***/
  80479. #ifndef FLAC__ORDINALS_H
  80480. #define FLAC__ORDINALS_H
  80481. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80482. #include <inttypes.h>
  80483. #endif
  80484. typedef signed char FLAC__int8;
  80485. typedef unsigned char FLAC__uint8;
  80486. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80487. typedef __int16 FLAC__int16;
  80488. typedef __int32 FLAC__int32;
  80489. typedef __int64 FLAC__int64;
  80490. typedef unsigned __int16 FLAC__uint16;
  80491. typedef unsigned __int32 FLAC__uint32;
  80492. typedef unsigned __int64 FLAC__uint64;
  80493. #elif defined(__EMX__)
  80494. typedef short FLAC__int16;
  80495. typedef long FLAC__int32;
  80496. typedef long long FLAC__int64;
  80497. typedef unsigned short FLAC__uint16;
  80498. typedef unsigned long FLAC__uint32;
  80499. typedef unsigned long long FLAC__uint64;
  80500. #else
  80501. typedef int16_t FLAC__int16;
  80502. typedef int32_t FLAC__int32;
  80503. typedef int64_t FLAC__int64;
  80504. typedef uint16_t FLAC__uint16;
  80505. typedef uint32_t FLAC__uint32;
  80506. typedef uint64_t FLAC__uint64;
  80507. #endif
  80508. typedef int FLAC__bool;
  80509. typedef FLAC__uint8 FLAC__byte;
  80510. #ifdef true
  80511. #undef true
  80512. #endif
  80513. #ifdef false
  80514. #undef false
  80515. #endif
  80516. #ifndef __cplusplus
  80517. #define true 1
  80518. #define false 0
  80519. #endif
  80520. #endif
  80521. /*** End of inlined file: ordinals.h ***/
  80522. #include <stdlib.h> /* for size_t */
  80523. #ifdef __cplusplus
  80524. extern "C" {
  80525. #endif
  80526. typedef void* FLAC__IOHandle;
  80527. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80528. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80529. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  80530. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  80531. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  80532. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  80533. typedef struct {
  80534. FLAC__IOCallback_Read read;
  80535. FLAC__IOCallback_Write write;
  80536. FLAC__IOCallback_Seek seek;
  80537. FLAC__IOCallback_Tell tell;
  80538. FLAC__IOCallback_Eof eof;
  80539. FLAC__IOCallback_Close close;
  80540. } FLAC__IOCallbacks;
  80541. #ifdef __cplusplus
  80542. }
  80543. #endif
  80544. #endif
  80545. /*** End of inlined file: callback.h ***/
  80546. /*** Start of inlined file: format.h ***/
  80547. #ifndef FLAC__FORMAT_H
  80548. #define FLAC__FORMAT_H
  80549. #ifdef __cplusplus
  80550. extern "C" {
  80551. #endif
  80552. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  80553. #define FLAC__MIN_BLOCK_SIZE (16u)
  80554. #define FLAC__MAX_BLOCK_SIZE (65535u)
  80555. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  80556. #define FLAC__MAX_CHANNELS (8u)
  80557. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  80558. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  80559. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  80560. #define FLAC__MAX_SAMPLE_RATE (655350u)
  80561. #define FLAC__MAX_LPC_ORDER (32u)
  80562. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  80563. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  80564. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  80565. #define FLAC__MAX_FIXED_ORDER (4u)
  80566. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  80567. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  80568. extern FLAC_API const char *FLAC__VERSION_STRING;
  80569. extern FLAC_API const char *FLAC__VENDOR_STRING;
  80570. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  80571. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  80572. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  80573. #define FLAC__STREAM_SYNC_LENGTH (4u)
  80574. typedef enum {
  80575. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  80576. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  80577. } FLAC__EntropyCodingMethodType;
  80578. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  80579. typedef struct {
  80580. unsigned *parameters;
  80581. unsigned *raw_bits;
  80582. unsigned capacity_by_order;
  80583. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  80584. typedef struct {
  80585. unsigned order;
  80586. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  80587. } FLAC__EntropyCodingMethod_PartitionedRice;
  80588. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  80589. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  80590. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  80591. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  80592. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  80593. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  80594. typedef struct {
  80595. FLAC__EntropyCodingMethodType type;
  80596. union {
  80597. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  80598. } data;
  80599. } FLAC__EntropyCodingMethod;
  80600. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  80601. typedef enum {
  80602. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  80603. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  80604. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  80605. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  80606. } FLAC__SubframeType;
  80607. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  80608. typedef struct {
  80609. FLAC__int32 value; /**< The constant signal value. */
  80610. } FLAC__Subframe_Constant;
  80611. typedef struct {
  80612. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  80613. } FLAC__Subframe_Verbatim;
  80614. typedef struct {
  80615. FLAC__EntropyCodingMethod entropy_coding_method;
  80616. unsigned order;
  80617. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  80618. const FLAC__int32 *residual;
  80619. } FLAC__Subframe_Fixed;
  80620. typedef struct {
  80621. FLAC__EntropyCodingMethod entropy_coding_method;
  80622. unsigned order;
  80623. unsigned qlp_coeff_precision;
  80624. int quantization_level;
  80625. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  80626. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  80627. const FLAC__int32 *residual;
  80628. } FLAC__Subframe_LPC;
  80629. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  80630. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  80631. typedef struct {
  80632. FLAC__SubframeType type;
  80633. union {
  80634. FLAC__Subframe_Constant constant;
  80635. FLAC__Subframe_Fixed fixed;
  80636. FLAC__Subframe_LPC lpc;
  80637. FLAC__Subframe_Verbatim verbatim;
  80638. } data;
  80639. unsigned wasted_bits;
  80640. } FLAC__Subframe;
  80641. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  80642. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  80643. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  80644. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  80645. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  80646. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  80647. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  80648. typedef enum {
  80649. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  80650. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  80651. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  80652. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  80653. } FLAC__ChannelAssignment;
  80654. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  80655. typedef enum {
  80656. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  80657. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  80658. } FLAC__FrameNumberType;
  80659. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  80660. typedef struct {
  80661. unsigned blocksize;
  80662. unsigned sample_rate;
  80663. unsigned channels;
  80664. FLAC__ChannelAssignment channel_assignment;
  80665. unsigned bits_per_sample;
  80666. FLAC__FrameNumberType number_type;
  80667. union {
  80668. FLAC__uint32 frame_number;
  80669. FLAC__uint64 sample_number;
  80670. } number;
  80671. FLAC__uint8 crc;
  80672. } FLAC__FrameHeader;
  80673. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  80674. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  80675. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  80676. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  80677. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  80678. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  80679. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  80680. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  80681. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  80682. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  80683. typedef struct {
  80684. FLAC__uint16 crc;
  80685. } FLAC__FrameFooter;
  80686. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  80687. typedef struct {
  80688. FLAC__FrameHeader header;
  80689. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  80690. FLAC__FrameFooter footer;
  80691. } FLAC__Frame;
  80692. typedef enum {
  80693. FLAC__METADATA_TYPE_STREAMINFO = 0,
  80694. FLAC__METADATA_TYPE_PADDING = 1,
  80695. FLAC__METADATA_TYPE_APPLICATION = 2,
  80696. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  80697. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  80698. FLAC__METADATA_TYPE_CUESHEET = 5,
  80699. FLAC__METADATA_TYPE_PICTURE = 6,
  80700. FLAC__METADATA_TYPE_UNDEFINED = 7
  80701. } FLAC__MetadataType;
  80702. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  80703. typedef struct {
  80704. unsigned min_blocksize, max_blocksize;
  80705. unsigned min_framesize, max_framesize;
  80706. unsigned sample_rate;
  80707. unsigned channels;
  80708. unsigned bits_per_sample;
  80709. FLAC__uint64 total_samples;
  80710. FLAC__byte md5sum[16];
  80711. } FLAC__StreamMetadata_StreamInfo;
  80712. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80713. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80714. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80715. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80716. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  80717. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  80718. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  80719. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  80720. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  80721. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  80722. typedef struct {
  80723. int dummy;
  80724. } FLAC__StreamMetadata_Padding;
  80725. typedef struct {
  80726. FLAC__byte id[4];
  80727. FLAC__byte *data;
  80728. } FLAC__StreamMetadata_Application;
  80729. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  80730. typedef struct {
  80731. FLAC__uint64 sample_number;
  80732. FLAC__uint64 stream_offset;
  80733. unsigned frame_samples;
  80734. } FLAC__StreamMetadata_SeekPoint;
  80735. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  80736. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  80737. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  80738. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  80739. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  80740. typedef struct {
  80741. unsigned num_points;
  80742. FLAC__StreamMetadata_SeekPoint *points;
  80743. } FLAC__StreamMetadata_SeekTable;
  80744. typedef struct {
  80745. FLAC__uint32 length;
  80746. FLAC__byte *entry;
  80747. } FLAC__StreamMetadata_VorbisComment_Entry;
  80748. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  80749. typedef struct {
  80750. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  80751. FLAC__uint32 num_comments;
  80752. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  80753. } FLAC__StreamMetadata_VorbisComment;
  80754. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  80755. typedef struct {
  80756. FLAC__uint64 offset;
  80757. FLAC__byte number;
  80758. } FLAC__StreamMetadata_CueSheet_Index;
  80759. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  80760. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  80761. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  80762. typedef struct {
  80763. FLAC__uint64 offset;
  80764. FLAC__byte number;
  80765. char isrc[13];
  80766. unsigned type:1;
  80767. unsigned pre_emphasis:1;
  80768. FLAC__byte num_indices;
  80769. FLAC__StreamMetadata_CueSheet_Index *indices;
  80770. } FLAC__StreamMetadata_CueSheet_Track;
  80771. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  80772. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  80773. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  80774. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  80775. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  80776. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  80777. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  80778. typedef struct {
  80779. char media_catalog_number[129];
  80780. FLAC__uint64 lead_in;
  80781. FLAC__bool is_cd;
  80782. unsigned num_tracks;
  80783. FLAC__StreamMetadata_CueSheet_Track *tracks;
  80784. } FLAC__StreamMetadata_CueSheet;
  80785. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  80786. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  80787. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  80788. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  80789. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  80790. typedef enum {
  80791. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  80792. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  80793. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  80794. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  80795. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  80796. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  80797. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  80798. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  80799. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  80800. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  80801. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  80802. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  80803. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  80804. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  80805. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  80806. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  80807. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  80808. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  80809. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  80810. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  80811. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  80812. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  80813. } FLAC__StreamMetadata_Picture_Type;
  80814. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  80815. typedef struct {
  80816. FLAC__StreamMetadata_Picture_Type type;
  80817. char *mime_type;
  80818. FLAC__byte *description;
  80819. FLAC__uint32 width;
  80820. FLAC__uint32 height;
  80821. FLAC__uint32 depth;
  80822. FLAC__uint32 colors;
  80823. FLAC__uint32 data_length;
  80824. FLAC__byte *data;
  80825. } FLAC__StreamMetadata_Picture;
  80826. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  80827. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  80828. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  80829. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  80830. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  80831. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  80832. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  80833. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  80834. typedef struct {
  80835. FLAC__byte *data;
  80836. } FLAC__StreamMetadata_Unknown;
  80837. typedef struct {
  80838. FLAC__MetadataType type;
  80839. FLAC__bool is_last;
  80840. unsigned length;
  80841. union {
  80842. FLAC__StreamMetadata_StreamInfo stream_info;
  80843. FLAC__StreamMetadata_Padding padding;
  80844. FLAC__StreamMetadata_Application application;
  80845. FLAC__StreamMetadata_SeekTable seek_table;
  80846. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  80847. FLAC__StreamMetadata_CueSheet cue_sheet;
  80848. FLAC__StreamMetadata_Picture picture;
  80849. FLAC__StreamMetadata_Unknown unknown;
  80850. } data;
  80851. } FLAC__StreamMetadata;
  80852. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  80853. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  80854. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  80855. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  80856. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  80857. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  80858. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  80859. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  80860. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  80861. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  80862. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  80863. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  80864. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  80865. #ifdef __cplusplus
  80866. }
  80867. #endif
  80868. #endif
  80869. /*** End of inlined file: format.h ***/
  80870. /*** Start of inlined file: metadata.h ***/
  80871. #ifndef FLAC__METADATA_H
  80872. #define FLAC__METADATA_H
  80873. #include <sys/types.h> /* for off_t */
  80874. #ifdef __cplusplus
  80875. extern "C" {
  80876. #endif
  80877. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  80878. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  80879. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  80880. 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);
  80881. struct FLAC__Metadata_SimpleIterator;
  80882. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  80883. typedef enum {
  80884. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  80885. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  80886. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  80887. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  80888. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  80889. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  80890. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  80891. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  80892. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  80893. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  80894. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  80895. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  80896. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  80897. } FLAC__Metadata_SimpleIteratorStatus;
  80898. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  80899. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  80900. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  80901. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  80902. 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);
  80903. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  80904. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  80905. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  80906. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  80907. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  80908. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  80909. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  80910. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  80911. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  80912. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80913. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80914. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  80915. struct FLAC__Metadata_Chain;
  80916. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  80917. struct FLAC__Metadata_Iterator;
  80918. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  80919. typedef enum {
  80920. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  80921. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  80922. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  80923. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  80924. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  80925. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  80926. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  80927. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  80928. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  80929. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  80930. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  80931. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  80932. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  80933. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  80934. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  80935. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  80936. } FLAC__Metadata_ChainStatus;
  80937. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  80938. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  80939. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  80940. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  80941. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  80942. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  80943. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80944. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80945. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  80946. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  80947. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80948. 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);
  80949. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  80950. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  80951. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  80952. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  80953. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  80954. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  80955. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  80956. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  80957. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  80958. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80959. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  80960. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80961. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80962. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  80963. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  80964. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  80965. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  80966. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  80967. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  80968. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80969. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80970. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  80971. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  80972. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  80973. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  80974. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  80975. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  80976. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  80977. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  80978. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80979. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  80980. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80981. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80982. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80983. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  80984. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  80985. 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);
  80986. 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);
  80987. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  80988. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  80989. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  80990. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  80991. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  80992. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  80993. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  80994. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  80995. 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);
  80996. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  80997. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  80998. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  80999. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81000. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81001. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  81002. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  81003. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  81004. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  81005. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  81006. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  81007. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  81008. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  81009. #ifdef __cplusplus
  81010. }
  81011. #endif
  81012. #endif
  81013. /*** End of inlined file: metadata.h ***/
  81014. /*** Start of inlined file: stream_decoder.h ***/
  81015. #ifndef FLAC__STREAM_DECODER_H
  81016. #define FLAC__STREAM_DECODER_H
  81017. #include <stdio.h> /* for FILE */
  81018. #ifdef __cplusplus
  81019. extern "C" {
  81020. #endif
  81021. typedef enum {
  81022. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81023. FLAC__STREAM_DECODER_READ_METADATA,
  81024. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81025. FLAC__STREAM_DECODER_READ_FRAME,
  81026. FLAC__STREAM_DECODER_END_OF_STREAM,
  81027. FLAC__STREAM_DECODER_OGG_ERROR,
  81028. FLAC__STREAM_DECODER_SEEK_ERROR,
  81029. FLAC__STREAM_DECODER_ABORTED,
  81030. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81031. FLAC__STREAM_DECODER_UNINITIALIZED
  81032. } FLAC__StreamDecoderState;
  81033. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81034. typedef enum {
  81035. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81036. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81037. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81038. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81039. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81040. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81041. } FLAC__StreamDecoderInitStatus;
  81042. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81043. typedef enum {
  81044. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81045. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81046. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81047. } FLAC__StreamDecoderReadStatus;
  81048. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81049. typedef enum {
  81050. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81051. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81052. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81053. } FLAC__StreamDecoderSeekStatus;
  81054. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81055. typedef enum {
  81056. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81057. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81058. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81059. } FLAC__StreamDecoderTellStatus;
  81060. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81061. typedef enum {
  81062. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81063. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81064. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81065. } FLAC__StreamDecoderLengthStatus;
  81066. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81067. typedef enum {
  81068. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81069. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81070. } FLAC__StreamDecoderWriteStatus;
  81071. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81072. typedef enum {
  81073. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81074. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81075. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81076. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81077. } FLAC__StreamDecoderErrorStatus;
  81078. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81079. struct FLAC__StreamDecoderProtected;
  81080. struct FLAC__StreamDecoderPrivate;
  81081. typedef struct {
  81082. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81083. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81084. } FLAC__StreamDecoder;
  81085. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81086. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81087. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81088. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81089. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81090. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81091. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81092. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81093. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81094. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81095. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81096. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81097. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81098. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81099. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81100. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81101. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81102. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81103. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81104. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81105. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81106. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81107. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81108. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81109. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81110. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81111. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81112. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81113. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81114. FLAC__StreamDecoder *decoder,
  81115. FLAC__StreamDecoderReadCallback read_callback,
  81116. FLAC__StreamDecoderSeekCallback seek_callback,
  81117. FLAC__StreamDecoderTellCallback tell_callback,
  81118. FLAC__StreamDecoderLengthCallback length_callback,
  81119. FLAC__StreamDecoderEofCallback eof_callback,
  81120. FLAC__StreamDecoderWriteCallback write_callback,
  81121. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81122. FLAC__StreamDecoderErrorCallback error_callback,
  81123. void *client_data
  81124. );
  81125. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81126. FLAC__StreamDecoder *decoder,
  81127. FLAC__StreamDecoderReadCallback read_callback,
  81128. FLAC__StreamDecoderSeekCallback seek_callback,
  81129. FLAC__StreamDecoderTellCallback tell_callback,
  81130. FLAC__StreamDecoderLengthCallback length_callback,
  81131. FLAC__StreamDecoderEofCallback eof_callback,
  81132. FLAC__StreamDecoderWriteCallback write_callback,
  81133. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81134. FLAC__StreamDecoderErrorCallback error_callback,
  81135. void *client_data
  81136. );
  81137. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81138. FLAC__StreamDecoder *decoder,
  81139. FILE *file,
  81140. FLAC__StreamDecoderWriteCallback write_callback,
  81141. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81142. FLAC__StreamDecoderErrorCallback error_callback,
  81143. void *client_data
  81144. );
  81145. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81146. FLAC__StreamDecoder *decoder,
  81147. FILE *file,
  81148. FLAC__StreamDecoderWriteCallback write_callback,
  81149. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81150. FLAC__StreamDecoderErrorCallback error_callback,
  81151. void *client_data
  81152. );
  81153. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81154. FLAC__StreamDecoder *decoder,
  81155. const char *filename,
  81156. FLAC__StreamDecoderWriteCallback write_callback,
  81157. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81158. FLAC__StreamDecoderErrorCallback error_callback,
  81159. void *client_data
  81160. );
  81161. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81162. FLAC__StreamDecoder *decoder,
  81163. const char *filename,
  81164. FLAC__StreamDecoderWriteCallback write_callback,
  81165. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81166. FLAC__StreamDecoderErrorCallback error_callback,
  81167. void *client_data
  81168. );
  81169. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81170. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81171. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81172. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81173. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81174. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81175. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81176. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81177. #ifdef __cplusplus
  81178. }
  81179. #endif
  81180. #endif
  81181. /*** End of inlined file: stream_decoder.h ***/
  81182. /*** Start of inlined file: stream_encoder.h ***/
  81183. #ifndef FLAC__STREAM_ENCODER_H
  81184. #define FLAC__STREAM_ENCODER_H
  81185. #include <stdio.h> /* for FILE */
  81186. #ifdef __cplusplus
  81187. extern "C" {
  81188. #endif
  81189. typedef enum {
  81190. FLAC__STREAM_ENCODER_OK = 0,
  81191. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81192. FLAC__STREAM_ENCODER_OGG_ERROR,
  81193. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81194. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81195. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81196. FLAC__STREAM_ENCODER_IO_ERROR,
  81197. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81198. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81199. } FLAC__StreamEncoderState;
  81200. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81201. typedef enum {
  81202. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81203. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81204. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81205. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81206. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81207. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81208. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81209. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81210. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81211. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81212. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81213. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81214. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81215. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81216. } FLAC__StreamEncoderInitStatus;
  81217. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81218. typedef enum {
  81219. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81220. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81221. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81222. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81223. } FLAC__StreamEncoderReadStatus;
  81224. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81225. typedef enum {
  81226. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81227. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81228. } FLAC__StreamEncoderWriteStatus;
  81229. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81230. typedef enum {
  81231. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81232. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81233. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81234. } FLAC__StreamEncoderSeekStatus;
  81235. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81236. typedef enum {
  81237. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81238. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81239. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81240. } FLAC__StreamEncoderTellStatus;
  81241. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81242. struct FLAC__StreamEncoderProtected;
  81243. struct FLAC__StreamEncoderPrivate;
  81244. typedef struct {
  81245. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81246. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81247. } FLAC__StreamEncoder;
  81248. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81249. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81250. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81251. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81252. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81253. 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);
  81254. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81255. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81256. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81257. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81258. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81259. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81260. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81261. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81262. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81263. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81264. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81265. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81266. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81267. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81268. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81269. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81270. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81271. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81272. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81273. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81274. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81275. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81276. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81277. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81278. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81279. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81280. 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);
  81281. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81282. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81283. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81284. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81285. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81286. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81287. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81288. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81289. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81290. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81291. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81292. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81293. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81294. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81295. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81296. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81297. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81298. 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);
  81299. 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);
  81300. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81301. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81302. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81303. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81304. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81305. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81306. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81307. #ifdef __cplusplus
  81308. }
  81309. #endif
  81310. #endif
  81311. /*** End of inlined file: stream_encoder.h ***/
  81312. #ifdef _MSC_VER
  81313. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81314. {
  81315. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81316. return (x>>16) | (x<<16);
  81317. }
  81318. #endif
  81319. #if defined(_MSC_VER) && defined(_X86_)
  81320. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81321. {
  81322. __asm {
  81323. mov edx, start
  81324. mov ecx, len
  81325. test ecx, ecx
  81326. loop1:
  81327. jz done1
  81328. mov eax, [edx]
  81329. bswap eax
  81330. mov [edx], eax
  81331. add edx, 4
  81332. dec ecx
  81333. jmp short loop1
  81334. done1:
  81335. }
  81336. }
  81337. #endif
  81338. #endif
  81339. /*** End of inlined file: all.h ***/
  81340. /*** Start of inlined file: bitmath.c ***/
  81341. /*** Start of inlined file: juce_FlacHeader.h ***/
  81342. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81343. // tasks..
  81344. #define VERSION "1.2.1"
  81345. #define FLAC__NO_DLL 1
  81346. #if JUCE_MSVC
  81347. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81348. #endif
  81349. #if JUCE_MAC
  81350. #define FLAC__SYS_DARWIN 1
  81351. #endif
  81352. /*** End of inlined file: juce_FlacHeader.h ***/
  81353. #if JUCE_USE_FLAC
  81354. #if HAVE_CONFIG_H
  81355. # include <config.h>
  81356. #endif
  81357. /*** Start of inlined file: bitmath.h ***/
  81358. #ifndef FLAC__PRIVATE__BITMATH_H
  81359. #define FLAC__PRIVATE__BITMATH_H
  81360. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81361. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81362. unsigned FLAC__bitmath_silog2(int v);
  81363. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81364. #endif
  81365. /*** End of inlined file: bitmath.h ***/
  81366. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81367. {
  81368. unsigned l = 0;
  81369. FLAC__ASSERT(v > 0);
  81370. while(v >>= 1)
  81371. l++;
  81372. return l;
  81373. }
  81374. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81375. {
  81376. unsigned l = 0;
  81377. FLAC__ASSERT(v > 0);
  81378. while(v >>= 1)
  81379. l++;
  81380. return l;
  81381. }
  81382. unsigned FLAC__bitmath_silog2(int v)
  81383. {
  81384. while(1) {
  81385. if(v == 0) {
  81386. return 0;
  81387. }
  81388. else if(v > 0) {
  81389. unsigned l = 0;
  81390. while(v) {
  81391. l++;
  81392. v >>= 1;
  81393. }
  81394. return l+1;
  81395. }
  81396. else if(v == -1) {
  81397. return 2;
  81398. }
  81399. else {
  81400. v++;
  81401. v = -v;
  81402. }
  81403. }
  81404. }
  81405. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81406. {
  81407. while(1) {
  81408. if(v == 0) {
  81409. return 0;
  81410. }
  81411. else if(v > 0) {
  81412. unsigned l = 0;
  81413. while(v) {
  81414. l++;
  81415. v >>= 1;
  81416. }
  81417. return l+1;
  81418. }
  81419. else if(v == -1) {
  81420. return 2;
  81421. }
  81422. else {
  81423. v++;
  81424. v = -v;
  81425. }
  81426. }
  81427. }
  81428. #endif
  81429. /*** End of inlined file: bitmath.c ***/
  81430. /*** Start of inlined file: bitreader.c ***/
  81431. /*** Start of inlined file: juce_FlacHeader.h ***/
  81432. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81433. // tasks..
  81434. #define VERSION "1.2.1"
  81435. #define FLAC__NO_DLL 1
  81436. #if JUCE_MSVC
  81437. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81438. #endif
  81439. #if JUCE_MAC
  81440. #define FLAC__SYS_DARWIN 1
  81441. #endif
  81442. /*** End of inlined file: juce_FlacHeader.h ***/
  81443. #if JUCE_USE_FLAC
  81444. #if HAVE_CONFIG_H
  81445. # include <config.h>
  81446. #endif
  81447. #include <stdlib.h> /* for malloc() */
  81448. #include <string.h> /* for memcpy(), memset() */
  81449. #ifdef _MSC_VER
  81450. #include <winsock.h> /* for ntohl() */
  81451. #elif defined FLAC__SYS_DARWIN
  81452. #include <machine/endian.h> /* for ntohl() */
  81453. #elif defined __MINGW32__
  81454. #include <winsock.h> /* for ntohl() */
  81455. #else
  81456. #include <netinet/in.h> /* for ntohl() */
  81457. #endif
  81458. /*** Start of inlined file: bitreader.h ***/
  81459. #ifndef FLAC__PRIVATE__BITREADER_H
  81460. #define FLAC__PRIVATE__BITREADER_H
  81461. #include <stdio.h> /* for FILE */
  81462. /*** Start of inlined file: cpu.h ***/
  81463. #ifndef FLAC__PRIVATE__CPU_H
  81464. #define FLAC__PRIVATE__CPU_H
  81465. #ifdef HAVE_CONFIG_H
  81466. #include <config.h>
  81467. #endif
  81468. typedef enum {
  81469. FLAC__CPUINFO_TYPE_IA32,
  81470. FLAC__CPUINFO_TYPE_PPC,
  81471. FLAC__CPUINFO_TYPE_UNKNOWN
  81472. } FLAC__CPUInfo_Type;
  81473. typedef struct {
  81474. FLAC__bool cpuid;
  81475. FLAC__bool bswap;
  81476. FLAC__bool cmov;
  81477. FLAC__bool mmx;
  81478. FLAC__bool fxsr;
  81479. FLAC__bool sse;
  81480. FLAC__bool sse2;
  81481. FLAC__bool sse3;
  81482. FLAC__bool ssse3;
  81483. FLAC__bool _3dnow;
  81484. FLAC__bool ext3dnow;
  81485. FLAC__bool extmmx;
  81486. } FLAC__CPUInfo_IA32;
  81487. typedef struct {
  81488. FLAC__bool altivec;
  81489. FLAC__bool ppc64;
  81490. } FLAC__CPUInfo_PPC;
  81491. typedef struct {
  81492. FLAC__bool use_asm;
  81493. FLAC__CPUInfo_Type type;
  81494. union {
  81495. FLAC__CPUInfo_IA32 ia32;
  81496. FLAC__CPUInfo_PPC ppc;
  81497. } data;
  81498. } FLAC__CPUInfo;
  81499. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81500. #ifndef FLAC__NO_ASM
  81501. #ifdef FLAC__CPU_IA32
  81502. #ifdef FLAC__HAS_NASM
  81503. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81504. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81505. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81506. #endif
  81507. #endif
  81508. #endif
  81509. #endif
  81510. /*** End of inlined file: cpu.h ***/
  81511. struct FLAC__BitReader;
  81512. typedef struct FLAC__BitReader FLAC__BitReader;
  81513. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81514. FLAC__BitReader *FLAC__bitreader_new(void);
  81515. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81516. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81517. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81518. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81519. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81520. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81521. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81522. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81523. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  81524. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  81525. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  81526. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  81527. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  81528. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  81529. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  81530. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81531. 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! */
  81532. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  81533. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81534. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81535. #ifndef FLAC__NO_ASM
  81536. # ifdef FLAC__CPU_IA32
  81537. # ifdef FLAC__HAS_NASM
  81538. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81539. # endif
  81540. # endif
  81541. #endif
  81542. #if 0 /* UNUSED */
  81543. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81544. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  81545. #endif
  81546. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  81547. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  81548. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  81549. #endif
  81550. /*** End of inlined file: bitreader.h ***/
  81551. /*** Start of inlined file: crc.h ***/
  81552. #ifndef FLAC__PRIVATE__CRC_H
  81553. #define FLAC__PRIVATE__CRC_H
  81554. extern FLAC__byte const FLAC__crc8_table[256];
  81555. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  81556. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  81557. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  81558. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  81559. extern unsigned FLAC__crc16_table[256];
  81560. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  81561. #if 0
  81562. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  81563. #endif
  81564. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  81565. #endif
  81566. /*** End of inlined file: crc.h ***/
  81567. typedef FLAC__uint32 brword;
  81568. #define FLAC__BYTES_PER_WORD 4
  81569. #define FLAC__BITS_PER_WORD 32
  81570. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  81571. #if WORDS_BIGENDIAN
  81572. #define SWAP_BE_WORD_TO_HOST(x) (x)
  81573. #else
  81574. #if defined (_MSC_VER) && defined (_X86_)
  81575. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  81576. #else
  81577. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  81578. #endif
  81579. #endif
  81580. #define COUNT_ZERO_MSBS(word) ( \
  81581. (word) <= 0xffff ? \
  81582. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  81583. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  81584. )
  81585. #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])) )
  81586. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  81587. static const unsigned char byte_to_unary_table[] = {
  81588. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  81589. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  81590. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81591. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81592. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81593. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81594. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81595. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  81604. };
  81605. #ifdef min
  81606. #undef min
  81607. #endif
  81608. #define min(x,y) ((x)<(y)?(x):(y))
  81609. #ifdef max
  81610. #undef max
  81611. #endif
  81612. #define max(x,y) ((x)>(y)?(x):(y))
  81613. #ifdef _MSC_VER
  81614. #define FLAC__U64L(x) x
  81615. #else
  81616. #define FLAC__U64L(x) x##LLU
  81617. #endif
  81618. #ifndef FLaC__INLINE
  81619. #define FLaC__INLINE
  81620. #endif
  81621. struct FLAC__BitReader {
  81622. brword *buffer;
  81623. unsigned capacity; /* in words */
  81624. unsigned words; /* # of completed words in buffer */
  81625. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  81626. unsigned consumed_words; /* #words ... */
  81627. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  81628. unsigned read_crc16; /* the running frame CRC */
  81629. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  81630. FLAC__BitReaderReadCallback read_callback;
  81631. void *client_data;
  81632. FLAC__CPUInfo cpu_info;
  81633. };
  81634. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  81635. {
  81636. register unsigned crc = br->read_crc16;
  81637. #if FLAC__BYTES_PER_WORD == 4
  81638. switch(br->crc16_align) {
  81639. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  81640. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81641. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81642. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81643. }
  81644. #elif FLAC__BYTES_PER_WORD == 8
  81645. switch(br->crc16_align) {
  81646. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  81647. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  81648. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  81649. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  81650. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  81651. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81652. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81653. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81654. }
  81655. #else
  81656. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  81657. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  81658. br->read_crc16 = crc;
  81659. #endif
  81660. br->crc16_align = 0;
  81661. }
  81662. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  81663. {
  81664. unsigned start, end;
  81665. size_t bytes;
  81666. FLAC__byte *target;
  81667. if(br->consumed_words > 0) {
  81668. start = br->consumed_words;
  81669. end = br->words + (br->bytes? 1:0);
  81670. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  81671. br->words -= start;
  81672. br->consumed_words = 0;
  81673. }
  81674. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  81675. if(bytes == 0)
  81676. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  81677. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  81678. #if WORDS_BIGENDIAN
  81679. #else
  81680. if(br->bytes)
  81681. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  81682. #endif
  81683. if(!br->read_callback(target, &bytes, br->client_data))
  81684. return false;
  81685. #if WORDS_BIGENDIAN
  81686. #else
  81687. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  81688. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  81689. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  81690. start = br->words;
  81691. local_swap32_block_(br->buffer + start, end - start);
  81692. }
  81693. else
  81694. # endif
  81695. for(start = br->words; start < end; start++)
  81696. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  81697. #endif
  81698. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  81699. br->words = end / FLAC__BYTES_PER_WORD;
  81700. br->bytes = end % FLAC__BYTES_PER_WORD;
  81701. return true;
  81702. }
  81703. FLAC__BitReader *FLAC__bitreader_new(void)
  81704. {
  81705. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  81706. return br;
  81707. }
  81708. void FLAC__bitreader_delete(FLAC__BitReader *br)
  81709. {
  81710. FLAC__ASSERT(0 != br);
  81711. FLAC__bitreader_free(br);
  81712. free(br);
  81713. }
  81714. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  81715. {
  81716. FLAC__ASSERT(0 != br);
  81717. br->words = br->bytes = 0;
  81718. br->consumed_words = br->consumed_bits = 0;
  81719. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  81720. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  81721. if(br->buffer == 0)
  81722. return false;
  81723. br->read_callback = rcb;
  81724. br->client_data = cd;
  81725. br->cpu_info = cpu;
  81726. return true;
  81727. }
  81728. void FLAC__bitreader_free(FLAC__BitReader *br)
  81729. {
  81730. FLAC__ASSERT(0 != br);
  81731. if(0 != br->buffer)
  81732. free(br->buffer);
  81733. br->buffer = 0;
  81734. br->capacity = 0;
  81735. br->words = br->bytes = 0;
  81736. br->consumed_words = br->consumed_bits = 0;
  81737. br->read_callback = 0;
  81738. br->client_data = 0;
  81739. }
  81740. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  81741. {
  81742. br->words = br->bytes = 0;
  81743. br->consumed_words = br->consumed_bits = 0;
  81744. return true;
  81745. }
  81746. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  81747. {
  81748. unsigned i, j;
  81749. if(br == 0) {
  81750. fprintf(out, "bitreader is NULL\n");
  81751. }
  81752. else {
  81753. 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);
  81754. for(i = 0; i < br->words; i++) {
  81755. fprintf(out, "%08X: ", i);
  81756. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  81757. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81758. fprintf(out, ".");
  81759. else
  81760. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  81761. fprintf(out, "\n");
  81762. }
  81763. if(br->bytes > 0) {
  81764. fprintf(out, "%08X: ", i);
  81765. for(j = 0; j < br->bytes*8; j++)
  81766. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81767. fprintf(out, ".");
  81768. else
  81769. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  81770. fprintf(out, "\n");
  81771. }
  81772. }
  81773. }
  81774. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  81775. {
  81776. FLAC__ASSERT(0 != br);
  81777. FLAC__ASSERT(0 != br->buffer);
  81778. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81779. br->read_crc16 = (unsigned)seed;
  81780. br->crc16_align = br->consumed_bits;
  81781. }
  81782. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  81783. {
  81784. FLAC__ASSERT(0 != br);
  81785. FLAC__ASSERT(0 != br->buffer);
  81786. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81787. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  81788. if(br->consumed_bits) {
  81789. const brword tail = br->buffer[br->consumed_words];
  81790. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  81791. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  81792. }
  81793. return br->read_crc16;
  81794. }
  81795. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  81796. {
  81797. return ((br->consumed_bits & 7) == 0);
  81798. }
  81799. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  81800. {
  81801. return 8 - (br->consumed_bits & 7);
  81802. }
  81803. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  81804. {
  81805. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  81806. }
  81807. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  81808. {
  81809. FLAC__ASSERT(0 != br);
  81810. FLAC__ASSERT(0 != br->buffer);
  81811. FLAC__ASSERT(bits <= 32);
  81812. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  81813. FLAC__ASSERT(br->consumed_words <= br->words);
  81814. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  81815. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  81816. *val = 0;
  81817. return true;
  81818. }
  81819. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  81820. if(!bitreader_read_from_client_(br))
  81821. return false;
  81822. }
  81823. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  81824. if(br->consumed_bits) {
  81825. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  81826. const brword word = br->buffer[br->consumed_words];
  81827. if(bits < n) {
  81828. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  81829. br->consumed_bits += bits;
  81830. return true;
  81831. }
  81832. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  81833. bits -= n;
  81834. crc16_update_word_(br, word);
  81835. br->consumed_words++;
  81836. br->consumed_bits = 0;
  81837. 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 */
  81838. *val <<= bits;
  81839. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  81840. br->consumed_bits = bits;
  81841. }
  81842. return true;
  81843. }
  81844. else {
  81845. const brword word = br->buffer[br->consumed_words];
  81846. if(bits < FLAC__BITS_PER_WORD) {
  81847. *val = word >> (FLAC__BITS_PER_WORD-bits);
  81848. br->consumed_bits = bits;
  81849. return true;
  81850. }
  81851. *val = word;
  81852. crc16_update_word_(br, word);
  81853. br->consumed_words++;
  81854. return true;
  81855. }
  81856. }
  81857. else {
  81858. if(br->consumed_bits) {
  81859. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  81860. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  81861. br->consumed_bits += bits;
  81862. return true;
  81863. }
  81864. else {
  81865. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  81866. br->consumed_bits += bits;
  81867. return true;
  81868. }
  81869. }
  81870. }
  81871. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  81872. {
  81873. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  81874. return false;
  81875. *val <<= (32-bits);
  81876. *val >>= (32-bits);
  81877. return true;
  81878. }
  81879. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  81880. {
  81881. FLAC__uint32 hi, lo;
  81882. if(bits > 32) {
  81883. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  81884. return false;
  81885. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  81886. return false;
  81887. *val = hi;
  81888. *val <<= 32;
  81889. *val |= lo;
  81890. }
  81891. else {
  81892. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  81893. return false;
  81894. *val = lo;
  81895. }
  81896. return true;
  81897. }
  81898. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  81899. {
  81900. FLAC__uint32 x8, x32 = 0;
  81901. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  81902. return false;
  81903. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81904. return false;
  81905. x32 |= (x8 << 8);
  81906. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81907. return false;
  81908. x32 |= (x8 << 16);
  81909. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81910. return false;
  81911. x32 |= (x8 << 24);
  81912. *val = x32;
  81913. return true;
  81914. }
  81915. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  81916. {
  81917. FLAC__ASSERT(0 != br);
  81918. FLAC__ASSERT(0 != br->buffer);
  81919. if(bits > 0) {
  81920. const unsigned n = br->consumed_bits & 7;
  81921. unsigned m;
  81922. FLAC__uint32 x;
  81923. if(n != 0) {
  81924. m = min(8-n, bits);
  81925. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  81926. return false;
  81927. bits -= m;
  81928. }
  81929. m = bits / 8;
  81930. if(m > 0) {
  81931. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  81932. return false;
  81933. bits %= 8;
  81934. }
  81935. if(bits > 0) {
  81936. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  81937. return false;
  81938. }
  81939. }
  81940. return true;
  81941. }
  81942. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  81943. {
  81944. FLAC__uint32 x;
  81945. FLAC__ASSERT(0 != br);
  81946. FLAC__ASSERT(0 != br->buffer);
  81947. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81948. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81949. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81950. return false;
  81951. nvals--;
  81952. }
  81953. if(0 == nvals)
  81954. return true;
  81955. while(nvals >= FLAC__BYTES_PER_WORD) {
  81956. if(br->consumed_words < br->words) {
  81957. br->consumed_words++;
  81958. nvals -= FLAC__BYTES_PER_WORD;
  81959. }
  81960. else if(!bitreader_read_from_client_(br))
  81961. return false;
  81962. }
  81963. while(nvals) {
  81964. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81965. return false;
  81966. nvals--;
  81967. }
  81968. return true;
  81969. }
  81970. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  81971. {
  81972. FLAC__uint32 x;
  81973. FLAC__ASSERT(0 != br);
  81974. FLAC__ASSERT(0 != br->buffer);
  81975. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81976. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81977. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81978. return false;
  81979. *val++ = (FLAC__byte)x;
  81980. nvals--;
  81981. }
  81982. if(0 == nvals)
  81983. return true;
  81984. while(nvals >= FLAC__BYTES_PER_WORD) {
  81985. if(br->consumed_words < br->words) {
  81986. const brword word = br->buffer[br->consumed_words++];
  81987. #if FLAC__BYTES_PER_WORD == 4
  81988. val[0] = (FLAC__byte)(word >> 24);
  81989. val[1] = (FLAC__byte)(word >> 16);
  81990. val[2] = (FLAC__byte)(word >> 8);
  81991. val[3] = (FLAC__byte)word;
  81992. #elif FLAC__BYTES_PER_WORD == 8
  81993. val[0] = (FLAC__byte)(word >> 56);
  81994. val[1] = (FLAC__byte)(word >> 48);
  81995. val[2] = (FLAC__byte)(word >> 40);
  81996. val[3] = (FLAC__byte)(word >> 32);
  81997. val[4] = (FLAC__byte)(word >> 24);
  81998. val[5] = (FLAC__byte)(word >> 16);
  81999. val[6] = (FLAC__byte)(word >> 8);
  82000. val[7] = (FLAC__byte)word;
  82001. #else
  82002. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  82003. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  82004. #endif
  82005. val += FLAC__BYTES_PER_WORD;
  82006. nvals -= FLAC__BYTES_PER_WORD;
  82007. }
  82008. else if(!bitreader_read_from_client_(br))
  82009. return false;
  82010. }
  82011. while(nvals) {
  82012. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82013. return false;
  82014. *val++ = (FLAC__byte)x;
  82015. nvals--;
  82016. }
  82017. return true;
  82018. }
  82019. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82020. #if 0 /* slow but readable version */
  82021. {
  82022. unsigned bit;
  82023. FLAC__ASSERT(0 != br);
  82024. FLAC__ASSERT(0 != br->buffer);
  82025. *val = 0;
  82026. while(1) {
  82027. if(!FLAC__bitreader_read_bit(br, &bit))
  82028. return false;
  82029. if(bit)
  82030. break;
  82031. else
  82032. *val++;
  82033. }
  82034. return true;
  82035. }
  82036. #else
  82037. {
  82038. unsigned i;
  82039. FLAC__ASSERT(0 != br);
  82040. FLAC__ASSERT(0 != br->buffer);
  82041. *val = 0;
  82042. while(1) {
  82043. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82044. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82045. if(b) {
  82046. i = COUNT_ZERO_MSBS(b);
  82047. *val += i;
  82048. i++;
  82049. br->consumed_bits += i;
  82050. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82051. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82052. br->consumed_words++;
  82053. br->consumed_bits = 0;
  82054. }
  82055. return true;
  82056. }
  82057. else {
  82058. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82059. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82060. br->consumed_words++;
  82061. br->consumed_bits = 0;
  82062. }
  82063. }
  82064. if(br->bytes) {
  82065. const unsigned end = br->bytes * 8;
  82066. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82067. if(b) {
  82068. i = COUNT_ZERO_MSBS(b);
  82069. *val += i;
  82070. i++;
  82071. br->consumed_bits += i;
  82072. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82073. return true;
  82074. }
  82075. else {
  82076. *val += end - br->consumed_bits;
  82077. br->consumed_bits += end;
  82078. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82079. }
  82080. }
  82081. if(!bitreader_read_from_client_(br))
  82082. return false;
  82083. }
  82084. }
  82085. #endif
  82086. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82087. {
  82088. FLAC__uint32 lsbs = 0, msbs = 0;
  82089. unsigned uval;
  82090. FLAC__ASSERT(0 != br);
  82091. FLAC__ASSERT(0 != br->buffer);
  82092. FLAC__ASSERT(parameter <= 31);
  82093. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82094. return false;
  82095. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82096. return false;
  82097. uval = (msbs << parameter) | lsbs;
  82098. if(uval & 1)
  82099. *val = -((int)(uval >> 1)) - 1;
  82100. else
  82101. *val = (int)(uval >> 1);
  82102. return true;
  82103. }
  82104. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82105. #ifdef _MSC_VER
  82106. {
  82107. unsigned i;
  82108. unsigned uval = 0;
  82109. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82110. register unsigned cwords;
  82111. register unsigned cbits;
  82112. FLAC__ASSERT(0 != br);
  82113. FLAC__ASSERT(0 != br->buffer);
  82114. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82115. FLAC__ASSERT(parameter < 32);
  82116. if(nvals == 0)
  82117. return true;
  82118. cbits = br->consumed_bits;
  82119. cwords = br->consumed_words;
  82120. while(1) {
  82121. while(1) {
  82122. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82123. brword b = br->buffer[cwords] << cbits;
  82124. if(b) {
  82125. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82126. __asm {
  82127. bsr eax, b
  82128. not eax
  82129. and eax, 31
  82130. mov i, eax
  82131. }
  82132. #else
  82133. i = COUNT_ZERO_MSBS(b);
  82134. #endif
  82135. uval += i;
  82136. bits = parameter;
  82137. i++;
  82138. cbits += i;
  82139. if(cbits == FLAC__BITS_PER_WORD) {
  82140. crc16_update_word_(br, br->buffer[cwords]);
  82141. cwords++;
  82142. cbits = 0;
  82143. }
  82144. goto break1;
  82145. }
  82146. else {
  82147. uval += FLAC__BITS_PER_WORD - cbits;
  82148. crc16_update_word_(br, br->buffer[cwords]);
  82149. cwords++;
  82150. cbits = 0;
  82151. }
  82152. }
  82153. if(br->bytes) {
  82154. const unsigned end = br->bytes * 8;
  82155. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82156. if(b) {
  82157. i = COUNT_ZERO_MSBS(b);
  82158. uval += i;
  82159. bits = parameter;
  82160. i++;
  82161. cbits += i;
  82162. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82163. goto break1;
  82164. }
  82165. else {
  82166. uval += end - cbits;
  82167. cbits += end;
  82168. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82169. }
  82170. }
  82171. br->consumed_bits = cbits;
  82172. br->consumed_words = cwords;
  82173. if(!bitreader_read_from_client_(br))
  82174. return false;
  82175. cwords = br->consumed_words;
  82176. }
  82177. break1:
  82178. FLAC__ASSERT(cwords <= br->words);
  82179. if(bits) {
  82180. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82181. br->consumed_bits = cbits;
  82182. br->consumed_words = cwords;
  82183. if(!bitreader_read_from_client_(br))
  82184. return false;
  82185. cwords = br->consumed_words;
  82186. }
  82187. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82188. if(cbits) {
  82189. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82190. const brword word = br->buffer[cwords];
  82191. if(bits < n) {
  82192. uval <<= bits;
  82193. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82194. cbits += bits;
  82195. goto break2;
  82196. }
  82197. uval <<= n;
  82198. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82199. bits -= n;
  82200. crc16_update_word_(br, word);
  82201. cwords++;
  82202. cbits = 0;
  82203. 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 */
  82204. uval <<= bits;
  82205. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82206. cbits = bits;
  82207. }
  82208. goto break2;
  82209. }
  82210. else {
  82211. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82212. uval <<= bits;
  82213. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82214. cbits = bits;
  82215. goto break2;
  82216. }
  82217. }
  82218. else {
  82219. uval <<= bits;
  82220. if(cbits) {
  82221. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82222. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82223. cbits += bits;
  82224. goto break2;
  82225. }
  82226. else {
  82227. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82228. cbits += bits;
  82229. goto break2;
  82230. }
  82231. }
  82232. }
  82233. break2:
  82234. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82235. --nvals;
  82236. if(nvals == 0) {
  82237. br->consumed_bits = cbits;
  82238. br->consumed_words = cwords;
  82239. return true;
  82240. }
  82241. uval = 0;
  82242. ++vals;
  82243. }
  82244. }
  82245. #else
  82246. {
  82247. unsigned i;
  82248. unsigned uval = 0;
  82249. register unsigned cwords;
  82250. register unsigned cbits;
  82251. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82252. FLAC__ASSERT(0 != br);
  82253. FLAC__ASSERT(0 != br->buffer);
  82254. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82255. FLAC__ASSERT(parameter < 32);
  82256. if(nvals == 0)
  82257. return true;
  82258. cbits = br->consumed_bits;
  82259. cwords = br->consumed_words;
  82260. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82261. while(1) {
  82262. while(1) {
  82263. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82264. brword b = br->buffer[cwords] << cbits;
  82265. if(b) {
  82266. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82267. asm volatile (
  82268. "bsrl %1, %0;"
  82269. "notl %0;"
  82270. "andl $31, %0;"
  82271. : "=r"(i)
  82272. : "r"(b)
  82273. );
  82274. #else
  82275. i = COUNT_ZERO_MSBS(b);
  82276. #endif
  82277. uval += i;
  82278. cbits += i;
  82279. cbits++; /* skip over stop bit */
  82280. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82281. crc16_update_word_(br, br->buffer[cwords]);
  82282. cwords++;
  82283. cbits = 0;
  82284. }
  82285. goto break1;
  82286. }
  82287. else {
  82288. uval += FLAC__BITS_PER_WORD - cbits;
  82289. crc16_update_word_(br, br->buffer[cwords]);
  82290. cwords++;
  82291. cbits = 0;
  82292. }
  82293. }
  82294. if(br->bytes) {
  82295. const unsigned end = br->bytes * 8;
  82296. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82297. if(b) {
  82298. i = COUNT_ZERO_MSBS(b);
  82299. uval += i;
  82300. cbits += i;
  82301. cbits++; /* skip over stop bit */
  82302. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82303. goto break1;
  82304. }
  82305. else {
  82306. uval += end - cbits;
  82307. cbits += end;
  82308. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82309. }
  82310. }
  82311. br->consumed_bits = cbits;
  82312. br->consumed_words = cwords;
  82313. if(!bitreader_read_from_client_(br))
  82314. return false;
  82315. cwords = br->consumed_words;
  82316. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82317. }
  82318. break1:
  82319. ucbits -= uval;
  82320. ucbits--; /* account for stop bit */
  82321. FLAC__ASSERT(cwords <= br->words);
  82322. if(parameter) {
  82323. while(ucbits < parameter) {
  82324. br->consumed_bits = cbits;
  82325. br->consumed_words = cwords;
  82326. if(!bitreader_read_from_client_(br))
  82327. return false;
  82328. cwords = br->consumed_words;
  82329. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82330. }
  82331. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82332. if(cbits) {
  82333. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82334. const brword word = br->buffer[cwords];
  82335. if(parameter < n) {
  82336. uval <<= parameter;
  82337. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82338. cbits += parameter;
  82339. }
  82340. else {
  82341. uval <<= n;
  82342. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82343. crc16_update_word_(br, word);
  82344. cwords++;
  82345. cbits = parameter - n;
  82346. 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 */
  82347. uval <<= cbits;
  82348. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82349. }
  82350. }
  82351. }
  82352. else {
  82353. cbits = parameter;
  82354. uval <<= parameter;
  82355. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82356. }
  82357. }
  82358. else {
  82359. uval <<= parameter;
  82360. if(cbits) {
  82361. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82362. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82363. cbits += parameter;
  82364. }
  82365. else {
  82366. cbits = parameter;
  82367. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82368. }
  82369. }
  82370. }
  82371. ucbits -= parameter;
  82372. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82373. --nvals;
  82374. if(nvals == 0) {
  82375. br->consumed_bits = cbits;
  82376. br->consumed_words = cwords;
  82377. return true;
  82378. }
  82379. uval = 0;
  82380. ++vals;
  82381. }
  82382. }
  82383. #endif
  82384. #if 0 /* UNUSED */
  82385. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82386. {
  82387. FLAC__uint32 lsbs = 0, msbs = 0;
  82388. unsigned bit, uval, k;
  82389. FLAC__ASSERT(0 != br);
  82390. FLAC__ASSERT(0 != br->buffer);
  82391. k = FLAC__bitmath_ilog2(parameter);
  82392. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82393. return false;
  82394. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82395. return false;
  82396. if(parameter == 1u<<k) {
  82397. uval = (msbs << k) | lsbs;
  82398. }
  82399. else {
  82400. unsigned d = (1 << (k+1)) - parameter;
  82401. if(lsbs >= d) {
  82402. if(!FLAC__bitreader_read_bit(br, &bit))
  82403. return false;
  82404. lsbs <<= 1;
  82405. lsbs |= bit;
  82406. lsbs -= d;
  82407. }
  82408. uval = msbs * parameter + lsbs;
  82409. }
  82410. if(uval & 1)
  82411. *val = -((int)(uval >> 1)) - 1;
  82412. else
  82413. *val = (int)(uval >> 1);
  82414. return true;
  82415. }
  82416. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82417. {
  82418. FLAC__uint32 lsbs, msbs = 0;
  82419. unsigned bit, k;
  82420. FLAC__ASSERT(0 != br);
  82421. FLAC__ASSERT(0 != br->buffer);
  82422. k = FLAC__bitmath_ilog2(parameter);
  82423. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82424. return false;
  82425. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82426. return false;
  82427. if(parameter == 1u<<k) {
  82428. *val = (msbs << k) | lsbs;
  82429. }
  82430. else {
  82431. unsigned d = (1 << (k+1)) - parameter;
  82432. if(lsbs >= d) {
  82433. if(!FLAC__bitreader_read_bit(br, &bit))
  82434. return false;
  82435. lsbs <<= 1;
  82436. lsbs |= bit;
  82437. lsbs -= d;
  82438. }
  82439. *val = msbs * parameter + lsbs;
  82440. }
  82441. return true;
  82442. }
  82443. #endif /* UNUSED */
  82444. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82445. {
  82446. FLAC__uint32 v = 0;
  82447. FLAC__uint32 x;
  82448. unsigned i;
  82449. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82450. return false;
  82451. if(raw)
  82452. raw[(*rawlen)++] = (FLAC__byte)x;
  82453. if(!(x & 0x80)) { /* 0xxxxxxx */
  82454. v = x;
  82455. i = 0;
  82456. }
  82457. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82458. v = x & 0x1F;
  82459. i = 1;
  82460. }
  82461. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82462. v = x & 0x0F;
  82463. i = 2;
  82464. }
  82465. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82466. v = x & 0x07;
  82467. i = 3;
  82468. }
  82469. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82470. v = x & 0x03;
  82471. i = 4;
  82472. }
  82473. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82474. v = x & 0x01;
  82475. i = 5;
  82476. }
  82477. else {
  82478. *val = 0xffffffff;
  82479. return true;
  82480. }
  82481. for( ; i; i--) {
  82482. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82483. return false;
  82484. if(raw)
  82485. raw[(*rawlen)++] = (FLAC__byte)x;
  82486. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82487. *val = 0xffffffff;
  82488. return true;
  82489. }
  82490. v <<= 6;
  82491. v |= (x & 0x3F);
  82492. }
  82493. *val = v;
  82494. return true;
  82495. }
  82496. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82497. {
  82498. FLAC__uint64 v = 0;
  82499. FLAC__uint32 x;
  82500. unsigned i;
  82501. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82502. return false;
  82503. if(raw)
  82504. raw[(*rawlen)++] = (FLAC__byte)x;
  82505. if(!(x & 0x80)) { /* 0xxxxxxx */
  82506. v = x;
  82507. i = 0;
  82508. }
  82509. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82510. v = x & 0x1F;
  82511. i = 1;
  82512. }
  82513. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82514. v = x & 0x0F;
  82515. i = 2;
  82516. }
  82517. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82518. v = x & 0x07;
  82519. i = 3;
  82520. }
  82521. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82522. v = x & 0x03;
  82523. i = 4;
  82524. }
  82525. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82526. v = x & 0x01;
  82527. i = 5;
  82528. }
  82529. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  82530. v = 0;
  82531. i = 6;
  82532. }
  82533. else {
  82534. *val = FLAC__U64L(0xffffffffffffffff);
  82535. return true;
  82536. }
  82537. for( ; i; i--) {
  82538. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82539. return false;
  82540. if(raw)
  82541. raw[(*rawlen)++] = (FLAC__byte)x;
  82542. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82543. *val = FLAC__U64L(0xffffffffffffffff);
  82544. return true;
  82545. }
  82546. v <<= 6;
  82547. v |= (x & 0x3F);
  82548. }
  82549. *val = v;
  82550. return true;
  82551. }
  82552. #endif
  82553. /*** End of inlined file: bitreader.c ***/
  82554. /*** Start of inlined file: bitwriter.c ***/
  82555. /*** Start of inlined file: juce_FlacHeader.h ***/
  82556. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82557. // tasks..
  82558. #define VERSION "1.2.1"
  82559. #define FLAC__NO_DLL 1
  82560. #if JUCE_MSVC
  82561. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82562. #endif
  82563. #if JUCE_MAC
  82564. #define FLAC__SYS_DARWIN 1
  82565. #endif
  82566. /*** End of inlined file: juce_FlacHeader.h ***/
  82567. #if JUCE_USE_FLAC
  82568. #if HAVE_CONFIG_H
  82569. # include <config.h>
  82570. #endif
  82571. #include <stdlib.h> /* for malloc() */
  82572. #include <string.h> /* for memcpy(), memset() */
  82573. #ifdef _MSC_VER
  82574. #include <winsock.h> /* for ntohl() */
  82575. #elif defined FLAC__SYS_DARWIN
  82576. #include <machine/endian.h> /* for ntohl() */
  82577. #elif defined __MINGW32__
  82578. #include <winsock.h> /* for ntohl() */
  82579. #else
  82580. #include <netinet/in.h> /* for ntohl() */
  82581. #endif
  82582. #if 0 /* UNUSED */
  82583. #endif
  82584. /*** Start of inlined file: bitwriter.h ***/
  82585. #ifndef FLAC__PRIVATE__BITWRITER_H
  82586. #define FLAC__PRIVATE__BITWRITER_H
  82587. #include <stdio.h> /* for FILE */
  82588. struct FLAC__BitWriter;
  82589. typedef struct FLAC__BitWriter FLAC__BitWriter;
  82590. FLAC__BitWriter *FLAC__bitwriter_new(void);
  82591. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  82592. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  82593. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  82594. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  82595. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  82596. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  82597. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  82598. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  82599. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  82600. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  82601. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  82602. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  82603. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  82604. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  82605. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  82606. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  82607. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  82608. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  82609. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  82610. #if 0 /* UNUSED */
  82611. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  82612. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  82613. #endif
  82614. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  82615. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  82616. #if 0 /* UNUSED */
  82617. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  82618. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  82619. #endif
  82620. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  82621. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  82622. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  82623. #endif
  82624. /*** End of inlined file: bitwriter.h ***/
  82625. /*** Start of inlined file: alloc.h ***/
  82626. #ifndef FLAC__SHARE__ALLOC_H
  82627. #define FLAC__SHARE__ALLOC_H
  82628. #if HAVE_CONFIG_H
  82629. # include <config.h>
  82630. #endif
  82631. #include <limits.h> /* for SIZE_MAX */
  82632. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  82633. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  82634. #endif
  82635. #include <stdlib.h> /* for size_t, malloc(), etc */
  82636. #ifndef SIZE_MAX
  82637. # ifndef SIZE_T_MAX
  82638. # ifdef _MSC_VER
  82639. # define SIZE_T_MAX UINT_MAX
  82640. # else
  82641. # error
  82642. # endif
  82643. # endif
  82644. # define SIZE_MAX SIZE_T_MAX
  82645. #endif
  82646. #ifndef FLaC__INLINE
  82647. #define FLaC__INLINE
  82648. #endif
  82649. static FLaC__INLINE void *safe_malloc_(size_t size)
  82650. {
  82651. if(!size)
  82652. size++;
  82653. return malloc(size);
  82654. }
  82655. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  82656. {
  82657. if(!nmemb || !size)
  82658. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82659. return calloc(nmemb, size);
  82660. }
  82661. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  82662. {
  82663. size2 += size1;
  82664. if(size2 < size1)
  82665. return 0;
  82666. return safe_malloc_(size2);
  82667. }
  82668. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  82669. {
  82670. size2 += size1;
  82671. if(size2 < size1)
  82672. return 0;
  82673. size3 += size2;
  82674. if(size3 < size2)
  82675. return 0;
  82676. return safe_malloc_(size3);
  82677. }
  82678. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  82679. {
  82680. size2 += size1;
  82681. if(size2 < size1)
  82682. return 0;
  82683. size3 += size2;
  82684. if(size3 < size2)
  82685. return 0;
  82686. size4 += size3;
  82687. if(size4 < size3)
  82688. return 0;
  82689. return safe_malloc_(size4);
  82690. }
  82691. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  82692. #if 0
  82693. needs support for cases where sizeof(size_t) != 4
  82694. {
  82695. if(sizeof(size_t) == 4) {
  82696. if ((double)size1 * (double)size2 < 4294967296.0)
  82697. return malloc(size1*size2);
  82698. }
  82699. return 0;
  82700. }
  82701. #else
  82702. {
  82703. if(!size1 || !size2)
  82704. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82705. if(size1 > SIZE_MAX / size2)
  82706. return 0;
  82707. return malloc(size1*size2);
  82708. }
  82709. #endif
  82710. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  82711. {
  82712. if(!size1 || !size2 || !size3)
  82713. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82714. if(size1 > SIZE_MAX / size2)
  82715. return 0;
  82716. size1 *= size2;
  82717. if(size1 > SIZE_MAX / size3)
  82718. return 0;
  82719. return malloc(size1*size3);
  82720. }
  82721. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  82722. {
  82723. if(!size1 || !size2)
  82724. return safe_malloc_(size3);
  82725. if(size1 > SIZE_MAX / size2)
  82726. return 0;
  82727. return safe_malloc_add_2op_(size1*size2, size3);
  82728. }
  82729. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  82730. {
  82731. if(!size1 || (!size2 && !size3))
  82732. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82733. size2 += size3;
  82734. if(size2 < size3)
  82735. return 0;
  82736. return safe_malloc_mul_2op_(size1, size2);
  82737. }
  82738. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  82739. {
  82740. size2 += size1;
  82741. if(size2 < size1)
  82742. return 0;
  82743. return realloc(ptr, size2);
  82744. }
  82745. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  82746. {
  82747. size2 += size1;
  82748. if(size2 < size1)
  82749. return 0;
  82750. size3 += size2;
  82751. if(size3 < size2)
  82752. return 0;
  82753. return realloc(ptr, size3);
  82754. }
  82755. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  82756. {
  82757. size2 += size1;
  82758. if(size2 < size1)
  82759. return 0;
  82760. size3 += size2;
  82761. if(size3 < size2)
  82762. return 0;
  82763. size4 += size3;
  82764. if(size4 < size3)
  82765. return 0;
  82766. return realloc(ptr, size4);
  82767. }
  82768. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  82769. {
  82770. if(!size1 || !size2)
  82771. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82772. if(size1 > SIZE_MAX / size2)
  82773. return 0;
  82774. return realloc(ptr, size1*size2);
  82775. }
  82776. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  82777. {
  82778. if(!size1 || (!size2 && !size3))
  82779. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82780. size2 += size3;
  82781. if(size2 < size3)
  82782. return 0;
  82783. return safe_realloc_mul_2op_(ptr, size1, size2);
  82784. }
  82785. #endif
  82786. /*** End of inlined file: alloc.h ***/
  82787. typedef FLAC__uint32 bwword;
  82788. #define FLAC__BYTES_PER_WORD 4
  82789. #define FLAC__BITS_PER_WORD 32
  82790. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82791. #if WORDS_BIGENDIAN
  82792. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82793. #else
  82794. #ifdef _MSC_VER
  82795. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82796. #else
  82797. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82798. #endif
  82799. #endif
  82800. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  82801. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  82802. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  82803. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  82804. #ifdef min
  82805. #undef min
  82806. #endif
  82807. #define min(x,y) ((x)<(y)?(x):(y))
  82808. #ifdef _MSC_VER
  82809. #define FLAC__U64L(x) x
  82810. #else
  82811. #define FLAC__U64L(x) x##LLU
  82812. #endif
  82813. #ifndef FLaC__INLINE
  82814. #define FLaC__INLINE
  82815. #endif
  82816. struct FLAC__BitWriter {
  82817. bwword *buffer;
  82818. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  82819. unsigned capacity; /* capacity of buffer in words */
  82820. unsigned words; /* # of complete words in buffer */
  82821. unsigned bits; /* # of used bits in accum */
  82822. };
  82823. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  82824. {
  82825. unsigned new_capacity;
  82826. bwword *new_buffer;
  82827. FLAC__ASSERT(0 != bw);
  82828. FLAC__ASSERT(0 != bw->buffer);
  82829. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  82830. if(bw->capacity >= new_capacity)
  82831. return true;
  82832. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  82833. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82834. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82835. FLAC__ASSERT(new_capacity > bw->capacity);
  82836. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  82837. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  82838. if(new_buffer == 0)
  82839. return false;
  82840. bw->buffer = new_buffer;
  82841. bw->capacity = new_capacity;
  82842. return true;
  82843. }
  82844. FLAC__BitWriter *FLAC__bitwriter_new(void)
  82845. {
  82846. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  82847. return bw;
  82848. }
  82849. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  82850. {
  82851. FLAC__ASSERT(0 != bw);
  82852. FLAC__bitwriter_free(bw);
  82853. free(bw);
  82854. }
  82855. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  82856. {
  82857. FLAC__ASSERT(0 != bw);
  82858. bw->words = bw->bits = 0;
  82859. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  82860. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  82861. if(bw->buffer == 0)
  82862. return false;
  82863. return true;
  82864. }
  82865. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  82866. {
  82867. FLAC__ASSERT(0 != bw);
  82868. if(0 != bw->buffer)
  82869. free(bw->buffer);
  82870. bw->buffer = 0;
  82871. bw->capacity = 0;
  82872. bw->words = bw->bits = 0;
  82873. }
  82874. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  82875. {
  82876. bw->words = bw->bits = 0;
  82877. }
  82878. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  82879. {
  82880. unsigned i, j;
  82881. if(bw == 0) {
  82882. fprintf(out, "bitwriter is NULL\n");
  82883. }
  82884. else {
  82885. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  82886. for(i = 0; i < bw->words; i++) {
  82887. fprintf(out, "%08X: ", i);
  82888. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82889. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82890. fprintf(out, "\n");
  82891. }
  82892. if(bw->bits > 0) {
  82893. fprintf(out, "%08X: ", i);
  82894. for(j = 0; j < bw->bits; j++)
  82895. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  82896. fprintf(out, "\n");
  82897. }
  82898. }
  82899. }
  82900. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  82901. {
  82902. const FLAC__byte *buffer;
  82903. size_t bytes;
  82904. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82905. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82906. return false;
  82907. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  82908. FLAC__bitwriter_release_buffer(bw);
  82909. return true;
  82910. }
  82911. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  82912. {
  82913. const FLAC__byte *buffer;
  82914. size_t bytes;
  82915. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82916. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82917. return false;
  82918. *crc = FLAC__crc8(buffer, bytes);
  82919. FLAC__bitwriter_release_buffer(bw);
  82920. return true;
  82921. }
  82922. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  82923. {
  82924. return ((bw->bits & 7) == 0);
  82925. }
  82926. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  82927. {
  82928. return FLAC__TOTAL_BITS(bw);
  82929. }
  82930. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  82931. {
  82932. FLAC__ASSERT((bw->bits & 7) == 0);
  82933. if(bw->bits & 7)
  82934. return false;
  82935. if(bw->bits) {
  82936. FLAC__ASSERT(bw->words <= bw->capacity);
  82937. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  82938. return false;
  82939. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  82940. }
  82941. *buffer = (FLAC__byte*)bw->buffer;
  82942. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  82943. return true;
  82944. }
  82945. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  82946. {
  82947. (void)bw;
  82948. }
  82949. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  82950. {
  82951. unsigned n;
  82952. FLAC__ASSERT(0 != bw);
  82953. FLAC__ASSERT(0 != bw->buffer);
  82954. if(bits == 0)
  82955. return true;
  82956. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82957. return false;
  82958. if(bw->bits) {
  82959. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  82960. bw->accum <<= n;
  82961. bits -= n;
  82962. bw->bits += n;
  82963. if(bw->bits == FLAC__BITS_PER_WORD) {
  82964. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82965. bw->bits = 0;
  82966. }
  82967. else
  82968. return true;
  82969. }
  82970. while(bits >= FLAC__BITS_PER_WORD) {
  82971. bw->buffer[bw->words++] = 0;
  82972. bits -= FLAC__BITS_PER_WORD;
  82973. }
  82974. if(bits > 0) {
  82975. bw->accum = 0;
  82976. bw->bits = bits;
  82977. }
  82978. return true;
  82979. }
  82980. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  82981. {
  82982. register unsigned left;
  82983. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82984. FLAC__ASSERT(0 != bw);
  82985. FLAC__ASSERT(0 != bw->buffer);
  82986. FLAC__ASSERT(bits <= 32);
  82987. if(bits == 0)
  82988. return true;
  82989. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82990. return false;
  82991. left = FLAC__BITS_PER_WORD - bw->bits;
  82992. if(bits < left) {
  82993. bw->accum <<= bits;
  82994. bw->accum |= val;
  82995. bw->bits += bits;
  82996. }
  82997. 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 */
  82998. bw->accum <<= left;
  82999. bw->accum |= val >> (bw->bits = bits - left);
  83000. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83001. bw->accum = val;
  83002. }
  83003. else {
  83004. bw->accum = val;
  83005. bw->bits = 0;
  83006. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  83007. }
  83008. return true;
  83009. }
  83010. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83011. {
  83012. if(bits < 32)
  83013. val &= (~(0xffffffff << bits));
  83014. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83015. }
  83016. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83017. {
  83018. if(bits > 32) {
  83019. return
  83020. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83021. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83022. }
  83023. else
  83024. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83025. }
  83026. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83027. {
  83028. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83029. return false;
  83030. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83031. return false;
  83032. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83033. return false;
  83034. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83035. return false;
  83036. return true;
  83037. }
  83038. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83039. {
  83040. unsigned i;
  83041. for(i = 0; i < nvals; i++) {
  83042. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83043. return false;
  83044. }
  83045. return true;
  83046. }
  83047. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83048. {
  83049. if(val < 32)
  83050. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83051. else
  83052. return
  83053. FLAC__bitwriter_write_zeroes(bw, val) &&
  83054. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83055. }
  83056. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83057. {
  83058. FLAC__uint32 uval;
  83059. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83060. uval = (val<<1) ^ (val>>31);
  83061. return 1 + parameter + (uval >> parameter);
  83062. }
  83063. #if 0 /* UNUSED */
  83064. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83065. {
  83066. unsigned bits, msbs, uval;
  83067. unsigned k;
  83068. FLAC__ASSERT(parameter > 0);
  83069. if(val < 0)
  83070. uval = (unsigned)(((-(++val)) << 1) + 1);
  83071. else
  83072. uval = (unsigned)(val << 1);
  83073. k = FLAC__bitmath_ilog2(parameter);
  83074. if(parameter == 1u<<k) {
  83075. FLAC__ASSERT(k <= 30);
  83076. msbs = uval >> k;
  83077. bits = 1 + k + msbs;
  83078. }
  83079. else {
  83080. unsigned q, r, d;
  83081. d = (1 << (k+1)) - parameter;
  83082. q = uval / parameter;
  83083. r = uval - (q * parameter);
  83084. bits = 1 + q + k;
  83085. if(r >= d)
  83086. bits++;
  83087. }
  83088. return bits;
  83089. }
  83090. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83091. {
  83092. unsigned bits, msbs;
  83093. unsigned k;
  83094. FLAC__ASSERT(parameter > 0);
  83095. k = FLAC__bitmath_ilog2(parameter);
  83096. if(parameter == 1u<<k) {
  83097. FLAC__ASSERT(k <= 30);
  83098. msbs = uval >> k;
  83099. bits = 1 + k + msbs;
  83100. }
  83101. else {
  83102. unsigned q, r, d;
  83103. d = (1 << (k+1)) - parameter;
  83104. q = uval / parameter;
  83105. r = uval - (q * parameter);
  83106. bits = 1 + q + k;
  83107. if(r >= d)
  83108. bits++;
  83109. }
  83110. return bits;
  83111. }
  83112. #endif /* UNUSED */
  83113. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83114. {
  83115. unsigned total_bits, interesting_bits, msbs;
  83116. FLAC__uint32 uval, pattern;
  83117. FLAC__ASSERT(0 != bw);
  83118. FLAC__ASSERT(0 != bw->buffer);
  83119. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83120. uval = (val<<1) ^ (val>>31);
  83121. msbs = uval >> parameter;
  83122. interesting_bits = 1 + parameter;
  83123. total_bits = interesting_bits + msbs;
  83124. pattern = 1 << parameter; /* the unary end bit */
  83125. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83126. if(total_bits <= 32)
  83127. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83128. else
  83129. return
  83130. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83131. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83132. }
  83133. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83134. {
  83135. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83136. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83137. FLAC__uint32 uval;
  83138. unsigned left;
  83139. const unsigned lsbits = 1 + parameter;
  83140. unsigned msbits;
  83141. FLAC__ASSERT(0 != bw);
  83142. FLAC__ASSERT(0 != bw->buffer);
  83143. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83144. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83145. while(nvals) {
  83146. uval = (*vals<<1) ^ (*vals>>31);
  83147. msbits = uval >> parameter;
  83148. #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) */
  83149. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83150. bw->bits = bw->bits + msbits + lsbits;
  83151. uval |= mask1; /* set stop bit */
  83152. uval &= mask2; /* mask off unused top bits */
  83153. bw->accum <<= msbits;
  83154. bw->accum <<= lsbits;
  83155. bw->accum |= uval;
  83156. if(bw->bits == FLAC__BITS_PER_WORD) {
  83157. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83158. bw->bits = 0;
  83159. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83160. FLAC__ASSERT(bw->capacity == bw->words);
  83161. return false;
  83162. }
  83163. }
  83164. }
  83165. else {
  83166. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83167. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83168. bw->bits = bw->bits + msbits + lsbits;
  83169. uval |= mask1; /* set stop bit */
  83170. uval &= mask2; /* mask off unused top bits */
  83171. bw->accum <<= msbits + lsbits;
  83172. bw->accum |= uval;
  83173. }
  83174. else {
  83175. #endif
  83176. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83177. return false;
  83178. if(msbits) {
  83179. if(bw->bits) {
  83180. left = FLAC__BITS_PER_WORD - bw->bits;
  83181. if(msbits < left) {
  83182. bw->accum <<= msbits;
  83183. bw->bits += msbits;
  83184. goto break1;
  83185. }
  83186. else {
  83187. bw->accum <<= left;
  83188. msbits -= left;
  83189. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83190. bw->bits = 0;
  83191. }
  83192. }
  83193. while(msbits >= FLAC__BITS_PER_WORD) {
  83194. bw->buffer[bw->words++] = 0;
  83195. msbits -= FLAC__BITS_PER_WORD;
  83196. }
  83197. if(msbits > 0) {
  83198. bw->accum = 0;
  83199. bw->bits = msbits;
  83200. }
  83201. }
  83202. break1:
  83203. uval |= mask1; /* set stop bit */
  83204. uval &= mask2; /* mask off unused top bits */
  83205. left = FLAC__BITS_PER_WORD - bw->bits;
  83206. if(lsbits < left) {
  83207. bw->accum <<= lsbits;
  83208. bw->accum |= uval;
  83209. bw->bits += lsbits;
  83210. }
  83211. else {
  83212. FLAC__ASSERT(bw->bits);
  83213. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83214. bw->accum <<= left;
  83215. bw->accum |= uval >> (bw->bits = lsbits - left);
  83216. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83217. bw->accum = uval;
  83218. }
  83219. #if 1
  83220. }
  83221. #endif
  83222. vals++;
  83223. nvals--;
  83224. }
  83225. return true;
  83226. }
  83227. #if 0 /* UNUSED */
  83228. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83229. {
  83230. unsigned total_bits, msbs, uval;
  83231. unsigned k;
  83232. FLAC__ASSERT(0 != bw);
  83233. FLAC__ASSERT(0 != bw->buffer);
  83234. FLAC__ASSERT(parameter > 0);
  83235. if(val < 0)
  83236. uval = (unsigned)(((-(++val)) << 1) + 1);
  83237. else
  83238. uval = (unsigned)(val << 1);
  83239. k = FLAC__bitmath_ilog2(parameter);
  83240. if(parameter == 1u<<k) {
  83241. unsigned pattern;
  83242. FLAC__ASSERT(k <= 30);
  83243. msbs = uval >> k;
  83244. total_bits = 1 + k + msbs;
  83245. pattern = 1 << k; /* the unary end bit */
  83246. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83247. if(total_bits <= 32) {
  83248. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83249. return false;
  83250. }
  83251. else {
  83252. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83253. return false;
  83254. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83255. return false;
  83256. }
  83257. }
  83258. else {
  83259. unsigned q, r, d;
  83260. d = (1 << (k+1)) - parameter;
  83261. q = uval / parameter;
  83262. r = uval - (q * parameter);
  83263. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83264. return false;
  83265. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83266. return false;
  83267. if(r >= d) {
  83268. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83269. return false;
  83270. }
  83271. else {
  83272. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83273. return false;
  83274. }
  83275. }
  83276. return true;
  83277. }
  83278. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83279. {
  83280. unsigned total_bits, msbs;
  83281. unsigned k;
  83282. FLAC__ASSERT(0 != bw);
  83283. FLAC__ASSERT(0 != bw->buffer);
  83284. FLAC__ASSERT(parameter > 0);
  83285. k = FLAC__bitmath_ilog2(parameter);
  83286. if(parameter == 1u<<k) {
  83287. unsigned pattern;
  83288. FLAC__ASSERT(k <= 30);
  83289. msbs = uval >> k;
  83290. total_bits = 1 + k + msbs;
  83291. pattern = 1 << k; /* the unary end bit */
  83292. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83293. if(total_bits <= 32) {
  83294. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83295. return false;
  83296. }
  83297. else {
  83298. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83299. return false;
  83300. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83301. return false;
  83302. }
  83303. }
  83304. else {
  83305. unsigned q, r, d;
  83306. d = (1 << (k+1)) - parameter;
  83307. q = uval / parameter;
  83308. r = uval - (q * parameter);
  83309. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83310. return false;
  83311. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83312. return false;
  83313. if(r >= d) {
  83314. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83315. return false;
  83316. }
  83317. else {
  83318. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83319. return false;
  83320. }
  83321. }
  83322. return true;
  83323. }
  83324. #endif /* UNUSED */
  83325. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83326. {
  83327. FLAC__bool ok = 1;
  83328. FLAC__ASSERT(0 != bw);
  83329. FLAC__ASSERT(0 != bw->buffer);
  83330. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83331. if(val < 0x80) {
  83332. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83333. }
  83334. else if(val < 0x800) {
  83335. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83336. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83337. }
  83338. else if(val < 0x10000) {
  83339. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83340. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83341. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83342. }
  83343. else if(val < 0x200000) {
  83344. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83345. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83346. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83347. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83348. }
  83349. else if(val < 0x4000000) {
  83350. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83351. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83352. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83353. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83354. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83355. }
  83356. else {
  83357. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83358. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83359. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83360. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83361. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83362. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83363. }
  83364. return ok;
  83365. }
  83366. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83367. {
  83368. FLAC__bool ok = 1;
  83369. FLAC__ASSERT(0 != bw);
  83370. FLAC__ASSERT(0 != bw->buffer);
  83371. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83372. if(val < 0x80) {
  83373. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83374. }
  83375. else if(val < 0x800) {
  83376. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83377. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83378. }
  83379. else if(val < 0x10000) {
  83380. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83381. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83382. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83383. }
  83384. else if(val < 0x200000) {
  83385. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83386. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83387. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83388. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83389. }
  83390. else if(val < 0x4000000) {
  83391. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83392. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83393. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83394. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83395. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83396. }
  83397. else if(val < 0x80000000) {
  83398. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83399. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83400. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83401. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83402. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83403. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83404. }
  83405. else {
  83406. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83407. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83408. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83409. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83410. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83411. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83412. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83413. }
  83414. return ok;
  83415. }
  83416. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83417. {
  83418. if(bw->bits & 7u)
  83419. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83420. else
  83421. return true;
  83422. }
  83423. #endif
  83424. /*** End of inlined file: bitwriter.c ***/
  83425. /*** Start of inlined file: cpu.c ***/
  83426. /*** Start of inlined file: juce_FlacHeader.h ***/
  83427. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83428. // tasks..
  83429. #define VERSION "1.2.1"
  83430. #define FLAC__NO_DLL 1
  83431. #if JUCE_MSVC
  83432. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83433. #endif
  83434. #if JUCE_MAC
  83435. #define FLAC__SYS_DARWIN 1
  83436. #endif
  83437. /*** End of inlined file: juce_FlacHeader.h ***/
  83438. #if JUCE_USE_FLAC
  83439. #if HAVE_CONFIG_H
  83440. # include <config.h>
  83441. #endif
  83442. #include <stdlib.h>
  83443. #include <stdio.h>
  83444. #if defined FLAC__CPU_IA32
  83445. # include <signal.h>
  83446. #elif defined FLAC__CPU_PPC
  83447. # if !defined FLAC__NO_ASM
  83448. # if defined FLAC__SYS_DARWIN
  83449. # include <sys/sysctl.h>
  83450. # include <mach/mach.h>
  83451. # include <mach/mach_host.h>
  83452. # include <mach/host_info.h>
  83453. # include <mach/machine.h>
  83454. # ifndef CPU_SUBTYPE_POWERPC_970
  83455. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83456. # endif
  83457. # else /* FLAC__SYS_DARWIN */
  83458. # include <signal.h>
  83459. # include <setjmp.h>
  83460. static sigjmp_buf jmpbuf;
  83461. static volatile sig_atomic_t canjump = 0;
  83462. static void sigill_handler (int sig)
  83463. {
  83464. if (!canjump) {
  83465. signal (sig, SIG_DFL);
  83466. raise (sig);
  83467. }
  83468. canjump = 0;
  83469. siglongjmp (jmpbuf, 1);
  83470. }
  83471. # endif /* FLAC__SYS_DARWIN */
  83472. # endif /* FLAC__NO_ASM */
  83473. #endif /* FLAC__CPU_PPC */
  83474. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83475. #include <sys/param.h>
  83476. #include <sys/sysctl.h>
  83477. #include <machine/cpu.h>
  83478. #endif
  83479. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83480. #include <sys/types.h>
  83481. #include <sys/sysctl.h>
  83482. #endif
  83483. #if defined(__APPLE__)
  83484. #endif
  83485. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83486. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83487. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83488. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83489. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83490. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83491. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83492. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83493. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83494. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83495. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83496. # if defined(__linux__)
  83497. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83498. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83499. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83500. {
  83501. (void)signal;
  83502. sc.eip += 3 + 3 + 6;
  83503. }
  83504. # else
  83505. # include <sys/ucontext.h>
  83506. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83507. {
  83508. (void)signal, (void)si;
  83509. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83510. }
  83511. # endif
  83512. # elif defined(_MSC_VER)
  83513. # include <windows.h>
  83514. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83515. # ifdef USE_TRY_CATCH_FLAVOR
  83516. # else
  83517. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83518. {
  83519. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83520. ep->ContextRecord->Eip += 3 + 3 + 6;
  83521. return EXCEPTION_CONTINUE_EXECUTION;
  83522. }
  83523. return EXCEPTION_CONTINUE_SEARCH;
  83524. }
  83525. # endif
  83526. # endif
  83527. #endif
  83528. void FLAC__cpu_info(FLAC__CPUInfo *info)
  83529. {
  83530. #ifdef FLAC__CPU_IA32
  83531. info->type = FLAC__CPUINFO_TYPE_IA32;
  83532. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  83533. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  83534. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  83535. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  83536. info->data.ia32.cmov = false;
  83537. info->data.ia32.mmx = false;
  83538. info->data.ia32.fxsr = false;
  83539. info->data.ia32.sse = false;
  83540. info->data.ia32.sse2 = false;
  83541. info->data.ia32.sse3 = false;
  83542. info->data.ia32.ssse3 = false;
  83543. info->data.ia32._3dnow = false;
  83544. info->data.ia32.ext3dnow = false;
  83545. info->data.ia32.extmmx = false;
  83546. if(info->data.ia32.cpuid) {
  83547. FLAC__uint32 flags_edx, flags_ecx;
  83548. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  83549. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  83550. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  83551. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  83552. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  83553. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  83554. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  83555. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  83556. #ifdef FLAC__USE_3DNOW
  83557. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  83558. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  83559. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  83560. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  83561. #else
  83562. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  83563. #endif
  83564. #ifdef DEBUG
  83565. fprintf(stderr, "CPU info (IA-32):\n");
  83566. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  83567. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  83568. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  83569. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  83570. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  83571. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83572. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  83573. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  83574. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  83575. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  83576. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  83577. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  83578. #endif
  83579. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  83580. #if defined FLAC__NO_SSE_OS
  83581. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83582. #elif defined FLAC__SSE_OS
  83583. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  83584. int sse = 0;
  83585. size_t len;
  83586. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  83587. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  83588. if(!sse)
  83589. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83590. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  83591. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  83592. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  83593. size_t len = sizeof(val);
  83594. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83595. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83596. else { /* double-check SSE2 */
  83597. mib[1] = CPU_SSE2;
  83598. len = sizeof(val);
  83599. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83600. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83601. }
  83602. # else
  83603. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83604. # endif
  83605. #elif defined(__linux__)
  83606. int sse = 0;
  83607. struct sigaction sigill_save;
  83608. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83609. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  83610. #else
  83611. struct sigaction sigill_sse;
  83612. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  83613. __sigemptyset(&sigill_sse.sa_mask);
  83614. 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 */
  83615. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  83616. #endif
  83617. {
  83618. asm volatile (
  83619. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  83620. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  83621. "incl %0\n\t" /* SIGILL handler will jump over this */
  83622. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  83623. "nop\n\t"
  83624. "nop\n\t"
  83625. "nop\n\t"
  83626. "nop\n\t"
  83627. "nop\n\t"
  83628. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  83629. "nop\n\t"
  83630. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  83631. : "=r"(sse)
  83632. : "r"(sse)
  83633. );
  83634. sigaction(SIGILL, &sigill_save, NULL);
  83635. }
  83636. if(!sse)
  83637. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83638. #elif defined(_MSC_VER)
  83639. # ifdef USE_TRY_CATCH_FLAVOR
  83640. _try {
  83641. __asm {
  83642. # if _MSC_VER <= 1200
  83643. _emit 0x0F
  83644. _emit 0x57
  83645. _emit 0xC0
  83646. # else
  83647. xorps xmm0,xmm0
  83648. # endif
  83649. }
  83650. }
  83651. _except(EXCEPTION_EXECUTE_HANDLER) {
  83652. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  83653. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83654. }
  83655. # else
  83656. int sse = 0;
  83657. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  83658. __asm {
  83659. # if _MSC_VER <= 1200
  83660. _emit 0x0F
  83661. _emit 0x57
  83662. _emit 0xC0
  83663. # else
  83664. xorps xmm0,xmm0
  83665. # endif
  83666. inc sse
  83667. nop
  83668. nop
  83669. nop
  83670. nop
  83671. nop
  83672. nop
  83673. nop
  83674. nop
  83675. nop
  83676. }
  83677. SetUnhandledExceptionFilter(save);
  83678. if(!sse)
  83679. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83680. # endif
  83681. #else
  83682. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83683. #endif
  83684. #ifdef DEBUG
  83685. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83686. #endif
  83687. }
  83688. }
  83689. #else
  83690. info->use_asm = false;
  83691. #endif
  83692. #elif defined FLAC__CPU_PPC
  83693. info->type = FLAC__CPUINFO_TYPE_PPC;
  83694. # if !defined FLAC__NO_ASM
  83695. info->use_asm = true;
  83696. # ifdef FLAC__USE_ALTIVEC
  83697. # if defined FLAC__SYS_DARWIN
  83698. {
  83699. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  83700. size_t len = sizeof(val);
  83701. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  83702. }
  83703. {
  83704. host_basic_info_data_t hostInfo;
  83705. mach_msg_type_number_t infoCount;
  83706. infoCount = HOST_BASIC_INFO_COUNT;
  83707. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  83708. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  83709. }
  83710. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  83711. {
  83712. info->data.ppc.altivec = 0;
  83713. info->data.ppc.ppc64 = 0;
  83714. signal (SIGILL, sigill_handler);
  83715. canjump = 0;
  83716. if (!sigsetjmp (jmpbuf, 1)) {
  83717. canjump = 1;
  83718. asm volatile (
  83719. "mtspr 256, %0\n\t"
  83720. "vand %%v0, %%v0, %%v0"
  83721. :
  83722. : "r" (-1)
  83723. );
  83724. info->data.ppc.altivec = 1;
  83725. }
  83726. canjump = 0;
  83727. if (!sigsetjmp (jmpbuf, 1)) {
  83728. int x = 0;
  83729. canjump = 1;
  83730. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  83731. info->data.ppc.ppc64 = 1;
  83732. }
  83733. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  83734. }
  83735. # endif
  83736. # else /* !FLAC__USE_ALTIVEC */
  83737. info->data.ppc.altivec = 0;
  83738. info->data.ppc.ppc64 = 0;
  83739. # endif
  83740. # else
  83741. info->use_asm = false;
  83742. # endif
  83743. #else
  83744. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  83745. info->use_asm = false;
  83746. #endif
  83747. }
  83748. #endif
  83749. /*** End of inlined file: cpu.c ***/
  83750. /*** Start of inlined file: crc.c ***/
  83751. /*** Start of inlined file: juce_FlacHeader.h ***/
  83752. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83753. // tasks..
  83754. #define VERSION "1.2.1"
  83755. #define FLAC__NO_DLL 1
  83756. #if JUCE_MSVC
  83757. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83758. #endif
  83759. #if JUCE_MAC
  83760. #define FLAC__SYS_DARWIN 1
  83761. #endif
  83762. /*** End of inlined file: juce_FlacHeader.h ***/
  83763. #if JUCE_USE_FLAC
  83764. #if HAVE_CONFIG_H
  83765. # include <config.h>
  83766. #endif
  83767. FLAC__byte const FLAC__crc8_table[256] = {
  83768. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  83769. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  83770. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  83771. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  83772. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  83773. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  83774. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  83775. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  83776. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  83777. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  83778. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  83779. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  83780. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  83781. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  83782. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  83783. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  83784. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  83785. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  83786. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  83787. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  83788. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  83789. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  83790. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  83791. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  83792. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  83793. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  83794. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  83795. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  83796. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  83797. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  83798. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  83799. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  83800. };
  83801. unsigned FLAC__crc16_table[256] = {
  83802. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  83803. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  83804. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  83805. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  83806. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  83807. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  83808. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  83809. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  83810. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  83811. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  83812. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  83813. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  83814. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  83815. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  83816. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  83817. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  83818. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  83819. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  83820. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  83821. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  83822. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  83823. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  83824. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  83825. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  83826. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  83827. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  83828. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  83829. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  83830. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  83831. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  83832. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  83833. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  83834. };
  83835. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  83836. {
  83837. *crc = FLAC__crc8_table[*crc ^ data];
  83838. }
  83839. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  83840. {
  83841. while(len--)
  83842. *crc = FLAC__crc8_table[*crc ^ *data++];
  83843. }
  83844. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  83845. {
  83846. FLAC__uint8 crc = 0;
  83847. while(len--)
  83848. crc = FLAC__crc8_table[crc ^ *data++];
  83849. return crc;
  83850. }
  83851. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  83852. {
  83853. unsigned crc = 0;
  83854. while(len--)
  83855. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  83856. return crc;
  83857. }
  83858. #endif
  83859. /*** End of inlined file: crc.c ***/
  83860. /*** Start of inlined file: fixed.c ***/
  83861. /*** Start of inlined file: juce_FlacHeader.h ***/
  83862. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83863. // tasks..
  83864. #define VERSION "1.2.1"
  83865. #define FLAC__NO_DLL 1
  83866. #if JUCE_MSVC
  83867. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83868. #endif
  83869. #if JUCE_MAC
  83870. #define FLAC__SYS_DARWIN 1
  83871. #endif
  83872. /*** End of inlined file: juce_FlacHeader.h ***/
  83873. #if JUCE_USE_FLAC
  83874. #if HAVE_CONFIG_H
  83875. # include <config.h>
  83876. #endif
  83877. #include <math.h>
  83878. #include <string.h>
  83879. /*** Start of inlined file: fixed.h ***/
  83880. #ifndef FLAC__PRIVATE__FIXED_H
  83881. #define FLAC__PRIVATE__FIXED_H
  83882. #ifdef HAVE_CONFIG_H
  83883. #include <config.h>
  83884. #endif
  83885. /*** Start of inlined file: float.h ***/
  83886. #ifndef FLAC__PRIVATE__FLOAT_H
  83887. #define FLAC__PRIVATE__FLOAT_H
  83888. #ifdef HAVE_CONFIG_H
  83889. #include <config.h>
  83890. #endif
  83891. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83892. typedef double FLAC__double;
  83893. typedef float FLAC__float;
  83894. typedef float FLAC__real;
  83895. #else
  83896. typedef FLAC__int32 FLAC__fixedpoint;
  83897. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  83898. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  83899. extern const FLAC__fixedpoint FLAC__FP_ONE;
  83900. extern const FLAC__fixedpoint FLAC__FP_LN2;
  83901. extern const FLAC__fixedpoint FLAC__FP_E;
  83902. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  83903. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  83904. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  83905. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  83906. #endif
  83907. #endif
  83908. /*** End of inlined file: float.h ***/
  83909. /*** Start of inlined file: format.h ***/
  83910. #ifndef FLAC__PRIVATE__FORMAT_H
  83911. #define FLAC__PRIVATE__FORMAT_H
  83912. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  83913. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  83914. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  83915. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83916. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83917. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  83918. #endif
  83919. /*** End of inlined file: format.h ***/
  83920. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83921. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83922. # ifndef FLAC__NO_ASM
  83923. # ifdef FLAC__CPU_IA32
  83924. # ifdef FLAC__HAS_NASM
  83925. 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]);
  83926. # endif
  83927. # endif
  83928. # endif
  83929. 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]);
  83930. #else
  83931. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83932. 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]);
  83933. #endif
  83934. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  83935. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  83936. #endif
  83937. /*** End of inlined file: fixed.h ***/
  83938. #ifndef M_LN2
  83939. #define M_LN2 0.69314718055994530942
  83940. #endif
  83941. #ifdef min
  83942. #undef min
  83943. #endif
  83944. #define min(x,y) ((x) < (y)? (x) : (y))
  83945. #ifdef local_abs
  83946. #undef local_abs
  83947. #endif
  83948. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  83949. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  83950. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  83951. {
  83952. FLAC__uint32 rbps;
  83953. unsigned bits; /* the number of bits required to represent a number */
  83954. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83955. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83956. FLAC__ASSERT(err > 0);
  83957. FLAC__ASSERT(n > 0);
  83958. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  83959. if(err <= n)
  83960. return 0;
  83961. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  83962. err <<= fracbits;
  83963. err /= n;
  83964. FLAC__ASSERT(err > 0);
  83965. bits = FLAC__bitmath_ilog2(err)+1;
  83966. if(bits > 16) {
  83967. err >>= (bits-16);
  83968. fracbits -= (bits-16);
  83969. }
  83970. rbps = (FLAC__uint32)err;
  83971. rbps *= FLAC__FP_LN2;
  83972. fracbits += 16;
  83973. FLAC__ASSERT(fracbits >= 0);
  83974. {
  83975. const int f = fracbits & 3;
  83976. if(f) {
  83977. rbps >>= f;
  83978. fracbits -= f;
  83979. }
  83980. }
  83981. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  83982. if(rbps == 0)
  83983. return 0;
  83984. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  83985. FLAC__ASSERT(fracbits >= -3);
  83986. if(fracbits < 16)
  83987. return rbps << (16-fracbits);
  83988. else if(fracbits > 16)
  83989. return rbps >> (fracbits-16);
  83990. else
  83991. return rbps;
  83992. }
  83993. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  83994. {
  83995. FLAC__uint32 rbps;
  83996. unsigned bits; /* the number of bits required to represent a number */
  83997. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83998. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83999. FLAC__ASSERT(err > 0);
  84000. FLAC__ASSERT(n > 0);
  84001. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84002. if(err <= n)
  84003. return 0;
  84004. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  84005. err <<= fracbits;
  84006. err /= n;
  84007. FLAC__ASSERT(err > 0);
  84008. bits = FLAC__bitmath_ilog2_wide(err)+1;
  84009. if(bits > 16) {
  84010. err >>= (bits-16);
  84011. fracbits -= (bits-16);
  84012. }
  84013. rbps = (FLAC__uint32)err;
  84014. rbps *= FLAC__FP_LN2;
  84015. fracbits += 16;
  84016. FLAC__ASSERT(fracbits >= 0);
  84017. {
  84018. const int f = fracbits & 3;
  84019. if(f) {
  84020. rbps >>= f;
  84021. fracbits -= f;
  84022. }
  84023. }
  84024. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84025. if(rbps == 0)
  84026. return 0;
  84027. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84028. FLAC__ASSERT(fracbits >= -3);
  84029. if(fracbits < 16)
  84030. return rbps << (16-fracbits);
  84031. else if(fracbits > 16)
  84032. return rbps >> (fracbits-16);
  84033. else
  84034. return rbps;
  84035. }
  84036. #endif
  84037. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84038. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84039. #else
  84040. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84041. #endif
  84042. {
  84043. FLAC__int32 last_error_0 = data[-1];
  84044. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84045. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84046. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84047. FLAC__int32 error, save;
  84048. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84049. unsigned i, order;
  84050. for(i = 0; i < data_len; i++) {
  84051. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84052. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84053. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84054. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84055. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84056. }
  84057. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84058. order = 0;
  84059. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84060. order = 1;
  84061. else if(total_error_2 < min(total_error_3, total_error_4))
  84062. order = 2;
  84063. else if(total_error_3 < total_error_4)
  84064. order = 3;
  84065. else
  84066. order = 4;
  84067. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84068. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84069. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84070. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84071. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84072. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84073. 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);
  84074. 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);
  84075. 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);
  84076. 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);
  84077. 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);
  84078. #else
  84079. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84080. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84081. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84082. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84083. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84084. #endif
  84085. return order;
  84086. }
  84087. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84088. 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])
  84089. #else
  84090. 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])
  84091. #endif
  84092. {
  84093. FLAC__int32 last_error_0 = data[-1];
  84094. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84095. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84096. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84097. FLAC__int32 error, save;
  84098. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84099. unsigned i, order;
  84100. for(i = 0; i < data_len; i++) {
  84101. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84102. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84103. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84104. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84105. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84106. }
  84107. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84108. order = 0;
  84109. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84110. order = 1;
  84111. else if(total_error_2 < min(total_error_3, total_error_4))
  84112. order = 2;
  84113. else if(total_error_3 < total_error_4)
  84114. order = 3;
  84115. else
  84116. order = 4;
  84117. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84118. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84119. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84120. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84121. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84122. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84123. #if defined _MSC_VER || defined __MINGW32__
  84124. 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);
  84125. 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);
  84126. 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);
  84127. 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);
  84128. 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);
  84129. #else
  84130. 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);
  84131. 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);
  84132. 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);
  84133. 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);
  84134. 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);
  84135. #endif
  84136. #else
  84137. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84138. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84139. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84140. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84141. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84142. #endif
  84143. return order;
  84144. }
  84145. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84146. {
  84147. const int idata_len = (int)data_len;
  84148. int i;
  84149. switch(order) {
  84150. case 0:
  84151. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84152. memcpy(residual, data, sizeof(residual[0])*data_len);
  84153. break;
  84154. case 1:
  84155. for(i = 0; i < idata_len; i++)
  84156. residual[i] = data[i] - data[i-1];
  84157. break;
  84158. case 2:
  84159. for(i = 0; i < idata_len; i++)
  84160. #if 1 /* OPT: may be faster with some compilers on some systems */
  84161. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84162. #else
  84163. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84164. #endif
  84165. break;
  84166. case 3:
  84167. for(i = 0; i < idata_len; i++)
  84168. #if 1 /* OPT: may be faster with some compilers on some systems */
  84169. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84170. #else
  84171. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84172. #endif
  84173. break;
  84174. case 4:
  84175. for(i = 0; i < idata_len; i++)
  84176. #if 1 /* OPT: may be faster with some compilers on some systems */
  84177. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84178. #else
  84179. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84180. #endif
  84181. break;
  84182. default:
  84183. FLAC__ASSERT(0);
  84184. }
  84185. }
  84186. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84187. {
  84188. int i, idata_len = (int)data_len;
  84189. switch(order) {
  84190. case 0:
  84191. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84192. memcpy(data, residual, sizeof(residual[0])*data_len);
  84193. break;
  84194. case 1:
  84195. for(i = 0; i < idata_len; i++)
  84196. data[i] = residual[i] + data[i-1];
  84197. break;
  84198. case 2:
  84199. for(i = 0; i < idata_len; i++)
  84200. #if 1 /* OPT: may be faster with some compilers on some systems */
  84201. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84202. #else
  84203. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84204. #endif
  84205. break;
  84206. case 3:
  84207. for(i = 0; i < idata_len; i++)
  84208. #if 1 /* OPT: may be faster with some compilers on some systems */
  84209. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84210. #else
  84211. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84212. #endif
  84213. break;
  84214. case 4:
  84215. for(i = 0; i < idata_len; i++)
  84216. #if 1 /* OPT: may be faster with some compilers on some systems */
  84217. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84218. #else
  84219. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84220. #endif
  84221. break;
  84222. default:
  84223. FLAC__ASSERT(0);
  84224. }
  84225. }
  84226. #endif
  84227. /*** End of inlined file: fixed.c ***/
  84228. /*** Start of inlined file: float.c ***/
  84229. /*** Start of inlined file: juce_FlacHeader.h ***/
  84230. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84231. // tasks..
  84232. #define VERSION "1.2.1"
  84233. #define FLAC__NO_DLL 1
  84234. #if JUCE_MSVC
  84235. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84236. #endif
  84237. #if JUCE_MAC
  84238. #define FLAC__SYS_DARWIN 1
  84239. #endif
  84240. /*** End of inlined file: juce_FlacHeader.h ***/
  84241. #if JUCE_USE_FLAC
  84242. #if HAVE_CONFIG_H
  84243. # include <config.h>
  84244. #endif
  84245. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84246. #ifdef _MSC_VER
  84247. #define FLAC__U64L(x) x
  84248. #else
  84249. #define FLAC__U64L(x) x##LLU
  84250. #endif
  84251. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84252. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84253. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84254. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84255. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84256. #define LOG2_LOOKUP_PRECISION 16
  84257. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84258. {
  84259. 0x00000000,
  84260. 0x00000001,
  84261. 0x00000000,
  84262. 0x00000000,
  84263. 0x00000000,
  84264. 0x00000000,
  84265. 0x00000000,
  84266. 0x00000000,
  84267. 0x00000000,
  84268. 0x00000000,
  84269. 0x00000000,
  84270. 0x00000000,
  84271. 0x00000000,
  84272. 0x00000000,
  84273. 0x00000000,
  84274. 0x00000000
  84275. },
  84276. {
  84277. 0x00000000,
  84278. 0x00000010,
  84279. 0x00000007,
  84280. 0x00000003,
  84281. 0x00000001,
  84282. 0x00000001,
  84283. 0x00000000,
  84284. 0x00000000,
  84285. 0x00000000,
  84286. 0x00000000,
  84287. 0x00000000,
  84288. 0x00000000,
  84289. 0x00000000,
  84290. 0x00000000,
  84291. 0x00000000,
  84292. 0x00000000
  84293. },
  84294. {
  84295. 0x00000000,
  84296. 0x00000100,
  84297. 0x0000006a,
  84298. 0x00000031,
  84299. 0x00000018,
  84300. 0x0000000c,
  84301. 0x00000006,
  84302. 0x00000003,
  84303. 0x00000001,
  84304. 0x00000001,
  84305. 0x00000000,
  84306. 0x00000000,
  84307. 0x00000000,
  84308. 0x00000000,
  84309. 0x00000000,
  84310. 0x00000000
  84311. },
  84312. {
  84313. 0x00000000,
  84314. 0x00001000,
  84315. 0x000006a4,
  84316. 0x00000315,
  84317. 0x0000017d,
  84318. 0x000000bc,
  84319. 0x0000005d,
  84320. 0x0000002e,
  84321. 0x00000017,
  84322. 0x0000000c,
  84323. 0x00000006,
  84324. 0x00000003,
  84325. 0x00000001,
  84326. 0x00000001,
  84327. 0x00000000,
  84328. 0x00000000
  84329. },
  84330. {
  84331. 0x00000000,
  84332. 0x00010000,
  84333. 0x00006a40,
  84334. 0x00003151,
  84335. 0x000017d6,
  84336. 0x00000bba,
  84337. 0x000005d1,
  84338. 0x000002e6,
  84339. 0x00000172,
  84340. 0x000000b9,
  84341. 0x0000005c,
  84342. 0x0000002e,
  84343. 0x00000017,
  84344. 0x0000000c,
  84345. 0x00000006,
  84346. 0x00000003
  84347. },
  84348. {
  84349. 0x00000000,
  84350. 0x00100000,
  84351. 0x0006a3fe,
  84352. 0x00031513,
  84353. 0x00017d60,
  84354. 0x0000bb9d,
  84355. 0x00005d10,
  84356. 0x00002e59,
  84357. 0x00001721,
  84358. 0x00000b8e,
  84359. 0x000005c6,
  84360. 0x000002e3,
  84361. 0x00000171,
  84362. 0x000000b9,
  84363. 0x0000005c,
  84364. 0x0000002e
  84365. },
  84366. {
  84367. 0x00000000,
  84368. 0x01000000,
  84369. 0x006a3fe6,
  84370. 0x00315130,
  84371. 0x0017d605,
  84372. 0x000bb9ca,
  84373. 0x0005d0fc,
  84374. 0x0002e58f,
  84375. 0x0001720e,
  84376. 0x0000b8d8,
  84377. 0x00005c61,
  84378. 0x00002e2d,
  84379. 0x00001716,
  84380. 0x00000b8b,
  84381. 0x000005c5,
  84382. 0x000002e3
  84383. },
  84384. {
  84385. 0x00000000,
  84386. 0x10000000,
  84387. 0x06a3fe5c,
  84388. 0x03151301,
  84389. 0x017d6049,
  84390. 0x00bb9ca6,
  84391. 0x005d0fba,
  84392. 0x002e58f7,
  84393. 0x001720da,
  84394. 0x000b8d87,
  84395. 0x0005c60b,
  84396. 0x0002e2d7,
  84397. 0x00017160,
  84398. 0x0000b8ad,
  84399. 0x00005c56,
  84400. 0x00002e2b
  84401. }
  84402. };
  84403. #if 0
  84404. static const FLAC__uint64 log2_lookup_wide[] = {
  84405. {
  84406. 0x00000000,
  84407. FLAC__U64L(0x100000000),
  84408. FLAC__U64L(0x6a3fe5c6),
  84409. FLAC__U64L(0x31513015),
  84410. FLAC__U64L(0x17d60497),
  84411. FLAC__U64L(0x0bb9ca65),
  84412. FLAC__U64L(0x05d0fba2),
  84413. FLAC__U64L(0x02e58f74),
  84414. FLAC__U64L(0x01720d9c),
  84415. FLAC__U64L(0x00b8d875),
  84416. FLAC__U64L(0x005c60aa),
  84417. FLAC__U64L(0x002e2d72),
  84418. FLAC__U64L(0x00171600),
  84419. FLAC__U64L(0x000b8ad2),
  84420. FLAC__U64L(0x0005c55d),
  84421. FLAC__U64L(0x0002e2ac)
  84422. },
  84423. {
  84424. 0x00000000,
  84425. FLAC__U64L(0x1000000000000),
  84426. FLAC__U64L(0x6a3fe5c60429),
  84427. FLAC__U64L(0x315130157f7a),
  84428. FLAC__U64L(0x17d60496cfbb),
  84429. FLAC__U64L(0xbb9ca64ecac),
  84430. FLAC__U64L(0x5d0fba187cd),
  84431. FLAC__U64L(0x2e58f7441ee),
  84432. FLAC__U64L(0x1720d9c06a8),
  84433. FLAC__U64L(0xb8d8752173),
  84434. FLAC__U64L(0x5c60aa252e),
  84435. FLAC__U64L(0x2e2d71b0d8),
  84436. FLAC__U64L(0x1716001719),
  84437. FLAC__U64L(0xb8ad1de1b),
  84438. FLAC__U64L(0x5c55d640d),
  84439. FLAC__U64L(0x2e2abcf52)
  84440. }
  84441. };
  84442. #endif
  84443. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84444. {
  84445. const FLAC__uint32 ONE = (1u << fracbits);
  84446. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84447. FLAC__ASSERT(fracbits < 32);
  84448. FLAC__ASSERT((fracbits & 0x3) == 0);
  84449. if(x < ONE)
  84450. return 0;
  84451. if(precision > LOG2_LOOKUP_PRECISION)
  84452. precision = LOG2_LOOKUP_PRECISION;
  84453. {
  84454. FLAC__uint32 y = 0;
  84455. FLAC__uint32 z = x >> 1, k = 1;
  84456. while (x > ONE && k < precision) {
  84457. if (x - z >= ONE) {
  84458. x -= z;
  84459. z = x >> k;
  84460. y += table[k];
  84461. }
  84462. else {
  84463. z >>= 1;
  84464. k++;
  84465. }
  84466. }
  84467. return y;
  84468. }
  84469. }
  84470. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84471. #endif
  84472. /*** End of inlined file: float.c ***/
  84473. /*** Start of inlined file: format.c ***/
  84474. /*** Start of inlined file: juce_FlacHeader.h ***/
  84475. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84476. // tasks..
  84477. #define VERSION "1.2.1"
  84478. #define FLAC__NO_DLL 1
  84479. #if JUCE_MSVC
  84480. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84481. #endif
  84482. #if JUCE_MAC
  84483. #define FLAC__SYS_DARWIN 1
  84484. #endif
  84485. /*** End of inlined file: juce_FlacHeader.h ***/
  84486. #if JUCE_USE_FLAC
  84487. #if HAVE_CONFIG_H
  84488. # include <config.h>
  84489. #endif
  84490. #include <stdio.h>
  84491. #include <stdlib.h> /* for qsort() */
  84492. #include <string.h> /* for memset() */
  84493. #ifndef FLaC__INLINE
  84494. #define FLaC__INLINE
  84495. #endif
  84496. #ifdef min
  84497. #undef min
  84498. #endif
  84499. #define min(a,b) ((a)<(b)?(a):(b))
  84500. #ifdef _MSC_VER
  84501. #define FLAC__U64L(x) x
  84502. #else
  84503. #define FLAC__U64L(x) x##LLU
  84504. #endif
  84505. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84506. ;
  84507. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84508. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84509. #else
  84510. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84511. #endif
  84512. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84513. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84514. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84515. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84516. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84517. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84518. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84519. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84520. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84521. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84522. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84523. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  84524. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  84525. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  84526. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  84527. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  84528. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  84529. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  84530. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  84531. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  84532. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  84533. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  84534. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  84535. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  84536. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  84537. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  84538. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  84539. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  84540. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  84541. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  84542. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  84543. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  84544. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  84545. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  84546. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  84547. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  84548. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  84549. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  84550. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  84551. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  84552. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  84553. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  84554. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  84555. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  84556. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  84557. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  84558. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  84559. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  84560. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  84561. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  84562. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  84563. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  84564. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  84565. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  84566. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  84567. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  84568. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  84569. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  84570. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  84571. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  84572. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  84573. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  84574. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  84575. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  84576. "PARTITIONED_RICE",
  84577. "PARTITIONED_RICE2"
  84578. };
  84579. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  84580. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  84581. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  84582. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  84583. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  84584. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  84585. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  84586. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  84587. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  84588. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  84589. "CONSTANT",
  84590. "VERBATIM",
  84591. "FIXED",
  84592. "LPC"
  84593. };
  84594. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  84595. "INDEPENDENT",
  84596. "LEFT_SIDE",
  84597. "RIGHT_SIDE",
  84598. "MID_SIDE"
  84599. };
  84600. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  84601. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  84602. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  84603. };
  84604. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  84605. "STREAMINFO",
  84606. "PADDING",
  84607. "APPLICATION",
  84608. "SEEKTABLE",
  84609. "VORBIS_COMMENT",
  84610. "CUESHEET",
  84611. "PICTURE"
  84612. };
  84613. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  84614. "Other",
  84615. "32x32 pixels 'file icon' (PNG only)",
  84616. "Other file icon",
  84617. "Cover (front)",
  84618. "Cover (back)",
  84619. "Leaflet page",
  84620. "Media (e.g. label side of CD)",
  84621. "Lead artist/lead performer/soloist",
  84622. "Artist/performer",
  84623. "Conductor",
  84624. "Band/Orchestra",
  84625. "Composer",
  84626. "Lyricist/text writer",
  84627. "Recording Location",
  84628. "During recording",
  84629. "During performance",
  84630. "Movie/video screen capture",
  84631. "A bright coloured fish",
  84632. "Illustration",
  84633. "Band/artist logotype",
  84634. "Publisher/Studio logotype"
  84635. };
  84636. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  84637. {
  84638. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  84639. return false;
  84640. }
  84641. else
  84642. return true;
  84643. }
  84644. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  84645. {
  84646. if(
  84647. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  84648. (
  84649. sample_rate >= (1u << 16) &&
  84650. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  84651. )
  84652. ) {
  84653. return false;
  84654. }
  84655. else
  84656. return true;
  84657. }
  84658. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  84659. {
  84660. unsigned i;
  84661. FLAC__uint64 prev_sample_number = 0;
  84662. FLAC__bool got_prev = false;
  84663. FLAC__ASSERT(0 != seek_table);
  84664. for(i = 0; i < seek_table->num_points; i++) {
  84665. if(got_prev) {
  84666. if(
  84667. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  84668. seek_table->points[i].sample_number <= prev_sample_number
  84669. )
  84670. return false;
  84671. }
  84672. prev_sample_number = seek_table->points[i].sample_number;
  84673. got_prev = true;
  84674. }
  84675. return true;
  84676. }
  84677. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  84678. {
  84679. if(l->sample_number == r->sample_number)
  84680. return 0;
  84681. else if(l->sample_number < r->sample_number)
  84682. return -1;
  84683. else
  84684. return 1;
  84685. }
  84686. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  84687. {
  84688. unsigned i, j;
  84689. FLAC__bool first;
  84690. FLAC__ASSERT(0 != seek_table);
  84691. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  84692. first = true;
  84693. for(i = j = 0; i < seek_table->num_points; i++) {
  84694. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  84695. if(!first) {
  84696. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  84697. continue;
  84698. }
  84699. }
  84700. first = false;
  84701. seek_table->points[j++] = seek_table->points[i];
  84702. }
  84703. for(i = j; i < seek_table->num_points; i++) {
  84704. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  84705. seek_table->points[i].stream_offset = 0;
  84706. seek_table->points[i].frame_samples = 0;
  84707. }
  84708. return j;
  84709. }
  84710. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  84711. {
  84712. FLAC__ASSERT(0 != utf8);
  84713. if ((utf8[0] & 0x80) == 0) {
  84714. return 1;
  84715. }
  84716. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  84717. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  84718. return 0;
  84719. return 2;
  84720. }
  84721. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  84722. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  84723. return 0;
  84724. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  84725. return 0;
  84726. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  84727. return 0;
  84728. return 3;
  84729. }
  84730. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  84731. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  84732. return 0;
  84733. return 4;
  84734. }
  84735. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  84736. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  84737. return 0;
  84738. return 5;
  84739. }
  84740. 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) {
  84741. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  84742. return 0;
  84743. return 6;
  84744. }
  84745. else {
  84746. return 0;
  84747. }
  84748. }
  84749. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  84750. {
  84751. char c;
  84752. for(c = *name; c; c = *(++name))
  84753. if(c < 0x20 || c == 0x3d || c > 0x7d)
  84754. return false;
  84755. return true;
  84756. }
  84757. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  84758. {
  84759. if(length == (unsigned)(-1)) {
  84760. while(*value) {
  84761. unsigned n = utf8len_(value);
  84762. if(n == 0)
  84763. return false;
  84764. value += n;
  84765. }
  84766. }
  84767. else {
  84768. const FLAC__byte *end = value + length;
  84769. while(value < end) {
  84770. unsigned n = utf8len_(value);
  84771. if(n == 0)
  84772. return false;
  84773. value += n;
  84774. }
  84775. if(value != end)
  84776. return false;
  84777. }
  84778. return true;
  84779. }
  84780. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  84781. {
  84782. const FLAC__byte *s, *end;
  84783. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  84784. if(*s < 0x20 || *s > 0x7D)
  84785. return false;
  84786. }
  84787. if(s == end)
  84788. return false;
  84789. s++; /* skip '=' */
  84790. while(s < end) {
  84791. unsigned n = utf8len_(s);
  84792. if(n == 0)
  84793. return false;
  84794. s += n;
  84795. }
  84796. if(s != end)
  84797. return false;
  84798. return true;
  84799. }
  84800. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  84801. {
  84802. unsigned i, j;
  84803. if(check_cd_da_subset) {
  84804. if(cue_sheet->lead_in < 2 * 44100) {
  84805. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  84806. return false;
  84807. }
  84808. if(cue_sheet->lead_in % 588 != 0) {
  84809. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  84810. return false;
  84811. }
  84812. }
  84813. if(cue_sheet->num_tracks == 0) {
  84814. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  84815. return false;
  84816. }
  84817. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  84818. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  84819. return false;
  84820. }
  84821. for(i = 0; i < cue_sheet->num_tracks; i++) {
  84822. if(cue_sheet->tracks[i].number == 0) {
  84823. if(violation) *violation = "cue sheet may not have a track number 0";
  84824. return false;
  84825. }
  84826. if(check_cd_da_subset) {
  84827. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  84828. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  84829. return false;
  84830. }
  84831. }
  84832. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  84833. if(violation) {
  84834. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  84835. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  84836. else
  84837. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  84838. }
  84839. return false;
  84840. }
  84841. if(i < cue_sheet->num_tracks - 1) {
  84842. if(cue_sheet->tracks[i].num_indices == 0) {
  84843. if(violation) *violation = "cue sheet track must have at least one index point";
  84844. return false;
  84845. }
  84846. if(cue_sheet->tracks[i].indices[0].number > 1) {
  84847. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  84848. return false;
  84849. }
  84850. }
  84851. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  84852. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  84853. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  84854. return false;
  84855. }
  84856. if(j > 0) {
  84857. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  84858. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  84859. return false;
  84860. }
  84861. }
  84862. }
  84863. }
  84864. return true;
  84865. }
  84866. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  84867. {
  84868. char *p;
  84869. FLAC__byte *b;
  84870. for(p = picture->mime_type; *p; p++) {
  84871. if(*p < 0x20 || *p > 0x7e) {
  84872. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  84873. return false;
  84874. }
  84875. }
  84876. for(b = picture->description; *b; ) {
  84877. unsigned n = utf8len_(b);
  84878. if(n == 0) {
  84879. if(violation) *violation = "description string must be valid UTF-8";
  84880. return false;
  84881. }
  84882. b += n;
  84883. }
  84884. return true;
  84885. }
  84886. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  84887. {
  84888. return
  84889. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  84890. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  84891. blocksize,
  84892. predictor_order
  84893. );
  84894. }
  84895. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  84896. {
  84897. unsigned max_rice_partition_order = 0;
  84898. while(!(blocksize & 1)) {
  84899. max_rice_partition_order++;
  84900. blocksize >>= 1;
  84901. }
  84902. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  84903. }
  84904. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  84905. {
  84906. unsigned max_rice_partition_order = limit;
  84907. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  84908. max_rice_partition_order--;
  84909. FLAC__ASSERT(
  84910. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  84911. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  84912. );
  84913. return max_rice_partition_order;
  84914. }
  84915. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84916. {
  84917. FLAC__ASSERT(0 != object);
  84918. object->parameters = 0;
  84919. object->raw_bits = 0;
  84920. object->capacity_by_order = 0;
  84921. }
  84922. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84923. {
  84924. FLAC__ASSERT(0 != object);
  84925. if(0 != object->parameters)
  84926. free(object->parameters);
  84927. if(0 != object->raw_bits)
  84928. free(object->raw_bits);
  84929. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  84930. }
  84931. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  84932. {
  84933. FLAC__ASSERT(0 != object);
  84934. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  84935. if(object->capacity_by_order < max_partition_order) {
  84936. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  84937. return false;
  84938. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  84939. return false;
  84940. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  84941. object->capacity_by_order = max_partition_order;
  84942. }
  84943. return true;
  84944. }
  84945. #endif
  84946. /*** End of inlined file: format.c ***/
  84947. /*** Start of inlined file: lpc_flac.c ***/
  84948. /*** Start of inlined file: juce_FlacHeader.h ***/
  84949. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84950. // tasks..
  84951. #define VERSION "1.2.1"
  84952. #define FLAC__NO_DLL 1
  84953. #if JUCE_MSVC
  84954. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84955. #endif
  84956. #if JUCE_MAC
  84957. #define FLAC__SYS_DARWIN 1
  84958. #endif
  84959. /*** End of inlined file: juce_FlacHeader.h ***/
  84960. #if JUCE_USE_FLAC
  84961. #if HAVE_CONFIG_H
  84962. # include <config.h>
  84963. #endif
  84964. #include <math.h>
  84965. /*** Start of inlined file: lpc.h ***/
  84966. #ifndef FLAC__PRIVATE__LPC_H
  84967. #define FLAC__PRIVATE__LPC_H
  84968. #ifdef HAVE_CONFIG_H
  84969. #include <config.h>
  84970. #endif
  84971. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84972. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  84973. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84974. #ifndef FLAC__NO_ASM
  84975. # ifdef FLAC__CPU_IA32
  84976. # ifdef FLAC__HAS_NASM
  84977. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84978. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84979. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84980. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84981. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84982. # endif
  84983. # endif
  84984. #endif
  84985. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  84986. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  84987. 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[]);
  84988. 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[]);
  84989. #ifndef FLAC__NO_ASM
  84990. # ifdef FLAC__CPU_IA32
  84991. # ifdef FLAC__HAS_NASM
  84992. 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[]);
  84993. 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[]);
  84994. # endif
  84995. # endif
  84996. #endif
  84997. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  84998. 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[]);
  84999. 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[]);
  85000. #ifndef FLAC__NO_ASM
  85001. # ifdef FLAC__CPU_IA32
  85002. # ifdef FLAC__HAS_NASM
  85003. 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[]);
  85004. 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[]);
  85005. # endif /* FLAC__HAS_NASM */
  85006. # elif defined FLAC__CPU_PPC
  85007. 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[]);
  85008. 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[]);
  85009. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  85010. #endif /* FLAC__NO_ASM */
  85011. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85012. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85013. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85014. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85015. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85016. #endif
  85017. /*** End of inlined file: lpc.h ***/
  85018. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85019. #include <stdio.h>
  85020. #endif
  85021. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85022. #ifndef M_LN2
  85023. #define M_LN2 0.69314718055994530942
  85024. #endif
  85025. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85026. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85027. {
  85028. unsigned i;
  85029. for(i = 0; i < data_len; i++)
  85030. out[i] = in[i] * window[i];
  85031. }
  85032. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85033. {
  85034. #if 0
  85035. FLAC__real d;
  85036. unsigned i;
  85037. FLAC__ASSERT(lag > 0);
  85038. FLAC__ASSERT(lag <= data_len);
  85039. while(lag--) {
  85040. for(i = lag, d = 0.0; i < data_len; i++)
  85041. d += data[i] * data[i - lag];
  85042. autoc[lag] = d;
  85043. }
  85044. #endif
  85045. FLAC__real d;
  85046. unsigned sample, coeff;
  85047. const unsigned limit = data_len - lag;
  85048. FLAC__ASSERT(lag > 0);
  85049. FLAC__ASSERT(lag <= data_len);
  85050. for(coeff = 0; coeff < lag; coeff++)
  85051. autoc[coeff] = 0.0;
  85052. for(sample = 0; sample <= limit; sample++) {
  85053. d = data[sample];
  85054. for(coeff = 0; coeff < lag; coeff++)
  85055. autoc[coeff] += d * data[sample+coeff];
  85056. }
  85057. for(; sample < data_len; sample++) {
  85058. d = data[sample];
  85059. for(coeff = 0; coeff < data_len - sample; coeff++)
  85060. autoc[coeff] += d * data[sample+coeff];
  85061. }
  85062. }
  85063. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85064. {
  85065. unsigned i, j;
  85066. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85067. FLAC__ASSERT(0 != max_order);
  85068. FLAC__ASSERT(0 < *max_order);
  85069. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85070. FLAC__ASSERT(autoc[0] != 0.0);
  85071. err = autoc[0];
  85072. for(i = 0; i < *max_order; i++) {
  85073. r = -autoc[i+1];
  85074. for(j = 0; j < i; j++)
  85075. r -= lpc[j] * autoc[i-j];
  85076. ref[i] = (r/=err);
  85077. lpc[i]=r;
  85078. for(j = 0; j < (i>>1); j++) {
  85079. FLAC__double tmp = lpc[j];
  85080. lpc[j] += r * lpc[i-1-j];
  85081. lpc[i-1-j] += r * tmp;
  85082. }
  85083. if(i & 1)
  85084. lpc[j] += lpc[j] * r;
  85085. err *= (1.0 - r * r);
  85086. for(j = 0; j <= i; j++)
  85087. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85088. error[i] = err;
  85089. if(err == 0.0) {
  85090. *max_order = i+1;
  85091. return;
  85092. }
  85093. }
  85094. }
  85095. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85096. {
  85097. unsigned i;
  85098. FLAC__double cmax;
  85099. FLAC__int32 qmax, qmin;
  85100. FLAC__ASSERT(precision > 0);
  85101. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85102. precision--;
  85103. qmax = 1 << precision;
  85104. qmin = -qmax;
  85105. qmax--;
  85106. cmax = 0.0;
  85107. for(i = 0; i < order; i++) {
  85108. const FLAC__double d = fabs(lp_coeff[i]);
  85109. if(d > cmax)
  85110. cmax = d;
  85111. }
  85112. if(cmax <= 0.0) {
  85113. return 2;
  85114. }
  85115. else {
  85116. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85117. const int min_shiftlimit = -max_shiftlimit - 1;
  85118. int log2cmax;
  85119. (void)frexp(cmax, &log2cmax);
  85120. log2cmax--;
  85121. *shift = (int)precision - log2cmax - 1;
  85122. if(*shift > max_shiftlimit)
  85123. *shift = max_shiftlimit;
  85124. else if(*shift < min_shiftlimit)
  85125. return 1;
  85126. }
  85127. if(*shift >= 0) {
  85128. FLAC__double error = 0.0;
  85129. FLAC__int32 q;
  85130. for(i = 0; i < order; i++) {
  85131. error += lp_coeff[i] * (1 << *shift);
  85132. #if 1 /* unfortunately lround() is C99 */
  85133. if(error >= 0.0)
  85134. q = (FLAC__int32)(error + 0.5);
  85135. else
  85136. q = (FLAC__int32)(error - 0.5);
  85137. #else
  85138. q = lround(error);
  85139. #endif
  85140. #ifdef FLAC__OVERFLOW_DETECT
  85141. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85142. 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]);
  85143. else if(q < qmin)
  85144. 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]);
  85145. #endif
  85146. if(q > qmax)
  85147. q = qmax;
  85148. else if(q < qmin)
  85149. q = qmin;
  85150. error -= q;
  85151. qlp_coeff[i] = q;
  85152. }
  85153. }
  85154. else {
  85155. const int nshift = -(*shift);
  85156. FLAC__double error = 0.0;
  85157. FLAC__int32 q;
  85158. #ifdef DEBUG
  85159. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85160. #endif
  85161. for(i = 0; i < order; i++) {
  85162. error += lp_coeff[i] / (1 << nshift);
  85163. #if 1 /* unfortunately lround() is C99 */
  85164. if(error >= 0.0)
  85165. q = (FLAC__int32)(error + 0.5);
  85166. else
  85167. q = (FLAC__int32)(error - 0.5);
  85168. #else
  85169. q = lround(error);
  85170. #endif
  85171. #ifdef FLAC__OVERFLOW_DETECT
  85172. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85173. 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]);
  85174. else if(q < qmin)
  85175. 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]);
  85176. #endif
  85177. if(q > qmax)
  85178. q = qmax;
  85179. else if(q < qmin)
  85180. q = qmin;
  85181. error -= q;
  85182. qlp_coeff[i] = q;
  85183. }
  85184. *shift = 0;
  85185. }
  85186. return 0;
  85187. }
  85188. 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[])
  85189. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85190. {
  85191. FLAC__int64 sumo;
  85192. unsigned i, j;
  85193. FLAC__int32 sum;
  85194. const FLAC__int32 *history;
  85195. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85196. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85197. for(i=0;i<order;i++)
  85198. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85199. fprintf(stderr,"\n");
  85200. #endif
  85201. FLAC__ASSERT(order > 0);
  85202. for(i = 0; i < data_len; i++) {
  85203. sumo = 0;
  85204. sum = 0;
  85205. history = data;
  85206. for(j = 0; j < order; j++) {
  85207. sum += qlp_coeff[j] * (*(--history));
  85208. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85209. #if defined _MSC_VER
  85210. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85211. 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);
  85212. #else
  85213. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85214. 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);
  85215. #endif
  85216. }
  85217. *(residual++) = *(data++) - (sum >> lp_quantization);
  85218. }
  85219. }
  85220. #else /* fully unrolled version for normal use */
  85221. {
  85222. int i;
  85223. FLAC__int32 sum;
  85224. FLAC__ASSERT(order > 0);
  85225. FLAC__ASSERT(order <= 32);
  85226. if(order <= 12) {
  85227. if(order > 8) {
  85228. if(order > 10) {
  85229. if(order == 12) {
  85230. for(i = 0; i < (int)data_len; i++) {
  85231. sum = 0;
  85232. sum += qlp_coeff[11] * data[i-12];
  85233. sum += qlp_coeff[10] * data[i-11];
  85234. sum += qlp_coeff[9] * data[i-10];
  85235. sum += qlp_coeff[8] * data[i-9];
  85236. sum += qlp_coeff[7] * data[i-8];
  85237. sum += qlp_coeff[6] * data[i-7];
  85238. sum += qlp_coeff[5] * data[i-6];
  85239. sum += qlp_coeff[4] * data[i-5];
  85240. sum += qlp_coeff[3] * data[i-4];
  85241. sum += qlp_coeff[2] * data[i-3];
  85242. sum += qlp_coeff[1] * data[i-2];
  85243. sum += qlp_coeff[0] * data[i-1];
  85244. residual[i] = data[i] - (sum >> lp_quantization);
  85245. }
  85246. }
  85247. else { /* order == 11 */
  85248. for(i = 0; i < (int)data_len; i++) {
  85249. sum = 0;
  85250. sum += qlp_coeff[10] * data[i-11];
  85251. sum += qlp_coeff[9] * data[i-10];
  85252. sum += qlp_coeff[8] * data[i-9];
  85253. sum += qlp_coeff[7] * data[i-8];
  85254. sum += qlp_coeff[6] * data[i-7];
  85255. sum += qlp_coeff[5] * data[i-6];
  85256. sum += qlp_coeff[4] * data[i-5];
  85257. sum += qlp_coeff[3] * data[i-4];
  85258. sum += qlp_coeff[2] * data[i-3];
  85259. sum += qlp_coeff[1] * data[i-2];
  85260. sum += qlp_coeff[0] * data[i-1];
  85261. residual[i] = data[i] - (sum >> lp_quantization);
  85262. }
  85263. }
  85264. }
  85265. else {
  85266. if(order == 10) {
  85267. for(i = 0; i < (int)data_len; i++) {
  85268. sum = 0;
  85269. sum += qlp_coeff[9] * data[i-10];
  85270. sum += qlp_coeff[8] * data[i-9];
  85271. sum += qlp_coeff[7] * data[i-8];
  85272. sum += qlp_coeff[6] * data[i-7];
  85273. sum += qlp_coeff[5] * data[i-6];
  85274. sum += qlp_coeff[4] * data[i-5];
  85275. sum += qlp_coeff[3] * data[i-4];
  85276. sum += qlp_coeff[2] * data[i-3];
  85277. sum += qlp_coeff[1] * data[i-2];
  85278. sum += qlp_coeff[0] * data[i-1];
  85279. residual[i] = data[i] - (sum >> lp_quantization);
  85280. }
  85281. }
  85282. else { /* order == 9 */
  85283. for(i = 0; i < (int)data_len; i++) {
  85284. sum = 0;
  85285. sum += qlp_coeff[8] * data[i-9];
  85286. sum += qlp_coeff[7] * data[i-8];
  85287. sum += qlp_coeff[6] * data[i-7];
  85288. sum += qlp_coeff[5] * data[i-6];
  85289. sum += qlp_coeff[4] * data[i-5];
  85290. sum += qlp_coeff[3] * data[i-4];
  85291. sum += qlp_coeff[2] * data[i-3];
  85292. sum += qlp_coeff[1] * data[i-2];
  85293. sum += qlp_coeff[0] * data[i-1];
  85294. residual[i] = data[i] - (sum >> lp_quantization);
  85295. }
  85296. }
  85297. }
  85298. }
  85299. else if(order > 4) {
  85300. if(order > 6) {
  85301. if(order == 8) {
  85302. for(i = 0; i < (int)data_len; i++) {
  85303. sum = 0;
  85304. sum += qlp_coeff[7] * data[i-8];
  85305. sum += qlp_coeff[6] * data[i-7];
  85306. sum += qlp_coeff[5] * data[i-6];
  85307. sum += qlp_coeff[4] * data[i-5];
  85308. sum += qlp_coeff[3] * data[i-4];
  85309. sum += qlp_coeff[2] * data[i-3];
  85310. sum += qlp_coeff[1] * data[i-2];
  85311. sum += qlp_coeff[0] * data[i-1];
  85312. residual[i] = data[i] - (sum >> lp_quantization);
  85313. }
  85314. }
  85315. else { /* order == 7 */
  85316. for(i = 0; i < (int)data_len; i++) {
  85317. sum = 0;
  85318. sum += qlp_coeff[6] * data[i-7];
  85319. sum += qlp_coeff[5] * data[i-6];
  85320. sum += qlp_coeff[4] * data[i-5];
  85321. sum += qlp_coeff[3] * data[i-4];
  85322. sum += qlp_coeff[2] * data[i-3];
  85323. sum += qlp_coeff[1] * data[i-2];
  85324. sum += qlp_coeff[0] * data[i-1];
  85325. residual[i] = data[i] - (sum >> lp_quantization);
  85326. }
  85327. }
  85328. }
  85329. else {
  85330. if(order == 6) {
  85331. for(i = 0; i < (int)data_len; i++) {
  85332. sum = 0;
  85333. sum += qlp_coeff[5] * data[i-6];
  85334. sum += qlp_coeff[4] * data[i-5];
  85335. sum += qlp_coeff[3] * data[i-4];
  85336. sum += qlp_coeff[2] * data[i-3];
  85337. sum += qlp_coeff[1] * data[i-2];
  85338. sum += qlp_coeff[0] * data[i-1];
  85339. residual[i] = data[i] - (sum >> lp_quantization);
  85340. }
  85341. }
  85342. else { /* order == 5 */
  85343. for(i = 0; i < (int)data_len; i++) {
  85344. sum = 0;
  85345. sum += qlp_coeff[4] * data[i-5];
  85346. sum += qlp_coeff[3] * data[i-4];
  85347. sum += qlp_coeff[2] * data[i-3];
  85348. sum += qlp_coeff[1] * data[i-2];
  85349. sum += qlp_coeff[0] * data[i-1];
  85350. residual[i] = data[i] - (sum >> lp_quantization);
  85351. }
  85352. }
  85353. }
  85354. }
  85355. else {
  85356. if(order > 2) {
  85357. if(order == 4) {
  85358. for(i = 0; i < (int)data_len; i++) {
  85359. sum = 0;
  85360. sum += qlp_coeff[3] * data[i-4];
  85361. sum += qlp_coeff[2] * data[i-3];
  85362. sum += qlp_coeff[1] * data[i-2];
  85363. sum += qlp_coeff[0] * data[i-1];
  85364. residual[i] = data[i] - (sum >> lp_quantization);
  85365. }
  85366. }
  85367. else { /* order == 3 */
  85368. for(i = 0; i < (int)data_len; i++) {
  85369. sum = 0;
  85370. sum += qlp_coeff[2] * data[i-3];
  85371. sum += qlp_coeff[1] * data[i-2];
  85372. sum += qlp_coeff[0] * data[i-1];
  85373. residual[i] = data[i] - (sum >> lp_quantization);
  85374. }
  85375. }
  85376. }
  85377. else {
  85378. if(order == 2) {
  85379. for(i = 0; i < (int)data_len; i++) {
  85380. sum = 0;
  85381. sum += qlp_coeff[1] * data[i-2];
  85382. sum += qlp_coeff[0] * data[i-1];
  85383. residual[i] = data[i] - (sum >> lp_quantization);
  85384. }
  85385. }
  85386. else { /* order == 1 */
  85387. for(i = 0; i < (int)data_len; i++)
  85388. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85389. }
  85390. }
  85391. }
  85392. }
  85393. else { /* order > 12 */
  85394. for(i = 0; i < (int)data_len; i++) {
  85395. sum = 0;
  85396. switch(order) {
  85397. case 32: sum += qlp_coeff[31] * data[i-32];
  85398. case 31: sum += qlp_coeff[30] * data[i-31];
  85399. case 30: sum += qlp_coeff[29] * data[i-30];
  85400. case 29: sum += qlp_coeff[28] * data[i-29];
  85401. case 28: sum += qlp_coeff[27] * data[i-28];
  85402. case 27: sum += qlp_coeff[26] * data[i-27];
  85403. case 26: sum += qlp_coeff[25] * data[i-26];
  85404. case 25: sum += qlp_coeff[24] * data[i-25];
  85405. case 24: sum += qlp_coeff[23] * data[i-24];
  85406. case 23: sum += qlp_coeff[22] * data[i-23];
  85407. case 22: sum += qlp_coeff[21] * data[i-22];
  85408. case 21: sum += qlp_coeff[20] * data[i-21];
  85409. case 20: sum += qlp_coeff[19] * data[i-20];
  85410. case 19: sum += qlp_coeff[18] * data[i-19];
  85411. case 18: sum += qlp_coeff[17] * data[i-18];
  85412. case 17: sum += qlp_coeff[16] * data[i-17];
  85413. case 16: sum += qlp_coeff[15] * data[i-16];
  85414. case 15: sum += qlp_coeff[14] * data[i-15];
  85415. case 14: sum += qlp_coeff[13] * data[i-14];
  85416. case 13: sum += qlp_coeff[12] * data[i-13];
  85417. sum += qlp_coeff[11] * data[i-12];
  85418. sum += qlp_coeff[10] * data[i-11];
  85419. sum += qlp_coeff[ 9] * data[i-10];
  85420. sum += qlp_coeff[ 8] * data[i- 9];
  85421. sum += qlp_coeff[ 7] * data[i- 8];
  85422. sum += qlp_coeff[ 6] * data[i- 7];
  85423. sum += qlp_coeff[ 5] * data[i- 6];
  85424. sum += qlp_coeff[ 4] * data[i- 5];
  85425. sum += qlp_coeff[ 3] * data[i- 4];
  85426. sum += qlp_coeff[ 2] * data[i- 3];
  85427. sum += qlp_coeff[ 1] * data[i- 2];
  85428. sum += qlp_coeff[ 0] * data[i- 1];
  85429. }
  85430. residual[i] = data[i] - (sum >> lp_quantization);
  85431. }
  85432. }
  85433. }
  85434. #endif
  85435. 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[])
  85436. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85437. {
  85438. unsigned i, j;
  85439. FLAC__int64 sum;
  85440. const FLAC__int32 *history;
  85441. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85442. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85443. for(i=0;i<order;i++)
  85444. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85445. fprintf(stderr,"\n");
  85446. #endif
  85447. FLAC__ASSERT(order > 0);
  85448. for(i = 0; i < data_len; i++) {
  85449. sum = 0;
  85450. history = data;
  85451. for(j = 0; j < order; j++)
  85452. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85453. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85454. #if defined _MSC_VER
  85455. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85456. #else
  85457. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85458. #endif
  85459. break;
  85460. }
  85461. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85462. #if defined _MSC_VER
  85463. 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));
  85464. #else
  85465. 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)));
  85466. #endif
  85467. break;
  85468. }
  85469. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85470. }
  85471. }
  85472. #else /* fully unrolled version for normal use */
  85473. {
  85474. int i;
  85475. FLAC__int64 sum;
  85476. FLAC__ASSERT(order > 0);
  85477. FLAC__ASSERT(order <= 32);
  85478. if(order <= 12) {
  85479. if(order > 8) {
  85480. if(order > 10) {
  85481. if(order == 12) {
  85482. for(i = 0; i < (int)data_len; i++) {
  85483. sum = 0;
  85484. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85485. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85486. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85487. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85488. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85489. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85490. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85491. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85492. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85493. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85494. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85495. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85496. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85497. }
  85498. }
  85499. else { /* order == 11 */
  85500. for(i = 0; i < (int)data_len; i++) {
  85501. sum = 0;
  85502. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85503. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85504. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85505. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85506. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85507. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85508. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85509. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85510. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85511. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85512. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85513. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85514. }
  85515. }
  85516. }
  85517. else {
  85518. if(order == 10) {
  85519. for(i = 0; i < (int)data_len; i++) {
  85520. sum = 0;
  85521. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85522. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85523. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85524. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85525. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85526. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85527. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85528. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85529. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85530. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85531. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85532. }
  85533. }
  85534. else { /* order == 9 */
  85535. for(i = 0; i < (int)data_len; i++) {
  85536. sum = 0;
  85537. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85538. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85539. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85540. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85541. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85542. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85543. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85544. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85545. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85546. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85547. }
  85548. }
  85549. }
  85550. }
  85551. else if(order > 4) {
  85552. if(order > 6) {
  85553. if(order == 8) {
  85554. for(i = 0; i < (int)data_len; i++) {
  85555. sum = 0;
  85556. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85557. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85558. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85559. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85560. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85561. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85562. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85563. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85564. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85565. }
  85566. }
  85567. else { /* order == 7 */
  85568. for(i = 0; i < (int)data_len; i++) {
  85569. sum = 0;
  85570. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85571. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85572. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85573. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85574. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85575. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85576. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85577. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85578. }
  85579. }
  85580. }
  85581. else {
  85582. if(order == 6) {
  85583. for(i = 0; i < (int)data_len; i++) {
  85584. sum = 0;
  85585. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85586. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85587. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85588. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85589. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85590. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85591. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85592. }
  85593. }
  85594. else { /* order == 5 */
  85595. for(i = 0; i < (int)data_len; i++) {
  85596. sum = 0;
  85597. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85598. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85599. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85600. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85601. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85602. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85603. }
  85604. }
  85605. }
  85606. }
  85607. else {
  85608. if(order > 2) {
  85609. if(order == 4) {
  85610. for(i = 0; i < (int)data_len; i++) {
  85611. sum = 0;
  85612. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85613. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85614. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85615. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85616. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85617. }
  85618. }
  85619. else { /* order == 3 */
  85620. for(i = 0; i < (int)data_len; i++) {
  85621. sum = 0;
  85622. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85623. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85624. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85625. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85626. }
  85627. }
  85628. }
  85629. else {
  85630. if(order == 2) {
  85631. for(i = 0; i < (int)data_len; i++) {
  85632. sum = 0;
  85633. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85634. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85635. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85636. }
  85637. }
  85638. else { /* order == 1 */
  85639. for(i = 0; i < (int)data_len; i++)
  85640. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  85641. }
  85642. }
  85643. }
  85644. }
  85645. else { /* order > 12 */
  85646. for(i = 0; i < (int)data_len; i++) {
  85647. sum = 0;
  85648. switch(order) {
  85649. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  85650. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  85651. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  85652. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  85653. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  85654. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  85655. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  85656. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  85657. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  85658. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  85659. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  85660. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  85661. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  85662. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  85663. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  85664. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  85665. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  85666. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  85667. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  85668. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  85669. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85670. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85671. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  85672. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  85673. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  85674. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  85675. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  85676. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  85677. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  85678. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  85679. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  85680. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  85681. }
  85682. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85683. }
  85684. }
  85685. }
  85686. #endif
  85687. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85688. 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[])
  85689. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85690. {
  85691. FLAC__int64 sumo;
  85692. unsigned i, j;
  85693. FLAC__int32 sum;
  85694. const FLAC__int32 *r = residual, *history;
  85695. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85696. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85697. for(i=0;i<order;i++)
  85698. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85699. fprintf(stderr,"\n");
  85700. #endif
  85701. FLAC__ASSERT(order > 0);
  85702. for(i = 0; i < data_len; i++) {
  85703. sumo = 0;
  85704. sum = 0;
  85705. history = data;
  85706. for(j = 0; j < order; j++) {
  85707. sum += qlp_coeff[j] * (*(--history));
  85708. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85709. #if defined _MSC_VER
  85710. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85711. 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);
  85712. #else
  85713. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85714. 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);
  85715. #endif
  85716. }
  85717. *(data++) = *(r++) + (sum >> lp_quantization);
  85718. }
  85719. }
  85720. #else /* fully unrolled version for normal use */
  85721. {
  85722. int i;
  85723. FLAC__int32 sum;
  85724. FLAC__ASSERT(order > 0);
  85725. FLAC__ASSERT(order <= 32);
  85726. if(order <= 12) {
  85727. if(order > 8) {
  85728. if(order > 10) {
  85729. if(order == 12) {
  85730. for(i = 0; i < (int)data_len; i++) {
  85731. sum = 0;
  85732. sum += qlp_coeff[11] * data[i-12];
  85733. sum += qlp_coeff[10] * data[i-11];
  85734. sum += qlp_coeff[9] * data[i-10];
  85735. sum += qlp_coeff[8] * data[i-9];
  85736. sum += qlp_coeff[7] * data[i-8];
  85737. sum += qlp_coeff[6] * data[i-7];
  85738. sum += qlp_coeff[5] * data[i-6];
  85739. sum += qlp_coeff[4] * data[i-5];
  85740. sum += qlp_coeff[3] * data[i-4];
  85741. sum += qlp_coeff[2] * data[i-3];
  85742. sum += qlp_coeff[1] * data[i-2];
  85743. sum += qlp_coeff[0] * data[i-1];
  85744. data[i] = residual[i] + (sum >> lp_quantization);
  85745. }
  85746. }
  85747. else { /* order == 11 */
  85748. for(i = 0; i < (int)data_len; i++) {
  85749. sum = 0;
  85750. sum += qlp_coeff[10] * data[i-11];
  85751. sum += qlp_coeff[9] * data[i-10];
  85752. sum += qlp_coeff[8] * data[i-9];
  85753. sum += qlp_coeff[7] * data[i-8];
  85754. sum += qlp_coeff[6] * data[i-7];
  85755. sum += qlp_coeff[5] * data[i-6];
  85756. sum += qlp_coeff[4] * data[i-5];
  85757. sum += qlp_coeff[3] * data[i-4];
  85758. sum += qlp_coeff[2] * data[i-3];
  85759. sum += qlp_coeff[1] * data[i-2];
  85760. sum += qlp_coeff[0] * data[i-1];
  85761. data[i] = residual[i] + (sum >> lp_quantization);
  85762. }
  85763. }
  85764. }
  85765. else {
  85766. if(order == 10) {
  85767. for(i = 0; i < (int)data_len; i++) {
  85768. sum = 0;
  85769. sum += qlp_coeff[9] * data[i-10];
  85770. sum += qlp_coeff[8] * data[i-9];
  85771. sum += qlp_coeff[7] * data[i-8];
  85772. sum += qlp_coeff[6] * data[i-7];
  85773. sum += qlp_coeff[5] * data[i-6];
  85774. sum += qlp_coeff[4] * data[i-5];
  85775. sum += qlp_coeff[3] * data[i-4];
  85776. sum += qlp_coeff[2] * data[i-3];
  85777. sum += qlp_coeff[1] * data[i-2];
  85778. sum += qlp_coeff[0] * data[i-1];
  85779. data[i] = residual[i] + (sum >> lp_quantization);
  85780. }
  85781. }
  85782. else { /* order == 9 */
  85783. for(i = 0; i < (int)data_len; i++) {
  85784. sum = 0;
  85785. sum += qlp_coeff[8] * data[i-9];
  85786. sum += qlp_coeff[7] * data[i-8];
  85787. sum += qlp_coeff[6] * data[i-7];
  85788. sum += qlp_coeff[5] * data[i-6];
  85789. sum += qlp_coeff[4] * data[i-5];
  85790. sum += qlp_coeff[3] * data[i-4];
  85791. sum += qlp_coeff[2] * data[i-3];
  85792. sum += qlp_coeff[1] * data[i-2];
  85793. sum += qlp_coeff[0] * data[i-1];
  85794. data[i] = residual[i] + (sum >> lp_quantization);
  85795. }
  85796. }
  85797. }
  85798. }
  85799. else if(order > 4) {
  85800. if(order > 6) {
  85801. if(order == 8) {
  85802. for(i = 0; i < (int)data_len; i++) {
  85803. sum = 0;
  85804. sum += qlp_coeff[7] * data[i-8];
  85805. sum += qlp_coeff[6] * data[i-7];
  85806. sum += qlp_coeff[5] * data[i-6];
  85807. sum += qlp_coeff[4] * data[i-5];
  85808. sum += qlp_coeff[3] * data[i-4];
  85809. sum += qlp_coeff[2] * data[i-3];
  85810. sum += qlp_coeff[1] * data[i-2];
  85811. sum += qlp_coeff[0] * data[i-1];
  85812. data[i] = residual[i] + (sum >> lp_quantization);
  85813. }
  85814. }
  85815. else { /* order == 7 */
  85816. for(i = 0; i < (int)data_len; i++) {
  85817. sum = 0;
  85818. sum += qlp_coeff[6] * data[i-7];
  85819. sum += qlp_coeff[5] * data[i-6];
  85820. sum += qlp_coeff[4] * data[i-5];
  85821. sum += qlp_coeff[3] * data[i-4];
  85822. sum += qlp_coeff[2] * data[i-3];
  85823. sum += qlp_coeff[1] * data[i-2];
  85824. sum += qlp_coeff[0] * data[i-1];
  85825. data[i] = residual[i] + (sum >> lp_quantization);
  85826. }
  85827. }
  85828. }
  85829. else {
  85830. if(order == 6) {
  85831. for(i = 0; i < (int)data_len; i++) {
  85832. sum = 0;
  85833. sum += qlp_coeff[5] * data[i-6];
  85834. sum += qlp_coeff[4] * data[i-5];
  85835. sum += qlp_coeff[3] * data[i-4];
  85836. sum += qlp_coeff[2] * data[i-3];
  85837. sum += qlp_coeff[1] * data[i-2];
  85838. sum += qlp_coeff[0] * data[i-1];
  85839. data[i] = residual[i] + (sum >> lp_quantization);
  85840. }
  85841. }
  85842. else { /* order == 5 */
  85843. for(i = 0; i < (int)data_len; i++) {
  85844. sum = 0;
  85845. sum += qlp_coeff[4] * data[i-5];
  85846. sum += qlp_coeff[3] * data[i-4];
  85847. sum += qlp_coeff[2] * data[i-3];
  85848. sum += qlp_coeff[1] * data[i-2];
  85849. sum += qlp_coeff[0] * data[i-1];
  85850. data[i] = residual[i] + (sum >> lp_quantization);
  85851. }
  85852. }
  85853. }
  85854. }
  85855. else {
  85856. if(order > 2) {
  85857. if(order == 4) {
  85858. for(i = 0; i < (int)data_len; i++) {
  85859. sum = 0;
  85860. sum += qlp_coeff[3] * data[i-4];
  85861. sum += qlp_coeff[2] * data[i-3];
  85862. sum += qlp_coeff[1] * data[i-2];
  85863. sum += qlp_coeff[0] * data[i-1];
  85864. data[i] = residual[i] + (sum >> lp_quantization);
  85865. }
  85866. }
  85867. else { /* order == 3 */
  85868. for(i = 0; i < (int)data_len; i++) {
  85869. sum = 0;
  85870. sum += qlp_coeff[2] * data[i-3];
  85871. sum += qlp_coeff[1] * data[i-2];
  85872. sum += qlp_coeff[0] * data[i-1];
  85873. data[i] = residual[i] + (sum >> lp_quantization);
  85874. }
  85875. }
  85876. }
  85877. else {
  85878. if(order == 2) {
  85879. for(i = 0; i < (int)data_len; i++) {
  85880. sum = 0;
  85881. sum += qlp_coeff[1] * data[i-2];
  85882. sum += qlp_coeff[0] * data[i-1];
  85883. data[i] = residual[i] + (sum >> lp_quantization);
  85884. }
  85885. }
  85886. else { /* order == 1 */
  85887. for(i = 0; i < (int)data_len; i++)
  85888. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85889. }
  85890. }
  85891. }
  85892. }
  85893. else { /* order > 12 */
  85894. for(i = 0; i < (int)data_len; i++) {
  85895. sum = 0;
  85896. switch(order) {
  85897. case 32: sum += qlp_coeff[31] * data[i-32];
  85898. case 31: sum += qlp_coeff[30] * data[i-31];
  85899. case 30: sum += qlp_coeff[29] * data[i-30];
  85900. case 29: sum += qlp_coeff[28] * data[i-29];
  85901. case 28: sum += qlp_coeff[27] * data[i-28];
  85902. case 27: sum += qlp_coeff[26] * data[i-27];
  85903. case 26: sum += qlp_coeff[25] * data[i-26];
  85904. case 25: sum += qlp_coeff[24] * data[i-25];
  85905. case 24: sum += qlp_coeff[23] * data[i-24];
  85906. case 23: sum += qlp_coeff[22] * data[i-23];
  85907. case 22: sum += qlp_coeff[21] * data[i-22];
  85908. case 21: sum += qlp_coeff[20] * data[i-21];
  85909. case 20: sum += qlp_coeff[19] * data[i-20];
  85910. case 19: sum += qlp_coeff[18] * data[i-19];
  85911. case 18: sum += qlp_coeff[17] * data[i-18];
  85912. case 17: sum += qlp_coeff[16] * data[i-17];
  85913. case 16: sum += qlp_coeff[15] * data[i-16];
  85914. case 15: sum += qlp_coeff[14] * data[i-15];
  85915. case 14: sum += qlp_coeff[13] * data[i-14];
  85916. case 13: sum += qlp_coeff[12] * data[i-13];
  85917. sum += qlp_coeff[11] * data[i-12];
  85918. sum += qlp_coeff[10] * data[i-11];
  85919. sum += qlp_coeff[ 9] * data[i-10];
  85920. sum += qlp_coeff[ 8] * data[i- 9];
  85921. sum += qlp_coeff[ 7] * data[i- 8];
  85922. sum += qlp_coeff[ 6] * data[i- 7];
  85923. sum += qlp_coeff[ 5] * data[i- 6];
  85924. sum += qlp_coeff[ 4] * data[i- 5];
  85925. sum += qlp_coeff[ 3] * data[i- 4];
  85926. sum += qlp_coeff[ 2] * data[i- 3];
  85927. sum += qlp_coeff[ 1] * data[i- 2];
  85928. sum += qlp_coeff[ 0] * data[i- 1];
  85929. }
  85930. data[i] = residual[i] + (sum >> lp_quantization);
  85931. }
  85932. }
  85933. }
  85934. #endif
  85935. 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[])
  85936. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85937. {
  85938. unsigned i, j;
  85939. FLAC__int64 sum;
  85940. const FLAC__int32 *r = residual, *history;
  85941. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85942. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85943. for(i=0;i<order;i++)
  85944. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85945. fprintf(stderr,"\n");
  85946. #endif
  85947. FLAC__ASSERT(order > 0);
  85948. for(i = 0; i < data_len; i++) {
  85949. sum = 0;
  85950. history = data;
  85951. for(j = 0; j < order; j++)
  85952. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85953. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85954. #ifdef _MSC_VER
  85955. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85956. #else
  85957. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85958. #endif
  85959. break;
  85960. }
  85961. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  85962. #ifdef _MSC_VER
  85963. 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));
  85964. #else
  85965. 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)));
  85966. #endif
  85967. break;
  85968. }
  85969. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  85970. }
  85971. }
  85972. #else /* fully unrolled version for normal use */
  85973. {
  85974. int i;
  85975. FLAC__int64 sum;
  85976. FLAC__ASSERT(order > 0);
  85977. FLAC__ASSERT(order <= 32);
  85978. if(order <= 12) {
  85979. if(order > 8) {
  85980. if(order > 10) {
  85981. if(order == 12) {
  85982. for(i = 0; i < (int)data_len; i++) {
  85983. sum = 0;
  85984. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85985. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85986. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85987. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85988. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85989. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85990. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85991. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85992. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85993. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85994. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85995. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85996. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85997. }
  85998. }
  85999. else { /* order == 11 */
  86000. for(i = 0; i < (int)data_len; i++) {
  86001. sum = 0;
  86002. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86003. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86004. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86005. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86006. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86007. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86008. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86009. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86010. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86011. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86012. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86013. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86014. }
  86015. }
  86016. }
  86017. else {
  86018. if(order == 10) {
  86019. for(i = 0; i < (int)data_len; i++) {
  86020. sum = 0;
  86021. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86022. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86023. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86024. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86025. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86026. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86027. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86028. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86029. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86030. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86031. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86032. }
  86033. }
  86034. else { /* order == 9 */
  86035. for(i = 0; i < (int)data_len; i++) {
  86036. sum = 0;
  86037. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86038. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86039. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86040. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86041. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86042. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86043. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86044. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86045. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86046. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86047. }
  86048. }
  86049. }
  86050. }
  86051. else if(order > 4) {
  86052. if(order > 6) {
  86053. if(order == 8) {
  86054. for(i = 0; i < (int)data_len; i++) {
  86055. sum = 0;
  86056. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86057. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86058. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86059. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86060. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86061. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86062. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86063. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86064. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86065. }
  86066. }
  86067. else { /* order == 7 */
  86068. for(i = 0; i < (int)data_len; i++) {
  86069. sum = 0;
  86070. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86071. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86072. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86073. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86074. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86075. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86076. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86077. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86078. }
  86079. }
  86080. }
  86081. else {
  86082. if(order == 6) {
  86083. for(i = 0; i < (int)data_len; i++) {
  86084. sum = 0;
  86085. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86086. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86087. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86088. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86089. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86090. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86091. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86092. }
  86093. }
  86094. else { /* order == 5 */
  86095. for(i = 0; i < (int)data_len; i++) {
  86096. sum = 0;
  86097. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86098. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86099. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86100. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86101. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86102. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86103. }
  86104. }
  86105. }
  86106. }
  86107. else {
  86108. if(order > 2) {
  86109. if(order == 4) {
  86110. for(i = 0; i < (int)data_len; i++) {
  86111. sum = 0;
  86112. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86113. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86114. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86115. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86116. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86117. }
  86118. }
  86119. else { /* order == 3 */
  86120. for(i = 0; i < (int)data_len; i++) {
  86121. sum = 0;
  86122. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86123. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86124. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86125. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86126. }
  86127. }
  86128. }
  86129. else {
  86130. if(order == 2) {
  86131. for(i = 0; i < (int)data_len; i++) {
  86132. sum = 0;
  86133. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86134. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86135. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86136. }
  86137. }
  86138. else { /* order == 1 */
  86139. for(i = 0; i < (int)data_len; i++)
  86140. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86141. }
  86142. }
  86143. }
  86144. }
  86145. else { /* order > 12 */
  86146. for(i = 0; i < (int)data_len; i++) {
  86147. sum = 0;
  86148. switch(order) {
  86149. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86150. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86151. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86152. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86153. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86154. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86155. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86156. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86157. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86158. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86159. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86160. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86161. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86162. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86163. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86164. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86165. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86166. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86167. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86168. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86169. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86170. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86171. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86172. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86173. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86174. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86175. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86176. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86177. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86178. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86179. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86180. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86181. }
  86182. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86183. }
  86184. }
  86185. }
  86186. #endif
  86187. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86188. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86189. {
  86190. FLAC__double error_scale;
  86191. FLAC__ASSERT(total_samples > 0);
  86192. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86193. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86194. }
  86195. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86196. {
  86197. if(lpc_error > 0.0) {
  86198. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86199. if(bps >= 0.0)
  86200. return bps;
  86201. else
  86202. return 0.0;
  86203. }
  86204. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86205. return 1e32;
  86206. }
  86207. else {
  86208. return 0.0;
  86209. }
  86210. }
  86211. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86212. {
  86213. 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 */
  86214. FLAC__double bits, best_bits, error_scale;
  86215. FLAC__ASSERT(max_order > 0);
  86216. FLAC__ASSERT(total_samples > 0);
  86217. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86218. best_index = 0;
  86219. best_bits = (unsigned)(-1);
  86220. for(index = 0, order = 1; index < max_order; index++, order++) {
  86221. 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);
  86222. if(bits < best_bits) {
  86223. best_index = index;
  86224. best_bits = bits;
  86225. }
  86226. }
  86227. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86228. }
  86229. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86230. #endif
  86231. /*** End of inlined file: lpc_flac.c ***/
  86232. /*** Start of inlined file: md5.c ***/
  86233. /*** Start of inlined file: juce_FlacHeader.h ***/
  86234. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86235. // tasks..
  86236. #define VERSION "1.2.1"
  86237. #define FLAC__NO_DLL 1
  86238. #if JUCE_MSVC
  86239. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86240. #endif
  86241. #if JUCE_MAC
  86242. #define FLAC__SYS_DARWIN 1
  86243. #endif
  86244. /*** End of inlined file: juce_FlacHeader.h ***/
  86245. #if JUCE_USE_FLAC
  86246. #if HAVE_CONFIG_H
  86247. # include <config.h>
  86248. #endif
  86249. #include <stdlib.h> /* for malloc() */
  86250. #include <string.h> /* for memcpy() */
  86251. /*** Start of inlined file: md5.h ***/
  86252. #ifndef FLAC__PRIVATE__MD5_H
  86253. #define FLAC__PRIVATE__MD5_H
  86254. typedef struct {
  86255. FLAC__uint32 in[16];
  86256. FLAC__uint32 buf[4];
  86257. FLAC__uint32 bytes[2];
  86258. FLAC__byte *internal_buf;
  86259. size_t capacity;
  86260. } FLAC__MD5Context;
  86261. void FLAC__MD5Init(FLAC__MD5Context *context);
  86262. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86263. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86264. #endif
  86265. /*** End of inlined file: md5.h ***/
  86266. #ifndef FLaC__INLINE
  86267. #define FLaC__INLINE
  86268. #endif
  86269. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86270. #define F2(x, y, z) F1(z, x, y)
  86271. #define F3(x, y, z) (x ^ y ^ z)
  86272. #define F4(x, y, z) (y ^ (x | ~z))
  86273. #define MD5STEP(f,w,x,y,z,in,s) \
  86274. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86275. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86276. {
  86277. register FLAC__uint32 a, b, c, d;
  86278. a = buf[0];
  86279. b = buf[1];
  86280. c = buf[2];
  86281. d = buf[3];
  86282. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86283. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86284. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86285. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86286. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86287. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86288. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86289. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86290. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86291. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86292. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86293. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86294. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86295. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86296. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86297. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86298. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86299. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86300. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86301. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86302. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86303. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86304. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86305. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86306. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86307. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86308. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86309. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86310. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86311. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86312. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86313. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86314. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86315. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86316. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86317. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86318. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86319. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86320. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86321. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86322. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86323. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86324. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86325. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86326. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86327. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86328. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86329. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86330. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86331. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86332. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86333. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86334. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86335. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86336. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86337. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86338. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86339. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86340. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86341. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86342. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86343. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86344. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86345. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86346. buf[0] += a;
  86347. buf[1] += b;
  86348. buf[2] += c;
  86349. buf[3] += d;
  86350. }
  86351. #if WORDS_BIGENDIAN
  86352. //@@@@@@ OPT: use bswap/intrinsics
  86353. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86354. {
  86355. register FLAC__uint32 x;
  86356. do {
  86357. x = *buf;
  86358. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86359. *buf++ = (x >> 16) | (x << 16);
  86360. } while (--words);
  86361. }
  86362. static void byteSwapX16(FLAC__uint32 *buf)
  86363. {
  86364. register FLAC__uint32 x;
  86365. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86366. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86367. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86368. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86369. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86370. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86371. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86372. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86373. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86374. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86375. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86376. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86377. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86378. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86379. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86380. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86381. }
  86382. #else
  86383. #define byteSwap(buf, words)
  86384. #define byteSwapX16(buf)
  86385. #endif
  86386. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86387. {
  86388. FLAC__uint32 t;
  86389. t = ctx->bytes[0];
  86390. if ((ctx->bytes[0] = t + len) < t)
  86391. ctx->bytes[1]++; /* Carry from low to high */
  86392. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86393. if (t > len) {
  86394. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86395. return;
  86396. }
  86397. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86398. byteSwapX16(ctx->in);
  86399. FLAC__MD5Transform(ctx->buf, ctx->in);
  86400. buf += t;
  86401. len -= t;
  86402. while (len >= 64) {
  86403. memcpy(ctx->in, buf, 64);
  86404. byteSwapX16(ctx->in);
  86405. FLAC__MD5Transform(ctx->buf, ctx->in);
  86406. buf += 64;
  86407. len -= 64;
  86408. }
  86409. memcpy(ctx->in, buf, len);
  86410. }
  86411. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86412. {
  86413. ctx->buf[0] = 0x67452301;
  86414. ctx->buf[1] = 0xefcdab89;
  86415. ctx->buf[2] = 0x98badcfe;
  86416. ctx->buf[3] = 0x10325476;
  86417. ctx->bytes[0] = 0;
  86418. ctx->bytes[1] = 0;
  86419. ctx->internal_buf = 0;
  86420. ctx->capacity = 0;
  86421. }
  86422. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86423. {
  86424. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86425. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86426. *p++ = 0x80;
  86427. count = 56 - 1 - count;
  86428. if (count < 0) { /* Padding forces an extra block */
  86429. memset(p, 0, count + 8);
  86430. byteSwapX16(ctx->in);
  86431. FLAC__MD5Transform(ctx->buf, ctx->in);
  86432. p = (FLAC__byte *)ctx->in;
  86433. count = 56;
  86434. }
  86435. memset(p, 0, count);
  86436. byteSwap(ctx->in, 14);
  86437. ctx->in[14] = ctx->bytes[0] << 3;
  86438. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86439. FLAC__MD5Transform(ctx->buf, ctx->in);
  86440. byteSwap(ctx->buf, 4);
  86441. memcpy(digest, ctx->buf, 16);
  86442. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86443. if(0 != ctx->internal_buf) {
  86444. free(ctx->internal_buf);
  86445. ctx->internal_buf = 0;
  86446. ctx->capacity = 0;
  86447. }
  86448. }
  86449. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86450. {
  86451. unsigned channel, sample;
  86452. register FLAC__int32 a_word;
  86453. register FLAC__byte *buf_ = buf;
  86454. #if WORDS_BIGENDIAN
  86455. #else
  86456. if(channels == 2 && bytes_per_sample == 2) {
  86457. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86458. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86459. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86460. *buf1_ = (FLAC__int16)signal[1][sample];
  86461. }
  86462. else if(channels == 1 && bytes_per_sample == 2) {
  86463. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86464. for(sample = 0; sample < samples; sample++)
  86465. *buf1_++ = (FLAC__int16)signal[0][sample];
  86466. }
  86467. else
  86468. #endif
  86469. if(bytes_per_sample == 2) {
  86470. if(channels == 2) {
  86471. for(sample = 0; sample < samples; sample++) {
  86472. a_word = signal[0][sample];
  86473. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86474. *buf_++ = (FLAC__byte)a_word;
  86475. a_word = signal[1][sample];
  86476. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86477. *buf_++ = (FLAC__byte)a_word;
  86478. }
  86479. }
  86480. else if(channels == 1) {
  86481. for(sample = 0; sample < samples; sample++) {
  86482. a_word = signal[0][sample];
  86483. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86484. *buf_++ = (FLAC__byte)a_word;
  86485. }
  86486. }
  86487. else {
  86488. for(sample = 0; sample < samples; sample++) {
  86489. for(channel = 0; channel < channels; channel++) {
  86490. a_word = signal[channel][sample];
  86491. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86492. *buf_++ = (FLAC__byte)a_word;
  86493. }
  86494. }
  86495. }
  86496. }
  86497. else if(bytes_per_sample == 3) {
  86498. if(channels == 2) {
  86499. for(sample = 0; sample < samples; sample++) {
  86500. a_word = signal[0][sample];
  86501. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86502. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86503. *buf_++ = (FLAC__byte)a_word;
  86504. a_word = signal[1][sample];
  86505. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86506. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86507. *buf_++ = (FLAC__byte)a_word;
  86508. }
  86509. }
  86510. else if(channels == 1) {
  86511. for(sample = 0; sample < samples; sample++) {
  86512. a_word = signal[0][sample];
  86513. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86514. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86515. *buf_++ = (FLAC__byte)a_word;
  86516. }
  86517. }
  86518. else {
  86519. for(sample = 0; sample < samples; sample++) {
  86520. for(channel = 0; channel < channels; channel++) {
  86521. a_word = signal[channel][sample];
  86522. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86523. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86524. *buf_++ = (FLAC__byte)a_word;
  86525. }
  86526. }
  86527. }
  86528. }
  86529. else if(bytes_per_sample == 1) {
  86530. if(channels == 2) {
  86531. for(sample = 0; sample < samples; sample++) {
  86532. a_word = signal[0][sample];
  86533. *buf_++ = (FLAC__byte)a_word;
  86534. a_word = signal[1][sample];
  86535. *buf_++ = (FLAC__byte)a_word;
  86536. }
  86537. }
  86538. else if(channels == 1) {
  86539. for(sample = 0; sample < samples; sample++) {
  86540. a_word = signal[0][sample];
  86541. *buf_++ = (FLAC__byte)a_word;
  86542. }
  86543. }
  86544. else {
  86545. for(sample = 0; sample < samples; sample++) {
  86546. for(channel = 0; channel < channels; channel++) {
  86547. a_word = signal[channel][sample];
  86548. *buf_++ = (FLAC__byte)a_word;
  86549. }
  86550. }
  86551. }
  86552. }
  86553. else { /* bytes_per_sample == 4, maybe optimize more later */
  86554. for(sample = 0; sample < samples; sample++) {
  86555. for(channel = 0; channel < channels; channel++) {
  86556. a_word = signal[channel][sample];
  86557. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86558. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86559. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86560. *buf_++ = (FLAC__byte)a_word;
  86561. }
  86562. }
  86563. }
  86564. }
  86565. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86566. {
  86567. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  86568. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  86569. return false;
  86570. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  86571. return false;
  86572. if(ctx->capacity < bytes_needed) {
  86573. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  86574. if(0 == tmp) {
  86575. free(ctx->internal_buf);
  86576. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  86577. return false;
  86578. }
  86579. ctx->internal_buf = tmp;
  86580. ctx->capacity = bytes_needed;
  86581. }
  86582. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  86583. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  86584. return true;
  86585. }
  86586. #endif
  86587. /*** End of inlined file: md5.c ***/
  86588. /*** Start of inlined file: memory.c ***/
  86589. /*** Start of inlined file: juce_FlacHeader.h ***/
  86590. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86591. // tasks..
  86592. #define VERSION "1.2.1"
  86593. #define FLAC__NO_DLL 1
  86594. #if JUCE_MSVC
  86595. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86596. #endif
  86597. #if JUCE_MAC
  86598. #define FLAC__SYS_DARWIN 1
  86599. #endif
  86600. /*** End of inlined file: juce_FlacHeader.h ***/
  86601. #if JUCE_USE_FLAC
  86602. #if HAVE_CONFIG_H
  86603. # include <config.h>
  86604. #endif
  86605. /*** Start of inlined file: memory.h ***/
  86606. #ifndef FLAC__PRIVATE__MEMORY_H
  86607. #define FLAC__PRIVATE__MEMORY_H
  86608. #ifdef HAVE_CONFIG_H
  86609. #include <config.h>
  86610. #endif
  86611. #include <stdlib.h> /* for size_t */
  86612. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  86613. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  86614. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  86615. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  86616. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  86617. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86618. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  86619. #endif
  86620. #endif
  86621. /*** End of inlined file: memory.h ***/
  86622. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  86623. {
  86624. void *x;
  86625. FLAC__ASSERT(0 != aligned_address);
  86626. #ifdef FLAC__ALIGN_MALLOC_DATA
  86627. x = safe_malloc_add_2op_(bytes, /*+*/31);
  86628. #ifdef SIZEOF_VOIDP
  86629. #if SIZEOF_VOIDP == 4
  86630. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86631. #elif SIZEOF_VOIDP == 8
  86632. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86633. #else
  86634. # error Unsupported sizeof(void*)
  86635. #endif
  86636. #else
  86637. if(sizeof(void*) == sizeof(unsigned))
  86638. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86639. else if(sizeof(void*) == sizeof(FLAC__uint64))
  86640. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86641. else
  86642. return 0;
  86643. #endif
  86644. #else
  86645. x = safe_malloc_(bytes);
  86646. *aligned_address = x;
  86647. #endif
  86648. return x;
  86649. }
  86650. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  86651. {
  86652. FLAC__int32 *pu; /* unaligned pointer */
  86653. union { /* union needed to comply with C99 pointer aliasing rules */
  86654. FLAC__int32 *pa; /* aligned pointer */
  86655. void *pv; /* aligned pointer alias */
  86656. } u;
  86657. FLAC__ASSERT(elements > 0);
  86658. FLAC__ASSERT(0 != unaligned_pointer);
  86659. FLAC__ASSERT(0 != aligned_pointer);
  86660. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86661. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  86662. if(0 == pu) {
  86663. return false;
  86664. }
  86665. else {
  86666. if(*unaligned_pointer != 0)
  86667. free(*unaligned_pointer);
  86668. *unaligned_pointer = pu;
  86669. *aligned_pointer = u.pa;
  86670. return true;
  86671. }
  86672. }
  86673. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  86674. {
  86675. FLAC__uint32 *pu; /* unaligned pointer */
  86676. union { /* union needed to comply with C99 pointer aliasing rules */
  86677. FLAC__uint32 *pa; /* aligned pointer */
  86678. void *pv; /* aligned pointer alias */
  86679. } u;
  86680. FLAC__ASSERT(elements > 0);
  86681. FLAC__ASSERT(0 != unaligned_pointer);
  86682. FLAC__ASSERT(0 != aligned_pointer);
  86683. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86684. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86685. if(0 == pu) {
  86686. return false;
  86687. }
  86688. else {
  86689. if(*unaligned_pointer != 0)
  86690. free(*unaligned_pointer);
  86691. *unaligned_pointer = pu;
  86692. *aligned_pointer = u.pa;
  86693. return true;
  86694. }
  86695. }
  86696. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  86697. {
  86698. FLAC__uint64 *pu; /* unaligned pointer */
  86699. union { /* union needed to comply with C99 pointer aliasing rules */
  86700. FLAC__uint64 *pa; /* aligned pointer */
  86701. void *pv; /* aligned pointer alias */
  86702. } u;
  86703. FLAC__ASSERT(elements > 0);
  86704. FLAC__ASSERT(0 != unaligned_pointer);
  86705. FLAC__ASSERT(0 != aligned_pointer);
  86706. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86707. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86708. if(0 == pu) {
  86709. return false;
  86710. }
  86711. else {
  86712. if(*unaligned_pointer != 0)
  86713. free(*unaligned_pointer);
  86714. *unaligned_pointer = pu;
  86715. *aligned_pointer = u.pa;
  86716. return true;
  86717. }
  86718. }
  86719. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  86720. {
  86721. unsigned *pu; /* unaligned pointer */
  86722. union { /* union needed to comply with C99 pointer aliasing rules */
  86723. unsigned *pa; /* aligned pointer */
  86724. void *pv; /* aligned pointer alias */
  86725. } u;
  86726. FLAC__ASSERT(elements > 0);
  86727. FLAC__ASSERT(0 != unaligned_pointer);
  86728. FLAC__ASSERT(0 != aligned_pointer);
  86729. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86730. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86731. if(0 == pu) {
  86732. return false;
  86733. }
  86734. else {
  86735. if(*unaligned_pointer != 0)
  86736. free(*unaligned_pointer);
  86737. *unaligned_pointer = pu;
  86738. *aligned_pointer = u.pa;
  86739. return true;
  86740. }
  86741. }
  86742. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86743. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  86744. {
  86745. FLAC__real *pu; /* unaligned pointer */
  86746. union { /* union needed to comply with C99 pointer aliasing rules */
  86747. FLAC__real *pa; /* aligned pointer */
  86748. void *pv; /* aligned pointer alias */
  86749. } u;
  86750. FLAC__ASSERT(elements > 0);
  86751. FLAC__ASSERT(0 != unaligned_pointer);
  86752. FLAC__ASSERT(0 != aligned_pointer);
  86753. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86754. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86755. if(0 == pu) {
  86756. return false;
  86757. }
  86758. else {
  86759. if(*unaligned_pointer != 0)
  86760. free(*unaligned_pointer);
  86761. *unaligned_pointer = pu;
  86762. *aligned_pointer = u.pa;
  86763. return true;
  86764. }
  86765. }
  86766. #endif
  86767. #endif
  86768. /*** End of inlined file: memory.c ***/
  86769. /*** Start of inlined file: stream_decoder.c ***/
  86770. /*** Start of inlined file: juce_FlacHeader.h ***/
  86771. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86772. // tasks..
  86773. #define VERSION "1.2.1"
  86774. #define FLAC__NO_DLL 1
  86775. #if JUCE_MSVC
  86776. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86777. #endif
  86778. #if JUCE_MAC
  86779. #define FLAC__SYS_DARWIN 1
  86780. #endif
  86781. /*** End of inlined file: juce_FlacHeader.h ***/
  86782. #if JUCE_USE_FLAC
  86783. #if HAVE_CONFIG_H
  86784. # include <config.h>
  86785. #endif
  86786. #if defined _MSC_VER || defined __MINGW32__
  86787. #include <io.h> /* for _setmode() */
  86788. #include <fcntl.h> /* for _O_BINARY */
  86789. #endif
  86790. #if defined __CYGWIN__ || defined __EMX__
  86791. #include <io.h> /* for setmode(), O_BINARY */
  86792. #include <fcntl.h> /* for _O_BINARY */
  86793. #endif
  86794. #include <stdio.h>
  86795. #include <stdlib.h> /* for malloc() */
  86796. #include <string.h> /* for memset/memcpy() */
  86797. #include <sys/stat.h> /* for stat() */
  86798. #include <sys/types.h> /* for off_t */
  86799. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  86800. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  86801. #define fseeko fseek
  86802. #define ftello ftell
  86803. #endif
  86804. #endif
  86805. /*** Start of inlined file: stream_decoder.h ***/
  86806. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  86807. #define FLAC__PROTECTED__STREAM_DECODER_H
  86808. #if FLAC__HAS_OGG
  86809. #include "include/private/ogg_decoder_aspect.h"
  86810. #endif
  86811. typedef struct FLAC__StreamDecoderProtected {
  86812. FLAC__StreamDecoderState state;
  86813. unsigned channels;
  86814. FLAC__ChannelAssignment channel_assignment;
  86815. unsigned bits_per_sample;
  86816. unsigned sample_rate; /* in Hz */
  86817. unsigned blocksize; /* in samples (per channel) */
  86818. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  86819. #if FLAC__HAS_OGG
  86820. FLAC__OggDecoderAspect ogg_decoder_aspect;
  86821. #endif
  86822. } FLAC__StreamDecoderProtected;
  86823. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  86824. #endif
  86825. /*** End of inlined file: stream_decoder.h ***/
  86826. #ifdef max
  86827. #undef max
  86828. #endif
  86829. #define max(a,b) ((a)>(b)?(a):(b))
  86830. #ifdef _MSC_VER
  86831. #define FLAC__U64L(x) x
  86832. #else
  86833. #define FLAC__U64L(x) x##LLU
  86834. #endif
  86835. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  86836. #if FLAC__HAS_OGG
  86837. 1
  86838. #else
  86839. 0
  86840. #endif
  86841. ;
  86842. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  86843. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  86844. static FILE *get_binary_stdin_(void);
  86845. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  86846. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  86847. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  86848. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  86849. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86850. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86851. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  86852. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  86853. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  86854. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  86855. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  86856. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  86857. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  86858. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86859. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86860. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86861. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86862. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86863. 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);
  86864. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  86865. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  86866. #if FLAC__HAS_OGG
  86867. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  86868. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86869. #endif
  86870. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  86871. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  86872. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86873. #if FLAC__HAS_OGG
  86874. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86875. #endif
  86876. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86877. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  86878. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  86879. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  86880. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  86881. typedef struct FLAC__StreamDecoderPrivate {
  86882. #if FLAC__HAS_OGG
  86883. FLAC__bool is_ogg;
  86884. #endif
  86885. FLAC__StreamDecoderReadCallback read_callback;
  86886. FLAC__StreamDecoderSeekCallback seek_callback;
  86887. FLAC__StreamDecoderTellCallback tell_callback;
  86888. FLAC__StreamDecoderLengthCallback length_callback;
  86889. FLAC__StreamDecoderEofCallback eof_callback;
  86890. FLAC__StreamDecoderWriteCallback write_callback;
  86891. FLAC__StreamDecoderMetadataCallback metadata_callback;
  86892. FLAC__StreamDecoderErrorCallback error_callback;
  86893. 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[]);
  86894. 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[]);
  86895. 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[]);
  86896. 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[]);
  86897. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  86898. void *client_data;
  86899. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  86900. FLAC__BitReader *input;
  86901. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  86902. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  86903. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  86904. unsigned output_capacity, output_channels;
  86905. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  86906. FLAC__uint64 samples_decoded;
  86907. FLAC__bool has_stream_info, has_seek_table;
  86908. FLAC__StreamMetadata stream_info;
  86909. FLAC__StreamMetadata seek_table;
  86910. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  86911. FLAC__byte *metadata_filter_ids;
  86912. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  86913. FLAC__Frame frame;
  86914. FLAC__bool cached; /* true if there is a byte in lookahead */
  86915. FLAC__CPUInfo cpuinfo;
  86916. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  86917. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  86918. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  86919. 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 */
  86920. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  86921. FLAC__bool is_seeking;
  86922. FLAC__MD5Context md5context;
  86923. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  86924. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  86925. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  86926. FLAC__uint64 target_sample;
  86927. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  86928. #if FLAC__HAS_OGG
  86929. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  86930. #endif
  86931. } FLAC__StreamDecoderPrivate;
  86932. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  86933. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  86934. "FLAC__STREAM_DECODER_READ_METADATA",
  86935. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  86936. "FLAC__STREAM_DECODER_READ_FRAME",
  86937. "FLAC__STREAM_DECODER_END_OF_STREAM",
  86938. "FLAC__STREAM_DECODER_OGG_ERROR",
  86939. "FLAC__STREAM_DECODER_SEEK_ERROR",
  86940. "FLAC__STREAM_DECODER_ABORTED",
  86941. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  86942. "FLAC__STREAM_DECODER_UNINITIALIZED"
  86943. };
  86944. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  86945. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  86946. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  86947. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  86948. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  86949. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  86950. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  86951. };
  86952. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  86953. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  86954. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  86955. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  86956. };
  86957. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  86958. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  86959. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  86960. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  86961. };
  86962. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  86963. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  86964. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  86965. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  86966. };
  86967. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  86968. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  86969. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  86970. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  86971. };
  86972. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  86973. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  86974. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  86975. };
  86976. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  86977. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  86978. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  86979. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  86980. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  86981. };
  86982. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  86983. {
  86984. FLAC__StreamDecoder *decoder;
  86985. unsigned i;
  86986. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  86987. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  86988. if(decoder == 0) {
  86989. return 0;
  86990. }
  86991. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  86992. if(decoder->protected_ == 0) {
  86993. free(decoder);
  86994. return 0;
  86995. }
  86996. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  86997. if(decoder->private_ == 0) {
  86998. free(decoder->protected_);
  86999. free(decoder);
  87000. return 0;
  87001. }
  87002. decoder->private_->input = FLAC__bitreader_new();
  87003. if(decoder->private_->input == 0) {
  87004. free(decoder->private_);
  87005. free(decoder->protected_);
  87006. free(decoder);
  87007. return 0;
  87008. }
  87009. decoder->private_->metadata_filter_ids_capacity = 16;
  87010. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87011. FLAC__bitreader_delete(decoder->private_->input);
  87012. free(decoder->private_);
  87013. free(decoder->protected_);
  87014. free(decoder);
  87015. return 0;
  87016. }
  87017. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87018. decoder->private_->output[i] = 0;
  87019. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87020. }
  87021. decoder->private_->output_capacity = 0;
  87022. decoder->private_->output_channels = 0;
  87023. decoder->private_->has_seek_table = false;
  87024. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87025. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87026. decoder->private_->file = 0;
  87027. set_defaults_dec(decoder);
  87028. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87029. return decoder;
  87030. }
  87031. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87032. {
  87033. unsigned i;
  87034. FLAC__ASSERT(0 != decoder);
  87035. FLAC__ASSERT(0 != decoder->protected_);
  87036. FLAC__ASSERT(0 != decoder->private_);
  87037. FLAC__ASSERT(0 != decoder->private_->input);
  87038. (void)FLAC__stream_decoder_finish(decoder);
  87039. if(0 != decoder->private_->metadata_filter_ids)
  87040. free(decoder->private_->metadata_filter_ids);
  87041. FLAC__bitreader_delete(decoder->private_->input);
  87042. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87043. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87044. free(decoder->private_);
  87045. free(decoder->protected_);
  87046. free(decoder);
  87047. }
  87048. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87049. FLAC__StreamDecoder *decoder,
  87050. FLAC__StreamDecoderReadCallback read_callback,
  87051. FLAC__StreamDecoderSeekCallback seek_callback,
  87052. FLAC__StreamDecoderTellCallback tell_callback,
  87053. FLAC__StreamDecoderLengthCallback length_callback,
  87054. FLAC__StreamDecoderEofCallback eof_callback,
  87055. FLAC__StreamDecoderWriteCallback write_callback,
  87056. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87057. FLAC__StreamDecoderErrorCallback error_callback,
  87058. void *client_data,
  87059. FLAC__bool is_ogg
  87060. )
  87061. {
  87062. FLAC__ASSERT(0 != decoder);
  87063. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87064. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87065. #if !FLAC__HAS_OGG
  87066. if(is_ogg)
  87067. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87068. #endif
  87069. if(
  87070. 0 == read_callback ||
  87071. 0 == write_callback ||
  87072. 0 == error_callback ||
  87073. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87074. )
  87075. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87076. #if FLAC__HAS_OGG
  87077. decoder->private_->is_ogg = is_ogg;
  87078. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87079. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87080. #endif
  87081. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87082. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87083. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87084. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87085. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87086. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87087. #ifndef FLAC__NO_ASM
  87088. if(decoder->private_->cpuinfo.use_asm) {
  87089. #ifdef FLAC__CPU_IA32
  87090. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87091. #ifdef FLAC__HAS_NASM
  87092. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87093. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87094. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87095. #endif
  87096. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87097. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87098. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87099. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87100. }
  87101. else {
  87102. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87103. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87104. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87105. }
  87106. #endif
  87107. #elif defined FLAC__CPU_PPC
  87108. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87109. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87110. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87111. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87112. }
  87113. #endif
  87114. }
  87115. #endif
  87116. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87117. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87118. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87119. }
  87120. decoder->private_->read_callback = read_callback;
  87121. decoder->private_->seek_callback = seek_callback;
  87122. decoder->private_->tell_callback = tell_callback;
  87123. decoder->private_->length_callback = length_callback;
  87124. decoder->private_->eof_callback = eof_callback;
  87125. decoder->private_->write_callback = write_callback;
  87126. decoder->private_->metadata_callback = metadata_callback;
  87127. decoder->private_->error_callback = error_callback;
  87128. decoder->private_->client_data = client_data;
  87129. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87130. decoder->private_->samples_decoded = 0;
  87131. decoder->private_->has_stream_info = false;
  87132. decoder->private_->cached = false;
  87133. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87134. decoder->private_->is_seeking = false;
  87135. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87136. if(!FLAC__stream_decoder_reset(decoder)) {
  87137. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87138. }
  87139. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87140. }
  87141. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87142. FLAC__StreamDecoder *decoder,
  87143. FLAC__StreamDecoderReadCallback read_callback,
  87144. FLAC__StreamDecoderSeekCallback seek_callback,
  87145. FLAC__StreamDecoderTellCallback tell_callback,
  87146. FLAC__StreamDecoderLengthCallback length_callback,
  87147. FLAC__StreamDecoderEofCallback eof_callback,
  87148. FLAC__StreamDecoderWriteCallback write_callback,
  87149. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87150. FLAC__StreamDecoderErrorCallback error_callback,
  87151. void *client_data
  87152. )
  87153. {
  87154. return init_stream_internal_dec(
  87155. decoder,
  87156. read_callback,
  87157. seek_callback,
  87158. tell_callback,
  87159. length_callback,
  87160. eof_callback,
  87161. write_callback,
  87162. metadata_callback,
  87163. error_callback,
  87164. client_data,
  87165. false
  87166. );
  87167. }
  87168. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87169. FLAC__StreamDecoder *decoder,
  87170. FLAC__StreamDecoderReadCallback read_callback,
  87171. FLAC__StreamDecoderSeekCallback seek_callback,
  87172. FLAC__StreamDecoderTellCallback tell_callback,
  87173. FLAC__StreamDecoderLengthCallback length_callback,
  87174. FLAC__StreamDecoderEofCallback eof_callback,
  87175. FLAC__StreamDecoderWriteCallback write_callback,
  87176. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87177. FLAC__StreamDecoderErrorCallback error_callback,
  87178. void *client_data
  87179. )
  87180. {
  87181. return init_stream_internal_dec(
  87182. decoder,
  87183. read_callback,
  87184. seek_callback,
  87185. tell_callback,
  87186. length_callback,
  87187. eof_callback,
  87188. write_callback,
  87189. metadata_callback,
  87190. error_callback,
  87191. client_data,
  87192. true
  87193. );
  87194. }
  87195. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87196. FLAC__StreamDecoder *decoder,
  87197. FILE *file,
  87198. FLAC__StreamDecoderWriteCallback write_callback,
  87199. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87200. FLAC__StreamDecoderErrorCallback error_callback,
  87201. void *client_data,
  87202. FLAC__bool is_ogg
  87203. )
  87204. {
  87205. FLAC__ASSERT(0 != decoder);
  87206. FLAC__ASSERT(0 != file);
  87207. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87208. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87209. if(0 == write_callback || 0 == error_callback)
  87210. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87211. if(file == stdin)
  87212. file = get_binary_stdin_(); /* just to be safe */
  87213. decoder->private_->file = file;
  87214. return init_stream_internal_dec(
  87215. decoder,
  87216. file_read_callback_dec,
  87217. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87218. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87219. decoder->private_->file == stdin? 0: file_length_callback_,
  87220. file_eof_callback_,
  87221. write_callback,
  87222. metadata_callback,
  87223. error_callback,
  87224. client_data,
  87225. is_ogg
  87226. );
  87227. }
  87228. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87229. FLAC__StreamDecoder *decoder,
  87230. FILE *file,
  87231. FLAC__StreamDecoderWriteCallback write_callback,
  87232. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87233. FLAC__StreamDecoderErrorCallback error_callback,
  87234. void *client_data
  87235. )
  87236. {
  87237. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87238. }
  87239. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87240. FLAC__StreamDecoder *decoder,
  87241. FILE *file,
  87242. FLAC__StreamDecoderWriteCallback write_callback,
  87243. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87244. FLAC__StreamDecoderErrorCallback error_callback,
  87245. void *client_data
  87246. )
  87247. {
  87248. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87249. }
  87250. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87251. FLAC__StreamDecoder *decoder,
  87252. const char *filename,
  87253. FLAC__StreamDecoderWriteCallback write_callback,
  87254. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87255. FLAC__StreamDecoderErrorCallback error_callback,
  87256. void *client_data,
  87257. FLAC__bool is_ogg
  87258. )
  87259. {
  87260. FILE *file;
  87261. FLAC__ASSERT(0 != decoder);
  87262. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87263. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87264. if(0 == write_callback || 0 == error_callback)
  87265. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87266. file = filename? fopen(filename, "rb") : stdin;
  87267. if(0 == file)
  87268. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87269. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87270. }
  87271. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87272. FLAC__StreamDecoder *decoder,
  87273. const char *filename,
  87274. FLAC__StreamDecoderWriteCallback write_callback,
  87275. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87276. FLAC__StreamDecoderErrorCallback error_callback,
  87277. void *client_data
  87278. )
  87279. {
  87280. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87281. }
  87282. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87283. FLAC__StreamDecoder *decoder,
  87284. const char *filename,
  87285. FLAC__StreamDecoderWriteCallback write_callback,
  87286. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87287. FLAC__StreamDecoderErrorCallback error_callback,
  87288. void *client_data
  87289. )
  87290. {
  87291. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87292. }
  87293. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87294. {
  87295. FLAC__bool md5_failed = false;
  87296. unsigned i;
  87297. FLAC__ASSERT(0 != decoder);
  87298. FLAC__ASSERT(0 != decoder->private_);
  87299. FLAC__ASSERT(0 != decoder->protected_);
  87300. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87301. return true;
  87302. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87303. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87304. free(decoder->private_->seek_table.data.seek_table.points);
  87305. decoder->private_->seek_table.data.seek_table.points = 0;
  87306. decoder->private_->has_seek_table = false;
  87307. }
  87308. FLAC__bitreader_free(decoder->private_->input);
  87309. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87310. if(0 != decoder->private_->output[i]) {
  87311. free(decoder->private_->output[i]-4);
  87312. decoder->private_->output[i] = 0;
  87313. }
  87314. if(0 != decoder->private_->residual_unaligned[i]) {
  87315. free(decoder->private_->residual_unaligned[i]);
  87316. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87317. }
  87318. }
  87319. decoder->private_->output_capacity = 0;
  87320. decoder->private_->output_channels = 0;
  87321. #if FLAC__HAS_OGG
  87322. if(decoder->private_->is_ogg)
  87323. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87324. #endif
  87325. if(0 != decoder->private_->file) {
  87326. if(decoder->private_->file != stdin)
  87327. fclose(decoder->private_->file);
  87328. decoder->private_->file = 0;
  87329. }
  87330. if(decoder->private_->do_md5_checking) {
  87331. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87332. md5_failed = true;
  87333. }
  87334. decoder->private_->is_seeking = false;
  87335. set_defaults_dec(decoder);
  87336. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87337. return !md5_failed;
  87338. }
  87339. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87340. {
  87341. FLAC__ASSERT(0 != decoder);
  87342. FLAC__ASSERT(0 != decoder->private_);
  87343. FLAC__ASSERT(0 != decoder->protected_);
  87344. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87345. return false;
  87346. #if FLAC__HAS_OGG
  87347. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87348. return true;
  87349. #else
  87350. (void)value;
  87351. return false;
  87352. #endif
  87353. }
  87354. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87355. {
  87356. FLAC__ASSERT(0 != decoder);
  87357. FLAC__ASSERT(0 != decoder->protected_);
  87358. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87359. return false;
  87360. decoder->protected_->md5_checking = value;
  87361. return true;
  87362. }
  87363. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87364. {
  87365. FLAC__ASSERT(0 != decoder);
  87366. FLAC__ASSERT(0 != decoder->private_);
  87367. FLAC__ASSERT(0 != decoder->protected_);
  87368. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87369. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87370. return false;
  87371. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87372. return false;
  87373. decoder->private_->metadata_filter[type] = true;
  87374. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87375. decoder->private_->metadata_filter_ids_count = 0;
  87376. return true;
  87377. }
  87378. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87379. {
  87380. FLAC__ASSERT(0 != decoder);
  87381. FLAC__ASSERT(0 != decoder->private_);
  87382. FLAC__ASSERT(0 != decoder->protected_);
  87383. FLAC__ASSERT(0 != id);
  87384. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87385. return false;
  87386. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87387. return true;
  87388. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87389. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87390. 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))) {
  87391. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87392. return false;
  87393. }
  87394. decoder->private_->metadata_filter_ids_capacity *= 2;
  87395. }
  87396. 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));
  87397. decoder->private_->metadata_filter_ids_count++;
  87398. return true;
  87399. }
  87400. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87401. {
  87402. unsigned i;
  87403. FLAC__ASSERT(0 != decoder);
  87404. FLAC__ASSERT(0 != decoder->private_);
  87405. FLAC__ASSERT(0 != decoder->protected_);
  87406. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87407. return false;
  87408. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87409. decoder->private_->metadata_filter[i] = true;
  87410. decoder->private_->metadata_filter_ids_count = 0;
  87411. return true;
  87412. }
  87413. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87414. {
  87415. FLAC__ASSERT(0 != decoder);
  87416. FLAC__ASSERT(0 != decoder->private_);
  87417. FLAC__ASSERT(0 != decoder->protected_);
  87418. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87419. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87420. return false;
  87421. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87422. return false;
  87423. decoder->private_->metadata_filter[type] = false;
  87424. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87425. decoder->private_->metadata_filter_ids_count = 0;
  87426. return true;
  87427. }
  87428. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87429. {
  87430. FLAC__ASSERT(0 != decoder);
  87431. FLAC__ASSERT(0 != decoder->private_);
  87432. FLAC__ASSERT(0 != decoder->protected_);
  87433. FLAC__ASSERT(0 != id);
  87434. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87435. return false;
  87436. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87437. return true;
  87438. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87439. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87440. 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))) {
  87441. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87442. return false;
  87443. }
  87444. decoder->private_->metadata_filter_ids_capacity *= 2;
  87445. }
  87446. 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));
  87447. decoder->private_->metadata_filter_ids_count++;
  87448. return true;
  87449. }
  87450. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87451. {
  87452. FLAC__ASSERT(0 != decoder);
  87453. FLAC__ASSERT(0 != decoder->private_);
  87454. FLAC__ASSERT(0 != decoder->protected_);
  87455. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87456. return false;
  87457. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87458. decoder->private_->metadata_filter_ids_count = 0;
  87459. return true;
  87460. }
  87461. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87462. {
  87463. FLAC__ASSERT(0 != decoder);
  87464. FLAC__ASSERT(0 != decoder->protected_);
  87465. return decoder->protected_->state;
  87466. }
  87467. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87468. {
  87469. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87470. }
  87471. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87472. {
  87473. FLAC__ASSERT(0 != decoder);
  87474. FLAC__ASSERT(0 != decoder->protected_);
  87475. return decoder->protected_->md5_checking;
  87476. }
  87477. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87478. {
  87479. FLAC__ASSERT(0 != decoder);
  87480. FLAC__ASSERT(0 != decoder->protected_);
  87481. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87482. }
  87483. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87484. {
  87485. FLAC__ASSERT(0 != decoder);
  87486. FLAC__ASSERT(0 != decoder->protected_);
  87487. return decoder->protected_->channels;
  87488. }
  87489. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87490. {
  87491. FLAC__ASSERT(0 != decoder);
  87492. FLAC__ASSERT(0 != decoder->protected_);
  87493. return decoder->protected_->channel_assignment;
  87494. }
  87495. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87496. {
  87497. FLAC__ASSERT(0 != decoder);
  87498. FLAC__ASSERT(0 != decoder->protected_);
  87499. return decoder->protected_->bits_per_sample;
  87500. }
  87501. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87502. {
  87503. FLAC__ASSERT(0 != decoder);
  87504. FLAC__ASSERT(0 != decoder->protected_);
  87505. return decoder->protected_->sample_rate;
  87506. }
  87507. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87508. {
  87509. FLAC__ASSERT(0 != decoder);
  87510. FLAC__ASSERT(0 != decoder->protected_);
  87511. return decoder->protected_->blocksize;
  87512. }
  87513. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87514. {
  87515. FLAC__ASSERT(0 != decoder);
  87516. FLAC__ASSERT(0 != decoder->private_);
  87517. FLAC__ASSERT(0 != position);
  87518. #if FLAC__HAS_OGG
  87519. if(decoder->private_->is_ogg)
  87520. return false;
  87521. #endif
  87522. if(0 == decoder->private_->tell_callback)
  87523. return false;
  87524. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  87525. return false;
  87526. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  87527. return false;
  87528. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  87529. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  87530. return true;
  87531. }
  87532. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  87533. {
  87534. FLAC__ASSERT(0 != decoder);
  87535. FLAC__ASSERT(0 != decoder->private_);
  87536. FLAC__ASSERT(0 != decoder->protected_);
  87537. decoder->private_->samples_decoded = 0;
  87538. decoder->private_->do_md5_checking = false;
  87539. #if FLAC__HAS_OGG
  87540. if(decoder->private_->is_ogg)
  87541. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  87542. #endif
  87543. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  87544. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87545. return false;
  87546. }
  87547. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87548. return true;
  87549. }
  87550. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  87551. {
  87552. FLAC__ASSERT(0 != decoder);
  87553. FLAC__ASSERT(0 != decoder->private_);
  87554. FLAC__ASSERT(0 != decoder->protected_);
  87555. if(!FLAC__stream_decoder_flush(decoder)) {
  87556. return false;
  87557. }
  87558. #if FLAC__HAS_OGG
  87559. if(decoder->private_->is_ogg)
  87560. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  87561. #endif
  87562. if(!decoder->private_->internal_reset_hack) {
  87563. if(decoder->private_->file == stdin)
  87564. return false; /* can't rewind stdin, reset fails */
  87565. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  87566. return false; /* seekable and seek fails, reset fails */
  87567. }
  87568. else
  87569. decoder->private_->internal_reset_hack = false;
  87570. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  87571. decoder->private_->has_stream_info = false;
  87572. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87573. free(decoder->private_->seek_table.data.seek_table.points);
  87574. decoder->private_->seek_table.data.seek_table.points = 0;
  87575. decoder->private_->has_seek_table = false;
  87576. }
  87577. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87578. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87579. FLAC__MD5Init(&decoder->private_->md5context);
  87580. decoder->private_->first_frame_offset = 0;
  87581. decoder->private_->unparseable_frame_count = 0;
  87582. return true;
  87583. }
  87584. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  87585. {
  87586. FLAC__bool got_a_frame;
  87587. FLAC__ASSERT(0 != decoder);
  87588. FLAC__ASSERT(0 != decoder->protected_);
  87589. while(1) {
  87590. switch(decoder->protected_->state) {
  87591. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87592. if(!find_metadata_(decoder))
  87593. return false; /* above function sets the status for us */
  87594. break;
  87595. case FLAC__STREAM_DECODER_READ_METADATA:
  87596. if(!read_metadata_(decoder))
  87597. return false; /* above function sets the status for us */
  87598. else
  87599. return true;
  87600. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87601. if(!frame_sync_(decoder))
  87602. return true; /* above function sets the status for us */
  87603. break;
  87604. case FLAC__STREAM_DECODER_READ_FRAME:
  87605. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  87606. return false; /* above function sets the status for us */
  87607. if(got_a_frame)
  87608. return true; /* above function sets the status for us */
  87609. break;
  87610. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87611. case FLAC__STREAM_DECODER_ABORTED:
  87612. return true;
  87613. default:
  87614. FLAC__ASSERT(0);
  87615. return false;
  87616. }
  87617. }
  87618. }
  87619. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  87620. {
  87621. FLAC__ASSERT(0 != decoder);
  87622. FLAC__ASSERT(0 != decoder->protected_);
  87623. while(1) {
  87624. switch(decoder->protected_->state) {
  87625. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87626. if(!find_metadata_(decoder))
  87627. return false; /* above function sets the status for us */
  87628. break;
  87629. case FLAC__STREAM_DECODER_READ_METADATA:
  87630. if(!read_metadata_(decoder))
  87631. return false; /* above function sets the status for us */
  87632. break;
  87633. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87634. case FLAC__STREAM_DECODER_READ_FRAME:
  87635. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87636. case FLAC__STREAM_DECODER_ABORTED:
  87637. return true;
  87638. default:
  87639. FLAC__ASSERT(0);
  87640. return false;
  87641. }
  87642. }
  87643. }
  87644. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  87645. {
  87646. FLAC__bool dummy;
  87647. FLAC__ASSERT(0 != decoder);
  87648. FLAC__ASSERT(0 != decoder->protected_);
  87649. while(1) {
  87650. switch(decoder->protected_->state) {
  87651. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87652. if(!find_metadata_(decoder))
  87653. return false; /* above function sets the status for us */
  87654. break;
  87655. case FLAC__STREAM_DECODER_READ_METADATA:
  87656. if(!read_metadata_(decoder))
  87657. return false; /* above function sets the status for us */
  87658. break;
  87659. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87660. if(!frame_sync_(decoder))
  87661. return true; /* above function sets the status for us */
  87662. break;
  87663. case FLAC__STREAM_DECODER_READ_FRAME:
  87664. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  87665. return false; /* above function sets the status for us */
  87666. break;
  87667. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87668. case FLAC__STREAM_DECODER_ABORTED:
  87669. return true;
  87670. default:
  87671. FLAC__ASSERT(0);
  87672. return false;
  87673. }
  87674. }
  87675. }
  87676. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  87677. {
  87678. FLAC__bool got_a_frame;
  87679. FLAC__ASSERT(0 != decoder);
  87680. FLAC__ASSERT(0 != decoder->protected_);
  87681. while(1) {
  87682. switch(decoder->protected_->state) {
  87683. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87684. case FLAC__STREAM_DECODER_READ_METADATA:
  87685. return false; /* above function sets the status for us */
  87686. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87687. if(!frame_sync_(decoder))
  87688. return true; /* above function sets the status for us */
  87689. break;
  87690. case FLAC__STREAM_DECODER_READ_FRAME:
  87691. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  87692. return false; /* above function sets the status for us */
  87693. if(got_a_frame)
  87694. return true; /* above function sets the status for us */
  87695. break;
  87696. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87697. case FLAC__STREAM_DECODER_ABORTED:
  87698. return true;
  87699. default:
  87700. FLAC__ASSERT(0);
  87701. return false;
  87702. }
  87703. }
  87704. }
  87705. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  87706. {
  87707. FLAC__uint64 length;
  87708. FLAC__ASSERT(0 != decoder);
  87709. if(
  87710. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  87711. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  87712. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  87713. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  87714. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  87715. )
  87716. return false;
  87717. if(0 == decoder->private_->seek_callback)
  87718. return false;
  87719. FLAC__ASSERT(decoder->private_->seek_callback);
  87720. FLAC__ASSERT(decoder->private_->tell_callback);
  87721. FLAC__ASSERT(decoder->private_->length_callback);
  87722. FLAC__ASSERT(decoder->private_->eof_callback);
  87723. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  87724. return false;
  87725. decoder->private_->is_seeking = true;
  87726. decoder->private_->do_md5_checking = false;
  87727. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  87728. decoder->private_->is_seeking = false;
  87729. return false;
  87730. }
  87731. if(
  87732. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  87733. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  87734. ) {
  87735. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  87736. decoder->private_->is_seeking = false;
  87737. return false;
  87738. }
  87739. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  87740. decoder->private_->is_seeking = false;
  87741. return false;
  87742. }
  87743. }
  87744. {
  87745. const FLAC__bool ok =
  87746. #if FLAC__HAS_OGG
  87747. decoder->private_->is_ogg?
  87748. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  87749. #endif
  87750. seek_to_absolute_sample_(decoder, length, sample)
  87751. ;
  87752. decoder->private_->is_seeking = false;
  87753. return ok;
  87754. }
  87755. }
  87756. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  87757. {
  87758. FLAC__ASSERT(0 != decoder);
  87759. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87760. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  87761. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  87762. }
  87763. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  87764. {
  87765. #if FLAC__HAS_OGG
  87766. decoder->private_->is_ogg = false;
  87767. #endif
  87768. decoder->private_->read_callback = 0;
  87769. decoder->private_->seek_callback = 0;
  87770. decoder->private_->tell_callback = 0;
  87771. decoder->private_->length_callback = 0;
  87772. decoder->private_->eof_callback = 0;
  87773. decoder->private_->write_callback = 0;
  87774. decoder->private_->metadata_callback = 0;
  87775. decoder->private_->error_callback = 0;
  87776. decoder->private_->client_data = 0;
  87777. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87778. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  87779. decoder->private_->metadata_filter_ids_count = 0;
  87780. decoder->protected_->md5_checking = false;
  87781. #if FLAC__HAS_OGG
  87782. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  87783. #endif
  87784. }
  87785. FILE *get_binary_stdin_(void)
  87786. {
  87787. #if defined _MSC_VER || defined __MINGW32__
  87788. _setmode(_fileno(stdin), _O_BINARY);
  87789. #elif defined __CYGWIN__
  87790. setmode(_fileno(stdin), _O_BINARY);
  87791. #elif defined __EMX__
  87792. setmode(fileno(stdin), O_BINARY);
  87793. #endif
  87794. return stdin;
  87795. }
  87796. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  87797. {
  87798. unsigned i;
  87799. FLAC__int32 *tmp;
  87800. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  87801. return true;
  87802. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87803. if(0 != decoder->private_->output[i]) {
  87804. free(decoder->private_->output[i]-4);
  87805. decoder->private_->output[i] = 0;
  87806. }
  87807. if(0 != decoder->private_->residual_unaligned[i]) {
  87808. free(decoder->private_->residual_unaligned[i]);
  87809. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87810. }
  87811. }
  87812. for(i = 0; i < channels; i++) {
  87813. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  87814. if(tmp == 0) {
  87815. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87816. return false;
  87817. }
  87818. memset(tmp, 0, sizeof(FLAC__int32)*4);
  87819. decoder->private_->output[i] = tmp + 4;
  87820. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  87821. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87822. return false;
  87823. }
  87824. }
  87825. decoder->private_->output_capacity = size;
  87826. decoder->private_->output_channels = channels;
  87827. return true;
  87828. }
  87829. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  87830. {
  87831. size_t i;
  87832. FLAC__ASSERT(0 != decoder);
  87833. FLAC__ASSERT(0 != decoder->private_);
  87834. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  87835. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  87836. return true;
  87837. return false;
  87838. }
  87839. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  87840. {
  87841. FLAC__uint32 x;
  87842. unsigned i, id_;
  87843. FLAC__bool first = true;
  87844. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87845. for(i = id_ = 0; i < 4; ) {
  87846. if(decoder->private_->cached) {
  87847. x = (FLAC__uint32)decoder->private_->lookahead;
  87848. decoder->private_->cached = false;
  87849. }
  87850. else {
  87851. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87852. return false; /* read_callback_ sets the state for us */
  87853. }
  87854. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  87855. first = true;
  87856. i++;
  87857. id_ = 0;
  87858. continue;
  87859. }
  87860. if(x == ID3V2_TAG_[id_]) {
  87861. id_++;
  87862. i = 0;
  87863. if(id_ == 3) {
  87864. if(!skip_id3v2_tag_(decoder))
  87865. return false; /* skip_id3v2_tag_ sets the state for us */
  87866. }
  87867. continue;
  87868. }
  87869. id_ = 0;
  87870. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87871. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  87872. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87873. return false; /* read_callback_ sets the state for us */
  87874. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87875. decoder->private_->lookahead = (FLAC__byte)x;
  87876. decoder->private_->cached = true;
  87877. }
  87878. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  87879. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  87880. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  87881. return true;
  87882. }
  87883. }
  87884. i = 0;
  87885. if(first) {
  87886. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  87887. first = false;
  87888. }
  87889. }
  87890. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  87891. return true;
  87892. }
  87893. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  87894. {
  87895. FLAC__bool is_last;
  87896. FLAC__uint32 i, x, type, length;
  87897. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87898. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  87899. return false; /* read_callback_ sets the state for us */
  87900. is_last = x? true : false;
  87901. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  87902. return false; /* read_callback_ sets the state for us */
  87903. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  87904. return false; /* read_callback_ sets the state for us */
  87905. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  87906. if(!read_metadata_streaminfo_(decoder, is_last, length))
  87907. return false;
  87908. decoder->private_->has_stream_info = true;
  87909. 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))
  87910. decoder->private_->do_md5_checking = false;
  87911. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  87912. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  87913. }
  87914. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  87915. if(!read_metadata_seektable_(decoder, is_last, length))
  87916. return false;
  87917. decoder->private_->has_seek_table = true;
  87918. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  87919. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  87920. }
  87921. else {
  87922. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  87923. unsigned real_length = length;
  87924. FLAC__StreamMetadata block;
  87925. block.is_last = is_last;
  87926. block.type = (FLAC__MetadataType)type;
  87927. block.length = length;
  87928. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  87929. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  87930. return false; /* read_callback_ sets the state for us */
  87931. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  87932. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  87933. return false;
  87934. }
  87935. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  87936. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  87937. skip_it = !skip_it;
  87938. }
  87939. if(skip_it) {
  87940. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87941. return false; /* read_callback_ sets the state for us */
  87942. }
  87943. else {
  87944. switch(type) {
  87945. case FLAC__METADATA_TYPE_PADDING:
  87946. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87947. return false; /* read_callback_ sets the state for us */
  87948. break;
  87949. case FLAC__METADATA_TYPE_APPLICATION:
  87950. if(real_length > 0) {
  87951. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  87952. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87953. return false;
  87954. }
  87955. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  87956. return false; /* read_callback_ sets the state for us */
  87957. }
  87958. else
  87959. block.data.application.data = 0;
  87960. break;
  87961. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  87962. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  87963. return false;
  87964. break;
  87965. case FLAC__METADATA_TYPE_CUESHEET:
  87966. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  87967. return false;
  87968. break;
  87969. case FLAC__METADATA_TYPE_PICTURE:
  87970. if(!read_metadata_picture_(decoder, &block.data.picture))
  87971. return false;
  87972. break;
  87973. case FLAC__METADATA_TYPE_STREAMINFO:
  87974. case FLAC__METADATA_TYPE_SEEKTABLE:
  87975. FLAC__ASSERT(0);
  87976. break;
  87977. default:
  87978. if(real_length > 0) {
  87979. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  87980. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87981. return false;
  87982. }
  87983. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  87984. return false; /* read_callback_ sets the state for us */
  87985. }
  87986. else
  87987. block.data.unknown.data = 0;
  87988. break;
  87989. }
  87990. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  87991. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  87992. switch(type) {
  87993. case FLAC__METADATA_TYPE_PADDING:
  87994. break;
  87995. case FLAC__METADATA_TYPE_APPLICATION:
  87996. if(0 != block.data.application.data)
  87997. free(block.data.application.data);
  87998. break;
  87999. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88000. if(0 != block.data.vorbis_comment.vendor_string.entry)
  88001. free(block.data.vorbis_comment.vendor_string.entry);
  88002. if(block.data.vorbis_comment.num_comments > 0)
  88003. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  88004. if(0 != block.data.vorbis_comment.comments[i].entry)
  88005. free(block.data.vorbis_comment.comments[i].entry);
  88006. if(0 != block.data.vorbis_comment.comments)
  88007. free(block.data.vorbis_comment.comments);
  88008. break;
  88009. case FLAC__METADATA_TYPE_CUESHEET:
  88010. if(block.data.cue_sheet.num_tracks > 0)
  88011. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88012. if(0 != block.data.cue_sheet.tracks[i].indices)
  88013. free(block.data.cue_sheet.tracks[i].indices);
  88014. if(0 != block.data.cue_sheet.tracks)
  88015. free(block.data.cue_sheet.tracks);
  88016. break;
  88017. case FLAC__METADATA_TYPE_PICTURE:
  88018. if(0 != block.data.picture.mime_type)
  88019. free(block.data.picture.mime_type);
  88020. if(0 != block.data.picture.description)
  88021. free(block.data.picture.description);
  88022. if(0 != block.data.picture.data)
  88023. free(block.data.picture.data);
  88024. break;
  88025. case FLAC__METADATA_TYPE_STREAMINFO:
  88026. case FLAC__METADATA_TYPE_SEEKTABLE:
  88027. FLAC__ASSERT(0);
  88028. default:
  88029. if(0 != block.data.unknown.data)
  88030. free(block.data.unknown.data);
  88031. break;
  88032. }
  88033. }
  88034. }
  88035. if(is_last) {
  88036. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88037. decoder->private_->first_frame_offset = 0;
  88038. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88039. }
  88040. return true;
  88041. }
  88042. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88043. {
  88044. FLAC__uint32 x;
  88045. unsigned bits, used_bits = 0;
  88046. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88047. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88048. decoder->private_->stream_info.is_last = is_last;
  88049. decoder->private_->stream_info.length = length;
  88050. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88051. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88052. return false; /* read_callback_ sets the state for us */
  88053. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88054. used_bits += bits;
  88055. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88056. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88057. return false; /* read_callback_ sets the state for us */
  88058. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88059. used_bits += bits;
  88060. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88061. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88062. return false; /* read_callback_ sets the state for us */
  88063. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88064. used_bits += bits;
  88065. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88066. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88067. return false; /* read_callback_ sets the state for us */
  88068. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88069. used_bits += bits;
  88070. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88071. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88072. return false; /* read_callback_ sets the state for us */
  88073. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88074. used_bits += bits;
  88075. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88076. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88077. return false; /* read_callback_ sets the state for us */
  88078. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88079. used_bits += bits;
  88080. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88081. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88082. return false; /* read_callback_ sets the state for us */
  88083. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88084. used_bits += bits;
  88085. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88086. 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))
  88087. return false; /* read_callback_ sets the state for us */
  88088. used_bits += bits;
  88089. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88090. return false; /* read_callback_ sets the state for us */
  88091. used_bits += 16*8;
  88092. FLAC__ASSERT(used_bits % 8 == 0);
  88093. length -= (used_bits / 8);
  88094. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88095. return false; /* read_callback_ sets the state for us */
  88096. return true;
  88097. }
  88098. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88099. {
  88100. FLAC__uint32 i, x;
  88101. FLAC__uint64 xx;
  88102. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88103. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88104. decoder->private_->seek_table.is_last = is_last;
  88105. decoder->private_->seek_table.length = length;
  88106. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88107. 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)))) {
  88108. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88109. return false;
  88110. }
  88111. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88112. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88113. return false; /* read_callback_ sets the state for us */
  88114. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88115. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88116. return false; /* read_callback_ sets the state for us */
  88117. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88118. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88119. return false; /* read_callback_ sets the state for us */
  88120. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88121. }
  88122. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88123. if(length > 0) {
  88124. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88125. return false; /* read_callback_ sets the state for us */
  88126. }
  88127. return true;
  88128. }
  88129. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88130. {
  88131. FLAC__uint32 i;
  88132. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88133. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88134. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88135. return false; /* read_callback_ sets the state for us */
  88136. if(obj->vendor_string.length > 0) {
  88137. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88138. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88139. return false;
  88140. }
  88141. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88142. return false; /* read_callback_ sets the state for us */
  88143. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88144. }
  88145. else
  88146. obj->vendor_string.entry = 0;
  88147. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88148. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88149. return false; /* read_callback_ sets the state for us */
  88150. if(obj->num_comments > 0) {
  88151. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88152. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88153. return false;
  88154. }
  88155. for(i = 0; i < obj->num_comments; i++) {
  88156. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88157. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88158. return false; /* read_callback_ sets the state for us */
  88159. if(obj->comments[i].length > 0) {
  88160. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88161. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88162. return false;
  88163. }
  88164. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88165. return false; /* read_callback_ sets the state for us */
  88166. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88167. }
  88168. else
  88169. obj->comments[i].entry = 0;
  88170. }
  88171. }
  88172. else {
  88173. obj->comments = 0;
  88174. }
  88175. return true;
  88176. }
  88177. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88178. {
  88179. FLAC__uint32 i, j, x;
  88180. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88181. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88182. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88183. 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))
  88184. return false; /* read_callback_ sets the state for us */
  88185. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88186. return false; /* read_callback_ sets the state for us */
  88187. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88188. return false; /* read_callback_ sets the state for us */
  88189. obj->is_cd = x? true : false;
  88190. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88191. return false; /* read_callback_ sets the state for us */
  88192. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88193. return false; /* read_callback_ sets the state for us */
  88194. obj->num_tracks = x;
  88195. if(obj->num_tracks > 0) {
  88196. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88197. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88198. return false;
  88199. }
  88200. for(i = 0; i < obj->num_tracks; i++) {
  88201. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88202. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88203. return false; /* read_callback_ sets the state for us */
  88204. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88205. return false; /* read_callback_ sets the state for us */
  88206. track->number = (FLAC__byte)x;
  88207. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88208. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88209. return false; /* read_callback_ sets the state for us */
  88210. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88211. return false; /* read_callback_ sets the state for us */
  88212. track->type = x;
  88213. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88214. return false; /* read_callback_ sets the state for us */
  88215. track->pre_emphasis = x;
  88216. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88217. return false; /* read_callback_ sets the state for us */
  88218. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88219. return false; /* read_callback_ sets the state for us */
  88220. track->num_indices = (FLAC__byte)x;
  88221. if(track->num_indices > 0) {
  88222. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88223. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88224. return false;
  88225. }
  88226. for(j = 0; j < track->num_indices; j++) {
  88227. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88228. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88229. return false; /* read_callback_ sets the state for us */
  88230. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88231. return false; /* read_callback_ sets the state for us */
  88232. index->number = (FLAC__byte)x;
  88233. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88234. return false; /* read_callback_ sets the state for us */
  88235. }
  88236. }
  88237. }
  88238. }
  88239. return true;
  88240. }
  88241. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88242. {
  88243. FLAC__uint32 x;
  88244. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88245. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88246. return false; /* read_callback_ sets the state for us */
  88247. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88248. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88249. return false; /* read_callback_ sets the state for us */
  88250. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88251. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88252. return false;
  88253. }
  88254. if(x > 0) {
  88255. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88256. return false; /* read_callback_ sets the state for us */
  88257. }
  88258. obj->mime_type[x] = '\0';
  88259. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88260. return false; /* read_callback_ sets the state for us */
  88261. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88262. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88263. return false;
  88264. }
  88265. if(x > 0) {
  88266. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88267. return false; /* read_callback_ sets the state for us */
  88268. }
  88269. obj->description[x] = '\0';
  88270. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88271. return false; /* read_callback_ sets the state for us */
  88272. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88273. return false; /* read_callback_ sets the state for us */
  88274. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88275. return false; /* read_callback_ sets the state for us */
  88276. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88277. return false; /* read_callback_ sets the state for us */
  88278. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88279. return false; /* read_callback_ sets the state for us */
  88280. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88281. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88282. return false;
  88283. }
  88284. if(obj->data_length > 0) {
  88285. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88286. return false; /* read_callback_ sets the state for us */
  88287. }
  88288. return true;
  88289. }
  88290. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88291. {
  88292. FLAC__uint32 x;
  88293. unsigned i, skip;
  88294. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88295. return false; /* read_callback_ sets the state for us */
  88296. skip = 0;
  88297. for(i = 0; i < 4; i++) {
  88298. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88299. return false; /* read_callback_ sets the state for us */
  88300. skip <<= 7;
  88301. skip |= (x & 0x7f);
  88302. }
  88303. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88304. return false; /* read_callback_ sets the state for us */
  88305. return true;
  88306. }
  88307. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88308. {
  88309. FLAC__uint32 x;
  88310. FLAC__bool first = true;
  88311. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88312. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88313. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88314. return true;
  88315. }
  88316. }
  88317. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88318. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88319. return false; /* read_callback_ sets the state for us */
  88320. }
  88321. while(1) {
  88322. if(decoder->private_->cached) {
  88323. x = (FLAC__uint32)decoder->private_->lookahead;
  88324. decoder->private_->cached = false;
  88325. }
  88326. else {
  88327. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88328. return false; /* read_callback_ sets the state for us */
  88329. }
  88330. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88331. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88332. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88333. return false; /* read_callback_ sets the state for us */
  88334. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88335. decoder->private_->lookahead = (FLAC__byte)x;
  88336. decoder->private_->cached = true;
  88337. }
  88338. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88339. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88340. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88341. return true;
  88342. }
  88343. }
  88344. if(first) {
  88345. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88346. first = false;
  88347. }
  88348. }
  88349. return true;
  88350. }
  88351. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88352. {
  88353. unsigned channel;
  88354. unsigned i;
  88355. FLAC__int32 mid, side;
  88356. unsigned frame_crc; /* the one we calculate from the input stream */
  88357. FLAC__uint32 x;
  88358. *got_a_frame = false;
  88359. frame_crc = 0;
  88360. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88361. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88362. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88363. if(!read_frame_header_(decoder))
  88364. return false;
  88365. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88366. return true;
  88367. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88368. return false;
  88369. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88370. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88371. switch(decoder->private_->frame.header.channel_assignment) {
  88372. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88373. break;
  88374. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88375. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88376. if(channel == 1)
  88377. bps++;
  88378. break;
  88379. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88380. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88381. if(channel == 0)
  88382. bps++;
  88383. break;
  88384. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88385. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88386. if(channel == 1)
  88387. bps++;
  88388. break;
  88389. default:
  88390. FLAC__ASSERT(0);
  88391. }
  88392. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88393. return false;
  88394. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88395. return true;
  88396. }
  88397. if(!read_zero_padding_(decoder))
  88398. return false;
  88399. 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) */
  88400. return true;
  88401. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88402. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88403. return false; /* read_callback_ sets the state for us */
  88404. if(frame_crc == x) {
  88405. if(do_full_decode) {
  88406. switch(decoder->private_->frame.header.channel_assignment) {
  88407. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88408. break;
  88409. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88410. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88411. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88412. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88413. break;
  88414. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88415. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88416. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88417. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88418. break;
  88419. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88420. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88421. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88422. #if 1
  88423. mid = decoder->private_->output[0][i];
  88424. side = decoder->private_->output[1][i];
  88425. mid <<= 1;
  88426. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88427. decoder->private_->output[0][i] = (mid + side) >> 1;
  88428. decoder->private_->output[1][i] = (mid - side) >> 1;
  88429. #else
  88430. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88431. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88432. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88433. #endif
  88434. }
  88435. break;
  88436. default:
  88437. FLAC__ASSERT(0);
  88438. break;
  88439. }
  88440. }
  88441. }
  88442. else {
  88443. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88444. if(do_full_decode) {
  88445. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88446. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88447. }
  88448. }
  88449. }
  88450. *got_a_frame = true;
  88451. if(decoder->private_->next_fixed_block_size)
  88452. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88453. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88454. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88455. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88456. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88457. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88458. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88459. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88460. if(do_full_decode) {
  88461. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88462. return false;
  88463. }
  88464. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88465. return true;
  88466. }
  88467. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88468. {
  88469. FLAC__uint32 x;
  88470. FLAC__uint64 xx;
  88471. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88472. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88473. unsigned raw_header_len;
  88474. FLAC__bool is_unparseable = false;
  88475. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88476. raw_header[0] = decoder->private_->header_warmup[0];
  88477. raw_header[1] = decoder->private_->header_warmup[1];
  88478. raw_header_len = 2;
  88479. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88480. is_unparseable = true;
  88481. for(i = 0; i < 2; i++) {
  88482. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88483. return false; /* read_callback_ sets the state for us */
  88484. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88485. decoder->private_->lookahead = (FLAC__byte)x;
  88486. decoder->private_->cached = true;
  88487. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88488. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88489. return true;
  88490. }
  88491. raw_header[raw_header_len++] = (FLAC__byte)x;
  88492. }
  88493. switch(x = raw_header[2] >> 4) {
  88494. case 0:
  88495. is_unparseable = true;
  88496. break;
  88497. case 1:
  88498. decoder->private_->frame.header.blocksize = 192;
  88499. break;
  88500. case 2:
  88501. case 3:
  88502. case 4:
  88503. case 5:
  88504. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88505. break;
  88506. case 6:
  88507. case 7:
  88508. blocksize_hint = x;
  88509. break;
  88510. case 8:
  88511. case 9:
  88512. case 10:
  88513. case 11:
  88514. case 12:
  88515. case 13:
  88516. case 14:
  88517. case 15:
  88518. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88519. break;
  88520. default:
  88521. FLAC__ASSERT(0);
  88522. break;
  88523. }
  88524. switch(x = raw_header[2] & 0x0f) {
  88525. case 0:
  88526. if(decoder->private_->has_stream_info)
  88527. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  88528. else
  88529. is_unparseable = true;
  88530. break;
  88531. case 1:
  88532. decoder->private_->frame.header.sample_rate = 88200;
  88533. break;
  88534. case 2:
  88535. decoder->private_->frame.header.sample_rate = 176400;
  88536. break;
  88537. case 3:
  88538. decoder->private_->frame.header.sample_rate = 192000;
  88539. break;
  88540. case 4:
  88541. decoder->private_->frame.header.sample_rate = 8000;
  88542. break;
  88543. case 5:
  88544. decoder->private_->frame.header.sample_rate = 16000;
  88545. break;
  88546. case 6:
  88547. decoder->private_->frame.header.sample_rate = 22050;
  88548. break;
  88549. case 7:
  88550. decoder->private_->frame.header.sample_rate = 24000;
  88551. break;
  88552. case 8:
  88553. decoder->private_->frame.header.sample_rate = 32000;
  88554. break;
  88555. case 9:
  88556. decoder->private_->frame.header.sample_rate = 44100;
  88557. break;
  88558. case 10:
  88559. decoder->private_->frame.header.sample_rate = 48000;
  88560. break;
  88561. case 11:
  88562. decoder->private_->frame.header.sample_rate = 96000;
  88563. break;
  88564. case 12:
  88565. case 13:
  88566. case 14:
  88567. sample_rate_hint = x;
  88568. break;
  88569. case 15:
  88570. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88571. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88572. return true;
  88573. default:
  88574. FLAC__ASSERT(0);
  88575. }
  88576. x = (unsigned)(raw_header[3] >> 4);
  88577. if(x & 8) {
  88578. decoder->private_->frame.header.channels = 2;
  88579. switch(x & 7) {
  88580. case 0:
  88581. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  88582. break;
  88583. case 1:
  88584. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  88585. break;
  88586. case 2:
  88587. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  88588. break;
  88589. default:
  88590. is_unparseable = true;
  88591. break;
  88592. }
  88593. }
  88594. else {
  88595. decoder->private_->frame.header.channels = (unsigned)x + 1;
  88596. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  88597. }
  88598. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  88599. case 0:
  88600. if(decoder->private_->has_stream_info)
  88601. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  88602. else
  88603. is_unparseable = true;
  88604. break;
  88605. case 1:
  88606. decoder->private_->frame.header.bits_per_sample = 8;
  88607. break;
  88608. case 2:
  88609. decoder->private_->frame.header.bits_per_sample = 12;
  88610. break;
  88611. case 4:
  88612. decoder->private_->frame.header.bits_per_sample = 16;
  88613. break;
  88614. case 5:
  88615. decoder->private_->frame.header.bits_per_sample = 20;
  88616. break;
  88617. case 6:
  88618. decoder->private_->frame.header.bits_per_sample = 24;
  88619. break;
  88620. case 3:
  88621. case 7:
  88622. is_unparseable = true;
  88623. break;
  88624. default:
  88625. FLAC__ASSERT(0);
  88626. break;
  88627. }
  88628. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  88629. is_unparseable = true;
  88630. if(
  88631. raw_header[1] & 0x01 ||
  88632. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  88633. ) { /* variable blocksize */
  88634. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  88635. return false; /* read_callback_ sets the state for us */
  88636. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  88637. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88638. decoder->private_->cached = true;
  88639. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88640. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88641. return true;
  88642. }
  88643. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88644. decoder->private_->frame.header.number.sample_number = xx;
  88645. }
  88646. else { /* fixed blocksize */
  88647. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  88648. return false; /* read_callback_ sets the state for us */
  88649. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  88650. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88651. decoder->private_->cached = true;
  88652. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88653. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88654. return true;
  88655. }
  88656. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  88657. decoder->private_->frame.header.number.frame_number = x;
  88658. }
  88659. if(blocksize_hint) {
  88660. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88661. return false; /* read_callback_ sets the state for us */
  88662. raw_header[raw_header_len++] = (FLAC__byte)x;
  88663. if(blocksize_hint == 7) {
  88664. FLAC__uint32 _x;
  88665. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88666. return false; /* read_callback_ sets the state for us */
  88667. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88668. x = (x << 8) | _x;
  88669. }
  88670. decoder->private_->frame.header.blocksize = x+1;
  88671. }
  88672. if(sample_rate_hint) {
  88673. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88674. return false; /* read_callback_ sets the state for us */
  88675. raw_header[raw_header_len++] = (FLAC__byte)x;
  88676. if(sample_rate_hint != 12) {
  88677. FLAC__uint32 _x;
  88678. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88679. return false; /* read_callback_ sets the state for us */
  88680. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88681. x = (x << 8) | _x;
  88682. }
  88683. if(sample_rate_hint == 12)
  88684. decoder->private_->frame.header.sample_rate = x*1000;
  88685. else if(sample_rate_hint == 13)
  88686. decoder->private_->frame.header.sample_rate = x;
  88687. else
  88688. decoder->private_->frame.header.sample_rate = x*10;
  88689. }
  88690. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88691. return false; /* read_callback_ sets the state for us */
  88692. crc8 = (FLAC__byte)x;
  88693. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  88694. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88695. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88696. return true;
  88697. }
  88698. decoder->private_->next_fixed_block_size = 0;
  88699. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  88700. x = decoder->private_->frame.header.number.frame_number;
  88701. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88702. if(decoder->private_->fixed_block_size)
  88703. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  88704. else if(decoder->private_->has_stream_info) {
  88705. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  88706. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  88707. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  88708. }
  88709. else
  88710. is_unparseable = true;
  88711. }
  88712. else if(x == 0) {
  88713. decoder->private_->frame.header.number.sample_number = 0;
  88714. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  88715. }
  88716. else {
  88717. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  88718. }
  88719. }
  88720. if(is_unparseable) {
  88721. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88722. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88723. return true;
  88724. }
  88725. return true;
  88726. }
  88727. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88728. {
  88729. FLAC__uint32 x;
  88730. FLAC__bool wasted_bits;
  88731. unsigned i;
  88732. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  88733. return false; /* read_callback_ sets the state for us */
  88734. wasted_bits = (x & 1);
  88735. x &= 0xfe;
  88736. if(wasted_bits) {
  88737. unsigned u;
  88738. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  88739. return false; /* read_callback_ sets the state for us */
  88740. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  88741. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  88742. }
  88743. else
  88744. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  88745. if(x & 0x80) {
  88746. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88747. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88748. return true;
  88749. }
  88750. else if(x == 0) {
  88751. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  88752. return false;
  88753. }
  88754. else if(x == 2) {
  88755. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  88756. return false;
  88757. }
  88758. else if(x < 16) {
  88759. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88760. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88761. return true;
  88762. }
  88763. else if(x <= 24) {
  88764. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  88765. return false;
  88766. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88767. return true;
  88768. }
  88769. else if(x < 64) {
  88770. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88771. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88772. return true;
  88773. }
  88774. else {
  88775. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  88776. return false;
  88777. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88778. return true;
  88779. }
  88780. if(wasted_bits && do_full_decode) {
  88781. x = decoder->private_->frame.subframes[channel].wasted_bits;
  88782. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88783. decoder->private_->output[channel][i] <<= x;
  88784. }
  88785. return true;
  88786. }
  88787. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88788. {
  88789. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  88790. FLAC__int32 x;
  88791. unsigned i;
  88792. FLAC__int32 *output = decoder->private_->output[channel];
  88793. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  88794. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88795. return false; /* read_callback_ sets the state for us */
  88796. subframe->value = x;
  88797. if(do_full_decode) {
  88798. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88799. output[i] = x;
  88800. }
  88801. return true;
  88802. }
  88803. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88804. {
  88805. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  88806. FLAC__int32 i32;
  88807. FLAC__uint32 u32;
  88808. unsigned u;
  88809. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  88810. subframe->residual = decoder->private_->residual[channel];
  88811. subframe->order = order;
  88812. for(u = 0; u < order; u++) {
  88813. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88814. return false; /* read_callback_ sets the state for us */
  88815. subframe->warmup[u] = i32;
  88816. }
  88817. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88818. return false; /* read_callback_ sets the state for us */
  88819. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88820. switch(subframe->entropy_coding_method.type) {
  88821. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88822. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88823. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88824. return false; /* read_callback_ sets the state for us */
  88825. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88826. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88827. break;
  88828. default:
  88829. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88830. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88831. return true;
  88832. }
  88833. switch(subframe->entropy_coding_method.type) {
  88834. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88835. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88836. 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))
  88837. return false;
  88838. break;
  88839. default:
  88840. FLAC__ASSERT(0);
  88841. }
  88842. if(do_full_decode) {
  88843. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88844. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  88845. }
  88846. return true;
  88847. }
  88848. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88849. {
  88850. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  88851. FLAC__int32 i32;
  88852. FLAC__uint32 u32;
  88853. unsigned u;
  88854. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  88855. subframe->residual = decoder->private_->residual[channel];
  88856. subframe->order = order;
  88857. for(u = 0; u < order; u++) {
  88858. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88859. return false; /* read_callback_ sets the state for us */
  88860. subframe->warmup[u] = i32;
  88861. }
  88862. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  88863. return false; /* read_callback_ sets the state for us */
  88864. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  88865. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88866. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88867. return true;
  88868. }
  88869. subframe->qlp_coeff_precision = u32+1;
  88870. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  88871. return false; /* read_callback_ sets the state for us */
  88872. subframe->quantization_level = i32;
  88873. for(u = 0; u < order; u++) {
  88874. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  88875. return false; /* read_callback_ sets the state for us */
  88876. subframe->qlp_coeff[u] = i32;
  88877. }
  88878. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88879. return false; /* read_callback_ sets the state for us */
  88880. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88881. switch(subframe->entropy_coding_method.type) {
  88882. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88883. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88884. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88885. return false; /* read_callback_ sets the state for us */
  88886. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88887. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88888. break;
  88889. default:
  88890. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88891. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88892. return true;
  88893. }
  88894. switch(subframe->entropy_coding_method.type) {
  88895. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88896. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88897. 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))
  88898. return false;
  88899. break;
  88900. default:
  88901. FLAC__ASSERT(0);
  88902. }
  88903. if(do_full_decode) {
  88904. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88905. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  88906. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  88907. if(order <= 8)
  88908. 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);
  88909. else
  88910. 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);
  88911. }
  88912. else
  88913. 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);
  88914. else
  88915. 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);
  88916. }
  88917. return true;
  88918. }
  88919. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88920. {
  88921. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  88922. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  88923. unsigned i;
  88924. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  88925. subframe->data = residual;
  88926. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88927. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88928. return false; /* read_callback_ sets the state for us */
  88929. residual[i] = x;
  88930. }
  88931. if(do_full_decode)
  88932. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88933. return true;
  88934. }
  88935. 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)
  88936. {
  88937. FLAC__uint32 rice_parameter;
  88938. int i;
  88939. unsigned partition, sample, u;
  88940. const unsigned partitions = 1u << partition_order;
  88941. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  88942. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  88943. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  88944. if(partition_order == 0) {
  88945. if(decoder->private_->frame.header.blocksize < predictor_order) {
  88946. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88947. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88948. return true;
  88949. }
  88950. }
  88951. else {
  88952. if(partition_samples < predictor_order) {
  88953. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88954. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88955. return true;
  88956. }
  88957. }
  88958. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  88959. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88960. return false;
  88961. }
  88962. sample = 0;
  88963. for(partition = 0; partition < partitions; partition++) {
  88964. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  88965. return false; /* read_callback_ sets the state for us */
  88966. partitioned_rice_contents->parameters[partition] = rice_parameter;
  88967. if(rice_parameter < pesc) {
  88968. partitioned_rice_contents->raw_bits[partition] = 0;
  88969. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  88970. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  88971. return false; /* read_callback_ sets the state for us */
  88972. sample += u;
  88973. }
  88974. else {
  88975. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  88976. return false; /* read_callback_ sets the state for us */
  88977. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  88978. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  88979. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  88980. return false; /* read_callback_ sets the state for us */
  88981. residual[sample] = i;
  88982. }
  88983. }
  88984. }
  88985. return true;
  88986. }
  88987. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  88988. {
  88989. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88990. FLAC__uint32 zero = 0;
  88991. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88992. return false; /* read_callback_ sets the state for us */
  88993. if(zero != 0) {
  88994. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88995. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88996. }
  88997. }
  88998. return true;
  88999. }
  89000. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  89001. {
  89002. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  89003. if(
  89004. #if FLAC__HAS_OGG
  89005. !decoder->private_->is_ogg &&
  89006. #endif
  89007. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89008. ) {
  89009. *bytes = 0;
  89010. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89011. return false;
  89012. }
  89013. else if(*bytes > 0) {
  89014. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89015. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89016. return false;
  89017. }
  89018. else {
  89019. const FLAC__StreamDecoderReadStatus status =
  89020. #if FLAC__HAS_OGG
  89021. decoder->private_->is_ogg?
  89022. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89023. #endif
  89024. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89025. ;
  89026. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89027. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89028. return false;
  89029. }
  89030. else if(*bytes == 0) {
  89031. if(
  89032. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89033. (
  89034. #if FLAC__HAS_OGG
  89035. !decoder->private_->is_ogg &&
  89036. #endif
  89037. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89038. )
  89039. ) {
  89040. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89041. return false;
  89042. }
  89043. else
  89044. return true;
  89045. }
  89046. else
  89047. return true;
  89048. }
  89049. }
  89050. else {
  89051. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89052. return false;
  89053. }
  89054. }
  89055. #if FLAC__HAS_OGG
  89056. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89057. {
  89058. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89059. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89060. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89061. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89062. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89063. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89064. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89065. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89066. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89067. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89068. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89069. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89070. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89071. default:
  89072. FLAC__ASSERT(0);
  89073. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89074. }
  89075. }
  89076. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89077. {
  89078. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89079. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89080. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89081. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89082. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89083. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89084. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89085. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89086. default:
  89087. FLAC__ASSERT(0);
  89088. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89089. }
  89090. }
  89091. #endif
  89092. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89093. {
  89094. if(decoder->private_->is_seeking) {
  89095. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89096. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89097. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89098. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89099. #if FLAC__HAS_OGG
  89100. decoder->private_->got_a_frame = true;
  89101. #endif
  89102. decoder->private_->last_frame = *frame; /* save the frame */
  89103. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89104. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89105. decoder->private_->is_seeking = false;
  89106. if(delta > 0) {
  89107. unsigned channel;
  89108. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89109. for(channel = 0; channel < frame->header.channels; channel++)
  89110. newbuffer[channel] = buffer[channel] + delta;
  89111. decoder->private_->last_frame.header.blocksize -= delta;
  89112. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89113. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89114. }
  89115. else {
  89116. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89117. }
  89118. }
  89119. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89120. }
  89121. if(!decoder->private_->has_stream_info)
  89122. decoder->private_->do_md5_checking = false;
  89123. if(decoder->private_->do_md5_checking) {
  89124. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89125. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89126. }
  89127. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89128. }
  89129. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89130. {
  89131. if(!decoder->private_->is_seeking)
  89132. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89133. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89134. decoder->private_->unparseable_frame_count++;
  89135. }
  89136. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89137. {
  89138. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89139. FLAC__int64 pos = -1;
  89140. int i;
  89141. unsigned approx_bytes_per_frame;
  89142. FLAC__bool first_seek = true;
  89143. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89144. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89145. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89146. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89147. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89148. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89149. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89150. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89151. if(channels == 0)
  89152. channels = decoder->private_->stream_info.data.stream_info.channels;
  89153. if(bps == 0)
  89154. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89155. if(max_framesize > 0)
  89156. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89157. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89158. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89159. }
  89160. else
  89161. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89162. lower_bound = first_frame_offset;
  89163. lower_bound_sample = 0;
  89164. upper_bound = stream_length;
  89165. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89166. if(seek_table) {
  89167. FLAC__uint64 new_lower_bound = lower_bound;
  89168. FLAC__uint64 new_upper_bound = upper_bound;
  89169. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89170. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89171. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89172. if(
  89173. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89174. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89175. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89176. seek_table->points[i].sample_number <= target_sample
  89177. )
  89178. break;
  89179. }
  89180. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89181. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89182. new_lower_bound_sample = seek_table->points[i].sample_number;
  89183. }
  89184. for(i = 0; i < (int)seek_table->num_points; i++) {
  89185. if(
  89186. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89187. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89188. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89189. seek_table->points[i].sample_number > target_sample
  89190. )
  89191. break;
  89192. }
  89193. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89194. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89195. new_upper_bound_sample = seek_table->points[i].sample_number;
  89196. }
  89197. if(new_upper_bound >= new_lower_bound) {
  89198. lower_bound = new_lower_bound;
  89199. upper_bound = new_upper_bound;
  89200. lower_bound_sample = new_lower_bound_sample;
  89201. upper_bound_sample = new_upper_bound_sample;
  89202. }
  89203. }
  89204. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89205. if(upper_bound_sample == lower_bound_sample)
  89206. upper_bound_sample++;
  89207. decoder->private_->target_sample = target_sample;
  89208. while(1) {
  89209. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89210. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89211. return false;
  89212. }
  89213. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89214. #if defined _MSC_VER || defined __MINGW32__
  89215. 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;
  89216. #else
  89217. 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;
  89218. #endif
  89219. #else
  89220. if(upper_bound - lower_bound < 0xffffffff)
  89221. 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;
  89222. else /* @@@ WATCHOUT, ~2TB limit */
  89223. 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;
  89224. #endif
  89225. if(pos >= (FLAC__int64)upper_bound)
  89226. pos = (FLAC__int64)upper_bound - 1;
  89227. if(pos < (FLAC__int64)lower_bound)
  89228. pos = (FLAC__int64)lower_bound;
  89229. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89230. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89231. return false;
  89232. }
  89233. if(!FLAC__stream_decoder_flush(decoder)) {
  89234. return false;
  89235. }
  89236. decoder->private_->unparseable_frame_count = 0;
  89237. if(!FLAC__stream_decoder_process_single(decoder)) {
  89238. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89239. return false;
  89240. }
  89241. #if 0
  89242. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89243. break;
  89244. #endif
  89245. if(!decoder->private_->is_seeking)
  89246. break;
  89247. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89248. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89249. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89250. if (pos == (FLAC__int64)lower_bound) {
  89251. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89252. return false;
  89253. }
  89254. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89255. continue;
  89256. }
  89257. first_seek = false;
  89258. if (this_frame_sample < lower_bound_sample) {
  89259. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89260. return false;
  89261. }
  89262. if(target_sample < this_frame_sample) {
  89263. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89264. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89265. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89266. return false;
  89267. }
  89268. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89269. }
  89270. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89271. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89272. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89273. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89274. return false;
  89275. }
  89276. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89277. }
  89278. }
  89279. return true;
  89280. }
  89281. #if FLAC__HAS_OGG
  89282. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89283. {
  89284. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89285. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89286. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89287. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89288. FLAC__bool did_a_seek;
  89289. unsigned iteration = 0;
  89290. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89291. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89292. if(right_sample == 0) {
  89293. right_sample = (FLAC__uint64)(-1);
  89294. BINARY_SEARCH_AFTER_ITERATION = 0;
  89295. }
  89296. decoder->private_->target_sample = target_sample;
  89297. for( ; ; iteration++) {
  89298. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89299. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89300. pos = (right_pos + left_pos) / 2;
  89301. }
  89302. else {
  89303. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89304. #if defined _MSC_VER || defined __MINGW32__
  89305. 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));
  89306. #else
  89307. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89308. #endif
  89309. #else
  89310. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89311. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89312. else /* @@@ WATCHOUT, ~2TB limit */
  89313. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89314. #endif
  89315. }
  89316. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89317. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89318. return false;
  89319. }
  89320. if(!FLAC__stream_decoder_flush(decoder)) {
  89321. return false;
  89322. }
  89323. did_a_seek = true;
  89324. }
  89325. else
  89326. did_a_seek = false;
  89327. decoder->private_->got_a_frame = false;
  89328. if(!FLAC__stream_decoder_process_single(decoder)) {
  89329. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89330. return false;
  89331. }
  89332. if(!decoder->private_->got_a_frame) {
  89333. if(did_a_seek) {
  89334. right_pos = pos;
  89335. BINARY_SEARCH_AFTER_ITERATION = 0;
  89336. }
  89337. else {
  89338. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89339. return false;
  89340. }
  89341. }
  89342. else if(!decoder->private_->is_seeking) {
  89343. break;
  89344. }
  89345. else {
  89346. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89347. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89348. if (did_a_seek) {
  89349. if (this_frame_sample <= target_sample) {
  89350. FLAC__ASSERT(this_frame_sample != target_sample);
  89351. left_sample = this_frame_sample;
  89352. if (left_pos == pos) {
  89353. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89354. return false;
  89355. }
  89356. left_pos = pos;
  89357. }
  89358. else if(this_frame_sample > target_sample) {
  89359. right_sample = this_frame_sample;
  89360. if (right_pos == pos) {
  89361. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89362. return false;
  89363. }
  89364. right_pos = pos;
  89365. }
  89366. }
  89367. }
  89368. }
  89369. return true;
  89370. }
  89371. #endif
  89372. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89373. {
  89374. (void)client_data;
  89375. if(*bytes > 0) {
  89376. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89377. if(ferror(decoder->private_->file))
  89378. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89379. else if(*bytes == 0)
  89380. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89381. else
  89382. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89383. }
  89384. else
  89385. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89386. }
  89387. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89388. {
  89389. (void)client_data;
  89390. if(decoder->private_->file == stdin)
  89391. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89392. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89393. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89394. else
  89395. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89396. }
  89397. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89398. {
  89399. off_t pos;
  89400. (void)client_data;
  89401. if(decoder->private_->file == stdin)
  89402. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89403. else if((pos = ftello(decoder->private_->file)) < 0)
  89404. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89405. else {
  89406. *absolute_byte_offset = (FLAC__uint64)pos;
  89407. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89408. }
  89409. }
  89410. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89411. {
  89412. struct stat filestats;
  89413. (void)client_data;
  89414. if(decoder->private_->file == stdin)
  89415. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89416. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89417. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89418. else {
  89419. *stream_length = (FLAC__uint64)filestats.st_size;
  89420. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89421. }
  89422. }
  89423. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89424. {
  89425. (void)client_data;
  89426. return feof(decoder->private_->file)? true : false;
  89427. }
  89428. #endif
  89429. /*** End of inlined file: stream_decoder.c ***/
  89430. /*** Start of inlined file: stream_encoder.c ***/
  89431. /*** Start of inlined file: juce_FlacHeader.h ***/
  89432. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89433. // tasks..
  89434. #define VERSION "1.2.1"
  89435. #define FLAC__NO_DLL 1
  89436. #if JUCE_MSVC
  89437. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89438. #endif
  89439. #if JUCE_MAC
  89440. #define FLAC__SYS_DARWIN 1
  89441. #endif
  89442. /*** End of inlined file: juce_FlacHeader.h ***/
  89443. #if JUCE_USE_FLAC
  89444. #if HAVE_CONFIG_H
  89445. # include <config.h>
  89446. #endif
  89447. #if defined _MSC_VER || defined __MINGW32__
  89448. #include <io.h> /* for _setmode() */
  89449. #include <fcntl.h> /* for _O_BINARY */
  89450. #endif
  89451. #if defined __CYGWIN__ || defined __EMX__
  89452. #include <io.h> /* for setmode(), O_BINARY */
  89453. #include <fcntl.h> /* for _O_BINARY */
  89454. #endif
  89455. #include <limits.h>
  89456. #include <stdio.h>
  89457. #include <stdlib.h> /* for malloc() */
  89458. #include <string.h> /* for memcpy() */
  89459. #include <sys/types.h> /* for off_t */
  89460. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89461. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89462. #define fseeko fseek
  89463. #define ftello ftell
  89464. #endif
  89465. #endif
  89466. /*** Start of inlined file: stream_encoder.h ***/
  89467. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89468. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89469. #if FLAC__HAS_OGG
  89470. #include "private/ogg_encoder_aspect.h"
  89471. #endif
  89472. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89473. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89474. typedef enum {
  89475. FLAC__APODIZATION_BARTLETT,
  89476. FLAC__APODIZATION_BARTLETT_HANN,
  89477. FLAC__APODIZATION_BLACKMAN,
  89478. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89479. FLAC__APODIZATION_CONNES,
  89480. FLAC__APODIZATION_FLATTOP,
  89481. FLAC__APODIZATION_GAUSS,
  89482. FLAC__APODIZATION_HAMMING,
  89483. FLAC__APODIZATION_HANN,
  89484. FLAC__APODIZATION_KAISER_BESSEL,
  89485. FLAC__APODIZATION_NUTTALL,
  89486. FLAC__APODIZATION_RECTANGLE,
  89487. FLAC__APODIZATION_TRIANGLE,
  89488. FLAC__APODIZATION_TUKEY,
  89489. FLAC__APODIZATION_WELCH
  89490. } FLAC__ApodizationFunction;
  89491. typedef struct {
  89492. FLAC__ApodizationFunction type;
  89493. union {
  89494. struct {
  89495. FLAC__real stddev;
  89496. } gauss;
  89497. struct {
  89498. FLAC__real p;
  89499. } tukey;
  89500. } parameters;
  89501. } FLAC__ApodizationSpecification;
  89502. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89503. typedef struct FLAC__StreamEncoderProtected {
  89504. FLAC__StreamEncoderState state;
  89505. FLAC__bool verify;
  89506. FLAC__bool streamable_subset;
  89507. FLAC__bool do_md5;
  89508. FLAC__bool do_mid_side_stereo;
  89509. FLAC__bool loose_mid_side_stereo;
  89510. unsigned channels;
  89511. unsigned bits_per_sample;
  89512. unsigned sample_rate;
  89513. unsigned blocksize;
  89514. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89515. unsigned num_apodizations;
  89516. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89517. #endif
  89518. unsigned max_lpc_order;
  89519. unsigned qlp_coeff_precision;
  89520. FLAC__bool do_qlp_coeff_prec_search;
  89521. FLAC__bool do_exhaustive_model_search;
  89522. FLAC__bool do_escape_coding;
  89523. unsigned min_residual_partition_order;
  89524. unsigned max_residual_partition_order;
  89525. unsigned rice_parameter_search_dist;
  89526. FLAC__uint64 total_samples_estimate;
  89527. FLAC__StreamMetadata **metadata;
  89528. unsigned num_metadata_blocks;
  89529. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  89530. #if FLAC__HAS_OGG
  89531. FLAC__OggEncoderAspect ogg_encoder_aspect;
  89532. #endif
  89533. } FLAC__StreamEncoderProtected;
  89534. #endif
  89535. /*** End of inlined file: stream_encoder.h ***/
  89536. #if FLAC__HAS_OGG
  89537. #include "include/private/ogg_helper.h"
  89538. #include "include/private/ogg_mapping.h"
  89539. #endif
  89540. /*** Start of inlined file: stream_encoder_framing.h ***/
  89541. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89542. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89543. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  89544. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  89545. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89546. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89547. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89548. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89549. #endif
  89550. /*** End of inlined file: stream_encoder_framing.h ***/
  89551. /*** Start of inlined file: window.h ***/
  89552. #ifndef FLAC__PRIVATE__WINDOW_H
  89553. #define FLAC__PRIVATE__WINDOW_H
  89554. #ifdef HAVE_CONFIG_H
  89555. #include <config.h>
  89556. #endif
  89557. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89558. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  89559. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  89560. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  89561. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  89562. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  89563. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  89564. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  89565. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  89566. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  89567. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  89568. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  89569. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  89570. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  89571. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  89572. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  89573. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  89574. #endif
  89575. /*** End of inlined file: window.h ***/
  89576. #ifndef FLaC__INLINE
  89577. #define FLaC__INLINE
  89578. #endif
  89579. #ifdef min
  89580. #undef min
  89581. #endif
  89582. #define min(x,y) ((x)<(y)?(x):(y))
  89583. #ifdef max
  89584. #undef max
  89585. #endif
  89586. #define max(x,y) ((x)>(y)?(x):(y))
  89587. #undef EXACT_RICE_BITS_CALCULATION
  89588. #undef ENABLE_RICE_PARAMETER_SEARCH
  89589. typedef struct {
  89590. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  89591. unsigned size; /* of each data[] in samples */
  89592. unsigned tail;
  89593. } verify_input_fifo;
  89594. typedef struct {
  89595. const FLAC__byte *data;
  89596. unsigned capacity;
  89597. unsigned bytes;
  89598. } verify_output;
  89599. typedef enum {
  89600. ENCODER_IN_MAGIC = 0,
  89601. ENCODER_IN_METADATA = 1,
  89602. ENCODER_IN_AUDIO = 2
  89603. } EncoderStateHint;
  89604. static struct CompressionLevels {
  89605. FLAC__bool do_mid_side_stereo;
  89606. FLAC__bool loose_mid_side_stereo;
  89607. unsigned max_lpc_order;
  89608. unsigned qlp_coeff_precision;
  89609. FLAC__bool do_qlp_coeff_prec_search;
  89610. FLAC__bool do_escape_coding;
  89611. FLAC__bool do_exhaustive_model_search;
  89612. unsigned min_residual_partition_order;
  89613. unsigned max_residual_partition_order;
  89614. unsigned rice_parameter_search_dist;
  89615. } compression_levels_[] = {
  89616. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  89617. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  89618. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  89619. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  89620. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  89621. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  89622. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  89623. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  89624. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  89625. };
  89626. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  89627. static void free_(FLAC__StreamEncoder *encoder);
  89628. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  89629. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  89630. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  89631. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  89632. #if FLAC__HAS_OGG
  89633. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  89634. #endif
  89635. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  89636. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  89637. static FLAC__bool process_subframe_(
  89638. FLAC__StreamEncoder *encoder,
  89639. unsigned min_partition_order,
  89640. unsigned max_partition_order,
  89641. const FLAC__FrameHeader *frame_header,
  89642. unsigned subframe_bps,
  89643. const FLAC__int32 integer_signal[],
  89644. FLAC__Subframe *subframe[2],
  89645. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  89646. FLAC__int32 *residual[2],
  89647. unsigned *best_subframe,
  89648. unsigned *best_bits
  89649. );
  89650. static FLAC__bool add_subframe_(
  89651. FLAC__StreamEncoder *encoder,
  89652. unsigned blocksize,
  89653. unsigned subframe_bps,
  89654. const FLAC__Subframe *subframe,
  89655. FLAC__BitWriter *frame
  89656. );
  89657. static unsigned evaluate_constant_subframe_(
  89658. FLAC__StreamEncoder *encoder,
  89659. const FLAC__int32 signal,
  89660. unsigned blocksize,
  89661. unsigned subframe_bps,
  89662. FLAC__Subframe *subframe
  89663. );
  89664. static unsigned evaluate_fixed_subframe_(
  89665. FLAC__StreamEncoder *encoder,
  89666. const FLAC__int32 signal[],
  89667. FLAC__int32 residual[],
  89668. FLAC__uint64 abs_residual_partition_sums[],
  89669. unsigned raw_bits_per_partition[],
  89670. unsigned blocksize,
  89671. unsigned subframe_bps,
  89672. unsigned order,
  89673. unsigned rice_parameter,
  89674. unsigned rice_parameter_limit,
  89675. unsigned min_partition_order,
  89676. unsigned max_partition_order,
  89677. FLAC__bool do_escape_coding,
  89678. unsigned rice_parameter_search_dist,
  89679. FLAC__Subframe *subframe,
  89680. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89681. );
  89682. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89683. static unsigned evaluate_lpc_subframe_(
  89684. FLAC__StreamEncoder *encoder,
  89685. const FLAC__int32 signal[],
  89686. FLAC__int32 residual[],
  89687. FLAC__uint64 abs_residual_partition_sums[],
  89688. unsigned raw_bits_per_partition[],
  89689. const FLAC__real lp_coeff[],
  89690. unsigned blocksize,
  89691. unsigned subframe_bps,
  89692. unsigned order,
  89693. unsigned qlp_coeff_precision,
  89694. unsigned rice_parameter,
  89695. unsigned rice_parameter_limit,
  89696. unsigned min_partition_order,
  89697. unsigned max_partition_order,
  89698. FLAC__bool do_escape_coding,
  89699. unsigned rice_parameter_search_dist,
  89700. FLAC__Subframe *subframe,
  89701. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89702. );
  89703. #endif
  89704. static unsigned evaluate_verbatim_subframe_(
  89705. FLAC__StreamEncoder *encoder,
  89706. const FLAC__int32 signal[],
  89707. unsigned blocksize,
  89708. unsigned subframe_bps,
  89709. FLAC__Subframe *subframe
  89710. );
  89711. static unsigned find_best_partition_order_(
  89712. struct FLAC__StreamEncoderPrivate *private_,
  89713. const FLAC__int32 residual[],
  89714. FLAC__uint64 abs_residual_partition_sums[],
  89715. unsigned raw_bits_per_partition[],
  89716. unsigned residual_samples,
  89717. unsigned predictor_order,
  89718. unsigned rice_parameter,
  89719. unsigned rice_parameter_limit,
  89720. unsigned min_partition_order,
  89721. unsigned max_partition_order,
  89722. unsigned bps,
  89723. FLAC__bool do_escape_coding,
  89724. unsigned rice_parameter_search_dist,
  89725. FLAC__EntropyCodingMethod *best_ecm
  89726. );
  89727. static void precompute_partition_info_sums_(
  89728. const FLAC__int32 residual[],
  89729. FLAC__uint64 abs_residual_partition_sums[],
  89730. unsigned residual_samples,
  89731. unsigned predictor_order,
  89732. unsigned min_partition_order,
  89733. unsigned max_partition_order,
  89734. unsigned bps
  89735. );
  89736. static void precompute_partition_info_escapes_(
  89737. const FLAC__int32 residual[],
  89738. unsigned raw_bits_per_partition[],
  89739. unsigned residual_samples,
  89740. unsigned predictor_order,
  89741. unsigned min_partition_order,
  89742. unsigned max_partition_order
  89743. );
  89744. static FLAC__bool set_partitioned_rice_(
  89745. #ifdef EXACT_RICE_BITS_CALCULATION
  89746. const FLAC__int32 residual[],
  89747. #endif
  89748. const FLAC__uint64 abs_residual_partition_sums[],
  89749. const unsigned raw_bits_per_partition[],
  89750. const unsigned residual_samples,
  89751. const unsigned predictor_order,
  89752. const unsigned suggested_rice_parameter,
  89753. const unsigned rice_parameter_limit,
  89754. const unsigned rice_parameter_search_dist,
  89755. const unsigned partition_order,
  89756. const FLAC__bool search_for_escapes,
  89757. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  89758. unsigned *bits
  89759. );
  89760. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  89761. static void append_to_verify_fifo_(
  89762. verify_input_fifo *fifo,
  89763. const FLAC__int32 * const input[],
  89764. unsigned input_offset,
  89765. unsigned channels,
  89766. unsigned wide_samples
  89767. );
  89768. static void append_to_verify_fifo_interleaved_(
  89769. verify_input_fifo *fifo,
  89770. const FLAC__int32 input[],
  89771. unsigned input_offset,
  89772. unsigned channels,
  89773. unsigned wide_samples
  89774. );
  89775. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89776. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  89777. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  89778. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  89779. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89780. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  89781. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  89782. 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);
  89783. static FILE *get_binary_stdout_(void);
  89784. typedef struct FLAC__StreamEncoderPrivate {
  89785. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  89786. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  89787. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  89788. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89789. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  89790. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  89791. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  89792. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  89793. #endif
  89794. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  89795. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  89796. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  89797. FLAC__int32 *residual_workspace_mid_side[2][2];
  89798. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  89799. FLAC__Subframe subframe_workspace_mid_side[2][2];
  89800. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89801. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  89802. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  89803. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  89804. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89805. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  89806. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  89807. unsigned best_subframe_mid_side[2];
  89808. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  89809. unsigned best_subframe_bits_mid_side[2];
  89810. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  89811. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  89812. FLAC__BitWriter *frame; /* the current frame being worked on */
  89813. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  89814. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  89815. FLAC__ChannelAssignment last_channel_assignment;
  89816. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  89817. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  89818. unsigned current_sample_number;
  89819. unsigned current_frame_number;
  89820. FLAC__MD5Context md5context;
  89821. FLAC__CPUInfo cpuinfo;
  89822. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89823. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89824. #else
  89825. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89826. #endif
  89827. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89828. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  89829. 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[]);
  89830. 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[]);
  89831. 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[]);
  89832. #endif
  89833. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  89834. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  89835. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  89836. FLAC__bool disable_constant_subframes;
  89837. FLAC__bool disable_fixed_subframes;
  89838. FLAC__bool disable_verbatim_subframes;
  89839. #if FLAC__HAS_OGG
  89840. FLAC__bool is_ogg;
  89841. #endif
  89842. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  89843. FLAC__StreamEncoderSeekCallback seek_callback;
  89844. FLAC__StreamEncoderTellCallback tell_callback;
  89845. FLAC__StreamEncoderWriteCallback write_callback;
  89846. FLAC__StreamEncoderMetadataCallback metadata_callback;
  89847. FLAC__StreamEncoderProgressCallback progress_callback;
  89848. void *client_data;
  89849. unsigned first_seekpoint_to_check;
  89850. FILE *file; /* only used when encoding to a file */
  89851. FLAC__uint64 bytes_written;
  89852. FLAC__uint64 samples_written;
  89853. unsigned frames_written;
  89854. unsigned total_frames_estimate;
  89855. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  89856. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  89857. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89858. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  89859. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  89860. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  89861. FLAC__real *windowed_signal_unaligned;
  89862. #endif
  89863. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  89864. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  89865. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  89866. unsigned *raw_bits_per_partition_unaligned;
  89867. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89868. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  89869. #endif
  89870. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  89871. struct {
  89872. FLAC__StreamDecoder *decoder;
  89873. EncoderStateHint state_hint;
  89874. FLAC__bool needs_magic_hack;
  89875. verify_input_fifo input_fifo;
  89876. verify_output output;
  89877. struct {
  89878. FLAC__uint64 absolute_sample;
  89879. unsigned frame_number;
  89880. unsigned channel;
  89881. unsigned sample;
  89882. FLAC__int32 expected;
  89883. FLAC__int32 got;
  89884. } error_stats;
  89885. } verify;
  89886. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  89887. } FLAC__StreamEncoderPrivate;
  89888. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  89889. "FLAC__STREAM_ENCODER_OK",
  89890. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  89891. "FLAC__STREAM_ENCODER_OGG_ERROR",
  89892. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  89893. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  89894. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  89895. "FLAC__STREAM_ENCODER_IO_ERROR",
  89896. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  89897. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  89898. };
  89899. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  89900. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  89901. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  89902. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  89903. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  89904. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  89905. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  89906. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  89907. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  89908. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  89909. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  89910. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  89911. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  89912. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  89913. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  89914. };
  89915. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  89916. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  89917. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  89918. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  89919. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  89920. };
  89921. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  89922. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  89923. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  89924. };
  89925. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  89926. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  89927. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  89928. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  89929. };
  89930. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  89931. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  89932. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  89933. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  89934. };
  89935. static const unsigned OVERREAD_ = 1;
  89936. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  89937. {
  89938. FLAC__StreamEncoder *encoder;
  89939. unsigned i;
  89940. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  89941. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  89942. if(encoder == 0) {
  89943. return 0;
  89944. }
  89945. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  89946. if(encoder->protected_ == 0) {
  89947. free(encoder);
  89948. return 0;
  89949. }
  89950. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  89951. if(encoder->private_ == 0) {
  89952. free(encoder->protected_);
  89953. free(encoder);
  89954. return 0;
  89955. }
  89956. encoder->private_->frame = FLAC__bitwriter_new();
  89957. if(encoder->private_->frame == 0) {
  89958. free(encoder->private_);
  89959. free(encoder->protected_);
  89960. free(encoder);
  89961. return 0;
  89962. }
  89963. encoder->private_->file = 0;
  89964. set_defaults_enc(encoder);
  89965. encoder->private_->is_being_deleted = false;
  89966. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89967. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  89968. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  89969. }
  89970. for(i = 0; i < 2; i++) {
  89971. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  89972. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  89973. }
  89974. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89975. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  89976. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  89977. }
  89978. for(i = 0; i < 2; i++) {
  89979. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  89980. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  89981. }
  89982. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89983. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  89984. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  89985. }
  89986. for(i = 0; i < 2; i++) {
  89987. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  89988. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  89989. }
  89990. for(i = 0; i < 2; i++)
  89991. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  89992. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  89993. return encoder;
  89994. }
  89995. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  89996. {
  89997. unsigned i;
  89998. FLAC__ASSERT(0 != encoder);
  89999. FLAC__ASSERT(0 != encoder->protected_);
  90000. FLAC__ASSERT(0 != encoder->private_);
  90001. FLAC__ASSERT(0 != encoder->private_->frame);
  90002. encoder->private_->is_being_deleted = true;
  90003. (void)FLAC__stream_encoder_finish(encoder);
  90004. if(0 != encoder->private_->verify.decoder)
  90005. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  90006. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90007. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90008. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90009. }
  90010. for(i = 0; i < 2; i++) {
  90011. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90012. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90013. }
  90014. for(i = 0; i < 2; i++)
  90015. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90016. FLAC__bitwriter_delete(encoder->private_->frame);
  90017. free(encoder->private_);
  90018. free(encoder->protected_);
  90019. free(encoder);
  90020. }
  90021. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90022. FLAC__StreamEncoder *encoder,
  90023. FLAC__StreamEncoderReadCallback read_callback,
  90024. FLAC__StreamEncoderWriteCallback write_callback,
  90025. FLAC__StreamEncoderSeekCallback seek_callback,
  90026. FLAC__StreamEncoderTellCallback tell_callback,
  90027. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90028. void *client_data,
  90029. FLAC__bool is_ogg
  90030. )
  90031. {
  90032. unsigned i;
  90033. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90034. FLAC__ASSERT(0 != encoder);
  90035. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90036. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90037. #if !FLAC__HAS_OGG
  90038. if(is_ogg)
  90039. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90040. #endif
  90041. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90042. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90043. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90044. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90045. if(encoder->protected_->channels != 2) {
  90046. encoder->protected_->do_mid_side_stereo = false;
  90047. encoder->protected_->loose_mid_side_stereo = false;
  90048. }
  90049. else if(!encoder->protected_->do_mid_side_stereo)
  90050. encoder->protected_->loose_mid_side_stereo = false;
  90051. if(encoder->protected_->bits_per_sample >= 32)
  90052. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90053. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90054. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90055. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90056. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90057. if(encoder->protected_->blocksize == 0) {
  90058. if(encoder->protected_->max_lpc_order == 0)
  90059. encoder->protected_->blocksize = 1152;
  90060. else
  90061. encoder->protected_->blocksize = 4096;
  90062. }
  90063. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90064. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90065. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90066. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90067. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90068. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90069. if(encoder->protected_->qlp_coeff_precision == 0) {
  90070. if(encoder->protected_->bits_per_sample < 16) {
  90071. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90072. }
  90073. else if(encoder->protected_->bits_per_sample == 16) {
  90074. if(encoder->protected_->blocksize <= 192)
  90075. encoder->protected_->qlp_coeff_precision = 7;
  90076. else if(encoder->protected_->blocksize <= 384)
  90077. encoder->protected_->qlp_coeff_precision = 8;
  90078. else if(encoder->protected_->blocksize <= 576)
  90079. encoder->protected_->qlp_coeff_precision = 9;
  90080. else if(encoder->protected_->blocksize <= 1152)
  90081. encoder->protected_->qlp_coeff_precision = 10;
  90082. else if(encoder->protected_->blocksize <= 2304)
  90083. encoder->protected_->qlp_coeff_precision = 11;
  90084. else if(encoder->protected_->blocksize <= 4608)
  90085. encoder->protected_->qlp_coeff_precision = 12;
  90086. else
  90087. encoder->protected_->qlp_coeff_precision = 13;
  90088. }
  90089. else {
  90090. if(encoder->protected_->blocksize <= 384)
  90091. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90092. else if(encoder->protected_->blocksize <= 1152)
  90093. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90094. else
  90095. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90096. }
  90097. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90098. }
  90099. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90100. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90101. if(encoder->protected_->streamable_subset) {
  90102. if(
  90103. encoder->protected_->blocksize != 192 &&
  90104. encoder->protected_->blocksize != 576 &&
  90105. encoder->protected_->blocksize != 1152 &&
  90106. encoder->protected_->blocksize != 2304 &&
  90107. encoder->protected_->blocksize != 4608 &&
  90108. encoder->protected_->blocksize != 256 &&
  90109. encoder->protected_->blocksize != 512 &&
  90110. encoder->protected_->blocksize != 1024 &&
  90111. encoder->protected_->blocksize != 2048 &&
  90112. encoder->protected_->blocksize != 4096 &&
  90113. encoder->protected_->blocksize != 8192 &&
  90114. encoder->protected_->blocksize != 16384
  90115. )
  90116. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90117. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90118. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90119. if(
  90120. encoder->protected_->bits_per_sample != 8 &&
  90121. encoder->protected_->bits_per_sample != 12 &&
  90122. encoder->protected_->bits_per_sample != 16 &&
  90123. encoder->protected_->bits_per_sample != 20 &&
  90124. encoder->protected_->bits_per_sample != 24
  90125. )
  90126. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90127. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90128. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90129. if(
  90130. encoder->protected_->sample_rate <= 48000 &&
  90131. (
  90132. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90133. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90134. )
  90135. ) {
  90136. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90137. }
  90138. }
  90139. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90140. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90141. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90142. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90143. #if FLAC__HAS_OGG
  90144. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90145. unsigned i;
  90146. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90147. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90148. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90149. for( ; i > 0; i--)
  90150. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90151. encoder->protected_->metadata[0] = vc;
  90152. break;
  90153. }
  90154. }
  90155. }
  90156. #endif
  90157. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90158. unsigned i;
  90159. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90160. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90161. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90162. break; /* take only the first one */
  90163. }
  90164. }
  90165. }
  90166. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90167. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90168. metadata_has_seektable = false;
  90169. metadata_has_vorbis_comment = false;
  90170. metadata_picture_has_type1 = false;
  90171. metadata_picture_has_type2 = false;
  90172. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90173. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90174. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90175. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90176. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90177. if(metadata_has_seektable) /* only one is allowed */
  90178. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90179. metadata_has_seektable = true;
  90180. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90181. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90182. }
  90183. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90184. if(metadata_has_vorbis_comment) /* only one is allowed */
  90185. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90186. metadata_has_vorbis_comment = true;
  90187. }
  90188. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90189. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90190. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90191. }
  90192. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90193. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90194. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90195. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90196. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90197. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90198. metadata_picture_has_type1 = true;
  90199. if(
  90200. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90201. (
  90202. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90203. m->data.picture.width != 32 ||
  90204. m->data.picture.height != 32
  90205. )
  90206. )
  90207. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90208. }
  90209. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90210. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90211. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90212. metadata_picture_has_type2 = true;
  90213. }
  90214. }
  90215. }
  90216. encoder->private_->input_capacity = 0;
  90217. for(i = 0; i < encoder->protected_->channels; i++) {
  90218. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90219. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90220. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90221. #endif
  90222. }
  90223. for(i = 0; i < 2; i++) {
  90224. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90225. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90226. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90227. #endif
  90228. }
  90229. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90230. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90231. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90232. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90233. #endif
  90234. for(i = 0; i < encoder->protected_->channels; i++) {
  90235. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90236. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90237. encoder->private_->best_subframe[i] = 0;
  90238. }
  90239. for(i = 0; i < 2; i++) {
  90240. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90241. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90242. encoder->private_->best_subframe_mid_side[i] = 0;
  90243. }
  90244. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90245. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90246. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90247. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90248. #else
  90249. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90250. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90251. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90252. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90253. 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);
  90254. #endif
  90255. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90256. encoder->private_->loose_mid_side_stereo_frames = 1;
  90257. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90258. encoder->private_->current_sample_number = 0;
  90259. encoder->private_->current_frame_number = 0;
  90260. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90261. 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? */
  90262. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90263. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90264. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90265. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90266. #endif
  90267. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90268. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90269. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90270. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90271. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90272. #endif
  90273. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90274. # ifndef FLAC__NO_ASM
  90275. if(encoder->private_->cpuinfo.use_asm) {
  90276. # ifdef FLAC__CPU_IA32
  90277. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90278. # ifdef FLAC__HAS_NASM
  90279. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90280. if(encoder->protected_->max_lpc_order < 4)
  90281. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90282. else if(encoder->protected_->max_lpc_order < 8)
  90283. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90284. else if(encoder->protected_->max_lpc_order < 12)
  90285. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90286. else
  90287. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90288. }
  90289. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90290. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90291. else
  90292. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90293. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90294. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90295. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90296. }
  90297. else {
  90298. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90299. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90300. }
  90301. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90302. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90303. # endif /* FLAC__HAS_NASM */
  90304. # endif /* FLAC__CPU_IA32 */
  90305. }
  90306. # endif /* !FLAC__NO_ASM */
  90307. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90308. if(encoder->private_->use_wide_by_block) {
  90309. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90310. }
  90311. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90312. #if FLAC__HAS_OGG
  90313. encoder->private_->is_ogg = is_ogg;
  90314. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90315. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90316. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90317. }
  90318. #endif
  90319. encoder->private_->read_callback = read_callback;
  90320. encoder->private_->write_callback = write_callback;
  90321. encoder->private_->seek_callback = seek_callback;
  90322. encoder->private_->tell_callback = tell_callback;
  90323. encoder->private_->metadata_callback = metadata_callback;
  90324. encoder->private_->client_data = client_data;
  90325. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90326. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90327. }
  90328. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90329. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90330. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90331. }
  90332. if(encoder->protected_->verify) {
  90333. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90334. for(i = 0; i < encoder->protected_->channels; i++) {
  90335. 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))) {
  90336. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90337. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90338. }
  90339. }
  90340. encoder->private_->verify.input_fifo.tail = 0;
  90341. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90342. if(0 == encoder->private_->verify.decoder) {
  90343. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90344. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90345. }
  90346. 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) {
  90347. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90348. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90349. }
  90350. }
  90351. encoder->private_->verify.error_stats.absolute_sample = 0;
  90352. encoder->private_->verify.error_stats.frame_number = 0;
  90353. encoder->private_->verify.error_stats.channel = 0;
  90354. encoder->private_->verify.error_stats.sample = 0;
  90355. encoder->private_->verify.error_stats.expected = 0;
  90356. encoder->private_->verify.error_stats.got = 0;
  90357. encoder->private_->first_seekpoint_to_check = 0;
  90358. encoder->private_->samples_written = 0;
  90359. encoder->protected_->streaminfo_offset = 0;
  90360. encoder->protected_->seektable_offset = 0;
  90361. encoder->protected_->audio_offset = 0;
  90362. if(encoder->protected_->verify)
  90363. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90364. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90365. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90366. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90367. }
  90368. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90369. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90370. }
  90371. if(encoder->protected_->verify)
  90372. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90373. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90374. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90375. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90376. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90377. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90378. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90379. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90380. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90381. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90382. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90383. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90384. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90385. if(encoder->protected_->do_md5)
  90386. FLAC__MD5Init(&encoder->private_->md5context);
  90387. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90388. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90389. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90390. }
  90391. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90392. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90393. }
  90394. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90395. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90396. if(!metadata_has_vorbis_comment) {
  90397. FLAC__StreamMetadata vorbis_comment;
  90398. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90399. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90400. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90401. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90402. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90403. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90404. vorbis_comment.data.vorbis_comment.comments = 0;
  90405. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90406. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90407. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90408. }
  90409. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90410. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90411. }
  90412. }
  90413. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90414. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90415. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90416. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90417. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90418. }
  90419. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90420. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90421. }
  90422. }
  90423. 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 */
  90424. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90425. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90426. }
  90427. if(encoder->protected_->verify)
  90428. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90429. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90430. }
  90431. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90432. FLAC__StreamEncoder *encoder,
  90433. FLAC__StreamEncoderWriteCallback write_callback,
  90434. FLAC__StreamEncoderSeekCallback seek_callback,
  90435. FLAC__StreamEncoderTellCallback tell_callback,
  90436. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90437. void *client_data
  90438. )
  90439. {
  90440. return init_stream_internal_enc(
  90441. encoder,
  90442. 0,
  90443. write_callback,
  90444. seek_callback,
  90445. tell_callback,
  90446. metadata_callback,
  90447. client_data,
  90448. false
  90449. );
  90450. }
  90451. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90452. FLAC__StreamEncoder *encoder,
  90453. FLAC__StreamEncoderReadCallback read_callback,
  90454. FLAC__StreamEncoderWriteCallback write_callback,
  90455. FLAC__StreamEncoderSeekCallback seek_callback,
  90456. FLAC__StreamEncoderTellCallback tell_callback,
  90457. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90458. void *client_data
  90459. )
  90460. {
  90461. return init_stream_internal_enc(
  90462. encoder,
  90463. read_callback,
  90464. write_callback,
  90465. seek_callback,
  90466. tell_callback,
  90467. metadata_callback,
  90468. client_data,
  90469. true
  90470. );
  90471. }
  90472. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90473. FLAC__StreamEncoder *encoder,
  90474. FILE *file,
  90475. FLAC__StreamEncoderProgressCallback progress_callback,
  90476. void *client_data,
  90477. FLAC__bool is_ogg
  90478. )
  90479. {
  90480. FLAC__StreamEncoderInitStatus init_status;
  90481. FLAC__ASSERT(0 != encoder);
  90482. FLAC__ASSERT(0 != file);
  90483. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90484. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90485. if(file == 0) {
  90486. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90487. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90488. }
  90489. if(file == stdout)
  90490. file = get_binary_stdout_(); /* just to be safe */
  90491. encoder->private_->file = file;
  90492. encoder->private_->progress_callback = progress_callback;
  90493. encoder->private_->bytes_written = 0;
  90494. encoder->private_->samples_written = 0;
  90495. encoder->private_->frames_written = 0;
  90496. init_status = init_stream_internal_enc(
  90497. encoder,
  90498. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90499. file_write_callback_,
  90500. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90501. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90502. 0,
  90503. client_data,
  90504. is_ogg
  90505. );
  90506. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90507. return init_status;
  90508. }
  90509. {
  90510. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90511. FLAC__ASSERT(blocksize != 0);
  90512. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90513. }
  90514. return init_status;
  90515. }
  90516. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90517. FLAC__StreamEncoder *encoder,
  90518. FILE *file,
  90519. FLAC__StreamEncoderProgressCallback progress_callback,
  90520. void *client_data
  90521. )
  90522. {
  90523. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  90524. }
  90525. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  90526. FLAC__StreamEncoder *encoder,
  90527. FILE *file,
  90528. FLAC__StreamEncoderProgressCallback progress_callback,
  90529. void *client_data
  90530. )
  90531. {
  90532. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  90533. }
  90534. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  90535. FLAC__StreamEncoder *encoder,
  90536. const char *filename,
  90537. FLAC__StreamEncoderProgressCallback progress_callback,
  90538. void *client_data,
  90539. FLAC__bool is_ogg
  90540. )
  90541. {
  90542. FILE *file;
  90543. FLAC__ASSERT(0 != encoder);
  90544. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90545. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90546. file = filename? fopen(filename, "w+b") : stdout;
  90547. if(file == 0) {
  90548. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90549. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90550. }
  90551. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  90552. }
  90553. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  90554. FLAC__StreamEncoder *encoder,
  90555. const char *filename,
  90556. FLAC__StreamEncoderProgressCallback progress_callback,
  90557. void *client_data
  90558. )
  90559. {
  90560. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  90561. }
  90562. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  90563. FLAC__StreamEncoder *encoder,
  90564. const char *filename,
  90565. FLAC__StreamEncoderProgressCallback progress_callback,
  90566. void *client_data
  90567. )
  90568. {
  90569. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  90570. }
  90571. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  90572. {
  90573. FLAC__bool error = false;
  90574. FLAC__ASSERT(0 != encoder);
  90575. FLAC__ASSERT(0 != encoder->private_);
  90576. FLAC__ASSERT(0 != encoder->protected_);
  90577. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  90578. return true;
  90579. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  90580. if(encoder->private_->current_sample_number != 0) {
  90581. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  90582. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  90583. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  90584. error = true;
  90585. }
  90586. }
  90587. if(encoder->protected_->do_md5)
  90588. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  90589. if(!encoder->private_->is_being_deleted) {
  90590. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  90591. if(encoder->private_->seek_callback) {
  90592. #if FLAC__HAS_OGG
  90593. if(encoder->private_->is_ogg)
  90594. update_ogg_metadata_(encoder);
  90595. else
  90596. #endif
  90597. update_metadata_(encoder);
  90598. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  90599. error = true;
  90600. }
  90601. if(encoder->private_->metadata_callback)
  90602. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  90603. }
  90604. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  90605. if(!error)
  90606. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  90607. error = true;
  90608. }
  90609. }
  90610. if(0 != encoder->private_->file) {
  90611. if(encoder->private_->file != stdout)
  90612. fclose(encoder->private_->file);
  90613. encoder->private_->file = 0;
  90614. }
  90615. #if FLAC__HAS_OGG
  90616. if(encoder->private_->is_ogg)
  90617. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  90618. #endif
  90619. free_(encoder);
  90620. set_defaults_enc(encoder);
  90621. if(!error)
  90622. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90623. return !error;
  90624. }
  90625. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  90626. {
  90627. FLAC__ASSERT(0 != encoder);
  90628. FLAC__ASSERT(0 != encoder->private_);
  90629. FLAC__ASSERT(0 != encoder->protected_);
  90630. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90631. return false;
  90632. #if FLAC__HAS_OGG
  90633. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  90634. return true;
  90635. #else
  90636. (void)value;
  90637. return false;
  90638. #endif
  90639. }
  90640. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(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. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  90648. encoder->protected_->verify = value;
  90649. #endif
  90650. return true;
  90651. }
  90652. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90653. {
  90654. FLAC__ASSERT(0 != encoder);
  90655. FLAC__ASSERT(0 != encoder->private_);
  90656. FLAC__ASSERT(0 != encoder->protected_);
  90657. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90658. return false;
  90659. encoder->protected_->streamable_subset = value;
  90660. return true;
  90661. }
  90662. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90663. {
  90664. FLAC__ASSERT(0 != encoder);
  90665. FLAC__ASSERT(0 != encoder->private_);
  90666. FLAC__ASSERT(0 != encoder->protected_);
  90667. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90668. return false;
  90669. encoder->protected_->do_md5 = value;
  90670. return true;
  90671. }
  90672. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  90673. {
  90674. FLAC__ASSERT(0 != encoder);
  90675. FLAC__ASSERT(0 != encoder->private_);
  90676. FLAC__ASSERT(0 != encoder->protected_);
  90677. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90678. return false;
  90679. encoder->protected_->channels = value;
  90680. return true;
  90681. }
  90682. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  90683. {
  90684. FLAC__ASSERT(0 != encoder);
  90685. FLAC__ASSERT(0 != encoder->private_);
  90686. FLAC__ASSERT(0 != encoder->protected_);
  90687. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90688. return false;
  90689. encoder->protected_->bits_per_sample = value;
  90690. return true;
  90691. }
  90692. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  90693. {
  90694. FLAC__ASSERT(0 != encoder);
  90695. FLAC__ASSERT(0 != encoder->private_);
  90696. FLAC__ASSERT(0 != encoder->protected_);
  90697. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90698. return false;
  90699. encoder->protected_->sample_rate = value;
  90700. return true;
  90701. }
  90702. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  90703. {
  90704. FLAC__bool ok = true;
  90705. FLAC__ASSERT(0 != encoder);
  90706. FLAC__ASSERT(0 != encoder->private_);
  90707. FLAC__ASSERT(0 != encoder->protected_);
  90708. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90709. return false;
  90710. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  90711. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  90712. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  90713. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  90714. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90715. #if 0
  90716. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  90717. #else
  90718. encoder->protected_->num_apodizations = 1;
  90719. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90720. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90721. #endif
  90722. #endif
  90723. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  90724. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  90725. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  90726. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  90727. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  90728. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  90729. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  90730. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  90731. return ok;
  90732. }
  90733. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  90734. {
  90735. FLAC__ASSERT(0 != encoder);
  90736. FLAC__ASSERT(0 != encoder->private_);
  90737. FLAC__ASSERT(0 != encoder->protected_);
  90738. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90739. return false;
  90740. encoder->protected_->blocksize = value;
  90741. return true;
  90742. }
  90743. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90744. {
  90745. FLAC__ASSERT(0 != encoder);
  90746. FLAC__ASSERT(0 != encoder->private_);
  90747. FLAC__ASSERT(0 != encoder->protected_);
  90748. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90749. return false;
  90750. encoder->protected_->do_mid_side_stereo = value;
  90751. return true;
  90752. }
  90753. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90754. {
  90755. FLAC__ASSERT(0 != encoder);
  90756. FLAC__ASSERT(0 != encoder->private_);
  90757. FLAC__ASSERT(0 != encoder->protected_);
  90758. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90759. return false;
  90760. encoder->protected_->loose_mid_side_stereo = value;
  90761. return true;
  90762. }
  90763. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  90764. {
  90765. FLAC__ASSERT(0 != encoder);
  90766. FLAC__ASSERT(0 != encoder->private_);
  90767. FLAC__ASSERT(0 != encoder->protected_);
  90768. FLAC__ASSERT(0 != specification);
  90769. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90770. return false;
  90771. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  90772. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  90773. #else
  90774. encoder->protected_->num_apodizations = 0;
  90775. while(1) {
  90776. const char *s = strchr(specification, ';');
  90777. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  90778. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  90779. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  90780. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  90781. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  90782. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  90783. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  90784. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  90785. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  90786. else if(n==6 && 0 == strncmp("connes" , specification, n))
  90787. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  90788. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  90789. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  90790. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  90791. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  90792. if (stddev > 0.0 && stddev <= 0.5) {
  90793. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  90794. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  90795. }
  90796. }
  90797. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  90798. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  90799. else if(n==4 && 0 == strncmp("hann" , specification, n))
  90800. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  90801. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  90802. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  90803. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  90804. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  90805. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  90806. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  90807. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  90808. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  90809. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  90810. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  90811. if (p >= 0.0 && p <= 1.0) {
  90812. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  90813. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  90814. }
  90815. }
  90816. else if(n==5 && 0 == strncmp("welch" , specification, n))
  90817. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  90818. if (encoder->protected_->num_apodizations == 32)
  90819. break;
  90820. if (s)
  90821. specification = s+1;
  90822. else
  90823. break;
  90824. }
  90825. if(encoder->protected_->num_apodizations == 0) {
  90826. encoder->protected_->num_apodizations = 1;
  90827. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90828. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90829. }
  90830. #endif
  90831. return true;
  90832. }
  90833. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  90834. {
  90835. FLAC__ASSERT(0 != encoder);
  90836. FLAC__ASSERT(0 != encoder->private_);
  90837. FLAC__ASSERT(0 != encoder->protected_);
  90838. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90839. return false;
  90840. encoder->protected_->max_lpc_order = value;
  90841. return true;
  90842. }
  90843. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  90844. {
  90845. FLAC__ASSERT(0 != encoder);
  90846. FLAC__ASSERT(0 != encoder->private_);
  90847. FLAC__ASSERT(0 != encoder->protected_);
  90848. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90849. return false;
  90850. encoder->protected_->qlp_coeff_precision = value;
  90851. return true;
  90852. }
  90853. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90854. {
  90855. FLAC__ASSERT(0 != encoder);
  90856. FLAC__ASSERT(0 != encoder->private_);
  90857. FLAC__ASSERT(0 != encoder->protected_);
  90858. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90859. return false;
  90860. encoder->protected_->do_qlp_coeff_prec_search = value;
  90861. return true;
  90862. }
  90863. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90864. {
  90865. FLAC__ASSERT(0 != encoder);
  90866. FLAC__ASSERT(0 != encoder->private_);
  90867. FLAC__ASSERT(0 != encoder->protected_);
  90868. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90869. return false;
  90870. #if 0
  90871. encoder->protected_->do_escape_coding = value;
  90872. #else
  90873. (void)value;
  90874. #endif
  90875. return true;
  90876. }
  90877. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90878. {
  90879. FLAC__ASSERT(0 != encoder);
  90880. FLAC__ASSERT(0 != encoder->private_);
  90881. FLAC__ASSERT(0 != encoder->protected_);
  90882. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90883. return false;
  90884. encoder->protected_->do_exhaustive_model_search = value;
  90885. return true;
  90886. }
  90887. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90888. {
  90889. FLAC__ASSERT(0 != encoder);
  90890. FLAC__ASSERT(0 != encoder->private_);
  90891. FLAC__ASSERT(0 != encoder->protected_);
  90892. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90893. return false;
  90894. encoder->protected_->min_residual_partition_order = value;
  90895. return true;
  90896. }
  90897. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90898. {
  90899. FLAC__ASSERT(0 != encoder);
  90900. FLAC__ASSERT(0 != encoder->private_);
  90901. FLAC__ASSERT(0 != encoder->protected_);
  90902. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90903. return false;
  90904. encoder->protected_->max_residual_partition_order = value;
  90905. return true;
  90906. }
  90907. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  90908. {
  90909. FLAC__ASSERT(0 != encoder);
  90910. FLAC__ASSERT(0 != encoder->private_);
  90911. FLAC__ASSERT(0 != encoder->protected_);
  90912. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90913. return false;
  90914. #if 0
  90915. encoder->protected_->rice_parameter_search_dist = value;
  90916. #else
  90917. (void)value;
  90918. #endif
  90919. return true;
  90920. }
  90921. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  90922. {
  90923. FLAC__ASSERT(0 != encoder);
  90924. FLAC__ASSERT(0 != encoder->private_);
  90925. FLAC__ASSERT(0 != encoder->protected_);
  90926. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90927. return false;
  90928. encoder->protected_->total_samples_estimate = value;
  90929. return true;
  90930. }
  90931. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  90932. {
  90933. FLAC__ASSERT(0 != encoder);
  90934. FLAC__ASSERT(0 != encoder->private_);
  90935. FLAC__ASSERT(0 != encoder->protected_);
  90936. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90937. return false;
  90938. if(0 == metadata)
  90939. num_blocks = 0;
  90940. if(0 == num_blocks)
  90941. metadata = 0;
  90942. if(encoder->protected_->metadata) {
  90943. free(encoder->protected_->metadata);
  90944. encoder->protected_->metadata = 0;
  90945. encoder->protected_->num_metadata_blocks = 0;
  90946. }
  90947. if(num_blocks) {
  90948. FLAC__StreamMetadata **m;
  90949. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  90950. return false;
  90951. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  90952. encoder->protected_->metadata = m;
  90953. encoder->protected_->num_metadata_blocks = num_blocks;
  90954. }
  90955. #if FLAC__HAS_OGG
  90956. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  90957. return false;
  90958. #endif
  90959. return true;
  90960. }
  90961. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90962. {
  90963. FLAC__ASSERT(0 != encoder);
  90964. FLAC__ASSERT(0 != encoder->private_);
  90965. FLAC__ASSERT(0 != encoder->protected_);
  90966. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90967. return false;
  90968. encoder->private_->disable_constant_subframes = value;
  90969. return true;
  90970. }
  90971. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90972. {
  90973. FLAC__ASSERT(0 != encoder);
  90974. FLAC__ASSERT(0 != encoder->private_);
  90975. FLAC__ASSERT(0 != encoder->protected_);
  90976. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90977. return false;
  90978. encoder->private_->disable_fixed_subframes = value;
  90979. return true;
  90980. }
  90981. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90982. {
  90983. FLAC__ASSERT(0 != encoder);
  90984. FLAC__ASSERT(0 != encoder->private_);
  90985. FLAC__ASSERT(0 != encoder->protected_);
  90986. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90987. return false;
  90988. encoder->private_->disable_verbatim_subframes = value;
  90989. return true;
  90990. }
  90991. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  90992. {
  90993. FLAC__ASSERT(0 != encoder);
  90994. FLAC__ASSERT(0 != encoder->private_);
  90995. FLAC__ASSERT(0 != encoder->protected_);
  90996. return encoder->protected_->state;
  90997. }
  90998. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  90999. {
  91000. FLAC__ASSERT(0 != encoder);
  91001. FLAC__ASSERT(0 != encoder->private_);
  91002. FLAC__ASSERT(0 != encoder->protected_);
  91003. if(encoder->protected_->verify)
  91004. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  91005. else
  91006. return FLAC__STREAM_DECODER_UNINITIALIZED;
  91007. }
  91008. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  91009. {
  91010. FLAC__ASSERT(0 != encoder);
  91011. FLAC__ASSERT(0 != encoder->private_);
  91012. FLAC__ASSERT(0 != encoder->protected_);
  91013. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  91014. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91015. else
  91016. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91017. }
  91018. 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)
  91019. {
  91020. FLAC__ASSERT(0 != encoder);
  91021. FLAC__ASSERT(0 != encoder->private_);
  91022. FLAC__ASSERT(0 != encoder->protected_);
  91023. if(0 != absolute_sample)
  91024. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91025. if(0 != frame_number)
  91026. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91027. if(0 != channel)
  91028. *channel = encoder->private_->verify.error_stats.channel;
  91029. if(0 != sample)
  91030. *sample = encoder->private_->verify.error_stats.sample;
  91031. if(0 != expected)
  91032. *expected = encoder->private_->verify.error_stats.expected;
  91033. if(0 != got)
  91034. *got = encoder->private_->verify.error_stats.got;
  91035. }
  91036. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91037. {
  91038. FLAC__ASSERT(0 != encoder);
  91039. FLAC__ASSERT(0 != encoder->private_);
  91040. FLAC__ASSERT(0 != encoder->protected_);
  91041. return encoder->protected_->verify;
  91042. }
  91043. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91044. {
  91045. FLAC__ASSERT(0 != encoder);
  91046. FLAC__ASSERT(0 != encoder->private_);
  91047. FLAC__ASSERT(0 != encoder->protected_);
  91048. return encoder->protected_->streamable_subset;
  91049. }
  91050. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91051. {
  91052. FLAC__ASSERT(0 != encoder);
  91053. FLAC__ASSERT(0 != encoder->private_);
  91054. FLAC__ASSERT(0 != encoder->protected_);
  91055. return encoder->protected_->do_md5;
  91056. }
  91057. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91058. {
  91059. FLAC__ASSERT(0 != encoder);
  91060. FLAC__ASSERT(0 != encoder->private_);
  91061. FLAC__ASSERT(0 != encoder->protected_);
  91062. return encoder->protected_->channels;
  91063. }
  91064. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91065. {
  91066. FLAC__ASSERT(0 != encoder);
  91067. FLAC__ASSERT(0 != encoder->private_);
  91068. FLAC__ASSERT(0 != encoder->protected_);
  91069. return encoder->protected_->bits_per_sample;
  91070. }
  91071. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91072. {
  91073. FLAC__ASSERT(0 != encoder);
  91074. FLAC__ASSERT(0 != encoder->private_);
  91075. FLAC__ASSERT(0 != encoder->protected_);
  91076. return encoder->protected_->sample_rate;
  91077. }
  91078. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91079. {
  91080. FLAC__ASSERT(0 != encoder);
  91081. FLAC__ASSERT(0 != encoder->private_);
  91082. FLAC__ASSERT(0 != encoder->protected_);
  91083. return encoder->protected_->blocksize;
  91084. }
  91085. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91086. {
  91087. FLAC__ASSERT(0 != encoder);
  91088. FLAC__ASSERT(0 != encoder->private_);
  91089. FLAC__ASSERT(0 != encoder->protected_);
  91090. return encoder->protected_->do_mid_side_stereo;
  91091. }
  91092. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91093. {
  91094. FLAC__ASSERT(0 != encoder);
  91095. FLAC__ASSERT(0 != encoder->private_);
  91096. FLAC__ASSERT(0 != encoder->protected_);
  91097. return encoder->protected_->loose_mid_side_stereo;
  91098. }
  91099. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91100. {
  91101. FLAC__ASSERT(0 != encoder);
  91102. FLAC__ASSERT(0 != encoder->private_);
  91103. FLAC__ASSERT(0 != encoder->protected_);
  91104. return encoder->protected_->max_lpc_order;
  91105. }
  91106. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91107. {
  91108. FLAC__ASSERT(0 != encoder);
  91109. FLAC__ASSERT(0 != encoder->private_);
  91110. FLAC__ASSERT(0 != encoder->protected_);
  91111. return encoder->protected_->qlp_coeff_precision;
  91112. }
  91113. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91114. {
  91115. FLAC__ASSERT(0 != encoder);
  91116. FLAC__ASSERT(0 != encoder->private_);
  91117. FLAC__ASSERT(0 != encoder->protected_);
  91118. return encoder->protected_->do_qlp_coeff_prec_search;
  91119. }
  91120. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91121. {
  91122. FLAC__ASSERT(0 != encoder);
  91123. FLAC__ASSERT(0 != encoder->private_);
  91124. FLAC__ASSERT(0 != encoder->protected_);
  91125. return encoder->protected_->do_escape_coding;
  91126. }
  91127. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91128. {
  91129. FLAC__ASSERT(0 != encoder);
  91130. FLAC__ASSERT(0 != encoder->private_);
  91131. FLAC__ASSERT(0 != encoder->protected_);
  91132. return encoder->protected_->do_exhaustive_model_search;
  91133. }
  91134. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91135. {
  91136. FLAC__ASSERT(0 != encoder);
  91137. FLAC__ASSERT(0 != encoder->private_);
  91138. FLAC__ASSERT(0 != encoder->protected_);
  91139. return encoder->protected_->min_residual_partition_order;
  91140. }
  91141. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91142. {
  91143. FLAC__ASSERT(0 != encoder);
  91144. FLAC__ASSERT(0 != encoder->private_);
  91145. FLAC__ASSERT(0 != encoder->protected_);
  91146. return encoder->protected_->max_residual_partition_order;
  91147. }
  91148. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91149. {
  91150. FLAC__ASSERT(0 != encoder);
  91151. FLAC__ASSERT(0 != encoder->private_);
  91152. FLAC__ASSERT(0 != encoder->protected_);
  91153. return encoder->protected_->rice_parameter_search_dist;
  91154. }
  91155. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91156. {
  91157. FLAC__ASSERT(0 != encoder);
  91158. FLAC__ASSERT(0 != encoder->private_);
  91159. FLAC__ASSERT(0 != encoder->protected_);
  91160. return encoder->protected_->total_samples_estimate;
  91161. }
  91162. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91163. {
  91164. unsigned i, j = 0, channel;
  91165. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91166. FLAC__ASSERT(0 != encoder);
  91167. FLAC__ASSERT(0 != encoder->private_);
  91168. FLAC__ASSERT(0 != encoder->protected_);
  91169. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91170. do {
  91171. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91172. if(encoder->protected_->verify)
  91173. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91174. for(channel = 0; channel < channels; channel++)
  91175. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91176. if(encoder->protected_->do_mid_side_stereo) {
  91177. FLAC__ASSERT(channels == 2);
  91178. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91179. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91180. 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' ! */
  91181. }
  91182. }
  91183. else
  91184. j += n;
  91185. encoder->private_->current_sample_number += n;
  91186. if(encoder->private_->current_sample_number > blocksize) {
  91187. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91188. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91189. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91190. return false;
  91191. for(channel = 0; channel < channels; channel++)
  91192. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91193. if(encoder->protected_->do_mid_side_stereo) {
  91194. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91195. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91196. }
  91197. encoder->private_->current_sample_number = 1;
  91198. }
  91199. } while(j < samples);
  91200. return true;
  91201. }
  91202. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91203. {
  91204. unsigned i, j, k, channel;
  91205. FLAC__int32 x, mid, side;
  91206. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91207. FLAC__ASSERT(0 != encoder);
  91208. FLAC__ASSERT(0 != encoder->private_);
  91209. FLAC__ASSERT(0 != encoder->protected_);
  91210. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91211. j = k = 0;
  91212. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91213. do {
  91214. if(encoder->protected_->verify)
  91215. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91216. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91217. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91218. x = buffer[k++];
  91219. encoder->private_->integer_signal[1][i] = x;
  91220. mid += x;
  91221. side -= x;
  91222. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91223. encoder->private_->integer_signal_mid_side[1][i] = side;
  91224. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91225. }
  91226. encoder->private_->current_sample_number = i;
  91227. if(i > blocksize) {
  91228. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91229. return false;
  91230. /* move unprocessed overread samples to beginnings of arrays */
  91231. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91232. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91233. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91234. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91235. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91236. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91237. encoder->private_->current_sample_number = 1;
  91238. }
  91239. } while(j < samples);
  91240. }
  91241. else {
  91242. do {
  91243. if(encoder->protected_->verify)
  91244. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91245. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91246. for(channel = 0; channel < channels; channel++)
  91247. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91248. }
  91249. encoder->private_->current_sample_number = i;
  91250. if(i > blocksize) {
  91251. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91252. return false;
  91253. /* move unprocessed overread samples to beginnings of arrays */
  91254. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91255. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91256. for(channel = 0; channel < channels; channel++)
  91257. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91258. encoder->private_->current_sample_number = 1;
  91259. }
  91260. } while(j < samples);
  91261. }
  91262. return true;
  91263. }
  91264. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91265. {
  91266. FLAC__ASSERT(0 != encoder);
  91267. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91268. encoder->protected_->verify = true;
  91269. #else
  91270. encoder->protected_->verify = false;
  91271. #endif
  91272. encoder->protected_->streamable_subset = true;
  91273. encoder->protected_->do_md5 = true;
  91274. encoder->protected_->do_mid_side_stereo = false;
  91275. encoder->protected_->loose_mid_side_stereo = false;
  91276. encoder->protected_->channels = 2;
  91277. encoder->protected_->bits_per_sample = 16;
  91278. encoder->protected_->sample_rate = 44100;
  91279. encoder->protected_->blocksize = 0;
  91280. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91281. encoder->protected_->num_apodizations = 1;
  91282. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91283. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91284. #endif
  91285. encoder->protected_->max_lpc_order = 0;
  91286. encoder->protected_->qlp_coeff_precision = 0;
  91287. encoder->protected_->do_qlp_coeff_prec_search = false;
  91288. encoder->protected_->do_exhaustive_model_search = false;
  91289. encoder->protected_->do_escape_coding = false;
  91290. encoder->protected_->min_residual_partition_order = 0;
  91291. encoder->protected_->max_residual_partition_order = 0;
  91292. encoder->protected_->rice_parameter_search_dist = 0;
  91293. encoder->protected_->total_samples_estimate = 0;
  91294. encoder->protected_->metadata = 0;
  91295. encoder->protected_->num_metadata_blocks = 0;
  91296. encoder->private_->seek_table = 0;
  91297. encoder->private_->disable_constant_subframes = false;
  91298. encoder->private_->disable_fixed_subframes = false;
  91299. encoder->private_->disable_verbatim_subframes = false;
  91300. #if FLAC__HAS_OGG
  91301. encoder->private_->is_ogg = false;
  91302. #endif
  91303. encoder->private_->read_callback = 0;
  91304. encoder->private_->write_callback = 0;
  91305. encoder->private_->seek_callback = 0;
  91306. encoder->private_->tell_callback = 0;
  91307. encoder->private_->metadata_callback = 0;
  91308. encoder->private_->progress_callback = 0;
  91309. encoder->private_->client_data = 0;
  91310. #if FLAC__HAS_OGG
  91311. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91312. #endif
  91313. }
  91314. void free_(FLAC__StreamEncoder *encoder)
  91315. {
  91316. unsigned i, channel;
  91317. FLAC__ASSERT(0 != encoder);
  91318. if(encoder->protected_->metadata) {
  91319. free(encoder->protected_->metadata);
  91320. encoder->protected_->metadata = 0;
  91321. encoder->protected_->num_metadata_blocks = 0;
  91322. }
  91323. for(i = 0; i < encoder->protected_->channels; i++) {
  91324. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91325. free(encoder->private_->integer_signal_unaligned[i]);
  91326. encoder->private_->integer_signal_unaligned[i] = 0;
  91327. }
  91328. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91329. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91330. free(encoder->private_->real_signal_unaligned[i]);
  91331. encoder->private_->real_signal_unaligned[i] = 0;
  91332. }
  91333. #endif
  91334. }
  91335. for(i = 0; i < 2; i++) {
  91336. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91337. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91338. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91339. }
  91340. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91341. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91342. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91343. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91344. }
  91345. #endif
  91346. }
  91347. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91348. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91349. if(0 != encoder->private_->window_unaligned[i]) {
  91350. free(encoder->private_->window_unaligned[i]);
  91351. encoder->private_->window_unaligned[i] = 0;
  91352. }
  91353. }
  91354. if(0 != encoder->private_->windowed_signal_unaligned) {
  91355. free(encoder->private_->windowed_signal_unaligned);
  91356. encoder->private_->windowed_signal_unaligned = 0;
  91357. }
  91358. #endif
  91359. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91360. for(i = 0; i < 2; i++) {
  91361. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91362. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91363. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91364. }
  91365. }
  91366. }
  91367. for(channel = 0; channel < 2; channel++) {
  91368. for(i = 0; i < 2; i++) {
  91369. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91370. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91371. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91372. }
  91373. }
  91374. }
  91375. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91376. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91377. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91378. }
  91379. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91380. free(encoder->private_->raw_bits_per_partition_unaligned);
  91381. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91382. }
  91383. if(encoder->protected_->verify) {
  91384. for(i = 0; i < encoder->protected_->channels; i++) {
  91385. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91386. free(encoder->private_->verify.input_fifo.data[i]);
  91387. encoder->private_->verify.input_fifo.data[i] = 0;
  91388. }
  91389. }
  91390. }
  91391. FLAC__bitwriter_free(encoder->private_->frame);
  91392. }
  91393. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91394. {
  91395. FLAC__bool ok;
  91396. unsigned i, channel;
  91397. FLAC__ASSERT(new_blocksize > 0);
  91398. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91399. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91400. if(new_blocksize <= encoder->private_->input_capacity)
  91401. return true;
  91402. ok = true;
  91403. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91404. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91405. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91406. encoder->private_->integer_signal[i] += 4;
  91407. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91408. #if 0 /* @@@ currently unused */
  91409. if(encoder->protected_->max_lpc_order > 0)
  91410. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91411. #endif
  91412. #endif
  91413. }
  91414. for(i = 0; ok && i < 2; i++) {
  91415. 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]);
  91416. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91417. encoder->private_->integer_signal_mid_side[i] += 4;
  91418. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91419. #if 0 /* @@@ currently unused */
  91420. if(encoder->protected_->max_lpc_order > 0)
  91421. 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]);
  91422. #endif
  91423. #endif
  91424. }
  91425. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91426. if(ok && encoder->protected_->max_lpc_order > 0) {
  91427. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91428. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91429. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91430. }
  91431. #endif
  91432. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91433. for(i = 0; ok && i < 2; i++) {
  91434. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91435. }
  91436. }
  91437. for(channel = 0; ok && channel < 2; channel++) {
  91438. for(i = 0; ok && i < 2; i++) {
  91439. 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]);
  91440. }
  91441. }
  91442. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91443. if(encoder->protected_->do_escape_coding)
  91444. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91445. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91446. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91447. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91448. switch(encoder->protected_->apodizations[i].type) {
  91449. case FLAC__APODIZATION_BARTLETT:
  91450. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91451. break;
  91452. case FLAC__APODIZATION_BARTLETT_HANN:
  91453. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91454. break;
  91455. case FLAC__APODIZATION_BLACKMAN:
  91456. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91457. break;
  91458. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91459. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91460. break;
  91461. case FLAC__APODIZATION_CONNES:
  91462. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91463. break;
  91464. case FLAC__APODIZATION_FLATTOP:
  91465. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91466. break;
  91467. case FLAC__APODIZATION_GAUSS:
  91468. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91469. break;
  91470. case FLAC__APODIZATION_HAMMING:
  91471. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91472. break;
  91473. case FLAC__APODIZATION_HANN:
  91474. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91475. break;
  91476. case FLAC__APODIZATION_KAISER_BESSEL:
  91477. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91478. break;
  91479. case FLAC__APODIZATION_NUTTALL:
  91480. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91481. break;
  91482. case FLAC__APODIZATION_RECTANGLE:
  91483. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91484. break;
  91485. case FLAC__APODIZATION_TRIANGLE:
  91486. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91487. break;
  91488. case FLAC__APODIZATION_TUKEY:
  91489. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91490. break;
  91491. case FLAC__APODIZATION_WELCH:
  91492. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91493. break;
  91494. default:
  91495. FLAC__ASSERT(0);
  91496. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91497. break;
  91498. }
  91499. }
  91500. }
  91501. #endif
  91502. if(ok)
  91503. encoder->private_->input_capacity = new_blocksize;
  91504. else
  91505. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91506. return ok;
  91507. }
  91508. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91509. {
  91510. const FLAC__byte *buffer;
  91511. size_t bytes;
  91512. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91513. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91514. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91515. return false;
  91516. }
  91517. if(encoder->protected_->verify) {
  91518. encoder->private_->verify.output.data = buffer;
  91519. encoder->private_->verify.output.bytes = bytes;
  91520. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91521. encoder->private_->verify.needs_magic_hack = true;
  91522. }
  91523. else {
  91524. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  91525. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91526. FLAC__bitwriter_clear(encoder->private_->frame);
  91527. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  91528. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91529. return false;
  91530. }
  91531. }
  91532. }
  91533. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91534. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91535. FLAC__bitwriter_clear(encoder->private_->frame);
  91536. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91537. return false;
  91538. }
  91539. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91540. FLAC__bitwriter_clear(encoder->private_->frame);
  91541. if(samples > 0) {
  91542. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  91543. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  91544. }
  91545. return true;
  91546. }
  91547. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  91548. {
  91549. FLAC__StreamEncoderWriteStatus status;
  91550. FLAC__uint64 output_position = 0;
  91551. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  91552. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91553. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  91554. }
  91555. if(samples == 0) {
  91556. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  91557. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  91558. encoder->protected_->streaminfo_offset = output_position;
  91559. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  91560. encoder->protected_->seektable_offset = output_position;
  91561. }
  91562. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  91563. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91564. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  91565. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  91566. FLAC__uint64 test_sample;
  91567. unsigned i;
  91568. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  91569. test_sample = encoder->private_->seek_table->points[i].sample_number;
  91570. if(test_sample > frame_last_sample) {
  91571. break;
  91572. }
  91573. else if(test_sample >= frame_first_sample) {
  91574. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  91575. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  91576. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  91577. encoder->private_->first_seekpoint_to_check++;
  91578. }
  91579. else {
  91580. encoder->private_->first_seekpoint_to_check++;
  91581. }
  91582. }
  91583. }
  91584. #if FLAC__HAS_OGG
  91585. if(encoder->private_->is_ogg) {
  91586. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  91587. &encoder->protected_->ogg_encoder_aspect,
  91588. buffer,
  91589. bytes,
  91590. samples,
  91591. encoder->private_->current_frame_number,
  91592. is_last_block,
  91593. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  91594. encoder,
  91595. encoder->private_->client_data
  91596. );
  91597. }
  91598. else
  91599. #endif
  91600. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  91601. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91602. encoder->private_->bytes_written += bytes;
  91603. encoder->private_->samples_written += samples;
  91604. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  91605. }
  91606. else
  91607. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91608. return status;
  91609. }
  91610. void update_metadata_(const FLAC__StreamEncoder *encoder)
  91611. {
  91612. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91613. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91614. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91615. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91616. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91617. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  91618. FLAC__StreamEncoderSeekStatus seek_status;
  91619. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91620. {
  91621. const unsigned md5_offset =
  91622. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91623. (
  91624. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91625. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91626. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91627. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91628. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91629. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91630. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91631. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91632. ) / 8;
  91633. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91634. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91635. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91636. return;
  91637. }
  91638. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91639. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91640. return;
  91641. }
  91642. }
  91643. {
  91644. const unsigned total_samples_byte_offset =
  91645. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91646. (
  91647. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91648. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91649. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91650. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91651. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91652. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91653. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91654. - 4
  91655. ) / 8;
  91656. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  91657. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91658. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91659. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91660. b[4] = (FLAC__byte)(samples & 0xFF);
  91661. 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) {
  91662. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91663. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91664. return;
  91665. }
  91666. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91667. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91668. return;
  91669. }
  91670. }
  91671. {
  91672. const unsigned min_framesize_offset =
  91673. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91674. (
  91675. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91676. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91677. ) / 8;
  91678. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91679. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91680. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91681. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91682. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91683. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91684. 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) {
  91685. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91686. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91687. return;
  91688. }
  91689. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91690. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91691. return;
  91692. }
  91693. }
  91694. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91695. unsigned i;
  91696. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91697. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91698. 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) {
  91699. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91700. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91701. return;
  91702. }
  91703. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  91704. FLAC__uint64 xx;
  91705. unsigned x;
  91706. xx = encoder->private_->seek_table->points[i].sample_number;
  91707. b[7] = (FLAC__byte)xx; xx >>= 8;
  91708. b[6] = (FLAC__byte)xx; xx >>= 8;
  91709. b[5] = (FLAC__byte)xx; xx >>= 8;
  91710. b[4] = (FLAC__byte)xx; xx >>= 8;
  91711. b[3] = (FLAC__byte)xx; xx >>= 8;
  91712. b[2] = (FLAC__byte)xx; xx >>= 8;
  91713. b[1] = (FLAC__byte)xx; xx >>= 8;
  91714. b[0] = (FLAC__byte)xx; xx >>= 8;
  91715. xx = encoder->private_->seek_table->points[i].stream_offset;
  91716. b[15] = (FLAC__byte)xx; xx >>= 8;
  91717. b[14] = (FLAC__byte)xx; xx >>= 8;
  91718. b[13] = (FLAC__byte)xx; xx >>= 8;
  91719. b[12] = (FLAC__byte)xx; xx >>= 8;
  91720. b[11] = (FLAC__byte)xx; xx >>= 8;
  91721. b[10] = (FLAC__byte)xx; xx >>= 8;
  91722. b[9] = (FLAC__byte)xx; xx >>= 8;
  91723. b[8] = (FLAC__byte)xx; xx >>= 8;
  91724. x = encoder->private_->seek_table->points[i].frame_samples;
  91725. b[17] = (FLAC__byte)x; x >>= 8;
  91726. b[16] = (FLAC__byte)x; x >>= 8;
  91727. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91728. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91729. return;
  91730. }
  91731. }
  91732. }
  91733. }
  91734. #if FLAC__HAS_OGG
  91735. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  91736. {
  91737. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  91738. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  91739. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  91740. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  91741. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  91742. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  91743. FLAC__STREAM_SYNC_LENGTH
  91744. ;
  91745. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91746. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91747. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91748. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91749. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91750. ogg_page page;
  91751. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91752. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  91753. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  91754. return;
  91755. simple_ogg_page__init(&page);
  91756. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91757. simple_ogg_page__clear(&page);
  91758. return; /* state already set */
  91759. }
  91760. {
  91761. const unsigned md5_offset =
  91762. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91763. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91764. (
  91765. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91766. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91767. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91768. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91769. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91770. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91771. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91772. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91773. ) / 8;
  91774. if(md5_offset + 16 > (unsigned)page.body_len) {
  91775. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91776. simple_ogg_page__clear(&page);
  91777. return;
  91778. }
  91779. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  91780. }
  91781. {
  91782. const unsigned total_samples_byte_offset =
  91783. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91784. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91785. (
  91786. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91787. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91788. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91789. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91790. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91791. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91792. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91793. - 4
  91794. ) / 8;
  91795. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  91796. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91797. simple_ogg_page__clear(&page);
  91798. return;
  91799. }
  91800. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  91801. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  91802. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91803. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91804. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91805. b[4] = (FLAC__byte)(samples & 0xFF);
  91806. memcpy(page.body + total_samples_byte_offset, b, 5);
  91807. }
  91808. {
  91809. const unsigned min_framesize_offset =
  91810. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91811. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91812. (
  91813. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91814. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91815. ) / 8;
  91816. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  91817. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91818. simple_ogg_page__clear(&page);
  91819. return;
  91820. }
  91821. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91822. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91823. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91824. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91825. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91826. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91827. memcpy(page.body + min_framesize_offset, b, 6);
  91828. }
  91829. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91830. simple_ogg_page__clear(&page);
  91831. return; /* state already set */
  91832. }
  91833. simple_ogg_page__clear(&page);
  91834. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91835. unsigned i;
  91836. FLAC__byte *p;
  91837. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91838. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91839. simple_ogg_page__init(&page);
  91840. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91841. simple_ogg_page__clear(&page);
  91842. return; /* state already set */
  91843. }
  91844. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  91845. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91846. simple_ogg_page__clear(&page);
  91847. return;
  91848. }
  91849. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  91850. FLAC__uint64 xx;
  91851. unsigned x;
  91852. xx = encoder->private_->seek_table->points[i].sample_number;
  91853. b[7] = (FLAC__byte)xx; xx >>= 8;
  91854. b[6] = (FLAC__byte)xx; xx >>= 8;
  91855. b[5] = (FLAC__byte)xx; xx >>= 8;
  91856. b[4] = (FLAC__byte)xx; xx >>= 8;
  91857. b[3] = (FLAC__byte)xx; xx >>= 8;
  91858. b[2] = (FLAC__byte)xx; xx >>= 8;
  91859. b[1] = (FLAC__byte)xx; xx >>= 8;
  91860. b[0] = (FLAC__byte)xx; xx >>= 8;
  91861. xx = encoder->private_->seek_table->points[i].stream_offset;
  91862. b[15] = (FLAC__byte)xx; xx >>= 8;
  91863. b[14] = (FLAC__byte)xx; xx >>= 8;
  91864. b[13] = (FLAC__byte)xx; xx >>= 8;
  91865. b[12] = (FLAC__byte)xx; xx >>= 8;
  91866. b[11] = (FLAC__byte)xx; xx >>= 8;
  91867. b[10] = (FLAC__byte)xx; xx >>= 8;
  91868. b[9] = (FLAC__byte)xx; xx >>= 8;
  91869. b[8] = (FLAC__byte)xx; xx >>= 8;
  91870. x = encoder->private_->seek_table->points[i].frame_samples;
  91871. b[17] = (FLAC__byte)x; x >>= 8;
  91872. b[16] = (FLAC__byte)x; x >>= 8;
  91873. memcpy(p, b, 18);
  91874. }
  91875. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91876. simple_ogg_page__clear(&page);
  91877. return; /* state already set */
  91878. }
  91879. simple_ogg_page__clear(&page);
  91880. }
  91881. }
  91882. #endif
  91883. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  91884. {
  91885. FLAC__uint16 crc;
  91886. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91887. 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)) {
  91888. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91889. return false;
  91890. }
  91891. if(!process_subframes_(encoder, is_fractional_block)) {
  91892. return false;
  91893. }
  91894. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  91895. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91896. return false;
  91897. }
  91898. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91899. if(
  91900. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  91901. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  91902. ) {
  91903. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91904. return false;
  91905. }
  91906. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  91907. return false;
  91908. }
  91909. encoder->private_->current_sample_number = 0;
  91910. encoder->private_->current_frame_number++;
  91911. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  91912. return true;
  91913. }
  91914. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  91915. {
  91916. FLAC__FrameHeader frame_header;
  91917. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  91918. FLAC__bool do_independent, do_mid_side;
  91919. if(is_fractional_block) {
  91920. max_partition_order = 0;
  91921. }
  91922. else {
  91923. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  91924. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  91925. }
  91926. min_partition_order = min(min_partition_order, max_partition_order);
  91927. frame_header.blocksize = encoder->protected_->blocksize;
  91928. frame_header.sample_rate = encoder->protected_->sample_rate;
  91929. frame_header.channels = encoder->protected_->channels;
  91930. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  91931. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  91932. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  91933. frame_header.number.frame_number = encoder->private_->current_frame_number;
  91934. if(encoder->protected_->do_mid_side_stereo) {
  91935. if(encoder->protected_->loose_mid_side_stereo) {
  91936. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  91937. do_independent = true;
  91938. do_mid_side = true;
  91939. }
  91940. else {
  91941. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  91942. do_mid_side = !do_independent;
  91943. }
  91944. }
  91945. else {
  91946. do_independent = true;
  91947. do_mid_side = true;
  91948. }
  91949. }
  91950. else {
  91951. do_independent = true;
  91952. do_mid_side = false;
  91953. }
  91954. FLAC__ASSERT(do_independent || do_mid_side);
  91955. if(do_independent) {
  91956. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91957. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  91958. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  91959. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  91960. }
  91961. }
  91962. if(do_mid_side) {
  91963. FLAC__ASSERT(encoder->protected_->channels == 2);
  91964. for(channel = 0; channel < 2; channel++) {
  91965. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  91966. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  91967. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  91968. }
  91969. }
  91970. if(do_independent) {
  91971. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91972. if(!
  91973. process_subframe_(
  91974. encoder,
  91975. min_partition_order,
  91976. max_partition_order,
  91977. &frame_header,
  91978. encoder->private_->subframe_bps[channel],
  91979. encoder->private_->integer_signal[channel],
  91980. encoder->private_->subframe_workspace_ptr[channel],
  91981. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  91982. encoder->private_->residual_workspace[channel],
  91983. encoder->private_->best_subframe+channel,
  91984. encoder->private_->best_subframe_bits+channel
  91985. )
  91986. )
  91987. return false;
  91988. }
  91989. }
  91990. if(do_mid_side) {
  91991. FLAC__ASSERT(encoder->protected_->channels == 2);
  91992. for(channel = 0; channel < 2; channel++) {
  91993. if(!
  91994. process_subframe_(
  91995. encoder,
  91996. min_partition_order,
  91997. max_partition_order,
  91998. &frame_header,
  91999. encoder->private_->subframe_bps_mid_side[channel],
  92000. encoder->private_->integer_signal_mid_side[channel],
  92001. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  92002. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  92003. encoder->private_->residual_workspace_mid_side[channel],
  92004. encoder->private_->best_subframe_mid_side+channel,
  92005. encoder->private_->best_subframe_bits_mid_side+channel
  92006. )
  92007. )
  92008. return false;
  92009. }
  92010. }
  92011. if(do_mid_side) {
  92012. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92013. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92014. FLAC__ChannelAssignment channel_assignment;
  92015. FLAC__ASSERT(encoder->protected_->channels == 2);
  92016. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92017. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92018. }
  92019. else {
  92020. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92021. unsigned min_bits;
  92022. int ca;
  92023. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92024. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92025. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92026. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92027. FLAC__ASSERT(do_independent && do_mid_side);
  92028. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92029. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92030. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92031. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92032. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92033. min_bits = bits[channel_assignment];
  92034. for(ca = 1; ca <= 3; ca++) {
  92035. if(bits[ca] < min_bits) {
  92036. min_bits = bits[ca];
  92037. channel_assignment = (FLAC__ChannelAssignment)ca;
  92038. }
  92039. }
  92040. }
  92041. frame_header.channel_assignment = channel_assignment;
  92042. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92043. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92044. return false;
  92045. }
  92046. switch(channel_assignment) {
  92047. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92048. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92049. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92050. break;
  92051. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92052. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92053. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92054. break;
  92055. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92056. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92057. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92058. break;
  92059. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92060. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92061. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92062. break;
  92063. default:
  92064. FLAC__ASSERT(0);
  92065. }
  92066. switch(channel_assignment) {
  92067. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92068. left_bps = encoder->private_->subframe_bps [0];
  92069. right_bps = encoder->private_->subframe_bps [1];
  92070. break;
  92071. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92072. left_bps = encoder->private_->subframe_bps [0];
  92073. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92074. break;
  92075. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92076. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92077. right_bps = encoder->private_->subframe_bps [1];
  92078. break;
  92079. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92080. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92081. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92082. break;
  92083. default:
  92084. FLAC__ASSERT(0);
  92085. }
  92086. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92087. return false;
  92088. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92089. return false;
  92090. }
  92091. else {
  92092. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92093. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92094. return false;
  92095. }
  92096. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92097. 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)) {
  92098. return false;
  92099. }
  92100. }
  92101. }
  92102. if(encoder->protected_->loose_mid_side_stereo) {
  92103. encoder->private_->loose_mid_side_stereo_frame_count++;
  92104. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92105. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92106. }
  92107. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92108. return true;
  92109. }
  92110. FLAC__bool process_subframe_(
  92111. FLAC__StreamEncoder *encoder,
  92112. unsigned min_partition_order,
  92113. unsigned max_partition_order,
  92114. const FLAC__FrameHeader *frame_header,
  92115. unsigned subframe_bps,
  92116. const FLAC__int32 integer_signal[],
  92117. FLAC__Subframe *subframe[2],
  92118. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92119. FLAC__int32 *residual[2],
  92120. unsigned *best_subframe,
  92121. unsigned *best_bits
  92122. )
  92123. {
  92124. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92125. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92126. #else
  92127. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92128. #endif
  92129. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92130. FLAC__double lpc_residual_bits_per_sample;
  92131. 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 */
  92132. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92133. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92134. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92135. #endif
  92136. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92137. unsigned rice_parameter;
  92138. unsigned _candidate_bits, _best_bits;
  92139. unsigned _best_subframe;
  92140. 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;
  92141. FLAC__ASSERT(frame_header->blocksize > 0);
  92142. _best_subframe = 0;
  92143. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92144. _best_bits = UINT_MAX;
  92145. else
  92146. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92147. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92148. unsigned signal_is_constant = false;
  92149. 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);
  92150. if(
  92151. !encoder->private_->disable_constant_subframes &&
  92152. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92153. fixed_residual_bits_per_sample[1] == 0.0
  92154. #else
  92155. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92156. #endif
  92157. ) {
  92158. unsigned i;
  92159. signal_is_constant = true;
  92160. for(i = 1; i < frame_header->blocksize; i++) {
  92161. if(integer_signal[0] != integer_signal[i]) {
  92162. signal_is_constant = false;
  92163. break;
  92164. }
  92165. }
  92166. }
  92167. if(signal_is_constant) {
  92168. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92169. if(_candidate_bits < _best_bits) {
  92170. _best_subframe = !_best_subframe;
  92171. _best_bits = _candidate_bits;
  92172. }
  92173. }
  92174. else {
  92175. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92176. if(encoder->protected_->do_exhaustive_model_search) {
  92177. min_fixed_order = 0;
  92178. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92179. }
  92180. else {
  92181. min_fixed_order = max_fixed_order = guess_fixed_order;
  92182. }
  92183. if(max_fixed_order >= frame_header->blocksize)
  92184. max_fixed_order = frame_header->blocksize - 1;
  92185. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92186. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92187. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92188. continue; /* don't even try */
  92189. 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 */
  92190. #else
  92191. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92192. continue; /* don't even try */
  92193. 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 */
  92194. #endif
  92195. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92196. if(rice_parameter >= rice_parameter_limit) {
  92197. #ifdef DEBUG_VERBOSE
  92198. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92199. #endif
  92200. rice_parameter = rice_parameter_limit - 1;
  92201. }
  92202. _candidate_bits =
  92203. evaluate_fixed_subframe_(
  92204. encoder,
  92205. integer_signal,
  92206. residual[!_best_subframe],
  92207. encoder->private_->abs_residual_partition_sums,
  92208. encoder->private_->raw_bits_per_partition,
  92209. frame_header->blocksize,
  92210. subframe_bps,
  92211. fixed_order,
  92212. rice_parameter,
  92213. rice_parameter_limit,
  92214. min_partition_order,
  92215. max_partition_order,
  92216. encoder->protected_->do_escape_coding,
  92217. encoder->protected_->rice_parameter_search_dist,
  92218. subframe[!_best_subframe],
  92219. partitioned_rice_contents[!_best_subframe]
  92220. );
  92221. if(_candidate_bits < _best_bits) {
  92222. _best_subframe = !_best_subframe;
  92223. _best_bits = _candidate_bits;
  92224. }
  92225. }
  92226. }
  92227. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92228. if(encoder->protected_->max_lpc_order > 0) {
  92229. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92230. max_lpc_order = frame_header->blocksize-1;
  92231. else
  92232. max_lpc_order = encoder->protected_->max_lpc_order;
  92233. if(max_lpc_order > 0) {
  92234. unsigned a;
  92235. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92236. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92237. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92238. if(autoc[0] != 0.0) {
  92239. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92240. if(encoder->protected_->do_exhaustive_model_search) {
  92241. min_lpc_order = 1;
  92242. }
  92243. else {
  92244. const unsigned guess_lpc_order =
  92245. FLAC__lpc_compute_best_order(
  92246. lpc_error,
  92247. max_lpc_order,
  92248. frame_header->blocksize,
  92249. subframe_bps + (
  92250. encoder->protected_->do_qlp_coeff_prec_search?
  92251. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92252. encoder->protected_->qlp_coeff_precision
  92253. )
  92254. );
  92255. min_lpc_order = max_lpc_order = guess_lpc_order;
  92256. }
  92257. if(max_lpc_order >= frame_header->blocksize)
  92258. max_lpc_order = frame_header->blocksize - 1;
  92259. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92260. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92261. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92262. continue; /* don't even try */
  92263. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92264. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92265. if(rice_parameter >= rice_parameter_limit) {
  92266. #ifdef DEBUG_VERBOSE
  92267. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92268. #endif
  92269. rice_parameter = rice_parameter_limit - 1;
  92270. }
  92271. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92272. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92273. if(subframe_bps <= 17) {
  92274. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92275. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92276. }
  92277. else
  92278. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92279. }
  92280. else {
  92281. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92282. }
  92283. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92284. _candidate_bits =
  92285. evaluate_lpc_subframe_(
  92286. encoder,
  92287. integer_signal,
  92288. residual[!_best_subframe],
  92289. encoder->private_->abs_residual_partition_sums,
  92290. encoder->private_->raw_bits_per_partition,
  92291. encoder->private_->lp_coeff[lpc_order-1],
  92292. frame_header->blocksize,
  92293. subframe_bps,
  92294. lpc_order,
  92295. qlp_coeff_precision,
  92296. rice_parameter,
  92297. rice_parameter_limit,
  92298. min_partition_order,
  92299. max_partition_order,
  92300. encoder->protected_->do_escape_coding,
  92301. encoder->protected_->rice_parameter_search_dist,
  92302. subframe[!_best_subframe],
  92303. partitioned_rice_contents[!_best_subframe]
  92304. );
  92305. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92306. if(_candidate_bits < _best_bits) {
  92307. _best_subframe = !_best_subframe;
  92308. _best_bits = _candidate_bits;
  92309. }
  92310. }
  92311. }
  92312. }
  92313. }
  92314. }
  92315. }
  92316. }
  92317. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92318. }
  92319. }
  92320. if(_best_bits == UINT_MAX) {
  92321. FLAC__ASSERT(_best_subframe == 0);
  92322. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92323. }
  92324. *best_subframe = _best_subframe;
  92325. *best_bits = _best_bits;
  92326. return true;
  92327. }
  92328. FLAC__bool add_subframe_(
  92329. FLAC__StreamEncoder *encoder,
  92330. unsigned blocksize,
  92331. unsigned subframe_bps,
  92332. const FLAC__Subframe *subframe,
  92333. FLAC__BitWriter *frame
  92334. )
  92335. {
  92336. switch(subframe->type) {
  92337. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92338. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92339. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92340. return false;
  92341. }
  92342. break;
  92343. case FLAC__SUBFRAME_TYPE_FIXED:
  92344. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92345. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92346. return false;
  92347. }
  92348. break;
  92349. case FLAC__SUBFRAME_TYPE_LPC:
  92350. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92351. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92352. return false;
  92353. }
  92354. break;
  92355. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92356. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92357. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92358. return false;
  92359. }
  92360. break;
  92361. default:
  92362. FLAC__ASSERT(0);
  92363. }
  92364. return true;
  92365. }
  92366. #define SPOTCHECK_ESTIMATE 0
  92367. #if SPOTCHECK_ESTIMATE
  92368. static void spotcheck_subframe_estimate_(
  92369. FLAC__StreamEncoder *encoder,
  92370. unsigned blocksize,
  92371. unsigned subframe_bps,
  92372. const FLAC__Subframe *subframe,
  92373. unsigned estimate
  92374. )
  92375. {
  92376. FLAC__bool ret;
  92377. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92378. if(frame == 0) {
  92379. fprintf(stderr, "EST: can't allocate frame\n");
  92380. return;
  92381. }
  92382. if(!FLAC__bitwriter_init(frame)) {
  92383. fprintf(stderr, "EST: can't init frame\n");
  92384. return;
  92385. }
  92386. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92387. FLAC__ASSERT(ret);
  92388. {
  92389. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92390. if(estimate != actual)
  92391. 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);
  92392. }
  92393. FLAC__bitwriter_delete(frame);
  92394. }
  92395. #endif
  92396. unsigned evaluate_constant_subframe_(
  92397. FLAC__StreamEncoder *encoder,
  92398. const FLAC__int32 signal,
  92399. unsigned blocksize,
  92400. unsigned subframe_bps,
  92401. FLAC__Subframe *subframe
  92402. )
  92403. {
  92404. unsigned estimate;
  92405. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92406. subframe->data.constant.value = signal;
  92407. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92408. #if SPOTCHECK_ESTIMATE
  92409. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92410. #else
  92411. (void)encoder, (void)blocksize;
  92412. #endif
  92413. return estimate;
  92414. }
  92415. unsigned evaluate_fixed_subframe_(
  92416. FLAC__StreamEncoder *encoder,
  92417. const FLAC__int32 signal[],
  92418. FLAC__int32 residual[],
  92419. FLAC__uint64 abs_residual_partition_sums[],
  92420. unsigned raw_bits_per_partition[],
  92421. unsigned blocksize,
  92422. unsigned subframe_bps,
  92423. unsigned order,
  92424. unsigned rice_parameter,
  92425. unsigned rice_parameter_limit,
  92426. unsigned min_partition_order,
  92427. unsigned max_partition_order,
  92428. FLAC__bool do_escape_coding,
  92429. unsigned rice_parameter_search_dist,
  92430. FLAC__Subframe *subframe,
  92431. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92432. )
  92433. {
  92434. unsigned i, residual_bits, estimate;
  92435. const unsigned residual_samples = blocksize - order;
  92436. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92437. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92438. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92439. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92440. subframe->data.fixed.residual = residual;
  92441. residual_bits =
  92442. find_best_partition_order_(
  92443. encoder->private_,
  92444. residual,
  92445. abs_residual_partition_sums,
  92446. raw_bits_per_partition,
  92447. residual_samples,
  92448. order,
  92449. rice_parameter,
  92450. rice_parameter_limit,
  92451. min_partition_order,
  92452. max_partition_order,
  92453. subframe_bps,
  92454. do_escape_coding,
  92455. rice_parameter_search_dist,
  92456. &subframe->data.fixed.entropy_coding_method
  92457. );
  92458. subframe->data.fixed.order = order;
  92459. for(i = 0; i < order; i++)
  92460. subframe->data.fixed.warmup[i] = signal[i];
  92461. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92462. #if SPOTCHECK_ESTIMATE
  92463. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92464. #endif
  92465. return estimate;
  92466. }
  92467. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92468. unsigned evaluate_lpc_subframe_(
  92469. FLAC__StreamEncoder *encoder,
  92470. const FLAC__int32 signal[],
  92471. FLAC__int32 residual[],
  92472. FLAC__uint64 abs_residual_partition_sums[],
  92473. unsigned raw_bits_per_partition[],
  92474. const FLAC__real lp_coeff[],
  92475. unsigned blocksize,
  92476. unsigned subframe_bps,
  92477. unsigned order,
  92478. unsigned qlp_coeff_precision,
  92479. unsigned rice_parameter,
  92480. unsigned rice_parameter_limit,
  92481. unsigned min_partition_order,
  92482. unsigned max_partition_order,
  92483. FLAC__bool do_escape_coding,
  92484. unsigned rice_parameter_search_dist,
  92485. FLAC__Subframe *subframe,
  92486. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92487. )
  92488. {
  92489. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92490. unsigned i, residual_bits, estimate;
  92491. int quantization, ret;
  92492. const unsigned residual_samples = blocksize - order;
  92493. if(subframe_bps <= 16) {
  92494. FLAC__ASSERT(order > 0);
  92495. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92496. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92497. }
  92498. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92499. if(ret != 0)
  92500. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92501. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92502. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92503. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92504. else
  92505. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92506. else
  92507. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92508. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92509. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92510. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92511. subframe->data.lpc.residual = residual;
  92512. residual_bits =
  92513. find_best_partition_order_(
  92514. encoder->private_,
  92515. residual,
  92516. abs_residual_partition_sums,
  92517. raw_bits_per_partition,
  92518. residual_samples,
  92519. order,
  92520. rice_parameter,
  92521. rice_parameter_limit,
  92522. min_partition_order,
  92523. max_partition_order,
  92524. subframe_bps,
  92525. do_escape_coding,
  92526. rice_parameter_search_dist,
  92527. &subframe->data.lpc.entropy_coding_method
  92528. );
  92529. subframe->data.lpc.order = order;
  92530. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  92531. subframe->data.lpc.quantization_level = quantization;
  92532. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  92533. for(i = 0; i < order; i++)
  92534. subframe->data.lpc.warmup[i] = signal[i];
  92535. 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;
  92536. #if SPOTCHECK_ESTIMATE
  92537. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92538. #endif
  92539. return estimate;
  92540. }
  92541. #endif
  92542. unsigned evaluate_verbatim_subframe_(
  92543. FLAC__StreamEncoder *encoder,
  92544. const FLAC__int32 signal[],
  92545. unsigned blocksize,
  92546. unsigned subframe_bps,
  92547. FLAC__Subframe *subframe
  92548. )
  92549. {
  92550. unsigned estimate;
  92551. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  92552. subframe->data.verbatim.data = signal;
  92553. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  92554. #if SPOTCHECK_ESTIMATE
  92555. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92556. #else
  92557. (void)encoder;
  92558. #endif
  92559. return estimate;
  92560. }
  92561. unsigned find_best_partition_order_(
  92562. FLAC__StreamEncoderPrivate *private_,
  92563. const FLAC__int32 residual[],
  92564. FLAC__uint64 abs_residual_partition_sums[],
  92565. unsigned raw_bits_per_partition[],
  92566. unsigned residual_samples,
  92567. unsigned predictor_order,
  92568. unsigned rice_parameter,
  92569. unsigned rice_parameter_limit,
  92570. unsigned min_partition_order,
  92571. unsigned max_partition_order,
  92572. unsigned bps,
  92573. FLAC__bool do_escape_coding,
  92574. unsigned rice_parameter_search_dist,
  92575. FLAC__EntropyCodingMethod *best_ecm
  92576. )
  92577. {
  92578. unsigned residual_bits, best_residual_bits = 0;
  92579. unsigned best_parameters_index = 0;
  92580. unsigned best_partition_order = 0;
  92581. const unsigned blocksize = residual_samples + predictor_order;
  92582. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  92583. min_partition_order = min(min_partition_order, max_partition_order);
  92584. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  92585. if(do_escape_coding)
  92586. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  92587. {
  92588. int partition_order;
  92589. unsigned sum;
  92590. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  92591. if(!
  92592. set_partitioned_rice_(
  92593. #ifdef EXACT_RICE_BITS_CALCULATION
  92594. residual,
  92595. #endif
  92596. abs_residual_partition_sums+sum,
  92597. raw_bits_per_partition+sum,
  92598. residual_samples,
  92599. predictor_order,
  92600. rice_parameter,
  92601. rice_parameter_limit,
  92602. rice_parameter_search_dist,
  92603. (unsigned)partition_order,
  92604. do_escape_coding,
  92605. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  92606. &residual_bits
  92607. )
  92608. )
  92609. {
  92610. FLAC__ASSERT(best_residual_bits != 0);
  92611. break;
  92612. }
  92613. sum += 1u << partition_order;
  92614. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  92615. best_residual_bits = residual_bits;
  92616. best_parameters_index = !best_parameters_index;
  92617. best_partition_order = partition_order;
  92618. }
  92619. }
  92620. }
  92621. best_ecm->data.partitioned_rice.order = best_partition_order;
  92622. {
  92623. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  92624. unsigned partition;
  92625. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  92626. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  92627. if(do_escape_coding)
  92628. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  92629. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  92630. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  92631. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  92632. break;
  92633. }
  92634. }
  92635. }
  92636. return best_residual_bits;
  92637. }
  92638. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92639. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  92640. const FLAC__int32 residual[],
  92641. FLAC__uint64 abs_residual_partition_sums[],
  92642. unsigned blocksize,
  92643. unsigned predictor_order,
  92644. unsigned min_partition_order,
  92645. unsigned max_partition_order
  92646. );
  92647. #endif
  92648. void precompute_partition_info_sums_(
  92649. const FLAC__int32 residual[],
  92650. FLAC__uint64 abs_residual_partition_sums[],
  92651. unsigned residual_samples,
  92652. unsigned predictor_order,
  92653. unsigned min_partition_order,
  92654. unsigned max_partition_order,
  92655. unsigned bps
  92656. )
  92657. {
  92658. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  92659. unsigned partitions = 1u << max_partition_order;
  92660. FLAC__ASSERT(default_partition_samples > predictor_order);
  92661. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92662. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92663. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  92664. return;
  92665. }
  92666. #endif
  92667. {
  92668. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  92669. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92670. FLAC__uint32 abs_residual_partition_sum;
  92671. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92672. end += default_partition_samples;
  92673. abs_residual_partition_sum = 0;
  92674. for( ; residual_sample < end; residual_sample++)
  92675. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92676. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92677. }
  92678. }
  92679. else { /* have to pessimistically use 64 bits for accumulator */
  92680. FLAC__uint64 abs_residual_partition_sum;
  92681. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92682. end += default_partition_samples;
  92683. abs_residual_partition_sum = 0;
  92684. for( ; residual_sample < end; residual_sample++)
  92685. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92686. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92687. }
  92688. }
  92689. }
  92690. {
  92691. unsigned from_partition = 0, to_partition = partitions;
  92692. int partition_order;
  92693. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  92694. unsigned i;
  92695. partitions >>= 1;
  92696. for(i = 0; i < partitions; i++) {
  92697. abs_residual_partition_sums[to_partition++] =
  92698. abs_residual_partition_sums[from_partition ] +
  92699. abs_residual_partition_sums[from_partition+1];
  92700. from_partition += 2;
  92701. }
  92702. }
  92703. }
  92704. }
  92705. void precompute_partition_info_escapes_(
  92706. const FLAC__int32 residual[],
  92707. unsigned raw_bits_per_partition[],
  92708. unsigned residual_samples,
  92709. unsigned predictor_order,
  92710. unsigned min_partition_order,
  92711. unsigned max_partition_order
  92712. )
  92713. {
  92714. int partition_order;
  92715. unsigned from_partition, to_partition = 0;
  92716. const unsigned blocksize = residual_samples + predictor_order;
  92717. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  92718. FLAC__int32 r;
  92719. FLAC__uint32 rmax;
  92720. unsigned partition, partition_sample, partition_samples, residual_sample;
  92721. const unsigned partitions = 1u << partition_order;
  92722. const unsigned default_partition_samples = blocksize >> partition_order;
  92723. FLAC__ASSERT(default_partition_samples > predictor_order);
  92724. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92725. partition_samples = default_partition_samples;
  92726. if(partition == 0)
  92727. partition_samples -= predictor_order;
  92728. rmax = 0;
  92729. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  92730. r = residual[residual_sample++];
  92731. if(r < 0)
  92732. rmax |= ~r;
  92733. else
  92734. rmax |= r;
  92735. }
  92736. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  92737. }
  92738. to_partition = partitions;
  92739. break; /*@@@ yuck, should remove the 'for' loop instead */
  92740. }
  92741. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  92742. unsigned m;
  92743. unsigned i;
  92744. const unsigned partitions = 1u << partition_order;
  92745. for(i = 0; i < partitions; i++) {
  92746. m = raw_bits_per_partition[from_partition];
  92747. from_partition++;
  92748. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  92749. from_partition++;
  92750. to_partition++;
  92751. }
  92752. }
  92753. }
  92754. #ifdef EXACT_RICE_BITS_CALCULATION
  92755. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92756. const unsigned rice_parameter,
  92757. const unsigned partition_samples,
  92758. const FLAC__int32 *residual
  92759. )
  92760. {
  92761. unsigned i, partition_bits =
  92762. 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 */
  92763. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  92764. ;
  92765. for(i = 0; i < partition_samples; i++)
  92766. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  92767. return partition_bits;
  92768. }
  92769. #else
  92770. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92771. const unsigned rice_parameter,
  92772. const unsigned partition_samples,
  92773. const FLAC__uint64 abs_residual_partition_sum
  92774. )
  92775. {
  92776. return
  92777. 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 */
  92778. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  92779. (
  92780. rice_parameter?
  92781. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  92782. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  92783. )
  92784. - (partition_samples >> 1)
  92785. ;
  92786. }
  92787. #endif
  92788. FLAC__bool set_partitioned_rice_(
  92789. #ifdef EXACT_RICE_BITS_CALCULATION
  92790. const FLAC__int32 residual[],
  92791. #endif
  92792. const FLAC__uint64 abs_residual_partition_sums[],
  92793. const unsigned raw_bits_per_partition[],
  92794. const unsigned residual_samples,
  92795. const unsigned predictor_order,
  92796. const unsigned suggested_rice_parameter,
  92797. const unsigned rice_parameter_limit,
  92798. const unsigned rice_parameter_search_dist,
  92799. const unsigned partition_order,
  92800. const FLAC__bool search_for_escapes,
  92801. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  92802. unsigned *bits
  92803. )
  92804. {
  92805. unsigned rice_parameter, partition_bits;
  92806. unsigned best_partition_bits, best_rice_parameter = 0;
  92807. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  92808. unsigned *parameters, *raw_bits;
  92809. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92810. unsigned min_rice_parameter, max_rice_parameter;
  92811. #else
  92812. (void)rice_parameter_search_dist;
  92813. #endif
  92814. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92815. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92816. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  92817. parameters = partitioned_rice_contents->parameters;
  92818. raw_bits = partitioned_rice_contents->raw_bits;
  92819. if(partition_order == 0) {
  92820. best_partition_bits = (unsigned)(-1);
  92821. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92822. if(rice_parameter_search_dist) {
  92823. if(suggested_rice_parameter < rice_parameter_search_dist)
  92824. min_rice_parameter = 0;
  92825. else
  92826. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  92827. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  92828. if(max_rice_parameter >= rice_parameter_limit) {
  92829. #ifdef DEBUG_VERBOSE
  92830. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  92831. #endif
  92832. max_rice_parameter = rice_parameter_limit - 1;
  92833. }
  92834. }
  92835. else
  92836. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  92837. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92838. #else
  92839. rice_parameter = suggested_rice_parameter;
  92840. #endif
  92841. #ifdef EXACT_RICE_BITS_CALCULATION
  92842. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  92843. #else
  92844. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  92845. #endif
  92846. if(partition_bits < best_partition_bits) {
  92847. best_rice_parameter = rice_parameter;
  92848. best_partition_bits = partition_bits;
  92849. }
  92850. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92851. }
  92852. #endif
  92853. if(search_for_escapes) {
  92854. 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;
  92855. if(partition_bits <= best_partition_bits) {
  92856. raw_bits[0] = raw_bits_per_partition[0];
  92857. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92858. best_partition_bits = partition_bits;
  92859. }
  92860. else
  92861. raw_bits[0] = 0;
  92862. }
  92863. parameters[0] = best_rice_parameter;
  92864. bits_ += best_partition_bits;
  92865. }
  92866. else {
  92867. unsigned partition, residual_sample;
  92868. unsigned partition_samples;
  92869. FLAC__uint64 mean, k;
  92870. const unsigned partitions = 1u << partition_order;
  92871. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92872. partition_samples = (residual_samples+predictor_order) >> partition_order;
  92873. if(partition == 0) {
  92874. if(partition_samples <= predictor_order)
  92875. return false;
  92876. else
  92877. partition_samples -= predictor_order;
  92878. }
  92879. mean = abs_residual_partition_sums[partition];
  92880. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  92881. ;
  92882. if(rice_parameter >= rice_parameter_limit) {
  92883. #ifdef DEBUG_VERBOSE
  92884. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  92885. #endif
  92886. rice_parameter = rice_parameter_limit - 1;
  92887. }
  92888. best_partition_bits = (unsigned)(-1);
  92889. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92890. if(rice_parameter_search_dist) {
  92891. if(rice_parameter < rice_parameter_search_dist)
  92892. min_rice_parameter = 0;
  92893. else
  92894. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  92895. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  92896. if(max_rice_parameter >= rice_parameter_limit) {
  92897. #ifdef DEBUG_VERBOSE
  92898. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  92899. #endif
  92900. max_rice_parameter = rice_parameter_limit - 1;
  92901. }
  92902. }
  92903. else
  92904. min_rice_parameter = max_rice_parameter = rice_parameter;
  92905. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92906. #endif
  92907. #ifdef EXACT_RICE_BITS_CALCULATION
  92908. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  92909. #else
  92910. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  92911. #endif
  92912. if(partition_bits < best_partition_bits) {
  92913. best_rice_parameter = rice_parameter;
  92914. best_partition_bits = partition_bits;
  92915. }
  92916. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92917. }
  92918. #endif
  92919. if(search_for_escapes) {
  92920. 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;
  92921. if(partition_bits <= best_partition_bits) {
  92922. raw_bits[partition] = raw_bits_per_partition[partition];
  92923. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92924. best_partition_bits = partition_bits;
  92925. }
  92926. else
  92927. raw_bits[partition] = 0;
  92928. }
  92929. parameters[partition] = best_rice_parameter;
  92930. bits_ += best_partition_bits;
  92931. residual_sample += partition_samples;
  92932. }
  92933. }
  92934. *bits = bits_;
  92935. return true;
  92936. }
  92937. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  92938. {
  92939. unsigned i, shift;
  92940. FLAC__int32 x = 0;
  92941. for(i = 0; i < samples && !(x&1); i++)
  92942. x |= signal[i];
  92943. if(x == 0) {
  92944. shift = 0;
  92945. }
  92946. else {
  92947. for(shift = 0; !(x&1); shift++)
  92948. x >>= 1;
  92949. }
  92950. if(shift > 0) {
  92951. for(i = 0; i < samples; i++)
  92952. signal[i] >>= shift;
  92953. }
  92954. return shift;
  92955. }
  92956. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92957. {
  92958. unsigned channel;
  92959. for(channel = 0; channel < channels; channel++)
  92960. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  92961. fifo->tail += wide_samples;
  92962. FLAC__ASSERT(fifo->tail <= fifo->size);
  92963. }
  92964. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92965. {
  92966. unsigned channel;
  92967. unsigned sample, wide_sample;
  92968. unsigned tail = fifo->tail;
  92969. sample = input_offset * channels;
  92970. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  92971. for(channel = 0; channel < channels; channel++)
  92972. fifo->data[channel][tail] = input[sample++];
  92973. tail++;
  92974. }
  92975. fifo->tail = tail;
  92976. FLAC__ASSERT(fifo->tail <= fifo->size);
  92977. }
  92978. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  92979. {
  92980. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  92981. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  92982. (void)decoder;
  92983. if(encoder->private_->verify.needs_magic_hack) {
  92984. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  92985. *bytes = FLAC__STREAM_SYNC_LENGTH;
  92986. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  92987. encoder->private_->verify.needs_magic_hack = false;
  92988. }
  92989. else {
  92990. if(encoded_bytes == 0) {
  92991. FLAC__ASSERT(0);
  92992. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  92993. }
  92994. else if(encoded_bytes < *bytes)
  92995. *bytes = encoded_bytes;
  92996. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  92997. encoder->private_->verify.output.data += *bytes;
  92998. encoder->private_->verify.output.bytes -= *bytes;
  92999. }
  93000. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93001. }
  93002. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  93003. {
  93004. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  93005. unsigned channel;
  93006. const unsigned channels = frame->header.channels;
  93007. const unsigned blocksize = frame->header.blocksize;
  93008. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  93009. (void)decoder;
  93010. for(channel = 0; channel < channels; channel++) {
  93011. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93012. unsigned i, sample = 0;
  93013. FLAC__int32 expect = 0, got = 0;
  93014. for(i = 0; i < blocksize; i++) {
  93015. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93016. sample = i;
  93017. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93018. got = (FLAC__int32)buffer[channel][i];
  93019. break;
  93020. }
  93021. }
  93022. FLAC__ASSERT(i < blocksize);
  93023. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93024. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93025. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93026. encoder->private_->verify.error_stats.channel = channel;
  93027. encoder->private_->verify.error_stats.sample = sample;
  93028. encoder->private_->verify.error_stats.expected = expect;
  93029. encoder->private_->verify.error_stats.got = got;
  93030. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93031. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93032. }
  93033. }
  93034. encoder->private_->verify.input_fifo.tail -= blocksize;
  93035. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93036. for(channel = 0; channel < channels; channel++)
  93037. 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]));
  93038. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93039. }
  93040. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93041. {
  93042. (void)decoder, (void)metadata, (void)client_data;
  93043. }
  93044. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93045. {
  93046. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93047. (void)decoder, (void)status;
  93048. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93049. }
  93050. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93051. {
  93052. (void)client_data;
  93053. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93054. if (*bytes == 0) {
  93055. if (feof(encoder->private_->file))
  93056. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93057. else if (ferror(encoder->private_->file))
  93058. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93059. }
  93060. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93061. }
  93062. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93063. {
  93064. (void)client_data;
  93065. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93066. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93067. else
  93068. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93069. }
  93070. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93071. {
  93072. off_t offset;
  93073. (void)client_data;
  93074. offset = ftello(encoder->private_->file);
  93075. if(offset < 0) {
  93076. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93077. }
  93078. else {
  93079. *absolute_byte_offset = (FLAC__uint64)offset;
  93080. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93081. }
  93082. }
  93083. #ifdef FLAC__VALGRIND_TESTING
  93084. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93085. {
  93086. size_t ret = fwrite(ptr, size, nmemb, stream);
  93087. if(!ferror(stream))
  93088. fflush(stream);
  93089. return ret;
  93090. }
  93091. #else
  93092. #define local__fwrite fwrite
  93093. #endif
  93094. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93095. {
  93096. (void)client_data, (void)current_frame;
  93097. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93098. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93099. #if FLAC__HAS_OGG
  93100. encoder->private_->is_ogg? true :
  93101. #endif
  93102. samples > 0
  93103. );
  93104. if(call_it) {
  93105. 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);
  93106. }
  93107. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93108. }
  93109. else
  93110. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93111. }
  93112. FILE *get_binary_stdout_(void)
  93113. {
  93114. #if defined _MSC_VER || defined __MINGW32__
  93115. _setmode(_fileno(stdout), _O_BINARY);
  93116. #elif defined __CYGWIN__
  93117. setmode(_fileno(stdout), _O_BINARY);
  93118. #elif defined __EMX__
  93119. setmode(fileno(stdout), O_BINARY);
  93120. #endif
  93121. return stdout;
  93122. }
  93123. #endif
  93124. /*** End of inlined file: stream_encoder.c ***/
  93125. /*** Start of inlined file: stream_encoder_framing.c ***/
  93126. /*** Start of inlined file: juce_FlacHeader.h ***/
  93127. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93128. // tasks..
  93129. #define VERSION "1.2.1"
  93130. #define FLAC__NO_DLL 1
  93131. #if JUCE_MSVC
  93132. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93133. #endif
  93134. #if JUCE_MAC
  93135. #define FLAC__SYS_DARWIN 1
  93136. #endif
  93137. /*** End of inlined file: juce_FlacHeader.h ***/
  93138. #if JUCE_USE_FLAC
  93139. #if HAVE_CONFIG_H
  93140. # include <config.h>
  93141. #endif
  93142. #include <stdio.h>
  93143. #include <string.h> /* for strlen() */
  93144. #ifdef max
  93145. #undef max
  93146. #endif
  93147. #define max(x,y) ((x)>(y)?(x):(y))
  93148. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93149. 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);
  93150. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93151. {
  93152. unsigned i, j;
  93153. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93154. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93155. return false;
  93156. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93157. return false;
  93158. i = metadata->length;
  93159. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93160. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93161. i -= metadata->data.vorbis_comment.vendor_string.length;
  93162. i += vendor_string_length;
  93163. }
  93164. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93165. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93166. return false;
  93167. switch(metadata->type) {
  93168. case FLAC__METADATA_TYPE_STREAMINFO:
  93169. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93170. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93171. return false;
  93172. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93173. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93174. return false;
  93175. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93176. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93177. return false;
  93178. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93179. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93180. return false;
  93181. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93182. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93183. return false;
  93184. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93185. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93186. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93187. return false;
  93188. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93189. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93190. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93191. return false;
  93192. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93193. return false;
  93194. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93195. return false;
  93196. break;
  93197. case FLAC__METADATA_TYPE_PADDING:
  93198. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93199. return false;
  93200. break;
  93201. case FLAC__METADATA_TYPE_APPLICATION:
  93202. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93203. return false;
  93204. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93205. return false;
  93206. break;
  93207. case FLAC__METADATA_TYPE_SEEKTABLE:
  93208. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93209. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93210. return false;
  93211. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93212. return false;
  93213. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93214. return false;
  93215. }
  93216. break;
  93217. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93218. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93219. return false;
  93220. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93221. return false;
  93222. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93223. return false;
  93224. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93225. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93226. return false;
  93227. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93228. return false;
  93229. }
  93230. break;
  93231. case FLAC__METADATA_TYPE_CUESHEET:
  93232. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93233. 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))
  93234. return false;
  93235. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93236. return false;
  93237. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93238. return false;
  93239. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93240. return false;
  93241. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93242. return false;
  93243. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93244. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93245. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93246. return false;
  93247. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93248. return false;
  93249. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93250. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93251. return false;
  93252. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93253. return false;
  93254. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93255. return false;
  93256. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93257. return false;
  93258. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93259. return false;
  93260. for(j = 0; j < track->num_indices; j++) {
  93261. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93262. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93263. return false;
  93264. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93265. return false;
  93266. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93267. return false;
  93268. }
  93269. }
  93270. break;
  93271. case FLAC__METADATA_TYPE_PICTURE:
  93272. {
  93273. size_t len;
  93274. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93275. return false;
  93276. len = strlen(metadata->data.picture.mime_type);
  93277. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93278. return false;
  93279. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93280. return false;
  93281. len = strlen((const char *)metadata->data.picture.description);
  93282. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93283. return false;
  93284. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93285. return false;
  93286. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93287. return false;
  93288. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93289. return false;
  93290. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93291. return false;
  93292. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93293. return false;
  93294. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93295. return false;
  93296. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93297. return false;
  93298. }
  93299. break;
  93300. default:
  93301. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93302. return false;
  93303. break;
  93304. }
  93305. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93306. return true;
  93307. }
  93308. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93309. {
  93310. unsigned u, blocksize_hint, sample_rate_hint;
  93311. FLAC__byte crc;
  93312. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93313. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93314. return false;
  93315. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93316. return false;
  93317. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93318. return false;
  93319. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93320. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93321. blocksize_hint = 0;
  93322. switch(header->blocksize) {
  93323. case 192: u = 1; break;
  93324. case 576: u = 2; break;
  93325. case 1152: u = 3; break;
  93326. case 2304: u = 4; break;
  93327. case 4608: u = 5; break;
  93328. case 256: u = 8; break;
  93329. case 512: u = 9; break;
  93330. case 1024: u = 10; break;
  93331. case 2048: u = 11; break;
  93332. case 4096: u = 12; break;
  93333. case 8192: u = 13; break;
  93334. case 16384: u = 14; break;
  93335. case 32768: u = 15; break;
  93336. default:
  93337. if(header->blocksize <= 0x100)
  93338. blocksize_hint = u = 6;
  93339. else
  93340. blocksize_hint = u = 7;
  93341. break;
  93342. }
  93343. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93344. return false;
  93345. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93346. sample_rate_hint = 0;
  93347. switch(header->sample_rate) {
  93348. case 88200: u = 1; break;
  93349. case 176400: u = 2; break;
  93350. case 192000: u = 3; break;
  93351. case 8000: u = 4; break;
  93352. case 16000: u = 5; break;
  93353. case 22050: u = 6; break;
  93354. case 24000: u = 7; break;
  93355. case 32000: u = 8; break;
  93356. case 44100: u = 9; break;
  93357. case 48000: u = 10; break;
  93358. case 96000: u = 11; break;
  93359. default:
  93360. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93361. sample_rate_hint = u = 12;
  93362. else if(header->sample_rate % 10 == 0)
  93363. sample_rate_hint = u = 14;
  93364. else if(header->sample_rate <= 0xffff)
  93365. sample_rate_hint = u = 13;
  93366. else
  93367. u = 0;
  93368. break;
  93369. }
  93370. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93371. return false;
  93372. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93373. switch(header->channel_assignment) {
  93374. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93375. u = header->channels - 1;
  93376. break;
  93377. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93378. FLAC__ASSERT(header->channels == 2);
  93379. u = 8;
  93380. break;
  93381. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93382. FLAC__ASSERT(header->channels == 2);
  93383. u = 9;
  93384. break;
  93385. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93386. FLAC__ASSERT(header->channels == 2);
  93387. u = 10;
  93388. break;
  93389. default:
  93390. FLAC__ASSERT(0);
  93391. }
  93392. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93393. return false;
  93394. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93395. switch(header->bits_per_sample) {
  93396. case 8 : u = 1; break;
  93397. case 12: u = 2; break;
  93398. case 16: u = 4; break;
  93399. case 20: u = 5; break;
  93400. case 24: u = 6; break;
  93401. default: u = 0; break;
  93402. }
  93403. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93404. return false;
  93405. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93406. return false;
  93407. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93408. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93409. return false;
  93410. }
  93411. else {
  93412. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93413. return false;
  93414. }
  93415. if(blocksize_hint)
  93416. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93417. return false;
  93418. switch(sample_rate_hint) {
  93419. case 12:
  93420. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93421. return false;
  93422. break;
  93423. case 13:
  93424. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93425. return false;
  93426. break;
  93427. case 14:
  93428. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93429. return false;
  93430. break;
  93431. }
  93432. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93433. return false;
  93434. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93435. return false;
  93436. return true;
  93437. }
  93438. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93439. {
  93440. FLAC__bool ok;
  93441. ok =
  93442. 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) &&
  93443. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93444. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93445. ;
  93446. return ok;
  93447. }
  93448. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93449. {
  93450. unsigned i;
  93451. 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))
  93452. return false;
  93453. if(wasted_bits)
  93454. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93455. return false;
  93456. for(i = 0; i < subframe->order; i++)
  93457. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93458. return false;
  93459. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93460. return false;
  93461. switch(subframe->entropy_coding_method.type) {
  93462. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93463. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93464. if(!add_residual_partitioned_rice_(
  93465. bw,
  93466. subframe->residual,
  93467. residual_samples,
  93468. subframe->order,
  93469. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93470. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93471. subframe->entropy_coding_method.data.partitioned_rice.order,
  93472. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93473. ))
  93474. return false;
  93475. break;
  93476. default:
  93477. FLAC__ASSERT(0);
  93478. }
  93479. return true;
  93480. }
  93481. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93482. {
  93483. unsigned i;
  93484. 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))
  93485. return false;
  93486. if(wasted_bits)
  93487. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93488. return false;
  93489. for(i = 0; i < subframe->order; i++)
  93490. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93491. return false;
  93492. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93493. return false;
  93494. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93495. return false;
  93496. for(i = 0; i < subframe->order; i++)
  93497. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93498. return false;
  93499. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93500. return false;
  93501. switch(subframe->entropy_coding_method.type) {
  93502. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93503. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93504. if(!add_residual_partitioned_rice_(
  93505. bw,
  93506. subframe->residual,
  93507. residual_samples,
  93508. subframe->order,
  93509. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93510. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93511. subframe->entropy_coding_method.data.partitioned_rice.order,
  93512. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93513. ))
  93514. return false;
  93515. break;
  93516. default:
  93517. FLAC__ASSERT(0);
  93518. }
  93519. return true;
  93520. }
  93521. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93522. {
  93523. unsigned i;
  93524. const FLAC__int32 *signal = subframe->data;
  93525. 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))
  93526. return false;
  93527. if(wasted_bits)
  93528. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93529. return false;
  93530. for(i = 0; i < samples; i++)
  93531. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  93532. return false;
  93533. return true;
  93534. }
  93535. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  93536. {
  93537. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  93538. return false;
  93539. switch(method->type) {
  93540. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93541. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93542. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  93543. return false;
  93544. break;
  93545. default:
  93546. FLAC__ASSERT(0);
  93547. }
  93548. return true;
  93549. }
  93550. 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)
  93551. {
  93552. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  93553. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  93554. if(partition_order == 0) {
  93555. unsigned i;
  93556. if(raw_bits[0] == 0) {
  93557. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  93558. return false;
  93559. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  93560. return false;
  93561. }
  93562. else {
  93563. FLAC__ASSERT(rice_parameters[0] == 0);
  93564. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93565. return false;
  93566. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93567. return false;
  93568. for(i = 0; i < residual_samples; i++) {
  93569. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  93570. return false;
  93571. }
  93572. }
  93573. return true;
  93574. }
  93575. else {
  93576. unsigned i, j, k = 0, k_last = 0;
  93577. unsigned partition_samples;
  93578. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  93579. for(i = 0; i < (1u<<partition_order); i++) {
  93580. partition_samples = default_partition_samples;
  93581. if(i == 0)
  93582. partition_samples -= predictor_order;
  93583. k += partition_samples;
  93584. if(raw_bits[i] == 0) {
  93585. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  93586. return false;
  93587. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  93588. return false;
  93589. }
  93590. else {
  93591. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93592. return false;
  93593. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93594. return false;
  93595. for(j = k_last; j < k; j++) {
  93596. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  93597. return false;
  93598. }
  93599. }
  93600. k_last = k;
  93601. }
  93602. return true;
  93603. }
  93604. }
  93605. #endif
  93606. /*** End of inlined file: stream_encoder_framing.c ***/
  93607. /*** Start of inlined file: window_flac.c ***/
  93608. /*** Start of inlined file: juce_FlacHeader.h ***/
  93609. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93610. // tasks..
  93611. #define VERSION "1.2.1"
  93612. #define FLAC__NO_DLL 1
  93613. #if JUCE_MSVC
  93614. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93615. #endif
  93616. #if JUCE_MAC
  93617. #define FLAC__SYS_DARWIN 1
  93618. #endif
  93619. /*** End of inlined file: juce_FlacHeader.h ***/
  93620. #if JUCE_USE_FLAC
  93621. #if HAVE_CONFIG_H
  93622. # include <config.h>
  93623. #endif
  93624. #include <math.h>
  93625. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93626. #ifndef M_PI
  93627. #define M_PI 3.14159265358979323846
  93628. #endif
  93629. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  93630. {
  93631. const FLAC__int32 N = L - 1;
  93632. FLAC__int32 n;
  93633. if (L & 1) {
  93634. for (n = 0; n <= N/2; n++)
  93635. window[n] = 2.0f * n / (float)N;
  93636. for (; n <= N; n++)
  93637. window[n] = 2.0f - 2.0f * n / (float)N;
  93638. }
  93639. else {
  93640. for (n = 0; n <= L/2-1; n++)
  93641. window[n] = 2.0f * n / (float)N;
  93642. for (; n <= N; n++)
  93643. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  93644. }
  93645. }
  93646. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  93647. {
  93648. const FLAC__int32 N = L - 1;
  93649. FLAC__int32 n;
  93650. for (n = 0; n < L; n++)
  93651. 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)));
  93652. }
  93653. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  93654. {
  93655. const FLAC__int32 N = L - 1;
  93656. FLAC__int32 n;
  93657. for (n = 0; n < L; n++)
  93658. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  93659. }
  93660. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  93661. {
  93662. const FLAC__int32 N = L - 1;
  93663. FLAC__int32 n;
  93664. for (n = 0; n <= N; n++)
  93665. 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));
  93666. }
  93667. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  93668. {
  93669. const FLAC__int32 N = L - 1;
  93670. const double N2 = (double)N / 2.;
  93671. FLAC__int32 n;
  93672. for (n = 0; n <= N; n++) {
  93673. double k = ((double)n - N2) / N2;
  93674. k = 1.0f - k * k;
  93675. window[n] = (FLAC__real)(k * k);
  93676. }
  93677. }
  93678. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  93679. {
  93680. const FLAC__int32 N = L - 1;
  93681. FLAC__int32 n;
  93682. for (n = 0; n < L; n++)
  93683. 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));
  93684. }
  93685. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  93686. {
  93687. const FLAC__int32 N = L - 1;
  93688. const double N2 = (double)N / 2.;
  93689. FLAC__int32 n;
  93690. for (n = 0; n <= N; n++) {
  93691. const double k = ((double)n - N2) / (stddev * N2);
  93692. window[n] = (FLAC__real)exp(-0.5f * k * k);
  93693. }
  93694. }
  93695. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  93696. {
  93697. const FLAC__int32 N = L - 1;
  93698. FLAC__int32 n;
  93699. for (n = 0; n < L; n++)
  93700. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  93701. }
  93702. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  93703. {
  93704. const FLAC__int32 N = L - 1;
  93705. FLAC__int32 n;
  93706. for (n = 0; n < L; n++)
  93707. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  93708. }
  93709. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  93710. {
  93711. const FLAC__int32 N = L - 1;
  93712. FLAC__int32 n;
  93713. for (n = 0; n < L; n++)
  93714. 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));
  93715. }
  93716. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  93717. {
  93718. const FLAC__int32 N = L - 1;
  93719. FLAC__int32 n;
  93720. for (n = 0; n < L; n++)
  93721. 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));
  93722. }
  93723. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  93724. {
  93725. FLAC__int32 n;
  93726. for (n = 0; n < L; n++)
  93727. window[n] = 1.0f;
  93728. }
  93729. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  93730. {
  93731. FLAC__int32 n;
  93732. if (L & 1) {
  93733. for (n = 1; n <= L+1/2; n++)
  93734. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  93735. for (; n <= L; n++)
  93736. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  93737. }
  93738. else {
  93739. for (n = 1; n <= L/2; n++)
  93740. window[n-1] = 2.0f * n / (float)L;
  93741. for (; n <= L; n++)
  93742. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  93743. }
  93744. }
  93745. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  93746. {
  93747. if (p <= 0.0)
  93748. FLAC__window_rectangle(window, L);
  93749. else if (p >= 1.0)
  93750. FLAC__window_hann(window, L);
  93751. else {
  93752. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  93753. FLAC__int32 n;
  93754. FLAC__window_rectangle(window, L);
  93755. if (Np > 0) {
  93756. for (n = 0; n <= Np; n++) {
  93757. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  93758. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  93759. }
  93760. }
  93761. }
  93762. }
  93763. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  93764. {
  93765. const FLAC__int32 N = L - 1;
  93766. const double N2 = (double)N / 2.;
  93767. FLAC__int32 n;
  93768. for (n = 0; n <= N; n++) {
  93769. const double k = ((double)n - N2) / N2;
  93770. window[n] = (FLAC__real)(1.0f - k * k);
  93771. }
  93772. }
  93773. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  93774. #endif
  93775. /*** End of inlined file: window_flac.c ***/
  93776. #else
  93777. #include <FLAC/all.h>
  93778. #endif
  93779. }
  93780. #undef max
  93781. #undef min
  93782. #ifdef _MSC_VER
  93783. #pragma warning (pop)
  93784. #endif
  93785. BEGIN_JUCE_NAMESPACE
  93786. static const char* const flacFormatName = "FLAC file";
  93787. static const juce_wchar* const flacExtensions[] = { T(".flac"), 0 };
  93788. class FlacReader : public AudioFormatReader
  93789. {
  93790. public:
  93791. FlacReader (InputStream* const in)
  93792. : AudioFormatReader (in, TRANS (flacFormatName)),
  93793. reservoir (2, 0),
  93794. reservoirStart (0),
  93795. samplesInReservoir (0),
  93796. scanningForLength (false)
  93797. {
  93798. using namespace FlacNamespace;
  93799. lengthInSamples = 0;
  93800. decoder = FLAC__stream_decoder_new();
  93801. ok = FLAC__stream_decoder_init_stream (decoder,
  93802. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  93803. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  93804. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  93805. if (ok)
  93806. {
  93807. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93808. if (lengthInSamples == 0 && sampleRate > 0)
  93809. {
  93810. // the length hasn't been stored in the metadata, so we'll need to
  93811. // work it out the length the hard way, by scanning the whole file..
  93812. scanningForLength = true;
  93813. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  93814. scanningForLength = false;
  93815. const int64 tempLength = lengthInSamples;
  93816. FLAC__stream_decoder_reset (decoder);
  93817. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93818. lengthInSamples = tempLength;
  93819. }
  93820. }
  93821. }
  93822. ~FlacReader()
  93823. {
  93824. FlacNamespace::FLAC__stream_decoder_delete (decoder);
  93825. }
  93826. void useMetadata (const FlacNamespace::FLAC__StreamMetadata_StreamInfo& info)
  93827. {
  93828. sampleRate = info.sample_rate;
  93829. bitsPerSample = info.bits_per_sample;
  93830. lengthInSamples = (unsigned int) info.total_samples;
  93831. numChannels = info.channels;
  93832. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  93833. }
  93834. // returns the number of samples read
  93835. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  93836. int64 startSampleInFile, int numSamples)
  93837. {
  93838. using namespace FlacNamespace;
  93839. if (! ok)
  93840. return false;
  93841. while (numSamples > 0)
  93842. {
  93843. if (startSampleInFile >= reservoirStart
  93844. && startSampleInFile < reservoirStart + samplesInReservoir)
  93845. {
  93846. const int num = (int) jmin ((int64) numSamples,
  93847. reservoirStart + samplesInReservoir - startSampleInFile);
  93848. jassert (num > 0);
  93849. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  93850. if (destSamples[i] != 0)
  93851. memcpy (destSamples[i] + startOffsetInDestBuffer,
  93852. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  93853. sizeof (int) * num);
  93854. startOffsetInDestBuffer += num;
  93855. startSampleInFile += num;
  93856. numSamples -= num;
  93857. }
  93858. else
  93859. {
  93860. if (startSampleInFile >= (int) lengthInSamples)
  93861. {
  93862. samplesInReservoir = 0;
  93863. }
  93864. else if (startSampleInFile < reservoirStart
  93865. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  93866. {
  93867. // had some problems with flac crashing if the read pos is aligned more
  93868. // accurately than this. Probably fixed in newer versions of the library, though.
  93869. reservoirStart = (int) (startSampleInFile & ~511);
  93870. samplesInReservoir = 0;
  93871. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  93872. }
  93873. else
  93874. {
  93875. reservoirStart += samplesInReservoir;
  93876. samplesInReservoir = 0;
  93877. FLAC__stream_decoder_process_single (decoder);
  93878. }
  93879. if (samplesInReservoir == 0)
  93880. break;
  93881. }
  93882. }
  93883. if (numSamples > 0)
  93884. {
  93885. for (int i = numDestChannels; --i >= 0;)
  93886. if (destSamples[i] != 0)
  93887. zeromem (destSamples[i] + startOffsetInDestBuffer,
  93888. sizeof (int) * numSamples);
  93889. }
  93890. return true;
  93891. }
  93892. void useSamples (const FlacNamespace::FLAC__int32* const buffer[], int numSamples)
  93893. {
  93894. if (scanningForLength)
  93895. {
  93896. lengthInSamples += numSamples;
  93897. }
  93898. else
  93899. {
  93900. if (numSamples > reservoir.getNumSamples())
  93901. reservoir.setSize (numChannels, numSamples, false, false, true);
  93902. const int bitsToShift = 32 - bitsPerSample;
  93903. for (int i = 0; i < (int) numChannels; ++i)
  93904. {
  93905. const FlacNamespace::FLAC__int32* src = buffer[i];
  93906. int n = i;
  93907. while (src == 0 && n > 0)
  93908. src = buffer [--n];
  93909. if (src != 0)
  93910. {
  93911. int* dest = (int*) reservoir.getSampleData(i);
  93912. for (int j = 0; j < numSamples; ++j)
  93913. dest[j] = src[j] << bitsToShift;
  93914. }
  93915. }
  93916. samplesInReservoir = numSamples;
  93917. }
  93918. }
  93919. static FlacNamespace::FLAC__StreamDecoderReadStatus readCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__byte buffer[], size_t* bytes, void* client_data)
  93920. {
  93921. using namespace FlacNamespace;
  93922. *bytes = (size_t) static_cast <const FlacReader*> (client_data)->input->read (buffer, (int) *bytes);
  93923. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93924. }
  93925. static FlacNamespace::FLAC__StreamDecoderSeekStatus seekCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64 absolute_byte_offset, void* client_data)
  93926. {
  93927. using namespace FlacNamespace;
  93928. static_cast <const FlacReader*> (client_data)->input->setPosition ((int) absolute_byte_offset);
  93929. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  93930. }
  93931. static FlacNamespace::FLAC__StreamDecoderTellStatus tellCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  93932. {
  93933. using namespace FlacNamespace;
  93934. *absolute_byte_offset = static_cast <const FlacReader*> (client_data)->input->getPosition();
  93935. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  93936. }
  93937. static FlacNamespace::FLAC__StreamDecoderLengthStatus lengthCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* stream_length, void* client_data)
  93938. {
  93939. using namespace FlacNamespace;
  93940. *stream_length = static_cast <const FlacReader*> (client_data)->input->getTotalLength();
  93941. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  93942. }
  93943. static FlacNamespace::FLAC__bool eofCallback_ (const FlacNamespace::FLAC__StreamDecoder*, void* client_data)
  93944. {
  93945. return static_cast <const FlacReader*> (client_data)->input->isExhausted();
  93946. }
  93947. static FlacNamespace::FLAC__StreamDecoderWriteStatus writeCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93948. const FlacNamespace::FLAC__Frame* frame,
  93949. const FlacNamespace::FLAC__int32* const buffer[],
  93950. void* client_data)
  93951. {
  93952. using namespace FlacNamespace;
  93953. static_cast <FlacReader*> (client_data)->useSamples (buffer, frame->header.blocksize);
  93954. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93955. }
  93956. static void metadataCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93957. const FlacNamespace::FLAC__StreamMetadata* metadata,
  93958. void* client_data)
  93959. {
  93960. static_cast <FlacReader*> (client_data)->useMetadata (metadata->data.stream_info);
  93961. }
  93962. static void errorCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__StreamDecoderErrorStatus, void*)
  93963. {
  93964. }
  93965. juce_UseDebuggingNewOperator
  93966. private:
  93967. FlacNamespace::FLAC__StreamDecoder* decoder;
  93968. AudioSampleBuffer reservoir;
  93969. int reservoirStart, samplesInReservoir;
  93970. bool ok, scanningForLength;
  93971. FlacReader (const FlacReader&);
  93972. FlacReader& operator= (const FlacReader&);
  93973. };
  93974. class FlacWriter : public AudioFormatWriter
  93975. {
  93976. public:
  93977. FlacWriter (OutputStream* const out,
  93978. const double sampleRate_,
  93979. const int numChannels_,
  93980. const int bitsPerSample_)
  93981. : AudioFormatWriter (out, TRANS (flacFormatName),
  93982. sampleRate_,
  93983. numChannels_,
  93984. bitsPerSample_)
  93985. {
  93986. using namespace FlacNamespace;
  93987. encoder = FLAC__stream_encoder_new();
  93988. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  93989. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  93990. FLAC__stream_encoder_set_channels (encoder, numChannels);
  93991. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  93992. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  93993. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  93994. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  93995. ok = FLAC__stream_encoder_init_stream (encoder,
  93996. encodeWriteCallback, encodeSeekCallback,
  93997. encodeTellCallback, encodeMetadataCallback,
  93998. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  93999. }
  94000. ~FlacWriter()
  94001. {
  94002. if (ok)
  94003. {
  94004. FlacNamespace::FLAC__stream_encoder_finish (encoder);
  94005. output->flush();
  94006. }
  94007. else
  94008. {
  94009. output = 0; // to stop the base class deleting this, as it needs to be returned
  94010. // to the caller of createWriter()
  94011. }
  94012. FlacNamespace::FLAC__stream_encoder_delete (encoder);
  94013. }
  94014. bool write (const int** samplesToWrite, int numSamples)
  94015. {
  94016. using namespace FlacNamespace;
  94017. if (! ok)
  94018. return false;
  94019. int* buf[3];
  94020. const int bitsToShift = 32 - bitsPerSample;
  94021. if (bitsToShift > 0)
  94022. {
  94023. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94024. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94025. buf[0] = (int*) temp.getData();
  94026. buf[1] = buf[0] + numSamples;
  94027. buf[2] = 0;
  94028. for (int i = numChannelsToWrite; --i >= 0;)
  94029. {
  94030. if (samplesToWrite[i] != 0)
  94031. {
  94032. for (int j = 0; j < numSamples; ++j)
  94033. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94034. }
  94035. }
  94036. samplesToWrite = (const int**) buf;
  94037. }
  94038. return FLAC__stream_encoder_process (encoder,
  94039. (const FLAC__int32**) samplesToWrite,
  94040. numSamples) != 0;
  94041. }
  94042. bool writeData (const void* const data, const int size) const
  94043. {
  94044. return output->write (data, size);
  94045. }
  94046. static void packUint32 (FlacNamespace::FLAC__uint32 val, FlacNamespace::FLAC__byte* b, const int bytes)
  94047. {
  94048. using namespace FlacNamespace;
  94049. b += bytes;
  94050. for (int i = 0; i < bytes; ++i)
  94051. {
  94052. *(--b) = (FLAC__byte) (val & 0xff);
  94053. val >>= 8;
  94054. }
  94055. }
  94056. void writeMetaData (const FlacNamespace::FLAC__StreamMetadata* metadata)
  94057. {
  94058. using namespace FlacNamespace;
  94059. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94060. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94061. const unsigned int channelsMinus1 = info.channels - 1;
  94062. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94063. packUint32 (info.min_blocksize, buffer, 2);
  94064. packUint32 (info.max_blocksize, buffer + 2, 2);
  94065. packUint32 (info.min_framesize, buffer + 4, 3);
  94066. packUint32 (info.max_framesize, buffer + 7, 3);
  94067. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94068. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94069. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94070. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94071. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94072. memcpy (buffer + 18, info.md5sum, 16);
  94073. const bool seekOk = output->setPosition (4);
  94074. (void) seekOk;
  94075. // if this fails, you've given it an output stream that can't seek! It needs
  94076. // to be able to seek back to write the header
  94077. jassert (seekOk);
  94078. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94079. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94080. }
  94081. static FlacNamespace::FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FlacNamespace::FLAC__StreamEncoder*,
  94082. const FlacNamespace::FLAC__byte buffer[],
  94083. size_t bytes,
  94084. unsigned int /*samples*/,
  94085. unsigned int /*current_frame*/,
  94086. void* client_data)
  94087. {
  94088. using namespace FlacNamespace;
  94089. return static_cast <FlacWriter*> (client_data)->writeData (buffer, (int) bytes)
  94090. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94091. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94092. }
  94093. static FlacNamespace::FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64, void*)
  94094. {
  94095. using namespace FlacNamespace;
  94096. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94097. }
  94098. static FlacNamespace::FLAC__StreamEncoderTellStatus encodeTellCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  94099. {
  94100. using namespace FlacNamespace;
  94101. if (client_data == 0)
  94102. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94103. *absolute_byte_offset = (FLAC__uint64) static_cast <FlacWriter*> (client_data)->output->getPosition();
  94104. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94105. }
  94106. static void encodeMetadataCallback (const FlacNamespace::FLAC__StreamEncoder*, const FlacNamespace::FLAC__StreamMetadata* metadata, void* client_data)
  94107. {
  94108. static_cast <FlacWriter*> (client_data)->writeMetaData (metadata);
  94109. }
  94110. juce_UseDebuggingNewOperator
  94111. bool ok;
  94112. private:
  94113. FlacNamespace::FLAC__StreamEncoder* encoder;
  94114. MemoryBlock temp;
  94115. FlacWriter (const FlacWriter&);
  94116. FlacWriter& operator= (const FlacWriter&);
  94117. };
  94118. FlacAudioFormat::FlacAudioFormat()
  94119. : AudioFormat (TRANS (flacFormatName), (const juce_wchar**) flacExtensions)
  94120. {
  94121. }
  94122. FlacAudioFormat::~FlacAudioFormat()
  94123. {
  94124. }
  94125. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94126. {
  94127. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94128. return Array <int> (rates);
  94129. }
  94130. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94131. {
  94132. const int depths[] = { 16, 24, 0 };
  94133. return Array <int> (depths);
  94134. }
  94135. bool FlacAudioFormat::canDoStereo()
  94136. {
  94137. return true;
  94138. }
  94139. bool FlacAudioFormat::canDoMono()
  94140. {
  94141. return true;
  94142. }
  94143. bool FlacAudioFormat::isCompressed()
  94144. {
  94145. return true;
  94146. }
  94147. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94148. const bool deleteStreamIfOpeningFails)
  94149. {
  94150. ScopedPointer<FlacReader> r (new FlacReader (in));
  94151. if (r->sampleRate != 0)
  94152. return r.release();
  94153. if (! deleteStreamIfOpeningFails)
  94154. r->input = 0;
  94155. return 0;
  94156. }
  94157. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94158. double sampleRate,
  94159. unsigned int numberOfChannels,
  94160. int bitsPerSample,
  94161. const StringPairArray& /*metadataValues*/,
  94162. int /*qualityOptionIndex*/)
  94163. {
  94164. if (getPossibleBitDepths().contains (bitsPerSample))
  94165. {
  94166. ScopedPointer<FlacWriter> w (new FlacWriter (out, sampleRate, numberOfChannels, bitsPerSample));
  94167. if (w->ok)
  94168. return w.release();
  94169. }
  94170. return 0;
  94171. }
  94172. END_JUCE_NAMESPACE
  94173. #endif
  94174. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94175. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94176. #if JUCE_USE_OGGVORBIS
  94177. #if JUCE_MAC
  94178. #define __MACOSX__ 1
  94179. #endif
  94180. namespace OggVorbisNamespace
  94181. {
  94182. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94183. /*** Start of inlined file: vorbisenc.h ***/
  94184. #ifndef _OV_ENC_H_
  94185. #define _OV_ENC_H_
  94186. #ifdef __cplusplus
  94187. extern "C"
  94188. {
  94189. #endif /* __cplusplus */
  94190. /*** Start of inlined file: codec.h ***/
  94191. #ifndef _vorbis_codec_h_
  94192. #define _vorbis_codec_h_
  94193. #ifdef __cplusplus
  94194. extern "C"
  94195. {
  94196. #endif /* __cplusplus */
  94197. /*** Start of inlined file: ogg.h ***/
  94198. #ifndef _OGG_H
  94199. #define _OGG_H
  94200. #ifdef __cplusplus
  94201. extern "C" {
  94202. #endif
  94203. /*** Start of inlined file: os_types.h ***/
  94204. #ifndef _OS_TYPES_H
  94205. #define _OS_TYPES_H
  94206. #define _ogg_malloc malloc
  94207. #define _ogg_calloc calloc
  94208. #define _ogg_realloc realloc
  94209. #define _ogg_free free
  94210. #if defined(_WIN32)
  94211. # if defined(__CYGWIN__)
  94212. # include <_G_config.h>
  94213. typedef _G_int64_t ogg_int64_t;
  94214. typedef _G_int32_t ogg_int32_t;
  94215. typedef _G_uint32_t ogg_uint32_t;
  94216. typedef _G_int16_t ogg_int16_t;
  94217. typedef _G_uint16_t ogg_uint16_t;
  94218. # elif defined(__MINGW32__)
  94219. typedef short ogg_int16_t;
  94220. typedef unsigned short ogg_uint16_t;
  94221. typedef int ogg_int32_t;
  94222. typedef unsigned int ogg_uint32_t;
  94223. typedef long long ogg_int64_t;
  94224. typedef unsigned long long ogg_uint64_t;
  94225. # elif defined(__MWERKS__)
  94226. typedef long long ogg_int64_t;
  94227. typedef int ogg_int32_t;
  94228. typedef unsigned int ogg_uint32_t;
  94229. typedef short ogg_int16_t;
  94230. typedef unsigned short ogg_uint16_t;
  94231. # else
  94232. typedef __int64 ogg_int64_t;
  94233. typedef __int32 ogg_int32_t;
  94234. typedef unsigned __int32 ogg_uint32_t;
  94235. typedef __int16 ogg_int16_t;
  94236. typedef unsigned __int16 ogg_uint16_t;
  94237. # endif
  94238. #elif defined(__MACOS__)
  94239. # include <sys/types.h>
  94240. typedef SInt16 ogg_int16_t;
  94241. typedef UInt16 ogg_uint16_t;
  94242. typedef SInt32 ogg_int32_t;
  94243. typedef UInt32 ogg_uint32_t;
  94244. typedef SInt64 ogg_int64_t;
  94245. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94246. # include <sys/types.h>
  94247. typedef int16_t ogg_int16_t;
  94248. typedef u_int16_t ogg_uint16_t;
  94249. typedef int32_t ogg_int32_t;
  94250. typedef u_int32_t ogg_uint32_t;
  94251. typedef int64_t ogg_int64_t;
  94252. #elif defined(__BEOS__)
  94253. # include <inttypes.h>
  94254. typedef int16_t ogg_int16_t;
  94255. typedef u_int16_t ogg_uint16_t;
  94256. typedef int32_t ogg_int32_t;
  94257. typedef u_int32_t ogg_uint32_t;
  94258. typedef int64_t ogg_int64_t;
  94259. #elif defined (__EMX__)
  94260. typedef short ogg_int16_t;
  94261. typedef unsigned short ogg_uint16_t;
  94262. typedef int ogg_int32_t;
  94263. typedef unsigned int ogg_uint32_t;
  94264. typedef long long ogg_int64_t;
  94265. #elif defined (DJGPP)
  94266. typedef short ogg_int16_t;
  94267. typedef int ogg_int32_t;
  94268. typedef unsigned int ogg_uint32_t;
  94269. typedef long long ogg_int64_t;
  94270. #elif defined(R5900)
  94271. typedef long ogg_int64_t;
  94272. typedef int ogg_int32_t;
  94273. typedef unsigned ogg_uint32_t;
  94274. typedef short ogg_int16_t;
  94275. #elif defined(__SYMBIAN32__)
  94276. typedef signed short ogg_int16_t;
  94277. typedef unsigned short ogg_uint16_t;
  94278. typedef signed int ogg_int32_t;
  94279. typedef unsigned int ogg_uint32_t;
  94280. typedef long long int ogg_int64_t;
  94281. #else
  94282. # include <sys/types.h>
  94283. /*** Start of inlined file: config_types.h ***/
  94284. #ifndef __CONFIG_TYPES_H__
  94285. #define __CONFIG_TYPES_H__
  94286. typedef int16_t ogg_int16_t;
  94287. typedef unsigned short ogg_uint16_t;
  94288. typedef int32_t ogg_int32_t;
  94289. typedef unsigned int ogg_uint32_t;
  94290. typedef int64_t ogg_int64_t;
  94291. #endif
  94292. /*** End of inlined file: config_types.h ***/
  94293. #endif
  94294. #endif /* _OS_TYPES_H */
  94295. /*** End of inlined file: os_types.h ***/
  94296. typedef struct {
  94297. long endbyte;
  94298. int endbit;
  94299. unsigned char *buffer;
  94300. unsigned char *ptr;
  94301. long storage;
  94302. } oggpack_buffer;
  94303. typedef struct {
  94304. unsigned char *header;
  94305. long header_len;
  94306. unsigned char *body;
  94307. long body_len;
  94308. } ogg_page;
  94309. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94310. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94311. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94312. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94313. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94314. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94315. }
  94316. typedef struct {
  94317. unsigned char *body_data; /* bytes from packet bodies */
  94318. long body_storage; /* storage elements allocated */
  94319. long body_fill; /* elements stored; fill mark */
  94320. long body_returned; /* elements of fill returned */
  94321. int *lacing_vals; /* The values that will go to the segment table */
  94322. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94323. this way, but it is simple coupled to the
  94324. lacing fifo */
  94325. long lacing_storage;
  94326. long lacing_fill;
  94327. long lacing_packet;
  94328. long lacing_returned;
  94329. unsigned char header[282]; /* working space for header encode */
  94330. int header_fill;
  94331. int e_o_s; /* set when we have buffered the last packet in the
  94332. logical bitstream */
  94333. int b_o_s; /* set after we've written the initial page
  94334. of a logical bitstream */
  94335. long serialno;
  94336. long pageno;
  94337. ogg_int64_t packetno; /* sequence number for decode; the framing
  94338. knows where there's a hole in the data,
  94339. but we need coupling so that the codec
  94340. (which is in a seperate abstraction
  94341. layer) also knows about the gap */
  94342. ogg_int64_t granulepos;
  94343. } ogg_stream_state;
  94344. typedef struct {
  94345. unsigned char *packet;
  94346. long bytes;
  94347. long b_o_s;
  94348. long e_o_s;
  94349. ogg_int64_t granulepos;
  94350. ogg_int64_t packetno; /* sequence number for decode; the framing
  94351. knows where there's a hole in the data,
  94352. but we need coupling so that the codec
  94353. (which is in a seperate abstraction
  94354. layer) also knows about the gap */
  94355. } ogg_packet;
  94356. typedef struct {
  94357. unsigned char *data;
  94358. int storage;
  94359. int fill;
  94360. int returned;
  94361. int unsynced;
  94362. int headerbytes;
  94363. int bodybytes;
  94364. } ogg_sync_state;
  94365. extern void oggpack_writeinit(oggpack_buffer *b);
  94366. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94367. extern void oggpack_writealign(oggpack_buffer *b);
  94368. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94369. extern void oggpack_reset(oggpack_buffer *b);
  94370. extern void oggpack_writeclear(oggpack_buffer *b);
  94371. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94372. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94373. extern long oggpack_look(oggpack_buffer *b,int bits);
  94374. extern long oggpack_look1(oggpack_buffer *b);
  94375. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94376. extern void oggpack_adv1(oggpack_buffer *b);
  94377. extern long oggpack_read(oggpack_buffer *b,int bits);
  94378. extern long oggpack_read1(oggpack_buffer *b);
  94379. extern long oggpack_bytes(oggpack_buffer *b);
  94380. extern long oggpack_bits(oggpack_buffer *b);
  94381. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94382. extern void oggpackB_writeinit(oggpack_buffer *b);
  94383. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94384. extern void oggpackB_writealign(oggpack_buffer *b);
  94385. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94386. extern void oggpackB_reset(oggpack_buffer *b);
  94387. extern void oggpackB_writeclear(oggpack_buffer *b);
  94388. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94389. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94390. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94391. extern long oggpackB_look1(oggpack_buffer *b);
  94392. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94393. extern void oggpackB_adv1(oggpack_buffer *b);
  94394. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94395. extern long oggpackB_read1(oggpack_buffer *b);
  94396. extern long oggpackB_bytes(oggpack_buffer *b);
  94397. extern long oggpackB_bits(oggpack_buffer *b);
  94398. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94399. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94400. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94401. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94402. extern int ogg_sync_init(ogg_sync_state *oy);
  94403. extern int ogg_sync_clear(ogg_sync_state *oy);
  94404. extern int ogg_sync_reset(ogg_sync_state *oy);
  94405. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94406. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94407. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94408. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94409. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94410. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94411. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94412. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94413. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94414. extern int ogg_stream_clear(ogg_stream_state *os);
  94415. extern int ogg_stream_reset(ogg_stream_state *os);
  94416. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94417. extern int ogg_stream_destroy(ogg_stream_state *os);
  94418. extern int ogg_stream_eos(ogg_stream_state *os);
  94419. extern void ogg_page_checksum_set(ogg_page *og);
  94420. extern int ogg_page_version(ogg_page *og);
  94421. extern int ogg_page_continued(ogg_page *og);
  94422. extern int ogg_page_bos(ogg_page *og);
  94423. extern int ogg_page_eos(ogg_page *og);
  94424. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94425. extern int ogg_page_serialno(ogg_page *og);
  94426. extern long ogg_page_pageno(ogg_page *og);
  94427. extern int ogg_page_packets(ogg_page *og);
  94428. extern void ogg_packet_clear(ogg_packet *op);
  94429. #ifdef __cplusplus
  94430. }
  94431. #endif
  94432. #endif /* _OGG_H */
  94433. /*** End of inlined file: ogg.h ***/
  94434. typedef struct vorbis_info{
  94435. int version;
  94436. int channels;
  94437. long rate;
  94438. long bitrate_upper;
  94439. long bitrate_nominal;
  94440. long bitrate_lower;
  94441. long bitrate_window;
  94442. void *codec_setup;
  94443. } vorbis_info;
  94444. typedef struct vorbis_dsp_state{
  94445. int analysisp;
  94446. vorbis_info *vi;
  94447. float **pcm;
  94448. float **pcmret;
  94449. int pcm_storage;
  94450. int pcm_current;
  94451. int pcm_returned;
  94452. int preextrapolate;
  94453. int eofflag;
  94454. long lW;
  94455. long W;
  94456. long nW;
  94457. long centerW;
  94458. ogg_int64_t granulepos;
  94459. ogg_int64_t sequence;
  94460. ogg_int64_t glue_bits;
  94461. ogg_int64_t time_bits;
  94462. ogg_int64_t floor_bits;
  94463. ogg_int64_t res_bits;
  94464. void *backend_state;
  94465. } vorbis_dsp_state;
  94466. typedef struct vorbis_block{
  94467. float **pcm; /* this is a pointer into local storage */
  94468. oggpack_buffer opb;
  94469. long lW;
  94470. long W;
  94471. long nW;
  94472. int pcmend;
  94473. int mode;
  94474. int eofflag;
  94475. ogg_int64_t granulepos;
  94476. ogg_int64_t sequence;
  94477. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94478. void *localstore;
  94479. long localtop;
  94480. long localalloc;
  94481. long totaluse;
  94482. struct alloc_chain *reap;
  94483. long glue_bits;
  94484. long time_bits;
  94485. long floor_bits;
  94486. long res_bits;
  94487. void *internal;
  94488. } vorbis_block;
  94489. struct alloc_chain{
  94490. void *ptr;
  94491. struct alloc_chain *next;
  94492. };
  94493. typedef struct vorbis_comment{
  94494. char **user_comments;
  94495. int *comment_lengths;
  94496. int comments;
  94497. char *vendor;
  94498. } vorbis_comment;
  94499. extern void vorbis_info_init(vorbis_info *vi);
  94500. extern void vorbis_info_clear(vorbis_info *vi);
  94501. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94502. extern void vorbis_comment_init(vorbis_comment *vc);
  94503. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94504. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94505. const char *tag, char *contents);
  94506. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94507. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94508. extern void vorbis_comment_clear(vorbis_comment *vc);
  94509. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94510. extern int vorbis_block_clear(vorbis_block *vb);
  94511. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94512. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94513. ogg_int64_t granulepos);
  94514. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94515. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94516. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94517. vorbis_comment *vc,
  94518. ogg_packet *op,
  94519. ogg_packet *op_comm,
  94520. ogg_packet *op_code);
  94521. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94522. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94523. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94524. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94525. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94526. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94527. ogg_packet *op);
  94528. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94529. ogg_packet *op);
  94530. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94531. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94532. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94533. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94534. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  94535. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  94536. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  94537. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  94538. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  94539. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  94540. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  94541. #define OV_FALSE -1
  94542. #define OV_EOF -2
  94543. #define OV_HOLE -3
  94544. #define OV_EREAD -128
  94545. #define OV_EFAULT -129
  94546. #define OV_EIMPL -130
  94547. #define OV_EINVAL -131
  94548. #define OV_ENOTVORBIS -132
  94549. #define OV_EBADHEADER -133
  94550. #define OV_EVERSION -134
  94551. #define OV_ENOTAUDIO -135
  94552. #define OV_EBADPACKET -136
  94553. #define OV_EBADLINK -137
  94554. #define OV_ENOSEEK -138
  94555. #ifdef __cplusplus
  94556. }
  94557. #endif /* __cplusplus */
  94558. #endif
  94559. /*** End of inlined file: codec.h ***/
  94560. extern int vorbis_encode_init(vorbis_info *vi,
  94561. long channels,
  94562. long rate,
  94563. long max_bitrate,
  94564. long nominal_bitrate,
  94565. long min_bitrate);
  94566. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  94567. long channels,
  94568. long rate,
  94569. long max_bitrate,
  94570. long nominal_bitrate,
  94571. long min_bitrate);
  94572. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  94573. long channels,
  94574. long rate,
  94575. float quality /* quality level from 0. (lo) to 1. (hi) */
  94576. );
  94577. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  94578. long channels,
  94579. long rate,
  94580. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  94581. );
  94582. extern int vorbis_encode_setup_init(vorbis_info *vi);
  94583. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  94584. #define OV_ECTL_RATEMANAGE_GET 0x10
  94585. #define OV_ECTL_RATEMANAGE_SET 0x11
  94586. #define OV_ECTL_RATEMANAGE_AVG 0x12
  94587. #define OV_ECTL_RATEMANAGE_HARD 0x13
  94588. struct ovectl_ratemanage_arg {
  94589. int management_active;
  94590. long bitrate_hard_min;
  94591. long bitrate_hard_max;
  94592. double bitrate_hard_window;
  94593. long bitrate_av_lo;
  94594. long bitrate_av_hi;
  94595. double bitrate_av_window;
  94596. double bitrate_av_window_center;
  94597. };
  94598. #define OV_ECTL_RATEMANAGE2_GET 0x14
  94599. #define OV_ECTL_RATEMANAGE2_SET 0x15
  94600. struct ovectl_ratemanage2_arg {
  94601. int management_active;
  94602. long bitrate_limit_min_kbps;
  94603. long bitrate_limit_max_kbps;
  94604. long bitrate_limit_reservoir_bits;
  94605. double bitrate_limit_reservoir_bias;
  94606. long bitrate_average_kbps;
  94607. double bitrate_average_damping;
  94608. };
  94609. #define OV_ECTL_LOWPASS_GET 0x20
  94610. #define OV_ECTL_LOWPASS_SET 0x21
  94611. #define OV_ECTL_IBLOCK_GET 0x30
  94612. #define OV_ECTL_IBLOCK_SET 0x31
  94613. #ifdef __cplusplus
  94614. }
  94615. #endif /* __cplusplus */
  94616. #endif
  94617. /*** End of inlined file: vorbisenc.h ***/
  94618. /*** Start of inlined file: vorbisfile.h ***/
  94619. #ifndef _OV_FILE_H_
  94620. #define _OV_FILE_H_
  94621. #ifdef __cplusplus
  94622. extern "C"
  94623. {
  94624. #endif /* __cplusplus */
  94625. #include <stdio.h>
  94626. typedef struct {
  94627. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  94628. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  94629. int (*close_func) (void *datasource);
  94630. long (*tell_func) (void *datasource);
  94631. } ov_callbacks;
  94632. #define NOTOPEN 0
  94633. #define PARTOPEN 1
  94634. #define OPENED 2
  94635. #define STREAMSET 3
  94636. #define INITSET 4
  94637. typedef struct OggVorbis_File {
  94638. void *datasource; /* Pointer to a FILE *, etc. */
  94639. int seekable;
  94640. ogg_int64_t offset;
  94641. ogg_int64_t end;
  94642. ogg_sync_state oy;
  94643. int links;
  94644. ogg_int64_t *offsets;
  94645. ogg_int64_t *dataoffsets;
  94646. long *serialnos;
  94647. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  94648. compatability; x2 size, stores both
  94649. beginning and end values */
  94650. vorbis_info *vi;
  94651. vorbis_comment *vc;
  94652. ogg_int64_t pcm_offset;
  94653. int ready_state;
  94654. long current_serialno;
  94655. int current_link;
  94656. double bittrack;
  94657. double samptrack;
  94658. ogg_stream_state os; /* take physical pages, weld into a logical
  94659. stream of packets */
  94660. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  94661. vorbis_block vb; /* local working space for packet->PCM decode */
  94662. ov_callbacks callbacks;
  94663. } OggVorbis_File;
  94664. extern int ov_clear(OggVorbis_File *vf);
  94665. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94666. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  94667. char *initial, long ibytes, ov_callbacks callbacks);
  94668. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94669. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  94670. char *initial, long ibytes, ov_callbacks callbacks);
  94671. extern int ov_test_open(OggVorbis_File *vf);
  94672. extern long ov_bitrate(OggVorbis_File *vf,int i);
  94673. extern long ov_bitrate_instant(OggVorbis_File *vf);
  94674. extern long ov_streams(OggVorbis_File *vf);
  94675. extern long ov_seekable(OggVorbis_File *vf);
  94676. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  94677. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  94678. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  94679. extern double ov_time_total(OggVorbis_File *vf,int i);
  94680. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94681. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94682. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  94683. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  94684. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  94685. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94686. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94687. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94688. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  94689. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  94690. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  94691. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  94692. extern double ov_time_tell(OggVorbis_File *vf);
  94693. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  94694. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  94695. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  94696. int *bitstream);
  94697. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  94698. int bigendianp,int word,int sgned,int *bitstream);
  94699. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  94700. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  94701. extern int ov_halfrate_p(OggVorbis_File *vf);
  94702. #ifdef __cplusplus
  94703. }
  94704. #endif /* __cplusplus */
  94705. #endif
  94706. /*** End of inlined file: vorbisfile.h ***/
  94707. /*** Start of inlined file: bitwise.c ***/
  94708. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  94709. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  94710. // tasks..
  94711. #if JUCE_MSVC
  94712. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  94713. #endif
  94714. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  94715. #if JUCE_USE_OGGVORBIS
  94716. #include <string.h>
  94717. #include <stdlib.h>
  94718. #define BUFFER_INCREMENT 256
  94719. static const unsigned long mask[]=
  94720. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  94721. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  94722. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  94723. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  94724. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  94725. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  94726. 0x3fffffff,0x7fffffff,0xffffffff };
  94727. static const unsigned int mask8B[]=
  94728. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  94729. void oggpack_writeinit(oggpack_buffer *b){
  94730. memset(b,0,sizeof(*b));
  94731. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  94732. b->buffer[0]='\0';
  94733. b->storage=BUFFER_INCREMENT;
  94734. }
  94735. void oggpackB_writeinit(oggpack_buffer *b){
  94736. oggpack_writeinit(b);
  94737. }
  94738. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  94739. long bytes=bits>>3;
  94740. bits-=bytes*8;
  94741. b->ptr=b->buffer+bytes;
  94742. b->endbit=bits;
  94743. b->endbyte=bytes;
  94744. *b->ptr&=mask[bits];
  94745. }
  94746. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  94747. long bytes=bits>>3;
  94748. bits-=bytes*8;
  94749. b->ptr=b->buffer+bytes;
  94750. b->endbit=bits;
  94751. b->endbyte=bytes;
  94752. *b->ptr&=mask8B[bits];
  94753. }
  94754. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  94755. if(b->endbyte+4>=b->storage){
  94756. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94757. b->storage+=BUFFER_INCREMENT;
  94758. b->ptr=b->buffer+b->endbyte;
  94759. }
  94760. value&=mask[bits];
  94761. bits+=b->endbit;
  94762. b->ptr[0]|=value<<b->endbit;
  94763. if(bits>=8){
  94764. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  94765. if(bits>=16){
  94766. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  94767. if(bits>=24){
  94768. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  94769. if(bits>=32){
  94770. if(b->endbit)
  94771. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  94772. else
  94773. b->ptr[4]=0;
  94774. }
  94775. }
  94776. }
  94777. }
  94778. b->endbyte+=bits/8;
  94779. b->ptr+=bits/8;
  94780. b->endbit=bits&7;
  94781. }
  94782. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  94783. if(b->endbyte+4>=b->storage){
  94784. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94785. b->storage+=BUFFER_INCREMENT;
  94786. b->ptr=b->buffer+b->endbyte;
  94787. }
  94788. value=(value&mask[bits])<<(32-bits);
  94789. bits+=b->endbit;
  94790. b->ptr[0]|=value>>(24+b->endbit);
  94791. if(bits>=8){
  94792. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  94793. if(bits>=16){
  94794. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  94795. if(bits>=24){
  94796. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  94797. if(bits>=32){
  94798. if(b->endbit)
  94799. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  94800. else
  94801. b->ptr[4]=0;
  94802. }
  94803. }
  94804. }
  94805. }
  94806. b->endbyte+=bits/8;
  94807. b->ptr+=bits/8;
  94808. b->endbit=bits&7;
  94809. }
  94810. void oggpack_writealign(oggpack_buffer *b){
  94811. int bits=8-b->endbit;
  94812. if(bits<8)
  94813. oggpack_write(b,0,bits);
  94814. }
  94815. void oggpackB_writealign(oggpack_buffer *b){
  94816. int bits=8-b->endbit;
  94817. if(bits<8)
  94818. oggpackB_write(b,0,bits);
  94819. }
  94820. static void oggpack_writecopy_helper(oggpack_buffer *b,
  94821. void *source,
  94822. long bits,
  94823. void (*w)(oggpack_buffer *,
  94824. unsigned long,
  94825. int),
  94826. int msb){
  94827. unsigned char *ptr=(unsigned char *)source;
  94828. long bytes=bits/8;
  94829. bits-=bytes*8;
  94830. if(b->endbit){
  94831. int i;
  94832. for(i=0;i<bytes;i++)
  94833. w(b,(unsigned long)(ptr[i]),8);
  94834. }else{
  94835. if(b->endbyte+bytes+1>=b->storage){
  94836. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  94837. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  94838. b->ptr=b->buffer+b->endbyte;
  94839. }
  94840. memmove(b->ptr,source,bytes);
  94841. b->ptr+=bytes;
  94842. b->endbyte+=bytes;
  94843. *b->ptr=0;
  94844. }
  94845. if(bits){
  94846. if(msb)
  94847. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  94848. else
  94849. w(b,(unsigned long)(ptr[bytes]),bits);
  94850. }
  94851. }
  94852. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  94853. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  94854. }
  94855. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  94856. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  94857. }
  94858. void oggpack_reset(oggpack_buffer *b){
  94859. b->ptr=b->buffer;
  94860. b->buffer[0]=0;
  94861. b->endbit=b->endbyte=0;
  94862. }
  94863. void oggpackB_reset(oggpack_buffer *b){
  94864. oggpack_reset(b);
  94865. }
  94866. void oggpack_writeclear(oggpack_buffer *b){
  94867. _ogg_free(b->buffer);
  94868. memset(b,0,sizeof(*b));
  94869. }
  94870. void oggpackB_writeclear(oggpack_buffer *b){
  94871. oggpack_writeclear(b);
  94872. }
  94873. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94874. memset(b,0,sizeof(*b));
  94875. b->buffer=b->ptr=buf;
  94876. b->storage=bytes;
  94877. }
  94878. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94879. oggpack_readinit(b,buf,bytes);
  94880. }
  94881. long oggpack_look(oggpack_buffer *b,int bits){
  94882. unsigned long ret;
  94883. unsigned long m=mask[bits];
  94884. bits+=b->endbit;
  94885. if(b->endbyte+4>=b->storage){
  94886. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94887. }
  94888. ret=b->ptr[0]>>b->endbit;
  94889. if(bits>8){
  94890. ret|=b->ptr[1]<<(8-b->endbit);
  94891. if(bits>16){
  94892. ret|=b->ptr[2]<<(16-b->endbit);
  94893. if(bits>24){
  94894. ret|=b->ptr[3]<<(24-b->endbit);
  94895. if(bits>32 && b->endbit)
  94896. ret|=b->ptr[4]<<(32-b->endbit);
  94897. }
  94898. }
  94899. }
  94900. return(m&ret);
  94901. }
  94902. long oggpackB_look(oggpack_buffer *b,int bits){
  94903. unsigned long ret;
  94904. int m=32-bits;
  94905. bits+=b->endbit;
  94906. if(b->endbyte+4>=b->storage){
  94907. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94908. }
  94909. ret=b->ptr[0]<<(24+b->endbit);
  94910. if(bits>8){
  94911. ret|=b->ptr[1]<<(16+b->endbit);
  94912. if(bits>16){
  94913. ret|=b->ptr[2]<<(8+b->endbit);
  94914. if(bits>24){
  94915. ret|=b->ptr[3]<<(b->endbit);
  94916. if(bits>32 && b->endbit)
  94917. ret|=b->ptr[4]>>(8-b->endbit);
  94918. }
  94919. }
  94920. }
  94921. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  94922. }
  94923. long oggpack_look1(oggpack_buffer *b){
  94924. if(b->endbyte>=b->storage)return(-1);
  94925. return((b->ptr[0]>>b->endbit)&1);
  94926. }
  94927. long oggpackB_look1(oggpack_buffer *b){
  94928. if(b->endbyte>=b->storage)return(-1);
  94929. return((b->ptr[0]>>(7-b->endbit))&1);
  94930. }
  94931. void oggpack_adv(oggpack_buffer *b,int bits){
  94932. bits+=b->endbit;
  94933. b->ptr+=bits/8;
  94934. b->endbyte+=bits/8;
  94935. b->endbit=bits&7;
  94936. }
  94937. void oggpackB_adv(oggpack_buffer *b,int bits){
  94938. oggpack_adv(b,bits);
  94939. }
  94940. void oggpack_adv1(oggpack_buffer *b){
  94941. if(++(b->endbit)>7){
  94942. b->endbit=0;
  94943. b->ptr++;
  94944. b->endbyte++;
  94945. }
  94946. }
  94947. void oggpackB_adv1(oggpack_buffer *b){
  94948. oggpack_adv1(b);
  94949. }
  94950. long oggpack_read(oggpack_buffer *b,int bits){
  94951. long ret;
  94952. unsigned long m=mask[bits];
  94953. bits+=b->endbit;
  94954. if(b->endbyte+4>=b->storage){
  94955. ret=-1L;
  94956. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94957. }
  94958. ret=b->ptr[0]>>b->endbit;
  94959. if(bits>8){
  94960. ret|=b->ptr[1]<<(8-b->endbit);
  94961. if(bits>16){
  94962. ret|=b->ptr[2]<<(16-b->endbit);
  94963. if(bits>24){
  94964. ret|=b->ptr[3]<<(24-b->endbit);
  94965. if(bits>32 && b->endbit){
  94966. ret|=b->ptr[4]<<(32-b->endbit);
  94967. }
  94968. }
  94969. }
  94970. }
  94971. ret&=m;
  94972. overflow:
  94973. b->ptr+=bits/8;
  94974. b->endbyte+=bits/8;
  94975. b->endbit=bits&7;
  94976. return(ret);
  94977. }
  94978. long oggpackB_read(oggpack_buffer *b,int bits){
  94979. long ret;
  94980. long m=32-bits;
  94981. bits+=b->endbit;
  94982. if(b->endbyte+4>=b->storage){
  94983. ret=-1L;
  94984. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94985. }
  94986. ret=b->ptr[0]<<(24+b->endbit);
  94987. if(bits>8){
  94988. ret|=b->ptr[1]<<(16+b->endbit);
  94989. if(bits>16){
  94990. ret|=b->ptr[2]<<(8+b->endbit);
  94991. if(bits>24){
  94992. ret|=b->ptr[3]<<(b->endbit);
  94993. if(bits>32 && b->endbit)
  94994. ret|=b->ptr[4]>>(8-b->endbit);
  94995. }
  94996. }
  94997. }
  94998. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  94999. overflow:
  95000. b->ptr+=bits/8;
  95001. b->endbyte+=bits/8;
  95002. b->endbit=bits&7;
  95003. return(ret);
  95004. }
  95005. long oggpack_read1(oggpack_buffer *b){
  95006. long ret;
  95007. if(b->endbyte>=b->storage){
  95008. ret=-1L;
  95009. goto overflow;
  95010. }
  95011. ret=(b->ptr[0]>>b->endbit)&1;
  95012. overflow:
  95013. b->endbit++;
  95014. if(b->endbit>7){
  95015. b->endbit=0;
  95016. b->ptr++;
  95017. b->endbyte++;
  95018. }
  95019. return(ret);
  95020. }
  95021. long oggpackB_read1(oggpack_buffer *b){
  95022. long ret;
  95023. if(b->endbyte>=b->storage){
  95024. ret=-1L;
  95025. goto overflow;
  95026. }
  95027. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95028. overflow:
  95029. b->endbit++;
  95030. if(b->endbit>7){
  95031. b->endbit=0;
  95032. b->ptr++;
  95033. b->endbyte++;
  95034. }
  95035. return(ret);
  95036. }
  95037. long oggpack_bytes(oggpack_buffer *b){
  95038. return(b->endbyte+(b->endbit+7)/8);
  95039. }
  95040. long oggpack_bits(oggpack_buffer *b){
  95041. return(b->endbyte*8+b->endbit);
  95042. }
  95043. long oggpackB_bytes(oggpack_buffer *b){
  95044. return oggpack_bytes(b);
  95045. }
  95046. long oggpackB_bits(oggpack_buffer *b){
  95047. return oggpack_bits(b);
  95048. }
  95049. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95050. return(b->buffer);
  95051. }
  95052. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95053. return oggpack_get_buffer(b);
  95054. }
  95055. #ifdef _V_SELFTEST
  95056. #include <stdio.h>
  95057. static int ilog(unsigned int v){
  95058. int ret=0;
  95059. while(v){
  95060. ret++;
  95061. v>>=1;
  95062. }
  95063. return(ret);
  95064. }
  95065. oggpack_buffer o;
  95066. oggpack_buffer r;
  95067. void report(char *in){
  95068. fprintf(stderr,"%s",in);
  95069. exit(1);
  95070. }
  95071. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95072. long bytes,i;
  95073. unsigned char *buffer;
  95074. oggpack_reset(&o);
  95075. for(i=0;i<vals;i++)
  95076. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95077. buffer=oggpack_get_buffer(&o);
  95078. bytes=oggpack_bytes(&o);
  95079. if(bytes!=compsize)report("wrong number of bytes!\n");
  95080. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95081. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95082. report("wrote incorrect value!\n");
  95083. }
  95084. oggpack_readinit(&r,buffer,bytes);
  95085. for(i=0;i<vals;i++){
  95086. int tbit=bits?bits:ilog(b[i]);
  95087. if(oggpack_look(&r,tbit)==-1)
  95088. report("out of data!\n");
  95089. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95090. report("looked at incorrect value!\n");
  95091. if(tbit==1)
  95092. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95093. report("looked at single bit incorrect value!\n");
  95094. if(tbit==1){
  95095. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95096. report("read incorrect single bit value!\n");
  95097. }else{
  95098. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95099. report("read incorrect value!\n");
  95100. }
  95101. }
  95102. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95103. }
  95104. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95105. long bytes,i;
  95106. unsigned char *buffer;
  95107. oggpackB_reset(&o);
  95108. for(i=0;i<vals;i++)
  95109. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95110. buffer=oggpackB_get_buffer(&o);
  95111. bytes=oggpackB_bytes(&o);
  95112. if(bytes!=compsize)report("wrong number of bytes!\n");
  95113. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95114. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95115. report("wrote incorrect value!\n");
  95116. }
  95117. oggpackB_readinit(&r,buffer,bytes);
  95118. for(i=0;i<vals;i++){
  95119. int tbit=bits?bits:ilog(b[i]);
  95120. if(oggpackB_look(&r,tbit)==-1)
  95121. report("out of data!\n");
  95122. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95123. report("looked at incorrect value!\n");
  95124. if(tbit==1)
  95125. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95126. report("looked at single bit incorrect value!\n");
  95127. if(tbit==1){
  95128. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95129. report("read incorrect single bit value!\n");
  95130. }else{
  95131. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95132. report("read incorrect value!\n");
  95133. }
  95134. }
  95135. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95136. }
  95137. int main(void){
  95138. unsigned char *buffer;
  95139. long bytes,i;
  95140. static unsigned long testbuffer1[]=
  95141. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95142. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95143. int test1size=43;
  95144. static unsigned long testbuffer2[]=
  95145. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95146. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95147. 85525151,0,12321,1,349528352};
  95148. int test2size=21;
  95149. static unsigned long testbuffer3[]=
  95150. {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,
  95151. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95152. int test3size=56;
  95153. static unsigned long large[]=
  95154. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95155. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95156. 85525151,0,12321,1,2146528352};
  95157. int onesize=33;
  95158. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95159. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95160. 223,4};
  95161. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95162. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95163. 245,251,128};
  95164. int twosize=6;
  95165. static int two[6]={61,255,255,251,231,29};
  95166. static int twoB[6]={247,63,255,253,249,120};
  95167. int threesize=54;
  95168. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95169. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95170. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95171. 100,52,4,14,18,86,77,1};
  95172. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95173. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95174. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95175. 200,20,254,4,58,106,176,144,0};
  95176. int foursize=38;
  95177. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95178. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95179. 28,2,133,0,1};
  95180. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95181. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95182. 129,10,4,32};
  95183. int fivesize=45;
  95184. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95185. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95186. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95187. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95188. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95189. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95190. int sixsize=7;
  95191. static int six[7]={17,177,170,242,169,19,148};
  95192. static int sixB[7]={136,141,85,79,149,200,41};
  95193. oggpack_writeinit(&o);
  95194. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95195. cliptest(testbuffer1,test1size,0,one,onesize);
  95196. fprintf(stderr,"ok.");
  95197. fprintf(stderr,"\nNull bit call (LSb): ");
  95198. cliptest(testbuffer3,test3size,0,two,twosize);
  95199. fprintf(stderr,"ok.");
  95200. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95201. cliptest(testbuffer2,test2size,0,three,threesize);
  95202. fprintf(stderr,"ok.");
  95203. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95204. oggpack_reset(&o);
  95205. for(i=0;i<test2size;i++)
  95206. oggpack_write(&o,large[i],32);
  95207. buffer=oggpack_get_buffer(&o);
  95208. bytes=oggpack_bytes(&o);
  95209. oggpack_readinit(&r,buffer,bytes);
  95210. for(i=0;i<test2size;i++){
  95211. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95212. if(oggpack_look(&r,32)!=large[i]){
  95213. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95214. oggpack_look(&r,32),large[i]);
  95215. report("read incorrect value!\n");
  95216. }
  95217. oggpack_adv(&r,32);
  95218. }
  95219. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95220. fprintf(stderr,"ok.");
  95221. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95222. cliptest(testbuffer1,test1size,7,four,foursize);
  95223. fprintf(stderr,"ok.");
  95224. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95225. cliptest(testbuffer2,test2size,17,five,fivesize);
  95226. fprintf(stderr,"ok.");
  95227. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95228. cliptest(testbuffer3,test3size,1,six,sixsize);
  95229. fprintf(stderr,"ok.");
  95230. fprintf(stderr,"\nTesting read past end (LSb): ");
  95231. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95232. for(i=0;i<64;i++){
  95233. if(oggpack_read(&r,1)!=0){
  95234. fprintf(stderr,"failed; got -1 prematurely.\n");
  95235. exit(1);
  95236. }
  95237. }
  95238. if(oggpack_look(&r,1)!=-1 ||
  95239. oggpack_read(&r,1)!=-1){
  95240. fprintf(stderr,"failed; read past end without -1.\n");
  95241. exit(1);
  95242. }
  95243. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95244. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95245. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95246. exit(1);
  95247. }
  95248. if(oggpack_look(&r,18)!=0 ||
  95249. oggpack_look(&r,18)!=0){
  95250. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95251. exit(1);
  95252. }
  95253. if(oggpack_look(&r,19)!=-1 ||
  95254. oggpack_look(&r,19)!=-1){
  95255. fprintf(stderr,"failed; read past end without -1.\n");
  95256. exit(1);
  95257. }
  95258. if(oggpack_look(&r,32)!=-1 ||
  95259. oggpack_look(&r,32)!=-1){
  95260. fprintf(stderr,"failed; read past end without -1.\n");
  95261. exit(1);
  95262. }
  95263. oggpack_writeclear(&o);
  95264. fprintf(stderr,"ok.\n");
  95265. oggpackB_writeinit(&o);
  95266. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95267. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95268. fprintf(stderr,"ok.");
  95269. fprintf(stderr,"\nNull bit call (MSb): ");
  95270. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95271. fprintf(stderr,"ok.");
  95272. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95273. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95274. fprintf(stderr,"ok.");
  95275. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95276. oggpackB_reset(&o);
  95277. for(i=0;i<test2size;i++)
  95278. oggpackB_write(&o,large[i],32);
  95279. buffer=oggpackB_get_buffer(&o);
  95280. bytes=oggpackB_bytes(&o);
  95281. oggpackB_readinit(&r,buffer,bytes);
  95282. for(i=0;i<test2size;i++){
  95283. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95284. if(oggpackB_look(&r,32)!=large[i]){
  95285. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95286. oggpackB_look(&r,32),large[i]);
  95287. report("read incorrect value!\n");
  95288. }
  95289. oggpackB_adv(&r,32);
  95290. }
  95291. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95292. fprintf(stderr,"ok.");
  95293. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95294. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95295. fprintf(stderr,"ok.");
  95296. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95297. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95298. fprintf(stderr,"ok.");
  95299. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95300. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95301. fprintf(stderr,"ok.");
  95302. fprintf(stderr,"\nTesting read past end (MSb): ");
  95303. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95304. for(i=0;i<64;i++){
  95305. if(oggpackB_read(&r,1)!=0){
  95306. fprintf(stderr,"failed; got -1 prematurely.\n");
  95307. exit(1);
  95308. }
  95309. }
  95310. if(oggpackB_look(&r,1)!=-1 ||
  95311. oggpackB_read(&r,1)!=-1){
  95312. fprintf(stderr,"failed; read past end without -1.\n");
  95313. exit(1);
  95314. }
  95315. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95316. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95317. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95318. exit(1);
  95319. }
  95320. if(oggpackB_look(&r,18)!=0 ||
  95321. oggpackB_look(&r,18)!=0){
  95322. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95323. exit(1);
  95324. }
  95325. if(oggpackB_look(&r,19)!=-1 ||
  95326. oggpackB_look(&r,19)!=-1){
  95327. fprintf(stderr,"failed; read past end without -1.\n");
  95328. exit(1);
  95329. }
  95330. if(oggpackB_look(&r,32)!=-1 ||
  95331. oggpackB_look(&r,32)!=-1){
  95332. fprintf(stderr,"failed; read past end without -1.\n");
  95333. exit(1);
  95334. }
  95335. oggpackB_writeclear(&o);
  95336. fprintf(stderr,"ok.\n\n");
  95337. return(0);
  95338. }
  95339. #endif /* _V_SELFTEST */
  95340. #undef BUFFER_INCREMENT
  95341. #endif
  95342. /*** End of inlined file: bitwise.c ***/
  95343. /*** Start of inlined file: framing.c ***/
  95344. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95345. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95346. // tasks..
  95347. #if JUCE_MSVC
  95348. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95349. #endif
  95350. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95351. #if JUCE_USE_OGGVORBIS
  95352. #include <stdlib.h>
  95353. #include <string.h>
  95354. int ogg_page_version(ogg_page *og){
  95355. return((int)(og->header[4]));
  95356. }
  95357. int ogg_page_continued(ogg_page *og){
  95358. return((int)(og->header[5]&0x01));
  95359. }
  95360. int ogg_page_bos(ogg_page *og){
  95361. return((int)(og->header[5]&0x02));
  95362. }
  95363. int ogg_page_eos(ogg_page *og){
  95364. return((int)(og->header[5]&0x04));
  95365. }
  95366. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95367. unsigned char *page=og->header;
  95368. ogg_int64_t granulepos=page[13]&(0xff);
  95369. granulepos= (granulepos<<8)|(page[12]&0xff);
  95370. granulepos= (granulepos<<8)|(page[11]&0xff);
  95371. granulepos= (granulepos<<8)|(page[10]&0xff);
  95372. granulepos= (granulepos<<8)|(page[9]&0xff);
  95373. granulepos= (granulepos<<8)|(page[8]&0xff);
  95374. granulepos= (granulepos<<8)|(page[7]&0xff);
  95375. granulepos= (granulepos<<8)|(page[6]&0xff);
  95376. return(granulepos);
  95377. }
  95378. int ogg_page_serialno(ogg_page *og){
  95379. return(og->header[14] |
  95380. (og->header[15]<<8) |
  95381. (og->header[16]<<16) |
  95382. (og->header[17]<<24));
  95383. }
  95384. long ogg_page_pageno(ogg_page *og){
  95385. return(og->header[18] |
  95386. (og->header[19]<<8) |
  95387. (og->header[20]<<16) |
  95388. (og->header[21]<<24));
  95389. }
  95390. int ogg_page_packets(ogg_page *og){
  95391. int i,n=og->header[26],count=0;
  95392. for(i=0;i<n;i++)
  95393. if(og->header[27+i]<255)count++;
  95394. return(count);
  95395. }
  95396. #if 0
  95397. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95398. int i;
  95399. unsigned long r;
  95400. r = index << 24;
  95401. for (i=0; i<8; i++)
  95402. if (r & 0x80000000UL)
  95403. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95404. polynomial, although we use an
  95405. unreflected alg and an init/final
  95406. of 0, not 0xffffffff */
  95407. else
  95408. r<<=1;
  95409. return (r & 0xffffffffUL);
  95410. }
  95411. #endif
  95412. static const ogg_uint32_t crc_lookup[256]={
  95413. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95414. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95415. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95416. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95417. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95418. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95419. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95420. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95421. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95422. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95423. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95424. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95425. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95426. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95427. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95428. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95429. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95430. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95431. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95432. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95433. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95434. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95435. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95436. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95437. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95438. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95439. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95440. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95441. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95442. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95443. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95444. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95445. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95446. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95447. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95448. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95449. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95450. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95451. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95452. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95453. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95454. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95455. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95456. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95457. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95458. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95459. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95460. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95461. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95462. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95463. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95464. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95465. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95466. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95467. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95468. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95469. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95470. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95471. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95472. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95473. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95474. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95475. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95476. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95477. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95478. if(os){
  95479. memset(os,0,sizeof(*os));
  95480. os->body_storage=16*1024;
  95481. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95482. os->lacing_storage=1024;
  95483. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95484. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95485. os->serialno=serialno;
  95486. return(0);
  95487. }
  95488. return(-1);
  95489. }
  95490. int ogg_stream_clear(ogg_stream_state *os){
  95491. if(os){
  95492. if(os->body_data)_ogg_free(os->body_data);
  95493. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95494. if(os->granule_vals)_ogg_free(os->granule_vals);
  95495. memset(os,0,sizeof(*os));
  95496. }
  95497. return(0);
  95498. }
  95499. int ogg_stream_destroy(ogg_stream_state *os){
  95500. if(os){
  95501. ogg_stream_clear(os);
  95502. _ogg_free(os);
  95503. }
  95504. return(0);
  95505. }
  95506. static void _os_body_expand(ogg_stream_state *os,int needed){
  95507. if(os->body_storage<=os->body_fill+needed){
  95508. os->body_storage+=(needed+1024);
  95509. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95510. }
  95511. }
  95512. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95513. if(os->lacing_storage<=os->lacing_fill+needed){
  95514. os->lacing_storage+=(needed+32);
  95515. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95516. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95517. }
  95518. }
  95519. void ogg_page_checksum_set(ogg_page *og){
  95520. if(og){
  95521. ogg_uint32_t crc_reg=0;
  95522. int i;
  95523. og->header[22]=0;
  95524. og->header[23]=0;
  95525. og->header[24]=0;
  95526. og->header[25]=0;
  95527. for(i=0;i<og->header_len;i++)
  95528. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95529. for(i=0;i<og->body_len;i++)
  95530. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95531. og->header[22]=(unsigned char)(crc_reg&0xff);
  95532. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95533. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95534. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  95535. }
  95536. }
  95537. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  95538. int lacing_vals=op->bytes/255+1,i;
  95539. if(os->body_returned){
  95540. os->body_fill-=os->body_returned;
  95541. if(os->body_fill)
  95542. memmove(os->body_data,os->body_data+os->body_returned,
  95543. os->body_fill);
  95544. os->body_returned=0;
  95545. }
  95546. _os_body_expand(os,op->bytes);
  95547. _os_lacing_expand(os,lacing_vals);
  95548. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  95549. os->body_fill+=op->bytes;
  95550. for(i=0;i<lacing_vals-1;i++){
  95551. os->lacing_vals[os->lacing_fill+i]=255;
  95552. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  95553. }
  95554. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  95555. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  95556. os->lacing_vals[os->lacing_fill]|= 0x100;
  95557. os->lacing_fill+=lacing_vals;
  95558. os->packetno++;
  95559. if(op->e_o_s)os->e_o_s=1;
  95560. return(0);
  95561. }
  95562. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  95563. int i;
  95564. int vals=0;
  95565. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  95566. int bytes=0;
  95567. long acc=0;
  95568. ogg_int64_t granule_pos=-1;
  95569. if(maxvals==0)return(0);
  95570. if(os->b_o_s==0){ /* 'initial header page' case */
  95571. granule_pos=0;
  95572. for(vals=0;vals<maxvals;vals++){
  95573. if((os->lacing_vals[vals]&0x0ff)<255){
  95574. vals++;
  95575. break;
  95576. }
  95577. }
  95578. }else{
  95579. for(vals=0;vals<maxvals;vals++){
  95580. if(acc>4096)break;
  95581. acc+=os->lacing_vals[vals]&0x0ff;
  95582. if((os->lacing_vals[vals]&0xff)<255)
  95583. granule_pos=os->granule_vals[vals];
  95584. }
  95585. }
  95586. memcpy(os->header,"OggS",4);
  95587. os->header[4]=0x00;
  95588. os->header[5]=0x00;
  95589. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  95590. if(os->b_o_s==0)os->header[5]|=0x02;
  95591. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  95592. os->b_o_s=1;
  95593. for(i=6;i<14;i++){
  95594. os->header[i]=(unsigned char)(granule_pos&0xff);
  95595. granule_pos>>=8;
  95596. }
  95597. {
  95598. long serialno=os->serialno;
  95599. for(i=14;i<18;i++){
  95600. os->header[i]=(unsigned char)(serialno&0xff);
  95601. serialno>>=8;
  95602. }
  95603. }
  95604. if(os->pageno==-1)os->pageno=0; /* because someone called
  95605. stream_reset; this would be a
  95606. strange thing to do in an
  95607. encode stream, but it has
  95608. plausible uses */
  95609. {
  95610. long pageno=os->pageno++;
  95611. for(i=18;i<22;i++){
  95612. os->header[i]=(unsigned char)(pageno&0xff);
  95613. pageno>>=8;
  95614. }
  95615. }
  95616. os->header[22]=0;
  95617. os->header[23]=0;
  95618. os->header[24]=0;
  95619. os->header[25]=0;
  95620. os->header[26]=(unsigned char)(vals&0xff);
  95621. for(i=0;i<vals;i++)
  95622. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  95623. og->header=os->header;
  95624. og->header_len=os->header_fill=vals+27;
  95625. og->body=os->body_data+os->body_returned;
  95626. og->body_len=bytes;
  95627. os->lacing_fill-=vals;
  95628. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  95629. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  95630. os->body_returned+=bytes;
  95631. ogg_page_checksum_set(og);
  95632. return(1);
  95633. }
  95634. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  95635. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  95636. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  95637. os->lacing_fill>=255 || /* 'segment table full' case */
  95638. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  95639. return(ogg_stream_flush(os,og));
  95640. }
  95641. return(0);
  95642. }
  95643. int ogg_stream_eos(ogg_stream_state *os){
  95644. return os->e_o_s;
  95645. }
  95646. int ogg_sync_init(ogg_sync_state *oy){
  95647. if(oy){
  95648. memset(oy,0,sizeof(*oy));
  95649. }
  95650. return(0);
  95651. }
  95652. int ogg_sync_clear(ogg_sync_state *oy){
  95653. if(oy){
  95654. if(oy->data)_ogg_free(oy->data);
  95655. ogg_sync_init(oy);
  95656. }
  95657. return(0);
  95658. }
  95659. int ogg_sync_destroy(ogg_sync_state *oy){
  95660. if(oy){
  95661. ogg_sync_clear(oy);
  95662. _ogg_free(oy);
  95663. }
  95664. return(0);
  95665. }
  95666. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  95667. if(oy->returned){
  95668. oy->fill-=oy->returned;
  95669. if(oy->fill>0)
  95670. memmove(oy->data,oy->data+oy->returned,oy->fill);
  95671. oy->returned=0;
  95672. }
  95673. if(size>oy->storage-oy->fill){
  95674. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  95675. if(oy->data)
  95676. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  95677. else
  95678. oy->data=(unsigned char*) _ogg_malloc(newsize);
  95679. oy->storage=newsize;
  95680. }
  95681. return((char *)oy->data+oy->fill);
  95682. }
  95683. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  95684. if(oy->fill+bytes>oy->storage)return(-1);
  95685. oy->fill+=bytes;
  95686. return(0);
  95687. }
  95688. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  95689. unsigned char *page=oy->data+oy->returned;
  95690. unsigned char *next;
  95691. long bytes=oy->fill-oy->returned;
  95692. if(oy->headerbytes==0){
  95693. int headerbytes,i;
  95694. if(bytes<27)return(0); /* not enough for a header */
  95695. if(memcmp(page,"OggS",4))goto sync_fail;
  95696. headerbytes=page[26]+27;
  95697. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  95698. for(i=0;i<page[26];i++)
  95699. oy->bodybytes+=page[27+i];
  95700. oy->headerbytes=headerbytes;
  95701. }
  95702. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  95703. {
  95704. char chksum[4];
  95705. ogg_page log;
  95706. memcpy(chksum,page+22,4);
  95707. memset(page+22,0,4);
  95708. log.header=page;
  95709. log.header_len=oy->headerbytes;
  95710. log.body=page+oy->headerbytes;
  95711. log.body_len=oy->bodybytes;
  95712. ogg_page_checksum_set(&log);
  95713. if(memcmp(chksum,page+22,4)){
  95714. memcpy(page+22,chksum,4);
  95715. goto sync_fail;
  95716. }
  95717. }
  95718. {
  95719. unsigned char *page=oy->data+oy->returned;
  95720. long bytes;
  95721. if(og){
  95722. og->header=page;
  95723. og->header_len=oy->headerbytes;
  95724. og->body=page+oy->headerbytes;
  95725. og->body_len=oy->bodybytes;
  95726. }
  95727. oy->unsynced=0;
  95728. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  95729. oy->headerbytes=0;
  95730. oy->bodybytes=0;
  95731. return(bytes);
  95732. }
  95733. sync_fail:
  95734. oy->headerbytes=0;
  95735. oy->bodybytes=0;
  95736. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  95737. if(!next)
  95738. next=oy->data+oy->fill;
  95739. oy->returned=next-oy->data;
  95740. return(-(next-page));
  95741. }
  95742. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  95743. for(;;){
  95744. long ret=ogg_sync_pageseek(oy,og);
  95745. if(ret>0){
  95746. return(1);
  95747. }
  95748. if(ret==0){
  95749. return(0);
  95750. }
  95751. if(!oy->unsynced){
  95752. oy->unsynced=1;
  95753. return(-1);
  95754. }
  95755. }
  95756. }
  95757. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  95758. unsigned char *header=og->header;
  95759. unsigned char *body=og->body;
  95760. long bodysize=og->body_len;
  95761. int segptr=0;
  95762. int version=ogg_page_version(og);
  95763. int continued=ogg_page_continued(og);
  95764. int bos=ogg_page_bos(og);
  95765. int eos=ogg_page_eos(og);
  95766. ogg_int64_t granulepos=ogg_page_granulepos(og);
  95767. int serialno=ogg_page_serialno(og);
  95768. long pageno=ogg_page_pageno(og);
  95769. int segments=header[26];
  95770. {
  95771. long lr=os->lacing_returned;
  95772. long br=os->body_returned;
  95773. if(br){
  95774. os->body_fill-=br;
  95775. if(os->body_fill)
  95776. memmove(os->body_data,os->body_data+br,os->body_fill);
  95777. os->body_returned=0;
  95778. }
  95779. if(lr){
  95780. if(os->lacing_fill-lr){
  95781. memmove(os->lacing_vals,os->lacing_vals+lr,
  95782. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  95783. memmove(os->granule_vals,os->granule_vals+lr,
  95784. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  95785. }
  95786. os->lacing_fill-=lr;
  95787. os->lacing_packet-=lr;
  95788. os->lacing_returned=0;
  95789. }
  95790. }
  95791. if(serialno!=os->serialno)return(-1);
  95792. if(version>0)return(-1);
  95793. _os_lacing_expand(os,segments+1);
  95794. if(pageno!=os->pageno){
  95795. int i;
  95796. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  95797. os->body_fill-=os->lacing_vals[i]&0xff;
  95798. os->lacing_fill=os->lacing_packet;
  95799. if(os->pageno!=-1){
  95800. os->lacing_vals[os->lacing_fill++]=0x400;
  95801. os->lacing_packet++;
  95802. }
  95803. }
  95804. if(continued){
  95805. if(os->lacing_fill<1 ||
  95806. os->lacing_vals[os->lacing_fill-1]==0x400){
  95807. bos=0;
  95808. for(;segptr<segments;segptr++){
  95809. int val=header[27+segptr];
  95810. body+=val;
  95811. bodysize-=val;
  95812. if(val<255){
  95813. segptr++;
  95814. break;
  95815. }
  95816. }
  95817. }
  95818. }
  95819. if(bodysize){
  95820. _os_body_expand(os,bodysize);
  95821. memcpy(os->body_data+os->body_fill,body,bodysize);
  95822. os->body_fill+=bodysize;
  95823. }
  95824. {
  95825. int saved=-1;
  95826. while(segptr<segments){
  95827. int val=header[27+segptr];
  95828. os->lacing_vals[os->lacing_fill]=val;
  95829. os->granule_vals[os->lacing_fill]=-1;
  95830. if(bos){
  95831. os->lacing_vals[os->lacing_fill]|=0x100;
  95832. bos=0;
  95833. }
  95834. if(val<255)saved=os->lacing_fill;
  95835. os->lacing_fill++;
  95836. segptr++;
  95837. if(val<255)os->lacing_packet=os->lacing_fill;
  95838. }
  95839. if(saved!=-1){
  95840. os->granule_vals[saved]=granulepos;
  95841. }
  95842. }
  95843. if(eos){
  95844. os->e_o_s=1;
  95845. if(os->lacing_fill>0)
  95846. os->lacing_vals[os->lacing_fill-1]|=0x200;
  95847. }
  95848. os->pageno=pageno+1;
  95849. return(0);
  95850. }
  95851. int ogg_sync_reset(ogg_sync_state *oy){
  95852. oy->fill=0;
  95853. oy->returned=0;
  95854. oy->unsynced=0;
  95855. oy->headerbytes=0;
  95856. oy->bodybytes=0;
  95857. return(0);
  95858. }
  95859. int ogg_stream_reset(ogg_stream_state *os){
  95860. os->body_fill=0;
  95861. os->body_returned=0;
  95862. os->lacing_fill=0;
  95863. os->lacing_packet=0;
  95864. os->lacing_returned=0;
  95865. os->header_fill=0;
  95866. os->e_o_s=0;
  95867. os->b_o_s=0;
  95868. os->pageno=-1;
  95869. os->packetno=0;
  95870. os->granulepos=0;
  95871. return(0);
  95872. }
  95873. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  95874. ogg_stream_reset(os);
  95875. os->serialno=serialno;
  95876. return(0);
  95877. }
  95878. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  95879. int ptr=os->lacing_returned;
  95880. if(os->lacing_packet<=ptr)return(0);
  95881. if(os->lacing_vals[ptr]&0x400){
  95882. os->lacing_returned++;
  95883. os->packetno++;
  95884. return(-1);
  95885. }
  95886. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  95887. to ask if there's a whole packet
  95888. waiting */
  95889. {
  95890. int size=os->lacing_vals[ptr]&0xff;
  95891. int bytes=size;
  95892. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  95893. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  95894. while(size==255){
  95895. int val=os->lacing_vals[++ptr];
  95896. size=val&0xff;
  95897. if(val&0x200)eos=0x200;
  95898. bytes+=size;
  95899. }
  95900. if(op){
  95901. op->e_o_s=eos;
  95902. op->b_o_s=bos;
  95903. op->packet=os->body_data+os->body_returned;
  95904. op->packetno=os->packetno;
  95905. op->granulepos=os->granule_vals[ptr];
  95906. op->bytes=bytes;
  95907. }
  95908. if(adv){
  95909. os->body_returned+=bytes;
  95910. os->lacing_returned=ptr+1;
  95911. os->packetno++;
  95912. }
  95913. }
  95914. return(1);
  95915. }
  95916. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  95917. return _packetout(os,op,1);
  95918. }
  95919. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  95920. return _packetout(os,op,0);
  95921. }
  95922. void ogg_packet_clear(ogg_packet *op) {
  95923. _ogg_free(op->packet);
  95924. memset(op, 0, sizeof(*op));
  95925. }
  95926. #ifdef _V_SELFTEST
  95927. #include <stdio.h>
  95928. ogg_stream_state os_en, os_de;
  95929. ogg_sync_state oy;
  95930. void checkpacket(ogg_packet *op,int len, int no, int pos){
  95931. long j;
  95932. static int sequence=0;
  95933. static int lastno=0;
  95934. if(op->bytes!=len){
  95935. fprintf(stderr,"incorrect packet length!\n");
  95936. exit(1);
  95937. }
  95938. if(op->granulepos!=pos){
  95939. fprintf(stderr,"incorrect packet position!\n");
  95940. exit(1);
  95941. }
  95942. if(no==0){
  95943. sequence=0;
  95944. }else{
  95945. sequence++;
  95946. if(no>lastno+1)
  95947. sequence++;
  95948. }
  95949. lastno=no;
  95950. if(op->packetno!=sequence){
  95951. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  95952. (long)(op->packetno),sequence);
  95953. exit(1);
  95954. }
  95955. for(j=0;j<op->bytes;j++)
  95956. if(op->packet[j]!=((j+no)&0xff)){
  95957. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  95958. j,op->packet[j],(j+no)&0xff);
  95959. exit(1);
  95960. }
  95961. }
  95962. void check_page(unsigned char *data,const int *header,ogg_page *og){
  95963. long j;
  95964. for(j=0;j<og->body_len;j++)
  95965. if(og->body[j]!=data[j]){
  95966. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  95967. j,data[j],og->body[j]);
  95968. exit(1);
  95969. }
  95970. for(j=0;j<og->header_len;j++){
  95971. if(og->header[j]!=header[j]){
  95972. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  95973. for(j=0;j<header[26]+27;j++)
  95974. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  95975. fprintf(stderr,"\n");
  95976. exit(1);
  95977. }
  95978. }
  95979. if(og->header_len!=header[26]+27){
  95980. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  95981. og->header_len,header[26]+27);
  95982. exit(1);
  95983. }
  95984. }
  95985. void print_header(ogg_page *og){
  95986. int j;
  95987. fprintf(stderr,"\nHEADER:\n");
  95988. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  95989. og->header[0],og->header[1],og->header[2],og->header[3],
  95990. (int)og->header[4],(int)og->header[5]);
  95991. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  95992. (og->header[9]<<24)|(og->header[8]<<16)|
  95993. (og->header[7]<<8)|og->header[6],
  95994. (og->header[17]<<24)|(og->header[16]<<16)|
  95995. (og->header[15]<<8)|og->header[14],
  95996. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  95997. (og->header[19]<<8)|og->header[18]);
  95998. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  95999. (int)og->header[22],(int)og->header[23],
  96000. (int)og->header[24],(int)og->header[25],
  96001. (int)og->header[26]);
  96002. for(j=27;j<og->header_len;j++)
  96003. fprintf(stderr,"%d ",(int)og->header[j]);
  96004. fprintf(stderr,")\n\n");
  96005. }
  96006. void copy_page(ogg_page *og){
  96007. unsigned char *temp=_ogg_malloc(og->header_len);
  96008. memcpy(temp,og->header,og->header_len);
  96009. og->header=temp;
  96010. temp=_ogg_malloc(og->body_len);
  96011. memcpy(temp,og->body,og->body_len);
  96012. og->body=temp;
  96013. }
  96014. void free_page(ogg_page *og){
  96015. _ogg_free (og->header);
  96016. _ogg_free (og->body);
  96017. }
  96018. void error(void){
  96019. fprintf(stderr,"error!\n");
  96020. exit(1);
  96021. }
  96022. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96023. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96024. 0x01,0x02,0x03,0x04,0,0,0,0,
  96025. 0x15,0xed,0xec,0x91,
  96026. 1,
  96027. 17};
  96028. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96029. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96030. 0x01,0x02,0x03,0x04,0,0,0,0,
  96031. 0x59,0x10,0x6c,0x2c,
  96032. 1,
  96033. 17};
  96034. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96035. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96036. 0x01,0x02,0x03,0x04,1,0,0,0,
  96037. 0x89,0x33,0x85,0xce,
  96038. 13,
  96039. 254,255,0,255,1,255,245,255,255,0,
  96040. 255,255,90};
  96041. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96042. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96043. 0x01,0x02,0x03,0x04,0,0,0,0,
  96044. 0xff,0x7b,0x23,0x17,
  96045. 1,
  96046. 0};
  96047. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96048. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96049. 0x01,0x02,0x03,0x04,1,0,0,0,
  96050. 0x5c,0x3f,0x66,0xcb,
  96051. 17,
  96052. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96053. 255,255,90,0};
  96054. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96055. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96056. 0x01,0x02,0x03,0x04,0,0,0,0,
  96057. 0x01,0x27,0x31,0xaa,
  96058. 18,
  96059. 255,255,255,255,255,255,255,255,
  96060. 255,255,255,255,255,255,255,255,255,10};
  96061. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96062. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96063. 0x01,0x02,0x03,0x04,1,0,0,0,
  96064. 0x7f,0x4e,0x8a,0xd2,
  96065. 4,
  96066. 255,4,255,0};
  96067. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96068. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96069. 0x01,0x02,0x03,0x04,0,0,0,0,
  96070. 0xff,0x7b,0x23,0x17,
  96071. 1,
  96072. 0};
  96073. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96074. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96075. 0x01,0x02,0x03,0x04,1,0,0,0,
  96076. 0x54,0x05,0x51,0xc8,
  96077. 17,
  96078. 255,255,255,255,255,255,255,255,
  96079. 255,255,255,255,255,255,255,255,255};
  96080. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96081. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96082. 0x01,0x02,0x03,0x04,2,0,0,0,
  96083. 0xc8,0xc3,0xcb,0xed,
  96084. 5,
  96085. 10,255,4,255,0};
  96086. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96087. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96088. 0x01,0x02,0x03,0x04,0,0,0,0,
  96089. 0xff,0x7b,0x23,0x17,
  96090. 1,
  96091. 0};
  96092. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96093. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96094. 0x01,0x02,0x03,0x04,1,0,0,0,
  96095. 0xed,0x2a,0x2e,0xa7,
  96096. 255,
  96097. 10,10,10,10,10,10,10,10,
  96098. 10,10,10,10,10,10,10,10,
  96099. 10,10,10,10,10,10,10,10,
  96100. 10,10,10,10,10,10,10,10,
  96101. 10,10,10,10,10,10,10,10,
  96102. 10,10,10,10,10,10,10,10,
  96103. 10,10,10,10,10,10,10,10,
  96104. 10,10,10,10,10,10,10,10,
  96105. 10,10,10,10,10,10,10,10,
  96106. 10,10,10,10,10,10,10,10,
  96107. 10,10,10,10,10,10,10,10,
  96108. 10,10,10,10,10,10,10,10,
  96109. 10,10,10,10,10,10,10,10,
  96110. 10,10,10,10,10,10,10,10,
  96111. 10,10,10,10,10,10,10,10,
  96112. 10,10,10,10,10,10,10,10,
  96113. 10,10,10,10,10,10,10,10,
  96114. 10,10,10,10,10,10,10,10,
  96115. 10,10,10,10,10,10,10,10,
  96116. 10,10,10,10,10,10,10,10,
  96117. 10,10,10,10,10,10,10,10,
  96118. 10,10,10,10,10,10,10,10,
  96119. 10,10,10,10,10,10,10,10,
  96120. 10,10,10,10,10,10,10,10,
  96121. 10,10,10,10,10,10,10,10,
  96122. 10,10,10,10,10,10,10,10,
  96123. 10,10,10,10,10,10,10,10,
  96124. 10,10,10,10,10,10,10,10,
  96125. 10,10,10,10,10,10,10,10,
  96126. 10,10,10,10,10,10,10,10,
  96127. 10,10,10,10,10,10,10,10,
  96128. 10,10,10,10,10,10,10};
  96129. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96130. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96131. 0x01,0x02,0x03,0x04,2,0,0,0,
  96132. 0x6c,0x3b,0x82,0x3d,
  96133. 1,
  96134. 50};
  96135. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96136. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96137. 0x01,0x02,0x03,0x04,0,0,0,0,
  96138. 0xff,0x7b,0x23,0x17,
  96139. 1,
  96140. 0};
  96141. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96142. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96143. 0x01,0x02,0x03,0x04,1,0,0,0,
  96144. 0x3c,0xd9,0x4d,0x3f,
  96145. 17,
  96146. 100,255,255,255,255,255,255,255,255,
  96147. 255,255,255,255,255,255,255,255};
  96148. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96149. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96150. 0x01,0x02,0x03,0x04,2,0,0,0,
  96151. 0x01,0xd2,0xe5,0xe5,
  96152. 17,
  96153. 255,255,255,255,255,255,255,255,
  96154. 255,255,255,255,255,255,255,255,255};
  96155. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96156. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96157. 0x01,0x02,0x03,0x04,3,0,0,0,
  96158. 0xef,0xdd,0x88,0xde,
  96159. 7,
  96160. 255,255,75,255,4,255,0};
  96161. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96162. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96163. 0x01,0x02,0x03,0x04,0,0,0,0,
  96164. 0xff,0x7b,0x23,0x17,
  96165. 1,
  96166. 0};
  96167. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96168. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96169. 0x01,0x02,0x03,0x04,1,0,0,0,
  96170. 0x3c,0xd9,0x4d,0x3f,
  96171. 17,
  96172. 100,255,255,255,255,255,255,255,255,
  96173. 255,255,255,255,255,255,255,255};
  96174. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96175. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96176. 0x01,0x02,0x03,0x04,2,0,0,0,
  96177. 0xd4,0xe0,0x60,0xe5,
  96178. 1,0};
  96179. void test_pack(const int *pl, const int **headers, int byteskip,
  96180. int pageskip, int packetskip){
  96181. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96182. long inptr=0;
  96183. long outptr=0;
  96184. long deptr=0;
  96185. long depacket=0;
  96186. long granule_pos=7,pageno=0;
  96187. int i,j,packets,pageout=pageskip;
  96188. int eosflag=0;
  96189. int bosflag=0;
  96190. int byteskipcount=0;
  96191. ogg_stream_reset(&os_en);
  96192. ogg_stream_reset(&os_de);
  96193. ogg_sync_reset(&oy);
  96194. for(packets=0;packets<packetskip;packets++)
  96195. depacket+=pl[packets];
  96196. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96197. for(i=0;i<packets;i++){
  96198. ogg_packet op;
  96199. int len=pl[i];
  96200. op.packet=data+inptr;
  96201. op.bytes=len;
  96202. op.e_o_s=(pl[i+1]<0?1:0);
  96203. op.granulepos=granule_pos;
  96204. granule_pos+=1024;
  96205. for(j=0;j<len;j++)data[inptr++]=i+j;
  96206. ogg_stream_packetin(&os_en,&op);
  96207. {
  96208. ogg_page og;
  96209. while(ogg_stream_pageout(&os_en,&og)){
  96210. fprintf(stderr,"%ld, ",pageno);
  96211. if(headers[pageno]==NULL){
  96212. fprintf(stderr,"coded too many pages!\n");
  96213. exit(1);
  96214. }
  96215. check_page(data+outptr,headers[pageno],&og);
  96216. outptr+=og.body_len;
  96217. pageno++;
  96218. if(pageskip){
  96219. bosflag=1;
  96220. pageskip--;
  96221. deptr+=og.body_len;
  96222. }
  96223. {
  96224. ogg_page og_de;
  96225. ogg_packet op_de,op_de2;
  96226. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96227. char *next=buf;
  96228. byteskipcount+=og.header_len;
  96229. if(byteskipcount>byteskip){
  96230. memcpy(next,og.header,byteskipcount-byteskip);
  96231. next+=byteskipcount-byteskip;
  96232. byteskipcount=byteskip;
  96233. }
  96234. byteskipcount+=og.body_len;
  96235. if(byteskipcount>byteskip){
  96236. memcpy(next,og.body,byteskipcount-byteskip);
  96237. next+=byteskipcount-byteskip;
  96238. byteskipcount=byteskip;
  96239. }
  96240. ogg_sync_wrote(&oy,next-buf);
  96241. while(1){
  96242. int ret=ogg_sync_pageout(&oy,&og_de);
  96243. if(ret==0)break;
  96244. if(ret<0)continue;
  96245. fprintf(stderr,"(%ld), ",pageout);
  96246. check_page(data+deptr,headers[pageout],&og_de);
  96247. deptr+=og_de.body_len;
  96248. pageout++;
  96249. ogg_stream_pagein(&os_de,&og_de);
  96250. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96251. ogg_stream_packetpeek(&os_de,NULL);
  96252. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96253. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96254. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96255. depacket);
  96256. exit(1);
  96257. }
  96258. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96259. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96260. depacket);
  96261. exit(1);
  96262. }
  96263. if(bosflag==0 && op_de.b_o_s==0){
  96264. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96265. exit(1);
  96266. }
  96267. if(bosflag && op_de.b_o_s){
  96268. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96269. exit(1);
  96270. }
  96271. bosflag=1;
  96272. depacket+=op_de.bytes;
  96273. if(eosflag){
  96274. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96275. exit(1);
  96276. }
  96277. if(op_de.e_o_s)eosflag=1;
  96278. if(op_de.granulepos!=-1){
  96279. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96280. }
  96281. }
  96282. }
  96283. }
  96284. }
  96285. }
  96286. }
  96287. _ogg_free(data);
  96288. if(headers[pageno]!=NULL){
  96289. fprintf(stderr,"did not write last page!\n");
  96290. exit(1);
  96291. }
  96292. if(headers[pageout]!=NULL){
  96293. fprintf(stderr,"did not decode last page!\n");
  96294. exit(1);
  96295. }
  96296. if(inptr!=outptr){
  96297. fprintf(stderr,"encoded page data incomplete!\n");
  96298. exit(1);
  96299. }
  96300. if(inptr!=deptr){
  96301. fprintf(stderr,"decoded page data incomplete!\n");
  96302. exit(1);
  96303. }
  96304. if(inptr!=depacket){
  96305. fprintf(stderr,"decoded packet data incomplete!\n");
  96306. exit(1);
  96307. }
  96308. if(!eosflag){
  96309. fprintf(stderr,"Never got a packet with EOS set!\n");
  96310. exit(1);
  96311. }
  96312. fprintf(stderr,"ok.\n");
  96313. }
  96314. int main(void){
  96315. ogg_stream_init(&os_en,0x04030201);
  96316. ogg_stream_init(&os_de,0x04030201);
  96317. ogg_sync_init(&oy);
  96318. {
  96319. const int packets[]={17, -1};
  96320. const int *headret[]={head1_0,NULL};
  96321. fprintf(stderr,"testing single page encoding... ");
  96322. test_pack(packets,headret,0,0,0);
  96323. }
  96324. {
  96325. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96326. const int *headret[]={head1_1,head2_1,NULL};
  96327. fprintf(stderr,"testing basic page encoding... ");
  96328. test_pack(packets,headret,0,0,0);
  96329. }
  96330. {
  96331. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96332. const int *headret[]={head1_2,head2_2,NULL};
  96333. fprintf(stderr,"testing basic nil packets... ");
  96334. test_pack(packets,headret,0,0,0);
  96335. }
  96336. {
  96337. const int packets[]={4345,259,255,-1};
  96338. const int *headret[]={head1_3,head2_3,NULL};
  96339. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96340. test_pack(packets,headret,0,0,0);
  96341. }
  96342. {
  96343. const int packets[]={0,4345,259,255,-1};
  96344. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96345. fprintf(stderr,"testing single packet page span... ");
  96346. test_pack(packets,headret,0,0,0);
  96347. }
  96348. {
  96349. const int packets[]={0,10,10,10,10,10,10,10,10,
  96350. 10,10,10,10,10,10,10,10,
  96351. 10,10,10,10,10,10,10,10,
  96352. 10,10,10,10,10,10,10,10,
  96353. 10,10,10,10,10,10,10,10,
  96354. 10,10,10,10,10,10,10,10,
  96355. 10,10,10,10,10,10,10,10,
  96356. 10,10,10,10,10,10,10,10,
  96357. 10,10,10,10,10,10,10,10,
  96358. 10,10,10,10,10,10,10,10,
  96359. 10,10,10,10,10,10,10,10,
  96360. 10,10,10,10,10,10,10,10,
  96361. 10,10,10,10,10,10,10,10,
  96362. 10,10,10,10,10,10,10,10,
  96363. 10,10,10,10,10,10,10,10,
  96364. 10,10,10,10,10,10,10,10,
  96365. 10,10,10,10,10,10,10,10,
  96366. 10,10,10,10,10,10,10,10,
  96367. 10,10,10,10,10,10,10,10,
  96368. 10,10,10,10,10,10,10,10,
  96369. 10,10,10,10,10,10,10,10,
  96370. 10,10,10,10,10,10,10,10,
  96371. 10,10,10,10,10,10,10,10,
  96372. 10,10,10,10,10,10,10,10,
  96373. 10,10,10,10,10,10,10,10,
  96374. 10,10,10,10,10,10,10,10,
  96375. 10,10,10,10,10,10,10,10,
  96376. 10,10,10,10,10,10,10,10,
  96377. 10,10,10,10,10,10,10,10,
  96378. 10,10,10,10,10,10,10,10,
  96379. 10,10,10,10,10,10,10,10,
  96380. 10,10,10,10,10,10,10,50,-1};
  96381. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96382. fprintf(stderr,"testing max packet segments... ");
  96383. test_pack(packets,headret,0,0,0);
  96384. }
  96385. {
  96386. const int packets[]={0,100,9000,259,255,-1};
  96387. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96388. fprintf(stderr,"testing very large packets... ");
  96389. test_pack(packets,headret,0,0,0);
  96390. }
  96391. {
  96392. const int packets[]={0,100,9000,259,255,-1};
  96393. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96394. fprintf(stderr,"testing continuation resync in very large packets... ");
  96395. test_pack(packets,headret,100,2,3);
  96396. }
  96397. {
  96398. const int packets[]={0,100,4080,-1};
  96399. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96400. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96401. test_pack(packets,headret,0,0,0);
  96402. }
  96403. {
  96404. unsigned char *data=_ogg_malloc(1024*1024);
  96405. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96406. int inptr=0,i,j;
  96407. ogg_page og[5];
  96408. ogg_stream_reset(&os_en);
  96409. for(i=0;pl[i]!=-1;i++){
  96410. ogg_packet op;
  96411. int len=pl[i];
  96412. op.packet=data+inptr;
  96413. op.bytes=len;
  96414. op.e_o_s=(pl[i+1]<0?1:0);
  96415. op.granulepos=(i+1)*1000;
  96416. for(j=0;j<len;j++)data[inptr++]=i+j;
  96417. ogg_stream_packetin(&os_en,&op);
  96418. }
  96419. _ogg_free(data);
  96420. for(i=0;i<5;i++){
  96421. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96422. fprintf(stderr,"Too few pages output building sync tests!\n");
  96423. exit(1);
  96424. }
  96425. copy_page(&og[i]);
  96426. }
  96427. {
  96428. ogg_page temp;
  96429. ogg_packet test;
  96430. fprintf(stderr,"Testing loss of pages... ");
  96431. ogg_sync_reset(&oy);
  96432. ogg_stream_reset(&os_de);
  96433. for(i=0;i<5;i++){
  96434. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96435. og[i].header_len);
  96436. ogg_sync_wrote(&oy,og[i].header_len);
  96437. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96438. ogg_sync_wrote(&oy,og[i].body_len);
  96439. }
  96440. ogg_sync_pageout(&oy,&temp);
  96441. ogg_stream_pagein(&os_de,&temp);
  96442. ogg_sync_pageout(&oy,&temp);
  96443. ogg_stream_pagein(&os_de,&temp);
  96444. ogg_sync_pageout(&oy,&temp);
  96445. ogg_sync_pageout(&oy,&temp);
  96446. ogg_stream_pagein(&os_de,&temp);
  96447. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96448. checkpacket(&test,0,0,0);
  96449. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96450. checkpacket(&test,100,1,-1);
  96451. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96452. checkpacket(&test,4079,2,3000);
  96453. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96454. fprintf(stderr,"Error: loss of page did not return error\n");
  96455. exit(1);
  96456. }
  96457. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96458. checkpacket(&test,76,5,-1);
  96459. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96460. checkpacket(&test,34,6,-1);
  96461. fprintf(stderr,"ok.\n");
  96462. }
  96463. {
  96464. ogg_page temp;
  96465. ogg_packet test;
  96466. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96467. ogg_sync_reset(&oy);
  96468. ogg_stream_reset(&os_de);
  96469. for(i=0;i<5;i++){
  96470. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96471. og[i].header_len);
  96472. ogg_sync_wrote(&oy,og[i].header_len);
  96473. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96474. ogg_sync_wrote(&oy,og[i].body_len);
  96475. }
  96476. ogg_sync_pageout(&oy,&temp);
  96477. ogg_stream_pagein(&os_de,&temp);
  96478. ogg_sync_pageout(&oy,&temp);
  96479. ogg_stream_pagein(&os_de,&temp);
  96480. ogg_sync_pageout(&oy,&temp);
  96481. ogg_stream_pagein(&os_de,&temp);
  96482. ogg_sync_pageout(&oy,&temp);
  96483. ogg_sync_pageout(&oy,&temp);
  96484. ogg_stream_pagein(&os_de,&temp);
  96485. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96486. checkpacket(&test,0,0,0);
  96487. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96488. checkpacket(&test,100,1,-1);
  96489. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96490. checkpacket(&test,4079,2,3000);
  96491. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96492. checkpacket(&test,2956,3,4000);
  96493. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96494. fprintf(stderr,"Error: loss of page did not return error\n");
  96495. exit(1);
  96496. }
  96497. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96498. checkpacket(&test,300,13,14000);
  96499. fprintf(stderr,"ok.\n");
  96500. }
  96501. {
  96502. ogg_page og_de;
  96503. fprintf(stderr,"Testing sync on partial inputs... ");
  96504. ogg_sync_reset(&oy);
  96505. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96506. 3);
  96507. ogg_sync_wrote(&oy,3);
  96508. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96509. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96510. 20);
  96511. ogg_sync_wrote(&oy,20);
  96512. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96513. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96514. 5);
  96515. ogg_sync_wrote(&oy,5);
  96516. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96517. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96518. og[1].header_len-28);
  96519. ogg_sync_wrote(&oy,og[1].header_len-28);
  96520. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96521. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96522. ogg_sync_wrote(&oy,1000);
  96523. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96524. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96525. og[1].body_len-1000);
  96526. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96527. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96528. fprintf(stderr,"ok.\n");
  96529. }
  96530. {
  96531. ogg_page og_de;
  96532. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96533. ogg_sync_reset(&oy);
  96534. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96535. og[1].header_len);
  96536. ogg_sync_wrote(&oy,og[1].header_len);
  96537. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96538. og[1].body_len);
  96539. ogg_sync_wrote(&oy,og[1].body_len);
  96540. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96541. 20);
  96542. ogg_sync_wrote(&oy,20);
  96543. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96544. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96545. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  96546. og[1].header_len-20);
  96547. ogg_sync_wrote(&oy,og[1].header_len-20);
  96548. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96549. og[1].body_len);
  96550. ogg_sync_wrote(&oy,og[1].body_len);
  96551. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96552. fprintf(stderr,"ok.\n");
  96553. }
  96554. {
  96555. ogg_page og_de;
  96556. fprintf(stderr,"Testing search for capture... ");
  96557. ogg_sync_reset(&oy);
  96558. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96559. og[1].body_len);
  96560. ogg_sync_wrote(&oy,og[1].body_len);
  96561. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96562. og[1].header_len);
  96563. ogg_sync_wrote(&oy,og[1].header_len);
  96564. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96565. og[1].body_len);
  96566. ogg_sync_wrote(&oy,og[1].body_len);
  96567. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96568. 20);
  96569. ogg_sync_wrote(&oy,20);
  96570. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96571. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96572. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96573. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  96574. og[2].header_len-20);
  96575. ogg_sync_wrote(&oy,og[2].header_len-20);
  96576. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96577. og[2].body_len);
  96578. ogg_sync_wrote(&oy,og[2].body_len);
  96579. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96580. fprintf(stderr,"ok.\n");
  96581. }
  96582. {
  96583. ogg_page og_de;
  96584. fprintf(stderr,"Testing recapture... ");
  96585. ogg_sync_reset(&oy);
  96586. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96587. og[1].header_len);
  96588. ogg_sync_wrote(&oy,og[1].header_len);
  96589. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96590. og[1].body_len);
  96591. ogg_sync_wrote(&oy,og[1].body_len);
  96592. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96593. og[2].header_len);
  96594. ogg_sync_wrote(&oy,og[2].header_len);
  96595. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96596. og[2].header_len);
  96597. ogg_sync_wrote(&oy,og[2].header_len);
  96598. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96599. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96600. og[2].body_len-5);
  96601. ogg_sync_wrote(&oy,og[2].body_len-5);
  96602. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  96603. og[3].header_len);
  96604. ogg_sync_wrote(&oy,og[3].header_len);
  96605. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  96606. og[3].body_len);
  96607. ogg_sync_wrote(&oy,og[3].body_len);
  96608. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96609. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96610. fprintf(stderr,"ok.\n");
  96611. }
  96612. {
  96613. for(i=0;i<5;i++){
  96614. free_page(&og[i]);
  96615. }
  96616. }
  96617. }
  96618. return(0);
  96619. }
  96620. #endif
  96621. #endif
  96622. /*** End of inlined file: framing.c ***/
  96623. /*** Start of inlined file: analysis.c ***/
  96624. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  96625. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  96626. // tasks..
  96627. #if JUCE_MSVC
  96628. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  96629. #endif
  96630. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  96631. #if JUCE_USE_OGGVORBIS
  96632. #include <stdio.h>
  96633. #include <string.h>
  96634. #include <math.h>
  96635. /*** Start of inlined file: codec_internal.h ***/
  96636. #ifndef _V_CODECI_H_
  96637. #define _V_CODECI_H_
  96638. /*** Start of inlined file: envelope.h ***/
  96639. #ifndef _V_ENVELOPE_
  96640. #define _V_ENVELOPE_
  96641. /*** Start of inlined file: mdct.h ***/
  96642. #ifndef _OGG_mdct_H_
  96643. #define _OGG_mdct_H_
  96644. #ifdef MDCT_INTEGERIZED
  96645. #define DATA_TYPE int
  96646. #define REG_TYPE register int
  96647. #define TRIGBITS 14
  96648. #define cPI3_8 6270
  96649. #define cPI2_8 11585
  96650. #define cPI1_8 15137
  96651. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  96652. #define MULT_NORM(x) ((x)>>TRIGBITS)
  96653. #define HALVE(x) ((x)>>1)
  96654. #else
  96655. #define DATA_TYPE float
  96656. #define REG_TYPE float
  96657. #define cPI3_8 .38268343236508977175F
  96658. #define cPI2_8 .70710678118654752441F
  96659. #define cPI1_8 .92387953251128675613F
  96660. #define FLOAT_CONV(x) (x)
  96661. #define MULT_NORM(x) (x)
  96662. #define HALVE(x) ((x)*.5f)
  96663. #endif
  96664. typedef struct {
  96665. int n;
  96666. int log2n;
  96667. DATA_TYPE *trig;
  96668. int *bitrev;
  96669. DATA_TYPE scale;
  96670. } mdct_lookup;
  96671. extern void mdct_init(mdct_lookup *lookup,int n);
  96672. extern void mdct_clear(mdct_lookup *l);
  96673. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96674. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96675. #endif
  96676. /*** End of inlined file: mdct.h ***/
  96677. #define VE_PRE 16
  96678. #define VE_WIN 4
  96679. #define VE_POST 2
  96680. #define VE_AMP (VE_PRE+VE_POST-1)
  96681. #define VE_BANDS 7
  96682. #define VE_NEARDC 15
  96683. #define VE_MINSTRETCH 2 /* a bit less than short block */
  96684. #define VE_MAXSTRETCH 12 /* one-third full block */
  96685. typedef struct {
  96686. float ampbuf[VE_AMP];
  96687. int ampptr;
  96688. float nearDC[VE_NEARDC];
  96689. float nearDC_acc;
  96690. float nearDC_partialacc;
  96691. int nearptr;
  96692. } envelope_filter_state;
  96693. typedef struct {
  96694. int begin;
  96695. int end;
  96696. float *window;
  96697. float total;
  96698. } envelope_band;
  96699. typedef struct {
  96700. int ch;
  96701. int winlength;
  96702. int searchstep;
  96703. float minenergy;
  96704. mdct_lookup mdct;
  96705. float *mdct_win;
  96706. envelope_band band[VE_BANDS];
  96707. envelope_filter_state *filter;
  96708. int stretch;
  96709. int *mark;
  96710. long storage;
  96711. long current;
  96712. long curmark;
  96713. long cursor;
  96714. } envelope_lookup;
  96715. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  96716. extern void _ve_envelope_clear(envelope_lookup *e);
  96717. extern long _ve_envelope_search(vorbis_dsp_state *v);
  96718. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  96719. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  96720. #endif
  96721. /*** End of inlined file: envelope.h ***/
  96722. /*** Start of inlined file: codebook.h ***/
  96723. #ifndef _V_CODEBOOK_H_
  96724. #define _V_CODEBOOK_H_
  96725. typedef struct static_codebook{
  96726. long dim; /* codebook dimensions (elements per vector) */
  96727. long entries; /* codebook entries */
  96728. long *lengthlist; /* codeword lengths in bits */
  96729. int maptype; /* 0=none
  96730. 1=implicitly populated values from map column
  96731. 2=listed arbitrary values */
  96732. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  96733. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  96734. int q_quant; /* bits: 0 < quant <= 16 */
  96735. int q_sequencep; /* bitflag */
  96736. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  96737. map == 2: list of dim*entries quantized entry vals
  96738. */
  96739. struct encode_aux_nearestmatch *nearest_tree;
  96740. struct encode_aux_threshmatch *thresh_tree;
  96741. struct encode_aux_pigeonhole *pigeon_tree;
  96742. int allocedp;
  96743. } static_codebook;
  96744. typedef struct encode_aux_nearestmatch{
  96745. long *ptr0;
  96746. long *ptr1;
  96747. long *p; /* decision points (each is an entry) */
  96748. long *q; /* decision points (each is an entry) */
  96749. long aux; /* number of tree entries */
  96750. long alloc;
  96751. } encode_aux_nearestmatch;
  96752. typedef struct encode_aux_threshmatch{
  96753. float *quantthresh;
  96754. long *quantmap;
  96755. int quantvals;
  96756. int threshvals;
  96757. } encode_aux_threshmatch;
  96758. typedef struct encode_aux_pigeonhole{
  96759. float min;
  96760. float del;
  96761. int mapentries;
  96762. int quantvals;
  96763. long *pigeonmap;
  96764. long fittotal;
  96765. long *fitlist;
  96766. long *fitmap;
  96767. long *fitlength;
  96768. } encode_aux_pigeonhole;
  96769. typedef struct codebook{
  96770. long dim; /* codebook dimensions (elements per vector) */
  96771. long entries; /* codebook entries */
  96772. long used_entries; /* populated codebook entries */
  96773. const static_codebook *c;
  96774. float *valuelist; /* list of dim*entries actual entry values */
  96775. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  96776. int *dec_index; /* only used if sparseness collapsed */
  96777. char *dec_codelengths;
  96778. ogg_uint32_t *dec_firsttable;
  96779. int dec_firsttablen;
  96780. int dec_maxlength;
  96781. } codebook;
  96782. extern void vorbis_staticbook_clear(static_codebook *b);
  96783. extern void vorbis_staticbook_destroy(static_codebook *b);
  96784. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  96785. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  96786. extern void vorbis_book_clear(codebook *b);
  96787. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  96788. extern float *_book_logdist(const static_codebook *b,float *vals);
  96789. extern float _float32_unpack(long val);
  96790. extern long _float32_pack(float val);
  96791. extern int _best(codebook *book, float *a, int step);
  96792. extern int _ilog(unsigned int v);
  96793. extern long _book_maptype1_quantvals(const static_codebook *b);
  96794. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  96795. extern long vorbis_book_codeword(codebook *book,int entry);
  96796. extern long vorbis_book_codelen(codebook *book,int entry);
  96797. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  96798. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  96799. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  96800. extern int vorbis_book_errorv(codebook *book, float *a);
  96801. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  96802. oggpack_buffer *b);
  96803. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  96804. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  96805. oggpack_buffer *b,int n);
  96806. extern long vorbis_book_decodev_set(codebook *book, float *a,
  96807. oggpack_buffer *b,int n);
  96808. extern long vorbis_book_decodev_add(codebook *book, float *a,
  96809. oggpack_buffer *b,int n);
  96810. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  96811. long off,int ch,
  96812. oggpack_buffer *b,int n);
  96813. #endif
  96814. /*** End of inlined file: codebook.h ***/
  96815. #define BLOCKTYPE_IMPULSE 0
  96816. #define BLOCKTYPE_PADDING 1
  96817. #define BLOCKTYPE_TRANSITION 0
  96818. #define BLOCKTYPE_LONG 1
  96819. #define PACKETBLOBS 15
  96820. typedef struct vorbis_block_internal{
  96821. float **pcmdelay; /* this is a pointer into local storage */
  96822. float ampmax;
  96823. int blocktype;
  96824. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  96825. blob [PACKETBLOBS/2] points to
  96826. the oggpack_buffer in the
  96827. main vorbis_block */
  96828. } vorbis_block_internal;
  96829. typedef void vorbis_look_floor;
  96830. typedef void vorbis_look_residue;
  96831. typedef void vorbis_look_transform;
  96832. typedef struct {
  96833. int blockflag;
  96834. int windowtype;
  96835. int transformtype;
  96836. int mapping;
  96837. } vorbis_info_mode;
  96838. typedef void vorbis_info_floor;
  96839. typedef void vorbis_info_residue;
  96840. typedef void vorbis_info_mapping;
  96841. /*** Start of inlined file: psy.h ***/
  96842. #ifndef _V_PSY_H_
  96843. #define _V_PSY_H_
  96844. /*** Start of inlined file: smallft.h ***/
  96845. #ifndef _V_SMFT_H_
  96846. #define _V_SMFT_H_
  96847. typedef struct {
  96848. int n;
  96849. float *trigcache;
  96850. int *splitcache;
  96851. } drft_lookup;
  96852. extern void drft_forward(drft_lookup *l,float *data);
  96853. extern void drft_backward(drft_lookup *l,float *data);
  96854. extern void drft_init(drft_lookup *l,int n);
  96855. extern void drft_clear(drft_lookup *l);
  96856. #endif
  96857. /*** End of inlined file: smallft.h ***/
  96858. /*** Start of inlined file: backends.h ***/
  96859. #ifndef _vorbis_backend_h_
  96860. #define _vorbis_backend_h_
  96861. typedef struct{
  96862. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  96863. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  96864. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  96865. void (*free_info) (vorbis_info_floor *);
  96866. void (*free_look) (vorbis_look_floor *);
  96867. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  96868. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  96869. void *buffer,float *);
  96870. } vorbis_func_floor;
  96871. typedef struct{
  96872. int order;
  96873. long rate;
  96874. long barkmap;
  96875. int ampbits;
  96876. int ampdB;
  96877. int numbooks; /* <= 16 */
  96878. int books[16];
  96879. float lessthan; /* encode-only config setting hacks for libvorbis */
  96880. float greaterthan; /* encode-only config setting hacks for libvorbis */
  96881. } vorbis_info_floor0;
  96882. #define VIF_POSIT 63
  96883. #define VIF_CLASS 16
  96884. #define VIF_PARTS 31
  96885. typedef struct{
  96886. int partitions; /* 0 to 31 */
  96887. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  96888. int class_dim[VIF_CLASS]; /* 1 to 8 */
  96889. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  96890. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  96891. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  96892. int mult; /* 1 2 3 or 4 */
  96893. int postlist[VIF_POSIT+2]; /* first two implicit */
  96894. float maxover;
  96895. float maxunder;
  96896. float maxerr;
  96897. float twofitweight;
  96898. float twofitatten;
  96899. int n;
  96900. } vorbis_info_floor1;
  96901. typedef struct{
  96902. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  96903. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  96904. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  96905. vorbis_info_residue *);
  96906. void (*free_info) (vorbis_info_residue *);
  96907. void (*free_look) (vorbis_look_residue *);
  96908. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  96909. float **,int *,int);
  96910. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  96911. vorbis_look_residue *,
  96912. float **,float **,int *,int,long **);
  96913. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  96914. float **,int *,int);
  96915. } vorbis_func_residue;
  96916. typedef struct vorbis_info_residue0{
  96917. long begin;
  96918. long end;
  96919. int grouping; /* group n vectors per partition */
  96920. int partitions; /* possible codebooks for a partition */
  96921. int groupbook; /* huffbook for partitioning */
  96922. int secondstages[64]; /* expanded out to pointers in lookup */
  96923. int booklist[256]; /* list of second stage books */
  96924. float classmetric1[64];
  96925. float classmetric2[64];
  96926. } vorbis_info_residue0;
  96927. typedef struct{
  96928. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  96929. oggpack_buffer *);
  96930. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  96931. void (*free_info) (vorbis_info_mapping *);
  96932. int (*forward) (struct vorbis_block *vb);
  96933. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  96934. } vorbis_func_mapping;
  96935. typedef struct vorbis_info_mapping0{
  96936. int submaps; /* <= 16 */
  96937. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  96938. int floorsubmap[16]; /* [mux] submap to floors */
  96939. int residuesubmap[16]; /* [mux] submap to residue */
  96940. int coupling_steps;
  96941. int coupling_mag[256];
  96942. int coupling_ang[256];
  96943. } vorbis_info_mapping0;
  96944. #endif
  96945. /*** End of inlined file: backends.h ***/
  96946. #ifndef EHMER_MAX
  96947. #define EHMER_MAX 56
  96948. #endif
  96949. #define P_BANDS 17 /* 62Hz to 16kHz */
  96950. #define P_LEVELS 8 /* 30dB to 100dB */
  96951. #define P_LEVEL_0 30. /* 30 dB */
  96952. #define P_NOISECURVES 3
  96953. #define NOISE_COMPAND_LEVELS 40
  96954. typedef struct vorbis_info_psy{
  96955. int blockflag;
  96956. float ath_adjatt;
  96957. float ath_maxatt;
  96958. float tone_masteratt[P_NOISECURVES];
  96959. float tone_centerboost;
  96960. float tone_decay;
  96961. float tone_abs_limit;
  96962. float toneatt[P_BANDS];
  96963. int noisemaskp;
  96964. float noisemaxsupp;
  96965. float noisewindowlo;
  96966. float noisewindowhi;
  96967. int noisewindowlomin;
  96968. int noisewindowhimin;
  96969. int noisewindowfixed;
  96970. float noiseoff[P_NOISECURVES][P_BANDS];
  96971. float noisecompand[NOISE_COMPAND_LEVELS];
  96972. float max_curve_dB;
  96973. int normal_channel_p;
  96974. int normal_point_p;
  96975. int normal_start;
  96976. int normal_partition;
  96977. double normal_thresh;
  96978. } vorbis_info_psy;
  96979. typedef struct{
  96980. int eighth_octave_lines;
  96981. float preecho_thresh[VE_BANDS];
  96982. float postecho_thresh[VE_BANDS];
  96983. float stretch_penalty;
  96984. float preecho_minenergy;
  96985. float ampmax_att_per_sec;
  96986. int coupling_pkHz[PACKETBLOBS];
  96987. int coupling_pointlimit[2][PACKETBLOBS];
  96988. int coupling_prepointamp[PACKETBLOBS];
  96989. int coupling_postpointamp[PACKETBLOBS];
  96990. int sliding_lowpass[2][PACKETBLOBS];
  96991. } vorbis_info_psy_global;
  96992. typedef struct {
  96993. float ampmax;
  96994. int channels;
  96995. vorbis_info_psy_global *gi;
  96996. int coupling_pointlimit[2][P_NOISECURVES];
  96997. } vorbis_look_psy_global;
  96998. typedef struct {
  96999. int n;
  97000. struct vorbis_info_psy *vi;
  97001. float ***tonecurves;
  97002. float **noiseoffset;
  97003. float *ath;
  97004. long *octave; /* in n.ocshift format */
  97005. long *bark;
  97006. long firstoc;
  97007. long shiftoc;
  97008. int eighth_octave_lines; /* power of two, please */
  97009. int total_octave_lines;
  97010. long rate; /* cache it */
  97011. float m_val; /* Masking compensation value */
  97012. } vorbis_look_psy;
  97013. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97014. vorbis_info_psy_global *gi,int n,long rate);
  97015. extern void _vp_psy_clear(vorbis_look_psy *p);
  97016. extern void *_vi_psy_dup(void *source);
  97017. extern void _vi_psy_free(vorbis_info_psy *i);
  97018. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97019. extern void _vp_remove_floor(vorbis_look_psy *p,
  97020. float *mdct,
  97021. int *icodedflr,
  97022. float *residue,
  97023. int sliding_lowpass);
  97024. extern void _vp_noisemask(vorbis_look_psy *p,
  97025. float *logmdct,
  97026. float *logmask);
  97027. extern void _vp_tonemask(vorbis_look_psy *p,
  97028. float *logfft,
  97029. float *logmask,
  97030. float global_specmax,
  97031. float local_specmax);
  97032. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97033. float *noise,
  97034. float *tone,
  97035. int offset_select,
  97036. float *logmask,
  97037. float *mdct,
  97038. float *logmdct);
  97039. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97040. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97041. vorbis_info_psy_global *g,
  97042. vorbis_look_psy *p,
  97043. vorbis_info_mapping0 *vi,
  97044. float **mdct);
  97045. extern void _vp_couple(int blobno,
  97046. vorbis_info_psy_global *g,
  97047. vorbis_look_psy *p,
  97048. vorbis_info_mapping0 *vi,
  97049. float **res,
  97050. float **mag_memo,
  97051. int **mag_sort,
  97052. int **ifloor,
  97053. int *nonzero,
  97054. int sliding_lowpass);
  97055. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97056. float *in,float *out,int *sortedindex);
  97057. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97058. float *magnitudes,int *sortedindex);
  97059. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97060. vorbis_look_psy *p,
  97061. vorbis_info_mapping0 *vi,
  97062. float **mags);
  97063. extern void hf_reduction(vorbis_info_psy_global *g,
  97064. vorbis_look_psy *p,
  97065. vorbis_info_mapping0 *vi,
  97066. float **mdct);
  97067. #endif
  97068. /*** End of inlined file: psy.h ***/
  97069. /*** Start of inlined file: bitrate.h ***/
  97070. #ifndef _V_BITRATE_H_
  97071. #define _V_BITRATE_H_
  97072. /*** Start of inlined file: os.h ***/
  97073. #ifndef _OS_H
  97074. #define _OS_H
  97075. #ifdef HAVE_CONFIG_H
  97076. #include "config.h"
  97077. #endif
  97078. #include <math.h>
  97079. /*** Start of inlined file: misc.h ***/
  97080. #ifndef _V_RANDOM_H_
  97081. #define _V_RANDOM_H_
  97082. extern int analysis_noisy;
  97083. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97084. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97085. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97086. ogg_int64_t off);
  97087. #ifdef DEBUG_MALLOC
  97088. #define _VDBG_GRAPHFILE "malloc.m"
  97089. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97090. extern void _VDBG_free(void *ptr,char *file,long line);
  97091. #ifndef MISC_C
  97092. #undef _ogg_malloc
  97093. #undef _ogg_calloc
  97094. #undef _ogg_realloc
  97095. #undef _ogg_free
  97096. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97097. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97098. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97099. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97100. #endif
  97101. #endif
  97102. #endif
  97103. /*** End of inlined file: misc.h ***/
  97104. #ifndef _V_IFDEFJAIL_H_
  97105. # define _V_IFDEFJAIL_H_
  97106. # ifdef __GNUC__
  97107. # define STIN static __inline__
  97108. # elif _WIN32
  97109. # define STIN static __inline
  97110. # else
  97111. # define STIN static
  97112. # endif
  97113. #ifdef DJGPP
  97114. # define rint(x) (floor((x)+0.5f))
  97115. #endif
  97116. #ifndef M_PI
  97117. # define M_PI (3.1415926536f)
  97118. #endif
  97119. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97120. # include <malloc.h>
  97121. # define rint(x) (floor((x)+0.5f))
  97122. # define NO_FLOAT_MATH_LIB
  97123. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97124. #endif
  97125. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97126. void *_alloca(size_t size);
  97127. # define alloca _alloca
  97128. #endif
  97129. #ifndef FAST_HYPOT
  97130. # define FAST_HYPOT hypot
  97131. #endif
  97132. #endif
  97133. #ifdef HAVE_ALLOCA_H
  97134. # include <alloca.h>
  97135. #endif
  97136. #ifdef USE_MEMORY_H
  97137. # include <memory.h>
  97138. #endif
  97139. #ifndef min
  97140. # define min(x,y) ((x)>(y)?(y):(x))
  97141. #endif
  97142. #ifndef max
  97143. # define max(x,y) ((x)<(y)?(y):(x))
  97144. #endif
  97145. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97146. # define VORBIS_FPU_CONTROL
  97147. typedef ogg_int16_t vorbis_fpu_control;
  97148. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97149. ogg_int16_t ret;
  97150. ogg_int16_t temp;
  97151. __asm__ __volatile__("fnstcw %0\n\t"
  97152. "movw %0,%%dx\n\t"
  97153. "orw $62463,%%dx\n\t"
  97154. "movw %%dx,%1\n\t"
  97155. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97156. *fpu=ret;
  97157. }
  97158. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97159. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97160. }
  97161. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97162. we get extra fst/fld to
  97163. truncate precision */
  97164. int i;
  97165. __asm__("fistl %0": "=m"(i) : "t"(f));
  97166. return(i);
  97167. }
  97168. #endif
  97169. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97170. # define VORBIS_FPU_CONTROL
  97171. typedef ogg_int16_t vorbis_fpu_control;
  97172. static __inline int vorbis_ftoi(double f){
  97173. int i;
  97174. __asm{
  97175. fld f
  97176. fistp i
  97177. }
  97178. return i;
  97179. }
  97180. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97181. }
  97182. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97183. }
  97184. #endif
  97185. #ifndef VORBIS_FPU_CONTROL
  97186. typedef int vorbis_fpu_control;
  97187. static int vorbis_ftoi(double f){
  97188. return (int)(f+.5);
  97189. }
  97190. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97191. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97192. #endif
  97193. #endif /* _OS_H */
  97194. /*** End of inlined file: os.h ***/
  97195. typedef struct bitrate_manager_state {
  97196. int managed;
  97197. long avg_reservoir;
  97198. long minmax_reservoir;
  97199. long avg_bitsper;
  97200. long min_bitsper;
  97201. long max_bitsper;
  97202. long short_per_long;
  97203. double avgfloat;
  97204. vorbis_block *vb;
  97205. int choice;
  97206. } bitrate_manager_state;
  97207. typedef struct bitrate_manager_info{
  97208. long avg_rate;
  97209. long min_rate;
  97210. long max_rate;
  97211. long reservoir_bits;
  97212. double reservoir_bias;
  97213. double slew_damp;
  97214. } bitrate_manager_info;
  97215. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97216. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97217. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97218. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97219. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97220. #endif
  97221. /*** End of inlined file: bitrate.h ***/
  97222. static int ilog(unsigned int v){
  97223. int ret=0;
  97224. while(v){
  97225. ret++;
  97226. v>>=1;
  97227. }
  97228. return(ret);
  97229. }
  97230. static int ilog2(unsigned int v){
  97231. int ret=0;
  97232. if(v)--v;
  97233. while(v){
  97234. ret++;
  97235. v>>=1;
  97236. }
  97237. return(ret);
  97238. }
  97239. typedef struct private_state {
  97240. envelope_lookup *ve; /* envelope lookup */
  97241. int window[2];
  97242. vorbis_look_transform **transform[2]; /* block, type */
  97243. drft_lookup fft_look[2];
  97244. int modebits;
  97245. vorbis_look_floor **flr;
  97246. vorbis_look_residue **residue;
  97247. vorbis_look_psy *psy;
  97248. vorbis_look_psy_global *psy_g_look;
  97249. unsigned char *header;
  97250. unsigned char *header1;
  97251. unsigned char *header2;
  97252. bitrate_manager_state bms;
  97253. ogg_int64_t sample_count;
  97254. } private_state;
  97255. /*** Start of inlined file: highlevel.h ***/
  97256. typedef struct highlevel_byblocktype {
  97257. double tone_mask_setting;
  97258. double tone_peaklimit_setting;
  97259. double noise_bias_setting;
  97260. double noise_compand_setting;
  97261. } highlevel_byblocktype;
  97262. typedef struct highlevel_encode_setup {
  97263. void *setup;
  97264. int set_in_stone;
  97265. double base_setting;
  97266. double long_setting;
  97267. double short_setting;
  97268. double impulse_noisetune;
  97269. int managed;
  97270. long bitrate_min;
  97271. long bitrate_av;
  97272. double bitrate_av_damp;
  97273. long bitrate_max;
  97274. long bitrate_reservoir;
  97275. double bitrate_reservoir_bias;
  97276. int impulse_block_p;
  97277. int noise_normalize_p;
  97278. double stereo_point_setting;
  97279. double lowpass_kHz;
  97280. double ath_floating_dB;
  97281. double ath_absolute_dB;
  97282. double amplitude_track_dBpersec;
  97283. double trigger_setting;
  97284. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97285. } highlevel_encode_setup;
  97286. /*** End of inlined file: highlevel.h ***/
  97287. typedef struct codec_setup_info {
  97288. long blocksizes[2];
  97289. int modes;
  97290. int maps;
  97291. int floors;
  97292. int residues;
  97293. int books;
  97294. int psys; /* encode only */
  97295. vorbis_info_mode *mode_param[64];
  97296. int map_type[64];
  97297. vorbis_info_mapping *map_param[64];
  97298. int floor_type[64];
  97299. vorbis_info_floor *floor_param[64];
  97300. int residue_type[64];
  97301. vorbis_info_residue *residue_param[64];
  97302. static_codebook *book_param[256];
  97303. codebook *fullbooks;
  97304. vorbis_info_psy *psy_param[4]; /* encode only */
  97305. vorbis_info_psy_global psy_g_param;
  97306. bitrate_manager_info bi;
  97307. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97308. highly redundant structure, but
  97309. improves clarity of program flow. */
  97310. int halfrate_flag; /* painless downsample for decode */
  97311. } codec_setup_info;
  97312. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97313. extern void _vp_global_free(vorbis_look_psy_global *look);
  97314. #endif
  97315. /*** End of inlined file: codec_internal.h ***/
  97316. /*** Start of inlined file: registry.h ***/
  97317. #ifndef _V_REG_H_
  97318. #define _V_REG_H_
  97319. #define VI_TRANSFORMB 1
  97320. #define VI_WINDOWB 1
  97321. #define VI_TIMEB 1
  97322. #define VI_FLOORB 2
  97323. #define VI_RESB 3
  97324. #define VI_MAPB 1
  97325. extern vorbis_func_floor *_floor_P[];
  97326. extern vorbis_func_residue *_residue_P[];
  97327. extern vorbis_func_mapping *_mapping_P[];
  97328. #endif
  97329. /*** End of inlined file: registry.h ***/
  97330. /*** Start of inlined file: scales.h ***/
  97331. #ifndef _V_SCALES_H_
  97332. #define _V_SCALES_H_
  97333. #include <math.h>
  97334. #define VORBIS_IEEE_FLOAT32 1
  97335. #ifdef VORBIS_IEEE_FLOAT32
  97336. static float unitnorm(float x){
  97337. union {
  97338. ogg_uint32_t i;
  97339. float f;
  97340. } ix;
  97341. ix.f = x;
  97342. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97343. return ix.f;
  97344. }
  97345. static float todB(const float *x){
  97346. union {
  97347. ogg_uint32_t i;
  97348. float f;
  97349. } ix;
  97350. ix.f = *x;
  97351. ix.i = ix.i&0x7fffffff;
  97352. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97353. }
  97354. #define todB_nn(x) todB(x)
  97355. #else
  97356. static float unitnorm(float x){
  97357. if(x<0)return(-1.f);
  97358. return(1.f);
  97359. }
  97360. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97361. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97362. #endif
  97363. #define fromdB(x) (exp((x)*.11512925f))
  97364. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97365. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97366. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97367. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97368. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97369. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97370. #endif
  97371. /*** End of inlined file: scales.h ***/
  97372. int analysis_noisy=1;
  97373. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97374. int ret,i;
  97375. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97376. vb->glue_bits=0;
  97377. vb->time_bits=0;
  97378. vb->floor_bits=0;
  97379. vb->res_bits=0;
  97380. for(i=0;i<PACKETBLOBS;i++)
  97381. oggpack_reset(vbi->packetblob[i]);
  97382. if((ret=_mapping_P[0]->forward(vb)))
  97383. return(ret);
  97384. if(op){
  97385. if(vorbis_bitrate_managed(vb))
  97386. return(OV_EINVAL);
  97387. op->packet=oggpack_get_buffer(&vb->opb);
  97388. op->bytes=oggpack_bytes(&vb->opb);
  97389. op->b_o_s=0;
  97390. op->e_o_s=vb->eofflag;
  97391. op->granulepos=vb->granulepos;
  97392. op->packetno=vb->sequence; /* for sake of completeness */
  97393. }
  97394. return(0);
  97395. }
  97396. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97397. int j;
  97398. FILE *of;
  97399. char buffer[80];
  97400. sprintf(buffer,"%s_%d.m",base,i);
  97401. of=fopen(buffer,"w");
  97402. if(!of)perror("failed to open data dump file");
  97403. for(j=0;j<n;j++){
  97404. if(bark){
  97405. float b=toBARK((4000.f*j/n)+.25);
  97406. fprintf(of,"%f ",b);
  97407. }else
  97408. if(off!=0)
  97409. fprintf(of,"%f ",(double)(j+off)/8000.);
  97410. else
  97411. fprintf(of,"%f ",(double)j);
  97412. if(dB){
  97413. float val;
  97414. if(v[j]==0.)
  97415. val=-140.;
  97416. else
  97417. val=todB(v+j);
  97418. fprintf(of,"%f\n",val);
  97419. }else{
  97420. fprintf(of,"%f\n",v[j]);
  97421. }
  97422. }
  97423. fclose(of);
  97424. }
  97425. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97426. ogg_int64_t off){
  97427. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97428. }
  97429. #endif
  97430. /*** End of inlined file: analysis.c ***/
  97431. /*** Start of inlined file: bitrate.c ***/
  97432. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97433. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97434. // tasks..
  97435. #if JUCE_MSVC
  97436. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97437. #endif
  97438. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97439. #if JUCE_USE_OGGVORBIS
  97440. #include <stdlib.h>
  97441. #include <string.h>
  97442. #include <math.h>
  97443. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97444. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97445. bitrate_manager_info *bi=&ci->bi;
  97446. memset(bm,0,sizeof(*bm));
  97447. if(bi && (bi->reservoir_bits>0)){
  97448. long ratesamples=vi->rate;
  97449. int halfsamples=ci->blocksizes[0]>>1;
  97450. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97451. bm->managed=1;
  97452. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97453. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97454. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97455. bm->avgfloat=PACKETBLOBS/2;
  97456. {
  97457. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97458. bm->minmax_reservoir=desired_fill;
  97459. bm->avg_reservoir=desired_fill;
  97460. }
  97461. }
  97462. }
  97463. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97464. memset(bm,0,sizeof(*bm));
  97465. return;
  97466. }
  97467. int vorbis_bitrate_managed(vorbis_block *vb){
  97468. vorbis_dsp_state *vd=vb->vd;
  97469. private_state *b=(private_state*)vd->backend_state;
  97470. bitrate_manager_state *bm=&b->bms;
  97471. if(bm && bm->managed)return(1);
  97472. return(0);
  97473. }
  97474. int vorbis_bitrate_addblock(vorbis_block *vb){
  97475. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97476. vorbis_dsp_state *vd=vb->vd;
  97477. private_state *b=(private_state*)vd->backend_state;
  97478. bitrate_manager_state *bm=&b->bms;
  97479. vorbis_info *vi=vd->vi;
  97480. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97481. bitrate_manager_info *bi=&ci->bi;
  97482. int choice=rint(bm->avgfloat);
  97483. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97484. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97485. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97486. int samples=ci->blocksizes[vb->W]>>1;
  97487. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97488. if(!bm->managed){
  97489. if(bm->vb)return(-1); /* one has been submitted without
  97490. being claimed */
  97491. bm->vb=vb;
  97492. return(0);
  97493. }
  97494. bm->vb=vb;
  97495. if(bm->avg_bitsper>0){
  97496. double slew=0.;
  97497. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97498. double slewlimit= 15./bi->slew_damp;
  97499. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97500. while(choice>0 && this_bits>avg_target_bits &&
  97501. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97502. choice--;
  97503. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97504. }
  97505. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97506. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97507. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97508. choice++;
  97509. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97510. }
  97511. }
  97512. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97513. if(slew<-slewlimit)slew=-slewlimit;
  97514. if(slew>slewlimit)slew=slewlimit;
  97515. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97516. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97517. }
  97518. if(bm->min_bitsper>0){
  97519. if(this_bits<min_target_bits){
  97520. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97521. choice++;
  97522. if(choice>=PACKETBLOBS)break;
  97523. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97524. }
  97525. }
  97526. }
  97527. if(bm->max_bitsper>0){
  97528. if(this_bits>max_target_bits){
  97529. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97530. choice--;
  97531. if(choice<0)break;
  97532. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97533. }
  97534. }
  97535. }
  97536. if(choice<0){
  97537. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  97538. bm->choice=choice=0;
  97539. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  97540. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  97541. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97542. }
  97543. }else{
  97544. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  97545. if(choice>=PACKETBLOBS)
  97546. choice=PACKETBLOBS-1;
  97547. bm->choice=choice;
  97548. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  97549. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  97550. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97551. }
  97552. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  97553. if(max_target_bits>0 && this_bits>max_target_bits){
  97554. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97555. }else if(min_target_bits>0 && this_bits<min_target_bits){
  97556. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97557. }else{
  97558. if(bm->minmax_reservoir>desired_fill){
  97559. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  97560. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97561. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  97562. }else{
  97563. bm->minmax_reservoir=desired_fill;
  97564. }
  97565. }else{
  97566. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  97567. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97568. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  97569. }else{
  97570. bm->minmax_reservoir=desired_fill;
  97571. }
  97572. }
  97573. }
  97574. }
  97575. if(bm->avg_bitsper>0){
  97576. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97577. bm->avg_reservoir+=this_bits-avg_target_bits;
  97578. }
  97579. return(0);
  97580. }
  97581. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  97582. private_state *b=(private_state*)vd->backend_state;
  97583. bitrate_manager_state *bm=&b->bms;
  97584. vorbis_block *vb=bm->vb;
  97585. int choice=PACKETBLOBS/2;
  97586. if(!vb)return 0;
  97587. if(op){
  97588. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97589. if(vorbis_bitrate_managed(vb))
  97590. choice=bm->choice;
  97591. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  97592. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  97593. op->b_o_s=0;
  97594. op->e_o_s=vb->eofflag;
  97595. op->granulepos=vb->granulepos;
  97596. op->packetno=vb->sequence; /* for sake of completeness */
  97597. }
  97598. bm->vb=0;
  97599. return(1);
  97600. }
  97601. #endif
  97602. /*** End of inlined file: bitrate.c ***/
  97603. /*** Start of inlined file: block.c ***/
  97604. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97605. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97606. // tasks..
  97607. #if JUCE_MSVC
  97608. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97609. #endif
  97610. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97611. #if JUCE_USE_OGGVORBIS
  97612. #include <stdio.h>
  97613. #include <stdlib.h>
  97614. #include <string.h>
  97615. /*** Start of inlined file: window.h ***/
  97616. #ifndef _V_WINDOW_
  97617. #define _V_WINDOW_
  97618. extern float *_vorbis_window_get(int n);
  97619. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  97620. int lW,int W,int nW);
  97621. #endif
  97622. /*** End of inlined file: window.h ***/
  97623. /*** Start of inlined file: lpc.h ***/
  97624. #ifndef _V_LPC_H_
  97625. #define _V_LPC_H_
  97626. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  97627. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  97628. float *data,long n);
  97629. #endif
  97630. /*** End of inlined file: lpc.h ***/
  97631. #ifndef WORD_ALIGN
  97632. #define WORD_ALIGN 8
  97633. #endif
  97634. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  97635. int i;
  97636. memset(vb,0,sizeof(*vb));
  97637. vb->vd=v;
  97638. vb->localalloc=0;
  97639. vb->localstore=NULL;
  97640. if(v->analysisp){
  97641. vorbis_block_internal *vbi=(vorbis_block_internal*)
  97642. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  97643. vbi->ampmax=-9999;
  97644. for(i=0;i<PACKETBLOBS;i++){
  97645. if(i==PACKETBLOBS/2){
  97646. vbi->packetblob[i]=&vb->opb;
  97647. }else{
  97648. vbi->packetblob[i]=
  97649. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  97650. }
  97651. oggpack_writeinit(vbi->packetblob[i]);
  97652. }
  97653. }
  97654. return(0);
  97655. }
  97656. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  97657. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  97658. if(bytes+vb->localtop>vb->localalloc){
  97659. if(vb->localstore){
  97660. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  97661. vb->totaluse+=vb->localtop;
  97662. link->next=vb->reap;
  97663. link->ptr=vb->localstore;
  97664. vb->reap=link;
  97665. }
  97666. vb->localalloc=bytes;
  97667. vb->localstore=_ogg_malloc(vb->localalloc);
  97668. vb->localtop=0;
  97669. }
  97670. {
  97671. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  97672. vb->localtop+=bytes;
  97673. return ret;
  97674. }
  97675. }
  97676. void _vorbis_block_ripcord(vorbis_block *vb){
  97677. struct alloc_chain *reap=vb->reap;
  97678. while(reap){
  97679. struct alloc_chain *next=reap->next;
  97680. _ogg_free(reap->ptr);
  97681. memset(reap,0,sizeof(*reap));
  97682. _ogg_free(reap);
  97683. reap=next;
  97684. }
  97685. if(vb->totaluse){
  97686. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  97687. vb->localalloc+=vb->totaluse;
  97688. vb->totaluse=0;
  97689. }
  97690. vb->localtop=0;
  97691. vb->reap=NULL;
  97692. }
  97693. int vorbis_block_clear(vorbis_block *vb){
  97694. int i;
  97695. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97696. _vorbis_block_ripcord(vb);
  97697. if(vb->localstore)_ogg_free(vb->localstore);
  97698. if(vbi){
  97699. for(i=0;i<PACKETBLOBS;i++){
  97700. oggpack_writeclear(vbi->packetblob[i]);
  97701. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  97702. }
  97703. _ogg_free(vbi);
  97704. }
  97705. memset(vb,0,sizeof(*vb));
  97706. return(0);
  97707. }
  97708. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  97709. int i;
  97710. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97711. private_state *b=NULL;
  97712. int hs;
  97713. if(ci==NULL) return 1;
  97714. hs=ci->halfrate_flag;
  97715. memset(v,0,sizeof(*v));
  97716. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  97717. v->vi=vi;
  97718. b->modebits=ilog2(ci->modes);
  97719. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  97720. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  97721. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97722. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97723. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  97724. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  97725. b->window[0]=ilog2(ci->blocksizes[0])-6;
  97726. b->window[1]=ilog2(ci->blocksizes[1])-6;
  97727. if(encp){ /* encode/decode differ here */
  97728. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  97729. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  97730. if(!ci->fullbooks){
  97731. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97732. for(i=0;i<ci->books;i++)
  97733. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  97734. }
  97735. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  97736. for(i=0;i<ci->psys;i++){
  97737. _vp_psy_init(b->psy+i,
  97738. ci->psy_param[i],
  97739. &ci->psy_g_param,
  97740. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  97741. vi->rate);
  97742. }
  97743. v->analysisp=1;
  97744. }else{
  97745. if(!ci->fullbooks){
  97746. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97747. for(i=0;i<ci->books;i++){
  97748. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  97749. vorbis_staticbook_destroy(ci->book_param[i]);
  97750. ci->book_param[i]=NULL;
  97751. }
  97752. }
  97753. }
  97754. v->pcm_storage=ci->blocksizes[1];
  97755. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  97756. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  97757. {
  97758. int i;
  97759. for(i=0;i<vi->channels;i++)
  97760. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  97761. }
  97762. v->lW=0; /* previous window size */
  97763. v->W=0; /* current window size */
  97764. v->centerW=ci->blocksizes[1]/2;
  97765. v->pcm_current=v->centerW;
  97766. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  97767. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  97768. for(i=0;i<ci->floors;i++)
  97769. b->flr[i]=_floor_P[ci->floor_type[i]]->
  97770. look(v,ci->floor_param[i]);
  97771. for(i=0;i<ci->residues;i++)
  97772. b->residue[i]=_residue_P[ci->residue_type[i]]->
  97773. look(v,ci->residue_param[i]);
  97774. return 0;
  97775. }
  97776. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97777. private_state *b=NULL;
  97778. if(_vds_shared_init(v,vi,1))return 1;
  97779. b=(private_state*)v->backend_state;
  97780. b->psy_g_look=_vp_global_look(vi);
  97781. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  97782. _ve_envelope_init(b->ve,vi);
  97783. vorbis_bitrate_init(vi,&b->bms);
  97784. v->sequence=3;
  97785. return(0);
  97786. }
  97787. void vorbis_dsp_clear(vorbis_dsp_state *v){
  97788. int i;
  97789. if(v){
  97790. vorbis_info *vi=v->vi;
  97791. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  97792. private_state *b=(private_state*)v->backend_state;
  97793. if(b){
  97794. if(b->ve){
  97795. _ve_envelope_clear(b->ve);
  97796. _ogg_free(b->ve);
  97797. }
  97798. if(b->transform[0]){
  97799. mdct_clear((mdct_lookup*) b->transform[0][0]);
  97800. _ogg_free(b->transform[0][0]);
  97801. _ogg_free(b->transform[0]);
  97802. }
  97803. if(b->transform[1]){
  97804. mdct_clear((mdct_lookup*) b->transform[1][0]);
  97805. _ogg_free(b->transform[1][0]);
  97806. _ogg_free(b->transform[1]);
  97807. }
  97808. if(b->flr){
  97809. for(i=0;i<ci->floors;i++)
  97810. _floor_P[ci->floor_type[i]]->
  97811. free_look(b->flr[i]);
  97812. _ogg_free(b->flr);
  97813. }
  97814. if(b->residue){
  97815. for(i=0;i<ci->residues;i++)
  97816. _residue_P[ci->residue_type[i]]->
  97817. free_look(b->residue[i]);
  97818. _ogg_free(b->residue);
  97819. }
  97820. if(b->psy){
  97821. for(i=0;i<ci->psys;i++)
  97822. _vp_psy_clear(b->psy+i);
  97823. _ogg_free(b->psy);
  97824. }
  97825. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  97826. vorbis_bitrate_clear(&b->bms);
  97827. drft_clear(&b->fft_look[0]);
  97828. drft_clear(&b->fft_look[1]);
  97829. }
  97830. if(v->pcm){
  97831. for(i=0;i<vi->channels;i++)
  97832. if(v->pcm[i])_ogg_free(v->pcm[i]);
  97833. _ogg_free(v->pcm);
  97834. if(v->pcmret)_ogg_free(v->pcmret);
  97835. }
  97836. if(b){
  97837. if(b->header)_ogg_free(b->header);
  97838. if(b->header1)_ogg_free(b->header1);
  97839. if(b->header2)_ogg_free(b->header2);
  97840. _ogg_free(b);
  97841. }
  97842. memset(v,0,sizeof(*v));
  97843. }
  97844. }
  97845. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  97846. int i;
  97847. vorbis_info *vi=v->vi;
  97848. private_state *b=(private_state*)v->backend_state;
  97849. if(b->header)_ogg_free(b->header);b->header=NULL;
  97850. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  97851. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  97852. if(v->pcm_current+vals>=v->pcm_storage){
  97853. v->pcm_storage=v->pcm_current+vals*2;
  97854. for(i=0;i<vi->channels;i++){
  97855. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  97856. }
  97857. }
  97858. for(i=0;i<vi->channels;i++)
  97859. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  97860. return(v->pcmret);
  97861. }
  97862. static void _preextrapolate_helper(vorbis_dsp_state *v){
  97863. int i;
  97864. int order=32;
  97865. float *lpc=(float*)alloca(order*sizeof(*lpc));
  97866. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  97867. long j;
  97868. v->preextrapolate=1;
  97869. if(v->pcm_current-v->centerW>order*2){ /* safety */
  97870. for(i=0;i<v->vi->channels;i++){
  97871. for(j=0;j<v->pcm_current;j++)
  97872. work[j]=v->pcm[i][v->pcm_current-j-1];
  97873. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  97874. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  97875. order,
  97876. work+v->pcm_current-v->centerW,
  97877. v->centerW);
  97878. for(j=0;j<v->pcm_current;j++)
  97879. v->pcm[i][v->pcm_current-j-1]=work[j];
  97880. }
  97881. }
  97882. }
  97883. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  97884. vorbis_info *vi=v->vi;
  97885. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97886. if(vals<=0){
  97887. int order=32;
  97888. int i;
  97889. float *lpc=(float*) alloca(order*sizeof(*lpc));
  97890. if(!v->preextrapolate)
  97891. _preextrapolate_helper(v);
  97892. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  97893. v->eofflag=v->pcm_current;
  97894. v->pcm_current+=ci->blocksizes[1]*3;
  97895. for(i=0;i<vi->channels;i++){
  97896. if(v->eofflag>order*2){
  97897. long n;
  97898. n=v->eofflag;
  97899. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  97900. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  97901. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  97902. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  97903. }else{
  97904. memset(v->pcm[i]+v->eofflag,0,
  97905. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  97906. }
  97907. }
  97908. }else{
  97909. if(v->pcm_current+vals>v->pcm_storage)
  97910. return(OV_EINVAL);
  97911. v->pcm_current+=vals;
  97912. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  97913. _preextrapolate_helper(v);
  97914. }
  97915. return(0);
  97916. }
  97917. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  97918. int i;
  97919. vorbis_info *vi=v->vi;
  97920. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97921. private_state *b=(private_state*)v->backend_state;
  97922. vorbis_look_psy_global *g=b->psy_g_look;
  97923. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  97924. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97925. if(!v->preextrapolate)return(0);
  97926. if(v->eofflag==-1)return(0);
  97927. {
  97928. long bp=_ve_envelope_search(v);
  97929. if(bp==-1){
  97930. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  97931. full long block */
  97932. v->nW=0;
  97933. }else{
  97934. if(ci->blocksizes[0]==ci->blocksizes[1])
  97935. v->nW=0;
  97936. else
  97937. v->nW=bp;
  97938. }
  97939. }
  97940. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  97941. {
  97942. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  97943. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  97944. although this check is
  97945. less strict that the
  97946. _ve_envelope_search,
  97947. the search is not run
  97948. if we only use one
  97949. block size */
  97950. }
  97951. _vorbis_block_ripcord(vb);
  97952. vb->lW=v->lW;
  97953. vb->W=v->W;
  97954. vb->nW=v->nW;
  97955. if(v->W){
  97956. if(!v->lW || !v->nW){
  97957. vbi->blocktype=BLOCKTYPE_TRANSITION;
  97958. }else{
  97959. vbi->blocktype=BLOCKTYPE_LONG;
  97960. }
  97961. }else{
  97962. if(_ve_envelope_mark(v)){
  97963. vbi->blocktype=BLOCKTYPE_IMPULSE;
  97964. }else{
  97965. vbi->blocktype=BLOCKTYPE_PADDING;
  97966. }
  97967. }
  97968. vb->vd=v;
  97969. vb->sequence=v->sequence++;
  97970. vb->granulepos=v->granulepos;
  97971. vb->pcmend=ci->blocksizes[v->W];
  97972. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  97973. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  97974. vbi->ampmax=g->ampmax;
  97975. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  97976. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  97977. for(i=0;i<vi->channels;i++){
  97978. vbi->pcmdelay[i]=
  97979. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97980. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97981. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  97982. }
  97983. if(v->eofflag){
  97984. if(v->centerW>=v->eofflag){
  97985. v->eofflag=-1;
  97986. vb->eofflag=1;
  97987. return(1);
  97988. }
  97989. }
  97990. {
  97991. int new_centerNext=ci->blocksizes[1]/2;
  97992. int movementW=centerNext-new_centerNext;
  97993. if(movementW>0){
  97994. _ve_envelope_shift(b->ve,movementW);
  97995. v->pcm_current-=movementW;
  97996. for(i=0;i<vi->channels;i++)
  97997. memmove(v->pcm[i],v->pcm[i]+movementW,
  97998. v->pcm_current*sizeof(*v->pcm[i]));
  97999. v->lW=v->W;
  98000. v->W=v->nW;
  98001. v->centerW=new_centerNext;
  98002. if(v->eofflag){
  98003. v->eofflag-=movementW;
  98004. if(v->eofflag<=0)v->eofflag=-1;
  98005. if(v->centerW>=v->eofflag){
  98006. v->granulepos+=movementW-(v->centerW-v->eofflag);
  98007. }else{
  98008. v->granulepos+=movementW;
  98009. }
  98010. }else{
  98011. v->granulepos+=movementW;
  98012. }
  98013. }
  98014. }
  98015. return(1);
  98016. }
  98017. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98018. vorbis_info *vi=v->vi;
  98019. codec_setup_info *ci;
  98020. int hs;
  98021. if(!v->backend_state)return -1;
  98022. if(!vi)return -1;
  98023. ci=(codec_setup_info*) vi->codec_setup;
  98024. if(!ci)return -1;
  98025. hs=ci->halfrate_flag;
  98026. v->centerW=ci->blocksizes[1]>>(hs+1);
  98027. v->pcm_current=v->centerW>>hs;
  98028. v->pcm_returned=-1;
  98029. v->granulepos=-1;
  98030. v->sequence=-1;
  98031. v->eofflag=0;
  98032. ((private_state *)(v->backend_state))->sample_count=-1;
  98033. return(0);
  98034. }
  98035. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98036. if(_vds_shared_init(v,vi,0)) return 1;
  98037. vorbis_synthesis_restart(v);
  98038. return 0;
  98039. }
  98040. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98041. vorbis_info *vi=v->vi;
  98042. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98043. private_state *b=(private_state*)v->backend_state;
  98044. int hs=ci->halfrate_flag;
  98045. int i,j;
  98046. if(!vb)return(OV_EINVAL);
  98047. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98048. v->lW=v->W;
  98049. v->W=vb->W;
  98050. v->nW=-1;
  98051. if((v->sequence==-1)||
  98052. (v->sequence+1 != vb->sequence)){
  98053. v->granulepos=-1; /* out of sequence; lose count */
  98054. b->sample_count=-1;
  98055. }
  98056. v->sequence=vb->sequence;
  98057. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98058. was called on block */
  98059. int n=ci->blocksizes[v->W]>>(hs+1);
  98060. int n0=ci->blocksizes[0]>>(hs+1);
  98061. int n1=ci->blocksizes[1]>>(hs+1);
  98062. int thisCenter;
  98063. int prevCenter;
  98064. v->glue_bits+=vb->glue_bits;
  98065. v->time_bits+=vb->time_bits;
  98066. v->floor_bits+=vb->floor_bits;
  98067. v->res_bits+=vb->res_bits;
  98068. if(v->centerW){
  98069. thisCenter=n1;
  98070. prevCenter=0;
  98071. }else{
  98072. thisCenter=0;
  98073. prevCenter=n1;
  98074. }
  98075. for(j=0;j<vi->channels;j++){
  98076. if(v->lW){
  98077. if(v->W){
  98078. float *w=_vorbis_window_get(b->window[1]-hs);
  98079. float *pcm=v->pcm[j]+prevCenter;
  98080. float *p=vb->pcm[j];
  98081. for(i=0;i<n1;i++)
  98082. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98083. }else{
  98084. float *w=_vorbis_window_get(b->window[0]-hs);
  98085. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98086. float *p=vb->pcm[j];
  98087. for(i=0;i<n0;i++)
  98088. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98089. }
  98090. }else{
  98091. if(v->W){
  98092. float *w=_vorbis_window_get(b->window[0]-hs);
  98093. float *pcm=v->pcm[j]+prevCenter;
  98094. float *p=vb->pcm[j]+n1/2-n0/2;
  98095. for(i=0;i<n0;i++)
  98096. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98097. for(;i<n1/2+n0/2;i++)
  98098. pcm[i]=p[i];
  98099. }else{
  98100. float *w=_vorbis_window_get(b->window[0]-hs);
  98101. float *pcm=v->pcm[j]+prevCenter;
  98102. float *p=vb->pcm[j];
  98103. for(i=0;i<n0;i++)
  98104. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98105. }
  98106. }
  98107. {
  98108. float *pcm=v->pcm[j]+thisCenter;
  98109. float *p=vb->pcm[j]+n;
  98110. for(i=0;i<n;i++)
  98111. pcm[i]=p[i];
  98112. }
  98113. }
  98114. if(v->centerW)
  98115. v->centerW=0;
  98116. else
  98117. v->centerW=n1;
  98118. if(v->pcm_returned==-1){
  98119. v->pcm_returned=thisCenter;
  98120. v->pcm_current=thisCenter;
  98121. }else{
  98122. v->pcm_returned=prevCenter;
  98123. v->pcm_current=prevCenter+
  98124. ((ci->blocksizes[v->lW]/4+
  98125. ci->blocksizes[v->W]/4)>>hs);
  98126. }
  98127. }
  98128. if(b->sample_count==-1){
  98129. b->sample_count=0;
  98130. }else{
  98131. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98132. }
  98133. if(v->granulepos==-1){
  98134. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98135. v->granulepos=vb->granulepos;
  98136. if(b->sample_count>v->granulepos){
  98137. if(vb->eofflag){
  98138. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98139. }else{
  98140. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98141. if(v->pcm_returned>v->pcm_current)
  98142. v->pcm_returned=v->pcm_current;
  98143. }
  98144. }
  98145. }
  98146. }else{
  98147. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98148. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98149. if(v->granulepos>vb->granulepos){
  98150. long extra=v->granulepos-vb->granulepos;
  98151. if(extra)
  98152. if(vb->eofflag){
  98153. v->pcm_current-=extra>>hs;
  98154. } /* else {Shouldn't happen *unless* the bitstream is out of
  98155. spec. Either way, believe the bitstream } */
  98156. } /* else {Shouldn't happen *unless* the bitstream is out of
  98157. spec. Either way, believe the bitstream } */
  98158. v->granulepos=vb->granulepos;
  98159. }
  98160. }
  98161. if(vb->eofflag)v->eofflag=1;
  98162. return(0);
  98163. }
  98164. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98165. vorbis_info *vi=v->vi;
  98166. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98167. if(pcm){
  98168. int i;
  98169. for(i=0;i<vi->channels;i++)
  98170. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98171. *pcm=v->pcmret;
  98172. }
  98173. return(v->pcm_current-v->pcm_returned);
  98174. }
  98175. return(0);
  98176. }
  98177. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98178. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98179. v->pcm_returned+=n;
  98180. return(0);
  98181. }
  98182. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98183. vorbis_info *vi=v->vi;
  98184. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98185. int hs=ci->halfrate_flag;
  98186. int n=ci->blocksizes[v->W]>>(hs+1);
  98187. int n0=ci->blocksizes[0]>>(hs+1);
  98188. int n1=ci->blocksizes[1]>>(hs+1);
  98189. int i,j;
  98190. if(v->pcm_returned<0)return 0;
  98191. if(v->centerW==n1){
  98192. for(j=0;j<vi->channels;j++){
  98193. float *p=v->pcm[j];
  98194. for(i=0;i<n1;i++){
  98195. float temp=p[i];
  98196. p[i]=p[i+n1];
  98197. p[i+n1]=temp;
  98198. }
  98199. }
  98200. v->pcm_current-=n1;
  98201. v->pcm_returned-=n1;
  98202. v->centerW=0;
  98203. }
  98204. if((v->lW^v->W)==1){
  98205. for(j=0;j<vi->channels;j++){
  98206. float *s=v->pcm[j];
  98207. float *d=v->pcm[j]+(n1-n0)/2;
  98208. for(i=(n1+n0)/2-1;i>=0;--i)
  98209. d[i]=s[i];
  98210. }
  98211. v->pcm_returned+=(n1-n0)/2;
  98212. v->pcm_current+=(n1-n0)/2;
  98213. }else{
  98214. if(v->lW==0){
  98215. for(j=0;j<vi->channels;j++){
  98216. float *s=v->pcm[j];
  98217. float *d=v->pcm[j]+n1-n0;
  98218. for(i=n0-1;i>=0;--i)
  98219. d[i]=s[i];
  98220. }
  98221. v->pcm_returned+=n1-n0;
  98222. v->pcm_current+=n1-n0;
  98223. }
  98224. }
  98225. if(pcm){
  98226. int i;
  98227. for(i=0;i<vi->channels;i++)
  98228. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98229. *pcm=v->pcmret;
  98230. }
  98231. return(n1+n-v->pcm_returned);
  98232. }
  98233. float *vorbis_window(vorbis_dsp_state *v,int W){
  98234. vorbis_info *vi=v->vi;
  98235. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98236. int hs=ci->halfrate_flag;
  98237. private_state *b=(private_state*)v->backend_state;
  98238. if(b->window[W]-1<0)return NULL;
  98239. return _vorbis_window_get(b->window[W]-hs);
  98240. }
  98241. #endif
  98242. /*** End of inlined file: block.c ***/
  98243. /*** Start of inlined file: codebook.c ***/
  98244. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98245. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98246. // tasks..
  98247. #if JUCE_MSVC
  98248. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98249. #endif
  98250. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98251. #if JUCE_USE_OGGVORBIS
  98252. #include <stdlib.h>
  98253. #include <string.h>
  98254. #include <math.h>
  98255. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98256. long i,j;
  98257. int ordered=0;
  98258. oggpack_write(opb,0x564342,24);
  98259. oggpack_write(opb,c->dim,16);
  98260. oggpack_write(opb,c->entries,24);
  98261. for(i=1;i<c->entries;i++)
  98262. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98263. if(i==c->entries)ordered=1;
  98264. if(ordered){
  98265. long count=0;
  98266. oggpack_write(opb,1,1); /* ordered */
  98267. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98268. for(i=1;i<c->entries;i++){
  98269. long thisx=c->lengthlist[i];
  98270. long last=c->lengthlist[i-1];
  98271. if(thisx>last){
  98272. for(j=last;j<thisx;j++){
  98273. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98274. count=i;
  98275. }
  98276. }
  98277. }
  98278. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98279. }else{
  98280. oggpack_write(opb,0,1); /* unordered */
  98281. for(i=0;i<c->entries;i++)
  98282. if(c->lengthlist[i]==0)break;
  98283. if(i==c->entries){
  98284. oggpack_write(opb,0,1); /* no unused entries */
  98285. for(i=0;i<c->entries;i++)
  98286. oggpack_write(opb,c->lengthlist[i]-1,5);
  98287. }else{
  98288. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98289. for(i=0;i<c->entries;i++){
  98290. if(c->lengthlist[i]==0){
  98291. oggpack_write(opb,0,1);
  98292. }else{
  98293. oggpack_write(opb,1,1);
  98294. oggpack_write(opb,c->lengthlist[i]-1,5);
  98295. }
  98296. }
  98297. }
  98298. }
  98299. oggpack_write(opb,c->maptype,4);
  98300. switch(c->maptype){
  98301. case 0:
  98302. break;
  98303. case 1:case 2:
  98304. if(!c->quantlist){
  98305. return(-1);
  98306. }
  98307. oggpack_write(opb,c->q_min,32);
  98308. oggpack_write(opb,c->q_delta,32);
  98309. oggpack_write(opb,c->q_quant-1,4);
  98310. oggpack_write(opb,c->q_sequencep,1);
  98311. {
  98312. int quantvals;
  98313. switch(c->maptype){
  98314. case 1:
  98315. quantvals=_book_maptype1_quantvals(c);
  98316. break;
  98317. case 2:
  98318. quantvals=c->entries*c->dim;
  98319. break;
  98320. default: /* NOT_REACHABLE */
  98321. quantvals=-1;
  98322. }
  98323. for(i=0;i<quantvals;i++)
  98324. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98325. }
  98326. break;
  98327. default:
  98328. return(-1);
  98329. }
  98330. return(0);
  98331. }
  98332. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98333. long i,j;
  98334. memset(s,0,sizeof(*s));
  98335. s->allocedp=1;
  98336. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98337. s->dim=oggpack_read(opb,16);
  98338. s->entries=oggpack_read(opb,24);
  98339. if(s->entries==-1)goto _eofout;
  98340. switch((int)oggpack_read(opb,1)){
  98341. case 0:
  98342. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98343. if(oggpack_read(opb,1)){
  98344. for(i=0;i<s->entries;i++){
  98345. if(oggpack_read(opb,1)){
  98346. long num=oggpack_read(opb,5);
  98347. if(num==-1)goto _eofout;
  98348. s->lengthlist[i]=num+1;
  98349. }else
  98350. s->lengthlist[i]=0;
  98351. }
  98352. }else{
  98353. for(i=0;i<s->entries;i++){
  98354. long num=oggpack_read(opb,5);
  98355. if(num==-1)goto _eofout;
  98356. s->lengthlist[i]=num+1;
  98357. }
  98358. }
  98359. break;
  98360. case 1:
  98361. {
  98362. long length=oggpack_read(opb,5)+1;
  98363. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98364. for(i=0;i<s->entries;){
  98365. long num=oggpack_read(opb,_ilog(s->entries-i));
  98366. if(num==-1)goto _eofout;
  98367. for(j=0;j<num && i<s->entries;j++,i++)
  98368. s->lengthlist[i]=length;
  98369. length++;
  98370. }
  98371. }
  98372. break;
  98373. default:
  98374. return(-1);
  98375. }
  98376. switch((s->maptype=oggpack_read(opb,4))){
  98377. case 0:
  98378. break;
  98379. case 1: case 2:
  98380. s->q_min=oggpack_read(opb,32);
  98381. s->q_delta=oggpack_read(opb,32);
  98382. s->q_quant=oggpack_read(opb,4)+1;
  98383. s->q_sequencep=oggpack_read(opb,1);
  98384. {
  98385. int quantvals=0;
  98386. switch(s->maptype){
  98387. case 1:
  98388. quantvals=_book_maptype1_quantvals(s);
  98389. break;
  98390. case 2:
  98391. quantvals=s->entries*s->dim;
  98392. break;
  98393. }
  98394. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98395. for(i=0;i<quantvals;i++)
  98396. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98397. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98398. }
  98399. break;
  98400. default:
  98401. goto _errout;
  98402. }
  98403. return(0);
  98404. _errout:
  98405. _eofout:
  98406. vorbis_staticbook_clear(s);
  98407. return(-1);
  98408. }
  98409. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98410. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98411. return(book->c->lengthlist[a]);
  98412. }
  98413. int vorbis_book_errorv(codebook *book,float *a){
  98414. int dim=book->dim,k;
  98415. int best=_best(book,a,1);
  98416. for(k=0;k<dim;k++)
  98417. a[k]=(book->valuelist+best*dim)[k];
  98418. return(best);
  98419. }
  98420. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98421. int k,dim=book->dim;
  98422. for(k=0;k<dim;k++)
  98423. a[k]=(book->valuelist+best*dim)[k];
  98424. return(vorbis_book_encode(book,best,b));
  98425. }
  98426. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98427. int read=book->dec_maxlength;
  98428. long lo,hi;
  98429. long lok = oggpack_look(b,book->dec_firsttablen);
  98430. if (lok >= 0) {
  98431. long entry = book->dec_firsttable[lok];
  98432. if(entry&0x80000000UL){
  98433. lo=(entry>>15)&0x7fff;
  98434. hi=book->used_entries-(entry&0x7fff);
  98435. }else{
  98436. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98437. return(entry-1);
  98438. }
  98439. }else{
  98440. lo=0;
  98441. hi=book->used_entries;
  98442. }
  98443. lok = oggpack_look(b, read);
  98444. while(lok<0 && read>1)
  98445. lok = oggpack_look(b, --read);
  98446. if(lok<0)return -1;
  98447. {
  98448. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98449. while(hi-lo>1){
  98450. long p=(hi-lo)>>1;
  98451. long test=book->codelist[lo+p]>testword;
  98452. lo+=p&(test-1);
  98453. hi-=p&(-test);
  98454. }
  98455. if(book->dec_codelengths[lo]<=read){
  98456. oggpack_adv(b, book->dec_codelengths[lo]);
  98457. return(lo);
  98458. }
  98459. }
  98460. oggpack_adv(b, read);
  98461. return(-1);
  98462. }
  98463. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98464. long packed_entry=decode_packed_entry_number(book,b);
  98465. if(packed_entry>=0)
  98466. return(book->dec_index[packed_entry]);
  98467. return(packed_entry);
  98468. }
  98469. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98470. int step=n/book->dim;
  98471. long *entry = (long*)alloca(sizeof(*entry)*step);
  98472. float **t = (float**)alloca(sizeof(*t)*step);
  98473. int i,j,o;
  98474. for (i = 0; i < step; i++) {
  98475. entry[i]=decode_packed_entry_number(book,b);
  98476. if(entry[i]==-1)return(-1);
  98477. t[i] = book->valuelist+entry[i]*book->dim;
  98478. }
  98479. for(i=0,o=0;i<book->dim;i++,o+=step)
  98480. for (j=0;j<step;j++)
  98481. a[o+j]+=t[j][i];
  98482. return(0);
  98483. }
  98484. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98485. int i,j,entry;
  98486. float *t;
  98487. if(book->dim>8){
  98488. for(i=0;i<n;){
  98489. entry = decode_packed_entry_number(book,b);
  98490. if(entry==-1)return(-1);
  98491. t = book->valuelist+entry*book->dim;
  98492. for (j=0;j<book->dim;)
  98493. a[i++]+=t[j++];
  98494. }
  98495. }else{
  98496. for(i=0;i<n;){
  98497. entry = decode_packed_entry_number(book,b);
  98498. if(entry==-1)return(-1);
  98499. t = book->valuelist+entry*book->dim;
  98500. j=0;
  98501. switch((int)book->dim){
  98502. case 8:
  98503. a[i++]+=t[j++];
  98504. case 7:
  98505. a[i++]+=t[j++];
  98506. case 6:
  98507. a[i++]+=t[j++];
  98508. case 5:
  98509. a[i++]+=t[j++];
  98510. case 4:
  98511. a[i++]+=t[j++];
  98512. case 3:
  98513. a[i++]+=t[j++];
  98514. case 2:
  98515. a[i++]+=t[j++];
  98516. case 1:
  98517. a[i++]+=t[j++];
  98518. case 0:
  98519. break;
  98520. }
  98521. }
  98522. }
  98523. return(0);
  98524. }
  98525. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98526. int i,j,entry;
  98527. float *t;
  98528. for(i=0;i<n;){
  98529. entry = decode_packed_entry_number(book,b);
  98530. if(entry==-1)return(-1);
  98531. t = book->valuelist+entry*book->dim;
  98532. for (j=0;j<book->dim;)
  98533. a[i++]=t[j++];
  98534. }
  98535. return(0);
  98536. }
  98537. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  98538. oggpack_buffer *b,int n){
  98539. long i,j,entry;
  98540. int chptr=0;
  98541. for(i=offset/ch;i<(offset+n)/ch;){
  98542. entry = decode_packed_entry_number(book,b);
  98543. if(entry==-1)return(-1);
  98544. {
  98545. const float *t = book->valuelist+entry*book->dim;
  98546. for (j=0;j<book->dim;j++){
  98547. a[chptr++][i]+=t[j];
  98548. if(chptr==ch){
  98549. chptr=0;
  98550. i++;
  98551. }
  98552. }
  98553. }
  98554. }
  98555. return(0);
  98556. }
  98557. #ifdef _V_SELFTEST
  98558. #include <stdio.h>
  98559. #include "vorbis/book/lsp20_0.vqh"
  98560. #include "vorbis/book/res0a_13.vqh"
  98561. #define TESTSIZE 40
  98562. float test1[TESTSIZE]={
  98563. 0.105939f,
  98564. 0.215373f,
  98565. 0.429117f,
  98566. 0.587974f,
  98567. 0.181173f,
  98568. 0.296583f,
  98569. 0.515707f,
  98570. 0.715261f,
  98571. 0.162327f,
  98572. 0.263834f,
  98573. 0.342876f,
  98574. 0.406025f,
  98575. 0.103571f,
  98576. 0.223561f,
  98577. 0.368513f,
  98578. 0.540313f,
  98579. 0.136672f,
  98580. 0.395882f,
  98581. 0.587183f,
  98582. 0.652476f,
  98583. 0.114338f,
  98584. 0.417300f,
  98585. 0.525486f,
  98586. 0.698679f,
  98587. 0.147492f,
  98588. 0.324481f,
  98589. 0.643089f,
  98590. 0.757582f,
  98591. 0.139556f,
  98592. 0.215795f,
  98593. 0.324559f,
  98594. 0.399387f,
  98595. 0.120236f,
  98596. 0.267420f,
  98597. 0.446940f,
  98598. 0.608760f,
  98599. 0.115587f,
  98600. 0.287234f,
  98601. 0.571081f,
  98602. 0.708603f,
  98603. };
  98604. float test3[TESTSIZE]={
  98605. 0,1,-2,3,4,-5,6,7,8,9,
  98606. 8,-2,7,-1,4,6,8,3,1,-9,
  98607. 10,11,12,13,14,15,26,17,18,19,
  98608. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  98609. static_codebook *testlist[]={&_vq_book_lsp20_0,
  98610. &_vq_book_res0a_13,NULL};
  98611. float *testvec[]={test1,test3};
  98612. int main(){
  98613. oggpack_buffer write;
  98614. oggpack_buffer read;
  98615. long ptr=0,i;
  98616. oggpack_writeinit(&write);
  98617. fprintf(stderr,"Testing codebook abstraction...:\n");
  98618. while(testlist[ptr]){
  98619. codebook c;
  98620. static_codebook s;
  98621. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  98622. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  98623. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  98624. memset(iv,0,sizeof(*iv)*TESTSIZE);
  98625. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  98626. oggpack_reset(&write);
  98627. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  98628. we can write */
  98629. vorbis_staticbook_pack(testlist[ptr],&write);
  98630. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  98631. for(i=0;i<TESTSIZE;i+=c.dim){
  98632. int best=_best(&c,qv+i,1);
  98633. vorbis_book_encodev(&c,best,qv+i,&write);
  98634. }
  98635. vorbis_book_clear(&c);
  98636. fprintf(stderr,"OK.\n");
  98637. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  98638. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  98639. if(vorbis_staticbook_unpack(&read,&s)){
  98640. fprintf(stderr,"Error unpacking codebook.\n");
  98641. exit(1);
  98642. }
  98643. if(vorbis_book_init_decode(&c,&s)){
  98644. fprintf(stderr,"Error initializing codebook.\n");
  98645. exit(1);
  98646. }
  98647. for(i=0;i<TESTSIZE;i+=c.dim)
  98648. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  98649. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  98650. exit(1);
  98651. }
  98652. for(i=0;i<TESTSIZE;i++)
  98653. if(fabs(qv[i]-iv[i])>.000001){
  98654. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  98655. iv[i],qv[i],i);
  98656. exit(1);
  98657. }
  98658. fprintf(stderr,"OK\n");
  98659. ptr++;
  98660. }
  98661. exit(0);
  98662. }
  98663. #endif
  98664. #endif
  98665. /*** End of inlined file: codebook.c ***/
  98666. /*** Start of inlined file: envelope.c ***/
  98667. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98668. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98669. // tasks..
  98670. #if JUCE_MSVC
  98671. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98672. #endif
  98673. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98674. #if JUCE_USE_OGGVORBIS
  98675. #include <stdlib.h>
  98676. #include <string.h>
  98677. #include <stdio.h>
  98678. #include <math.h>
  98679. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  98680. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98681. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98682. int ch=vi->channels;
  98683. int i,j;
  98684. int n=e->winlength=128;
  98685. e->searchstep=64; /* not random */
  98686. e->minenergy=gi->preecho_minenergy;
  98687. e->ch=ch;
  98688. e->storage=128;
  98689. e->cursor=ci->blocksizes[1]/2;
  98690. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  98691. mdct_init(&e->mdct,n);
  98692. for(i=0;i<n;i++){
  98693. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  98694. e->mdct_win[i]*=e->mdct_win[i];
  98695. }
  98696. e->band[0].begin=2; e->band[0].end=4;
  98697. e->band[1].begin=4; e->band[1].end=5;
  98698. e->band[2].begin=6; e->band[2].end=6;
  98699. e->band[3].begin=9; e->band[3].end=8;
  98700. e->band[4].begin=13; e->band[4].end=8;
  98701. e->band[5].begin=17; e->band[5].end=8;
  98702. e->band[6].begin=22; e->band[6].end=8;
  98703. for(j=0;j<VE_BANDS;j++){
  98704. n=e->band[j].end;
  98705. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  98706. for(i=0;i<n;i++){
  98707. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  98708. e->band[j].total+=e->band[j].window[i];
  98709. }
  98710. e->band[j].total=1./e->band[j].total;
  98711. }
  98712. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  98713. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  98714. }
  98715. void _ve_envelope_clear(envelope_lookup *e){
  98716. int i;
  98717. mdct_clear(&e->mdct);
  98718. for(i=0;i<VE_BANDS;i++)
  98719. _ogg_free(e->band[i].window);
  98720. _ogg_free(e->mdct_win);
  98721. _ogg_free(e->filter);
  98722. _ogg_free(e->mark);
  98723. memset(e,0,sizeof(*e));
  98724. }
  98725. static int _ve_amp(envelope_lookup *ve,
  98726. vorbis_info_psy_global *gi,
  98727. float *data,
  98728. envelope_band *bands,
  98729. envelope_filter_state *filters,
  98730. long pos){
  98731. long n=ve->winlength;
  98732. int ret=0;
  98733. long i,j;
  98734. float decay;
  98735. float minV=ve->minenergy;
  98736. float *vec=(float*) alloca(n*sizeof(*vec));
  98737. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  98738. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  98739. if(penalty<0.f)penalty=0.f;
  98740. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  98741. for(i=0;i<n;i++)
  98742. vec[i]=data[i]*ve->mdct_win[i];
  98743. mdct_forward(&ve->mdct,vec,vec);
  98744. {
  98745. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  98746. int ptr=filters->nearptr;
  98747. if(ptr==0){
  98748. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  98749. filters->nearDC_partialacc=temp;
  98750. }else{
  98751. decay=filters->nearDC_acc+=temp;
  98752. filters->nearDC_partialacc+=temp;
  98753. }
  98754. filters->nearDC_acc-=filters->nearDC[ptr];
  98755. filters->nearDC[ptr]=temp;
  98756. decay*=(1./(VE_NEARDC+1));
  98757. filters->nearptr++;
  98758. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  98759. decay=todB(&decay)*.5-15.f;
  98760. }
  98761. for(i=0;i<n/2;i+=2){
  98762. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  98763. val=todB(&val)*.5f;
  98764. if(val<decay)val=decay;
  98765. if(val<minV)val=minV;
  98766. vec[i>>1]=val;
  98767. decay-=8.;
  98768. }
  98769. for(j=0;j<VE_BANDS;j++){
  98770. float acc=0.;
  98771. float valmax,valmin;
  98772. for(i=0;i<bands[j].end;i++)
  98773. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  98774. acc*=bands[j].total;
  98775. {
  98776. int p,thisx=filters[j].ampptr;
  98777. float postmax,postmin,premax=-99999.f,premin=99999.f;
  98778. p=thisx;
  98779. p--;
  98780. if(p<0)p+=VE_AMP;
  98781. postmax=max(acc,filters[j].ampbuf[p]);
  98782. postmin=min(acc,filters[j].ampbuf[p]);
  98783. for(i=0;i<stretch;i++){
  98784. p--;
  98785. if(p<0)p+=VE_AMP;
  98786. premax=max(premax,filters[j].ampbuf[p]);
  98787. premin=min(premin,filters[j].ampbuf[p]);
  98788. }
  98789. valmin=postmin-premin;
  98790. valmax=postmax-premax;
  98791. filters[j].ampbuf[thisx]=acc;
  98792. filters[j].ampptr++;
  98793. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  98794. }
  98795. if(valmax>gi->preecho_thresh[j]+penalty){
  98796. ret|=1;
  98797. ret|=4;
  98798. }
  98799. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  98800. }
  98801. return(ret);
  98802. }
  98803. #if 0
  98804. static int seq=0;
  98805. static ogg_int64_t totalshift=-1024;
  98806. #endif
  98807. long _ve_envelope_search(vorbis_dsp_state *v){
  98808. vorbis_info *vi=v->vi;
  98809. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98810. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98811. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98812. long i,j;
  98813. int first=ve->current/ve->searchstep;
  98814. int last=v->pcm_current/ve->searchstep-VE_WIN;
  98815. if(first<0)first=0;
  98816. if(last+VE_WIN+VE_POST>ve->storage){
  98817. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  98818. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  98819. }
  98820. for(j=first;j<last;j++){
  98821. int ret=0;
  98822. ve->stretch++;
  98823. if(ve->stretch>VE_MAXSTRETCH*2)
  98824. ve->stretch=VE_MAXSTRETCH*2;
  98825. for(i=0;i<ve->ch;i++){
  98826. float *pcm=v->pcm[i]+ve->searchstep*(j);
  98827. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  98828. }
  98829. ve->mark[j+VE_POST]=0;
  98830. if(ret&1){
  98831. ve->mark[j]=1;
  98832. ve->mark[j+1]=1;
  98833. }
  98834. if(ret&2){
  98835. ve->mark[j]=1;
  98836. if(j>0)ve->mark[j-1]=1;
  98837. }
  98838. if(ret&4)ve->stretch=-1;
  98839. }
  98840. ve->current=last*ve->searchstep;
  98841. {
  98842. long centerW=v->centerW;
  98843. long testW=
  98844. centerW+
  98845. ci->blocksizes[v->W]/4+
  98846. ci->blocksizes[1]/2+
  98847. ci->blocksizes[0]/4;
  98848. j=ve->cursor;
  98849. while(j<ve->current-(ve->searchstep)){/* account for postecho
  98850. working back one window */
  98851. if(j>=testW)return(1);
  98852. ve->cursor=j;
  98853. if(ve->mark[j/ve->searchstep]){
  98854. if(j>centerW){
  98855. #if 0
  98856. if(j>ve->curmark){
  98857. float *marker=alloca(v->pcm_current*sizeof(*marker));
  98858. int l,m;
  98859. memset(marker,0,sizeof(*marker)*v->pcm_current);
  98860. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  98861. seq,
  98862. (totalshift+ve->cursor)/44100.,
  98863. (totalshift+j)/44100.);
  98864. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  98865. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  98866. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  98867. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  98868. for(m=0;m<VE_BANDS;m++){
  98869. char buf[80];
  98870. sprintf(buf,"delL%d",m);
  98871. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  98872. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98873. }
  98874. for(m=0;m<VE_BANDS;m++){
  98875. char buf[80];
  98876. sprintf(buf,"delR%d",m);
  98877. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  98878. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98879. }
  98880. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  98881. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  98882. seq++;
  98883. }
  98884. #endif
  98885. ve->curmark=j;
  98886. if(j>=testW)return(1);
  98887. return(0);
  98888. }
  98889. }
  98890. j+=ve->searchstep;
  98891. }
  98892. }
  98893. return(-1);
  98894. }
  98895. int _ve_envelope_mark(vorbis_dsp_state *v){
  98896. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98897. vorbis_info *vi=v->vi;
  98898. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98899. long centerW=v->centerW;
  98900. long beginW=centerW-ci->blocksizes[v->W]/4;
  98901. long endW=centerW+ci->blocksizes[v->W]/4;
  98902. if(v->W){
  98903. beginW-=ci->blocksizes[v->lW]/4;
  98904. endW+=ci->blocksizes[v->nW]/4;
  98905. }else{
  98906. beginW-=ci->blocksizes[0]/4;
  98907. endW+=ci->blocksizes[0]/4;
  98908. }
  98909. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  98910. {
  98911. long first=beginW/ve->searchstep;
  98912. long last=endW/ve->searchstep;
  98913. long i;
  98914. for(i=first;i<last;i++)
  98915. if(ve->mark[i])return(1);
  98916. }
  98917. return(0);
  98918. }
  98919. void _ve_envelope_shift(envelope_lookup *e,long shift){
  98920. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  98921. ahead of ve->current */
  98922. int smallshift=shift/e->searchstep;
  98923. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  98924. #if 0
  98925. for(i=0;i<VE_BANDS*e->ch;i++)
  98926. memmove(e->filter[i].markers,
  98927. e->filter[i].markers+smallshift,
  98928. (1024-smallshift)*sizeof(*(*e->filter).markers));
  98929. totalshift+=shift;
  98930. #endif
  98931. e->current-=shift;
  98932. if(e->curmark>=0)
  98933. e->curmark-=shift;
  98934. e->cursor-=shift;
  98935. }
  98936. #endif
  98937. /*** End of inlined file: envelope.c ***/
  98938. /*** Start of inlined file: floor0.c ***/
  98939. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98940. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98941. // tasks..
  98942. #if JUCE_MSVC
  98943. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98944. #endif
  98945. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98946. #if JUCE_USE_OGGVORBIS
  98947. #include <stdlib.h>
  98948. #include <string.h>
  98949. #include <math.h>
  98950. /*** Start of inlined file: lsp.h ***/
  98951. #ifndef _V_LSP_H_
  98952. #define _V_LSP_H_
  98953. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  98954. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  98955. float *lsp,int m,
  98956. float amp,float ampoffset);
  98957. #endif
  98958. /*** End of inlined file: lsp.h ***/
  98959. #include <stdio.h>
  98960. typedef struct {
  98961. int ln;
  98962. int m;
  98963. int **linearmap;
  98964. int n[2];
  98965. vorbis_info_floor0 *vi;
  98966. long bits;
  98967. long frames;
  98968. } vorbis_look_floor0;
  98969. static void floor0_free_info(vorbis_info_floor *i){
  98970. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  98971. if(info){
  98972. memset(info,0,sizeof(*info));
  98973. _ogg_free(info);
  98974. }
  98975. }
  98976. static void floor0_free_look(vorbis_look_floor *i){
  98977. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98978. if(look){
  98979. if(look->linearmap){
  98980. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  98981. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  98982. _ogg_free(look->linearmap);
  98983. }
  98984. memset(look,0,sizeof(*look));
  98985. _ogg_free(look);
  98986. }
  98987. }
  98988. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  98989. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98990. int j;
  98991. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  98992. info->order=oggpack_read(opb,8);
  98993. info->rate=oggpack_read(opb,16);
  98994. info->barkmap=oggpack_read(opb,16);
  98995. info->ampbits=oggpack_read(opb,6);
  98996. info->ampdB=oggpack_read(opb,8);
  98997. info->numbooks=oggpack_read(opb,4)+1;
  98998. if(info->order<1)goto err_out;
  98999. if(info->rate<1)goto err_out;
  99000. if(info->barkmap<1)goto err_out;
  99001. if(info->numbooks<1)goto err_out;
  99002. for(j=0;j<info->numbooks;j++){
  99003. info->books[j]=oggpack_read(opb,8);
  99004. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  99005. }
  99006. return(info);
  99007. err_out:
  99008. floor0_free_info(info);
  99009. return(NULL);
  99010. }
  99011. static void floor0_map_lazy_init(vorbis_block *vb,
  99012. vorbis_info_floor *infoX,
  99013. vorbis_look_floor0 *look){
  99014. if(!look->linearmap[vb->W]){
  99015. vorbis_dsp_state *vd=vb->vd;
  99016. vorbis_info *vi=vd->vi;
  99017. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99018. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99019. int W=vb->W;
  99020. int n=ci->blocksizes[W]/2,j;
  99021. float scale=look->ln/toBARK(info->rate/2.f);
  99022. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99023. for(j=0;j<n;j++){
  99024. int val=floor( toBARK((info->rate/2.f)/n*j)
  99025. *scale); /* bark numbers represent band edges */
  99026. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99027. look->linearmap[W][j]=val;
  99028. }
  99029. look->linearmap[W][j]=-1;
  99030. look->n[W]=n;
  99031. }
  99032. }
  99033. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99034. vorbis_info_floor *i){
  99035. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99036. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99037. look->m=info->order;
  99038. look->ln=info->barkmap;
  99039. look->vi=info;
  99040. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99041. return look;
  99042. }
  99043. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99044. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99045. vorbis_info_floor0 *info=look->vi;
  99046. int j,k;
  99047. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99048. if(ampraw>0){ /* also handles the -1 out of data case */
  99049. long maxval=(1<<info->ampbits)-1;
  99050. float amp=(float)ampraw/maxval*info->ampdB;
  99051. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99052. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99053. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99054. codebook *b=ci->fullbooks+info->books[booknum];
  99055. float last=0.f;
  99056. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99057. for(j=0;j<look->m;j+=b->dim)
  99058. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99059. for(j=0;j<look->m;){
  99060. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99061. last=lsp[j-1];
  99062. }
  99063. lsp[look->m]=amp;
  99064. return(lsp);
  99065. }
  99066. }
  99067. eop:
  99068. return(NULL);
  99069. }
  99070. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99071. void *memo,float *out){
  99072. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99073. vorbis_info_floor0 *info=look->vi;
  99074. floor0_map_lazy_init(vb,info,look);
  99075. if(memo){
  99076. float *lsp=(float *)memo;
  99077. float amp=lsp[look->m];
  99078. vorbis_lsp_to_curve(out,
  99079. look->linearmap[vb->W],
  99080. look->n[vb->W],
  99081. look->ln,
  99082. lsp,look->m,amp,(float)info->ampdB);
  99083. return(1);
  99084. }
  99085. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99086. return(0);
  99087. }
  99088. vorbis_func_floor floor0_exportbundle={
  99089. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99090. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99091. };
  99092. #endif
  99093. /*** End of inlined file: floor0.c ***/
  99094. /*** Start of inlined file: floor1.c ***/
  99095. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99096. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99097. // tasks..
  99098. #if JUCE_MSVC
  99099. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99100. #endif
  99101. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99102. #if JUCE_USE_OGGVORBIS
  99103. #include <stdlib.h>
  99104. #include <string.h>
  99105. #include <math.h>
  99106. #include <stdio.h>
  99107. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99108. typedef struct {
  99109. int sorted_index[VIF_POSIT+2];
  99110. int forward_index[VIF_POSIT+2];
  99111. int reverse_index[VIF_POSIT+2];
  99112. int hineighbor[VIF_POSIT];
  99113. int loneighbor[VIF_POSIT];
  99114. int posts;
  99115. int n;
  99116. int quant_q;
  99117. vorbis_info_floor1 *vi;
  99118. long phrasebits;
  99119. long postbits;
  99120. long frames;
  99121. } vorbis_look_floor1;
  99122. typedef struct lsfit_acc{
  99123. long x0;
  99124. long x1;
  99125. long xa;
  99126. long ya;
  99127. long x2a;
  99128. long y2a;
  99129. long xya;
  99130. long an;
  99131. } lsfit_acc;
  99132. static void floor1_free_info(vorbis_info_floor *i){
  99133. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99134. if(info){
  99135. memset(info,0,sizeof(*info));
  99136. _ogg_free(info);
  99137. }
  99138. }
  99139. static void floor1_free_look(vorbis_look_floor *i){
  99140. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99141. if(look){
  99142. memset(look,0,sizeof(*look));
  99143. _ogg_free(look);
  99144. }
  99145. }
  99146. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99147. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99148. int j,k;
  99149. int count=0;
  99150. int rangebits;
  99151. int maxposit=info->postlist[1];
  99152. int maxclass=-1;
  99153. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99154. for(j=0;j<info->partitions;j++){
  99155. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99156. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99157. }
  99158. for(j=0;j<maxclass+1;j++){
  99159. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99160. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99161. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99162. for(k=0;k<(1<<info->class_subs[j]);k++)
  99163. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99164. }
  99165. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99166. oggpack_write(opb,ilog2(maxposit),4);
  99167. rangebits=ilog2(maxposit);
  99168. for(j=0,k=0;j<info->partitions;j++){
  99169. count+=info->class_dim[info->partitionclass[j]];
  99170. for(;k<count;k++)
  99171. oggpack_write(opb,info->postlist[k+2],rangebits);
  99172. }
  99173. }
  99174. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99175. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99176. int j,k,count=0,maxclass=-1,rangebits;
  99177. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99178. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99179. for(j=0;j<info->partitions;j++){
  99180. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99181. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99182. }
  99183. for(j=0;j<maxclass+1;j++){
  99184. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99185. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99186. if(info->class_subs[j]<0)
  99187. goto err_out;
  99188. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99189. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99190. goto err_out;
  99191. for(k=0;k<(1<<info->class_subs[j]);k++){
  99192. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99193. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99194. goto err_out;
  99195. }
  99196. }
  99197. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99198. rangebits=oggpack_read(opb,4);
  99199. for(j=0,k=0;j<info->partitions;j++){
  99200. count+=info->class_dim[info->partitionclass[j]];
  99201. for(;k<count;k++){
  99202. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99203. if(t<0 || t>=(1<<rangebits))
  99204. goto err_out;
  99205. }
  99206. }
  99207. info->postlist[0]=0;
  99208. info->postlist[1]=1<<rangebits;
  99209. return(info);
  99210. err_out:
  99211. floor1_free_info(info);
  99212. return(NULL);
  99213. }
  99214. static int icomp(const void *a,const void *b){
  99215. return(**(int **)a-**(int **)b);
  99216. }
  99217. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99218. vorbis_info_floor *in){
  99219. int *sortpointer[VIF_POSIT+2];
  99220. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99221. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99222. int i,j,n=0;
  99223. look->vi=info;
  99224. look->n=info->postlist[1];
  99225. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99226. n+=2;
  99227. look->posts=n;
  99228. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99229. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99230. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99231. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99232. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99233. switch(info->mult){
  99234. case 1: /* 1024 -> 256 */
  99235. look->quant_q=256;
  99236. break;
  99237. case 2: /* 1024 -> 128 */
  99238. look->quant_q=128;
  99239. break;
  99240. case 3: /* 1024 -> 86 */
  99241. look->quant_q=86;
  99242. break;
  99243. case 4: /* 1024 -> 64 */
  99244. look->quant_q=64;
  99245. break;
  99246. }
  99247. for(i=0;i<n-2;i++){
  99248. int lo=0;
  99249. int hi=1;
  99250. int lx=0;
  99251. int hx=look->n;
  99252. int currentx=info->postlist[i+2];
  99253. for(j=0;j<i+2;j++){
  99254. int x=info->postlist[j];
  99255. if(x>lx && x<currentx){
  99256. lo=j;
  99257. lx=x;
  99258. }
  99259. if(x<hx && x>currentx){
  99260. hi=j;
  99261. hx=x;
  99262. }
  99263. }
  99264. look->loneighbor[i]=lo;
  99265. look->hineighbor[i]=hi;
  99266. }
  99267. return(look);
  99268. }
  99269. static int render_point(int x0,int x1,int y0,int y1,int x){
  99270. y0&=0x7fff; /* mask off flag */
  99271. y1&=0x7fff;
  99272. {
  99273. int dy=y1-y0;
  99274. int adx=x1-x0;
  99275. int ady=abs(dy);
  99276. int err=ady*(x-x0);
  99277. int off=err/adx;
  99278. if(dy<0)return(y0-off);
  99279. return(y0+off);
  99280. }
  99281. }
  99282. static int vorbis_dBquant(const float *x){
  99283. int i= *x*7.3142857f+1023.5f;
  99284. if(i>1023)return(1023);
  99285. if(i<0)return(0);
  99286. return i;
  99287. }
  99288. static float FLOOR1_fromdB_LOOKUP[256]={
  99289. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99290. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99291. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99292. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99293. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99294. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99295. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99296. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99297. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99298. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99299. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99300. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99301. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99302. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99303. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99304. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99305. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99306. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99307. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99308. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99309. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99310. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99311. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99312. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99313. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99314. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99315. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99316. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99317. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99318. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99319. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99320. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99321. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99322. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99323. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99324. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99325. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99326. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99327. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99328. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99329. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99330. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99331. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99332. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99333. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99334. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99335. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99336. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99337. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99338. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99339. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99340. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99341. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99342. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99343. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99344. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99345. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99346. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99347. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99348. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99349. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99350. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99351. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99352. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99353. };
  99354. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99355. int dy=y1-y0;
  99356. int adx=x1-x0;
  99357. int ady=abs(dy);
  99358. int base=dy/adx;
  99359. int sy=(dy<0?base-1:base+1);
  99360. int x=x0;
  99361. int y=y0;
  99362. int err=0;
  99363. ady-=abs(base*adx);
  99364. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99365. while(++x<x1){
  99366. err=err+ady;
  99367. if(err>=adx){
  99368. err-=adx;
  99369. y+=sy;
  99370. }else{
  99371. y+=base;
  99372. }
  99373. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99374. }
  99375. }
  99376. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99377. int dy=y1-y0;
  99378. int adx=x1-x0;
  99379. int ady=abs(dy);
  99380. int base=dy/adx;
  99381. int sy=(dy<0?base-1:base+1);
  99382. int x=x0;
  99383. int y=y0;
  99384. int err=0;
  99385. ady-=abs(base*adx);
  99386. d[x]=y;
  99387. while(++x<x1){
  99388. err=err+ady;
  99389. if(err>=adx){
  99390. err-=adx;
  99391. y+=sy;
  99392. }else{
  99393. y+=base;
  99394. }
  99395. d[x]=y;
  99396. }
  99397. }
  99398. static int accumulate_fit(const float *flr,const float *mdct,
  99399. int x0, int x1,lsfit_acc *a,
  99400. int n,vorbis_info_floor1 *info){
  99401. long i;
  99402. 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;
  99403. memset(a,0,sizeof(*a));
  99404. a->x0=x0;
  99405. a->x1=x1;
  99406. if(x1>=n)x1=n-1;
  99407. for(i=x0;i<=x1;i++){
  99408. int quantized=vorbis_dBquant(flr+i);
  99409. if(quantized){
  99410. if(mdct[i]+info->twofitatten>=flr[i]){
  99411. xa += i;
  99412. ya += quantized;
  99413. x2a += i*i;
  99414. y2a += quantized*quantized;
  99415. xya += i*quantized;
  99416. na++;
  99417. }else{
  99418. xb += i;
  99419. yb += quantized;
  99420. x2b += i*i;
  99421. y2b += quantized*quantized;
  99422. xyb += i*quantized;
  99423. nb++;
  99424. }
  99425. }
  99426. }
  99427. xb+=xa;
  99428. yb+=ya;
  99429. x2b+=x2a;
  99430. y2b+=y2a;
  99431. xyb+=xya;
  99432. nb+=na;
  99433. {
  99434. int weight=nb*info->twofitweight/(na+1);
  99435. a->xa=xa*weight+xb;
  99436. a->ya=ya*weight+yb;
  99437. a->x2a=x2a*weight+x2b;
  99438. a->y2a=y2a*weight+y2b;
  99439. a->xya=xya*weight+xyb;
  99440. a->an=na*weight+nb;
  99441. }
  99442. return(na);
  99443. }
  99444. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99445. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99446. long x0=a[0].x0;
  99447. long x1=a[fits-1].x1;
  99448. for(i=0;i<fits;i++){
  99449. x+=a[i].xa;
  99450. y+=a[i].ya;
  99451. x2+=a[i].x2a;
  99452. y2+=a[i].y2a;
  99453. xy+=a[i].xya;
  99454. an+=a[i].an;
  99455. }
  99456. if(*y0>=0){
  99457. x+= x0;
  99458. y+= *y0;
  99459. x2+= x0 * x0;
  99460. y2+= *y0 * *y0;
  99461. xy+= *y0 * x0;
  99462. an++;
  99463. }
  99464. if(*y1>=0){
  99465. x+= x1;
  99466. y+= *y1;
  99467. x2+= x1 * x1;
  99468. y2+= *y1 * *y1;
  99469. xy+= *y1 * x1;
  99470. an++;
  99471. }
  99472. if(an){
  99473. double fx=x;
  99474. double fy=y;
  99475. double fx2=x2;
  99476. double fxy=xy;
  99477. double denom=1./(an*fx2-fx*fx);
  99478. double a=(fy*fx2-fxy*fx)*denom;
  99479. double b=(an*fxy-fx*fy)*denom;
  99480. *y0=rint(a+b*x0);
  99481. *y1=rint(a+b*x1);
  99482. if(*y0>1023)*y0=1023;
  99483. if(*y1>1023)*y1=1023;
  99484. if(*y0<0)*y0=0;
  99485. if(*y1<0)*y1=0;
  99486. }else{
  99487. *y0=0;
  99488. *y1=0;
  99489. }
  99490. }
  99491. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99492. const float *mdct,
  99493. vorbis_info_floor1 *info){
  99494. int dy=y1-y0;
  99495. int adx=x1-x0;
  99496. int ady=abs(dy);
  99497. int base=dy/adx;
  99498. int sy=(dy<0?base-1:base+1);
  99499. int x=x0;
  99500. int y=y0;
  99501. int err=0;
  99502. int val=vorbis_dBquant(mask+x);
  99503. int mse=0;
  99504. int n=0;
  99505. ady-=abs(base*adx);
  99506. mse=(y-val);
  99507. mse*=mse;
  99508. n++;
  99509. if(mdct[x]+info->twofitatten>=mask[x]){
  99510. if(y+info->maxover<val)return(1);
  99511. if(y-info->maxunder>val)return(1);
  99512. }
  99513. while(++x<x1){
  99514. err=err+ady;
  99515. if(err>=adx){
  99516. err-=adx;
  99517. y+=sy;
  99518. }else{
  99519. y+=base;
  99520. }
  99521. val=vorbis_dBquant(mask+x);
  99522. mse+=((y-val)*(y-val));
  99523. n++;
  99524. if(mdct[x]+info->twofitatten>=mask[x]){
  99525. if(val){
  99526. if(y+info->maxover<val)return(1);
  99527. if(y-info->maxunder>val)return(1);
  99528. }
  99529. }
  99530. }
  99531. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99532. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99533. if(mse/n>info->maxerr)return(1);
  99534. return(0);
  99535. }
  99536. static int post_Y(int *A,int *B,int pos){
  99537. if(A[pos]<0)
  99538. return B[pos];
  99539. if(B[pos]<0)
  99540. return A[pos];
  99541. return (A[pos]+B[pos])>>1;
  99542. }
  99543. int *floor1_fit(vorbis_block *vb,void *look_,
  99544. const float *logmdct, /* in */
  99545. const float *logmask){
  99546. long i,j;
  99547. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  99548. vorbis_info_floor1 *info=look->vi;
  99549. long n=look->n;
  99550. long posts=look->posts;
  99551. long nonzero=0;
  99552. lsfit_acc fits[VIF_POSIT+1];
  99553. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  99554. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  99555. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  99556. int hineighbor[VIF_POSIT+2];
  99557. int *output=NULL;
  99558. int memo[VIF_POSIT+2];
  99559. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  99560. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  99561. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  99562. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  99563. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  99564. if(posts==0){
  99565. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  99566. }else{
  99567. for(i=0;i<posts-1;i++)
  99568. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  99569. look->sorted_index[i+1],fits+i,
  99570. n,info);
  99571. }
  99572. if(nonzero){
  99573. int y0=-200;
  99574. int y1=-200;
  99575. fit_line(fits,posts-1,&y0,&y1);
  99576. fit_valueA[0]=y0;
  99577. fit_valueB[0]=y0;
  99578. fit_valueB[1]=y1;
  99579. fit_valueA[1]=y1;
  99580. for(i=2;i<posts;i++){
  99581. int sortpos=look->reverse_index[i];
  99582. int ln=loneighbor[sortpos];
  99583. int hn=hineighbor[sortpos];
  99584. if(memo[ln]!=hn){
  99585. int lsortpos=look->reverse_index[ln];
  99586. int hsortpos=look->reverse_index[hn];
  99587. memo[ln]=hn;
  99588. {
  99589. int lx=info->postlist[ln];
  99590. int hx=info->postlist[hn];
  99591. int ly=post_Y(fit_valueA,fit_valueB,ln);
  99592. int hy=post_Y(fit_valueA,fit_valueB,hn);
  99593. if(ly==-1 || hy==-1){
  99594. exit(1);
  99595. }
  99596. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  99597. int ly0=-200;
  99598. int ly1=-200;
  99599. int hy0=-200;
  99600. int hy1=-200;
  99601. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  99602. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  99603. fit_valueB[ln]=ly0;
  99604. if(ln==0)fit_valueA[ln]=ly0;
  99605. fit_valueA[i]=ly1;
  99606. fit_valueB[i]=hy0;
  99607. fit_valueA[hn]=hy1;
  99608. if(hn==1)fit_valueB[hn]=hy1;
  99609. if(ly1>=0 || hy0>=0){
  99610. for(j=sortpos-1;j>=0;j--)
  99611. if(hineighbor[j]==hn)
  99612. hineighbor[j]=i;
  99613. else
  99614. break;
  99615. for(j=sortpos+1;j<posts;j++)
  99616. if(loneighbor[j]==ln)
  99617. loneighbor[j]=i;
  99618. else
  99619. break;
  99620. }
  99621. }else{
  99622. fit_valueA[i]=-200;
  99623. fit_valueB[i]=-200;
  99624. }
  99625. }
  99626. }
  99627. }
  99628. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99629. output[0]=post_Y(fit_valueA,fit_valueB,0);
  99630. output[1]=post_Y(fit_valueA,fit_valueB,1);
  99631. for(i=2;i<posts;i++){
  99632. int ln=look->loneighbor[i-2];
  99633. int hn=look->hineighbor[i-2];
  99634. int x0=info->postlist[ln];
  99635. int x1=info->postlist[hn];
  99636. int y0=output[ln];
  99637. int y1=output[hn];
  99638. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99639. int vx=post_Y(fit_valueA,fit_valueB,i);
  99640. if(vx>=0 && predicted!=vx){
  99641. output[i]=vx;
  99642. }else{
  99643. output[i]= predicted|0x8000;
  99644. }
  99645. }
  99646. }
  99647. return(output);
  99648. }
  99649. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  99650. int *A,int *B,
  99651. int del){
  99652. long i;
  99653. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  99654. long posts=look->posts;
  99655. int *output=NULL;
  99656. if(A && B){
  99657. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99658. for(i=0;i<posts;i++){
  99659. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  99660. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  99661. }
  99662. }
  99663. return(output);
  99664. }
  99665. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  99666. void*look_,
  99667. int *post,int *ilogmask){
  99668. long i,j;
  99669. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  99670. vorbis_info_floor1 *info=look->vi;
  99671. long posts=look->posts;
  99672. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99673. int out[VIF_POSIT+2];
  99674. static_codebook **sbooks=ci->book_param;
  99675. codebook *books=ci->fullbooks;
  99676. static long seq=0;
  99677. if(post){
  99678. for(i=0;i<posts;i++){
  99679. int val=post[i]&0x7fff;
  99680. switch(info->mult){
  99681. case 1: /* 1024 -> 256 */
  99682. val>>=2;
  99683. break;
  99684. case 2: /* 1024 -> 128 */
  99685. val>>=3;
  99686. break;
  99687. case 3: /* 1024 -> 86 */
  99688. val/=12;
  99689. break;
  99690. case 4: /* 1024 -> 64 */
  99691. val>>=4;
  99692. break;
  99693. }
  99694. post[i]=val | (post[i]&0x8000);
  99695. }
  99696. out[0]=post[0];
  99697. out[1]=post[1];
  99698. for(i=2;i<posts;i++){
  99699. int ln=look->loneighbor[i-2];
  99700. int hn=look->hineighbor[i-2];
  99701. int x0=info->postlist[ln];
  99702. int x1=info->postlist[hn];
  99703. int y0=post[ln];
  99704. int y1=post[hn];
  99705. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99706. if((post[i]&0x8000) || (predicted==post[i])){
  99707. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  99708. in interpolation */
  99709. out[i]=0;
  99710. }else{
  99711. int headroom=(look->quant_q-predicted<predicted?
  99712. look->quant_q-predicted:predicted);
  99713. int val=post[i]-predicted;
  99714. if(val<0)
  99715. if(val<-headroom)
  99716. val=headroom-val-1;
  99717. else
  99718. val=-1-(val<<1);
  99719. else
  99720. if(val>=headroom)
  99721. val= val+headroom;
  99722. else
  99723. val<<=1;
  99724. out[i]=val;
  99725. post[ln]&=0x7fff;
  99726. post[hn]&=0x7fff;
  99727. }
  99728. }
  99729. oggpack_write(opb,1,1);
  99730. look->frames++;
  99731. look->postbits+=ilog(look->quant_q-1)*2;
  99732. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  99733. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  99734. for(i=0,j=2;i<info->partitions;i++){
  99735. int classx=info->partitionclass[i];
  99736. int cdim=info->class_dim[classx];
  99737. int csubbits=info->class_subs[classx];
  99738. int csub=1<<csubbits;
  99739. int bookas[8]={0,0,0,0,0,0,0,0};
  99740. int cval=0;
  99741. int cshift=0;
  99742. int k,l;
  99743. if(csubbits){
  99744. int maxval[8];
  99745. for(k=0;k<csub;k++){
  99746. int booknum=info->class_subbook[classx][k];
  99747. if(booknum<0){
  99748. maxval[k]=1;
  99749. }else{
  99750. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  99751. }
  99752. }
  99753. for(k=0;k<cdim;k++){
  99754. for(l=0;l<csub;l++){
  99755. int val=out[j+k];
  99756. if(val<maxval[l]){
  99757. bookas[k]=l;
  99758. break;
  99759. }
  99760. }
  99761. cval|= bookas[k]<<cshift;
  99762. cshift+=csubbits;
  99763. }
  99764. look->phrasebits+=
  99765. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  99766. #ifdef TRAIN_FLOOR1
  99767. {
  99768. FILE *of;
  99769. char buffer[80];
  99770. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  99771. vb->pcmend/2,posts-2,class);
  99772. of=fopen(buffer,"a");
  99773. fprintf(of,"%d\n",cval);
  99774. fclose(of);
  99775. }
  99776. #endif
  99777. }
  99778. for(k=0;k<cdim;k++){
  99779. int book=info->class_subbook[classx][bookas[k]];
  99780. if(book>=0){
  99781. if(out[j+k]<(books+book)->entries)
  99782. look->postbits+=vorbis_book_encode(books+book,
  99783. out[j+k],opb);
  99784. #ifdef TRAIN_FLOOR1
  99785. {
  99786. FILE *of;
  99787. char buffer[80];
  99788. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  99789. vb->pcmend/2,posts-2,class,bookas[k]);
  99790. of=fopen(buffer,"a");
  99791. fprintf(of,"%d\n",out[j+k]);
  99792. fclose(of);
  99793. }
  99794. #endif
  99795. }
  99796. }
  99797. j+=cdim;
  99798. }
  99799. {
  99800. int hx=0;
  99801. int lx=0;
  99802. int ly=post[0]*info->mult;
  99803. for(j=1;j<look->posts;j++){
  99804. int current=look->forward_index[j];
  99805. int hy=post[current]&0x7fff;
  99806. if(hy==post[current]){
  99807. hy*=info->mult;
  99808. hx=info->postlist[current];
  99809. render_line0(lx,hx,ly,hy,ilogmask);
  99810. lx=hx;
  99811. ly=hy;
  99812. }
  99813. }
  99814. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  99815. seq++;
  99816. return(1);
  99817. }
  99818. }else{
  99819. oggpack_write(opb,0,1);
  99820. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  99821. seq++;
  99822. return(0);
  99823. }
  99824. }
  99825. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  99826. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99827. vorbis_info_floor1 *info=look->vi;
  99828. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99829. int i,j,k;
  99830. codebook *books=ci->fullbooks;
  99831. if(oggpack_read(&vb->opb,1)==1){
  99832. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  99833. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99834. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99835. for(i=0,j=2;i<info->partitions;i++){
  99836. int classx=info->partitionclass[i];
  99837. int cdim=info->class_dim[classx];
  99838. int csubbits=info->class_subs[classx];
  99839. int csub=1<<csubbits;
  99840. int cval=0;
  99841. if(csubbits){
  99842. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  99843. if(cval==-1)goto eop;
  99844. }
  99845. for(k=0;k<cdim;k++){
  99846. int book=info->class_subbook[classx][cval&(csub-1)];
  99847. cval>>=csubbits;
  99848. if(book>=0){
  99849. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  99850. goto eop;
  99851. }else{
  99852. fit_value[j+k]=0;
  99853. }
  99854. }
  99855. j+=cdim;
  99856. }
  99857. for(i=2;i<look->posts;i++){
  99858. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  99859. info->postlist[look->hineighbor[i-2]],
  99860. fit_value[look->loneighbor[i-2]],
  99861. fit_value[look->hineighbor[i-2]],
  99862. info->postlist[i]);
  99863. int hiroom=look->quant_q-predicted;
  99864. int loroom=predicted;
  99865. int room=(hiroom<loroom?hiroom:loroom)<<1;
  99866. int val=fit_value[i];
  99867. if(val){
  99868. if(val>=room){
  99869. if(hiroom>loroom){
  99870. val = val-loroom;
  99871. }else{
  99872. val = -1-(val-hiroom);
  99873. }
  99874. }else{
  99875. if(val&1){
  99876. val= -((val+1)>>1);
  99877. }else{
  99878. val>>=1;
  99879. }
  99880. }
  99881. fit_value[i]=val+predicted;
  99882. fit_value[look->loneighbor[i-2]]&=0x7fff;
  99883. fit_value[look->hineighbor[i-2]]&=0x7fff;
  99884. }else{
  99885. fit_value[i]=predicted|0x8000;
  99886. }
  99887. }
  99888. return(fit_value);
  99889. }
  99890. eop:
  99891. return(NULL);
  99892. }
  99893. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  99894. float *out){
  99895. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99896. vorbis_info_floor1 *info=look->vi;
  99897. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99898. int n=ci->blocksizes[vb->W]/2;
  99899. int j;
  99900. if(memo){
  99901. int *fit_value=(int *)memo;
  99902. int hx=0;
  99903. int lx=0;
  99904. int ly=fit_value[0]*info->mult;
  99905. for(j=1;j<look->posts;j++){
  99906. int current=look->forward_index[j];
  99907. int hy=fit_value[current]&0x7fff;
  99908. if(hy==fit_value[current]){
  99909. hy*=info->mult;
  99910. hx=info->postlist[current];
  99911. render_line(lx,hx,ly,hy,out);
  99912. lx=hx;
  99913. ly=hy;
  99914. }
  99915. }
  99916. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  99917. return(1);
  99918. }
  99919. memset(out,0,sizeof(*out)*n);
  99920. return(0);
  99921. }
  99922. vorbis_func_floor floor1_exportbundle={
  99923. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  99924. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  99925. };
  99926. #endif
  99927. /*** End of inlined file: floor1.c ***/
  99928. /*** Start of inlined file: info.c ***/
  99929. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99930. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99931. // tasks..
  99932. #if JUCE_MSVC
  99933. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99934. #endif
  99935. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99936. #if JUCE_USE_OGGVORBIS
  99937. #include <stdlib.h>
  99938. #include <string.h>
  99939. #include <ctype.h>
  99940. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  99941. while(bytes--){
  99942. oggpack_write(o,*s++,8);
  99943. }
  99944. }
  99945. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  99946. while(bytes--){
  99947. *buf++=oggpack_read(o,8);
  99948. }
  99949. }
  99950. void vorbis_comment_init(vorbis_comment *vc){
  99951. memset(vc,0,sizeof(*vc));
  99952. }
  99953. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  99954. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  99955. (vc->comments+2)*sizeof(*vc->user_comments));
  99956. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  99957. (vc->comments+2)*sizeof(*vc->comment_lengths));
  99958. vc->comment_lengths[vc->comments]=strlen(comment);
  99959. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  99960. strcpy(vc->user_comments[vc->comments], comment);
  99961. vc->comments++;
  99962. vc->user_comments[vc->comments]=NULL;
  99963. }
  99964. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  99965. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  99966. strcpy(comment, tag);
  99967. strcat(comment, "=");
  99968. strcat(comment, contents);
  99969. vorbis_comment_add(vc, comment);
  99970. }
  99971. static int tagcompare(const char *s1, const char *s2, int n){
  99972. int c=0;
  99973. while(c < n){
  99974. if(toupper(s1[c]) != toupper(s2[c]))
  99975. return !0;
  99976. c++;
  99977. }
  99978. return 0;
  99979. }
  99980. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  99981. long i;
  99982. int found = 0;
  99983. int taglen = strlen(tag)+1; /* +1 for the = we append */
  99984. char *fulltag = (char*)alloca(taglen+ 1);
  99985. strcpy(fulltag, tag);
  99986. strcat(fulltag, "=");
  99987. for(i=0;i<vc->comments;i++){
  99988. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  99989. if(count == found)
  99990. return vc->user_comments[i] + taglen;
  99991. else
  99992. found++;
  99993. }
  99994. }
  99995. return NULL; /* didn't find anything */
  99996. }
  99997. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  99998. int i,count=0;
  99999. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100000. char *fulltag = (char*)alloca(taglen+1);
  100001. strcpy(fulltag,tag);
  100002. strcat(fulltag, "=");
  100003. for(i=0;i<vc->comments;i++){
  100004. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  100005. count++;
  100006. }
  100007. return count;
  100008. }
  100009. void vorbis_comment_clear(vorbis_comment *vc){
  100010. if(vc){
  100011. long i;
  100012. for(i=0;i<vc->comments;i++)
  100013. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100014. if(vc->user_comments)_ogg_free(vc->user_comments);
  100015. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100016. if(vc->vendor)_ogg_free(vc->vendor);
  100017. }
  100018. memset(vc,0,sizeof(*vc));
  100019. }
  100020. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100021. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100022. return ci ? ci->blocksizes[zo] : -1;
  100023. }
  100024. void vorbis_info_init(vorbis_info *vi){
  100025. memset(vi,0,sizeof(*vi));
  100026. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100027. }
  100028. void vorbis_info_clear(vorbis_info *vi){
  100029. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100030. int i;
  100031. if(ci){
  100032. for(i=0;i<ci->modes;i++)
  100033. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100034. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100035. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100036. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100037. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100038. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100039. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100040. for(i=0;i<ci->books;i++){
  100041. if(ci->book_param[i]){
  100042. vorbis_staticbook_destroy(ci->book_param[i]);
  100043. }
  100044. if(ci->fullbooks)
  100045. vorbis_book_clear(ci->fullbooks+i);
  100046. }
  100047. if(ci->fullbooks)
  100048. _ogg_free(ci->fullbooks);
  100049. for(i=0;i<ci->psys;i++)
  100050. _vi_psy_free(ci->psy_param[i]);
  100051. _ogg_free(ci);
  100052. }
  100053. memset(vi,0,sizeof(*vi));
  100054. }
  100055. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100056. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100057. if(!ci)return(OV_EFAULT);
  100058. vi->version=oggpack_read(opb,32);
  100059. if(vi->version!=0)return(OV_EVERSION);
  100060. vi->channels=oggpack_read(opb,8);
  100061. vi->rate=oggpack_read(opb,32);
  100062. vi->bitrate_upper=oggpack_read(opb,32);
  100063. vi->bitrate_nominal=oggpack_read(opb,32);
  100064. vi->bitrate_lower=oggpack_read(opb,32);
  100065. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100066. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100067. if(vi->rate<1)goto err_out;
  100068. if(vi->channels<1)goto err_out;
  100069. if(ci->blocksizes[0]<8)goto err_out;
  100070. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100071. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100072. return(0);
  100073. err_out:
  100074. vorbis_info_clear(vi);
  100075. return(OV_EBADHEADER);
  100076. }
  100077. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100078. int i;
  100079. int vendorlen=oggpack_read(opb,32);
  100080. if(vendorlen<0)goto err_out;
  100081. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100082. _v_readstring(opb,vc->vendor,vendorlen);
  100083. vc->comments=oggpack_read(opb,32);
  100084. if(vc->comments<0)goto err_out;
  100085. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100086. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100087. for(i=0;i<vc->comments;i++){
  100088. int len=oggpack_read(opb,32);
  100089. if(len<0)goto err_out;
  100090. vc->comment_lengths[i]=len;
  100091. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100092. _v_readstring(opb,vc->user_comments[i],len);
  100093. }
  100094. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100095. return(0);
  100096. err_out:
  100097. vorbis_comment_clear(vc);
  100098. return(OV_EBADHEADER);
  100099. }
  100100. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100101. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100102. int i;
  100103. if(!ci)return(OV_EFAULT);
  100104. ci->books=oggpack_read(opb,8)+1;
  100105. for(i=0;i<ci->books;i++){
  100106. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100107. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100108. }
  100109. {
  100110. int times=oggpack_read(opb,6)+1;
  100111. for(i=0;i<times;i++){
  100112. int test=oggpack_read(opb,16);
  100113. if(test<0 || test>=VI_TIMEB)goto err_out;
  100114. }
  100115. }
  100116. ci->floors=oggpack_read(opb,6)+1;
  100117. for(i=0;i<ci->floors;i++){
  100118. ci->floor_type[i]=oggpack_read(opb,16);
  100119. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100120. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100121. if(!ci->floor_param[i])goto err_out;
  100122. }
  100123. ci->residues=oggpack_read(opb,6)+1;
  100124. for(i=0;i<ci->residues;i++){
  100125. ci->residue_type[i]=oggpack_read(opb,16);
  100126. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100127. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100128. if(!ci->residue_param[i])goto err_out;
  100129. }
  100130. ci->maps=oggpack_read(opb,6)+1;
  100131. for(i=0;i<ci->maps;i++){
  100132. ci->map_type[i]=oggpack_read(opb,16);
  100133. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100134. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100135. if(!ci->map_param[i])goto err_out;
  100136. }
  100137. ci->modes=oggpack_read(opb,6)+1;
  100138. for(i=0;i<ci->modes;i++){
  100139. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100140. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100141. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100142. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100143. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100144. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100145. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100146. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100147. }
  100148. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100149. return(0);
  100150. err_out:
  100151. vorbis_info_clear(vi);
  100152. return(OV_EBADHEADER);
  100153. }
  100154. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100155. oggpack_buffer opb;
  100156. if(op){
  100157. oggpack_readinit(&opb,op->packet,op->bytes);
  100158. {
  100159. char buffer[6];
  100160. int packtype=oggpack_read(&opb,8);
  100161. memset(buffer,0,6);
  100162. _v_readstring(&opb,buffer,6);
  100163. if(memcmp(buffer,"vorbis",6)){
  100164. return(OV_ENOTVORBIS);
  100165. }
  100166. switch(packtype){
  100167. case 0x01: /* least significant *bit* is read first */
  100168. if(!op->b_o_s){
  100169. return(OV_EBADHEADER);
  100170. }
  100171. if(vi->rate!=0){
  100172. return(OV_EBADHEADER);
  100173. }
  100174. return(_vorbis_unpack_info(vi,&opb));
  100175. case 0x03: /* least significant *bit* is read first */
  100176. if(vi->rate==0){
  100177. return(OV_EBADHEADER);
  100178. }
  100179. return(_vorbis_unpack_comment(vc,&opb));
  100180. case 0x05: /* least significant *bit* is read first */
  100181. if(vi->rate==0 || vc->vendor==NULL){
  100182. return(OV_EBADHEADER);
  100183. }
  100184. return(_vorbis_unpack_books(vi,&opb));
  100185. default:
  100186. return(OV_EBADHEADER);
  100187. break;
  100188. }
  100189. }
  100190. }
  100191. return(OV_EBADHEADER);
  100192. }
  100193. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100194. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100195. if(!ci)return(OV_EFAULT);
  100196. oggpack_write(opb,0x01,8);
  100197. _v_writestring(opb,"vorbis", 6);
  100198. oggpack_write(opb,0x00,32);
  100199. oggpack_write(opb,vi->channels,8);
  100200. oggpack_write(opb,vi->rate,32);
  100201. oggpack_write(opb,vi->bitrate_upper,32);
  100202. oggpack_write(opb,vi->bitrate_nominal,32);
  100203. oggpack_write(opb,vi->bitrate_lower,32);
  100204. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100205. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100206. oggpack_write(opb,1,1);
  100207. return(0);
  100208. }
  100209. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100210. char temp[]="Xiph.Org libVorbis I 20050304";
  100211. int bytes = strlen(temp);
  100212. oggpack_write(opb,0x03,8);
  100213. _v_writestring(opb,"vorbis", 6);
  100214. oggpack_write(opb,bytes,32);
  100215. _v_writestring(opb,temp, bytes);
  100216. oggpack_write(opb,vc->comments,32);
  100217. if(vc->comments){
  100218. int i;
  100219. for(i=0;i<vc->comments;i++){
  100220. if(vc->user_comments[i]){
  100221. oggpack_write(opb,vc->comment_lengths[i],32);
  100222. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100223. }else{
  100224. oggpack_write(opb,0,32);
  100225. }
  100226. }
  100227. }
  100228. oggpack_write(opb,1,1);
  100229. return(0);
  100230. }
  100231. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100232. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100233. int i;
  100234. if(!ci)return(OV_EFAULT);
  100235. oggpack_write(opb,0x05,8);
  100236. _v_writestring(opb,"vorbis", 6);
  100237. oggpack_write(opb,ci->books-1,8);
  100238. for(i=0;i<ci->books;i++)
  100239. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100240. oggpack_write(opb,0,6);
  100241. oggpack_write(opb,0,16);
  100242. oggpack_write(opb,ci->floors-1,6);
  100243. for(i=0;i<ci->floors;i++){
  100244. oggpack_write(opb,ci->floor_type[i],16);
  100245. if(_floor_P[ci->floor_type[i]]->pack)
  100246. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100247. else
  100248. goto err_out;
  100249. }
  100250. oggpack_write(opb,ci->residues-1,6);
  100251. for(i=0;i<ci->residues;i++){
  100252. oggpack_write(opb,ci->residue_type[i],16);
  100253. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100254. }
  100255. oggpack_write(opb,ci->maps-1,6);
  100256. for(i=0;i<ci->maps;i++){
  100257. oggpack_write(opb,ci->map_type[i],16);
  100258. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100259. }
  100260. oggpack_write(opb,ci->modes-1,6);
  100261. for(i=0;i<ci->modes;i++){
  100262. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100263. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100264. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100265. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100266. }
  100267. oggpack_write(opb,1,1);
  100268. return(0);
  100269. err_out:
  100270. return(-1);
  100271. }
  100272. int vorbis_commentheader_out(vorbis_comment *vc,
  100273. ogg_packet *op){
  100274. oggpack_buffer opb;
  100275. oggpack_writeinit(&opb);
  100276. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100277. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100278. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100279. op->bytes=oggpack_bytes(&opb);
  100280. op->b_o_s=0;
  100281. op->e_o_s=0;
  100282. op->granulepos=0;
  100283. op->packetno=1;
  100284. return 0;
  100285. }
  100286. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100287. vorbis_comment *vc,
  100288. ogg_packet *op,
  100289. ogg_packet *op_comm,
  100290. ogg_packet *op_code){
  100291. int ret=OV_EIMPL;
  100292. vorbis_info *vi=v->vi;
  100293. oggpack_buffer opb;
  100294. private_state *b=(private_state*)v->backend_state;
  100295. if(!b){
  100296. ret=OV_EFAULT;
  100297. goto err_out;
  100298. }
  100299. oggpack_writeinit(&opb);
  100300. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100301. if(b->header)_ogg_free(b->header);
  100302. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100303. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100304. op->packet=b->header;
  100305. op->bytes=oggpack_bytes(&opb);
  100306. op->b_o_s=1;
  100307. op->e_o_s=0;
  100308. op->granulepos=0;
  100309. op->packetno=0;
  100310. oggpack_reset(&opb);
  100311. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100312. if(b->header1)_ogg_free(b->header1);
  100313. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100314. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100315. op_comm->packet=b->header1;
  100316. op_comm->bytes=oggpack_bytes(&opb);
  100317. op_comm->b_o_s=0;
  100318. op_comm->e_o_s=0;
  100319. op_comm->granulepos=0;
  100320. op_comm->packetno=1;
  100321. oggpack_reset(&opb);
  100322. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100323. if(b->header2)_ogg_free(b->header2);
  100324. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100325. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100326. op_code->packet=b->header2;
  100327. op_code->bytes=oggpack_bytes(&opb);
  100328. op_code->b_o_s=0;
  100329. op_code->e_o_s=0;
  100330. op_code->granulepos=0;
  100331. op_code->packetno=2;
  100332. oggpack_writeclear(&opb);
  100333. return(0);
  100334. err_out:
  100335. oggpack_writeclear(&opb);
  100336. memset(op,0,sizeof(*op));
  100337. memset(op_comm,0,sizeof(*op_comm));
  100338. memset(op_code,0,sizeof(*op_code));
  100339. if(b->header)_ogg_free(b->header);
  100340. if(b->header1)_ogg_free(b->header1);
  100341. if(b->header2)_ogg_free(b->header2);
  100342. b->header=NULL;
  100343. b->header1=NULL;
  100344. b->header2=NULL;
  100345. return(ret);
  100346. }
  100347. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100348. if(granulepos>=0)
  100349. return((double)granulepos/v->vi->rate);
  100350. return(-1);
  100351. }
  100352. #endif
  100353. /*** End of inlined file: info.c ***/
  100354. /*** Start of inlined file: lpc.c ***/
  100355. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100356. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100357. // tasks..
  100358. #if JUCE_MSVC
  100359. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100360. #endif
  100361. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100362. #if JUCE_USE_OGGVORBIS
  100363. #include <stdlib.h>
  100364. #include <string.h>
  100365. #include <math.h>
  100366. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100367. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100368. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100369. double error;
  100370. int i,j;
  100371. j=m+1;
  100372. while(j--){
  100373. double d=0; /* double needed for accumulator depth */
  100374. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100375. aut[j]=d;
  100376. }
  100377. error=aut[0];
  100378. for(i=0;i<m;i++){
  100379. double r= -aut[i+1];
  100380. if(error==0){
  100381. memset(lpci,0,m*sizeof(*lpci));
  100382. return 0;
  100383. }
  100384. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100385. r/=error;
  100386. lpc[i]=r;
  100387. for(j=0;j<i/2;j++){
  100388. double tmp=lpc[j];
  100389. lpc[j]+=r*lpc[i-1-j];
  100390. lpc[i-1-j]+=r*tmp;
  100391. }
  100392. if(i%2)lpc[j]+=lpc[j]*r;
  100393. error*=1.f-r*r;
  100394. }
  100395. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100396. return error;
  100397. }
  100398. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100399. float *data,long n){
  100400. long i,j,o,p;
  100401. float y;
  100402. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100403. if(!prime)
  100404. for(i=0;i<m;i++)
  100405. work[i]=0.f;
  100406. else
  100407. for(i=0;i<m;i++)
  100408. work[i]=prime[i];
  100409. for(i=0;i<n;i++){
  100410. y=0;
  100411. o=i;
  100412. p=m;
  100413. for(j=0;j<m;j++)
  100414. y-=work[o++]*coeff[--p];
  100415. data[i]=work[o]=y;
  100416. }
  100417. }
  100418. #endif
  100419. /*** End of inlined file: lpc.c ***/
  100420. /*** Start of inlined file: lsp.c ***/
  100421. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100422. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100423. // tasks..
  100424. #if JUCE_MSVC
  100425. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100426. #endif
  100427. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100428. #if JUCE_USE_OGGVORBIS
  100429. #include <math.h>
  100430. #include <string.h>
  100431. #include <stdlib.h>
  100432. /*** Start of inlined file: lookup.h ***/
  100433. #ifndef _V_LOOKUP_H_
  100434. #ifdef FLOAT_LOOKUP
  100435. extern float vorbis_coslook(float a);
  100436. extern float vorbis_invsqlook(float a);
  100437. extern float vorbis_invsq2explook(int a);
  100438. extern float vorbis_fromdBlook(float a);
  100439. #endif
  100440. #ifdef INT_LOOKUP
  100441. extern long vorbis_invsqlook_i(long a,long e);
  100442. extern long vorbis_coslook_i(long a);
  100443. extern float vorbis_fromdBlook_i(long a);
  100444. #endif
  100445. #endif
  100446. /*** End of inlined file: lookup.h ***/
  100447. #define FLOAT_LOOKUP
  100448. #undef INT_LOOKUP
  100449. #ifdef FLOAT_LOOKUP
  100450. /*** Start of inlined file: lookup.c ***/
  100451. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100452. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100453. // tasks..
  100454. #if JUCE_MSVC
  100455. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100456. #endif
  100457. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100458. #if JUCE_USE_OGGVORBIS
  100459. #include <math.h>
  100460. /*** Start of inlined file: lookup.h ***/
  100461. #ifndef _V_LOOKUP_H_
  100462. #ifdef FLOAT_LOOKUP
  100463. extern float vorbis_coslook(float a);
  100464. extern float vorbis_invsqlook(float a);
  100465. extern float vorbis_invsq2explook(int a);
  100466. extern float vorbis_fromdBlook(float a);
  100467. #endif
  100468. #ifdef INT_LOOKUP
  100469. extern long vorbis_invsqlook_i(long a,long e);
  100470. extern long vorbis_coslook_i(long a);
  100471. extern float vorbis_fromdBlook_i(long a);
  100472. #endif
  100473. #endif
  100474. /*** End of inlined file: lookup.h ***/
  100475. /*** Start of inlined file: lookup_data.h ***/
  100476. #ifndef _V_LOOKUP_DATA_H_
  100477. #ifdef FLOAT_LOOKUP
  100478. #define COS_LOOKUP_SZ 128
  100479. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100480. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100481. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100482. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100483. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100484. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100485. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100486. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100487. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100488. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100489. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100490. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100491. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100492. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100493. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100494. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100495. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100496. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100497. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100498. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100499. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100500. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100501. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100502. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100503. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100504. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100505. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100506. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100507. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100508. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100509. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100510. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100511. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100512. -1.0000000000000f,
  100513. };
  100514. #define INVSQ_LOOKUP_SZ 32
  100515. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100516. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100517. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100518. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100519. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100520. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100521. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100522. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100523. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100524. 1.000000000000f,
  100525. };
  100526. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100527. #define INVSQ2EXP_LOOKUP_MAX 32
  100528. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100529. INVSQ2EXP_LOOKUP_MIN+1]={
  100530. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100531. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100532. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100533. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100534. 256.f, 181.019336f, 128.f, 90.50966799f,
  100535. 64.f, 45.254834f, 32.f, 22.627417f,
  100536. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100537. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100538. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100539. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100540. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100541. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100542. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100543. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100544. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100545. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100546. 1.525878906e-05f,
  100547. };
  100548. #endif
  100549. #define FROMdB_LOOKUP_SZ 35
  100550. #define FROMdB2_LOOKUP_SZ 32
  100551. #define FROMdB_SHIFT 5
  100552. #define FROMdB2_SHIFT 3
  100553. #define FROMdB2_MASK 31
  100554. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100555. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100556. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100557. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100558. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100559. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100560. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100561. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100562. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100563. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100564. };
  100565. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100566. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100567. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100568. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100569. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100570. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100571. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100572. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100573. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100574. };
  100575. #ifdef INT_LOOKUP
  100576. #define INVSQ_LOOKUP_I_SHIFT 10
  100577. #define INVSQ_LOOKUP_I_MASK 1023
  100578. static long INVSQ_LOOKUP_I[64+1]={
  100579. 92682l, 91966l, 91267l, 90583l,
  100580. 89915l, 89261l, 88621l, 87995l,
  100581. 87381l, 86781l, 86192l, 85616l,
  100582. 85051l, 84497l, 83953l, 83420l,
  100583. 82897l, 82384l, 81880l, 81385l,
  100584. 80899l, 80422l, 79953l, 79492l,
  100585. 79039l, 78594l, 78156l, 77726l,
  100586. 77302l, 76885l, 76475l, 76072l,
  100587. 75674l, 75283l, 74898l, 74519l,
  100588. 74146l, 73778l, 73415l, 73058l,
  100589. 72706l, 72359l, 72016l, 71679l,
  100590. 71347l, 71019l, 70695l, 70376l,
  100591. 70061l, 69750l, 69444l, 69141l,
  100592. 68842l, 68548l, 68256l, 67969l,
  100593. 67685l, 67405l, 67128l, 66855l,
  100594. 66585l, 66318l, 66054l, 65794l,
  100595. 65536l,
  100596. };
  100597. #define COS_LOOKUP_I_SHIFT 9
  100598. #define COS_LOOKUP_I_MASK 511
  100599. #define COS_LOOKUP_I_SZ 128
  100600. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100601. 16384l, 16379l, 16364l, 16340l,
  100602. 16305l, 16261l, 16207l, 16143l,
  100603. 16069l, 15986l, 15893l, 15791l,
  100604. 15679l, 15557l, 15426l, 15286l,
  100605. 15137l, 14978l, 14811l, 14635l,
  100606. 14449l, 14256l, 14053l, 13842l,
  100607. 13623l, 13395l, 13160l, 12916l,
  100608. 12665l, 12406l, 12140l, 11866l,
  100609. 11585l, 11297l, 11003l, 10702l,
  100610. 10394l, 10080l, 9760l, 9434l,
  100611. 9102l, 8765l, 8423l, 8076l,
  100612. 7723l, 7366l, 7005l, 6639l,
  100613. 6270l, 5897l, 5520l, 5139l,
  100614. 4756l, 4370l, 3981l, 3590l,
  100615. 3196l, 2801l, 2404l, 2006l,
  100616. 1606l, 1205l, 804l, 402l,
  100617. 0l, -401l, -803l, -1204l,
  100618. -1605l, -2005l, -2403l, -2800l,
  100619. -3195l, -3589l, -3980l, -4369l,
  100620. -4755l, -5138l, -5519l, -5896l,
  100621. -6269l, -6638l, -7004l, -7365l,
  100622. -7722l, -8075l, -8422l, -8764l,
  100623. -9101l, -9433l, -9759l, -10079l,
  100624. -10393l, -10701l, -11002l, -11296l,
  100625. -11584l, -11865l, -12139l, -12405l,
  100626. -12664l, -12915l, -13159l, -13394l,
  100627. -13622l, -13841l, -14052l, -14255l,
  100628. -14448l, -14634l, -14810l, -14977l,
  100629. -15136l, -15285l, -15425l, -15556l,
  100630. -15678l, -15790l, -15892l, -15985l,
  100631. -16068l, -16142l, -16206l, -16260l,
  100632. -16304l, -16339l, -16363l, -16378l,
  100633. -16383l,
  100634. };
  100635. #endif
  100636. #endif
  100637. /*** End of inlined file: lookup_data.h ***/
  100638. #ifdef FLOAT_LOOKUP
  100639. float vorbis_coslook(float a){
  100640. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100641. int i=vorbis_ftoi(d-.5);
  100642. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100643. }
  100644. float vorbis_invsqlook(float a){
  100645. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100646. int i=vorbis_ftoi(d-.5f);
  100647. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100648. }
  100649. float vorbis_invsq2explook(int a){
  100650. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100651. }
  100652. #include <stdio.h>
  100653. float vorbis_fromdBlook(float a){
  100654. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100655. return (i<0)?1.f:
  100656. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100657. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100658. }
  100659. #endif
  100660. #ifdef INT_LOOKUP
  100661. long vorbis_invsqlook_i(long a,long e){
  100662. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100663. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100664. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100665. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100666. d)>>16); /* result 1.16 */
  100667. e+=32;
  100668. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100669. e=(e>>1)-8;
  100670. return(val>>e);
  100671. }
  100672. float vorbis_fromdBlook_i(long a){
  100673. int i=(-a)>>(12-FROMdB2_SHIFT);
  100674. return (i<0)?1.f:
  100675. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100676. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100677. }
  100678. long vorbis_coslook_i(long a){
  100679. int i=a>>COS_LOOKUP_I_SHIFT;
  100680. int d=a&COS_LOOKUP_I_MASK;
  100681. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100682. COS_LOOKUP_I_SHIFT);
  100683. }
  100684. #endif
  100685. #endif
  100686. /*** End of inlined file: lookup.c ***/
  100687. /* catch this in the build system; we #include for
  100688. compilers (like gcc) that can't inline across
  100689. modules */
  100690. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100691. float amp,float ampoffset){
  100692. int i;
  100693. float wdel=M_PI/ln;
  100694. vorbis_fpu_control fpu;
  100695. (void) fpu; // to avoid an unused variable warning
  100696. vorbis_fpu_setround(&fpu);
  100697. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  100698. i=0;
  100699. while(i<n){
  100700. int k=map[i];
  100701. int qexp;
  100702. float p=.7071067812f;
  100703. float q=.7071067812f;
  100704. float w=vorbis_coslook(wdel*k);
  100705. float *ftmp=lsp;
  100706. int c=m>>1;
  100707. do{
  100708. q*=ftmp[0]-w;
  100709. p*=ftmp[1]-w;
  100710. ftmp+=2;
  100711. }while(--c);
  100712. if(m&1){
  100713. q*=ftmp[0]-w;
  100714. q*=q;
  100715. p*=p*(1.f-w*w);
  100716. }else{
  100717. q*=q*(1.f+w);
  100718. p*=p*(1.f-w);
  100719. }
  100720. q=frexp(p+q,&qexp);
  100721. q=vorbis_fromdBlook(amp*
  100722. vorbis_invsqlook(q)*
  100723. vorbis_invsq2explook(qexp+m)-
  100724. ampoffset);
  100725. do{
  100726. curve[i++]*=q;
  100727. }while(map[i]==k);
  100728. }
  100729. vorbis_fpu_restore(fpu);
  100730. }
  100731. #else
  100732. #ifdef INT_LOOKUP
  100733. /*** Start of inlined file: lookup.c ***/
  100734. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100735. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100736. // tasks..
  100737. #if JUCE_MSVC
  100738. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100739. #endif
  100740. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100741. #if JUCE_USE_OGGVORBIS
  100742. #include <math.h>
  100743. /*** Start of inlined file: lookup.h ***/
  100744. #ifndef _V_LOOKUP_H_
  100745. #ifdef FLOAT_LOOKUP
  100746. extern float vorbis_coslook(float a);
  100747. extern float vorbis_invsqlook(float a);
  100748. extern float vorbis_invsq2explook(int a);
  100749. extern float vorbis_fromdBlook(float a);
  100750. #endif
  100751. #ifdef INT_LOOKUP
  100752. extern long vorbis_invsqlook_i(long a,long e);
  100753. extern long vorbis_coslook_i(long a);
  100754. extern float vorbis_fromdBlook_i(long a);
  100755. #endif
  100756. #endif
  100757. /*** End of inlined file: lookup.h ***/
  100758. /*** Start of inlined file: lookup_data.h ***/
  100759. #ifndef _V_LOOKUP_DATA_H_
  100760. #ifdef FLOAT_LOOKUP
  100761. #define COS_LOOKUP_SZ 128
  100762. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100763. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100764. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100765. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100766. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100767. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100768. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100769. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100770. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100771. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100772. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100773. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100774. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100775. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100776. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100777. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100778. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100779. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100780. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100781. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100782. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100783. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100784. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100785. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100786. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100787. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100788. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100789. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100790. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100791. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100792. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100793. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100794. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100795. -1.0000000000000f,
  100796. };
  100797. #define INVSQ_LOOKUP_SZ 32
  100798. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100799. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100800. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100801. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100802. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100803. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100804. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100805. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100806. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100807. 1.000000000000f,
  100808. };
  100809. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100810. #define INVSQ2EXP_LOOKUP_MAX 32
  100811. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100812. INVSQ2EXP_LOOKUP_MIN+1]={
  100813. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100814. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100815. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100816. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100817. 256.f, 181.019336f, 128.f, 90.50966799f,
  100818. 64.f, 45.254834f, 32.f, 22.627417f,
  100819. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100820. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100821. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100822. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100823. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100824. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100825. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100826. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100827. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100828. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100829. 1.525878906e-05f,
  100830. };
  100831. #endif
  100832. #define FROMdB_LOOKUP_SZ 35
  100833. #define FROMdB2_LOOKUP_SZ 32
  100834. #define FROMdB_SHIFT 5
  100835. #define FROMdB2_SHIFT 3
  100836. #define FROMdB2_MASK 31
  100837. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100838. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100839. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100840. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100841. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100842. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100843. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100844. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100845. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100846. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100847. };
  100848. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100849. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100850. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100851. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100852. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100853. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100854. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100855. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100856. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100857. };
  100858. #ifdef INT_LOOKUP
  100859. #define INVSQ_LOOKUP_I_SHIFT 10
  100860. #define INVSQ_LOOKUP_I_MASK 1023
  100861. static long INVSQ_LOOKUP_I[64+1]={
  100862. 92682l, 91966l, 91267l, 90583l,
  100863. 89915l, 89261l, 88621l, 87995l,
  100864. 87381l, 86781l, 86192l, 85616l,
  100865. 85051l, 84497l, 83953l, 83420l,
  100866. 82897l, 82384l, 81880l, 81385l,
  100867. 80899l, 80422l, 79953l, 79492l,
  100868. 79039l, 78594l, 78156l, 77726l,
  100869. 77302l, 76885l, 76475l, 76072l,
  100870. 75674l, 75283l, 74898l, 74519l,
  100871. 74146l, 73778l, 73415l, 73058l,
  100872. 72706l, 72359l, 72016l, 71679l,
  100873. 71347l, 71019l, 70695l, 70376l,
  100874. 70061l, 69750l, 69444l, 69141l,
  100875. 68842l, 68548l, 68256l, 67969l,
  100876. 67685l, 67405l, 67128l, 66855l,
  100877. 66585l, 66318l, 66054l, 65794l,
  100878. 65536l,
  100879. };
  100880. #define COS_LOOKUP_I_SHIFT 9
  100881. #define COS_LOOKUP_I_MASK 511
  100882. #define COS_LOOKUP_I_SZ 128
  100883. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100884. 16384l, 16379l, 16364l, 16340l,
  100885. 16305l, 16261l, 16207l, 16143l,
  100886. 16069l, 15986l, 15893l, 15791l,
  100887. 15679l, 15557l, 15426l, 15286l,
  100888. 15137l, 14978l, 14811l, 14635l,
  100889. 14449l, 14256l, 14053l, 13842l,
  100890. 13623l, 13395l, 13160l, 12916l,
  100891. 12665l, 12406l, 12140l, 11866l,
  100892. 11585l, 11297l, 11003l, 10702l,
  100893. 10394l, 10080l, 9760l, 9434l,
  100894. 9102l, 8765l, 8423l, 8076l,
  100895. 7723l, 7366l, 7005l, 6639l,
  100896. 6270l, 5897l, 5520l, 5139l,
  100897. 4756l, 4370l, 3981l, 3590l,
  100898. 3196l, 2801l, 2404l, 2006l,
  100899. 1606l, 1205l, 804l, 402l,
  100900. 0l, -401l, -803l, -1204l,
  100901. -1605l, -2005l, -2403l, -2800l,
  100902. -3195l, -3589l, -3980l, -4369l,
  100903. -4755l, -5138l, -5519l, -5896l,
  100904. -6269l, -6638l, -7004l, -7365l,
  100905. -7722l, -8075l, -8422l, -8764l,
  100906. -9101l, -9433l, -9759l, -10079l,
  100907. -10393l, -10701l, -11002l, -11296l,
  100908. -11584l, -11865l, -12139l, -12405l,
  100909. -12664l, -12915l, -13159l, -13394l,
  100910. -13622l, -13841l, -14052l, -14255l,
  100911. -14448l, -14634l, -14810l, -14977l,
  100912. -15136l, -15285l, -15425l, -15556l,
  100913. -15678l, -15790l, -15892l, -15985l,
  100914. -16068l, -16142l, -16206l, -16260l,
  100915. -16304l, -16339l, -16363l, -16378l,
  100916. -16383l,
  100917. };
  100918. #endif
  100919. #endif
  100920. /*** End of inlined file: lookup_data.h ***/
  100921. #ifdef FLOAT_LOOKUP
  100922. float vorbis_coslook(float a){
  100923. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100924. int i=vorbis_ftoi(d-.5);
  100925. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100926. }
  100927. float vorbis_invsqlook(float a){
  100928. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100929. int i=vorbis_ftoi(d-.5f);
  100930. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100931. }
  100932. float vorbis_invsq2explook(int a){
  100933. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100934. }
  100935. #include <stdio.h>
  100936. float vorbis_fromdBlook(float a){
  100937. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100938. return (i<0)?1.f:
  100939. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100940. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100941. }
  100942. #endif
  100943. #ifdef INT_LOOKUP
  100944. long vorbis_invsqlook_i(long a,long e){
  100945. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100946. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100947. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100948. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100949. d)>>16); /* result 1.16 */
  100950. e+=32;
  100951. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100952. e=(e>>1)-8;
  100953. return(val>>e);
  100954. }
  100955. float vorbis_fromdBlook_i(long a){
  100956. int i=(-a)>>(12-FROMdB2_SHIFT);
  100957. return (i<0)?1.f:
  100958. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100959. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100960. }
  100961. long vorbis_coslook_i(long a){
  100962. int i=a>>COS_LOOKUP_I_SHIFT;
  100963. int d=a&COS_LOOKUP_I_MASK;
  100964. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100965. COS_LOOKUP_I_SHIFT);
  100966. }
  100967. #endif
  100968. #endif
  100969. /*** End of inlined file: lookup.c ***/
  100970. /* catch this in the build system; we #include for
  100971. compilers (like gcc) that can't inline across
  100972. modules */
  100973. static int MLOOP_1[64]={
  100974. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  100975. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  100976. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100977. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100978. };
  100979. static int MLOOP_2[64]={
  100980. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  100981. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  100982. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100983. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100984. };
  100985. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  100986. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100987. float amp,float ampoffset){
  100988. int i;
  100989. int ampoffseti=rint(ampoffset*4096.f);
  100990. int ampi=rint(amp*16.f);
  100991. long *ilsp=alloca(m*sizeof(*ilsp));
  100992. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  100993. i=0;
  100994. while(i<n){
  100995. int j,k=map[i];
  100996. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  100997. unsigned long qi=46341;
  100998. int qexp=0,shift;
  100999. long wi=vorbis_coslook_i(k*65536/ln);
  101000. qi*=labs(ilsp[0]-wi);
  101001. pi*=labs(ilsp[1]-wi);
  101002. for(j=3;j<m;j+=2){
  101003. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101004. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101005. shift=MLOOP_3[(pi|qi)>>16];
  101006. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101007. pi=(pi>>shift)*labs(ilsp[j]-wi);
  101008. qexp+=shift;
  101009. }
  101010. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101011. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101012. shift=MLOOP_3[(pi|qi)>>16];
  101013. if(m&1){
  101014. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101015. pi=(pi>>shift)<<14;
  101016. qexp+=shift;
  101017. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101018. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101019. shift=MLOOP_3[(pi|qi)>>16];
  101020. pi>>=shift;
  101021. qi>>=shift;
  101022. qexp+=shift-14*((m+1)>>1);
  101023. pi=((pi*pi)>>16);
  101024. qi=((qi*qi)>>16);
  101025. qexp=qexp*2+m;
  101026. pi*=(1<<14)-((wi*wi)>>14);
  101027. qi+=pi>>14;
  101028. }else{
  101029. pi>>=shift;
  101030. qi>>=shift;
  101031. qexp+=shift-7*m;
  101032. pi=((pi*pi)>>16);
  101033. qi=((qi*qi)>>16);
  101034. qexp=qexp*2+m;
  101035. pi*=(1<<14)-wi;
  101036. qi*=(1<<14)+wi;
  101037. qi=(qi+pi)>>14;
  101038. }
  101039. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101040. qi>>=1; qexp++;
  101041. }else
  101042. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101043. qi<<=1; qexp--;
  101044. }
  101045. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101046. vorbis_invsqlook_i(qi,qexp)-
  101047. ampoffseti); /* 8.12[0] */
  101048. curve[i]*=amp;
  101049. while(map[++i]==k)curve[i]*=amp;
  101050. }
  101051. }
  101052. #else
  101053. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101054. float amp,float ampoffset){
  101055. int i;
  101056. float wdel=M_PI/ln;
  101057. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101058. i=0;
  101059. while(i<n){
  101060. int j,k=map[i];
  101061. float p=.5f;
  101062. float q=.5f;
  101063. float w=2.f*cos(wdel*k);
  101064. for(j=1;j<m;j+=2){
  101065. q *= w-lsp[j-1];
  101066. p *= w-lsp[j];
  101067. }
  101068. if(j==m){
  101069. q*=w-lsp[j-1];
  101070. p*=p*(4.f-w*w);
  101071. q*=q;
  101072. }else{
  101073. p*=p*(2.f-w);
  101074. q*=q*(2.f+w);
  101075. }
  101076. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101077. curve[i]*=q;
  101078. while(map[++i]==k)curve[i]*=q;
  101079. }
  101080. }
  101081. #endif
  101082. #endif
  101083. static void cheby(float *g, int ord) {
  101084. int i, j;
  101085. g[0] *= .5f;
  101086. for(i=2; i<= ord; i++) {
  101087. for(j=ord; j >= i; j--) {
  101088. g[j-2] -= g[j];
  101089. g[j] += g[j];
  101090. }
  101091. }
  101092. }
  101093. static int comp(const void *a,const void *b){
  101094. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101095. }
  101096. #define EPSILON 10e-7
  101097. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101098. int i,m;
  101099. double lastdelta=0.f;
  101100. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101101. for(i=0;i<=ord;i++)defl[i]=a[i];
  101102. for(m=ord;m>0;m--){
  101103. double newx=0.f,delta;
  101104. while(1){
  101105. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101106. for(i=m;i>0;i--){
  101107. ppp = newx*ppp + pp;
  101108. pp = newx*pp + p;
  101109. p = newx*p + defl[i-1];
  101110. }
  101111. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101112. if(denom<0)
  101113. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101114. if(pp>0){
  101115. denom = pp + sqrt(denom);
  101116. if(denom<EPSILON)denom=EPSILON;
  101117. }else{
  101118. denom = pp - sqrt(denom);
  101119. if(denom>-(EPSILON))denom=-(EPSILON);
  101120. }
  101121. delta = m*p/denom;
  101122. newx -= delta;
  101123. if(delta<0.f)delta*=-1;
  101124. if(fabs(delta/newx)<10e-12)break;
  101125. lastdelta=delta;
  101126. }
  101127. r[m-1]=newx;
  101128. for(i=m;i>0;i--)
  101129. defl[i-1]+=newx*defl[i];
  101130. defl++;
  101131. }
  101132. return(0);
  101133. }
  101134. static int Newton_Raphson(float *a,int ord,float *r){
  101135. int i, k, count=0;
  101136. double error=1.f;
  101137. double *root=(double*)alloca(ord*sizeof(*root));
  101138. for(i=0; i<ord;i++) root[i] = r[i];
  101139. while(error>1e-20){
  101140. error=0;
  101141. for(i=0; i<ord; i++) { /* Update each point. */
  101142. double pp=0.,delta;
  101143. double rooti=root[i];
  101144. double p=a[ord];
  101145. for(k=ord-1; k>= 0; k--) {
  101146. pp= pp* rooti + p;
  101147. p = p * rooti + a[k];
  101148. }
  101149. delta = p/pp;
  101150. root[i] -= delta;
  101151. error+= delta*delta;
  101152. }
  101153. if(count>40)return(-1);
  101154. count++;
  101155. }
  101156. for(i=0; i<ord;i++) r[i] = root[i];
  101157. return(0);
  101158. }
  101159. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101160. int order2=(m+1)>>1;
  101161. int g1_order,g2_order;
  101162. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101163. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101164. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101165. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101166. int i;
  101167. g1_order=(m+1)>>1;
  101168. g2_order=(m) >>1;
  101169. g1[g1_order] = 1.f;
  101170. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101171. g2[g2_order] = 1.f;
  101172. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101173. if(g1_order>g2_order){
  101174. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101175. }else{
  101176. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101177. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101178. }
  101179. cheby(g1,g1_order);
  101180. cheby(g2,g2_order);
  101181. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101182. Laguerre_With_Deflation(g2,g2_order,g2r))
  101183. return(-1);
  101184. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101185. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101186. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101187. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101188. for(i=0;i<g1_order;i++)
  101189. lsp[i*2] = acos(g1r[i]);
  101190. for(i=0;i<g2_order;i++)
  101191. lsp[i*2+1] = acos(g2r[i]);
  101192. return(0);
  101193. }
  101194. #endif
  101195. /*** End of inlined file: lsp.c ***/
  101196. /*** Start of inlined file: mapping0.c ***/
  101197. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101198. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101199. // tasks..
  101200. #if JUCE_MSVC
  101201. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101202. #endif
  101203. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101204. #if JUCE_USE_OGGVORBIS
  101205. #include <stdlib.h>
  101206. #include <stdio.h>
  101207. #include <string.h>
  101208. #include <math.h>
  101209. static void mapping0_free_info(vorbis_info_mapping *i){
  101210. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101211. if(info){
  101212. memset(info,0,sizeof(*info));
  101213. _ogg_free(info);
  101214. }
  101215. }
  101216. static int ilog3(unsigned int v){
  101217. int ret=0;
  101218. if(v)--v;
  101219. while(v){
  101220. ret++;
  101221. v>>=1;
  101222. }
  101223. return(ret);
  101224. }
  101225. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101226. oggpack_buffer *opb){
  101227. int i;
  101228. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101229. if(info->submaps>1){
  101230. oggpack_write(opb,1,1);
  101231. oggpack_write(opb,info->submaps-1,4);
  101232. }else
  101233. oggpack_write(opb,0,1);
  101234. if(info->coupling_steps>0){
  101235. oggpack_write(opb,1,1);
  101236. oggpack_write(opb,info->coupling_steps-1,8);
  101237. for(i=0;i<info->coupling_steps;i++){
  101238. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101239. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101240. }
  101241. }else
  101242. oggpack_write(opb,0,1);
  101243. oggpack_write(opb,0,2); /* 2,3:reserved */
  101244. if(info->submaps>1){
  101245. for(i=0;i<vi->channels;i++)
  101246. oggpack_write(opb,info->chmuxlist[i],4);
  101247. }
  101248. for(i=0;i<info->submaps;i++){
  101249. oggpack_write(opb,0,8); /* time submap unused */
  101250. oggpack_write(opb,info->floorsubmap[i],8);
  101251. oggpack_write(opb,info->residuesubmap[i],8);
  101252. }
  101253. }
  101254. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101255. int i;
  101256. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101257. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101258. memset(info,0,sizeof(*info));
  101259. if(oggpack_read(opb,1))
  101260. info->submaps=oggpack_read(opb,4)+1;
  101261. else
  101262. info->submaps=1;
  101263. if(oggpack_read(opb,1)){
  101264. info->coupling_steps=oggpack_read(opb,8)+1;
  101265. for(i=0;i<info->coupling_steps;i++){
  101266. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101267. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101268. if(testM<0 ||
  101269. testA<0 ||
  101270. testM==testA ||
  101271. testM>=vi->channels ||
  101272. testA>=vi->channels) goto err_out;
  101273. }
  101274. }
  101275. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101276. if(info->submaps>1){
  101277. for(i=0;i<vi->channels;i++){
  101278. info->chmuxlist[i]=oggpack_read(opb,4);
  101279. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101280. }
  101281. }
  101282. for(i=0;i<info->submaps;i++){
  101283. oggpack_read(opb,8); /* time submap unused */
  101284. info->floorsubmap[i]=oggpack_read(opb,8);
  101285. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101286. info->residuesubmap[i]=oggpack_read(opb,8);
  101287. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101288. }
  101289. return info;
  101290. err_out:
  101291. mapping0_free_info(info);
  101292. return(NULL);
  101293. }
  101294. #if 0
  101295. static long seq=0;
  101296. static ogg_int64_t total=0;
  101297. static float FLOOR1_fromdB_LOOKUP[256]={
  101298. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101299. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101300. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101301. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101302. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101303. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101304. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101305. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101306. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101307. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101308. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101309. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101310. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101311. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101312. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101313. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101314. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101315. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101316. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101317. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101318. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101319. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101320. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101321. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101322. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101323. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101324. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101325. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101326. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101327. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101328. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101329. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101330. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101331. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101332. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101333. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101334. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101335. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101336. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101337. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101338. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101339. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101340. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101341. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101342. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101343. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101344. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101345. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101346. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101347. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101348. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101349. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101350. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101351. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101352. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101353. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101354. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101355. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101356. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101357. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101358. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101359. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101360. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101361. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101362. };
  101363. #endif
  101364. extern int *floor1_fit(vorbis_block *vb,void *look,
  101365. const float *logmdct, /* in */
  101366. const float *logmask);
  101367. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101368. int *A,int *B,
  101369. int del);
  101370. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101371. void*look,
  101372. int *post,int *ilogmask);
  101373. static int mapping0_forward(vorbis_block *vb){
  101374. vorbis_dsp_state *vd=vb->vd;
  101375. vorbis_info *vi=vd->vi;
  101376. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101377. private_state *b=(private_state*)vb->vd->backend_state;
  101378. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101379. int n=vb->pcmend;
  101380. int i,j,k;
  101381. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101382. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101383. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101384. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101385. float global_ampmax=vbi->ampmax;
  101386. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101387. int blocktype=vbi->blocktype;
  101388. int modenumber=vb->W;
  101389. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101390. vorbis_look_psy *psy_look=
  101391. b->psy+blocktype+(vb->W?2:0);
  101392. vb->mode=modenumber;
  101393. for(i=0;i<vi->channels;i++){
  101394. float scale=4.f/n;
  101395. float scale_dB;
  101396. float *pcm =vb->pcm[i];
  101397. float *logfft =pcm;
  101398. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101399. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101400. todB estimation used on IEEE 754
  101401. compliant machines had a bug that
  101402. returned dB values about a third
  101403. of a decibel too high. The bug
  101404. was harmless because tunings
  101405. implicitly took that into
  101406. account. However, fixing the bug
  101407. in the estimator requires
  101408. changing all the tunings as well.
  101409. For now, it's easier to sync
  101410. things back up here, and
  101411. recalibrate the tunings in the
  101412. next major model upgrade. */
  101413. #if 0
  101414. if(vi->channels==2)
  101415. if(i==0)
  101416. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101417. else
  101418. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101419. #endif
  101420. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101421. #if 0
  101422. if(vi->channels==2)
  101423. if(i==0)
  101424. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101425. else
  101426. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101427. #endif
  101428. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101429. drft_forward(&b->fft_look[vb->W],pcm);
  101430. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101431. original todB estimation used on
  101432. IEEE 754 compliant machines had a
  101433. bug that returned dB values about
  101434. a third of a decibel too high.
  101435. The bug was harmless because
  101436. tunings implicitly took that into
  101437. account. However, fixing the bug
  101438. in the estimator requires
  101439. changing all the tunings as well.
  101440. For now, it's easier to sync
  101441. things back up here, and
  101442. recalibrate the tunings in the
  101443. next major model upgrade. */
  101444. local_ampmax[i]=logfft[0];
  101445. for(j=1;j<n-1;j+=2){
  101446. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101447. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101448. .345 is a hack; the original todB
  101449. estimation used on IEEE 754
  101450. compliant machines had a bug that
  101451. returned dB values about a third
  101452. of a decibel too high. The bug
  101453. was harmless because tunings
  101454. implicitly took that into
  101455. account. However, fixing the bug
  101456. in the estimator requires
  101457. changing all the tunings as well.
  101458. For now, it's easier to sync
  101459. things back up here, and
  101460. recalibrate the tunings in the
  101461. next major model upgrade. */
  101462. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101463. }
  101464. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101465. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101466. #if 0
  101467. if(vi->channels==2){
  101468. if(i==0){
  101469. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101470. }else{
  101471. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101472. }
  101473. }
  101474. #endif
  101475. }
  101476. {
  101477. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101478. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101479. for(i=0;i<vi->channels;i++){
  101480. int submap=info->chmuxlist[i];
  101481. float *mdct =gmdct[i];
  101482. float *logfft =vb->pcm[i];
  101483. float *logmdct =logfft+n/2;
  101484. float *logmask =logfft;
  101485. vb->mode=modenumber;
  101486. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101487. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101488. for(j=0;j<n/2;j++)
  101489. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101490. todB estimation used on IEEE 754
  101491. compliant machines had a bug that
  101492. returned dB values about a third
  101493. of a decibel too high. The bug
  101494. was harmless because tunings
  101495. implicitly took that into
  101496. account. However, fixing the bug
  101497. in the estimator requires
  101498. changing all the tunings as well.
  101499. For now, it's easier to sync
  101500. things back up here, and
  101501. recalibrate the tunings in the
  101502. next major model upgrade. */
  101503. #if 0
  101504. if(vi->channels==2){
  101505. if(i==0)
  101506. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101507. else
  101508. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101509. }else{
  101510. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101511. }
  101512. #endif
  101513. _vp_noisemask(psy_look,
  101514. logmdct,
  101515. noise); /* noise does not have by-frequency offset
  101516. bias applied yet */
  101517. #if 0
  101518. if(vi->channels==2){
  101519. if(i==0)
  101520. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101521. else
  101522. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101523. }
  101524. #endif
  101525. _vp_tonemask(psy_look,
  101526. logfft,
  101527. tone,
  101528. global_ampmax,
  101529. local_ampmax[i]);
  101530. #if 0
  101531. if(vi->channels==2){
  101532. if(i==0)
  101533. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101534. else
  101535. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  101536. }
  101537. #endif
  101538. #if 0
  101539. {
  101540. float aotuv[psy_look->n];
  101541. #endif
  101542. _vp_offset_and_mix(psy_look,
  101543. noise,
  101544. tone,
  101545. 1,
  101546. logmask,
  101547. mdct,
  101548. logmdct);
  101549. #if 0
  101550. if(vi->channels==2){
  101551. if(i==0)
  101552. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  101553. else
  101554. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  101555. }
  101556. }
  101557. #endif
  101558. #if 0
  101559. if(vi->channels==2){
  101560. if(i==0)
  101561. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  101562. else
  101563. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  101564. }
  101565. #endif
  101566. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  101567. floor_posts[i][PACKETBLOBS/2]=
  101568. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101569. logmdct,
  101570. logmask);
  101571. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  101572. _vp_offset_and_mix(psy_look,
  101573. noise,
  101574. tone,
  101575. 2,
  101576. logmask,
  101577. mdct,
  101578. logmdct);
  101579. #if 0
  101580. if(vi->channels==2){
  101581. if(i==0)
  101582. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  101583. else
  101584. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  101585. }
  101586. #endif
  101587. floor_posts[i][PACKETBLOBS-1]=
  101588. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101589. logmdct,
  101590. logmask);
  101591. _vp_offset_and_mix(psy_look,
  101592. noise,
  101593. tone,
  101594. 0,
  101595. logmask,
  101596. mdct,
  101597. logmdct);
  101598. #if 0
  101599. if(vi->channels==2)
  101600. if(i==0)
  101601. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  101602. else
  101603. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  101604. #endif
  101605. floor_posts[i][0]=
  101606. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101607. logmdct,
  101608. logmask);
  101609. for(k=1;k<PACKETBLOBS/2;k++)
  101610. floor_posts[i][k]=
  101611. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101612. floor_posts[i][0],
  101613. floor_posts[i][PACKETBLOBS/2],
  101614. k*65536/(PACKETBLOBS/2));
  101615. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  101616. floor_posts[i][k]=
  101617. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101618. floor_posts[i][PACKETBLOBS/2],
  101619. floor_posts[i][PACKETBLOBS-1],
  101620. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  101621. }
  101622. }
  101623. }
  101624. vbi->ampmax=global_ampmax;
  101625. {
  101626. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  101627. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  101628. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101629. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  101630. float **mag_memo;
  101631. int **mag_sort;
  101632. if(info->coupling_steps){
  101633. mag_memo=_vp_quantize_couple_memo(vb,
  101634. &ci->psy_g_param,
  101635. psy_look,
  101636. info,
  101637. gmdct);
  101638. mag_sort=_vp_quantize_couple_sort(vb,
  101639. psy_look,
  101640. info,
  101641. mag_memo);
  101642. hf_reduction(&ci->psy_g_param,
  101643. psy_look,
  101644. info,
  101645. mag_memo);
  101646. }
  101647. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  101648. if(psy_look->vi->normal_channel_p){
  101649. for(i=0;i<vi->channels;i++){
  101650. float *mdct =gmdct[i];
  101651. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  101652. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  101653. }
  101654. }
  101655. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  101656. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  101657. k++){
  101658. oggpack_buffer *opb=vbi->packetblob[k];
  101659. oggpack_write(opb,0,1);
  101660. oggpack_write(opb,modenumber,b->modebits);
  101661. if(vb->W){
  101662. oggpack_write(opb,vb->lW,1);
  101663. oggpack_write(opb,vb->nW,1);
  101664. }
  101665. for(i=0;i<vi->channels;i++){
  101666. int submap=info->chmuxlist[i];
  101667. float *mdct =gmdct[i];
  101668. float *res =vb->pcm[i];
  101669. int *ilogmask=ilogmaskch[i]=
  101670. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101671. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  101672. floor_posts[i][k],
  101673. ilogmask);
  101674. #if 0
  101675. {
  101676. char buf[80];
  101677. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  101678. float work[n/2];
  101679. for(j=0;j<n/2;j++)
  101680. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  101681. _analysis_output(buf,seq,work,n/2,1,1,0);
  101682. }
  101683. #endif
  101684. _vp_remove_floor(psy_look,
  101685. mdct,
  101686. ilogmask,
  101687. res,
  101688. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101689. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  101690. #if 0
  101691. {
  101692. char buf[80];
  101693. float work[n/2];
  101694. for(j=0;j<n/2;j++)
  101695. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  101696. sprintf(buf,"resI%c%d",i?'R':'L',k);
  101697. _analysis_output(buf,seq,work,n/2,1,1,0);
  101698. }
  101699. #endif
  101700. }
  101701. if(info->coupling_steps){
  101702. _vp_couple(k,
  101703. &ci->psy_g_param,
  101704. psy_look,
  101705. info,
  101706. vb->pcm,
  101707. mag_memo,
  101708. mag_sort,
  101709. ilogmaskch,
  101710. nonzero,
  101711. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101712. }
  101713. for(i=0;i<info->submaps;i++){
  101714. int ch_in_bundle=0;
  101715. long **classifications;
  101716. int resnum=info->residuesubmap[i];
  101717. for(j=0;j<vi->channels;j++){
  101718. if(info->chmuxlist[j]==i){
  101719. zerobundle[ch_in_bundle]=0;
  101720. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  101721. res_bundle[ch_in_bundle]=vb->pcm[j];
  101722. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  101723. }
  101724. }
  101725. classifications=_residue_P[ci->residue_type[resnum]]->
  101726. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  101727. _residue_P[ci->residue_type[resnum]]->
  101728. forward(opb,vb,b->residue[resnum],
  101729. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  101730. }
  101731. }
  101732. }
  101733. #if 0
  101734. seq++;
  101735. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  101736. #endif
  101737. return(0);
  101738. }
  101739. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  101740. vorbis_dsp_state *vd=vb->vd;
  101741. vorbis_info *vi=vd->vi;
  101742. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  101743. private_state *b=(private_state*)vd->backend_state;
  101744. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  101745. int i,j;
  101746. long n=vb->pcmend=ci->blocksizes[vb->W];
  101747. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  101748. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101749. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  101750. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  101751. for(i=0;i<vi->channels;i++){
  101752. int submap=info->chmuxlist[i];
  101753. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101754. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  101755. if(floormemo[i])
  101756. nonzero[i]=1;
  101757. else
  101758. nonzero[i]=0;
  101759. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  101760. }
  101761. for(i=0;i<info->coupling_steps;i++){
  101762. if(nonzero[info->coupling_mag[i]] ||
  101763. nonzero[info->coupling_ang[i]]){
  101764. nonzero[info->coupling_mag[i]]=1;
  101765. nonzero[info->coupling_ang[i]]=1;
  101766. }
  101767. }
  101768. for(i=0;i<info->submaps;i++){
  101769. int ch_in_bundle=0;
  101770. for(j=0;j<vi->channels;j++){
  101771. if(info->chmuxlist[j]==i){
  101772. if(nonzero[j])
  101773. zerobundle[ch_in_bundle]=1;
  101774. else
  101775. zerobundle[ch_in_bundle]=0;
  101776. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  101777. }
  101778. }
  101779. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  101780. inverse(vb,b->residue[info->residuesubmap[i]],
  101781. pcmbundle,zerobundle,ch_in_bundle);
  101782. }
  101783. for(i=info->coupling_steps-1;i>=0;i--){
  101784. float *pcmM=vb->pcm[info->coupling_mag[i]];
  101785. float *pcmA=vb->pcm[info->coupling_ang[i]];
  101786. for(j=0;j<n/2;j++){
  101787. float mag=pcmM[j];
  101788. float ang=pcmA[j];
  101789. if(mag>0)
  101790. if(ang>0){
  101791. pcmM[j]=mag;
  101792. pcmA[j]=mag-ang;
  101793. }else{
  101794. pcmA[j]=mag;
  101795. pcmM[j]=mag+ang;
  101796. }
  101797. else
  101798. if(ang>0){
  101799. pcmM[j]=mag;
  101800. pcmA[j]=mag+ang;
  101801. }else{
  101802. pcmA[j]=mag;
  101803. pcmM[j]=mag-ang;
  101804. }
  101805. }
  101806. }
  101807. for(i=0;i<vi->channels;i++){
  101808. float *pcm=vb->pcm[i];
  101809. int submap=info->chmuxlist[i];
  101810. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101811. inverse2(vb,b->flr[info->floorsubmap[submap]],
  101812. floormemo[i],pcm);
  101813. }
  101814. for(i=0;i<vi->channels;i++){
  101815. float *pcm=vb->pcm[i];
  101816. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  101817. }
  101818. return(0);
  101819. }
  101820. vorbis_func_mapping mapping0_exportbundle={
  101821. &mapping0_pack,
  101822. &mapping0_unpack,
  101823. &mapping0_free_info,
  101824. &mapping0_forward,
  101825. &mapping0_inverse
  101826. };
  101827. #endif
  101828. /*** End of inlined file: mapping0.c ***/
  101829. /*** Start of inlined file: mdct.c ***/
  101830. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101831. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101832. // tasks..
  101833. #if JUCE_MSVC
  101834. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101835. #endif
  101836. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101837. #if JUCE_USE_OGGVORBIS
  101838. #include <stdio.h>
  101839. #include <stdlib.h>
  101840. #include <string.h>
  101841. #include <math.h>
  101842. void mdct_init(mdct_lookup *lookup,int n){
  101843. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  101844. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  101845. int i;
  101846. int n2=n>>1;
  101847. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  101848. lookup->n=n;
  101849. lookup->trig=T;
  101850. lookup->bitrev=bitrev;
  101851. for(i=0;i<n/4;i++){
  101852. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  101853. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  101854. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  101855. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  101856. }
  101857. for(i=0;i<n/8;i++){
  101858. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  101859. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  101860. }
  101861. {
  101862. int mask=(1<<(log2n-1))-1,i,j;
  101863. int msb=1<<(log2n-2);
  101864. for(i=0;i<n/8;i++){
  101865. int acc=0;
  101866. for(j=0;msb>>j;j++)
  101867. if((msb>>j)&i)acc|=1<<j;
  101868. bitrev[i*2]=((~acc)&mask)-1;
  101869. bitrev[i*2+1]=acc;
  101870. }
  101871. }
  101872. lookup->scale=FLOAT_CONV(4.f/n);
  101873. }
  101874. STIN void mdct_butterfly_8(DATA_TYPE *x){
  101875. REG_TYPE r0 = x[6] + x[2];
  101876. REG_TYPE r1 = x[6] - x[2];
  101877. REG_TYPE r2 = x[4] + x[0];
  101878. REG_TYPE r3 = x[4] - x[0];
  101879. x[6] = r0 + r2;
  101880. x[4] = r0 - r2;
  101881. r0 = x[5] - x[1];
  101882. r2 = x[7] - x[3];
  101883. x[0] = r1 + r0;
  101884. x[2] = r1 - r0;
  101885. r0 = x[5] + x[1];
  101886. r1 = x[7] + x[3];
  101887. x[3] = r2 + r3;
  101888. x[1] = r2 - r3;
  101889. x[7] = r1 + r0;
  101890. x[5] = r1 - r0;
  101891. }
  101892. STIN void mdct_butterfly_16(DATA_TYPE *x){
  101893. REG_TYPE r0 = x[1] - x[9];
  101894. REG_TYPE r1 = x[0] - x[8];
  101895. x[8] += x[0];
  101896. x[9] += x[1];
  101897. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  101898. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  101899. r0 = x[3] - x[11];
  101900. r1 = x[10] - x[2];
  101901. x[10] += x[2];
  101902. x[11] += x[3];
  101903. x[2] = r0;
  101904. x[3] = r1;
  101905. r0 = x[12] - x[4];
  101906. r1 = x[13] - x[5];
  101907. x[12] += x[4];
  101908. x[13] += x[5];
  101909. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  101910. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  101911. r0 = x[14] - x[6];
  101912. r1 = x[15] - x[7];
  101913. x[14] += x[6];
  101914. x[15] += x[7];
  101915. x[6] = r0;
  101916. x[7] = r1;
  101917. mdct_butterfly_8(x);
  101918. mdct_butterfly_8(x+8);
  101919. }
  101920. STIN void mdct_butterfly_32(DATA_TYPE *x){
  101921. REG_TYPE r0 = x[30] - x[14];
  101922. REG_TYPE r1 = x[31] - x[15];
  101923. x[30] += x[14];
  101924. x[31] += x[15];
  101925. x[14] = r0;
  101926. x[15] = r1;
  101927. r0 = x[28] - x[12];
  101928. r1 = x[29] - x[13];
  101929. x[28] += x[12];
  101930. x[29] += x[13];
  101931. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  101932. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  101933. r0 = x[26] - x[10];
  101934. r1 = x[27] - x[11];
  101935. x[26] += x[10];
  101936. x[27] += x[11];
  101937. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  101938. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  101939. r0 = x[24] - x[8];
  101940. r1 = x[25] - x[9];
  101941. x[24] += x[8];
  101942. x[25] += x[9];
  101943. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  101944. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101945. r0 = x[22] - x[6];
  101946. r1 = x[7] - x[23];
  101947. x[22] += x[6];
  101948. x[23] += x[7];
  101949. x[6] = r1;
  101950. x[7] = r0;
  101951. r0 = x[4] - x[20];
  101952. r1 = x[5] - x[21];
  101953. x[20] += x[4];
  101954. x[21] += x[5];
  101955. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  101956. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  101957. r0 = x[2] - x[18];
  101958. r1 = x[3] - x[19];
  101959. x[18] += x[2];
  101960. x[19] += x[3];
  101961. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  101962. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  101963. r0 = x[0] - x[16];
  101964. r1 = x[1] - x[17];
  101965. x[16] += x[0];
  101966. x[17] += x[1];
  101967. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101968. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  101969. mdct_butterfly_16(x);
  101970. mdct_butterfly_16(x+16);
  101971. }
  101972. STIN void mdct_butterfly_first(DATA_TYPE *T,
  101973. DATA_TYPE *x,
  101974. int points){
  101975. DATA_TYPE *x1 = x + points - 8;
  101976. DATA_TYPE *x2 = x + (points>>1) - 8;
  101977. REG_TYPE r0;
  101978. REG_TYPE r1;
  101979. do{
  101980. r0 = x1[6] - x2[6];
  101981. r1 = x1[7] - x2[7];
  101982. x1[6] += x2[6];
  101983. x1[7] += x2[7];
  101984. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101985. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101986. r0 = x1[4] - x2[4];
  101987. r1 = x1[5] - x2[5];
  101988. x1[4] += x2[4];
  101989. x1[5] += x2[5];
  101990. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  101991. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  101992. r0 = x1[2] - x2[2];
  101993. r1 = x1[3] - x2[3];
  101994. x1[2] += x2[2];
  101995. x1[3] += x2[3];
  101996. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  101997. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  101998. r0 = x1[0] - x2[0];
  101999. r1 = x1[1] - x2[1];
  102000. x1[0] += x2[0];
  102001. x1[1] += x2[1];
  102002. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  102003. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  102004. x1-=8;
  102005. x2-=8;
  102006. T+=16;
  102007. }while(x2>=x);
  102008. }
  102009. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  102010. DATA_TYPE *x,
  102011. int points,
  102012. int trigint){
  102013. DATA_TYPE *x1 = x + points - 8;
  102014. DATA_TYPE *x2 = x + (points>>1) - 8;
  102015. REG_TYPE r0;
  102016. REG_TYPE r1;
  102017. do{
  102018. r0 = x1[6] - x2[6];
  102019. r1 = x1[7] - x2[7];
  102020. x1[6] += x2[6];
  102021. x1[7] += x2[7];
  102022. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102023. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102024. T+=trigint;
  102025. r0 = x1[4] - x2[4];
  102026. r1 = x1[5] - x2[5];
  102027. x1[4] += x2[4];
  102028. x1[5] += x2[5];
  102029. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102030. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102031. T+=trigint;
  102032. r0 = x1[2] - x2[2];
  102033. r1 = x1[3] - x2[3];
  102034. x1[2] += x2[2];
  102035. x1[3] += x2[3];
  102036. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102037. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102038. T+=trigint;
  102039. r0 = x1[0] - x2[0];
  102040. r1 = x1[1] - x2[1];
  102041. x1[0] += x2[0];
  102042. x1[1] += x2[1];
  102043. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102044. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102045. T+=trigint;
  102046. x1-=8;
  102047. x2-=8;
  102048. }while(x2>=x);
  102049. }
  102050. STIN void mdct_butterflies(mdct_lookup *init,
  102051. DATA_TYPE *x,
  102052. int points){
  102053. DATA_TYPE *T=init->trig;
  102054. int stages=init->log2n-5;
  102055. int i,j;
  102056. if(--stages>0){
  102057. mdct_butterfly_first(T,x,points);
  102058. }
  102059. for(i=1;--stages>0;i++){
  102060. for(j=0;j<(1<<i);j++)
  102061. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102062. }
  102063. for(j=0;j<points;j+=32)
  102064. mdct_butterfly_32(x+j);
  102065. }
  102066. void mdct_clear(mdct_lookup *l){
  102067. if(l){
  102068. if(l->trig)_ogg_free(l->trig);
  102069. if(l->bitrev)_ogg_free(l->bitrev);
  102070. memset(l,0,sizeof(*l));
  102071. }
  102072. }
  102073. STIN void mdct_bitreverse(mdct_lookup *init,
  102074. DATA_TYPE *x){
  102075. int n = init->n;
  102076. int *bit = init->bitrev;
  102077. DATA_TYPE *w0 = x;
  102078. DATA_TYPE *w1 = x = w0+(n>>1);
  102079. DATA_TYPE *T = init->trig+n;
  102080. do{
  102081. DATA_TYPE *x0 = x+bit[0];
  102082. DATA_TYPE *x1 = x+bit[1];
  102083. REG_TYPE r0 = x0[1] - x1[1];
  102084. REG_TYPE r1 = x0[0] + x1[0];
  102085. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102086. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102087. w1 -= 4;
  102088. r0 = HALVE(x0[1] + x1[1]);
  102089. r1 = HALVE(x0[0] - x1[0]);
  102090. w0[0] = r0 + r2;
  102091. w1[2] = r0 - r2;
  102092. w0[1] = r1 + r3;
  102093. w1[3] = r3 - r1;
  102094. x0 = x+bit[2];
  102095. x1 = x+bit[3];
  102096. r0 = x0[1] - x1[1];
  102097. r1 = x0[0] + x1[0];
  102098. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102099. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102100. r0 = HALVE(x0[1] + x1[1]);
  102101. r1 = HALVE(x0[0] - x1[0]);
  102102. w0[2] = r0 + r2;
  102103. w1[0] = r0 - r2;
  102104. w0[3] = r1 + r3;
  102105. w1[1] = r3 - r1;
  102106. T += 4;
  102107. bit += 4;
  102108. w0 += 4;
  102109. }while(w0<w1);
  102110. }
  102111. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102112. int n=init->n;
  102113. int n2=n>>1;
  102114. int n4=n>>2;
  102115. DATA_TYPE *iX = in+n2-7;
  102116. DATA_TYPE *oX = out+n2+n4;
  102117. DATA_TYPE *T = init->trig+n4;
  102118. do{
  102119. oX -= 4;
  102120. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102121. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102122. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102123. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102124. iX -= 8;
  102125. T += 4;
  102126. }while(iX>=in);
  102127. iX = in+n2-8;
  102128. oX = out+n2+n4;
  102129. T = init->trig+n4;
  102130. do{
  102131. T -= 4;
  102132. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102133. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102134. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102135. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102136. iX -= 8;
  102137. oX += 4;
  102138. }while(iX>=in);
  102139. mdct_butterflies(init,out+n2,n2);
  102140. mdct_bitreverse(init,out);
  102141. {
  102142. DATA_TYPE *oX1=out+n2+n4;
  102143. DATA_TYPE *oX2=out+n2+n4;
  102144. DATA_TYPE *iX =out;
  102145. T =init->trig+n2;
  102146. do{
  102147. oX1-=4;
  102148. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102149. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102150. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102151. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102152. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102153. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102154. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102155. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102156. oX2+=4;
  102157. iX += 8;
  102158. T += 8;
  102159. }while(iX<oX1);
  102160. iX=out+n2+n4;
  102161. oX1=out+n4;
  102162. oX2=oX1;
  102163. do{
  102164. oX1-=4;
  102165. iX-=4;
  102166. oX2[0] = -(oX1[3] = iX[3]);
  102167. oX2[1] = -(oX1[2] = iX[2]);
  102168. oX2[2] = -(oX1[1] = iX[1]);
  102169. oX2[3] = -(oX1[0] = iX[0]);
  102170. oX2+=4;
  102171. }while(oX2<iX);
  102172. iX=out+n2+n4;
  102173. oX1=out+n2+n4;
  102174. oX2=out+n2;
  102175. do{
  102176. oX1-=4;
  102177. oX1[0]= iX[3];
  102178. oX1[1]= iX[2];
  102179. oX1[2]= iX[1];
  102180. oX1[3]= iX[0];
  102181. iX+=4;
  102182. }while(oX1>oX2);
  102183. }
  102184. }
  102185. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102186. int n=init->n;
  102187. int n2=n>>1;
  102188. int n4=n>>2;
  102189. int n8=n>>3;
  102190. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102191. DATA_TYPE *w2=w+n2;
  102192. REG_TYPE r0;
  102193. REG_TYPE r1;
  102194. DATA_TYPE *x0=in+n2+n4;
  102195. DATA_TYPE *x1=x0+1;
  102196. DATA_TYPE *T=init->trig+n2;
  102197. int i=0;
  102198. for(i=0;i<n8;i+=2){
  102199. x0 -=4;
  102200. T-=2;
  102201. r0= x0[2] + x1[0];
  102202. r1= x0[0] + x1[2];
  102203. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102204. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102205. x1 +=4;
  102206. }
  102207. x1=in+1;
  102208. for(;i<n2-n8;i+=2){
  102209. T-=2;
  102210. x0 -=4;
  102211. r0= x0[2] - x1[0];
  102212. r1= x0[0] - x1[2];
  102213. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102214. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102215. x1 +=4;
  102216. }
  102217. x0=in+n;
  102218. for(;i<n2;i+=2){
  102219. T-=2;
  102220. x0 -=4;
  102221. r0= -x0[2] - x1[0];
  102222. r1= -x0[0] - x1[2];
  102223. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102224. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102225. x1 +=4;
  102226. }
  102227. mdct_butterflies(init,w+n2,n2);
  102228. mdct_bitreverse(init,w);
  102229. T=init->trig+n2;
  102230. x0=out+n2;
  102231. for(i=0;i<n4;i++){
  102232. x0--;
  102233. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102234. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102235. w+=2;
  102236. T+=2;
  102237. }
  102238. }
  102239. #endif
  102240. /*** End of inlined file: mdct.c ***/
  102241. /*** Start of inlined file: psy.c ***/
  102242. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102243. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102244. // tasks..
  102245. #if JUCE_MSVC
  102246. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102247. #endif
  102248. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102249. #if JUCE_USE_OGGVORBIS
  102250. #include <stdlib.h>
  102251. #include <math.h>
  102252. #include <string.h>
  102253. /*** Start of inlined file: masking.h ***/
  102254. #ifndef _V_MASKING_H_
  102255. #define _V_MASKING_H_
  102256. #define MAX_ATH 88
  102257. static float ATH[]={
  102258. -51, -52, -53, -54, -55, -56, -57, -58,
  102259. -59, -60, -61, -62, -63, -64, -65, -66,
  102260. -67, -68, -69, -70, -71, -72, -73, -74,
  102261. -75, -76, -77, -78, -80, -81, -82, -83,
  102262. -84, -85, -86, -87, -88, -88, -89, -89,
  102263. -90, -91, -91, -92, -93, -94, -95, -96,
  102264. -96, -97, -98, -98, -99, -99,-100,-100,
  102265. -101,-102,-103,-104,-106,-107,-107,-107,
  102266. -107,-105,-103,-102,-101, -99, -98, -96,
  102267. -95, -95, -96, -97, -96, -95, -93, -90,
  102268. -80, -70, -50, -40, -30, -30, -30, -30
  102269. };
  102270. #define EHMER_OFFSET 16
  102271. #define EHMER_MAX 56
  102272. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102273. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102274. -60, -60, -60, -60, -62, -62, -65, -73,
  102275. -69, -68, -68, -67, -70, -70, -72, -74,
  102276. -75, -79, -79, -80, -83, -88, -93, -100,
  102277. -110, -999, -999, -999, -999, -999, -999, -999,
  102278. -999, -999, -999, -999, -999, -999, -999, -999,
  102279. -999, -999, -999, -999, -999, -999, -999, -999},
  102280. { -48, -48, -48, -48, -48, -48, -48, -48,
  102281. -48, -48, -48, -48, -48, -53, -61, -66,
  102282. -66, -68, -67, -70, -76, -76, -72, -73,
  102283. -75, -76, -78, -79, -83, -88, -93, -100,
  102284. -110, -999, -999, -999, -999, -999, -999, -999,
  102285. -999, -999, -999, -999, -999, -999, -999, -999,
  102286. -999, -999, -999, -999, -999, -999, -999, -999},
  102287. { -37, -37, -37, -37, -37, -37, -37, -37,
  102288. -38, -40, -42, -46, -48, -53, -55, -62,
  102289. -65, -58, -56, -56, -61, -60, -65, -67,
  102290. -69, -71, -77, -77, -78, -80, -82, -84,
  102291. -88, -93, -98, -106, -112, -999, -999, -999,
  102292. -999, -999, -999, -999, -999, -999, -999, -999,
  102293. -999, -999, -999, -999, -999, -999, -999, -999},
  102294. { -25, -25, -25, -25, -25, -25, -25, -25,
  102295. -25, -26, -27, -29, -32, -38, -48, -52,
  102296. -52, -50, -48, -48, -51, -52, -54, -60,
  102297. -67, -67, -66, -68, -69, -73, -73, -76,
  102298. -80, -81, -81, -85, -85, -86, -88, -93,
  102299. -100, -110, -999, -999, -999, -999, -999, -999,
  102300. -999, -999, -999, -999, -999, -999, -999, -999},
  102301. { -16, -16, -16, -16, -16, -16, -16, -16,
  102302. -17, -19, -20, -22, -26, -28, -31, -40,
  102303. -47, -39, -39, -40, -42, -43, -47, -51,
  102304. -57, -52, -55, -55, -60, -58, -62, -63,
  102305. -70, -67, -69, -72, -73, -77, -80, -82,
  102306. -83, -87, -90, -94, -98, -104, -115, -999,
  102307. -999, -999, -999, -999, -999, -999, -999, -999},
  102308. { -8, -8, -8, -8, -8, -8, -8, -8,
  102309. -8, -8, -10, -11, -15, -19, -25, -30,
  102310. -34, -31, -30, -31, -29, -32, -35, -42,
  102311. -48, -42, -44, -46, -50, -50, -51, -52,
  102312. -59, -54, -55, -55, -58, -62, -63, -66,
  102313. -72, -73, -76, -75, -78, -80, -80, -81,
  102314. -84, -88, -90, -94, -98, -101, -106, -110}},
  102315. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102316. -66, -66, -66, -66, -66, -67, -67, -67,
  102317. -76, -72, -71, -74, -76, -76, -75, -78,
  102318. -79, -79, -81, -83, -86, -89, -93, -97,
  102319. -100, -105, -110, -999, -999, -999, -999, -999,
  102320. -999, -999, -999, -999, -999, -999, -999, -999,
  102321. -999, -999, -999, -999, -999, -999, -999, -999},
  102322. { -47, -47, -47, -47, -47, -47, -47, -47,
  102323. -47, -47, -47, -48, -51, -55, -59, -66,
  102324. -66, -66, -67, -66, -68, -69, -70, -74,
  102325. -79, -77, -77, -78, -80, -81, -82, -84,
  102326. -86, -88, -91, -95, -100, -108, -116, -999,
  102327. -999, -999, -999, -999, -999, -999, -999, -999,
  102328. -999, -999, -999, -999, -999, -999, -999, -999},
  102329. { -36, -36, -36, -36, -36, -36, -36, -36,
  102330. -36, -37, -37, -41, -44, -48, -51, -58,
  102331. -62, -60, -57, -59, -59, -60, -63, -65,
  102332. -72, -71, -70, -72, -74, -77, -76, -78,
  102333. -81, -81, -80, -83, -86, -91, -96, -100,
  102334. -105, -110, -999, -999, -999, -999, -999, -999,
  102335. -999, -999, -999, -999, -999, -999, -999, -999},
  102336. { -28, -28, -28, -28, -28, -28, -28, -28,
  102337. -28, -30, -32, -32, -33, -35, -41, -49,
  102338. -50, -49, -47, -48, -48, -52, -51, -57,
  102339. -65, -61, -59, -61, -64, -69, -70, -74,
  102340. -77, -77, -78, -81, -84, -85, -87, -90,
  102341. -92, -96, -100, -107, -112, -999, -999, -999,
  102342. -999, -999, -999, -999, -999, -999, -999, -999},
  102343. { -19, -19, -19, -19, -19, -19, -19, -19,
  102344. -20, -21, -23, -27, -30, -35, -36, -41,
  102345. -46, -44, -42, -40, -41, -41, -43, -48,
  102346. -55, -53, -52, -53, -56, -59, -58, -60,
  102347. -67, -66, -69, -71, -72, -75, -79, -81,
  102348. -84, -87, -90, -93, -97, -101, -107, -114,
  102349. -999, -999, -999, -999, -999, -999, -999, -999},
  102350. { -9, -9, -9, -9, -9, -9, -9, -9,
  102351. -11, -12, -12, -15, -16, -20, -23, -30,
  102352. -37, -34, -33, -34, -31, -32, -32, -38,
  102353. -47, -44, -41, -40, -47, -49, -46, -46,
  102354. -58, -50, -50, -54, -58, -62, -64, -67,
  102355. -67, -70, -72, -76, -79, -83, -87, -91,
  102356. -96, -100, -104, -110, -999, -999, -999, -999}},
  102357. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102358. -62, -62, -63, -64, -66, -67, -66, -68,
  102359. -75, -72, -76, -75, -76, -78, -79, -82,
  102360. -84, -85, -90, -94, -101, -110, -999, -999,
  102361. -999, -999, -999, -999, -999, -999, -999, -999,
  102362. -999, -999, -999, -999, -999, -999, -999, -999,
  102363. -999, -999, -999, -999, -999, -999, -999, -999},
  102364. { -59, -59, -59, -59, -59, -59, -59, -59,
  102365. -59, -59, -59, -60, -60, -61, -63, -66,
  102366. -71, -68, -70, -70, -71, -72, -72, -75,
  102367. -81, -78, -79, -82, -83, -86, -90, -97,
  102368. -103, -113, -999, -999, -999, -999, -999, -999,
  102369. -999, -999, -999, -999, -999, -999, -999, -999,
  102370. -999, -999, -999, -999, -999, -999, -999, -999},
  102371. { -53, -53, -53, -53, -53, -53, -53, -53,
  102372. -53, -54, -55, -57, -56, -57, -55, -61,
  102373. -65, -60, -60, -62, -63, -63, -66, -68,
  102374. -74, -73, -75, -75, -78, -80, -80, -82,
  102375. -85, -90, -96, -101, -108, -999, -999, -999,
  102376. -999, -999, -999, -999, -999, -999, -999, -999,
  102377. -999, -999, -999, -999, -999, -999, -999, -999},
  102378. { -46, -46, -46, -46, -46, -46, -46, -46,
  102379. -46, -46, -47, -47, -47, -47, -48, -51,
  102380. -57, -51, -49, -50, -51, -53, -54, -59,
  102381. -66, -60, -62, -67, -67, -70, -72, -75,
  102382. -76, -78, -81, -85, -88, -94, -97, -104,
  102383. -112, -999, -999, -999, -999, -999, -999, -999,
  102384. -999, -999, -999, -999, -999, -999, -999, -999},
  102385. { -36, -36, -36, -36, -36, -36, -36, -36,
  102386. -39, -41, -42, -42, -39, -38, -41, -43,
  102387. -52, -44, -40, -39, -37, -37, -40, -47,
  102388. -54, -50, -48, -50, -55, -61, -59, -62,
  102389. -66, -66, -66, -69, -69, -73, -74, -74,
  102390. -75, -77, -79, -82, -87, -91, -95, -100,
  102391. -108, -115, -999, -999, -999, -999, -999, -999},
  102392. { -28, -26, -24, -22, -20, -20, -23, -29,
  102393. -30, -31, -28, -27, -28, -28, -28, -35,
  102394. -40, -33, -32, -29, -30, -30, -30, -37,
  102395. -45, -41, -37, -38, -45, -47, -47, -48,
  102396. -53, -49, -48, -50, -49, -49, -51, -52,
  102397. -58, -56, -57, -56, -60, -61, -62, -70,
  102398. -72, -74, -78, -83, -88, -93, -100, -106}},
  102399. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102400. -999, -110, -105, -100, -95, -91, -87, -83,
  102401. -80, -78, -76, -78, -78, -81, -83, -85,
  102402. -86, -85, -86, -87, -90, -97, -107, -999,
  102403. -999, -999, -999, -999, -999, -999, -999, -999,
  102404. -999, -999, -999, -999, -999, -999, -999, -999,
  102405. -999, -999, -999, -999, -999, -999, -999, -999},
  102406. {-999, -999, -999, -110, -105, -100, -95, -90,
  102407. -85, -81, -77, -73, -70, -67, -67, -68,
  102408. -75, -73, -70, -69, -70, -72, -75, -79,
  102409. -84, -83, -84, -86, -88, -89, -89, -93,
  102410. -98, -105, -112, -999, -999, -999, -999, -999,
  102411. -999, -999, -999, -999, -999, -999, -999, -999,
  102412. -999, -999, -999, -999, -999, -999, -999, -999},
  102413. {-105, -100, -95, -90, -85, -80, -76, -71,
  102414. -68, -68, -65, -63, -63, -62, -62, -64,
  102415. -65, -64, -61, -62, -63, -64, -66, -68,
  102416. -73, -73, -74, -75, -76, -81, -83, -85,
  102417. -88, -89, -92, -95, -100, -108, -999, -999,
  102418. -999, -999, -999, -999, -999, -999, -999, -999,
  102419. -999, -999, -999, -999, -999, -999, -999, -999},
  102420. { -80, -75, -71, -68, -65, -63, -62, -61,
  102421. -61, -61, -61, -59, -56, -57, -53, -50,
  102422. -58, -52, -50, -50, -52, -53, -54, -58,
  102423. -67, -63, -67, -68, -72, -75, -78, -80,
  102424. -81, -81, -82, -85, -89, -90, -93, -97,
  102425. -101, -107, -114, -999, -999, -999, -999, -999,
  102426. -999, -999, -999, -999, -999, -999, -999, -999},
  102427. { -65, -61, -59, -57, -56, -55, -55, -56,
  102428. -56, -57, -55, -53, -52, -47, -44, -44,
  102429. -50, -44, -41, -39, -39, -42, -40, -46,
  102430. -51, -49, -50, -53, -54, -63, -60, -61,
  102431. -62, -66, -66, -66, -70, -73, -74, -75,
  102432. -76, -75, -79, -85, -89, -91, -96, -102,
  102433. -110, -999, -999, -999, -999, -999, -999, -999},
  102434. { -52, -50, -49, -49, -48, -48, -48, -49,
  102435. -50, -50, -49, -46, -43, -39, -35, -33,
  102436. -38, -36, -32, -29, -32, -32, -32, -35,
  102437. -44, -39, -38, -38, -46, -50, -45, -46,
  102438. -53, -50, -50, -50, -54, -54, -53, -53,
  102439. -56, -57, -59, -66, -70, -72, -74, -79,
  102440. -83, -85, -90, -97, -114, -999, -999, -999}},
  102441. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102442. -100, -95, -90, -86, -80, -75, -75, -79,
  102443. -80, -79, -80, -81, -82, -88, -95, -103,
  102444. -110, -999, -999, -999, -999, -999, -999, -999,
  102445. -999, -999, -999, -999, -999, -999, -999, -999,
  102446. -999, -999, -999, -999, -999, -999, -999, -999,
  102447. -999, -999, -999, -999, -999, -999, -999, -999},
  102448. {-999, -999, -999, -999, -108, -103, -98, -93,
  102449. -88, -83, -79, -78, -75, -71, -67, -68,
  102450. -73, -73, -72, -73, -75, -77, -80, -82,
  102451. -88, -93, -100, -107, -114, -999, -999, -999,
  102452. -999, -999, -999, -999, -999, -999, -999, -999,
  102453. -999, -999, -999, -999, -999, -999, -999, -999,
  102454. -999, -999, -999, -999, -999, -999, -999, -999},
  102455. {-999, -999, -999, -110, -105, -101, -96, -90,
  102456. -86, -81, -77, -73, -69, -66, -61, -62,
  102457. -66, -64, -62, -65, -66, -70, -72, -76,
  102458. -81, -80, -84, -90, -95, -102, -110, -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, -999, -999, -107, -103, -97, -92, -88,
  102463. -83, -79, -74, -70, -66, -59, -53, -58,
  102464. -62, -55, -54, -54, -54, -58, -61, -62,
  102465. -72, -70, -72, -75, -78, -80, -81, -80,
  102466. -83, -83, -88, -93, -100, -107, -115, -999,
  102467. -999, -999, -999, -999, -999, -999, -999, -999,
  102468. -999, -999, -999, -999, -999, -999, -999, -999},
  102469. {-999, -999, -999, -105, -100, -95, -90, -85,
  102470. -80, -75, -70, -66, -62, -56, -48, -44,
  102471. -48, -46, -46, -43, -46, -48, -48, -51,
  102472. -58, -58, -59, -60, -62, -62, -61, -61,
  102473. -65, -64, -65, -68, -70, -74, -75, -78,
  102474. -81, -86, -95, -110, -999, -999, -999, -999,
  102475. -999, -999, -999, -999, -999, -999, -999, -999},
  102476. {-999, -999, -105, -100, -95, -90, -85, -80,
  102477. -75, -70, -65, -61, -55, -49, -39, -33,
  102478. -40, -35, -32, -38, -40, -33, -35, -37,
  102479. -46, -41, -45, -44, -46, -42, -45, -46,
  102480. -52, -50, -50, -50, -54, -54, -55, -57,
  102481. -62, -64, -66, -68, -70, -76, -81, -90,
  102482. -100, -110, -999, -999, -999, -999, -999, -999}},
  102483. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102484. -105, -98, -90, -85, -82, -83, -80, -78,
  102485. -84, -79, -80, -83, -87, -89, -91, -93,
  102486. -99, -106, -117, -999, -999, -999, -999, -999,
  102487. -999, -999, -999, -999, -999, -999, -999, -999,
  102488. -999, -999, -999, -999, -999, -999, -999, -999,
  102489. -999, -999, -999, -999, -999, -999, -999, -999},
  102490. {-999, -999, -999, -999, -999, -999, -999, -999,
  102491. -105, -98, -90, -85, -80, -75, -70, -68,
  102492. -74, -72, -74, -77, -80, -82, -85, -87,
  102493. -92, -89, -91, -95, -100, -106, -112, -999,
  102494. -999, -999, -999, -999, -999, -999, -999, -999,
  102495. -999, -999, -999, -999, -999, -999, -999, -999,
  102496. -999, -999, -999, -999, -999, -999, -999, -999},
  102497. {-999, -999, -999, -999, -999, -999, -999, -999,
  102498. -105, -98, -90, -83, -75, -71, -63, -64,
  102499. -67, -62, -64, -67, -70, -73, -77, -81,
  102500. -84, -83, -85, -89, -90, -93, -98, -104,
  102501. -109, -114, -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, -999, -999, -999, -999, -999, -999, -999,
  102505. -103, -96, -88, -81, -75, -68, -58, -54,
  102506. -56, -54, -56, -56, -58, -60, -63, -66,
  102507. -74, -69, -72, -72, -75, -74, -77, -81,
  102508. -81, -82, -84, -87, -93, -96, -99, -104,
  102509. -110, -999, -999, -999, -999, -999, -999, -999,
  102510. -999, -999, -999, -999, -999, -999, -999, -999},
  102511. {-999, -999, -999, -999, -999, -108, -102, -96,
  102512. -91, -85, -80, -74, -68, -60, -51, -46,
  102513. -48, -46, -43, -45, -47, -47, -49, -48,
  102514. -56, -53, -55, -58, -57, -63, -58, -60,
  102515. -66, -64, -67, -70, -70, -74, -77, -84,
  102516. -86, -89, -91, -93, -94, -101, -109, -118,
  102517. -999, -999, -999, -999, -999, -999, -999, -999},
  102518. {-999, -999, -999, -108, -103, -98, -93, -88,
  102519. -83, -78, -73, -68, -60, -53, -44, -35,
  102520. -38, -38, -34, -34, -36, -40, -41, -44,
  102521. -51, -45, -46, -47, -46, -54, -50, -49,
  102522. -50, -50, -50, -51, -54, -57, -58, -60,
  102523. -66, -66, -66, -64, -65, -68, -77, -82,
  102524. -87, -95, -110, -999, -999, -999, -999, -999}},
  102525. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102526. -107, -102, -97, -92, -87, -83, -78, -75,
  102527. -82, -79, -83, -85, -89, -92, -95, -98,
  102528. -101, -105, -109, -113, -999, -999, -999, -999,
  102529. -999, -999, -999, -999, -999, -999, -999, -999,
  102530. -999, -999, -999, -999, -999, -999, -999, -999,
  102531. -999, -999, -999, -999, -999, -999, -999, -999},
  102532. {-999, -999, -999, -999, -999, -999, -999, -106,
  102533. -100, -95, -90, -86, -81, -78, -74, -69,
  102534. -74, -74, -76, -79, -83, -84, -86, -89,
  102535. -92, -97, -93, -100, -103, -107, -110, -999,
  102536. -999, -999, -999, -999, -999, -999, -999, -999,
  102537. -999, -999, -999, -999, -999, -999, -999, -999,
  102538. -999, -999, -999, -999, -999, -999, -999, -999},
  102539. {-999, -999, -999, -999, -999, -999, -106, -100,
  102540. -95, -90, -87, -83, -80, -75, -69, -60,
  102541. -66, -66, -68, -70, -74, -78, -79, -81,
  102542. -81, -83, -84, -87, -93, -96, -99, -103,
  102543. -107, -110, -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, -999, -999, -999, -108, -103, -98,
  102547. -93, -89, -85, -82, -78, -71, -62, -55,
  102548. -58, -58, -54, -54, -55, -59, -61, -62,
  102549. -70, -66, -66, -67, -70, -72, -75, -78,
  102550. -84, -84, -84, -88, -91, -90, -95, -98,
  102551. -102, -103, -106, -110, -999, -999, -999, -999,
  102552. -999, -999, -999, -999, -999, -999, -999, -999},
  102553. {-999, -999, -999, -999, -108, -103, -98, -94,
  102554. -90, -87, -82, -79, -73, -67, -58, -47,
  102555. -50, -45, -41, -45, -48, -44, -44, -49,
  102556. -54, -51, -48, -47, -49, -50, -51, -57,
  102557. -58, -60, -63, -69, -70, -69, -71, -74,
  102558. -78, -82, -90, -95, -101, -105, -110, -999,
  102559. -999, -999, -999, -999, -999, -999, -999, -999},
  102560. {-999, -999, -999, -105, -101, -97, -93, -90,
  102561. -85, -80, -77, -72, -65, -56, -48, -37,
  102562. -40, -36, -34, -40, -50, -47, -38, -41,
  102563. -47, -38, -35, -39, -38, -43, -40, -45,
  102564. -50, -45, -44, -47, -50, -55, -48, -48,
  102565. -52, -66, -70, -76, -82, -90, -97, -105,
  102566. -110, -999, -999, -999, -999, -999, -999, -999}},
  102567. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102568. -999, -108, -103, -98, -93, -86, -79, -76,
  102569. -83, -81, -85, -87, -89, -93, -98, -102,
  102570. -107, -112, -999, -999, -999, -999, -999, -999,
  102571. -999, -999, -999, -999, -999, -999, -999, -999,
  102572. -999, -999, -999, -999, -999, -999, -999, -999,
  102573. -999, -999, -999, -999, -999, -999, -999, -999},
  102574. {-999, -999, -999, -999, -999, -999, -999, -999,
  102575. -999, -108, -103, -98, -93, -86, -79, -71,
  102576. -77, -74, -77, -79, -81, -84, -85, -90,
  102577. -92, -93, -92, -98, -101, -108, -112, -999,
  102578. -999, -999, -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, -999, -999, -999, -999, -999,
  102582. -108, -103, -98, -93, -87, -78, -68, -65,
  102583. -66, -62, -65, -67, -70, -73, -75, -78,
  102584. -82, -82, -83, -84, -91, -93, -98, -102,
  102585. -106, -110, -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, -999, -999, -999, -999, -999, -999,
  102589. -105, -100, -95, -90, -82, -74, -62, -57,
  102590. -58, -56, -51, -52, -52, -54, -54, -58,
  102591. -66, -59, -60, -63, -66, -69, -73, -79,
  102592. -83, -84, -80, -81, -81, -82, -88, -92,
  102593. -98, -105, -113, -999, -999, -999, -999, -999,
  102594. -999, -999, -999, -999, -999, -999, -999, -999},
  102595. {-999, -999, -999, -999, -999, -999, -999, -107,
  102596. -102, -97, -92, -84, -79, -69, -57, -47,
  102597. -52, -47, -44, -45, -50, -52, -42, -42,
  102598. -53, -43, -43, -48, -51, -56, -55, -52,
  102599. -57, -59, -61, -62, -67, -71, -78, -83,
  102600. -86, -94, -98, -103, -110, -999, -999, -999,
  102601. -999, -999, -999, -999, -999, -999, -999, -999},
  102602. {-999, -999, -999, -999, -999, -999, -105, -100,
  102603. -95, -90, -84, -78, -70, -61, -51, -41,
  102604. -40, -38, -40, -46, -52, -51, -41, -40,
  102605. -46, -40, -38, -38, -41, -46, -41, -46,
  102606. -47, -43, -43, -45, -41, -45, -56, -67,
  102607. -68, -83, -87, -90, -95, -102, -107, -113,
  102608. -999, -999, -999, -999, -999, -999, -999, -999}},
  102609. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102610. -999, -109, -105, -101, -96, -91, -84, -77,
  102611. -82, -82, -85, -89, -94, -100, -106, -110,
  102612. -999, -999, -999, -999, -999, -999, -999, -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, -999, -999, -999, -999, -999, -999, -999,
  102617. -999, -106, -103, -98, -92, -85, -80, -71,
  102618. -75, -72, -76, -80, -84, -86, -89, -93,
  102619. -100, -107, -113, -999, -999, -999, -999, -999,
  102620. -999, -999, -999, -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, -999, -999, -999, -107,
  102624. -104, -101, -97, -92, -88, -84, -80, -64,
  102625. -66, -63, -64, -66, -69, -73, -77, -83,
  102626. -83, -86, -91, -98, -104, -111, -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, -999, -999, -999, -107,
  102631. -104, -101, -97, -92, -90, -84, -74, -57,
  102632. -58, -52, -55, -54, -50, -52, -50, -52,
  102633. -63, -62, -69, -76, -77, -78, -78, -79,
  102634. -82, -88, -94, -100, -106, -111, -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, -999, -999, -106, -102,
  102638. -98, -95, -90, -85, -83, -78, -70, -50,
  102639. -50, -41, -44, -49, -47, -50, -50, -44,
  102640. -55, -46, -47, -48, -48, -54, -49, -49,
  102641. -58, -62, -71, -81, -87, -92, -97, -102,
  102642. -108, -114, -999, -999, -999, -999, -999, -999,
  102643. -999, -999, -999, -999, -999, -999, -999, -999},
  102644. {-999, -999, -999, -999, -999, -999, -106, -102,
  102645. -98, -95, -90, -85, -83, -78, -70, -45,
  102646. -43, -41, -47, -50, -51, -50, -49, -45,
  102647. -47, -41, -44, -41, -39, -43, -38, -37,
  102648. -40, -41, -44, -50, -58, -65, -73, -79,
  102649. -85, -92, -97, -101, -105, -109, -113, -999,
  102650. -999, -999, -999, -999, -999, -999, -999, -999}},
  102651. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102652. -999, -999, -999, -107, -100, -95, -87, -81,
  102653. -85, -83, -88, -93, -100, -107, -114, -999,
  102654. -999, -999, -999, -999, -999, -999, -999, -999,
  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, -999, -999, -999, -999, -999, -999,
  102659. -999, -999, -107, -101, -95, -88, -83, -76,
  102660. -73, -72, -79, -84, -90, -95, -100, -105,
  102661. -110, -115, -999, -999, -999, -999, -999, -999,
  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, -999, -999, -999,
  102666. -999, -999, -104, -98, -92, -87, -81, -70,
  102667. -65, -62, -67, -71, -74, -80, -85, -91,
  102668. -95, -99, -103, -108, -111, -114, -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, -999, -999, -999,
  102673. -999, -999, -103, -97, -90, -85, -76, -60,
  102674. -56, -54, -60, -62, -61, -56, -63, -65,
  102675. -73, -74, -77, -75, -78, -81, -86, -87,
  102676. -88, -91, -94, -98, -103, -110, -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, -999, -999, -999, -105,
  102680. -100, -97, -92, -86, -81, -79, -70, -57,
  102681. -51, -47, -51, -58, -60, -56, -53, -50,
  102682. -58, -52, -50, -50, -53, -55, -64, -69,
  102683. -71, -85, -82, -78, -81, -85, -95, -102,
  102684. -112, -999, -999, -999, -999, -999, -999, -999,
  102685. -999, -999, -999, -999, -999, -999, -999, -999},
  102686. {-999, -999, -999, -999, -999, -999, -999, -105,
  102687. -100, -97, -92, -85, -83, -79, -72, -49,
  102688. -40, -43, -43, -54, -56, -51, -50, -40,
  102689. -43, -38, -36, -35, -37, -38, -37, -44,
  102690. -54, -60, -57, -60, -70, -75, -84, -92,
  102691. -103, -112, -999, -999, -999, -999, -999, -999,
  102692. -999, -999, -999, -999, -999, -999, -999, -999}},
  102693. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102694. -999, -999, -999, -110, -102, -95, -89, -82,
  102695. -83, -84, -90, -92, -99, -107, -113, -999,
  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, -999, -999, -999, -999, -999,
  102701. -999, -999, -107, -101, -95, -89, -83, -72,
  102702. -74, -78, -85, -88, -88, -90, -92, -98,
  102703. -105, -111, -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, -999, -999, -999, -999, -999,
  102708. -999, -109, -103, -97, -93, -87, -81, -70,
  102709. -70, -67, -75, -73, -76, -79, -81, -83,
  102710. -88, -89, -97, -103, -110, -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, -999, -999, -999, -999, -999, -999,
  102715. -999, -107, -100, -94, -88, -83, -75, -63,
  102716. -59, -59, -63, -66, -60, -62, -67, -67,
  102717. -77, -76, -81, -88, -86, -92, -96, -102,
  102718. -109, -116, -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, -999, -999, -999, -999, -999, -999,
  102722. -999, -105, -98, -92, -86, -81, -73, -56,
  102723. -52, -47, -55, -60, -58, -52, -51, -45,
  102724. -49, -50, -53, -54, -61, -71, -70, -69,
  102725. -78, -79, -87, -90, -96, -104, -112, -999,
  102726. -999, -999, -999, -999, -999, -999, -999, -999,
  102727. -999, -999, -999, -999, -999, -999, -999, -999},
  102728. {-999, -999, -999, -999, -999, -999, -999, -999,
  102729. -999, -103, -96, -90, -86, -78, -70, -51,
  102730. -42, -47, -48, -55, -54, -54, -53, -42,
  102731. -35, -28, -33, -38, -37, -44, -47, -49,
  102732. -54, -63, -68, -78, -82, -89, -94, -99,
  102733. -104, -109, -114, -999, -999, -999, -999, -999,
  102734. -999, -999, -999, -999, -999, -999, -999, -999}},
  102735. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102736. -999, -999, -999, -999, -110, -100, -90, -79,
  102737. -85, -81, -82, -82, -89, -94, -99, -103,
  102738. -109, -115, -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, -999, -999, -999, -999, -999, -999, -999,
  102743. -999, -999, -999, -999, -105, -97, -85, -72,
  102744. -74, -70, -70, -70, -76, -85, -91, -93,
  102745. -97, -103, -109, -115, -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, -999, -999, -999, -999,
  102750. -999, -999, -999, -999, -112, -93, -81, -68,
  102751. -62, -60, -60, -57, -63, -70, -77, -82,
  102752. -90, -93, -98, -104, -109, -113, -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, -999, -999, -999, -999,
  102757. -999, -999, -999, -113, -100, -93, -84, -63,
  102758. -58, -48, -53, -54, -52, -52, -57, -64,
  102759. -66, -76, -83, -81, -85, -85, -90, -95,
  102760. -98, -101, -103, -106, -108, -111, -999, -999,
  102761. -999, -999, -999, -999, -999, -999, -999, -999,
  102762. -999, -999, -999, -999, -999, -999, -999, -999},
  102763. {-999, -999, -999, -999, -999, -999, -999, -999,
  102764. -999, -999, -999, -105, -95, -86, -74, -53,
  102765. -50, -38, -43, -49, -43, -42, -39, -39,
  102766. -46, -52, -57, -56, -72, -69, -74, -81,
  102767. -87, -92, -94, -97, -99, -102, -105, -108,
  102768. -999, -999, -999, -999, -999, -999, -999, -999,
  102769. -999, -999, -999, -999, -999, -999, -999, -999},
  102770. {-999, -999, -999, -999, -999, -999, -999, -999,
  102771. -999, -999, -108, -99, -90, -76, -66, -45,
  102772. -43, -41, -44, -47, -43, -47, -40, -30,
  102773. -31, -31, -39, -33, -40, -41, -43, -53,
  102774. -59, -70, -73, -77, -79, -82, -84, -87,
  102775. -999, -999, -999, -999, -999, -999, -999, -999,
  102776. -999, -999, -999, -999, -999, -999, -999, -999}},
  102777. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102778. -999, -999, -999, -999, -999, -110, -91, -76,
  102779. -75, -85, -93, -98, -104, -110, -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, -999, -999, -999, -999, -999,
  102785. -999, -999, -999, -999, -999, -110, -91, -70,
  102786. -70, -75, -86, -89, -94, -98, -101, -106,
  102787. -110, -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, -999, -999, -999,
  102792. -999, -999, -999, -999, -110, -95, -80, -60,
  102793. -65, -64, -74, -83, -88, -91, -95, -99,
  102794. -103, -107, -110, -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, -999, -999, -999,
  102799. -999, -999, -999, -999, -110, -95, -80, -58,
  102800. -55, -49, -66, -68, -71, -78, -78, -80,
  102801. -88, -85, -89, -97, -100, -105, -110, -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, -999, -999, -999,
  102806. -999, -999, -999, -999, -110, -95, -80, -53,
  102807. -52, -41, -59, -59, -49, -58, -56, -63,
  102808. -86, -79, -90, -93, -98, -103, -107, -112,
  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, -999, -999, -999,
  102813. -999, -999, -999, -110, -97, -91, -73, -45,
  102814. -40, -33, -53, -61, -49, -54, -50, -50,
  102815. -60, -52, -67, -74, -81, -92, -96, -100,
  102816. -105, -110, -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, -999, -999, -999, -999,
  102820. -999, -999, -999, -113, -106, -99, -92, -77,
  102821. -80, -88, -97, -106, -115, -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, -999, -999, -999, -999,
  102827. -999, -999, -116, -109, -102, -95, -89, -74,
  102828. -72, -88, -87, -95, -102, -109, -116, -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, -999, -999, -999, -999, -999,
  102834. -999, -999, -116, -109, -102, -95, -89, -75,
  102835. -66, -74, -77, -78, -86, -87, -90, -96,
  102836. -105, -115, -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, -999, -999, -999, -999, -999,
  102841. -999, -999, -115, -108, -101, -94, -88, -66,
  102842. -56, -61, -70, -65, -78, -72, -83, -84,
  102843. -93, -98, -105, -110, -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, -999, -999, -999, -999, -999,
  102848. -999, -999, -110, -105, -95, -89, -82, -57,
  102849. -52, -52, -59, -56, -59, -58, -69, -67,
  102850. -88, -82, -82, -89, -94, -100, -108, -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, -999, -999, -999, -999, -999,
  102855. -999, -110, -101, -96, -90, -83, -77, -54,
  102856. -43, -38, -50, -48, -52, -48, -42, -42,
  102857. -51, -52, -53, -59, -65, -71, -78, -85,
  102858. -95, -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, -999, -999, -999, -999, -999,
  102862. -999, -999, -999, -999, -120, -105, -86, -68,
  102863. -78, -79, -90, -100, -110, -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, -999, -999, -999, -999, -999,
  102869. -999, -999, -999, -999, -120, -105, -86, -66,
  102870. -73, -77, -88, -96, -105, -115, -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. -999, -999, -999, -999, -999, -999, -999, -999},
  102875. {-999, -999, -999, -999, -999, -999, -999, -999,
  102876. -999, -999, -999, -120, -105, -92, -80, -61,
  102877. -64, -68, -80, -87, -92, -100, -110, -999,
  102878. -999, -999, -999, -999, -999, -999, -999, -999,
  102879. -999, -999, -999, -999, -999, -999, -999, -999,
  102880. -999, -999, -999, -999, -999, -999, -999, -999,
  102881. -999, -999, -999, -999, -999, -999, -999, -999},
  102882. {-999, -999, -999, -999, -999, -999, -999, -999,
  102883. -999, -999, -999, -120, -104, -91, -79, -52,
  102884. -60, -54, -64, -69, -77, -80, -82, -84,
  102885. -85, -87, -88, -90, -999, -999, -999, -999,
  102886. -999, -999, -999, -999, -999, -999, -999, -999,
  102887. -999, -999, -999, -999, -999, -999, -999, -999,
  102888. -999, -999, -999, -999, -999, -999, -999, -999},
  102889. {-999, -999, -999, -999, -999, -999, -999, -999,
  102890. -999, -999, -999, -118, -100, -87, -77, -49,
  102891. -50, -44, -58, -61, -61, -67, -65, -62,
  102892. -62, -62, -65, -68, -999, -999, -999, -999,
  102893. -999, -999, -999, -999, -999, -999, -999, -999,
  102894. -999, -999, -999, -999, -999, -999, -999, -999,
  102895. -999, -999, -999, -999, -999, -999, -999, -999},
  102896. {-999, -999, -999, -999, -999, -999, -999, -999,
  102897. -999, -999, -999, -115, -98, -84, -62, -49,
  102898. -44, -38, -46, -49, -49, -46, -39, -37,
  102899. -39, -40, -42, -43, -999, -999, -999, -999,
  102900. -999, -999, -999, -999, -999, -999, -999, -999,
  102901. -999, -999, -999, -999, -999, -999, -999, -999,
  102902. -999, -999, -999, -999, -999, -999, -999, -999}},
  102903. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102904. -999, -999, -999, -999, -999, -110, -88, -74,
  102905. -77, -82, -82, -85, -90, -94, -99, -104,
  102906. -999, -999, -999, -999, -999, -999, -999, -999,
  102907. -999, -999, -999, -999, -999, -999, -999, -999,
  102908. -999, -999, -999, -999, -999, -999, -999, -999,
  102909. -999, -999, -999, -999, -999, -999, -999, -999},
  102910. {-999, -999, -999, -999, -999, -999, -999, -999,
  102911. -999, -999, -999, -999, -999, -110, -88, -66,
  102912. -70, -81, -80, -81, -84, -88, -91, -93,
  102913. -999, -999, -999, -999, -999, -999, -999, -999,
  102914. -999, -999, -999, -999, -999, -999, -999, -999,
  102915. -999, -999, -999, -999, -999, -999, -999, -999,
  102916. -999, -999, -999, -999, -999, -999, -999, -999},
  102917. {-999, -999, -999, -999, -999, -999, -999, -999,
  102918. -999, -999, -999, -999, -999, -110, -88, -61,
  102919. -63, -70, -71, -74, -77, -80, -83, -85,
  102920. -999, -999, -999, -999, -999, -999, -999, -999,
  102921. -999, -999, -999, -999, -999, -999, -999, -999,
  102922. -999, -999, -999, -999, -999, -999, -999, -999,
  102923. -999, -999, -999, -999, -999, -999, -999, -999},
  102924. {-999, -999, -999, -999, -999, -999, -999, -999,
  102925. -999, -999, -999, -999, -999, -110, -86, -62,
  102926. -63, -62, -62, -58, -52, -50, -50, -52,
  102927. -54, -999, -999, -999, -999, -999, -999, -999,
  102928. -999, -999, -999, -999, -999, -999, -999, -999,
  102929. -999, -999, -999, -999, -999, -999, -999, -999,
  102930. -999, -999, -999, -999, -999, -999, -999, -999},
  102931. {-999, -999, -999, -999, -999, -999, -999, -999,
  102932. -999, -999, -999, -999, -118, -108, -84, -53,
  102933. -50, -50, -50, -55, -47, -45, -40, -40,
  102934. -40, -999, -999, -999, -999, -999, -999, -999,
  102935. -999, -999, -999, -999, -999, -999, -999, -999,
  102936. -999, -999, -999, -999, -999, -999, -999, -999,
  102937. -999, -999, -999, -999, -999, -999, -999, -999},
  102938. {-999, -999, -999, -999, -999, -999, -999, -999,
  102939. -999, -999, -999, -999, -118, -100, -73, -43,
  102940. -37, -42, -43, -53, -38, -37, -35, -35,
  102941. -38, -999, -999, -999, -999, -999, -999, -999,
  102942. -999, -999, -999, -999, -999, -999, -999, -999,
  102943. -999, -999, -999, -999, -999, -999, -999, -999,
  102944. -999, -999, -999, -999, -999, -999, -999, -999}},
  102945. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102946. -999, -999, -999, -110, -100, -91, -84, -74,
  102947. -80, -80, -80, -80, -80, -999, -999, -999,
  102948. -999, -999, -999, -999, -999, -999, -999, -999,
  102949. -999, -999, -999, -999, -999, -999, -999, -999,
  102950. -999, -999, -999, -999, -999, -999, -999, -999,
  102951. -999, -999, -999, -999, -999, -999, -999, -999},
  102952. {-999, -999, -999, -999, -999, -999, -999, -999,
  102953. -999, -999, -999, -110, -100, -91, -84, -74,
  102954. -68, -68, -68, -68, -68, -999, -999, -999,
  102955. -999, -999, -999, -999, -999, -999, -999, -999,
  102956. -999, -999, -999, -999, -999, -999, -999, -999,
  102957. -999, -999, -999, -999, -999, -999, -999, -999,
  102958. -999, -999, -999, -999, -999, -999, -999, -999},
  102959. {-999, -999, -999, -999, -999, -999, -999, -999,
  102960. -999, -999, -999, -110, -100, -86, -78, -70,
  102961. -60, -45, -30, -21, -999, -999, -999, -999,
  102962. -999, -999, -999, -999, -999, -999, -999, -999,
  102963. -999, -999, -999, -999, -999, -999, -999, -999,
  102964. -999, -999, -999, -999, -999, -999, -999, -999,
  102965. -999, -999, -999, -999, -999, -999, -999, -999},
  102966. {-999, -999, -999, -999, -999, -999, -999, -999,
  102967. -999, -999, -999, -110, -100, -87, -78, -67,
  102968. -48, -38, -29, -21, -999, -999, -999, -999,
  102969. -999, -999, -999, -999, -999, -999, -999, -999,
  102970. -999, -999, -999, -999, -999, -999, -999, -999,
  102971. -999, -999, -999, -999, -999, -999, -999, -999,
  102972. -999, -999, -999, -999, -999, -999, -999, -999},
  102973. {-999, -999, -999, -999, -999, -999, -999, -999,
  102974. -999, -999, -999, -110, -100, -86, -69, -56,
  102975. -45, -35, -33, -29, -999, -999, -999, -999,
  102976. -999, -999, -999, -999, -999, -999, -999, -999,
  102977. -999, -999, -999, -999, -999, -999, -999, -999,
  102978. -999, -999, -999, -999, -999, -999, -999, -999,
  102979. -999, -999, -999, -999, -999, -999, -999, -999},
  102980. {-999, -999, -999, -999, -999, -999, -999, -999,
  102981. -999, -999, -999, -110, -100, -83, -71, -48,
  102982. -27, -38, -37, -34, -999, -999, -999, -999,
  102983. -999, -999, -999, -999, -999, -999, -999, -999,
  102984. -999, -999, -999, -999, -999, -999, -999, -999,
  102985. -999, -999, -999, -999, -999, -999, -999, -999,
  102986. -999, -999, -999, -999, -999, -999, -999, -999}}
  102987. };
  102988. #endif
  102989. /*** End of inlined file: masking.h ***/
  102990. #define NEGINF -9999.f
  102991. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  102992. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  102993. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  102994. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  102995. vorbis_info_psy_global *gi=&ci->psy_g_param;
  102996. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  102997. look->channels=vi->channels;
  102998. look->ampmax=-9999.;
  102999. look->gi=gi;
  103000. return(look);
  103001. }
  103002. void _vp_global_free(vorbis_look_psy_global *look){
  103003. if(look){
  103004. memset(look,0,sizeof(*look));
  103005. _ogg_free(look);
  103006. }
  103007. }
  103008. void _vi_gpsy_free(vorbis_info_psy_global *i){
  103009. if(i){
  103010. memset(i,0,sizeof(*i));
  103011. _ogg_free(i);
  103012. }
  103013. }
  103014. void _vi_psy_free(vorbis_info_psy *i){
  103015. if(i){
  103016. memset(i,0,sizeof(*i));
  103017. _ogg_free(i);
  103018. }
  103019. }
  103020. static void min_curve(float *c,
  103021. float *c2){
  103022. int i;
  103023. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103024. }
  103025. static void max_curve(float *c,
  103026. float *c2){
  103027. int i;
  103028. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103029. }
  103030. static void attenuate_curve(float *c,float att){
  103031. int i;
  103032. for(i=0;i<EHMER_MAX;i++)
  103033. c[i]+=att;
  103034. }
  103035. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103036. float center_boost, float center_decay_rate){
  103037. int i,j,k,m;
  103038. float ath[EHMER_MAX];
  103039. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103040. float athc[P_LEVELS][EHMER_MAX];
  103041. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103042. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103043. memset(workc,0,sizeof(workc));
  103044. for(i=0;i<P_BANDS;i++){
  103045. int ath_offset=i*4;
  103046. for(j=0;j<EHMER_MAX;j++){
  103047. float min=999.;
  103048. for(k=0;k<4;k++)
  103049. if(j+k+ath_offset<MAX_ATH){
  103050. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103051. }else{
  103052. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103053. }
  103054. ath[j]=min;
  103055. }
  103056. for(j=0;j<6;j++)
  103057. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103058. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103059. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103060. for(j=0;j<P_LEVELS;j++){
  103061. for(k=0;k<EHMER_MAX;k++){
  103062. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103063. if(adj<0. && center_boost>0)adj=0.;
  103064. if(adj>0. && center_boost<0)adj=0.;
  103065. workc[i][j][k]+=adj;
  103066. }
  103067. }
  103068. for(j=0;j<P_LEVELS;j++){
  103069. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103070. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103071. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103072. max_curve(athc[j],workc[i][j]);
  103073. }
  103074. for(j=1;j<P_LEVELS;j++){
  103075. min_curve(athc[j],athc[j-1]);
  103076. min_curve(workc[i][j],athc[j]);
  103077. }
  103078. }
  103079. for(i=0;i<P_BANDS;i++){
  103080. int hi_curve,lo_curve,bin;
  103081. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103082. bin=floor(fromOC(i*.5)/binHz);
  103083. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103084. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103085. if(lo_curve>i)lo_curve=i;
  103086. if(lo_curve<0)lo_curve=0;
  103087. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103088. for(m=0;m<P_LEVELS;m++){
  103089. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103090. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103091. for(k=lo_curve;k<=hi_curve;k++){
  103092. int l=0;
  103093. for(j=0;j<EHMER_MAX;j++){
  103094. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103095. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103096. if(lo_bin<0)lo_bin=0;
  103097. if(lo_bin>n)lo_bin=n;
  103098. if(lo_bin<l)l=lo_bin;
  103099. if(hi_bin<0)hi_bin=0;
  103100. if(hi_bin>n)hi_bin=n;
  103101. for(;l<hi_bin && l<n;l++)
  103102. if(brute_buffer[l]>workc[k][m][j])
  103103. brute_buffer[l]=workc[k][m][j];
  103104. }
  103105. for(;l<n;l++)
  103106. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103107. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103108. }
  103109. if(i+1<P_BANDS){
  103110. int l=0;
  103111. k=i+1;
  103112. for(j=0;j<EHMER_MAX;j++){
  103113. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103114. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103115. if(lo_bin<0)lo_bin=0;
  103116. if(lo_bin>n)lo_bin=n;
  103117. if(lo_bin<l)l=lo_bin;
  103118. if(hi_bin<0)hi_bin=0;
  103119. if(hi_bin>n)hi_bin=n;
  103120. for(;l<hi_bin && l<n;l++)
  103121. if(brute_buffer[l]>workc[k][m][j])
  103122. brute_buffer[l]=workc[k][m][j];
  103123. }
  103124. for(;l<n;l++)
  103125. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103126. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103127. }
  103128. for(j=0;j<EHMER_MAX;j++){
  103129. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103130. if(bin<0){
  103131. ret[i][m][j+2]=-999.;
  103132. }else{
  103133. if(bin>=n){
  103134. ret[i][m][j+2]=-999.;
  103135. }else{
  103136. ret[i][m][j+2]=brute_buffer[bin];
  103137. }
  103138. }
  103139. }
  103140. for(j=0;j<EHMER_OFFSET;j++)
  103141. if(ret[i][m][j+2]>-200.f)break;
  103142. ret[i][m][0]=j;
  103143. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103144. if(ret[i][m][j+2]>-200.f)
  103145. break;
  103146. ret[i][m][1]=j;
  103147. }
  103148. }
  103149. return(ret);
  103150. }
  103151. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103152. vorbis_info_psy_global *gi,int n,long rate){
  103153. long i,j,lo=-99,hi=1;
  103154. long maxoc;
  103155. memset(p,0,sizeof(*p));
  103156. p->eighth_octave_lines=gi->eighth_octave_lines;
  103157. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103158. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103159. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103160. p->total_octave_lines=maxoc-p->firstoc+1;
  103161. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103162. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103163. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103164. p->vi=vi;
  103165. p->n=n;
  103166. p->rate=rate;
  103167. p->m_val = 1.;
  103168. if(rate < 26000) p->m_val = 0;
  103169. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103170. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103171. for(i=0,j=0;i<MAX_ATH-1;i++){
  103172. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103173. float base=ATH[i];
  103174. if(j<endpos){
  103175. float delta=(ATH[i+1]-base)/(endpos-j);
  103176. for(;j<endpos && j<n;j++){
  103177. p->ath[j]=base+100.;
  103178. base+=delta;
  103179. }
  103180. }
  103181. }
  103182. for(i=0;i<n;i++){
  103183. float bark=toBARK(rate/(2*n)*i);
  103184. for(;lo+vi->noisewindowlomin<i &&
  103185. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103186. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103187. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103188. p->bark[i]=((lo-1)<<16)+(hi-1);
  103189. }
  103190. for(i=0;i<n;i++)
  103191. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103192. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103193. vi->tone_centerboost,vi->tone_decay);
  103194. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103195. for(i=0;i<P_NOISECURVES;i++)
  103196. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103197. for(i=0;i<n;i++){
  103198. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103199. int inthalfoc;
  103200. float del;
  103201. if(halfoc<0)halfoc=0;
  103202. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103203. inthalfoc=(int)halfoc;
  103204. del=halfoc-inthalfoc;
  103205. for(j=0;j<P_NOISECURVES;j++)
  103206. p->noiseoffset[j][i]=
  103207. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103208. p->vi->noiseoff[j][inthalfoc+1]*del;
  103209. }
  103210. #if 0
  103211. {
  103212. static int ls=0;
  103213. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103214. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103215. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103216. }
  103217. #endif
  103218. }
  103219. void _vp_psy_clear(vorbis_look_psy *p){
  103220. int i,j;
  103221. if(p){
  103222. if(p->ath)_ogg_free(p->ath);
  103223. if(p->octave)_ogg_free(p->octave);
  103224. if(p->bark)_ogg_free(p->bark);
  103225. if(p->tonecurves){
  103226. for(i=0;i<P_BANDS;i++){
  103227. for(j=0;j<P_LEVELS;j++){
  103228. _ogg_free(p->tonecurves[i][j]);
  103229. }
  103230. _ogg_free(p->tonecurves[i]);
  103231. }
  103232. _ogg_free(p->tonecurves);
  103233. }
  103234. if(p->noiseoffset){
  103235. for(i=0;i<P_NOISECURVES;i++){
  103236. _ogg_free(p->noiseoffset[i]);
  103237. }
  103238. _ogg_free(p->noiseoffset);
  103239. }
  103240. memset(p,0,sizeof(*p));
  103241. }
  103242. }
  103243. static void seed_curve(float *seed,
  103244. const float **curves,
  103245. float amp,
  103246. int oc, int n,
  103247. int linesper,float dBoffset){
  103248. int i,post1;
  103249. int seedptr;
  103250. const float *posts,*curve;
  103251. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103252. choice=max(choice,0);
  103253. choice=min(choice,P_LEVELS-1);
  103254. posts=curves[choice];
  103255. curve=posts+2;
  103256. post1=(int)posts[1];
  103257. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103258. for(i=posts[0];i<post1;i++){
  103259. if(seedptr>0){
  103260. float lin=amp+curve[i];
  103261. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103262. }
  103263. seedptr+=linesper;
  103264. if(seedptr>=n)break;
  103265. }
  103266. }
  103267. static void seed_loop(vorbis_look_psy *p,
  103268. const float ***curves,
  103269. const float *f,
  103270. const float *flr,
  103271. float *seed,
  103272. float specmax){
  103273. vorbis_info_psy *vi=p->vi;
  103274. long n=p->n,i;
  103275. float dBoffset=vi->max_curve_dB-specmax;
  103276. for(i=0;i<n;i++){
  103277. float max=f[i];
  103278. long oc=p->octave[i];
  103279. while(i+1<n && p->octave[i+1]==oc){
  103280. i++;
  103281. if(f[i]>max)max=f[i];
  103282. }
  103283. if(max+6.f>flr[i]){
  103284. oc=oc>>p->shiftoc;
  103285. if(oc>=P_BANDS)oc=P_BANDS-1;
  103286. if(oc<0)oc=0;
  103287. seed_curve(seed,
  103288. curves[oc],
  103289. max,
  103290. p->octave[i]-p->firstoc,
  103291. p->total_octave_lines,
  103292. p->eighth_octave_lines,
  103293. dBoffset);
  103294. }
  103295. }
  103296. }
  103297. static void seed_chase(float *seeds, int linesper, long n){
  103298. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103299. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103300. long stack=0;
  103301. long pos=0;
  103302. long i;
  103303. for(i=0;i<n;i++){
  103304. if(stack<2){
  103305. posstack[stack]=i;
  103306. ampstack[stack++]=seeds[i];
  103307. }else{
  103308. while(1){
  103309. if(seeds[i]<ampstack[stack-1]){
  103310. posstack[stack]=i;
  103311. ampstack[stack++]=seeds[i];
  103312. break;
  103313. }else{
  103314. if(i<posstack[stack-1]+linesper){
  103315. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103316. i<posstack[stack-2]+linesper){
  103317. stack--;
  103318. continue;
  103319. }
  103320. }
  103321. posstack[stack]=i;
  103322. ampstack[stack++]=seeds[i];
  103323. break;
  103324. }
  103325. }
  103326. }
  103327. }
  103328. for(i=0;i<stack;i++){
  103329. long endpos;
  103330. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103331. endpos=posstack[i+1];
  103332. }else{
  103333. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103334. discarded in short frames */
  103335. }
  103336. if(endpos>n)endpos=n;
  103337. for(;pos<endpos;pos++)
  103338. seeds[pos]=ampstack[i];
  103339. }
  103340. }
  103341. #include<stdio.h>
  103342. static void max_seeds(vorbis_look_psy *p,
  103343. float *seed,
  103344. float *flr){
  103345. long n=p->total_octave_lines;
  103346. int linesper=p->eighth_octave_lines;
  103347. long linpos=0;
  103348. long pos;
  103349. seed_chase(seed,linesper,n); /* for masking */
  103350. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103351. while(linpos+1<p->n){
  103352. float minV=seed[pos];
  103353. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103354. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103355. while(pos+1<=end){
  103356. pos++;
  103357. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103358. minV=seed[pos];
  103359. }
  103360. end=pos+p->firstoc;
  103361. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103362. if(flr[linpos]<minV)flr[linpos]=minV;
  103363. }
  103364. {
  103365. float minV=seed[p->total_octave_lines-1];
  103366. for(;linpos<p->n;linpos++)
  103367. if(flr[linpos]<minV)flr[linpos]=minV;
  103368. }
  103369. }
  103370. static void bark_noise_hybridmp(int n,const long *b,
  103371. const float *f,
  103372. float *noise,
  103373. const float offset,
  103374. const int fixed){
  103375. float *N=(float*) alloca(n*sizeof(*N));
  103376. float *X=(float*) alloca(n*sizeof(*N));
  103377. float *XX=(float*) alloca(n*sizeof(*N));
  103378. float *Y=(float*) alloca(n*sizeof(*N));
  103379. float *XY=(float*) alloca(n*sizeof(*N));
  103380. float tN, tX, tXX, tY, tXY;
  103381. int i;
  103382. int lo, hi;
  103383. float R, A, B, D;
  103384. float w, x, y;
  103385. tN = tX = tXX = tY = tXY = 0.f;
  103386. y = f[0] + offset;
  103387. if (y < 1.f) y = 1.f;
  103388. w = y * y * .5;
  103389. tN += w;
  103390. tX += w;
  103391. tY += w * y;
  103392. N[0] = tN;
  103393. X[0] = tX;
  103394. XX[0] = tXX;
  103395. Y[0] = tY;
  103396. XY[0] = tXY;
  103397. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103398. y = f[i] + offset;
  103399. if (y < 1.f) y = 1.f;
  103400. w = y * y;
  103401. tN += w;
  103402. tX += w * x;
  103403. tXX += w * x * x;
  103404. tY += w * y;
  103405. tXY += w * x * y;
  103406. N[i] = tN;
  103407. X[i] = tX;
  103408. XX[i] = tXX;
  103409. Y[i] = tY;
  103410. XY[i] = tXY;
  103411. }
  103412. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103413. lo = b[i] >> 16;
  103414. if( lo>=0 ) break;
  103415. hi = b[i] & 0xffff;
  103416. tN = N[hi] + N[-lo];
  103417. tX = X[hi] - X[-lo];
  103418. tXX = XX[hi] + XX[-lo];
  103419. tY = Y[hi] + Y[-lo];
  103420. tXY = XY[hi] - XY[-lo];
  103421. A = tY * tXX - tX * tXY;
  103422. B = tN * tXY - tX * tY;
  103423. D = tN * tXX - tX * tX;
  103424. R = (A + x * B) / D;
  103425. if (R < 0.f)
  103426. R = 0.f;
  103427. noise[i] = R - offset;
  103428. }
  103429. for ( ;; i++, x += 1.f) {
  103430. lo = b[i] >> 16;
  103431. hi = b[i] & 0xffff;
  103432. if(hi>=n)break;
  103433. tN = N[hi] - N[lo];
  103434. tX = X[hi] - X[lo];
  103435. tXX = XX[hi] - XX[lo];
  103436. tY = Y[hi] - Y[lo];
  103437. tXY = XY[hi] - XY[lo];
  103438. A = tY * tXX - tX * tXY;
  103439. B = tN * tXY - tX * tY;
  103440. D = tN * tXX - tX * tX;
  103441. R = (A + x * B) / D;
  103442. if (R < 0.f) R = 0.f;
  103443. noise[i] = R - offset;
  103444. }
  103445. for ( ; i < n; i++, x += 1.f) {
  103446. R = (A + x * B) / D;
  103447. if (R < 0.f) R = 0.f;
  103448. noise[i] = R - offset;
  103449. }
  103450. if (fixed <= 0) return;
  103451. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103452. hi = i + fixed / 2;
  103453. lo = hi - fixed;
  103454. if(lo>=0)break;
  103455. tN = N[hi] + N[-lo];
  103456. tX = X[hi] - X[-lo];
  103457. tXX = XX[hi] + XX[-lo];
  103458. tY = Y[hi] + Y[-lo];
  103459. tXY = XY[hi] - XY[-lo];
  103460. A = tY * tXX - tX * tXY;
  103461. B = tN * tXY - tX * tY;
  103462. D = tN * tXX - tX * tX;
  103463. R = (A + x * B) / D;
  103464. if (R - offset < noise[i]) noise[i] = R - offset;
  103465. }
  103466. for ( ;; i++, x += 1.f) {
  103467. hi = i + fixed / 2;
  103468. lo = hi - fixed;
  103469. if(hi>=n)break;
  103470. tN = N[hi] - N[lo];
  103471. tX = X[hi] - X[lo];
  103472. tXX = XX[hi] - XX[lo];
  103473. tY = Y[hi] - Y[lo];
  103474. tXY = XY[hi] - XY[lo];
  103475. A = tY * tXX - tX * tXY;
  103476. B = tN * tXY - tX * tY;
  103477. D = tN * tXX - tX * tX;
  103478. R = (A + x * B) / D;
  103479. if (R - offset < noise[i]) noise[i] = R - offset;
  103480. }
  103481. for ( ; i < n; i++, x += 1.f) {
  103482. R = (A + x * B) / D;
  103483. if (R - offset < noise[i]) noise[i] = R - offset;
  103484. }
  103485. }
  103486. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103487. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103488. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103489. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103490. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103491. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103492. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103493. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103494. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103495. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103496. 973377.F, 913981.F, 858210.F, 805842.F,
  103497. 756669.F, 710497.F, 667142.F, 626433.F,
  103498. 588208.F, 552316.F, 518613.F, 486967.F,
  103499. 457252.F, 429351.F, 403152.F, 378551.F,
  103500. 355452.F, 333762.F, 313396.F, 294273.F,
  103501. 276316.F, 259455.F, 243623.F, 228757.F,
  103502. 214798.F, 201691.F, 189384.F, 177828.F,
  103503. 166977.F, 156788.F, 147221.F, 138237.F,
  103504. 129802.F, 121881.F, 114444.F, 107461.F,
  103505. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103506. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103507. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103508. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103509. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103510. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103511. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103512. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103513. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103514. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103515. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103516. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103517. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103518. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103519. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103520. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103521. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103522. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103523. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103524. 842.910F, 791.475F, 743.179F, 697.830F,
  103525. 655.249F, 615.265F, 577.722F, 542.469F,
  103526. 509.367F, 478.286F, 449.101F, 421.696F,
  103527. 395.964F, 371.803F, 349.115F, 327.812F,
  103528. 307.809F, 289.026F, 271.390F, 254.830F,
  103529. 239.280F, 224.679F, 210.969F, 198.096F,
  103530. 186.008F, 174.658F, 164.000F, 153.993F,
  103531. 144.596F, 135.773F, 127.488F, 119.708F,
  103532. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103533. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103534. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  103535. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  103536. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  103537. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  103538. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  103539. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  103540. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  103541. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  103542. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  103543. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  103544. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  103545. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  103546. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  103547. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  103548. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  103549. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  103550. 1.20790F, 1.13419F, 1.06499F, 1.F
  103551. };
  103552. void _vp_remove_floor(vorbis_look_psy *p,
  103553. float *mdct,
  103554. int *codedflr,
  103555. float *residue,
  103556. int sliding_lowpass){
  103557. int i,n=p->n;
  103558. if(sliding_lowpass>n)sliding_lowpass=n;
  103559. for(i=0;i<sliding_lowpass;i++){
  103560. residue[i]=
  103561. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  103562. }
  103563. for(;i<n;i++)
  103564. residue[i]=0.;
  103565. }
  103566. void _vp_noisemask(vorbis_look_psy *p,
  103567. float *logmdct,
  103568. float *logmask){
  103569. int i,n=p->n;
  103570. float *work=(float*) alloca(n*sizeof(*work));
  103571. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  103572. 140.,-1);
  103573. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  103574. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  103575. p->vi->noisewindowfixed);
  103576. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  103577. #if 0
  103578. {
  103579. static int seq=0;
  103580. float work2[n];
  103581. for(i=0;i<n;i++){
  103582. work2[i]=logmask[i]+work[i];
  103583. }
  103584. if(seq&1)
  103585. _analysis_output("median2R",seq/2,work,n,1,0,0);
  103586. else
  103587. _analysis_output("median2L",seq/2,work,n,1,0,0);
  103588. if(seq&1)
  103589. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  103590. else
  103591. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  103592. seq++;
  103593. }
  103594. #endif
  103595. for(i=0;i<n;i++){
  103596. int dB=logmask[i]+.5;
  103597. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  103598. if(dB<0)dB=0;
  103599. logmask[i]= work[i]+p->vi->noisecompand[dB];
  103600. }
  103601. }
  103602. void _vp_tonemask(vorbis_look_psy *p,
  103603. float *logfft,
  103604. float *logmask,
  103605. float global_specmax,
  103606. float local_specmax){
  103607. int i,n=p->n;
  103608. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  103609. float att=local_specmax+p->vi->ath_adjatt;
  103610. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  103611. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  103612. for(i=0;i<n;i++)
  103613. logmask[i]=p->ath[i]+att;
  103614. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  103615. max_seeds(p,seed,logmask);
  103616. }
  103617. void _vp_offset_and_mix(vorbis_look_psy *p,
  103618. float *noise,
  103619. float *tone,
  103620. int offset_select,
  103621. float *logmask,
  103622. float *mdct,
  103623. float *logmdct){
  103624. int i,n=p->n;
  103625. float de, coeffi, cx;/* AoTuV */
  103626. float toneatt=p->vi->tone_masteratt[offset_select];
  103627. cx = p->m_val;
  103628. for(i=0;i<n;i++){
  103629. float val= noise[i]+p->noiseoffset[offset_select][i];
  103630. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  103631. logmask[i]=max(val,tone[i]+toneatt);
  103632. if(offset_select == 1) {
  103633. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  103634. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  103635. if(val > coeffi){
  103636. de = 1.0-((val-coeffi)*0.005*cx);
  103637. if(de < 0) de = 0.0001;
  103638. }else
  103639. de = 1.0-((val-coeffi)*0.0003*cx);
  103640. mdct[i] *= de;
  103641. }
  103642. }
  103643. }
  103644. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  103645. vorbis_info *vi=vd->vi;
  103646. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103647. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103648. int n=ci->blocksizes[vd->W]/2;
  103649. float secs=(float)n/vi->rate;
  103650. amp+=secs*gi->ampmax_att_per_sec;
  103651. if(amp<-9999)amp=-9999;
  103652. return(amp);
  103653. }
  103654. static void couple_lossless(float A, float B,
  103655. float *qA, float *qB){
  103656. int test1=fabs(*qA)>fabs(*qB);
  103657. test1-= fabs(*qA)<fabs(*qB);
  103658. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  103659. if(test1==1){
  103660. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  103661. }else{
  103662. float temp=*qB;
  103663. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  103664. *qA=temp;
  103665. }
  103666. if(*qB>fabs(*qA)*1.9999f){
  103667. *qB= -fabs(*qA)*2.f;
  103668. *qA= -*qA;
  103669. }
  103670. }
  103671. static float hypot_lookup[32]={
  103672. -0.009935, -0.011245, -0.012726, -0.014397,
  103673. -0.016282, -0.018407, -0.020800, -0.023494,
  103674. -0.026522, -0.029923, -0.033737, -0.038010,
  103675. -0.042787, -0.048121, -0.054064, -0.060671,
  103676. -0.068000, -0.076109, -0.085054, -0.094892,
  103677. -0.105675, -0.117451, -0.130260, -0.144134,
  103678. -0.159093, -0.175146, -0.192286, -0.210490,
  103679. -0.229718, -0.249913, -0.271001, -0.292893};
  103680. static void precomputed_couple_point(float premag,
  103681. int floorA,int floorB,
  103682. float *mag, float *ang){
  103683. int test=(floorA>floorB)-1;
  103684. int offset=31-abs(floorA-floorB);
  103685. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  103686. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  103687. *mag=premag*floormag;
  103688. *ang=0.f;
  103689. }
  103690. static float dipole_hypot(float a, float b){
  103691. if(a>0.){
  103692. if(b>0.)return sqrt(a*a+b*b);
  103693. if(a>-b)return sqrt(a*a-b*b);
  103694. return -sqrt(b*b-a*a);
  103695. }
  103696. if(b<0.)return -sqrt(a*a+b*b);
  103697. if(-a>b)return -sqrt(a*a-b*b);
  103698. return sqrt(b*b-a*a);
  103699. }
  103700. static float round_hypot(float a, float b){
  103701. if(a>0.){
  103702. if(b>0.)return sqrt(a*a+b*b);
  103703. if(a>-b)return sqrt(a*a+b*b);
  103704. return -sqrt(b*b+a*a);
  103705. }
  103706. if(b<0.)return -sqrt(a*a+b*b);
  103707. if(-a>b)return -sqrt(a*a+b*b);
  103708. return sqrt(b*b+a*a);
  103709. }
  103710. float **_vp_quantize_couple_memo(vorbis_block *vb,
  103711. vorbis_info_psy_global *g,
  103712. vorbis_look_psy *p,
  103713. vorbis_info_mapping0 *vi,
  103714. float **mdct){
  103715. int i,j,n=p->n;
  103716. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103717. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103718. for(i=0;i<vi->coupling_steps;i++){
  103719. float *mdctM=mdct[vi->coupling_mag[i]];
  103720. float *mdctA=mdct[vi->coupling_ang[i]];
  103721. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103722. for(j=0;j<limit;j++)
  103723. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  103724. for(;j<n;j++)
  103725. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  103726. }
  103727. return(ret);
  103728. }
  103729. static int apsort(const void *a, const void *b){
  103730. float f1=fabs(**(float**)a);
  103731. float f2=fabs(**(float**)b);
  103732. return (f1<f2)-(f1>f2);
  103733. }
  103734. int **_vp_quantize_couple_sort(vorbis_block *vb,
  103735. vorbis_look_psy *p,
  103736. vorbis_info_mapping0 *vi,
  103737. float **mags){
  103738. if(p->vi->normal_point_p){
  103739. int i,j,k,n=p->n;
  103740. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103741. int partition=p->vi->normal_partition;
  103742. float **work=(float**) alloca(sizeof(*work)*partition);
  103743. for(i=0;i<vi->coupling_steps;i++){
  103744. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103745. for(j=0;j<n;j+=partition){
  103746. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  103747. qsort(work,partition,sizeof(*work),apsort);
  103748. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  103749. }
  103750. }
  103751. return(ret);
  103752. }
  103753. return(NULL);
  103754. }
  103755. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  103756. float *magnitudes,int *sortedindex){
  103757. int i,j,n=p->n;
  103758. vorbis_info_psy *vi=p->vi;
  103759. int partition=vi->normal_partition;
  103760. float **work=(float**) alloca(sizeof(*work)*partition);
  103761. int start=vi->normal_start;
  103762. for(j=start;j<n;j+=partition){
  103763. if(j+partition>n)partition=n-j;
  103764. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  103765. qsort(work,partition,sizeof(*work),apsort);
  103766. for(i=0;i<partition;i++){
  103767. sortedindex[i+j-start]=work[i]-magnitudes;
  103768. }
  103769. }
  103770. }
  103771. void _vp_noise_normalize(vorbis_look_psy *p,
  103772. float *in,float *out,int *sortedindex){
  103773. int flag=0,i,j=0,n=p->n;
  103774. vorbis_info_psy *vi=p->vi;
  103775. int partition=vi->normal_partition;
  103776. int start=vi->normal_start;
  103777. if(start>n)start=n;
  103778. if(vi->normal_channel_p){
  103779. for(;j<start;j++)
  103780. out[j]=rint(in[j]);
  103781. for(;j+partition<=n;j+=partition){
  103782. float acc=0.;
  103783. int k;
  103784. for(i=j;i<j+partition;i++)
  103785. acc+=in[i]*in[i];
  103786. for(i=0;i<partition;i++){
  103787. k=sortedindex[i+j-start];
  103788. if(in[k]*in[k]>=.25f){
  103789. out[k]=rint(in[k]);
  103790. acc-=in[k]*in[k];
  103791. flag=1;
  103792. }else{
  103793. if(acc<vi->normal_thresh)break;
  103794. out[k]=unitnorm(in[k]);
  103795. acc-=1.;
  103796. }
  103797. }
  103798. for(;i<partition;i++){
  103799. k=sortedindex[i+j-start];
  103800. out[k]=0.;
  103801. }
  103802. }
  103803. }
  103804. for(;j<n;j++)
  103805. out[j]=rint(in[j]);
  103806. }
  103807. void _vp_couple(int blobno,
  103808. vorbis_info_psy_global *g,
  103809. vorbis_look_psy *p,
  103810. vorbis_info_mapping0 *vi,
  103811. float **res,
  103812. float **mag_memo,
  103813. int **mag_sort,
  103814. int **ifloor,
  103815. int *nonzero,
  103816. int sliding_lowpass){
  103817. int i,j,k,n=p->n;
  103818. for(i=0;i<vi->coupling_steps;i++){
  103819. if(nonzero[vi->coupling_mag[i]] ||
  103820. nonzero[vi->coupling_ang[i]]){
  103821. float *rM=res[vi->coupling_mag[i]];
  103822. float *rA=res[vi->coupling_ang[i]];
  103823. float *qM=rM+n;
  103824. float *qA=rA+n;
  103825. int *floorM=ifloor[vi->coupling_mag[i]];
  103826. int *floorA=ifloor[vi->coupling_ang[i]];
  103827. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  103828. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  103829. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  103830. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  103831. int pointlimit=limit;
  103832. nonzero[vi->coupling_mag[i]]=1;
  103833. nonzero[vi->coupling_ang[i]]=1;
  103834. if(n > 1000)
  103835. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  103836. for(j=0;j<p->n;j+=partition){
  103837. float acc=0.f;
  103838. for(k=0;k<partition;k++){
  103839. int l=k+j;
  103840. if(l<sliding_lowpass){
  103841. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  103842. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  103843. precomputed_couple_point(mag_memo[i][l],
  103844. floorM[l],floorA[l],
  103845. qM+l,qA+l);
  103846. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  103847. }else{
  103848. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  103849. }
  103850. }else{
  103851. qM[l]=0.;
  103852. qA[l]=0.;
  103853. }
  103854. }
  103855. if(p->vi->normal_point_p){
  103856. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  103857. int l=mag_sort[i][j+k];
  103858. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  103859. qM[l]=unitnorm(qM[l]);
  103860. acc-=1.f;
  103861. }
  103862. }
  103863. }
  103864. }
  103865. }
  103866. }
  103867. }
  103868. void hf_reduction(vorbis_info_psy_global *g,
  103869. vorbis_look_psy *p,
  103870. vorbis_info_mapping0 *vi,
  103871. float **mdct){
  103872. int i,j,n=p->n, de=0.3*p->m_val;
  103873. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103874. for(i=0; i<vi->coupling_steps; i++){
  103875. for(j=limit; j<n; j++)
  103876. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  103877. }
  103878. }
  103879. #endif
  103880. /*** End of inlined file: psy.c ***/
  103881. /*** Start of inlined file: registry.c ***/
  103882. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103883. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103884. // tasks..
  103885. #if JUCE_MSVC
  103886. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103887. #endif
  103888. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103889. #if JUCE_USE_OGGVORBIS
  103890. extern vorbis_func_floor floor0_exportbundle;
  103891. extern vorbis_func_floor floor1_exportbundle;
  103892. extern vorbis_func_residue residue0_exportbundle;
  103893. extern vorbis_func_residue residue1_exportbundle;
  103894. extern vorbis_func_residue residue2_exportbundle;
  103895. extern vorbis_func_mapping mapping0_exportbundle;
  103896. vorbis_func_floor *_floor_P[]={
  103897. &floor0_exportbundle,
  103898. &floor1_exportbundle,
  103899. };
  103900. vorbis_func_residue *_residue_P[]={
  103901. &residue0_exportbundle,
  103902. &residue1_exportbundle,
  103903. &residue2_exportbundle,
  103904. };
  103905. vorbis_func_mapping *_mapping_P[]={
  103906. &mapping0_exportbundle,
  103907. };
  103908. #endif
  103909. /*** End of inlined file: registry.c ***/
  103910. /*** Start of inlined file: res0.c ***/
  103911. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103912. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103913. // tasks..
  103914. #if JUCE_MSVC
  103915. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103916. #endif
  103917. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103918. #if JUCE_USE_OGGVORBIS
  103919. #include <stdlib.h>
  103920. #include <string.h>
  103921. #include <math.h>
  103922. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  103923. #include <stdio.h>
  103924. #endif
  103925. typedef struct {
  103926. vorbis_info_residue0 *info;
  103927. int parts;
  103928. int stages;
  103929. codebook *fullbooks;
  103930. codebook *phrasebook;
  103931. codebook ***partbooks;
  103932. int partvals;
  103933. int **decodemap;
  103934. long postbits;
  103935. long phrasebits;
  103936. long frames;
  103937. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  103938. int train_seq;
  103939. long *training_data[8][64];
  103940. float training_max[8][64];
  103941. float training_min[8][64];
  103942. float tmin;
  103943. float tmax;
  103944. #endif
  103945. } vorbis_look_residue0;
  103946. void res0_free_info(vorbis_info_residue *i){
  103947. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  103948. if(info){
  103949. memset(info,0,sizeof(*info));
  103950. _ogg_free(info);
  103951. }
  103952. }
  103953. void res0_free_look(vorbis_look_residue *i){
  103954. int j;
  103955. if(i){
  103956. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  103957. #ifdef TRAIN_RES
  103958. {
  103959. int j,k,l;
  103960. for(j=0;j<look->parts;j++){
  103961. for(k=0;k<8;k++)
  103962. if(look->training_data[k][j]){
  103963. char buffer[80];
  103964. FILE *of;
  103965. codebook *statebook=look->partbooks[j][k];
  103966. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  103967. of=fopen(buffer,"a");
  103968. for(l=0;l<statebook->entries;l++)
  103969. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  103970. fclose(of);
  103971. _ogg_free(look->training_data[k][j]);
  103972. look->training_data[k][j]=NULL;
  103973. }
  103974. }
  103975. }
  103976. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  103977. #endif
  103978. for(j=0;j<look->parts;j++)
  103979. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  103980. _ogg_free(look->partbooks);
  103981. for(j=0;j<look->partvals;j++)
  103982. _ogg_free(look->decodemap[j]);
  103983. _ogg_free(look->decodemap);
  103984. memset(look,0,sizeof(*look));
  103985. _ogg_free(look);
  103986. }
  103987. }
  103988. static int icount(unsigned int v){
  103989. int ret=0;
  103990. while(v){
  103991. ret+=v&1;
  103992. v>>=1;
  103993. }
  103994. return(ret);
  103995. }
  103996. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  103997. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  103998. int j,acc=0;
  103999. oggpack_write(opb,info->begin,24);
  104000. oggpack_write(opb,info->end,24);
  104001. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  104002. code with a partitioned book */
  104003. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  104004. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  104005. for(j=0;j<info->partitions;j++){
  104006. if(ilog(info->secondstages[j])>3){
  104007. oggpack_write(opb,info->secondstages[j],3);
  104008. oggpack_write(opb,1,1);
  104009. oggpack_write(opb,info->secondstages[j]>>3,5);
  104010. }else
  104011. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104012. acc+=icount(info->secondstages[j]);
  104013. }
  104014. for(j=0;j<acc;j++)
  104015. oggpack_write(opb,info->booklist[j],8);
  104016. }
  104017. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104018. int j,acc=0;
  104019. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104020. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104021. info->begin=oggpack_read(opb,24);
  104022. info->end=oggpack_read(opb,24);
  104023. info->grouping=oggpack_read(opb,24)+1;
  104024. info->partitions=oggpack_read(opb,6)+1;
  104025. info->groupbook=oggpack_read(opb,8);
  104026. for(j=0;j<info->partitions;j++){
  104027. int cascade=oggpack_read(opb,3);
  104028. if(oggpack_read(opb,1))
  104029. cascade|=(oggpack_read(opb,5)<<3);
  104030. info->secondstages[j]=cascade;
  104031. acc+=icount(cascade);
  104032. }
  104033. for(j=0;j<acc;j++)
  104034. info->booklist[j]=oggpack_read(opb,8);
  104035. if(info->groupbook>=ci->books)goto errout;
  104036. for(j=0;j<acc;j++)
  104037. if(info->booklist[j]>=ci->books)goto errout;
  104038. return(info);
  104039. errout:
  104040. res0_free_info(info);
  104041. return(NULL);
  104042. }
  104043. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104044. vorbis_info_residue *vr){
  104045. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104046. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104047. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104048. int j,k,acc=0;
  104049. int dim;
  104050. int maxstage=0;
  104051. look->info=info;
  104052. look->parts=info->partitions;
  104053. look->fullbooks=ci->fullbooks;
  104054. look->phrasebook=ci->fullbooks+info->groupbook;
  104055. dim=look->phrasebook->dim;
  104056. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104057. for(j=0;j<look->parts;j++){
  104058. int stages=ilog(info->secondstages[j]);
  104059. if(stages){
  104060. if(stages>maxstage)maxstage=stages;
  104061. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104062. for(k=0;k<stages;k++)
  104063. if(info->secondstages[j]&(1<<k)){
  104064. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104065. #ifdef TRAIN_RES
  104066. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104067. sizeof(***look->training_data));
  104068. #endif
  104069. }
  104070. }
  104071. }
  104072. look->partvals=rint(pow((float)look->parts,(float)dim));
  104073. look->stages=maxstage;
  104074. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104075. for(j=0;j<look->partvals;j++){
  104076. long val=j;
  104077. long mult=look->partvals/look->parts;
  104078. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104079. for(k=0;k<dim;k++){
  104080. long deco=val/mult;
  104081. val-=deco*mult;
  104082. mult/=look->parts;
  104083. look->decodemap[j][k]=deco;
  104084. }
  104085. }
  104086. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104087. {
  104088. static int train_seq=0;
  104089. look->train_seq=train_seq++;
  104090. }
  104091. #endif
  104092. return(look);
  104093. }
  104094. static int local_book_besterror(codebook *book,float *a){
  104095. int dim=book->dim,i,k,o;
  104096. int best=0;
  104097. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104098. for(k=0,o=dim;k<dim;++k){
  104099. float val=a[--o];
  104100. i=tt->threshvals>>1;
  104101. if(val<tt->quantthresh[i]){
  104102. if(val<tt->quantthresh[i-1]){
  104103. for(--i;i>0;--i)
  104104. if(val>=tt->quantthresh[i-1])
  104105. break;
  104106. }
  104107. }else{
  104108. for(++i;i<tt->threshvals-1;++i)
  104109. if(val<tt->quantthresh[i])break;
  104110. }
  104111. best=(best*tt->quantvals)+tt->quantmap[i];
  104112. }
  104113. if(book->c->lengthlist[best]<=0){
  104114. const static_codebook *c=book->c;
  104115. int i,j;
  104116. float bestf=0.f;
  104117. float *e=book->valuelist;
  104118. best=-1;
  104119. for(i=0;i<book->entries;i++){
  104120. if(c->lengthlist[i]>0){
  104121. float thisx=0.f;
  104122. for(j=0;j<dim;j++){
  104123. float val=(e[j]-a[j]);
  104124. thisx+=val*val;
  104125. }
  104126. if(best==-1 || thisx<bestf){
  104127. bestf=thisx;
  104128. best=i;
  104129. }
  104130. }
  104131. e+=dim;
  104132. }
  104133. }
  104134. {
  104135. float *ptr=book->valuelist+best*dim;
  104136. for(i=0;i<dim;i++)
  104137. *a++ -= *ptr++;
  104138. }
  104139. return(best);
  104140. }
  104141. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104142. codebook *book,long *acc){
  104143. int i,bits=0;
  104144. int dim=book->dim;
  104145. int step=n/dim;
  104146. for(i=0;i<step;i++){
  104147. int entry=local_book_besterror(book,vec+i*dim);
  104148. #ifdef TRAIN_RES
  104149. acc[entry]++;
  104150. #endif
  104151. bits+=vorbis_book_encode(book,entry,opb);
  104152. }
  104153. return(bits);
  104154. }
  104155. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104156. float **in,int ch){
  104157. long i,j,k;
  104158. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104159. vorbis_info_residue0 *info=look->info;
  104160. int samples_per_partition=info->grouping;
  104161. int possible_partitions=info->partitions;
  104162. int n=info->end-info->begin;
  104163. int partvals=n/samples_per_partition;
  104164. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104165. float scale=100./samples_per_partition;
  104166. for(i=0;i<ch;i++){
  104167. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104168. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104169. }
  104170. for(i=0;i<partvals;i++){
  104171. int offset=i*samples_per_partition+info->begin;
  104172. for(j=0;j<ch;j++){
  104173. float max=0.;
  104174. float ent=0.;
  104175. for(k=0;k<samples_per_partition;k++){
  104176. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104177. ent+=fabs(rint(in[j][offset+k]));
  104178. }
  104179. ent*=scale;
  104180. for(k=0;k<possible_partitions-1;k++)
  104181. if(max<=info->classmetric1[k] &&
  104182. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104183. break;
  104184. partword[j][i]=k;
  104185. }
  104186. }
  104187. #ifdef TRAIN_RESAUX
  104188. {
  104189. FILE *of;
  104190. char buffer[80];
  104191. for(i=0;i<ch;i++){
  104192. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104193. of=fopen(buffer,"a");
  104194. for(j=0;j<partvals;j++)
  104195. fprintf(of,"%ld, ",partword[i][j]);
  104196. fprintf(of,"\n");
  104197. fclose(of);
  104198. }
  104199. }
  104200. #endif
  104201. look->frames++;
  104202. return(partword);
  104203. }
  104204. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104205. int ch){
  104206. long i,j,k,l;
  104207. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104208. vorbis_info_residue0 *info=look->info;
  104209. int samples_per_partition=info->grouping;
  104210. int possible_partitions=info->partitions;
  104211. int n=info->end-info->begin;
  104212. int partvals=n/samples_per_partition;
  104213. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104214. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104215. FILE *of;
  104216. char buffer[80];
  104217. #endif
  104218. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104219. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104220. for(i=0,l=info->begin/ch;i<partvals;i++){
  104221. float magmax=0.f;
  104222. float angmax=0.f;
  104223. for(j=0;j<samples_per_partition;j+=ch){
  104224. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104225. for(k=1;k<ch;k++)
  104226. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104227. l++;
  104228. }
  104229. for(j=0;j<possible_partitions-1;j++)
  104230. if(magmax<=info->classmetric1[j] &&
  104231. angmax<=info->classmetric2[j])
  104232. break;
  104233. partword[0][i]=j;
  104234. }
  104235. #ifdef TRAIN_RESAUX
  104236. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104237. of=fopen(buffer,"a");
  104238. for(i=0;i<partvals;i++)
  104239. fprintf(of,"%ld, ",partword[0][i]);
  104240. fprintf(of,"\n");
  104241. fclose(of);
  104242. #endif
  104243. look->frames++;
  104244. return(partword);
  104245. }
  104246. static int _01forward(oggpack_buffer *opb,
  104247. vorbis_block *vb,vorbis_look_residue *vl,
  104248. float **in,int ch,
  104249. long **partword,
  104250. int (*encode)(oggpack_buffer *,float *,int,
  104251. codebook *,long *)){
  104252. long i,j,k,s;
  104253. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104254. vorbis_info_residue0 *info=look->info;
  104255. int samples_per_partition=info->grouping;
  104256. int possible_partitions=info->partitions;
  104257. int partitions_per_word=look->phrasebook->dim;
  104258. int n=info->end-info->begin;
  104259. int partvals=n/samples_per_partition;
  104260. long resbits[128];
  104261. long resvals[128];
  104262. #ifdef TRAIN_RES
  104263. for(i=0;i<ch;i++)
  104264. for(j=info->begin;j<info->end;j++){
  104265. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104266. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104267. }
  104268. #endif
  104269. memset(resbits,0,sizeof(resbits));
  104270. memset(resvals,0,sizeof(resvals));
  104271. for(s=0;s<look->stages;s++){
  104272. for(i=0;i<partvals;){
  104273. if(s==0){
  104274. for(j=0;j<ch;j++){
  104275. long val=partword[j][i];
  104276. for(k=1;k<partitions_per_word;k++){
  104277. val*=possible_partitions;
  104278. if(i+k<partvals)
  104279. val+=partword[j][i+k];
  104280. }
  104281. if(val<look->phrasebook->entries)
  104282. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104283. #if 0 /*def TRAIN_RES*/
  104284. else
  104285. fprintf(stderr,"!");
  104286. #endif
  104287. }
  104288. }
  104289. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104290. long offset=i*samples_per_partition+info->begin;
  104291. for(j=0;j<ch;j++){
  104292. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104293. if(info->secondstages[partword[j][i]]&(1<<s)){
  104294. codebook *statebook=look->partbooks[partword[j][i]][s];
  104295. if(statebook){
  104296. int ret;
  104297. long *accumulator=NULL;
  104298. #ifdef TRAIN_RES
  104299. accumulator=look->training_data[s][partword[j][i]];
  104300. {
  104301. int l;
  104302. float *samples=in[j]+offset;
  104303. for(l=0;l<samples_per_partition;l++){
  104304. if(samples[l]<look->training_min[s][partword[j][i]])
  104305. look->training_min[s][partword[j][i]]=samples[l];
  104306. if(samples[l]>look->training_max[s][partword[j][i]])
  104307. look->training_max[s][partword[j][i]]=samples[l];
  104308. }
  104309. }
  104310. #endif
  104311. ret=encode(opb,in[j]+offset,samples_per_partition,
  104312. statebook,accumulator);
  104313. look->postbits+=ret;
  104314. resbits[partword[j][i]]+=ret;
  104315. }
  104316. }
  104317. }
  104318. }
  104319. }
  104320. }
  104321. return(0);
  104322. }
  104323. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104324. float **in,int ch,
  104325. long (*decodepart)(codebook *, float *,
  104326. oggpack_buffer *,int)){
  104327. long i,j,k,l,s;
  104328. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104329. vorbis_info_residue0 *info=look->info;
  104330. int samples_per_partition=info->grouping;
  104331. int partitions_per_word=look->phrasebook->dim;
  104332. int n=info->end-info->begin;
  104333. int partvals=n/samples_per_partition;
  104334. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104335. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104336. for(j=0;j<ch;j++)
  104337. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104338. for(s=0;s<look->stages;s++){
  104339. for(i=0,l=0;i<partvals;l++){
  104340. if(s==0){
  104341. for(j=0;j<ch;j++){
  104342. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104343. if(temp==-1)goto eopbreak;
  104344. partword[j][l]=look->decodemap[temp];
  104345. if(partword[j][l]==NULL)goto errout;
  104346. }
  104347. }
  104348. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104349. for(j=0;j<ch;j++){
  104350. long offset=info->begin+i*samples_per_partition;
  104351. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104352. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104353. if(stagebook){
  104354. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104355. samples_per_partition)==-1)goto eopbreak;
  104356. }
  104357. }
  104358. }
  104359. }
  104360. }
  104361. errout:
  104362. eopbreak:
  104363. return(0);
  104364. }
  104365. #if 0
  104366. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104367. float **in,int *nonzero,int ch){
  104368. int i,used=0;
  104369. for(i=0;i<ch;i++)
  104370. if(nonzero[i])
  104371. in[used++]=in[i];
  104372. if(used)
  104373. return(_01class(vb,vl,in,used));
  104374. else
  104375. return(0);
  104376. }
  104377. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104378. float **in,float **out,int *nonzero,int ch,
  104379. long **partword){
  104380. int i,j,used=0,n=vb->pcmend/2;
  104381. for(i=0;i<ch;i++)
  104382. if(nonzero[i]){
  104383. if(out)
  104384. for(j=0;j<n;j++)
  104385. out[i][j]+=in[i][j];
  104386. in[used++]=in[i];
  104387. }
  104388. if(used){
  104389. int ret=_01forward(vb,vl,in,used,partword,
  104390. _interleaved_encodepart);
  104391. if(out){
  104392. used=0;
  104393. for(i=0;i<ch;i++)
  104394. if(nonzero[i]){
  104395. for(j=0;j<n;j++)
  104396. out[i][j]-=in[used][j];
  104397. used++;
  104398. }
  104399. }
  104400. return(ret);
  104401. }else{
  104402. return(0);
  104403. }
  104404. }
  104405. #endif
  104406. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104407. float **in,int *nonzero,int ch){
  104408. int i,used=0;
  104409. for(i=0;i<ch;i++)
  104410. if(nonzero[i])
  104411. in[used++]=in[i];
  104412. if(used)
  104413. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104414. else
  104415. return(0);
  104416. }
  104417. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104418. float **in,float **out,int *nonzero,int ch,
  104419. long **partword){
  104420. int i,j,used=0,n=vb->pcmend/2;
  104421. for(i=0;i<ch;i++)
  104422. if(nonzero[i]){
  104423. if(out)
  104424. for(j=0;j<n;j++)
  104425. out[i][j]+=in[i][j];
  104426. in[used++]=in[i];
  104427. }
  104428. if(used){
  104429. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104430. if(out){
  104431. used=0;
  104432. for(i=0;i<ch;i++)
  104433. if(nonzero[i]){
  104434. for(j=0;j<n;j++)
  104435. out[i][j]-=in[used][j];
  104436. used++;
  104437. }
  104438. }
  104439. return(ret);
  104440. }else{
  104441. return(0);
  104442. }
  104443. }
  104444. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104445. float **in,int *nonzero,int ch){
  104446. int i,used=0;
  104447. for(i=0;i<ch;i++)
  104448. if(nonzero[i])
  104449. in[used++]=in[i];
  104450. if(used)
  104451. return(_01class(vb,vl,in,used));
  104452. else
  104453. return(0);
  104454. }
  104455. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104456. float **in,int *nonzero,int ch){
  104457. int i,used=0;
  104458. for(i=0;i<ch;i++)
  104459. if(nonzero[i])
  104460. in[used++]=in[i];
  104461. if(used)
  104462. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104463. else
  104464. return(0);
  104465. }
  104466. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104467. float **in,int *nonzero,int ch){
  104468. int i,used=0;
  104469. for(i=0;i<ch;i++)
  104470. if(nonzero[i])used++;
  104471. if(used)
  104472. return(_2class(vb,vl,in,ch));
  104473. else
  104474. return(0);
  104475. }
  104476. int res2_forward(oggpack_buffer *opb,
  104477. vorbis_block *vb,vorbis_look_residue *vl,
  104478. float **in,float **out,int *nonzero,int ch,
  104479. long **partword){
  104480. long i,j,k,n=vb->pcmend/2,used=0;
  104481. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104482. for(i=0;i<ch;i++){
  104483. float *pcm=in[i];
  104484. if(nonzero[i])used++;
  104485. for(j=0,k=i;j<n;j++,k+=ch)
  104486. work[k]=pcm[j];
  104487. }
  104488. if(used){
  104489. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104490. if(out){
  104491. for(i=0;i<ch;i++){
  104492. float *pcm=in[i];
  104493. float *sofar=out[i];
  104494. for(j=0,k=i;j<n;j++,k+=ch)
  104495. sofar[j]+=pcm[j]-work[k];
  104496. }
  104497. }
  104498. return(ret);
  104499. }else{
  104500. return(0);
  104501. }
  104502. }
  104503. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104504. float **in,int *nonzero,int ch){
  104505. long i,k,l,s;
  104506. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104507. vorbis_info_residue0 *info=look->info;
  104508. int samples_per_partition=info->grouping;
  104509. int partitions_per_word=look->phrasebook->dim;
  104510. int n=info->end-info->begin;
  104511. int partvals=n/samples_per_partition;
  104512. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104513. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104514. for(i=0;i<ch;i++)if(nonzero[i])break;
  104515. if(i==ch)return(0); /* no nonzero vectors */
  104516. for(s=0;s<look->stages;s++){
  104517. for(i=0,l=0;i<partvals;l++){
  104518. if(s==0){
  104519. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104520. if(temp==-1)goto eopbreak;
  104521. partword[l]=look->decodemap[temp];
  104522. if(partword[l]==NULL)goto errout;
  104523. }
  104524. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104525. if(info->secondstages[partword[l][k]]&(1<<s)){
  104526. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104527. if(stagebook){
  104528. if(vorbis_book_decodevv_add(stagebook,in,
  104529. i*samples_per_partition+info->begin,ch,
  104530. &vb->opb,samples_per_partition)==-1)
  104531. goto eopbreak;
  104532. }
  104533. }
  104534. }
  104535. }
  104536. errout:
  104537. eopbreak:
  104538. return(0);
  104539. }
  104540. vorbis_func_residue residue0_exportbundle={
  104541. NULL,
  104542. &res0_unpack,
  104543. &res0_look,
  104544. &res0_free_info,
  104545. &res0_free_look,
  104546. NULL,
  104547. NULL,
  104548. &res0_inverse
  104549. };
  104550. vorbis_func_residue residue1_exportbundle={
  104551. &res0_pack,
  104552. &res0_unpack,
  104553. &res0_look,
  104554. &res0_free_info,
  104555. &res0_free_look,
  104556. &res1_class,
  104557. &res1_forward,
  104558. &res1_inverse
  104559. };
  104560. vorbis_func_residue residue2_exportbundle={
  104561. &res0_pack,
  104562. &res0_unpack,
  104563. &res0_look,
  104564. &res0_free_info,
  104565. &res0_free_look,
  104566. &res2_class,
  104567. &res2_forward,
  104568. &res2_inverse
  104569. };
  104570. #endif
  104571. /*** End of inlined file: res0.c ***/
  104572. /*** Start of inlined file: sharedbook.c ***/
  104573. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104574. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104575. // tasks..
  104576. #if JUCE_MSVC
  104577. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104578. #endif
  104579. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104580. #if JUCE_USE_OGGVORBIS
  104581. #include <stdlib.h>
  104582. #include <math.h>
  104583. #include <string.h>
  104584. int _ilog(unsigned int v){
  104585. int ret=0;
  104586. while(v){
  104587. ret++;
  104588. v>>=1;
  104589. }
  104590. return(ret);
  104591. }
  104592. #define VQ_FEXP 10
  104593. #define VQ_FMAN 21
  104594. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  104595. long _float32_pack(float val){
  104596. int sign=0;
  104597. long exp;
  104598. long mant;
  104599. if(val<0){
  104600. sign=0x80000000;
  104601. val= -val;
  104602. }
  104603. exp= floor(log(val)/log(2.f));
  104604. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  104605. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  104606. return(sign|exp|mant);
  104607. }
  104608. float _float32_unpack(long val){
  104609. double mant=val&0x1fffff;
  104610. int sign=val&0x80000000;
  104611. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  104612. if(sign)mant= -mant;
  104613. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  104614. }
  104615. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  104616. long i,j,count=0;
  104617. ogg_uint32_t marker[33];
  104618. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  104619. memset(marker,0,sizeof(marker));
  104620. for(i=0;i<n;i++){
  104621. long length=l[i];
  104622. if(length>0){
  104623. ogg_uint32_t entry=marker[length];
  104624. if(length<32 && (entry>>length)){
  104625. _ogg_free(r);
  104626. return(NULL);
  104627. }
  104628. r[count++]=entry;
  104629. {
  104630. for(j=length;j>0;j--){
  104631. if(marker[j]&1){
  104632. if(j==1)
  104633. marker[1]++;
  104634. else
  104635. marker[j]=marker[j-1]<<1;
  104636. break; /* invariant says next upper marker would already
  104637. have been moved if it was on the same path */
  104638. }
  104639. marker[j]++;
  104640. }
  104641. }
  104642. for(j=length+1;j<33;j++)
  104643. if((marker[j]>>1) == entry){
  104644. entry=marker[j];
  104645. marker[j]=marker[j-1]<<1;
  104646. }else
  104647. break;
  104648. }else
  104649. if(sparsecount==0)count++;
  104650. }
  104651. for(i=0,count=0;i<n;i++){
  104652. ogg_uint32_t temp=0;
  104653. for(j=0;j<l[i];j++){
  104654. temp<<=1;
  104655. temp|=(r[count]>>j)&1;
  104656. }
  104657. if(sparsecount){
  104658. if(l[i])
  104659. r[count++]=temp;
  104660. }else
  104661. r[count++]=temp;
  104662. }
  104663. return(r);
  104664. }
  104665. long _book_maptype1_quantvals(const static_codebook *b){
  104666. long vals=floor(pow((float)b->entries,1.f/b->dim));
  104667. while(1){
  104668. long acc=1;
  104669. long acc1=1;
  104670. int i;
  104671. for(i=0;i<b->dim;i++){
  104672. acc*=vals;
  104673. acc1*=vals+1;
  104674. }
  104675. if(acc<=b->entries && acc1>b->entries){
  104676. return(vals);
  104677. }else{
  104678. if(acc>b->entries){
  104679. vals--;
  104680. }else{
  104681. vals++;
  104682. }
  104683. }
  104684. }
  104685. }
  104686. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  104687. long j,k,count=0;
  104688. if(b->maptype==1 || b->maptype==2){
  104689. int quantvals;
  104690. float mindel=_float32_unpack(b->q_min);
  104691. float delta=_float32_unpack(b->q_delta);
  104692. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  104693. switch(b->maptype){
  104694. case 1:
  104695. quantvals=_book_maptype1_quantvals(b);
  104696. for(j=0;j<b->entries;j++){
  104697. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104698. float last=0.f;
  104699. int indexdiv=1;
  104700. for(k=0;k<b->dim;k++){
  104701. int index= (j/indexdiv)%quantvals;
  104702. float val=b->quantlist[index];
  104703. val=fabs(val)*delta+mindel+last;
  104704. if(b->q_sequencep)last=val;
  104705. if(sparsemap)
  104706. r[sparsemap[count]*b->dim+k]=val;
  104707. else
  104708. r[count*b->dim+k]=val;
  104709. indexdiv*=quantvals;
  104710. }
  104711. count++;
  104712. }
  104713. }
  104714. break;
  104715. case 2:
  104716. for(j=0;j<b->entries;j++){
  104717. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104718. float last=0.f;
  104719. for(k=0;k<b->dim;k++){
  104720. float val=b->quantlist[j*b->dim+k];
  104721. val=fabs(val)*delta+mindel+last;
  104722. if(b->q_sequencep)last=val;
  104723. if(sparsemap)
  104724. r[sparsemap[count]*b->dim+k]=val;
  104725. else
  104726. r[count*b->dim+k]=val;
  104727. }
  104728. count++;
  104729. }
  104730. }
  104731. break;
  104732. }
  104733. return(r);
  104734. }
  104735. return(NULL);
  104736. }
  104737. void vorbis_staticbook_clear(static_codebook *b){
  104738. if(b->allocedp){
  104739. if(b->quantlist)_ogg_free(b->quantlist);
  104740. if(b->lengthlist)_ogg_free(b->lengthlist);
  104741. if(b->nearest_tree){
  104742. _ogg_free(b->nearest_tree->ptr0);
  104743. _ogg_free(b->nearest_tree->ptr1);
  104744. _ogg_free(b->nearest_tree->p);
  104745. _ogg_free(b->nearest_tree->q);
  104746. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  104747. _ogg_free(b->nearest_tree);
  104748. }
  104749. if(b->thresh_tree){
  104750. _ogg_free(b->thresh_tree->quantthresh);
  104751. _ogg_free(b->thresh_tree->quantmap);
  104752. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  104753. _ogg_free(b->thresh_tree);
  104754. }
  104755. memset(b,0,sizeof(*b));
  104756. }
  104757. }
  104758. void vorbis_staticbook_destroy(static_codebook *b){
  104759. if(b->allocedp){
  104760. vorbis_staticbook_clear(b);
  104761. _ogg_free(b);
  104762. }
  104763. }
  104764. void vorbis_book_clear(codebook *b){
  104765. if(b->valuelist)_ogg_free(b->valuelist);
  104766. if(b->codelist)_ogg_free(b->codelist);
  104767. if(b->dec_index)_ogg_free(b->dec_index);
  104768. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  104769. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  104770. memset(b,0,sizeof(*b));
  104771. }
  104772. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  104773. memset(c,0,sizeof(*c));
  104774. c->c=s;
  104775. c->entries=s->entries;
  104776. c->used_entries=s->entries;
  104777. c->dim=s->dim;
  104778. c->codelist=_make_words(s->lengthlist,s->entries,0);
  104779. c->valuelist=_book_unquantize(s,s->entries,NULL);
  104780. return(0);
  104781. }
  104782. static int sort32a(const void *a,const void *b){
  104783. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  104784. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  104785. }
  104786. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  104787. int i,j,n=0,tabn;
  104788. int *sortindex;
  104789. memset(c,0,sizeof(*c));
  104790. for(i=0;i<s->entries;i++)
  104791. if(s->lengthlist[i]>0)
  104792. n++;
  104793. c->entries=s->entries;
  104794. c->used_entries=n;
  104795. c->dim=s->dim;
  104796. {
  104797. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  104798. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  104799. if(codes==NULL)goto err_out;
  104800. for(i=0;i<n;i++){
  104801. codes[i]=ogg_bitreverse(codes[i]);
  104802. codep[i]=codes+i;
  104803. }
  104804. qsort(codep,n,sizeof(*codep),sort32a);
  104805. sortindex=(int*)alloca(n*sizeof(*sortindex));
  104806. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  104807. for(i=0;i<n;i++){
  104808. int position=codep[i]-codes;
  104809. sortindex[position]=i;
  104810. }
  104811. for(i=0;i<n;i++)
  104812. c->codelist[sortindex[i]]=codes[i];
  104813. _ogg_free(codes);
  104814. }
  104815. c->valuelist=_book_unquantize(s,n,sortindex);
  104816. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  104817. for(n=0,i=0;i<s->entries;i++)
  104818. if(s->lengthlist[i]>0)
  104819. c->dec_index[sortindex[n++]]=i;
  104820. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  104821. for(n=0,i=0;i<s->entries;i++)
  104822. if(s->lengthlist[i]>0)
  104823. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  104824. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  104825. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  104826. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  104827. tabn=1<<c->dec_firsttablen;
  104828. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  104829. c->dec_maxlength=0;
  104830. for(i=0;i<n;i++){
  104831. if(c->dec_maxlength<c->dec_codelengths[i])
  104832. c->dec_maxlength=c->dec_codelengths[i];
  104833. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  104834. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  104835. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  104836. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  104837. }
  104838. }
  104839. {
  104840. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  104841. long lo=0,hi=0;
  104842. for(i=0;i<tabn;i++){
  104843. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  104844. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  104845. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  104846. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  104847. {
  104848. unsigned long loval=lo;
  104849. unsigned long hival=n-hi;
  104850. if(loval>0x7fff)loval=0x7fff;
  104851. if(hival>0x7fff)hival=0x7fff;
  104852. c->dec_firsttable[ogg_bitreverse(word)]=
  104853. 0x80000000UL | (loval<<15) | hival;
  104854. }
  104855. }
  104856. }
  104857. }
  104858. return(0);
  104859. err_out:
  104860. vorbis_book_clear(c);
  104861. return(-1);
  104862. }
  104863. static float _dist(int el,float *ref, float *b,int step){
  104864. int i;
  104865. float acc=0.f;
  104866. for(i=0;i<el;i++){
  104867. float val=(ref[i]-b[i*step]);
  104868. acc+=val*val;
  104869. }
  104870. return(acc);
  104871. }
  104872. int _best(codebook *book, float *a, int step){
  104873. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104874. #if 0
  104875. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  104876. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  104877. #endif
  104878. int dim=book->dim;
  104879. int k,o;
  104880. if(tt){
  104881. int index=0,i;
  104882. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104883. i=tt->threshvals>>1;
  104884. if(a[o]<tt->quantthresh[i]){
  104885. for(;i>0;i--)
  104886. if(a[o]>=tt->quantthresh[i-1])
  104887. break;
  104888. }else{
  104889. for(i++;i<tt->threshvals-1;i++)
  104890. if(a[o]<tt->quantthresh[i])break;
  104891. }
  104892. index=(index*tt->quantvals)+tt->quantmap[i];
  104893. }
  104894. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  104895. use a decision tree after all
  104896. and fall through*/
  104897. return(index);
  104898. }
  104899. #if 0
  104900. if(pt){
  104901. const static_codebook *c=book->c;
  104902. int i,besti=-1;
  104903. float best=0.f;
  104904. int entry=0;
  104905. if(c->q_sequencep){
  104906. int pv;
  104907. long mul=1;
  104908. float qlast=0;
  104909. for(k=0,o=0;k<dim;k++,o+=step){
  104910. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  104911. if(pv<0 || pv>=pt->mapentries)break;
  104912. entry+=pt->pigeonmap[pv]*mul;
  104913. mul*=pt->quantvals;
  104914. qlast+=pv*pt->del+pt->min;
  104915. }
  104916. }else{
  104917. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104918. int pv=(int)((a[o]-pt->min)/pt->del);
  104919. if(pv<0 || pv>=pt->mapentries)break;
  104920. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  104921. }
  104922. }
  104923. if(k==dim && pt->fitlength[entry]){
  104924. long *list=pt->fitlist+pt->fitmap[entry];
  104925. for(i=0;i<pt->fitlength[entry];i++){
  104926. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  104927. if(besti==-1 || this<best){
  104928. best=this;
  104929. besti=list[i];
  104930. }
  104931. }
  104932. return(besti);
  104933. }
  104934. }
  104935. if(nt){
  104936. while(1){
  104937. float c=0.f;
  104938. float *p=book->valuelist+nt->p[ptr];
  104939. float *q=book->valuelist+nt->q[ptr];
  104940. for(k=0,o=0;k<dim;k++,o+=step)
  104941. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  104942. if(c>0.f) /* in A */
  104943. ptr= -nt->ptr0[ptr];
  104944. else /* in B */
  104945. ptr= -nt->ptr1[ptr];
  104946. if(ptr<=0)break;
  104947. }
  104948. return(-ptr);
  104949. }
  104950. #endif
  104951. {
  104952. const static_codebook *c=book->c;
  104953. int i,besti=-1;
  104954. float best=0.f;
  104955. float *e=book->valuelist;
  104956. for(i=0;i<book->entries;i++){
  104957. if(c->lengthlist[i]>0){
  104958. float thisx=_dist(dim,e,a,step);
  104959. if(besti==-1 || thisx<best){
  104960. best=thisx;
  104961. besti=i;
  104962. }
  104963. }
  104964. e+=dim;
  104965. }
  104966. return(besti);
  104967. }
  104968. }
  104969. long vorbis_book_codeword(codebook *book,int entry){
  104970. if(book->c) /* only use with encode; decode optimizations are
  104971. allowed to break this */
  104972. return book->codelist[entry];
  104973. return -1;
  104974. }
  104975. long vorbis_book_codelen(codebook *book,int entry){
  104976. if(book->c) /* only use with encode; decode optimizations are
  104977. allowed to break this */
  104978. return book->c->lengthlist[entry];
  104979. return -1;
  104980. }
  104981. #ifdef _V_SELFTEST
  104982. #include <stdio.h>
  104983. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  104984. static long partial_quantlist1[]={0,7,2};
  104985. static_codebook test1={
  104986. 4,16,
  104987. NULL,
  104988. 0,
  104989. 0,0,0,0,
  104990. NULL,
  104991. NULL,NULL
  104992. };
  104993. static float *test1_result=NULL;
  104994. static_codebook test2={
  104995. 4,3,
  104996. NULL,
  104997. 2,
  104998. -533200896,1611661312,4,0,
  104999. full_quantlist1,
  105000. NULL,NULL
  105001. };
  105002. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  105003. static_codebook test3={
  105004. 4,3,
  105005. NULL,
  105006. 2,
  105007. -533200896,1611661312,4,1,
  105008. full_quantlist1,
  105009. NULL,NULL
  105010. };
  105011. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105012. static_codebook test4={
  105013. 3,27,
  105014. NULL,
  105015. 1,
  105016. -533200896,1611661312,4,0,
  105017. partial_quantlist1,
  105018. NULL,NULL
  105019. };
  105020. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105021. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105022. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105023. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105024. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105025. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105026. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105027. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105028. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105029. static_codebook test5={
  105030. 3,27,
  105031. NULL,
  105032. 1,
  105033. -533200896,1611661312,4,1,
  105034. partial_quantlist1,
  105035. NULL,NULL
  105036. };
  105037. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105038. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105039. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105040. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105041. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105042. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105043. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105044. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105045. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105046. void run_test(static_codebook *b,float *comp){
  105047. float *out=_book_unquantize(b,b->entries,NULL);
  105048. int i;
  105049. if(comp){
  105050. if(!out){
  105051. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105052. exit(1);
  105053. }
  105054. for(i=0;i<b->entries*b->dim;i++)
  105055. if(fabs(out[i]-comp[i])>.0001){
  105056. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105057. "position %d, %g != %g\n",i,out[i],comp[i]);
  105058. exit(1);
  105059. }
  105060. }else{
  105061. if(out){
  105062. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105063. " correct result should have been NULL\n");
  105064. exit(1);
  105065. }
  105066. }
  105067. }
  105068. int main(){
  105069. fprintf(stderr,"Dequant test 1... ");
  105070. run_test(&test1,test1_result);
  105071. fprintf(stderr,"OK\nDequant test 2... ");
  105072. run_test(&test2,test2_result);
  105073. fprintf(stderr,"OK\nDequant test 3... ");
  105074. run_test(&test3,test3_result);
  105075. fprintf(stderr,"OK\nDequant test 4... ");
  105076. run_test(&test4,test4_result);
  105077. fprintf(stderr,"OK\nDequant test 5... ");
  105078. run_test(&test5,test5_result);
  105079. fprintf(stderr,"OK\n\n");
  105080. return(0);
  105081. }
  105082. #endif
  105083. #endif
  105084. /*** End of inlined file: sharedbook.c ***/
  105085. /*** Start of inlined file: smallft.c ***/
  105086. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105087. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105088. // tasks..
  105089. #if JUCE_MSVC
  105090. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105091. #endif
  105092. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105093. #if JUCE_USE_OGGVORBIS
  105094. #include <stdlib.h>
  105095. #include <string.h>
  105096. #include <math.h>
  105097. static void drfti1(int n, float *wa, int *ifac){
  105098. static int ntryh[4] = { 4,2,3,5 };
  105099. static float tpi = 6.28318530717958648f;
  105100. float arg,argh,argld,fi;
  105101. int ntry=0,i,j=-1;
  105102. int k1, l1, l2, ib;
  105103. int ld, ii, ip, is, nq, nr;
  105104. int ido, ipm, nfm1;
  105105. int nl=n;
  105106. int nf=0;
  105107. L101:
  105108. j++;
  105109. if (j < 4)
  105110. ntry=ntryh[j];
  105111. else
  105112. ntry+=2;
  105113. L104:
  105114. nq=nl/ntry;
  105115. nr=nl-ntry*nq;
  105116. if (nr!=0) goto L101;
  105117. nf++;
  105118. ifac[nf+1]=ntry;
  105119. nl=nq;
  105120. if(ntry!=2)goto L107;
  105121. if(nf==1)goto L107;
  105122. for (i=1;i<nf;i++){
  105123. ib=nf-i+1;
  105124. ifac[ib+1]=ifac[ib];
  105125. }
  105126. ifac[2] = 2;
  105127. L107:
  105128. if(nl!=1)goto L104;
  105129. ifac[0]=n;
  105130. ifac[1]=nf;
  105131. argh=tpi/n;
  105132. is=0;
  105133. nfm1=nf-1;
  105134. l1=1;
  105135. if(nfm1==0)return;
  105136. for (k1=0;k1<nfm1;k1++){
  105137. ip=ifac[k1+2];
  105138. ld=0;
  105139. l2=l1*ip;
  105140. ido=n/l2;
  105141. ipm=ip-1;
  105142. for (j=0;j<ipm;j++){
  105143. ld+=l1;
  105144. i=is;
  105145. argld=(float)ld*argh;
  105146. fi=0.f;
  105147. for (ii=2;ii<ido;ii+=2){
  105148. fi+=1.f;
  105149. arg=fi*argld;
  105150. wa[i++]=cos(arg);
  105151. wa[i++]=sin(arg);
  105152. }
  105153. is+=ido;
  105154. }
  105155. l1=l2;
  105156. }
  105157. }
  105158. static void fdrffti(int n, float *wsave, int *ifac){
  105159. if (n == 1) return;
  105160. drfti1(n, wsave+n, ifac);
  105161. }
  105162. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105163. int i,k;
  105164. float ti2,tr2;
  105165. int t0,t1,t2,t3,t4,t5,t6;
  105166. t1=0;
  105167. t0=(t2=l1*ido);
  105168. t3=ido<<1;
  105169. for(k=0;k<l1;k++){
  105170. ch[t1<<1]=cc[t1]+cc[t2];
  105171. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105172. t1+=ido;
  105173. t2+=ido;
  105174. }
  105175. if(ido<2)return;
  105176. if(ido==2)goto L105;
  105177. t1=0;
  105178. t2=t0;
  105179. for(k=0;k<l1;k++){
  105180. t3=t2;
  105181. t4=(t1<<1)+(ido<<1);
  105182. t5=t1;
  105183. t6=t1+t1;
  105184. for(i=2;i<ido;i+=2){
  105185. t3+=2;
  105186. t4-=2;
  105187. t5+=2;
  105188. t6+=2;
  105189. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105190. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105191. ch[t6]=cc[t5]+ti2;
  105192. ch[t4]=ti2-cc[t5];
  105193. ch[t6-1]=cc[t5-1]+tr2;
  105194. ch[t4-1]=cc[t5-1]-tr2;
  105195. }
  105196. t1+=ido;
  105197. t2+=ido;
  105198. }
  105199. if(ido%2==1)return;
  105200. L105:
  105201. t3=(t2=(t1=ido)-1);
  105202. t2+=t0;
  105203. for(k=0;k<l1;k++){
  105204. ch[t1]=-cc[t2];
  105205. ch[t1-1]=cc[t3];
  105206. t1+=ido<<1;
  105207. t2+=ido;
  105208. t3+=ido;
  105209. }
  105210. }
  105211. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105212. float *wa2,float *wa3){
  105213. static float hsqt2 = .70710678118654752f;
  105214. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105215. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105216. t0=l1*ido;
  105217. t1=t0;
  105218. t4=t1<<1;
  105219. t2=t1+(t1<<1);
  105220. t3=0;
  105221. for(k=0;k<l1;k++){
  105222. tr1=cc[t1]+cc[t2];
  105223. tr2=cc[t3]+cc[t4];
  105224. ch[t5=t3<<2]=tr1+tr2;
  105225. ch[(ido<<2)+t5-1]=tr2-tr1;
  105226. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105227. ch[t5]=cc[t2]-cc[t1];
  105228. t1+=ido;
  105229. t2+=ido;
  105230. t3+=ido;
  105231. t4+=ido;
  105232. }
  105233. if(ido<2)return;
  105234. if(ido==2)goto L105;
  105235. t1=0;
  105236. for(k=0;k<l1;k++){
  105237. t2=t1;
  105238. t4=t1<<2;
  105239. t5=(t6=ido<<1)+t4;
  105240. for(i=2;i<ido;i+=2){
  105241. t3=(t2+=2);
  105242. t4+=2;
  105243. t5-=2;
  105244. t3+=t0;
  105245. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105246. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105247. t3+=t0;
  105248. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105249. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105250. t3+=t0;
  105251. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105252. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105253. tr1=cr2+cr4;
  105254. tr4=cr4-cr2;
  105255. ti1=ci2+ci4;
  105256. ti4=ci2-ci4;
  105257. ti2=cc[t2]+ci3;
  105258. ti3=cc[t2]-ci3;
  105259. tr2=cc[t2-1]+cr3;
  105260. tr3=cc[t2-1]-cr3;
  105261. ch[t4-1]=tr1+tr2;
  105262. ch[t4]=ti1+ti2;
  105263. ch[t5-1]=tr3-ti4;
  105264. ch[t5]=tr4-ti3;
  105265. ch[t4+t6-1]=ti4+tr3;
  105266. ch[t4+t6]=tr4+ti3;
  105267. ch[t5+t6-1]=tr2-tr1;
  105268. ch[t5+t6]=ti1-ti2;
  105269. }
  105270. t1+=ido;
  105271. }
  105272. if(ido&1)return;
  105273. L105:
  105274. t2=(t1=t0+ido-1)+(t0<<1);
  105275. t3=ido<<2;
  105276. t4=ido;
  105277. t5=ido<<1;
  105278. t6=ido;
  105279. for(k=0;k<l1;k++){
  105280. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105281. tr1=hsqt2*(cc[t1]-cc[t2]);
  105282. ch[t4-1]=tr1+cc[t6-1];
  105283. ch[t4+t5-1]=cc[t6-1]-tr1;
  105284. ch[t4]=ti1-cc[t1+t0];
  105285. ch[t4+t5]=ti1+cc[t1+t0];
  105286. t1+=ido;
  105287. t2+=ido;
  105288. t4+=t3;
  105289. t6+=ido;
  105290. }
  105291. }
  105292. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105293. float *c2,float *ch,float *ch2,float *wa){
  105294. static float tpi=6.283185307179586f;
  105295. int idij,ipph,i,j,k,l,ic,ik,is;
  105296. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105297. float dc2,ai1,ai2,ar1,ar2,ds2;
  105298. int nbd;
  105299. float dcp,arg,dsp,ar1h,ar2h;
  105300. int idp2,ipp2;
  105301. arg=tpi/(float)ip;
  105302. dcp=cos(arg);
  105303. dsp=sin(arg);
  105304. ipph=(ip+1)>>1;
  105305. ipp2=ip;
  105306. idp2=ido;
  105307. nbd=(ido-1)>>1;
  105308. t0=l1*ido;
  105309. t10=ip*ido;
  105310. if(ido==1)goto L119;
  105311. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105312. t1=0;
  105313. for(j=1;j<ip;j++){
  105314. t1+=t0;
  105315. t2=t1;
  105316. for(k=0;k<l1;k++){
  105317. ch[t2]=c1[t2];
  105318. t2+=ido;
  105319. }
  105320. }
  105321. is=-ido;
  105322. t1=0;
  105323. if(nbd>l1){
  105324. for(j=1;j<ip;j++){
  105325. t1+=t0;
  105326. is+=ido;
  105327. t2= -ido+t1;
  105328. for(k=0;k<l1;k++){
  105329. idij=is-1;
  105330. t2+=ido;
  105331. t3=t2;
  105332. for(i=2;i<ido;i+=2){
  105333. idij+=2;
  105334. t3+=2;
  105335. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105336. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105337. }
  105338. }
  105339. }
  105340. }else{
  105341. for(j=1;j<ip;j++){
  105342. is+=ido;
  105343. idij=is-1;
  105344. t1+=t0;
  105345. t2=t1;
  105346. for(i=2;i<ido;i+=2){
  105347. idij+=2;
  105348. t2+=2;
  105349. t3=t2;
  105350. for(k=0;k<l1;k++){
  105351. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105352. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105353. t3+=ido;
  105354. }
  105355. }
  105356. }
  105357. }
  105358. t1=0;
  105359. t2=ipp2*t0;
  105360. if(nbd<l1){
  105361. for(j=1;j<ipph;j++){
  105362. t1+=t0;
  105363. t2-=t0;
  105364. t3=t1;
  105365. t4=t2;
  105366. for(i=2;i<ido;i+=2){
  105367. t3+=2;
  105368. t4+=2;
  105369. t5=t3-ido;
  105370. t6=t4-ido;
  105371. for(k=0;k<l1;k++){
  105372. t5+=ido;
  105373. t6+=ido;
  105374. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105375. c1[t6-1]=ch[t5]-ch[t6];
  105376. c1[t5]=ch[t5]+ch[t6];
  105377. c1[t6]=ch[t6-1]-ch[t5-1];
  105378. }
  105379. }
  105380. }
  105381. }else{
  105382. for(j=1;j<ipph;j++){
  105383. t1+=t0;
  105384. t2-=t0;
  105385. t3=t1;
  105386. t4=t2;
  105387. for(k=0;k<l1;k++){
  105388. t5=t3;
  105389. t6=t4;
  105390. for(i=2;i<ido;i+=2){
  105391. t5+=2;
  105392. t6+=2;
  105393. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105394. c1[t6-1]=ch[t5]-ch[t6];
  105395. c1[t5]=ch[t5]+ch[t6];
  105396. c1[t6]=ch[t6-1]-ch[t5-1];
  105397. }
  105398. t3+=ido;
  105399. t4+=ido;
  105400. }
  105401. }
  105402. }
  105403. L119:
  105404. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105405. t1=0;
  105406. t2=ipp2*idl1;
  105407. for(j=1;j<ipph;j++){
  105408. t1+=t0;
  105409. t2-=t0;
  105410. t3=t1-ido;
  105411. t4=t2-ido;
  105412. for(k=0;k<l1;k++){
  105413. t3+=ido;
  105414. t4+=ido;
  105415. c1[t3]=ch[t3]+ch[t4];
  105416. c1[t4]=ch[t4]-ch[t3];
  105417. }
  105418. }
  105419. ar1=1.f;
  105420. ai1=0.f;
  105421. t1=0;
  105422. t2=ipp2*idl1;
  105423. t3=(ip-1)*idl1;
  105424. for(l=1;l<ipph;l++){
  105425. t1+=idl1;
  105426. t2-=idl1;
  105427. ar1h=dcp*ar1-dsp*ai1;
  105428. ai1=dcp*ai1+dsp*ar1;
  105429. ar1=ar1h;
  105430. t4=t1;
  105431. t5=t2;
  105432. t6=t3;
  105433. t7=idl1;
  105434. for(ik=0;ik<idl1;ik++){
  105435. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105436. ch2[t5++]=ai1*c2[t6++];
  105437. }
  105438. dc2=ar1;
  105439. ds2=ai1;
  105440. ar2=ar1;
  105441. ai2=ai1;
  105442. t4=idl1;
  105443. t5=(ipp2-1)*idl1;
  105444. for(j=2;j<ipph;j++){
  105445. t4+=idl1;
  105446. t5-=idl1;
  105447. ar2h=dc2*ar2-ds2*ai2;
  105448. ai2=dc2*ai2+ds2*ar2;
  105449. ar2=ar2h;
  105450. t6=t1;
  105451. t7=t2;
  105452. t8=t4;
  105453. t9=t5;
  105454. for(ik=0;ik<idl1;ik++){
  105455. ch2[t6++]+=ar2*c2[t8++];
  105456. ch2[t7++]+=ai2*c2[t9++];
  105457. }
  105458. }
  105459. }
  105460. t1=0;
  105461. for(j=1;j<ipph;j++){
  105462. t1+=idl1;
  105463. t2=t1;
  105464. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105465. }
  105466. if(ido<l1)goto L132;
  105467. t1=0;
  105468. t2=0;
  105469. for(k=0;k<l1;k++){
  105470. t3=t1;
  105471. t4=t2;
  105472. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105473. t1+=ido;
  105474. t2+=t10;
  105475. }
  105476. goto L135;
  105477. L132:
  105478. for(i=0;i<ido;i++){
  105479. t1=i;
  105480. t2=i;
  105481. for(k=0;k<l1;k++){
  105482. cc[t2]=ch[t1];
  105483. t1+=ido;
  105484. t2+=t10;
  105485. }
  105486. }
  105487. L135:
  105488. t1=0;
  105489. t2=ido<<1;
  105490. t3=0;
  105491. t4=ipp2*t0;
  105492. for(j=1;j<ipph;j++){
  105493. t1+=t2;
  105494. t3+=t0;
  105495. t4-=t0;
  105496. t5=t1;
  105497. t6=t3;
  105498. t7=t4;
  105499. for(k=0;k<l1;k++){
  105500. cc[t5-1]=ch[t6];
  105501. cc[t5]=ch[t7];
  105502. t5+=t10;
  105503. t6+=ido;
  105504. t7+=ido;
  105505. }
  105506. }
  105507. if(ido==1)return;
  105508. if(nbd<l1)goto L141;
  105509. t1=-ido;
  105510. t3=0;
  105511. t4=0;
  105512. t5=ipp2*t0;
  105513. for(j=1;j<ipph;j++){
  105514. t1+=t2;
  105515. t3+=t2;
  105516. t4+=t0;
  105517. t5-=t0;
  105518. t6=t1;
  105519. t7=t3;
  105520. t8=t4;
  105521. t9=t5;
  105522. for(k=0;k<l1;k++){
  105523. for(i=2;i<ido;i+=2){
  105524. ic=idp2-i;
  105525. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105526. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105527. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105528. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105529. }
  105530. t6+=t10;
  105531. t7+=t10;
  105532. t8+=ido;
  105533. t9+=ido;
  105534. }
  105535. }
  105536. return;
  105537. L141:
  105538. t1=-ido;
  105539. t3=0;
  105540. t4=0;
  105541. t5=ipp2*t0;
  105542. for(j=1;j<ipph;j++){
  105543. t1+=t2;
  105544. t3+=t2;
  105545. t4+=t0;
  105546. t5-=t0;
  105547. for(i=2;i<ido;i+=2){
  105548. t6=idp2+t1-i;
  105549. t7=i+t3;
  105550. t8=i+t4;
  105551. t9=i+t5;
  105552. for(k=0;k<l1;k++){
  105553. cc[t7-1]=ch[t8-1]+ch[t9-1];
  105554. cc[t6-1]=ch[t8-1]-ch[t9-1];
  105555. cc[t7]=ch[t8]+ch[t9];
  105556. cc[t6]=ch[t9]-ch[t8];
  105557. t6+=t10;
  105558. t7+=t10;
  105559. t8+=ido;
  105560. t9+=ido;
  105561. }
  105562. }
  105563. }
  105564. }
  105565. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  105566. int i,k1,l1,l2;
  105567. int na,kh,nf;
  105568. int ip,iw,ido,idl1,ix2,ix3;
  105569. nf=ifac[1];
  105570. na=1;
  105571. l2=n;
  105572. iw=n;
  105573. for(k1=0;k1<nf;k1++){
  105574. kh=nf-k1;
  105575. ip=ifac[kh+1];
  105576. l1=l2/ip;
  105577. ido=n/l2;
  105578. idl1=ido*l1;
  105579. iw-=(ip-1)*ido;
  105580. na=1-na;
  105581. if(ip!=4)goto L102;
  105582. ix2=iw+ido;
  105583. ix3=ix2+ido;
  105584. if(na!=0)
  105585. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105586. else
  105587. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105588. goto L110;
  105589. L102:
  105590. if(ip!=2)goto L104;
  105591. if(na!=0)goto L103;
  105592. dradf2(ido,l1,c,ch,wa+iw-1);
  105593. goto L110;
  105594. L103:
  105595. dradf2(ido,l1,ch,c,wa+iw-1);
  105596. goto L110;
  105597. L104:
  105598. if(ido==1)na=1-na;
  105599. if(na!=0)goto L109;
  105600. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105601. na=1;
  105602. goto L110;
  105603. L109:
  105604. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105605. na=0;
  105606. L110:
  105607. l2=l1;
  105608. }
  105609. if(na==1)return;
  105610. for(i=0;i<n;i++)c[i]=ch[i];
  105611. }
  105612. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  105613. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105614. float ti2,tr2;
  105615. t0=l1*ido;
  105616. t1=0;
  105617. t2=0;
  105618. t3=(ido<<1)-1;
  105619. for(k=0;k<l1;k++){
  105620. ch[t1]=cc[t2]+cc[t3+t2];
  105621. ch[t1+t0]=cc[t2]-cc[t3+t2];
  105622. t2=(t1+=ido)<<1;
  105623. }
  105624. if(ido<2)return;
  105625. if(ido==2)goto L105;
  105626. t1=0;
  105627. t2=0;
  105628. for(k=0;k<l1;k++){
  105629. t3=t1;
  105630. t5=(t4=t2)+(ido<<1);
  105631. t6=t0+t1;
  105632. for(i=2;i<ido;i+=2){
  105633. t3+=2;
  105634. t4+=2;
  105635. t5-=2;
  105636. t6+=2;
  105637. ch[t3-1]=cc[t4-1]+cc[t5-1];
  105638. tr2=cc[t4-1]-cc[t5-1];
  105639. ch[t3]=cc[t4]-cc[t5];
  105640. ti2=cc[t4]+cc[t5];
  105641. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  105642. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  105643. }
  105644. t2=(t1+=ido)<<1;
  105645. }
  105646. if(ido%2==1)return;
  105647. L105:
  105648. t1=ido-1;
  105649. t2=ido-1;
  105650. for(k=0;k<l1;k++){
  105651. ch[t1]=cc[t2]+cc[t2];
  105652. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  105653. t1+=ido;
  105654. t2+=ido<<1;
  105655. }
  105656. }
  105657. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  105658. float *wa2){
  105659. static float taur = -.5f;
  105660. static float taui = .8660254037844386f;
  105661. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105662. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  105663. t0=l1*ido;
  105664. t1=0;
  105665. t2=t0<<1;
  105666. t3=ido<<1;
  105667. t4=ido+(ido<<1);
  105668. t5=0;
  105669. for(k=0;k<l1;k++){
  105670. tr2=cc[t3-1]+cc[t3-1];
  105671. cr2=cc[t5]+(taur*tr2);
  105672. ch[t1]=cc[t5]+tr2;
  105673. ci3=taui*(cc[t3]+cc[t3]);
  105674. ch[t1+t0]=cr2-ci3;
  105675. ch[t1+t2]=cr2+ci3;
  105676. t1+=ido;
  105677. t3+=t4;
  105678. t5+=t4;
  105679. }
  105680. if(ido==1)return;
  105681. t1=0;
  105682. t3=ido<<1;
  105683. for(k=0;k<l1;k++){
  105684. t7=t1+(t1<<1);
  105685. t6=(t5=t7+t3);
  105686. t8=t1;
  105687. t10=(t9=t1+t0)+t0;
  105688. for(i=2;i<ido;i+=2){
  105689. t5+=2;
  105690. t6-=2;
  105691. t7+=2;
  105692. t8+=2;
  105693. t9+=2;
  105694. t10+=2;
  105695. tr2=cc[t5-1]+cc[t6-1];
  105696. cr2=cc[t7-1]+(taur*tr2);
  105697. ch[t8-1]=cc[t7-1]+tr2;
  105698. ti2=cc[t5]-cc[t6];
  105699. ci2=cc[t7]+(taur*ti2);
  105700. ch[t8]=cc[t7]+ti2;
  105701. cr3=taui*(cc[t5-1]-cc[t6-1]);
  105702. ci3=taui*(cc[t5]+cc[t6]);
  105703. dr2=cr2-ci3;
  105704. dr3=cr2+ci3;
  105705. di2=ci2+cr3;
  105706. di3=ci2-cr3;
  105707. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  105708. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  105709. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  105710. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  105711. }
  105712. t1+=ido;
  105713. }
  105714. }
  105715. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  105716. float *wa2,float *wa3){
  105717. static float sqrt2=1.414213562373095f;
  105718. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  105719. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105720. t0=l1*ido;
  105721. t1=0;
  105722. t2=ido<<2;
  105723. t3=0;
  105724. t6=ido<<1;
  105725. for(k=0;k<l1;k++){
  105726. t4=t3+t6;
  105727. t5=t1;
  105728. tr3=cc[t4-1]+cc[t4-1];
  105729. tr4=cc[t4]+cc[t4];
  105730. tr1=cc[t3]-cc[(t4+=t6)-1];
  105731. tr2=cc[t3]+cc[t4-1];
  105732. ch[t5]=tr2+tr3;
  105733. ch[t5+=t0]=tr1-tr4;
  105734. ch[t5+=t0]=tr2-tr3;
  105735. ch[t5+=t0]=tr1+tr4;
  105736. t1+=ido;
  105737. t3+=t2;
  105738. }
  105739. if(ido<2)return;
  105740. if(ido==2)goto L105;
  105741. t1=0;
  105742. for(k=0;k<l1;k++){
  105743. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  105744. t7=t1;
  105745. for(i=2;i<ido;i+=2){
  105746. t2+=2;
  105747. t3+=2;
  105748. t4-=2;
  105749. t5-=2;
  105750. t7+=2;
  105751. ti1=cc[t2]+cc[t5];
  105752. ti2=cc[t2]-cc[t5];
  105753. ti3=cc[t3]-cc[t4];
  105754. tr4=cc[t3]+cc[t4];
  105755. tr1=cc[t2-1]-cc[t5-1];
  105756. tr2=cc[t2-1]+cc[t5-1];
  105757. ti4=cc[t3-1]-cc[t4-1];
  105758. tr3=cc[t3-1]+cc[t4-1];
  105759. ch[t7-1]=tr2+tr3;
  105760. cr3=tr2-tr3;
  105761. ch[t7]=ti2+ti3;
  105762. ci3=ti2-ti3;
  105763. cr2=tr1-tr4;
  105764. cr4=tr1+tr4;
  105765. ci2=ti1+ti4;
  105766. ci4=ti1-ti4;
  105767. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  105768. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  105769. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  105770. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  105771. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  105772. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  105773. }
  105774. t1+=ido;
  105775. }
  105776. if(ido%2 == 1)return;
  105777. L105:
  105778. t1=ido;
  105779. t2=ido<<2;
  105780. t3=ido-1;
  105781. t4=ido+(ido<<1);
  105782. for(k=0;k<l1;k++){
  105783. t5=t3;
  105784. ti1=cc[t1]+cc[t4];
  105785. ti2=cc[t4]-cc[t1];
  105786. tr1=cc[t1-1]-cc[t4-1];
  105787. tr2=cc[t1-1]+cc[t4-1];
  105788. ch[t5]=tr2+tr2;
  105789. ch[t5+=t0]=sqrt2*(tr1-ti1);
  105790. ch[t5+=t0]=ti2+ti2;
  105791. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  105792. t3+=ido;
  105793. t1+=t2;
  105794. t4+=t2;
  105795. }
  105796. }
  105797. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105798. float *c2,float *ch,float *ch2,float *wa){
  105799. static float tpi=6.283185307179586f;
  105800. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  105801. t11,t12;
  105802. float dc2,ai1,ai2,ar1,ar2,ds2;
  105803. int nbd;
  105804. float dcp,arg,dsp,ar1h,ar2h;
  105805. int ipp2;
  105806. t10=ip*ido;
  105807. t0=l1*ido;
  105808. arg=tpi/(float)ip;
  105809. dcp=cos(arg);
  105810. dsp=sin(arg);
  105811. nbd=(ido-1)>>1;
  105812. ipp2=ip;
  105813. ipph=(ip+1)>>1;
  105814. if(ido<l1)goto L103;
  105815. t1=0;
  105816. t2=0;
  105817. for(k=0;k<l1;k++){
  105818. t3=t1;
  105819. t4=t2;
  105820. for(i=0;i<ido;i++){
  105821. ch[t3]=cc[t4];
  105822. t3++;
  105823. t4++;
  105824. }
  105825. t1+=ido;
  105826. t2+=t10;
  105827. }
  105828. goto L106;
  105829. L103:
  105830. t1=0;
  105831. for(i=0;i<ido;i++){
  105832. t2=t1;
  105833. t3=t1;
  105834. for(k=0;k<l1;k++){
  105835. ch[t2]=cc[t3];
  105836. t2+=ido;
  105837. t3+=t10;
  105838. }
  105839. t1++;
  105840. }
  105841. L106:
  105842. t1=0;
  105843. t2=ipp2*t0;
  105844. t7=(t5=ido<<1);
  105845. for(j=1;j<ipph;j++){
  105846. t1+=t0;
  105847. t2-=t0;
  105848. t3=t1;
  105849. t4=t2;
  105850. t6=t5;
  105851. for(k=0;k<l1;k++){
  105852. ch[t3]=cc[t6-1]+cc[t6-1];
  105853. ch[t4]=cc[t6]+cc[t6];
  105854. t3+=ido;
  105855. t4+=ido;
  105856. t6+=t10;
  105857. }
  105858. t5+=t7;
  105859. }
  105860. if (ido == 1)goto L116;
  105861. if(nbd<l1)goto L112;
  105862. t1=0;
  105863. t2=ipp2*t0;
  105864. t7=0;
  105865. for(j=1;j<ipph;j++){
  105866. t1+=t0;
  105867. t2-=t0;
  105868. t3=t1;
  105869. t4=t2;
  105870. t7+=(ido<<1);
  105871. t8=t7;
  105872. for(k=0;k<l1;k++){
  105873. t5=t3;
  105874. t6=t4;
  105875. t9=t8;
  105876. t11=t8;
  105877. for(i=2;i<ido;i+=2){
  105878. t5+=2;
  105879. t6+=2;
  105880. t9+=2;
  105881. t11-=2;
  105882. ch[t5-1]=cc[t9-1]+cc[t11-1];
  105883. ch[t6-1]=cc[t9-1]-cc[t11-1];
  105884. ch[t5]=cc[t9]-cc[t11];
  105885. ch[t6]=cc[t9]+cc[t11];
  105886. }
  105887. t3+=ido;
  105888. t4+=ido;
  105889. t8+=t10;
  105890. }
  105891. }
  105892. goto L116;
  105893. L112:
  105894. t1=0;
  105895. t2=ipp2*t0;
  105896. t7=0;
  105897. for(j=1;j<ipph;j++){
  105898. t1+=t0;
  105899. t2-=t0;
  105900. t3=t1;
  105901. t4=t2;
  105902. t7+=(ido<<1);
  105903. t8=t7;
  105904. t9=t7;
  105905. for(i=2;i<ido;i+=2){
  105906. t3+=2;
  105907. t4+=2;
  105908. t8+=2;
  105909. t9-=2;
  105910. t5=t3;
  105911. t6=t4;
  105912. t11=t8;
  105913. t12=t9;
  105914. for(k=0;k<l1;k++){
  105915. ch[t5-1]=cc[t11-1]+cc[t12-1];
  105916. ch[t6-1]=cc[t11-1]-cc[t12-1];
  105917. ch[t5]=cc[t11]-cc[t12];
  105918. ch[t6]=cc[t11]+cc[t12];
  105919. t5+=ido;
  105920. t6+=ido;
  105921. t11+=t10;
  105922. t12+=t10;
  105923. }
  105924. }
  105925. }
  105926. L116:
  105927. ar1=1.f;
  105928. ai1=0.f;
  105929. t1=0;
  105930. t9=(t2=ipp2*idl1);
  105931. t3=(ip-1)*idl1;
  105932. for(l=1;l<ipph;l++){
  105933. t1+=idl1;
  105934. t2-=idl1;
  105935. ar1h=dcp*ar1-dsp*ai1;
  105936. ai1=dcp*ai1+dsp*ar1;
  105937. ar1=ar1h;
  105938. t4=t1;
  105939. t5=t2;
  105940. t6=0;
  105941. t7=idl1;
  105942. t8=t3;
  105943. for(ik=0;ik<idl1;ik++){
  105944. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  105945. c2[t5++]=ai1*ch2[t8++];
  105946. }
  105947. dc2=ar1;
  105948. ds2=ai1;
  105949. ar2=ar1;
  105950. ai2=ai1;
  105951. t6=idl1;
  105952. t7=t9-idl1;
  105953. for(j=2;j<ipph;j++){
  105954. t6+=idl1;
  105955. t7-=idl1;
  105956. ar2h=dc2*ar2-ds2*ai2;
  105957. ai2=dc2*ai2+ds2*ar2;
  105958. ar2=ar2h;
  105959. t4=t1;
  105960. t5=t2;
  105961. t11=t6;
  105962. t12=t7;
  105963. for(ik=0;ik<idl1;ik++){
  105964. c2[t4++]+=ar2*ch2[t11++];
  105965. c2[t5++]+=ai2*ch2[t12++];
  105966. }
  105967. }
  105968. }
  105969. t1=0;
  105970. for(j=1;j<ipph;j++){
  105971. t1+=idl1;
  105972. t2=t1;
  105973. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  105974. }
  105975. t1=0;
  105976. t2=ipp2*t0;
  105977. for(j=1;j<ipph;j++){
  105978. t1+=t0;
  105979. t2-=t0;
  105980. t3=t1;
  105981. t4=t2;
  105982. for(k=0;k<l1;k++){
  105983. ch[t3]=c1[t3]-c1[t4];
  105984. ch[t4]=c1[t3]+c1[t4];
  105985. t3+=ido;
  105986. t4+=ido;
  105987. }
  105988. }
  105989. if(ido==1)goto L132;
  105990. if(nbd<l1)goto L128;
  105991. t1=0;
  105992. t2=ipp2*t0;
  105993. for(j=1;j<ipph;j++){
  105994. t1+=t0;
  105995. t2-=t0;
  105996. t3=t1;
  105997. t4=t2;
  105998. for(k=0;k<l1;k++){
  105999. t5=t3;
  106000. t6=t4;
  106001. for(i=2;i<ido;i+=2){
  106002. t5+=2;
  106003. t6+=2;
  106004. ch[t5-1]=c1[t5-1]-c1[t6];
  106005. ch[t6-1]=c1[t5-1]+c1[t6];
  106006. ch[t5]=c1[t5]+c1[t6-1];
  106007. ch[t6]=c1[t5]-c1[t6-1];
  106008. }
  106009. t3+=ido;
  106010. t4+=ido;
  106011. }
  106012. }
  106013. goto L132;
  106014. L128:
  106015. t1=0;
  106016. t2=ipp2*t0;
  106017. for(j=1;j<ipph;j++){
  106018. t1+=t0;
  106019. t2-=t0;
  106020. t3=t1;
  106021. t4=t2;
  106022. for(i=2;i<ido;i+=2){
  106023. t3+=2;
  106024. t4+=2;
  106025. t5=t3;
  106026. t6=t4;
  106027. for(k=0;k<l1;k++){
  106028. ch[t5-1]=c1[t5-1]-c1[t6];
  106029. ch[t6-1]=c1[t5-1]+c1[t6];
  106030. ch[t5]=c1[t5]+c1[t6-1];
  106031. ch[t6]=c1[t5]-c1[t6-1];
  106032. t5+=ido;
  106033. t6+=ido;
  106034. }
  106035. }
  106036. }
  106037. L132:
  106038. if(ido==1)return;
  106039. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106040. t1=0;
  106041. for(j=1;j<ip;j++){
  106042. t2=(t1+=t0);
  106043. for(k=0;k<l1;k++){
  106044. c1[t2]=ch[t2];
  106045. t2+=ido;
  106046. }
  106047. }
  106048. if(nbd>l1)goto L139;
  106049. is= -ido-1;
  106050. t1=0;
  106051. for(j=1;j<ip;j++){
  106052. is+=ido;
  106053. t1+=t0;
  106054. idij=is;
  106055. t2=t1;
  106056. for(i=2;i<ido;i+=2){
  106057. t2+=2;
  106058. idij+=2;
  106059. t3=t2;
  106060. for(k=0;k<l1;k++){
  106061. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106062. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106063. t3+=ido;
  106064. }
  106065. }
  106066. }
  106067. return;
  106068. L139:
  106069. is= -ido-1;
  106070. t1=0;
  106071. for(j=1;j<ip;j++){
  106072. is+=ido;
  106073. t1+=t0;
  106074. t2=t1;
  106075. for(k=0;k<l1;k++){
  106076. idij=is;
  106077. t3=t2;
  106078. for(i=2;i<ido;i+=2){
  106079. idij+=2;
  106080. t3+=2;
  106081. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106082. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106083. }
  106084. t2+=ido;
  106085. }
  106086. }
  106087. }
  106088. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106089. int i,k1,l1,l2;
  106090. int na;
  106091. int nf,ip,iw,ix2,ix3,ido,idl1;
  106092. nf=ifac[1];
  106093. na=0;
  106094. l1=1;
  106095. iw=1;
  106096. for(k1=0;k1<nf;k1++){
  106097. ip=ifac[k1 + 2];
  106098. l2=ip*l1;
  106099. ido=n/l2;
  106100. idl1=ido*l1;
  106101. if(ip!=4)goto L103;
  106102. ix2=iw+ido;
  106103. ix3=ix2+ido;
  106104. if(na!=0)
  106105. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106106. else
  106107. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106108. na=1-na;
  106109. goto L115;
  106110. L103:
  106111. if(ip!=2)goto L106;
  106112. if(na!=0)
  106113. dradb2(ido,l1,ch,c,wa+iw-1);
  106114. else
  106115. dradb2(ido,l1,c,ch,wa+iw-1);
  106116. na=1-na;
  106117. goto L115;
  106118. L106:
  106119. if(ip!=3)goto L109;
  106120. ix2=iw+ido;
  106121. if(na!=0)
  106122. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106123. else
  106124. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106125. na=1-na;
  106126. goto L115;
  106127. L109:
  106128. if(na!=0)
  106129. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106130. else
  106131. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106132. if(ido==1)na=1-na;
  106133. L115:
  106134. l1=l2;
  106135. iw+=(ip-1)*ido;
  106136. }
  106137. if(na==0)return;
  106138. for(i=0;i<n;i++)c[i]=ch[i];
  106139. }
  106140. void drft_forward(drft_lookup *l,float *data){
  106141. if(l->n==1)return;
  106142. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106143. }
  106144. void drft_backward(drft_lookup *l,float *data){
  106145. if (l->n==1)return;
  106146. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106147. }
  106148. void drft_init(drft_lookup *l,int n){
  106149. l->n=n;
  106150. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106151. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106152. fdrffti(n, l->trigcache, l->splitcache);
  106153. }
  106154. void drft_clear(drft_lookup *l){
  106155. if(l){
  106156. if(l->trigcache)_ogg_free(l->trigcache);
  106157. if(l->splitcache)_ogg_free(l->splitcache);
  106158. memset(l,0,sizeof(*l));
  106159. }
  106160. }
  106161. #endif
  106162. /*** End of inlined file: smallft.c ***/
  106163. /*** Start of inlined file: synthesis.c ***/
  106164. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106165. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106166. // tasks..
  106167. #if JUCE_MSVC
  106168. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106169. #endif
  106170. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106171. #if JUCE_USE_OGGVORBIS
  106172. #include <stdio.h>
  106173. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106174. vorbis_dsp_state *vd=vb->vd;
  106175. private_state *b=(private_state*)vd->backend_state;
  106176. vorbis_info *vi=vd->vi;
  106177. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106178. oggpack_buffer *opb=&vb->opb;
  106179. int type,mode,i;
  106180. _vorbis_block_ripcord(vb);
  106181. oggpack_readinit(opb,op->packet,op->bytes);
  106182. if(oggpack_read(opb,1)!=0){
  106183. return(OV_ENOTAUDIO);
  106184. }
  106185. mode=oggpack_read(opb,b->modebits);
  106186. if(mode==-1)return(OV_EBADPACKET);
  106187. vb->mode=mode;
  106188. vb->W=ci->mode_param[mode]->blockflag;
  106189. if(vb->W){
  106190. vb->lW=oggpack_read(opb,1);
  106191. vb->nW=oggpack_read(opb,1);
  106192. if(vb->nW==-1) return(OV_EBADPACKET);
  106193. }else{
  106194. vb->lW=0;
  106195. vb->nW=0;
  106196. }
  106197. vb->granulepos=op->granulepos;
  106198. vb->sequence=op->packetno;
  106199. vb->eofflag=op->e_o_s;
  106200. vb->pcmend=ci->blocksizes[vb->W];
  106201. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106202. for(i=0;i<vi->channels;i++)
  106203. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106204. type=ci->map_type[ci->mode_param[mode]->mapping];
  106205. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106206. mapping]));
  106207. }
  106208. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106209. vorbis_dsp_state *vd=vb->vd;
  106210. private_state *b=(private_state*)vd->backend_state;
  106211. vorbis_info *vi=vd->vi;
  106212. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106213. oggpack_buffer *opb=&vb->opb;
  106214. int mode;
  106215. _vorbis_block_ripcord(vb);
  106216. oggpack_readinit(opb,op->packet,op->bytes);
  106217. if(oggpack_read(opb,1)!=0){
  106218. return(OV_ENOTAUDIO);
  106219. }
  106220. mode=oggpack_read(opb,b->modebits);
  106221. if(mode==-1)return(OV_EBADPACKET);
  106222. vb->mode=mode;
  106223. vb->W=ci->mode_param[mode]->blockflag;
  106224. if(vb->W){
  106225. vb->lW=oggpack_read(opb,1);
  106226. vb->nW=oggpack_read(opb,1);
  106227. if(vb->nW==-1) return(OV_EBADPACKET);
  106228. }else{
  106229. vb->lW=0;
  106230. vb->nW=0;
  106231. }
  106232. vb->granulepos=op->granulepos;
  106233. vb->sequence=op->packetno;
  106234. vb->eofflag=op->e_o_s;
  106235. vb->pcmend=0;
  106236. vb->pcm=NULL;
  106237. return(0);
  106238. }
  106239. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106240. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106241. oggpack_buffer opb;
  106242. int mode;
  106243. oggpack_readinit(&opb,op->packet,op->bytes);
  106244. if(oggpack_read(&opb,1)!=0){
  106245. return(OV_ENOTAUDIO);
  106246. }
  106247. {
  106248. int modebits=0;
  106249. int v=ci->modes;
  106250. while(v>1){
  106251. modebits++;
  106252. v>>=1;
  106253. }
  106254. mode=oggpack_read(&opb,modebits);
  106255. }
  106256. if(mode==-1)return(OV_EBADPACKET);
  106257. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106258. }
  106259. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106260. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106261. if(ci->blocksizes[0]<=64 && flag)return -1;
  106262. ci->halfrate_flag=(flag?1:0);
  106263. return 0;
  106264. }
  106265. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106266. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106267. return ci->halfrate_flag;
  106268. }
  106269. #endif
  106270. /*** End of inlined file: synthesis.c ***/
  106271. /*** Start of inlined file: vorbisenc.c ***/
  106272. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106273. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106274. // tasks..
  106275. #if JUCE_MSVC
  106276. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106277. #endif
  106278. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106279. #if JUCE_USE_OGGVORBIS
  106280. #include <stdlib.h>
  106281. #include <string.h>
  106282. #include <math.h>
  106283. typedef struct {
  106284. static_codebook *books[12][3];
  106285. } static_bookblock;
  106286. typedef struct {
  106287. int res_type;
  106288. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106289. vorbis_info_residue0 *res;
  106290. static_codebook *book_aux;
  106291. static_codebook *book_aux_managed;
  106292. static_bookblock *books_base;
  106293. static_bookblock *books_base_managed;
  106294. } vorbis_residue_template;
  106295. typedef struct {
  106296. vorbis_info_mapping0 *map;
  106297. vorbis_residue_template *res;
  106298. } vorbis_mapping_template;
  106299. typedef struct vp_adjblock{
  106300. int block[P_BANDS];
  106301. } vp_adjblock;
  106302. typedef struct {
  106303. int data[NOISE_COMPAND_LEVELS];
  106304. } compandblock;
  106305. typedef struct {
  106306. int att[P_NOISECURVES];
  106307. float boost;
  106308. float decay;
  106309. } att3;
  106310. typedef struct { int data[P_NOISECURVES]; } adj3;
  106311. typedef struct {
  106312. int pre[PACKETBLOBS];
  106313. int post[PACKETBLOBS];
  106314. float kHz[PACKETBLOBS];
  106315. float lowpasskHz[PACKETBLOBS];
  106316. } adj_stereo;
  106317. typedef struct {
  106318. int lo;
  106319. int hi;
  106320. int fixed;
  106321. } noiseguard;
  106322. typedef struct {
  106323. int data[P_NOISECURVES][17];
  106324. } noise3;
  106325. typedef struct {
  106326. int mappings;
  106327. double *rate_mapping;
  106328. double *quality_mapping;
  106329. int coupling_restriction;
  106330. long samplerate_min_restriction;
  106331. long samplerate_max_restriction;
  106332. int *blocksize_short;
  106333. int *blocksize_long;
  106334. att3 *psy_tone_masteratt;
  106335. int *psy_tone_0dB;
  106336. int *psy_tone_dBsuppress;
  106337. vp_adjblock *psy_tone_adj_impulse;
  106338. vp_adjblock *psy_tone_adj_long;
  106339. vp_adjblock *psy_tone_adj_other;
  106340. noiseguard *psy_noiseguards;
  106341. noise3 *psy_noise_bias_impulse;
  106342. noise3 *psy_noise_bias_padding;
  106343. noise3 *psy_noise_bias_trans;
  106344. noise3 *psy_noise_bias_long;
  106345. int *psy_noise_dBsuppress;
  106346. compandblock *psy_noise_compand;
  106347. double *psy_noise_compand_short_mapping;
  106348. double *psy_noise_compand_long_mapping;
  106349. int *psy_noise_normal_start[2];
  106350. int *psy_noise_normal_partition[2];
  106351. double *psy_noise_normal_thresh;
  106352. int *psy_ath_float;
  106353. int *psy_ath_abs;
  106354. double *psy_lowpass;
  106355. vorbis_info_psy_global *global_params;
  106356. double *global_mapping;
  106357. adj_stereo *stereo_modes;
  106358. static_codebook ***floor_books;
  106359. vorbis_info_floor1 *floor_params;
  106360. int *floor_short_mapping;
  106361. int *floor_long_mapping;
  106362. vorbis_mapping_template *maps;
  106363. } ve_setup_data_template;
  106364. static vorbis_info_mode _mode_template[2]={
  106365. {0,0,0,0},
  106366. {1,0,0,1}
  106367. };
  106368. static vorbis_info_mapping0 _map_nominal[2]={
  106369. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106370. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106371. };
  106372. /*** Start of inlined file: setup_44.h ***/
  106373. /*** Start of inlined file: floor_all.h ***/
  106374. /*** Start of inlined file: floor_books.h ***/
  106375. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106376. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106377. };
  106378. static static_codebook _huff_book_line_256x7_0sub1 = {
  106379. 1, 9,
  106380. _huff_lengthlist_line_256x7_0sub1,
  106381. 0, 0, 0, 0, 0,
  106382. NULL,
  106383. NULL,
  106384. NULL,
  106385. NULL,
  106386. 0
  106387. };
  106388. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106390. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106391. };
  106392. static static_codebook _huff_book_line_256x7_0sub2 = {
  106393. 1, 25,
  106394. _huff_lengthlist_line_256x7_0sub2,
  106395. 0, 0, 0, 0, 0,
  106396. NULL,
  106397. NULL,
  106398. NULL,
  106399. NULL,
  106400. 0
  106401. };
  106402. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106405. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106406. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106407. };
  106408. static static_codebook _huff_book_line_256x7_0sub3 = {
  106409. 1, 64,
  106410. _huff_lengthlist_line_256x7_0sub3,
  106411. 0, 0, 0, 0, 0,
  106412. NULL,
  106413. NULL,
  106414. NULL,
  106415. NULL,
  106416. 0
  106417. };
  106418. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106419. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106420. };
  106421. static static_codebook _huff_book_line_256x7_1sub1 = {
  106422. 1, 9,
  106423. _huff_lengthlist_line_256x7_1sub1,
  106424. 0, 0, 0, 0, 0,
  106425. NULL,
  106426. NULL,
  106427. NULL,
  106428. NULL,
  106429. 0
  106430. };
  106431. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106433. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106434. };
  106435. static static_codebook _huff_book_line_256x7_1sub2 = {
  106436. 1, 25,
  106437. _huff_lengthlist_line_256x7_1sub2,
  106438. 0, 0, 0, 0, 0,
  106439. NULL,
  106440. NULL,
  106441. NULL,
  106442. NULL,
  106443. 0
  106444. };
  106445. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106448. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106449. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106450. };
  106451. static static_codebook _huff_book_line_256x7_1sub3 = {
  106452. 1, 64,
  106453. _huff_lengthlist_line_256x7_1sub3,
  106454. 0, 0, 0, 0, 0,
  106455. NULL,
  106456. NULL,
  106457. NULL,
  106458. NULL,
  106459. 0
  106460. };
  106461. static long _huff_lengthlist_line_256x7_class0[] = {
  106462. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106463. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106464. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106465. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106466. };
  106467. static static_codebook _huff_book_line_256x7_class0 = {
  106468. 1, 64,
  106469. _huff_lengthlist_line_256x7_class0,
  106470. 0, 0, 0, 0, 0,
  106471. NULL,
  106472. NULL,
  106473. NULL,
  106474. NULL,
  106475. 0
  106476. };
  106477. static long _huff_lengthlist_line_256x7_class1[] = {
  106478. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106479. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106480. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106481. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106482. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106483. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106484. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106485. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106486. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106487. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106488. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106489. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106490. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106491. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106492. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106493. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106494. };
  106495. static static_codebook _huff_book_line_256x7_class1 = {
  106496. 1, 256,
  106497. _huff_lengthlist_line_256x7_class1,
  106498. 0, 0, 0, 0, 0,
  106499. NULL,
  106500. NULL,
  106501. NULL,
  106502. NULL,
  106503. 0
  106504. };
  106505. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106506. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106507. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106508. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106509. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106510. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106511. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106512. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106513. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106514. };
  106515. static static_codebook _huff_book_line_512x17_0sub0 = {
  106516. 1, 128,
  106517. _huff_lengthlist_line_512x17_0sub0,
  106518. 0, 0, 0, 0, 0,
  106519. NULL,
  106520. NULL,
  106521. NULL,
  106522. NULL,
  106523. 0
  106524. };
  106525. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106526. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106527. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106528. };
  106529. static static_codebook _huff_book_line_512x17_1sub0 = {
  106530. 1, 32,
  106531. _huff_lengthlist_line_512x17_1sub0,
  106532. 0, 0, 0, 0, 0,
  106533. NULL,
  106534. NULL,
  106535. NULL,
  106536. NULL,
  106537. 0
  106538. };
  106539. static long _huff_lengthlist_line_512x17_1sub1[] = {
  106540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106542. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  106543. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  106544. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  106545. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  106546. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  106547. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106548. };
  106549. static static_codebook _huff_book_line_512x17_1sub1 = {
  106550. 1, 128,
  106551. _huff_lengthlist_line_512x17_1sub1,
  106552. 0, 0, 0, 0, 0,
  106553. NULL,
  106554. NULL,
  106555. NULL,
  106556. NULL,
  106557. 0
  106558. };
  106559. static long _huff_lengthlist_line_512x17_2sub1[] = {
  106560. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  106561. 5, 3,
  106562. };
  106563. static static_codebook _huff_book_line_512x17_2sub1 = {
  106564. 1, 18,
  106565. _huff_lengthlist_line_512x17_2sub1,
  106566. 0, 0, 0, 0, 0,
  106567. NULL,
  106568. NULL,
  106569. NULL,
  106570. NULL,
  106571. 0
  106572. };
  106573. static long _huff_lengthlist_line_512x17_2sub2[] = {
  106574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106575. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  106576. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  106577. 9, 8,
  106578. };
  106579. static static_codebook _huff_book_line_512x17_2sub2 = {
  106580. 1, 50,
  106581. _huff_lengthlist_line_512x17_2sub2,
  106582. 0, 0, 0, 0, 0,
  106583. NULL,
  106584. NULL,
  106585. NULL,
  106586. NULL,
  106587. 0
  106588. };
  106589. static long _huff_lengthlist_line_512x17_2sub3[] = {
  106590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106593. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  106594. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  106595. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106596. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106597. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106598. };
  106599. static static_codebook _huff_book_line_512x17_2sub3 = {
  106600. 1, 128,
  106601. _huff_lengthlist_line_512x17_2sub3,
  106602. 0, 0, 0, 0, 0,
  106603. NULL,
  106604. NULL,
  106605. NULL,
  106606. NULL,
  106607. 0
  106608. };
  106609. static long _huff_lengthlist_line_512x17_3sub1[] = {
  106610. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  106611. 5, 5,
  106612. };
  106613. static static_codebook _huff_book_line_512x17_3sub1 = {
  106614. 1, 18,
  106615. _huff_lengthlist_line_512x17_3sub1,
  106616. 0, 0, 0, 0, 0,
  106617. NULL,
  106618. NULL,
  106619. NULL,
  106620. NULL,
  106621. 0
  106622. };
  106623. static long _huff_lengthlist_line_512x17_3sub2[] = {
  106624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106625. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  106626. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  106627. 11,14,
  106628. };
  106629. static static_codebook _huff_book_line_512x17_3sub2 = {
  106630. 1, 50,
  106631. _huff_lengthlist_line_512x17_3sub2,
  106632. 0, 0, 0, 0, 0,
  106633. NULL,
  106634. NULL,
  106635. NULL,
  106636. NULL,
  106637. 0
  106638. };
  106639. static long _huff_lengthlist_line_512x17_3sub3[] = {
  106640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106643. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  106644. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106645. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106646. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106647. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106648. };
  106649. static static_codebook _huff_book_line_512x17_3sub3 = {
  106650. 1, 128,
  106651. _huff_lengthlist_line_512x17_3sub3,
  106652. 0, 0, 0, 0, 0,
  106653. NULL,
  106654. NULL,
  106655. NULL,
  106656. NULL,
  106657. 0
  106658. };
  106659. static long _huff_lengthlist_line_512x17_class1[] = {
  106660. 1, 2, 3, 6, 5, 4, 7, 7,
  106661. };
  106662. static static_codebook _huff_book_line_512x17_class1 = {
  106663. 1, 8,
  106664. _huff_lengthlist_line_512x17_class1,
  106665. 0, 0, 0, 0, 0,
  106666. NULL,
  106667. NULL,
  106668. NULL,
  106669. NULL,
  106670. 0
  106671. };
  106672. static long _huff_lengthlist_line_512x17_class2[] = {
  106673. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  106674. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  106675. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  106676. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  106677. };
  106678. static static_codebook _huff_book_line_512x17_class2 = {
  106679. 1, 64,
  106680. _huff_lengthlist_line_512x17_class2,
  106681. 0, 0, 0, 0, 0,
  106682. NULL,
  106683. NULL,
  106684. NULL,
  106685. NULL,
  106686. 0
  106687. };
  106688. static long _huff_lengthlist_line_512x17_class3[] = {
  106689. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  106690. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  106691. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  106692. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  106693. };
  106694. static static_codebook _huff_book_line_512x17_class3 = {
  106695. 1, 64,
  106696. _huff_lengthlist_line_512x17_class3,
  106697. 0, 0, 0, 0, 0,
  106698. NULL,
  106699. NULL,
  106700. NULL,
  106701. NULL,
  106702. 0
  106703. };
  106704. static long _huff_lengthlist_line_128x4_class0[] = {
  106705. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  106706. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  106707. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  106708. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  106709. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  106710. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  106711. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  106712. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  106713. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  106714. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  106715. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  106716. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  106717. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  106718. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  106719. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  106720. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  106721. };
  106722. static static_codebook _huff_book_line_128x4_class0 = {
  106723. 1, 256,
  106724. _huff_lengthlist_line_128x4_class0,
  106725. 0, 0, 0, 0, 0,
  106726. NULL,
  106727. NULL,
  106728. NULL,
  106729. NULL,
  106730. 0
  106731. };
  106732. static long _huff_lengthlist_line_128x4_0sub0[] = {
  106733. 2, 2, 2, 2,
  106734. };
  106735. static static_codebook _huff_book_line_128x4_0sub0 = {
  106736. 1, 4,
  106737. _huff_lengthlist_line_128x4_0sub0,
  106738. 0, 0, 0, 0, 0,
  106739. NULL,
  106740. NULL,
  106741. NULL,
  106742. NULL,
  106743. 0
  106744. };
  106745. static long _huff_lengthlist_line_128x4_0sub1[] = {
  106746. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  106747. };
  106748. static static_codebook _huff_book_line_128x4_0sub1 = {
  106749. 1, 10,
  106750. _huff_lengthlist_line_128x4_0sub1,
  106751. 0, 0, 0, 0, 0,
  106752. NULL,
  106753. NULL,
  106754. NULL,
  106755. NULL,
  106756. 0
  106757. };
  106758. static long _huff_lengthlist_line_128x4_0sub2[] = {
  106759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  106760. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  106761. };
  106762. static static_codebook _huff_book_line_128x4_0sub2 = {
  106763. 1, 25,
  106764. _huff_lengthlist_line_128x4_0sub2,
  106765. 0, 0, 0, 0, 0,
  106766. NULL,
  106767. NULL,
  106768. NULL,
  106769. NULL,
  106770. 0
  106771. };
  106772. static long _huff_lengthlist_line_128x4_0sub3[] = {
  106773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106775. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  106776. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  106777. };
  106778. static static_codebook _huff_book_line_128x4_0sub3 = {
  106779. 1, 64,
  106780. _huff_lengthlist_line_128x4_0sub3,
  106781. 0, 0, 0, 0, 0,
  106782. NULL,
  106783. NULL,
  106784. NULL,
  106785. NULL,
  106786. 0
  106787. };
  106788. static long _huff_lengthlist_line_256x4_class0[] = {
  106789. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  106790. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  106791. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  106792. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  106793. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  106794. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  106795. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  106796. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  106797. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  106798. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  106799. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  106800. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  106801. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  106802. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  106803. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  106804. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  106805. };
  106806. static static_codebook _huff_book_line_256x4_class0 = {
  106807. 1, 256,
  106808. _huff_lengthlist_line_256x4_class0,
  106809. 0, 0, 0, 0, 0,
  106810. NULL,
  106811. NULL,
  106812. NULL,
  106813. NULL,
  106814. 0
  106815. };
  106816. static long _huff_lengthlist_line_256x4_0sub0[] = {
  106817. 2, 2, 2, 2,
  106818. };
  106819. static static_codebook _huff_book_line_256x4_0sub0 = {
  106820. 1, 4,
  106821. _huff_lengthlist_line_256x4_0sub0,
  106822. 0, 0, 0, 0, 0,
  106823. NULL,
  106824. NULL,
  106825. NULL,
  106826. NULL,
  106827. 0
  106828. };
  106829. static long _huff_lengthlist_line_256x4_0sub1[] = {
  106830. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  106831. };
  106832. static static_codebook _huff_book_line_256x4_0sub1 = {
  106833. 1, 10,
  106834. _huff_lengthlist_line_256x4_0sub1,
  106835. 0, 0, 0, 0, 0,
  106836. NULL,
  106837. NULL,
  106838. NULL,
  106839. NULL,
  106840. 0
  106841. };
  106842. static long _huff_lengthlist_line_256x4_0sub2[] = {
  106843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  106844. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  106845. };
  106846. static static_codebook _huff_book_line_256x4_0sub2 = {
  106847. 1, 25,
  106848. _huff_lengthlist_line_256x4_0sub2,
  106849. 0, 0, 0, 0, 0,
  106850. NULL,
  106851. NULL,
  106852. NULL,
  106853. NULL,
  106854. 0
  106855. };
  106856. static long _huff_lengthlist_line_256x4_0sub3[] = {
  106857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106859. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  106860. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  106861. };
  106862. static static_codebook _huff_book_line_256x4_0sub3 = {
  106863. 1, 64,
  106864. _huff_lengthlist_line_256x4_0sub3,
  106865. 0, 0, 0, 0, 0,
  106866. NULL,
  106867. NULL,
  106868. NULL,
  106869. NULL,
  106870. 0
  106871. };
  106872. static long _huff_lengthlist_line_128x7_class0[] = {
  106873. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  106874. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  106875. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  106876. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  106877. };
  106878. static static_codebook _huff_book_line_128x7_class0 = {
  106879. 1, 64,
  106880. _huff_lengthlist_line_128x7_class0,
  106881. 0, 0, 0, 0, 0,
  106882. NULL,
  106883. NULL,
  106884. NULL,
  106885. NULL,
  106886. 0
  106887. };
  106888. static long _huff_lengthlist_line_128x7_class1[] = {
  106889. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  106890. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  106891. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  106892. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  106893. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  106894. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  106895. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  106896. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  106897. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  106898. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  106899. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  106900. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  106901. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  106902. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  106903. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  106904. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  106905. };
  106906. static static_codebook _huff_book_line_128x7_class1 = {
  106907. 1, 256,
  106908. _huff_lengthlist_line_128x7_class1,
  106909. 0, 0, 0, 0, 0,
  106910. NULL,
  106911. NULL,
  106912. NULL,
  106913. NULL,
  106914. 0
  106915. };
  106916. static long _huff_lengthlist_line_128x7_0sub1[] = {
  106917. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  106918. };
  106919. static static_codebook _huff_book_line_128x7_0sub1 = {
  106920. 1, 9,
  106921. _huff_lengthlist_line_128x7_0sub1,
  106922. 0, 0, 0, 0, 0,
  106923. NULL,
  106924. NULL,
  106925. NULL,
  106926. NULL,
  106927. 0
  106928. };
  106929. static long _huff_lengthlist_line_128x7_0sub2[] = {
  106930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  106931. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  106932. };
  106933. static static_codebook _huff_book_line_128x7_0sub2 = {
  106934. 1, 25,
  106935. _huff_lengthlist_line_128x7_0sub2,
  106936. 0, 0, 0, 0, 0,
  106937. NULL,
  106938. NULL,
  106939. NULL,
  106940. NULL,
  106941. 0
  106942. };
  106943. static long _huff_lengthlist_line_128x7_0sub3[] = {
  106944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  106946. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  106947. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  106948. };
  106949. static static_codebook _huff_book_line_128x7_0sub3 = {
  106950. 1, 64,
  106951. _huff_lengthlist_line_128x7_0sub3,
  106952. 0, 0, 0, 0, 0,
  106953. NULL,
  106954. NULL,
  106955. NULL,
  106956. NULL,
  106957. 0
  106958. };
  106959. static long _huff_lengthlist_line_128x7_1sub1[] = {
  106960. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  106961. };
  106962. static static_codebook _huff_book_line_128x7_1sub1 = {
  106963. 1, 9,
  106964. _huff_lengthlist_line_128x7_1sub1,
  106965. 0, 0, 0, 0, 0,
  106966. NULL,
  106967. NULL,
  106968. NULL,
  106969. NULL,
  106970. 0
  106971. };
  106972. static long _huff_lengthlist_line_128x7_1sub2[] = {
  106973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  106974. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  106975. };
  106976. static static_codebook _huff_book_line_128x7_1sub2 = {
  106977. 1, 25,
  106978. _huff_lengthlist_line_128x7_1sub2,
  106979. 0, 0, 0, 0, 0,
  106980. NULL,
  106981. NULL,
  106982. NULL,
  106983. NULL,
  106984. 0
  106985. };
  106986. static long _huff_lengthlist_line_128x7_1sub3[] = {
  106987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  106989. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  106990. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  106991. };
  106992. static static_codebook _huff_book_line_128x7_1sub3 = {
  106993. 1, 64,
  106994. _huff_lengthlist_line_128x7_1sub3,
  106995. 0, 0, 0, 0, 0,
  106996. NULL,
  106997. NULL,
  106998. NULL,
  106999. NULL,
  107000. 0
  107001. };
  107002. static long _huff_lengthlist_line_128x11_class1[] = {
  107003. 1, 6, 3, 7, 2, 4, 5, 7,
  107004. };
  107005. static static_codebook _huff_book_line_128x11_class1 = {
  107006. 1, 8,
  107007. _huff_lengthlist_line_128x11_class1,
  107008. 0, 0, 0, 0, 0,
  107009. NULL,
  107010. NULL,
  107011. NULL,
  107012. NULL,
  107013. 0
  107014. };
  107015. static long _huff_lengthlist_line_128x11_class2[] = {
  107016. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107017. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107018. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107019. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107020. };
  107021. static static_codebook _huff_book_line_128x11_class2 = {
  107022. 1, 64,
  107023. _huff_lengthlist_line_128x11_class2,
  107024. 0, 0, 0, 0, 0,
  107025. NULL,
  107026. NULL,
  107027. NULL,
  107028. NULL,
  107029. 0
  107030. };
  107031. static long _huff_lengthlist_line_128x11_class3[] = {
  107032. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107033. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107034. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107035. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107036. };
  107037. static static_codebook _huff_book_line_128x11_class3 = {
  107038. 1, 64,
  107039. _huff_lengthlist_line_128x11_class3,
  107040. 0, 0, 0, 0, 0,
  107041. NULL,
  107042. NULL,
  107043. NULL,
  107044. NULL,
  107045. 0
  107046. };
  107047. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107048. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107049. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107050. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107051. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107052. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107053. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107054. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107055. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107056. };
  107057. static static_codebook _huff_book_line_128x11_0sub0 = {
  107058. 1, 128,
  107059. _huff_lengthlist_line_128x11_0sub0,
  107060. 0, 0, 0, 0, 0,
  107061. NULL,
  107062. NULL,
  107063. NULL,
  107064. NULL,
  107065. 0
  107066. };
  107067. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107068. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107069. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107070. };
  107071. static static_codebook _huff_book_line_128x11_1sub0 = {
  107072. 1, 32,
  107073. _huff_lengthlist_line_128x11_1sub0,
  107074. 0, 0, 0, 0, 0,
  107075. NULL,
  107076. NULL,
  107077. NULL,
  107078. NULL,
  107079. 0
  107080. };
  107081. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107084. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107085. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107086. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107087. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107088. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107089. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107090. };
  107091. static static_codebook _huff_book_line_128x11_1sub1 = {
  107092. 1, 128,
  107093. _huff_lengthlist_line_128x11_1sub1,
  107094. 0, 0, 0, 0, 0,
  107095. NULL,
  107096. NULL,
  107097. NULL,
  107098. NULL,
  107099. 0
  107100. };
  107101. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107102. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107103. 5, 5,
  107104. };
  107105. static static_codebook _huff_book_line_128x11_2sub1 = {
  107106. 1, 18,
  107107. _huff_lengthlist_line_128x11_2sub1,
  107108. 0, 0, 0, 0, 0,
  107109. NULL,
  107110. NULL,
  107111. NULL,
  107112. NULL,
  107113. 0
  107114. };
  107115. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107117. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107118. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107119. 8,11,
  107120. };
  107121. static static_codebook _huff_book_line_128x11_2sub2 = {
  107122. 1, 50,
  107123. _huff_lengthlist_line_128x11_2sub2,
  107124. 0, 0, 0, 0, 0,
  107125. NULL,
  107126. NULL,
  107127. NULL,
  107128. NULL,
  107129. 0
  107130. };
  107131. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107135. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107136. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107137. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107138. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107139. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107140. };
  107141. static static_codebook _huff_book_line_128x11_2sub3 = {
  107142. 1, 128,
  107143. _huff_lengthlist_line_128x11_2sub3,
  107144. 0, 0, 0, 0, 0,
  107145. NULL,
  107146. NULL,
  107147. NULL,
  107148. NULL,
  107149. 0
  107150. };
  107151. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107152. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107153. 5, 4,
  107154. };
  107155. static static_codebook _huff_book_line_128x11_3sub1 = {
  107156. 1, 18,
  107157. _huff_lengthlist_line_128x11_3sub1,
  107158. 0, 0, 0, 0, 0,
  107159. NULL,
  107160. NULL,
  107161. NULL,
  107162. NULL,
  107163. 0
  107164. };
  107165. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107167. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107168. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107169. 12, 6,
  107170. };
  107171. static static_codebook _huff_book_line_128x11_3sub2 = {
  107172. 1, 50,
  107173. _huff_lengthlist_line_128x11_3sub2,
  107174. 0, 0, 0, 0, 0,
  107175. NULL,
  107176. NULL,
  107177. NULL,
  107178. NULL,
  107179. 0
  107180. };
  107181. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107185. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107186. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107187. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107188. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107189. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107190. };
  107191. static static_codebook _huff_book_line_128x11_3sub3 = {
  107192. 1, 128,
  107193. _huff_lengthlist_line_128x11_3sub3,
  107194. 0, 0, 0, 0, 0,
  107195. NULL,
  107196. NULL,
  107197. NULL,
  107198. NULL,
  107199. 0
  107200. };
  107201. static long _huff_lengthlist_line_128x17_class1[] = {
  107202. 1, 3, 4, 7, 2, 5, 6, 7,
  107203. };
  107204. static static_codebook _huff_book_line_128x17_class1 = {
  107205. 1, 8,
  107206. _huff_lengthlist_line_128x17_class1,
  107207. 0, 0, 0, 0, 0,
  107208. NULL,
  107209. NULL,
  107210. NULL,
  107211. NULL,
  107212. 0
  107213. };
  107214. static long _huff_lengthlist_line_128x17_class2[] = {
  107215. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107216. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107217. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107218. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107219. };
  107220. static static_codebook _huff_book_line_128x17_class2 = {
  107221. 1, 64,
  107222. _huff_lengthlist_line_128x17_class2,
  107223. 0, 0, 0, 0, 0,
  107224. NULL,
  107225. NULL,
  107226. NULL,
  107227. NULL,
  107228. 0
  107229. };
  107230. static long _huff_lengthlist_line_128x17_class3[] = {
  107231. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107232. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107233. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107234. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107235. };
  107236. static static_codebook _huff_book_line_128x17_class3 = {
  107237. 1, 64,
  107238. _huff_lengthlist_line_128x17_class3,
  107239. 0, 0, 0, 0, 0,
  107240. NULL,
  107241. NULL,
  107242. NULL,
  107243. NULL,
  107244. 0
  107245. };
  107246. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107247. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107248. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107249. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107250. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107251. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107252. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107253. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107254. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107255. };
  107256. static static_codebook _huff_book_line_128x17_0sub0 = {
  107257. 1, 128,
  107258. _huff_lengthlist_line_128x17_0sub0,
  107259. 0, 0, 0, 0, 0,
  107260. NULL,
  107261. NULL,
  107262. NULL,
  107263. NULL,
  107264. 0
  107265. };
  107266. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107267. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107268. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107269. };
  107270. static static_codebook _huff_book_line_128x17_1sub0 = {
  107271. 1, 32,
  107272. _huff_lengthlist_line_128x17_1sub0,
  107273. 0, 0, 0, 0, 0,
  107274. NULL,
  107275. NULL,
  107276. NULL,
  107277. NULL,
  107278. 0
  107279. };
  107280. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107283. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107284. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107285. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107286. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107287. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107288. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107289. };
  107290. static static_codebook _huff_book_line_128x17_1sub1 = {
  107291. 1, 128,
  107292. _huff_lengthlist_line_128x17_1sub1,
  107293. 0, 0, 0, 0, 0,
  107294. NULL,
  107295. NULL,
  107296. NULL,
  107297. NULL,
  107298. 0
  107299. };
  107300. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107301. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107302. 9, 4,
  107303. };
  107304. static static_codebook _huff_book_line_128x17_2sub1 = {
  107305. 1, 18,
  107306. _huff_lengthlist_line_128x17_2sub1,
  107307. 0, 0, 0, 0, 0,
  107308. NULL,
  107309. NULL,
  107310. NULL,
  107311. NULL,
  107312. 0
  107313. };
  107314. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107316. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107317. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107318. 13,13,
  107319. };
  107320. static static_codebook _huff_book_line_128x17_2sub2 = {
  107321. 1, 50,
  107322. _huff_lengthlist_line_128x17_2sub2,
  107323. 0, 0, 0, 0, 0,
  107324. NULL,
  107325. NULL,
  107326. NULL,
  107327. NULL,
  107328. 0
  107329. };
  107330. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107334. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107335. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107336. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107337. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107338. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107339. };
  107340. static static_codebook _huff_book_line_128x17_2sub3 = {
  107341. 1, 128,
  107342. _huff_lengthlist_line_128x17_2sub3,
  107343. 0, 0, 0, 0, 0,
  107344. NULL,
  107345. NULL,
  107346. NULL,
  107347. NULL,
  107348. 0
  107349. };
  107350. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107351. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107352. 6, 4,
  107353. };
  107354. static static_codebook _huff_book_line_128x17_3sub1 = {
  107355. 1, 18,
  107356. _huff_lengthlist_line_128x17_3sub1,
  107357. 0, 0, 0, 0, 0,
  107358. NULL,
  107359. NULL,
  107360. NULL,
  107361. NULL,
  107362. 0
  107363. };
  107364. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107366. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107367. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107368. 10, 8,
  107369. };
  107370. static static_codebook _huff_book_line_128x17_3sub2 = {
  107371. 1, 50,
  107372. _huff_lengthlist_line_128x17_3sub2,
  107373. 0, 0, 0, 0, 0,
  107374. NULL,
  107375. NULL,
  107376. NULL,
  107377. NULL,
  107378. 0
  107379. };
  107380. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107384. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107385. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107386. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107387. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107388. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107389. };
  107390. static static_codebook _huff_book_line_128x17_3sub3 = {
  107391. 1, 128,
  107392. _huff_lengthlist_line_128x17_3sub3,
  107393. 0, 0, 0, 0, 0,
  107394. NULL,
  107395. NULL,
  107396. NULL,
  107397. NULL,
  107398. 0
  107399. };
  107400. static long _huff_lengthlist_line_1024x27_class1[] = {
  107401. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107402. };
  107403. static static_codebook _huff_book_line_1024x27_class1 = {
  107404. 1, 16,
  107405. _huff_lengthlist_line_1024x27_class1,
  107406. 0, 0, 0, 0, 0,
  107407. NULL,
  107408. NULL,
  107409. NULL,
  107410. NULL,
  107411. 0
  107412. };
  107413. static long _huff_lengthlist_line_1024x27_class2[] = {
  107414. 1, 4, 2, 6, 3, 7, 5, 7,
  107415. };
  107416. static static_codebook _huff_book_line_1024x27_class2 = {
  107417. 1, 8,
  107418. _huff_lengthlist_line_1024x27_class2,
  107419. 0, 0, 0, 0, 0,
  107420. NULL,
  107421. NULL,
  107422. NULL,
  107423. NULL,
  107424. 0
  107425. };
  107426. static long _huff_lengthlist_line_1024x27_class3[] = {
  107427. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107428. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107429. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107430. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107431. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107432. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107433. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107434. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107435. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107436. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107437. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107438. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107439. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107440. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107441. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107442. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107443. };
  107444. static static_codebook _huff_book_line_1024x27_class3 = {
  107445. 1, 256,
  107446. _huff_lengthlist_line_1024x27_class3,
  107447. 0, 0, 0, 0, 0,
  107448. NULL,
  107449. NULL,
  107450. NULL,
  107451. NULL,
  107452. 0
  107453. };
  107454. static long _huff_lengthlist_line_1024x27_class4[] = {
  107455. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107456. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107457. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107458. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107459. };
  107460. static static_codebook _huff_book_line_1024x27_class4 = {
  107461. 1, 64,
  107462. _huff_lengthlist_line_1024x27_class4,
  107463. 0, 0, 0, 0, 0,
  107464. NULL,
  107465. NULL,
  107466. NULL,
  107467. NULL,
  107468. 0
  107469. };
  107470. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107471. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107472. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107473. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107474. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107475. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107476. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107477. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107478. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107479. };
  107480. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107481. 1, 128,
  107482. _huff_lengthlist_line_1024x27_0sub0,
  107483. 0, 0, 0, 0, 0,
  107484. NULL,
  107485. NULL,
  107486. NULL,
  107487. NULL,
  107488. 0
  107489. };
  107490. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107491. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107492. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107493. };
  107494. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107495. 1, 32,
  107496. _huff_lengthlist_line_1024x27_1sub0,
  107497. 0, 0, 0, 0, 0,
  107498. NULL,
  107499. NULL,
  107500. NULL,
  107501. NULL,
  107502. 0
  107503. };
  107504. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107507. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107508. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107509. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107510. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107511. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107512. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107513. };
  107514. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107515. 1, 128,
  107516. _huff_lengthlist_line_1024x27_1sub1,
  107517. 0, 0, 0, 0, 0,
  107518. NULL,
  107519. NULL,
  107520. NULL,
  107521. NULL,
  107522. 0
  107523. };
  107524. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107525. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107526. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107527. };
  107528. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107529. 1, 32,
  107530. _huff_lengthlist_line_1024x27_2sub0,
  107531. 0, 0, 0, 0, 0,
  107532. NULL,
  107533. NULL,
  107534. NULL,
  107535. NULL,
  107536. 0
  107537. };
  107538. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  107539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107541. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  107542. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  107543. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  107544. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  107545. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  107546. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  107547. };
  107548. static static_codebook _huff_book_line_1024x27_2sub1 = {
  107549. 1, 128,
  107550. _huff_lengthlist_line_1024x27_2sub1,
  107551. 0, 0, 0, 0, 0,
  107552. NULL,
  107553. NULL,
  107554. NULL,
  107555. NULL,
  107556. 0
  107557. };
  107558. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  107559. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  107560. 5, 5,
  107561. };
  107562. static static_codebook _huff_book_line_1024x27_3sub1 = {
  107563. 1, 18,
  107564. _huff_lengthlist_line_1024x27_3sub1,
  107565. 0, 0, 0, 0, 0,
  107566. NULL,
  107567. NULL,
  107568. NULL,
  107569. NULL,
  107570. 0
  107571. };
  107572. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  107573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107574. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  107575. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  107576. 9,11,
  107577. };
  107578. static static_codebook _huff_book_line_1024x27_3sub2 = {
  107579. 1, 50,
  107580. _huff_lengthlist_line_1024x27_3sub2,
  107581. 0, 0, 0, 0, 0,
  107582. NULL,
  107583. NULL,
  107584. NULL,
  107585. NULL,
  107586. 0
  107587. };
  107588. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  107589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107592. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  107593. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  107594. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107595. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107596. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107597. };
  107598. static static_codebook _huff_book_line_1024x27_3sub3 = {
  107599. 1, 128,
  107600. _huff_lengthlist_line_1024x27_3sub3,
  107601. 0, 0, 0, 0, 0,
  107602. NULL,
  107603. NULL,
  107604. NULL,
  107605. NULL,
  107606. 0
  107607. };
  107608. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  107609. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  107610. 5, 4,
  107611. };
  107612. static static_codebook _huff_book_line_1024x27_4sub1 = {
  107613. 1, 18,
  107614. _huff_lengthlist_line_1024x27_4sub1,
  107615. 0, 0, 0, 0, 0,
  107616. NULL,
  107617. NULL,
  107618. NULL,
  107619. NULL,
  107620. 0
  107621. };
  107622. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  107623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107624. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  107625. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  107626. 9,12,
  107627. };
  107628. static static_codebook _huff_book_line_1024x27_4sub2 = {
  107629. 1, 50,
  107630. _huff_lengthlist_line_1024x27_4sub2,
  107631. 0, 0, 0, 0, 0,
  107632. NULL,
  107633. NULL,
  107634. NULL,
  107635. NULL,
  107636. 0
  107637. };
  107638. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  107639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107642. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  107643. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  107644. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107645. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107646. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  107647. };
  107648. static static_codebook _huff_book_line_1024x27_4sub3 = {
  107649. 1, 128,
  107650. _huff_lengthlist_line_1024x27_4sub3,
  107651. 0, 0, 0, 0, 0,
  107652. NULL,
  107653. NULL,
  107654. NULL,
  107655. NULL,
  107656. 0
  107657. };
  107658. static long _huff_lengthlist_line_2048x27_class1[] = {
  107659. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  107660. };
  107661. static static_codebook _huff_book_line_2048x27_class1 = {
  107662. 1, 16,
  107663. _huff_lengthlist_line_2048x27_class1,
  107664. 0, 0, 0, 0, 0,
  107665. NULL,
  107666. NULL,
  107667. NULL,
  107668. NULL,
  107669. 0
  107670. };
  107671. static long _huff_lengthlist_line_2048x27_class2[] = {
  107672. 1, 2, 3, 6, 4, 7, 5, 7,
  107673. };
  107674. static static_codebook _huff_book_line_2048x27_class2 = {
  107675. 1, 8,
  107676. _huff_lengthlist_line_2048x27_class2,
  107677. 0, 0, 0, 0, 0,
  107678. NULL,
  107679. NULL,
  107680. NULL,
  107681. NULL,
  107682. 0
  107683. };
  107684. static long _huff_lengthlist_line_2048x27_class3[] = {
  107685. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  107686. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  107687. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  107688. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  107689. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  107690. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  107691. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  107692. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  107693. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  107694. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  107695. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  107696. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107697. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  107698. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  107699. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107700. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107701. };
  107702. static static_codebook _huff_book_line_2048x27_class3 = {
  107703. 1, 256,
  107704. _huff_lengthlist_line_2048x27_class3,
  107705. 0, 0, 0, 0, 0,
  107706. NULL,
  107707. NULL,
  107708. NULL,
  107709. NULL,
  107710. 0
  107711. };
  107712. static long _huff_lengthlist_line_2048x27_class4[] = {
  107713. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  107714. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  107715. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  107716. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  107717. };
  107718. static static_codebook _huff_book_line_2048x27_class4 = {
  107719. 1, 64,
  107720. _huff_lengthlist_line_2048x27_class4,
  107721. 0, 0, 0, 0, 0,
  107722. NULL,
  107723. NULL,
  107724. NULL,
  107725. NULL,
  107726. 0
  107727. };
  107728. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  107729. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107730. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  107731. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  107732. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  107733. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  107734. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  107735. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  107736. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  107737. };
  107738. static static_codebook _huff_book_line_2048x27_0sub0 = {
  107739. 1, 128,
  107740. _huff_lengthlist_line_2048x27_0sub0,
  107741. 0, 0, 0, 0, 0,
  107742. NULL,
  107743. NULL,
  107744. NULL,
  107745. NULL,
  107746. 0
  107747. };
  107748. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  107749. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107750. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  107751. };
  107752. static static_codebook _huff_book_line_2048x27_1sub0 = {
  107753. 1, 32,
  107754. _huff_lengthlist_line_2048x27_1sub0,
  107755. 0, 0, 0, 0, 0,
  107756. NULL,
  107757. NULL,
  107758. NULL,
  107759. NULL,
  107760. 0
  107761. };
  107762. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  107763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107765. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  107766. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  107767. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  107768. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  107769. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  107770. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  107771. };
  107772. static static_codebook _huff_book_line_2048x27_1sub1 = {
  107773. 1, 128,
  107774. _huff_lengthlist_line_2048x27_1sub1,
  107775. 0, 0, 0, 0, 0,
  107776. NULL,
  107777. NULL,
  107778. NULL,
  107779. NULL,
  107780. 0
  107781. };
  107782. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  107783. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107784. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  107785. };
  107786. static static_codebook _huff_book_line_2048x27_2sub0 = {
  107787. 1, 32,
  107788. _huff_lengthlist_line_2048x27_2sub0,
  107789. 0, 0, 0, 0, 0,
  107790. NULL,
  107791. NULL,
  107792. NULL,
  107793. NULL,
  107794. 0
  107795. };
  107796. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  107797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107799. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  107800. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  107801. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  107802. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  107803. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  107804. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107805. };
  107806. static static_codebook _huff_book_line_2048x27_2sub1 = {
  107807. 1, 128,
  107808. _huff_lengthlist_line_2048x27_2sub1,
  107809. 0, 0, 0, 0, 0,
  107810. NULL,
  107811. NULL,
  107812. NULL,
  107813. NULL,
  107814. 0
  107815. };
  107816. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  107817. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  107818. 5, 5,
  107819. };
  107820. static static_codebook _huff_book_line_2048x27_3sub1 = {
  107821. 1, 18,
  107822. _huff_lengthlist_line_2048x27_3sub1,
  107823. 0, 0, 0, 0, 0,
  107824. NULL,
  107825. NULL,
  107826. NULL,
  107827. NULL,
  107828. 0
  107829. };
  107830. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  107831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107832. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  107833. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  107834. 10,12,
  107835. };
  107836. static static_codebook _huff_book_line_2048x27_3sub2 = {
  107837. 1, 50,
  107838. _huff_lengthlist_line_2048x27_3sub2,
  107839. 0, 0, 0, 0, 0,
  107840. NULL,
  107841. NULL,
  107842. NULL,
  107843. NULL,
  107844. 0
  107845. };
  107846. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  107847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107850. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  107851. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107852. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107853. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107854. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107855. };
  107856. static static_codebook _huff_book_line_2048x27_3sub3 = {
  107857. 1, 128,
  107858. _huff_lengthlist_line_2048x27_3sub3,
  107859. 0, 0, 0, 0, 0,
  107860. NULL,
  107861. NULL,
  107862. NULL,
  107863. NULL,
  107864. 0
  107865. };
  107866. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  107867. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  107868. 4, 5,
  107869. };
  107870. static static_codebook _huff_book_line_2048x27_4sub1 = {
  107871. 1, 18,
  107872. _huff_lengthlist_line_2048x27_4sub1,
  107873. 0, 0, 0, 0, 0,
  107874. NULL,
  107875. NULL,
  107876. NULL,
  107877. NULL,
  107878. 0
  107879. };
  107880. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  107881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107882. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  107883. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  107884. 10,10,
  107885. };
  107886. static static_codebook _huff_book_line_2048x27_4sub2 = {
  107887. 1, 50,
  107888. _huff_lengthlist_line_2048x27_4sub2,
  107889. 0, 0, 0, 0, 0,
  107890. NULL,
  107891. NULL,
  107892. NULL,
  107893. NULL,
  107894. 0
  107895. };
  107896. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  107897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107900. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  107901. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  107902. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107903. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107904. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107905. };
  107906. static static_codebook _huff_book_line_2048x27_4sub3 = {
  107907. 1, 128,
  107908. _huff_lengthlist_line_2048x27_4sub3,
  107909. 0, 0, 0, 0, 0,
  107910. NULL,
  107911. NULL,
  107912. NULL,
  107913. NULL,
  107914. 0
  107915. };
  107916. static long _huff_lengthlist_line_256x4low_class0[] = {
  107917. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  107918. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  107919. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  107920. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  107921. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  107922. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  107923. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  107924. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  107925. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  107926. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  107927. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  107928. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  107929. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  107930. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  107931. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  107932. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  107933. };
  107934. static static_codebook _huff_book_line_256x4low_class0 = {
  107935. 1, 256,
  107936. _huff_lengthlist_line_256x4low_class0,
  107937. 0, 0, 0, 0, 0,
  107938. NULL,
  107939. NULL,
  107940. NULL,
  107941. NULL,
  107942. 0
  107943. };
  107944. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  107945. 1, 3, 2, 3,
  107946. };
  107947. static static_codebook _huff_book_line_256x4low_0sub0 = {
  107948. 1, 4,
  107949. _huff_lengthlist_line_256x4low_0sub0,
  107950. 0, 0, 0, 0, 0,
  107951. NULL,
  107952. NULL,
  107953. NULL,
  107954. NULL,
  107955. 0
  107956. };
  107957. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  107958. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  107959. };
  107960. static static_codebook _huff_book_line_256x4low_0sub1 = {
  107961. 1, 10,
  107962. _huff_lengthlist_line_256x4low_0sub1,
  107963. 0, 0, 0, 0, 0,
  107964. NULL,
  107965. NULL,
  107966. NULL,
  107967. NULL,
  107968. 0
  107969. };
  107970. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  107971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  107972. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  107973. };
  107974. static static_codebook _huff_book_line_256x4low_0sub2 = {
  107975. 1, 25,
  107976. _huff_lengthlist_line_256x4low_0sub2,
  107977. 0, 0, 0, 0, 0,
  107978. NULL,
  107979. NULL,
  107980. NULL,
  107981. NULL,
  107982. 0
  107983. };
  107984. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  107985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  107987. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  107988. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  107989. };
  107990. static static_codebook _huff_book_line_256x4low_0sub3 = {
  107991. 1, 64,
  107992. _huff_lengthlist_line_256x4low_0sub3,
  107993. 0, 0, 0, 0, 0,
  107994. NULL,
  107995. NULL,
  107996. NULL,
  107997. NULL,
  107998. 0
  107999. };
  108000. /*** End of inlined file: floor_books.h ***/
  108001. static static_codebook *_floor_128x4_books[]={
  108002. &_huff_book_line_128x4_class0,
  108003. &_huff_book_line_128x4_0sub0,
  108004. &_huff_book_line_128x4_0sub1,
  108005. &_huff_book_line_128x4_0sub2,
  108006. &_huff_book_line_128x4_0sub3,
  108007. };
  108008. static static_codebook *_floor_256x4_books[]={
  108009. &_huff_book_line_256x4_class0,
  108010. &_huff_book_line_256x4_0sub0,
  108011. &_huff_book_line_256x4_0sub1,
  108012. &_huff_book_line_256x4_0sub2,
  108013. &_huff_book_line_256x4_0sub3,
  108014. };
  108015. static static_codebook *_floor_128x7_books[]={
  108016. &_huff_book_line_128x7_class0,
  108017. &_huff_book_line_128x7_class1,
  108018. &_huff_book_line_128x7_0sub1,
  108019. &_huff_book_line_128x7_0sub2,
  108020. &_huff_book_line_128x7_0sub3,
  108021. &_huff_book_line_128x7_1sub1,
  108022. &_huff_book_line_128x7_1sub2,
  108023. &_huff_book_line_128x7_1sub3,
  108024. };
  108025. static static_codebook *_floor_256x7_books[]={
  108026. &_huff_book_line_256x7_class0,
  108027. &_huff_book_line_256x7_class1,
  108028. &_huff_book_line_256x7_0sub1,
  108029. &_huff_book_line_256x7_0sub2,
  108030. &_huff_book_line_256x7_0sub3,
  108031. &_huff_book_line_256x7_1sub1,
  108032. &_huff_book_line_256x7_1sub2,
  108033. &_huff_book_line_256x7_1sub3,
  108034. };
  108035. static static_codebook *_floor_128x11_books[]={
  108036. &_huff_book_line_128x11_class1,
  108037. &_huff_book_line_128x11_class2,
  108038. &_huff_book_line_128x11_class3,
  108039. &_huff_book_line_128x11_0sub0,
  108040. &_huff_book_line_128x11_1sub0,
  108041. &_huff_book_line_128x11_1sub1,
  108042. &_huff_book_line_128x11_2sub1,
  108043. &_huff_book_line_128x11_2sub2,
  108044. &_huff_book_line_128x11_2sub3,
  108045. &_huff_book_line_128x11_3sub1,
  108046. &_huff_book_line_128x11_3sub2,
  108047. &_huff_book_line_128x11_3sub3,
  108048. };
  108049. static static_codebook *_floor_128x17_books[]={
  108050. &_huff_book_line_128x17_class1,
  108051. &_huff_book_line_128x17_class2,
  108052. &_huff_book_line_128x17_class3,
  108053. &_huff_book_line_128x17_0sub0,
  108054. &_huff_book_line_128x17_1sub0,
  108055. &_huff_book_line_128x17_1sub1,
  108056. &_huff_book_line_128x17_2sub1,
  108057. &_huff_book_line_128x17_2sub2,
  108058. &_huff_book_line_128x17_2sub3,
  108059. &_huff_book_line_128x17_3sub1,
  108060. &_huff_book_line_128x17_3sub2,
  108061. &_huff_book_line_128x17_3sub3,
  108062. };
  108063. static static_codebook *_floor_256x4low_books[]={
  108064. &_huff_book_line_256x4low_class0,
  108065. &_huff_book_line_256x4low_0sub0,
  108066. &_huff_book_line_256x4low_0sub1,
  108067. &_huff_book_line_256x4low_0sub2,
  108068. &_huff_book_line_256x4low_0sub3,
  108069. };
  108070. static static_codebook *_floor_1024x27_books[]={
  108071. &_huff_book_line_1024x27_class1,
  108072. &_huff_book_line_1024x27_class2,
  108073. &_huff_book_line_1024x27_class3,
  108074. &_huff_book_line_1024x27_class4,
  108075. &_huff_book_line_1024x27_0sub0,
  108076. &_huff_book_line_1024x27_1sub0,
  108077. &_huff_book_line_1024x27_1sub1,
  108078. &_huff_book_line_1024x27_2sub0,
  108079. &_huff_book_line_1024x27_2sub1,
  108080. &_huff_book_line_1024x27_3sub1,
  108081. &_huff_book_line_1024x27_3sub2,
  108082. &_huff_book_line_1024x27_3sub3,
  108083. &_huff_book_line_1024x27_4sub1,
  108084. &_huff_book_line_1024x27_4sub2,
  108085. &_huff_book_line_1024x27_4sub3,
  108086. };
  108087. static static_codebook *_floor_2048x27_books[]={
  108088. &_huff_book_line_2048x27_class1,
  108089. &_huff_book_line_2048x27_class2,
  108090. &_huff_book_line_2048x27_class3,
  108091. &_huff_book_line_2048x27_class4,
  108092. &_huff_book_line_2048x27_0sub0,
  108093. &_huff_book_line_2048x27_1sub0,
  108094. &_huff_book_line_2048x27_1sub1,
  108095. &_huff_book_line_2048x27_2sub0,
  108096. &_huff_book_line_2048x27_2sub1,
  108097. &_huff_book_line_2048x27_3sub1,
  108098. &_huff_book_line_2048x27_3sub2,
  108099. &_huff_book_line_2048x27_3sub3,
  108100. &_huff_book_line_2048x27_4sub1,
  108101. &_huff_book_line_2048x27_4sub2,
  108102. &_huff_book_line_2048x27_4sub3,
  108103. };
  108104. static static_codebook *_floor_512x17_books[]={
  108105. &_huff_book_line_512x17_class1,
  108106. &_huff_book_line_512x17_class2,
  108107. &_huff_book_line_512x17_class3,
  108108. &_huff_book_line_512x17_0sub0,
  108109. &_huff_book_line_512x17_1sub0,
  108110. &_huff_book_line_512x17_1sub1,
  108111. &_huff_book_line_512x17_2sub1,
  108112. &_huff_book_line_512x17_2sub2,
  108113. &_huff_book_line_512x17_2sub3,
  108114. &_huff_book_line_512x17_3sub1,
  108115. &_huff_book_line_512x17_3sub2,
  108116. &_huff_book_line_512x17_3sub3,
  108117. };
  108118. static static_codebook **_floor_books[10]={
  108119. _floor_128x4_books,
  108120. _floor_256x4_books,
  108121. _floor_128x7_books,
  108122. _floor_256x7_books,
  108123. _floor_128x11_books,
  108124. _floor_128x17_books,
  108125. _floor_256x4low_books,
  108126. _floor_1024x27_books,
  108127. _floor_2048x27_books,
  108128. _floor_512x17_books,
  108129. };
  108130. static vorbis_info_floor1 _floor[10]={
  108131. {
  108132. 1,{0},{4},{2},{0},
  108133. {{1,2,3,4}},
  108134. 4,{0,128, 33,8,16,70},
  108135. 60,30,500, 1.,18., -1
  108136. },
  108137. {
  108138. 1,{0},{4},{2},{0},
  108139. {{1,2,3,4}},
  108140. 4,{0,256, 66,16,32,140},
  108141. 60,30,500, 1.,18., -1
  108142. },
  108143. {
  108144. 2,{0,1},{3,4},{2,2},{0,1},
  108145. {{-1,2,3,4},{-1,5,6,7}},
  108146. 4,{0,128, 14,4,58, 2,8,28,90},
  108147. 60,30,500, 1.,18., -1
  108148. },
  108149. {
  108150. 2,{0,1},{3,4},{2,2},{0,1},
  108151. {{-1,2,3,4},{-1,5,6,7}},
  108152. 4,{0,256, 28,8,116, 4,16,56,180},
  108153. 60,30,500, 1.,18., -1
  108154. },
  108155. {
  108156. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108157. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108158. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108159. 60,30,500, 1,18., -1
  108160. },
  108161. {
  108162. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108163. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108164. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108165. 60,30,500, 1,18., -1
  108166. },
  108167. {
  108168. 1,{0},{4},{2},{0},
  108169. {{1,2,3,4}},
  108170. 4,{0,256, 66,16,32,140},
  108171. 60,30,500, 1.,18., -1
  108172. },
  108173. {
  108174. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108175. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108176. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108177. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108178. 60,30,500, 3,18., -1 /* lowpass */
  108179. },
  108180. {
  108181. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108182. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108183. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108184. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108185. 60,30,500, 3,18., -1 /* lowpass */
  108186. },
  108187. {
  108188. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108189. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108190. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108191. 7,23,39, 55,79,110, 156,232,360},
  108192. 60,30,500, 1,18., -1 /* lowpass! */
  108193. },
  108194. };
  108195. /*** End of inlined file: floor_all.h ***/
  108196. /*** Start of inlined file: residue_44.h ***/
  108197. /*** Start of inlined file: res_books_stereo.h ***/
  108198. static long _vq_quantlist__16c0_s_p1_0[] = {
  108199. 1,
  108200. 0,
  108201. 2,
  108202. };
  108203. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108204. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108205. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108210. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108215. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 8, 0, 0, 0, 0,
  108250. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0,
  108255. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 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, 7,10,10, 0, 0,
  108260. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108296. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108301. 0, 0, 0, 0, 0, 9,10,12, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108306. 0, 0, 0, 0, 0, 0, 9,12, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108541. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108612. 0, 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,
  108615. };
  108616. static float _vq_quantthresh__16c0_s_p1_0[] = {
  108617. -0.5, 0.5,
  108618. };
  108619. static long _vq_quantmap__16c0_s_p1_0[] = {
  108620. 1, 0, 2,
  108621. };
  108622. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  108623. _vq_quantthresh__16c0_s_p1_0,
  108624. _vq_quantmap__16c0_s_p1_0,
  108625. 3,
  108626. 3
  108627. };
  108628. static static_codebook _16c0_s_p1_0 = {
  108629. 8, 6561,
  108630. _vq_lengthlist__16c0_s_p1_0,
  108631. 1, -535822336, 1611661312, 2, 0,
  108632. _vq_quantlist__16c0_s_p1_0,
  108633. NULL,
  108634. &_vq_auxt__16c0_s_p1_0,
  108635. NULL,
  108636. 0
  108637. };
  108638. static long _vq_quantlist__16c0_s_p2_0[] = {
  108639. 2,
  108640. 1,
  108641. 3,
  108642. 0,
  108643. 4,
  108644. };
  108645. static long _vq_lengthlist__16c0_s_p2_0[] = {
  108646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108685. 0,
  108686. };
  108687. static float _vq_quantthresh__16c0_s_p2_0[] = {
  108688. -1.5, -0.5, 0.5, 1.5,
  108689. };
  108690. static long _vq_quantmap__16c0_s_p2_0[] = {
  108691. 3, 1, 0, 2, 4,
  108692. };
  108693. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  108694. _vq_quantthresh__16c0_s_p2_0,
  108695. _vq_quantmap__16c0_s_p2_0,
  108696. 5,
  108697. 5
  108698. };
  108699. static static_codebook _16c0_s_p2_0 = {
  108700. 4, 625,
  108701. _vq_lengthlist__16c0_s_p2_0,
  108702. 1, -533725184, 1611661312, 3, 0,
  108703. _vq_quantlist__16c0_s_p2_0,
  108704. NULL,
  108705. &_vq_auxt__16c0_s_p2_0,
  108706. NULL,
  108707. 0
  108708. };
  108709. static long _vq_quantlist__16c0_s_p3_0[] = {
  108710. 2,
  108711. 1,
  108712. 3,
  108713. 0,
  108714. 4,
  108715. };
  108716. static long _vq_lengthlist__16c0_s_p3_0[] = {
  108717. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  108719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108720. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  108722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108723. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  108724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108756. 0,
  108757. };
  108758. static float _vq_quantthresh__16c0_s_p3_0[] = {
  108759. -1.5, -0.5, 0.5, 1.5,
  108760. };
  108761. static long _vq_quantmap__16c0_s_p3_0[] = {
  108762. 3, 1, 0, 2, 4,
  108763. };
  108764. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  108765. _vq_quantthresh__16c0_s_p3_0,
  108766. _vq_quantmap__16c0_s_p3_0,
  108767. 5,
  108768. 5
  108769. };
  108770. static static_codebook _16c0_s_p3_0 = {
  108771. 4, 625,
  108772. _vq_lengthlist__16c0_s_p3_0,
  108773. 1, -533725184, 1611661312, 3, 0,
  108774. _vq_quantlist__16c0_s_p3_0,
  108775. NULL,
  108776. &_vq_auxt__16c0_s_p3_0,
  108777. NULL,
  108778. 0
  108779. };
  108780. static long _vq_quantlist__16c0_s_p4_0[] = {
  108781. 4,
  108782. 3,
  108783. 5,
  108784. 2,
  108785. 6,
  108786. 1,
  108787. 7,
  108788. 0,
  108789. 8,
  108790. };
  108791. static long _vq_lengthlist__16c0_s_p4_0[] = {
  108792. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  108793. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  108794. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  108795. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  108796. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108797. 0,
  108798. };
  108799. static float _vq_quantthresh__16c0_s_p4_0[] = {
  108800. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108801. };
  108802. static long _vq_quantmap__16c0_s_p4_0[] = {
  108803. 7, 5, 3, 1, 0, 2, 4, 6,
  108804. 8,
  108805. };
  108806. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  108807. _vq_quantthresh__16c0_s_p4_0,
  108808. _vq_quantmap__16c0_s_p4_0,
  108809. 9,
  108810. 9
  108811. };
  108812. static static_codebook _16c0_s_p4_0 = {
  108813. 2, 81,
  108814. _vq_lengthlist__16c0_s_p4_0,
  108815. 1, -531628032, 1611661312, 4, 0,
  108816. _vq_quantlist__16c0_s_p4_0,
  108817. NULL,
  108818. &_vq_auxt__16c0_s_p4_0,
  108819. NULL,
  108820. 0
  108821. };
  108822. static long _vq_quantlist__16c0_s_p5_0[] = {
  108823. 4,
  108824. 3,
  108825. 5,
  108826. 2,
  108827. 6,
  108828. 1,
  108829. 7,
  108830. 0,
  108831. 8,
  108832. };
  108833. static long _vq_lengthlist__16c0_s_p5_0[] = {
  108834. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  108835. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  108836. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  108837. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  108838. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  108839. 10,
  108840. };
  108841. static float _vq_quantthresh__16c0_s_p5_0[] = {
  108842. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108843. };
  108844. static long _vq_quantmap__16c0_s_p5_0[] = {
  108845. 7, 5, 3, 1, 0, 2, 4, 6,
  108846. 8,
  108847. };
  108848. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  108849. _vq_quantthresh__16c0_s_p5_0,
  108850. _vq_quantmap__16c0_s_p5_0,
  108851. 9,
  108852. 9
  108853. };
  108854. static static_codebook _16c0_s_p5_0 = {
  108855. 2, 81,
  108856. _vq_lengthlist__16c0_s_p5_0,
  108857. 1, -531628032, 1611661312, 4, 0,
  108858. _vq_quantlist__16c0_s_p5_0,
  108859. NULL,
  108860. &_vq_auxt__16c0_s_p5_0,
  108861. NULL,
  108862. 0
  108863. };
  108864. static long _vq_quantlist__16c0_s_p6_0[] = {
  108865. 8,
  108866. 7,
  108867. 9,
  108868. 6,
  108869. 10,
  108870. 5,
  108871. 11,
  108872. 4,
  108873. 12,
  108874. 3,
  108875. 13,
  108876. 2,
  108877. 14,
  108878. 1,
  108879. 15,
  108880. 0,
  108881. 16,
  108882. };
  108883. static long _vq_lengthlist__16c0_s_p6_0[] = {
  108884. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  108885. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  108886. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  108887. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  108888. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  108889. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  108890. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  108891. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  108892. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  108893. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  108894. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  108895. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  108896. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  108897. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  108898. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  108899. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  108900. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  108901. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  108902. 14,
  108903. };
  108904. static float _vq_quantthresh__16c0_s_p6_0[] = {
  108905. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  108906. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  108907. };
  108908. static long _vq_quantmap__16c0_s_p6_0[] = {
  108909. 15, 13, 11, 9, 7, 5, 3, 1,
  108910. 0, 2, 4, 6, 8, 10, 12, 14,
  108911. 16,
  108912. };
  108913. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  108914. _vq_quantthresh__16c0_s_p6_0,
  108915. _vq_quantmap__16c0_s_p6_0,
  108916. 17,
  108917. 17
  108918. };
  108919. static static_codebook _16c0_s_p6_0 = {
  108920. 2, 289,
  108921. _vq_lengthlist__16c0_s_p6_0,
  108922. 1, -529530880, 1611661312, 5, 0,
  108923. _vq_quantlist__16c0_s_p6_0,
  108924. NULL,
  108925. &_vq_auxt__16c0_s_p6_0,
  108926. NULL,
  108927. 0
  108928. };
  108929. static long _vq_quantlist__16c0_s_p7_0[] = {
  108930. 1,
  108931. 0,
  108932. 2,
  108933. };
  108934. static long _vq_lengthlist__16c0_s_p7_0[] = {
  108935. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  108936. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  108937. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  108938. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  108939. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  108940. 13,
  108941. };
  108942. static float _vq_quantthresh__16c0_s_p7_0[] = {
  108943. -5.5, 5.5,
  108944. };
  108945. static long _vq_quantmap__16c0_s_p7_0[] = {
  108946. 1, 0, 2,
  108947. };
  108948. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  108949. _vq_quantthresh__16c0_s_p7_0,
  108950. _vq_quantmap__16c0_s_p7_0,
  108951. 3,
  108952. 3
  108953. };
  108954. static static_codebook _16c0_s_p7_0 = {
  108955. 4, 81,
  108956. _vq_lengthlist__16c0_s_p7_0,
  108957. 1, -529137664, 1618345984, 2, 0,
  108958. _vq_quantlist__16c0_s_p7_0,
  108959. NULL,
  108960. &_vq_auxt__16c0_s_p7_0,
  108961. NULL,
  108962. 0
  108963. };
  108964. static long _vq_quantlist__16c0_s_p7_1[] = {
  108965. 5,
  108966. 4,
  108967. 6,
  108968. 3,
  108969. 7,
  108970. 2,
  108971. 8,
  108972. 1,
  108973. 9,
  108974. 0,
  108975. 10,
  108976. };
  108977. static long _vq_lengthlist__16c0_s_p7_1[] = {
  108978. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  108979. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  108980. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  108981. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  108982. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  108983. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  108984. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  108985. 11,11,11, 9, 9, 9, 9,10,10,
  108986. };
  108987. static float _vq_quantthresh__16c0_s_p7_1[] = {
  108988. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  108989. 3.5, 4.5,
  108990. };
  108991. static long _vq_quantmap__16c0_s_p7_1[] = {
  108992. 9, 7, 5, 3, 1, 0, 2, 4,
  108993. 6, 8, 10,
  108994. };
  108995. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  108996. _vq_quantthresh__16c0_s_p7_1,
  108997. _vq_quantmap__16c0_s_p7_1,
  108998. 11,
  108999. 11
  109000. };
  109001. static static_codebook _16c0_s_p7_1 = {
  109002. 2, 121,
  109003. _vq_lengthlist__16c0_s_p7_1,
  109004. 1, -531365888, 1611661312, 4, 0,
  109005. _vq_quantlist__16c0_s_p7_1,
  109006. NULL,
  109007. &_vq_auxt__16c0_s_p7_1,
  109008. NULL,
  109009. 0
  109010. };
  109011. static long _vq_quantlist__16c0_s_p8_0[] = {
  109012. 6,
  109013. 5,
  109014. 7,
  109015. 4,
  109016. 8,
  109017. 3,
  109018. 9,
  109019. 2,
  109020. 10,
  109021. 1,
  109022. 11,
  109023. 0,
  109024. 12,
  109025. };
  109026. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109027. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109028. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109029. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109030. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109031. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109032. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109033. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109034. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109035. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109036. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109037. 0,12,13,13,12,13,14,14,14,
  109038. };
  109039. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109040. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109041. 12.5, 17.5, 22.5, 27.5,
  109042. };
  109043. static long _vq_quantmap__16c0_s_p8_0[] = {
  109044. 11, 9, 7, 5, 3, 1, 0, 2,
  109045. 4, 6, 8, 10, 12,
  109046. };
  109047. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109048. _vq_quantthresh__16c0_s_p8_0,
  109049. _vq_quantmap__16c0_s_p8_0,
  109050. 13,
  109051. 13
  109052. };
  109053. static static_codebook _16c0_s_p8_0 = {
  109054. 2, 169,
  109055. _vq_lengthlist__16c0_s_p8_0,
  109056. 1, -526516224, 1616117760, 4, 0,
  109057. _vq_quantlist__16c0_s_p8_0,
  109058. NULL,
  109059. &_vq_auxt__16c0_s_p8_0,
  109060. NULL,
  109061. 0
  109062. };
  109063. static long _vq_quantlist__16c0_s_p8_1[] = {
  109064. 2,
  109065. 1,
  109066. 3,
  109067. 0,
  109068. 4,
  109069. };
  109070. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109071. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109072. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109073. };
  109074. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109075. -1.5, -0.5, 0.5, 1.5,
  109076. };
  109077. static long _vq_quantmap__16c0_s_p8_1[] = {
  109078. 3, 1, 0, 2, 4,
  109079. };
  109080. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109081. _vq_quantthresh__16c0_s_p8_1,
  109082. _vq_quantmap__16c0_s_p8_1,
  109083. 5,
  109084. 5
  109085. };
  109086. static static_codebook _16c0_s_p8_1 = {
  109087. 2, 25,
  109088. _vq_lengthlist__16c0_s_p8_1,
  109089. 1, -533725184, 1611661312, 3, 0,
  109090. _vq_quantlist__16c0_s_p8_1,
  109091. NULL,
  109092. &_vq_auxt__16c0_s_p8_1,
  109093. NULL,
  109094. 0
  109095. };
  109096. static long _vq_quantlist__16c0_s_p9_0[] = {
  109097. 1,
  109098. 0,
  109099. 2,
  109100. };
  109101. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109102. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109103. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109104. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109105. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109106. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109107. 7,
  109108. };
  109109. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109110. -157.5, 157.5,
  109111. };
  109112. static long _vq_quantmap__16c0_s_p9_0[] = {
  109113. 1, 0, 2,
  109114. };
  109115. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109116. _vq_quantthresh__16c0_s_p9_0,
  109117. _vq_quantmap__16c0_s_p9_0,
  109118. 3,
  109119. 3
  109120. };
  109121. static static_codebook _16c0_s_p9_0 = {
  109122. 4, 81,
  109123. _vq_lengthlist__16c0_s_p9_0,
  109124. 1, -518803456, 1628680192, 2, 0,
  109125. _vq_quantlist__16c0_s_p9_0,
  109126. NULL,
  109127. &_vq_auxt__16c0_s_p9_0,
  109128. NULL,
  109129. 0
  109130. };
  109131. static long _vq_quantlist__16c0_s_p9_1[] = {
  109132. 7,
  109133. 6,
  109134. 8,
  109135. 5,
  109136. 9,
  109137. 4,
  109138. 10,
  109139. 3,
  109140. 11,
  109141. 2,
  109142. 12,
  109143. 1,
  109144. 13,
  109145. 0,
  109146. 14,
  109147. };
  109148. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109149. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109150. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109151. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109152. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109153. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109154. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109155. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109156. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109157. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109158. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109159. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109160. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109161. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109162. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109163. 10,
  109164. };
  109165. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109166. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109167. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109168. };
  109169. static long _vq_quantmap__16c0_s_p9_1[] = {
  109170. 13, 11, 9, 7, 5, 3, 1, 0,
  109171. 2, 4, 6, 8, 10, 12, 14,
  109172. };
  109173. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109174. _vq_quantthresh__16c0_s_p9_1,
  109175. _vq_quantmap__16c0_s_p9_1,
  109176. 15,
  109177. 15
  109178. };
  109179. static static_codebook _16c0_s_p9_1 = {
  109180. 2, 225,
  109181. _vq_lengthlist__16c0_s_p9_1,
  109182. 1, -520986624, 1620377600, 4, 0,
  109183. _vq_quantlist__16c0_s_p9_1,
  109184. NULL,
  109185. &_vq_auxt__16c0_s_p9_1,
  109186. NULL,
  109187. 0
  109188. };
  109189. static long _vq_quantlist__16c0_s_p9_2[] = {
  109190. 10,
  109191. 9,
  109192. 11,
  109193. 8,
  109194. 12,
  109195. 7,
  109196. 13,
  109197. 6,
  109198. 14,
  109199. 5,
  109200. 15,
  109201. 4,
  109202. 16,
  109203. 3,
  109204. 17,
  109205. 2,
  109206. 18,
  109207. 1,
  109208. 19,
  109209. 0,
  109210. 20,
  109211. };
  109212. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109213. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109214. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109215. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109216. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109217. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109218. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109219. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109220. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109221. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109222. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109223. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109224. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109225. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109226. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109227. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109228. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109229. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109230. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109231. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109232. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109233. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109234. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109235. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109236. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109237. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109238. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109239. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109240. 10,11,10,10,11, 9,10,10,10,
  109241. };
  109242. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109243. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109244. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109245. 6.5, 7.5, 8.5, 9.5,
  109246. };
  109247. static long _vq_quantmap__16c0_s_p9_2[] = {
  109248. 19, 17, 15, 13, 11, 9, 7, 5,
  109249. 3, 1, 0, 2, 4, 6, 8, 10,
  109250. 12, 14, 16, 18, 20,
  109251. };
  109252. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109253. _vq_quantthresh__16c0_s_p9_2,
  109254. _vq_quantmap__16c0_s_p9_2,
  109255. 21,
  109256. 21
  109257. };
  109258. static static_codebook _16c0_s_p9_2 = {
  109259. 2, 441,
  109260. _vq_lengthlist__16c0_s_p9_2,
  109261. 1, -529268736, 1611661312, 5, 0,
  109262. _vq_quantlist__16c0_s_p9_2,
  109263. NULL,
  109264. &_vq_auxt__16c0_s_p9_2,
  109265. NULL,
  109266. 0
  109267. };
  109268. static long _huff_lengthlist__16c0_s_single[] = {
  109269. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109270. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109271. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109272. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109273. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109274. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109275. 16,16,18,18,
  109276. };
  109277. static static_codebook _huff_book__16c0_s_single = {
  109278. 2, 100,
  109279. _huff_lengthlist__16c0_s_single,
  109280. 0, 0, 0, 0, 0,
  109281. NULL,
  109282. NULL,
  109283. NULL,
  109284. NULL,
  109285. 0
  109286. };
  109287. static long _huff_lengthlist__16c1_s_long[] = {
  109288. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109289. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109290. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109291. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109292. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109293. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109294. 12,11,11,13,
  109295. };
  109296. static static_codebook _huff_book__16c1_s_long = {
  109297. 2, 100,
  109298. _huff_lengthlist__16c1_s_long,
  109299. 0, 0, 0, 0, 0,
  109300. NULL,
  109301. NULL,
  109302. NULL,
  109303. NULL,
  109304. 0
  109305. };
  109306. static long _vq_quantlist__16c1_s_p1_0[] = {
  109307. 1,
  109308. 0,
  109309. 2,
  109310. };
  109311. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109312. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109313. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109318. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109323. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 7, 0, 0, 0, 0,
  109358. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  109363. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  109368. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109404. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109409. 0, 0, 0, 0, 0, 8, 9,11, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109414. 0, 0, 0, 0, 0, 0, 9,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109649. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109720. 0, 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,
  109723. };
  109724. static float _vq_quantthresh__16c1_s_p1_0[] = {
  109725. -0.5, 0.5,
  109726. };
  109727. static long _vq_quantmap__16c1_s_p1_0[] = {
  109728. 1, 0, 2,
  109729. };
  109730. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  109731. _vq_quantthresh__16c1_s_p1_0,
  109732. _vq_quantmap__16c1_s_p1_0,
  109733. 3,
  109734. 3
  109735. };
  109736. static static_codebook _16c1_s_p1_0 = {
  109737. 8, 6561,
  109738. _vq_lengthlist__16c1_s_p1_0,
  109739. 1, -535822336, 1611661312, 2, 0,
  109740. _vq_quantlist__16c1_s_p1_0,
  109741. NULL,
  109742. &_vq_auxt__16c1_s_p1_0,
  109743. NULL,
  109744. 0
  109745. };
  109746. static long _vq_quantlist__16c1_s_p2_0[] = {
  109747. 2,
  109748. 1,
  109749. 3,
  109750. 0,
  109751. 4,
  109752. };
  109753. static long _vq_lengthlist__16c1_s_p2_0[] = {
  109754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109793. 0,
  109794. };
  109795. static float _vq_quantthresh__16c1_s_p2_0[] = {
  109796. -1.5, -0.5, 0.5, 1.5,
  109797. };
  109798. static long _vq_quantmap__16c1_s_p2_0[] = {
  109799. 3, 1, 0, 2, 4,
  109800. };
  109801. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  109802. _vq_quantthresh__16c1_s_p2_0,
  109803. _vq_quantmap__16c1_s_p2_0,
  109804. 5,
  109805. 5
  109806. };
  109807. static static_codebook _16c1_s_p2_0 = {
  109808. 4, 625,
  109809. _vq_lengthlist__16c1_s_p2_0,
  109810. 1, -533725184, 1611661312, 3, 0,
  109811. _vq_quantlist__16c1_s_p2_0,
  109812. NULL,
  109813. &_vq_auxt__16c1_s_p2_0,
  109814. NULL,
  109815. 0
  109816. };
  109817. static long _vq_quantlist__16c1_s_p3_0[] = {
  109818. 2,
  109819. 1,
  109820. 3,
  109821. 0,
  109822. 4,
  109823. };
  109824. static long _vq_lengthlist__16c1_s_p3_0[] = {
  109825. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  109827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109828. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  109830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109831. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109864. 0,
  109865. };
  109866. static float _vq_quantthresh__16c1_s_p3_0[] = {
  109867. -1.5, -0.5, 0.5, 1.5,
  109868. };
  109869. static long _vq_quantmap__16c1_s_p3_0[] = {
  109870. 3, 1, 0, 2, 4,
  109871. };
  109872. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  109873. _vq_quantthresh__16c1_s_p3_0,
  109874. _vq_quantmap__16c1_s_p3_0,
  109875. 5,
  109876. 5
  109877. };
  109878. static static_codebook _16c1_s_p3_0 = {
  109879. 4, 625,
  109880. _vq_lengthlist__16c1_s_p3_0,
  109881. 1, -533725184, 1611661312, 3, 0,
  109882. _vq_quantlist__16c1_s_p3_0,
  109883. NULL,
  109884. &_vq_auxt__16c1_s_p3_0,
  109885. NULL,
  109886. 0
  109887. };
  109888. static long _vq_quantlist__16c1_s_p4_0[] = {
  109889. 4,
  109890. 3,
  109891. 5,
  109892. 2,
  109893. 6,
  109894. 1,
  109895. 7,
  109896. 0,
  109897. 8,
  109898. };
  109899. static long _vq_lengthlist__16c1_s_p4_0[] = {
  109900. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109901. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109902. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109903. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  109904. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109905. 0,
  109906. };
  109907. static float _vq_quantthresh__16c1_s_p4_0[] = {
  109908. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109909. };
  109910. static long _vq_quantmap__16c1_s_p4_0[] = {
  109911. 7, 5, 3, 1, 0, 2, 4, 6,
  109912. 8,
  109913. };
  109914. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  109915. _vq_quantthresh__16c1_s_p4_0,
  109916. _vq_quantmap__16c1_s_p4_0,
  109917. 9,
  109918. 9
  109919. };
  109920. static static_codebook _16c1_s_p4_0 = {
  109921. 2, 81,
  109922. _vq_lengthlist__16c1_s_p4_0,
  109923. 1, -531628032, 1611661312, 4, 0,
  109924. _vq_quantlist__16c1_s_p4_0,
  109925. NULL,
  109926. &_vq_auxt__16c1_s_p4_0,
  109927. NULL,
  109928. 0
  109929. };
  109930. static long _vq_quantlist__16c1_s_p5_0[] = {
  109931. 4,
  109932. 3,
  109933. 5,
  109934. 2,
  109935. 6,
  109936. 1,
  109937. 7,
  109938. 0,
  109939. 8,
  109940. };
  109941. static long _vq_lengthlist__16c1_s_p5_0[] = {
  109942. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109943. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  109944. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  109945. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  109946. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109947. 10,
  109948. };
  109949. static float _vq_quantthresh__16c1_s_p5_0[] = {
  109950. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109951. };
  109952. static long _vq_quantmap__16c1_s_p5_0[] = {
  109953. 7, 5, 3, 1, 0, 2, 4, 6,
  109954. 8,
  109955. };
  109956. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  109957. _vq_quantthresh__16c1_s_p5_0,
  109958. _vq_quantmap__16c1_s_p5_0,
  109959. 9,
  109960. 9
  109961. };
  109962. static static_codebook _16c1_s_p5_0 = {
  109963. 2, 81,
  109964. _vq_lengthlist__16c1_s_p5_0,
  109965. 1, -531628032, 1611661312, 4, 0,
  109966. _vq_quantlist__16c1_s_p5_0,
  109967. NULL,
  109968. &_vq_auxt__16c1_s_p5_0,
  109969. NULL,
  109970. 0
  109971. };
  109972. static long _vq_quantlist__16c1_s_p6_0[] = {
  109973. 8,
  109974. 7,
  109975. 9,
  109976. 6,
  109977. 10,
  109978. 5,
  109979. 11,
  109980. 4,
  109981. 12,
  109982. 3,
  109983. 13,
  109984. 2,
  109985. 14,
  109986. 1,
  109987. 15,
  109988. 0,
  109989. 16,
  109990. };
  109991. static long _vq_lengthlist__16c1_s_p6_0[] = {
  109992. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  109993. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  109994. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  109995. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  109996. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  109997. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109998. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109999. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  110000. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  110001. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  110002. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  110003. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  110004. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  110005. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  110006. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  110007. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  110008. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  110009. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  110010. 14,
  110011. };
  110012. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110013. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110014. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110015. };
  110016. static long _vq_quantmap__16c1_s_p6_0[] = {
  110017. 15, 13, 11, 9, 7, 5, 3, 1,
  110018. 0, 2, 4, 6, 8, 10, 12, 14,
  110019. 16,
  110020. };
  110021. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110022. _vq_quantthresh__16c1_s_p6_0,
  110023. _vq_quantmap__16c1_s_p6_0,
  110024. 17,
  110025. 17
  110026. };
  110027. static static_codebook _16c1_s_p6_0 = {
  110028. 2, 289,
  110029. _vq_lengthlist__16c1_s_p6_0,
  110030. 1, -529530880, 1611661312, 5, 0,
  110031. _vq_quantlist__16c1_s_p6_0,
  110032. NULL,
  110033. &_vq_auxt__16c1_s_p6_0,
  110034. NULL,
  110035. 0
  110036. };
  110037. static long _vq_quantlist__16c1_s_p7_0[] = {
  110038. 1,
  110039. 0,
  110040. 2,
  110041. };
  110042. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110043. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110044. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110045. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110046. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110047. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110048. 11,
  110049. };
  110050. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110051. -5.5, 5.5,
  110052. };
  110053. static long _vq_quantmap__16c1_s_p7_0[] = {
  110054. 1, 0, 2,
  110055. };
  110056. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110057. _vq_quantthresh__16c1_s_p7_0,
  110058. _vq_quantmap__16c1_s_p7_0,
  110059. 3,
  110060. 3
  110061. };
  110062. static static_codebook _16c1_s_p7_0 = {
  110063. 4, 81,
  110064. _vq_lengthlist__16c1_s_p7_0,
  110065. 1, -529137664, 1618345984, 2, 0,
  110066. _vq_quantlist__16c1_s_p7_0,
  110067. NULL,
  110068. &_vq_auxt__16c1_s_p7_0,
  110069. NULL,
  110070. 0
  110071. };
  110072. static long _vq_quantlist__16c1_s_p7_1[] = {
  110073. 5,
  110074. 4,
  110075. 6,
  110076. 3,
  110077. 7,
  110078. 2,
  110079. 8,
  110080. 1,
  110081. 9,
  110082. 0,
  110083. 10,
  110084. };
  110085. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110086. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110087. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110088. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110089. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110090. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110091. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110092. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110093. 10,10,10, 8, 8, 8, 8, 9, 9,
  110094. };
  110095. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110096. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110097. 3.5, 4.5,
  110098. };
  110099. static long _vq_quantmap__16c1_s_p7_1[] = {
  110100. 9, 7, 5, 3, 1, 0, 2, 4,
  110101. 6, 8, 10,
  110102. };
  110103. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110104. _vq_quantthresh__16c1_s_p7_1,
  110105. _vq_quantmap__16c1_s_p7_1,
  110106. 11,
  110107. 11
  110108. };
  110109. static static_codebook _16c1_s_p7_1 = {
  110110. 2, 121,
  110111. _vq_lengthlist__16c1_s_p7_1,
  110112. 1, -531365888, 1611661312, 4, 0,
  110113. _vq_quantlist__16c1_s_p7_1,
  110114. NULL,
  110115. &_vq_auxt__16c1_s_p7_1,
  110116. NULL,
  110117. 0
  110118. };
  110119. static long _vq_quantlist__16c1_s_p8_0[] = {
  110120. 6,
  110121. 5,
  110122. 7,
  110123. 4,
  110124. 8,
  110125. 3,
  110126. 9,
  110127. 2,
  110128. 10,
  110129. 1,
  110130. 11,
  110131. 0,
  110132. 12,
  110133. };
  110134. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110135. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110136. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110137. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110138. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110139. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110140. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110141. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110142. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110143. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110144. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110145. 0,12,12,12,12,13,13,14,15,
  110146. };
  110147. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110148. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110149. 12.5, 17.5, 22.5, 27.5,
  110150. };
  110151. static long _vq_quantmap__16c1_s_p8_0[] = {
  110152. 11, 9, 7, 5, 3, 1, 0, 2,
  110153. 4, 6, 8, 10, 12,
  110154. };
  110155. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110156. _vq_quantthresh__16c1_s_p8_0,
  110157. _vq_quantmap__16c1_s_p8_0,
  110158. 13,
  110159. 13
  110160. };
  110161. static static_codebook _16c1_s_p8_0 = {
  110162. 2, 169,
  110163. _vq_lengthlist__16c1_s_p8_0,
  110164. 1, -526516224, 1616117760, 4, 0,
  110165. _vq_quantlist__16c1_s_p8_0,
  110166. NULL,
  110167. &_vq_auxt__16c1_s_p8_0,
  110168. NULL,
  110169. 0
  110170. };
  110171. static long _vq_quantlist__16c1_s_p8_1[] = {
  110172. 2,
  110173. 1,
  110174. 3,
  110175. 0,
  110176. 4,
  110177. };
  110178. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110179. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110180. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110181. };
  110182. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110183. -1.5, -0.5, 0.5, 1.5,
  110184. };
  110185. static long _vq_quantmap__16c1_s_p8_1[] = {
  110186. 3, 1, 0, 2, 4,
  110187. };
  110188. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110189. _vq_quantthresh__16c1_s_p8_1,
  110190. _vq_quantmap__16c1_s_p8_1,
  110191. 5,
  110192. 5
  110193. };
  110194. static static_codebook _16c1_s_p8_1 = {
  110195. 2, 25,
  110196. _vq_lengthlist__16c1_s_p8_1,
  110197. 1, -533725184, 1611661312, 3, 0,
  110198. _vq_quantlist__16c1_s_p8_1,
  110199. NULL,
  110200. &_vq_auxt__16c1_s_p8_1,
  110201. NULL,
  110202. 0
  110203. };
  110204. static long _vq_quantlist__16c1_s_p9_0[] = {
  110205. 6,
  110206. 5,
  110207. 7,
  110208. 4,
  110209. 8,
  110210. 3,
  110211. 9,
  110212. 2,
  110213. 10,
  110214. 1,
  110215. 11,
  110216. 0,
  110217. 12,
  110218. };
  110219. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110220. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110221. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110222. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110223. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110224. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110225. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110226. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110227. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110228. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110229. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110230. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110231. };
  110232. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110233. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110234. 787.5, 1102.5, 1417.5, 1732.5,
  110235. };
  110236. static long _vq_quantmap__16c1_s_p9_0[] = {
  110237. 11, 9, 7, 5, 3, 1, 0, 2,
  110238. 4, 6, 8, 10, 12,
  110239. };
  110240. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110241. _vq_quantthresh__16c1_s_p9_0,
  110242. _vq_quantmap__16c1_s_p9_0,
  110243. 13,
  110244. 13
  110245. };
  110246. static static_codebook _16c1_s_p9_0 = {
  110247. 2, 169,
  110248. _vq_lengthlist__16c1_s_p9_0,
  110249. 1, -513964032, 1628680192, 4, 0,
  110250. _vq_quantlist__16c1_s_p9_0,
  110251. NULL,
  110252. &_vq_auxt__16c1_s_p9_0,
  110253. NULL,
  110254. 0
  110255. };
  110256. static long _vq_quantlist__16c1_s_p9_1[] = {
  110257. 7,
  110258. 6,
  110259. 8,
  110260. 5,
  110261. 9,
  110262. 4,
  110263. 10,
  110264. 3,
  110265. 11,
  110266. 2,
  110267. 12,
  110268. 1,
  110269. 13,
  110270. 0,
  110271. 14,
  110272. };
  110273. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110274. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110275. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110276. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110277. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110278. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110279. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110280. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110281. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110282. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110283. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110284. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110285. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110286. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110287. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110288. 13,
  110289. };
  110290. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110291. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110292. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110293. };
  110294. static long _vq_quantmap__16c1_s_p9_1[] = {
  110295. 13, 11, 9, 7, 5, 3, 1, 0,
  110296. 2, 4, 6, 8, 10, 12, 14,
  110297. };
  110298. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110299. _vq_quantthresh__16c1_s_p9_1,
  110300. _vq_quantmap__16c1_s_p9_1,
  110301. 15,
  110302. 15
  110303. };
  110304. static static_codebook _16c1_s_p9_1 = {
  110305. 2, 225,
  110306. _vq_lengthlist__16c1_s_p9_1,
  110307. 1, -520986624, 1620377600, 4, 0,
  110308. _vq_quantlist__16c1_s_p9_1,
  110309. NULL,
  110310. &_vq_auxt__16c1_s_p9_1,
  110311. NULL,
  110312. 0
  110313. };
  110314. static long _vq_quantlist__16c1_s_p9_2[] = {
  110315. 10,
  110316. 9,
  110317. 11,
  110318. 8,
  110319. 12,
  110320. 7,
  110321. 13,
  110322. 6,
  110323. 14,
  110324. 5,
  110325. 15,
  110326. 4,
  110327. 16,
  110328. 3,
  110329. 17,
  110330. 2,
  110331. 18,
  110332. 1,
  110333. 19,
  110334. 0,
  110335. 20,
  110336. };
  110337. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110338. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110339. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110340. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110341. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110342. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110343. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110344. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110345. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110346. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110347. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110348. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110349. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110350. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110351. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110352. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110353. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110354. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110355. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110356. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110357. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110358. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110359. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110360. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110361. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110362. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110363. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110364. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110365. 11,11,11,11,12,11,11,12,11,
  110366. };
  110367. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110368. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110369. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110370. 6.5, 7.5, 8.5, 9.5,
  110371. };
  110372. static long _vq_quantmap__16c1_s_p9_2[] = {
  110373. 19, 17, 15, 13, 11, 9, 7, 5,
  110374. 3, 1, 0, 2, 4, 6, 8, 10,
  110375. 12, 14, 16, 18, 20,
  110376. };
  110377. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110378. _vq_quantthresh__16c1_s_p9_2,
  110379. _vq_quantmap__16c1_s_p9_2,
  110380. 21,
  110381. 21
  110382. };
  110383. static static_codebook _16c1_s_p9_2 = {
  110384. 2, 441,
  110385. _vq_lengthlist__16c1_s_p9_2,
  110386. 1, -529268736, 1611661312, 5, 0,
  110387. _vq_quantlist__16c1_s_p9_2,
  110388. NULL,
  110389. &_vq_auxt__16c1_s_p9_2,
  110390. NULL,
  110391. 0
  110392. };
  110393. static long _huff_lengthlist__16c1_s_short[] = {
  110394. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110395. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110396. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110397. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110398. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110399. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110400. 9, 9,10,13,
  110401. };
  110402. static static_codebook _huff_book__16c1_s_short = {
  110403. 2, 100,
  110404. _huff_lengthlist__16c1_s_short,
  110405. 0, 0, 0, 0, 0,
  110406. NULL,
  110407. NULL,
  110408. NULL,
  110409. NULL,
  110410. 0
  110411. };
  110412. static long _huff_lengthlist__16c2_s_long[] = {
  110413. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110414. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110415. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110416. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110417. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110418. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110419. 14,14,16,18,
  110420. };
  110421. static static_codebook _huff_book__16c2_s_long = {
  110422. 2, 100,
  110423. _huff_lengthlist__16c2_s_long,
  110424. 0, 0, 0, 0, 0,
  110425. NULL,
  110426. NULL,
  110427. NULL,
  110428. NULL,
  110429. 0
  110430. };
  110431. static long _vq_quantlist__16c2_s_p1_0[] = {
  110432. 1,
  110433. 0,
  110434. 2,
  110435. };
  110436. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110437. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110438. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110442. 0,
  110443. };
  110444. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110445. -0.5, 0.5,
  110446. };
  110447. static long _vq_quantmap__16c2_s_p1_0[] = {
  110448. 1, 0, 2,
  110449. };
  110450. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110451. _vq_quantthresh__16c2_s_p1_0,
  110452. _vq_quantmap__16c2_s_p1_0,
  110453. 3,
  110454. 3
  110455. };
  110456. static static_codebook _16c2_s_p1_0 = {
  110457. 4, 81,
  110458. _vq_lengthlist__16c2_s_p1_0,
  110459. 1, -535822336, 1611661312, 2, 0,
  110460. _vq_quantlist__16c2_s_p1_0,
  110461. NULL,
  110462. &_vq_auxt__16c2_s_p1_0,
  110463. NULL,
  110464. 0
  110465. };
  110466. static long _vq_quantlist__16c2_s_p2_0[] = {
  110467. 2,
  110468. 1,
  110469. 3,
  110470. 0,
  110471. 4,
  110472. };
  110473. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110474. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110475. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110476. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110477. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110478. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110479. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110480. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110481. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110486. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110487. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110488. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110489. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110494. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110495. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110496. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110497. 13,13, 0, 0, 0,12,13, 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, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110503. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110504. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110505. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  110510. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110511. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110512. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110513. 13,
  110514. };
  110515. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110516. -1.5, -0.5, 0.5, 1.5,
  110517. };
  110518. static long _vq_quantmap__16c2_s_p2_0[] = {
  110519. 3, 1, 0, 2, 4,
  110520. };
  110521. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110522. _vq_quantthresh__16c2_s_p2_0,
  110523. _vq_quantmap__16c2_s_p2_0,
  110524. 5,
  110525. 5
  110526. };
  110527. static static_codebook _16c2_s_p2_0 = {
  110528. 4, 625,
  110529. _vq_lengthlist__16c2_s_p2_0,
  110530. 1, -533725184, 1611661312, 3, 0,
  110531. _vq_quantlist__16c2_s_p2_0,
  110532. NULL,
  110533. &_vq_auxt__16c2_s_p2_0,
  110534. NULL,
  110535. 0
  110536. };
  110537. static long _vq_quantlist__16c2_s_p3_0[] = {
  110538. 4,
  110539. 3,
  110540. 5,
  110541. 2,
  110542. 6,
  110543. 1,
  110544. 7,
  110545. 0,
  110546. 8,
  110547. };
  110548. static long _vq_lengthlist__16c2_s_p3_0[] = {
  110549. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  110550. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  110551. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  110552. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  110553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110554. 0,
  110555. };
  110556. static float _vq_quantthresh__16c2_s_p3_0[] = {
  110557. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110558. };
  110559. static long _vq_quantmap__16c2_s_p3_0[] = {
  110560. 7, 5, 3, 1, 0, 2, 4, 6,
  110561. 8,
  110562. };
  110563. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  110564. _vq_quantthresh__16c2_s_p3_0,
  110565. _vq_quantmap__16c2_s_p3_0,
  110566. 9,
  110567. 9
  110568. };
  110569. static static_codebook _16c2_s_p3_0 = {
  110570. 2, 81,
  110571. _vq_lengthlist__16c2_s_p3_0,
  110572. 1, -531628032, 1611661312, 4, 0,
  110573. _vq_quantlist__16c2_s_p3_0,
  110574. NULL,
  110575. &_vq_auxt__16c2_s_p3_0,
  110576. NULL,
  110577. 0
  110578. };
  110579. static long _vq_quantlist__16c2_s_p4_0[] = {
  110580. 8,
  110581. 7,
  110582. 9,
  110583. 6,
  110584. 10,
  110585. 5,
  110586. 11,
  110587. 4,
  110588. 12,
  110589. 3,
  110590. 13,
  110591. 2,
  110592. 14,
  110593. 1,
  110594. 15,
  110595. 0,
  110596. 16,
  110597. };
  110598. static long _vq_lengthlist__16c2_s_p4_0[] = {
  110599. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  110600. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  110601. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  110602. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  110603. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  110604. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  110605. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  110606. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  110607. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  110608. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  110609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110617. 0,
  110618. };
  110619. static float _vq_quantthresh__16c2_s_p4_0[] = {
  110620. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110621. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110622. };
  110623. static long _vq_quantmap__16c2_s_p4_0[] = {
  110624. 15, 13, 11, 9, 7, 5, 3, 1,
  110625. 0, 2, 4, 6, 8, 10, 12, 14,
  110626. 16,
  110627. };
  110628. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  110629. _vq_quantthresh__16c2_s_p4_0,
  110630. _vq_quantmap__16c2_s_p4_0,
  110631. 17,
  110632. 17
  110633. };
  110634. static static_codebook _16c2_s_p4_0 = {
  110635. 2, 289,
  110636. _vq_lengthlist__16c2_s_p4_0,
  110637. 1, -529530880, 1611661312, 5, 0,
  110638. _vq_quantlist__16c2_s_p4_0,
  110639. NULL,
  110640. &_vq_auxt__16c2_s_p4_0,
  110641. NULL,
  110642. 0
  110643. };
  110644. static long _vq_quantlist__16c2_s_p5_0[] = {
  110645. 1,
  110646. 0,
  110647. 2,
  110648. };
  110649. static long _vq_lengthlist__16c2_s_p5_0[] = {
  110650. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  110651. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  110652. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  110653. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  110654. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  110655. 12,
  110656. };
  110657. static float _vq_quantthresh__16c2_s_p5_0[] = {
  110658. -5.5, 5.5,
  110659. };
  110660. static long _vq_quantmap__16c2_s_p5_0[] = {
  110661. 1, 0, 2,
  110662. };
  110663. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  110664. _vq_quantthresh__16c2_s_p5_0,
  110665. _vq_quantmap__16c2_s_p5_0,
  110666. 3,
  110667. 3
  110668. };
  110669. static static_codebook _16c2_s_p5_0 = {
  110670. 4, 81,
  110671. _vq_lengthlist__16c2_s_p5_0,
  110672. 1, -529137664, 1618345984, 2, 0,
  110673. _vq_quantlist__16c2_s_p5_0,
  110674. NULL,
  110675. &_vq_auxt__16c2_s_p5_0,
  110676. NULL,
  110677. 0
  110678. };
  110679. static long _vq_quantlist__16c2_s_p5_1[] = {
  110680. 5,
  110681. 4,
  110682. 6,
  110683. 3,
  110684. 7,
  110685. 2,
  110686. 8,
  110687. 1,
  110688. 9,
  110689. 0,
  110690. 10,
  110691. };
  110692. static long _vq_lengthlist__16c2_s_p5_1[] = {
  110693. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  110694. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  110695. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  110696. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  110697. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  110698. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  110699. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  110700. 11,11,11, 7, 7, 8, 8, 8, 8,
  110701. };
  110702. static float _vq_quantthresh__16c2_s_p5_1[] = {
  110703. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110704. 3.5, 4.5,
  110705. };
  110706. static long _vq_quantmap__16c2_s_p5_1[] = {
  110707. 9, 7, 5, 3, 1, 0, 2, 4,
  110708. 6, 8, 10,
  110709. };
  110710. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  110711. _vq_quantthresh__16c2_s_p5_1,
  110712. _vq_quantmap__16c2_s_p5_1,
  110713. 11,
  110714. 11
  110715. };
  110716. static static_codebook _16c2_s_p5_1 = {
  110717. 2, 121,
  110718. _vq_lengthlist__16c2_s_p5_1,
  110719. 1, -531365888, 1611661312, 4, 0,
  110720. _vq_quantlist__16c2_s_p5_1,
  110721. NULL,
  110722. &_vq_auxt__16c2_s_p5_1,
  110723. NULL,
  110724. 0
  110725. };
  110726. static long _vq_quantlist__16c2_s_p6_0[] = {
  110727. 6,
  110728. 5,
  110729. 7,
  110730. 4,
  110731. 8,
  110732. 3,
  110733. 9,
  110734. 2,
  110735. 10,
  110736. 1,
  110737. 11,
  110738. 0,
  110739. 12,
  110740. };
  110741. static long _vq_lengthlist__16c2_s_p6_0[] = {
  110742. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110743. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  110744. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  110745. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  110746. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  110747. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  110748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110752. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110753. };
  110754. static float _vq_quantthresh__16c2_s_p6_0[] = {
  110755. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110756. 12.5, 17.5, 22.5, 27.5,
  110757. };
  110758. static long _vq_quantmap__16c2_s_p6_0[] = {
  110759. 11, 9, 7, 5, 3, 1, 0, 2,
  110760. 4, 6, 8, 10, 12,
  110761. };
  110762. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  110763. _vq_quantthresh__16c2_s_p6_0,
  110764. _vq_quantmap__16c2_s_p6_0,
  110765. 13,
  110766. 13
  110767. };
  110768. static static_codebook _16c2_s_p6_0 = {
  110769. 2, 169,
  110770. _vq_lengthlist__16c2_s_p6_0,
  110771. 1, -526516224, 1616117760, 4, 0,
  110772. _vq_quantlist__16c2_s_p6_0,
  110773. NULL,
  110774. &_vq_auxt__16c2_s_p6_0,
  110775. NULL,
  110776. 0
  110777. };
  110778. static long _vq_quantlist__16c2_s_p6_1[] = {
  110779. 2,
  110780. 1,
  110781. 3,
  110782. 0,
  110783. 4,
  110784. };
  110785. static long _vq_lengthlist__16c2_s_p6_1[] = {
  110786. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110787. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110788. };
  110789. static float _vq_quantthresh__16c2_s_p6_1[] = {
  110790. -1.5, -0.5, 0.5, 1.5,
  110791. };
  110792. static long _vq_quantmap__16c2_s_p6_1[] = {
  110793. 3, 1, 0, 2, 4,
  110794. };
  110795. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  110796. _vq_quantthresh__16c2_s_p6_1,
  110797. _vq_quantmap__16c2_s_p6_1,
  110798. 5,
  110799. 5
  110800. };
  110801. static static_codebook _16c2_s_p6_1 = {
  110802. 2, 25,
  110803. _vq_lengthlist__16c2_s_p6_1,
  110804. 1, -533725184, 1611661312, 3, 0,
  110805. _vq_quantlist__16c2_s_p6_1,
  110806. NULL,
  110807. &_vq_auxt__16c2_s_p6_1,
  110808. NULL,
  110809. 0
  110810. };
  110811. static long _vq_quantlist__16c2_s_p7_0[] = {
  110812. 6,
  110813. 5,
  110814. 7,
  110815. 4,
  110816. 8,
  110817. 3,
  110818. 9,
  110819. 2,
  110820. 10,
  110821. 1,
  110822. 11,
  110823. 0,
  110824. 12,
  110825. };
  110826. static long _vq_lengthlist__16c2_s_p7_0[] = {
  110827. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110828. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  110829. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  110830. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  110831. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  110832. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  110833. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  110834. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  110835. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  110836. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  110837. 18,13,14,13,13,14,13,15,14,
  110838. };
  110839. static float _vq_quantthresh__16c2_s_p7_0[] = {
  110840. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  110841. 27.5, 38.5, 49.5, 60.5,
  110842. };
  110843. static long _vq_quantmap__16c2_s_p7_0[] = {
  110844. 11, 9, 7, 5, 3, 1, 0, 2,
  110845. 4, 6, 8, 10, 12,
  110846. };
  110847. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  110848. _vq_quantthresh__16c2_s_p7_0,
  110849. _vq_quantmap__16c2_s_p7_0,
  110850. 13,
  110851. 13
  110852. };
  110853. static static_codebook _16c2_s_p7_0 = {
  110854. 2, 169,
  110855. _vq_lengthlist__16c2_s_p7_0,
  110856. 1, -523206656, 1618345984, 4, 0,
  110857. _vq_quantlist__16c2_s_p7_0,
  110858. NULL,
  110859. &_vq_auxt__16c2_s_p7_0,
  110860. NULL,
  110861. 0
  110862. };
  110863. static long _vq_quantlist__16c2_s_p7_1[] = {
  110864. 5,
  110865. 4,
  110866. 6,
  110867. 3,
  110868. 7,
  110869. 2,
  110870. 8,
  110871. 1,
  110872. 9,
  110873. 0,
  110874. 10,
  110875. };
  110876. static long _vq_lengthlist__16c2_s_p7_1[] = {
  110877. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  110878. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  110879. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  110880. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110881. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  110882. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  110883. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  110884. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110885. };
  110886. static float _vq_quantthresh__16c2_s_p7_1[] = {
  110887. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110888. 3.5, 4.5,
  110889. };
  110890. static long _vq_quantmap__16c2_s_p7_1[] = {
  110891. 9, 7, 5, 3, 1, 0, 2, 4,
  110892. 6, 8, 10,
  110893. };
  110894. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  110895. _vq_quantthresh__16c2_s_p7_1,
  110896. _vq_quantmap__16c2_s_p7_1,
  110897. 11,
  110898. 11
  110899. };
  110900. static static_codebook _16c2_s_p7_1 = {
  110901. 2, 121,
  110902. _vq_lengthlist__16c2_s_p7_1,
  110903. 1, -531365888, 1611661312, 4, 0,
  110904. _vq_quantlist__16c2_s_p7_1,
  110905. NULL,
  110906. &_vq_auxt__16c2_s_p7_1,
  110907. NULL,
  110908. 0
  110909. };
  110910. static long _vq_quantlist__16c2_s_p8_0[] = {
  110911. 7,
  110912. 6,
  110913. 8,
  110914. 5,
  110915. 9,
  110916. 4,
  110917. 10,
  110918. 3,
  110919. 11,
  110920. 2,
  110921. 12,
  110922. 1,
  110923. 13,
  110924. 0,
  110925. 14,
  110926. };
  110927. static long _vq_lengthlist__16c2_s_p8_0[] = {
  110928. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  110929. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  110930. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  110931. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  110932. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  110933. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  110934. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  110935. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  110936. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  110937. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  110938. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  110939. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  110940. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  110941. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  110942. 13,
  110943. };
  110944. static float _vq_quantthresh__16c2_s_p8_0[] = {
  110945. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110946. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110947. };
  110948. static long _vq_quantmap__16c2_s_p8_0[] = {
  110949. 13, 11, 9, 7, 5, 3, 1, 0,
  110950. 2, 4, 6, 8, 10, 12, 14,
  110951. };
  110952. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  110953. _vq_quantthresh__16c2_s_p8_0,
  110954. _vq_quantmap__16c2_s_p8_0,
  110955. 15,
  110956. 15
  110957. };
  110958. static static_codebook _16c2_s_p8_0 = {
  110959. 2, 225,
  110960. _vq_lengthlist__16c2_s_p8_0,
  110961. 1, -520986624, 1620377600, 4, 0,
  110962. _vq_quantlist__16c2_s_p8_0,
  110963. NULL,
  110964. &_vq_auxt__16c2_s_p8_0,
  110965. NULL,
  110966. 0
  110967. };
  110968. static long _vq_quantlist__16c2_s_p8_1[] = {
  110969. 10,
  110970. 9,
  110971. 11,
  110972. 8,
  110973. 12,
  110974. 7,
  110975. 13,
  110976. 6,
  110977. 14,
  110978. 5,
  110979. 15,
  110980. 4,
  110981. 16,
  110982. 3,
  110983. 17,
  110984. 2,
  110985. 18,
  110986. 1,
  110987. 19,
  110988. 0,
  110989. 20,
  110990. };
  110991. static long _vq_lengthlist__16c2_s_p8_1[] = {
  110992. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  110993. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  110994. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  110995. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  110996. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  110997. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  110998. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  110999. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  111000. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  111001. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  111002. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  111003. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  111004. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  111005. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  111006. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  111007. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  111008. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  111009. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  111010. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111011. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111012. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111013. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111014. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111015. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111016. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111017. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111018. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111019. 10,11,10,10,10,10,10,10,10,
  111020. };
  111021. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111022. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111023. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111024. 6.5, 7.5, 8.5, 9.5,
  111025. };
  111026. static long _vq_quantmap__16c2_s_p8_1[] = {
  111027. 19, 17, 15, 13, 11, 9, 7, 5,
  111028. 3, 1, 0, 2, 4, 6, 8, 10,
  111029. 12, 14, 16, 18, 20,
  111030. };
  111031. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111032. _vq_quantthresh__16c2_s_p8_1,
  111033. _vq_quantmap__16c2_s_p8_1,
  111034. 21,
  111035. 21
  111036. };
  111037. static static_codebook _16c2_s_p8_1 = {
  111038. 2, 441,
  111039. _vq_lengthlist__16c2_s_p8_1,
  111040. 1, -529268736, 1611661312, 5, 0,
  111041. _vq_quantlist__16c2_s_p8_1,
  111042. NULL,
  111043. &_vq_auxt__16c2_s_p8_1,
  111044. NULL,
  111045. 0
  111046. };
  111047. static long _vq_quantlist__16c2_s_p9_0[] = {
  111048. 6,
  111049. 5,
  111050. 7,
  111051. 4,
  111052. 8,
  111053. 3,
  111054. 9,
  111055. 2,
  111056. 10,
  111057. 1,
  111058. 11,
  111059. 0,
  111060. 12,
  111061. };
  111062. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111063. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111064. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111065. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111066. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111067. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111068. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111069. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111070. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111071. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111072. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111073. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111074. };
  111075. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111076. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111077. 2327.5, 3258.5, 4189.5, 5120.5,
  111078. };
  111079. static long _vq_quantmap__16c2_s_p9_0[] = {
  111080. 11, 9, 7, 5, 3, 1, 0, 2,
  111081. 4, 6, 8, 10, 12,
  111082. };
  111083. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111084. _vq_quantthresh__16c2_s_p9_0,
  111085. _vq_quantmap__16c2_s_p9_0,
  111086. 13,
  111087. 13
  111088. };
  111089. static static_codebook _16c2_s_p9_0 = {
  111090. 2, 169,
  111091. _vq_lengthlist__16c2_s_p9_0,
  111092. 1, -510275072, 1631393792, 4, 0,
  111093. _vq_quantlist__16c2_s_p9_0,
  111094. NULL,
  111095. &_vq_auxt__16c2_s_p9_0,
  111096. NULL,
  111097. 0
  111098. };
  111099. static long _vq_quantlist__16c2_s_p9_1[] = {
  111100. 8,
  111101. 7,
  111102. 9,
  111103. 6,
  111104. 10,
  111105. 5,
  111106. 11,
  111107. 4,
  111108. 12,
  111109. 3,
  111110. 13,
  111111. 2,
  111112. 14,
  111113. 1,
  111114. 15,
  111115. 0,
  111116. 16,
  111117. };
  111118. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111119. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111120. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111121. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111122. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111123. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111124. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111125. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111126. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111127. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111128. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111129. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111130. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111131. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111132. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111133. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111134. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111135. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111136. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111137. 10,
  111138. };
  111139. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111140. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111141. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111142. };
  111143. static long _vq_quantmap__16c2_s_p9_1[] = {
  111144. 15, 13, 11, 9, 7, 5, 3, 1,
  111145. 0, 2, 4, 6, 8, 10, 12, 14,
  111146. 16,
  111147. };
  111148. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111149. _vq_quantthresh__16c2_s_p9_1,
  111150. _vq_quantmap__16c2_s_p9_1,
  111151. 17,
  111152. 17
  111153. };
  111154. static static_codebook _16c2_s_p9_1 = {
  111155. 2, 289,
  111156. _vq_lengthlist__16c2_s_p9_1,
  111157. 1, -518488064, 1622704128, 5, 0,
  111158. _vq_quantlist__16c2_s_p9_1,
  111159. NULL,
  111160. &_vq_auxt__16c2_s_p9_1,
  111161. NULL,
  111162. 0
  111163. };
  111164. static long _vq_quantlist__16c2_s_p9_2[] = {
  111165. 13,
  111166. 12,
  111167. 14,
  111168. 11,
  111169. 15,
  111170. 10,
  111171. 16,
  111172. 9,
  111173. 17,
  111174. 8,
  111175. 18,
  111176. 7,
  111177. 19,
  111178. 6,
  111179. 20,
  111180. 5,
  111181. 21,
  111182. 4,
  111183. 22,
  111184. 3,
  111185. 23,
  111186. 2,
  111187. 24,
  111188. 1,
  111189. 25,
  111190. 0,
  111191. 26,
  111192. };
  111193. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111194. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111195. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111196. };
  111197. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111198. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111199. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111200. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111201. 11.5, 12.5,
  111202. };
  111203. static long _vq_quantmap__16c2_s_p9_2[] = {
  111204. 25, 23, 21, 19, 17, 15, 13, 11,
  111205. 9, 7, 5, 3, 1, 0, 2, 4,
  111206. 6, 8, 10, 12, 14, 16, 18, 20,
  111207. 22, 24, 26,
  111208. };
  111209. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111210. _vq_quantthresh__16c2_s_p9_2,
  111211. _vq_quantmap__16c2_s_p9_2,
  111212. 27,
  111213. 27
  111214. };
  111215. static static_codebook _16c2_s_p9_2 = {
  111216. 1, 27,
  111217. _vq_lengthlist__16c2_s_p9_2,
  111218. 1, -528875520, 1611661312, 5, 0,
  111219. _vq_quantlist__16c2_s_p9_2,
  111220. NULL,
  111221. &_vq_auxt__16c2_s_p9_2,
  111222. NULL,
  111223. 0
  111224. };
  111225. static long _huff_lengthlist__16c2_s_short[] = {
  111226. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111227. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111228. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111229. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111230. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111231. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111232. 15,12,14,14,
  111233. };
  111234. static static_codebook _huff_book__16c2_s_short = {
  111235. 2, 100,
  111236. _huff_lengthlist__16c2_s_short,
  111237. 0, 0, 0, 0, 0,
  111238. NULL,
  111239. NULL,
  111240. NULL,
  111241. NULL,
  111242. 0
  111243. };
  111244. static long _vq_quantlist__8c0_s_p1_0[] = {
  111245. 1,
  111246. 0,
  111247. 2,
  111248. };
  111249. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111250. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111251. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111256. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111261. 0, 0, 0, 0, 7, 9, 8, 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, 5, 8, 8, 0, 0, 0, 0,
  111296. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  111301. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 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, 7, 9,10, 0, 0,
  111306. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111342. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111347. 0, 0, 0, 0, 0, 9,10,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111352. 0, 0, 0, 0, 0, 0, 8,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111587. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111658. 0, 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,
  111661. };
  111662. static float _vq_quantthresh__8c0_s_p1_0[] = {
  111663. -0.5, 0.5,
  111664. };
  111665. static long _vq_quantmap__8c0_s_p1_0[] = {
  111666. 1, 0, 2,
  111667. };
  111668. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  111669. _vq_quantthresh__8c0_s_p1_0,
  111670. _vq_quantmap__8c0_s_p1_0,
  111671. 3,
  111672. 3
  111673. };
  111674. static static_codebook _8c0_s_p1_0 = {
  111675. 8, 6561,
  111676. _vq_lengthlist__8c0_s_p1_0,
  111677. 1, -535822336, 1611661312, 2, 0,
  111678. _vq_quantlist__8c0_s_p1_0,
  111679. NULL,
  111680. &_vq_auxt__8c0_s_p1_0,
  111681. NULL,
  111682. 0
  111683. };
  111684. static long _vq_quantlist__8c0_s_p2_0[] = {
  111685. 2,
  111686. 1,
  111687. 3,
  111688. 0,
  111689. 4,
  111690. };
  111691. static long _vq_lengthlist__8c0_s_p2_0[] = {
  111692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111731. 0,
  111732. };
  111733. static float _vq_quantthresh__8c0_s_p2_0[] = {
  111734. -1.5, -0.5, 0.5, 1.5,
  111735. };
  111736. static long _vq_quantmap__8c0_s_p2_0[] = {
  111737. 3, 1, 0, 2, 4,
  111738. };
  111739. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  111740. _vq_quantthresh__8c0_s_p2_0,
  111741. _vq_quantmap__8c0_s_p2_0,
  111742. 5,
  111743. 5
  111744. };
  111745. static static_codebook _8c0_s_p2_0 = {
  111746. 4, 625,
  111747. _vq_lengthlist__8c0_s_p2_0,
  111748. 1, -533725184, 1611661312, 3, 0,
  111749. _vq_quantlist__8c0_s_p2_0,
  111750. NULL,
  111751. &_vq_auxt__8c0_s_p2_0,
  111752. NULL,
  111753. 0
  111754. };
  111755. static long _vq_quantlist__8c0_s_p3_0[] = {
  111756. 2,
  111757. 1,
  111758. 3,
  111759. 0,
  111760. 4,
  111761. };
  111762. static long _vq_lengthlist__8c0_s_p3_0[] = {
  111763. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  111765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111766. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  111768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111769. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  111770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111802. 0,
  111803. };
  111804. static float _vq_quantthresh__8c0_s_p3_0[] = {
  111805. -1.5, -0.5, 0.5, 1.5,
  111806. };
  111807. static long _vq_quantmap__8c0_s_p3_0[] = {
  111808. 3, 1, 0, 2, 4,
  111809. };
  111810. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  111811. _vq_quantthresh__8c0_s_p3_0,
  111812. _vq_quantmap__8c0_s_p3_0,
  111813. 5,
  111814. 5
  111815. };
  111816. static static_codebook _8c0_s_p3_0 = {
  111817. 4, 625,
  111818. _vq_lengthlist__8c0_s_p3_0,
  111819. 1, -533725184, 1611661312, 3, 0,
  111820. _vq_quantlist__8c0_s_p3_0,
  111821. NULL,
  111822. &_vq_auxt__8c0_s_p3_0,
  111823. NULL,
  111824. 0
  111825. };
  111826. static long _vq_quantlist__8c0_s_p4_0[] = {
  111827. 4,
  111828. 3,
  111829. 5,
  111830. 2,
  111831. 6,
  111832. 1,
  111833. 7,
  111834. 0,
  111835. 8,
  111836. };
  111837. static long _vq_lengthlist__8c0_s_p4_0[] = {
  111838. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  111839. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  111840. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  111841. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  111842. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111843. 0,
  111844. };
  111845. static float _vq_quantthresh__8c0_s_p4_0[] = {
  111846. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111847. };
  111848. static long _vq_quantmap__8c0_s_p4_0[] = {
  111849. 7, 5, 3, 1, 0, 2, 4, 6,
  111850. 8,
  111851. };
  111852. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  111853. _vq_quantthresh__8c0_s_p4_0,
  111854. _vq_quantmap__8c0_s_p4_0,
  111855. 9,
  111856. 9
  111857. };
  111858. static static_codebook _8c0_s_p4_0 = {
  111859. 2, 81,
  111860. _vq_lengthlist__8c0_s_p4_0,
  111861. 1, -531628032, 1611661312, 4, 0,
  111862. _vq_quantlist__8c0_s_p4_0,
  111863. NULL,
  111864. &_vq_auxt__8c0_s_p4_0,
  111865. NULL,
  111866. 0
  111867. };
  111868. static long _vq_quantlist__8c0_s_p5_0[] = {
  111869. 4,
  111870. 3,
  111871. 5,
  111872. 2,
  111873. 6,
  111874. 1,
  111875. 7,
  111876. 0,
  111877. 8,
  111878. };
  111879. static long _vq_lengthlist__8c0_s_p5_0[] = {
  111880. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  111881. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  111882. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  111883. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  111884. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  111885. 10,
  111886. };
  111887. static float _vq_quantthresh__8c0_s_p5_0[] = {
  111888. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111889. };
  111890. static long _vq_quantmap__8c0_s_p5_0[] = {
  111891. 7, 5, 3, 1, 0, 2, 4, 6,
  111892. 8,
  111893. };
  111894. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  111895. _vq_quantthresh__8c0_s_p5_0,
  111896. _vq_quantmap__8c0_s_p5_0,
  111897. 9,
  111898. 9
  111899. };
  111900. static static_codebook _8c0_s_p5_0 = {
  111901. 2, 81,
  111902. _vq_lengthlist__8c0_s_p5_0,
  111903. 1, -531628032, 1611661312, 4, 0,
  111904. _vq_quantlist__8c0_s_p5_0,
  111905. NULL,
  111906. &_vq_auxt__8c0_s_p5_0,
  111907. NULL,
  111908. 0
  111909. };
  111910. static long _vq_quantlist__8c0_s_p6_0[] = {
  111911. 8,
  111912. 7,
  111913. 9,
  111914. 6,
  111915. 10,
  111916. 5,
  111917. 11,
  111918. 4,
  111919. 12,
  111920. 3,
  111921. 13,
  111922. 2,
  111923. 14,
  111924. 1,
  111925. 15,
  111926. 0,
  111927. 16,
  111928. };
  111929. static long _vq_lengthlist__8c0_s_p6_0[] = {
  111930. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  111931. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  111932. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  111933. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  111934. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  111935. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  111936. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  111937. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  111938. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  111939. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  111940. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  111941. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  111942. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  111943. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  111944. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  111945. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  111946. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  111947. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  111948. 14,
  111949. };
  111950. static float _vq_quantthresh__8c0_s_p6_0[] = {
  111951. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111952. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111953. };
  111954. static long _vq_quantmap__8c0_s_p6_0[] = {
  111955. 15, 13, 11, 9, 7, 5, 3, 1,
  111956. 0, 2, 4, 6, 8, 10, 12, 14,
  111957. 16,
  111958. };
  111959. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  111960. _vq_quantthresh__8c0_s_p6_0,
  111961. _vq_quantmap__8c0_s_p6_0,
  111962. 17,
  111963. 17
  111964. };
  111965. static static_codebook _8c0_s_p6_0 = {
  111966. 2, 289,
  111967. _vq_lengthlist__8c0_s_p6_0,
  111968. 1, -529530880, 1611661312, 5, 0,
  111969. _vq_quantlist__8c0_s_p6_0,
  111970. NULL,
  111971. &_vq_auxt__8c0_s_p6_0,
  111972. NULL,
  111973. 0
  111974. };
  111975. static long _vq_quantlist__8c0_s_p7_0[] = {
  111976. 1,
  111977. 0,
  111978. 2,
  111979. };
  111980. static long _vq_lengthlist__8c0_s_p7_0[] = {
  111981. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  111982. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  111983. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  111984. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  111985. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  111986. 10,
  111987. };
  111988. static float _vq_quantthresh__8c0_s_p7_0[] = {
  111989. -5.5, 5.5,
  111990. };
  111991. static long _vq_quantmap__8c0_s_p7_0[] = {
  111992. 1, 0, 2,
  111993. };
  111994. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  111995. _vq_quantthresh__8c0_s_p7_0,
  111996. _vq_quantmap__8c0_s_p7_0,
  111997. 3,
  111998. 3
  111999. };
  112000. static static_codebook _8c0_s_p7_0 = {
  112001. 4, 81,
  112002. _vq_lengthlist__8c0_s_p7_0,
  112003. 1, -529137664, 1618345984, 2, 0,
  112004. _vq_quantlist__8c0_s_p7_0,
  112005. NULL,
  112006. &_vq_auxt__8c0_s_p7_0,
  112007. NULL,
  112008. 0
  112009. };
  112010. static long _vq_quantlist__8c0_s_p7_1[] = {
  112011. 5,
  112012. 4,
  112013. 6,
  112014. 3,
  112015. 7,
  112016. 2,
  112017. 8,
  112018. 1,
  112019. 9,
  112020. 0,
  112021. 10,
  112022. };
  112023. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112024. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112025. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112026. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112027. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112028. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112029. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112030. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112031. 10,10,10, 9, 9, 9,10,10,10,
  112032. };
  112033. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112034. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112035. 3.5, 4.5,
  112036. };
  112037. static long _vq_quantmap__8c0_s_p7_1[] = {
  112038. 9, 7, 5, 3, 1, 0, 2, 4,
  112039. 6, 8, 10,
  112040. };
  112041. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112042. _vq_quantthresh__8c0_s_p7_1,
  112043. _vq_quantmap__8c0_s_p7_1,
  112044. 11,
  112045. 11
  112046. };
  112047. static static_codebook _8c0_s_p7_1 = {
  112048. 2, 121,
  112049. _vq_lengthlist__8c0_s_p7_1,
  112050. 1, -531365888, 1611661312, 4, 0,
  112051. _vq_quantlist__8c0_s_p7_1,
  112052. NULL,
  112053. &_vq_auxt__8c0_s_p7_1,
  112054. NULL,
  112055. 0
  112056. };
  112057. static long _vq_quantlist__8c0_s_p8_0[] = {
  112058. 6,
  112059. 5,
  112060. 7,
  112061. 4,
  112062. 8,
  112063. 3,
  112064. 9,
  112065. 2,
  112066. 10,
  112067. 1,
  112068. 11,
  112069. 0,
  112070. 12,
  112071. };
  112072. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112073. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112074. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112075. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112076. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112077. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112078. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112079. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112080. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112081. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112082. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112083. 0, 0,13,13,11,13,13,11,12,
  112084. };
  112085. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112086. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112087. 12.5, 17.5, 22.5, 27.5,
  112088. };
  112089. static long _vq_quantmap__8c0_s_p8_0[] = {
  112090. 11, 9, 7, 5, 3, 1, 0, 2,
  112091. 4, 6, 8, 10, 12,
  112092. };
  112093. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112094. _vq_quantthresh__8c0_s_p8_0,
  112095. _vq_quantmap__8c0_s_p8_0,
  112096. 13,
  112097. 13
  112098. };
  112099. static static_codebook _8c0_s_p8_0 = {
  112100. 2, 169,
  112101. _vq_lengthlist__8c0_s_p8_0,
  112102. 1, -526516224, 1616117760, 4, 0,
  112103. _vq_quantlist__8c0_s_p8_0,
  112104. NULL,
  112105. &_vq_auxt__8c0_s_p8_0,
  112106. NULL,
  112107. 0
  112108. };
  112109. static long _vq_quantlist__8c0_s_p8_1[] = {
  112110. 2,
  112111. 1,
  112112. 3,
  112113. 0,
  112114. 4,
  112115. };
  112116. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112117. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112118. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112119. };
  112120. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112121. -1.5, -0.5, 0.5, 1.5,
  112122. };
  112123. static long _vq_quantmap__8c0_s_p8_1[] = {
  112124. 3, 1, 0, 2, 4,
  112125. };
  112126. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112127. _vq_quantthresh__8c0_s_p8_1,
  112128. _vq_quantmap__8c0_s_p8_1,
  112129. 5,
  112130. 5
  112131. };
  112132. static static_codebook _8c0_s_p8_1 = {
  112133. 2, 25,
  112134. _vq_lengthlist__8c0_s_p8_1,
  112135. 1, -533725184, 1611661312, 3, 0,
  112136. _vq_quantlist__8c0_s_p8_1,
  112137. NULL,
  112138. &_vq_auxt__8c0_s_p8_1,
  112139. NULL,
  112140. 0
  112141. };
  112142. static long _vq_quantlist__8c0_s_p9_0[] = {
  112143. 1,
  112144. 0,
  112145. 2,
  112146. };
  112147. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112148. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112149. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112150. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112151. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112152. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112153. 7,
  112154. };
  112155. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112156. -157.5, 157.5,
  112157. };
  112158. static long _vq_quantmap__8c0_s_p9_0[] = {
  112159. 1, 0, 2,
  112160. };
  112161. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112162. _vq_quantthresh__8c0_s_p9_0,
  112163. _vq_quantmap__8c0_s_p9_0,
  112164. 3,
  112165. 3
  112166. };
  112167. static static_codebook _8c0_s_p9_0 = {
  112168. 4, 81,
  112169. _vq_lengthlist__8c0_s_p9_0,
  112170. 1, -518803456, 1628680192, 2, 0,
  112171. _vq_quantlist__8c0_s_p9_0,
  112172. NULL,
  112173. &_vq_auxt__8c0_s_p9_0,
  112174. NULL,
  112175. 0
  112176. };
  112177. static long _vq_quantlist__8c0_s_p9_1[] = {
  112178. 7,
  112179. 6,
  112180. 8,
  112181. 5,
  112182. 9,
  112183. 4,
  112184. 10,
  112185. 3,
  112186. 11,
  112187. 2,
  112188. 12,
  112189. 1,
  112190. 13,
  112191. 0,
  112192. 14,
  112193. };
  112194. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112195. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112196. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112197. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112198. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112199. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112200. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112201. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112202. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112203. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112204. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112205. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112206. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112207. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112208. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112209. 11,
  112210. };
  112211. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112212. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112213. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112214. };
  112215. static long _vq_quantmap__8c0_s_p9_1[] = {
  112216. 13, 11, 9, 7, 5, 3, 1, 0,
  112217. 2, 4, 6, 8, 10, 12, 14,
  112218. };
  112219. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112220. _vq_quantthresh__8c0_s_p9_1,
  112221. _vq_quantmap__8c0_s_p9_1,
  112222. 15,
  112223. 15
  112224. };
  112225. static static_codebook _8c0_s_p9_1 = {
  112226. 2, 225,
  112227. _vq_lengthlist__8c0_s_p9_1,
  112228. 1, -520986624, 1620377600, 4, 0,
  112229. _vq_quantlist__8c0_s_p9_1,
  112230. NULL,
  112231. &_vq_auxt__8c0_s_p9_1,
  112232. NULL,
  112233. 0
  112234. };
  112235. static long _vq_quantlist__8c0_s_p9_2[] = {
  112236. 10,
  112237. 9,
  112238. 11,
  112239. 8,
  112240. 12,
  112241. 7,
  112242. 13,
  112243. 6,
  112244. 14,
  112245. 5,
  112246. 15,
  112247. 4,
  112248. 16,
  112249. 3,
  112250. 17,
  112251. 2,
  112252. 18,
  112253. 1,
  112254. 19,
  112255. 0,
  112256. 20,
  112257. };
  112258. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112259. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112260. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112261. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112262. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112263. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112264. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112265. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112266. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112267. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112268. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112269. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112270. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112271. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112272. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112273. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112274. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112275. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112276. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112277. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112278. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112279. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112280. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112281. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112282. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112283. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112284. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112285. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112286. 10,11, 9,11,10, 9,10, 9,10,
  112287. };
  112288. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112289. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112290. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112291. 6.5, 7.5, 8.5, 9.5,
  112292. };
  112293. static long _vq_quantmap__8c0_s_p9_2[] = {
  112294. 19, 17, 15, 13, 11, 9, 7, 5,
  112295. 3, 1, 0, 2, 4, 6, 8, 10,
  112296. 12, 14, 16, 18, 20,
  112297. };
  112298. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112299. _vq_quantthresh__8c0_s_p9_2,
  112300. _vq_quantmap__8c0_s_p9_2,
  112301. 21,
  112302. 21
  112303. };
  112304. static static_codebook _8c0_s_p9_2 = {
  112305. 2, 441,
  112306. _vq_lengthlist__8c0_s_p9_2,
  112307. 1, -529268736, 1611661312, 5, 0,
  112308. _vq_quantlist__8c0_s_p9_2,
  112309. NULL,
  112310. &_vq_auxt__8c0_s_p9_2,
  112311. NULL,
  112312. 0
  112313. };
  112314. static long _huff_lengthlist__8c0_s_single[] = {
  112315. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112316. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112317. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112318. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112319. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112320. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112321. 17,16,17,17,
  112322. };
  112323. static static_codebook _huff_book__8c0_s_single = {
  112324. 2, 100,
  112325. _huff_lengthlist__8c0_s_single,
  112326. 0, 0, 0, 0, 0,
  112327. NULL,
  112328. NULL,
  112329. NULL,
  112330. NULL,
  112331. 0
  112332. };
  112333. static long _vq_quantlist__8c1_s_p1_0[] = {
  112334. 1,
  112335. 0,
  112336. 2,
  112337. };
  112338. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112339. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112340. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112345. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112350. 0, 0, 0, 0, 7, 9, 8, 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, 5, 8, 8, 0, 0, 0, 0,
  112385. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  112390. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  112395. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112431. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112436. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112441. 0, 0, 0, 0, 0, 0, 8,10, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112676. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112747. 0, 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,
  112750. };
  112751. static float _vq_quantthresh__8c1_s_p1_0[] = {
  112752. -0.5, 0.5,
  112753. };
  112754. static long _vq_quantmap__8c1_s_p1_0[] = {
  112755. 1, 0, 2,
  112756. };
  112757. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  112758. _vq_quantthresh__8c1_s_p1_0,
  112759. _vq_quantmap__8c1_s_p1_0,
  112760. 3,
  112761. 3
  112762. };
  112763. static static_codebook _8c1_s_p1_0 = {
  112764. 8, 6561,
  112765. _vq_lengthlist__8c1_s_p1_0,
  112766. 1, -535822336, 1611661312, 2, 0,
  112767. _vq_quantlist__8c1_s_p1_0,
  112768. NULL,
  112769. &_vq_auxt__8c1_s_p1_0,
  112770. NULL,
  112771. 0
  112772. };
  112773. static long _vq_quantlist__8c1_s_p2_0[] = {
  112774. 2,
  112775. 1,
  112776. 3,
  112777. 0,
  112778. 4,
  112779. };
  112780. static long _vq_lengthlist__8c1_s_p2_0[] = {
  112781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112820. 0,
  112821. };
  112822. static float _vq_quantthresh__8c1_s_p2_0[] = {
  112823. -1.5, -0.5, 0.5, 1.5,
  112824. };
  112825. static long _vq_quantmap__8c1_s_p2_0[] = {
  112826. 3, 1, 0, 2, 4,
  112827. };
  112828. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  112829. _vq_quantthresh__8c1_s_p2_0,
  112830. _vq_quantmap__8c1_s_p2_0,
  112831. 5,
  112832. 5
  112833. };
  112834. static static_codebook _8c1_s_p2_0 = {
  112835. 4, 625,
  112836. _vq_lengthlist__8c1_s_p2_0,
  112837. 1, -533725184, 1611661312, 3, 0,
  112838. _vq_quantlist__8c1_s_p2_0,
  112839. NULL,
  112840. &_vq_auxt__8c1_s_p2_0,
  112841. NULL,
  112842. 0
  112843. };
  112844. static long _vq_quantlist__8c1_s_p3_0[] = {
  112845. 2,
  112846. 1,
  112847. 3,
  112848. 0,
  112849. 4,
  112850. };
  112851. static long _vq_lengthlist__8c1_s_p3_0[] = {
  112852. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  112854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112855. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  112857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112858. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112891. 0,
  112892. };
  112893. static float _vq_quantthresh__8c1_s_p3_0[] = {
  112894. -1.5, -0.5, 0.5, 1.5,
  112895. };
  112896. static long _vq_quantmap__8c1_s_p3_0[] = {
  112897. 3, 1, 0, 2, 4,
  112898. };
  112899. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  112900. _vq_quantthresh__8c1_s_p3_0,
  112901. _vq_quantmap__8c1_s_p3_0,
  112902. 5,
  112903. 5
  112904. };
  112905. static static_codebook _8c1_s_p3_0 = {
  112906. 4, 625,
  112907. _vq_lengthlist__8c1_s_p3_0,
  112908. 1, -533725184, 1611661312, 3, 0,
  112909. _vq_quantlist__8c1_s_p3_0,
  112910. NULL,
  112911. &_vq_auxt__8c1_s_p3_0,
  112912. NULL,
  112913. 0
  112914. };
  112915. static long _vq_quantlist__8c1_s_p4_0[] = {
  112916. 4,
  112917. 3,
  112918. 5,
  112919. 2,
  112920. 6,
  112921. 1,
  112922. 7,
  112923. 0,
  112924. 8,
  112925. };
  112926. static long _vq_lengthlist__8c1_s_p4_0[] = {
  112927. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112928. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112929. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112930. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112931. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112932. 0,
  112933. };
  112934. static float _vq_quantthresh__8c1_s_p4_0[] = {
  112935. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112936. };
  112937. static long _vq_quantmap__8c1_s_p4_0[] = {
  112938. 7, 5, 3, 1, 0, 2, 4, 6,
  112939. 8,
  112940. };
  112941. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  112942. _vq_quantthresh__8c1_s_p4_0,
  112943. _vq_quantmap__8c1_s_p4_0,
  112944. 9,
  112945. 9
  112946. };
  112947. static static_codebook _8c1_s_p4_0 = {
  112948. 2, 81,
  112949. _vq_lengthlist__8c1_s_p4_0,
  112950. 1, -531628032, 1611661312, 4, 0,
  112951. _vq_quantlist__8c1_s_p4_0,
  112952. NULL,
  112953. &_vq_auxt__8c1_s_p4_0,
  112954. NULL,
  112955. 0
  112956. };
  112957. static long _vq_quantlist__8c1_s_p5_0[] = {
  112958. 4,
  112959. 3,
  112960. 5,
  112961. 2,
  112962. 6,
  112963. 1,
  112964. 7,
  112965. 0,
  112966. 8,
  112967. };
  112968. static long _vq_lengthlist__8c1_s_p5_0[] = {
  112969. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  112970. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  112971. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  112972. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  112973. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112974. 10,
  112975. };
  112976. static float _vq_quantthresh__8c1_s_p5_0[] = {
  112977. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112978. };
  112979. static long _vq_quantmap__8c1_s_p5_0[] = {
  112980. 7, 5, 3, 1, 0, 2, 4, 6,
  112981. 8,
  112982. };
  112983. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  112984. _vq_quantthresh__8c1_s_p5_0,
  112985. _vq_quantmap__8c1_s_p5_0,
  112986. 9,
  112987. 9
  112988. };
  112989. static static_codebook _8c1_s_p5_0 = {
  112990. 2, 81,
  112991. _vq_lengthlist__8c1_s_p5_0,
  112992. 1, -531628032, 1611661312, 4, 0,
  112993. _vq_quantlist__8c1_s_p5_0,
  112994. NULL,
  112995. &_vq_auxt__8c1_s_p5_0,
  112996. NULL,
  112997. 0
  112998. };
  112999. static long _vq_quantlist__8c1_s_p6_0[] = {
  113000. 8,
  113001. 7,
  113002. 9,
  113003. 6,
  113004. 10,
  113005. 5,
  113006. 11,
  113007. 4,
  113008. 12,
  113009. 3,
  113010. 13,
  113011. 2,
  113012. 14,
  113013. 1,
  113014. 15,
  113015. 0,
  113016. 16,
  113017. };
  113018. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113019. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113020. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113021. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113022. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113023. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113024. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113025. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113026. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113027. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113028. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113029. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113030. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113031. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113032. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113033. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113034. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113035. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113036. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113037. 14,
  113038. };
  113039. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113040. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113041. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113042. };
  113043. static long _vq_quantmap__8c1_s_p6_0[] = {
  113044. 15, 13, 11, 9, 7, 5, 3, 1,
  113045. 0, 2, 4, 6, 8, 10, 12, 14,
  113046. 16,
  113047. };
  113048. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113049. _vq_quantthresh__8c1_s_p6_0,
  113050. _vq_quantmap__8c1_s_p6_0,
  113051. 17,
  113052. 17
  113053. };
  113054. static static_codebook _8c1_s_p6_0 = {
  113055. 2, 289,
  113056. _vq_lengthlist__8c1_s_p6_0,
  113057. 1, -529530880, 1611661312, 5, 0,
  113058. _vq_quantlist__8c1_s_p6_0,
  113059. NULL,
  113060. &_vq_auxt__8c1_s_p6_0,
  113061. NULL,
  113062. 0
  113063. };
  113064. static long _vq_quantlist__8c1_s_p7_0[] = {
  113065. 1,
  113066. 0,
  113067. 2,
  113068. };
  113069. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113070. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113071. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113072. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113073. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113074. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113075. 9,
  113076. };
  113077. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113078. -5.5, 5.5,
  113079. };
  113080. static long _vq_quantmap__8c1_s_p7_0[] = {
  113081. 1, 0, 2,
  113082. };
  113083. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113084. _vq_quantthresh__8c1_s_p7_0,
  113085. _vq_quantmap__8c1_s_p7_0,
  113086. 3,
  113087. 3
  113088. };
  113089. static static_codebook _8c1_s_p7_0 = {
  113090. 4, 81,
  113091. _vq_lengthlist__8c1_s_p7_0,
  113092. 1, -529137664, 1618345984, 2, 0,
  113093. _vq_quantlist__8c1_s_p7_0,
  113094. NULL,
  113095. &_vq_auxt__8c1_s_p7_0,
  113096. NULL,
  113097. 0
  113098. };
  113099. static long _vq_quantlist__8c1_s_p7_1[] = {
  113100. 5,
  113101. 4,
  113102. 6,
  113103. 3,
  113104. 7,
  113105. 2,
  113106. 8,
  113107. 1,
  113108. 9,
  113109. 0,
  113110. 10,
  113111. };
  113112. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113113. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113114. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113115. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113116. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113117. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113118. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113119. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113120. 10,10,10, 8, 8, 8, 8, 8, 8,
  113121. };
  113122. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113123. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113124. 3.5, 4.5,
  113125. };
  113126. static long _vq_quantmap__8c1_s_p7_1[] = {
  113127. 9, 7, 5, 3, 1, 0, 2, 4,
  113128. 6, 8, 10,
  113129. };
  113130. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113131. _vq_quantthresh__8c1_s_p7_1,
  113132. _vq_quantmap__8c1_s_p7_1,
  113133. 11,
  113134. 11
  113135. };
  113136. static static_codebook _8c1_s_p7_1 = {
  113137. 2, 121,
  113138. _vq_lengthlist__8c1_s_p7_1,
  113139. 1, -531365888, 1611661312, 4, 0,
  113140. _vq_quantlist__8c1_s_p7_1,
  113141. NULL,
  113142. &_vq_auxt__8c1_s_p7_1,
  113143. NULL,
  113144. 0
  113145. };
  113146. static long _vq_quantlist__8c1_s_p8_0[] = {
  113147. 6,
  113148. 5,
  113149. 7,
  113150. 4,
  113151. 8,
  113152. 3,
  113153. 9,
  113154. 2,
  113155. 10,
  113156. 1,
  113157. 11,
  113158. 0,
  113159. 12,
  113160. };
  113161. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113162. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113163. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113164. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113165. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113166. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113167. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113168. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113169. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113170. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113171. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113172. 0,12,12,11,10,12,11,13,12,
  113173. };
  113174. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113175. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113176. 12.5, 17.5, 22.5, 27.5,
  113177. };
  113178. static long _vq_quantmap__8c1_s_p8_0[] = {
  113179. 11, 9, 7, 5, 3, 1, 0, 2,
  113180. 4, 6, 8, 10, 12,
  113181. };
  113182. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113183. _vq_quantthresh__8c1_s_p8_0,
  113184. _vq_quantmap__8c1_s_p8_0,
  113185. 13,
  113186. 13
  113187. };
  113188. static static_codebook _8c1_s_p8_0 = {
  113189. 2, 169,
  113190. _vq_lengthlist__8c1_s_p8_0,
  113191. 1, -526516224, 1616117760, 4, 0,
  113192. _vq_quantlist__8c1_s_p8_0,
  113193. NULL,
  113194. &_vq_auxt__8c1_s_p8_0,
  113195. NULL,
  113196. 0
  113197. };
  113198. static long _vq_quantlist__8c1_s_p8_1[] = {
  113199. 2,
  113200. 1,
  113201. 3,
  113202. 0,
  113203. 4,
  113204. };
  113205. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113206. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113207. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113208. };
  113209. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113210. -1.5, -0.5, 0.5, 1.5,
  113211. };
  113212. static long _vq_quantmap__8c1_s_p8_1[] = {
  113213. 3, 1, 0, 2, 4,
  113214. };
  113215. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113216. _vq_quantthresh__8c1_s_p8_1,
  113217. _vq_quantmap__8c1_s_p8_1,
  113218. 5,
  113219. 5
  113220. };
  113221. static static_codebook _8c1_s_p8_1 = {
  113222. 2, 25,
  113223. _vq_lengthlist__8c1_s_p8_1,
  113224. 1, -533725184, 1611661312, 3, 0,
  113225. _vq_quantlist__8c1_s_p8_1,
  113226. NULL,
  113227. &_vq_auxt__8c1_s_p8_1,
  113228. NULL,
  113229. 0
  113230. };
  113231. static long _vq_quantlist__8c1_s_p9_0[] = {
  113232. 6,
  113233. 5,
  113234. 7,
  113235. 4,
  113236. 8,
  113237. 3,
  113238. 9,
  113239. 2,
  113240. 10,
  113241. 1,
  113242. 11,
  113243. 0,
  113244. 12,
  113245. };
  113246. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113247. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113248. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113249. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113250. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113251. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113252. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113253. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113254. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113255. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113256. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113257. 10,10,10,10,10, 9, 9, 9, 9,
  113258. };
  113259. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113260. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113261. 787.5, 1102.5, 1417.5, 1732.5,
  113262. };
  113263. static long _vq_quantmap__8c1_s_p9_0[] = {
  113264. 11, 9, 7, 5, 3, 1, 0, 2,
  113265. 4, 6, 8, 10, 12,
  113266. };
  113267. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113268. _vq_quantthresh__8c1_s_p9_0,
  113269. _vq_quantmap__8c1_s_p9_0,
  113270. 13,
  113271. 13
  113272. };
  113273. static static_codebook _8c1_s_p9_0 = {
  113274. 2, 169,
  113275. _vq_lengthlist__8c1_s_p9_0,
  113276. 1, -513964032, 1628680192, 4, 0,
  113277. _vq_quantlist__8c1_s_p9_0,
  113278. NULL,
  113279. &_vq_auxt__8c1_s_p9_0,
  113280. NULL,
  113281. 0
  113282. };
  113283. static long _vq_quantlist__8c1_s_p9_1[] = {
  113284. 7,
  113285. 6,
  113286. 8,
  113287. 5,
  113288. 9,
  113289. 4,
  113290. 10,
  113291. 3,
  113292. 11,
  113293. 2,
  113294. 12,
  113295. 1,
  113296. 13,
  113297. 0,
  113298. 14,
  113299. };
  113300. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113301. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113302. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113303. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113304. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113305. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113306. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113307. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113308. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113309. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113310. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113311. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113312. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113313. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113314. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113315. 15,
  113316. };
  113317. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113318. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113319. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113320. };
  113321. static long _vq_quantmap__8c1_s_p9_1[] = {
  113322. 13, 11, 9, 7, 5, 3, 1, 0,
  113323. 2, 4, 6, 8, 10, 12, 14,
  113324. };
  113325. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113326. _vq_quantthresh__8c1_s_p9_1,
  113327. _vq_quantmap__8c1_s_p9_1,
  113328. 15,
  113329. 15
  113330. };
  113331. static static_codebook _8c1_s_p9_1 = {
  113332. 2, 225,
  113333. _vq_lengthlist__8c1_s_p9_1,
  113334. 1, -520986624, 1620377600, 4, 0,
  113335. _vq_quantlist__8c1_s_p9_1,
  113336. NULL,
  113337. &_vq_auxt__8c1_s_p9_1,
  113338. NULL,
  113339. 0
  113340. };
  113341. static long _vq_quantlist__8c1_s_p9_2[] = {
  113342. 10,
  113343. 9,
  113344. 11,
  113345. 8,
  113346. 12,
  113347. 7,
  113348. 13,
  113349. 6,
  113350. 14,
  113351. 5,
  113352. 15,
  113353. 4,
  113354. 16,
  113355. 3,
  113356. 17,
  113357. 2,
  113358. 18,
  113359. 1,
  113360. 19,
  113361. 0,
  113362. 20,
  113363. };
  113364. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113365. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113366. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113367. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113368. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113369. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113370. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113371. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113372. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113373. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113374. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113375. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113376. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113377. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113378. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113379. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113380. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113381. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113382. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113383. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113384. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113385. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113386. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113387. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113388. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113389. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113390. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113391. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113392. 10,10,10,10,10,10,10,10,10,
  113393. };
  113394. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113395. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113396. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113397. 6.5, 7.5, 8.5, 9.5,
  113398. };
  113399. static long _vq_quantmap__8c1_s_p9_2[] = {
  113400. 19, 17, 15, 13, 11, 9, 7, 5,
  113401. 3, 1, 0, 2, 4, 6, 8, 10,
  113402. 12, 14, 16, 18, 20,
  113403. };
  113404. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113405. _vq_quantthresh__8c1_s_p9_2,
  113406. _vq_quantmap__8c1_s_p9_2,
  113407. 21,
  113408. 21
  113409. };
  113410. static static_codebook _8c1_s_p9_2 = {
  113411. 2, 441,
  113412. _vq_lengthlist__8c1_s_p9_2,
  113413. 1, -529268736, 1611661312, 5, 0,
  113414. _vq_quantlist__8c1_s_p9_2,
  113415. NULL,
  113416. &_vq_auxt__8c1_s_p9_2,
  113417. NULL,
  113418. 0
  113419. };
  113420. static long _huff_lengthlist__8c1_s_single[] = {
  113421. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113422. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113423. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113424. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113425. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113426. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113427. 9, 7, 7, 8,
  113428. };
  113429. static static_codebook _huff_book__8c1_s_single = {
  113430. 2, 100,
  113431. _huff_lengthlist__8c1_s_single,
  113432. 0, 0, 0, 0, 0,
  113433. NULL,
  113434. NULL,
  113435. NULL,
  113436. NULL,
  113437. 0
  113438. };
  113439. static long _huff_lengthlist__44c2_s_long[] = {
  113440. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113441. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113442. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113443. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113444. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113445. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113446. 10, 8, 8, 9,
  113447. };
  113448. static static_codebook _huff_book__44c2_s_long = {
  113449. 2, 100,
  113450. _huff_lengthlist__44c2_s_long,
  113451. 0, 0, 0, 0, 0,
  113452. NULL,
  113453. NULL,
  113454. NULL,
  113455. NULL,
  113456. 0
  113457. };
  113458. static long _vq_quantlist__44c2_s_p1_0[] = {
  113459. 1,
  113460. 0,
  113461. 2,
  113462. };
  113463. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113464. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113465. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113470. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113475. 0, 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0,
  113510. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  113515. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  113520. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113556. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113561. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113566. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113805. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113872. 0, 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,
  113875. };
  113876. static float _vq_quantthresh__44c2_s_p1_0[] = {
  113877. -0.5, 0.5,
  113878. };
  113879. static long _vq_quantmap__44c2_s_p1_0[] = {
  113880. 1, 0, 2,
  113881. };
  113882. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  113883. _vq_quantthresh__44c2_s_p1_0,
  113884. _vq_quantmap__44c2_s_p1_0,
  113885. 3,
  113886. 3
  113887. };
  113888. static static_codebook _44c2_s_p1_0 = {
  113889. 8, 6561,
  113890. _vq_lengthlist__44c2_s_p1_0,
  113891. 1, -535822336, 1611661312, 2, 0,
  113892. _vq_quantlist__44c2_s_p1_0,
  113893. NULL,
  113894. &_vq_auxt__44c2_s_p1_0,
  113895. NULL,
  113896. 0
  113897. };
  113898. static long _vq_quantlist__44c2_s_p2_0[] = {
  113899. 2,
  113900. 1,
  113901. 3,
  113902. 0,
  113903. 4,
  113904. };
  113905. static long _vq_lengthlist__44c2_s_p2_0[] = {
  113906. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  113907. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  113908. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  113909. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  113910. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113915. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  113916. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  113917. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  113918. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113923. 0, 0, 0, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  113924. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  113925. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  113926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113931. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  113932. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  113933. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  113934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113945. 0,
  113946. };
  113947. static float _vq_quantthresh__44c2_s_p2_0[] = {
  113948. -1.5, -0.5, 0.5, 1.5,
  113949. };
  113950. static long _vq_quantmap__44c2_s_p2_0[] = {
  113951. 3, 1, 0, 2, 4,
  113952. };
  113953. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  113954. _vq_quantthresh__44c2_s_p2_0,
  113955. _vq_quantmap__44c2_s_p2_0,
  113956. 5,
  113957. 5
  113958. };
  113959. static static_codebook _44c2_s_p2_0 = {
  113960. 4, 625,
  113961. _vq_lengthlist__44c2_s_p2_0,
  113962. 1, -533725184, 1611661312, 3, 0,
  113963. _vq_quantlist__44c2_s_p2_0,
  113964. NULL,
  113965. &_vq_auxt__44c2_s_p2_0,
  113966. NULL,
  113967. 0
  113968. };
  113969. static long _vq_quantlist__44c2_s_p3_0[] = {
  113970. 2,
  113971. 1,
  113972. 3,
  113973. 0,
  113974. 4,
  113975. };
  113976. static long _vq_lengthlist__44c2_s_p3_0[] = {
  113977. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113980. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  113982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113983. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114016. 0,
  114017. };
  114018. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114019. -1.5, -0.5, 0.5, 1.5,
  114020. };
  114021. static long _vq_quantmap__44c2_s_p3_0[] = {
  114022. 3, 1, 0, 2, 4,
  114023. };
  114024. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114025. _vq_quantthresh__44c2_s_p3_0,
  114026. _vq_quantmap__44c2_s_p3_0,
  114027. 5,
  114028. 5
  114029. };
  114030. static static_codebook _44c2_s_p3_0 = {
  114031. 4, 625,
  114032. _vq_lengthlist__44c2_s_p3_0,
  114033. 1, -533725184, 1611661312, 3, 0,
  114034. _vq_quantlist__44c2_s_p3_0,
  114035. NULL,
  114036. &_vq_auxt__44c2_s_p3_0,
  114037. NULL,
  114038. 0
  114039. };
  114040. static long _vq_quantlist__44c2_s_p4_0[] = {
  114041. 4,
  114042. 3,
  114043. 5,
  114044. 2,
  114045. 6,
  114046. 1,
  114047. 7,
  114048. 0,
  114049. 8,
  114050. };
  114051. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114052. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114053. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114054. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114055. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114056. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114057. 0,
  114058. };
  114059. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114060. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114061. };
  114062. static long _vq_quantmap__44c2_s_p4_0[] = {
  114063. 7, 5, 3, 1, 0, 2, 4, 6,
  114064. 8,
  114065. };
  114066. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114067. _vq_quantthresh__44c2_s_p4_0,
  114068. _vq_quantmap__44c2_s_p4_0,
  114069. 9,
  114070. 9
  114071. };
  114072. static static_codebook _44c2_s_p4_0 = {
  114073. 2, 81,
  114074. _vq_lengthlist__44c2_s_p4_0,
  114075. 1, -531628032, 1611661312, 4, 0,
  114076. _vq_quantlist__44c2_s_p4_0,
  114077. NULL,
  114078. &_vq_auxt__44c2_s_p4_0,
  114079. NULL,
  114080. 0
  114081. };
  114082. static long _vq_quantlist__44c2_s_p5_0[] = {
  114083. 4,
  114084. 3,
  114085. 5,
  114086. 2,
  114087. 6,
  114088. 1,
  114089. 7,
  114090. 0,
  114091. 8,
  114092. };
  114093. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114094. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114095. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114096. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114097. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114098. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114099. 11,
  114100. };
  114101. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114102. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114103. };
  114104. static long _vq_quantmap__44c2_s_p5_0[] = {
  114105. 7, 5, 3, 1, 0, 2, 4, 6,
  114106. 8,
  114107. };
  114108. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114109. _vq_quantthresh__44c2_s_p5_0,
  114110. _vq_quantmap__44c2_s_p5_0,
  114111. 9,
  114112. 9
  114113. };
  114114. static static_codebook _44c2_s_p5_0 = {
  114115. 2, 81,
  114116. _vq_lengthlist__44c2_s_p5_0,
  114117. 1, -531628032, 1611661312, 4, 0,
  114118. _vq_quantlist__44c2_s_p5_0,
  114119. NULL,
  114120. &_vq_auxt__44c2_s_p5_0,
  114121. NULL,
  114122. 0
  114123. };
  114124. static long _vq_quantlist__44c2_s_p6_0[] = {
  114125. 8,
  114126. 7,
  114127. 9,
  114128. 6,
  114129. 10,
  114130. 5,
  114131. 11,
  114132. 4,
  114133. 12,
  114134. 3,
  114135. 13,
  114136. 2,
  114137. 14,
  114138. 1,
  114139. 15,
  114140. 0,
  114141. 16,
  114142. };
  114143. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114144. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114145. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114146. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114147. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114148. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114149. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114150. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114151. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114152. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114153. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114154. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114155. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114156. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114157. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114158. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114159. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114160. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114161. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114162. 14,
  114163. };
  114164. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114165. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114166. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114167. };
  114168. static long _vq_quantmap__44c2_s_p6_0[] = {
  114169. 15, 13, 11, 9, 7, 5, 3, 1,
  114170. 0, 2, 4, 6, 8, 10, 12, 14,
  114171. 16,
  114172. };
  114173. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114174. _vq_quantthresh__44c2_s_p6_0,
  114175. _vq_quantmap__44c2_s_p6_0,
  114176. 17,
  114177. 17
  114178. };
  114179. static static_codebook _44c2_s_p6_0 = {
  114180. 2, 289,
  114181. _vq_lengthlist__44c2_s_p6_0,
  114182. 1, -529530880, 1611661312, 5, 0,
  114183. _vq_quantlist__44c2_s_p6_0,
  114184. NULL,
  114185. &_vq_auxt__44c2_s_p6_0,
  114186. NULL,
  114187. 0
  114188. };
  114189. static long _vq_quantlist__44c2_s_p7_0[] = {
  114190. 1,
  114191. 0,
  114192. 2,
  114193. };
  114194. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114195. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114196. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114197. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114198. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114199. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114200. 11,
  114201. };
  114202. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114203. -5.5, 5.5,
  114204. };
  114205. static long _vq_quantmap__44c2_s_p7_0[] = {
  114206. 1, 0, 2,
  114207. };
  114208. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114209. _vq_quantthresh__44c2_s_p7_0,
  114210. _vq_quantmap__44c2_s_p7_0,
  114211. 3,
  114212. 3
  114213. };
  114214. static static_codebook _44c2_s_p7_0 = {
  114215. 4, 81,
  114216. _vq_lengthlist__44c2_s_p7_0,
  114217. 1, -529137664, 1618345984, 2, 0,
  114218. _vq_quantlist__44c2_s_p7_0,
  114219. NULL,
  114220. &_vq_auxt__44c2_s_p7_0,
  114221. NULL,
  114222. 0
  114223. };
  114224. static long _vq_quantlist__44c2_s_p7_1[] = {
  114225. 5,
  114226. 4,
  114227. 6,
  114228. 3,
  114229. 7,
  114230. 2,
  114231. 8,
  114232. 1,
  114233. 9,
  114234. 0,
  114235. 10,
  114236. };
  114237. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114238. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114239. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114240. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114241. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114242. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114243. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114244. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114245. 10,10,10, 8, 8, 8, 8, 8, 8,
  114246. };
  114247. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114248. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114249. 3.5, 4.5,
  114250. };
  114251. static long _vq_quantmap__44c2_s_p7_1[] = {
  114252. 9, 7, 5, 3, 1, 0, 2, 4,
  114253. 6, 8, 10,
  114254. };
  114255. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114256. _vq_quantthresh__44c2_s_p7_1,
  114257. _vq_quantmap__44c2_s_p7_1,
  114258. 11,
  114259. 11
  114260. };
  114261. static static_codebook _44c2_s_p7_1 = {
  114262. 2, 121,
  114263. _vq_lengthlist__44c2_s_p7_1,
  114264. 1, -531365888, 1611661312, 4, 0,
  114265. _vq_quantlist__44c2_s_p7_1,
  114266. NULL,
  114267. &_vq_auxt__44c2_s_p7_1,
  114268. NULL,
  114269. 0
  114270. };
  114271. static long _vq_quantlist__44c2_s_p8_0[] = {
  114272. 6,
  114273. 5,
  114274. 7,
  114275. 4,
  114276. 8,
  114277. 3,
  114278. 9,
  114279. 2,
  114280. 10,
  114281. 1,
  114282. 11,
  114283. 0,
  114284. 12,
  114285. };
  114286. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114287. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114288. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114289. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114290. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114291. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114292. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114293. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114294. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114295. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114296. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114297. 0,12,12,12,12,13,12,14,14,
  114298. };
  114299. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114300. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114301. 12.5, 17.5, 22.5, 27.5,
  114302. };
  114303. static long _vq_quantmap__44c2_s_p8_0[] = {
  114304. 11, 9, 7, 5, 3, 1, 0, 2,
  114305. 4, 6, 8, 10, 12,
  114306. };
  114307. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114308. _vq_quantthresh__44c2_s_p8_0,
  114309. _vq_quantmap__44c2_s_p8_0,
  114310. 13,
  114311. 13
  114312. };
  114313. static static_codebook _44c2_s_p8_0 = {
  114314. 2, 169,
  114315. _vq_lengthlist__44c2_s_p8_0,
  114316. 1, -526516224, 1616117760, 4, 0,
  114317. _vq_quantlist__44c2_s_p8_0,
  114318. NULL,
  114319. &_vq_auxt__44c2_s_p8_0,
  114320. NULL,
  114321. 0
  114322. };
  114323. static long _vq_quantlist__44c2_s_p8_1[] = {
  114324. 2,
  114325. 1,
  114326. 3,
  114327. 0,
  114328. 4,
  114329. };
  114330. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114331. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114332. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114333. };
  114334. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114335. -1.5, -0.5, 0.5, 1.5,
  114336. };
  114337. static long _vq_quantmap__44c2_s_p8_1[] = {
  114338. 3, 1, 0, 2, 4,
  114339. };
  114340. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114341. _vq_quantthresh__44c2_s_p8_1,
  114342. _vq_quantmap__44c2_s_p8_1,
  114343. 5,
  114344. 5
  114345. };
  114346. static static_codebook _44c2_s_p8_1 = {
  114347. 2, 25,
  114348. _vq_lengthlist__44c2_s_p8_1,
  114349. 1, -533725184, 1611661312, 3, 0,
  114350. _vq_quantlist__44c2_s_p8_1,
  114351. NULL,
  114352. &_vq_auxt__44c2_s_p8_1,
  114353. NULL,
  114354. 0
  114355. };
  114356. static long _vq_quantlist__44c2_s_p9_0[] = {
  114357. 6,
  114358. 5,
  114359. 7,
  114360. 4,
  114361. 8,
  114362. 3,
  114363. 9,
  114364. 2,
  114365. 10,
  114366. 1,
  114367. 11,
  114368. 0,
  114369. 12,
  114370. };
  114371. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114372. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114373. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114374. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114375. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114376. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114377. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114378. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114379. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114380. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114381. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114382. 11,11,11,11,11,11,11,11,11,
  114383. };
  114384. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114385. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114386. 552.5, 773.5, 994.5, 1215.5,
  114387. };
  114388. static long _vq_quantmap__44c2_s_p9_0[] = {
  114389. 11, 9, 7, 5, 3, 1, 0, 2,
  114390. 4, 6, 8, 10, 12,
  114391. };
  114392. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114393. _vq_quantthresh__44c2_s_p9_0,
  114394. _vq_quantmap__44c2_s_p9_0,
  114395. 13,
  114396. 13
  114397. };
  114398. static static_codebook _44c2_s_p9_0 = {
  114399. 2, 169,
  114400. _vq_lengthlist__44c2_s_p9_0,
  114401. 1, -514541568, 1627103232, 4, 0,
  114402. _vq_quantlist__44c2_s_p9_0,
  114403. NULL,
  114404. &_vq_auxt__44c2_s_p9_0,
  114405. NULL,
  114406. 0
  114407. };
  114408. static long _vq_quantlist__44c2_s_p9_1[] = {
  114409. 6,
  114410. 5,
  114411. 7,
  114412. 4,
  114413. 8,
  114414. 3,
  114415. 9,
  114416. 2,
  114417. 10,
  114418. 1,
  114419. 11,
  114420. 0,
  114421. 12,
  114422. };
  114423. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114424. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114425. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114426. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114427. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114428. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114429. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114430. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114431. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114432. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114433. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114434. 17,13,12,12,10,13,11,14,14,
  114435. };
  114436. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114437. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114438. 42.5, 59.5, 76.5, 93.5,
  114439. };
  114440. static long _vq_quantmap__44c2_s_p9_1[] = {
  114441. 11, 9, 7, 5, 3, 1, 0, 2,
  114442. 4, 6, 8, 10, 12,
  114443. };
  114444. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114445. _vq_quantthresh__44c2_s_p9_1,
  114446. _vq_quantmap__44c2_s_p9_1,
  114447. 13,
  114448. 13
  114449. };
  114450. static static_codebook _44c2_s_p9_1 = {
  114451. 2, 169,
  114452. _vq_lengthlist__44c2_s_p9_1,
  114453. 1, -522616832, 1620115456, 4, 0,
  114454. _vq_quantlist__44c2_s_p9_1,
  114455. NULL,
  114456. &_vq_auxt__44c2_s_p9_1,
  114457. NULL,
  114458. 0
  114459. };
  114460. static long _vq_quantlist__44c2_s_p9_2[] = {
  114461. 8,
  114462. 7,
  114463. 9,
  114464. 6,
  114465. 10,
  114466. 5,
  114467. 11,
  114468. 4,
  114469. 12,
  114470. 3,
  114471. 13,
  114472. 2,
  114473. 14,
  114474. 1,
  114475. 15,
  114476. 0,
  114477. 16,
  114478. };
  114479. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114480. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114481. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114482. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114483. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114484. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114485. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114486. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114487. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114488. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114489. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114490. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114491. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114492. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114493. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114494. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114495. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114496. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114497. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114498. 10,
  114499. };
  114500. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114501. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114502. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114503. };
  114504. static long _vq_quantmap__44c2_s_p9_2[] = {
  114505. 15, 13, 11, 9, 7, 5, 3, 1,
  114506. 0, 2, 4, 6, 8, 10, 12, 14,
  114507. 16,
  114508. };
  114509. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114510. _vq_quantthresh__44c2_s_p9_2,
  114511. _vq_quantmap__44c2_s_p9_2,
  114512. 17,
  114513. 17
  114514. };
  114515. static static_codebook _44c2_s_p9_2 = {
  114516. 2, 289,
  114517. _vq_lengthlist__44c2_s_p9_2,
  114518. 1, -529530880, 1611661312, 5, 0,
  114519. _vq_quantlist__44c2_s_p9_2,
  114520. NULL,
  114521. &_vq_auxt__44c2_s_p9_2,
  114522. NULL,
  114523. 0
  114524. };
  114525. static long _huff_lengthlist__44c2_s_short[] = {
  114526. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114527. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114528. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114529. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114530. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114531. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114532. 6, 8, 9,12,
  114533. };
  114534. static static_codebook _huff_book__44c2_s_short = {
  114535. 2, 100,
  114536. _huff_lengthlist__44c2_s_short,
  114537. 0, 0, 0, 0, 0,
  114538. NULL,
  114539. NULL,
  114540. NULL,
  114541. NULL,
  114542. 0
  114543. };
  114544. static long _huff_lengthlist__44c3_s_long[] = {
  114545. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  114546. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  114547. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  114548. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  114549. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  114550. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  114551. 9, 8, 8, 8,
  114552. };
  114553. static static_codebook _huff_book__44c3_s_long = {
  114554. 2, 100,
  114555. _huff_lengthlist__44c3_s_long,
  114556. 0, 0, 0, 0, 0,
  114557. NULL,
  114558. NULL,
  114559. NULL,
  114560. NULL,
  114561. 0
  114562. };
  114563. static long _vq_quantlist__44c3_s_p1_0[] = {
  114564. 1,
  114565. 0,
  114566. 2,
  114567. };
  114568. static long _vq_lengthlist__44c3_s_p1_0[] = {
  114569. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114570. 0, 0, 5, 6, 6, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114575. 0, 0, 0, 6, 7, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114580. 0, 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0,
  114615. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  114620. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  114625. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114661. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114666. 0, 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114671. 0, 0, 0, 0, 0, 0, 8, 9, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114910. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114977. 0, 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,
  114980. };
  114981. static float _vq_quantthresh__44c3_s_p1_0[] = {
  114982. -0.5, 0.5,
  114983. };
  114984. static long _vq_quantmap__44c3_s_p1_0[] = {
  114985. 1, 0, 2,
  114986. };
  114987. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  114988. _vq_quantthresh__44c3_s_p1_0,
  114989. _vq_quantmap__44c3_s_p1_0,
  114990. 3,
  114991. 3
  114992. };
  114993. static static_codebook _44c3_s_p1_0 = {
  114994. 8, 6561,
  114995. _vq_lengthlist__44c3_s_p1_0,
  114996. 1, -535822336, 1611661312, 2, 0,
  114997. _vq_quantlist__44c3_s_p1_0,
  114998. NULL,
  114999. &_vq_auxt__44c3_s_p1_0,
  115000. NULL,
  115001. 0
  115002. };
  115003. static long _vq_quantlist__44c3_s_p2_0[] = {
  115004. 2,
  115005. 1,
  115006. 3,
  115007. 0,
  115008. 4,
  115009. };
  115010. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115011. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115012. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115013. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115014. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115015. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115020. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115021. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115022. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115023. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115028. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115029. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115030. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  115031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115036. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115037. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115038. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115050. 0,
  115051. };
  115052. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115053. -1.5, -0.5, 0.5, 1.5,
  115054. };
  115055. static long _vq_quantmap__44c3_s_p2_0[] = {
  115056. 3, 1, 0, 2, 4,
  115057. };
  115058. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115059. _vq_quantthresh__44c3_s_p2_0,
  115060. _vq_quantmap__44c3_s_p2_0,
  115061. 5,
  115062. 5
  115063. };
  115064. static static_codebook _44c3_s_p2_0 = {
  115065. 4, 625,
  115066. _vq_lengthlist__44c3_s_p2_0,
  115067. 1, -533725184, 1611661312, 3, 0,
  115068. _vq_quantlist__44c3_s_p2_0,
  115069. NULL,
  115070. &_vq_auxt__44c3_s_p2_0,
  115071. NULL,
  115072. 0
  115073. };
  115074. static long _vq_quantlist__44c3_s_p3_0[] = {
  115075. 2,
  115076. 1,
  115077. 3,
  115078. 0,
  115079. 4,
  115080. };
  115081. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115082. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115085. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115088. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115121. 0,
  115122. };
  115123. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115124. -1.5, -0.5, 0.5, 1.5,
  115125. };
  115126. static long _vq_quantmap__44c3_s_p3_0[] = {
  115127. 3, 1, 0, 2, 4,
  115128. };
  115129. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115130. _vq_quantthresh__44c3_s_p3_0,
  115131. _vq_quantmap__44c3_s_p3_0,
  115132. 5,
  115133. 5
  115134. };
  115135. static static_codebook _44c3_s_p3_0 = {
  115136. 4, 625,
  115137. _vq_lengthlist__44c3_s_p3_0,
  115138. 1, -533725184, 1611661312, 3, 0,
  115139. _vq_quantlist__44c3_s_p3_0,
  115140. NULL,
  115141. &_vq_auxt__44c3_s_p3_0,
  115142. NULL,
  115143. 0
  115144. };
  115145. static long _vq_quantlist__44c3_s_p4_0[] = {
  115146. 4,
  115147. 3,
  115148. 5,
  115149. 2,
  115150. 6,
  115151. 1,
  115152. 7,
  115153. 0,
  115154. 8,
  115155. };
  115156. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115157. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115158. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115159. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115160. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115161. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115162. 0,
  115163. };
  115164. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115165. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115166. };
  115167. static long _vq_quantmap__44c3_s_p4_0[] = {
  115168. 7, 5, 3, 1, 0, 2, 4, 6,
  115169. 8,
  115170. };
  115171. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115172. _vq_quantthresh__44c3_s_p4_0,
  115173. _vq_quantmap__44c3_s_p4_0,
  115174. 9,
  115175. 9
  115176. };
  115177. static static_codebook _44c3_s_p4_0 = {
  115178. 2, 81,
  115179. _vq_lengthlist__44c3_s_p4_0,
  115180. 1, -531628032, 1611661312, 4, 0,
  115181. _vq_quantlist__44c3_s_p4_0,
  115182. NULL,
  115183. &_vq_auxt__44c3_s_p4_0,
  115184. NULL,
  115185. 0
  115186. };
  115187. static long _vq_quantlist__44c3_s_p5_0[] = {
  115188. 4,
  115189. 3,
  115190. 5,
  115191. 2,
  115192. 6,
  115193. 1,
  115194. 7,
  115195. 0,
  115196. 8,
  115197. };
  115198. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115199. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115200. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115201. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115202. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115203. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115204. 11,
  115205. };
  115206. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115207. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115208. };
  115209. static long _vq_quantmap__44c3_s_p5_0[] = {
  115210. 7, 5, 3, 1, 0, 2, 4, 6,
  115211. 8,
  115212. };
  115213. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115214. _vq_quantthresh__44c3_s_p5_0,
  115215. _vq_quantmap__44c3_s_p5_0,
  115216. 9,
  115217. 9
  115218. };
  115219. static static_codebook _44c3_s_p5_0 = {
  115220. 2, 81,
  115221. _vq_lengthlist__44c3_s_p5_0,
  115222. 1, -531628032, 1611661312, 4, 0,
  115223. _vq_quantlist__44c3_s_p5_0,
  115224. NULL,
  115225. &_vq_auxt__44c3_s_p5_0,
  115226. NULL,
  115227. 0
  115228. };
  115229. static long _vq_quantlist__44c3_s_p6_0[] = {
  115230. 8,
  115231. 7,
  115232. 9,
  115233. 6,
  115234. 10,
  115235. 5,
  115236. 11,
  115237. 4,
  115238. 12,
  115239. 3,
  115240. 13,
  115241. 2,
  115242. 14,
  115243. 1,
  115244. 15,
  115245. 0,
  115246. 16,
  115247. };
  115248. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115249. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115250. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115251. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115252. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115253. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115254. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115255. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115256. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115257. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115258. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115259. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115260. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115261. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115262. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115263. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115264. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115265. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115266. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115267. 13,
  115268. };
  115269. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115270. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115271. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115272. };
  115273. static long _vq_quantmap__44c3_s_p6_0[] = {
  115274. 15, 13, 11, 9, 7, 5, 3, 1,
  115275. 0, 2, 4, 6, 8, 10, 12, 14,
  115276. 16,
  115277. };
  115278. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115279. _vq_quantthresh__44c3_s_p6_0,
  115280. _vq_quantmap__44c3_s_p6_0,
  115281. 17,
  115282. 17
  115283. };
  115284. static static_codebook _44c3_s_p6_0 = {
  115285. 2, 289,
  115286. _vq_lengthlist__44c3_s_p6_0,
  115287. 1, -529530880, 1611661312, 5, 0,
  115288. _vq_quantlist__44c3_s_p6_0,
  115289. NULL,
  115290. &_vq_auxt__44c3_s_p6_0,
  115291. NULL,
  115292. 0
  115293. };
  115294. static long _vq_quantlist__44c3_s_p7_0[] = {
  115295. 1,
  115296. 0,
  115297. 2,
  115298. };
  115299. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115300. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115301. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115302. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115303. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115304. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115305. 10,
  115306. };
  115307. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115308. -5.5, 5.5,
  115309. };
  115310. static long _vq_quantmap__44c3_s_p7_0[] = {
  115311. 1, 0, 2,
  115312. };
  115313. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115314. _vq_quantthresh__44c3_s_p7_0,
  115315. _vq_quantmap__44c3_s_p7_0,
  115316. 3,
  115317. 3
  115318. };
  115319. static static_codebook _44c3_s_p7_0 = {
  115320. 4, 81,
  115321. _vq_lengthlist__44c3_s_p7_0,
  115322. 1, -529137664, 1618345984, 2, 0,
  115323. _vq_quantlist__44c3_s_p7_0,
  115324. NULL,
  115325. &_vq_auxt__44c3_s_p7_0,
  115326. NULL,
  115327. 0
  115328. };
  115329. static long _vq_quantlist__44c3_s_p7_1[] = {
  115330. 5,
  115331. 4,
  115332. 6,
  115333. 3,
  115334. 7,
  115335. 2,
  115336. 8,
  115337. 1,
  115338. 9,
  115339. 0,
  115340. 10,
  115341. };
  115342. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115343. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115344. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115345. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115346. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115347. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115348. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115349. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115350. 10,10,10, 8, 8, 8, 8, 8, 8,
  115351. };
  115352. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115353. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115354. 3.5, 4.5,
  115355. };
  115356. static long _vq_quantmap__44c3_s_p7_1[] = {
  115357. 9, 7, 5, 3, 1, 0, 2, 4,
  115358. 6, 8, 10,
  115359. };
  115360. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115361. _vq_quantthresh__44c3_s_p7_1,
  115362. _vq_quantmap__44c3_s_p7_1,
  115363. 11,
  115364. 11
  115365. };
  115366. static static_codebook _44c3_s_p7_1 = {
  115367. 2, 121,
  115368. _vq_lengthlist__44c3_s_p7_1,
  115369. 1, -531365888, 1611661312, 4, 0,
  115370. _vq_quantlist__44c3_s_p7_1,
  115371. NULL,
  115372. &_vq_auxt__44c3_s_p7_1,
  115373. NULL,
  115374. 0
  115375. };
  115376. static long _vq_quantlist__44c3_s_p8_0[] = {
  115377. 6,
  115378. 5,
  115379. 7,
  115380. 4,
  115381. 8,
  115382. 3,
  115383. 9,
  115384. 2,
  115385. 10,
  115386. 1,
  115387. 11,
  115388. 0,
  115389. 12,
  115390. };
  115391. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115392. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115393. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115394. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115395. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115396. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115397. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115398. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115399. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115400. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115401. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115402. 0,13,13,12,12,13,12,14,13,
  115403. };
  115404. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115405. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115406. 12.5, 17.5, 22.5, 27.5,
  115407. };
  115408. static long _vq_quantmap__44c3_s_p8_0[] = {
  115409. 11, 9, 7, 5, 3, 1, 0, 2,
  115410. 4, 6, 8, 10, 12,
  115411. };
  115412. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115413. _vq_quantthresh__44c3_s_p8_0,
  115414. _vq_quantmap__44c3_s_p8_0,
  115415. 13,
  115416. 13
  115417. };
  115418. static static_codebook _44c3_s_p8_0 = {
  115419. 2, 169,
  115420. _vq_lengthlist__44c3_s_p8_0,
  115421. 1, -526516224, 1616117760, 4, 0,
  115422. _vq_quantlist__44c3_s_p8_0,
  115423. NULL,
  115424. &_vq_auxt__44c3_s_p8_0,
  115425. NULL,
  115426. 0
  115427. };
  115428. static long _vq_quantlist__44c3_s_p8_1[] = {
  115429. 2,
  115430. 1,
  115431. 3,
  115432. 0,
  115433. 4,
  115434. };
  115435. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115436. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115437. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115438. };
  115439. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115440. -1.5, -0.5, 0.5, 1.5,
  115441. };
  115442. static long _vq_quantmap__44c3_s_p8_1[] = {
  115443. 3, 1, 0, 2, 4,
  115444. };
  115445. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115446. _vq_quantthresh__44c3_s_p8_1,
  115447. _vq_quantmap__44c3_s_p8_1,
  115448. 5,
  115449. 5
  115450. };
  115451. static static_codebook _44c3_s_p8_1 = {
  115452. 2, 25,
  115453. _vq_lengthlist__44c3_s_p8_1,
  115454. 1, -533725184, 1611661312, 3, 0,
  115455. _vq_quantlist__44c3_s_p8_1,
  115456. NULL,
  115457. &_vq_auxt__44c3_s_p8_1,
  115458. NULL,
  115459. 0
  115460. };
  115461. static long _vq_quantlist__44c3_s_p9_0[] = {
  115462. 6,
  115463. 5,
  115464. 7,
  115465. 4,
  115466. 8,
  115467. 3,
  115468. 9,
  115469. 2,
  115470. 10,
  115471. 1,
  115472. 11,
  115473. 0,
  115474. 12,
  115475. };
  115476. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115477. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115478. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115479. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115480. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115481. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115482. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115483. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115484. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115485. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115486. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115487. 11,11,11,11,11,11,11,11,11,
  115488. };
  115489. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115490. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115491. 637.5, 892.5, 1147.5, 1402.5,
  115492. };
  115493. static long _vq_quantmap__44c3_s_p9_0[] = {
  115494. 11, 9, 7, 5, 3, 1, 0, 2,
  115495. 4, 6, 8, 10, 12,
  115496. };
  115497. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115498. _vq_quantthresh__44c3_s_p9_0,
  115499. _vq_quantmap__44c3_s_p9_0,
  115500. 13,
  115501. 13
  115502. };
  115503. static static_codebook _44c3_s_p9_0 = {
  115504. 2, 169,
  115505. _vq_lengthlist__44c3_s_p9_0,
  115506. 1, -514332672, 1627381760, 4, 0,
  115507. _vq_quantlist__44c3_s_p9_0,
  115508. NULL,
  115509. &_vq_auxt__44c3_s_p9_0,
  115510. NULL,
  115511. 0
  115512. };
  115513. static long _vq_quantlist__44c3_s_p9_1[] = {
  115514. 7,
  115515. 6,
  115516. 8,
  115517. 5,
  115518. 9,
  115519. 4,
  115520. 10,
  115521. 3,
  115522. 11,
  115523. 2,
  115524. 12,
  115525. 1,
  115526. 13,
  115527. 0,
  115528. 14,
  115529. };
  115530. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115531. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115532. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115533. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115534. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  115535. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  115536. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  115537. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  115538. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  115539. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  115540. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  115541. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  115542. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  115543. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  115544. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  115545. 15,
  115546. };
  115547. static float _vq_quantthresh__44c3_s_p9_1[] = {
  115548. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  115549. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  115550. };
  115551. static long _vq_quantmap__44c3_s_p9_1[] = {
  115552. 13, 11, 9, 7, 5, 3, 1, 0,
  115553. 2, 4, 6, 8, 10, 12, 14,
  115554. };
  115555. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  115556. _vq_quantthresh__44c3_s_p9_1,
  115557. _vq_quantmap__44c3_s_p9_1,
  115558. 15,
  115559. 15
  115560. };
  115561. static static_codebook _44c3_s_p9_1 = {
  115562. 2, 225,
  115563. _vq_lengthlist__44c3_s_p9_1,
  115564. 1, -522338304, 1620115456, 4, 0,
  115565. _vq_quantlist__44c3_s_p9_1,
  115566. NULL,
  115567. &_vq_auxt__44c3_s_p9_1,
  115568. NULL,
  115569. 0
  115570. };
  115571. static long _vq_quantlist__44c3_s_p9_2[] = {
  115572. 8,
  115573. 7,
  115574. 9,
  115575. 6,
  115576. 10,
  115577. 5,
  115578. 11,
  115579. 4,
  115580. 12,
  115581. 3,
  115582. 13,
  115583. 2,
  115584. 14,
  115585. 1,
  115586. 15,
  115587. 0,
  115588. 16,
  115589. };
  115590. static long _vq_lengthlist__44c3_s_p9_2[] = {
  115591. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115592. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  115593. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  115594. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115595. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  115596. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115597. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  115598. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  115599. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  115600. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  115601. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  115602. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  115603. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  115604. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  115605. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  115606. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  115607. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  115608. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  115609. 10,
  115610. };
  115611. static float _vq_quantthresh__44c3_s_p9_2[] = {
  115612. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115613. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115614. };
  115615. static long _vq_quantmap__44c3_s_p9_2[] = {
  115616. 15, 13, 11, 9, 7, 5, 3, 1,
  115617. 0, 2, 4, 6, 8, 10, 12, 14,
  115618. 16,
  115619. };
  115620. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  115621. _vq_quantthresh__44c3_s_p9_2,
  115622. _vq_quantmap__44c3_s_p9_2,
  115623. 17,
  115624. 17
  115625. };
  115626. static static_codebook _44c3_s_p9_2 = {
  115627. 2, 289,
  115628. _vq_lengthlist__44c3_s_p9_2,
  115629. 1, -529530880, 1611661312, 5, 0,
  115630. _vq_quantlist__44c3_s_p9_2,
  115631. NULL,
  115632. &_vq_auxt__44c3_s_p9_2,
  115633. NULL,
  115634. 0
  115635. };
  115636. static long _huff_lengthlist__44c3_s_short[] = {
  115637. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  115638. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  115639. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  115640. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  115641. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  115642. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  115643. 6, 8, 9,11,
  115644. };
  115645. static static_codebook _huff_book__44c3_s_short = {
  115646. 2, 100,
  115647. _huff_lengthlist__44c3_s_short,
  115648. 0, 0, 0, 0, 0,
  115649. NULL,
  115650. NULL,
  115651. NULL,
  115652. NULL,
  115653. 0
  115654. };
  115655. static long _huff_lengthlist__44c4_s_long[] = {
  115656. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  115657. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  115658. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  115659. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  115660. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  115661. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  115662. 9, 8, 7, 7,
  115663. };
  115664. static static_codebook _huff_book__44c4_s_long = {
  115665. 2, 100,
  115666. _huff_lengthlist__44c4_s_long,
  115667. 0, 0, 0, 0, 0,
  115668. NULL,
  115669. NULL,
  115670. NULL,
  115671. NULL,
  115672. 0
  115673. };
  115674. static long _vq_quantlist__44c4_s_p1_0[] = {
  115675. 1,
  115676. 0,
  115677. 2,
  115678. };
  115679. static long _vq_lengthlist__44c4_s_p1_0[] = {
  115680. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115681. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115686. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115691. 0, 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0,
  115726. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  115731. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  115736. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115772. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115777. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115782. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116021. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116088. 0, 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,
  116091. };
  116092. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116093. -0.5, 0.5,
  116094. };
  116095. static long _vq_quantmap__44c4_s_p1_0[] = {
  116096. 1, 0, 2,
  116097. };
  116098. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116099. _vq_quantthresh__44c4_s_p1_0,
  116100. _vq_quantmap__44c4_s_p1_0,
  116101. 3,
  116102. 3
  116103. };
  116104. static static_codebook _44c4_s_p1_0 = {
  116105. 8, 6561,
  116106. _vq_lengthlist__44c4_s_p1_0,
  116107. 1, -535822336, 1611661312, 2, 0,
  116108. _vq_quantlist__44c4_s_p1_0,
  116109. NULL,
  116110. &_vq_auxt__44c4_s_p1_0,
  116111. NULL,
  116112. 0
  116113. };
  116114. static long _vq_quantlist__44c4_s_p2_0[] = {
  116115. 2,
  116116. 1,
  116117. 3,
  116118. 0,
  116119. 4,
  116120. };
  116121. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116122. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116123. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116124. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116125. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116126. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116131. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116132. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116133. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116134. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116139. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116140. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116141. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  116142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116147. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116148. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116149. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116161. 0,
  116162. };
  116163. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116164. -1.5, -0.5, 0.5, 1.5,
  116165. };
  116166. static long _vq_quantmap__44c4_s_p2_0[] = {
  116167. 3, 1, 0, 2, 4,
  116168. };
  116169. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116170. _vq_quantthresh__44c4_s_p2_0,
  116171. _vq_quantmap__44c4_s_p2_0,
  116172. 5,
  116173. 5
  116174. };
  116175. static static_codebook _44c4_s_p2_0 = {
  116176. 4, 625,
  116177. _vq_lengthlist__44c4_s_p2_0,
  116178. 1, -533725184, 1611661312, 3, 0,
  116179. _vq_quantlist__44c4_s_p2_0,
  116180. NULL,
  116181. &_vq_auxt__44c4_s_p2_0,
  116182. NULL,
  116183. 0
  116184. };
  116185. static long _vq_quantlist__44c4_s_p3_0[] = {
  116186. 2,
  116187. 1,
  116188. 3,
  116189. 0,
  116190. 4,
  116191. };
  116192. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116193. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116196. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116199. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116232. 0,
  116233. };
  116234. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116235. -1.5, -0.5, 0.5, 1.5,
  116236. };
  116237. static long _vq_quantmap__44c4_s_p3_0[] = {
  116238. 3, 1, 0, 2, 4,
  116239. };
  116240. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116241. _vq_quantthresh__44c4_s_p3_0,
  116242. _vq_quantmap__44c4_s_p3_0,
  116243. 5,
  116244. 5
  116245. };
  116246. static static_codebook _44c4_s_p3_0 = {
  116247. 4, 625,
  116248. _vq_lengthlist__44c4_s_p3_0,
  116249. 1, -533725184, 1611661312, 3, 0,
  116250. _vq_quantlist__44c4_s_p3_0,
  116251. NULL,
  116252. &_vq_auxt__44c4_s_p3_0,
  116253. NULL,
  116254. 0
  116255. };
  116256. static long _vq_quantlist__44c4_s_p4_0[] = {
  116257. 4,
  116258. 3,
  116259. 5,
  116260. 2,
  116261. 6,
  116262. 1,
  116263. 7,
  116264. 0,
  116265. 8,
  116266. };
  116267. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116268. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116269. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116270. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116271. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116272. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116273. 0,
  116274. };
  116275. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116276. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116277. };
  116278. static long _vq_quantmap__44c4_s_p4_0[] = {
  116279. 7, 5, 3, 1, 0, 2, 4, 6,
  116280. 8,
  116281. };
  116282. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116283. _vq_quantthresh__44c4_s_p4_0,
  116284. _vq_quantmap__44c4_s_p4_0,
  116285. 9,
  116286. 9
  116287. };
  116288. static static_codebook _44c4_s_p4_0 = {
  116289. 2, 81,
  116290. _vq_lengthlist__44c4_s_p4_0,
  116291. 1, -531628032, 1611661312, 4, 0,
  116292. _vq_quantlist__44c4_s_p4_0,
  116293. NULL,
  116294. &_vq_auxt__44c4_s_p4_0,
  116295. NULL,
  116296. 0
  116297. };
  116298. static long _vq_quantlist__44c4_s_p5_0[] = {
  116299. 4,
  116300. 3,
  116301. 5,
  116302. 2,
  116303. 6,
  116304. 1,
  116305. 7,
  116306. 0,
  116307. 8,
  116308. };
  116309. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116310. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116311. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116312. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116313. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116314. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116315. 10,
  116316. };
  116317. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116318. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116319. };
  116320. static long _vq_quantmap__44c4_s_p5_0[] = {
  116321. 7, 5, 3, 1, 0, 2, 4, 6,
  116322. 8,
  116323. };
  116324. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116325. _vq_quantthresh__44c4_s_p5_0,
  116326. _vq_quantmap__44c4_s_p5_0,
  116327. 9,
  116328. 9
  116329. };
  116330. static static_codebook _44c4_s_p5_0 = {
  116331. 2, 81,
  116332. _vq_lengthlist__44c4_s_p5_0,
  116333. 1, -531628032, 1611661312, 4, 0,
  116334. _vq_quantlist__44c4_s_p5_0,
  116335. NULL,
  116336. &_vq_auxt__44c4_s_p5_0,
  116337. NULL,
  116338. 0
  116339. };
  116340. static long _vq_quantlist__44c4_s_p6_0[] = {
  116341. 8,
  116342. 7,
  116343. 9,
  116344. 6,
  116345. 10,
  116346. 5,
  116347. 11,
  116348. 4,
  116349. 12,
  116350. 3,
  116351. 13,
  116352. 2,
  116353. 14,
  116354. 1,
  116355. 15,
  116356. 0,
  116357. 16,
  116358. };
  116359. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116360. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116361. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116362. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116363. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116364. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116365. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116366. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116367. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116368. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116369. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116370. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116371. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116372. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116373. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116374. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116375. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116376. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116377. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116378. 13,
  116379. };
  116380. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116381. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116382. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116383. };
  116384. static long _vq_quantmap__44c4_s_p6_0[] = {
  116385. 15, 13, 11, 9, 7, 5, 3, 1,
  116386. 0, 2, 4, 6, 8, 10, 12, 14,
  116387. 16,
  116388. };
  116389. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116390. _vq_quantthresh__44c4_s_p6_0,
  116391. _vq_quantmap__44c4_s_p6_0,
  116392. 17,
  116393. 17
  116394. };
  116395. static static_codebook _44c4_s_p6_0 = {
  116396. 2, 289,
  116397. _vq_lengthlist__44c4_s_p6_0,
  116398. 1, -529530880, 1611661312, 5, 0,
  116399. _vq_quantlist__44c4_s_p6_0,
  116400. NULL,
  116401. &_vq_auxt__44c4_s_p6_0,
  116402. NULL,
  116403. 0
  116404. };
  116405. static long _vq_quantlist__44c4_s_p7_0[] = {
  116406. 1,
  116407. 0,
  116408. 2,
  116409. };
  116410. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116411. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116412. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116413. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116414. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116415. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116416. 10,
  116417. };
  116418. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116419. -5.5, 5.5,
  116420. };
  116421. static long _vq_quantmap__44c4_s_p7_0[] = {
  116422. 1, 0, 2,
  116423. };
  116424. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116425. _vq_quantthresh__44c4_s_p7_0,
  116426. _vq_quantmap__44c4_s_p7_0,
  116427. 3,
  116428. 3
  116429. };
  116430. static static_codebook _44c4_s_p7_0 = {
  116431. 4, 81,
  116432. _vq_lengthlist__44c4_s_p7_0,
  116433. 1, -529137664, 1618345984, 2, 0,
  116434. _vq_quantlist__44c4_s_p7_0,
  116435. NULL,
  116436. &_vq_auxt__44c4_s_p7_0,
  116437. NULL,
  116438. 0
  116439. };
  116440. static long _vq_quantlist__44c4_s_p7_1[] = {
  116441. 5,
  116442. 4,
  116443. 6,
  116444. 3,
  116445. 7,
  116446. 2,
  116447. 8,
  116448. 1,
  116449. 9,
  116450. 0,
  116451. 10,
  116452. };
  116453. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116454. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116455. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116456. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116457. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116458. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116459. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116460. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116461. 10,10,10, 8, 8, 8, 8, 9, 9,
  116462. };
  116463. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116464. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116465. 3.5, 4.5,
  116466. };
  116467. static long _vq_quantmap__44c4_s_p7_1[] = {
  116468. 9, 7, 5, 3, 1, 0, 2, 4,
  116469. 6, 8, 10,
  116470. };
  116471. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116472. _vq_quantthresh__44c4_s_p7_1,
  116473. _vq_quantmap__44c4_s_p7_1,
  116474. 11,
  116475. 11
  116476. };
  116477. static static_codebook _44c4_s_p7_1 = {
  116478. 2, 121,
  116479. _vq_lengthlist__44c4_s_p7_1,
  116480. 1, -531365888, 1611661312, 4, 0,
  116481. _vq_quantlist__44c4_s_p7_1,
  116482. NULL,
  116483. &_vq_auxt__44c4_s_p7_1,
  116484. NULL,
  116485. 0
  116486. };
  116487. static long _vq_quantlist__44c4_s_p8_0[] = {
  116488. 6,
  116489. 5,
  116490. 7,
  116491. 4,
  116492. 8,
  116493. 3,
  116494. 9,
  116495. 2,
  116496. 10,
  116497. 1,
  116498. 11,
  116499. 0,
  116500. 12,
  116501. };
  116502. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116503. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116504. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116505. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116506. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116507. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116508. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116509. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116510. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116511. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116512. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116513. 0,13,12,12,12,12,12,13,13,
  116514. };
  116515. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116516. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116517. 12.5, 17.5, 22.5, 27.5,
  116518. };
  116519. static long _vq_quantmap__44c4_s_p8_0[] = {
  116520. 11, 9, 7, 5, 3, 1, 0, 2,
  116521. 4, 6, 8, 10, 12,
  116522. };
  116523. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116524. _vq_quantthresh__44c4_s_p8_0,
  116525. _vq_quantmap__44c4_s_p8_0,
  116526. 13,
  116527. 13
  116528. };
  116529. static static_codebook _44c4_s_p8_0 = {
  116530. 2, 169,
  116531. _vq_lengthlist__44c4_s_p8_0,
  116532. 1, -526516224, 1616117760, 4, 0,
  116533. _vq_quantlist__44c4_s_p8_0,
  116534. NULL,
  116535. &_vq_auxt__44c4_s_p8_0,
  116536. NULL,
  116537. 0
  116538. };
  116539. static long _vq_quantlist__44c4_s_p8_1[] = {
  116540. 2,
  116541. 1,
  116542. 3,
  116543. 0,
  116544. 4,
  116545. };
  116546. static long _vq_lengthlist__44c4_s_p8_1[] = {
  116547. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  116548. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116549. };
  116550. static float _vq_quantthresh__44c4_s_p8_1[] = {
  116551. -1.5, -0.5, 0.5, 1.5,
  116552. };
  116553. static long _vq_quantmap__44c4_s_p8_1[] = {
  116554. 3, 1, 0, 2, 4,
  116555. };
  116556. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  116557. _vq_quantthresh__44c4_s_p8_1,
  116558. _vq_quantmap__44c4_s_p8_1,
  116559. 5,
  116560. 5
  116561. };
  116562. static static_codebook _44c4_s_p8_1 = {
  116563. 2, 25,
  116564. _vq_lengthlist__44c4_s_p8_1,
  116565. 1, -533725184, 1611661312, 3, 0,
  116566. _vq_quantlist__44c4_s_p8_1,
  116567. NULL,
  116568. &_vq_auxt__44c4_s_p8_1,
  116569. NULL,
  116570. 0
  116571. };
  116572. static long _vq_quantlist__44c4_s_p9_0[] = {
  116573. 6,
  116574. 5,
  116575. 7,
  116576. 4,
  116577. 8,
  116578. 3,
  116579. 9,
  116580. 2,
  116581. 10,
  116582. 1,
  116583. 11,
  116584. 0,
  116585. 12,
  116586. };
  116587. static long _vq_lengthlist__44c4_s_p9_0[] = {
  116588. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  116589. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  116590. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116591. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116592. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116593. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116594. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116595. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116596. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116597. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116598. 12,12,12,12,12,12,12,12,12,
  116599. };
  116600. static float _vq_quantthresh__44c4_s_p9_0[] = {
  116601. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  116602. 787.5, 1102.5, 1417.5, 1732.5,
  116603. };
  116604. static long _vq_quantmap__44c4_s_p9_0[] = {
  116605. 11, 9, 7, 5, 3, 1, 0, 2,
  116606. 4, 6, 8, 10, 12,
  116607. };
  116608. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  116609. _vq_quantthresh__44c4_s_p9_0,
  116610. _vq_quantmap__44c4_s_p9_0,
  116611. 13,
  116612. 13
  116613. };
  116614. static static_codebook _44c4_s_p9_0 = {
  116615. 2, 169,
  116616. _vq_lengthlist__44c4_s_p9_0,
  116617. 1, -513964032, 1628680192, 4, 0,
  116618. _vq_quantlist__44c4_s_p9_0,
  116619. NULL,
  116620. &_vq_auxt__44c4_s_p9_0,
  116621. NULL,
  116622. 0
  116623. };
  116624. static long _vq_quantlist__44c4_s_p9_1[] = {
  116625. 7,
  116626. 6,
  116627. 8,
  116628. 5,
  116629. 9,
  116630. 4,
  116631. 10,
  116632. 3,
  116633. 11,
  116634. 2,
  116635. 12,
  116636. 1,
  116637. 13,
  116638. 0,
  116639. 14,
  116640. };
  116641. static long _vq_lengthlist__44c4_s_p9_1[] = {
  116642. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  116643. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  116644. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  116645. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  116646. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  116647. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  116648. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  116649. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  116650. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  116651. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  116652. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  116653. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  116654. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  116655. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  116656. 15,
  116657. };
  116658. static float _vq_quantthresh__44c4_s_p9_1[] = {
  116659. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  116660. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  116661. };
  116662. static long _vq_quantmap__44c4_s_p9_1[] = {
  116663. 13, 11, 9, 7, 5, 3, 1, 0,
  116664. 2, 4, 6, 8, 10, 12, 14,
  116665. };
  116666. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  116667. _vq_quantthresh__44c4_s_p9_1,
  116668. _vq_quantmap__44c4_s_p9_1,
  116669. 15,
  116670. 15
  116671. };
  116672. static static_codebook _44c4_s_p9_1 = {
  116673. 2, 225,
  116674. _vq_lengthlist__44c4_s_p9_1,
  116675. 1, -520986624, 1620377600, 4, 0,
  116676. _vq_quantlist__44c4_s_p9_1,
  116677. NULL,
  116678. &_vq_auxt__44c4_s_p9_1,
  116679. NULL,
  116680. 0
  116681. };
  116682. static long _vq_quantlist__44c4_s_p9_2[] = {
  116683. 10,
  116684. 9,
  116685. 11,
  116686. 8,
  116687. 12,
  116688. 7,
  116689. 13,
  116690. 6,
  116691. 14,
  116692. 5,
  116693. 15,
  116694. 4,
  116695. 16,
  116696. 3,
  116697. 17,
  116698. 2,
  116699. 18,
  116700. 1,
  116701. 19,
  116702. 0,
  116703. 20,
  116704. };
  116705. static long _vq_lengthlist__44c4_s_p9_2[] = {
  116706. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  116707. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  116708. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  116709. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  116710. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  116711. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  116712. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  116713. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  116714. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  116715. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  116716. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  116717. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  116718. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  116719. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  116720. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  116721. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  116722. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  116723. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  116724. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  116725. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  116726. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  116727. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  116728. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  116729. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  116730. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  116731. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  116732. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  116733. 10,10,10,10,10,10,10,10,10,
  116734. };
  116735. static float _vq_quantthresh__44c4_s_p9_2[] = {
  116736. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  116737. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  116738. 6.5, 7.5, 8.5, 9.5,
  116739. };
  116740. static long _vq_quantmap__44c4_s_p9_2[] = {
  116741. 19, 17, 15, 13, 11, 9, 7, 5,
  116742. 3, 1, 0, 2, 4, 6, 8, 10,
  116743. 12, 14, 16, 18, 20,
  116744. };
  116745. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  116746. _vq_quantthresh__44c4_s_p9_2,
  116747. _vq_quantmap__44c4_s_p9_2,
  116748. 21,
  116749. 21
  116750. };
  116751. static static_codebook _44c4_s_p9_2 = {
  116752. 2, 441,
  116753. _vq_lengthlist__44c4_s_p9_2,
  116754. 1, -529268736, 1611661312, 5, 0,
  116755. _vq_quantlist__44c4_s_p9_2,
  116756. NULL,
  116757. &_vq_auxt__44c4_s_p9_2,
  116758. NULL,
  116759. 0
  116760. };
  116761. static long _huff_lengthlist__44c4_s_short[] = {
  116762. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  116763. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  116764. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  116765. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  116766. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  116767. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  116768. 7, 9,12,17,
  116769. };
  116770. static static_codebook _huff_book__44c4_s_short = {
  116771. 2, 100,
  116772. _huff_lengthlist__44c4_s_short,
  116773. 0, 0, 0, 0, 0,
  116774. NULL,
  116775. NULL,
  116776. NULL,
  116777. NULL,
  116778. 0
  116779. };
  116780. static long _huff_lengthlist__44c5_s_long[] = {
  116781. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  116782. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  116783. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  116784. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  116785. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  116786. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  116787. 9, 8, 7, 7,
  116788. };
  116789. static static_codebook _huff_book__44c5_s_long = {
  116790. 2, 100,
  116791. _huff_lengthlist__44c5_s_long,
  116792. 0, 0, 0, 0, 0,
  116793. NULL,
  116794. NULL,
  116795. NULL,
  116796. NULL,
  116797. 0
  116798. };
  116799. static long _vq_quantlist__44c5_s_p1_0[] = {
  116800. 1,
  116801. 0,
  116802. 2,
  116803. };
  116804. static long _vq_lengthlist__44c5_s_p1_0[] = {
  116805. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116806. 0, 0, 4, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116811. 0, 0, 0, 7, 8, 9, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  116816. 0, 0, 0, 0, 7, 9, 9, 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, 4, 7, 7, 0, 0, 0, 0,
  116851. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  116856. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  116861. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116897. 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  116902. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  116907. 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117146. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117213. 0, 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,
  117216. };
  117217. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117218. -0.5, 0.5,
  117219. };
  117220. static long _vq_quantmap__44c5_s_p1_0[] = {
  117221. 1, 0, 2,
  117222. };
  117223. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117224. _vq_quantthresh__44c5_s_p1_0,
  117225. _vq_quantmap__44c5_s_p1_0,
  117226. 3,
  117227. 3
  117228. };
  117229. static static_codebook _44c5_s_p1_0 = {
  117230. 8, 6561,
  117231. _vq_lengthlist__44c5_s_p1_0,
  117232. 1, -535822336, 1611661312, 2, 0,
  117233. _vq_quantlist__44c5_s_p1_0,
  117234. NULL,
  117235. &_vq_auxt__44c5_s_p1_0,
  117236. NULL,
  117237. 0
  117238. };
  117239. static long _vq_quantlist__44c5_s_p2_0[] = {
  117240. 2,
  117241. 1,
  117242. 3,
  117243. 0,
  117244. 4,
  117245. };
  117246. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117247. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117248. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117249. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117250. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117251. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117256. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117257. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117258. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117259. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117264. 0, 0, 0, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117265. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117266. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  117267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117272. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117273. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117274. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117286. 0,
  117287. };
  117288. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117289. -1.5, -0.5, 0.5, 1.5,
  117290. };
  117291. static long _vq_quantmap__44c5_s_p2_0[] = {
  117292. 3, 1, 0, 2, 4,
  117293. };
  117294. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117295. _vq_quantthresh__44c5_s_p2_0,
  117296. _vq_quantmap__44c5_s_p2_0,
  117297. 5,
  117298. 5
  117299. };
  117300. static static_codebook _44c5_s_p2_0 = {
  117301. 4, 625,
  117302. _vq_lengthlist__44c5_s_p2_0,
  117303. 1, -533725184, 1611661312, 3, 0,
  117304. _vq_quantlist__44c5_s_p2_0,
  117305. NULL,
  117306. &_vq_auxt__44c5_s_p2_0,
  117307. NULL,
  117308. 0
  117309. };
  117310. static long _vq_quantlist__44c5_s_p3_0[] = {
  117311. 2,
  117312. 1,
  117313. 3,
  117314. 0,
  117315. 4,
  117316. };
  117317. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117318. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117321. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117324. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  117325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117357. 0,
  117358. };
  117359. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117360. -1.5, -0.5, 0.5, 1.5,
  117361. };
  117362. static long _vq_quantmap__44c5_s_p3_0[] = {
  117363. 3, 1, 0, 2, 4,
  117364. };
  117365. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117366. _vq_quantthresh__44c5_s_p3_0,
  117367. _vq_quantmap__44c5_s_p3_0,
  117368. 5,
  117369. 5
  117370. };
  117371. static static_codebook _44c5_s_p3_0 = {
  117372. 4, 625,
  117373. _vq_lengthlist__44c5_s_p3_0,
  117374. 1, -533725184, 1611661312, 3, 0,
  117375. _vq_quantlist__44c5_s_p3_0,
  117376. NULL,
  117377. &_vq_auxt__44c5_s_p3_0,
  117378. NULL,
  117379. 0
  117380. };
  117381. static long _vq_quantlist__44c5_s_p4_0[] = {
  117382. 4,
  117383. 3,
  117384. 5,
  117385. 2,
  117386. 6,
  117387. 1,
  117388. 7,
  117389. 0,
  117390. 8,
  117391. };
  117392. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117393. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117394. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117395. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117396. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117397. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117398. 0,
  117399. };
  117400. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117401. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117402. };
  117403. static long _vq_quantmap__44c5_s_p4_0[] = {
  117404. 7, 5, 3, 1, 0, 2, 4, 6,
  117405. 8,
  117406. };
  117407. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117408. _vq_quantthresh__44c5_s_p4_0,
  117409. _vq_quantmap__44c5_s_p4_0,
  117410. 9,
  117411. 9
  117412. };
  117413. static static_codebook _44c5_s_p4_0 = {
  117414. 2, 81,
  117415. _vq_lengthlist__44c5_s_p4_0,
  117416. 1, -531628032, 1611661312, 4, 0,
  117417. _vq_quantlist__44c5_s_p4_0,
  117418. NULL,
  117419. &_vq_auxt__44c5_s_p4_0,
  117420. NULL,
  117421. 0
  117422. };
  117423. static long _vq_quantlist__44c5_s_p5_0[] = {
  117424. 4,
  117425. 3,
  117426. 5,
  117427. 2,
  117428. 6,
  117429. 1,
  117430. 7,
  117431. 0,
  117432. 8,
  117433. };
  117434. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117435. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117436. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117437. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117438. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117439. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117440. 10,
  117441. };
  117442. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117443. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117444. };
  117445. static long _vq_quantmap__44c5_s_p5_0[] = {
  117446. 7, 5, 3, 1, 0, 2, 4, 6,
  117447. 8,
  117448. };
  117449. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117450. _vq_quantthresh__44c5_s_p5_0,
  117451. _vq_quantmap__44c5_s_p5_0,
  117452. 9,
  117453. 9
  117454. };
  117455. static static_codebook _44c5_s_p5_0 = {
  117456. 2, 81,
  117457. _vq_lengthlist__44c5_s_p5_0,
  117458. 1, -531628032, 1611661312, 4, 0,
  117459. _vq_quantlist__44c5_s_p5_0,
  117460. NULL,
  117461. &_vq_auxt__44c5_s_p5_0,
  117462. NULL,
  117463. 0
  117464. };
  117465. static long _vq_quantlist__44c5_s_p6_0[] = {
  117466. 8,
  117467. 7,
  117468. 9,
  117469. 6,
  117470. 10,
  117471. 5,
  117472. 11,
  117473. 4,
  117474. 12,
  117475. 3,
  117476. 13,
  117477. 2,
  117478. 14,
  117479. 1,
  117480. 15,
  117481. 0,
  117482. 16,
  117483. };
  117484. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117485. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117486. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117487. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117488. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117489. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117490. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117491. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117492. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117493. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117494. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117495. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117496. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117497. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117498. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117499. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117500. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117501. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117502. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117503. 13,
  117504. };
  117505. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117506. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117507. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117508. };
  117509. static long _vq_quantmap__44c5_s_p6_0[] = {
  117510. 15, 13, 11, 9, 7, 5, 3, 1,
  117511. 0, 2, 4, 6, 8, 10, 12, 14,
  117512. 16,
  117513. };
  117514. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117515. _vq_quantthresh__44c5_s_p6_0,
  117516. _vq_quantmap__44c5_s_p6_0,
  117517. 17,
  117518. 17
  117519. };
  117520. static static_codebook _44c5_s_p6_0 = {
  117521. 2, 289,
  117522. _vq_lengthlist__44c5_s_p6_0,
  117523. 1, -529530880, 1611661312, 5, 0,
  117524. _vq_quantlist__44c5_s_p6_0,
  117525. NULL,
  117526. &_vq_auxt__44c5_s_p6_0,
  117527. NULL,
  117528. 0
  117529. };
  117530. static long _vq_quantlist__44c5_s_p7_0[] = {
  117531. 1,
  117532. 0,
  117533. 2,
  117534. };
  117535. static long _vq_lengthlist__44c5_s_p7_0[] = {
  117536. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117537. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117538. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117539. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117540. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117541. 10,
  117542. };
  117543. static float _vq_quantthresh__44c5_s_p7_0[] = {
  117544. -5.5, 5.5,
  117545. };
  117546. static long _vq_quantmap__44c5_s_p7_0[] = {
  117547. 1, 0, 2,
  117548. };
  117549. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  117550. _vq_quantthresh__44c5_s_p7_0,
  117551. _vq_quantmap__44c5_s_p7_0,
  117552. 3,
  117553. 3
  117554. };
  117555. static static_codebook _44c5_s_p7_0 = {
  117556. 4, 81,
  117557. _vq_lengthlist__44c5_s_p7_0,
  117558. 1, -529137664, 1618345984, 2, 0,
  117559. _vq_quantlist__44c5_s_p7_0,
  117560. NULL,
  117561. &_vq_auxt__44c5_s_p7_0,
  117562. NULL,
  117563. 0
  117564. };
  117565. static long _vq_quantlist__44c5_s_p7_1[] = {
  117566. 5,
  117567. 4,
  117568. 6,
  117569. 3,
  117570. 7,
  117571. 2,
  117572. 8,
  117573. 1,
  117574. 9,
  117575. 0,
  117576. 10,
  117577. };
  117578. static long _vq_lengthlist__44c5_s_p7_1[] = {
  117579. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  117580. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117581. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117582. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  117583. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117584. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  117585. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  117586. 10,10,10, 8, 8, 8, 8, 8, 8,
  117587. };
  117588. static float _vq_quantthresh__44c5_s_p7_1[] = {
  117589. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117590. 3.5, 4.5,
  117591. };
  117592. static long _vq_quantmap__44c5_s_p7_1[] = {
  117593. 9, 7, 5, 3, 1, 0, 2, 4,
  117594. 6, 8, 10,
  117595. };
  117596. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  117597. _vq_quantthresh__44c5_s_p7_1,
  117598. _vq_quantmap__44c5_s_p7_1,
  117599. 11,
  117600. 11
  117601. };
  117602. static static_codebook _44c5_s_p7_1 = {
  117603. 2, 121,
  117604. _vq_lengthlist__44c5_s_p7_1,
  117605. 1, -531365888, 1611661312, 4, 0,
  117606. _vq_quantlist__44c5_s_p7_1,
  117607. NULL,
  117608. &_vq_auxt__44c5_s_p7_1,
  117609. NULL,
  117610. 0
  117611. };
  117612. static long _vq_quantlist__44c5_s_p8_0[] = {
  117613. 6,
  117614. 5,
  117615. 7,
  117616. 4,
  117617. 8,
  117618. 3,
  117619. 9,
  117620. 2,
  117621. 10,
  117622. 1,
  117623. 11,
  117624. 0,
  117625. 12,
  117626. };
  117627. static long _vq_lengthlist__44c5_s_p8_0[] = {
  117628. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117629. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  117630. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117631. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117632. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  117633. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  117634. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  117635. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117636. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  117637. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117638. 0,12,12,12,12,12,12,13,13,
  117639. };
  117640. static float _vq_quantthresh__44c5_s_p8_0[] = {
  117641. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117642. 12.5, 17.5, 22.5, 27.5,
  117643. };
  117644. static long _vq_quantmap__44c5_s_p8_0[] = {
  117645. 11, 9, 7, 5, 3, 1, 0, 2,
  117646. 4, 6, 8, 10, 12,
  117647. };
  117648. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  117649. _vq_quantthresh__44c5_s_p8_0,
  117650. _vq_quantmap__44c5_s_p8_0,
  117651. 13,
  117652. 13
  117653. };
  117654. static static_codebook _44c5_s_p8_0 = {
  117655. 2, 169,
  117656. _vq_lengthlist__44c5_s_p8_0,
  117657. 1, -526516224, 1616117760, 4, 0,
  117658. _vq_quantlist__44c5_s_p8_0,
  117659. NULL,
  117660. &_vq_auxt__44c5_s_p8_0,
  117661. NULL,
  117662. 0
  117663. };
  117664. static long _vq_quantlist__44c5_s_p8_1[] = {
  117665. 2,
  117666. 1,
  117667. 3,
  117668. 0,
  117669. 4,
  117670. };
  117671. static long _vq_lengthlist__44c5_s_p8_1[] = {
  117672. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  117673. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117674. };
  117675. static float _vq_quantthresh__44c5_s_p8_1[] = {
  117676. -1.5, -0.5, 0.5, 1.5,
  117677. };
  117678. static long _vq_quantmap__44c5_s_p8_1[] = {
  117679. 3, 1, 0, 2, 4,
  117680. };
  117681. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  117682. _vq_quantthresh__44c5_s_p8_1,
  117683. _vq_quantmap__44c5_s_p8_1,
  117684. 5,
  117685. 5
  117686. };
  117687. static static_codebook _44c5_s_p8_1 = {
  117688. 2, 25,
  117689. _vq_lengthlist__44c5_s_p8_1,
  117690. 1, -533725184, 1611661312, 3, 0,
  117691. _vq_quantlist__44c5_s_p8_1,
  117692. NULL,
  117693. &_vq_auxt__44c5_s_p8_1,
  117694. NULL,
  117695. 0
  117696. };
  117697. static long _vq_quantlist__44c5_s_p9_0[] = {
  117698. 7,
  117699. 6,
  117700. 8,
  117701. 5,
  117702. 9,
  117703. 4,
  117704. 10,
  117705. 3,
  117706. 11,
  117707. 2,
  117708. 12,
  117709. 1,
  117710. 13,
  117711. 0,
  117712. 14,
  117713. };
  117714. static long _vq_lengthlist__44c5_s_p9_0[] = {
  117715. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  117716. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  117717. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117718. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117719. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117720. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117721. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117722. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117723. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117724. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117725. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117726. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117727. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117728. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  117729. 12,
  117730. };
  117731. static float _vq_quantthresh__44c5_s_p9_0[] = {
  117732. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  117733. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  117734. };
  117735. static long _vq_quantmap__44c5_s_p9_0[] = {
  117736. 13, 11, 9, 7, 5, 3, 1, 0,
  117737. 2, 4, 6, 8, 10, 12, 14,
  117738. };
  117739. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  117740. _vq_quantthresh__44c5_s_p9_0,
  117741. _vq_quantmap__44c5_s_p9_0,
  117742. 15,
  117743. 15
  117744. };
  117745. static static_codebook _44c5_s_p9_0 = {
  117746. 2, 225,
  117747. _vq_lengthlist__44c5_s_p9_0,
  117748. 1, -512522752, 1628852224, 4, 0,
  117749. _vq_quantlist__44c5_s_p9_0,
  117750. NULL,
  117751. &_vq_auxt__44c5_s_p9_0,
  117752. NULL,
  117753. 0
  117754. };
  117755. static long _vq_quantlist__44c5_s_p9_1[] = {
  117756. 8,
  117757. 7,
  117758. 9,
  117759. 6,
  117760. 10,
  117761. 5,
  117762. 11,
  117763. 4,
  117764. 12,
  117765. 3,
  117766. 13,
  117767. 2,
  117768. 14,
  117769. 1,
  117770. 15,
  117771. 0,
  117772. 16,
  117773. };
  117774. static long _vq_lengthlist__44c5_s_p9_1[] = {
  117775. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  117776. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  117777. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  117778. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  117779. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  117780. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  117781. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  117782. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  117783. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  117784. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  117785. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  117786. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  117787. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  117788. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  117789. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  117790. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  117791. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  117792. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  117793. 15,
  117794. };
  117795. static float _vq_quantthresh__44c5_s_p9_1[] = {
  117796. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  117797. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  117798. };
  117799. static long _vq_quantmap__44c5_s_p9_1[] = {
  117800. 15, 13, 11, 9, 7, 5, 3, 1,
  117801. 0, 2, 4, 6, 8, 10, 12, 14,
  117802. 16,
  117803. };
  117804. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  117805. _vq_quantthresh__44c5_s_p9_1,
  117806. _vq_quantmap__44c5_s_p9_1,
  117807. 17,
  117808. 17
  117809. };
  117810. static static_codebook _44c5_s_p9_1 = {
  117811. 2, 289,
  117812. _vq_lengthlist__44c5_s_p9_1,
  117813. 1, -520814592, 1620377600, 5, 0,
  117814. _vq_quantlist__44c5_s_p9_1,
  117815. NULL,
  117816. &_vq_auxt__44c5_s_p9_1,
  117817. NULL,
  117818. 0
  117819. };
  117820. static long _vq_quantlist__44c5_s_p9_2[] = {
  117821. 10,
  117822. 9,
  117823. 11,
  117824. 8,
  117825. 12,
  117826. 7,
  117827. 13,
  117828. 6,
  117829. 14,
  117830. 5,
  117831. 15,
  117832. 4,
  117833. 16,
  117834. 3,
  117835. 17,
  117836. 2,
  117837. 18,
  117838. 1,
  117839. 19,
  117840. 0,
  117841. 20,
  117842. };
  117843. static long _vq_lengthlist__44c5_s_p9_2[] = {
  117844. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117845. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  117846. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  117847. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  117848. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  117849. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  117850. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  117851. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  117852. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  117853. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  117854. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117855. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  117856. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  117857. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  117858. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  117859. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  117860. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117861. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117862. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  117863. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  117864. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117865. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117866. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  117867. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  117868. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  117869. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117870. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  117871. 10,10,10,10,10,10,10,10,10,
  117872. };
  117873. static float _vq_quantthresh__44c5_s_p9_2[] = {
  117874. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117875. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117876. 6.5, 7.5, 8.5, 9.5,
  117877. };
  117878. static long _vq_quantmap__44c5_s_p9_2[] = {
  117879. 19, 17, 15, 13, 11, 9, 7, 5,
  117880. 3, 1, 0, 2, 4, 6, 8, 10,
  117881. 12, 14, 16, 18, 20,
  117882. };
  117883. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  117884. _vq_quantthresh__44c5_s_p9_2,
  117885. _vq_quantmap__44c5_s_p9_2,
  117886. 21,
  117887. 21
  117888. };
  117889. static static_codebook _44c5_s_p9_2 = {
  117890. 2, 441,
  117891. _vq_lengthlist__44c5_s_p9_2,
  117892. 1, -529268736, 1611661312, 5, 0,
  117893. _vq_quantlist__44c5_s_p9_2,
  117894. NULL,
  117895. &_vq_auxt__44c5_s_p9_2,
  117896. NULL,
  117897. 0
  117898. };
  117899. static long _huff_lengthlist__44c5_s_short[] = {
  117900. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  117901. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  117902. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  117903. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  117904. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  117905. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  117906. 6, 8,11,16,
  117907. };
  117908. static static_codebook _huff_book__44c5_s_short = {
  117909. 2, 100,
  117910. _huff_lengthlist__44c5_s_short,
  117911. 0, 0, 0, 0, 0,
  117912. NULL,
  117913. NULL,
  117914. NULL,
  117915. NULL,
  117916. 0
  117917. };
  117918. static long _huff_lengthlist__44c6_s_long[] = {
  117919. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  117920. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  117921. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  117922. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  117923. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  117924. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  117925. 11,10,10,12,
  117926. };
  117927. static static_codebook _huff_book__44c6_s_long = {
  117928. 2, 100,
  117929. _huff_lengthlist__44c6_s_long,
  117930. 0, 0, 0, 0, 0,
  117931. NULL,
  117932. NULL,
  117933. NULL,
  117934. NULL,
  117935. 0
  117936. };
  117937. static long _vq_quantlist__44c6_s_p1_0[] = {
  117938. 1,
  117939. 0,
  117940. 2,
  117941. };
  117942. static long _vq_lengthlist__44c6_s_p1_0[] = {
  117943. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  117944. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  117945. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  117946. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  117947. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  117948. 8,
  117949. };
  117950. static float _vq_quantthresh__44c6_s_p1_0[] = {
  117951. -0.5, 0.5,
  117952. };
  117953. static long _vq_quantmap__44c6_s_p1_0[] = {
  117954. 1, 0, 2,
  117955. };
  117956. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  117957. _vq_quantthresh__44c6_s_p1_0,
  117958. _vq_quantmap__44c6_s_p1_0,
  117959. 3,
  117960. 3
  117961. };
  117962. static static_codebook _44c6_s_p1_0 = {
  117963. 4, 81,
  117964. _vq_lengthlist__44c6_s_p1_0,
  117965. 1, -535822336, 1611661312, 2, 0,
  117966. _vq_quantlist__44c6_s_p1_0,
  117967. NULL,
  117968. &_vq_auxt__44c6_s_p1_0,
  117969. NULL,
  117970. 0
  117971. };
  117972. static long _vq_quantlist__44c6_s_p2_0[] = {
  117973. 2,
  117974. 1,
  117975. 3,
  117976. 0,
  117977. 4,
  117978. };
  117979. static long _vq_lengthlist__44c6_s_p2_0[] = {
  117980. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  117981. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  117982. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  117983. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  117984. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  117985. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  117986. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  117987. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  117988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117989. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  117990. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  117991. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  117992. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  117993. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  117994. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  117995. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  117996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117997. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  117998. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  117999. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  118000. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  118001. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  118002. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118003. 13,13, 0, 0, 0,13,13, 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. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  118006. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118007. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118008. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  118009. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118010. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118011. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118016. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118017. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118018. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118019. 13,
  118020. };
  118021. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118022. -1.5, -0.5, 0.5, 1.5,
  118023. };
  118024. static long _vq_quantmap__44c6_s_p2_0[] = {
  118025. 3, 1, 0, 2, 4,
  118026. };
  118027. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118028. _vq_quantthresh__44c6_s_p2_0,
  118029. _vq_quantmap__44c6_s_p2_0,
  118030. 5,
  118031. 5
  118032. };
  118033. static static_codebook _44c6_s_p2_0 = {
  118034. 4, 625,
  118035. _vq_lengthlist__44c6_s_p2_0,
  118036. 1, -533725184, 1611661312, 3, 0,
  118037. _vq_quantlist__44c6_s_p2_0,
  118038. NULL,
  118039. &_vq_auxt__44c6_s_p2_0,
  118040. NULL,
  118041. 0
  118042. };
  118043. static long _vq_quantlist__44c6_s_p3_0[] = {
  118044. 4,
  118045. 3,
  118046. 5,
  118047. 2,
  118048. 6,
  118049. 1,
  118050. 7,
  118051. 0,
  118052. 8,
  118053. };
  118054. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118055. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118056. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118057. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118058. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118060. 0,
  118061. };
  118062. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118063. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118064. };
  118065. static long _vq_quantmap__44c6_s_p3_0[] = {
  118066. 7, 5, 3, 1, 0, 2, 4, 6,
  118067. 8,
  118068. };
  118069. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118070. _vq_quantthresh__44c6_s_p3_0,
  118071. _vq_quantmap__44c6_s_p3_0,
  118072. 9,
  118073. 9
  118074. };
  118075. static static_codebook _44c6_s_p3_0 = {
  118076. 2, 81,
  118077. _vq_lengthlist__44c6_s_p3_0,
  118078. 1, -531628032, 1611661312, 4, 0,
  118079. _vq_quantlist__44c6_s_p3_0,
  118080. NULL,
  118081. &_vq_auxt__44c6_s_p3_0,
  118082. NULL,
  118083. 0
  118084. };
  118085. static long _vq_quantlist__44c6_s_p4_0[] = {
  118086. 8,
  118087. 7,
  118088. 9,
  118089. 6,
  118090. 10,
  118091. 5,
  118092. 11,
  118093. 4,
  118094. 12,
  118095. 3,
  118096. 13,
  118097. 2,
  118098. 14,
  118099. 1,
  118100. 15,
  118101. 0,
  118102. 16,
  118103. };
  118104. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118105. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118106. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118107. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118108. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118109. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118110. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118111. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118112. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118113. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118114. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118123. 0,
  118124. };
  118125. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118126. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118127. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118128. };
  118129. static long _vq_quantmap__44c6_s_p4_0[] = {
  118130. 15, 13, 11, 9, 7, 5, 3, 1,
  118131. 0, 2, 4, 6, 8, 10, 12, 14,
  118132. 16,
  118133. };
  118134. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118135. _vq_quantthresh__44c6_s_p4_0,
  118136. _vq_quantmap__44c6_s_p4_0,
  118137. 17,
  118138. 17
  118139. };
  118140. static static_codebook _44c6_s_p4_0 = {
  118141. 2, 289,
  118142. _vq_lengthlist__44c6_s_p4_0,
  118143. 1, -529530880, 1611661312, 5, 0,
  118144. _vq_quantlist__44c6_s_p4_0,
  118145. NULL,
  118146. &_vq_auxt__44c6_s_p4_0,
  118147. NULL,
  118148. 0
  118149. };
  118150. static long _vq_quantlist__44c6_s_p5_0[] = {
  118151. 1,
  118152. 0,
  118153. 2,
  118154. };
  118155. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118156. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118157. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118158. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118159. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118160. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118161. 12,
  118162. };
  118163. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118164. -5.5, 5.5,
  118165. };
  118166. static long _vq_quantmap__44c6_s_p5_0[] = {
  118167. 1, 0, 2,
  118168. };
  118169. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118170. _vq_quantthresh__44c6_s_p5_0,
  118171. _vq_quantmap__44c6_s_p5_0,
  118172. 3,
  118173. 3
  118174. };
  118175. static static_codebook _44c6_s_p5_0 = {
  118176. 4, 81,
  118177. _vq_lengthlist__44c6_s_p5_0,
  118178. 1, -529137664, 1618345984, 2, 0,
  118179. _vq_quantlist__44c6_s_p5_0,
  118180. NULL,
  118181. &_vq_auxt__44c6_s_p5_0,
  118182. NULL,
  118183. 0
  118184. };
  118185. static long _vq_quantlist__44c6_s_p5_1[] = {
  118186. 5,
  118187. 4,
  118188. 6,
  118189. 3,
  118190. 7,
  118191. 2,
  118192. 8,
  118193. 1,
  118194. 9,
  118195. 0,
  118196. 10,
  118197. };
  118198. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118199. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118200. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118201. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118202. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118203. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118204. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118205. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118206. 11,10,10, 7, 7, 8, 8, 8, 8,
  118207. };
  118208. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118209. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118210. 3.5, 4.5,
  118211. };
  118212. static long _vq_quantmap__44c6_s_p5_1[] = {
  118213. 9, 7, 5, 3, 1, 0, 2, 4,
  118214. 6, 8, 10,
  118215. };
  118216. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118217. _vq_quantthresh__44c6_s_p5_1,
  118218. _vq_quantmap__44c6_s_p5_1,
  118219. 11,
  118220. 11
  118221. };
  118222. static static_codebook _44c6_s_p5_1 = {
  118223. 2, 121,
  118224. _vq_lengthlist__44c6_s_p5_1,
  118225. 1, -531365888, 1611661312, 4, 0,
  118226. _vq_quantlist__44c6_s_p5_1,
  118227. NULL,
  118228. &_vq_auxt__44c6_s_p5_1,
  118229. NULL,
  118230. 0
  118231. };
  118232. static long _vq_quantlist__44c6_s_p6_0[] = {
  118233. 6,
  118234. 5,
  118235. 7,
  118236. 4,
  118237. 8,
  118238. 3,
  118239. 9,
  118240. 2,
  118241. 10,
  118242. 1,
  118243. 11,
  118244. 0,
  118245. 12,
  118246. };
  118247. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118248. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118249. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118250. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118251. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118252. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118253. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118258. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118259. };
  118260. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118261. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118262. 12.5, 17.5, 22.5, 27.5,
  118263. };
  118264. static long _vq_quantmap__44c6_s_p6_0[] = {
  118265. 11, 9, 7, 5, 3, 1, 0, 2,
  118266. 4, 6, 8, 10, 12,
  118267. };
  118268. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118269. _vq_quantthresh__44c6_s_p6_0,
  118270. _vq_quantmap__44c6_s_p6_0,
  118271. 13,
  118272. 13
  118273. };
  118274. static static_codebook _44c6_s_p6_0 = {
  118275. 2, 169,
  118276. _vq_lengthlist__44c6_s_p6_0,
  118277. 1, -526516224, 1616117760, 4, 0,
  118278. _vq_quantlist__44c6_s_p6_0,
  118279. NULL,
  118280. &_vq_auxt__44c6_s_p6_0,
  118281. NULL,
  118282. 0
  118283. };
  118284. static long _vq_quantlist__44c6_s_p6_1[] = {
  118285. 2,
  118286. 1,
  118287. 3,
  118288. 0,
  118289. 4,
  118290. };
  118291. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118292. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118293. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118294. };
  118295. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118296. -1.5, -0.5, 0.5, 1.5,
  118297. };
  118298. static long _vq_quantmap__44c6_s_p6_1[] = {
  118299. 3, 1, 0, 2, 4,
  118300. };
  118301. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118302. _vq_quantthresh__44c6_s_p6_1,
  118303. _vq_quantmap__44c6_s_p6_1,
  118304. 5,
  118305. 5
  118306. };
  118307. static static_codebook _44c6_s_p6_1 = {
  118308. 2, 25,
  118309. _vq_lengthlist__44c6_s_p6_1,
  118310. 1, -533725184, 1611661312, 3, 0,
  118311. _vq_quantlist__44c6_s_p6_1,
  118312. NULL,
  118313. &_vq_auxt__44c6_s_p6_1,
  118314. NULL,
  118315. 0
  118316. };
  118317. static long _vq_quantlist__44c6_s_p7_0[] = {
  118318. 6,
  118319. 5,
  118320. 7,
  118321. 4,
  118322. 8,
  118323. 3,
  118324. 9,
  118325. 2,
  118326. 10,
  118327. 1,
  118328. 11,
  118329. 0,
  118330. 12,
  118331. };
  118332. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118333. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118334. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118335. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118336. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118337. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118338. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118339. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118340. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118341. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118342. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118343. 20,13,13,13,13,13,13,14,14,
  118344. };
  118345. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118346. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118347. 27.5, 38.5, 49.5, 60.5,
  118348. };
  118349. static long _vq_quantmap__44c6_s_p7_0[] = {
  118350. 11, 9, 7, 5, 3, 1, 0, 2,
  118351. 4, 6, 8, 10, 12,
  118352. };
  118353. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118354. _vq_quantthresh__44c6_s_p7_0,
  118355. _vq_quantmap__44c6_s_p7_0,
  118356. 13,
  118357. 13
  118358. };
  118359. static static_codebook _44c6_s_p7_0 = {
  118360. 2, 169,
  118361. _vq_lengthlist__44c6_s_p7_0,
  118362. 1, -523206656, 1618345984, 4, 0,
  118363. _vq_quantlist__44c6_s_p7_0,
  118364. NULL,
  118365. &_vq_auxt__44c6_s_p7_0,
  118366. NULL,
  118367. 0
  118368. };
  118369. static long _vq_quantlist__44c6_s_p7_1[] = {
  118370. 5,
  118371. 4,
  118372. 6,
  118373. 3,
  118374. 7,
  118375. 2,
  118376. 8,
  118377. 1,
  118378. 9,
  118379. 0,
  118380. 10,
  118381. };
  118382. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118383. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118384. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118385. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118386. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118387. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118388. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118389. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118390. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118391. };
  118392. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118393. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118394. 3.5, 4.5,
  118395. };
  118396. static long _vq_quantmap__44c6_s_p7_1[] = {
  118397. 9, 7, 5, 3, 1, 0, 2, 4,
  118398. 6, 8, 10,
  118399. };
  118400. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118401. _vq_quantthresh__44c6_s_p7_1,
  118402. _vq_quantmap__44c6_s_p7_1,
  118403. 11,
  118404. 11
  118405. };
  118406. static static_codebook _44c6_s_p7_1 = {
  118407. 2, 121,
  118408. _vq_lengthlist__44c6_s_p7_1,
  118409. 1, -531365888, 1611661312, 4, 0,
  118410. _vq_quantlist__44c6_s_p7_1,
  118411. NULL,
  118412. &_vq_auxt__44c6_s_p7_1,
  118413. NULL,
  118414. 0
  118415. };
  118416. static long _vq_quantlist__44c6_s_p8_0[] = {
  118417. 7,
  118418. 6,
  118419. 8,
  118420. 5,
  118421. 9,
  118422. 4,
  118423. 10,
  118424. 3,
  118425. 11,
  118426. 2,
  118427. 12,
  118428. 1,
  118429. 13,
  118430. 0,
  118431. 14,
  118432. };
  118433. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118434. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118435. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118436. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118437. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118438. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118439. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118440. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118441. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118442. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118443. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118444. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118445. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118446. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118447. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118448. 14,
  118449. };
  118450. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118451. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118452. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118453. };
  118454. static long _vq_quantmap__44c6_s_p8_0[] = {
  118455. 13, 11, 9, 7, 5, 3, 1, 0,
  118456. 2, 4, 6, 8, 10, 12, 14,
  118457. };
  118458. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118459. _vq_quantthresh__44c6_s_p8_0,
  118460. _vq_quantmap__44c6_s_p8_0,
  118461. 15,
  118462. 15
  118463. };
  118464. static static_codebook _44c6_s_p8_0 = {
  118465. 2, 225,
  118466. _vq_lengthlist__44c6_s_p8_0,
  118467. 1, -520986624, 1620377600, 4, 0,
  118468. _vq_quantlist__44c6_s_p8_0,
  118469. NULL,
  118470. &_vq_auxt__44c6_s_p8_0,
  118471. NULL,
  118472. 0
  118473. };
  118474. static long _vq_quantlist__44c6_s_p8_1[] = {
  118475. 10,
  118476. 9,
  118477. 11,
  118478. 8,
  118479. 12,
  118480. 7,
  118481. 13,
  118482. 6,
  118483. 14,
  118484. 5,
  118485. 15,
  118486. 4,
  118487. 16,
  118488. 3,
  118489. 17,
  118490. 2,
  118491. 18,
  118492. 1,
  118493. 19,
  118494. 0,
  118495. 20,
  118496. };
  118497. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118498. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118499. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118500. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118501. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118502. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118503. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118504. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118505. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118506. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118507. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118508. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118509. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118510. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118511. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118512. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118513. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118514. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118515. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118516. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118517. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118518. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118519. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118520. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118521. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118522. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118523. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118524. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118525. 10,10,10,10,10,10,10,10,10,
  118526. };
  118527. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118528. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118529. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118530. 6.5, 7.5, 8.5, 9.5,
  118531. };
  118532. static long _vq_quantmap__44c6_s_p8_1[] = {
  118533. 19, 17, 15, 13, 11, 9, 7, 5,
  118534. 3, 1, 0, 2, 4, 6, 8, 10,
  118535. 12, 14, 16, 18, 20,
  118536. };
  118537. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  118538. _vq_quantthresh__44c6_s_p8_1,
  118539. _vq_quantmap__44c6_s_p8_1,
  118540. 21,
  118541. 21
  118542. };
  118543. static static_codebook _44c6_s_p8_1 = {
  118544. 2, 441,
  118545. _vq_lengthlist__44c6_s_p8_1,
  118546. 1, -529268736, 1611661312, 5, 0,
  118547. _vq_quantlist__44c6_s_p8_1,
  118548. NULL,
  118549. &_vq_auxt__44c6_s_p8_1,
  118550. NULL,
  118551. 0
  118552. };
  118553. static long _vq_quantlist__44c6_s_p9_0[] = {
  118554. 6,
  118555. 5,
  118556. 7,
  118557. 4,
  118558. 8,
  118559. 3,
  118560. 9,
  118561. 2,
  118562. 10,
  118563. 1,
  118564. 11,
  118565. 0,
  118566. 12,
  118567. };
  118568. static long _vq_lengthlist__44c6_s_p9_0[] = {
  118569. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  118570. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  118571. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  118572. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  118573. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118574. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118575. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118576. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118577. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118578. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118579. 10,10,10,10,10,10,10,10,10,
  118580. };
  118581. static float _vq_quantthresh__44c6_s_p9_0[] = {
  118582. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  118583. 1592.5, 2229.5, 2866.5, 3503.5,
  118584. };
  118585. static long _vq_quantmap__44c6_s_p9_0[] = {
  118586. 11, 9, 7, 5, 3, 1, 0, 2,
  118587. 4, 6, 8, 10, 12,
  118588. };
  118589. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  118590. _vq_quantthresh__44c6_s_p9_0,
  118591. _vq_quantmap__44c6_s_p9_0,
  118592. 13,
  118593. 13
  118594. };
  118595. static static_codebook _44c6_s_p9_0 = {
  118596. 2, 169,
  118597. _vq_lengthlist__44c6_s_p9_0,
  118598. 1, -511845376, 1630791680, 4, 0,
  118599. _vq_quantlist__44c6_s_p9_0,
  118600. NULL,
  118601. &_vq_auxt__44c6_s_p9_0,
  118602. NULL,
  118603. 0
  118604. };
  118605. static long _vq_quantlist__44c6_s_p9_1[] = {
  118606. 6,
  118607. 5,
  118608. 7,
  118609. 4,
  118610. 8,
  118611. 3,
  118612. 9,
  118613. 2,
  118614. 10,
  118615. 1,
  118616. 11,
  118617. 0,
  118618. 12,
  118619. };
  118620. static long _vq_lengthlist__44c6_s_p9_1[] = {
  118621. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  118622. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  118623. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  118624. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  118625. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  118626. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  118627. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  118628. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  118629. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  118630. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  118631. 15,12,10,11,11,13,11,12,13,
  118632. };
  118633. static float _vq_quantthresh__44c6_s_p9_1[] = {
  118634. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  118635. 122.5, 171.5, 220.5, 269.5,
  118636. };
  118637. static long _vq_quantmap__44c6_s_p9_1[] = {
  118638. 11, 9, 7, 5, 3, 1, 0, 2,
  118639. 4, 6, 8, 10, 12,
  118640. };
  118641. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  118642. _vq_quantthresh__44c6_s_p9_1,
  118643. _vq_quantmap__44c6_s_p9_1,
  118644. 13,
  118645. 13
  118646. };
  118647. static static_codebook _44c6_s_p9_1 = {
  118648. 2, 169,
  118649. _vq_lengthlist__44c6_s_p9_1,
  118650. 1, -518889472, 1622704128, 4, 0,
  118651. _vq_quantlist__44c6_s_p9_1,
  118652. NULL,
  118653. &_vq_auxt__44c6_s_p9_1,
  118654. NULL,
  118655. 0
  118656. };
  118657. static long _vq_quantlist__44c6_s_p9_2[] = {
  118658. 24,
  118659. 23,
  118660. 25,
  118661. 22,
  118662. 26,
  118663. 21,
  118664. 27,
  118665. 20,
  118666. 28,
  118667. 19,
  118668. 29,
  118669. 18,
  118670. 30,
  118671. 17,
  118672. 31,
  118673. 16,
  118674. 32,
  118675. 15,
  118676. 33,
  118677. 14,
  118678. 34,
  118679. 13,
  118680. 35,
  118681. 12,
  118682. 36,
  118683. 11,
  118684. 37,
  118685. 10,
  118686. 38,
  118687. 9,
  118688. 39,
  118689. 8,
  118690. 40,
  118691. 7,
  118692. 41,
  118693. 6,
  118694. 42,
  118695. 5,
  118696. 43,
  118697. 4,
  118698. 44,
  118699. 3,
  118700. 45,
  118701. 2,
  118702. 46,
  118703. 1,
  118704. 47,
  118705. 0,
  118706. 48,
  118707. };
  118708. static long _vq_lengthlist__44c6_s_p9_2[] = {
  118709. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  118710. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118711. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118712. 7,
  118713. };
  118714. static float _vq_quantthresh__44c6_s_p9_2[] = {
  118715. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  118716. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  118717. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118718. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118719. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  118720. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  118721. };
  118722. static long _vq_quantmap__44c6_s_p9_2[] = {
  118723. 47, 45, 43, 41, 39, 37, 35, 33,
  118724. 31, 29, 27, 25, 23, 21, 19, 17,
  118725. 15, 13, 11, 9, 7, 5, 3, 1,
  118726. 0, 2, 4, 6, 8, 10, 12, 14,
  118727. 16, 18, 20, 22, 24, 26, 28, 30,
  118728. 32, 34, 36, 38, 40, 42, 44, 46,
  118729. 48,
  118730. };
  118731. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  118732. _vq_quantthresh__44c6_s_p9_2,
  118733. _vq_quantmap__44c6_s_p9_2,
  118734. 49,
  118735. 49
  118736. };
  118737. static static_codebook _44c6_s_p9_2 = {
  118738. 1, 49,
  118739. _vq_lengthlist__44c6_s_p9_2,
  118740. 1, -526909440, 1611661312, 6, 0,
  118741. _vq_quantlist__44c6_s_p9_2,
  118742. NULL,
  118743. &_vq_auxt__44c6_s_p9_2,
  118744. NULL,
  118745. 0
  118746. };
  118747. static long _huff_lengthlist__44c6_s_short[] = {
  118748. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  118749. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  118750. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  118751. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  118752. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  118753. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  118754. 9,10,17,18,
  118755. };
  118756. static static_codebook _huff_book__44c6_s_short = {
  118757. 2, 100,
  118758. _huff_lengthlist__44c6_s_short,
  118759. 0, 0, 0, 0, 0,
  118760. NULL,
  118761. NULL,
  118762. NULL,
  118763. NULL,
  118764. 0
  118765. };
  118766. static long _huff_lengthlist__44c7_s_long[] = {
  118767. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  118768. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  118769. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  118770. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  118771. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  118772. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  118773. 11,10,10,12,
  118774. };
  118775. static static_codebook _huff_book__44c7_s_long = {
  118776. 2, 100,
  118777. _huff_lengthlist__44c7_s_long,
  118778. 0, 0, 0, 0, 0,
  118779. NULL,
  118780. NULL,
  118781. NULL,
  118782. NULL,
  118783. 0
  118784. };
  118785. static long _vq_quantlist__44c7_s_p1_0[] = {
  118786. 1,
  118787. 0,
  118788. 2,
  118789. };
  118790. static long _vq_lengthlist__44c7_s_p1_0[] = {
  118791. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118792. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118793. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118794. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118795. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  118796. 8,
  118797. };
  118798. static float _vq_quantthresh__44c7_s_p1_0[] = {
  118799. -0.5, 0.5,
  118800. };
  118801. static long _vq_quantmap__44c7_s_p1_0[] = {
  118802. 1, 0, 2,
  118803. };
  118804. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  118805. _vq_quantthresh__44c7_s_p1_0,
  118806. _vq_quantmap__44c7_s_p1_0,
  118807. 3,
  118808. 3
  118809. };
  118810. static static_codebook _44c7_s_p1_0 = {
  118811. 4, 81,
  118812. _vq_lengthlist__44c7_s_p1_0,
  118813. 1, -535822336, 1611661312, 2, 0,
  118814. _vq_quantlist__44c7_s_p1_0,
  118815. NULL,
  118816. &_vq_auxt__44c7_s_p1_0,
  118817. NULL,
  118818. 0
  118819. };
  118820. static long _vq_quantlist__44c7_s_p2_0[] = {
  118821. 2,
  118822. 1,
  118823. 3,
  118824. 0,
  118825. 4,
  118826. };
  118827. static long _vq_lengthlist__44c7_s_p2_0[] = {
  118828. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118829. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118830. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118831. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118832. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  118833. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118834. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  118835. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118837. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118838. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118839. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118840. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118841. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118842. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  118843. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118845. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118846. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  118847. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  118848. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  118849. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  118850. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118851. 13,13, 0, 0, 0,12,13, 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. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  118854. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118855. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118856. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  118857. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118858. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  118859. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118864. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  118865. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  118866. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118867. 13,
  118868. };
  118869. static float _vq_quantthresh__44c7_s_p2_0[] = {
  118870. -1.5, -0.5, 0.5, 1.5,
  118871. };
  118872. static long _vq_quantmap__44c7_s_p2_0[] = {
  118873. 3, 1, 0, 2, 4,
  118874. };
  118875. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  118876. _vq_quantthresh__44c7_s_p2_0,
  118877. _vq_quantmap__44c7_s_p2_0,
  118878. 5,
  118879. 5
  118880. };
  118881. static static_codebook _44c7_s_p2_0 = {
  118882. 4, 625,
  118883. _vq_lengthlist__44c7_s_p2_0,
  118884. 1, -533725184, 1611661312, 3, 0,
  118885. _vq_quantlist__44c7_s_p2_0,
  118886. NULL,
  118887. &_vq_auxt__44c7_s_p2_0,
  118888. NULL,
  118889. 0
  118890. };
  118891. static long _vq_quantlist__44c7_s_p3_0[] = {
  118892. 4,
  118893. 3,
  118894. 5,
  118895. 2,
  118896. 6,
  118897. 1,
  118898. 7,
  118899. 0,
  118900. 8,
  118901. };
  118902. static long _vq_lengthlist__44c7_s_p3_0[] = {
  118903. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118904. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  118905. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  118906. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  118907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118908. 0,
  118909. };
  118910. static float _vq_quantthresh__44c7_s_p3_0[] = {
  118911. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118912. };
  118913. static long _vq_quantmap__44c7_s_p3_0[] = {
  118914. 7, 5, 3, 1, 0, 2, 4, 6,
  118915. 8,
  118916. };
  118917. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  118918. _vq_quantthresh__44c7_s_p3_0,
  118919. _vq_quantmap__44c7_s_p3_0,
  118920. 9,
  118921. 9
  118922. };
  118923. static static_codebook _44c7_s_p3_0 = {
  118924. 2, 81,
  118925. _vq_lengthlist__44c7_s_p3_0,
  118926. 1, -531628032, 1611661312, 4, 0,
  118927. _vq_quantlist__44c7_s_p3_0,
  118928. NULL,
  118929. &_vq_auxt__44c7_s_p3_0,
  118930. NULL,
  118931. 0
  118932. };
  118933. static long _vq_quantlist__44c7_s_p4_0[] = {
  118934. 8,
  118935. 7,
  118936. 9,
  118937. 6,
  118938. 10,
  118939. 5,
  118940. 11,
  118941. 4,
  118942. 12,
  118943. 3,
  118944. 13,
  118945. 2,
  118946. 14,
  118947. 1,
  118948. 15,
  118949. 0,
  118950. 16,
  118951. };
  118952. static long _vq_lengthlist__44c7_s_p4_0[] = {
  118953. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  118954. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  118955. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  118956. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  118957. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  118958. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  118959. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  118960. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118961. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  118962. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  118963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118971. 0,
  118972. };
  118973. static float _vq_quantthresh__44c7_s_p4_0[] = {
  118974. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118975. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118976. };
  118977. static long _vq_quantmap__44c7_s_p4_0[] = {
  118978. 15, 13, 11, 9, 7, 5, 3, 1,
  118979. 0, 2, 4, 6, 8, 10, 12, 14,
  118980. 16,
  118981. };
  118982. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  118983. _vq_quantthresh__44c7_s_p4_0,
  118984. _vq_quantmap__44c7_s_p4_0,
  118985. 17,
  118986. 17
  118987. };
  118988. static static_codebook _44c7_s_p4_0 = {
  118989. 2, 289,
  118990. _vq_lengthlist__44c7_s_p4_0,
  118991. 1, -529530880, 1611661312, 5, 0,
  118992. _vq_quantlist__44c7_s_p4_0,
  118993. NULL,
  118994. &_vq_auxt__44c7_s_p4_0,
  118995. NULL,
  118996. 0
  118997. };
  118998. static long _vq_quantlist__44c7_s_p5_0[] = {
  118999. 1,
  119000. 0,
  119001. 2,
  119002. };
  119003. static long _vq_lengthlist__44c7_s_p5_0[] = {
  119004. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  119005. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119006. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119007. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119008. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  119009. 12,
  119010. };
  119011. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119012. -5.5, 5.5,
  119013. };
  119014. static long _vq_quantmap__44c7_s_p5_0[] = {
  119015. 1, 0, 2,
  119016. };
  119017. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119018. _vq_quantthresh__44c7_s_p5_0,
  119019. _vq_quantmap__44c7_s_p5_0,
  119020. 3,
  119021. 3
  119022. };
  119023. static static_codebook _44c7_s_p5_0 = {
  119024. 4, 81,
  119025. _vq_lengthlist__44c7_s_p5_0,
  119026. 1, -529137664, 1618345984, 2, 0,
  119027. _vq_quantlist__44c7_s_p5_0,
  119028. NULL,
  119029. &_vq_auxt__44c7_s_p5_0,
  119030. NULL,
  119031. 0
  119032. };
  119033. static long _vq_quantlist__44c7_s_p5_1[] = {
  119034. 5,
  119035. 4,
  119036. 6,
  119037. 3,
  119038. 7,
  119039. 2,
  119040. 8,
  119041. 1,
  119042. 9,
  119043. 0,
  119044. 10,
  119045. };
  119046. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119047. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119048. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119049. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119050. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119051. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119052. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119053. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119054. 11,11,11, 7, 7, 8, 8, 8, 8,
  119055. };
  119056. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119057. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119058. 3.5, 4.5,
  119059. };
  119060. static long _vq_quantmap__44c7_s_p5_1[] = {
  119061. 9, 7, 5, 3, 1, 0, 2, 4,
  119062. 6, 8, 10,
  119063. };
  119064. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119065. _vq_quantthresh__44c7_s_p5_1,
  119066. _vq_quantmap__44c7_s_p5_1,
  119067. 11,
  119068. 11
  119069. };
  119070. static static_codebook _44c7_s_p5_1 = {
  119071. 2, 121,
  119072. _vq_lengthlist__44c7_s_p5_1,
  119073. 1, -531365888, 1611661312, 4, 0,
  119074. _vq_quantlist__44c7_s_p5_1,
  119075. NULL,
  119076. &_vq_auxt__44c7_s_p5_1,
  119077. NULL,
  119078. 0
  119079. };
  119080. static long _vq_quantlist__44c7_s_p6_0[] = {
  119081. 6,
  119082. 5,
  119083. 7,
  119084. 4,
  119085. 8,
  119086. 3,
  119087. 9,
  119088. 2,
  119089. 10,
  119090. 1,
  119091. 11,
  119092. 0,
  119093. 12,
  119094. };
  119095. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119096. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119097. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119098. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119099. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119100. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119101. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119106. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119107. };
  119108. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119109. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119110. 12.5, 17.5, 22.5, 27.5,
  119111. };
  119112. static long _vq_quantmap__44c7_s_p6_0[] = {
  119113. 11, 9, 7, 5, 3, 1, 0, 2,
  119114. 4, 6, 8, 10, 12,
  119115. };
  119116. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119117. _vq_quantthresh__44c7_s_p6_0,
  119118. _vq_quantmap__44c7_s_p6_0,
  119119. 13,
  119120. 13
  119121. };
  119122. static static_codebook _44c7_s_p6_0 = {
  119123. 2, 169,
  119124. _vq_lengthlist__44c7_s_p6_0,
  119125. 1, -526516224, 1616117760, 4, 0,
  119126. _vq_quantlist__44c7_s_p6_0,
  119127. NULL,
  119128. &_vq_auxt__44c7_s_p6_0,
  119129. NULL,
  119130. 0
  119131. };
  119132. static long _vq_quantlist__44c7_s_p6_1[] = {
  119133. 2,
  119134. 1,
  119135. 3,
  119136. 0,
  119137. 4,
  119138. };
  119139. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119140. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119141. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119142. };
  119143. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119144. -1.5, -0.5, 0.5, 1.5,
  119145. };
  119146. static long _vq_quantmap__44c7_s_p6_1[] = {
  119147. 3, 1, 0, 2, 4,
  119148. };
  119149. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119150. _vq_quantthresh__44c7_s_p6_1,
  119151. _vq_quantmap__44c7_s_p6_1,
  119152. 5,
  119153. 5
  119154. };
  119155. static static_codebook _44c7_s_p6_1 = {
  119156. 2, 25,
  119157. _vq_lengthlist__44c7_s_p6_1,
  119158. 1, -533725184, 1611661312, 3, 0,
  119159. _vq_quantlist__44c7_s_p6_1,
  119160. NULL,
  119161. &_vq_auxt__44c7_s_p6_1,
  119162. NULL,
  119163. 0
  119164. };
  119165. static long _vq_quantlist__44c7_s_p7_0[] = {
  119166. 6,
  119167. 5,
  119168. 7,
  119169. 4,
  119170. 8,
  119171. 3,
  119172. 9,
  119173. 2,
  119174. 10,
  119175. 1,
  119176. 11,
  119177. 0,
  119178. 12,
  119179. };
  119180. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119181. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119182. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119183. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119184. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119185. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119186. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119187. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119188. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119189. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119190. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119191. 19,13,13,13,13,14,14,15,15,
  119192. };
  119193. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119194. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119195. 27.5, 38.5, 49.5, 60.5,
  119196. };
  119197. static long _vq_quantmap__44c7_s_p7_0[] = {
  119198. 11, 9, 7, 5, 3, 1, 0, 2,
  119199. 4, 6, 8, 10, 12,
  119200. };
  119201. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119202. _vq_quantthresh__44c7_s_p7_0,
  119203. _vq_quantmap__44c7_s_p7_0,
  119204. 13,
  119205. 13
  119206. };
  119207. static static_codebook _44c7_s_p7_0 = {
  119208. 2, 169,
  119209. _vq_lengthlist__44c7_s_p7_0,
  119210. 1, -523206656, 1618345984, 4, 0,
  119211. _vq_quantlist__44c7_s_p7_0,
  119212. NULL,
  119213. &_vq_auxt__44c7_s_p7_0,
  119214. NULL,
  119215. 0
  119216. };
  119217. static long _vq_quantlist__44c7_s_p7_1[] = {
  119218. 5,
  119219. 4,
  119220. 6,
  119221. 3,
  119222. 7,
  119223. 2,
  119224. 8,
  119225. 1,
  119226. 9,
  119227. 0,
  119228. 10,
  119229. };
  119230. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119231. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119232. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119233. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119234. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119235. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119236. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119237. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119238. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119239. };
  119240. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119241. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119242. 3.5, 4.5,
  119243. };
  119244. static long _vq_quantmap__44c7_s_p7_1[] = {
  119245. 9, 7, 5, 3, 1, 0, 2, 4,
  119246. 6, 8, 10,
  119247. };
  119248. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119249. _vq_quantthresh__44c7_s_p7_1,
  119250. _vq_quantmap__44c7_s_p7_1,
  119251. 11,
  119252. 11
  119253. };
  119254. static static_codebook _44c7_s_p7_1 = {
  119255. 2, 121,
  119256. _vq_lengthlist__44c7_s_p7_1,
  119257. 1, -531365888, 1611661312, 4, 0,
  119258. _vq_quantlist__44c7_s_p7_1,
  119259. NULL,
  119260. &_vq_auxt__44c7_s_p7_1,
  119261. NULL,
  119262. 0
  119263. };
  119264. static long _vq_quantlist__44c7_s_p8_0[] = {
  119265. 7,
  119266. 6,
  119267. 8,
  119268. 5,
  119269. 9,
  119270. 4,
  119271. 10,
  119272. 3,
  119273. 11,
  119274. 2,
  119275. 12,
  119276. 1,
  119277. 13,
  119278. 0,
  119279. 14,
  119280. };
  119281. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119282. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119283. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119284. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119285. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119286. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119287. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119288. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119289. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119290. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119291. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119292. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119293. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119294. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119295. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119296. 14,
  119297. };
  119298. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119299. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119300. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119301. };
  119302. static long _vq_quantmap__44c7_s_p8_0[] = {
  119303. 13, 11, 9, 7, 5, 3, 1, 0,
  119304. 2, 4, 6, 8, 10, 12, 14,
  119305. };
  119306. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119307. _vq_quantthresh__44c7_s_p8_0,
  119308. _vq_quantmap__44c7_s_p8_0,
  119309. 15,
  119310. 15
  119311. };
  119312. static static_codebook _44c7_s_p8_0 = {
  119313. 2, 225,
  119314. _vq_lengthlist__44c7_s_p8_0,
  119315. 1, -520986624, 1620377600, 4, 0,
  119316. _vq_quantlist__44c7_s_p8_0,
  119317. NULL,
  119318. &_vq_auxt__44c7_s_p8_0,
  119319. NULL,
  119320. 0
  119321. };
  119322. static long _vq_quantlist__44c7_s_p8_1[] = {
  119323. 10,
  119324. 9,
  119325. 11,
  119326. 8,
  119327. 12,
  119328. 7,
  119329. 13,
  119330. 6,
  119331. 14,
  119332. 5,
  119333. 15,
  119334. 4,
  119335. 16,
  119336. 3,
  119337. 17,
  119338. 2,
  119339. 18,
  119340. 1,
  119341. 19,
  119342. 0,
  119343. 20,
  119344. };
  119345. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119346. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119347. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119348. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119349. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119350. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119351. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119352. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119353. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119354. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119355. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119356. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119357. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119358. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119359. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119360. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119361. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119362. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119363. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119364. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119365. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119366. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119367. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119368. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119369. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119370. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119371. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119372. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119373. 10,10,10,10,10,10,10,10,10,
  119374. };
  119375. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119376. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119377. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119378. 6.5, 7.5, 8.5, 9.5,
  119379. };
  119380. static long _vq_quantmap__44c7_s_p8_1[] = {
  119381. 19, 17, 15, 13, 11, 9, 7, 5,
  119382. 3, 1, 0, 2, 4, 6, 8, 10,
  119383. 12, 14, 16, 18, 20,
  119384. };
  119385. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119386. _vq_quantthresh__44c7_s_p8_1,
  119387. _vq_quantmap__44c7_s_p8_1,
  119388. 21,
  119389. 21
  119390. };
  119391. static static_codebook _44c7_s_p8_1 = {
  119392. 2, 441,
  119393. _vq_lengthlist__44c7_s_p8_1,
  119394. 1, -529268736, 1611661312, 5, 0,
  119395. _vq_quantlist__44c7_s_p8_1,
  119396. NULL,
  119397. &_vq_auxt__44c7_s_p8_1,
  119398. NULL,
  119399. 0
  119400. };
  119401. static long _vq_quantlist__44c7_s_p9_0[] = {
  119402. 6,
  119403. 5,
  119404. 7,
  119405. 4,
  119406. 8,
  119407. 3,
  119408. 9,
  119409. 2,
  119410. 10,
  119411. 1,
  119412. 11,
  119413. 0,
  119414. 12,
  119415. };
  119416. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119417. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119418. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119419. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119420. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119421. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119422. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119423. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119424. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119425. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119426. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119427. 11,11,11,11,11,11,11,11,11,
  119428. };
  119429. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119430. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119431. 1592.5, 2229.5, 2866.5, 3503.5,
  119432. };
  119433. static long _vq_quantmap__44c7_s_p9_0[] = {
  119434. 11, 9, 7, 5, 3, 1, 0, 2,
  119435. 4, 6, 8, 10, 12,
  119436. };
  119437. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119438. _vq_quantthresh__44c7_s_p9_0,
  119439. _vq_quantmap__44c7_s_p9_0,
  119440. 13,
  119441. 13
  119442. };
  119443. static static_codebook _44c7_s_p9_0 = {
  119444. 2, 169,
  119445. _vq_lengthlist__44c7_s_p9_0,
  119446. 1, -511845376, 1630791680, 4, 0,
  119447. _vq_quantlist__44c7_s_p9_0,
  119448. NULL,
  119449. &_vq_auxt__44c7_s_p9_0,
  119450. NULL,
  119451. 0
  119452. };
  119453. static long _vq_quantlist__44c7_s_p9_1[] = {
  119454. 6,
  119455. 5,
  119456. 7,
  119457. 4,
  119458. 8,
  119459. 3,
  119460. 9,
  119461. 2,
  119462. 10,
  119463. 1,
  119464. 11,
  119465. 0,
  119466. 12,
  119467. };
  119468. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119469. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119470. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119471. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119472. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119473. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119474. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119475. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119476. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119477. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119478. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119479. 15,11,11,10,10,12,12,12,12,
  119480. };
  119481. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119482. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119483. 122.5, 171.5, 220.5, 269.5,
  119484. };
  119485. static long _vq_quantmap__44c7_s_p9_1[] = {
  119486. 11, 9, 7, 5, 3, 1, 0, 2,
  119487. 4, 6, 8, 10, 12,
  119488. };
  119489. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119490. _vq_quantthresh__44c7_s_p9_1,
  119491. _vq_quantmap__44c7_s_p9_1,
  119492. 13,
  119493. 13
  119494. };
  119495. static static_codebook _44c7_s_p9_1 = {
  119496. 2, 169,
  119497. _vq_lengthlist__44c7_s_p9_1,
  119498. 1, -518889472, 1622704128, 4, 0,
  119499. _vq_quantlist__44c7_s_p9_1,
  119500. NULL,
  119501. &_vq_auxt__44c7_s_p9_1,
  119502. NULL,
  119503. 0
  119504. };
  119505. static long _vq_quantlist__44c7_s_p9_2[] = {
  119506. 24,
  119507. 23,
  119508. 25,
  119509. 22,
  119510. 26,
  119511. 21,
  119512. 27,
  119513. 20,
  119514. 28,
  119515. 19,
  119516. 29,
  119517. 18,
  119518. 30,
  119519. 17,
  119520. 31,
  119521. 16,
  119522. 32,
  119523. 15,
  119524. 33,
  119525. 14,
  119526. 34,
  119527. 13,
  119528. 35,
  119529. 12,
  119530. 36,
  119531. 11,
  119532. 37,
  119533. 10,
  119534. 38,
  119535. 9,
  119536. 39,
  119537. 8,
  119538. 40,
  119539. 7,
  119540. 41,
  119541. 6,
  119542. 42,
  119543. 5,
  119544. 43,
  119545. 4,
  119546. 44,
  119547. 3,
  119548. 45,
  119549. 2,
  119550. 46,
  119551. 1,
  119552. 47,
  119553. 0,
  119554. 48,
  119555. };
  119556. static long _vq_lengthlist__44c7_s_p9_2[] = {
  119557. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119558. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119559. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119560. 7,
  119561. };
  119562. static float _vq_quantthresh__44c7_s_p9_2[] = {
  119563. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119564. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119565. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119566. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119567. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119568. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119569. };
  119570. static long _vq_quantmap__44c7_s_p9_2[] = {
  119571. 47, 45, 43, 41, 39, 37, 35, 33,
  119572. 31, 29, 27, 25, 23, 21, 19, 17,
  119573. 15, 13, 11, 9, 7, 5, 3, 1,
  119574. 0, 2, 4, 6, 8, 10, 12, 14,
  119575. 16, 18, 20, 22, 24, 26, 28, 30,
  119576. 32, 34, 36, 38, 40, 42, 44, 46,
  119577. 48,
  119578. };
  119579. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  119580. _vq_quantthresh__44c7_s_p9_2,
  119581. _vq_quantmap__44c7_s_p9_2,
  119582. 49,
  119583. 49
  119584. };
  119585. static static_codebook _44c7_s_p9_2 = {
  119586. 1, 49,
  119587. _vq_lengthlist__44c7_s_p9_2,
  119588. 1, -526909440, 1611661312, 6, 0,
  119589. _vq_quantlist__44c7_s_p9_2,
  119590. NULL,
  119591. &_vq_auxt__44c7_s_p9_2,
  119592. NULL,
  119593. 0
  119594. };
  119595. static long _huff_lengthlist__44c7_s_short[] = {
  119596. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  119597. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  119598. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  119599. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  119600. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  119601. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  119602. 10, 9,11,14,
  119603. };
  119604. static static_codebook _huff_book__44c7_s_short = {
  119605. 2, 100,
  119606. _huff_lengthlist__44c7_s_short,
  119607. 0, 0, 0, 0, 0,
  119608. NULL,
  119609. NULL,
  119610. NULL,
  119611. NULL,
  119612. 0
  119613. };
  119614. static long _huff_lengthlist__44c8_s_long[] = {
  119615. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  119616. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  119617. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  119618. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  119619. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  119620. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  119621. 11, 9, 9,10,
  119622. };
  119623. static static_codebook _huff_book__44c8_s_long = {
  119624. 2, 100,
  119625. _huff_lengthlist__44c8_s_long,
  119626. 0, 0, 0, 0, 0,
  119627. NULL,
  119628. NULL,
  119629. NULL,
  119630. NULL,
  119631. 0
  119632. };
  119633. static long _vq_quantlist__44c8_s_p1_0[] = {
  119634. 1,
  119635. 0,
  119636. 2,
  119637. };
  119638. static long _vq_lengthlist__44c8_s_p1_0[] = {
  119639. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  119640. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119641. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119642. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119643. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119644. 8,
  119645. };
  119646. static float _vq_quantthresh__44c8_s_p1_0[] = {
  119647. -0.5, 0.5,
  119648. };
  119649. static long _vq_quantmap__44c8_s_p1_0[] = {
  119650. 1, 0, 2,
  119651. };
  119652. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  119653. _vq_quantthresh__44c8_s_p1_0,
  119654. _vq_quantmap__44c8_s_p1_0,
  119655. 3,
  119656. 3
  119657. };
  119658. static static_codebook _44c8_s_p1_0 = {
  119659. 4, 81,
  119660. _vq_lengthlist__44c8_s_p1_0,
  119661. 1, -535822336, 1611661312, 2, 0,
  119662. _vq_quantlist__44c8_s_p1_0,
  119663. NULL,
  119664. &_vq_auxt__44c8_s_p1_0,
  119665. NULL,
  119666. 0
  119667. };
  119668. static long _vq_quantlist__44c8_s_p2_0[] = {
  119669. 2,
  119670. 1,
  119671. 3,
  119672. 0,
  119673. 4,
  119674. };
  119675. static long _vq_lengthlist__44c8_s_p2_0[] = {
  119676. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119677. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119678. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119679. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  119680. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119681. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  119682. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  119683. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119685. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119686. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  119687. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119688. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  119689. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  119690. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  119691. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  119692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119693. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  119694. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  119695. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  119696. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  119697. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  119698. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  119699. 13,13, 0, 0, 0,12,13, 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. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119702. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  119703. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119704. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  119705. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  119706. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  119707. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119712. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  119713. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119714. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  119715. 13,
  119716. };
  119717. static float _vq_quantthresh__44c8_s_p2_0[] = {
  119718. -1.5, -0.5, 0.5, 1.5,
  119719. };
  119720. static long _vq_quantmap__44c8_s_p2_0[] = {
  119721. 3, 1, 0, 2, 4,
  119722. };
  119723. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  119724. _vq_quantthresh__44c8_s_p2_0,
  119725. _vq_quantmap__44c8_s_p2_0,
  119726. 5,
  119727. 5
  119728. };
  119729. static static_codebook _44c8_s_p2_0 = {
  119730. 4, 625,
  119731. _vq_lengthlist__44c8_s_p2_0,
  119732. 1, -533725184, 1611661312, 3, 0,
  119733. _vq_quantlist__44c8_s_p2_0,
  119734. NULL,
  119735. &_vq_auxt__44c8_s_p2_0,
  119736. NULL,
  119737. 0
  119738. };
  119739. static long _vq_quantlist__44c8_s_p3_0[] = {
  119740. 4,
  119741. 3,
  119742. 5,
  119743. 2,
  119744. 6,
  119745. 1,
  119746. 7,
  119747. 0,
  119748. 8,
  119749. };
  119750. static long _vq_lengthlist__44c8_s_p3_0[] = {
  119751. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119752. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119753. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119754. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119756. 0,
  119757. };
  119758. static float _vq_quantthresh__44c8_s_p3_0[] = {
  119759. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119760. };
  119761. static long _vq_quantmap__44c8_s_p3_0[] = {
  119762. 7, 5, 3, 1, 0, 2, 4, 6,
  119763. 8,
  119764. };
  119765. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  119766. _vq_quantthresh__44c8_s_p3_0,
  119767. _vq_quantmap__44c8_s_p3_0,
  119768. 9,
  119769. 9
  119770. };
  119771. static static_codebook _44c8_s_p3_0 = {
  119772. 2, 81,
  119773. _vq_lengthlist__44c8_s_p3_0,
  119774. 1, -531628032, 1611661312, 4, 0,
  119775. _vq_quantlist__44c8_s_p3_0,
  119776. NULL,
  119777. &_vq_auxt__44c8_s_p3_0,
  119778. NULL,
  119779. 0
  119780. };
  119781. static long _vq_quantlist__44c8_s_p4_0[] = {
  119782. 8,
  119783. 7,
  119784. 9,
  119785. 6,
  119786. 10,
  119787. 5,
  119788. 11,
  119789. 4,
  119790. 12,
  119791. 3,
  119792. 13,
  119793. 2,
  119794. 14,
  119795. 1,
  119796. 15,
  119797. 0,
  119798. 16,
  119799. };
  119800. static long _vq_lengthlist__44c8_s_p4_0[] = {
  119801. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119802. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  119803. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119804. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  119805. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  119806. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119807. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119808. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119809. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119810. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119819. 0,
  119820. };
  119821. static float _vq_quantthresh__44c8_s_p4_0[] = {
  119822. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119823. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119824. };
  119825. static long _vq_quantmap__44c8_s_p4_0[] = {
  119826. 15, 13, 11, 9, 7, 5, 3, 1,
  119827. 0, 2, 4, 6, 8, 10, 12, 14,
  119828. 16,
  119829. };
  119830. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  119831. _vq_quantthresh__44c8_s_p4_0,
  119832. _vq_quantmap__44c8_s_p4_0,
  119833. 17,
  119834. 17
  119835. };
  119836. static static_codebook _44c8_s_p4_0 = {
  119837. 2, 289,
  119838. _vq_lengthlist__44c8_s_p4_0,
  119839. 1, -529530880, 1611661312, 5, 0,
  119840. _vq_quantlist__44c8_s_p4_0,
  119841. NULL,
  119842. &_vq_auxt__44c8_s_p4_0,
  119843. NULL,
  119844. 0
  119845. };
  119846. static long _vq_quantlist__44c8_s_p5_0[] = {
  119847. 1,
  119848. 0,
  119849. 2,
  119850. };
  119851. static long _vq_lengthlist__44c8_s_p5_0[] = {
  119852. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  119853. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119854. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119855. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  119856. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  119857. 12,
  119858. };
  119859. static float _vq_quantthresh__44c8_s_p5_0[] = {
  119860. -5.5, 5.5,
  119861. };
  119862. static long _vq_quantmap__44c8_s_p5_0[] = {
  119863. 1, 0, 2,
  119864. };
  119865. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  119866. _vq_quantthresh__44c8_s_p5_0,
  119867. _vq_quantmap__44c8_s_p5_0,
  119868. 3,
  119869. 3
  119870. };
  119871. static static_codebook _44c8_s_p5_0 = {
  119872. 4, 81,
  119873. _vq_lengthlist__44c8_s_p5_0,
  119874. 1, -529137664, 1618345984, 2, 0,
  119875. _vq_quantlist__44c8_s_p5_0,
  119876. NULL,
  119877. &_vq_auxt__44c8_s_p5_0,
  119878. NULL,
  119879. 0
  119880. };
  119881. static long _vq_quantlist__44c8_s_p5_1[] = {
  119882. 5,
  119883. 4,
  119884. 6,
  119885. 3,
  119886. 7,
  119887. 2,
  119888. 8,
  119889. 1,
  119890. 9,
  119891. 0,
  119892. 10,
  119893. };
  119894. static long _vq_lengthlist__44c8_s_p5_1[] = {
  119895. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  119896. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  119897. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  119898. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  119899. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  119900. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  119901. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  119902. 11,11,11, 7, 7, 7, 7, 8, 8,
  119903. };
  119904. static float _vq_quantthresh__44c8_s_p5_1[] = {
  119905. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119906. 3.5, 4.5,
  119907. };
  119908. static long _vq_quantmap__44c8_s_p5_1[] = {
  119909. 9, 7, 5, 3, 1, 0, 2, 4,
  119910. 6, 8, 10,
  119911. };
  119912. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  119913. _vq_quantthresh__44c8_s_p5_1,
  119914. _vq_quantmap__44c8_s_p5_1,
  119915. 11,
  119916. 11
  119917. };
  119918. static static_codebook _44c8_s_p5_1 = {
  119919. 2, 121,
  119920. _vq_lengthlist__44c8_s_p5_1,
  119921. 1, -531365888, 1611661312, 4, 0,
  119922. _vq_quantlist__44c8_s_p5_1,
  119923. NULL,
  119924. &_vq_auxt__44c8_s_p5_1,
  119925. NULL,
  119926. 0
  119927. };
  119928. static long _vq_quantlist__44c8_s_p6_0[] = {
  119929. 6,
  119930. 5,
  119931. 7,
  119932. 4,
  119933. 8,
  119934. 3,
  119935. 9,
  119936. 2,
  119937. 10,
  119938. 1,
  119939. 11,
  119940. 0,
  119941. 12,
  119942. };
  119943. static long _vq_lengthlist__44c8_s_p6_0[] = {
  119944. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  119945. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  119946. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  119947. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  119948. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  119949. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  119950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119954. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119955. };
  119956. static float _vq_quantthresh__44c8_s_p6_0[] = {
  119957. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119958. 12.5, 17.5, 22.5, 27.5,
  119959. };
  119960. static long _vq_quantmap__44c8_s_p6_0[] = {
  119961. 11, 9, 7, 5, 3, 1, 0, 2,
  119962. 4, 6, 8, 10, 12,
  119963. };
  119964. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  119965. _vq_quantthresh__44c8_s_p6_0,
  119966. _vq_quantmap__44c8_s_p6_0,
  119967. 13,
  119968. 13
  119969. };
  119970. static static_codebook _44c8_s_p6_0 = {
  119971. 2, 169,
  119972. _vq_lengthlist__44c8_s_p6_0,
  119973. 1, -526516224, 1616117760, 4, 0,
  119974. _vq_quantlist__44c8_s_p6_0,
  119975. NULL,
  119976. &_vq_auxt__44c8_s_p6_0,
  119977. NULL,
  119978. 0
  119979. };
  119980. static long _vq_quantlist__44c8_s_p6_1[] = {
  119981. 2,
  119982. 1,
  119983. 3,
  119984. 0,
  119985. 4,
  119986. };
  119987. static long _vq_lengthlist__44c8_s_p6_1[] = {
  119988. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119989. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119990. };
  119991. static float _vq_quantthresh__44c8_s_p6_1[] = {
  119992. -1.5, -0.5, 0.5, 1.5,
  119993. };
  119994. static long _vq_quantmap__44c8_s_p6_1[] = {
  119995. 3, 1, 0, 2, 4,
  119996. };
  119997. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  119998. _vq_quantthresh__44c8_s_p6_1,
  119999. _vq_quantmap__44c8_s_p6_1,
  120000. 5,
  120001. 5
  120002. };
  120003. static static_codebook _44c8_s_p6_1 = {
  120004. 2, 25,
  120005. _vq_lengthlist__44c8_s_p6_1,
  120006. 1, -533725184, 1611661312, 3, 0,
  120007. _vq_quantlist__44c8_s_p6_1,
  120008. NULL,
  120009. &_vq_auxt__44c8_s_p6_1,
  120010. NULL,
  120011. 0
  120012. };
  120013. static long _vq_quantlist__44c8_s_p7_0[] = {
  120014. 6,
  120015. 5,
  120016. 7,
  120017. 4,
  120018. 8,
  120019. 3,
  120020. 9,
  120021. 2,
  120022. 10,
  120023. 1,
  120024. 11,
  120025. 0,
  120026. 12,
  120027. };
  120028. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120029. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120030. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120031. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120032. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120033. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120034. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120035. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120036. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120037. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120038. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120039. 20,13,13,13,13,14,13,15,15,
  120040. };
  120041. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120042. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120043. 27.5, 38.5, 49.5, 60.5,
  120044. };
  120045. static long _vq_quantmap__44c8_s_p7_0[] = {
  120046. 11, 9, 7, 5, 3, 1, 0, 2,
  120047. 4, 6, 8, 10, 12,
  120048. };
  120049. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120050. _vq_quantthresh__44c8_s_p7_0,
  120051. _vq_quantmap__44c8_s_p7_0,
  120052. 13,
  120053. 13
  120054. };
  120055. static static_codebook _44c8_s_p7_0 = {
  120056. 2, 169,
  120057. _vq_lengthlist__44c8_s_p7_0,
  120058. 1, -523206656, 1618345984, 4, 0,
  120059. _vq_quantlist__44c8_s_p7_0,
  120060. NULL,
  120061. &_vq_auxt__44c8_s_p7_0,
  120062. NULL,
  120063. 0
  120064. };
  120065. static long _vq_quantlist__44c8_s_p7_1[] = {
  120066. 5,
  120067. 4,
  120068. 6,
  120069. 3,
  120070. 7,
  120071. 2,
  120072. 8,
  120073. 1,
  120074. 9,
  120075. 0,
  120076. 10,
  120077. };
  120078. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120079. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120080. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120081. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120082. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120083. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120084. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120085. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120086. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120087. };
  120088. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120089. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120090. 3.5, 4.5,
  120091. };
  120092. static long _vq_quantmap__44c8_s_p7_1[] = {
  120093. 9, 7, 5, 3, 1, 0, 2, 4,
  120094. 6, 8, 10,
  120095. };
  120096. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120097. _vq_quantthresh__44c8_s_p7_1,
  120098. _vq_quantmap__44c8_s_p7_1,
  120099. 11,
  120100. 11
  120101. };
  120102. static static_codebook _44c8_s_p7_1 = {
  120103. 2, 121,
  120104. _vq_lengthlist__44c8_s_p7_1,
  120105. 1, -531365888, 1611661312, 4, 0,
  120106. _vq_quantlist__44c8_s_p7_1,
  120107. NULL,
  120108. &_vq_auxt__44c8_s_p7_1,
  120109. NULL,
  120110. 0
  120111. };
  120112. static long _vq_quantlist__44c8_s_p8_0[] = {
  120113. 7,
  120114. 6,
  120115. 8,
  120116. 5,
  120117. 9,
  120118. 4,
  120119. 10,
  120120. 3,
  120121. 11,
  120122. 2,
  120123. 12,
  120124. 1,
  120125. 13,
  120126. 0,
  120127. 14,
  120128. };
  120129. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120130. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120131. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120132. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120133. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120134. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120135. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120136. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120137. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120138. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120139. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120140. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120141. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120142. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120143. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120144. 15,
  120145. };
  120146. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120147. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120148. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120149. };
  120150. static long _vq_quantmap__44c8_s_p8_0[] = {
  120151. 13, 11, 9, 7, 5, 3, 1, 0,
  120152. 2, 4, 6, 8, 10, 12, 14,
  120153. };
  120154. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120155. _vq_quantthresh__44c8_s_p8_0,
  120156. _vq_quantmap__44c8_s_p8_0,
  120157. 15,
  120158. 15
  120159. };
  120160. static static_codebook _44c8_s_p8_0 = {
  120161. 2, 225,
  120162. _vq_lengthlist__44c8_s_p8_0,
  120163. 1, -520986624, 1620377600, 4, 0,
  120164. _vq_quantlist__44c8_s_p8_0,
  120165. NULL,
  120166. &_vq_auxt__44c8_s_p8_0,
  120167. NULL,
  120168. 0
  120169. };
  120170. static long _vq_quantlist__44c8_s_p8_1[] = {
  120171. 10,
  120172. 9,
  120173. 11,
  120174. 8,
  120175. 12,
  120176. 7,
  120177. 13,
  120178. 6,
  120179. 14,
  120180. 5,
  120181. 15,
  120182. 4,
  120183. 16,
  120184. 3,
  120185. 17,
  120186. 2,
  120187. 18,
  120188. 1,
  120189. 19,
  120190. 0,
  120191. 20,
  120192. };
  120193. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120194. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120195. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120196. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120197. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120198. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120199. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120200. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120201. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120202. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120203. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120204. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120205. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120206. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120207. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120208. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120209. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120210. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120211. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120212. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120213. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120214. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120215. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120216. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120217. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120218. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120219. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120220. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120221. 10, 9, 9,10,10, 9,10, 9, 9,
  120222. };
  120223. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120224. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120225. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120226. 6.5, 7.5, 8.5, 9.5,
  120227. };
  120228. static long _vq_quantmap__44c8_s_p8_1[] = {
  120229. 19, 17, 15, 13, 11, 9, 7, 5,
  120230. 3, 1, 0, 2, 4, 6, 8, 10,
  120231. 12, 14, 16, 18, 20,
  120232. };
  120233. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120234. _vq_quantthresh__44c8_s_p8_1,
  120235. _vq_quantmap__44c8_s_p8_1,
  120236. 21,
  120237. 21
  120238. };
  120239. static static_codebook _44c8_s_p8_1 = {
  120240. 2, 441,
  120241. _vq_lengthlist__44c8_s_p8_1,
  120242. 1, -529268736, 1611661312, 5, 0,
  120243. _vq_quantlist__44c8_s_p8_1,
  120244. NULL,
  120245. &_vq_auxt__44c8_s_p8_1,
  120246. NULL,
  120247. 0
  120248. };
  120249. static long _vq_quantlist__44c8_s_p9_0[] = {
  120250. 8,
  120251. 7,
  120252. 9,
  120253. 6,
  120254. 10,
  120255. 5,
  120256. 11,
  120257. 4,
  120258. 12,
  120259. 3,
  120260. 13,
  120261. 2,
  120262. 14,
  120263. 1,
  120264. 15,
  120265. 0,
  120266. 16,
  120267. };
  120268. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120269. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120270. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120271. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120272. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120273. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120274. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120275. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120276. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120277. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120278. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120279. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120280. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120281. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120282. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120283. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120284. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120285. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120286. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120287. 10,
  120288. };
  120289. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120290. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120291. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120292. };
  120293. static long _vq_quantmap__44c8_s_p9_0[] = {
  120294. 15, 13, 11, 9, 7, 5, 3, 1,
  120295. 0, 2, 4, 6, 8, 10, 12, 14,
  120296. 16,
  120297. };
  120298. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120299. _vq_quantthresh__44c8_s_p9_0,
  120300. _vq_quantmap__44c8_s_p9_0,
  120301. 17,
  120302. 17
  120303. };
  120304. static static_codebook _44c8_s_p9_0 = {
  120305. 2, 289,
  120306. _vq_lengthlist__44c8_s_p9_0,
  120307. 1, -509798400, 1631393792, 5, 0,
  120308. _vq_quantlist__44c8_s_p9_0,
  120309. NULL,
  120310. &_vq_auxt__44c8_s_p9_0,
  120311. NULL,
  120312. 0
  120313. };
  120314. static long _vq_quantlist__44c8_s_p9_1[] = {
  120315. 9,
  120316. 8,
  120317. 10,
  120318. 7,
  120319. 11,
  120320. 6,
  120321. 12,
  120322. 5,
  120323. 13,
  120324. 4,
  120325. 14,
  120326. 3,
  120327. 15,
  120328. 2,
  120329. 16,
  120330. 1,
  120331. 17,
  120332. 0,
  120333. 18,
  120334. };
  120335. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120336. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120337. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120338. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120339. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120340. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120341. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120342. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120343. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120344. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120345. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120346. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120347. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120348. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120349. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120350. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120351. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120352. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120353. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120354. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120355. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120356. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120357. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120358. 14,13,13,14,14,15,14,15,14,
  120359. };
  120360. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120361. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120362. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120363. 367.5, 416.5,
  120364. };
  120365. static long _vq_quantmap__44c8_s_p9_1[] = {
  120366. 17, 15, 13, 11, 9, 7, 5, 3,
  120367. 1, 0, 2, 4, 6, 8, 10, 12,
  120368. 14, 16, 18,
  120369. };
  120370. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120371. _vq_quantthresh__44c8_s_p9_1,
  120372. _vq_quantmap__44c8_s_p9_1,
  120373. 19,
  120374. 19
  120375. };
  120376. static static_codebook _44c8_s_p9_1 = {
  120377. 2, 361,
  120378. _vq_lengthlist__44c8_s_p9_1,
  120379. 1, -518287360, 1622704128, 5, 0,
  120380. _vq_quantlist__44c8_s_p9_1,
  120381. NULL,
  120382. &_vq_auxt__44c8_s_p9_1,
  120383. NULL,
  120384. 0
  120385. };
  120386. static long _vq_quantlist__44c8_s_p9_2[] = {
  120387. 24,
  120388. 23,
  120389. 25,
  120390. 22,
  120391. 26,
  120392. 21,
  120393. 27,
  120394. 20,
  120395. 28,
  120396. 19,
  120397. 29,
  120398. 18,
  120399. 30,
  120400. 17,
  120401. 31,
  120402. 16,
  120403. 32,
  120404. 15,
  120405. 33,
  120406. 14,
  120407. 34,
  120408. 13,
  120409. 35,
  120410. 12,
  120411. 36,
  120412. 11,
  120413. 37,
  120414. 10,
  120415. 38,
  120416. 9,
  120417. 39,
  120418. 8,
  120419. 40,
  120420. 7,
  120421. 41,
  120422. 6,
  120423. 42,
  120424. 5,
  120425. 43,
  120426. 4,
  120427. 44,
  120428. 3,
  120429. 45,
  120430. 2,
  120431. 46,
  120432. 1,
  120433. 47,
  120434. 0,
  120435. 48,
  120436. };
  120437. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120438. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120439. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120440. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120441. 7,
  120442. };
  120443. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120444. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120445. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120446. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120447. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120448. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120449. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120450. };
  120451. static long _vq_quantmap__44c8_s_p9_2[] = {
  120452. 47, 45, 43, 41, 39, 37, 35, 33,
  120453. 31, 29, 27, 25, 23, 21, 19, 17,
  120454. 15, 13, 11, 9, 7, 5, 3, 1,
  120455. 0, 2, 4, 6, 8, 10, 12, 14,
  120456. 16, 18, 20, 22, 24, 26, 28, 30,
  120457. 32, 34, 36, 38, 40, 42, 44, 46,
  120458. 48,
  120459. };
  120460. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120461. _vq_quantthresh__44c8_s_p9_2,
  120462. _vq_quantmap__44c8_s_p9_2,
  120463. 49,
  120464. 49
  120465. };
  120466. static static_codebook _44c8_s_p9_2 = {
  120467. 1, 49,
  120468. _vq_lengthlist__44c8_s_p9_2,
  120469. 1, -526909440, 1611661312, 6, 0,
  120470. _vq_quantlist__44c8_s_p9_2,
  120471. NULL,
  120472. &_vq_auxt__44c8_s_p9_2,
  120473. NULL,
  120474. 0
  120475. };
  120476. static long _huff_lengthlist__44c8_s_short[] = {
  120477. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120478. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120479. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120480. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120481. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120482. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120483. 10, 9,11,14,
  120484. };
  120485. static static_codebook _huff_book__44c8_s_short = {
  120486. 2, 100,
  120487. _huff_lengthlist__44c8_s_short,
  120488. 0, 0, 0, 0, 0,
  120489. NULL,
  120490. NULL,
  120491. NULL,
  120492. NULL,
  120493. 0
  120494. };
  120495. static long _huff_lengthlist__44c9_s_long[] = {
  120496. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120497. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120498. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120499. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120500. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120501. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120502. 10, 9, 8, 9,
  120503. };
  120504. static static_codebook _huff_book__44c9_s_long = {
  120505. 2, 100,
  120506. _huff_lengthlist__44c9_s_long,
  120507. 0, 0, 0, 0, 0,
  120508. NULL,
  120509. NULL,
  120510. NULL,
  120511. NULL,
  120512. 0
  120513. };
  120514. static long _vq_quantlist__44c9_s_p1_0[] = {
  120515. 1,
  120516. 0,
  120517. 2,
  120518. };
  120519. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120520. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120521. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120522. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120523. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120524. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120525. 7,
  120526. };
  120527. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120528. -0.5, 0.5,
  120529. };
  120530. static long _vq_quantmap__44c9_s_p1_0[] = {
  120531. 1, 0, 2,
  120532. };
  120533. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120534. _vq_quantthresh__44c9_s_p1_0,
  120535. _vq_quantmap__44c9_s_p1_0,
  120536. 3,
  120537. 3
  120538. };
  120539. static static_codebook _44c9_s_p1_0 = {
  120540. 4, 81,
  120541. _vq_lengthlist__44c9_s_p1_0,
  120542. 1, -535822336, 1611661312, 2, 0,
  120543. _vq_quantlist__44c9_s_p1_0,
  120544. NULL,
  120545. &_vq_auxt__44c9_s_p1_0,
  120546. NULL,
  120547. 0
  120548. };
  120549. static long _vq_quantlist__44c9_s_p2_0[] = {
  120550. 2,
  120551. 1,
  120552. 3,
  120553. 0,
  120554. 4,
  120555. };
  120556. static long _vq_lengthlist__44c9_s_p2_0[] = {
  120557. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120558. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  120559. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  120560. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  120561. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  120562. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  120563. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  120564. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  120565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120566. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  120567. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  120568. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  120569. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  120570. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  120571. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  120572. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  120573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120574. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  120575. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  120576. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  120577. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  120578. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  120579. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  120580. 12,12, 0, 0, 0,12,12, 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. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  120583. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  120584. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  120585. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  120586. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  120587. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  120588. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120593. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  120594. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  120595. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  120596. 12,
  120597. };
  120598. static float _vq_quantthresh__44c9_s_p2_0[] = {
  120599. -1.5, -0.5, 0.5, 1.5,
  120600. };
  120601. static long _vq_quantmap__44c9_s_p2_0[] = {
  120602. 3, 1, 0, 2, 4,
  120603. };
  120604. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  120605. _vq_quantthresh__44c9_s_p2_0,
  120606. _vq_quantmap__44c9_s_p2_0,
  120607. 5,
  120608. 5
  120609. };
  120610. static static_codebook _44c9_s_p2_0 = {
  120611. 4, 625,
  120612. _vq_lengthlist__44c9_s_p2_0,
  120613. 1, -533725184, 1611661312, 3, 0,
  120614. _vq_quantlist__44c9_s_p2_0,
  120615. NULL,
  120616. &_vq_auxt__44c9_s_p2_0,
  120617. NULL,
  120618. 0
  120619. };
  120620. static long _vq_quantlist__44c9_s_p3_0[] = {
  120621. 4,
  120622. 3,
  120623. 5,
  120624. 2,
  120625. 6,
  120626. 1,
  120627. 7,
  120628. 0,
  120629. 8,
  120630. };
  120631. static long _vq_lengthlist__44c9_s_p3_0[] = {
  120632. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  120633. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  120634. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  120635. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  120636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120637. 0,
  120638. };
  120639. static float _vq_quantthresh__44c9_s_p3_0[] = {
  120640. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120641. };
  120642. static long _vq_quantmap__44c9_s_p3_0[] = {
  120643. 7, 5, 3, 1, 0, 2, 4, 6,
  120644. 8,
  120645. };
  120646. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  120647. _vq_quantthresh__44c9_s_p3_0,
  120648. _vq_quantmap__44c9_s_p3_0,
  120649. 9,
  120650. 9
  120651. };
  120652. static static_codebook _44c9_s_p3_0 = {
  120653. 2, 81,
  120654. _vq_lengthlist__44c9_s_p3_0,
  120655. 1, -531628032, 1611661312, 4, 0,
  120656. _vq_quantlist__44c9_s_p3_0,
  120657. NULL,
  120658. &_vq_auxt__44c9_s_p3_0,
  120659. NULL,
  120660. 0
  120661. };
  120662. static long _vq_quantlist__44c9_s_p4_0[] = {
  120663. 8,
  120664. 7,
  120665. 9,
  120666. 6,
  120667. 10,
  120668. 5,
  120669. 11,
  120670. 4,
  120671. 12,
  120672. 3,
  120673. 13,
  120674. 2,
  120675. 14,
  120676. 1,
  120677. 15,
  120678. 0,
  120679. 16,
  120680. };
  120681. static long _vq_lengthlist__44c9_s_p4_0[] = {
  120682. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  120683. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  120684. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  120685. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  120686. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  120687. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  120688. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  120689. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120690. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120691. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  120692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120700. 0,
  120701. };
  120702. static float _vq_quantthresh__44c9_s_p4_0[] = {
  120703. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120704. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120705. };
  120706. static long _vq_quantmap__44c9_s_p4_0[] = {
  120707. 15, 13, 11, 9, 7, 5, 3, 1,
  120708. 0, 2, 4, 6, 8, 10, 12, 14,
  120709. 16,
  120710. };
  120711. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  120712. _vq_quantthresh__44c9_s_p4_0,
  120713. _vq_quantmap__44c9_s_p4_0,
  120714. 17,
  120715. 17
  120716. };
  120717. static static_codebook _44c9_s_p4_0 = {
  120718. 2, 289,
  120719. _vq_lengthlist__44c9_s_p4_0,
  120720. 1, -529530880, 1611661312, 5, 0,
  120721. _vq_quantlist__44c9_s_p4_0,
  120722. NULL,
  120723. &_vq_auxt__44c9_s_p4_0,
  120724. NULL,
  120725. 0
  120726. };
  120727. static long _vq_quantlist__44c9_s_p5_0[] = {
  120728. 1,
  120729. 0,
  120730. 2,
  120731. };
  120732. static long _vq_lengthlist__44c9_s_p5_0[] = {
  120733. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  120734. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  120735. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  120736. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  120737. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  120738. 12,
  120739. };
  120740. static float _vq_quantthresh__44c9_s_p5_0[] = {
  120741. -5.5, 5.5,
  120742. };
  120743. static long _vq_quantmap__44c9_s_p5_0[] = {
  120744. 1, 0, 2,
  120745. };
  120746. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  120747. _vq_quantthresh__44c9_s_p5_0,
  120748. _vq_quantmap__44c9_s_p5_0,
  120749. 3,
  120750. 3
  120751. };
  120752. static static_codebook _44c9_s_p5_0 = {
  120753. 4, 81,
  120754. _vq_lengthlist__44c9_s_p5_0,
  120755. 1, -529137664, 1618345984, 2, 0,
  120756. _vq_quantlist__44c9_s_p5_0,
  120757. NULL,
  120758. &_vq_auxt__44c9_s_p5_0,
  120759. NULL,
  120760. 0
  120761. };
  120762. static long _vq_quantlist__44c9_s_p5_1[] = {
  120763. 5,
  120764. 4,
  120765. 6,
  120766. 3,
  120767. 7,
  120768. 2,
  120769. 8,
  120770. 1,
  120771. 9,
  120772. 0,
  120773. 10,
  120774. };
  120775. static long _vq_lengthlist__44c9_s_p5_1[] = {
  120776. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  120777. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  120778. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  120779. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  120780. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  120781. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  120782. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  120783. 11,11,11, 7, 7, 7, 7, 7, 7,
  120784. };
  120785. static float _vq_quantthresh__44c9_s_p5_1[] = {
  120786. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120787. 3.5, 4.5,
  120788. };
  120789. static long _vq_quantmap__44c9_s_p5_1[] = {
  120790. 9, 7, 5, 3, 1, 0, 2, 4,
  120791. 6, 8, 10,
  120792. };
  120793. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  120794. _vq_quantthresh__44c9_s_p5_1,
  120795. _vq_quantmap__44c9_s_p5_1,
  120796. 11,
  120797. 11
  120798. };
  120799. static static_codebook _44c9_s_p5_1 = {
  120800. 2, 121,
  120801. _vq_lengthlist__44c9_s_p5_1,
  120802. 1, -531365888, 1611661312, 4, 0,
  120803. _vq_quantlist__44c9_s_p5_1,
  120804. NULL,
  120805. &_vq_auxt__44c9_s_p5_1,
  120806. NULL,
  120807. 0
  120808. };
  120809. static long _vq_quantlist__44c9_s_p6_0[] = {
  120810. 6,
  120811. 5,
  120812. 7,
  120813. 4,
  120814. 8,
  120815. 3,
  120816. 9,
  120817. 2,
  120818. 10,
  120819. 1,
  120820. 11,
  120821. 0,
  120822. 12,
  120823. };
  120824. static long _vq_lengthlist__44c9_s_p6_0[] = {
  120825. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  120826. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  120827. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  120828. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120829. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  120830. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  120831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120835. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120836. };
  120837. static float _vq_quantthresh__44c9_s_p6_0[] = {
  120838. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120839. 12.5, 17.5, 22.5, 27.5,
  120840. };
  120841. static long _vq_quantmap__44c9_s_p6_0[] = {
  120842. 11, 9, 7, 5, 3, 1, 0, 2,
  120843. 4, 6, 8, 10, 12,
  120844. };
  120845. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  120846. _vq_quantthresh__44c9_s_p6_0,
  120847. _vq_quantmap__44c9_s_p6_0,
  120848. 13,
  120849. 13
  120850. };
  120851. static static_codebook _44c9_s_p6_0 = {
  120852. 2, 169,
  120853. _vq_lengthlist__44c9_s_p6_0,
  120854. 1, -526516224, 1616117760, 4, 0,
  120855. _vq_quantlist__44c9_s_p6_0,
  120856. NULL,
  120857. &_vq_auxt__44c9_s_p6_0,
  120858. NULL,
  120859. 0
  120860. };
  120861. static long _vq_quantlist__44c9_s_p6_1[] = {
  120862. 2,
  120863. 1,
  120864. 3,
  120865. 0,
  120866. 4,
  120867. };
  120868. static long _vq_lengthlist__44c9_s_p6_1[] = {
  120869. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  120870. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  120871. };
  120872. static float _vq_quantthresh__44c9_s_p6_1[] = {
  120873. -1.5, -0.5, 0.5, 1.5,
  120874. };
  120875. static long _vq_quantmap__44c9_s_p6_1[] = {
  120876. 3, 1, 0, 2, 4,
  120877. };
  120878. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  120879. _vq_quantthresh__44c9_s_p6_1,
  120880. _vq_quantmap__44c9_s_p6_1,
  120881. 5,
  120882. 5
  120883. };
  120884. static static_codebook _44c9_s_p6_1 = {
  120885. 2, 25,
  120886. _vq_lengthlist__44c9_s_p6_1,
  120887. 1, -533725184, 1611661312, 3, 0,
  120888. _vq_quantlist__44c9_s_p6_1,
  120889. NULL,
  120890. &_vq_auxt__44c9_s_p6_1,
  120891. NULL,
  120892. 0
  120893. };
  120894. static long _vq_quantlist__44c9_s_p7_0[] = {
  120895. 6,
  120896. 5,
  120897. 7,
  120898. 4,
  120899. 8,
  120900. 3,
  120901. 9,
  120902. 2,
  120903. 10,
  120904. 1,
  120905. 11,
  120906. 0,
  120907. 12,
  120908. };
  120909. static long _vq_lengthlist__44c9_s_p7_0[] = {
  120910. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  120911. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  120912. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  120913. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  120914. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  120915. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  120916. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  120917. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  120918. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  120919. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  120920. 19,12,12,12,12,13,13,14,14,
  120921. };
  120922. static float _vq_quantthresh__44c9_s_p7_0[] = {
  120923. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120924. 27.5, 38.5, 49.5, 60.5,
  120925. };
  120926. static long _vq_quantmap__44c9_s_p7_0[] = {
  120927. 11, 9, 7, 5, 3, 1, 0, 2,
  120928. 4, 6, 8, 10, 12,
  120929. };
  120930. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  120931. _vq_quantthresh__44c9_s_p7_0,
  120932. _vq_quantmap__44c9_s_p7_0,
  120933. 13,
  120934. 13
  120935. };
  120936. static static_codebook _44c9_s_p7_0 = {
  120937. 2, 169,
  120938. _vq_lengthlist__44c9_s_p7_0,
  120939. 1, -523206656, 1618345984, 4, 0,
  120940. _vq_quantlist__44c9_s_p7_0,
  120941. NULL,
  120942. &_vq_auxt__44c9_s_p7_0,
  120943. NULL,
  120944. 0
  120945. };
  120946. static long _vq_quantlist__44c9_s_p7_1[] = {
  120947. 5,
  120948. 4,
  120949. 6,
  120950. 3,
  120951. 7,
  120952. 2,
  120953. 8,
  120954. 1,
  120955. 9,
  120956. 0,
  120957. 10,
  120958. };
  120959. static long _vq_lengthlist__44c9_s_p7_1[] = {
  120960. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  120961. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120962. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  120963. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120964. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120965. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120966. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120967. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120968. };
  120969. static float _vq_quantthresh__44c9_s_p7_1[] = {
  120970. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120971. 3.5, 4.5,
  120972. };
  120973. static long _vq_quantmap__44c9_s_p7_1[] = {
  120974. 9, 7, 5, 3, 1, 0, 2, 4,
  120975. 6, 8, 10,
  120976. };
  120977. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  120978. _vq_quantthresh__44c9_s_p7_1,
  120979. _vq_quantmap__44c9_s_p7_1,
  120980. 11,
  120981. 11
  120982. };
  120983. static static_codebook _44c9_s_p7_1 = {
  120984. 2, 121,
  120985. _vq_lengthlist__44c9_s_p7_1,
  120986. 1, -531365888, 1611661312, 4, 0,
  120987. _vq_quantlist__44c9_s_p7_1,
  120988. NULL,
  120989. &_vq_auxt__44c9_s_p7_1,
  120990. NULL,
  120991. 0
  120992. };
  120993. static long _vq_quantlist__44c9_s_p8_0[] = {
  120994. 7,
  120995. 6,
  120996. 8,
  120997. 5,
  120998. 9,
  120999. 4,
  121000. 10,
  121001. 3,
  121002. 11,
  121003. 2,
  121004. 12,
  121005. 1,
  121006. 13,
  121007. 0,
  121008. 14,
  121009. };
  121010. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121011. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121012. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121013. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121014. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121015. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121016. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121017. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121018. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121019. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121020. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121021. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121022. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121023. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121024. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121025. 14,
  121026. };
  121027. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121028. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121029. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121030. };
  121031. static long _vq_quantmap__44c9_s_p8_0[] = {
  121032. 13, 11, 9, 7, 5, 3, 1, 0,
  121033. 2, 4, 6, 8, 10, 12, 14,
  121034. };
  121035. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121036. _vq_quantthresh__44c9_s_p8_0,
  121037. _vq_quantmap__44c9_s_p8_0,
  121038. 15,
  121039. 15
  121040. };
  121041. static static_codebook _44c9_s_p8_0 = {
  121042. 2, 225,
  121043. _vq_lengthlist__44c9_s_p8_0,
  121044. 1, -520986624, 1620377600, 4, 0,
  121045. _vq_quantlist__44c9_s_p8_0,
  121046. NULL,
  121047. &_vq_auxt__44c9_s_p8_0,
  121048. NULL,
  121049. 0
  121050. };
  121051. static long _vq_quantlist__44c9_s_p8_1[] = {
  121052. 10,
  121053. 9,
  121054. 11,
  121055. 8,
  121056. 12,
  121057. 7,
  121058. 13,
  121059. 6,
  121060. 14,
  121061. 5,
  121062. 15,
  121063. 4,
  121064. 16,
  121065. 3,
  121066. 17,
  121067. 2,
  121068. 18,
  121069. 1,
  121070. 19,
  121071. 0,
  121072. 20,
  121073. };
  121074. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121075. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121076. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121077. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121078. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121079. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121080. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121081. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121082. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121083. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121084. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121085. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121086. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121087. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121088. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121089. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121090. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121091. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121092. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121093. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121094. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121095. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121096. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121097. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121098. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121099. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121100. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121101. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121102. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121103. };
  121104. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121105. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121106. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121107. 6.5, 7.5, 8.5, 9.5,
  121108. };
  121109. static long _vq_quantmap__44c9_s_p8_1[] = {
  121110. 19, 17, 15, 13, 11, 9, 7, 5,
  121111. 3, 1, 0, 2, 4, 6, 8, 10,
  121112. 12, 14, 16, 18, 20,
  121113. };
  121114. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121115. _vq_quantthresh__44c9_s_p8_1,
  121116. _vq_quantmap__44c9_s_p8_1,
  121117. 21,
  121118. 21
  121119. };
  121120. static static_codebook _44c9_s_p8_1 = {
  121121. 2, 441,
  121122. _vq_lengthlist__44c9_s_p8_1,
  121123. 1, -529268736, 1611661312, 5, 0,
  121124. _vq_quantlist__44c9_s_p8_1,
  121125. NULL,
  121126. &_vq_auxt__44c9_s_p8_1,
  121127. NULL,
  121128. 0
  121129. };
  121130. static long _vq_quantlist__44c9_s_p9_0[] = {
  121131. 9,
  121132. 8,
  121133. 10,
  121134. 7,
  121135. 11,
  121136. 6,
  121137. 12,
  121138. 5,
  121139. 13,
  121140. 4,
  121141. 14,
  121142. 3,
  121143. 15,
  121144. 2,
  121145. 16,
  121146. 1,
  121147. 17,
  121148. 0,
  121149. 18,
  121150. };
  121151. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121152. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121153. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121154. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121155. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121156. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121157. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121158. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121159. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121160. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121161. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121162. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121163. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121164. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121165. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121166. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121167. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121168. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121169. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121170. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121171. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121172. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121173. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121174. 11,11,11,11,11,11,11,11,11,
  121175. };
  121176. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121177. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121178. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121179. 6982.5, 7913.5,
  121180. };
  121181. static long _vq_quantmap__44c9_s_p9_0[] = {
  121182. 17, 15, 13, 11, 9, 7, 5, 3,
  121183. 1, 0, 2, 4, 6, 8, 10, 12,
  121184. 14, 16, 18,
  121185. };
  121186. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121187. _vq_quantthresh__44c9_s_p9_0,
  121188. _vq_quantmap__44c9_s_p9_0,
  121189. 19,
  121190. 19
  121191. };
  121192. static static_codebook _44c9_s_p9_0 = {
  121193. 2, 361,
  121194. _vq_lengthlist__44c9_s_p9_0,
  121195. 1, -508535424, 1631393792, 5, 0,
  121196. _vq_quantlist__44c9_s_p9_0,
  121197. NULL,
  121198. &_vq_auxt__44c9_s_p9_0,
  121199. NULL,
  121200. 0
  121201. };
  121202. static long _vq_quantlist__44c9_s_p9_1[] = {
  121203. 9,
  121204. 8,
  121205. 10,
  121206. 7,
  121207. 11,
  121208. 6,
  121209. 12,
  121210. 5,
  121211. 13,
  121212. 4,
  121213. 14,
  121214. 3,
  121215. 15,
  121216. 2,
  121217. 16,
  121218. 1,
  121219. 17,
  121220. 0,
  121221. 18,
  121222. };
  121223. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121224. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121225. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121226. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121227. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121228. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121229. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121230. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121231. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121232. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121233. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121234. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121235. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121236. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121237. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121238. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121239. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121240. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121241. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121242. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121243. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121244. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121245. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121246. 13,13,13,14,13,14,15,15,15,
  121247. };
  121248. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121249. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121250. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121251. 367.5, 416.5,
  121252. };
  121253. static long _vq_quantmap__44c9_s_p9_1[] = {
  121254. 17, 15, 13, 11, 9, 7, 5, 3,
  121255. 1, 0, 2, 4, 6, 8, 10, 12,
  121256. 14, 16, 18,
  121257. };
  121258. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121259. _vq_quantthresh__44c9_s_p9_1,
  121260. _vq_quantmap__44c9_s_p9_1,
  121261. 19,
  121262. 19
  121263. };
  121264. static static_codebook _44c9_s_p9_1 = {
  121265. 2, 361,
  121266. _vq_lengthlist__44c9_s_p9_1,
  121267. 1, -518287360, 1622704128, 5, 0,
  121268. _vq_quantlist__44c9_s_p9_1,
  121269. NULL,
  121270. &_vq_auxt__44c9_s_p9_1,
  121271. NULL,
  121272. 0
  121273. };
  121274. static long _vq_quantlist__44c9_s_p9_2[] = {
  121275. 24,
  121276. 23,
  121277. 25,
  121278. 22,
  121279. 26,
  121280. 21,
  121281. 27,
  121282. 20,
  121283. 28,
  121284. 19,
  121285. 29,
  121286. 18,
  121287. 30,
  121288. 17,
  121289. 31,
  121290. 16,
  121291. 32,
  121292. 15,
  121293. 33,
  121294. 14,
  121295. 34,
  121296. 13,
  121297. 35,
  121298. 12,
  121299. 36,
  121300. 11,
  121301. 37,
  121302. 10,
  121303. 38,
  121304. 9,
  121305. 39,
  121306. 8,
  121307. 40,
  121308. 7,
  121309. 41,
  121310. 6,
  121311. 42,
  121312. 5,
  121313. 43,
  121314. 4,
  121315. 44,
  121316. 3,
  121317. 45,
  121318. 2,
  121319. 46,
  121320. 1,
  121321. 47,
  121322. 0,
  121323. 48,
  121324. };
  121325. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121326. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121327. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121328. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121329. 7,
  121330. };
  121331. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121332. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121333. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121334. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121335. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121336. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121337. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121338. };
  121339. static long _vq_quantmap__44c9_s_p9_2[] = {
  121340. 47, 45, 43, 41, 39, 37, 35, 33,
  121341. 31, 29, 27, 25, 23, 21, 19, 17,
  121342. 15, 13, 11, 9, 7, 5, 3, 1,
  121343. 0, 2, 4, 6, 8, 10, 12, 14,
  121344. 16, 18, 20, 22, 24, 26, 28, 30,
  121345. 32, 34, 36, 38, 40, 42, 44, 46,
  121346. 48,
  121347. };
  121348. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121349. _vq_quantthresh__44c9_s_p9_2,
  121350. _vq_quantmap__44c9_s_p9_2,
  121351. 49,
  121352. 49
  121353. };
  121354. static static_codebook _44c9_s_p9_2 = {
  121355. 1, 49,
  121356. _vq_lengthlist__44c9_s_p9_2,
  121357. 1, -526909440, 1611661312, 6, 0,
  121358. _vq_quantlist__44c9_s_p9_2,
  121359. NULL,
  121360. &_vq_auxt__44c9_s_p9_2,
  121361. NULL,
  121362. 0
  121363. };
  121364. static long _huff_lengthlist__44c9_s_short[] = {
  121365. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121366. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121367. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121368. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121369. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121370. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121371. 9, 8,10,13,
  121372. };
  121373. static static_codebook _huff_book__44c9_s_short = {
  121374. 2, 100,
  121375. _huff_lengthlist__44c9_s_short,
  121376. 0, 0, 0, 0, 0,
  121377. NULL,
  121378. NULL,
  121379. NULL,
  121380. NULL,
  121381. 0
  121382. };
  121383. static long _huff_lengthlist__44c0_s_long[] = {
  121384. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121385. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121386. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121387. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121388. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121389. 12,
  121390. };
  121391. static static_codebook _huff_book__44c0_s_long = {
  121392. 2, 81,
  121393. _huff_lengthlist__44c0_s_long,
  121394. 0, 0, 0, 0, 0,
  121395. NULL,
  121396. NULL,
  121397. NULL,
  121398. NULL,
  121399. 0
  121400. };
  121401. static long _vq_quantlist__44c0_s_p1_0[] = {
  121402. 1,
  121403. 0,
  121404. 2,
  121405. };
  121406. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121407. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121408. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121413. 0, 0, 0, 7, 9, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121418. 0, 0, 0, 0, 7, 9, 9, 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, 5, 7, 7, 0, 0, 0, 0,
  121453. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  121458. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  121463. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121499. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121504. 0, 0, 0, 0, 0, 9, 9,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121509. 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121744. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121817. 0,
  121818. };
  121819. static float _vq_quantthresh__44c0_s_p1_0[] = {
  121820. -0.5, 0.5,
  121821. };
  121822. static long _vq_quantmap__44c0_s_p1_0[] = {
  121823. 1, 0, 2,
  121824. };
  121825. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  121826. _vq_quantthresh__44c0_s_p1_0,
  121827. _vq_quantmap__44c0_s_p1_0,
  121828. 3,
  121829. 3
  121830. };
  121831. static static_codebook _44c0_s_p1_0 = {
  121832. 8, 6561,
  121833. _vq_lengthlist__44c0_s_p1_0,
  121834. 1, -535822336, 1611661312, 2, 0,
  121835. _vq_quantlist__44c0_s_p1_0,
  121836. NULL,
  121837. &_vq_auxt__44c0_s_p1_0,
  121838. NULL,
  121839. 0
  121840. };
  121841. static long _vq_quantlist__44c0_s_p2_0[] = {
  121842. 2,
  121843. 1,
  121844. 3,
  121845. 0,
  121846. 4,
  121847. };
  121848. static long _vq_lengthlist__44c0_s_p2_0[] = {
  121849. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  121851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121852. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  121854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121855. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  121856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121888. 0,
  121889. };
  121890. static float _vq_quantthresh__44c0_s_p2_0[] = {
  121891. -1.5, -0.5, 0.5, 1.5,
  121892. };
  121893. static long _vq_quantmap__44c0_s_p2_0[] = {
  121894. 3, 1, 0, 2, 4,
  121895. };
  121896. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  121897. _vq_quantthresh__44c0_s_p2_0,
  121898. _vq_quantmap__44c0_s_p2_0,
  121899. 5,
  121900. 5
  121901. };
  121902. static static_codebook _44c0_s_p2_0 = {
  121903. 4, 625,
  121904. _vq_lengthlist__44c0_s_p2_0,
  121905. 1, -533725184, 1611661312, 3, 0,
  121906. _vq_quantlist__44c0_s_p2_0,
  121907. NULL,
  121908. &_vq_auxt__44c0_s_p2_0,
  121909. NULL,
  121910. 0
  121911. };
  121912. static long _vq_quantlist__44c0_s_p3_0[] = {
  121913. 4,
  121914. 3,
  121915. 5,
  121916. 2,
  121917. 6,
  121918. 1,
  121919. 7,
  121920. 0,
  121921. 8,
  121922. };
  121923. static long _vq_lengthlist__44c0_s_p3_0[] = {
  121924. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  121925. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  121926. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  121927. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  121928. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121929. 0,
  121930. };
  121931. static float _vq_quantthresh__44c0_s_p3_0[] = {
  121932. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121933. };
  121934. static long _vq_quantmap__44c0_s_p3_0[] = {
  121935. 7, 5, 3, 1, 0, 2, 4, 6,
  121936. 8,
  121937. };
  121938. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  121939. _vq_quantthresh__44c0_s_p3_0,
  121940. _vq_quantmap__44c0_s_p3_0,
  121941. 9,
  121942. 9
  121943. };
  121944. static static_codebook _44c0_s_p3_0 = {
  121945. 2, 81,
  121946. _vq_lengthlist__44c0_s_p3_0,
  121947. 1, -531628032, 1611661312, 4, 0,
  121948. _vq_quantlist__44c0_s_p3_0,
  121949. NULL,
  121950. &_vq_auxt__44c0_s_p3_0,
  121951. NULL,
  121952. 0
  121953. };
  121954. static long _vq_quantlist__44c0_s_p4_0[] = {
  121955. 4,
  121956. 3,
  121957. 5,
  121958. 2,
  121959. 6,
  121960. 1,
  121961. 7,
  121962. 0,
  121963. 8,
  121964. };
  121965. static long _vq_lengthlist__44c0_s_p4_0[] = {
  121966. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  121967. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  121968. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  121969. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  121970. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  121971. 10,
  121972. };
  121973. static float _vq_quantthresh__44c0_s_p4_0[] = {
  121974. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121975. };
  121976. static long _vq_quantmap__44c0_s_p4_0[] = {
  121977. 7, 5, 3, 1, 0, 2, 4, 6,
  121978. 8,
  121979. };
  121980. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  121981. _vq_quantthresh__44c0_s_p4_0,
  121982. _vq_quantmap__44c0_s_p4_0,
  121983. 9,
  121984. 9
  121985. };
  121986. static static_codebook _44c0_s_p4_0 = {
  121987. 2, 81,
  121988. _vq_lengthlist__44c0_s_p4_0,
  121989. 1, -531628032, 1611661312, 4, 0,
  121990. _vq_quantlist__44c0_s_p4_0,
  121991. NULL,
  121992. &_vq_auxt__44c0_s_p4_0,
  121993. NULL,
  121994. 0
  121995. };
  121996. static long _vq_quantlist__44c0_s_p5_0[] = {
  121997. 8,
  121998. 7,
  121999. 9,
  122000. 6,
  122001. 10,
  122002. 5,
  122003. 11,
  122004. 4,
  122005. 12,
  122006. 3,
  122007. 13,
  122008. 2,
  122009. 14,
  122010. 1,
  122011. 15,
  122012. 0,
  122013. 16,
  122014. };
  122015. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122016. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122017. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122018. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122019. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122020. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122021. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122022. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122023. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122024. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122025. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122026. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122027. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122028. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122029. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122030. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122031. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122032. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122033. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122034. 14,
  122035. };
  122036. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122037. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122038. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122039. };
  122040. static long _vq_quantmap__44c0_s_p5_0[] = {
  122041. 15, 13, 11, 9, 7, 5, 3, 1,
  122042. 0, 2, 4, 6, 8, 10, 12, 14,
  122043. 16,
  122044. };
  122045. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122046. _vq_quantthresh__44c0_s_p5_0,
  122047. _vq_quantmap__44c0_s_p5_0,
  122048. 17,
  122049. 17
  122050. };
  122051. static static_codebook _44c0_s_p5_0 = {
  122052. 2, 289,
  122053. _vq_lengthlist__44c0_s_p5_0,
  122054. 1, -529530880, 1611661312, 5, 0,
  122055. _vq_quantlist__44c0_s_p5_0,
  122056. NULL,
  122057. &_vq_auxt__44c0_s_p5_0,
  122058. NULL,
  122059. 0
  122060. };
  122061. static long _vq_quantlist__44c0_s_p6_0[] = {
  122062. 1,
  122063. 0,
  122064. 2,
  122065. };
  122066. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122067. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122068. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122069. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122070. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122071. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122072. 10,
  122073. };
  122074. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122075. -5.5, 5.5,
  122076. };
  122077. static long _vq_quantmap__44c0_s_p6_0[] = {
  122078. 1, 0, 2,
  122079. };
  122080. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122081. _vq_quantthresh__44c0_s_p6_0,
  122082. _vq_quantmap__44c0_s_p6_0,
  122083. 3,
  122084. 3
  122085. };
  122086. static static_codebook _44c0_s_p6_0 = {
  122087. 4, 81,
  122088. _vq_lengthlist__44c0_s_p6_0,
  122089. 1, -529137664, 1618345984, 2, 0,
  122090. _vq_quantlist__44c0_s_p6_0,
  122091. NULL,
  122092. &_vq_auxt__44c0_s_p6_0,
  122093. NULL,
  122094. 0
  122095. };
  122096. static long _vq_quantlist__44c0_s_p6_1[] = {
  122097. 5,
  122098. 4,
  122099. 6,
  122100. 3,
  122101. 7,
  122102. 2,
  122103. 8,
  122104. 1,
  122105. 9,
  122106. 0,
  122107. 10,
  122108. };
  122109. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122110. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122111. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122112. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122113. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122114. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122115. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122116. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122117. 10,10,10, 8, 8, 8, 8, 8, 8,
  122118. };
  122119. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122120. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122121. 3.5, 4.5,
  122122. };
  122123. static long _vq_quantmap__44c0_s_p6_1[] = {
  122124. 9, 7, 5, 3, 1, 0, 2, 4,
  122125. 6, 8, 10,
  122126. };
  122127. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122128. _vq_quantthresh__44c0_s_p6_1,
  122129. _vq_quantmap__44c0_s_p6_1,
  122130. 11,
  122131. 11
  122132. };
  122133. static static_codebook _44c0_s_p6_1 = {
  122134. 2, 121,
  122135. _vq_lengthlist__44c0_s_p6_1,
  122136. 1, -531365888, 1611661312, 4, 0,
  122137. _vq_quantlist__44c0_s_p6_1,
  122138. NULL,
  122139. &_vq_auxt__44c0_s_p6_1,
  122140. NULL,
  122141. 0
  122142. };
  122143. static long _vq_quantlist__44c0_s_p7_0[] = {
  122144. 6,
  122145. 5,
  122146. 7,
  122147. 4,
  122148. 8,
  122149. 3,
  122150. 9,
  122151. 2,
  122152. 10,
  122153. 1,
  122154. 11,
  122155. 0,
  122156. 12,
  122157. };
  122158. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122159. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122160. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122161. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122162. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122163. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122164. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122165. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122166. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122167. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122168. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122169. 0,12,12,11,11,12,12,13,13,
  122170. };
  122171. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122172. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122173. 12.5, 17.5, 22.5, 27.5,
  122174. };
  122175. static long _vq_quantmap__44c0_s_p7_0[] = {
  122176. 11, 9, 7, 5, 3, 1, 0, 2,
  122177. 4, 6, 8, 10, 12,
  122178. };
  122179. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122180. _vq_quantthresh__44c0_s_p7_0,
  122181. _vq_quantmap__44c0_s_p7_0,
  122182. 13,
  122183. 13
  122184. };
  122185. static static_codebook _44c0_s_p7_0 = {
  122186. 2, 169,
  122187. _vq_lengthlist__44c0_s_p7_0,
  122188. 1, -526516224, 1616117760, 4, 0,
  122189. _vq_quantlist__44c0_s_p7_0,
  122190. NULL,
  122191. &_vq_auxt__44c0_s_p7_0,
  122192. NULL,
  122193. 0
  122194. };
  122195. static long _vq_quantlist__44c0_s_p7_1[] = {
  122196. 2,
  122197. 1,
  122198. 3,
  122199. 0,
  122200. 4,
  122201. };
  122202. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122203. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122204. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122205. };
  122206. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122207. -1.5, -0.5, 0.5, 1.5,
  122208. };
  122209. static long _vq_quantmap__44c0_s_p7_1[] = {
  122210. 3, 1, 0, 2, 4,
  122211. };
  122212. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122213. _vq_quantthresh__44c0_s_p7_1,
  122214. _vq_quantmap__44c0_s_p7_1,
  122215. 5,
  122216. 5
  122217. };
  122218. static static_codebook _44c0_s_p7_1 = {
  122219. 2, 25,
  122220. _vq_lengthlist__44c0_s_p7_1,
  122221. 1, -533725184, 1611661312, 3, 0,
  122222. _vq_quantlist__44c0_s_p7_1,
  122223. NULL,
  122224. &_vq_auxt__44c0_s_p7_1,
  122225. NULL,
  122226. 0
  122227. };
  122228. static long _vq_quantlist__44c0_s_p8_0[] = {
  122229. 2,
  122230. 1,
  122231. 3,
  122232. 0,
  122233. 4,
  122234. };
  122235. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122236. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122237. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122238. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122239. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122240. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122241. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122242. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122243. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122244. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122245. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122246. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122247. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122248. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122249. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122250. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122251. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122252. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122253. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122254. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122255. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122256. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122257. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122258. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122259. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122260. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122261. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122262. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122263. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122264. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122265. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122266. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122267. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122268. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122269. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122270. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122271. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122272. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122273. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122274. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122275. 11,
  122276. };
  122277. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122278. -331.5, -110.5, 110.5, 331.5,
  122279. };
  122280. static long _vq_quantmap__44c0_s_p8_0[] = {
  122281. 3, 1, 0, 2, 4,
  122282. };
  122283. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122284. _vq_quantthresh__44c0_s_p8_0,
  122285. _vq_quantmap__44c0_s_p8_0,
  122286. 5,
  122287. 5
  122288. };
  122289. static static_codebook _44c0_s_p8_0 = {
  122290. 4, 625,
  122291. _vq_lengthlist__44c0_s_p8_0,
  122292. 1, -518283264, 1627103232, 3, 0,
  122293. _vq_quantlist__44c0_s_p8_0,
  122294. NULL,
  122295. &_vq_auxt__44c0_s_p8_0,
  122296. NULL,
  122297. 0
  122298. };
  122299. static long _vq_quantlist__44c0_s_p8_1[] = {
  122300. 6,
  122301. 5,
  122302. 7,
  122303. 4,
  122304. 8,
  122305. 3,
  122306. 9,
  122307. 2,
  122308. 10,
  122309. 1,
  122310. 11,
  122311. 0,
  122312. 12,
  122313. };
  122314. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122315. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122316. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122317. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122318. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122319. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122320. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122321. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122322. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122323. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122324. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122325. 16,13,13,12,12,14,14,15,13,
  122326. };
  122327. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122328. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122329. 42.5, 59.5, 76.5, 93.5,
  122330. };
  122331. static long _vq_quantmap__44c0_s_p8_1[] = {
  122332. 11, 9, 7, 5, 3, 1, 0, 2,
  122333. 4, 6, 8, 10, 12,
  122334. };
  122335. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122336. _vq_quantthresh__44c0_s_p8_1,
  122337. _vq_quantmap__44c0_s_p8_1,
  122338. 13,
  122339. 13
  122340. };
  122341. static static_codebook _44c0_s_p8_1 = {
  122342. 2, 169,
  122343. _vq_lengthlist__44c0_s_p8_1,
  122344. 1, -522616832, 1620115456, 4, 0,
  122345. _vq_quantlist__44c0_s_p8_1,
  122346. NULL,
  122347. &_vq_auxt__44c0_s_p8_1,
  122348. NULL,
  122349. 0
  122350. };
  122351. static long _vq_quantlist__44c0_s_p8_2[] = {
  122352. 8,
  122353. 7,
  122354. 9,
  122355. 6,
  122356. 10,
  122357. 5,
  122358. 11,
  122359. 4,
  122360. 12,
  122361. 3,
  122362. 13,
  122363. 2,
  122364. 14,
  122365. 1,
  122366. 15,
  122367. 0,
  122368. 16,
  122369. };
  122370. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122371. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122372. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122373. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122374. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122375. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122376. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122377. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122378. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122379. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122380. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122381. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122382. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122383. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122384. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122385. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122386. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122387. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122388. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122389. 10,
  122390. };
  122391. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122392. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122393. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122394. };
  122395. static long _vq_quantmap__44c0_s_p8_2[] = {
  122396. 15, 13, 11, 9, 7, 5, 3, 1,
  122397. 0, 2, 4, 6, 8, 10, 12, 14,
  122398. 16,
  122399. };
  122400. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122401. _vq_quantthresh__44c0_s_p8_2,
  122402. _vq_quantmap__44c0_s_p8_2,
  122403. 17,
  122404. 17
  122405. };
  122406. static static_codebook _44c0_s_p8_2 = {
  122407. 2, 289,
  122408. _vq_lengthlist__44c0_s_p8_2,
  122409. 1, -529530880, 1611661312, 5, 0,
  122410. _vq_quantlist__44c0_s_p8_2,
  122411. NULL,
  122412. &_vq_auxt__44c0_s_p8_2,
  122413. NULL,
  122414. 0
  122415. };
  122416. static long _huff_lengthlist__44c0_s_short[] = {
  122417. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122418. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122419. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122420. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122421. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122422. 12,
  122423. };
  122424. static static_codebook _huff_book__44c0_s_short = {
  122425. 2, 81,
  122426. _huff_lengthlist__44c0_s_short,
  122427. 0, 0, 0, 0, 0,
  122428. NULL,
  122429. NULL,
  122430. NULL,
  122431. NULL,
  122432. 0
  122433. };
  122434. static long _huff_lengthlist__44c0_sm_long[] = {
  122435. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122436. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122437. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122438. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122439. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122440. 13,
  122441. };
  122442. static static_codebook _huff_book__44c0_sm_long = {
  122443. 2, 81,
  122444. _huff_lengthlist__44c0_sm_long,
  122445. 0, 0, 0, 0, 0,
  122446. NULL,
  122447. NULL,
  122448. NULL,
  122449. NULL,
  122450. 0
  122451. };
  122452. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122453. 1,
  122454. 0,
  122455. 2,
  122456. };
  122457. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122458. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122459. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122464. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122469. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 7, 0, 0, 0, 0,
  122504. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  122509. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  122514. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122550. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122555. 0, 0, 0, 0, 0, 9, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122560. 0, 0, 0, 0, 0, 0, 9,10,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122795. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122868. 0,
  122869. };
  122870. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  122871. -0.5, 0.5,
  122872. };
  122873. static long _vq_quantmap__44c0_sm_p1_0[] = {
  122874. 1, 0, 2,
  122875. };
  122876. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  122877. _vq_quantthresh__44c0_sm_p1_0,
  122878. _vq_quantmap__44c0_sm_p1_0,
  122879. 3,
  122880. 3
  122881. };
  122882. static static_codebook _44c0_sm_p1_0 = {
  122883. 8, 6561,
  122884. _vq_lengthlist__44c0_sm_p1_0,
  122885. 1, -535822336, 1611661312, 2, 0,
  122886. _vq_quantlist__44c0_sm_p1_0,
  122887. NULL,
  122888. &_vq_auxt__44c0_sm_p1_0,
  122889. NULL,
  122890. 0
  122891. };
  122892. static long _vq_quantlist__44c0_sm_p2_0[] = {
  122893. 2,
  122894. 1,
  122895. 3,
  122896. 0,
  122897. 4,
  122898. };
  122899. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  122900. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  122902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122903. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122906. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122939. 0,
  122940. };
  122941. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  122942. -1.5, -0.5, 0.5, 1.5,
  122943. };
  122944. static long _vq_quantmap__44c0_sm_p2_0[] = {
  122945. 3, 1, 0, 2, 4,
  122946. };
  122947. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  122948. _vq_quantthresh__44c0_sm_p2_0,
  122949. _vq_quantmap__44c0_sm_p2_0,
  122950. 5,
  122951. 5
  122952. };
  122953. static static_codebook _44c0_sm_p2_0 = {
  122954. 4, 625,
  122955. _vq_lengthlist__44c0_sm_p2_0,
  122956. 1, -533725184, 1611661312, 3, 0,
  122957. _vq_quantlist__44c0_sm_p2_0,
  122958. NULL,
  122959. &_vq_auxt__44c0_sm_p2_0,
  122960. NULL,
  122961. 0
  122962. };
  122963. static long _vq_quantlist__44c0_sm_p3_0[] = {
  122964. 4,
  122965. 3,
  122966. 5,
  122967. 2,
  122968. 6,
  122969. 1,
  122970. 7,
  122971. 0,
  122972. 8,
  122973. };
  122974. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  122975. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  122976. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  122977. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  122978. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  122979. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122980. 0,
  122981. };
  122982. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  122983. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122984. };
  122985. static long _vq_quantmap__44c0_sm_p3_0[] = {
  122986. 7, 5, 3, 1, 0, 2, 4, 6,
  122987. 8,
  122988. };
  122989. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  122990. _vq_quantthresh__44c0_sm_p3_0,
  122991. _vq_quantmap__44c0_sm_p3_0,
  122992. 9,
  122993. 9
  122994. };
  122995. static static_codebook _44c0_sm_p3_0 = {
  122996. 2, 81,
  122997. _vq_lengthlist__44c0_sm_p3_0,
  122998. 1, -531628032, 1611661312, 4, 0,
  122999. _vq_quantlist__44c0_sm_p3_0,
  123000. NULL,
  123001. &_vq_auxt__44c0_sm_p3_0,
  123002. NULL,
  123003. 0
  123004. };
  123005. static long _vq_quantlist__44c0_sm_p4_0[] = {
  123006. 4,
  123007. 3,
  123008. 5,
  123009. 2,
  123010. 6,
  123011. 1,
  123012. 7,
  123013. 0,
  123014. 8,
  123015. };
  123016. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123017. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123018. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123019. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123020. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123021. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123022. 11,
  123023. };
  123024. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123025. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123026. };
  123027. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123028. 7, 5, 3, 1, 0, 2, 4, 6,
  123029. 8,
  123030. };
  123031. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123032. _vq_quantthresh__44c0_sm_p4_0,
  123033. _vq_quantmap__44c0_sm_p4_0,
  123034. 9,
  123035. 9
  123036. };
  123037. static static_codebook _44c0_sm_p4_0 = {
  123038. 2, 81,
  123039. _vq_lengthlist__44c0_sm_p4_0,
  123040. 1, -531628032, 1611661312, 4, 0,
  123041. _vq_quantlist__44c0_sm_p4_0,
  123042. NULL,
  123043. &_vq_auxt__44c0_sm_p4_0,
  123044. NULL,
  123045. 0
  123046. };
  123047. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123048. 8,
  123049. 7,
  123050. 9,
  123051. 6,
  123052. 10,
  123053. 5,
  123054. 11,
  123055. 4,
  123056. 12,
  123057. 3,
  123058. 13,
  123059. 2,
  123060. 14,
  123061. 1,
  123062. 15,
  123063. 0,
  123064. 16,
  123065. };
  123066. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123067. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123068. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123069. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123070. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123071. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123072. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123073. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123074. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123075. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123076. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123077. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123078. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123079. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123080. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123081. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123082. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123083. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123084. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123085. 14,
  123086. };
  123087. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123088. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123089. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123090. };
  123091. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123092. 15, 13, 11, 9, 7, 5, 3, 1,
  123093. 0, 2, 4, 6, 8, 10, 12, 14,
  123094. 16,
  123095. };
  123096. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123097. _vq_quantthresh__44c0_sm_p5_0,
  123098. _vq_quantmap__44c0_sm_p5_0,
  123099. 17,
  123100. 17
  123101. };
  123102. static static_codebook _44c0_sm_p5_0 = {
  123103. 2, 289,
  123104. _vq_lengthlist__44c0_sm_p5_0,
  123105. 1, -529530880, 1611661312, 5, 0,
  123106. _vq_quantlist__44c0_sm_p5_0,
  123107. NULL,
  123108. &_vq_auxt__44c0_sm_p5_0,
  123109. NULL,
  123110. 0
  123111. };
  123112. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123113. 1,
  123114. 0,
  123115. 2,
  123116. };
  123117. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123118. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123119. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123120. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123121. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123122. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123123. 11,
  123124. };
  123125. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123126. -5.5, 5.5,
  123127. };
  123128. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123129. 1, 0, 2,
  123130. };
  123131. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123132. _vq_quantthresh__44c0_sm_p6_0,
  123133. _vq_quantmap__44c0_sm_p6_0,
  123134. 3,
  123135. 3
  123136. };
  123137. static static_codebook _44c0_sm_p6_0 = {
  123138. 4, 81,
  123139. _vq_lengthlist__44c0_sm_p6_0,
  123140. 1, -529137664, 1618345984, 2, 0,
  123141. _vq_quantlist__44c0_sm_p6_0,
  123142. NULL,
  123143. &_vq_auxt__44c0_sm_p6_0,
  123144. NULL,
  123145. 0
  123146. };
  123147. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123148. 5,
  123149. 4,
  123150. 6,
  123151. 3,
  123152. 7,
  123153. 2,
  123154. 8,
  123155. 1,
  123156. 9,
  123157. 0,
  123158. 10,
  123159. };
  123160. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123161. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123162. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123163. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123164. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123165. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123166. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123167. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123168. 10,10,10, 8, 8, 8, 8, 8, 8,
  123169. };
  123170. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123171. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123172. 3.5, 4.5,
  123173. };
  123174. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123175. 9, 7, 5, 3, 1, 0, 2, 4,
  123176. 6, 8, 10,
  123177. };
  123178. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123179. _vq_quantthresh__44c0_sm_p6_1,
  123180. _vq_quantmap__44c0_sm_p6_1,
  123181. 11,
  123182. 11
  123183. };
  123184. static static_codebook _44c0_sm_p6_1 = {
  123185. 2, 121,
  123186. _vq_lengthlist__44c0_sm_p6_1,
  123187. 1, -531365888, 1611661312, 4, 0,
  123188. _vq_quantlist__44c0_sm_p6_1,
  123189. NULL,
  123190. &_vq_auxt__44c0_sm_p6_1,
  123191. NULL,
  123192. 0
  123193. };
  123194. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123195. 6,
  123196. 5,
  123197. 7,
  123198. 4,
  123199. 8,
  123200. 3,
  123201. 9,
  123202. 2,
  123203. 10,
  123204. 1,
  123205. 11,
  123206. 0,
  123207. 12,
  123208. };
  123209. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123210. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123211. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123212. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123213. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123214. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123215. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123216. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123217. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123218. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123219. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123220. 0,12,12,11,11,13,12,14,14,
  123221. };
  123222. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123223. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123224. 12.5, 17.5, 22.5, 27.5,
  123225. };
  123226. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123227. 11, 9, 7, 5, 3, 1, 0, 2,
  123228. 4, 6, 8, 10, 12,
  123229. };
  123230. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123231. _vq_quantthresh__44c0_sm_p7_0,
  123232. _vq_quantmap__44c0_sm_p7_0,
  123233. 13,
  123234. 13
  123235. };
  123236. static static_codebook _44c0_sm_p7_0 = {
  123237. 2, 169,
  123238. _vq_lengthlist__44c0_sm_p7_0,
  123239. 1, -526516224, 1616117760, 4, 0,
  123240. _vq_quantlist__44c0_sm_p7_0,
  123241. NULL,
  123242. &_vq_auxt__44c0_sm_p7_0,
  123243. NULL,
  123244. 0
  123245. };
  123246. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123247. 2,
  123248. 1,
  123249. 3,
  123250. 0,
  123251. 4,
  123252. };
  123253. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123254. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123255. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123256. };
  123257. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123258. -1.5, -0.5, 0.5, 1.5,
  123259. };
  123260. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123261. 3, 1, 0, 2, 4,
  123262. };
  123263. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123264. _vq_quantthresh__44c0_sm_p7_1,
  123265. _vq_quantmap__44c0_sm_p7_1,
  123266. 5,
  123267. 5
  123268. };
  123269. static static_codebook _44c0_sm_p7_1 = {
  123270. 2, 25,
  123271. _vq_lengthlist__44c0_sm_p7_1,
  123272. 1, -533725184, 1611661312, 3, 0,
  123273. _vq_quantlist__44c0_sm_p7_1,
  123274. NULL,
  123275. &_vq_auxt__44c0_sm_p7_1,
  123276. NULL,
  123277. 0
  123278. };
  123279. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123280. 4,
  123281. 3,
  123282. 5,
  123283. 2,
  123284. 6,
  123285. 1,
  123286. 7,
  123287. 0,
  123288. 8,
  123289. };
  123290. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123291. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123292. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123293. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123294. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123295. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123296. 12,
  123297. };
  123298. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123299. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123300. };
  123301. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123302. 7, 5, 3, 1, 0, 2, 4, 6,
  123303. 8,
  123304. };
  123305. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123306. _vq_quantthresh__44c0_sm_p8_0,
  123307. _vq_quantmap__44c0_sm_p8_0,
  123308. 9,
  123309. 9
  123310. };
  123311. static static_codebook _44c0_sm_p8_0 = {
  123312. 2, 81,
  123313. _vq_lengthlist__44c0_sm_p8_0,
  123314. 1, -516186112, 1627103232, 4, 0,
  123315. _vq_quantlist__44c0_sm_p8_0,
  123316. NULL,
  123317. &_vq_auxt__44c0_sm_p8_0,
  123318. NULL,
  123319. 0
  123320. };
  123321. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123322. 6,
  123323. 5,
  123324. 7,
  123325. 4,
  123326. 8,
  123327. 3,
  123328. 9,
  123329. 2,
  123330. 10,
  123331. 1,
  123332. 11,
  123333. 0,
  123334. 12,
  123335. };
  123336. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123337. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123338. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123339. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123340. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123341. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123342. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123343. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123344. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123345. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123346. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123347. 20,13,13,12,12,16,13,15,13,
  123348. };
  123349. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123350. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123351. 42.5, 59.5, 76.5, 93.5,
  123352. };
  123353. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123354. 11, 9, 7, 5, 3, 1, 0, 2,
  123355. 4, 6, 8, 10, 12,
  123356. };
  123357. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123358. _vq_quantthresh__44c0_sm_p8_1,
  123359. _vq_quantmap__44c0_sm_p8_1,
  123360. 13,
  123361. 13
  123362. };
  123363. static static_codebook _44c0_sm_p8_1 = {
  123364. 2, 169,
  123365. _vq_lengthlist__44c0_sm_p8_1,
  123366. 1, -522616832, 1620115456, 4, 0,
  123367. _vq_quantlist__44c0_sm_p8_1,
  123368. NULL,
  123369. &_vq_auxt__44c0_sm_p8_1,
  123370. NULL,
  123371. 0
  123372. };
  123373. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123374. 8,
  123375. 7,
  123376. 9,
  123377. 6,
  123378. 10,
  123379. 5,
  123380. 11,
  123381. 4,
  123382. 12,
  123383. 3,
  123384. 13,
  123385. 2,
  123386. 14,
  123387. 1,
  123388. 15,
  123389. 0,
  123390. 16,
  123391. };
  123392. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123393. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123394. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123395. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123396. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123397. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123398. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123399. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123400. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123401. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123402. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123403. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123404. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123405. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123406. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123407. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123408. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123409. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123410. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123411. 9,
  123412. };
  123413. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123414. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123415. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123416. };
  123417. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123418. 15, 13, 11, 9, 7, 5, 3, 1,
  123419. 0, 2, 4, 6, 8, 10, 12, 14,
  123420. 16,
  123421. };
  123422. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123423. _vq_quantthresh__44c0_sm_p8_2,
  123424. _vq_quantmap__44c0_sm_p8_2,
  123425. 17,
  123426. 17
  123427. };
  123428. static static_codebook _44c0_sm_p8_2 = {
  123429. 2, 289,
  123430. _vq_lengthlist__44c0_sm_p8_2,
  123431. 1, -529530880, 1611661312, 5, 0,
  123432. _vq_quantlist__44c0_sm_p8_2,
  123433. NULL,
  123434. &_vq_auxt__44c0_sm_p8_2,
  123435. NULL,
  123436. 0
  123437. };
  123438. static long _huff_lengthlist__44c0_sm_short[] = {
  123439. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123440. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123441. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123442. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123443. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123444. 12,
  123445. };
  123446. static static_codebook _huff_book__44c0_sm_short = {
  123447. 2, 81,
  123448. _huff_lengthlist__44c0_sm_short,
  123449. 0, 0, 0, 0, 0,
  123450. NULL,
  123451. NULL,
  123452. NULL,
  123453. NULL,
  123454. 0
  123455. };
  123456. static long _huff_lengthlist__44c1_s_long[] = {
  123457. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123458. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123459. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123460. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123461. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123462. 11,
  123463. };
  123464. static static_codebook _huff_book__44c1_s_long = {
  123465. 2, 81,
  123466. _huff_lengthlist__44c1_s_long,
  123467. 0, 0, 0, 0, 0,
  123468. NULL,
  123469. NULL,
  123470. NULL,
  123471. NULL,
  123472. 0
  123473. };
  123474. static long _vq_quantlist__44c1_s_p1_0[] = {
  123475. 1,
  123476. 0,
  123477. 2,
  123478. };
  123479. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123480. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123481. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123486. 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123491. 0, 0, 0, 0, 7, 8, 8, 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, 4, 7, 7, 0, 0, 0, 0,
  123526. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  123531. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  123536. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123572. 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  123577. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123582. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123817. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123890. 0,
  123891. };
  123892. static float _vq_quantthresh__44c1_s_p1_0[] = {
  123893. -0.5, 0.5,
  123894. };
  123895. static long _vq_quantmap__44c1_s_p1_0[] = {
  123896. 1, 0, 2,
  123897. };
  123898. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  123899. _vq_quantthresh__44c1_s_p1_0,
  123900. _vq_quantmap__44c1_s_p1_0,
  123901. 3,
  123902. 3
  123903. };
  123904. static static_codebook _44c1_s_p1_0 = {
  123905. 8, 6561,
  123906. _vq_lengthlist__44c1_s_p1_0,
  123907. 1, -535822336, 1611661312, 2, 0,
  123908. _vq_quantlist__44c1_s_p1_0,
  123909. NULL,
  123910. &_vq_auxt__44c1_s_p1_0,
  123911. NULL,
  123912. 0
  123913. };
  123914. static long _vq_quantlist__44c1_s_p2_0[] = {
  123915. 2,
  123916. 1,
  123917. 3,
  123918. 0,
  123919. 4,
  123920. };
  123921. static long _vq_lengthlist__44c1_s_p2_0[] = {
  123922. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  123924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123925. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  123927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123928. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123961. 0,
  123962. };
  123963. static float _vq_quantthresh__44c1_s_p2_0[] = {
  123964. -1.5, -0.5, 0.5, 1.5,
  123965. };
  123966. static long _vq_quantmap__44c1_s_p2_0[] = {
  123967. 3, 1, 0, 2, 4,
  123968. };
  123969. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  123970. _vq_quantthresh__44c1_s_p2_0,
  123971. _vq_quantmap__44c1_s_p2_0,
  123972. 5,
  123973. 5
  123974. };
  123975. static static_codebook _44c1_s_p2_0 = {
  123976. 4, 625,
  123977. _vq_lengthlist__44c1_s_p2_0,
  123978. 1, -533725184, 1611661312, 3, 0,
  123979. _vq_quantlist__44c1_s_p2_0,
  123980. NULL,
  123981. &_vq_auxt__44c1_s_p2_0,
  123982. NULL,
  123983. 0
  123984. };
  123985. static long _vq_quantlist__44c1_s_p3_0[] = {
  123986. 4,
  123987. 3,
  123988. 5,
  123989. 2,
  123990. 6,
  123991. 1,
  123992. 7,
  123993. 0,
  123994. 8,
  123995. };
  123996. static long _vq_lengthlist__44c1_s_p3_0[] = {
  123997. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  123998. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  123999. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124000. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124001. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124002. 0,
  124003. };
  124004. static float _vq_quantthresh__44c1_s_p3_0[] = {
  124005. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124006. };
  124007. static long _vq_quantmap__44c1_s_p3_0[] = {
  124008. 7, 5, 3, 1, 0, 2, 4, 6,
  124009. 8,
  124010. };
  124011. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124012. _vq_quantthresh__44c1_s_p3_0,
  124013. _vq_quantmap__44c1_s_p3_0,
  124014. 9,
  124015. 9
  124016. };
  124017. static static_codebook _44c1_s_p3_0 = {
  124018. 2, 81,
  124019. _vq_lengthlist__44c1_s_p3_0,
  124020. 1, -531628032, 1611661312, 4, 0,
  124021. _vq_quantlist__44c1_s_p3_0,
  124022. NULL,
  124023. &_vq_auxt__44c1_s_p3_0,
  124024. NULL,
  124025. 0
  124026. };
  124027. static long _vq_quantlist__44c1_s_p4_0[] = {
  124028. 4,
  124029. 3,
  124030. 5,
  124031. 2,
  124032. 6,
  124033. 1,
  124034. 7,
  124035. 0,
  124036. 8,
  124037. };
  124038. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124039. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124040. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124041. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124042. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124043. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124044. 11,
  124045. };
  124046. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124047. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124048. };
  124049. static long _vq_quantmap__44c1_s_p4_0[] = {
  124050. 7, 5, 3, 1, 0, 2, 4, 6,
  124051. 8,
  124052. };
  124053. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124054. _vq_quantthresh__44c1_s_p4_0,
  124055. _vq_quantmap__44c1_s_p4_0,
  124056. 9,
  124057. 9
  124058. };
  124059. static static_codebook _44c1_s_p4_0 = {
  124060. 2, 81,
  124061. _vq_lengthlist__44c1_s_p4_0,
  124062. 1, -531628032, 1611661312, 4, 0,
  124063. _vq_quantlist__44c1_s_p4_0,
  124064. NULL,
  124065. &_vq_auxt__44c1_s_p4_0,
  124066. NULL,
  124067. 0
  124068. };
  124069. static long _vq_quantlist__44c1_s_p5_0[] = {
  124070. 8,
  124071. 7,
  124072. 9,
  124073. 6,
  124074. 10,
  124075. 5,
  124076. 11,
  124077. 4,
  124078. 12,
  124079. 3,
  124080. 13,
  124081. 2,
  124082. 14,
  124083. 1,
  124084. 15,
  124085. 0,
  124086. 16,
  124087. };
  124088. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124089. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124090. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124091. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124092. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124093. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124094. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124095. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124096. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124097. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124098. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124099. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124100. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124101. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124102. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124103. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124104. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124105. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124106. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124107. 14,
  124108. };
  124109. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124110. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124111. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124112. };
  124113. static long _vq_quantmap__44c1_s_p5_0[] = {
  124114. 15, 13, 11, 9, 7, 5, 3, 1,
  124115. 0, 2, 4, 6, 8, 10, 12, 14,
  124116. 16,
  124117. };
  124118. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124119. _vq_quantthresh__44c1_s_p5_0,
  124120. _vq_quantmap__44c1_s_p5_0,
  124121. 17,
  124122. 17
  124123. };
  124124. static static_codebook _44c1_s_p5_0 = {
  124125. 2, 289,
  124126. _vq_lengthlist__44c1_s_p5_0,
  124127. 1, -529530880, 1611661312, 5, 0,
  124128. _vq_quantlist__44c1_s_p5_0,
  124129. NULL,
  124130. &_vq_auxt__44c1_s_p5_0,
  124131. NULL,
  124132. 0
  124133. };
  124134. static long _vq_quantlist__44c1_s_p6_0[] = {
  124135. 1,
  124136. 0,
  124137. 2,
  124138. };
  124139. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124140. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124141. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124142. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124143. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124144. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124145. 11,
  124146. };
  124147. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124148. -5.5, 5.5,
  124149. };
  124150. static long _vq_quantmap__44c1_s_p6_0[] = {
  124151. 1, 0, 2,
  124152. };
  124153. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124154. _vq_quantthresh__44c1_s_p6_0,
  124155. _vq_quantmap__44c1_s_p6_0,
  124156. 3,
  124157. 3
  124158. };
  124159. static static_codebook _44c1_s_p6_0 = {
  124160. 4, 81,
  124161. _vq_lengthlist__44c1_s_p6_0,
  124162. 1, -529137664, 1618345984, 2, 0,
  124163. _vq_quantlist__44c1_s_p6_0,
  124164. NULL,
  124165. &_vq_auxt__44c1_s_p6_0,
  124166. NULL,
  124167. 0
  124168. };
  124169. static long _vq_quantlist__44c1_s_p6_1[] = {
  124170. 5,
  124171. 4,
  124172. 6,
  124173. 3,
  124174. 7,
  124175. 2,
  124176. 8,
  124177. 1,
  124178. 9,
  124179. 0,
  124180. 10,
  124181. };
  124182. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124183. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124184. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124185. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124186. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124187. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124188. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124189. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124190. 10,10,10, 8, 8, 8, 8, 8, 8,
  124191. };
  124192. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124193. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124194. 3.5, 4.5,
  124195. };
  124196. static long _vq_quantmap__44c1_s_p6_1[] = {
  124197. 9, 7, 5, 3, 1, 0, 2, 4,
  124198. 6, 8, 10,
  124199. };
  124200. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124201. _vq_quantthresh__44c1_s_p6_1,
  124202. _vq_quantmap__44c1_s_p6_1,
  124203. 11,
  124204. 11
  124205. };
  124206. static static_codebook _44c1_s_p6_1 = {
  124207. 2, 121,
  124208. _vq_lengthlist__44c1_s_p6_1,
  124209. 1, -531365888, 1611661312, 4, 0,
  124210. _vq_quantlist__44c1_s_p6_1,
  124211. NULL,
  124212. &_vq_auxt__44c1_s_p6_1,
  124213. NULL,
  124214. 0
  124215. };
  124216. static long _vq_quantlist__44c1_s_p7_0[] = {
  124217. 6,
  124218. 5,
  124219. 7,
  124220. 4,
  124221. 8,
  124222. 3,
  124223. 9,
  124224. 2,
  124225. 10,
  124226. 1,
  124227. 11,
  124228. 0,
  124229. 12,
  124230. };
  124231. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124232. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124233. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124234. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124235. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124236. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124237. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124238. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124239. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124240. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124241. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124242. 0,12,11,11,11,13,10,14,13,
  124243. };
  124244. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124245. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124246. 12.5, 17.5, 22.5, 27.5,
  124247. };
  124248. static long _vq_quantmap__44c1_s_p7_0[] = {
  124249. 11, 9, 7, 5, 3, 1, 0, 2,
  124250. 4, 6, 8, 10, 12,
  124251. };
  124252. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124253. _vq_quantthresh__44c1_s_p7_0,
  124254. _vq_quantmap__44c1_s_p7_0,
  124255. 13,
  124256. 13
  124257. };
  124258. static static_codebook _44c1_s_p7_0 = {
  124259. 2, 169,
  124260. _vq_lengthlist__44c1_s_p7_0,
  124261. 1, -526516224, 1616117760, 4, 0,
  124262. _vq_quantlist__44c1_s_p7_0,
  124263. NULL,
  124264. &_vq_auxt__44c1_s_p7_0,
  124265. NULL,
  124266. 0
  124267. };
  124268. static long _vq_quantlist__44c1_s_p7_1[] = {
  124269. 2,
  124270. 1,
  124271. 3,
  124272. 0,
  124273. 4,
  124274. };
  124275. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124276. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124277. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124278. };
  124279. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124280. -1.5, -0.5, 0.5, 1.5,
  124281. };
  124282. static long _vq_quantmap__44c1_s_p7_1[] = {
  124283. 3, 1, 0, 2, 4,
  124284. };
  124285. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124286. _vq_quantthresh__44c1_s_p7_1,
  124287. _vq_quantmap__44c1_s_p7_1,
  124288. 5,
  124289. 5
  124290. };
  124291. static static_codebook _44c1_s_p7_1 = {
  124292. 2, 25,
  124293. _vq_lengthlist__44c1_s_p7_1,
  124294. 1, -533725184, 1611661312, 3, 0,
  124295. _vq_quantlist__44c1_s_p7_1,
  124296. NULL,
  124297. &_vq_auxt__44c1_s_p7_1,
  124298. NULL,
  124299. 0
  124300. };
  124301. static long _vq_quantlist__44c1_s_p8_0[] = {
  124302. 6,
  124303. 5,
  124304. 7,
  124305. 4,
  124306. 8,
  124307. 3,
  124308. 9,
  124309. 2,
  124310. 10,
  124311. 1,
  124312. 11,
  124313. 0,
  124314. 12,
  124315. };
  124316. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124317. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124318. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124319. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124320. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124321. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124322. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124323. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124324. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124325. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124326. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124327. 10,10,10,10,10,10,10,10,10,
  124328. };
  124329. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124330. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124331. 552.5, 773.5, 994.5, 1215.5,
  124332. };
  124333. static long _vq_quantmap__44c1_s_p8_0[] = {
  124334. 11, 9, 7, 5, 3, 1, 0, 2,
  124335. 4, 6, 8, 10, 12,
  124336. };
  124337. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124338. _vq_quantthresh__44c1_s_p8_0,
  124339. _vq_quantmap__44c1_s_p8_0,
  124340. 13,
  124341. 13
  124342. };
  124343. static static_codebook _44c1_s_p8_0 = {
  124344. 2, 169,
  124345. _vq_lengthlist__44c1_s_p8_0,
  124346. 1, -514541568, 1627103232, 4, 0,
  124347. _vq_quantlist__44c1_s_p8_0,
  124348. NULL,
  124349. &_vq_auxt__44c1_s_p8_0,
  124350. NULL,
  124351. 0
  124352. };
  124353. static long _vq_quantlist__44c1_s_p8_1[] = {
  124354. 6,
  124355. 5,
  124356. 7,
  124357. 4,
  124358. 8,
  124359. 3,
  124360. 9,
  124361. 2,
  124362. 10,
  124363. 1,
  124364. 11,
  124365. 0,
  124366. 12,
  124367. };
  124368. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124369. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124370. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124371. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124372. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124373. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124374. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124375. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124376. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124377. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124378. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124379. 16,13,12,12,11,14,12,15,13,
  124380. };
  124381. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124382. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124383. 42.5, 59.5, 76.5, 93.5,
  124384. };
  124385. static long _vq_quantmap__44c1_s_p8_1[] = {
  124386. 11, 9, 7, 5, 3, 1, 0, 2,
  124387. 4, 6, 8, 10, 12,
  124388. };
  124389. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124390. _vq_quantthresh__44c1_s_p8_1,
  124391. _vq_quantmap__44c1_s_p8_1,
  124392. 13,
  124393. 13
  124394. };
  124395. static static_codebook _44c1_s_p8_1 = {
  124396. 2, 169,
  124397. _vq_lengthlist__44c1_s_p8_1,
  124398. 1, -522616832, 1620115456, 4, 0,
  124399. _vq_quantlist__44c1_s_p8_1,
  124400. NULL,
  124401. &_vq_auxt__44c1_s_p8_1,
  124402. NULL,
  124403. 0
  124404. };
  124405. static long _vq_quantlist__44c1_s_p8_2[] = {
  124406. 8,
  124407. 7,
  124408. 9,
  124409. 6,
  124410. 10,
  124411. 5,
  124412. 11,
  124413. 4,
  124414. 12,
  124415. 3,
  124416. 13,
  124417. 2,
  124418. 14,
  124419. 1,
  124420. 15,
  124421. 0,
  124422. 16,
  124423. };
  124424. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124425. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124426. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124427. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124428. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124429. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124430. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124431. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124432. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124433. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124434. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124435. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124436. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124437. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124438. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124439. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124440. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124441. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124442. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124443. 9,
  124444. };
  124445. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124446. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124447. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124448. };
  124449. static long _vq_quantmap__44c1_s_p8_2[] = {
  124450. 15, 13, 11, 9, 7, 5, 3, 1,
  124451. 0, 2, 4, 6, 8, 10, 12, 14,
  124452. 16,
  124453. };
  124454. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124455. _vq_quantthresh__44c1_s_p8_2,
  124456. _vq_quantmap__44c1_s_p8_2,
  124457. 17,
  124458. 17
  124459. };
  124460. static static_codebook _44c1_s_p8_2 = {
  124461. 2, 289,
  124462. _vq_lengthlist__44c1_s_p8_2,
  124463. 1, -529530880, 1611661312, 5, 0,
  124464. _vq_quantlist__44c1_s_p8_2,
  124465. NULL,
  124466. &_vq_auxt__44c1_s_p8_2,
  124467. NULL,
  124468. 0
  124469. };
  124470. static long _huff_lengthlist__44c1_s_short[] = {
  124471. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124472. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124473. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124474. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124475. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124476. 11,
  124477. };
  124478. static static_codebook _huff_book__44c1_s_short = {
  124479. 2, 81,
  124480. _huff_lengthlist__44c1_s_short,
  124481. 0, 0, 0, 0, 0,
  124482. NULL,
  124483. NULL,
  124484. NULL,
  124485. NULL,
  124486. 0
  124487. };
  124488. static long _huff_lengthlist__44c1_sm_long[] = {
  124489. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124490. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124491. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124492. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124493. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124494. 11,
  124495. };
  124496. static static_codebook _huff_book__44c1_sm_long = {
  124497. 2, 81,
  124498. _huff_lengthlist__44c1_sm_long,
  124499. 0, 0, 0, 0, 0,
  124500. NULL,
  124501. NULL,
  124502. NULL,
  124503. NULL,
  124504. 0
  124505. };
  124506. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124507. 1,
  124508. 0,
  124509. 2,
  124510. };
  124511. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124512. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124513. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124518. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124523. 0, 0, 0, 0, 7, 9, 9, 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, 5, 8, 7, 0, 0, 0, 0,
  124558. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  124563. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  124568. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124604. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124609. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124614. 0, 0, 0, 0, 0, 0, 9,10, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124849. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124922. 0,
  124923. };
  124924. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  124925. -0.5, 0.5,
  124926. };
  124927. static long _vq_quantmap__44c1_sm_p1_0[] = {
  124928. 1, 0, 2,
  124929. };
  124930. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  124931. _vq_quantthresh__44c1_sm_p1_0,
  124932. _vq_quantmap__44c1_sm_p1_0,
  124933. 3,
  124934. 3
  124935. };
  124936. static static_codebook _44c1_sm_p1_0 = {
  124937. 8, 6561,
  124938. _vq_lengthlist__44c1_sm_p1_0,
  124939. 1, -535822336, 1611661312, 2, 0,
  124940. _vq_quantlist__44c1_sm_p1_0,
  124941. NULL,
  124942. &_vq_auxt__44c1_sm_p1_0,
  124943. NULL,
  124944. 0
  124945. };
  124946. static long _vq_quantlist__44c1_sm_p2_0[] = {
  124947. 2,
  124948. 1,
  124949. 3,
  124950. 0,
  124951. 4,
  124952. };
  124953. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  124954. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124957. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  124959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124960. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  124961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124993. 0,
  124994. };
  124995. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  124996. -1.5, -0.5, 0.5, 1.5,
  124997. };
  124998. static long _vq_quantmap__44c1_sm_p2_0[] = {
  124999. 3, 1, 0, 2, 4,
  125000. };
  125001. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  125002. _vq_quantthresh__44c1_sm_p2_0,
  125003. _vq_quantmap__44c1_sm_p2_0,
  125004. 5,
  125005. 5
  125006. };
  125007. static static_codebook _44c1_sm_p2_0 = {
  125008. 4, 625,
  125009. _vq_lengthlist__44c1_sm_p2_0,
  125010. 1, -533725184, 1611661312, 3, 0,
  125011. _vq_quantlist__44c1_sm_p2_0,
  125012. NULL,
  125013. &_vq_auxt__44c1_sm_p2_0,
  125014. NULL,
  125015. 0
  125016. };
  125017. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125018. 4,
  125019. 3,
  125020. 5,
  125021. 2,
  125022. 6,
  125023. 1,
  125024. 7,
  125025. 0,
  125026. 8,
  125027. };
  125028. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125029. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125030. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125031. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125032. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125033. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125034. 0,
  125035. };
  125036. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125037. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125038. };
  125039. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125040. 7, 5, 3, 1, 0, 2, 4, 6,
  125041. 8,
  125042. };
  125043. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125044. _vq_quantthresh__44c1_sm_p3_0,
  125045. _vq_quantmap__44c1_sm_p3_0,
  125046. 9,
  125047. 9
  125048. };
  125049. static static_codebook _44c1_sm_p3_0 = {
  125050. 2, 81,
  125051. _vq_lengthlist__44c1_sm_p3_0,
  125052. 1, -531628032, 1611661312, 4, 0,
  125053. _vq_quantlist__44c1_sm_p3_0,
  125054. NULL,
  125055. &_vq_auxt__44c1_sm_p3_0,
  125056. NULL,
  125057. 0
  125058. };
  125059. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125060. 4,
  125061. 3,
  125062. 5,
  125063. 2,
  125064. 6,
  125065. 1,
  125066. 7,
  125067. 0,
  125068. 8,
  125069. };
  125070. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125071. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125072. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125073. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125074. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125075. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125076. 11,
  125077. };
  125078. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125079. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125080. };
  125081. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125082. 7, 5, 3, 1, 0, 2, 4, 6,
  125083. 8,
  125084. };
  125085. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125086. _vq_quantthresh__44c1_sm_p4_0,
  125087. _vq_quantmap__44c1_sm_p4_0,
  125088. 9,
  125089. 9
  125090. };
  125091. static static_codebook _44c1_sm_p4_0 = {
  125092. 2, 81,
  125093. _vq_lengthlist__44c1_sm_p4_0,
  125094. 1, -531628032, 1611661312, 4, 0,
  125095. _vq_quantlist__44c1_sm_p4_0,
  125096. NULL,
  125097. &_vq_auxt__44c1_sm_p4_0,
  125098. NULL,
  125099. 0
  125100. };
  125101. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125102. 8,
  125103. 7,
  125104. 9,
  125105. 6,
  125106. 10,
  125107. 5,
  125108. 11,
  125109. 4,
  125110. 12,
  125111. 3,
  125112. 13,
  125113. 2,
  125114. 14,
  125115. 1,
  125116. 15,
  125117. 0,
  125118. 16,
  125119. };
  125120. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125121. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125122. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125123. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125124. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125125. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125126. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125127. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125128. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125129. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125130. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125131. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125132. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125133. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125134. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125135. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125136. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125137. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125138. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125139. 14,
  125140. };
  125141. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125142. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125143. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125144. };
  125145. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125146. 15, 13, 11, 9, 7, 5, 3, 1,
  125147. 0, 2, 4, 6, 8, 10, 12, 14,
  125148. 16,
  125149. };
  125150. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125151. _vq_quantthresh__44c1_sm_p5_0,
  125152. _vq_quantmap__44c1_sm_p5_0,
  125153. 17,
  125154. 17
  125155. };
  125156. static static_codebook _44c1_sm_p5_0 = {
  125157. 2, 289,
  125158. _vq_lengthlist__44c1_sm_p5_0,
  125159. 1, -529530880, 1611661312, 5, 0,
  125160. _vq_quantlist__44c1_sm_p5_0,
  125161. NULL,
  125162. &_vq_auxt__44c1_sm_p5_0,
  125163. NULL,
  125164. 0
  125165. };
  125166. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125167. 1,
  125168. 0,
  125169. 2,
  125170. };
  125171. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125172. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125173. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125174. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125175. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125176. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125177. 11,
  125178. };
  125179. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125180. -5.5, 5.5,
  125181. };
  125182. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125183. 1, 0, 2,
  125184. };
  125185. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125186. _vq_quantthresh__44c1_sm_p6_0,
  125187. _vq_quantmap__44c1_sm_p6_0,
  125188. 3,
  125189. 3
  125190. };
  125191. static static_codebook _44c1_sm_p6_0 = {
  125192. 4, 81,
  125193. _vq_lengthlist__44c1_sm_p6_0,
  125194. 1, -529137664, 1618345984, 2, 0,
  125195. _vq_quantlist__44c1_sm_p6_0,
  125196. NULL,
  125197. &_vq_auxt__44c1_sm_p6_0,
  125198. NULL,
  125199. 0
  125200. };
  125201. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125202. 5,
  125203. 4,
  125204. 6,
  125205. 3,
  125206. 7,
  125207. 2,
  125208. 8,
  125209. 1,
  125210. 9,
  125211. 0,
  125212. 10,
  125213. };
  125214. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125215. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125216. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125217. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125218. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125219. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125220. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125221. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125222. 10,10,10, 8, 8, 8, 8, 8, 8,
  125223. };
  125224. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125225. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125226. 3.5, 4.5,
  125227. };
  125228. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125229. 9, 7, 5, 3, 1, 0, 2, 4,
  125230. 6, 8, 10,
  125231. };
  125232. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125233. _vq_quantthresh__44c1_sm_p6_1,
  125234. _vq_quantmap__44c1_sm_p6_1,
  125235. 11,
  125236. 11
  125237. };
  125238. static static_codebook _44c1_sm_p6_1 = {
  125239. 2, 121,
  125240. _vq_lengthlist__44c1_sm_p6_1,
  125241. 1, -531365888, 1611661312, 4, 0,
  125242. _vq_quantlist__44c1_sm_p6_1,
  125243. NULL,
  125244. &_vq_auxt__44c1_sm_p6_1,
  125245. NULL,
  125246. 0
  125247. };
  125248. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125249. 6,
  125250. 5,
  125251. 7,
  125252. 4,
  125253. 8,
  125254. 3,
  125255. 9,
  125256. 2,
  125257. 10,
  125258. 1,
  125259. 11,
  125260. 0,
  125261. 12,
  125262. };
  125263. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125264. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125265. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125266. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125267. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125268. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125269. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125270. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125271. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125272. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125273. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125274. 0,12,12,11,11,13,12,14,13,
  125275. };
  125276. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125277. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125278. 12.5, 17.5, 22.5, 27.5,
  125279. };
  125280. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125281. 11, 9, 7, 5, 3, 1, 0, 2,
  125282. 4, 6, 8, 10, 12,
  125283. };
  125284. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125285. _vq_quantthresh__44c1_sm_p7_0,
  125286. _vq_quantmap__44c1_sm_p7_0,
  125287. 13,
  125288. 13
  125289. };
  125290. static static_codebook _44c1_sm_p7_0 = {
  125291. 2, 169,
  125292. _vq_lengthlist__44c1_sm_p7_0,
  125293. 1, -526516224, 1616117760, 4, 0,
  125294. _vq_quantlist__44c1_sm_p7_0,
  125295. NULL,
  125296. &_vq_auxt__44c1_sm_p7_0,
  125297. NULL,
  125298. 0
  125299. };
  125300. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125301. 2,
  125302. 1,
  125303. 3,
  125304. 0,
  125305. 4,
  125306. };
  125307. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125308. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125309. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125310. };
  125311. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125312. -1.5, -0.5, 0.5, 1.5,
  125313. };
  125314. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125315. 3, 1, 0, 2, 4,
  125316. };
  125317. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125318. _vq_quantthresh__44c1_sm_p7_1,
  125319. _vq_quantmap__44c1_sm_p7_1,
  125320. 5,
  125321. 5
  125322. };
  125323. static static_codebook _44c1_sm_p7_1 = {
  125324. 2, 25,
  125325. _vq_lengthlist__44c1_sm_p7_1,
  125326. 1, -533725184, 1611661312, 3, 0,
  125327. _vq_quantlist__44c1_sm_p7_1,
  125328. NULL,
  125329. &_vq_auxt__44c1_sm_p7_1,
  125330. NULL,
  125331. 0
  125332. };
  125333. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125334. 6,
  125335. 5,
  125336. 7,
  125337. 4,
  125338. 8,
  125339. 3,
  125340. 9,
  125341. 2,
  125342. 10,
  125343. 1,
  125344. 11,
  125345. 0,
  125346. 12,
  125347. };
  125348. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125349. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125350. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125351. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125352. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125353. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125354. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125355. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125356. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125357. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125358. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125359. 13,13,13,13,13,13,13,13,13,
  125360. };
  125361. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125362. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125363. 552.5, 773.5, 994.5, 1215.5,
  125364. };
  125365. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125366. 11, 9, 7, 5, 3, 1, 0, 2,
  125367. 4, 6, 8, 10, 12,
  125368. };
  125369. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125370. _vq_quantthresh__44c1_sm_p8_0,
  125371. _vq_quantmap__44c1_sm_p8_0,
  125372. 13,
  125373. 13
  125374. };
  125375. static static_codebook _44c1_sm_p8_0 = {
  125376. 2, 169,
  125377. _vq_lengthlist__44c1_sm_p8_0,
  125378. 1, -514541568, 1627103232, 4, 0,
  125379. _vq_quantlist__44c1_sm_p8_0,
  125380. NULL,
  125381. &_vq_auxt__44c1_sm_p8_0,
  125382. NULL,
  125383. 0
  125384. };
  125385. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125386. 6,
  125387. 5,
  125388. 7,
  125389. 4,
  125390. 8,
  125391. 3,
  125392. 9,
  125393. 2,
  125394. 10,
  125395. 1,
  125396. 11,
  125397. 0,
  125398. 12,
  125399. };
  125400. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125401. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125402. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125403. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125404. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125405. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125406. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125407. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125408. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125409. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125410. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125411. 20,13,12,12,12,14,12,14,13,
  125412. };
  125413. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125414. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125415. 42.5, 59.5, 76.5, 93.5,
  125416. };
  125417. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125418. 11, 9, 7, 5, 3, 1, 0, 2,
  125419. 4, 6, 8, 10, 12,
  125420. };
  125421. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125422. _vq_quantthresh__44c1_sm_p8_1,
  125423. _vq_quantmap__44c1_sm_p8_1,
  125424. 13,
  125425. 13
  125426. };
  125427. static static_codebook _44c1_sm_p8_1 = {
  125428. 2, 169,
  125429. _vq_lengthlist__44c1_sm_p8_1,
  125430. 1, -522616832, 1620115456, 4, 0,
  125431. _vq_quantlist__44c1_sm_p8_1,
  125432. NULL,
  125433. &_vq_auxt__44c1_sm_p8_1,
  125434. NULL,
  125435. 0
  125436. };
  125437. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125438. 8,
  125439. 7,
  125440. 9,
  125441. 6,
  125442. 10,
  125443. 5,
  125444. 11,
  125445. 4,
  125446. 12,
  125447. 3,
  125448. 13,
  125449. 2,
  125450. 14,
  125451. 1,
  125452. 15,
  125453. 0,
  125454. 16,
  125455. };
  125456. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125457. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125458. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125459. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125460. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125461. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125462. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125463. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125464. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125465. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125466. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125467. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125468. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125469. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125470. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125471. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125472. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125473. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125474. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125475. 9,
  125476. };
  125477. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125478. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125479. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125480. };
  125481. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125482. 15, 13, 11, 9, 7, 5, 3, 1,
  125483. 0, 2, 4, 6, 8, 10, 12, 14,
  125484. 16,
  125485. };
  125486. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125487. _vq_quantthresh__44c1_sm_p8_2,
  125488. _vq_quantmap__44c1_sm_p8_2,
  125489. 17,
  125490. 17
  125491. };
  125492. static static_codebook _44c1_sm_p8_2 = {
  125493. 2, 289,
  125494. _vq_lengthlist__44c1_sm_p8_2,
  125495. 1, -529530880, 1611661312, 5, 0,
  125496. _vq_quantlist__44c1_sm_p8_2,
  125497. NULL,
  125498. &_vq_auxt__44c1_sm_p8_2,
  125499. NULL,
  125500. 0
  125501. };
  125502. static long _huff_lengthlist__44c1_sm_short[] = {
  125503. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125504. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125505. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125506. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125507. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125508. 11,
  125509. };
  125510. static static_codebook _huff_book__44c1_sm_short = {
  125511. 2, 81,
  125512. _huff_lengthlist__44c1_sm_short,
  125513. 0, 0, 0, 0, 0,
  125514. NULL,
  125515. NULL,
  125516. NULL,
  125517. NULL,
  125518. 0
  125519. };
  125520. static long _huff_lengthlist__44cn1_s_long[] = {
  125521. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125522. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125523. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125524. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125525. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125526. 20,
  125527. };
  125528. static static_codebook _huff_book__44cn1_s_long = {
  125529. 2, 81,
  125530. _huff_lengthlist__44cn1_s_long,
  125531. 0, 0, 0, 0, 0,
  125532. NULL,
  125533. NULL,
  125534. NULL,
  125535. NULL,
  125536. 0
  125537. };
  125538. static long _vq_quantlist__44cn1_s_p1_0[] = {
  125539. 1,
  125540. 0,
  125541. 2,
  125542. };
  125543. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  125544. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125545. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  125550. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  125555. 0, 0, 0, 0, 8,10, 9, 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, 5, 8, 8, 0, 0, 0, 0,
  125590. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 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, 7,10,10, 0, 0, 0,
  125595. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 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, 7,10,10, 0, 0,
  125600. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  125636. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125641. 0, 0, 0, 0, 0, 9, 9,11, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  125646. 0, 0, 0, 0, 0, 0, 9,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125881. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125954. 0,
  125955. };
  125956. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  125957. -0.5, 0.5,
  125958. };
  125959. static long _vq_quantmap__44cn1_s_p1_0[] = {
  125960. 1, 0, 2,
  125961. };
  125962. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  125963. _vq_quantthresh__44cn1_s_p1_0,
  125964. _vq_quantmap__44cn1_s_p1_0,
  125965. 3,
  125966. 3
  125967. };
  125968. static static_codebook _44cn1_s_p1_0 = {
  125969. 8, 6561,
  125970. _vq_lengthlist__44cn1_s_p1_0,
  125971. 1, -535822336, 1611661312, 2, 0,
  125972. _vq_quantlist__44cn1_s_p1_0,
  125973. NULL,
  125974. &_vq_auxt__44cn1_s_p1_0,
  125975. NULL,
  125976. 0
  125977. };
  125978. static long _vq_quantlist__44cn1_s_p2_0[] = {
  125979. 2,
  125980. 1,
  125981. 3,
  125982. 0,
  125983. 4,
  125984. };
  125985. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  125986. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  125988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125989. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  125991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125992. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126025. 0,
  126026. };
  126027. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126028. -1.5, -0.5, 0.5, 1.5,
  126029. };
  126030. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126031. 3, 1, 0, 2, 4,
  126032. };
  126033. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126034. _vq_quantthresh__44cn1_s_p2_0,
  126035. _vq_quantmap__44cn1_s_p2_0,
  126036. 5,
  126037. 5
  126038. };
  126039. static static_codebook _44cn1_s_p2_0 = {
  126040. 4, 625,
  126041. _vq_lengthlist__44cn1_s_p2_0,
  126042. 1, -533725184, 1611661312, 3, 0,
  126043. _vq_quantlist__44cn1_s_p2_0,
  126044. NULL,
  126045. &_vq_auxt__44cn1_s_p2_0,
  126046. NULL,
  126047. 0
  126048. };
  126049. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126050. 4,
  126051. 3,
  126052. 5,
  126053. 2,
  126054. 6,
  126055. 1,
  126056. 7,
  126057. 0,
  126058. 8,
  126059. };
  126060. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126061. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126062. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126063. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126064. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126065. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126066. 0,
  126067. };
  126068. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126069. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126070. };
  126071. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126072. 7, 5, 3, 1, 0, 2, 4, 6,
  126073. 8,
  126074. };
  126075. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126076. _vq_quantthresh__44cn1_s_p3_0,
  126077. _vq_quantmap__44cn1_s_p3_0,
  126078. 9,
  126079. 9
  126080. };
  126081. static static_codebook _44cn1_s_p3_0 = {
  126082. 2, 81,
  126083. _vq_lengthlist__44cn1_s_p3_0,
  126084. 1, -531628032, 1611661312, 4, 0,
  126085. _vq_quantlist__44cn1_s_p3_0,
  126086. NULL,
  126087. &_vq_auxt__44cn1_s_p3_0,
  126088. NULL,
  126089. 0
  126090. };
  126091. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126092. 4,
  126093. 3,
  126094. 5,
  126095. 2,
  126096. 6,
  126097. 1,
  126098. 7,
  126099. 0,
  126100. 8,
  126101. };
  126102. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126103. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126104. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126105. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126106. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126107. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126108. 11,
  126109. };
  126110. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126111. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126112. };
  126113. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126114. 7, 5, 3, 1, 0, 2, 4, 6,
  126115. 8,
  126116. };
  126117. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126118. _vq_quantthresh__44cn1_s_p4_0,
  126119. _vq_quantmap__44cn1_s_p4_0,
  126120. 9,
  126121. 9
  126122. };
  126123. static static_codebook _44cn1_s_p4_0 = {
  126124. 2, 81,
  126125. _vq_lengthlist__44cn1_s_p4_0,
  126126. 1, -531628032, 1611661312, 4, 0,
  126127. _vq_quantlist__44cn1_s_p4_0,
  126128. NULL,
  126129. &_vq_auxt__44cn1_s_p4_0,
  126130. NULL,
  126131. 0
  126132. };
  126133. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126134. 8,
  126135. 7,
  126136. 9,
  126137. 6,
  126138. 10,
  126139. 5,
  126140. 11,
  126141. 4,
  126142. 12,
  126143. 3,
  126144. 13,
  126145. 2,
  126146. 14,
  126147. 1,
  126148. 15,
  126149. 0,
  126150. 16,
  126151. };
  126152. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126153. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126154. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126155. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126156. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126157. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126158. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126159. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126160. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126161. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126162. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126163. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126164. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126165. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126166. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126167. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126168. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126169. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126170. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126171. 14,
  126172. };
  126173. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126174. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126175. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126176. };
  126177. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126178. 15, 13, 11, 9, 7, 5, 3, 1,
  126179. 0, 2, 4, 6, 8, 10, 12, 14,
  126180. 16,
  126181. };
  126182. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126183. _vq_quantthresh__44cn1_s_p5_0,
  126184. _vq_quantmap__44cn1_s_p5_0,
  126185. 17,
  126186. 17
  126187. };
  126188. static static_codebook _44cn1_s_p5_0 = {
  126189. 2, 289,
  126190. _vq_lengthlist__44cn1_s_p5_0,
  126191. 1, -529530880, 1611661312, 5, 0,
  126192. _vq_quantlist__44cn1_s_p5_0,
  126193. NULL,
  126194. &_vq_auxt__44cn1_s_p5_0,
  126195. NULL,
  126196. 0
  126197. };
  126198. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126199. 1,
  126200. 0,
  126201. 2,
  126202. };
  126203. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126204. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126205. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126206. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126207. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126208. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126209. 10,
  126210. };
  126211. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126212. -5.5, 5.5,
  126213. };
  126214. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126215. 1, 0, 2,
  126216. };
  126217. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126218. _vq_quantthresh__44cn1_s_p6_0,
  126219. _vq_quantmap__44cn1_s_p6_0,
  126220. 3,
  126221. 3
  126222. };
  126223. static static_codebook _44cn1_s_p6_0 = {
  126224. 4, 81,
  126225. _vq_lengthlist__44cn1_s_p6_0,
  126226. 1, -529137664, 1618345984, 2, 0,
  126227. _vq_quantlist__44cn1_s_p6_0,
  126228. NULL,
  126229. &_vq_auxt__44cn1_s_p6_0,
  126230. NULL,
  126231. 0
  126232. };
  126233. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126234. 5,
  126235. 4,
  126236. 6,
  126237. 3,
  126238. 7,
  126239. 2,
  126240. 8,
  126241. 1,
  126242. 9,
  126243. 0,
  126244. 10,
  126245. };
  126246. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126247. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126248. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126249. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126250. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126251. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126252. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126253. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126254. 10,10,10, 9, 9, 9, 9, 9, 9,
  126255. };
  126256. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126257. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126258. 3.5, 4.5,
  126259. };
  126260. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126261. 9, 7, 5, 3, 1, 0, 2, 4,
  126262. 6, 8, 10,
  126263. };
  126264. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126265. _vq_quantthresh__44cn1_s_p6_1,
  126266. _vq_quantmap__44cn1_s_p6_1,
  126267. 11,
  126268. 11
  126269. };
  126270. static static_codebook _44cn1_s_p6_1 = {
  126271. 2, 121,
  126272. _vq_lengthlist__44cn1_s_p6_1,
  126273. 1, -531365888, 1611661312, 4, 0,
  126274. _vq_quantlist__44cn1_s_p6_1,
  126275. NULL,
  126276. &_vq_auxt__44cn1_s_p6_1,
  126277. NULL,
  126278. 0
  126279. };
  126280. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126281. 6,
  126282. 5,
  126283. 7,
  126284. 4,
  126285. 8,
  126286. 3,
  126287. 9,
  126288. 2,
  126289. 10,
  126290. 1,
  126291. 11,
  126292. 0,
  126293. 12,
  126294. };
  126295. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126296. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126297. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126298. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126299. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126300. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126301. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126302. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126303. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126304. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126305. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126306. 0,13,13,12,12,13,13,13,14,
  126307. };
  126308. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126309. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126310. 12.5, 17.5, 22.5, 27.5,
  126311. };
  126312. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126313. 11, 9, 7, 5, 3, 1, 0, 2,
  126314. 4, 6, 8, 10, 12,
  126315. };
  126316. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126317. _vq_quantthresh__44cn1_s_p7_0,
  126318. _vq_quantmap__44cn1_s_p7_0,
  126319. 13,
  126320. 13
  126321. };
  126322. static static_codebook _44cn1_s_p7_0 = {
  126323. 2, 169,
  126324. _vq_lengthlist__44cn1_s_p7_0,
  126325. 1, -526516224, 1616117760, 4, 0,
  126326. _vq_quantlist__44cn1_s_p7_0,
  126327. NULL,
  126328. &_vq_auxt__44cn1_s_p7_0,
  126329. NULL,
  126330. 0
  126331. };
  126332. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126333. 2,
  126334. 1,
  126335. 3,
  126336. 0,
  126337. 4,
  126338. };
  126339. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126340. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126341. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126342. };
  126343. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126344. -1.5, -0.5, 0.5, 1.5,
  126345. };
  126346. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126347. 3, 1, 0, 2, 4,
  126348. };
  126349. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126350. _vq_quantthresh__44cn1_s_p7_1,
  126351. _vq_quantmap__44cn1_s_p7_1,
  126352. 5,
  126353. 5
  126354. };
  126355. static static_codebook _44cn1_s_p7_1 = {
  126356. 2, 25,
  126357. _vq_lengthlist__44cn1_s_p7_1,
  126358. 1, -533725184, 1611661312, 3, 0,
  126359. _vq_quantlist__44cn1_s_p7_1,
  126360. NULL,
  126361. &_vq_auxt__44cn1_s_p7_1,
  126362. NULL,
  126363. 0
  126364. };
  126365. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126366. 2,
  126367. 1,
  126368. 3,
  126369. 0,
  126370. 4,
  126371. };
  126372. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126373. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126374. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126375. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126376. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126377. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126378. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126379. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126380. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126381. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126382. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126383. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126384. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126385. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126386. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126387. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126388. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126389. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126390. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126391. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126392. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126393. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126394. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126395. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126396. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126397. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126398. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126399. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126400. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126401. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126402. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126403. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126404. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126405. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126406. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126407. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126408. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126409. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126410. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126411. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126412. 12,
  126413. };
  126414. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126415. -331.5, -110.5, 110.5, 331.5,
  126416. };
  126417. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126418. 3, 1, 0, 2, 4,
  126419. };
  126420. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126421. _vq_quantthresh__44cn1_s_p8_0,
  126422. _vq_quantmap__44cn1_s_p8_0,
  126423. 5,
  126424. 5
  126425. };
  126426. static static_codebook _44cn1_s_p8_0 = {
  126427. 4, 625,
  126428. _vq_lengthlist__44cn1_s_p8_0,
  126429. 1, -518283264, 1627103232, 3, 0,
  126430. _vq_quantlist__44cn1_s_p8_0,
  126431. NULL,
  126432. &_vq_auxt__44cn1_s_p8_0,
  126433. NULL,
  126434. 0
  126435. };
  126436. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126437. 6,
  126438. 5,
  126439. 7,
  126440. 4,
  126441. 8,
  126442. 3,
  126443. 9,
  126444. 2,
  126445. 10,
  126446. 1,
  126447. 11,
  126448. 0,
  126449. 12,
  126450. };
  126451. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126452. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126453. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126454. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126455. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126456. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126457. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126458. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126459. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126460. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126461. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126462. 15,12,12,11,11,14,12,13,14,
  126463. };
  126464. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126465. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126466. 42.5, 59.5, 76.5, 93.5,
  126467. };
  126468. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126469. 11, 9, 7, 5, 3, 1, 0, 2,
  126470. 4, 6, 8, 10, 12,
  126471. };
  126472. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126473. _vq_quantthresh__44cn1_s_p8_1,
  126474. _vq_quantmap__44cn1_s_p8_1,
  126475. 13,
  126476. 13
  126477. };
  126478. static static_codebook _44cn1_s_p8_1 = {
  126479. 2, 169,
  126480. _vq_lengthlist__44cn1_s_p8_1,
  126481. 1, -522616832, 1620115456, 4, 0,
  126482. _vq_quantlist__44cn1_s_p8_1,
  126483. NULL,
  126484. &_vq_auxt__44cn1_s_p8_1,
  126485. NULL,
  126486. 0
  126487. };
  126488. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126489. 8,
  126490. 7,
  126491. 9,
  126492. 6,
  126493. 10,
  126494. 5,
  126495. 11,
  126496. 4,
  126497. 12,
  126498. 3,
  126499. 13,
  126500. 2,
  126501. 14,
  126502. 1,
  126503. 15,
  126504. 0,
  126505. 16,
  126506. };
  126507. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126508. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126509. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126510. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126511. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126512. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126513. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126514. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126515. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126516. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126517. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126518. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126519. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126520. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126521. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126522. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126523. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126524. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126525. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126526. 9,
  126527. };
  126528. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126529. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126530. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126531. };
  126532. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126533. 15, 13, 11, 9, 7, 5, 3, 1,
  126534. 0, 2, 4, 6, 8, 10, 12, 14,
  126535. 16,
  126536. };
  126537. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  126538. _vq_quantthresh__44cn1_s_p8_2,
  126539. _vq_quantmap__44cn1_s_p8_2,
  126540. 17,
  126541. 17
  126542. };
  126543. static static_codebook _44cn1_s_p8_2 = {
  126544. 2, 289,
  126545. _vq_lengthlist__44cn1_s_p8_2,
  126546. 1, -529530880, 1611661312, 5, 0,
  126547. _vq_quantlist__44cn1_s_p8_2,
  126548. NULL,
  126549. &_vq_auxt__44cn1_s_p8_2,
  126550. NULL,
  126551. 0
  126552. };
  126553. static long _huff_lengthlist__44cn1_s_short[] = {
  126554. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  126555. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  126556. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  126557. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  126558. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  126559. 10,
  126560. };
  126561. static static_codebook _huff_book__44cn1_s_short = {
  126562. 2, 81,
  126563. _huff_lengthlist__44cn1_s_short,
  126564. 0, 0, 0, 0, 0,
  126565. NULL,
  126566. NULL,
  126567. NULL,
  126568. NULL,
  126569. 0
  126570. };
  126571. static long _huff_lengthlist__44cn1_sm_long[] = {
  126572. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  126573. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  126574. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  126575. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  126576. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  126577. 17,
  126578. };
  126579. static static_codebook _huff_book__44cn1_sm_long = {
  126580. 2, 81,
  126581. _huff_lengthlist__44cn1_sm_long,
  126582. 0, 0, 0, 0, 0,
  126583. NULL,
  126584. NULL,
  126585. NULL,
  126586. NULL,
  126587. 0
  126588. };
  126589. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  126590. 1,
  126591. 0,
  126592. 2,
  126593. };
  126594. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  126595. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126596. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126601. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  126606. 0, 0, 0, 0, 8, 9, 9, 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, 5, 8, 8, 0, 0, 0, 0,
  126641. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  126646. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  126651. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126687. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126692. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  126697. 0, 0, 0, 0, 0, 0, 9,10, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126932. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127005. 0,
  127006. };
  127007. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  127008. -0.5, 0.5,
  127009. };
  127010. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127011. 1, 0, 2,
  127012. };
  127013. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127014. _vq_quantthresh__44cn1_sm_p1_0,
  127015. _vq_quantmap__44cn1_sm_p1_0,
  127016. 3,
  127017. 3
  127018. };
  127019. static static_codebook _44cn1_sm_p1_0 = {
  127020. 8, 6561,
  127021. _vq_lengthlist__44cn1_sm_p1_0,
  127022. 1, -535822336, 1611661312, 2, 0,
  127023. _vq_quantlist__44cn1_sm_p1_0,
  127024. NULL,
  127025. &_vq_auxt__44cn1_sm_p1_0,
  127026. NULL,
  127027. 0
  127028. };
  127029. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127030. 2,
  127031. 1,
  127032. 3,
  127033. 0,
  127034. 4,
  127035. };
  127036. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127037. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127040. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127043. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  127044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127076. 0,
  127077. };
  127078. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127079. -1.5, -0.5, 0.5, 1.5,
  127080. };
  127081. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127082. 3, 1, 0, 2, 4,
  127083. };
  127084. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127085. _vq_quantthresh__44cn1_sm_p2_0,
  127086. _vq_quantmap__44cn1_sm_p2_0,
  127087. 5,
  127088. 5
  127089. };
  127090. static static_codebook _44cn1_sm_p2_0 = {
  127091. 4, 625,
  127092. _vq_lengthlist__44cn1_sm_p2_0,
  127093. 1, -533725184, 1611661312, 3, 0,
  127094. _vq_quantlist__44cn1_sm_p2_0,
  127095. NULL,
  127096. &_vq_auxt__44cn1_sm_p2_0,
  127097. NULL,
  127098. 0
  127099. };
  127100. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127101. 4,
  127102. 3,
  127103. 5,
  127104. 2,
  127105. 6,
  127106. 1,
  127107. 7,
  127108. 0,
  127109. 8,
  127110. };
  127111. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127112. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127113. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127114. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127115. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127116. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127117. 0,
  127118. };
  127119. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127120. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127121. };
  127122. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127123. 7, 5, 3, 1, 0, 2, 4, 6,
  127124. 8,
  127125. };
  127126. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127127. _vq_quantthresh__44cn1_sm_p3_0,
  127128. _vq_quantmap__44cn1_sm_p3_0,
  127129. 9,
  127130. 9
  127131. };
  127132. static static_codebook _44cn1_sm_p3_0 = {
  127133. 2, 81,
  127134. _vq_lengthlist__44cn1_sm_p3_0,
  127135. 1, -531628032, 1611661312, 4, 0,
  127136. _vq_quantlist__44cn1_sm_p3_0,
  127137. NULL,
  127138. &_vq_auxt__44cn1_sm_p3_0,
  127139. NULL,
  127140. 0
  127141. };
  127142. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127143. 4,
  127144. 3,
  127145. 5,
  127146. 2,
  127147. 6,
  127148. 1,
  127149. 7,
  127150. 0,
  127151. 8,
  127152. };
  127153. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127154. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127155. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127156. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127157. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127158. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127159. 11,
  127160. };
  127161. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127162. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127163. };
  127164. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127165. 7, 5, 3, 1, 0, 2, 4, 6,
  127166. 8,
  127167. };
  127168. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127169. _vq_quantthresh__44cn1_sm_p4_0,
  127170. _vq_quantmap__44cn1_sm_p4_0,
  127171. 9,
  127172. 9
  127173. };
  127174. static static_codebook _44cn1_sm_p4_0 = {
  127175. 2, 81,
  127176. _vq_lengthlist__44cn1_sm_p4_0,
  127177. 1, -531628032, 1611661312, 4, 0,
  127178. _vq_quantlist__44cn1_sm_p4_0,
  127179. NULL,
  127180. &_vq_auxt__44cn1_sm_p4_0,
  127181. NULL,
  127182. 0
  127183. };
  127184. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127185. 8,
  127186. 7,
  127187. 9,
  127188. 6,
  127189. 10,
  127190. 5,
  127191. 11,
  127192. 4,
  127193. 12,
  127194. 3,
  127195. 13,
  127196. 2,
  127197. 14,
  127198. 1,
  127199. 15,
  127200. 0,
  127201. 16,
  127202. };
  127203. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127204. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127205. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127206. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127207. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127208. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127209. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127210. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127211. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127212. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127213. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127214. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127215. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127216. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127217. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127218. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127219. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127220. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127221. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127222. 14,
  127223. };
  127224. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127225. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127226. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127227. };
  127228. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127229. 15, 13, 11, 9, 7, 5, 3, 1,
  127230. 0, 2, 4, 6, 8, 10, 12, 14,
  127231. 16,
  127232. };
  127233. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127234. _vq_quantthresh__44cn1_sm_p5_0,
  127235. _vq_quantmap__44cn1_sm_p5_0,
  127236. 17,
  127237. 17
  127238. };
  127239. static static_codebook _44cn1_sm_p5_0 = {
  127240. 2, 289,
  127241. _vq_lengthlist__44cn1_sm_p5_0,
  127242. 1, -529530880, 1611661312, 5, 0,
  127243. _vq_quantlist__44cn1_sm_p5_0,
  127244. NULL,
  127245. &_vq_auxt__44cn1_sm_p5_0,
  127246. NULL,
  127247. 0
  127248. };
  127249. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127250. 1,
  127251. 0,
  127252. 2,
  127253. };
  127254. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127255. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127256. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127257. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127258. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127259. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127260. 10,
  127261. };
  127262. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127263. -5.5, 5.5,
  127264. };
  127265. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127266. 1, 0, 2,
  127267. };
  127268. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127269. _vq_quantthresh__44cn1_sm_p6_0,
  127270. _vq_quantmap__44cn1_sm_p6_0,
  127271. 3,
  127272. 3
  127273. };
  127274. static static_codebook _44cn1_sm_p6_0 = {
  127275. 4, 81,
  127276. _vq_lengthlist__44cn1_sm_p6_0,
  127277. 1, -529137664, 1618345984, 2, 0,
  127278. _vq_quantlist__44cn1_sm_p6_0,
  127279. NULL,
  127280. &_vq_auxt__44cn1_sm_p6_0,
  127281. NULL,
  127282. 0
  127283. };
  127284. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127285. 5,
  127286. 4,
  127287. 6,
  127288. 3,
  127289. 7,
  127290. 2,
  127291. 8,
  127292. 1,
  127293. 9,
  127294. 0,
  127295. 10,
  127296. };
  127297. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127298. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127299. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127300. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127301. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127302. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127303. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127304. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127305. 10,10,10, 8, 9, 8, 8, 9, 8,
  127306. };
  127307. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127308. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127309. 3.5, 4.5,
  127310. };
  127311. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127312. 9, 7, 5, 3, 1, 0, 2, 4,
  127313. 6, 8, 10,
  127314. };
  127315. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127316. _vq_quantthresh__44cn1_sm_p6_1,
  127317. _vq_quantmap__44cn1_sm_p6_1,
  127318. 11,
  127319. 11
  127320. };
  127321. static static_codebook _44cn1_sm_p6_1 = {
  127322. 2, 121,
  127323. _vq_lengthlist__44cn1_sm_p6_1,
  127324. 1, -531365888, 1611661312, 4, 0,
  127325. _vq_quantlist__44cn1_sm_p6_1,
  127326. NULL,
  127327. &_vq_auxt__44cn1_sm_p6_1,
  127328. NULL,
  127329. 0
  127330. };
  127331. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127332. 6,
  127333. 5,
  127334. 7,
  127335. 4,
  127336. 8,
  127337. 3,
  127338. 9,
  127339. 2,
  127340. 10,
  127341. 1,
  127342. 11,
  127343. 0,
  127344. 12,
  127345. };
  127346. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127347. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127348. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127349. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127350. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127351. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127352. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127353. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127354. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127355. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127356. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127357. 0,13,12,12,12,13,13,13,14,
  127358. };
  127359. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127360. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127361. 12.5, 17.5, 22.5, 27.5,
  127362. };
  127363. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127364. 11, 9, 7, 5, 3, 1, 0, 2,
  127365. 4, 6, 8, 10, 12,
  127366. };
  127367. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127368. _vq_quantthresh__44cn1_sm_p7_0,
  127369. _vq_quantmap__44cn1_sm_p7_0,
  127370. 13,
  127371. 13
  127372. };
  127373. static static_codebook _44cn1_sm_p7_0 = {
  127374. 2, 169,
  127375. _vq_lengthlist__44cn1_sm_p7_0,
  127376. 1, -526516224, 1616117760, 4, 0,
  127377. _vq_quantlist__44cn1_sm_p7_0,
  127378. NULL,
  127379. &_vq_auxt__44cn1_sm_p7_0,
  127380. NULL,
  127381. 0
  127382. };
  127383. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127384. 2,
  127385. 1,
  127386. 3,
  127387. 0,
  127388. 4,
  127389. };
  127390. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127391. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127392. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127393. };
  127394. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127395. -1.5, -0.5, 0.5, 1.5,
  127396. };
  127397. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127398. 3, 1, 0, 2, 4,
  127399. };
  127400. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127401. _vq_quantthresh__44cn1_sm_p7_1,
  127402. _vq_quantmap__44cn1_sm_p7_1,
  127403. 5,
  127404. 5
  127405. };
  127406. static static_codebook _44cn1_sm_p7_1 = {
  127407. 2, 25,
  127408. _vq_lengthlist__44cn1_sm_p7_1,
  127409. 1, -533725184, 1611661312, 3, 0,
  127410. _vq_quantlist__44cn1_sm_p7_1,
  127411. NULL,
  127412. &_vq_auxt__44cn1_sm_p7_1,
  127413. NULL,
  127414. 0
  127415. };
  127416. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127417. 4,
  127418. 3,
  127419. 5,
  127420. 2,
  127421. 6,
  127422. 1,
  127423. 7,
  127424. 0,
  127425. 8,
  127426. };
  127427. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127428. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127429. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127430. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127431. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127432. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127433. 14,
  127434. };
  127435. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127436. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127437. };
  127438. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127439. 7, 5, 3, 1, 0, 2, 4, 6,
  127440. 8,
  127441. };
  127442. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127443. _vq_quantthresh__44cn1_sm_p8_0,
  127444. _vq_quantmap__44cn1_sm_p8_0,
  127445. 9,
  127446. 9
  127447. };
  127448. static static_codebook _44cn1_sm_p8_0 = {
  127449. 2, 81,
  127450. _vq_lengthlist__44cn1_sm_p8_0,
  127451. 1, -516186112, 1627103232, 4, 0,
  127452. _vq_quantlist__44cn1_sm_p8_0,
  127453. NULL,
  127454. &_vq_auxt__44cn1_sm_p8_0,
  127455. NULL,
  127456. 0
  127457. };
  127458. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127459. 6,
  127460. 5,
  127461. 7,
  127462. 4,
  127463. 8,
  127464. 3,
  127465. 9,
  127466. 2,
  127467. 10,
  127468. 1,
  127469. 11,
  127470. 0,
  127471. 12,
  127472. };
  127473. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127474. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127475. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127476. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127477. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127478. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127479. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127480. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127481. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127482. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127483. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127484. 17,12,12,11,10,13,11,13,13,
  127485. };
  127486. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127487. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127488. 42.5, 59.5, 76.5, 93.5,
  127489. };
  127490. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127491. 11, 9, 7, 5, 3, 1, 0, 2,
  127492. 4, 6, 8, 10, 12,
  127493. };
  127494. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127495. _vq_quantthresh__44cn1_sm_p8_1,
  127496. _vq_quantmap__44cn1_sm_p8_1,
  127497. 13,
  127498. 13
  127499. };
  127500. static static_codebook _44cn1_sm_p8_1 = {
  127501. 2, 169,
  127502. _vq_lengthlist__44cn1_sm_p8_1,
  127503. 1, -522616832, 1620115456, 4, 0,
  127504. _vq_quantlist__44cn1_sm_p8_1,
  127505. NULL,
  127506. &_vq_auxt__44cn1_sm_p8_1,
  127507. NULL,
  127508. 0
  127509. };
  127510. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127511. 8,
  127512. 7,
  127513. 9,
  127514. 6,
  127515. 10,
  127516. 5,
  127517. 11,
  127518. 4,
  127519. 12,
  127520. 3,
  127521. 13,
  127522. 2,
  127523. 14,
  127524. 1,
  127525. 15,
  127526. 0,
  127527. 16,
  127528. };
  127529. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127530. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127531. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127532. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127533. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127534. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  127535. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  127536. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  127537. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  127538. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  127539. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  127540. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  127541. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  127542. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  127543. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  127544. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  127545. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127546. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127547. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  127548. 9,
  127549. };
  127550. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  127551. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127552. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127553. };
  127554. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  127555. 15, 13, 11, 9, 7, 5, 3, 1,
  127556. 0, 2, 4, 6, 8, 10, 12, 14,
  127557. 16,
  127558. };
  127559. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  127560. _vq_quantthresh__44cn1_sm_p8_2,
  127561. _vq_quantmap__44cn1_sm_p8_2,
  127562. 17,
  127563. 17
  127564. };
  127565. static static_codebook _44cn1_sm_p8_2 = {
  127566. 2, 289,
  127567. _vq_lengthlist__44cn1_sm_p8_2,
  127568. 1, -529530880, 1611661312, 5, 0,
  127569. _vq_quantlist__44cn1_sm_p8_2,
  127570. NULL,
  127571. &_vq_auxt__44cn1_sm_p8_2,
  127572. NULL,
  127573. 0
  127574. };
  127575. static long _huff_lengthlist__44cn1_sm_short[] = {
  127576. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  127577. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  127578. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  127579. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  127580. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  127581. 9,
  127582. };
  127583. static static_codebook _huff_book__44cn1_sm_short = {
  127584. 2, 81,
  127585. _huff_lengthlist__44cn1_sm_short,
  127586. 0, 0, 0, 0, 0,
  127587. NULL,
  127588. NULL,
  127589. NULL,
  127590. NULL,
  127591. 0
  127592. };
  127593. /*** End of inlined file: res_books_stereo.h ***/
  127594. static vorbis_info_residue0 _residue_44_low={
  127595. 0,-1, -1, 9,-1,
  127596. {0},
  127597. {-1},
  127598. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127599. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  127600. };
  127601. static vorbis_info_residue0 _residue_44_mid={
  127602. 0,-1, -1, 10,-1,
  127603. {0},
  127604. {-1},
  127605. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127606. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  127607. };
  127608. static vorbis_info_residue0 _residue_44_high={
  127609. 0,-1, -1, 10,-1,
  127610. {0},
  127611. {-1},
  127612. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  127613. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  127614. };
  127615. static static_bookblock _resbook_44s_n1={
  127616. {
  127617. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  127618. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  127619. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  127620. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  127621. }
  127622. };
  127623. static static_bookblock _resbook_44sm_n1={
  127624. {
  127625. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  127626. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  127627. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  127628. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  127629. }
  127630. };
  127631. static static_bookblock _resbook_44s_0={
  127632. {
  127633. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  127634. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  127635. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  127636. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  127637. }
  127638. };
  127639. static static_bookblock _resbook_44sm_0={
  127640. {
  127641. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  127642. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  127643. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  127644. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  127645. }
  127646. };
  127647. static static_bookblock _resbook_44s_1={
  127648. {
  127649. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  127650. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  127651. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  127652. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  127653. }
  127654. };
  127655. static static_bookblock _resbook_44sm_1={
  127656. {
  127657. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  127658. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  127659. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  127660. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  127661. }
  127662. };
  127663. static static_bookblock _resbook_44s_2={
  127664. {
  127665. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  127666. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  127667. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  127668. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  127669. }
  127670. };
  127671. static static_bookblock _resbook_44s_3={
  127672. {
  127673. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  127674. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  127675. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  127676. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  127677. }
  127678. };
  127679. static static_bookblock _resbook_44s_4={
  127680. {
  127681. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  127682. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  127683. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  127684. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  127685. }
  127686. };
  127687. static static_bookblock _resbook_44s_5={
  127688. {
  127689. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  127690. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  127691. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  127692. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  127693. }
  127694. };
  127695. static static_bookblock _resbook_44s_6={
  127696. {
  127697. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  127698. {0,0,&_44c6_s_p4_0},
  127699. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  127700. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  127701. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  127702. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  127703. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  127704. }
  127705. };
  127706. static static_bookblock _resbook_44s_7={
  127707. {
  127708. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  127709. {0,0,&_44c7_s_p4_0},
  127710. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  127711. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  127712. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  127713. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  127714. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  127715. }
  127716. };
  127717. static static_bookblock _resbook_44s_8={
  127718. {
  127719. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  127720. {0,0,&_44c8_s_p4_0},
  127721. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  127722. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  127723. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  127724. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  127725. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  127726. }
  127727. };
  127728. static static_bookblock _resbook_44s_9={
  127729. {
  127730. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  127731. {0,0,&_44c9_s_p4_0},
  127732. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  127733. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  127734. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  127735. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  127736. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  127737. }
  127738. };
  127739. static vorbis_residue_template _res_44s_n1[]={
  127740. {2,0, &_residue_44_low,
  127741. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  127742. &_resbook_44s_n1,&_resbook_44sm_n1},
  127743. {2,0, &_residue_44_low,
  127744. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  127745. &_resbook_44s_n1,&_resbook_44sm_n1}
  127746. };
  127747. static vorbis_residue_template _res_44s_0[]={
  127748. {2,0, &_residue_44_low,
  127749. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  127750. &_resbook_44s_0,&_resbook_44sm_0},
  127751. {2,0, &_residue_44_low,
  127752. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  127753. &_resbook_44s_0,&_resbook_44sm_0}
  127754. };
  127755. static vorbis_residue_template _res_44s_1[]={
  127756. {2,0, &_residue_44_low,
  127757. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  127758. &_resbook_44s_1,&_resbook_44sm_1},
  127759. {2,0, &_residue_44_low,
  127760. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  127761. &_resbook_44s_1,&_resbook_44sm_1}
  127762. };
  127763. static vorbis_residue_template _res_44s_2[]={
  127764. {2,0, &_residue_44_mid,
  127765. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  127766. &_resbook_44s_2,&_resbook_44s_2},
  127767. {2,0, &_residue_44_mid,
  127768. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  127769. &_resbook_44s_2,&_resbook_44s_2}
  127770. };
  127771. static vorbis_residue_template _res_44s_3[]={
  127772. {2,0, &_residue_44_mid,
  127773. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  127774. &_resbook_44s_3,&_resbook_44s_3},
  127775. {2,0, &_residue_44_mid,
  127776. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  127777. &_resbook_44s_3,&_resbook_44s_3}
  127778. };
  127779. static vorbis_residue_template _res_44s_4[]={
  127780. {2,0, &_residue_44_mid,
  127781. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  127782. &_resbook_44s_4,&_resbook_44s_4},
  127783. {2,0, &_residue_44_mid,
  127784. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  127785. &_resbook_44s_4,&_resbook_44s_4}
  127786. };
  127787. static vorbis_residue_template _res_44s_5[]={
  127788. {2,0, &_residue_44_mid,
  127789. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  127790. &_resbook_44s_5,&_resbook_44s_5},
  127791. {2,0, &_residue_44_mid,
  127792. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  127793. &_resbook_44s_5,&_resbook_44s_5}
  127794. };
  127795. static vorbis_residue_template _res_44s_6[]={
  127796. {2,0, &_residue_44_high,
  127797. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  127798. &_resbook_44s_6,&_resbook_44s_6},
  127799. {2,0, &_residue_44_high,
  127800. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  127801. &_resbook_44s_6,&_resbook_44s_6}
  127802. };
  127803. static vorbis_residue_template _res_44s_7[]={
  127804. {2,0, &_residue_44_high,
  127805. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  127806. &_resbook_44s_7,&_resbook_44s_7},
  127807. {2,0, &_residue_44_high,
  127808. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  127809. &_resbook_44s_7,&_resbook_44s_7}
  127810. };
  127811. static vorbis_residue_template _res_44s_8[]={
  127812. {2,0, &_residue_44_high,
  127813. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  127814. &_resbook_44s_8,&_resbook_44s_8},
  127815. {2,0, &_residue_44_high,
  127816. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  127817. &_resbook_44s_8,&_resbook_44s_8}
  127818. };
  127819. static vorbis_residue_template _res_44s_9[]={
  127820. {2,0, &_residue_44_high,
  127821. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  127822. &_resbook_44s_9,&_resbook_44s_9},
  127823. {2,0, &_residue_44_high,
  127824. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  127825. &_resbook_44s_9,&_resbook_44s_9}
  127826. };
  127827. static vorbis_mapping_template _mapres_template_44_stereo[]={
  127828. { _map_nominal, _res_44s_n1 }, /* -1 */
  127829. { _map_nominal, _res_44s_0 }, /* 0 */
  127830. { _map_nominal, _res_44s_1 }, /* 1 */
  127831. { _map_nominal, _res_44s_2 }, /* 2 */
  127832. { _map_nominal, _res_44s_3 }, /* 3 */
  127833. { _map_nominal, _res_44s_4 }, /* 4 */
  127834. { _map_nominal, _res_44s_5 }, /* 5 */
  127835. { _map_nominal, _res_44s_6 }, /* 6 */
  127836. { _map_nominal, _res_44s_7 }, /* 7 */
  127837. { _map_nominal, _res_44s_8 }, /* 8 */
  127838. { _map_nominal, _res_44s_9 }, /* 9 */
  127839. };
  127840. /*** End of inlined file: residue_44.h ***/
  127841. /*** Start of inlined file: psych_44.h ***/
  127842. static vorbis_info_psy_global _psy_global_44[5]={
  127843. {8, /* lines per eighth octave */
  127844. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  127845. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  127846. -6.f,
  127847. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127848. },
  127849. {8, /* lines per eighth octave */
  127850. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127851. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  127852. -6.f,
  127853. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127854. },
  127855. {8, /* lines per eighth octave */
  127856. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127857. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  127858. -6.f,
  127859. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127860. },
  127861. {8, /* lines per eighth octave */
  127862. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  127863. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  127864. -6.f,
  127865. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127866. },
  127867. {8, /* lines per eighth octave */
  127868. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  127869. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  127870. -6.f,
  127871. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127872. },
  127873. };
  127874. static compandblock _psy_compand_44[6]={
  127875. {{
  127876. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127877. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127878. 16,17,18,19,20,21,22, 23, /* 23dB */
  127879. 24,25,26,27,28,29,30, 31, /* 31dB */
  127880. 32,33,34,35,36,37,38, 39, /* 39dB */
  127881. }},
  127882. {{
  127883. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  127884. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  127885. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  127886. 15,16,17,17,17,18,18, 19, /* 31dB */
  127887. 19,19,20,21,22,23,24, 25, /* 39dB */
  127888. }},
  127889. {{
  127890. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  127891. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  127892. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127893. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127894. 11,12,13,14,15,16,17, 18, /* 39dB */
  127895. }},
  127896. {{
  127897. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127898. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127899. 16,17,18,19,20,21,22, 23, /* 23dB */
  127900. 24,25,26,27,28,29,30, 31, /* 31dB */
  127901. 32,33,34,35,36,37,38, 39, /* 39dB */
  127902. }},
  127903. {{
  127904. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127905. 8, 9,10,11,12,12,13, 13, /* 15dB */
  127906. 13,14,14,14,15,15,15, 15, /* 23dB */
  127907. 16,16,17,17,17,18,18, 19, /* 31dB */
  127908. 19,19,20,21,22,23,24, 25, /* 39dB */
  127909. }},
  127910. {{
  127911. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127912. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  127913. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127914. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127915. 11,12,13,14,15,16,17, 18, /* 39dB */
  127916. }}
  127917. };
  127918. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  127919. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  127920. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  127921. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  127922. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  127923. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  127924. /* 4 */
  127925. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127926. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127927. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127928. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127929. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127930. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127931. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127932. };
  127933. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  127934. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  127935. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  127936. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  127937. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  127938. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  127939. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127940. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127941. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127942. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127943. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127944. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127945. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127946. };
  127947. static noise3 _psy_noisebias_trans[12]={
  127948. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127949. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127950. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127951. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127952. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  127953. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127954. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127955. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  127956. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  127957. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  127958. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  127959. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  127960. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  127961. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  127962. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127963. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127964. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  127965. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127966. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127967. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  127968. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  127969. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127970. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  127971. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  127972. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127973. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  127974. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  127975. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  127976. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  127977. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127978. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127979. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  127980. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  127981. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  127982. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  127983. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127984. };
  127985. static noise3 _psy_noisebias_long[12]={
  127986. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  127987. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  127988. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127989. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  127990. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  127991. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127992. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127993. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  127994. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  127995. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  127996. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  127997. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127998. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  127999. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128000. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  128001. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128002. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128003. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  128004. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128005. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128006. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  128007. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128008. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128009. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  128010. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128011. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128012. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128013. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128014. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128015. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128016. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128017. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128018. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128019. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128020. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128021. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128022. };
  128023. static noise3 _psy_noisebias_impulse[12]={
  128024. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128025. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128026. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128027. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128028. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128029. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128030. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128031. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128032. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128033. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128034. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128035. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128036. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128037. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128038. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128039. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128040. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128041. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128042. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128043. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128044. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128045. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128046. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128047. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128048. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128049. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128050. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128051. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128052. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128053. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128054. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128055. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128056. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128057. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128058. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128059. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128060. };
  128061. static noise3 _psy_noisebias_padding[12]={
  128062. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128063. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128064. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128065. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128066. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128067. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128068. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128069. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128070. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128071. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128072. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128073. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128074. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128075. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128076. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128077. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128078. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128079. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128080. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128081. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128082. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128083. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128084. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128085. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128086. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128087. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128088. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128089. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128090. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128091. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128092. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128093. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128094. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128095. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128096. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128097. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128098. };
  128099. static noiseguard _psy_noiseguards_44[4]={
  128100. {3,3,15},
  128101. {3,3,15},
  128102. {10,10,100},
  128103. {10,10,100},
  128104. };
  128105. static int _psy_tone_suppress[12]={
  128106. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128107. };
  128108. static int _psy_tone_0dB[12]={
  128109. 90,90,95,95,95,95,105,105,105,105,105,105,
  128110. };
  128111. static int _psy_noise_suppress[12]={
  128112. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128113. };
  128114. static vorbis_info_psy _psy_info_template={
  128115. -1,
  128116. -140.,-140.,
  128117. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128118. 1, -0.f, .5f, .5f, 0,0,0,
  128119. {{-1},{-1},{-1}},{-1},105.f,
  128120. 0,0,-1,-1,0.,
  128121. };
  128122. static int _psy_ath_floater[12]={
  128123. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128124. };
  128125. static int _psy_ath_abs[12]={
  128126. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128127. };
  128128. static adj_stereo _psy_stereo_modes_44[12]={
  128129. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128130. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128131. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128132. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128133. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128134. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128135. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128136. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128137. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128138. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128139. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128140. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128141. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128142. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128143. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128144. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128145. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128146. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128147. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128148. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128149. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128150. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128151. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128152. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128153. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128154. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128155. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128156. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128157. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128158. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128159. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128160. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128161. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128162. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128163. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128164. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128165. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128166. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128167. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128168. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128169. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128170. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128171. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128172. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128173. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128174. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128175. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128176. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128177. };
  128178. static att3 _psy_tone_masteratt_44[12]={
  128179. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128180. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128181. /* 1 */
  128182. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128183. /* 2 */
  128184. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128185. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128186. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128187. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128188. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128189. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128190. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128191. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128192. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128193. };
  128194. static double _psy_lowpass_44[12]={
  128195. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128196. };
  128197. static int _noise_start_short_44[11]={
  128198. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128199. };
  128200. static int _noise_start_long_44[11]={
  128201. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128202. };
  128203. static int _noise_part_short_44[11]={
  128204. 8,8,8,8,8,8,8,8,8,8,8
  128205. };
  128206. static int _noise_part_long_44[11]={
  128207. 32,32,32,32,32,32,32,32,32,32,32
  128208. };
  128209. static double _noise_thresh_44[11]={
  128210. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128211. };
  128212. static double _noise_thresh_5only[2]={
  128213. .5,.5,
  128214. };
  128215. /*** End of inlined file: psych_44.h ***/
  128216. static double rate_mapping_44_stereo[12]={
  128217. 22500.,32000.,40000.,48000.,56000.,64000.,
  128218. 80000.,96000.,112000.,128000.,160000.,250001.
  128219. };
  128220. static double quality_mapping_44[12]={
  128221. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128222. };
  128223. static int blocksize_short_44[11]={
  128224. 512,256,256,256,256,256,256,256,256,256,256
  128225. };
  128226. static int blocksize_long_44[11]={
  128227. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128228. };
  128229. static double _psy_compand_short_mapping[12]={
  128230. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128231. };
  128232. static double _psy_compand_long_mapping[12]={
  128233. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128234. };
  128235. static double _global_mapping_44[12]={
  128236. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128237. };
  128238. static int _floor_short_mapping_44[11]={
  128239. 1,0,0,2,2,4,5,5,5,5,5
  128240. };
  128241. static int _floor_long_mapping_44[11]={
  128242. 8,7,7,7,7,7,7,7,7,7,7
  128243. };
  128244. ve_setup_data_template ve_setup_44_stereo={
  128245. 11,
  128246. rate_mapping_44_stereo,
  128247. quality_mapping_44,
  128248. 2,
  128249. 40000,
  128250. 50000,
  128251. blocksize_short_44,
  128252. blocksize_long_44,
  128253. _psy_tone_masteratt_44,
  128254. _psy_tone_0dB,
  128255. _psy_tone_suppress,
  128256. _vp_tonemask_adj_otherblock,
  128257. _vp_tonemask_adj_longblock,
  128258. _vp_tonemask_adj_otherblock,
  128259. _psy_noiseguards_44,
  128260. _psy_noisebias_impulse,
  128261. _psy_noisebias_padding,
  128262. _psy_noisebias_trans,
  128263. _psy_noisebias_long,
  128264. _psy_noise_suppress,
  128265. _psy_compand_44,
  128266. _psy_compand_short_mapping,
  128267. _psy_compand_long_mapping,
  128268. {_noise_start_short_44,_noise_start_long_44},
  128269. {_noise_part_short_44,_noise_part_long_44},
  128270. _noise_thresh_44,
  128271. _psy_ath_floater,
  128272. _psy_ath_abs,
  128273. _psy_lowpass_44,
  128274. _psy_global_44,
  128275. _global_mapping_44,
  128276. _psy_stereo_modes_44,
  128277. _floor_books,
  128278. _floor,
  128279. _floor_short_mapping_44,
  128280. _floor_long_mapping_44,
  128281. _mapres_template_44_stereo
  128282. };
  128283. /*** End of inlined file: setup_44.h ***/
  128284. /*** Start of inlined file: setup_44u.h ***/
  128285. /*** Start of inlined file: residue_44u.h ***/
  128286. /*** Start of inlined file: res_books_uncoupled.h ***/
  128287. static long _vq_quantlist__16u0__p1_0[] = {
  128288. 1,
  128289. 0,
  128290. 2,
  128291. };
  128292. static long _vq_lengthlist__16u0__p1_0[] = {
  128293. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128294. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128295. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128296. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128297. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128298. 12,
  128299. };
  128300. static float _vq_quantthresh__16u0__p1_0[] = {
  128301. -0.5, 0.5,
  128302. };
  128303. static long _vq_quantmap__16u0__p1_0[] = {
  128304. 1, 0, 2,
  128305. };
  128306. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128307. _vq_quantthresh__16u0__p1_0,
  128308. _vq_quantmap__16u0__p1_0,
  128309. 3,
  128310. 3
  128311. };
  128312. static static_codebook _16u0__p1_0 = {
  128313. 4, 81,
  128314. _vq_lengthlist__16u0__p1_0,
  128315. 1, -535822336, 1611661312, 2, 0,
  128316. _vq_quantlist__16u0__p1_0,
  128317. NULL,
  128318. &_vq_auxt__16u0__p1_0,
  128319. NULL,
  128320. 0
  128321. };
  128322. static long _vq_quantlist__16u0__p2_0[] = {
  128323. 1,
  128324. 0,
  128325. 2,
  128326. };
  128327. static long _vq_lengthlist__16u0__p2_0[] = {
  128328. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128329. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128330. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128331. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128332. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128333. 8,
  128334. };
  128335. static float _vq_quantthresh__16u0__p2_0[] = {
  128336. -0.5, 0.5,
  128337. };
  128338. static long _vq_quantmap__16u0__p2_0[] = {
  128339. 1, 0, 2,
  128340. };
  128341. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128342. _vq_quantthresh__16u0__p2_0,
  128343. _vq_quantmap__16u0__p2_0,
  128344. 3,
  128345. 3
  128346. };
  128347. static static_codebook _16u0__p2_0 = {
  128348. 4, 81,
  128349. _vq_lengthlist__16u0__p2_0,
  128350. 1, -535822336, 1611661312, 2, 0,
  128351. _vq_quantlist__16u0__p2_0,
  128352. NULL,
  128353. &_vq_auxt__16u0__p2_0,
  128354. NULL,
  128355. 0
  128356. };
  128357. static long _vq_quantlist__16u0__p3_0[] = {
  128358. 2,
  128359. 1,
  128360. 3,
  128361. 0,
  128362. 4,
  128363. };
  128364. static long _vq_lengthlist__16u0__p3_0[] = {
  128365. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128366. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128367. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128368. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128369. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128370. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128371. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128372. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128373. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128374. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128375. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128376. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128377. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128378. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128379. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128380. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128381. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128382. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128383. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128384. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128385. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128386. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128387. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128388. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128389. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128390. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128391. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128392. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128393. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128394. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128395. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128396. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128397. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128398. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128399. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128400. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128401. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128402. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128403. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128404. 18,
  128405. };
  128406. static float _vq_quantthresh__16u0__p3_0[] = {
  128407. -1.5, -0.5, 0.5, 1.5,
  128408. };
  128409. static long _vq_quantmap__16u0__p3_0[] = {
  128410. 3, 1, 0, 2, 4,
  128411. };
  128412. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128413. _vq_quantthresh__16u0__p3_0,
  128414. _vq_quantmap__16u0__p3_0,
  128415. 5,
  128416. 5
  128417. };
  128418. static static_codebook _16u0__p3_0 = {
  128419. 4, 625,
  128420. _vq_lengthlist__16u0__p3_0,
  128421. 1, -533725184, 1611661312, 3, 0,
  128422. _vq_quantlist__16u0__p3_0,
  128423. NULL,
  128424. &_vq_auxt__16u0__p3_0,
  128425. NULL,
  128426. 0
  128427. };
  128428. static long _vq_quantlist__16u0__p4_0[] = {
  128429. 2,
  128430. 1,
  128431. 3,
  128432. 0,
  128433. 4,
  128434. };
  128435. static long _vq_lengthlist__16u0__p4_0[] = {
  128436. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128437. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128438. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128439. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128440. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128441. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128442. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128443. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128444. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128445. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128446. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128447. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128448. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128449. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128450. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128451. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128452. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128453. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128454. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128455. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128456. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128457. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128458. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128459. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128460. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128461. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128462. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128463. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128464. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128465. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128466. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128467. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128468. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128469. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128470. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128471. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128472. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128473. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128474. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128475. 11,
  128476. };
  128477. static float _vq_quantthresh__16u0__p4_0[] = {
  128478. -1.5, -0.5, 0.5, 1.5,
  128479. };
  128480. static long _vq_quantmap__16u0__p4_0[] = {
  128481. 3, 1, 0, 2, 4,
  128482. };
  128483. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128484. _vq_quantthresh__16u0__p4_0,
  128485. _vq_quantmap__16u0__p4_0,
  128486. 5,
  128487. 5
  128488. };
  128489. static static_codebook _16u0__p4_0 = {
  128490. 4, 625,
  128491. _vq_lengthlist__16u0__p4_0,
  128492. 1, -533725184, 1611661312, 3, 0,
  128493. _vq_quantlist__16u0__p4_0,
  128494. NULL,
  128495. &_vq_auxt__16u0__p4_0,
  128496. NULL,
  128497. 0
  128498. };
  128499. static long _vq_quantlist__16u0__p5_0[] = {
  128500. 4,
  128501. 3,
  128502. 5,
  128503. 2,
  128504. 6,
  128505. 1,
  128506. 7,
  128507. 0,
  128508. 8,
  128509. };
  128510. static long _vq_lengthlist__16u0__p5_0[] = {
  128511. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128512. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128513. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128514. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128515. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128516. 12,
  128517. };
  128518. static float _vq_quantthresh__16u0__p5_0[] = {
  128519. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128520. };
  128521. static long _vq_quantmap__16u0__p5_0[] = {
  128522. 7, 5, 3, 1, 0, 2, 4, 6,
  128523. 8,
  128524. };
  128525. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128526. _vq_quantthresh__16u0__p5_0,
  128527. _vq_quantmap__16u0__p5_0,
  128528. 9,
  128529. 9
  128530. };
  128531. static static_codebook _16u0__p5_0 = {
  128532. 2, 81,
  128533. _vq_lengthlist__16u0__p5_0,
  128534. 1, -531628032, 1611661312, 4, 0,
  128535. _vq_quantlist__16u0__p5_0,
  128536. NULL,
  128537. &_vq_auxt__16u0__p5_0,
  128538. NULL,
  128539. 0
  128540. };
  128541. static long _vq_quantlist__16u0__p6_0[] = {
  128542. 6,
  128543. 5,
  128544. 7,
  128545. 4,
  128546. 8,
  128547. 3,
  128548. 9,
  128549. 2,
  128550. 10,
  128551. 1,
  128552. 11,
  128553. 0,
  128554. 12,
  128555. };
  128556. static long _vq_lengthlist__16u0__p6_0[] = {
  128557. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  128558. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  128559. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  128560. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  128561. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  128562. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  128563. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  128564. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  128565. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  128566. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  128567. 18, 0,19, 0, 0, 0, 0, 0, 0,
  128568. };
  128569. static float _vq_quantthresh__16u0__p6_0[] = {
  128570. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128571. 12.5, 17.5, 22.5, 27.5,
  128572. };
  128573. static long _vq_quantmap__16u0__p6_0[] = {
  128574. 11, 9, 7, 5, 3, 1, 0, 2,
  128575. 4, 6, 8, 10, 12,
  128576. };
  128577. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  128578. _vq_quantthresh__16u0__p6_0,
  128579. _vq_quantmap__16u0__p6_0,
  128580. 13,
  128581. 13
  128582. };
  128583. static static_codebook _16u0__p6_0 = {
  128584. 2, 169,
  128585. _vq_lengthlist__16u0__p6_0,
  128586. 1, -526516224, 1616117760, 4, 0,
  128587. _vq_quantlist__16u0__p6_0,
  128588. NULL,
  128589. &_vq_auxt__16u0__p6_0,
  128590. NULL,
  128591. 0
  128592. };
  128593. static long _vq_quantlist__16u0__p6_1[] = {
  128594. 2,
  128595. 1,
  128596. 3,
  128597. 0,
  128598. 4,
  128599. };
  128600. static long _vq_lengthlist__16u0__p6_1[] = {
  128601. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  128602. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  128603. };
  128604. static float _vq_quantthresh__16u0__p6_1[] = {
  128605. -1.5, -0.5, 0.5, 1.5,
  128606. };
  128607. static long _vq_quantmap__16u0__p6_1[] = {
  128608. 3, 1, 0, 2, 4,
  128609. };
  128610. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  128611. _vq_quantthresh__16u0__p6_1,
  128612. _vq_quantmap__16u0__p6_1,
  128613. 5,
  128614. 5
  128615. };
  128616. static static_codebook _16u0__p6_1 = {
  128617. 2, 25,
  128618. _vq_lengthlist__16u0__p6_1,
  128619. 1, -533725184, 1611661312, 3, 0,
  128620. _vq_quantlist__16u0__p6_1,
  128621. NULL,
  128622. &_vq_auxt__16u0__p6_1,
  128623. NULL,
  128624. 0
  128625. };
  128626. static long _vq_quantlist__16u0__p7_0[] = {
  128627. 1,
  128628. 0,
  128629. 2,
  128630. };
  128631. static long _vq_lengthlist__16u0__p7_0[] = {
  128632. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128633. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128634. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128635. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128636. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128637. 7,
  128638. };
  128639. static float _vq_quantthresh__16u0__p7_0[] = {
  128640. -157.5, 157.5,
  128641. };
  128642. static long _vq_quantmap__16u0__p7_0[] = {
  128643. 1, 0, 2,
  128644. };
  128645. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  128646. _vq_quantthresh__16u0__p7_0,
  128647. _vq_quantmap__16u0__p7_0,
  128648. 3,
  128649. 3
  128650. };
  128651. static static_codebook _16u0__p7_0 = {
  128652. 4, 81,
  128653. _vq_lengthlist__16u0__p7_0,
  128654. 1, -518803456, 1628680192, 2, 0,
  128655. _vq_quantlist__16u0__p7_0,
  128656. NULL,
  128657. &_vq_auxt__16u0__p7_0,
  128658. NULL,
  128659. 0
  128660. };
  128661. static long _vq_quantlist__16u0__p7_1[] = {
  128662. 7,
  128663. 6,
  128664. 8,
  128665. 5,
  128666. 9,
  128667. 4,
  128668. 10,
  128669. 3,
  128670. 11,
  128671. 2,
  128672. 12,
  128673. 1,
  128674. 13,
  128675. 0,
  128676. 14,
  128677. };
  128678. static long _vq_lengthlist__16u0__p7_1[] = {
  128679. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  128680. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  128681. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  128682. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  128683. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  128684. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  128685. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128686. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128687. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128688. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128689. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128690. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128691. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128692. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128693. 10,
  128694. };
  128695. static float _vq_quantthresh__16u0__p7_1[] = {
  128696. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  128697. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  128698. };
  128699. static long _vq_quantmap__16u0__p7_1[] = {
  128700. 13, 11, 9, 7, 5, 3, 1, 0,
  128701. 2, 4, 6, 8, 10, 12, 14,
  128702. };
  128703. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  128704. _vq_quantthresh__16u0__p7_1,
  128705. _vq_quantmap__16u0__p7_1,
  128706. 15,
  128707. 15
  128708. };
  128709. static static_codebook _16u0__p7_1 = {
  128710. 2, 225,
  128711. _vq_lengthlist__16u0__p7_1,
  128712. 1, -520986624, 1620377600, 4, 0,
  128713. _vq_quantlist__16u0__p7_1,
  128714. NULL,
  128715. &_vq_auxt__16u0__p7_1,
  128716. NULL,
  128717. 0
  128718. };
  128719. static long _vq_quantlist__16u0__p7_2[] = {
  128720. 10,
  128721. 9,
  128722. 11,
  128723. 8,
  128724. 12,
  128725. 7,
  128726. 13,
  128727. 6,
  128728. 14,
  128729. 5,
  128730. 15,
  128731. 4,
  128732. 16,
  128733. 3,
  128734. 17,
  128735. 2,
  128736. 18,
  128737. 1,
  128738. 19,
  128739. 0,
  128740. 20,
  128741. };
  128742. static long _vq_lengthlist__16u0__p7_2[] = {
  128743. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  128744. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  128745. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  128746. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  128747. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  128748. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  128749. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  128750. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  128751. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  128752. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  128753. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  128754. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  128755. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  128756. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  128757. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  128758. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  128759. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  128760. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  128761. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  128762. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  128763. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  128764. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  128765. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  128766. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  128767. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  128768. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  128769. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  128770. 10,10,12,11,10,11,11,11,10,
  128771. };
  128772. static float _vq_quantthresh__16u0__p7_2[] = {
  128773. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  128774. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  128775. 6.5, 7.5, 8.5, 9.5,
  128776. };
  128777. static long _vq_quantmap__16u0__p7_2[] = {
  128778. 19, 17, 15, 13, 11, 9, 7, 5,
  128779. 3, 1, 0, 2, 4, 6, 8, 10,
  128780. 12, 14, 16, 18, 20,
  128781. };
  128782. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  128783. _vq_quantthresh__16u0__p7_2,
  128784. _vq_quantmap__16u0__p7_2,
  128785. 21,
  128786. 21
  128787. };
  128788. static static_codebook _16u0__p7_2 = {
  128789. 2, 441,
  128790. _vq_lengthlist__16u0__p7_2,
  128791. 1, -529268736, 1611661312, 5, 0,
  128792. _vq_quantlist__16u0__p7_2,
  128793. NULL,
  128794. &_vq_auxt__16u0__p7_2,
  128795. NULL,
  128796. 0
  128797. };
  128798. static long _huff_lengthlist__16u0__single[] = {
  128799. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  128800. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  128801. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  128802. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  128803. };
  128804. static static_codebook _huff_book__16u0__single = {
  128805. 2, 64,
  128806. _huff_lengthlist__16u0__single,
  128807. 0, 0, 0, 0, 0,
  128808. NULL,
  128809. NULL,
  128810. NULL,
  128811. NULL,
  128812. 0
  128813. };
  128814. static long _huff_lengthlist__16u1__long[] = {
  128815. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  128816. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  128817. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  128818. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  128819. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  128820. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  128821. 16,13,16,18,
  128822. };
  128823. static static_codebook _huff_book__16u1__long = {
  128824. 2, 100,
  128825. _huff_lengthlist__16u1__long,
  128826. 0, 0, 0, 0, 0,
  128827. NULL,
  128828. NULL,
  128829. NULL,
  128830. NULL,
  128831. 0
  128832. };
  128833. static long _vq_quantlist__16u1__p1_0[] = {
  128834. 1,
  128835. 0,
  128836. 2,
  128837. };
  128838. static long _vq_lengthlist__16u1__p1_0[] = {
  128839. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  128840. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  128841. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  128842. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  128843. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  128844. 11,
  128845. };
  128846. static float _vq_quantthresh__16u1__p1_0[] = {
  128847. -0.5, 0.5,
  128848. };
  128849. static long _vq_quantmap__16u1__p1_0[] = {
  128850. 1, 0, 2,
  128851. };
  128852. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  128853. _vq_quantthresh__16u1__p1_0,
  128854. _vq_quantmap__16u1__p1_0,
  128855. 3,
  128856. 3
  128857. };
  128858. static static_codebook _16u1__p1_0 = {
  128859. 4, 81,
  128860. _vq_lengthlist__16u1__p1_0,
  128861. 1, -535822336, 1611661312, 2, 0,
  128862. _vq_quantlist__16u1__p1_0,
  128863. NULL,
  128864. &_vq_auxt__16u1__p1_0,
  128865. NULL,
  128866. 0
  128867. };
  128868. static long _vq_quantlist__16u1__p2_0[] = {
  128869. 1,
  128870. 0,
  128871. 2,
  128872. };
  128873. static long _vq_lengthlist__16u1__p2_0[] = {
  128874. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  128875. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  128876. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  128877. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  128878. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  128879. 8,
  128880. };
  128881. static float _vq_quantthresh__16u1__p2_0[] = {
  128882. -0.5, 0.5,
  128883. };
  128884. static long _vq_quantmap__16u1__p2_0[] = {
  128885. 1, 0, 2,
  128886. };
  128887. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  128888. _vq_quantthresh__16u1__p2_0,
  128889. _vq_quantmap__16u1__p2_0,
  128890. 3,
  128891. 3
  128892. };
  128893. static static_codebook _16u1__p2_0 = {
  128894. 4, 81,
  128895. _vq_lengthlist__16u1__p2_0,
  128896. 1, -535822336, 1611661312, 2, 0,
  128897. _vq_quantlist__16u1__p2_0,
  128898. NULL,
  128899. &_vq_auxt__16u1__p2_0,
  128900. NULL,
  128901. 0
  128902. };
  128903. static long _vq_quantlist__16u1__p3_0[] = {
  128904. 2,
  128905. 1,
  128906. 3,
  128907. 0,
  128908. 4,
  128909. };
  128910. static long _vq_lengthlist__16u1__p3_0[] = {
  128911. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  128912. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  128913. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  128914. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  128915. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  128916. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  128917. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  128918. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  128919. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  128920. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  128921. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  128922. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  128923. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  128924. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  128925. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  128926. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  128927. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  128928. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  128929. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  128930. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  128931. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  128932. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  128933. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  128934. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  128935. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  128936. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  128937. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  128938. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  128939. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  128940. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  128941. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  128942. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  128943. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  128944. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  128945. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  128946. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  128947. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  128948. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  128949. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  128950. 16,
  128951. };
  128952. static float _vq_quantthresh__16u1__p3_0[] = {
  128953. -1.5, -0.5, 0.5, 1.5,
  128954. };
  128955. static long _vq_quantmap__16u1__p3_0[] = {
  128956. 3, 1, 0, 2, 4,
  128957. };
  128958. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  128959. _vq_quantthresh__16u1__p3_0,
  128960. _vq_quantmap__16u1__p3_0,
  128961. 5,
  128962. 5
  128963. };
  128964. static static_codebook _16u1__p3_0 = {
  128965. 4, 625,
  128966. _vq_lengthlist__16u1__p3_0,
  128967. 1, -533725184, 1611661312, 3, 0,
  128968. _vq_quantlist__16u1__p3_0,
  128969. NULL,
  128970. &_vq_auxt__16u1__p3_0,
  128971. NULL,
  128972. 0
  128973. };
  128974. static long _vq_quantlist__16u1__p4_0[] = {
  128975. 2,
  128976. 1,
  128977. 3,
  128978. 0,
  128979. 4,
  128980. };
  128981. static long _vq_lengthlist__16u1__p4_0[] = {
  128982. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  128983. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  128984. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  128985. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  128986. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  128987. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  128988. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  128989. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  128990. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  128991. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  128992. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  128993. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  128994. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  128995. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  128996. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  128997. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  128998. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  128999. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  129000. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  129001. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  129002. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  129003. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  129004. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  129005. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  129006. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  129007. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  129008. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  129009. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  129010. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129011. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129012. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129013. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129014. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129015. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129016. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129017. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129018. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129019. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129020. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129021. 11,
  129022. };
  129023. static float _vq_quantthresh__16u1__p4_0[] = {
  129024. -1.5, -0.5, 0.5, 1.5,
  129025. };
  129026. static long _vq_quantmap__16u1__p4_0[] = {
  129027. 3, 1, 0, 2, 4,
  129028. };
  129029. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129030. _vq_quantthresh__16u1__p4_0,
  129031. _vq_quantmap__16u1__p4_0,
  129032. 5,
  129033. 5
  129034. };
  129035. static static_codebook _16u1__p4_0 = {
  129036. 4, 625,
  129037. _vq_lengthlist__16u1__p4_0,
  129038. 1, -533725184, 1611661312, 3, 0,
  129039. _vq_quantlist__16u1__p4_0,
  129040. NULL,
  129041. &_vq_auxt__16u1__p4_0,
  129042. NULL,
  129043. 0
  129044. };
  129045. static long _vq_quantlist__16u1__p5_0[] = {
  129046. 4,
  129047. 3,
  129048. 5,
  129049. 2,
  129050. 6,
  129051. 1,
  129052. 7,
  129053. 0,
  129054. 8,
  129055. };
  129056. static long _vq_lengthlist__16u1__p5_0[] = {
  129057. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129058. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129059. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129060. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129061. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129062. 13,
  129063. };
  129064. static float _vq_quantthresh__16u1__p5_0[] = {
  129065. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129066. };
  129067. static long _vq_quantmap__16u1__p5_0[] = {
  129068. 7, 5, 3, 1, 0, 2, 4, 6,
  129069. 8,
  129070. };
  129071. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129072. _vq_quantthresh__16u1__p5_0,
  129073. _vq_quantmap__16u1__p5_0,
  129074. 9,
  129075. 9
  129076. };
  129077. static static_codebook _16u1__p5_0 = {
  129078. 2, 81,
  129079. _vq_lengthlist__16u1__p5_0,
  129080. 1, -531628032, 1611661312, 4, 0,
  129081. _vq_quantlist__16u1__p5_0,
  129082. NULL,
  129083. &_vq_auxt__16u1__p5_0,
  129084. NULL,
  129085. 0
  129086. };
  129087. static long _vq_quantlist__16u1__p6_0[] = {
  129088. 4,
  129089. 3,
  129090. 5,
  129091. 2,
  129092. 6,
  129093. 1,
  129094. 7,
  129095. 0,
  129096. 8,
  129097. };
  129098. static long _vq_lengthlist__16u1__p6_0[] = {
  129099. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129100. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129101. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129102. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129103. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129104. 11,
  129105. };
  129106. static float _vq_quantthresh__16u1__p6_0[] = {
  129107. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129108. };
  129109. static long _vq_quantmap__16u1__p6_0[] = {
  129110. 7, 5, 3, 1, 0, 2, 4, 6,
  129111. 8,
  129112. };
  129113. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129114. _vq_quantthresh__16u1__p6_0,
  129115. _vq_quantmap__16u1__p6_0,
  129116. 9,
  129117. 9
  129118. };
  129119. static static_codebook _16u1__p6_0 = {
  129120. 2, 81,
  129121. _vq_lengthlist__16u1__p6_0,
  129122. 1, -531628032, 1611661312, 4, 0,
  129123. _vq_quantlist__16u1__p6_0,
  129124. NULL,
  129125. &_vq_auxt__16u1__p6_0,
  129126. NULL,
  129127. 0
  129128. };
  129129. static long _vq_quantlist__16u1__p7_0[] = {
  129130. 1,
  129131. 0,
  129132. 2,
  129133. };
  129134. static long _vq_lengthlist__16u1__p7_0[] = {
  129135. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129136. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129137. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129138. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129139. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129140. 13,
  129141. };
  129142. static float _vq_quantthresh__16u1__p7_0[] = {
  129143. -5.5, 5.5,
  129144. };
  129145. static long _vq_quantmap__16u1__p7_0[] = {
  129146. 1, 0, 2,
  129147. };
  129148. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129149. _vq_quantthresh__16u1__p7_0,
  129150. _vq_quantmap__16u1__p7_0,
  129151. 3,
  129152. 3
  129153. };
  129154. static static_codebook _16u1__p7_0 = {
  129155. 4, 81,
  129156. _vq_lengthlist__16u1__p7_0,
  129157. 1, -529137664, 1618345984, 2, 0,
  129158. _vq_quantlist__16u1__p7_0,
  129159. NULL,
  129160. &_vq_auxt__16u1__p7_0,
  129161. NULL,
  129162. 0
  129163. };
  129164. static long _vq_quantlist__16u1__p7_1[] = {
  129165. 5,
  129166. 4,
  129167. 6,
  129168. 3,
  129169. 7,
  129170. 2,
  129171. 8,
  129172. 1,
  129173. 9,
  129174. 0,
  129175. 10,
  129176. };
  129177. static long _vq_lengthlist__16u1__p7_1[] = {
  129178. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129179. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129180. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129181. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129182. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129183. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129184. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129185. 8, 9, 9,10,10,10,10,10,10,
  129186. };
  129187. static float _vq_quantthresh__16u1__p7_1[] = {
  129188. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129189. 3.5, 4.5,
  129190. };
  129191. static long _vq_quantmap__16u1__p7_1[] = {
  129192. 9, 7, 5, 3, 1, 0, 2, 4,
  129193. 6, 8, 10,
  129194. };
  129195. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129196. _vq_quantthresh__16u1__p7_1,
  129197. _vq_quantmap__16u1__p7_1,
  129198. 11,
  129199. 11
  129200. };
  129201. static static_codebook _16u1__p7_1 = {
  129202. 2, 121,
  129203. _vq_lengthlist__16u1__p7_1,
  129204. 1, -531365888, 1611661312, 4, 0,
  129205. _vq_quantlist__16u1__p7_1,
  129206. NULL,
  129207. &_vq_auxt__16u1__p7_1,
  129208. NULL,
  129209. 0
  129210. };
  129211. static long _vq_quantlist__16u1__p8_0[] = {
  129212. 5,
  129213. 4,
  129214. 6,
  129215. 3,
  129216. 7,
  129217. 2,
  129218. 8,
  129219. 1,
  129220. 9,
  129221. 0,
  129222. 10,
  129223. };
  129224. static long _vq_lengthlist__16u1__p8_0[] = {
  129225. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129226. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129227. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129228. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129229. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129230. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129231. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129232. 13,14,14,15,15,16,16,15,16,
  129233. };
  129234. static float _vq_quantthresh__16u1__p8_0[] = {
  129235. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129236. 38.5, 49.5,
  129237. };
  129238. static long _vq_quantmap__16u1__p8_0[] = {
  129239. 9, 7, 5, 3, 1, 0, 2, 4,
  129240. 6, 8, 10,
  129241. };
  129242. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129243. _vq_quantthresh__16u1__p8_0,
  129244. _vq_quantmap__16u1__p8_0,
  129245. 11,
  129246. 11
  129247. };
  129248. static static_codebook _16u1__p8_0 = {
  129249. 2, 121,
  129250. _vq_lengthlist__16u1__p8_0,
  129251. 1, -524582912, 1618345984, 4, 0,
  129252. _vq_quantlist__16u1__p8_0,
  129253. NULL,
  129254. &_vq_auxt__16u1__p8_0,
  129255. NULL,
  129256. 0
  129257. };
  129258. static long _vq_quantlist__16u1__p8_1[] = {
  129259. 5,
  129260. 4,
  129261. 6,
  129262. 3,
  129263. 7,
  129264. 2,
  129265. 8,
  129266. 1,
  129267. 9,
  129268. 0,
  129269. 10,
  129270. };
  129271. static long _vq_lengthlist__16u1__p8_1[] = {
  129272. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129273. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129274. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129275. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129276. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129277. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129278. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129279. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129280. };
  129281. static float _vq_quantthresh__16u1__p8_1[] = {
  129282. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129283. 3.5, 4.5,
  129284. };
  129285. static long _vq_quantmap__16u1__p8_1[] = {
  129286. 9, 7, 5, 3, 1, 0, 2, 4,
  129287. 6, 8, 10,
  129288. };
  129289. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129290. _vq_quantthresh__16u1__p8_1,
  129291. _vq_quantmap__16u1__p8_1,
  129292. 11,
  129293. 11
  129294. };
  129295. static static_codebook _16u1__p8_1 = {
  129296. 2, 121,
  129297. _vq_lengthlist__16u1__p8_1,
  129298. 1, -531365888, 1611661312, 4, 0,
  129299. _vq_quantlist__16u1__p8_1,
  129300. NULL,
  129301. &_vq_auxt__16u1__p8_1,
  129302. NULL,
  129303. 0
  129304. };
  129305. static long _vq_quantlist__16u1__p9_0[] = {
  129306. 7,
  129307. 6,
  129308. 8,
  129309. 5,
  129310. 9,
  129311. 4,
  129312. 10,
  129313. 3,
  129314. 11,
  129315. 2,
  129316. 12,
  129317. 1,
  129318. 13,
  129319. 0,
  129320. 14,
  129321. };
  129322. static long _vq_lengthlist__16u1__p9_0[] = {
  129323. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129324. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129325. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129326. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129327. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129328. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129329. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129330. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129331. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129332. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129333. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129334. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129335. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129336. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129337. 8,
  129338. };
  129339. static float _vq_quantthresh__16u1__p9_0[] = {
  129340. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129341. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129342. };
  129343. static long _vq_quantmap__16u1__p9_0[] = {
  129344. 13, 11, 9, 7, 5, 3, 1, 0,
  129345. 2, 4, 6, 8, 10, 12, 14,
  129346. };
  129347. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129348. _vq_quantthresh__16u1__p9_0,
  129349. _vq_quantmap__16u1__p9_0,
  129350. 15,
  129351. 15
  129352. };
  129353. static static_codebook _16u1__p9_0 = {
  129354. 2, 225,
  129355. _vq_lengthlist__16u1__p9_0,
  129356. 1, -514071552, 1627381760, 4, 0,
  129357. _vq_quantlist__16u1__p9_0,
  129358. NULL,
  129359. &_vq_auxt__16u1__p9_0,
  129360. NULL,
  129361. 0
  129362. };
  129363. static long _vq_quantlist__16u1__p9_1[] = {
  129364. 7,
  129365. 6,
  129366. 8,
  129367. 5,
  129368. 9,
  129369. 4,
  129370. 10,
  129371. 3,
  129372. 11,
  129373. 2,
  129374. 12,
  129375. 1,
  129376. 13,
  129377. 0,
  129378. 14,
  129379. };
  129380. static long _vq_lengthlist__16u1__p9_1[] = {
  129381. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129382. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129383. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129384. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129385. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129386. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129387. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129388. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129389. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129390. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129391. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129392. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129393. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129394. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129395. 9,
  129396. };
  129397. static float _vq_quantthresh__16u1__p9_1[] = {
  129398. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129399. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129400. };
  129401. static long _vq_quantmap__16u1__p9_1[] = {
  129402. 13, 11, 9, 7, 5, 3, 1, 0,
  129403. 2, 4, 6, 8, 10, 12, 14,
  129404. };
  129405. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129406. _vq_quantthresh__16u1__p9_1,
  129407. _vq_quantmap__16u1__p9_1,
  129408. 15,
  129409. 15
  129410. };
  129411. static static_codebook _16u1__p9_1 = {
  129412. 2, 225,
  129413. _vq_lengthlist__16u1__p9_1,
  129414. 1, -522338304, 1620115456, 4, 0,
  129415. _vq_quantlist__16u1__p9_1,
  129416. NULL,
  129417. &_vq_auxt__16u1__p9_1,
  129418. NULL,
  129419. 0
  129420. };
  129421. static long _vq_quantlist__16u1__p9_2[] = {
  129422. 8,
  129423. 7,
  129424. 9,
  129425. 6,
  129426. 10,
  129427. 5,
  129428. 11,
  129429. 4,
  129430. 12,
  129431. 3,
  129432. 13,
  129433. 2,
  129434. 14,
  129435. 1,
  129436. 15,
  129437. 0,
  129438. 16,
  129439. };
  129440. static long _vq_lengthlist__16u1__p9_2[] = {
  129441. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129442. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129443. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129444. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129445. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129446. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129447. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129448. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129449. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129450. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129451. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129452. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129453. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129454. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129455. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129456. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129457. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129458. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129459. 10,
  129460. };
  129461. static float _vq_quantthresh__16u1__p9_2[] = {
  129462. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129463. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129464. };
  129465. static long _vq_quantmap__16u1__p9_2[] = {
  129466. 15, 13, 11, 9, 7, 5, 3, 1,
  129467. 0, 2, 4, 6, 8, 10, 12, 14,
  129468. 16,
  129469. };
  129470. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129471. _vq_quantthresh__16u1__p9_2,
  129472. _vq_quantmap__16u1__p9_2,
  129473. 17,
  129474. 17
  129475. };
  129476. static static_codebook _16u1__p9_2 = {
  129477. 2, 289,
  129478. _vq_lengthlist__16u1__p9_2,
  129479. 1, -529530880, 1611661312, 5, 0,
  129480. _vq_quantlist__16u1__p9_2,
  129481. NULL,
  129482. &_vq_auxt__16u1__p9_2,
  129483. NULL,
  129484. 0
  129485. };
  129486. static long _huff_lengthlist__16u1__short[] = {
  129487. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129488. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129489. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129490. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129491. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129492. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129493. 16,16,16,16,
  129494. };
  129495. static static_codebook _huff_book__16u1__short = {
  129496. 2, 100,
  129497. _huff_lengthlist__16u1__short,
  129498. 0, 0, 0, 0, 0,
  129499. NULL,
  129500. NULL,
  129501. NULL,
  129502. NULL,
  129503. 0
  129504. };
  129505. static long _huff_lengthlist__16u2__long[] = {
  129506. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129507. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129508. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129509. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129510. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129511. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129512. 13,14,18,18,
  129513. };
  129514. static static_codebook _huff_book__16u2__long = {
  129515. 2, 100,
  129516. _huff_lengthlist__16u2__long,
  129517. 0, 0, 0, 0, 0,
  129518. NULL,
  129519. NULL,
  129520. NULL,
  129521. NULL,
  129522. 0
  129523. };
  129524. static long _huff_lengthlist__16u2__short[] = {
  129525. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129526. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129527. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129528. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129529. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129530. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129531. 16,16,16,16,
  129532. };
  129533. static static_codebook _huff_book__16u2__short = {
  129534. 2, 100,
  129535. _huff_lengthlist__16u2__short,
  129536. 0, 0, 0, 0, 0,
  129537. NULL,
  129538. NULL,
  129539. NULL,
  129540. NULL,
  129541. 0
  129542. };
  129543. static long _vq_quantlist__16u2_p1_0[] = {
  129544. 1,
  129545. 0,
  129546. 2,
  129547. };
  129548. static long _vq_lengthlist__16u2_p1_0[] = {
  129549. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  129550. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  129551. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  129552. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  129553. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  129554. 10,
  129555. };
  129556. static float _vq_quantthresh__16u2_p1_0[] = {
  129557. -0.5, 0.5,
  129558. };
  129559. static long _vq_quantmap__16u2_p1_0[] = {
  129560. 1, 0, 2,
  129561. };
  129562. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  129563. _vq_quantthresh__16u2_p1_0,
  129564. _vq_quantmap__16u2_p1_0,
  129565. 3,
  129566. 3
  129567. };
  129568. static static_codebook _16u2_p1_0 = {
  129569. 4, 81,
  129570. _vq_lengthlist__16u2_p1_0,
  129571. 1, -535822336, 1611661312, 2, 0,
  129572. _vq_quantlist__16u2_p1_0,
  129573. NULL,
  129574. &_vq_auxt__16u2_p1_0,
  129575. NULL,
  129576. 0
  129577. };
  129578. static long _vq_quantlist__16u2_p2_0[] = {
  129579. 2,
  129580. 1,
  129581. 3,
  129582. 0,
  129583. 4,
  129584. };
  129585. static long _vq_lengthlist__16u2_p2_0[] = {
  129586. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129587. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  129588. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  129589. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  129590. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  129591. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  129592. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  129593. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  129594. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129595. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  129596. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  129597. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  129598. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  129599. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  129600. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  129601. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  129602. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  129603. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  129604. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  129605. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  129606. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  129607. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  129608. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  129609. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  129610. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  129611. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  129612. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  129613. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  129614. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  129615. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  129616. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  129617. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  129618. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  129619. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  129620. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  129621. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  129622. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  129623. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  129624. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  129625. 13,
  129626. };
  129627. static float _vq_quantthresh__16u2_p2_0[] = {
  129628. -1.5, -0.5, 0.5, 1.5,
  129629. };
  129630. static long _vq_quantmap__16u2_p2_0[] = {
  129631. 3, 1, 0, 2, 4,
  129632. };
  129633. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  129634. _vq_quantthresh__16u2_p2_0,
  129635. _vq_quantmap__16u2_p2_0,
  129636. 5,
  129637. 5
  129638. };
  129639. static static_codebook _16u2_p2_0 = {
  129640. 4, 625,
  129641. _vq_lengthlist__16u2_p2_0,
  129642. 1, -533725184, 1611661312, 3, 0,
  129643. _vq_quantlist__16u2_p2_0,
  129644. NULL,
  129645. &_vq_auxt__16u2_p2_0,
  129646. NULL,
  129647. 0
  129648. };
  129649. static long _vq_quantlist__16u2_p3_0[] = {
  129650. 4,
  129651. 3,
  129652. 5,
  129653. 2,
  129654. 6,
  129655. 1,
  129656. 7,
  129657. 0,
  129658. 8,
  129659. };
  129660. static long _vq_lengthlist__16u2_p3_0[] = {
  129661. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  129662. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  129663. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129664. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129665. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129666. 11,
  129667. };
  129668. static float _vq_quantthresh__16u2_p3_0[] = {
  129669. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129670. };
  129671. static long _vq_quantmap__16u2_p3_0[] = {
  129672. 7, 5, 3, 1, 0, 2, 4, 6,
  129673. 8,
  129674. };
  129675. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  129676. _vq_quantthresh__16u2_p3_0,
  129677. _vq_quantmap__16u2_p3_0,
  129678. 9,
  129679. 9
  129680. };
  129681. static static_codebook _16u2_p3_0 = {
  129682. 2, 81,
  129683. _vq_lengthlist__16u2_p3_0,
  129684. 1, -531628032, 1611661312, 4, 0,
  129685. _vq_quantlist__16u2_p3_0,
  129686. NULL,
  129687. &_vq_auxt__16u2_p3_0,
  129688. NULL,
  129689. 0
  129690. };
  129691. static long _vq_quantlist__16u2_p4_0[] = {
  129692. 8,
  129693. 7,
  129694. 9,
  129695. 6,
  129696. 10,
  129697. 5,
  129698. 11,
  129699. 4,
  129700. 12,
  129701. 3,
  129702. 13,
  129703. 2,
  129704. 14,
  129705. 1,
  129706. 15,
  129707. 0,
  129708. 16,
  129709. };
  129710. static long _vq_lengthlist__16u2_p4_0[] = {
  129711. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  129712. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  129713. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  129714. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  129715. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  129716. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  129717. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  129718. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  129719. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  129720. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  129721. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  129722. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  129723. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  129724. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  129725. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  129726. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  129727. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  129728. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  129729. 14,
  129730. };
  129731. static float _vq_quantthresh__16u2_p4_0[] = {
  129732. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129733. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129734. };
  129735. static long _vq_quantmap__16u2_p4_0[] = {
  129736. 15, 13, 11, 9, 7, 5, 3, 1,
  129737. 0, 2, 4, 6, 8, 10, 12, 14,
  129738. 16,
  129739. };
  129740. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  129741. _vq_quantthresh__16u2_p4_0,
  129742. _vq_quantmap__16u2_p4_0,
  129743. 17,
  129744. 17
  129745. };
  129746. static static_codebook _16u2_p4_0 = {
  129747. 2, 289,
  129748. _vq_lengthlist__16u2_p4_0,
  129749. 1, -529530880, 1611661312, 5, 0,
  129750. _vq_quantlist__16u2_p4_0,
  129751. NULL,
  129752. &_vq_auxt__16u2_p4_0,
  129753. NULL,
  129754. 0
  129755. };
  129756. static long _vq_quantlist__16u2_p5_0[] = {
  129757. 1,
  129758. 0,
  129759. 2,
  129760. };
  129761. static long _vq_lengthlist__16u2_p5_0[] = {
  129762. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  129763. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  129764. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  129765. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  129766. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  129767. 10,
  129768. };
  129769. static float _vq_quantthresh__16u2_p5_0[] = {
  129770. -5.5, 5.5,
  129771. };
  129772. static long _vq_quantmap__16u2_p5_0[] = {
  129773. 1, 0, 2,
  129774. };
  129775. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  129776. _vq_quantthresh__16u2_p5_0,
  129777. _vq_quantmap__16u2_p5_0,
  129778. 3,
  129779. 3
  129780. };
  129781. static static_codebook _16u2_p5_0 = {
  129782. 4, 81,
  129783. _vq_lengthlist__16u2_p5_0,
  129784. 1, -529137664, 1618345984, 2, 0,
  129785. _vq_quantlist__16u2_p5_0,
  129786. NULL,
  129787. &_vq_auxt__16u2_p5_0,
  129788. NULL,
  129789. 0
  129790. };
  129791. static long _vq_quantlist__16u2_p5_1[] = {
  129792. 5,
  129793. 4,
  129794. 6,
  129795. 3,
  129796. 7,
  129797. 2,
  129798. 8,
  129799. 1,
  129800. 9,
  129801. 0,
  129802. 10,
  129803. };
  129804. static long _vq_lengthlist__16u2_p5_1[] = {
  129805. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  129806. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  129807. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  129808. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129809. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129810. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129811. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129812. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  129813. };
  129814. static float _vq_quantthresh__16u2_p5_1[] = {
  129815. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129816. 3.5, 4.5,
  129817. };
  129818. static long _vq_quantmap__16u2_p5_1[] = {
  129819. 9, 7, 5, 3, 1, 0, 2, 4,
  129820. 6, 8, 10,
  129821. };
  129822. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  129823. _vq_quantthresh__16u2_p5_1,
  129824. _vq_quantmap__16u2_p5_1,
  129825. 11,
  129826. 11
  129827. };
  129828. static static_codebook _16u2_p5_1 = {
  129829. 2, 121,
  129830. _vq_lengthlist__16u2_p5_1,
  129831. 1, -531365888, 1611661312, 4, 0,
  129832. _vq_quantlist__16u2_p5_1,
  129833. NULL,
  129834. &_vq_auxt__16u2_p5_1,
  129835. NULL,
  129836. 0
  129837. };
  129838. static long _vq_quantlist__16u2_p6_0[] = {
  129839. 6,
  129840. 5,
  129841. 7,
  129842. 4,
  129843. 8,
  129844. 3,
  129845. 9,
  129846. 2,
  129847. 10,
  129848. 1,
  129849. 11,
  129850. 0,
  129851. 12,
  129852. };
  129853. static long _vq_lengthlist__16u2_p6_0[] = {
  129854. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  129855. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  129856. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  129857. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  129858. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  129859. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  129860. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  129861. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  129862. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  129863. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  129864. 12,13,13,14,14,14,14,15,15,
  129865. };
  129866. static float _vq_quantthresh__16u2_p6_0[] = {
  129867. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129868. 12.5, 17.5, 22.5, 27.5,
  129869. };
  129870. static long _vq_quantmap__16u2_p6_0[] = {
  129871. 11, 9, 7, 5, 3, 1, 0, 2,
  129872. 4, 6, 8, 10, 12,
  129873. };
  129874. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  129875. _vq_quantthresh__16u2_p6_0,
  129876. _vq_quantmap__16u2_p6_0,
  129877. 13,
  129878. 13
  129879. };
  129880. static static_codebook _16u2_p6_0 = {
  129881. 2, 169,
  129882. _vq_lengthlist__16u2_p6_0,
  129883. 1, -526516224, 1616117760, 4, 0,
  129884. _vq_quantlist__16u2_p6_0,
  129885. NULL,
  129886. &_vq_auxt__16u2_p6_0,
  129887. NULL,
  129888. 0
  129889. };
  129890. static long _vq_quantlist__16u2_p6_1[] = {
  129891. 2,
  129892. 1,
  129893. 3,
  129894. 0,
  129895. 4,
  129896. };
  129897. static long _vq_lengthlist__16u2_p6_1[] = {
  129898. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  129899. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  129900. };
  129901. static float _vq_quantthresh__16u2_p6_1[] = {
  129902. -1.5, -0.5, 0.5, 1.5,
  129903. };
  129904. static long _vq_quantmap__16u2_p6_1[] = {
  129905. 3, 1, 0, 2, 4,
  129906. };
  129907. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  129908. _vq_quantthresh__16u2_p6_1,
  129909. _vq_quantmap__16u2_p6_1,
  129910. 5,
  129911. 5
  129912. };
  129913. static static_codebook _16u2_p6_1 = {
  129914. 2, 25,
  129915. _vq_lengthlist__16u2_p6_1,
  129916. 1, -533725184, 1611661312, 3, 0,
  129917. _vq_quantlist__16u2_p6_1,
  129918. NULL,
  129919. &_vq_auxt__16u2_p6_1,
  129920. NULL,
  129921. 0
  129922. };
  129923. static long _vq_quantlist__16u2_p7_0[] = {
  129924. 6,
  129925. 5,
  129926. 7,
  129927. 4,
  129928. 8,
  129929. 3,
  129930. 9,
  129931. 2,
  129932. 10,
  129933. 1,
  129934. 11,
  129935. 0,
  129936. 12,
  129937. };
  129938. static long _vq_lengthlist__16u2_p7_0[] = {
  129939. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  129940. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  129941. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  129942. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  129943. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  129944. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  129945. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  129946. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  129947. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  129948. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  129949. 12,13,13,13,14,14,14,15,14,
  129950. };
  129951. static float _vq_quantthresh__16u2_p7_0[] = {
  129952. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  129953. 27.5, 38.5, 49.5, 60.5,
  129954. };
  129955. static long _vq_quantmap__16u2_p7_0[] = {
  129956. 11, 9, 7, 5, 3, 1, 0, 2,
  129957. 4, 6, 8, 10, 12,
  129958. };
  129959. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  129960. _vq_quantthresh__16u2_p7_0,
  129961. _vq_quantmap__16u2_p7_0,
  129962. 13,
  129963. 13
  129964. };
  129965. static static_codebook _16u2_p7_0 = {
  129966. 2, 169,
  129967. _vq_lengthlist__16u2_p7_0,
  129968. 1, -523206656, 1618345984, 4, 0,
  129969. _vq_quantlist__16u2_p7_0,
  129970. NULL,
  129971. &_vq_auxt__16u2_p7_0,
  129972. NULL,
  129973. 0
  129974. };
  129975. static long _vq_quantlist__16u2_p7_1[] = {
  129976. 5,
  129977. 4,
  129978. 6,
  129979. 3,
  129980. 7,
  129981. 2,
  129982. 8,
  129983. 1,
  129984. 9,
  129985. 0,
  129986. 10,
  129987. };
  129988. static long _vq_lengthlist__16u2_p7_1[] = {
  129989. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  129990. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  129991. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  129992. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  129993. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  129994. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  129995. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  129996. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129997. };
  129998. static float _vq_quantthresh__16u2_p7_1[] = {
  129999. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130000. 3.5, 4.5,
  130001. };
  130002. static long _vq_quantmap__16u2_p7_1[] = {
  130003. 9, 7, 5, 3, 1, 0, 2, 4,
  130004. 6, 8, 10,
  130005. };
  130006. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  130007. _vq_quantthresh__16u2_p7_1,
  130008. _vq_quantmap__16u2_p7_1,
  130009. 11,
  130010. 11
  130011. };
  130012. static static_codebook _16u2_p7_1 = {
  130013. 2, 121,
  130014. _vq_lengthlist__16u2_p7_1,
  130015. 1, -531365888, 1611661312, 4, 0,
  130016. _vq_quantlist__16u2_p7_1,
  130017. NULL,
  130018. &_vq_auxt__16u2_p7_1,
  130019. NULL,
  130020. 0
  130021. };
  130022. static long _vq_quantlist__16u2_p8_0[] = {
  130023. 7,
  130024. 6,
  130025. 8,
  130026. 5,
  130027. 9,
  130028. 4,
  130029. 10,
  130030. 3,
  130031. 11,
  130032. 2,
  130033. 12,
  130034. 1,
  130035. 13,
  130036. 0,
  130037. 14,
  130038. };
  130039. static long _vq_lengthlist__16u2_p8_0[] = {
  130040. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130041. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130042. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130043. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130044. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130045. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130046. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130047. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130048. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130049. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130050. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130051. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130052. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130053. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130054. 14,
  130055. };
  130056. static float _vq_quantthresh__16u2_p8_0[] = {
  130057. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130058. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130059. };
  130060. static long _vq_quantmap__16u2_p8_0[] = {
  130061. 13, 11, 9, 7, 5, 3, 1, 0,
  130062. 2, 4, 6, 8, 10, 12, 14,
  130063. };
  130064. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130065. _vq_quantthresh__16u2_p8_0,
  130066. _vq_quantmap__16u2_p8_0,
  130067. 15,
  130068. 15
  130069. };
  130070. static static_codebook _16u2_p8_0 = {
  130071. 2, 225,
  130072. _vq_lengthlist__16u2_p8_0,
  130073. 1, -520986624, 1620377600, 4, 0,
  130074. _vq_quantlist__16u2_p8_0,
  130075. NULL,
  130076. &_vq_auxt__16u2_p8_0,
  130077. NULL,
  130078. 0
  130079. };
  130080. static long _vq_quantlist__16u2_p8_1[] = {
  130081. 10,
  130082. 9,
  130083. 11,
  130084. 8,
  130085. 12,
  130086. 7,
  130087. 13,
  130088. 6,
  130089. 14,
  130090. 5,
  130091. 15,
  130092. 4,
  130093. 16,
  130094. 3,
  130095. 17,
  130096. 2,
  130097. 18,
  130098. 1,
  130099. 19,
  130100. 0,
  130101. 20,
  130102. };
  130103. static long _vq_lengthlist__16u2_p8_1[] = {
  130104. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130105. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130106. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130107. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130108. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130109. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130110. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130111. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130112. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130113. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130114. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130115. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130116. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130117. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130118. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130119. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130120. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130121. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130122. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130123. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130124. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130125. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130126. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130127. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130128. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130129. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130130. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130131. 11,11,10,11,11,11,10,11,11,
  130132. };
  130133. static float _vq_quantthresh__16u2_p8_1[] = {
  130134. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130135. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130136. 6.5, 7.5, 8.5, 9.5,
  130137. };
  130138. static long _vq_quantmap__16u2_p8_1[] = {
  130139. 19, 17, 15, 13, 11, 9, 7, 5,
  130140. 3, 1, 0, 2, 4, 6, 8, 10,
  130141. 12, 14, 16, 18, 20,
  130142. };
  130143. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130144. _vq_quantthresh__16u2_p8_1,
  130145. _vq_quantmap__16u2_p8_1,
  130146. 21,
  130147. 21
  130148. };
  130149. static static_codebook _16u2_p8_1 = {
  130150. 2, 441,
  130151. _vq_lengthlist__16u2_p8_1,
  130152. 1, -529268736, 1611661312, 5, 0,
  130153. _vq_quantlist__16u2_p8_1,
  130154. NULL,
  130155. &_vq_auxt__16u2_p8_1,
  130156. NULL,
  130157. 0
  130158. };
  130159. static long _vq_quantlist__16u2_p9_0[] = {
  130160. 5586,
  130161. 4655,
  130162. 6517,
  130163. 3724,
  130164. 7448,
  130165. 2793,
  130166. 8379,
  130167. 1862,
  130168. 9310,
  130169. 931,
  130170. 10241,
  130171. 0,
  130172. 11172,
  130173. 5521,
  130174. 5651,
  130175. };
  130176. static long _vq_lengthlist__16u2_p9_0[] = {
  130177. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130178. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130179. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130180. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130181. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130182. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130183. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130184. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130185. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130186. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130187. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130188. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130189. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130190. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130191. 5,
  130192. };
  130193. static float _vq_quantthresh__16u2_p9_0[] = {
  130194. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130195. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130196. };
  130197. static long _vq_quantmap__16u2_p9_0[] = {
  130198. 11, 9, 7, 5, 3, 1, 13, 0,
  130199. 14, 2, 4, 6, 8, 10, 12,
  130200. };
  130201. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130202. _vq_quantthresh__16u2_p9_0,
  130203. _vq_quantmap__16u2_p9_0,
  130204. 15,
  130205. 15
  130206. };
  130207. static static_codebook _16u2_p9_0 = {
  130208. 2, 225,
  130209. _vq_lengthlist__16u2_p9_0,
  130210. 1, -510275072, 1611661312, 14, 0,
  130211. _vq_quantlist__16u2_p9_0,
  130212. NULL,
  130213. &_vq_auxt__16u2_p9_0,
  130214. NULL,
  130215. 0
  130216. };
  130217. static long _vq_quantlist__16u2_p9_1[] = {
  130218. 392,
  130219. 343,
  130220. 441,
  130221. 294,
  130222. 490,
  130223. 245,
  130224. 539,
  130225. 196,
  130226. 588,
  130227. 147,
  130228. 637,
  130229. 98,
  130230. 686,
  130231. 49,
  130232. 735,
  130233. 0,
  130234. 784,
  130235. 388,
  130236. 396,
  130237. };
  130238. static long _vq_lengthlist__16u2_p9_1[] = {
  130239. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130240. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130241. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130242. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130243. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130244. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130245. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130246. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130247. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130248. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130249. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130250. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130251. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130252. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130253. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130254. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130255. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130256. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130257. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130258. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130259. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130260. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130261. 11,11,11,11,11,11,11, 5, 4,
  130262. };
  130263. static float _vq_quantthresh__16u2_p9_1[] = {
  130264. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130265. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130266. 318.5, 367.5,
  130267. };
  130268. static long _vq_quantmap__16u2_p9_1[] = {
  130269. 15, 13, 11, 9, 7, 5, 3, 1,
  130270. 17, 0, 18, 2, 4, 6, 8, 10,
  130271. 12, 14, 16,
  130272. };
  130273. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130274. _vq_quantthresh__16u2_p9_1,
  130275. _vq_quantmap__16u2_p9_1,
  130276. 19,
  130277. 19
  130278. };
  130279. static static_codebook _16u2_p9_1 = {
  130280. 2, 361,
  130281. _vq_lengthlist__16u2_p9_1,
  130282. 1, -518488064, 1611661312, 10, 0,
  130283. _vq_quantlist__16u2_p9_1,
  130284. NULL,
  130285. &_vq_auxt__16u2_p9_1,
  130286. NULL,
  130287. 0
  130288. };
  130289. static long _vq_quantlist__16u2_p9_2[] = {
  130290. 24,
  130291. 23,
  130292. 25,
  130293. 22,
  130294. 26,
  130295. 21,
  130296. 27,
  130297. 20,
  130298. 28,
  130299. 19,
  130300. 29,
  130301. 18,
  130302. 30,
  130303. 17,
  130304. 31,
  130305. 16,
  130306. 32,
  130307. 15,
  130308. 33,
  130309. 14,
  130310. 34,
  130311. 13,
  130312. 35,
  130313. 12,
  130314. 36,
  130315. 11,
  130316. 37,
  130317. 10,
  130318. 38,
  130319. 9,
  130320. 39,
  130321. 8,
  130322. 40,
  130323. 7,
  130324. 41,
  130325. 6,
  130326. 42,
  130327. 5,
  130328. 43,
  130329. 4,
  130330. 44,
  130331. 3,
  130332. 45,
  130333. 2,
  130334. 46,
  130335. 1,
  130336. 47,
  130337. 0,
  130338. 48,
  130339. };
  130340. static long _vq_lengthlist__16u2_p9_2[] = {
  130341. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130342. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130343. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130344. 11,
  130345. };
  130346. static float _vq_quantthresh__16u2_p9_2[] = {
  130347. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130348. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130349. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130350. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130351. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130352. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130353. };
  130354. static long _vq_quantmap__16u2_p9_2[] = {
  130355. 47, 45, 43, 41, 39, 37, 35, 33,
  130356. 31, 29, 27, 25, 23, 21, 19, 17,
  130357. 15, 13, 11, 9, 7, 5, 3, 1,
  130358. 0, 2, 4, 6, 8, 10, 12, 14,
  130359. 16, 18, 20, 22, 24, 26, 28, 30,
  130360. 32, 34, 36, 38, 40, 42, 44, 46,
  130361. 48,
  130362. };
  130363. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130364. _vq_quantthresh__16u2_p9_2,
  130365. _vq_quantmap__16u2_p9_2,
  130366. 49,
  130367. 49
  130368. };
  130369. static static_codebook _16u2_p9_2 = {
  130370. 1, 49,
  130371. _vq_lengthlist__16u2_p9_2,
  130372. 1, -526909440, 1611661312, 6, 0,
  130373. _vq_quantlist__16u2_p9_2,
  130374. NULL,
  130375. &_vq_auxt__16u2_p9_2,
  130376. NULL,
  130377. 0
  130378. };
  130379. static long _vq_quantlist__8u0__p1_0[] = {
  130380. 1,
  130381. 0,
  130382. 2,
  130383. };
  130384. static long _vq_lengthlist__8u0__p1_0[] = {
  130385. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130386. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130387. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130388. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130389. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130390. 11,
  130391. };
  130392. static float _vq_quantthresh__8u0__p1_0[] = {
  130393. -0.5, 0.5,
  130394. };
  130395. static long _vq_quantmap__8u0__p1_0[] = {
  130396. 1, 0, 2,
  130397. };
  130398. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130399. _vq_quantthresh__8u0__p1_0,
  130400. _vq_quantmap__8u0__p1_0,
  130401. 3,
  130402. 3
  130403. };
  130404. static static_codebook _8u0__p1_0 = {
  130405. 4, 81,
  130406. _vq_lengthlist__8u0__p1_0,
  130407. 1, -535822336, 1611661312, 2, 0,
  130408. _vq_quantlist__8u0__p1_0,
  130409. NULL,
  130410. &_vq_auxt__8u0__p1_0,
  130411. NULL,
  130412. 0
  130413. };
  130414. static long _vq_quantlist__8u0__p2_0[] = {
  130415. 1,
  130416. 0,
  130417. 2,
  130418. };
  130419. static long _vq_lengthlist__8u0__p2_0[] = {
  130420. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130421. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130422. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130423. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130424. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130425. 8,
  130426. };
  130427. static float _vq_quantthresh__8u0__p2_0[] = {
  130428. -0.5, 0.5,
  130429. };
  130430. static long _vq_quantmap__8u0__p2_0[] = {
  130431. 1, 0, 2,
  130432. };
  130433. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130434. _vq_quantthresh__8u0__p2_0,
  130435. _vq_quantmap__8u0__p2_0,
  130436. 3,
  130437. 3
  130438. };
  130439. static static_codebook _8u0__p2_0 = {
  130440. 4, 81,
  130441. _vq_lengthlist__8u0__p2_0,
  130442. 1, -535822336, 1611661312, 2, 0,
  130443. _vq_quantlist__8u0__p2_0,
  130444. NULL,
  130445. &_vq_auxt__8u0__p2_0,
  130446. NULL,
  130447. 0
  130448. };
  130449. static long _vq_quantlist__8u0__p3_0[] = {
  130450. 2,
  130451. 1,
  130452. 3,
  130453. 0,
  130454. 4,
  130455. };
  130456. static long _vq_lengthlist__8u0__p3_0[] = {
  130457. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130458. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130459. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130460. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130461. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130462. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130463. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130464. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130465. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130466. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130467. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130468. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130469. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130470. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130471. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130472. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130473. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130474. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130475. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130476. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130477. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130478. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130479. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130480. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130481. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130482. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130483. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130484. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130485. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130486. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130487. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130488. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130489. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130490. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130491. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130492. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130493. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130494. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130495. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130496. 16,
  130497. };
  130498. static float _vq_quantthresh__8u0__p3_0[] = {
  130499. -1.5, -0.5, 0.5, 1.5,
  130500. };
  130501. static long _vq_quantmap__8u0__p3_0[] = {
  130502. 3, 1, 0, 2, 4,
  130503. };
  130504. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130505. _vq_quantthresh__8u0__p3_0,
  130506. _vq_quantmap__8u0__p3_0,
  130507. 5,
  130508. 5
  130509. };
  130510. static static_codebook _8u0__p3_0 = {
  130511. 4, 625,
  130512. _vq_lengthlist__8u0__p3_0,
  130513. 1, -533725184, 1611661312, 3, 0,
  130514. _vq_quantlist__8u0__p3_0,
  130515. NULL,
  130516. &_vq_auxt__8u0__p3_0,
  130517. NULL,
  130518. 0
  130519. };
  130520. static long _vq_quantlist__8u0__p4_0[] = {
  130521. 2,
  130522. 1,
  130523. 3,
  130524. 0,
  130525. 4,
  130526. };
  130527. static long _vq_lengthlist__8u0__p4_0[] = {
  130528. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130529. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130530. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130531. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130532. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130533. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130534. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  130535. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  130536. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  130537. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  130538. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  130539. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  130540. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  130541. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  130542. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  130543. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  130544. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  130545. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  130546. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  130547. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  130548. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  130549. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  130550. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  130551. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  130552. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  130553. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  130554. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  130555. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  130556. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  130557. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  130558. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  130559. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  130560. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  130561. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  130562. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  130563. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  130564. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  130565. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  130566. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  130567. 12,
  130568. };
  130569. static float _vq_quantthresh__8u0__p4_0[] = {
  130570. -1.5, -0.5, 0.5, 1.5,
  130571. };
  130572. static long _vq_quantmap__8u0__p4_0[] = {
  130573. 3, 1, 0, 2, 4,
  130574. };
  130575. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  130576. _vq_quantthresh__8u0__p4_0,
  130577. _vq_quantmap__8u0__p4_0,
  130578. 5,
  130579. 5
  130580. };
  130581. static static_codebook _8u0__p4_0 = {
  130582. 4, 625,
  130583. _vq_lengthlist__8u0__p4_0,
  130584. 1, -533725184, 1611661312, 3, 0,
  130585. _vq_quantlist__8u0__p4_0,
  130586. NULL,
  130587. &_vq_auxt__8u0__p4_0,
  130588. NULL,
  130589. 0
  130590. };
  130591. static long _vq_quantlist__8u0__p5_0[] = {
  130592. 4,
  130593. 3,
  130594. 5,
  130595. 2,
  130596. 6,
  130597. 1,
  130598. 7,
  130599. 0,
  130600. 8,
  130601. };
  130602. static long _vq_lengthlist__8u0__p5_0[] = {
  130603. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  130604. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  130605. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  130606. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  130607. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  130608. 12,
  130609. };
  130610. static float _vq_quantthresh__8u0__p5_0[] = {
  130611. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130612. };
  130613. static long _vq_quantmap__8u0__p5_0[] = {
  130614. 7, 5, 3, 1, 0, 2, 4, 6,
  130615. 8,
  130616. };
  130617. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  130618. _vq_quantthresh__8u0__p5_0,
  130619. _vq_quantmap__8u0__p5_0,
  130620. 9,
  130621. 9
  130622. };
  130623. static static_codebook _8u0__p5_0 = {
  130624. 2, 81,
  130625. _vq_lengthlist__8u0__p5_0,
  130626. 1, -531628032, 1611661312, 4, 0,
  130627. _vq_quantlist__8u0__p5_0,
  130628. NULL,
  130629. &_vq_auxt__8u0__p5_0,
  130630. NULL,
  130631. 0
  130632. };
  130633. static long _vq_quantlist__8u0__p6_0[] = {
  130634. 6,
  130635. 5,
  130636. 7,
  130637. 4,
  130638. 8,
  130639. 3,
  130640. 9,
  130641. 2,
  130642. 10,
  130643. 1,
  130644. 11,
  130645. 0,
  130646. 12,
  130647. };
  130648. static long _vq_lengthlist__8u0__p6_0[] = {
  130649. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  130650. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  130651. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  130652. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  130653. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  130654. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  130655. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  130656. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  130657. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  130658. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  130659. 16, 0,15, 0,17, 0, 0, 0, 0,
  130660. };
  130661. static float _vq_quantthresh__8u0__p6_0[] = {
  130662. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130663. 12.5, 17.5, 22.5, 27.5,
  130664. };
  130665. static long _vq_quantmap__8u0__p6_0[] = {
  130666. 11, 9, 7, 5, 3, 1, 0, 2,
  130667. 4, 6, 8, 10, 12,
  130668. };
  130669. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  130670. _vq_quantthresh__8u0__p6_0,
  130671. _vq_quantmap__8u0__p6_0,
  130672. 13,
  130673. 13
  130674. };
  130675. static static_codebook _8u0__p6_0 = {
  130676. 2, 169,
  130677. _vq_lengthlist__8u0__p6_0,
  130678. 1, -526516224, 1616117760, 4, 0,
  130679. _vq_quantlist__8u0__p6_0,
  130680. NULL,
  130681. &_vq_auxt__8u0__p6_0,
  130682. NULL,
  130683. 0
  130684. };
  130685. static long _vq_quantlist__8u0__p6_1[] = {
  130686. 2,
  130687. 1,
  130688. 3,
  130689. 0,
  130690. 4,
  130691. };
  130692. static long _vq_lengthlist__8u0__p6_1[] = {
  130693. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  130694. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  130695. };
  130696. static float _vq_quantthresh__8u0__p6_1[] = {
  130697. -1.5, -0.5, 0.5, 1.5,
  130698. };
  130699. static long _vq_quantmap__8u0__p6_1[] = {
  130700. 3, 1, 0, 2, 4,
  130701. };
  130702. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  130703. _vq_quantthresh__8u0__p6_1,
  130704. _vq_quantmap__8u0__p6_1,
  130705. 5,
  130706. 5
  130707. };
  130708. static static_codebook _8u0__p6_1 = {
  130709. 2, 25,
  130710. _vq_lengthlist__8u0__p6_1,
  130711. 1, -533725184, 1611661312, 3, 0,
  130712. _vq_quantlist__8u0__p6_1,
  130713. NULL,
  130714. &_vq_auxt__8u0__p6_1,
  130715. NULL,
  130716. 0
  130717. };
  130718. static long _vq_quantlist__8u0__p7_0[] = {
  130719. 1,
  130720. 0,
  130721. 2,
  130722. };
  130723. static long _vq_lengthlist__8u0__p7_0[] = {
  130724. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130725. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130726. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130727. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130728. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130729. 7,
  130730. };
  130731. static float _vq_quantthresh__8u0__p7_0[] = {
  130732. -157.5, 157.5,
  130733. };
  130734. static long _vq_quantmap__8u0__p7_0[] = {
  130735. 1, 0, 2,
  130736. };
  130737. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  130738. _vq_quantthresh__8u0__p7_0,
  130739. _vq_quantmap__8u0__p7_0,
  130740. 3,
  130741. 3
  130742. };
  130743. static static_codebook _8u0__p7_0 = {
  130744. 4, 81,
  130745. _vq_lengthlist__8u0__p7_0,
  130746. 1, -518803456, 1628680192, 2, 0,
  130747. _vq_quantlist__8u0__p7_0,
  130748. NULL,
  130749. &_vq_auxt__8u0__p7_0,
  130750. NULL,
  130751. 0
  130752. };
  130753. static long _vq_quantlist__8u0__p7_1[] = {
  130754. 7,
  130755. 6,
  130756. 8,
  130757. 5,
  130758. 9,
  130759. 4,
  130760. 10,
  130761. 3,
  130762. 11,
  130763. 2,
  130764. 12,
  130765. 1,
  130766. 13,
  130767. 0,
  130768. 14,
  130769. };
  130770. static long _vq_lengthlist__8u0__p7_1[] = {
  130771. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  130772. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  130773. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  130774. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  130775. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  130776. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  130777. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130778. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130779. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130780. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130781. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130782. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130783. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  130784. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130785. 10,
  130786. };
  130787. static float _vq_quantthresh__8u0__p7_1[] = {
  130788. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130789. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130790. };
  130791. static long _vq_quantmap__8u0__p7_1[] = {
  130792. 13, 11, 9, 7, 5, 3, 1, 0,
  130793. 2, 4, 6, 8, 10, 12, 14,
  130794. };
  130795. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  130796. _vq_quantthresh__8u0__p7_1,
  130797. _vq_quantmap__8u0__p7_1,
  130798. 15,
  130799. 15
  130800. };
  130801. static static_codebook _8u0__p7_1 = {
  130802. 2, 225,
  130803. _vq_lengthlist__8u0__p7_1,
  130804. 1, -520986624, 1620377600, 4, 0,
  130805. _vq_quantlist__8u0__p7_1,
  130806. NULL,
  130807. &_vq_auxt__8u0__p7_1,
  130808. NULL,
  130809. 0
  130810. };
  130811. static long _vq_quantlist__8u0__p7_2[] = {
  130812. 10,
  130813. 9,
  130814. 11,
  130815. 8,
  130816. 12,
  130817. 7,
  130818. 13,
  130819. 6,
  130820. 14,
  130821. 5,
  130822. 15,
  130823. 4,
  130824. 16,
  130825. 3,
  130826. 17,
  130827. 2,
  130828. 18,
  130829. 1,
  130830. 19,
  130831. 0,
  130832. 20,
  130833. };
  130834. static long _vq_lengthlist__8u0__p7_2[] = {
  130835. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  130836. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  130837. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  130838. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  130839. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  130840. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  130841. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  130842. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  130843. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  130844. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  130845. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  130846. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  130847. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  130848. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  130849. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  130850. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  130851. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  130852. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  130853. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  130854. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  130855. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  130856. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  130857. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  130858. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  130859. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  130860. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  130861. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  130862. 11,12,11,11,11,10,10,11,11,
  130863. };
  130864. static float _vq_quantthresh__8u0__p7_2[] = {
  130865. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130866. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130867. 6.5, 7.5, 8.5, 9.5,
  130868. };
  130869. static long _vq_quantmap__8u0__p7_2[] = {
  130870. 19, 17, 15, 13, 11, 9, 7, 5,
  130871. 3, 1, 0, 2, 4, 6, 8, 10,
  130872. 12, 14, 16, 18, 20,
  130873. };
  130874. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  130875. _vq_quantthresh__8u0__p7_2,
  130876. _vq_quantmap__8u0__p7_2,
  130877. 21,
  130878. 21
  130879. };
  130880. static static_codebook _8u0__p7_2 = {
  130881. 2, 441,
  130882. _vq_lengthlist__8u0__p7_2,
  130883. 1, -529268736, 1611661312, 5, 0,
  130884. _vq_quantlist__8u0__p7_2,
  130885. NULL,
  130886. &_vq_auxt__8u0__p7_2,
  130887. NULL,
  130888. 0
  130889. };
  130890. static long _huff_lengthlist__8u0__single[] = {
  130891. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  130892. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  130893. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  130894. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  130895. };
  130896. static static_codebook _huff_book__8u0__single = {
  130897. 2, 64,
  130898. _huff_lengthlist__8u0__single,
  130899. 0, 0, 0, 0, 0,
  130900. NULL,
  130901. NULL,
  130902. NULL,
  130903. NULL,
  130904. 0
  130905. };
  130906. static long _vq_quantlist__8u1__p1_0[] = {
  130907. 1,
  130908. 0,
  130909. 2,
  130910. };
  130911. static long _vq_lengthlist__8u1__p1_0[] = {
  130912. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  130913. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  130914. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  130915. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  130916. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  130917. 10,
  130918. };
  130919. static float _vq_quantthresh__8u1__p1_0[] = {
  130920. -0.5, 0.5,
  130921. };
  130922. static long _vq_quantmap__8u1__p1_0[] = {
  130923. 1, 0, 2,
  130924. };
  130925. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  130926. _vq_quantthresh__8u1__p1_0,
  130927. _vq_quantmap__8u1__p1_0,
  130928. 3,
  130929. 3
  130930. };
  130931. static static_codebook _8u1__p1_0 = {
  130932. 4, 81,
  130933. _vq_lengthlist__8u1__p1_0,
  130934. 1, -535822336, 1611661312, 2, 0,
  130935. _vq_quantlist__8u1__p1_0,
  130936. NULL,
  130937. &_vq_auxt__8u1__p1_0,
  130938. NULL,
  130939. 0
  130940. };
  130941. static long _vq_quantlist__8u1__p2_0[] = {
  130942. 1,
  130943. 0,
  130944. 2,
  130945. };
  130946. static long _vq_lengthlist__8u1__p2_0[] = {
  130947. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  130948. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  130949. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  130950. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  130951. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  130952. 7,
  130953. };
  130954. static float _vq_quantthresh__8u1__p2_0[] = {
  130955. -0.5, 0.5,
  130956. };
  130957. static long _vq_quantmap__8u1__p2_0[] = {
  130958. 1, 0, 2,
  130959. };
  130960. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  130961. _vq_quantthresh__8u1__p2_0,
  130962. _vq_quantmap__8u1__p2_0,
  130963. 3,
  130964. 3
  130965. };
  130966. static static_codebook _8u1__p2_0 = {
  130967. 4, 81,
  130968. _vq_lengthlist__8u1__p2_0,
  130969. 1, -535822336, 1611661312, 2, 0,
  130970. _vq_quantlist__8u1__p2_0,
  130971. NULL,
  130972. &_vq_auxt__8u1__p2_0,
  130973. NULL,
  130974. 0
  130975. };
  130976. static long _vq_quantlist__8u1__p3_0[] = {
  130977. 2,
  130978. 1,
  130979. 3,
  130980. 0,
  130981. 4,
  130982. };
  130983. static long _vq_lengthlist__8u1__p3_0[] = {
  130984. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130985. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130986. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  130987. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  130988. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  130989. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  130990. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  130991. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  130992. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  130993. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  130994. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  130995. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  130996. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  130997. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  130998. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  130999. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  131000. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  131001. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  131002. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  131003. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  131004. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  131005. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  131006. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  131007. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  131008. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  131009. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  131010. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131011. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131012. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131013. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131014. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131015. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131016. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131017. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131018. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131019. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131020. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131021. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131022. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131023. 16,
  131024. };
  131025. static float _vq_quantthresh__8u1__p3_0[] = {
  131026. -1.5, -0.5, 0.5, 1.5,
  131027. };
  131028. static long _vq_quantmap__8u1__p3_0[] = {
  131029. 3, 1, 0, 2, 4,
  131030. };
  131031. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131032. _vq_quantthresh__8u1__p3_0,
  131033. _vq_quantmap__8u1__p3_0,
  131034. 5,
  131035. 5
  131036. };
  131037. static static_codebook _8u1__p3_0 = {
  131038. 4, 625,
  131039. _vq_lengthlist__8u1__p3_0,
  131040. 1, -533725184, 1611661312, 3, 0,
  131041. _vq_quantlist__8u1__p3_0,
  131042. NULL,
  131043. &_vq_auxt__8u1__p3_0,
  131044. NULL,
  131045. 0
  131046. };
  131047. static long _vq_quantlist__8u1__p4_0[] = {
  131048. 2,
  131049. 1,
  131050. 3,
  131051. 0,
  131052. 4,
  131053. };
  131054. static long _vq_lengthlist__8u1__p4_0[] = {
  131055. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131056. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131057. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131058. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131059. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131060. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131061. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131062. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131063. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131064. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131065. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131066. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131067. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131068. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131069. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131070. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131071. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131072. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131073. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131074. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131075. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131076. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131077. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131078. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131079. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131080. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131081. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131082. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131083. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131084. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131085. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131086. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131087. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131088. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131089. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131090. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131091. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131092. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131093. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131094. 10,
  131095. };
  131096. static float _vq_quantthresh__8u1__p4_0[] = {
  131097. -1.5, -0.5, 0.5, 1.5,
  131098. };
  131099. static long _vq_quantmap__8u1__p4_0[] = {
  131100. 3, 1, 0, 2, 4,
  131101. };
  131102. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131103. _vq_quantthresh__8u1__p4_0,
  131104. _vq_quantmap__8u1__p4_0,
  131105. 5,
  131106. 5
  131107. };
  131108. static static_codebook _8u1__p4_0 = {
  131109. 4, 625,
  131110. _vq_lengthlist__8u1__p4_0,
  131111. 1, -533725184, 1611661312, 3, 0,
  131112. _vq_quantlist__8u1__p4_0,
  131113. NULL,
  131114. &_vq_auxt__8u1__p4_0,
  131115. NULL,
  131116. 0
  131117. };
  131118. static long _vq_quantlist__8u1__p5_0[] = {
  131119. 4,
  131120. 3,
  131121. 5,
  131122. 2,
  131123. 6,
  131124. 1,
  131125. 7,
  131126. 0,
  131127. 8,
  131128. };
  131129. static long _vq_lengthlist__8u1__p5_0[] = {
  131130. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131131. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131132. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131133. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131134. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131135. 13,
  131136. };
  131137. static float _vq_quantthresh__8u1__p5_0[] = {
  131138. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131139. };
  131140. static long _vq_quantmap__8u1__p5_0[] = {
  131141. 7, 5, 3, 1, 0, 2, 4, 6,
  131142. 8,
  131143. };
  131144. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131145. _vq_quantthresh__8u1__p5_0,
  131146. _vq_quantmap__8u1__p5_0,
  131147. 9,
  131148. 9
  131149. };
  131150. static static_codebook _8u1__p5_0 = {
  131151. 2, 81,
  131152. _vq_lengthlist__8u1__p5_0,
  131153. 1, -531628032, 1611661312, 4, 0,
  131154. _vq_quantlist__8u1__p5_0,
  131155. NULL,
  131156. &_vq_auxt__8u1__p5_0,
  131157. NULL,
  131158. 0
  131159. };
  131160. static long _vq_quantlist__8u1__p6_0[] = {
  131161. 4,
  131162. 3,
  131163. 5,
  131164. 2,
  131165. 6,
  131166. 1,
  131167. 7,
  131168. 0,
  131169. 8,
  131170. };
  131171. static long _vq_lengthlist__8u1__p6_0[] = {
  131172. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131173. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131174. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131175. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131176. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131177. 10,
  131178. };
  131179. static float _vq_quantthresh__8u1__p6_0[] = {
  131180. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131181. };
  131182. static long _vq_quantmap__8u1__p6_0[] = {
  131183. 7, 5, 3, 1, 0, 2, 4, 6,
  131184. 8,
  131185. };
  131186. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131187. _vq_quantthresh__8u1__p6_0,
  131188. _vq_quantmap__8u1__p6_0,
  131189. 9,
  131190. 9
  131191. };
  131192. static static_codebook _8u1__p6_0 = {
  131193. 2, 81,
  131194. _vq_lengthlist__8u1__p6_0,
  131195. 1, -531628032, 1611661312, 4, 0,
  131196. _vq_quantlist__8u1__p6_0,
  131197. NULL,
  131198. &_vq_auxt__8u1__p6_0,
  131199. NULL,
  131200. 0
  131201. };
  131202. static long _vq_quantlist__8u1__p7_0[] = {
  131203. 1,
  131204. 0,
  131205. 2,
  131206. };
  131207. static long _vq_lengthlist__8u1__p7_0[] = {
  131208. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131209. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131210. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131211. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131212. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131213. 11,
  131214. };
  131215. static float _vq_quantthresh__8u1__p7_0[] = {
  131216. -5.5, 5.5,
  131217. };
  131218. static long _vq_quantmap__8u1__p7_0[] = {
  131219. 1, 0, 2,
  131220. };
  131221. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131222. _vq_quantthresh__8u1__p7_0,
  131223. _vq_quantmap__8u1__p7_0,
  131224. 3,
  131225. 3
  131226. };
  131227. static static_codebook _8u1__p7_0 = {
  131228. 4, 81,
  131229. _vq_lengthlist__8u1__p7_0,
  131230. 1, -529137664, 1618345984, 2, 0,
  131231. _vq_quantlist__8u1__p7_0,
  131232. NULL,
  131233. &_vq_auxt__8u1__p7_0,
  131234. NULL,
  131235. 0
  131236. };
  131237. static long _vq_quantlist__8u1__p7_1[] = {
  131238. 5,
  131239. 4,
  131240. 6,
  131241. 3,
  131242. 7,
  131243. 2,
  131244. 8,
  131245. 1,
  131246. 9,
  131247. 0,
  131248. 10,
  131249. };
  131250. static long _vq_lengthlist__8u1__p7_1[] = {
  131251. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131252. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131253. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131254. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131255. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131256. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131257. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131258. 9, 9, 9, 9, 9,10,10,10,10,
  131259. };
  131260. static float _vq_quantthresh__8u1__p7_1[] = {
  131261. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131262. 3.5, 4.5,
  131263. };
  131264. static long _vq_quantmap__8u1__p7_1[] = {
  131265. 9, 7, 5, 3, 1, 0, 2, 4,
  131266. 6, 8, 10,
  131267. };
  131268. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131269. _vq_quantthresh__8u1__p7_1,
  131270. _vq_quantmap__8u1__p7_1,
  131271. 11,
  131272. 11
  131273. };
  131274. static static_codebook _8u1__p7_1 = {
  131275. 2, 121,
  131276. _vq_lengthlist__8u1__p7_1,
  131277. 1, -531365888, 1611661312, 4, 0,
  131278. _vq_quantlist__8u1__p7_1,
  131279. NULL,
  131280. &_vq_auxt__8u1__p7_1,
  131281. NULL,
  131282. 0
  131283. };
  131284. static long _vq_quantlist__8u1__p8_0[] = {
  131285. 5,
  131286. 4,
  131287. 6,
  131288. 3,
  131289. 7,
  131290. 2,
  131291. 8,
  131292. 1,
  131293. 9,
  131294. 0,
  131295. 10,
  131296. };
  131297. static long _vq_lengthlist__8u1__p8_0[] = {
  131298. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131299. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131300. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131301. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131302. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131303. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131304. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131305. 12,13,13,14,14,15,15,15,15,
  131306. };
  131307. static float _vq_quantthresh__8u1__p8_0[] = {
  131308. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131309. 38.5, 49.5,
  131310. };
  131311. static long _vq_quantmap__8u1__p8_0[] = {
  131312. 9, 7, 5, 3, 1, 0, 2, 4,
  131313. 6, 8, 10,
  131314. };
  131315. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131316. _vq_quantthresh__8u1__p8_0,
  131317. _vq_quantmap__8u1__p8_0,
  131318. 11,
  131319. 11
  131320. };
  131321. static static_codebook _8u1__p8_0 = {
  131322. 2, 121,
  131323. _vq_lengthlist__8u1__p8_0,
  131324. 1, -524582912, 1618345984, 4, 0,
  131325. _vq_quantlist__8u1__p8_0,
  131326. NULL,
  131327. &_vq_auxt__8u1__p8_0,
  131328. NULL,
  131329. 0
  131330. };
  131331. static long _vq_quantlist__8u1__p8_1[] = {
  131332. 5,
  131333. 4,
  131334. 6,
  131335. 3,
  131336. 7,
  131337. 2,
  131338. 8,
  131339. 1,
  131340. 9,
  131341. 0,
  131342. 10,
  131343. };
  131344. static long _vq_lengthlist__8u1__p8_1[] = {
  131345. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131346. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131347. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131348. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131349. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131350. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131351. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131352. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131353. };
  131354. static float _vq_quantthresh__8u1__p8_1[] = {
  131355. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131356. 3.5, 4.5,
  131357. };
  131358. static long _vq_quantmap__8u1__p8_1[] = {
  131359. 9, 7, 5, 3, 1, 0, 2, 4,
  131360. 6, 8, 10,
  131361. };
  131362. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131363. _vq_quantthresh__8u1__p8_1,
  131364. _vq_quantmap__8u1__p8_1,
  131365. 11,
  131366. 11
  131367. };
  131368. static static_codebook _8u1__p8_1 = {
  131369. 2, 121,
  131370. _vq_lengthlist__8u1__p8_1,
  131371. 1, -531365888, 1611661312, 4, 0,
  131372. _vq_quantlist__8u1__p8_1,
  131373. NULL,
  131374. &_vq_auxt__8u1__p8_1,
  131375. NULL,
  131376. 0
  131377. };
  131378. static long _vq_quantlist__8u1__p9_0[] = {
  131379. 7,
  131380. 6,
  131381. 8,
  131382. 5,
  131383. 9,
  131384. 4,
  131385. 10,
  131386. 3,
  131387. 11,
  131388. 2,
  131389. 12,
  131390. 1,
  131391. 13,
  131392. 0,
  131393. 14,
  131394. };
  131395. static long _vq_lengthlist__8u1__p9_0[] = {
  131396. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131397. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131398. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131399. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131400. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131401. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131402. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131403. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131404. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131405. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131406. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131407. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131408. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131409. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131410. 10,
  131411. };
  131412. static float _vq_quantthresh__8u1__p9_0[] = {
  131413. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131414. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131415. };
  131416. static long _vq_quantmap__8u1__p9_0[] = {
  131417. 13, 11, 9, 7, 5, 3, 1, 0,
  131418. 2, 4, 6, 8, 10, 12, 14,
  131419. };
  131420. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131421. _vq_quantthresh__8u1__p9_0,
  131422. _vq_quantmap__8u1__p9_0,
  131423. 15,
  131424. 15
  131425. };
  131426. static static_codebook _8u1__p9_0 = {
  131427. 2, 225,
  131428. _vq_lengthlist__8u1__p9_0,
  131429. 1, -514071552, 1627381760, 4, 0,
  131430. _vq_quantlist__8u1__p9_0,
  131431. NULL,
  131432. &_vq_auxt__8u1__p9_0,
  131433. NULL,
  131434. 0
  131435. };
  131436. static long _vq_quantlist__8u1__p9_1[] = {
  131437. 7,
  131438. 6,
  131439. 8,
  131440. 5,
  131441. 9,
  131442. 4,
  131443. 10,
  131444. 3,
  131445. 11,
  131446. 2,
  131447. 12,
  131448. 1,
  131449. 13,
  131450. 0,
  131451. 14,
  131452. };
  131453. static long _vq_lengthlist__8u1__p9_1[] = {
  131454. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131455. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131456. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131457. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131458. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131459. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131460. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131461. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131462. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131463. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131464. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131465. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131466. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131467. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131468. 13,
  131469. };
  131470. static float _vq_quantthresh__8u1__p9_1[] = {
  131471. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131472. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131473. };
  131474. static long _vq_quantmap__8u1__p9_1[] = {
  131475. 13, 11, 9, 7, 5, 3, 1, 0,
  131476. 2, 4, 6, 8, 10, 12, 14,
  131477. };
  131478. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131479. _vq_quantthresh__8u1__p9_1,
  131480. _vq_quantmap__8u1__p9_1,
  131481. 15,
  131482. 15
  131483. };
  131484. static static_codebook _8u1__p9_1 = {
  131485. 2, 225,
  131486. _vq_lengthlist__8u1__p9_1,
  131487. 1, -522338304, 1620115456, 4, 0,
  131488. _vq_quantlist__8u1__p9_1,
  131489. NULL,
  131490. &_vq_auxt__8u1__p9_1,
  131491. NULL,
  131492. 0
  131493. };
  131494. static long _vq_quantlist__8u1__p9_2[] = {
  131495. 8,
  131496. 7,
  131497. 9,
  131498. 6,
  131499. 10,
  131500. 5,
  131501. 11,
  131502. 4,
  131503. 12,
  131504. 3,
  131505. 13,
  131506. 2,
  131507. 14,
  131508. 1,
  131509. 15,
  131510. 0,
  131511. 16,
  131512. };
  131513. static long _vq_lengthlist__8u1__p9_2[] = {
  131514. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131515. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131516. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131517. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131518. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131519. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131520. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131521. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131522. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131523. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131524. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131525. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131526. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131527. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131528. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131529. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131530. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131531. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131532. 10,
  131533. };
  131534. static float _vq_quantthresh__8u1__p9_2[] = {
  131535. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131536. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131537. };
  131538. static long _vq_quantmap__8u1__p9_2[] = {
  131539. 15, 13, 11, 9, 7, 5, 3, 1,
  131540. 0, 2, 4, 6, 8, 10, 12, 14,
  131541. 16,
  131542. };
  131543. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  131544. _vq_quantthresh__8u1__p9_2,
  131545. _vq_quantmap__8u1__p9_2,
  131546. 17,
  131547. 17
  131548. };
  131549. static static_codebook _8u1__p9_2 = {
  131550. 2, 289,
  131551. _vq_lengthlist__8u1__p9_2,
  131552. 1, -529530880, 1611661312, 5, 0,
  131553. _vq_quantlist__8u1__p9_2,
  131554. NULL,
  131555. &_vq_auxt__8u1__p9_2,
  131556. NULL,
  131557. 0
  131558. };
  131559. static long _huff_lengthlist__8u1__single[] = {
  131560. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  131561. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  131562. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  131563. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  131564. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  131565. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  131566. 13, 8, 8,15,
  131567. };
  131568. static static_codebook _huff_book__8u1__single = {
  131569. 2, 100,
  131570. _huff_lengthlist__8u1__single,
  131571. 0, 0, 0, 0, 0,
  131572. NULL,
  131573. NULL,
  131574. NULL,
  131575. NULL,
  131576. 0
  131577. };
  131578. static long _huff_lengthlist__44u0__long[] = {
  131579. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131580. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131581. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131582. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131583. };
  131584. static static_codebook _huff_book__44u0__long = {
  131585. 2, 64,
  131586. _huff_lengthlist__44u0__long,
  131587. 0, 0, 0, 0, 0,
  131588. NULL,
  131589. NULL,
  131590. NULL,
  131591. NULL,
  131592. 0
  131593. };
  131594. static long _vq_quantlist__44u0__p1_0[] = {
  131595. 1,
  131596. 0,
  131597. 2,
  131598. };
  131599. static long _vq_lengthlist__44u0__p1_0[] = {
  131600. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  131601. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  131602. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  131603. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  131604. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  131605. 13,
  131606. };
  131607. static float _vq_quantthresh__44u0__p1_0[] = {
  131608. -0.5, 0.5,
  131609. };
  131610. static long _vq_quantmap__44u0__p1_0[] = {
  131611. 1, 0, 2,
  131612. };
  131613. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  131614. _vq_quantthresh__44u0__p1_0,
  131615. _vq_quantmap__44u0__p1_0,
  131616. 3,
  131617. 3
  131618. };
  131619. static static_codebook _44u0__p1_0 = {
  131620. 4, 81,
  131621. _vq_lengthlist__44u0__p1_0,
  131622. 1, -535822336, 1611661312, 2, 0,
  131623. _vq_quantlist__44u0__p1_0,
  131624. NULL,
  131625. &_vq_auxt__44u0__p1_0,
  131626. NULL,
  131627. 0
  131628. };
  131629. static long _vq_quantlist__44u0__p2_0[] = {
  131630. 1,
  131631. 0,
  131632. 2,
  131633. };
  131634. static long _vq_lengthlist__44u0__p2_0[] = {
  131635. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  131636. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  131637. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  131638. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  131639. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  131640. 9,
  131641. };
  131642. static float _vq_quantthresh__44u0__p2_0[] = {
  131643. -0.5, 0.5,
  131644. };
  131645. static long _vq_quantmap__44u0__p2_0[] = {
  131646. 1, 0, 2,
  131647. };
  131648. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  131649. _vq_quantthresh__44u0__p2_0,
  131650. _vq_quantmap__44u0__p2_0,
  131651. 3,
  131652. 3
  131653. };
  131654. static static_codebook _44u0__p2_0 = {
  131655. 4, 81,
  131656. _vq_lengthlist__44u0__p2_0,
  131657. 1, -535822336, 1611661312, 2, 0,
  131658. _vq_quantlist__44u0__p2_0,
  131659. NULL,
  131660. &_vq_auxt__44u0__p2_0,
  131661. NULL,
  131662. 0
  131663. };
  131664. static long _vq_quantlist__44u0__p3_0[] = {
  131665. 2,
  131666. 1,
  131667. 3,
  131668. 0,
  131669. 4,
  131670. };
  131671. static long _vq_lengthlist__44u0__p3_0[] = {
  131672. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  131673. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  131674. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  131675. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  131676. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  131677. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  131678. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  131679. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  131680. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  131681. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  131682. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  131683. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  131684. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  131685. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  131686. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  131687. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  131688. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  131689. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  131690. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  131691. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  131692. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  131693. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  131694. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  131695. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  131696. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  131697. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  131698. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  131699. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  131700. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  131701. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  131702. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  131703. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  131704. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  131705. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  131706. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  131707. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  131708. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  131709. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  131710. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  131711. 19,
  131712. };
  131713. static float _vq_quantthresh__44u0__p3_0[] = {
  131714. -1.5, -0.5, 0.5, 1.5,
  131715. };
  131716. static long _vq_quantmap__44u0__p3_0[] = {
  131717. 3, 1, 0, 2, 4,
  131718. };
  131719. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  131720. _vq_quantthresh__44u0__p3_0,
  131721. _vq_quantmap__44u0__p3_0,
  131722. 5,
  131723. 5
  131724. };
  131725. static static_codebook _44u0__p3_0 = {
  131726. 4, 625,
  131727. _vq_lengthlist__44u0__p3_0,
  131728. 1, -533725184, 1611661312, 3, 0,
  131729. _vq_quantlist__44u0__p3_0,
  131730. NULL,
  131731. &_vq_auxt__44u0__p3_0,
  131732. NULL,
  131733. 0
  131734. };
  131735. static long _vq_quantlist__44u0__p4_0[] = {
  131736. 2,
  131737. 1,
  131738. 3,
  131739. 0,
  131740. 4,
  131741. };
  131742. static long _vq_lengthlist__44u0__p4_0[] = {
  131743. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  131744. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  131745. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  131746. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  131747. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  131748. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  131749. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  131750. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  131751. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  131752. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  131753. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  131754. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  131755. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  131756. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  131757. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  131758. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  131759. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  131760. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  131761. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  131762. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  131763. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  131764. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  131765. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  131766. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  131767. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  131768. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  131769. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  131770. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  131771. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  131772. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  131773. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  131774. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  131775. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  131776. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  131777. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  131778. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  131779. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  131780. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  131781. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  131782. 12,
  131783. };
  131784. static float _vq_quantthresh__44u0__p4_0[] = {
  131785. -1.5, -0.5, 0.5, 1.5,
  131786. };
  131787. static long _vq_quantmap__44u0__p4_0[] = {
  131788. 3, 1, 0, 2, 4,
  131789. };
  131790. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  131791. _vq_quantthresh__44u0__p4_0,
  131792. _vq_quantmap__44u0__p4_0,
  131793. 5,
  131794. 5
  131795. };
  131796. static static_codebook _44u0__p4_0 = {
  131797. 4, 625,
  131798. _vq_lengthlist__44u0__p4_0,
  131799. 1, -533725184, 1611661312, 3, 0,
  131800. _vq_quantlist__44u0__p4_0,
  131801. NULL,
  131802. &_vq_auxt__44u0__p4_0,
  131803. NULL,
  131804. 0
  131805. };
  131806. static long _vq_quantlist__44u0__p5_0[] = {
  131807. 4,
  131808. 3,
  131809. 5,
  131810. 2,
  131811. 6,
  131812. 1,
  131813. 7,
  131814. 0,
  131815. 8,
  131816. };
  131817. static long _vq_lengthlist__44u0__p5_0[] = {
  131818. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  131819. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  131820. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  131821. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131822. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  131823. 12,
  131824. };
  131825. static float _vq_quantthresh__44u0__p5_0[] = {
  131826. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131827. };
  131828. static long _vq_quantmap__44u0__p5_0[] = {
  131829. 7, 5, 3, 1, 0, 2, 4, 6,
  131830. 8,
  131831. };
  131832. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  131833. _vq_quantthresh__44u0__p5_0,
  131834. _vq_quantmap__44u0__p5_0,
  131835. 9,
  131836. 9
  131837. };
  131838. static static_codebook _44u0__p5_0 = {
  131839. 2, 81,
  131840. _vq_lengthlist__44u0__p5_0,
  131841. 1, -531628032, 1611661312, 4, 0,
  131842. _vq_quantlist__44u0__p5_0,
  131843. NULL,
  131844. &_vq_auxt__44u0__p5_0,
  131845. NULL,
  131846. 0
  131847. };
  131848. static long _vq_quantlist__44u0__p6_0[] = {
  131849. 6,
  131850. 5,
  131851. 7,
  131852. 4,
  131853. 8,
  131854. 3,
  131855. 9,
  131856. 2,
  131857. 10,
  131858. 1,
  131859. 11,
  131860. 0,
  131861. 12,
  131862. };
  131863. static long _vq_lengthlist__44u0__p6_0[] = {
  131864. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  131865. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  131866. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  131867. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  131868. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  131869. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  131870. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  131871. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  131872. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  131873. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  131874. 15,17,16,17,18,17,17,18, 0,
  131875. };
  131876. static float _vq_quantthresh__44u0__p6_0[] = {
  131877. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131878. 12.5, 17.5, 22.5, 27.5,
  131879. };
  131880. static long _vq_quantmap__44u0__p6_0[] = {
  131881. 11, 9, 7, 5, 3, 1, 0, 2,
  131882. 4, 6, 8, 10, 12,
  131883. };
  131884. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  131885. _vq_quantthresh__44u0__p6_0,
  131886. _vq_quantmap__44u0__p6_0,
  131887. 13,
  131888. 13
  131889. };
  131890. static static_codebook _44u0__p6_0 = {
  131891. 2, 169,
  131892. _vq_lengthlist__44u0__p6_0,
  131893. 1, -526516224, 1616117760, 4, 0,
  131894. _vq_quantlist__44u0__p6_0,
  131895. NULL,
  131896. &_vq_auxt__44u0__p6_0,
  131897. NULL,
  131898. 0
  131899. };
  131900. static long _vq_quantlist__44u0__p6_1[] = {
  131901. 2,
  131902. 1,
  131903. 3,
  131904. 0,
  131905. 4,
  131906. };
  131907. static long _vq_lengthlist__44u0__p6_1[] = {
  131908. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  131909. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  131910. };
  131911. static float _vq_quantthresh__44u0__p6_1[] = {
  131912. -1.5, -0.5, 0.5, 1.5,
  131913. };
  131914. static long _vq_quantmap__44u0__p6_1[] = {
  131915. 3, 1, 0, 2, 4,
  131916. };
  131917. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  131918. _vq_quantthresh__44u0__p6_1,
  131919. _vq_quantmap__44u0__p6_1,
  131920. 5,
  131921. 5
  131922. };
  131923. static static_codebook _44u0__p6_1 = {
  131924. 2, 25,
  131925. _vq_lengthlist__44u0__p6_1,
  131926. 1, -533725184, 1611661312, 3, 0,
  131927. _vq_quantlist__44u0__p6_1,
  131928. NULL,
  131929. &_vq_auxt__44u0__p6_1,
  131930. NULL,
  131931. 0
  131932. };
  131933. static long _vq_quantlist__44u0__p7_0[] = {
  131934. 2,
  131935. 1,
  131936. 3,
  131937. 0,
  131938. 4,
  131939. };
  131940. static long _vq_lengthlist__44u0__p7_0[] = {
  131941. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  131942. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131943. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131944. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131945. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131946. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131947. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131948. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  131949. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131950. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131951. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131952. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131953. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131954. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131955. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131956. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131957. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131958. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131959. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131960. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131961. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131962. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131963. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131964. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131965. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131966. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131967. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131968. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131969. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131970. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131971. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  131972. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131973. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131974. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131975. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131976. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131977. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131978. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131979. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131980. 10,
  131981. };
  131982. static float _vq_quantthresh__44u0__p7_0[] = {
  131983. -253.5, -84.5, 84.5, 253.5,
  131984. };
  131985. static long _vq_quantmap__44u0__p7_0[] = {
  131986. 3, 1, 0, 2, 4,
  131987. };
  131988. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  131989. _vq_quantthresh__44u0__p7_0,
  131990. _vq_quantmap__44u0__p7_0,
  131991. 5,
  131992. 5
  131993. };
  131994. static static_codebook _44u0__p7_0 = {
  131995. 4, 625,
  131996. _vq_lengthlist__44u0__p7_0,
  131997. 1, -518709248, 1626677248, 3, 0,
  131998. _vq_quantlist__44u0__p7_0,
  131999. NULL,
  132000. &_vq_auxt__44u0__p7_0,
  132001. NULL,
  132002. 0
  132003. };
  132004. static long _vq_quantlist__44u0__p7_1[] = {
  132005. 6,
  132006. 5,
  132007. 7,
  132008. 4,
  132009. 8,
  132010. 3,
  132011. 9,
  132012. 2,
  132013. 10,
  132014. 1,
  132015. 11,
  132016. 0,
  132017. 12,
  132018. };
  132019. static long _vq_lengthlist__44u0__p7_1[] = {
  132020. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132021. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132022. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132023. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132024. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132025. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132026. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132027. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132028. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132029. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132030. 15,15,15,15,15,15,15,15,15,
  132031. };
  132032. static float _vq_quantthresh__44u0__p7_1[] = {
  132033. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132034. 32.5, 45.5, 58.5, 71.5,
  132035. };
  132036. static long _vq_quantmap__44u0__p7_1[] = {
  132037. 11, 9, 7, 5, 3, 1, 0, 2,
  132038. 4, 6, 8, 10, 12,
  132039. };
  132040. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132041. _vq_quantthresh__44u0__p7_1,
  132042. _vq_quantmap__44u0__p7_1,
  132043. 13,
  132044. 13
  132045. };
  132046. static static_codebook _44u0__p7_1 = {
  132047. 2, 169,
  132048. _vq_lengthlist__44u0__p7_1,
  132049. 1, -523010048, 1618608128, 4, 0,
  132050. _vq_quantlist__44u0__p7_1,
  132051. NULL,
  132052. &_vq_auxt__44u0__p7_1,
  132053. NULL,
  132054. 0
  132055. };
  132056. static long _vq_quantlist__44u0__p7_2[] = {
  132057. 6,
  132058. 5,
  132059. 7,
  132060. 4,
  132061. 8,
  132062. 3,
  132063. 9,
  132064. 2,
  132065. 10,
  132066. 1,
  132067. 11,
  132068. 0,
  132069. 12,
  132070. };
  132071. static long _vq_lengthlist__44u0__p7_2[] = {
  132072. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132073. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132074. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132075. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132076. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132077. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132078. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132079. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132080. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132081. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132082. 9, 9, 9,10, 9, 9,10,10, 9,
  132083. };
  132084. static float _vq_quantthresh__44u0__p7_2[] = {
  132085. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132086. 2.5, 3.5, 4.5, 5.5,
  132087. };
  132088. static long _vq_quantmap__44u0__p7_2[] = {
  132089. 11, 9, 7, 5, 3, 1, 0, 2,
  132090. 4, 6, 8, 10, 12,
  132091. };
  132092. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132093. _vq_quantthresh__44u0__p7_2,
  132094. _vq_quantmap__44u0__p7_2,
  132095. 13,
  132096. 13
  132097. };
  132098. static static_codebook _44u0__p7_2 = {
  132099. 2, 169,
  132100. _vq_lengthlist__44u0__p7_2,
  132101. 1, -531103744, 1611661312, 4, 0,
  132102. _vq_quantlist__44u0__p7_2,
  132103. NULL,
  132104. &_vq_auxt__44u0__p7_2,
  132105. NULL,
  132106. 0
  132107. };
  132108. static long _huff_lengthlist__44u0__short[] = {
  132109. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132110. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132111. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132112. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132113. };
  132114. static static_codebook _huff_book__44u0__short = {
  132115. 2, 64,
  132116. _huff_lengthlist__44u0__short,
  132117. 0, 0, 0, 0, 0,
  132118. NULL,
  132119. NULL,
  132120. NULL,
  132121. NULL,
  132122. 0
  132123. };
  132124. static long _huff_lengthlist__44u1__long[] = {
  132125. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132126. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132127. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132128. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132129. };
  132130. static static_codebook _huff_book__44u1__long = {
  132131. 2, 64,
  132132. _huff_lengthlist__44u1__long,
  132133. 0, 0, 0, 0, 0,
  132134. NULL,
  132135. NULL,
  132136. NULL,
  132137. NULL,
  132138. 0
  132139. };
  132140. static long _vq_quantlist__44u1__p1_0[] = {
  132141. 1,
  132142. 0,
  132143. 2,
  132144. };
  132145. static long _vq_lengthlist__44u1__p1_0[] = {
  132146. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132147. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132148. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132149. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132150. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132151. 13,
  132152. };
  132153. static float _vq_quantthresh__44u1__p1_0[] = {
  132154. -0.5, 0.5,
  132155. };
  132156. static long _vq_quantmap__44u1__p1_0[] = {
  132157. 1, 0, 2,
  132158. };
  132159. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132160. _vq_quantthresh__44u1__p1_0,
  132161. _vq_quantmap__44u1__p1_0,
  132162. 3,
  132163. 3
  132164. };
  132165. static static_codebook _44u1__p1_0 = {
  132166. 4, 81,
  132167. _vq_lengthlist__44u1__p1_0,
  132168. 1, -535822336, 1611661312, 2, 0,
  132169. _vq_quantlist__44u1__p1_0,
  132170. NULL,
  132171. &_vq_auxt__44u1__p1_0,
  132172. NULL,
  132173. 0
  132174. };
  132175. static long _vq_quantlist__44u1__p2_0[] = {
  132176. 1,
  132177. 0,
  132178. 2,
  132179. };
  132180. static long _vq_lengthlist__44u1__p2_0[] = {
  132181. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132182. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132183. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132184. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132185. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132186. 9,
  132187. };
  132188. static float _vq_quantthresh__44u1__p2_0[] = {
  132189. -0.5, 0.5,
  132190. };
  132191. static long _vq_quantmap__44u1__p2_0[] = {
  132192. 1, 0, 2,
  132193. };
  132194. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132195. _vq_quantthresh__44u1__p2_0,
  132196. _vq_quantmap__44u1__p2_0,
  132197. 3,
  132198. 3
  132199. };
  132200. static static_codebook _44u1__p2_0 = {
  132201. 4, 81,
  132202. _vq_lengthlist__44u1__p2_0,
  132203. 1, -535822336, 1611661312, 2, 0,
  132204. _vq_quantlist__44u1__p2_0,
  132205. NULL,
  132206. &_vq_auxt__44u1__p2_0,
  132207. NULL,
  132208. 0
  132209. };
  132210. static long _vq_quantlist__44u1__p3_0[] = {
  132211. 2,
  132212. 1,
  132213. 3,
  132214. 0,
  132215. 4,
  132216. };
  132217. static long _vq_lengthlist__44u1__p3_0[] = {
  132218. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132219. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132220. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132221. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132222. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132223. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132224. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132225. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132226. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132227. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132228. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132229. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132230. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132231. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132232. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132233. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132234. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132235. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132236. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132237. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132238. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132239. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132240. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132241. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132242. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132243. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132244. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132245. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132246. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132247. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132248. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132249. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132250. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132251. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132252. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132253. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132254. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132255. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132256. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132257. 19,
  132258. };
  132259. static float _vq_quantthresh__44u1__p3_0[] = {
  132260. -1.5, -0.5, 0.5, 1.5,
  132261. };
  132262. static long _vq_quantmap__44u1__p3_0[] = {
  132263. 3, 1, 0, 2, 4,
  132264. };
  132265. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132266. _vq_quantthresh__44u1__p3_0,
  132267. _vq_quantmap__44u1__p3_0,
  132268. 5,
  132269. 5
  132270. };
  132271. static static_codebook _44u1__p3_0 = {
  132272. 4, 625,
  132273. _vq_lengthlist__44u1__p3_0,
  132274. 1, -533725184, 1611661312, 3, 0,
  132275. _vq_quantlist__44u1__p3_0,
  132276. NULL,
  132277. &_vq_auxt__44u1__p3_0,
  132278. NULL,
  132279. 0
  132280. };
  132281. static long _vq_quantlist__44u1__p4_0[] = {
  132282. 2,
  132283. 1,
  132284. 3,
  132285. 0,
  132286. 4,
  132287. };
  132288. static long _vq_lengthlist__44u1__p4_0[] = {
  132289. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132290. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132291. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132292. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132293. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132294. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132295. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132296. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132297. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132298. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132299. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132300. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132301. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132302. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132303. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132304. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132305. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132306. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132307. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132308. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132309. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132310. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132311. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132312. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132313. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132314. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132315. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132316. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132317. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132318. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132319. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132320. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132321. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132322. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132323. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132324. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132325. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132326. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132327. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132328. 12,
  132329. };
  132330. static float _vq_quantthresh__44u1__p4_0[] = {
  132331. -1.5, -0.5, 0.5, 1.5,
  132332. };
  132333. static long _vq_quantmap__44u1__p4_0[] = {
  132334. 3, 1, 0, 2, 4,
  132335. };
  132336. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132337. _vq_quantthresh__44u1__p4_0,
  132338. _vq_quantmap__44u1__p4_0,
  132339. 5,
  132340. 5
  132341. };
  132342. static static_codebook _44u1__p4_0 = {
  132343. 4, 625,
  132344. _vq_lengthlist__44u1__p4_0,
  132345. 1, -533725184, 1611661312, 3, 0,
  132346. _vq_quantlist__44u1__p4_0,
  132347. NULL,
  132348. &_vq_auxt__44u1__p4_0,
  132349. NULL,
  132350. 0
  132351. };
  132352. static long _vq_quantlist__44u1__p5_0[] = {
  132353. 4,
  132354. 3,
  132355. 5,
  132356. 2,
  132357. 6,
  132358. 1,
  132359. 7,
  132360. 0,
  132361. 8,
  132362. };
  132363. static long _vq_lengthlist__44u1__p5_0[] = {
  132364. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132365. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132366. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132367. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132368. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132369. 12,
  132370. };
  132371. static float _vq_quantthresh__44u1__p5_0[] = {
  132372. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132373. };
  132374. static long _vq_quantmap__44u1__p5_0[] = {
  132375. 7, 5, 3, 1, 0, 2, 4, 6,
  132376. 8,
  132377. };
  132378. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132379. _vq_quantthresh__44u1__p5_0,
  132380. _vq_quantmap__44u1__p5_0,
  132381. 9,
  132382. 9
  132383. };
  132384. static static_codebook _44u1__p5_0 = {
  132385. 2, 81,
  132386. _vq_lengthlist__44u1__p5_0,
  132387. 1, -531628032, 1611661312, 4, 0,
  132388. _vq_quantlist__44u1__p5_0,
  132389. NULL,
  132390. &_vq_auxt__44u1__p5_0,
  132391. NULL,
  132392. 0
  132393. };
  132394. static long _vq_quantlist__44u1__p6_0[] = {
  132395. 6,
  132396. 5,
  132397. 7,
  132398. 4,
  132399. 8,
  132400. 3,
  132401. 9,
  132402. 2,
  132403. 10,
  132404. 1,
  132405. 11,
  132406. 0,
  132407. 12,
  132408. };
  132409. static long _vq_lengthlist__44u1__p6_0[] = {
  132410. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132411. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132412. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132413. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132414. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132415. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132416. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132417. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132418. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132419. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132420. 15,17,16,17,18,17,17,18, 0,
  132421. };
  132422. static float _vq_quantthresh__44u1__p6_0[] = {
  132423. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132424. 12.5, 17.5, 22.5, 27.5,
  132425. };
  132426. static long _vq_quantmap__44u1__p6_0[] = {
  132427. 11, 9, 7, 5, 3, 1, 0, 2,
  132428. 4, 6, 8, 10, 12,
  132429. };
  132430. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132431. _vq_quantthresh__44u1__p6_0,
  132432. _vq_quantmap__44u1__p6_0,
  132433. 13,
  132434. 13
  132435. };
  132436. static static_codebook _44u1__p6_0 = {
  132437. 2, 169,
  132438. _vq_lengthlist__44u1__p6_0,
  132439. 1, -526516224, 1616117760, 4, 0,
  132440. _vq_quantlist__44u1__p6_0,
  132441. NULL,
  132442. &_vq_auxt__44u1__p6_0,
  132443. NULL,
  132444. 0
  132445. };
  132446. static long _vq_quantlist__44u1__p6_1[] = {
  132447. 2,
  132448. 1,
  132449. 3,
  132450. 0,
  132451. 4,
  132452. };
  132453. static long _vq_lengthlist__44u1__p6_1[] = {
  132454. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132455. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132456. };
  132457. static float _vq_quantthresh__44u1__p6_1[] = {
  132458. -1.5, -0.5, 0.5, 1.5,
  132459. };
  132460. static long _vq_quantmap__44u1__p6_1[] = {
  132461. 3, 1, 0, 2, 4,
  132462. };
  132463. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132464. _vq_quantthresh__44u1__p6_1,
  132465. _vq_quantmap__44u1__p6_1,
  132466. 5,
  132467. 5
  132468. };
  132469. static static_codebook _44u1__p6_1 = {
  132470. 2, 25,
  132471. _vq_lengthlist__44u1__p6_1,
  132472. 1, -533725184, 1611661312, 3, 0,
  132473. _vq_quantlist__44u1__p6_1,
  132474. NULL,
  132475. &_vq_auxt__44u1__p6_1,
  132476. NULL,
  132477. 0
  132478. };
  132479. static long _vq_quantlist__44u1__p7_0[] = {
  132480. 3,
  132481. 2,
  132482. 4,
  132483. 1,
  132484. 5,
  132485. 0,
  132486. 6,
  132487. };
  132488. static long _vq_lengthlist__44u1__p7_0[] = {
  132489. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132490. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132491. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132492. 8,
  132493. };
  132494. static float _vq_quantthresh__44u1__p7_0[] = {
  132495. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132496. };
  132497. static long _vq_quantmap__44u1__p7_0[] = {
  132498. 5, 3, 1, 0, 2, 4, 6,
  132499. };
  132500. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132501. _vq_quantthresh__44u1__p7_0,
  132502. _vq_quantmap__44u1__p7_0,
  132503. 7,
  132504. 7
  132505. };
  132506. static static_codebook _44u1__p7_0 = {
  132507. 2, 49,
  132508. _vq_lengthlist__44u1__p7_0,
  132509. 1, -518017024, 1626677248, 3, 0,
  132510. _vq_quantlist__44u1__p7_0,
  132511. NULL,
  132512. &_vq_auxt__44u1__p7_0,
  132513. NULL,
  132514. 0
  132515. };
  132516. static long _vq_quantlist__44u1__p7_1[] = {
  132517. 6,
  132518. 5,
  132519. 7,
  132520. 4,
  132521. 8,
  132522. 3,
  132523. 9,
  132524. 2,
  132525. 10,
  132526. 1,
  132527. 11,
  132528. 0,
  132529. 12,
  132530. };
  132531. static long _vq_lengthlist__44u1__p7_1[] = {
  132532. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132533. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132534. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132535. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132536. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132537. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132538. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132539. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132540. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132541. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132542. 15,15,15,15,15,15,15,15,15,
  132543. };
  132544. static float _vq_quantthresh__44u1__p7_1[] = {
  132545. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132546. 32.5, 45.5, 58.5, 71.5,
  132547. };
  132548. static long _vq_quantmap__44u1__p7_1[] = {
  132549. 11, 9, 7, 5, 3, 1, 0, 2,
  132550. 4, 6, 8, 10, 12,
  132551. };
  132552. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  132553. _vq_quantthresh__44u1__p7_1,
  132554. _vq_quantmap__44u1__p7_1,
  132555. 13,
  132556. 13
  132557. };
  132558. static static_codebook _44u1__p7_1 = {
  132559. 2, 169,
  132560. _vq_lengthlist__44u1__p7_1,
  132561. 1, -523010048, 1618608128, 4, 0,
  132562. _vq_quantlist__44u1__p7_1,
  132563. NULL,
  132564. &_vq_auxt__44u1__p7_1,
  132565. NULL,
  132566. 0
  132567. };
  132568. static long _vq_quantlist__44u1__p7_2[] = {
  132569. 6,
  132570. 5,
  132571. 7,
  132572. 4,
  132573. 8,
  132574. 3,
  132575. 9,
  132576. 2,
  132577. 10,
  132578. 1,
  132579. 11,
  132580. 0,
  132581. 12,
  132582. };
  132583. static long _vq_lengthlist__44u1__p7_2[] = {
  132584. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132585. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132586. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132587. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132588. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132589. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132590. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132591. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132592. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132593. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132594. 9, 9, 9,10, 9, 9,10,10, 9,
  132595. };
  132596. static float _vq_quantthresh__44u1__p7_2[] = {
  132597. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132598. 2.5, 3.5, 4.5, 5.5,
  132599. };
  132600. static long _vq_quantmap__44u1__p7_2[] = {
  132601. 11, 9, 7, 5, 3, 1, 0, 2,
  132602. 4, 6, 8, 10, 12,
  132603. };
  132604. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  132605. _vq_quantthresh__44u1__p7_2,
  132606. _vq_quantmap__44u1__p7_2,
  132607. 13,
  132608. 13
  132609. };
  132610. static static_codebook _44u1__p7_2 = {
  132611. 2, 169,
  132612. _vq_lengthlist__44u1__p7_2,
  132613. 1, -531103744, 1611661312, 4, 0,
  132614. _vq_quantlist__44u1__p7_2,
  132615. NULL,
  132616. &_vq_auxt__44u1__p7_2,
  132617. NULL,
  132618. 0
  132619. };
  132620. static long _huff_lengthlist__44u1__short[] = {
  132621. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132622. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132623. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132624. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132625. };
  132626. static static_codebook _huff_book__44u1__short = {
  132627. 2, 64,
  132628. _huff_lengthlist__44u1__short,
  132629. 0, 0, 0, 0, 0,
  132630. NULL,
  132631. NULL,
  132632. NULL,
  132633. NULL,
  132634. 0
  132635. };
  132636. static long _huff_lengthlist__44u2__long[] = {
  132637. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  132638. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  132639. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  132640. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  132641. };
  132642. static static_codebook _huff_book__44u2__long = {
  132643. 2, 64,
  132644. _huff_lengthlist__44u2__long,
  132645. 0, 0, 0, 0, 0,
  132646. NULL,
  132647. NULL,
  132648. NULL,
  132649. NULL,
  132650. 0
  132651. };
  132652. static long _vq_quantlist__44u2__p1_0[] = {
  132653. 1,
  132654. 0,
  132655. 2,
  132656. };
  132657. static long _vq_lengthlist__44u2__p1_0[] = {
  132658. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132659. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132660. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  132661. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  132662. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  132663. 13,
  132664. };
  132665. static float _vq_quantthresh__44u2__p1_0[] = {
  132666. -0.5, 0.5,
  132667. };
  132668. static long _vq_quantmap__44u2__p1_0[] = {
  132669. 1, 0, 2,
  132670. };
  132671. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  132672. _vq_quantthresh__44u2__p1_0,
  132673. _vq_quantmap__44u2__p1_0,
  132674. 3,
  132675. 3
  132676. };
  132677. static static_codebook _44u2__p1_0 = {
  132678. 4, 81,
  132679. _vq_lengthlist__44u2__p1_0,
  132680. 1, -535822336, 1611661312, 2, 0,
  132681. _vq_quantlist__44u2__p1_0,
  132682. NULL,
  132683. &_vq_auxt__44u2__p1_0,
  132684. NULL,
  132685. 0
  132686. };
  132687. static long _vq_quantlist__44u2__p2_0[] = {
  132688. 1,
  132689. 0,
  132690. 2,
  132691. };
  132692. static long _vq_lengthlist__44u2__p2_0[] = {
  132693. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  132694. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  132695. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132696. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  132697. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132698. 9,
  132699. };
  132700. static float _vq_quantthresh__44u2__p2_0[] = {
  132701. -0.5, 0.5,
  132702. };
  132703. static long _vq_quantmap__44u2__p2_0[] = {
  132704. 1, 0, 2,
  132705. };
  132706. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  132707. _vq_quantthresh__44u2__p2_0,
  132708. _vq_quantmap__44u2__p2_0,
  132709. 3,
  132710. 3
  132711. };
  132712. static static_codebook _44u2__p2_0 = {
  132713. 4, 81,
  132714. _vq_lengthlist__44u2__p2_0,
  132715. 1, -535822336, 1611661312, 2, 0,
  132716. _vq_quantlist__44u2__p2_0,
  132717. NULL,
  132718. &_vq_auxt__44u2__p2_0,
  132719. NULL,
  132720. 0
  132721. };
  132722. static long _vq_quantlist__44u2__p3_0[] = {
  132723. 2,
  132724. 1,
  132725. 3,
  132726. 0,
  132727. 4,
  132728. };
  132729. static long _vq_lengthlist__44u2__p3_0[] = {
  132730. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  132731. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  132732. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  132733. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  132734. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  132735. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  132736. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  132737. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  132738. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  132739. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  132740. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  132741. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  132742. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  132743. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  132744. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  132745. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  132746. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  132747. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  132748. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  132749. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  132750. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  132751. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  132752. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  132753. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  132754. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  132755. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  132756. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  132757. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  132758. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  132759. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  132760. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  132761. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  132762. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  132763. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  132764. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  132765. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  132766. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  132767. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  132768. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  132769. 0,
  132770. };
  132771. static float _vq_quantthresh__44u2__p3_0[] = {
  132772. -1.5, -0.5, 0.5, 1.5,
  132773. };
  132774. static long _vq_quantmap__44u2__p3_0[] = {
  132775. 3, 1, 0, 2, 4,
  132776. };
  132777. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  132778. _vq_quantthresh__44u2__p3_0,
  132779. _vq_quantmap__44u2__p3_0,
  132780. 5,
  132781. 5
  132782. };
  132783. static static_codebook _44u2__p3_0 = {
  132784. 4, 625,
  132785. _vq_lengthlist__44u2__p3_0,
  132786. 1, -533725184, 1611661312, 3, 0,
  132787. _vq_quantlist__44u2__p3_0,
  132788. NULL,
  132789. &_vq_auxt__44u2__p3_0,
  132790. NULL,
  132791. 0
  132792. };
  132793. static long _vq_quantlist__44u2__p4_0[] = {
  132794. 2,
  132795. 1,
  132796. 3,
  132797. 0,
  132798. 4,
  132799. };
  132800. static long _vq_lengthlist__44u2__p4_0[] = {
  132801. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  132802. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  132803. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  132804. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  132805. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  132806. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  132807. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  132808. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  132809. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  132810. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  132811. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  132812. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132813. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  132814. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  132815. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  132816. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  132817. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  132818. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  132819. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  132820. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  132821. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  132822. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  132823. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  132824. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  132825. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  132826. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  132827. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  132828. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  132829. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  132830. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  132831. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  132832. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  132833. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  132834. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  132835. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  132836. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  132837. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  132838. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  132839. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  132840. 13,
  132841. };
  132842. static float _vq_quantthresh__44u2__p4_0[] = {
  132843. -1.5, -0.5, 0.5, 1.5,
  132844. };
  132845. static long _vq_quantmap__44u2__p4_0[] = {
  132846. 3, 1, 0, 2, 4,
  132847. };
  132848. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  132849. _vq_quantthresh__44u2__p4_0,
  132850. _vq_quantmap__44u2__p4_0,
  132851. 5,
  132852. 5
  132853. };
  132854. static static_codebook _44u2__p4_0 = {
  132855. 4, 625,
  132856. _vq_lengthlist__44u2__p4_0,
  132857. 1, -533725184, 1611661312, 3, 0,
  132858. _vq_quantlist__44u2__p4_0,
  132859. NULL,
  132860. &_vq_auxt__44u2__p4_0,
  132861. NULL,
  132862. 0
  132863. };
  132864. static long _vq_quantlist__44u2__p5_0[] = {
  132865. 4,
  132866. 3,
  132867. 5,
  132868. 2,
  132869. 6,
  132870. 1,
  132871. 7,
  132872. 0,
  132873. 8,
  132874. };
  132875. static long _vq_lengthlist__44u2__p5_0[] = {
  132876. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  132877. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  132878. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  132879. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  132880. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  132881. 13,
  132882. };
  132883. static float _vq_quantthresh__44u2__p5_0[] = {
  132884. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132885. };
  132886. static long _vq_quantmap__44u2__p5_0[] = {
  132887. 7, 5, 3, 1, 0, 2, 4, 6,
  132888. 8,
  132889. };
  132890. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  132891. _vq_quantthresh__44u2__p5_0,
  132892. _vq_quantmap__44u2__p5_0,
  132893. 9,
  132894. 9
  132895. };
  132896. static static_codebook _44u2__p5_0 = {
  132897. 2, 81,
  132898. _vq_lengthlist__44u2__p5_0,
  132899. 1, -531628032, 1611661312, 4, 0,
  132900. _vq_quantlist__44u2__p5_0,
  132901. NULL,
  132902. &_vq_auxt__44u2__p5_0,
  132903. NULL,
  132904. 0
  132905. };
  132906. static long _vq_quantlist__44u2__p6_0[] = {
  132907. 6,
  132908. 5,
  132909. 7,
  132910. 4,
  132911. 8,
  132912. 3,
  132913. 9,
  132914. 2,
  132915. 10,
  132916. 1,
  132917. 11,
  132918. 0,
  132919. 12,
  132920. };
  132921. static long _vq_lengthlist__44u2__p6_0[] = {
  132922. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  132923. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  132924. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  132925. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  132926. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  132927. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  132928. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  132929. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  132930. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  132931. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  132932. 15,17,17,16,18,17,18, 0, 0,
  132933. };
  132934. static float _vq_quantthresh__44u2__p6_0[] = {
  132935. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132936. 12.5, 17.5, 22.5, 27.5,
  132937. };
  132938. static long _vq_quantmap__44u2__p6_0[] = {
  132939. 11, 9, 7, 5, 3, 1, 0, 2,
  132940. 4, 6, 8, 10, 12,
  132941. };
  132942. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  132943. _vq_quantthresh__44u2__p6_0,
  132944. _vq_quantmap__44u2__p6_0,
  132945. 13,
  132946. 13
  132947. };
  132948. static static_codebook _44u2__p6_0 = {
  132949. 2, 169,
  132950. _vq_lengthlist__44u2__p6_0,
  132951. 1, -526516224, 1616117760, 4, 0,
  132952. _vq_quantlist__44u2__p6_0,
  132953. NULL,
  132954. &_vq_auxt__44u2__p6_0,
  132955. NULL,
  132956. 0
  132957. };
  132958. static long _vq_quantlist__44u2__p6_1[] = {
  132959. 2,
  132960. 1,
  132961. 3,
  132962. 0,
  132963. 4,
  132964. };
  132965. static long _vq_lengthlist__44u2__p6_1[] = {
  132966. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  132967. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  132968. };
  132969. static float _vq_quantthresh__44u2__p6_1[] = {
  132970. -1.5, -0.5, 0.5, 1.5,
  132971. };
  132972. static long _vq_quantmap__44u2__p6_1[] = {
  132973. 3, 1, 0, 2, 4,
  132974. };
  132975. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  132976. _vq_quantthresh__44u2__p6_1,
  132977. _vq_quantmap__44u2__p6_1,
  132978. 5,
  132979. 5
  132980. };
  132981. static static_codebook _44u2__p6_1 = {
  132982. 2, 25,
  132983. _vq_lengthlist__44u2__p6_1,
  132984. 1, -533725184, 1611661312, 3, 0,
  132985. _vq_quantlist__44u2__p6_1,
  132986. NULL,
  132987. &_vq_auxt__44u2__p6_1,
  132988. NULL,
  132989. 0
  132990. };
  132991. static long _vq_quantlist__44u2__p7_0[] = {
  132992. 4,
  132993. 3,
  132994. 5,
  132995. 2,
  132996. 6,
  132997. 1,
  132998. 7,
  132999. 0,
  133000. 8,
  133001. };
  133002. static long _vq_lengthlist__44u2__p7_0[] = {
  133003. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  133004. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  133005. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133006. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133007. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133008. 11,
  133009. };
  133010. static float _vq_quantthresh__44u2__p7_0[] = {
  133011. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133012. };
  133013. static long _vq_quantmap__44u2__p7_0[] = {
  133014. 7, 5, 3, 1, 0, 2, 4, 6,
  133015. 8,
  133016. };
  133017. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133018. _vq_quantthresh__44u2__p7_0,
  133019. _vq_quantmap__44u2__p7_0,
  133020. 9,
  133021. 9
  133022. };
  133023. static static_codebook _44u2__p7_0 = {
  133024. 2, 81,
  133025. _vq_lengthlist__44u2__p7_0,
  133026. 1, -516612096, 1626677248, 4, 0,
  133027. _vq_quantlist__44u2__p7_0,
  133028. NULL,
  133029. &_vq_auxt__44u2__p7_0,
  133030. NULL,
  133031. 0
  133032. };
  133033. static long _vq_quantlist__44u2__p7_1[] = {
  133034. 6,
  133035. 5,
  133036. 7,
  133037. 4,
  133038. 8,
  133039. 3,
  133040. 9,
  133041. 2,
  133042. 10,
  133043. 1,
  133044. 11,
  133045. 0,
  133046. 12,
  133047. };
  133048. static long _vq_lengthlist__44u2__p7_1[] = {
  133049. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133050. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133051. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133052. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133053. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133054. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133055. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133056. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133057. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133058. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133059. 14,14,14,17,15,17,17,17,17,
  133060. };
  133061. static float _vq_quantthresh__44u2__p7_1[] = {
  133062. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133063. 32.5, 45.5, 58.5, 71.5,
  133064. };
  133065. static long _vq_quantmap__44u2__p7_1[] = {
  133066. 11, 9, 7, 5, 3, 1, 0, 2,
  133067. 4, 6, 8, 10, 12,
  133068. };
  133069. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133070. _vq_quantthresh__44u2__p7_1,
  133071. _vq_quantmap__44u2__p7_1,
  133072. 13,
  133073. 13
  133074. };
  133075. static static_codebook _44u2__p7_1 = {
  133076. 2, 169,
  133077. _vq_lengthlist__44u2__p7_1,
  133078. 1, -523010048, 1618608128, 4, 0,
  133079. _vq_quantlist__44u2__p7_1,
  133080. NULL,
  133081. &_vq_auxt__44u2__p7_1,
  133082. NULL,
  133083. 0
  133084. };
  133085. static long _vq_quantlist__44u2__p7_2[] = {
  133086. 6,
  133087. 5,
  133088. 7,
  133089. 4,
  133090. 8,
  133091. 3,
  133092. 9,
  133093. 2,
  133094. 10,
  133095. 1,
  133096. 11,
  133097. 0,
  133098. 12,
  133099. };
  133100. static long _vq_lengthlist__44u2__p7_2[] = {
  133101. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133102. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133103. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133104. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133105. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133106. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133107. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133108. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133109. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133110. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133111. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133112. };
  133113. static float _vq_quantthresh__44u2__p7_2[] = {
  133114. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133115. 2.5, 3.5, 4.5, 5.5,
  133116. };
  133117. static long _vq_quantmap__44u2__p7_2[] = {
  133118. 11, 9, 7, 5, 3, 1, 0, 2,
  133119. 4, 6, 8, 10, 12,
  133120. };
  133121. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133122. _vq_quantthresh__44u2__p7_2,
  133123. _vq_quantmap__44u2__p7_2,
  133124. 13,
  133125. 13
  133126. };
  133127. static static_codebook _44u2__p7_2 = {
  133128. 2, 169,
  133129. _vq_lengthlist__44u2__p7_2,
  133130. 1, -531103744, 1611661312, 4, 0,
  133131. _vq_quantlist__44u2__p7_2,
  133132. NULL,
  133133. &_vq_auxt__44u2__p7_2,
  133134. NULL,
  133135. 0
  133136. };
  133137. static long _huff_lengthlist__44u2__short[] = {
  133138. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133139. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133140. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133141. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133142. };
  133143. static static_codebook _huff_book__44u2__short = {
  133144. 2, 64,
  133145. _huff_lengthlist__44u2__short,
  133146. 0, 0, 0, 0, 0,
  133147. NULL,
  133148. NULL,
  133149. NULL,
  133150. NULL,
  133151. 0
  133152. };
  133153. static long _huff_lengthlist__44u3__long[] = {
  133154. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133155. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133156. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133157. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133158. };
  133159. static static_codebook _huff_book__44u3__long = {
  133160. 2, 64,
  133161. _huff_lengthlist__44u3__long,
  133162. 0, 0, 0, 0, 0,
  133163. NULL,
  133164. NULL,
  133165. NULL,
  133166. NULL,
  133167. 0
  133168. };
  133169. static long _vq_quantlist__44u3__p1_0[] = {
  133170. 1,
  133171. 0,
  133172. 2,
  133173. };
  133174. static long _vq_lengthlist__44u3__p1_0[] = {
  133175. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133176. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133177. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133178. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133179. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133180. 13,
  133181. };
  133182. static float _vq_quantthresh__44u3__p1_0[] = {
  133183. -0.5, 0.5,
  133184. };
  133185. static long _vq_quantmap__44u3__p1_0[] = {
  133186. 1, 0, 2,
  133187. };
  133188. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133189. _vq_quantthresh__44u3__p1_0,
  133190. _vq_quantmap__44u3__p1_0,
  133191. 3,
  133192. 3
  133193. };
  133194. static static_codebook _44u3__p1_0 = {
  133195. 4, 81,
  133196. _vq_lengthlist__44u3__p1_0,
  133197. 1, -535822336, 1611661312, 2, 0,
  133198. _vq_quantlist__44u3__p1_0,
  133199. NULL,
  133200. &_vq_auxt__44u3__p1_0,
  133201. NULL,
  133202. 0
  133203. };
  133204. static long _vq_quantlist__44u3__p2_0[] = {
  133205. 1,
  133206. 0,
  133207. 2,
  133208. };
  133209. static long _vq_lengthlist__44u3__p2_0[] = {
  133210. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133211. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133212. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133213. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133214. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133215. 9,
  133216. };
  133217. static float _vq_quantthresh__44u3__p2_0[] = {
  133218. -0.5, 0.5,
  133219. };
  133220. static long _vq_quantmap__44u3__p2_0[] = {
  133221. 1, 0, 2,
  133222. };
  133223. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133224. _vq_quantthresh__44u3__p2_0,
  133225. _vq_quantmap__44u3__p2_0,
  133226. 3,
  133227. 3
  133228. };
  133229. static static_codebook _44u3__p2_0 = {
  133230. 4, 81,
  133231. _vq_lengthlist__44u3__p2_0,
  133232. 1, -535822336, 1611661312, 2, 0,
  133233. _vq_quantlist__44u3__p2_0,
  133234. NULL,
  133235. &_vq_auxt__44u3__p2_0,
  133236. NULL,
  133237. 0
  133238. };
  133239. static long _vq_quantlist__44u3__p3_0[] = {
  133240. 2,
  133241. 1,
  133242. 3,
  133243. 0,
  133244. 4,
  133245. };
  133246. static long _vq_lengthlist__44u3__p3_0[] = {
  133247. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133248. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133249. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133250. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133251. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133252. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133253. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133254. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133255. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133256. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133257. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133258. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133259. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133260. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133261. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133262. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133263. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133264. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133265. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133266. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133267. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133268. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133269. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133270. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133271. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133272. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133273. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133274. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133275. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133276. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133277. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133278. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133279. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133280. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133281. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133282. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133283. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133284. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133285. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133286. 0,
  133287. };
  133288. static float _vq_quantthresh__44u3__p3_0[] = {
  133289. -1.5, -0.5, 0.5, 1.5,
  133290. };
  133291. static long _vq_quantmap__44u3__p3_0[] = {
  133292. 3, 1, 0, 2, 4,
  133293. };
  133294. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133295. _vq_quantthresh__44u3__p3_0,
  133296. _vq_quantmap__44u3__p3_0,
  133297. 5,
  133298. 5
  133299. };
  133300. static static_codebook _44u3__p3_0 = {
  133301. 4, 625,
  133302. _vq_lengthlist__44u3__p3_0,
  133303. 1, -533725184, 1611661312, 3, 0,
  133304. _vq_quantlist__44u3__p3_0,
  133305. NULL,
  133306. &_vq_auxt__44u3__p3_0,
  133307. NULL,
  133308. 0
  133309. };
  133310. static long _vq_quantlist__44u3__p4_0[] = {
  133311. 2,
  133312. 1,
  133313. 3,
  133314. 0,
  133315. 4,
  133316. };
  133317. static long _vq_lengthlist__44u3__p4_0[] = {
  133318. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133319. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133320. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133321. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133322. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133323. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133324. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133325. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133326. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133327. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133328. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133329. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133330. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133331. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133332. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133333. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133334. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133335. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133336. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133337. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133338. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133339. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133340. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133341. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133342. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133343. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133344. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133345. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133346. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133347. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133348. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133349. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133350. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133351. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133352. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133353. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133354. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133355. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133356. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133357. 13,
  133358. };
  133359. static float _vq_quantthresh__44u3__p4_0[] = {
  133360. -1.5, -0.5, 0.5, 1.5,
  133361. };
  133362. static long _vq_quantmap__44u3__p4_0[] = {
  133363. 3, 1, 0, 2, 4,
  133364. };
  133365. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133366. _vq_quantthresh__44u3__p4_0,
  133367. _vq_quantmap__44u3__p4_0,
  133368. 5,
  133369. 5
  133370. };
  133371. static static_codebook _44u3__p4_0 = {
  133372. 4, 625,
  133373. _vq_lengthlist__44u3__p4_0,
  133374. 1, -533725184, 1611661312, 3, 0,
  133375. _vq_quantlist__44u3__p4_0,
  133376. NULL,
  133377. &_vq_auxt__44u3__p4_0,
  133378. NULL,
  133379. 0
  133380. };
  133381. static long _vq_quantlist__44u3__p5_0[] = {
  133382. 4,
  133383. 3,
  133384. 5,
  133385. 2,
  133386. 6,
  133387. 1,
  133388. 7,
  133389. 0,
  133390. 8,
  133391. };
  133392. static long _vq_lengthlist__44u3__p5_0[] = {
  133393. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133394. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133395. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133396. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133397. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133398. 12,
  133399. };
  133400. static float _vq_quantthresh__44u3__p5_0[] = {
  133401. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133402. };
  133403. static long _vq_quantmap__44u3__p5_0[] = {
  133404. 7, 5, 3, 1, 0, 2, 4, 6,
  133405. 8,
  133406. };
  133407. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133408. _vq_quantthresh__44u3__p5_0,
  133409. _vq_quantmap__44u3__p5_0,
  133410. 9,
  133411. 9
  133412. };
  133413. static static_codebook _44u3__p5_0 = {
  133414. 2, 81,
  133415. _vq_lengthlist__44u3__p5_0,
  133416. 1, -531628032, 1611661312, 4, 0,
  133417. _vq_quantlist__44u3__p5_0,
  133418. NULL,
  133419. &_vq_auxt__44u3__p5_0,
  133420. NULL,
  133421. 0
  133422. };
  133423. static long _vq_quantlist__44u3__p6_0[] = {
  133424. 6,
  133425. 5,
  133426. 7,
  133427. 4,
  133428. 8,
  133429. 3,
  133430. 9,
  133431. 2,
  133432. 10,
  133433. 1,
  133434. 11,
  133435. 0,
  133436. 12,
  133437. };
  133438. static long _vq_lengthlist__44u3__p6_0[] = {
  133439. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133440. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133441. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133442. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133443. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133444. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133445. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133446. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133447. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133448. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133449. 15,16,16,16,17,18,16,20,18,
  133450. };
  133451. static float _vq_quantthresh__44u3__p6_0[] = {
  133452. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133453. 12.5, 17.5, 22.5, 27.5,
  133454. };
  133455. static long _vq_quantmap__44u3__p6_0[] = {
  133456. 11, 9, 7, 5, 3, 1, 0, 2,
  133457. 4, 6, 8, 10, 12,
  133458. };
  133459. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133460. _vq_quantthresh__44u3__p6_0,
  133461. _vq_quantmap__44u3__p6_0,
  133462. 13,
  133463. 13
  133464. };
  133465. static static_codebook _44u3__p6_0 = {
  133466. 2, 169,
  133467. _vq_lengthlist__44u3__p6_0,
  133468. 1, -526516224, 1616117760, 4, 0,
  133469. _vq_quantlist__44u3__p6_0,
  133470. NULL,
  133471. &_vq_auxt__44u3__p6_0,
  133472. NULL,
  133473. 0
  133474. };
  133475. static long _vq_quantlist__44u3__p6_1[] = {
  133476. 2,
  133477. 1,
  133478. 3,
  133479. 0,
  133480. 4,
  133481. };
  133482. static long _vq_lengthlist__44u3__p6_1[] = {
  133483. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133484. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133485. };
  133486. static float _vq_quantthresh__44u3__p6_1[] = {
  133487. -1.5, -0.5, 0.5, 1.5,
  133488. };
  133489. static long _vq_quantmap__44u3__p6_1[] = {
  133490. 3, 1, 0, 2, 4,
  133491. };
  133492. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133493. _vq_quantthresh__44u3__p6_1,
  133494. _vq_quantmap__44u3__p6_1,
  133495. 5,
  133496. 5
  133497. };
  133498. static static_codebook _44u3__p6_1 = {
  133499. 2, 25,
  133500. _vq_lengthlist__44u3__p6_1,
  133501. 1, -533725184, 1611661312, 3, 0,
  133502. _vq_quantlist__44u3__p6_1,
  133503. NULL,
  133504. &_vq_auxt__44u3__p6_1,
  133505. NULL,
  133506. 0
  133507. };
  133508. static long _vq_quantlist__44u3__p7_0[] = {
  133509. 4,
  133510. 3,
  133511. 5,
  133512. 2,
  133513. 6,
  133514. 1,
  133515. 7,
  133516. 0,
  133517. 8,
  133518. };
  133519. static long _vq_lengthlist__44u3__p7_0[] = {
  133520. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133521. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133522. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133523. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133524. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133525. 9,
  133526. };
  133527. static float _vq_quantthresh__44u3__p7_0[] = {
  133528. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133529. };
  133530. static long _vq_quantmap__44u3__p7_0[] = {
  133531. 7, 5, 3, 1, 0, 2, 4, 6,
  133532. 8,
  133533. };
  133534. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  133535. _vq_quantthresh__44u3__p7_0,
  133536. _vq_quantmap__44u3__p7_0,
  133537. 9,
  133538. 9
  133539. };
  133540. static static_codebook _44u3__p7_0 = {
  133541. 2, 81,
  133542. _vq_lengthlist__44u3__p7_0,
  133543. 1, -515907584, 1627381760, 4, 0,
  133544. _vq_quantlist__44u3__p7_0,
  133545. NULL,
  133546. &_vq_auxt__44u3__p7_0,
  133547. NULL,
  133548. 0
  133549. };
  133550. static long _vq_quantlist__44u3__p7_1[] = {
  133551. 7,
  133552. 6,
  133553. 8,
  133554. 5,
  133555. 9,
  133556. 4,
  133557. 10,
  133558. 3,
  133559. 11,
  133560. 2,
  133561. 12,
  133562. 1,
  133563. 13,
  133564. 0,
  133565. 14,
  133566. };
  133567. static long _vq_lengthlist__44u3__p7_1[] = {
  133568. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  133569. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  133570. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  133571. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  133572. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  133573. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  133574. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  133575. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  133576. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  133577. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  133578. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  133579. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  133580. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  133581. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  133582. 17,
  133583. };
  133584. static float _vq_quantthresh__44u3__p7_1[] = {
  133585. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133586. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133587. };
  133588. static long _vq_quantmap__44u3__p7_1[] = {
  133589. 13, 11, 9, 7, 5, 3, 1, 0,
  133590. 2, 4, 6, 8, 10, 12, 14,
  133591. };
  133592. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  133593. _vq_quantthresh__44u3__p7_1,
  133594. _vq_quantmap__44u3__p7_1,
  133595. 15,
  133596. 15
  133597. };
  133598. static static_codebook _44u3__p7_1 = {
  133599. 2, 225,
  133600. _vq_lengthlist__44u3__p7_1,
  133601. 1, -522338304, 1620115456, 4, 0,
  133602. _vq_quantlist__44u3__p7_1,
  133603. NULL,
  133604. &_vq_auxt__44u3__p7_1,
  133605. NULL,
  133606. 0
  133607. };
  133608. static long _vq_quantlist__44u3__p7_2[] = {
  133609. 8,
  133610. 7,
  133611. 9,
  133612. 6,
  133613. 10,
  133614. 5,
  133615. 11,
  133616. 4,
  133617. 12,
  133618. 3,
  133619. 13,
  133620. 2,
  133621. 14,
  133622. 1,
  133623. 15,
  133624. 0,
  133625. 16,
  133626. };
  133627. static long _vq_lengthlist__44u3__p7_2[] = {
  133628. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133629. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133630. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  133631. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133632. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  133633. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133634. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  133635. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133636. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  133637. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  133638. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  133639. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  133640. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  133641. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133642. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  133643. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  133644. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  133645. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  133646. 11,
  133647. };
  133648. static float _vq_quantthresh__44u3__p7_2[] = {
  133649. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  133650. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  133651. };
  133652. static long _vq_quantmap__44u3__p7_2[] = {
  133653. 15, 13, 11, 9, 7, 5, 3, 1,
  133654. 0, 2, 4, 6, 8, 10, 12, 14,
  133655. 16,
  133656. };
  133657. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  133658. _vq_quantthresh__44u3__p7_2,
  133659. _vq_quantmap__44u3__p7_2,
  133660. 17,
  133661. 17
  133662. };
  133663. static static_codebook _44u3__p7_2 = {
  133664. 2, 289,
  133665. _vq_lengthlist__44u3__p7_2,
  133666. 1, -529530880, 1611661312, 5, 0,
  133667. _vq_quantlist__44u3__p7_2,
  133668. NULL,
  133669. &_vq_auxt__44u3__p7_2,
  133670. NULL,
  133671. 0
  133672. };
  133673. static long _huff_lengthlist__44u3__short[] = {
  133674. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  133675. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  133676. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  133677. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  133678. };
  133679. static static_codebook _huff_book__44u3__short = {
  133680. 2, 64,
  133681. _huff_lengthlist__44u3__short,
  133682. 0, 0, 0, 0, 0,
  133683. NULL,
  133684. NULL,
  133685. NULL,
  133686. NULL,
  133687. 0
  133688. };
  133689. static long _huff_lengthlist__44u4__long[] = {
  133690. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  133691. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  133692. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  133693. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  133694. };
  133695. static static_codebook _huff_book__44u4__long = {
  133696. 2, 64,
  133697. _huff_lengthlist__44u4__long,
  133698. 0, 0, 0, 0, 0,
  133699. NULL,
  133700. NULL,
  133701. NULL,
  133702. NULL,
  133703. 0
  133704. };
  133705. static long _vq_quantlist__44u4__p1_0[] = {
  133706. 1,
  133707. 0,
  133708. 2,
  133709. };
  133710. static long _vq_lengthlist__44u4__p1_0[] = {
  133711. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133712. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133713. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  133714. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133715. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  133716. 13,
  133717. };
  133718. static float _vq_quantthresh__44u4__p1_0[] = {
  133719. -0.5, 0.5,
  133720. };
  133721. static long _vq_quantmap__44u4__p1_0[] = {
  133722. 1, 0, 2,
  133723. };
  133724. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  133725. _vq_quantthresh__44u4__p1_0,
  133726. _vq_quantmap__44u4__p1_0,
  133727. 3,
  133728. 3
  133729. };
  133730. static static_codebook _44u4__p1_0 = {
  133731. 4, 81,
  133732. _vq_lengthlist__44u4__p1_0,
  133733. 1, -535822336, 1611661312, 2, 0,
  133734. _vq_quantlist__44u4__p1_0,
  133735. NULL,
  133736. &_vq_auxt__44u4__p1_0,
  133737. NULL,
  133738. 0
  133739. };
  133740. static long _vq_quantlist__44u4__p2_0[] = {
  133741. 1,
  133742. 0,
  133743. 2,
  133744. };
  133745. static long _vq_lengthlist__44u4__p2_0[] = {
  133746. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133747. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  133748. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133749. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  133750. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133751. 9,
  133752. };
  133753. static float _vq_quantthresh__44u4__p2_0[] = {
  133754. -0.5, 0.5,
  133755. };
  133756. static long _vq_quantmap__44u4__p2_0[] = {
  133757. 1, 0, 2,
  133758. };
  133759. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  133760. _vq_quantthresh__44u4__p2_0,
  133761. _vq_quantmap__44u4__p2_0,
  133762. 3,
  133763. 3
  133764. };
  133765. static static_codebook _44u4__p2_0 = {
  133766. 4, 81,
  133767. _vq_lengthlist__44u4__p2_0,
  133768. 1, -535822336, 1611661312, 2, 0,
  133769. _vq_quantlist__44u4__p2_0,
  133770. NULL,
  133771. &_vq_auxt__44u4__p2_0,
  133772. NULL,
  133773. 0
  133774. };
  133775. static long _vq_quantlist__44u4__p3_0[] = {
  133776. 2,
  133777. 1,
  133778. 3,
  133779. 0,
  133780. 4,
  133781. };
  133782. static long _vq_lengthlist__44u4__p3_0[] = {
  133783. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133784. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  133785. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  133786. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  133787. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  133788. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  133789. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  133790. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  133791. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  133792. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  133793. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  133794. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  133795. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  133796. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  133797. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  133798. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  133799. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  133800. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  133801. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  133802. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  133803. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  133804. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  133805. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  133806. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  133807. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  133808. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  133809. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  133810. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  133811. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  133812. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  133813. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  133814. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  133815. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  133816. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  133817. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  133818. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  133819. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  133820. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  133821. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  133822. 0,
  133823. };
  133824. static float _vq_quantthresh__44u4__p3_0[] = {
  133825. -1.5, -0.5, 0.5, 1.5,
  133826. };
  133827. static long _vq_quantmap__44u4__p3_0[] = {
  133828. 3, 1, 0, 2, 4,
  133829. };
  133830. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  133831. _vq_quantthresh__44u4__p3_0,
  133832. _vq_quantmap__44u4__p3_0,
  133833. 5,
  133834. 5
  133835. };
  133836. static static_codebook _44u4__p3_0 = {
  133837. 4, 625,
  133838. _vq_lengthlist__44u4__p3_0,
  133839. 1, -533725184, 1611661312, 3, 0,
  133840. _vq_quantlist__44u4__p3_0,
  133841. NULL,
  133842. &_vq_auxt__44u4__p3_0,
  133843. NULL,
  133844. 0
  133845. };
  133846. static long _vq_quantlist__44u4__p4_0[] = {
  133847. 2,
  133848. 1,
  133849. 3,
  133850. 0,
  133851. 4,
  133852. };
  133853. static long _vq_lengthlist__44u4__p4_0[] = {
  133854. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133855. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133856. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133857. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133858. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133859. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  133860. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  133861. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  133862. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133863. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133864. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133865. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133866. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133867. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  133868. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133869. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133870. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133871. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133872. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133873. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133874. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133875. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133876. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133877. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133878. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133879. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  133880. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  133881. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  133882. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  133883. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  133884. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  133885. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133886. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133887. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  133888. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133889. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  133890. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133891. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  133892. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  133893. 13,
  133894. };
  133895. static float _vq_quantthresh__44u4__p4_0[] = {
  133896. -1.5, -0.5, 0.5, 1.5,
  133897. };
  133898. static long _vq_quantmap__44u4__p4_0[] = {
  133899. 3, 1, 0, 2, 4,
  133900. };
  133901. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  133902. _vq_quantthresh__44u4__p4_0,
  133903. _vq_quantmap__44u4__p4_0,
  133904. 5,
  133905. 5
  133906. };
  133907. static static_codebook _44u4__p4_0 = {
  133908. 4, 625,
  133909. _vq_lengthlist__44u4__p4_0,
  133910. 1, -533725184, 1611661312, 3, 0,
  133911. _vq_quantlist__44u4__p4_0,
  133912. NULL,
  133913. &_vq_auxt__44u4__p4_0,
  133914. NULL,
  133915. 0
  133916. };
  133917. static long _vq_quantlist__44u4__p5_0[] = {
  133918. 4,
  133919. 3,
  133920. 5,
  133921. 2,
  133922. 6,
  133923. 1,
  133924. 7,
  133925. 0,
  133926. 8,
  133927. };
  133928. static long _vq_lengthlist__44u4__p5_0[] = {
  133929. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133930. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133931. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  133932. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133933. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  133934. 12,
  133935. };
  133936. static float _vq_quantthresh__44u4__p5_0[] = {
  133937. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133938. };
  133939. static long _vq_quantmap__44u4__p5_0[] = {
  133940. 7, 5, 3, 1, 0, 2, 4, 6,
  133941. 8,
  133942. };
  133943. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  133944. _vq_quantthresh__44u4__p5_0,
  133945. _vq_quantmap__44u4__p5_0,
  133946. 9,
  133947. 9
  133948. };
  133949. static static_codebook _44u4__p5_0 = {
  133950. 2, 81,
  133951. _vq_lengthlist__44u4__p5_0,
  133952. 1, -531628032, 1611661312, 4, 0,
  133953. _vq_quantlist__44u4__p5_0,
  133954. NULL,
  133955. &_vq_auxt__44u4__p5_0,
  133956. NULL,
  133957. 0
  133958. };
  133959. static long _vq_quantlist__44u4__p6_0[] = {
  133960. 6,
  133961. 5,
  133962. 7,
  133963. 4,
  133964. 8,
  133965. 3,
  133966. 9,
  133967. 2,
  133968. 10,
  133969. 1,
  133970. 11,
  133971. 0,
  133972. 12,
  133973. };
  133974. static long _vq_lengthlist__44u4__p6_0[] = {
  133975. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  133976. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133977. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133978. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133979. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  133980. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  133981. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  133982. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  133983. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  133984. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  133985. 16,16,16,17,17,18,17,20,21,
  133986. };
  133987. static float _vq_quantthresh__44u4__p6_0[] = {
  133988. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133989. 12.5, 17.5, 22.5, 27.5,
  133990. };
  133991. static long _vq_quantmap__44u4__p6_0[] = {
  133992. 11, 9, 7, 5, 3, 1, 0, 2,
  133993. 4, 6, 8, 10, 12,
  133994. };
  133995. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  133996. _vq_quantthresh__44u4__p6_0,
  133997. _vq_quantmap__44u4__p6_0,
  133998. 13,
  133999. 13
  134000. };
  134001. static static_codebook _44u4__p6_0 = {
  134002. 2, 169,
  134003. _vq_lengthlist__44u4__p6_0,
  134004. 1, -526516224, 1616117760, 4, 0,
  134005. _vq_quantlist__44u4__p6_0,
  134006. NULL,
  134007. &_vq_auxt__44u4__p6_0,
  134008. NULL,
  134009. 0
  134010. };
  134011. static long _vq_quantlist__44u4__p6_1[] = {
  134012. 2,
  134013. 1,
  134014. 3,
  134015. 0,
  134016. 4,
  134017. };
  134018. static long _vq_lengthlist__44u4__p6_1[] = {
  134019. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134020. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134021. };
  134022. static float _vq_quantthresh__44u4__p6_1[] = {
  134023. -1.5, -0.5, 0.5, 1.5,
  134024. };
  134025. static long _vq_quantmap__44u4__p6_1[] = {
  134026. 3, 1, 0, 2, 4,
  134027. };
  134028. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134029. _vq_quantthresh__44u4__p6_1,
  134030. _vq_quantmap__44u4__p6_1,
  134031. 5,
  134032. 5
  134033. };
  134034. static static_codebook _44u4__p6_1 = {
  134035. 2, 25,
  134036. _vq_lengthlist__44u4__p6_1,
  134037. 1, -533725184, 1611661312, 3, 0,
  134038. _vq_quantlist__44u4__p6_1,
  134039. NULL,
  134040. &_vq_auxt__44u4__p6_1,
  134041. NULL,
  134042. 0
  134043. };
  134044. static long _vq_quantlist__44u4__p7_0[] = {
  134045. 6,
  134046. 5,
  134047. 7,
  134048. 4,
  134049. 8,
  134050. 3,
  134051. 9,
  134052. 2,
  134053. 10,
  134054. 1,
  134055. 11,
  134056. 0,
  134057. 12,
  134058. };
  134059. static long _vq_lengthlist__44u4__p7_0[] = {
  134060. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134061. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134062. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134063. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134064. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134065. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134066. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134067. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134068. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134069. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134070. 11,11,11,11,11,11,11,11,11,
  134071. };
  134072. static float _vq_quantthresh__44u4__p7_0[] = {
  134073. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134074. 637.5, 892.5, 1147.5, 1402.5,
  134075. };
  134076. static long _vq_quantmap__44u4__p7_0[] = {
  134077. 11, 9, 7, 5, 3, 1, 0, 2,
  134078. 4, 6, 8, 10, 12,
  134079. };
  134080. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134081. _vq_quantthresh__44u4__p7_0,
  134082. _vq_quantmap__44u4__p7_0,
  134083. 13,
  134084. 13
  134085. };
  134086. static static_codebook _44u4__p7_0 = {
  134087. 2, 169,
  134088. _vq_lengthlist__44u4__p7_0,
  134089. 1, -514332672, 1627381760, 4, 0,
  134090. _vq_quantlist__44u4__p7_0,
  134091. NULL,
  134092. &_vq_auxt__44u4__p7_0,
  134093. NULL,
  134094. 0
  134095. };
  134096. static long _vq_quantlist__44u4__p7_1[] = {
  134097. 7,
  134098. 6,
  134099. 8,
  134100. 5,
  134101. 9,
  134102. 4,
  134103. 10,
  134104. 3,
  134105. 11,
  134106. 2,
  134107. 12,
  134108. 1,
  134109. 13,
  134110. 0,
  134111. 14,
  134112. };
  134113. static long _vq_lengthlist__44u4__p7_1[] = {
  134114. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134115. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134116. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134117. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134118. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134119. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134120. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134121. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134122. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134123. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134124. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134125. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134126. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134127. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134128. 16,
  134129. };
  134130. static float _vq_quantthresh__44u4__p7_1[] = {
  134131. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134132. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134133. };
  134134. static long _vq_quantmap__44u4__p7_1[] = {
  134135. 13, 11, 9, 7, 5, 3, 1, 0,
  134136. 2, 4, 6, 8, 10, 12, 14,
  134137. };
  134138. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134139. _vq_quantthresh__44u4__p7_1,
  134140. _vq_quantmap__44u4__p7_1,
  134141. 15,
  134142. 15
  134143. };
  134144. static static_codebook _44u4__p7_1 = {
  134145. 2, 225,
  134146. _vq_lengthlist__44u4__p7_1,
  134147. 1, -522338304, 1620115456, 4, 0,
  134148. _vq_quantlist__44u4__p7_1,
  134149. NULL,
  134150. &_vq_auxt__44u4__p7_1,
  134151. NULL,
  134152. 0
  134153. };
  134154. static long _vq_quantlist__44u4__p7_2[] = {
  134155. 8,
  134156. 7,
  134157. 9,
  134158. 6,
  134159. 10,
  134160. 5,
  134161. 11,
  134162. 4,
  134163. 12,
  134164. 3,
  134165. 13,
  134166. 2,
  134167. 14,
  134168. 1,
  134169. 15,
  134170. 0,
  134171. 16,
  134172. };
  134173. static long _vq_lengthlist__44u4__p7_2[] = {
  134174. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134175. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134176. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134177. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134178. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134179. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134180. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134181. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134182. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134183. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134184. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134185. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134186. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134187. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134188. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134189. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134190. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134191. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134192. 10,
  134193. };
  134194. static float _vq_quantthresh__44u4__p7_2[] = {
  134195. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134196. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134197. };
  134198. static long _vq_quantmap__44u4__p7_2[] = {
  134199. 15, 13, 11, 9, 7, 5, 3, 1,
  134200. 0, 2, 4, 6, 8, 10, 12, 14,
  134201. 16,
  134202. };
  134203. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134204. _vq_quantthresh__44u4__p7_2,
  134205. _vq_quantmap__44u4__p7_2,
  134206. 17,
  134207. 17
  134208. };
  134209. static static_codebook _44u4__p7_2 = {
  134210. 2, 289,
  134211. _vq_lengthlist__44u4__p7_2,
  134212. 1, -529530880, 1611661312, 5, 0,
  134213. _vq_quantlist__44u4__p7_2,
  134214. NULL,
  134215. &_vq_auxt__44u4__p7_2,
  134216. NULL,
  134217. 0
  134218. };
  134219. static long _huff_lengthlist__44u4__short[] = {
  134220. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134221. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134222. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134223. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134224. };
  134225. static static_codebook _huff_book__44u4__short = {
  134226. 2, 64,
  134227. _huff_lengthlist__44u4__short,
  134228. 0, 0, 0, 0, 0,
  134229. NULL,
  134230. NULL,
  134231. NULL,
  134232. NULL,
  134233. 0
  134234. };
  134235. static long _huff_lengthlist__44u5__long[] = {
  134236. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134237. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134238. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134239. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134240. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134241. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134242. 14, 8, 7, 8,
  134243. };
  134244. static static_codebook _huff_book__44u5__long = {
  134245. 2, 100,
  134246. _huff_lengthlist__44u5__long,
  134247. 0, 0, 0, 0, 0,
  134248. NULL,
  134249. NULL,
  134250. NULL,
  134251. NULL,
  134252. 0
  134253. };
  134254. static long _vq_quantlist__44u5__p1_0[] = {
  134255. 1,
  134256. 0,
  134257. 2,
  134258. };
  134259. static long _vq_lengthlist__44u5__p1_0[] = {
  134260. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134261. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134262. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134263. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134264. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134265. 12,
  134266. };
  134267. static float _vq_quantthresh__44u5__p1_0[] = {
  134268. -0.5, 0.5,
  134269. };
  134270. static long _vq_quantmap__44u5__p1_0[] = {
  134271. 1, 0, 2,
  134272. };
  134273. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134274. _vq_quantthresh__44u5__p1_0,
  134275. _vq_quantmap__44u5__p1_0,
  134276. 3,
  134277. 3
  134278. };
  134279. static static_codebook _44u5__p1_0 = {
  134280. 4, 81,
  134281. _vq_lengthlist__44u5__p1_0,
  134282. 1, -535822336, 1611661312, 2, 0,
  134283. _vq_quantlist__44u5__p1_0,
  134284. NULL,
  134285. &_vq_auxt__44u5__p1_0,
  134286. NULL,
  134287. 0
  134288. };
  134289. static long _vq_quantlist__44u5__p2_0[] = {
  134290. 1,
  134291. 0,
  134292. 2,
  134293. };
  134294. static long _vq_lengthlist__44u5__p2_0[] = {
  134295. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134296. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134297. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134298. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134299. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134300. 9,
  134301. };
  134302. static float _vq_quantthresh__44u5__p2_0[] = {
  134303. -0.5, 0.5,
  134304. };
  134305. static long _vq_quantmap__44u5__p2_0[] = {
  134306. 1, 0, 2,
  134307. };
  134308. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134309. _vq_quantthresh__44u5__p2_0,
  134310. _vq_quantmap__44u5__p2_0,
  134311. 3,
  134312. 3
  134313. };
  134314. static static_codebook _44u5__p2_0 = {
  134315. 4, 81,
  134316. _vq_lengthlist__44u5__p2_0,
  134317. 1, -535822336, 1611661312, 2, 0,
  134318. _vq_quantlist__44u5__p2_0,
  134319. NULL,
  134320. &_vq_auxt__44u5__p2_0,
  134321. NULL,
  134322. 0
  134323. };
  134324. static long _vq_quantlist__44u5__p3_0[] = {
  134325. 2,
  134326. 1,
  134327. 3,
  134328. 0,
  134329. 4,
  134330. };
  134331. static long _vq_lengthlist__44u5__p3_0[] = {
  134332. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134333. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134334. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134335. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134336. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134337. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134338. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134339. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134340. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134341. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134342. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134343. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134344. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134345. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134346. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134347. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134348. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134349. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134350. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134351. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134352. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134353. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134354. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134355. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134356. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134357. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134358. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134359. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134360. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134361. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134362. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134363. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134364. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134365. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134366. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134367. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134368. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134369. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134370. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134371. 0,
  134372. };
  134373. static float _vq_quantthresh__44u5__p3_0[] = {
  134374. -1.5, -0.5, 0.5, 1.5,
  134375. };
  134376. static long _vq_quantmap__44u5__p3_0[] = {
  134377. 3, 1, 0, 2, 4,
  134378. };
  134379. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134380. _vq_quantthresh__44u5__p3_0,
  134381. _vq_quantmap__44u5__p3_0,
  134382. 5,
  134383. 5
  134384. };
  134385. static static_codebook _44u5__p3_0 = {
  134386. 4, 625,
  134387. _vq_lengthlist__44u5__p3_0,
  134388. 1, -533725184, 1611661312, 3, 0,
  134389. _vq_quantlist__44u5__p3_0,
  134390. NULL,
  134391. &_vq_auxt__44u5__p3_0,
  134392. NULL,
  134393. 0
  134394. };
  134395. static long _vq_quantlist__44u5__p4_0[] = {
  134396. 2,
  134397. 1,
  134398. 3,
  134399. 0,
  134400. 4,
  134401. };
  134402. static long _vq_lengthlist__44u5__p4_0[] = {
  134403. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134404. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134405. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134406. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134407. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134408. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134409. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134410. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134411. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134412. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134413. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134414. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134415. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134416. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134417. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134418. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134419. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134420. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134421. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134422. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134423. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134424. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134425. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134426. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134427. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134428. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134429. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134430. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134431. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134432. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134433. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134434. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134435. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134436. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134437. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134438. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134439. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134440. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134441. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134442. 12,
  134443. };
  134444. static float _vq_quantthresh__44u5__p4_0[] = {
  134445. -1.5, -0.5, 0.5, 1.5,
  134446. };
  134447. static long _vq_quantmap__44u5__p4_0[] = {
  134448. 3, 1, 0, 2, 4,
  134449. };
  134450. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134451. _vq_quantthresh__44u5__p4_0,
  134452. _vq_quantmap__44u5__p4_0,
  134453. 5,
  134454. 5
  134455. };
  134456. static static_codebook _44u5__p4_0 = {
  134457. 4, 625,
  134458. _vq_lengthlist__44u5__p4_0,
  134459. 1, -533725184, 1611661312, 3, 0,
  134460. _vq_quantlist__44u5__p4_0,
  134461. NULL,
  134462. &_vq_auxt__44u5__p4_0,
  134463. NULL,
  134464. 0
  134465. };
  134466. static long _vq_quantlist__44u5__p5_0[] = {
  134467. 4,
  134468. 3,
  134469. 5,
  134470. 2,
  134471. 6,
  134472. 1,
  134473. 7,
  134474. 0,
  134475. 8,
  134476. };
  134477. static long _vq_lengthlist__44u5__p5_0[] = {
  134478. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134479. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134480. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134481. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134482. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134483. 14,
  134484. };
  134485. static float _vq_quantthresh__44u5__p5_0[] = {
  134486. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134487. };
  134488. static long _vq_quantmap__44u5__p5_0[] = {
  134489. 7, 5, 3, 1, 0, 2, 4, 6,
  134490. 8,
  134491. };
  134492. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134493. _vq_quantthresh__44u5__p5_0,
  134494. _vq_quantmap__44u5__p5_0,
  134495. 9,
  134496. 9
  134497. };
  134498. static static_codebook _44u5__p5_0 = {
  134499. 2, 81,
  134500. _vq_lengthlist__44u5__p5_0,
  134501. 1, -531628032, 1611661312, 4, 0,
  134502. _vq_quantlist__44u5__p5_0,
  134503. NULL,
  134504. &_vq_auxt__44u5__p5_0,
  134505. NULL,
  134506. 0
  134507. };
  134508. static long _vq_quantlist__44u5__p6_0[] = {
  134509. 4,
  134510. 3,
  134511. 5,
  134512. 2,
  134513. 6,
  134514. 1,
  134515. 7,
  134516. 0,
  134517. 8,
  134518. };
  134519. static long _vq_lengthlist__44u5__p6_0[] = {
  134520. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134521. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134522. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134523. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134524. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134525. 11,
  134526. };
  134527. static float _vq_quantthresh__44u5__p6_0[] = {
  134528. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134529. };
  134530. static long _vq_quantmap__44u5__p6_0[] = {
  134531. 7, 5, 3, 1, 0, 2, 4, 6,
  134532. 8,
  134533. };
  134534. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  134535. _vq_quantthresh__44u5__p6_0,
  134536. _vq_quantmap__44u5__p6_0,
  134537. 9,
  134538. 9
  134539. };
  134540. static static_codebook _44u5__p6_0 = {
  134541. 2, 81,
  134542. _vq_lengthlist__44u5__p6_0,
  134543. 1, -531628032, 1611661312, 4, 0,
  134544. _vq_quantlist__44u5__p6_0,
  134545. NULL,
  134546. &_vq_auxt__44u5__p6_0,
  134547. NULL,
  134548. 0
  134549. };
  134550. static long _vq_quantlist__44u5__p7_0[] = {
  134551. 1,
  134552. 0,
  134553. 2,
  134554. };
  134555. static long _vq_lengthlist__44u5__p7_0[] = {
  134556. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  134557. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  134558. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  134559. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  134560. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  134561. 12,
  134562. };
  134563. static float _vq_quantthresh__44u5__p7_0[] = {
  134564. -5.5, 5.5,
  134565. };
  134566. static long _vq_quantmap__44u5__p7_0[] = {
  134567. 1, 0, 2,
  134568. };
  134569. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  134570. _vq_quantthresh__44u5__p7_0,
  134571. _vq_quantmap__44u5__p7_0,
  134572. 3,
  134573. 3
  134574. };
  134575. static static_codebook _44u5__p7_0 = {
  134576. 4, 81,
  134577. _vq_lengthlist__44u5__p7_0,
  134578. 1, -529137664, 1618345984, 2, 0,
  134579. _vq_quantlist__44u5__p7_0,
  134580. NULL,
  134581. &_vq_auxt__44u5__p7_0,
  134582. NULL,
  134583. 0
  134584. };
  134585. static long _vq_quantlist__44u5__p7_1[] = {
  134586. 5,
  134587. 4,
  134588. 6,
  134589. 3,
  134590. 7,
  134591. 2,
  134592. 8,
  134593. 1,
  134594. 9,
  134595. 0,
  134596. 10,
  134597. };
  134598. static long _vq_lengthlist__44u5__p7_1[] = {
  134599. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  134600. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  134601. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  134602. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  134603. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  134604. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134605. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  134606. 9, 9, 9, 9, 9,10,10,10,10,
  134607. };
  134608. static float _vq_quantthresh__44u5__p7_1[] = {
  134609. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134610. 3.5, 4.5,
  134611. };
  134612. static long _vq_quantmap__44u5__p7_1[] = {
  134613. 9, 7, 5, 3, 1, 0, 2, 4,
  134614. 6, 8, 10,
  134615. };
  134616. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  134617. _vq_quantthresh__44u5__p7_1,
  134618. _vq_quantmap__44u5__p7_1,
  134619. 11,
  134620. 11
  134621. };
  134622. static static_codebook _44u5__p7_1 = {
  134623. 2, 121,
  134624. _vq_lengthlist__44u5__p7_1,
  134625. 1, -531365888, 1611661312, 4, 0,
  134626. _vq_quantlist__44u5__p7_1,
  134627. NULL,
  134628. &_vq_auxt__44u5__p7_1,
  134629. NULL,
  134630. 0
  134631. };
  134632. static long _vq_quantlist__44u5__p8_0[] = {
  134633. 5,
  134634. 4,
  134635. 6,
  134636. 3,
  134637. 7,
  134638. 2,
  134639. 8,
  134640. 1,
  134641. 9,
  134642. 0,
  134643. 10,
  134644. };
  134645. static long _vq_lengthlist__44u5__p8_0[] = {
  134646. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  134647. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  134648. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  134649. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  134650. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  134651. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  134652. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  134653. 12,13,13,14,14,14,14,15,15,
  134654. };
  134655. static float _vq_quantthresh__44u5__p8_0[] = {
  134656. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  134657. 38.5, 49.5,
  134658. };
  134659. static long _vq_quantmap__44u5__p8_0[] = {
  134660. 9, 7, 5, 3, 1, 0, 2, 4,
  134661. 6, 8, 10,
  134662. };
  134663. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  134664. _vq_quantthresh__44u5__p8_0,
  134665. _vq_quantmap__44u5__p8_0,
  134666. 11,
  134667. 11
  134668. };
  134669. static static_codebook _44u5__p8_0 = {
  134670. 2, 121,
  134671. _vq_lengthlist__44u5__p8_0,
  134672. 1, -524582912, 1618345984, 4, 0,
  134673. _vq_quantlist__44u5__p8_0,
  134674. NULL,
  134675. &_vq_auxt__44u5__p8_0,
  134676. NULL,
  134677. 0
  134678. };
  134679. static long _vq_quantlist__44u5__p8_1[] = {
  134680. 5,
  134681. 4,
  134682. 6,
  134683. 3,
  134684. 7,
  134685. 2,
  134686. 8,
  134687. 1,
  134688. 9,
  134689. 0,
  134690. 10,
  134691. };
  134692. static long _vq_lengthlist__44u5__p8_1[] = {
  134693. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  134694. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  134695. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  134696. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  134697. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  134698. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  134699. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134700. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134701. };
  134702. static float _vq_quantthresh__44u5__p8_1[] = {
  134703. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134704. 3.5, 4.5,
  134705. };
  134706. static long _vq_quantmap__44u5__p8_1[] = {
  134707. 9, 7, 5, 3, 1, 0, 2, 4,
  134708. 6, 8, 10,
  134709. };
  134710. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  134711. _vq_quantthresh__44u5__p8_1,
  134712. _vq_quantmap__44u5__p8_1,
  134713. 11,
  134714. 11
  134715. };
  134716. static static_codebook _44u5__p8_1 = {
  134717. 2, 121,
  134718. _vq_lengthlist__44u5__p8_1,
  134719. 1, -531365888, 1611661312, 4, 0,
  134720. _vq_quantlist__44u5__p8_1,
  134721. NULL,
  134722. &_vq_auxt__44u5__p8_1,
  134723. NULL,
  134724. 0
  134725. };
  134726. static long _vq_quantlist__44u5__p9_0[] = {
  134727. 6,
  134728. 5,
  134729. 7,
  134730. 4,
  134731. 8,
  134732. 3,
  134733. 9,
  134734. 2,
  134735. 10,
  134736. 1,
  134737. 11,
  134738. 0,
  134739. 12,
  134740. };
  134741. static long _vq_lengthlist__44u5__p9_0[] = {
  134742. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  134743. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  134744. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  134745. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  134746. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134747. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134748. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134749. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134750. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  134751. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134752. 12,12,12,12,12,12,12,12,12,
  134753. };
  134754. static float _vq_quantthresh__44u5__p9_0[] = {
  134755. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134756. 637.5, 892.5, 1147.5, 1402.5,
  134757. };
  134758. static long _vq_quantmap__44u5__p9_0[] = {
  134759. 11, 9, 7, 5, 3, 1, 0, 2,
  134760. 4, 6, 8, 10, 12,
  134761. };
  134762. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  134763. _vq_quantthresh__44u5__p9_0,
  134764. _vq_quantmap__44u5__p9_0,
  134765. 13,
  134766. 13
  134767. };
  134768. static static_codebook _44u5__p9_0 = {
  134769. 2, 169,
  134770. _vq_lengthlist__44u5__p9_0,
  134771. 1, -514332672, 1627381760, 4, 0,
  134772. _vq_quantlist__44u5__p9_0,
  134773. NULL,
  134774. &_vq_auxt__44u5__p9_0,
  134775. NULL,
  134776. 0
  134777. };
  134778. static long _vq_quantlist__44u5__p9_1[] = {
  134779. 7,
  134780. 6,
  134781. 8,
  134782. 5,
  134783. 9,
  134784. 4,
  134785. 10,
  134786. 3,
  134787. 11,
  134788. 2,
  134789. 12,
  134790. 1,
  134791. 13,
  134792. 0,
  134793. 14,
  134794. };
  134795. static long _vq_lengthlist__44u5__p9_1[] = {
  134796. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  134797. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  134798. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  134799. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  134800. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  134801. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  134802. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  134803. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  134804. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  134805. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  134806. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  134807. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  134808. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  134809. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  134810. 14,
  134811. };
  134812. static float _vq_quantthresh__44u5__p9_1[] = {
  134813. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134814. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134815. };
  134816. static long _vq_quantmap__44u5__p9_1[] = {
  134817. 13, 11, 9, 7, 5, 3, 1, 0,
  134818. 2, 4, 6, 8, 10, 12, 14,
  134819. };
  134820. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  134821. _vq_quantthresh__44u5__p9_1,
  134822. _vq_quantmap__44u5__p9_1,
  134823. 15,
  134824. 15
  134825. };
  134826. static static_codebook _44u5__p9_1 = {
  134827. 2, 225,
  134828. _vq_lengthlist__44u5__p9_1,
  134829. 1, -522338304, 1620115456, 4, 0,
  134830. _vq_quantlist__44u5__p9_1,
  134831. NULL,
  134832. &_vq_auxt__44u5__p9_1,
  134833. NULL,
  134834. 0
  134835. };
  134836. static long _vq_quantlist__44u5__p9_2[] = {
  134837. 8,
  134838. 7,
  134839. 9,
  134840. 6,
  134841. 10,
  134842. 5,
  134843. 11,
  134844. 4,
  134845. 12,
  134846. 3,
  134847. 13,
  134848. 2,
  134849. 14,
  134850. 1,
  134851. 15,
  134852. 0,
  134853. 16,
  134854. };
  134855. static long _vq_lengthlist__44u5__p9_2[] = {
  134856. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134857. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134858. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134859. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134860. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134861. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  134862. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134863. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  134864. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134865. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  134866. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  134867. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  134868. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134869. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134870. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134871. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134872. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  134873. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  134874. 10,
  134875. };
  134876. static float _vq_quantthresh__44u5__p9_2[] = {
  134877. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134878. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134879. };
  134880. static long _vq_quantmap__44u5__p9_2[] = {
  134881. 15, 13, 11, 9, 7, 5, 3, 1,
  134882. 0, 2, 4, 6, 8, 10, 12, 14,
  134883. 16,
  134884. };
  134885. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  134886. _vq_quantthresh__44u5__p9_2,
  134887. _vq_quantmap__44u5__p9_2,
  134888. 17,
  134889. 17
  134890. };
  134891. static static_codebook _44u5__p9_2 = {
  134892. 2, 289,
  134893. _vq_lengthlist__44u5__p9_2,
  134894. 1, -529530880, 1611661312, 5, 0,
  134895. _vq_quantlist__44u5__p9_2,
  134896. NULL,
  134897. &_vq_auxt__44u5__p9_2,
  134898. NULL,
  134899. 0
  134900. };
  134901. static long _huff_lengthlist__44u5__short[] = {
  134902. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  134903. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  134904. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  134905. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  134906. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  134907. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  134908. 6, 8,15,17,
  134909. };
  134910. static static_codebook _huff_book__44u5__short = {
  134911. 2, 100,
  134912. _huff_lengthlist__44u5__short,
  134913. 0, 0, 0, 0, 0,
  134914. NULL,
  134915. NULL,
  134916. NULL,
  134917. NULL,
  134918. 0
  134919. };
  134920. static long _huff_lengthlist__44u6__long[] = {
  134921. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  134922. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  134923. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  134924. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  134925. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  134926. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  134927. 13, 8, 7, 7,
  134928. };
  134929. static static_codebook _huff_book__44u6__long = {
  134930. 2, 100,
  134931. _huff_lengthlist__44u6__long,
  134932. 0, 0, 0, 0, 0,
  134933. NULL,
  134934. NULL,
  134935. NULL,
  134936. NULL,
  134937. 0
  134938. };
  134939. static long _vq_quantlist__44u6__p1_0[] = {
  134940. 1,
  134941. 0,
  134942. 2,
  134943. };
  134944. static long _vq_lengthlist__44u6__p1_0[] = {
  134945. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134946. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134947. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134948. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  134949. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134950. 12,
  134951. };
  134952. static float _vq_quantthresh__44u6__p1_0[] = {
  134953. -0.5, 0.5,
  134954. };
  134955. static long _vq_quantmap__44u6__p1_0[] = {
  134956. 1, 0, 2,
  134957. };
  134958. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  134959. _vq_quantthresh__44u6__p1_0,
  134960. _vq_quantmap__44u6__p1_0,
  134961. 3,
  134962. 3
  134963. };
  134964. static static_codebook _44u6__p1_0 = {
  134965. 4, 81,
  134966. _vq_lengthlist__44u6__p1_0,
  134967. 1, -535822336, 1611661312, 2, 0,
  134968. _vq_quantlist__44u6__p1_0,
  134969. NULL,
  134970. &_vq_auxt__44u6__p1_0,
  134971. NULL,
  134972. 0
  134973. };
  134974. static long _vq_quantlist__44u6__p2_0[] = {
  134975. 1,
  134976. 0,
  134977. 2,
  134978. };
  134979. static long _vq_lengthlist__44u6__p2_0[] = {
  134980. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134981. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134982. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  134983. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134984. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134985. 9,
  134986. };
  134987. static float _vq_quantthresh__44u6__p2_0[] = {
  134988. -0.5, 0.5,
  134989. };
  134990. static long _vq_quantmap__44u6__p2_0[] = {
  134991. 1, 0, 2,
  134992. };
  134993. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  134994. _vq_quantthresh__44u6__p2_0,
  134995. _vq_quantmap__44u6__p2_0,
  134996. 3,
  134997. 3
  134998. };
  134999. static static_codebook _44u6__p2_0 = {
  135000. 4, 81,
  135001. _vq_lengthlist__44u6__p2_0,
  135002. 1, -535822336, 1611661312, 2, 0,
  135003. _vq_quantlist__44u6__p2_0,
  135004. NULL,
  135005. &_vq_auxt__44u6__p2_0,
  135006. NULL,
  135007. 0
  135008. };
  135009. static long _vq_quantlist__44u6__p3_0[] = {
  135010. 2,
  135011. 1,
  135012. 3,
  135013. 0,
  135014. 4,
  135015. };
  135016. static long _vq_lengthlist__44u6__p3_0[] = {
  135017. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135018. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135019. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135020. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135021. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135022. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135023. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135024. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135025. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135026. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135027. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135028. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135029. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135030. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135031. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135032. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135033. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135034. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135035. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135036. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135037. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135038. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135039. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135040. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135041. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135042. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135043. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135044. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135045. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135046. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135047. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135048. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135049. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135050. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135051. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135052. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135053. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135054. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135055. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135056. 19,
  135057. };
  135058. static float _vq_quantthresh__44u6__p3_0[] = {
  135059. -1.5, -0.5, 0.5, 1.5,
  135060. };
  135061. static long _vq_quantmap__44u6__p3_0[] = {
  135062. 3, 1, 0, 2, 4,
  135063. };
  135064. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135065. _vq_quantthresh__44u6__p3_0,
  135066. _vq_quantmap__44u6__p3_0,
  135067. 5,
  135068. 5
  135069. };
  135070. static static_codebook _44u6__p3_0 = {
  135071. 4, 625,
  135072. _vq_lengthlist__44u6__p3_0,
  135073. 1, -533725184, 1611661312, 3, 0,
  135074. _vq_quantlist__44u6__p3_0,
  135075. NULL,
  135076. &_vq_auxt__44u6__p3_0,
  135077. NULL,
  135078. 0
  135079. };
  135080. static long _vq_quantlist__44u6__p4_0[] = {
  135081. 2,
  135082. 1,
  135083. 3,
  135084. 0,
  135085. 4,
  135086. };
  135087. static long _vq_lengthlist__44u6__p4_0[] = {
  135088. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135089. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135090. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135091. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135092. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135093. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135094. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135095. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135096. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135097. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135098. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135099. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135100. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135101. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135102. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135103. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135104. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135105. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135106. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135107. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135108. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135109. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135110. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135111. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135112. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135113. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135114. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135115. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135116. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135117. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135118. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135119. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135120. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135121. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135122. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135123. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135124. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135125. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135126. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135127. 13,
  135128. };
  135129. static float _vq_quantthresh__44u6__p4_0[] = {
  135130. -1.5, -0.5, 0.5, 1.5,
  135131. };
  135132. static long _vq_quantmap__44u6__p4_0[] = {
  135133. 3, 1, 0, 2, 4,
  135134. };
  135135. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135136. _vq_quantthresh__44u6__p4_0,
  135137. _vq_quantmap__44u6__p4_0,
  135138. 5,
  135139. 5
  135140. };
  135141. static static_codebook _44u6__p4_0 = {
  135142. 4, 625,
  135143. _vq_lengthlist__44u6__p4_0,
  135144. 1, -533725184, 1611661312, 3, 0,
  135145. _vq_quantlist__44u6__p4_0,
  135146. NULL,
  135147. &_vq_auxt__44u6__p4_0,
  135148. NULL,
  135149. 0
  135150. };
  135151. static long _vq_quantlist__44u6__p5_0[] = {
  135152. 4,
  135153. 3,
  135154. 5,
  135155. 2,
  135156. 6,
  135157. 1,
  135158. 7,
  135159. 0,
  135160. 8,
  135161. };
  135162. static long _vq_lengthlist__44u6__p5_0[] = {
  135163. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135164. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135165. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135166. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135167. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135168. 14,
  135169. };
  135170. static float _vq_quantthresh__44u6__p5_0[] = {
  135171. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135172. };
  135173. static long _vq_quantmap__44u6__p5_0[] = {
  135174. 7, 5, 3, 1, 0, 2, 4, 6,
  135175. 8,
  135176. };
  135177. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135178. _vq_quantthresh__44u6__p5_0,
  135179. _vq_quantmap__44u6__p5_0,
  135180. 9,
  135181. 9
  135182. };
  135183. static static_codebook _44u6__p5_0 = {
  135184. 2, 81,
  135185. _vq_lengthlist__44u6__p5_0,
  135186. 1, -531628032, 1611661312, 4, 0,
  135187. _vq_quantlist__44u6__p5_0,
  135188. NULL,
  135189. &_vq_auxt__44u6__p5_0,
  135190. NULL,
  135191. 0
  135192. };
  135193. static long _vq_quantlist__44u6__p6_0[] = {
  135194. 4,
  135195. 3,
  135196. 5,
  135197. 2,
  135198. 6,
  135199. 1,
  135200. 7,
  135201. 0,
  135202. 8,
  135203. };
  135204. static long _vq_lengthlist__44u6__p6_0[] = {
  135205. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135206. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135207. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135208. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135209. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135210. 12,
  135211. };
  135212. static float _vq_quantthresh__44u6__p6_0[] = {
  135213. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135214. };
  135215. static long _vq_quantmap__44u6__p6_0[] = {
  135216. 7, 5, 3, 1, 0, 2, 4, 6,
  135217. 8,
  135218. };
  135219. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135220. _vq_quantthresh__44u6__p6_0,
  135221. _vq_quantmap__44u6__p6_0,
  135222. 9,
  135223. 9
  135224. };
  135225. static static_codebook _44u6__p6_0 = {
  135226. 2, 81,
  135227. _vq_lengthlist__44u6__p6_0,
  135228. 1, -531628032, 1611661312, 4, 0,
  135229. _vq_quantlist__44u6__p6_0,
  135230. NULL,
  135231. &_vq_auxt__44u6__p6_0,
  135232. NULL,
  135233. 0
  135234. };
  135235. static long _vq_quantlist__44u6__p7_0[] = {
  135236. 1,
  135237. 0,
  135238. 2,
  135239. };
  135240. static long _vq_lengthlist__44u6__p7_0[] = {
  135241. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135242. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135243. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135244. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135245. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135246. 10,
  135247. };
  135248. static float _vq_quantthresh__44u6__p7_0[] = {
  135249. -5.5, 5.5,
  135250. };
  135251. static long _vq_quantmap__44u6__p7_0[] = {
  135252. 1, 0, 2,
  135253. };
  135254. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135255. _vq_quantthresh__44u6__p7_0,
  135256. _vq_quantmap__44u6__p7_0,
  135257. 3,
  135258. 3
  135259. };
  135260. static static_codebook _44u6__p7_0 = {
  135261. 4, 81,
  135262. _vq_lengthlist__44u6__p7_0,
  135263. 1, -529137664, 1618345984, 2, 0,
  135264. _vq_quantlist__44u6__p7_0,
  135265. NULL,
  135266. &_vq_auxt__44u6__p7_0,
  135267. NULL,
  135268. 0
  135269. };
  135270. static long _vq_quantlist__44u6__p7_1[] = {
  135271. 5,
  135272. 4,
  135273. 6,
  135274. 3,
  135275. 7,
  135276. 2,
  135277. 8,
  135278. 1,
  135279. 9,
  135280. 0,
  135281. 10,
  135282. };
  135283. static long _vq_lengthlist__44u6__p7_1[] = {
  135284. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135285. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135286. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135287. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135288. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135289. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135290. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135291. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135292. };
  135293. static float _vq_quantthresh__44u6__p7_1[] = {
  135294. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135295. 3.5, 4.5,
  135296. };
  135297. static long _vq_quantmap__44u6__p7_1[] = {
  135298. 9, 7, 5, 3, 1, 0, 2, 4,
  135299. 6, 8, 10,
  135300. };
  135301. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135302. _vq_quantthresh__44u6__p7_1,
  135303. _vq_quantmap__44u6__p7_1,
  135304. 11,
  135305. 11
  135306. };
  135307. static static_codebook _44u6__p7_1 = {
  135308. 2, 121,
  135309. _vq_lengthlist__44u6__p7_1,
  135310. 1, -531365888, 1611661312, 4, 0,
  135311. _vq_quantlist__44u6__p7_1,
  135312. NULL,
  135313. &_vq_auxt__44u6__p7_1,
  135314. NULL,
  135315. 0
  135316. };
  135317. static long _vq_quantlist__44u6__p8_0[] = {
  135318. 5,
  135319. 4,
  135320. 6,
  135321. 3,
  135322. 7,
  135323. 2,
  135324. 8,
  135325. 1,
  135326. 9,
  135327. 0,
  135328. 10,
  135329. };
  135330. static long _vq_lengthlist__44u6__p8_0[] = {
  135331. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135332. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135333. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135334. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135335. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135336. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135337. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135338. 12,13,13,14,14,14,15,15,15,
  135339. };
  135340. static float _vq_quantthresh__44u6__p8_0[] = {
  135341. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135342. 38.5, 49.5,
  135343. };
  135344. static long _vq_quantmap__44u6__p8_0[] = {
  135345. 9, 7, 5, 3, 1, 0, 2, 4,
  135346. 6, 8, 10,
  135347. };
  135348. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135349. _vq_quantthresh__44u6__p8_0,
  135350. _vq_quantmap__44u6__p8_0,
  135351. 11,
  135352. 11
  135353. };
  135354. static static_codebook _44u6__p8_0 = {
  135355. 2, 121,
  135356. _vq_lengthlist__44u6__p8_0,
  135357. 1, -524582912, 1618345984, 4, 0,
  135358. _vq_quantlist__44u6__p8_0,
  135359. NULL,
  135360. &_vq_auxt__44u6__p8_0,
  135361. NULL,
  135362. 0
  135363. };
  135364. static long _vq_quantlist__44u6__p8_1[] = {
  135365. 5,
  135366. 4,
  135367. 6,
  135368. 3,
  135369. 7,
  135370. 2,
  135371. 8,
  135372. 1,
  135373. 9,
  135374. 0,
  135375. 10,
  135376. };
  135377. static long _vq_lengthlist__44u6__p8_1[] = {
  135378. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135379. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135380. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135381. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135382. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135383. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135384. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135385. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135386. };
  135387. static float _vq_quantthresh__44u6__p8_1[] = {
  135388. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135389. 3.5, 4.5,
  135390. };
  135391. static long _vq_quantmap__44u6__p8_1[] = {
  135392. 9, 7, 5, 3, 1, 0, 2, 4,
  135393. 6, 8, 10,
  135394. };
  135395. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135396. _vq_quantthresh__44u6__p8_1,
  135397. _vq_quantmap__44u6__p8_1,
  135398. 11,
  135399. 11
  135400. };
  135401. static static_codebook _44u6__p8_1 = {
  135402. 2, 121,
  135403. _vq_lengthlist__44u6__p8_1,
  135404. 1, -531365888, 1611661312, 4, 0,
  135405. _vq_quantlist__44u6__p8_1,
  135406. NULL,
  135407. &_vq_auxt__44u6__p8_1,
  135408. NULL,
  135409. 0
  135410. };
  135411. static long _vq_quantlist__44u6__p9_0[] = {
  135412. 7,
  135413. 6,
  135414. 8,
  135415. 5,
  135416. 9,
  135417. 4,
  135418. 10,
  135419. 3,
  135420. 11,
  135421. 2,
  135422. 12,
  135423. 1,
  135424. 13,
  135425. 0,
  135426. 14,
  135427. };
  135428. static long _vq_lengthlist__44u6__p9_0[] = {
  135429. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135430. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135431. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135432. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135433. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135434. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135435. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135436. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135437. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135438. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135439. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135440. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135441. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135442. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135443. 14,
  135444. };
  135445. static float _vq_quantthresh__44u6__p9_0[] = {
  135446. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135447. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135448. };
  135449. static long _vq_quantmap__44u6__p9_0[] = {
  135450. 13, 11, 9, 7, 5, 3, 1, 0,
  135451. 2, 4, 6, 8, 10, 12, 14,
  135452. };
  135453. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135454. _vq_quantthresh__44u6__p9_0,
  135455. _vq_quantmap__44u6__p9_0,
  135456. 15,
  135457. 15
  135458. };
  135459. static static_codebook _44u6__p9_0 = {
  135460. 2, 225,
  135461. _vq_lengthlist__44u6__p9_0,
  135462. 1, -514071552, 1627381760, 4, 0,
  135463. _vq_quantlist__44u6__p9_0,
  135464. NULL,
  135465. &_vq_auxt__44u6__p9_0,
  135466. NULL,
  135467. 0
  135468. };
  135469. static long _vq_quantlist__44u6__p9_1[] = {
  135470. 7,
  135471. 6,
  135472. 8,
  135473. 5,
  135474. 9,
  135475. 4,
  135476. 10,
  135477. 3,
  135478. 11,
  135479. 2,
  135480. 12,
  135481. 1,
  135482. 13,
  135483. 0,
  135484. 14,
  135485. };
  135486. static long _vq_lengthlist__44u6__p9_1[] = {
  135487. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135488. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135489. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135490. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135491. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135492. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135493. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135494. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135495. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135496. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135497. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135498. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135499. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135500. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135501. 13,
  135502. };
  135503. static float _vq_quantthresh__44u6__p9_1[] = {
  135504. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135505. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135506. };
  135507. static long _vq_quantmap__44u6__p9_1[] = {
  135508. 13, 11, 9, 7, 5, 3, 1, 0,
  135509. 2, 4, 6, 8, 10, 12, 14,
  135510. };
  135511. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135512. _vq_quantthresh__44u6__p9_1,
  135513. _vq_quantmap__44u6__p9_1,
  135514. 15,
  135515. 15
  135516. };
  135517. static static_codebook _44u6__p9_1 = {
  135518. 2, 225,
  135519. _vq_lengthlist__44u6__p9_1,
  135520. 1, -522338304, 1620115456, 4, 0,
  135521. _vq_quantlist__44u6__p9_1,
  135522. NULL,
  135523. &_vq_auxt__44u6__p9_1,
  135524. NULL,
  135525. 0
  135526. };
  135527. static long _vq_quantlist__44u6__p9_2[] = {
  135528. 8,
  135529. 7,
  135530. 9,
  135531. 6,
  135532. 10,
  135533. 5,
  135534. 11,
  135535. 4,
  135536. 12,
  135537. 3,
  135538. 13,
  135539. 2,
  135540. 14,
  135541. 1,
  135542. 15,
  135543. 0,
  135544. 16,
  135545. };
  135546. static long _vq_lengthlist__44u6__p9_2[] = {
  135547. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  135548. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  135549. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  135550. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135551. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135552. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135553. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135554. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135555. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135556. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  135557. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  135558. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135559. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  135560. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  135561. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  135562. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  135563. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  135564. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  135565. 10,
  135566. };
  135567. static float _vq_quantthresh__44u6__p9_2[] = {
  135568. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135569. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135570. };
  135571. static long _vq_quantmap__44u6__p9_2[] = {
  135572. 15, 13, 11, 9, 7, 5, 3, 1,
  135573. 0, 2, 4, 6, 8, 10, 12, 14,
  135574. 16,
  135575. };
  135576. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  135577. _vq_quantthresh__44u6__p9_2,
  135578. _vq_quantmap__44u6__p9_2,
  135579. 17,
  135580. 17
  135581. };
  135582. static static_codebook _44u6__p9_2 = {
  135583. 2, 289,
  135584. _vq_lengthlist__44u6__p9_2,
  135585. 1, -529530880, 1611661312, 5, 0,
  135586. _vq_quantlist__44u6__p9_2,
  135587. NULL,
  135588. &_vq_auxt__44u6__p9_2,
  135589. NULL,
  135590. 0
  135591. };
  135592. static long _huff_lengthlist__44u6__short[] = {
  135593. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  135594. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  135595. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  135596. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  135597. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  135598. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  135599. 7, 6, 9,16,
  135600. };
  135601. static static_codebook _huff_book__44u6__short = {
  135602. 2, 100,
  135603. _huff_lengthlist__44u6__short,
  135604. 0, 0, 0, 0, 0,
  135605. NULL,
  135606. NULL,
  135607. NULL,
  135608. NULL,
  135609. 0
  135610. };
  135611. static long _huff_lengthlist__44u7__long[] = {
  135612. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  135613. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  135614. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  135615. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  135616. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  135617. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  135618. 12, 8, 6, 7,
  135619. };
  135620. static static_codebook _huff_book__44u7__long = {
  135621. 2, 100,
  135622. _huff_lengthlist__44u7__long,
  135623. 0, 0, 0, 0, 0,
  135624. NULL,
  135625. NULL,
  135626. NULL,
  135627. NULL,
  135628. 0
  135629. };
  135630. static long _vq_quantlist__44u7__p1_0[] = {
  135631. 1,
  135632. 0,
  135633. 2,
  135634. };
  135635. static long _vq_lengthlist__44u7__p1_0[] = {
  135636. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135637. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  135638. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135639. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  135640. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  135641. 12,
  135642. };
  135643. static float _vq_quantthresh__44u7__p1_0[] = {
  135644. -0.5, 0.5,
  135645. };
  135646. static long _vq_quantmap__44u7__p1_0[] = {
  135647. 1, 0, 2,
  135648. };
  135649. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  135650. _vq_quantthresh__44u7__p1_0,
  135651. _vq_quantmap__44u7__p1_0,
  135652. 3,
  135653. 3
  135654. };
  135655. static static_codebook _44u7__p1_0 = {
  135656. 4, 81,
  135657. _vq_lengthlist__44u7__p1_0,
  135658. 1, -535822336, 1611661312, 2, 0,
  135659. _vq_quantlist__44u7__p1_0,
  135660. NULL,
  135661. &_vq_auxt__44u7__p1_0,
  135662. NULL,
  135663. 0
  135664. };
  135665. static long _vq_quantlist__44u7__p2_0[] = {
  135666. 1,
  135667. 0,
  135668. 2,
  135669. };
  135670. static long _vq_lengthlist__44u7__p2_0[] = {
  135671. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135672. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135673. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  135674. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135675. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135676. 9,
  135677. };
  135678. static float _vq_quantthresh__44u7__p2_0[] = {
  135679. -0.5, 0.5,
  135680. };
  135681. static long _vq_quantmap__44u7__p2_0[] = {
  135682. 1, 0, 2,
  135683. };
  135684. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  135685. _vq_quantthresh__44u7__p2_0,
  135686. _vq_quantmap__44u7__p2_0,
  135687. 3,
  135688. 3
  135689. };
  135690. static static_codebook _44u7__p2_0 = {
  135691. 4, 81,
  135692. _vq_lengthlist__44u7__p2_0,
  135693. 1, -535822336, 1611661312, 2, 0,
  135694. _vq_quantlist__44u7__p2_0,
  135695. NULL,
  135696. &_vq_auxt__44u7__p2_0,
  135697. NULL,
  135698. 0
  135699. };
  135700. static long _vq_quantlist__44u7__p3_0[] = {
  135701. 2,
  135702. 1,
  135703. 3,
  135704. 0,
  135705. 4,
  135706. };
  135707. static long _vq_lengthlist__44u7__p3_0[] = {
  135708. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135709. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135710. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135711. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  135712. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  135713. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  135714. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  135715. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  135716. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  135717. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  135718. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  135719. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  135720. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  135721. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  135722. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  135723. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  135724. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  135725. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135726. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  135727. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  135728. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  135729. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  135730. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  135731. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  135732. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  135733. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  135734. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  135735. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  135736. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  135737. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  135738. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  135739. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  135740. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  135741. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  135742. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  135743. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  135744. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  135745. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  135746. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  135747. 0,
  135748. };
  135749. static float _vq_quantthresh__44u7__p3_0[] = {
  135750. -1.5, -0.5, 0.5, 1.5,
  135751. };
  135752. static long _vq_quantmap__44u7__p3_0[] = {
  135753. 3, 1, 0, 2, 4,
  135754. };
  135755. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  135756. _vq_quantthresh__44u7__p3_0,
  135757. _vq_quantmap__44u7__p3_0,
  135758. 5,
  135759. 5
  135760. };
  135761. static static_codebook _44u7__p3_0 = {
  135762. 4, 625,
  135763. _vq_lengthlist__44u7__p3_0,
  135764. 1, -533725184, 1611661312, 3, 0,
  135765. _vq_quantlist__44u7__p3_0,
  135766. NULL,
  135767. &_vq_auxt__44u7__p3_0,
  135768. NULL,
  135769. 0
  135770. };
  135771. static long _vq_quantlist__44u7__p4_0[] = {
  135772. 2,
  135773. 1,
  135774. 3,
  135775. 0,
  135776. 4,
  135777. };
  135778. static long _vq_lengthlist__44u7__p4_0[] = {
  135779. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135780. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  135781. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  135782. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  135783. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135784. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  135785. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  135786. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  135787. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135788. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135789. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  135790. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135791. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135792. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  135793. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  135794. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135795. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  135796. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135797. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  135798. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  135799. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135800. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135801. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  135802. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135803. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  135804. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  135805. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135806. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  135807. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  135808. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  135809. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  135810. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135811. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  135812. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135813. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  135814. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135815. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  135816. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  135817. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  135818. 14,
  135819. };
  135820. static float _vq_quantthresh__44u7__p4_0[] = {
  135821. -1.5, -0.5, 0.5, 1.5,
  135822. };
  135823. static long _vq_quantmap__44u7__p4_0[] = {
  135824. 3, 1, 0, 2, 4,
  135825. };
  135826. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  135827. _vq_quantthresh__44u7__p4_0,
  135828. _vq_quantmap__44u7__p4_0,
  135829. 5,
  135830. 5
  135831. };
  135832. static static_codebook _44u7__p4_0 = {
  135833. 4, 625,
  135834. _vq_lengthlist__44u7__p4_0,
  135835. 1, -533725184, 1611661312, 3, 0,
  135836. _vq_quantlist__44u7__p4_0,
  135837. NULL,
  135838. &_vq_auxt__44u7__p4_0,
  135839. NULL,
  135840. 0
  135841. };
  135842. static long _vq_quantlist__44u7__p5_0[] = {
  135843. 4,
  135844. 3,
  135845. 5,
  135846. 2,
  135847. 6,
  135848. 1,
  135849. 7,
  135850. 0,
  135851. 8,
  135852. };
  135853. static long _vq_lengthlist__44u7__p5_0[] = {
  135854. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135855. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  135856. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  135857. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  135858. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  135859. 14,
  135860. };
  135861. static float _vq_quantthresh__44u7__p5_0[] = {
  135862. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135863. };
  135864. static long _vq_quantmap__44u7__p5_0[] = {
  135865. 7, 5, 3, 1, 0, 2, 4, 6,
  135866. 8,
  135867. };
  135868. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  135869. _vq_quantthresh__44u7__p5_0,
  135870. _vq_quantmap__44u7__p5_0,
  135871. 9,
  135872. 9
  135873. };
  135874. static static_codebook _44u7__p5_0 = {
  135875. 2, 81,
  135876. _vq_lengthlist__44u7__p5_0,
  135877. 1, -531628032, 1611661312, 4, 0,
  135878. _vq_quantlist__44u7__p5_0,
  135879. NULL,
  135880. &_vq_auxt__44u7__p5_0,
  135881. NULL,
  135882. 0
  135883. };
  135884. static long _vq_quantlist__44u7__p6_0[] = {
  135885. 4,
  135886. 3,
  135887. 5,
  135888. 2,
  135889. 6,
  135890. 1,
  135891. 7,
  135892. 0,
  135893. 8,
  135894. };
  135895. static long _vq_lengthlist__44u7__p6_0[] = {
  135896. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  135897. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  135898. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135899. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  135900. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  135901. 12,
  135902. };
  135903. static float _vq_quantthresh__44u7__p6_0[] = {
  135904. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135905. };
  135906. static long _vq_quantmap__44u7__p6_0[] = {
  135907. 7, 5, 3, 1, 0, 2, 4, 6,
  135908. 8,
  135909. };
  135910. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  135911. _vq_quantthresh__44u7__p6_0,
  135912. _vq_quantmap__44u7__p6_0,
  135913. 9,
  135914. 9
  135915. };
  135916. static static_codebook _44u7__p6_0 = {
  135917. 2, 81,
  135918. _vq_lengthlist__44u7__p6_0,
  135919. 1, -531628032, 1611661312, 4, 0,
  135920. _vq_quantlist__44u7__p6_0,
  135921. NULL,
  135922. &_vq_auxt__44u7__p6_0,
  135923. NULL,
  135924. 0
  135925. };
  135926. static long _vq_quantlist__44u7__p7_0[] = {
  135927. 1,
  135928. 0,
  135929. 2,
  135930. };
  135931. static long _vq_lengthlist__44u7__p7_0[] = {
  135932. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  135933. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  135934. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  135935. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  135936. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  135937. 10,
  135938. };
  135939. static float _vq_quantthresh__44u7__p7_0[] = {
  135940. -5.5, 5.5,
  135941. };
  135942. static long _vq_quantmap__44u7__p7_0[] = {
  135943. 1, 0, 2,
  135944. };
  135945. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  135946. _vq_quantthresh__44u7__p7_0,
  135947. _vq_quantmap__44u7__p7_0,
  135948. 3,
  135949. 3
  135950. };
  135951. static static_codebook _44u7__p7_0 = {
  135952. 4, 81,
  135953. _vq_lengthlist__44u7__p7_0,
  135954. 1, -529137664, 1618345984, 2, 0,
  135955. _vq_quantlist__44u7__p7_0,
  135956. NULL,
  135957. &_vq_auxt__44u7__p7_0,
  135958. NULL,
  135959. 0
  135960. };
  135961. static long _vq_quantlist__44u7__p7_1[] = {
  135962. 5,
  135963. 4,
  135964. 6,
  135965. 3,
  135966. 7,
  135967. 2,
  135968. 8,
  135969. 1,
  135970. 9,
  135971. 0,
  135972. 10,
  135973. };
  135974. static long _vq_lengthlist__44u7__p7_1[] = {
  135975. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  135976. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  135977. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  135978. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  135979. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  135980. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135981. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  135982. 8, 9, 9, 9, 9, 9,10,10,10,
  135983. };
  135984. static float _vq_quantthresh__44u7__p7_1[] = {
  135985. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135986. 3.5, 4.5,
  135987. };
  135988. static long _vq_quantmap__44u7__p7_1[] = {
  135989. 9, 7, 5, 3, 1, 0, 2, 4,
  135990. 6, 8, 10,
  135991. };
  135992. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  135993. _vq_quantthresh__44u7__p7_1,
  135994. _vq_quantmap__44u7__p7_1,
  135995. 11,
  135996. 11
  135997. };
  135998. static static_codebook _44u7__p7_1 = {
  135999. 2, 121,
  136000. _vq_lengthlist__44u7__p7_1,
  136001. 1, -531365888, 1611661312, 4, 0,
  136002. _vq_quantlist__44u7__p7_1,
  136003. NULL,
  136004. &_vq_auxt__44u7__p7_1,
  136005. NULL,
  136006. 0
  136007. };
  136008. static long _vq_quantlist__44u7__p8_0[] = {
  136009. 5,
  136010. 4,
  136011. 6,
  136012. 3,
  136013. 7,
  136014. 2,
  136015. 8,
  136016. 1,
  136017. 9,
  136018. 0,
  136019. 10,
  136020. };
  136021. static long _vq_lengthlist__44u7__p8_0[] = {
  136022. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136023. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136024. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136025. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136026. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136027. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136028. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136029. 12,13,13,14,14,15,15,15,16,
  136030. };
  136031. static float _vq_quantthresh__44u7__p8_0[] = {
  136032. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136033. 38.5, 49.5,
  136034. };
  136035. static long _vq_quantmap__44u7__p8_0[] = {
  136036. 9, 7, 5, 3, 1, 0, 2, 4,
  136037. 6, 8, 10,
  136038. };
  136039. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136040. _vq_quantthresh__44u7__p8_0,
  136041. _vq_quantmap__44u7__p8_0,
  136042. 11,
  136043. 11
  136044. };
  136045. static static_codebook _44u7__p8_0 = {
  136046. 2, 121,
  136047. _vq_lengthlist__44u7__p8_0,
  136048. 1, -524582912, 1618345984, 4, 0,
  136049. _vq_quantlist__44u7__p8_0,
  136050. NULL,
  136051. &_vq_auxt__44u7__p8_0,
  136052. NULL,
  136053. 0
  136054. };
  136055. static long _vq_quantlist__44u7__p8_1[] = {
  136056. 5,
  136057. 4,
  136058. 6,
  136059. 3,
  136060. 7,
  136061. 2,
  136062. 8,
  136063. 1,
  136064. 9,
  136065. 0,
  136066. 10,
  136067. };
  136068. static long _vq_lengthlist__44u7__p8_1[] = {
  136069. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136070. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136071. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136072. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136073. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136074. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136075. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136076. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136077. };
  136078. static float _vq_quantthresh__44u7__p8_1[] = {
  136079. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136080. 3.5, 4.5,
  136081. };
  136082. static long _vq_quantmap__44u7__p8_1[] = {
  136083. 9, 7, 5, 3, 1, 0, 2, 4,
  136084. 6, 8, 10,
  136085. };
  136086. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136087. _vq_quantthresh__44u7__p8_1,
  136088. _vq_quantmap__44u7__p8_1,
  136089. 11,
  136090. 11
  136091. };
  136092. static static_codebook _44u7__p8_1 = {
  136093. 2, 121,
  136094. _vq_lengthlist__44u7__p8_1,
  136095. 1, -531365888, 1611661312, 4, 0,
  136096. _vq_quantlist__44u7__p8_1,
  136097. NULL,
  136098. &_vq_auxt__44u7__p8_1,
  136099. NULL,
  136100. 0
  136101. };
  136102. static long _vq_quantlist__44u7__p9_0[] = {
  136103. 5,
  136104. 4,
  136105. 6,
  136106. 3,
  136107. 7,
  136108. 2,
  136109. 8,
  136110. 1,
  136111. 9,
  136112. 0,
  136113. 10,
  136114. };
  136115. static long _vq_lengthlist__44u7__p9_0[] = {
  136116. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136117. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136118. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136119. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136120. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136121. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136122. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136123. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136124. };
  136125. static float _vq_quantthresh__44u7__p9_0[] = {
  136126. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136127. 2229.5, 2866.5,
  136128. };
  136129. static long _vq_quantmap__44u7__p9_0[] = {
  136130. 9, 7, 5, 3, 1, 0, 2, 4,
  136131. 6, 8, 10,
  136132. };
  136133. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136134. _vq_quantthresh__44u7__p9_0,
  136135. _vq_quantmap__44u7__p9_0,
  136136. 11,
  136137. 11
  136138. };
  136139. static static_codebook _44u7__p9_0 = {
  136140. 2, 121,
  136141. _vq_lengthlist__44u7__p9_0,
  136142. 1, -512171520, 1630791680, 4, 0,
  136143. _vq_quantlist__44u7__p9_0,
  136144. NULL,
  136145. &_vq_auxt__44u7__p9_0,
  136146. NULL,
  136147. 0
  136148. };
  136149. static long _vq_quantlist__44u7__p9_1[] = {
  136150. 6,
  136151. 5,
  136152. 7,
  136153. 4,
  136154. 8,
  136155. 3,
  136156. 9,
  136157. 2,
  136158. 10,
  136159. 1,
  136160. 11,
  136161. 0,
  136162. 12,
  136163. };
  136164. static long _vq_lengthlist__44u7__p9_1[] = {
  136165. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136166. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136167. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136168. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136169. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136170. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136171. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136172. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136173. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136174. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136175. 15,15,15,15,17,17,16,17,16,
  136176. };
  136177. static float _vq_quantthresh__44u7__p9_1[] = {
  136178. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136179. 122.5, 171.5, 220.5, 269.5,
  136180. };
  136181. static long _vq_quantmap__44u7__p9_1[] = {
  136182. 11, 9, 7, 5, 3, 1, 0, 2,
  136183. 4, 6, 8, 10, 12,
  136184. };
  136185. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136186. _vq_quantthresh__44u7__p9_1,
  136187. _vq_quantmap__44u7__p9_1,
  136188. 13,
  136189. 13
  136190. };
  136191. static static_codebook _44u7__p9_1 = {
  136192. 2, 169,
  136193. _vq_lengthlist__44u7__p9_1,
  136194. 1, -518889472, 1622704128, 4, 0,
  136195. _vq_quantlist__44u7__p9_1,
  136196. NULL,
  136197. &_vq_auxt__44u7__p9_1,
  136198. NULL,
  136199. 0
  136200. };
  136201. static long _vq_quantlist__44u7__p9_2[] = {
  136202. 24,
  136203. 23,
  136204. 25,
  136205. 22,
  136206. 26,
  136207. 21,
  136208. 27,
  136209. 20,
  136210. 28,
  136211. 19,
  136212. 29,
  136213. 18,
  136214. 30,
  136215. 17,
  136216. 31,
  136217. 16,
  136218. 32,
  136219. 15,
  136220. 33,
  136221. 14,
  136222. 34,
  136223. 13,
  136224. 35,
  136225. 12,
  136226. 36,
  136227. 11,
  136228. 37,
  136229. 10,
  136230. 38,
  136231. 9,
  136232. 39,
  136233. 8,
  136234. 40,
  136235. 7,
  136236. 41,
  136237. 6,
  136238. 42,
  136239. 5,
  136240. 43,
  136241. 4,
  136242. 44,
  136243. 3,
  136244. 45,
  136245. 2,
  136246. 46,
  136247. 1,
  136248. 47,
  136249. 0,
  136250. 48,
  136251. };
  136252. static long _vq_lengthlist__44u7__p9_2[] = {
  136253. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136254. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136255. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136256. 8,
  136257. };
  136258. static float _vq_quantthresh__44u7__p9_2[] = {
  136259. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136260. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136261. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136262. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136263. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136264. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136265. };
  136266. static long _vq_quantmap__44u7__p9_2[] = {
  136267. 47, 45, 43, 41, 39, 37, 35, 33,
  136268. 31, 29, 27, 25, 23, 21, 19, 17,
  136269. 15, 13, 11, 9, 7, 5, 3, 1,
  136270. 0, 2, 4, 6, 8, 10, 12, 14,
  136271. 16, 18, 20, 22, 24, 26, 28, 30,
  136272. 32, 34, 36, 38, 40, 42, 44, 46,
  136273. 48,
  136274. };
  136275. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136276. _vq_quantthresh__44u7__p9_2,
  136277. _vq_quantmap__44u7__p9_2,
  136278. 49,
  136279. 49
  136280. };
  136281. static static_codebook _44u7__p9_2 = {
  136282. 1, 49,
  136283. _vq_lengthlist__44u7__p9_2,
  136284. 1, -526909440, 1611661312, 6, 0,
  136285. _vq_quantlist__44u7__p9_2,
  136286. NULL,
  136287. &_vq_auxt__44u7__p9_2,
  136288. NULL,
  136289. 0
  136290. };
  136291. static long _huff_lengthlist__44u7__short[] = {
  136292. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136293. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136294. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136295. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136296. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136297. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136298. 6, 8, 5, 9,
  136299. };
  136300. static static_codebook _huff_book__44u7__short = {
  136301. 2, 100,
  136302. _huff_lengthlist__44u7__short,
  136303. 0, 0, 0, 0, 0,
  136304. NULL,
  136305. NULL,
  136306. NULL,
  136307. NULL,
  136308. 0
  136309. };
  136310. static long _huff_lengthlist__44u8__long[] = {
  136311. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136312. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136313. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136314. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136315. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136316. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136317. 10, 8, 8, 9,
  136318. };
  136319. static static_codebook _huff_book__44u8__long = {
  136320. 2, 100,
  136321. _huff_lengthlist__44u8__long,
  136322. 0, 0, 0, 0, 0,
  136323. NULL,
  136324. NULL,
  136325. NULL,
  136326. NULL,
  136327. 0
  136328. };
  136329. static long _huff_lengthlist__44u8__short[] = {
  136330. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136331. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136332. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136333. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136334. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136335. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136336. 10,10,15,17,
  136337. };
  136338. static static_codebook _huff_book__44u8__short = {
  136339. 2, 100,
  136340. _huff_lengthlist__44u8__short,
  136341. 0, 0, 0, 0, 0,
  136342. NULL,
  136343. NULL,
  136344. NULL,
  136345. NULL,
  136346. 0
  136347. };
  136348. static long _vq_quantlist__44u8_p1_0[] = {
  136349. 1,
  136350. 0,
  136351. 2,
  136352. };
  136353. static long _vq_lengthlist__44u8_p1_0[] = {
  136354. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136355. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136356. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136357. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136358. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136359. 10,
  136360. };
  136361. static float _vq_quantthresh__44u8_p1_0[] = {
  136362. -0.5, 0.5,
  136363. };
  136364. static long _vq_quantmap__44u8_p1_0[] = {
  136365. 1, 0, 2,
  136366. };
  136367. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136368. _vq_quantthresh__44u8_p1_0,
  136369. _vq_quantmap__44u8_p1_0,
  136370. 3,
  136371. 3
  136372. };
  136373. static static_codebook _44u8_p1_0 = {
  136374. 4, 81,
  136375. _vq_lengthlist__44u8_p1_0,
  136376. 1, -535822336, 1611661312, 2, 0,
  136377. _vq_quantlist__44u8_p1_0,
  136378. NULL,
  136379. &_vq_auxt__44u8_p1_0,
  136380. NULL,
  136381. 0
  136382. };
  136383. static long _vq_quantlist__44u8_p2_0[] = {
  136384. 2,
  136385. 1,
  136386. 3,
  136387. 0,
  136388. 4,
  136389. };
  136390. static long _vq_lengthlist__44u8_p2_0[] = {
  136391. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136392. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136393. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136394. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136395. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136396. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136397. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136398. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136399. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136400. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136401. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136402. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136403. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136404. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136405. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136406. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136407. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136408. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136409. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136410. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136411. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136412. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136413. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136414. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136415. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136416. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136417. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136418. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136419. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136420. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136421. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136422. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136423. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136424. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136425. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136426. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136427. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136428. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136429. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136430. 14,
  136431. };
  136432. static float _vq_quantthresh__44u8_p2_0[] = {
  136433. -1.5, -0.5, 0.5, 1.5,
  136434. };
  136435. static long _vq_quantmap__44u8_p2_0[] = {
  136436. 3, 1, 0, 2, 4,
  136437. };
  136438. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136439. _vq_quantthresh__44u8_p2_0,
  136440. _vq_quantmap__44u8_p2_0,
  136441. 5,
  136442. 5
  136443. };
  136444. static static_codebook _44u8_p2_0 = {
  136445. 4, 625,
  136446. _vq_lengthlist__44u8_p2_0,
  136447. 1, -533725184, 1611661312, 3, 0,
  136448. _vq_quantlist__44u8_p2_0,
  136449. NULL,
  136450. &_vq_auxt__44u8_p2_0,
  136451. NULL,
  136452. 0
  136453. };
  136454. static long _vq_quantlist__44u8_p3_0[] = {
  136455. 4,
  136456. 3,
  136457. 5,
  136458. 2,
  136459. 6,
  136460. 1,
  136461. 7,
  136462. 0,
  136463. 8,
  136464. };
  136465. static long _vq_lengthlist__44u8_p3_0[] = {
  136466. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136467. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136468. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136469. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136470. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136471. 12,
  136472. };
  136473. static float _vq_quantthresh__44u8_p3_0[] = {
  136474. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136475. };
  136476. static long _vq_quantmap__44u8_p3_0[] = {
  136477. 7, 5, 3, 1, 0, 2, 4, 6,
  136478. 8,
  136479. };
  136480. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136481. _vq_quantthresh__44u8_p3_0,
  136482. _vq_quantmap__44u8_p3_0,
  136483. 9,
  136484. 9
  136485. };
  136486. static static_codebook _44u8_p3_0 = {
  136487. 2, 81,
  136488. _vq_lengthlist__44u8_p3_0,
  136489. 1, -531628032, 1611661312, 4, 0,
  136490. _vq_quantlist__44u8_p3_0,
  136491. NULL,
  136492. &_vq_auxt__44u8_p3_0,
  136493. NULL,
  136494. 0
  136495. };
  136496. static long _vq_quantlist__44u8_p4_0[] = {
  136497. 8,
  136498. 7,
  136499. 9,
  136500. 6,
  136501. 10,
  136502. 5,
  136503. 11,
  136504. 4,
  136505. 12,
  136506. 3,
  136507. 13,
  136508. 2,
  136509. 14,
  136510. 1,
  136511. 15,
  136512. 0,
  136513. 16,
  136514. };
  136515. static long _vq_lengthlist__44u8_p4_0[] = {
  136516. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136517. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136518. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136519. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136520. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136521. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136522. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136523. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136524. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136525. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136526. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136527. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136528. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136529. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136530. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136531. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136532. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136533. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136534. 14,
  136535. };
  136536. static float _vq_quantthresh__44u8_p4_0[] = {
  136537. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136538. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136539. };
  136540. static long _vq_quantmap__44u8_p4_0[] = {
  136541. 15, 13, 11, 9, 7, 5, 3, 1,
  136542. 0, 2, 4, 6, 8, 10, 12, 14,
  136543. 16,
  136544. };
  136545. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  136546. _vq_quantthresh__44u8_p4_0,
  136547. _vq_quantmap__44u8_p4_0,
  136548. 17,
  136549. 17
  136550. };
  136551. static static_codebook _44u8_p4_0 = {
  136552. 2, 289,
  136553. _vq_lengthlist__44u8_p4_0,
  136554. 1, -529530880, 1611661312, 5, 0,
  136555. _vq_quantlist__44u8_p4_0,
  136556. NULL,
  136557. &_vq_auxt__44u8_p4_0,
  136558. NULL,
  136559. 0
  136560. };
  136561. static long _vq_quantlist__44u8_p5_0[] = {
  136562. 1,
  136563. 0,
  136564. 2,
  136565. };
  136566. static long _vq_lengthlist__44u8_p5_0[] = {
  136567. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  136568. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  136569. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  136570. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  136571. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  136572. 10,
  136573. };
  136574. static float _vq_quantthresh__44u8_p5_0[] = {
  136575. -5.5, 5.5,
  136576. };
  136577. static long _vq_quantmap__44u8_p5_0[] = {
  136578. 1, 0, 2,
  136579. };
  136580. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  136581. _vq_quantthresh__44u8_p5_0,
  136582. _vq_quantmap__44u8_p5_0,
  136583. 3,
  136584. 3
  136585. };
  136586. static static_codebook _44u8_p5_0 = {
  136587. 4, 81,
  136588. _vq_lengthlist__44u8_p5_0,
  136589. 1, -529137664, 1618345984, 2, 0,
  136590. _vq_quantlist__44u8_p5_0,
  136591. NULL,
  136592. &_vq_auxt__44u8_p5_0,
  136593. NULL,
  136594. 0
  136595. };
  136596. static long _vq_quantlist__44u8_p5_1[] = {
  136597. 5,
  136598. 4,
  136599. 6,
  136600. 3,
  136601. 7,
  136602. 2,
  136603. 8,
  136604. 1,
  136605. 9,
  136606. 0,
  136607. 10,
  136608. };
  136609. static long _vq_lengthlist__44u8_p5_1[] = {
  136610. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  136611. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  136612. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  136613. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  136614. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  136615. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136616. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  136617. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  136618. };
  136619. static float _vq_quantthresh__44u8_p5_1[] = {
  136620. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136621. 3.5, 4.5,
  136622. };
  136623. static long _vq_quantmap__44u8_p5_1[] = {
  136624. 9, 7, 5, 3, 1, 0, 2, 4,
  136625. 6, 8, 10,
  136626. };
  136627. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  136628. _vq_quantthresh__44u8_p5_1,
  136629. _vq_quantmap__44u8_p5_1,
  136630. 11,
  136631. 11
  136632. };
  136633. static static_codebook _44u8_p5_1 = {
  136634. 2, 121,
  136635. _vq_lengthlist__44u8_p5_1,
  136636. 1, -531365888, 1611661312, 4, 0,
  136637. _vq_quantlist__44u8_p5_1,
  136638. NULL,
  136639. &_vq_auxt__44u8_p5_1,
  136640. NULL,
  136641. 0
  136642. };
  136643. static long _vq_quantlist__44u8_p6_0[] = {
  136644. 6,
  136645. 5,
  136646. 7,
  136647. 4,
  136648. 8,
  136649. 3,
  136650. 9,
  136651. 2,
  136652. 10,
  136653. 1,
  136654. 11,
  136655. 0,
  136656. 12,
  136657. };
  136658. static long _vq_lengthlist__44u8_p6_0[] = {
  136659. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  136660. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  136661. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  136662. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  136663. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  136664. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  136665. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  136666. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  136667. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  136668. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  136669. 11,11,11,11,11,12,11,12,12,
  136670. };
  136671. static float _vq_quantthresh__44u8_p6_0[] = {
  136672. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  136673. 12.5, 17.5, 22.5, 27.5,
  136674. };
  136675. static long _vq_quantmap__44u8_p6_0[] = {
  136676. 11, 9, 7, 5, 3, 1, 0, 2,
  136677. 4, 6, 8, 10, 12,
  136678. };
  136679. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  136680. _vq_quantthresh__44u8_p6_0,
  136681. _vq_quantmap__44u8_p6_0,
  136682. 13,
  136683. 13
  136684. };
  136685. static static_codebook _44u8_p6_0 = {
  136686. 2, 169,
  136687. _vq_lengthlist__44u8_p6_0,
  136688. 1, -526516224, 1616117760, 4, 0,
  136689. _vq_quantlist__44u8_p6_0,
  136690. NULL,
  136691. &_vq_auxt__44u8_p6_0,
  136692. NULL,
  136693. 0
  136694. };
  136695. static long _vq_quantlist__44u8_p6_1[] = {
  136696. 2,
  136697. 1,
  136698. 3,
  136699. 0,
  136700. 4,
  136701. };
  136702. static long _vq_lengthlist__44u8_p6_1[] = {
  136703. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  136704. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  136705. };
  136706. static float _vq_quantthresh__44u8_p6_1[] = {
  136707. -1.5, -0.5, 0.5, 1.5,
  136708. };
  136709. static long _vq_quantmap__44u8_p6_1[] = {
  136710. 3, 1, 0, 2, 4,
  136711. };
  136712. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  136713. _vq_quantthresh__44u8_p6_1,
  136714. _vq_quantmap__44u8_p6_1,
  136715. 5,
  136716. 5
  136717. };
  136718. static static_codebook _44u8_p6_1 = {
  136719. 2, 25,
  136720. _vq_lengthlist__44u8_p6_1,
  136721. 1, -533725184, 1611661312, 3, 0,
  136722. _vq_quantlist__44u8_p6_1,
  136723. NULL,
  136724. &_vq_auxt__44u8_p6_1,
  136725. NULL,
  136726. 0
  136727. };
  136728. static long _vq_quantlist__44u8_p7_0[] = {
  136729. 6,
  136730. 5,
  136731. 7,
  136732. 4,
  136733. 8,
  136734. 3,
  136735. 9,
  136736. 2,
  136737. 10,
  136738. 1,
  136739. 11,
  136740. 0,
  136741. 12,
  136742. };
  136743. static long _vq_lengthlist__44u8_p7_0[] = {
  136744. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  136745. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  136746. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  136747. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  136748. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  136749. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  136750. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  136751. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  136752. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  136753. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  136754. 13,13,14,14,14,15,15,15,16,
  136755. };
  136756. static float _vq_quantthresh__44u8_p7_0[] = {
  136757. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  136758. 27.5, 38.5, 49.5, 60.5,
  136759. };
  136760. static long _vq_quantmap__44u8_p7_0[] = {
  136761. 11, 9, 7, 5, 3, 1, 0, 2,
  136762. 4, 6, 8, 10, 12,
  136763. };
  136764. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  136765. _vq_quantthresh__44u8_p7_0,
  136766. _vq_quantmap__44u8_p7_0,
  136767. 13,
  136768. 13
  136769. };
  136770. static static_codebook _44u8_p7_0 = {
  136771. 2, 169,
  136772. _vq_lengthlist__44u8_p7_0,
  136773. 1, -523206656, 1618345984, 4, 0,
  136774. _vq_quantlist__44u8_p7_0,
  136775. NULL,
  136776. &_vq_auxt__44u8_p7_0,
  136777. NULL,
  136778. 0
  136779. };
  136780. static long _vq_quantlist__44u8_p7_1[] = {
  136781. 5,
  136782. 4,
  136783. 6,
  136784. 3,
  136785. 7,
  136786. 2,
  136787. 8,
  136788. 1,
  136789. 9,
  136790. 0,
  136791. 10,
  136792. };
  136793. static long _vq_lengthlist__44u8_p7_1[] = {
  136794. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136795. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  136796. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136797. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  136798. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  136799. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136800. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136801. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136802. };
  136803. static float _vq_quantthresh__44u8_p7_1[] = {
  136804. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136805. 3.5, 4.5,
  136806. };
  136807. static long _vq_quantmap__44u8_p7_1[] = {
  136808. 9, 7, 5, 3, 1, 0, 2, 4,
  136809. 6, 8, 10,
  136810. };
  136811. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  136812. _vq_quantthresh__44u8_p7_1,
  136813. _vq_quantmap__44u8_p7_1,
  136814. 11,
  136815. 11
  136816. };
  136817. static static_codebook _44u8_p7_1 = {
  136818. 2, 121,
  136819. _vq_lengthlist__44u8_p7_1,
  136820. 1, -531365888, 1611661312, 4, 0,
  136821. _vq_quantlist__44u8_p7_1,
  136822. NULL,
  136823. &_vq_auxt__44u8_p7_1,
  136824. NULL,
  136825. 0
  136826. };
  136827. static long _vq_quantlist__44u8_p8_0[] = {
  136828. 7,
  136829. 6,
  136830. 8,
  136831. 5,
  136832. 9,
  136833. 4,
  136834. 10,
  136835. 3,
  136836. 11,
  136837. 2,
  136838. 12,
  136839. 1,
  136840. 13,
  136841. 0,
  136842. 14,
  136843. };
  136844. static long _vq_lengthlist__44u8_p8_0[] = {
  136845. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  136846. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  136847. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  136848. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  136849. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  136850. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  136851. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  136852. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  136853. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  136854. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  136855. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  136856. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  136857. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  136858. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  136859. 17,
  136860. };
  136861. static float _vq_quantthresh__44u8_p8_0[] = {
  136862. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  136863. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  136864. };
  136865. static long _vq_quantmap__44u8_p8_0[] = {
  136866. 13, 11, 9, 7, 5, 3, 1, 0,
  136867. 2, 4, 6, 8, 10, 12, 14,
  136868. };
  136869. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  136870. _vq_quantthresh__44u8_p8_0,
  136871. _vq_quantmap__44u8_p8_0,
  136872. 15,
  136873. 15
  136874. };
  136875. static static_codebook _44u8_p8_0 = {
  136876. 2, 225,
  136877. _vq_lengthlist__44u8_p8_0,
  136878. 1, -520986624, 1620377600, 4, 0,
  136879. _vq_quantlist__44u8_p8_0,
  136880. NULL,
  136881. &_vq_auxt__44u8_p8_0,
  136882. NULL,
  136883. 0
  136884. };
  136885. static long _vq_quantlist__44u8_p8_1[] = {
  136886. 10,
  136887. 9,
  136888. 11,
  136889. 8,
  136890. 12,
  136891. 7,
  136892. 13,
  136893. 6,
  136894. 14,
  136895. 5,
  136896. 15,
  136897. 4,
  136898. 16,
  136899. 3,
  136900. 17,
  136901. 2,
  136902. 18,
  136903. 1,
  136904. 19,
  136905. 0,
  136906. 20,
  136907. };
  136908. static long _vq_lengthlist__44u8_p8_1[] = {
  136909. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  136910. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  136911. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  136912. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  136913. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136914. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136915. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  136916. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  136917. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136918. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136919. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  136920. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  136921. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136922. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136923. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136924. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  136925. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  136926. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  136927. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  136928. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  136929. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136930. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136931. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136932. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  136933. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  136934. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136935. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  136936. 10,10,10,10,10,10,10,10,10,
  136937. };
  136938. static float _vq_quantthresh__44u8_p8_1[] = {
  136939. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  136940. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  136941. 6.5, 7.5, 8.5, 9.5,
  136942. };
  136943. static long _vq_quantmap__44u8_p8_1[] = {
  136944. 19, 17, 15, 13, 11, 9, 7, 5,
  136945. 3, 1, 0, 2, 4, 6, 8, 10,
  136946. 12, 14, 16, 18, 20,
  136947. };
  136948. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  136949. _vq_quantthresh__44u8_p8_1,
  136950. _vq_quantmap__44u8_p8_1,
  136951. 21,
  136952. 21
  136953. };
  136954. static static_codebook _44u8_p8_1 = {
  136955. 2, 441,
  136956. _vq_lengthlist__44u8_p8_1,
  136957. 1, -529268736, 1611661312, 5, 0,
  136958. _vq_quantlist__44u8_p8_1,
  136959. NULL,
  136960. &_vq_auxt__44u8_p8_1,
  136961. NULL,
  136962. 0
  136963. };
  136964. static long _vq_quantlist__44u8_p9_0[] = {
  136965. 4,
  136966. 3,
  136967. 5,
  136968. 2,
  136969. 6,
  136970. 1,
  136971. 7,
  136972. 0,
  136973. 8,
  136974. };
  136975. static long _vq_lengthlist__44u8_p9_0[] = {
  136976. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  136977. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136978. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136979. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136980. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136981. 8,
  136982. };
  136983. static float _vq_quantthresh__44u8_p9_0[] = {
  136984. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  136985. };
  136986. static long _vq_quantmap__44u8_p9_0[] = {
  136987. 7, 5, 3, 1, 0, 2, 4, 6,
  136988. 8,
  136989. };
  136990. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  136991. _vq_quantthresh__44u8_p9_0,
  136992. _vq_quantmap__44u8_p9_0,
  136993. 9,
  136994. 9
  136995. };
  136996. static static_codebook _44u8_p9_0 = {
  136997. 2, 81,
  136998. _vq_lengthlist__44u8_p9_0,
  136999. 1, -511895552, 1631393792, 4, 0,
  137000. _vq_quantlist__44u8_p9_0,
  137001. NULL,
  137002. &_vq_auxt__44u8_p9_0,
  137003. NULL,
  137004. 0
  137005. };
  137006. static long _vq_quantlist__44u8_p9_1[] = {
  137007. 9,
  137008. 8,
  137009. 10,
  137010. 7,
  137011. 11,
  137012. 6,
  137013. 12,
  137014. 5,
  137015. 13,
  137016. 4,
  137017. 14,
  137018. 3,
  137019. 15,
  137020. 2,
  137021. 16,
  137022. 1,
  137023. 17,
  137024. 0,
  137025. 18,
  137026. };
  137027. static long _vq_lengthlist__44u8_p9_1[] = {
  137028. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137029. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137030. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137031. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137032. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137033. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137034. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137035. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137036. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137037. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137038. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137039. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137040. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137041. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137042. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137043. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137044. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137045. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137046. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137047. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137048. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137049. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137050. 16,15,16,16,16,16,16,16,16,
  137051. };
  137052. static float _vq_quantthresh__44u8_p9_1[] = {
  137053. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137054. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137055. 367.5, 416.5,
  137056. };
  137057. static long _vq_quantmap__44u8_p9_1[] = {
  137058. 17, 15, 13, 11, 9, 7, 5, 3,
  137059. 1, 0, 2, 4, 6, 8, 10, 12,
  137060. 14, 16, 18,
  137061. };
  137062. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137063. _vq_quantthresh__44u8_p9_1,
  137064. _vq_quantmap__44u8_p9_1,
  137065. 19,
  137066. 19
  137067. };
  137068. static static_codebook _44u8_p9_1 = {
  137069. 2, 361,
  137070. _vq_lengthlist__44u8_p9_1,
  137071. 1, -518287360, 1622704128, 5, 0,
  137072. _vq_quantlist__44u8_p9_1,
  137073. NULL,
  137074. &_vq_auxt__44u8_p9_1,
  137075. NULL,
  137076. 0
  137077. };
  137078. static long _vq_quantlist__44u8_p9_2[] = {
  137079. 24,
  137080. 23,
  137081. 25,
  137082. 22,
  137083. 26,
  137084. 21,
  137085. 27,
  137086. 20,
  137087. 28,
  137088. 19,
  137089. 29,
  137090. 18,
  137091. 30,
  137092. 17,
  137093. 31,
  137094. 16,
  137095. 32,
  137096. 15,
  137097. 33,
  137098. 14,
  137099. 34,
  137100. 13,
  137101. 35,
  137102. 12,
  137103. 36,
  137104. 11,
  137105. 37,
  137106. 10,
  137107. 38,
  137108. 9,
  137109. 39,
  137110. 8,
  137111. 40,
  137112. 7,
  137113. 41,
  137114. 6,
  137115. 42,
  137116. 5,
  137117. 43,
  137118. 4,
  137119. 44,
  137120. 3,
  137121. 45,
  137122. 2,
  137123. 46,
  137124. 1,
  137125. 47,
  137126. 0,
  137127. 48,
  137128. };
  137129. static long _vq_lengthlist__44u8_p9_2[] = {
  137130. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137131. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137132. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137133. 7,
  137134. };
  137135. static float _vq_quantthresh__44u8_p9_2[] = {
  137136. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137137. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137138. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137139. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137140. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137141. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137142. };
  137143. static long _vq_quantmap__44u8_p9_2[] = {
  137144. 47, 45, 43, 41, 39, 37, 35, 33,
  137145. 31, 29, 27, 25, 23, 21, 19, 17,
  137146. 15, 13, 11, 9, 7, 5, 3, 1,
  137147. 0, 2, 4, 6, 8, 10, 12, 14,
  137148. 16, 18, 20, 22, 24, 26, 28, 30,
  137149. 32, 34, 36, 38, 40, 42, 44, 46,
  137150. 48,
  137151. };
  137152. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137153. _vq_quantthresh__44u8_p9_2,
  137154. _vq_quantmap__44u8_p9_2,
  137155. 49,
  137156. 49
  137157. };
  137158. static static_codebook _44u8_p9_2 = {
  137159. 1, 49,
  137160. _vq_lengthlist__44u8_p9_2,
  137161. 1, -526909440, 1611661312, 6, 0,
  137162. _vq_quantlist__44u8_p9_2,
  137163. NULL,
  137164. &_vq_auxt__44u8_p9_2,
  137165. NULL,
  137166. 0
  137167. };
  137168. static long _huff_lengthlist__44u9__long[] = {
  137169. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137170. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137171. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137172. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137173. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137174. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137175. 10, 8, 8, 9,
  137176. };
  137177. static static_codebook _huff_book__44u9__long = {
  137178. 2, 100,
  137179. _huff_lengthlist__44u9__long,
  137180. 0, 0, 0, 0, 0,
  137181. NULL,
  137182. NULL,
  137183. NULL,
  137184. NULL,
  137185. 0
  137186. };
  137187. static long _huff_lengthlist__44u9__short[] = {
  137188. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137189. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137190. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137191. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137192. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137193. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137194. 9, 9,12,15,
  137195. };
  137196. static static_codebook _huff_book__44u9__short = {
  137197. 2, 100,
  137198. _huff_lengthlist__44u9__short,
  137199. 0, 0, 0, 0, 0,
  137200. NULL,
  137201. NULL,
  137202. NULL,
  137203. NULL,
  137204. 0
  137205. };
  137206. static long _vq_quantlist__44u9_p1_0[] = {
  137207. 1,
  137208. 0,
  137209. 2,
  137210. };
  137211. static long _vq_lengthlist__44u9_p1_0[] = {
  137212. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137213. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137214. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137215. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137216. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137217. 10,
  137218. };
  137219. static float _vq_quantthresh__44u9_p1_0[] = {
  137220. -0.5, 0.5,
  137221. };
  137222. static long _vq_quantmap__44u9_p1_0[] = {
  137223. 1, 0, 2,
  137224. };
  137225. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137226. _vq_quantthresh__44u9_p1_0,
  137227. _vq_quantmap__44u9_p1_0,
  137228. 3,
  137229. 3
  137230. };
  137231. static static_codebook _44u9_p1_0 = {
  137232. 4, 81,
  137233. _vq_lengthlist__44u9_p1_0,
  137234. 1, -535822336, 1611661312, 2, 0,
  137235. _vq_quantlist__44u9_p1_0,
  137236. NULL,
  137237. &_vq_auxt__44u9_p1_0,
  137238. NULL,
  137239. 0
  137240. };
  137241. static long _vq_quantlist__44u9_p2_0[] = {
  137242. 2,
  137243. 1,
  137244. 3,
  137245. 0,
  137246. 4,
  137247. };
  137248. static long _vq_lengthlist__44u9_p2_0[] = {
  137249. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137250. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137251. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137252. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137253. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137254. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137255. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137256. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137257. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137258. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137259. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137260. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137261. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137262. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137263. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137264. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137265. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137266. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137267. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137268. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137269. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137270. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137271. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137272. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137273. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137274. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137275. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137276. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137277. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137278. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137279. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137280. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137281. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137282. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137283. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137284. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137285. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137286. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137287. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137288. 14,
  137289. };
  137290. static float _vq_quantthresh__44u9_p2_0[] = {
  137291. -1.5, -0.5, 0.5, 1.5,
  137292. };
  137293. static long _vq_quantmap__44u9_p2_0[] = {
  137294. 3, 1, 0, 2, 4,
  137295. };
  137296. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137297. _vq_quantthresh__44u9_p2_0,
  137298. _vq_quantmap__44u9_p2_0,
  137299. 5,
  137300. 5
  137301. };
  137302. static static_codebook _44u9_p2_0 = {
  137303. 4, 625,
  137304. _vq_lengthlist__44u9_p2_0,
  137305. 1, -533725184, 1611661312, 3, 0,
  137306. _vq_quantlist__44u9_p2_0,
  137307. NULL,
  137308. &_vq_auxt__44u9_p2_0,
  137309. NULL,
  137310. 0
  137311. };
  137312. static long _vq_quantlist__44u9_p3_0[] = {
  137313. 4,
  137314. 3,
  137315. 5,
  137316. 2,
  137317. 6,
  137318. 1,
  137319. 7,
  137320. 0,
  137321. 8,
  137322. };
  137323. static long _vq_lengthlist__44u9_p3_0[] = {
  137324. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137325. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137326. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137327. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137328. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137329. 11,
  137330. };
  137331. static float _vq_quantthresh__44u9_p3_0[] = {
  137332. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137333. };
  137334. static long _vq_quantmap__44u9_p3_0[] = {
  137335. 7, 5, 3, 1, 0, 2, 4, 6,
  137336. 8,
  137337. };
  137338. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137339. _vq_quantthresh__44u9_p3_0,
  137340. _vq_quantmap__44u9_p3_0,
  137341. 9,
  137342. 9
  137343. };
  137344. static static_codebook _44u9_p3_0 = {
  137345. 2, 81,
  137346. _vq_lengthlist__44u9_p3_0,
  137347. 1, -531628032, 1611661312, 4, 0,
  137348. _vq_quantlist__44u9_p3_0,
  137349. NULL,
  137350. &_vq_auxt__44u9_p3_0,
  137351. NULL,
  137352. 0
  137353. };
  137354. static long _vq_quantlist__44u9_p4_0[] = {
  137355. 8,
  137356. 7,
  137357. 9,
  137358. 6,
  137359. 10,
  137360. 5,
  137361. 11,
  137362. 4,
  137363. 12,
  137364. 3,
  137365. 13,
  137366. 2,
  137367. 14,
  137368. 1,
  137369. 15,
  137370. 0,
  137371. 16,
  137372. };
  137373. static long _vq_lengthlist__44u9_p4_0[] = {
  137374. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137375. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137376. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137377. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137378. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137379. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137380. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137381. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137382. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137383. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137384. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137385. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137386. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137387. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137388. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137389. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137390. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137391. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137392. 14,
  137393. };
  137394. static float _vq_quantthresh__44u9_p4_0[] = {
  137395. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137396. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137397. };
  137398. static long _vq_quantmap__44u9_p4_0[] = {
  137399. 15, 13, 11, 9, 7, 5, 3, 1,
  137400. 0, 2, 4, 6, 8, 10, 12, 14,
  137401. 16,
  137402. };
  137403. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137404. _vq_quantthresh__44u9_p4_0,
  137405. _vq_quantmap__44u9_p4_0,
  137406. 17,
  137407. 17
  137408. };
  137409. static static_codebook _44u9_p4_0 = {
  137410. 2, 289,
  137411. _vq_lengthlist__44u9_p4_0,
  137412. 1, -529530880, 1611661312, 5, 0,
  137413. _vq_quantlist__44u9_p4_0,
  137414. NULL,
  137415. &_vq_auxt__44u9_p4_0,
  137416. NULL,
  137417. 0
  137418. };
  137419. static long _vq_quantlist__44u9_p5_0[] = {
  137420. 1,
  137421. 0,
  137422. 2,
  137423. };
  137424. static long _vq_lengthlist__44u9_p5_0[] = {
  137425. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137426. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137427. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137428. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137429. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137430. 10,
  137431. };
  137432. static float _vq_quantthresh__44u9_p5_0[] = {
  137433. -5.5, 5.5,
  137434. };
  137435. static long _vq_quantmap__44u9_p5_0[] = {
  137436. 1, 0, 2,
  137437. };
  137438. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137439. _vq_quantthresh__44u9_p5_0,
  137440. _vq_quantmap__44u9_p5_0,
  137441. 3,
  137442. 3
  137443. };
  137444. static static_codebook _44u9_p5_0 = {
  137445. 4, 81,
  137446. _vq_lengthlist__44u9_p5_0,
  137447. 1, -529137664, 1618345984, 2, 0,
  137448. _vq_quantlist__44u9_p5_0,
  137449. NULL,
  137450. &_vq_auxt__44u9_p5_0,
  137451. NULL,
  137452. 0
  137453. };
  137454. static long _vq_quantlist__44u9_p5_1[] = {
  137455. 5,
  137456. 4,
  137457. 6,
  137458. 3,
  137459. 7,
  137460. 2,
  137461. 8,
  137462. 1,
  137463. 9,
  137464. 0,
  137465. 10,
  137466. };
  137467. static long _vq_lengthlist__44u9_p5_1[] = {
  137468. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137469. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137470. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137471. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137472. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137473. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137474. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137475. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137476. };
  137477. static float _vq_quantthresh__44u9_p5_1[] = {
  137478. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137479. 3.5, 4.5,
  137480. };
  137481. static long _vq_quantmap__44u9_p5_1[] = {
  137482. 9, 7, 5, 3, 1, 0, 2, 4,
  137483. 6, 8, 10,
  137484. };
  137485. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137486. _vq_quantthresh__44u9_p5_1,
  137487. _vq_quantmap__44u9_p5_1,
  137488. 11,
  137489. 11
  137490. };
  137491. static static_codebook _44u9_p5_1 = {
  137492. 2, 121,
  137493. _vq_lengthlist__44u9_p5_1,
  137494. 1, -531365888, 1611661312, 4, 0,
  137495. _vq_quantlist__44u9_p5_1,
  137496. NULL,
  137497. &_vq_auxt__44u9_p5_1,
  137498. NULL,
  137499. 0
  137500. };
  137501. static long _vq_quantlist__44u9_p6_0[] = {
  137502. 6,
  137503. 5,
  137504. 7,
  137505. 4,
  137506. 8,
  137507. 3,
  137508. 9,
  137509. 2,
  137510. 10,
  137511. 1,
  137512. 11,
  137513. 0,
  137514. 12,
  137515. };
  137516. static long _vq_lengthlist__44u9_p6_0[] = {
  137517. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137518. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137519. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137520. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137521. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137522. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137523. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137524. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137525. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137526. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137527. 10,11,11,11,11,12,11,12,12,
  137528. };
  137529. static float _vq_quantthresh__44u9_p6_0[] = {
  137530. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137531. 12.5, 17.5, 22.5, 27.5,
  137532. };
  137533. static long _vq_quantmap__44u9_p6_0[] = {
  137534. 11, 9, 7, 5, 3, 1, 0, 2,
  137535. 4, 6, 8, 10, 12,
  137536. };
  137537. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  137538. _vq_quantthresh__44u9_p6_0,
  137539. _vq_quantmap__44u9_p6_0,
  137540. 13,
  137541. 13
  137542. };
  137543. static static_codebook _44u9_p6_0 = {
  137544. 2, 169,
  137545. _vq_lengthlist__44u9_p6_0,
  137546. 1, -526516224, 1616117760, 4, 0,
  137547. _vq_quantlist__44u9_p6_0,
  137548. NULL,
  137549. &_vq_auxt__44u9_p6_0,
  137550. NULL,
  137551. 0
  137552. };
  137553. static long _vq_quantlist__44u9_p6_1[] = {
  137554. 2,
  137555. 1,
  137556. 3,
  137557. 0,
  137558. 4,
  137559. };
  137560. static long _vq_lengthlist__44u9_p6_1[] = {
  137561. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  137562. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137563. };
  137564. static float _vq_quantthresh__44u9_p6_1[] = {
  137565. -1.5, -0.5, 0.5, 1.5,
  137566. };
  137567. static long _vq_quantmap__44u9_p6_1[] = {
  137568. 3, 1, 0, 2, 4,
  137569. };
  137570. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  137571. _vq_quantthresh__44u9_p6_1,
  137572. _vq_quantmap__44u9_p6_1,
  137573. 5,
  137574. 5
  137575. };
  137576. static static_codebook _44u9_p6_1 = {
  137577. 2, 25,
  137578. _vq_lengthlist__44u9_p6_1,
  137579. 1, -533725184, 1611661312, 3, 0,
  137580. _vq_quantlist__44u9_p6_1,
  137581. NULL,
  137582. &_vq_auxt__44u9_p6_1,
  137583. NULL,
  137584. 0
  137585. };
  137586. static long _vq_quantlist__44u9_p7_0[] = {
  137587. 6,
  137588. 5,
  137589. 7,
  137590. 4,
  137591. 8,
  137592. 3,
  137593. 9,
  137594. 2,
  137595. 10,
  137596. 1,
  137597. 11,
  137598. 0,
  137599. 12,
  137600. };
  137601. static long _vq_lengthlist__44u9_p7_0[] = {
  137602. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  137603. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  137604. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  137605. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  137606. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137607. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137608. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  137609. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  137610. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  137611. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  137612. 12,13,13,14,14,14,15,15,15,
  137613. };
  137614. static float _vq_quantthresh__44u9_p7_0[] = {
  137615. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137616. 27.5, 38.5, 49.5, 60.5,
  137617. };
  137618. static long _vq_quantmap__44u9_p7_0[] = {
  137619. 11, 9, 7, 5, 3, 1, 0, 2,
  137620. 4, 6, 8, 10, 12,
  137621. };
  137622. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  137623. _vq_quantthresh__44u9_p7_0,
  137624. _vq_quantmap__44u9_p7_0,
  137625. 13,
  137626. 13
  137627. };
  137628. static static_codebook _44u9_p7_0 = {
  137629. 2, 169,
  137630. _vq_lengthlist__44u9_p7_0,
  137631. 1, -523206656, 1618345984, 4, 0,
  137632. _vq_quantlist__44u9_p7_0,
  137633. NULL,
  137634. &_vq_auxt__44u9_p7_0,
  137635. NULL,
  137636. 0
  137637. };
  137638. static long _vq_quantlist__44u9_p7_1[] = {
  137639. 5,
  137640. 4,
  137641. 6,
  137642. 3,
  137643. 7,
  137644. 2,
  137645. 8,
  137646. 1,
  137647. 9,
  137648. 0,
  137649. 10,
  137650. };
  137651. static long _vq_lengthlist__44u9_p7_1[] = {
  137652. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  137653. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137654. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  137655. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137656. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137657. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137658. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  137659. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137660. };
  137661. static float _vq_quantthresh__44u9_p7_1[] = {
  137662. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137663. 3.5, 4.5,
  137664. };
  137665. static long _vq_quantmap__44u9_p7_1[] = {
  137666. 9, 7, 5, 3, 1, 0, 2, 4,
  137667. 6, 8, 10,
  137668. };
  137669. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  137670. _vq_quantthresh__44u9_p7_1,
  137671. _vq_quantmap__44u9_p7_1,
  137672. 11,
  137673. 11
  137674. };
  137675. static static_codebook _44u9_p7_1 = {
  137676. 2, 121,
  137677. _vq_lengthlist__44u9_p7_1,
  137678. 1, -531365888, 1611661312, 4, 0,
  137679. _vq_quantlist__44u9_p7_1,
  137680. NULL,
  137681. &_vq_auxt__44u9_p7_1,
  137682. NULL,
  137683. 0
  137684. };
  137685. static long _vq_quantlist__44u9_p8_0[] = {
  137686. 7,
  137687. 6,
  137688. 8,
  137689. 5,
  137690. 9,
  137691. 4,
  137692. 10,
  137693. 3,
  137694. 11,
  137695. 2,
  137696. 12,
  137697. 1,
  137698. 13,
  137699. 0,
  137700. 14,
  137701. };
  137702. static long _vq_lengthlist__44u9_p8_0[] = {
  137703. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  137704. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137705. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  137706. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  137707. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  137708. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  137709. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  137710. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  137711. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  137712. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  137713. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  137714. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  137715. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  137716. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  137717. 15,
  137718. };
  137719. static float _vq_quantthresh__44u9_p8_0[] = {
  137720. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137721. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137722. };
  137723. static long _vq_quantmap__44u9_p8_0[] = {
  137724. 13, 11, 9, 7, 5, 3, 1, 0,
  137725. 2, 4, 6, 8, 10, 12, 14,
  137726. };
  137727. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  137728. _vq_quantthresh__44u9_p8_0,
  137729. _vq_quantmap__44u9_p8_0,
  137730. 15,
  137731. 15
  137732. };
  137733. static static_codebook _44u9_p8_0 = {
  137734. 2, 225,
  137735. _vq_lengthlist__44u9_p8_0,
  137736. 1, -520986624, 1620377600, 4, 0,
  137737. _vq_quantlist__44u9_p8_0,
  137738. NULL,
  137739. &_vq_auxt__44u9_p8_0,
  137740. NULL,
  137741. 0
  137742. };
  137743. static long _vq_quantlist__44u9_p8_1[] = {
  137744. 10,
  137745. 9,
  137746. 11,
  137747. 8,
  137748. 12,
  137749. 7,
  137750. 13,
  137751. 6,
  137752. 14,
  137753. 5,
  137754. 15,
  137755. 4,
  137756. 16,
  137757. 3,
  137758. 17,
  137759. 2,
  137760. 18,
  137761. 1,
  137762. 19,
  137763. 0,
  137764. 20,
  137765. };
  137766. static long _vq_lengthlist__44u9_p8_1[] = {
  137767. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137768. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137769. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  137770. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137771. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  137772. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137773. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137774. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  137775. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137776. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137777. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  137778. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  137779. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137780. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137781. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137782. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137783. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137784. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137785. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  137786. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137787. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137788. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  137789. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  137790. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  137791. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137792. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  137793. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137794. 10,10,10,10,10,10,10,10,10,
  137795. };
  137796. static float _vq_quantthresh__44u9_p8_1[] = {
  137797. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137798. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137799. 6.5, 7.5, 8.5, 9.5,
  137800. };
  137801. static long _vq_quantmap__44u9_p8_1[] = {
  137802. 19, 17, 15, 13, 11, 9, 7, 5,
  137803. 3, 1, 0, 2, 4, 6, 8, 10,
  137804. 12, 14, 16, 18, 20,
  137805. };
  137806. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  137807. _vq_quantthresh__44u9_p8_1,
  137808. _vq_quantmap__44u9_p8_1,
  137809. 21,
  137810. 21
  137811. };
  137812. static static_codebook _44u9_p8_1 = {
  137813. 2, 441,
  137814. _vq_lengthlist__44u9_p8_1,
  137815. 1, -529268736, 1611661312, 5, 0,
  137816. _vq_quantlist__44u9_p8_1,
  137817. NULL,
  137818. &_vq_auxt__44u9_p8_1,
  137819. NULL,
  137820. 0
  137821. };
  137822. static long _vq_quantlist__44u9_p9_0[] = {
  137823. 7,
  137824. 6,
  137825. 8,
  137826. 5,
  137827. 9,
  137828. 4,
  137829. 10,
  137830. 3,
  137831. 11,
  137832. 2,
  137833. 12,
  137834. 1,
  137835. 13,
  137836. 0,
  137837. 14,
  137838. };
  137839. static long _vq_lengthlist__44u9_p9_0[] = {
  137840. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  137841. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  137842. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137843. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137844. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137845. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137846. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137847. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137848. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137849. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137850. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137851. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137852. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137853. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137854. 10,
  137855. };
  137856. static float _vq_quantthresh__44u9_p9_0[] = {
  137857. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  137858. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  137859. };
  137860. static long _vq_quantmap__44u9_p9_0[] = {
  137861. 13, 11, 9, 7, 5, 3, 1, 0,
  137862. 2, 4, 6, 8, 10, 12, 14,
  137863. };
  137864. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  137865. _vq_quantthresh__44u9_p9_0,
  137866. _vq_quantmap__44u9_p9_0,
  137867. 15,
  137868. 15
  137869. };
  137870. static static_codebook _44u9_p9_0 = {
  137871. 2, 225,
  137872. _vq_lengthlist__44u9_p9_0,
  137873. 1, -510036736, 1631393792, 4, 0,
  137874. _vq_quantlist__44u9_p9_0,
  137875. NULL,
  137876. &_vq_auxt__44u9_p9_0,
  137877. NULL,
  137878. 0
  137879. };
  137880. static long _vq_quantlist__44u9_p9_1[] = {
  137881. 9,
  137882. 8,
  137883. 10,
  137884. 7,
  137885. 11,
  137886. 6,
  137887. 12,
  137888. 5,
  137889. 13,
  137890. 4,
  137891. 14,
  137892. 3,
  137893. 15,
  137894. 2,
  137895. 16,
  137896. 1,
  137897. 17,
  137898. 0,
  137899. 18,
  137900. };
  137901. static long _vq_lengthlist__44u9_p9_1[] = {
  137902. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  137903. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  137904. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  137905. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  137906. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  137907. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  137908. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  137909. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  137910. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  137911. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  137912. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  137913. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  137914. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  137915. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  137916. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  137917. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  137918. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  137919. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  137920. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  137921. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  137922. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  137923. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  137924. 17,17,15,17,15,17,16,16,17,
  137925. };
  137926. static float _vq_quantthresh__44u9_p9_1[] = {
  137927. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137928. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137929. 367.5, 416.5,
  137930. };
  137931. static long _vq_quantmap__44u9_p9_1[] = {
  137932. 17, 15, 13, 11, 9, 7, 5, 3,
  137933. 1, 0, 2, 4, 6, 8, 10, 12,
  137934. 14, 16, 18,
  137935. };
  137936. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  137937. _vq_quantthresh__44u9_p9_1,
  137938. _vq_quantmap__44u9_p9_1,
  137939. 19,
  137940. 19
  137941. };
  137942. static static_codebook _44u9_p9_1 = {
  137943. 2, 361,
  137944. _vq_lengthlist__44u9_p9_1,
  137945. 1, -518287360, 1622704128, 5, 0,
  137946. _vq_quantlist__44u9_p9_1,
  137947. NULL,
  137948. &_vq_auxt__44u9_p9_1,
  137949. NULL,
  137950. 0
  137951. };
  137952. static long _vq_quantlist__44u9_p9_2[] = {
  137953. 24,
  137954. 23,
  137955. 25,
  137956. 22,
  137957. 26,
  137958. 21,
  137959. 27,
  137960. 20,
  137961. 28,
  137962. 19,
  137963. 29,
  137964. 18,
  137965. 30,
  137966. 17,
  137967. 31,
  137968. 16,
  137969. 32,
  137970. 15,
  137971. 33,
  137972. 14,
  137973. 34,
  137974. 13,
  137975. 35,
  137976. 12,
  137977. 36,
  137978. 11,
  137979. 37,
  137980. 10,
  137981. 38,
  137982. 9,
  137983. 39,
  137984. 8,
  137985. 40,
  137986. 7,
  137987. 41,
  137988. 6,
  137989. 42,
  137990. 5,
  137991. 43,
  137992. 4,
  137993. 44,
  137994. 3,
  137995. 45,
  137996. 2,
  137997. 46,
  137998. 1,
  137999. 47,
  138000. 0,
  138001. 48,
  138002. };
  138003. static long _vq_lengthlist__44u9_p9_2[] = {
  138004. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  138005. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138006. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138007. 7,
  138008. };
  138009. static float _vq_quantthresh__44u9_p9_2[] = {
  138010. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138011. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138012. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138013. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138014. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138015. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138016. };
  138017. static long _vq_quantmap__44u9_p9_2[] = {
  138018. 47, 45, 43, 41, 39, 37, 35, 33,
  138019. 31, 29, 27, 25, 23, 21, 19, 17,
  138020. 15, 13, 11, 9, 7, 5, 3, 1,
  138021. 0, 2, 4, 6, 8, 10, 12, 14,
  138022. 16, 18, 20, 22, 24, 26, 28, 30,
  138023. 32, 34, 36, 38, 40, 42, 44, 46,
  138024. 48,
  138025. };
  138026. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138027. _vq_quantthresh__44u9_p9_2,
  138028. _vq_quantmap__44u9_p9_2,
  138029. 49,
  138030. 49
  138031. };
  138032. static static_codebook _44u9_p9_2 = {
  138033. 1, 49,
  138034. _vq_lengthlist__44u9_p9_2,
  138035. 1, -526909440, 1611661312, 6, 0,
  138036. _vq_quantlist__44u9_p9_2,
  138037. NULL,
  138038. &_vq_auxt__44u9_p9_2,
  138039. NULL,
  138040. 0
  138041. };
  138042. static long _huff_lengthlist__44un1__long[] = {
  138043. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138044. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138045. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138046. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138047. };
  138048. static static_codebook _huff_book__44un1__long = {
  138049. 2, 64,
  138050. _huff_lengthlist__44un1__long,
  138051. 0, 0, 0, 0, 0,
  138052. NULL,
  138053. NULL,
  138054. NULL,
  138055. NULL,
  138056. 0
  138057. };
  138058. static long _vq_quantlist__44un1__p1_0[] = {
  138059. 1,
  138060. 0,
  138061. 2,
  138062. };
  138063. static long _vq_lengthlist__44un1__p1_0[] = {
  138064. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138065. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138066. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138067. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138068. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138069. 12,
  138070. };
  138071. static float _vq_quantthresh__44un1__p1_0[] = {
  138072. -0.5, 0.5,
  138073. };
  138074. static long _vq_quantmap__44un1__p1_0[] = {
  138075. 1, 0, 2,
  138076. };
  138077. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138078. _vq_quantthresh__44un1__p1_0,
  138079. _vq_quantmap__44un1__p1_0,
  138080. 3,
  138081. 3
  138082. };
  138083. static static_codebook _44un1__p1_0 = {
  138084. 4, 81,
  138085. _vq_lengthlist__44un1__p1_0,
  138086. 1, -535822336, 1611661312, 2, 0,
  138087. _vq_quantlist__44un1__p1_0,
  138088. NULL,
  138089. &_vq_auxt__44un1__p1_0,
  138090. NULL,
  138091. 0
  138092. };
  138093. static long _vq_quantlist__44un1__p2_0[] = {
  138094. 1,
  138095. 0,
  138096. 2,
  138097. };
  138098. static long _vq_lengthlist__44un1__p2_0[] = {
  138099. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138100. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138101. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138102. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138103. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138104. 8,
  138105. };
  138106. static float _vq_quantthresh__44un1__p2_0[] = {
  138107. -0.5, 0.5,
  138108. };
  138109. static long _vq_quantmap__44un1__p2_0[] = {
  138110. 1, 0, 2,
  138111. };
  138112. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138113. _vq_quantthresh__44un1__p2_0,
  138114. _vq_quantmap__44un1__p2_0,
  138115. 3,
  138116. 3
  138117. };
  138118. static static_codebook _44un1__p2_0 = {
  138119. 4, 81,
  138120. _vq_lengthlist__44un1__p2_0,
  138121. 1, -535822336, 1611661312, 2, 0,
  138122. _vq_quantlist__44un1__p2_0,
  138123. NULL,
  138124. &_vq_auxt__44un1__p2_0,
  138125. NULL,
  138126. 0
  138127. };
  138128. static long _vq_quantlist__44un1__p3_0[] = {
  138129. 2,
  138130. 1,
  138131. 3,
  138132. 0,
  138133. 4,
  138134. };
  138135. static long _vq_lengthlist__44un1__p3_0[] = {
  138136. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138137. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138138. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138139. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138140. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138141. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138142. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138143. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138144. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138145. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138146. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138147. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138148. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138149. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138150. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138151. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138152. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138153. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138154. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138155. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138156. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138157. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138158. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138159. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138160. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138161. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138162. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138163. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138164. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138165. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138166. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138167. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138168. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138169. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138170. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138171. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138172. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138173. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138174. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138175. 17,
  138176. };
  138177. static float _vq_quantthresh__44un1__p3_0[] = {
  138178. -1.5, -0.5, 0.5, 1.5,
  138179. };
  138180. static long _vq_quantmap__44un1__p3_0[] = {
  138181. 3, 1, 0, 2, 4,
  138182. };
  138183. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138184. _vq_quantthresh__44un1__p3_0,
  138185. _vq_quantmap__44un1__p3_0,
  138186. 5,
  138187. 5
  138188. };
  138189. static static_codebook _44un1__p3_0 = {
  138190. 4, 625,
  138191. _vq_lengthlist__44un1__p3_0,
  138192. 1, -533725184, 1611661312, 3, 0,
  138193. _vq_quantlist__44un1__p3_0,
  138194. NULL,
  138195. &_vq_auxt__44un1__p3_0,
  138196. NULL,
  138197. 0
  138198. };
  138199. static long _vq_quantlist__44un1__p4_0[] = {
  138200. 2,
  138201. 1,
  138202. 3,
  138203. 0,
  138204. 4,
  138205. };
  138206. static long _vq_lengthlist__44un1__p4_0[] = {
  138207. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138208. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138209. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138210. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138211. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138212. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138213. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138214. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138215. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138216. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138217. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138218. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138219. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138220. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138221. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138222. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138223. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138224. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138225. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138226. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138227. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138228. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138229. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138230. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138231. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138232. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138233. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138234. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138235. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138236. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138237. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138238. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138239. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138240. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138241. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138242. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138243. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138244. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138245. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138246. 12,
  138247. };
  138248. static float _vq_quantthresh__44un1__p4_0[] = {
  138249. -1.5, -0.5, 0.5, 1.5,
  138250. };
  138251. static long _vq_quantmap__44un1__p4_0[] = {
  138252. 3, 1, 0, 2, 4,
  138253. };
  138254. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138255. _vq_quantthresh__44un1__p4_0,
  138256. _vq_quantmap__44un1__p4_0,
  138257. 5,
  138258. 5
  138259. };
  138260. static static_codebook _44un1__p4_0 = {
  138261. 4, 625,
  138262. _vq_lengthlist__44un1__p4_0,
  138263. 1, -533725184, 1611661312, 3, 0,
  138264. _vq_quantlist__44un1__p4_0,
  138265. NULL,
  138266. &_vq_auxt__44un1__p4_0,
  138267. NULL,
  138268. 0
  138269. };
  138270. static long _vq_quantlist__44un1__p5_0[] = {
  138271. 4,
  138272. 3,
  138273. 5,
  138274. 2,
  138275. 6,
  138276. 1,
  138277. 7,
  138278. 0,
  138279. 8,
  138280. };
  138281. static long _vq_lengthlist__44un1__p5_0[] = {
  138282. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138283. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138284. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138285. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138286. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138287. 12,
  138288. };
  138289. static float _vq_quantthresh__44un1__p5_0[] = {
  138290. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138291. };
  138292. static long _vq_quantmap__44un1__p5_0[] = {
  138293. 7, 5, 3, 1, 0, 2, 4, 6,
  138294. 8,
  138295. };
  138296. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138297. _vq_quantthresh__44un1__p5_0,
  138298. _vq_quantmap__44un1__p5_0,
  138299. 9,
  138300. 9
  138301. };
  138302. static static_codebook _44un1__p5_0 = {
  138303. 2, 81,
  138304. _vq_lengthlist__44un1__p5_0,
  138305. 1, -531628032, 1611661312, 4, 0,
  138306. _vq_quantlist__44un1__p5_0,
  138307. NULL,
  138308. &_vq_auxt__44un1__p5_0,
  138309. NULL,
  138310. 0
  138311. };
  138312. static long _vq_quantlist__44un1__p6_0[] = {
  138313. 6,
  138314. 5,
  138315. 7,
  138316. 4,
  138317. 8,
  138318. 3,
  138319. 9,
  138320. 2,
  138321. 10,
  138322. 1,
  138323. 11,
  138324. 0,
  138325. 12,
  138326. };
  138327. static long _vq_lengthlist__44un1__p6_0[] = {
  138328. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138329. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138330. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138331. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138332. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138333. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138334. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138335. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138336. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138337. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138338. 16, 0,15,18,18, 0,16, 0, 0,
  138339. };
  138340. static float _vq_quantthresh__44un1__p6_0[] = {
  138341. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138342. 12.5, 17.5, 22.5, 27.5,
  138343. };
  138344. static long _vq_quantmap__44un1__p6_0[] = {
  138345. 11, 9, 7, 5, 3, 1, 0, 2,
  138346. 4, 6, 8, 10, 12,
  138347. };
  138348. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138349. _vq_quantthresh__44un1__p6_0,
  138350. _vq_quantmap__44un1__p6_0,
  138351. 13,
  138352. 13
  138353. };
  138354. static static_codebook _44un1__p6_0 = {
  138355. 2, 169,
  138356. _vq_lengthlist__44un1__p6_0,
  138357. 1, -526516224, 1616117760, 4, 0,
  138358. _vq_quantlist__44un1__p6_0,
  138359. NULL,
  138360. &_vq_auxt__44un1__p6_0,
  138361. NULL,
  138362. 0
  138363. };
  138364. static long _vq_quantlist__44un1__p6_1[] = {
  138365. 2,
  138366. 1,
  138367. 3,
  138368. 0,
  138369. 4,
  138370. };
  138371. static long _vq_lengthlist__44un1__p6_1[] = {
  138372. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138373. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138374. };
  138375. static float _vq_quantthresh__44un1__p6_1[] = {
  138376. -1.5, -0.5, 0.5, 1.5,
  138377. };
  138378. static long _vq_quantmap__44un1__p6_1[] = {
  138379. 3, 1, 0, 2, 4,
  138380. };
  138381. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138382. _vq_quantthresh__44un1__p6_1,
  138383. _vq_quantmap__44un1__p6_1,
  138384. 5,
  138385. 5
  138386. };
  138387. static static_codebook _44un1__p6_1 = {
  138388. 2, 25,
  138389. _vq_lengthlist__44un1__p6_1,
  138390. 1, -533725184, 1611661312, 3, 0,
  138391. _vq_quantlist__44un1__p6_1,
  138392. NULL,
  138393. &_vq_auxt__44un1__p6_1,
  138394. NULL,
  138395. 0
  138396. };
  138397. static long _vq_quantlist__44un1__p7_0[] = {
  138398. 2,
  138399. 1,
  138400. 3,
  138401. 0,
  138402. 4,
  138403. };
  138404. static long _vq_lengthlist__44un1__p7_0[] = {
  138405. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138406. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138407. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138408. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138409. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138410. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138411. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138412. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138413. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138414. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138415. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138416. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138417. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138418. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138419. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138420. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138421. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138422. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138423. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138424. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138425. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138426. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138427. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138428. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138429. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138430. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138431. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138432. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138433. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138434. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138435. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138436. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138437. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138438. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138439. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138440. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138441. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138442. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138443. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138444. 10,
  138445. };
  138446. static float _vq_quantthresh__44un1__p7_0[] = {
  138447. -253.5, -84.5, 84.5, 253.5,
  138448. };
  138449. static long _vq_quantmap__44un1__p7_0[] = {
  138450. 3, 1, 0, 2, 4,
  138451. };
  138452. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138453. _vq_quantthresh__44un1__p7_0,
  138454. _vq_quantmap__44un1__p7_0,
  138455. 5,
  138456. 5
  138457. };
  138458. static static_codebook _44un1__p7_0 = {
  138459. 4, 625,
  138460. _vq_lengthlist__44un1__p7_0,
  138461. 1, -518709248, 1626677248, 3, 0,
  138462. _vq_quantlist__44un1__p7_0,
  138463. NULL,
  138464. &_vq_auxt__44un1__p7_0,
  138465. NULL,
  138466. 0
  138467. };
  138468. static long _vq_quantlist__44un1__p7_1[] = {
  138469. 6,
  138470. 5,
  138471. 7,
  138472. 4,
  138473. 8,
  138474. 3,
  138475. 9,
  138476. 2,
  138477. 10,
  138478. 1,
  138479. 11,
  138480. 0,
  138481. 12,
  138482. };
  138483. static long _vq_lengthlist__44un1__p7_1[] = {
  138484. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138485. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138486. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138487. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138488. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138489. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138490. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138491. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138492. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138493. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138494. 12,13,13,12,13,13,14,14,14,
  138495. };
  138496. static float _vq_quantthresh__44un1__p7_1[] = {
  138497. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138498. 32.5, 45.5, 58.5, 71.5,
  138499. };
  138500. static long _vq_quantmap__44un1__p7_1[] = {
  138501. 11, 9, 7, 5, 3, 1, 0, 2,
  138502. 4, 6, 8, 10, 12,
  138503. };
  138504. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138505. _vq_quantthresh__44un1__p7_1,
  138506. _vq_quantmap__44un1__p7_1,
  138507. 13,
  138508. 13
  138509. };
  138510. static static_codebook _44un1__p7_1 = {
  138511. 2, 169,
  138512. _vq_lengthlist__44un1__p7_1,
  138513. 1, -523010048, 1618608128, 4, 0,
  138514. _vq_quantlist__44un1__p7_1,
  138515. NULL,
  138516. &_vq_auxt__44un1__p7_1,
  138517. NULL,
  138518. 0
  138519. };
  138520. static long _vq_quantlist__44un1__p7_2[] = {
  138521. 6,
  138522. 5,
  138523. 7,
  138524. 4,
  138525. 8,
  138526. 3,
  138527. 9,
  138528. 2,
  138529. 10,
  138530. 1,
  138531. 11,
  138532. 0,
  138533. 12,
  138534. };
  138535. static long _vq_lengthlist__44un1__p7_2[] = {
  138536. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  138537. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  138538. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  138539. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  138540. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  138541. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  138542. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  138543. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  138544. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  138545. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  138546. 9, 9, 9,10,10,10,10,10,10,
  138547. };
  138548. static float _vq_quantthresh__44un1__p7_2[] = {
  138549. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  138550. 2.5, 3.5, 4.5, 5.5,
  138551. };
  138552. static long _vq_quantmap__44un1__p7_2[] = {
  138553. 11, 9, 7, 5, 3, 1, 0, 2,
  138554. 4, 6, 8, 10, 12,
  138555. };
  138556. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  138557. _vq_quantthresh__44un1__p7_2,
  138558. _vq_quantmap__44un1__p7_2,
  138559. 13,
  138560. 13
  138561. };
  138562. static static_codebook _44un1__p7_2 = {
  138563. 2, 169,
  138564. _vq_lengthlist__44un1__p7_2,
  138565. 1, -531103744, 1611661312, 4, 0,
  138566. _vq_quantlist__44un1__p7_2,
  138567. NULL,
  138568. &_vq_auxt__44un1__p7_2,
  138569. NULL,
  138570. 0
  138571. };
  138572. static long _huff_lengthlist__44un1__short[] = {
  138573. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  138574. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  138575. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  138576. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  138577. };
  138578. static static_codebook _huff_book__44un1__short = {
  138579. 2, 64,
  138580. _huff_lengthlist__44un1__short,
  138581. 0, 0, 0, 0, 0,
  138582. NULL,
  138583. NULL,
  138584. NULL,
  138585. NULL,
  138586. 0
  138587. };
  138588. /*** End of inlined file: res_books_uncoupled.h ***/
  138589. static vorbis_info_residue0 _residue_44_low_un={
  138590. 0,-1, -1, 8,-1,
  138591. {0},
  138592. {-1},
  138593. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  138594. { -1, 25, -1, 45, -1, -1, -1}
  138595. };
  138596. static vorbis_info_residue0 _residue_44_mid_un={
  138597. 0,-1, -1, 10,-1,
  138598. {0},
  138599. {-1},
  138600. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  138601. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  138602. };
  138603. static vorbis_info_residue0 _residue_44_hi_un={
  138604. 0,-1, -1, 10,-1,
  138605. {0},
  138606. {-1},
  138607. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  138608. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  138609. };
  138610. static vorbis_info_mapping0 _map_nominal_u[2]={
  138611. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  138612. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  138613. };
  138614. static static_bookblock _resbook_44u_n1={
  138615. {
  138616. {0},
  138617. {0,0,&_44un1__p1_0},
  138618. {0,0,&_44un1__p2_0},
  138619. {0,0,&_44un1__p3_0},
  138620. {0,0,&_44un1__p4_0},
  138621. {0,0,&_44un1__p5_0},
  138622. {&_44un1__p6_0,&_44un1__p6_1},
  138623. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  138624. }
  138625. };
  138626. static static_bookblock _resbook_44u_0={
  138627. {
  138628. {0},
  138629. {0,0,&_44u0__p1_0},
  138630. {0,0,&_44u0__p2_0},
  138631. {0,0,&_44u0__p3_0},
  138632. {0,0,&_44u0__p4_0},
  138633. {0,0,&_44u0__p5_0},
  138634. {&_44u0__p6_0,&_44u0__p6_1},
  138635. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  138636. }
  138637. };
  138638. static static_bookblock _resbook_44u_1={
  138639. {
  138640. {0},
  138641. {0,0,&_44u1__p1_0},
  138642. {0,0,&_44u1__p2_0},
  138643. {0,0,&_44u1__p3_0},
  138644. {0,0,&_44u1__p4_0},
  138645. {0,0,&_44u1__p5_0},
  138646. {&_44u1__p6_0,&_44u1__p6_1},
  138647. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  138648. }
  138649. };
  138650. static static_bookblock _resbook_44u_2={
  138651. {
  138652. {0},
  138653. {0,0,&_44u2__p1_0},
  138654. {0,0,&_44u2__p2_0},
  138655. {0,0,&_44u2__p3_0},
  138656. {0,0,&_44u2__p4_0},
  138657. {0,0,&_44u2__p5_0},
  138658. {&_44u2__p6_0,&_44u2__p6_1},
  138659. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  138660. }
  138661. };
  138662. static static_bookblock _resbook_44u_3={
  138663. {
  138664. {0},
  138665. {0,0,&_44u3__p1_0},
  138666. {0,0,&_44u3__p2_0},
  138667. {0,0,&_44u3__p3_0},
  138668. {0,0,&_44u3__p4_0},
  138669. {0,0,&_44u3__p5_0},
  138670. {&_44u3__p6_0,&_44u3__p6_1},
  138671. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  138672. }
  138673. };
  138674. static static_bookblock _resbook_44u_4={
  138675. {
  138676. {0},
  138677. {0,0,&_44u4__p1_0},
  138678. {0,0,&_44u4__p2_0},
  138679. {0,0,&_44u4__p3_0},
  138680. {0,0,&_44u4__p4_0},
  138681. {0,0,&_44u4__p5_0},
  138682. {&_44u4__p6_0,&_44u4__p6_1},
  138683. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  138684. }
  138685. };
  138686. static static_bookblock _resbook_44u_5={
  138687. {
  138688. {0},
  138689. {0,0,&_44u5__p1_0},
  138690. {0,0,&_44u5__p2_0},
  138691. {0,0,&_44u5__p3_0},
  138692. {0,0,&_44u5__p4_0},
  138693. {0,0,&_44u5__p5_0},
  138694. {0,0,&_44u5__p6_0},
  138695. {&_44u5__p7_0,&_44u5__p7_1},
  138696. {&_44u5__p8_0,&_44u5__p8_1},
  138697. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  138698. }
  138699. };
  138700. static static_bookblock _resbook_44u_6={
  138701. {
  138702. {0},
  138703. {0,0,&_44u6__p1_0},
  138704. {0,0,&_44u6__p2_0},
  138705. {0,0,&_44u6__p3_0},
  138706. {0,0,&_44u6__p4_0},
  138707. {0,0,&_44u6__p5_0},
  138708. {0,0,&_44u6__p6_0},
  138709. {&_44u6__p7_0,&_44u6__p7_1},
  138710. {&_44u6__p8_0,&_44u6__p8_1},
  138711. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  138712. }
  138713. };
  138714. static static_bookblock _resbook_44u_7={
  138715. {
  138716. {0},
  138717. {0,0,&_44u7__p1_0},
  138718. {0,0,&_44u7__p2_0},
  138719. {0,0,&_44u7__p3_0},
  138720. {0,0,&_44u7__p4_0},
  138721. {0,0,&_44u7__p5_0},
  138722. {0,0,&_44u7__p6_0},
  138723. {&_44u7__p7_0,&_44u7__p7_1},
  138724. {&_44u7__p8_0,&_44u7__p8_1},
  138725. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  138726. }
  138727. };
  138728. static static_bookblock _resbook_44u_8={
  138729. {
  138730. {0},
  138731. {0,0,&_44u8_p1_0},
  138732. {0,0,&_44u8_p2_0},
  138733. {0,0,&_44u8_p3_0},
  138734. {0,0,&_44u8_p4_0},
  138735. {&_44u8_p5_0,&_44u8_p5_1},
  138736. {&_44u8_p6_0,&_44u8_p6_1},
  138737. {&_44u8_p7_0,&_44u8_p7_1},
  138738. {&_44u8_p8_0,&_44u8_p8_1},
  138739. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  138740. }
  138741. };
  138742. static static_bookblock _resbook_44u_9={
  138743. {
  138744. {0},
  138745. {0,0,&_44u9_p1_0},
  138746. {0,0,&_44u9_p2_0},
  138747. {0,0,&_44u9_p3_0},
  138748. {0,0,&_44u9_p4_0},
  138749. {&_44u9_p5_0,&_44u9_p5_1},
  138750. {&_44u9_p6_0,&_44u9_p6_1},
  138751. {&_44u9_p7_0,&_44u9_p7_1},
  138752. {&_44u9_p8_0,&_44u9_p8_1},
  138753. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  138754. }
  138755. };
  138756. static vorbis_residue_template _res_44u_n1[]={
  138757. {1,0, &_residue_44_low_un,
  138758. &_huff_book__44un1__short,&_huff_book__44un1__short,
  138759. &_resbook_44u_n1,&_resbook_44u_n1},
  138760. {1,0, &_residue_44_low_un,
  138761. &_huff_book__44un1__long,&_huff_book__44un1__long,
  138762. &_resbook_44u_n1,&_resbook_44u_n1}
  138763. };
  138764. static vorbis_residue_template _res_44u_0[]={
  138765. {1,0, &_residue_44_low_un,
  138766. &_huff_book__44u0__short,&_huff_book__44u0__short,
  138767. &_resbook_44u_0,&_resbook_44u_0},
  138768. {1,0, &_residue_44_low_un,
  138769. &_huff_book__44u0__long,&_huff_book__44u0__long,
  138770. &_resbook_44u_0,&_resbook_44u_0}
  138771. };
  138772. static vorbis_residue_template _res_44u_1[]={
  138773. {1,0, &_residue_44_low_un,
  138774. &_huff_book__44u1__short,&_huff_book__44u1__short,
  138775. &_resbook_44u_1,&_resbook_44u_1},
  138776. {1,0, &_residue_44_low_un,
  138777. &_huff_book__44u1__long,&_huff_book__44u1__long,
  138778. &_resbook_44u_1,&_resbook_44u_1}
  138779. };
  138780. static vorbis_residue_template _res_44u_2[]={
  138781. {1,0, &_residue_44_low_un,
  138782. &_huff_book__44u2__short,&_huff_book__44u2__short,
  138783. &_resbook_44u_2,&_resbook_44u_2},
  138784. {1,0, &_residue_44_low_un,
  138785. &_huff_book__44u2__long,&_huff_book__44u2__long,
  138786. &_resbook_44u_2,&_resbook_44u_2}
  138787. };
  138788. static vorbis_residue_template _res_44u_3[]={
  138789. {1,0, &_residue_44_low_un,
  138790. &_huff_book__44u3__short,&_huff_book__44u3__short,
  138791. &_resbook_44u_3,&_resbook_44u_3},
  138792. {1,0, &_residue_44_low_un,
  138793. &_huff_book__44u3__long,&_huff_book__44u3__long,
  138794. &_resbook_44u_3,&_resbook_44u_3}
  138795. };
  138796. static vorbis_residue_template _res_44u_4[]={
  138797. {1,0, &_residue_44_low_un,
  138798. &_huff_book__44u4__short,&_huff_book__44u4__short,
  138799. &_resbook_44u_4,&_resbook_44u_4},
  138800. {1,0, &_residue_44_low_un,
  138801. &_huff_book__44u4__long,&_huff_book__44u4__long,
  138802. &_resbook_44u_4,&_resbook_44u_4}
  138803. };
  138804. static vorbis_residue_template _res_44u_5[]={
  138805. {1,0, &_residue_44_mid_un,
  138806. &_huff_book__44u5__short,&_huff_book__44u5__short,
  138807. &_resbook_44u_5,&_resbook_44u_5},
  138808. {1,0, &_residue_44_mid_un,
  138809. &_huff_book__44u5__long,&_huff_book__44u5__long,
  138810. &_resbook_44u_5,&_resbook_44u_5}
  138811. };
  138812. static vorbis_residue_template _res_44u_6[]={
  138813. {1,0, &_residue_44_mid_un,
  138814. &_huff_book__44u6__short,&_huff_book__44u6__short,
  138815. &_resbook_44u_6,&_resbook_44u_6},
  138816. {1,0, &_residue_44_mid_un,
  138817. &_huff_book__44u6__long,&_huff_book__44u6__long,
  138818. &_resbook_44u_6,&_resbook_44u_6}
  138819. };
  138820. static vorbis_residue_template _res_44u_7[]={
  138821. {1,0, &_residue_44_mid_un,
  138822. &_huff_book__44u7__short,&_huff_book__44u7__short,
  138823. &_resbook_44u_7,&_resbook_44u_7},
  138824. {1,0, &_residue_44_mid_un,
  138825. &_huff_book__44u7__long,&_huff_book__44u7__long,
  138826. &_resbook_44u_7,&_resbook_44u_7}
  138827. };
  138828. static vorbis_residue_template _res_44u_8[]={
  138829. {1,0, &_residue_44_hi_un,
  138830. &_huff_book__44u8__short,&_huff_book__44u8__short,
  138831. &_resbook_44u_8,&_resbook_44u_8},
  138832. {1,0, &_residue_44_hi_un,
  138833. &_huff_book__44u8__long,&_huff_book__44u8__long,
  138834. &_resbook_44u_8,&_resbook_44u_8}
  138835. };
  138836. static vorbis_residue_template _res_44u_9[]={
  138837. {1,0, &_residue_44_hi_un,
  138838. &_huff_book__44u9__short,&_huff_book__44u9__short,
  138839. &_resbook_44u_9,&_resbook_44u_9},
  138840. {1,0, &_residue_44_hi_un,
  138841. &_huff_book__44u9__long,&_huff_book__44u9__long,
  138842. &_resbook_44u_9,&_resbook_44u_9}
  138843. };
  138844. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  138845. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  138846. { _map_nominal_u, _res_44u_0 }, /* 0 */
  138847. { _map_nominal_u, _res_44u_1 }, /* 1 */
  138848. { _map_nominal_u, _res_44u_2 }, /* 2 */
  138849. { _map_nominal_u, _res_44u_3 }, /* 3 */
  138850. { _map_nominal_u, _res_44u_4 }, /* 4 */
  138851. { _map_nominal_u, _res_44u_5 }, /* 5 */
  138852. { _map_nominal_u, _res_44u_6 }, /* 6 */
  138853. { _map_nominal_u, _res_44u_7 }, /* 7 */
  138854. { _map_nominal_u, _res_44u_8 }, /* 8 */
  138855. { _map_nominal_u, _res_44u_9 }, /* 9 */
  138856. };
  138857. /*** End of inlined file: residue_44u.h ***/
  138858. static double rate_mapping_44_un[12]={
  138859. 32000.,48000.,60000.,70000.,80000.,86000.,
  138860. 96000.,110000.,120000.,140000.,160000.,240001.
  138861. };
  138862. ve_setup_data_template ve_setup_44_uncoupled={
  138863. 11,
  138864. rate_mapping_44_un,
  138865. quality_mapping_44,
  138866. -1,
  138867. 40000,
  138868. 50000,
  138869. blocksize_short_44,
  138870. blocksize_long_44,
  138871. _psy_tone_masteratt_44,
  138872. _psy_tone_0dB,
  138873. _psy_tone_suppress,
  138874. _vp_tonemask_adj_otherblock,
  138875. _vp_tonemask_adj_longblock,
  138876. _vp_tonemask_adj_otherblock,
  138877. _psy_noiseguards_44,
  138878. _psy_noisebias_impulse,
  138879. _psy_noisebias_padding,
  138880. _psy_noisebias_trans,
  138881. _psy_noisebias_long,
  138882. _psy_noise_suppress,
  138883. _psy_compand_44,
  138884. _psy_compand_short_mapping,
  138885. _psy_compand_long_mapping,
  138886. {_noise_start_short_44,_noise_start_long_44},
  138887. {_noise_part_short_44,_noise_part_long_44},
  138888. _noise_thresh_44,
  138889. _psy_ath_floater,
  138890. _psy_ath_abs,
  138891. _psy_lowpass_44,
  138892. _psy_global_44,
  138893. _global_mapping_44,
  138894. NULL,
  138895. _floor_books,
  138896. _floor,
  138897. _floor_short_mapping_44,
  138898. _floor_long_mapping_44,
  138899. _mapres_template_44_uncoupled
  138900. };
  138901. /*** End of inlined file: setup_44u.h ***/
  138902. /*** Start of inlined file: setup_32.h ***/
  138903. static double rate_mapping_32[12]={
  138904. 18000.,28000.,35000.,45000.,56000.,60000.,
  138905. 75000.,90000.,100000.,115000.,150000.,190000.,
  138906. };
  138907. static double rate_mapping_32_un[12]={
  138908. 30000.,42000.,52000.,64000.,72000.,78000.,
  138909. 86000.,92000.,110000.,120000.,140000.,190000.,
  138910. };
  138911. static double _psy_lowpass_32[12]={
  138912. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  138913. };
  138914. ve_setup_data_template ve_setup_32_stereo={
  138915. 11,
  138916. rate_mapping_32,
  138917. quality_mapping_44,
  138918. 2,
  138919. 26000,
  138920. 40000,
  138921. blocksize_short_44,
  138922. blocksize_long_44,
  138923. _psy_tone_masteratt_44,
  138924. _psy_tone_0dB,
  138925. _psy_tone_suppress,
  138926. _vp_tonemask_adj_otherblock,
  138927. _vp_tonemask_adj_longblock,
  138928. _vp_tonemask_adj_otherblock,
  138929. _psy_noiseguards_44,
  138930. _psy_noisebias_impulse,
  138931. _psy_noisebias_padding,
  138932. _psy_noisebias_trans,
  138933. _psy_noisebias_long,
  138934. _psy_noise_suppress,
  138935. _psy_compand_44,
  138936. _psy_compand_short_mapping,
  138937. _psy_compand_long_mapping,
  138938. {_noise_start_short_44,_noise_start_long_44},
  138939. {_noise_part_short_44,_noise_part_long_44},
  138940. _noise_thresh_44,
  138941. _psy_ath_floater,
  138942. _psy_ath_abs,
  138943. _psy_lowpass_32,
  138944. _psy_global_44,
  138945. _global_mapping_44,
  138946. _psy_stereo_modes_44,
  138947. _floor_books,
  138948. _floor,
  138949. _floor_short_mapping_44,
  138950. _floor_long_mapping_44,
  138951. _mapres_template_44_stereo
  138952. };
  138953. ve_setup_data_template ve_setup_32_uncoupled={
  138954. 11,
  138955. rate_mapping_32_un,
  138956. quality_mapping_44,
  138957. -1,
  138958. 26000,
  138959. 40000,
  138960. blocksize_short_44,
  138961. blocksize_long_44,
  138962. _psy_tone_masteratt_44,
  138963. _psy_tone_0dB,
  138964. _psy_tone_suppress,
  138965. _vp_tonemask_adj_otherblock,
  138966. _vp_tonemask_adj_longblock,
  138967. _vp_tonemask_adj_otherblock,
  138968. _psy_noiseguards_44,
  138969. _psy_noisebias_impulse,
  138970. _psy_noisebias_padding,
  138971. _psy_noisebias_trans,
  138972. _psy_noisebias_long,
  138973. _psy_noise_suppress,
  138974. _psy_compand_44,
  138975. _psy_compand_short_mapping,
  138976. _psy_compand_long_mapping,
  138977. {_noise_start_short_44,_noise_start_long_44},
  138978. {_noise_part_short_44,_noise_part_long_44},
  138979. _noise_thresh_44,
  138980. _psy_ath_floater,
  138981. _psy_ath_abs,
  138982. _psy_lowpass_32,
  138983. _psy_global_44,
  138984. _global_mapping_44,
  138985. NULL,
  138986. _floor_books,
  138987. _floor,
  138988. _floor_short_mapping_44,
  138989. _floor_long_mapping_44,
  138990. _mapres_template_44_uncoupled
  138991. };
  138992. /*** End of inlined file: setup_32.h ***/
  138993. /*** Start of inlined file: setup_8.h ***/
  138994. /*** Start of inlined file: psych_8.h ***/
  138995. static att3 _psy_tone_masteratt_8[3]={
  138996. {{ 32, 25, 12}, 0, 0}, /* 0 */
  138997. {{ 30, 25, 12}, 0, 0}, /* 0 */
  138998. {{ 20, 0, -14}, 0, 0}, /* 0 */
  138999. };
  139000. static vp_adjblock _vp_tonemask_adj_8[3]={
  139001. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139002. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139003. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  139004. };
  139005. static noise3 _psy_noisebias_8[3]={
  139006. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139007. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  139008. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139009. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139010. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139011. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139012. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139013. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139014. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139015. };
  139016. static adj_stereo _psy_stereo_modes_8[3]={
  139017. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139018. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139019. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139020. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139021. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139022. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139023. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139024. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139025. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139026. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139027. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139028. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139029. };
  139030. static noiseguard _psy_noiseguards_8[2]={
  139031. {10,10,-1},
  139032. {10,10,-1},
  139033. };
  139034. static compandblock _psy_compand_8[2]={
  139035. {{
  139036. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139037. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139038. 12,12,13,13,14,14,15, 15, /* 23dB */
  139039. 16,16,17,17,17,18,18, 19, /* 31dB */
  139040. 19,19,20,21,22,23,24, 25, /* 39dB */
  139041. }},
  139042. {{
  139043. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139044. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139045. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139046. 9,10,11,12,13,14,15, 16, /* 31dB */
  139047. 17,18,19,20,21,22,23, 24, /* 39dB */
  139048. }},
  139049. };
  139050. static double _psy_lowpass_8[3]={3.,4.,4.};
  139051. static int _noise_start_8[2]={
  139052. 64,64,
  139053. };
  139054. static int _noise_part_8[2]={
  139055. 8,8,
  139056. };
  139057. static int _psy_ath_floater_8[3]={
  139058. -100,-100,-105,
  139059. };
  139060. static int _psy_ath_abs_8[3]={
  139061. -130,-130,-140,
  139062. };
  139063. /*** End of inlined file: psych_8.h ***/
  139064. /*** Start of inlined file: residue_8.h ***/
  139065. static static_bookblock _resbook_8s_0={
  139066. {
  139067. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139068. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139069. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139070. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139071. }
  139072. };
  139073. static static_bookblock _resbook_8s_1={
  139074. {
  139075. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139076. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139077. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139078. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139079. }
  139080. };
  139081. static vorbis_residue_template _res_8s_0[]={
  139082. {2,0, &_residue_44_mid,
  139083. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139084. &_resbook_8s_0,&_resbook_8s_0},
  139085. };
  139086. static vorbis_residue_template _res_8s_1[]={
  139087. {2,0, &_residue_44_mid,
  139088. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139089. &_resbook_8s_1,&_resbook_8s_1},
  139090. };
  139091. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139092. { _map_nominal, _res_8s_0 }, /* 0 */
  139093. { _map_nominal, _res_8s_1 }, /* 1 */
  139094. };
  139095. static static_bookblock _resbook_8u_0={
  139096. {
  139097. {0},
  139098. {0,0,&_8u0__p1_0},
  139099. {0,0,&_8u0__p2_0},
  139100. {0,0,&_8u0__p3_0},
  139101. {0,0,&_8u0__p4_0},
  139102. {0,0,&_8u0__p5_0},
  139103. {&_8u0__p6_0,&_8u0__p6_1},
  139104. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139105. }
  139106. };
  139107. static static_bookblock _resbook_8u_1={
  139108. {
  139109. {0},
  139110. {0,0,&_8u1__p1_0},
  139111. {0,0,&_8u1__p2_0},
  139112. {0,0,&_8u1__p3_0},
  139113. {0,0,&_8u1__p4_0},
  139114. {0,0,&_8u1__p5_0},
  139115. {0,0,&_8u1__p6_0},
  139116. {&_8u1__p7_0,&_8u1__p7_1},
  139117. {&_8u1__p8_0,&_8u1__p8_1},
  139118. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139119. }
  139120. };
  139121. static vorbis_residue_template _res_8u_0[]={
  139122. {1,0, &_residue_44_low_un,
  139123. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139124. &_resbook_8u_0,&_resbook_8u_0},
  139125. };
  139126. static vorbis_residue_template _res_8u_1[]={
  139127. {1,0, &_residue_44_mid_un,
  139128. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139129. &_resbook_8u_1,&_resbook_8u_1},
  139130. };
  139131. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139132. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139133. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139134. };
  139135. /*** End of inlined file: residue_8.h ***/
  139136. static int blocksize_8[2]={
  139137. 512,512
  139138. };
  139139. static int _floor_mapping_8[2]={
  139140. 6,6,
  139141. };
  139142. static double rate_mapping_8[3]={
  139143. 6000.,9000.,32000.,
  139144. };
  139145. static double rate_mapping_8_uncoupled[3]={
  139146. 8000.,14000.,42000.,
  139147. };
  139148. static double quality_mapping_8[3]={
  139149. -.1,.0,1.
  139150. };
  139151. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139152. static double _global_mapping_8[3]={ 1., 2., 3. };
  139153. ve_setup_data_template ve_setup_8_stereo={
  139154. 2,
  139155. rate_mapping_8,
  139156. quality_mapping_8,
  139157. 2,
  139158. 8000,
  139159. 9000,
  139160. blocksize_8,
  139161. blocksize_8,
  139162. _psy_tone_masteratt_8,
  139163. _psy_tone_0dB,
  139164. _psy_tone_suppress,
  139165. _vp_tonemask_adj_8,
  139166. NULL,
  139167. _vp_tonemask_adj_8,
  139168. _psy_noiseguards_8,
  139169. _psy_noisebias_8,
  139170. _psy_noisebias_8,
  139171. NULL,
  139172. NULL,
  139173. _psy_noise_suppress,
  139174. _psy_compand_8,
  139175. _psy_compand_8_mapping,
  139176. NULL,
  139177. {_noise_start_8,_noise_start_8},
  139178. {_noise_part_8,_noise_part_8},
  139179. _noise_thresh_5only,
  139180. _psy_ath_floater_8,
  139181. _psy_ath_abs_8,
  139182. _psy_lowpass_8,
  139183. _psy_global_44,
  139184. _global_mapping_8,
  139185. _psy_stereo_modes_8,
  139186. _floor_books,
  139187. _floor,
  139188. _floor_mapping_8,
  139189. NULL,
  139190. _mapres_template_8_stereo
  139191. };
  139192. ve_setup_data_template ve_setup_8_uncoupled={
  139193. 2,
  139194. rate_mapping_8_uncoupled,
  139195. quality_mapping_8,
  139196. -1,
  139197. 8000,
  139198. 9000,
  139199. blocksize_8,
  139200. blocksize_8,
  139201. _psy_tone_masteratt_8,
  139202. _psy_tone_0dB,
  139203. _psy_tone_suppress,
  139204. _vp_tonemask_adj_8,
  139205. NULL,
  139206. _vp_tonemask_adj_8,
  139207. _psy_noiseguards_8,
  139208. _psy_noisebias_8,
  139209. _psy_noisebias_8,
  139210. NULL,
  139211. NULL,
  139212. _psy_noise_suppress,
  139213. _psy_compand_8,
  139214. _psy_compand_8_mapping,
  139215. NULL,
  139216. {_noise_start_8,_noise_start_8},
  139217. {_noise_part_8,_noise_part_8},
  139218. _noise_thresh_5only,
  139219. _psy_ath_floater_8,
  139220. _psy_ath_abs_8,
  139221. _psy_lowpass_8,
  139222. _psy_global_44,
  139223. _global_mapping_8,
  139224. _psy_stereo_modes_8,
  139225. _floor_books,
  139226. _floor,
  139227. _floor_mapping_8,
  139228. NULL,
  139229. _mapres_template_8_uncoupled
  139230. };
  139231. /*** End of inlined file: setup_8.h ***/
  139232. /*** Start of inlined file: setup_11.h ***/
  139233. /*** Start of inlined file: psych_11.h ***/
  139234. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139235. static att3 _psy_tone_masteratt_11[3]={
  139236. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139237. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139238. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139239. };
  139240. static vp_adjblock _vp_tonemask_adj_11[3]={
  139241. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139242. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139243. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139244. };
  139245. static noise3 _psy_noisebias_11[3]={
  139246. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139247. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139248. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139249. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139250. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139251. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139252. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139253. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139254. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139255. };
  139256. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139257. /*** End of inlined file: psych_11.h ***/
  139258. static int blocksize_11[2]={
  139259. 512,512
  139260. };
  139261. static int _floor_mapping_11[2]={
  139262. 6,6,
  139263. };
  139264. static double rate_mapping_11[3]={
  139265. 8000.,13000.,44000.,
  139266. };
  139267. static double rate_mapping_11_uncoupled[3]={
  139268. 12000.,20000.,50000.,
  139269. };
  139270. static double quality_mapping_11[3]={
  139271. -.1,.0,1.
  139272. };
  139273. ve_setup_data_template ve_setup_11_stereo={
  139274. 2,
  139275. rate_mapping_11,
  139276. quality_mapping_11,
  139277. 2,
  139278. 9000,
  139279. 15000,
  139280. blocksize_11,
  139281. blocksize_11,
  139282. _psy_tone_masteratt_11,
  139283. _psy_tone_0dB,
  139284. _psy_tone_suppress,
  139285. _vp_tonemask_adj_11,
  139286. NULL,
  139287. _vp_tonemask_adj_11,
  139288. _psy_noiseguards_8,
  139289. _psy_noisebias_11,
  139290. _psy_noisebias_11,
  139291. NULL,
  139292. NULL,
  139293. _psy_noise_suppress,
  139294. _psy_compand_8,
  139295. _psy_compand_8_mapping,
  139296. NULL,
  139297. {_noise_start_8,_noise_start_8},
  139298. {_noise_part_8,_noise_part_8},
  139299. _noise_thresh_11,
  139300. _psy_ath_floater_8,
  139301. _psy_ath_abs_8,
  139302. _psy_lowpass_11,
  139303. _psy_global_44,
  139304. _global_mapping_8,
  139305. _psy_stereo_modes_8,
  139306. _floor_books,
  139307. _floor,
  139308. _floor_mapping_11,
  139309. NULL,
  139310. _mapres_template_8_stereo
  139311. };
  139312. ve_setup_data_template ve_setup_11_uncoupled={
  139313. 2,
  139314. rate_mapping_11_uncoupled,
  139315. quality_mapping_11,
  139316. -1,
  139317. 9000,
  139318. 15000,
  139319. blocksize_11,
  139320. blocksize_11,
  139321. _psy_tone_masteratt_11,
  139322. _psy_tone_0dB,
  139323. _psy_tone_suppress,
  139324. _vp_tonemask_adj_11,
  139325. NULL,
  139326. _vp_tonemask_adj_11,
  139327. _psy_noiseguards_8,
  139328. _psy_noisebias_11,
  139329. _psy_noisebias_11,
  139330. NULL,
  139331. NULL,
  139332. _psy_noise_suppress,
  139333. _psy_compand_8,
  139334. _psy_compand_8_mapping,
  139335. NULL,
  139336. {_noise_start_8,_noise_start_8},
  139337. {_noise_part_8,_noise_part_8},
  139338. _noise_thresh_11,
  139339. _psy_ath_floater_8,
  139340. _psy_ath_abs_8,
  139341. _psy_lowpass_11,
  139342. _psy_global_44,
  139343. _global_mapping_8,
  139344. _psy_stereo_modes_8,
  139345. _floor_books,
  139346. _floor,
  139347. _floor_mapping_11,
  139348. NULL,
  139349. _mapres_template_8_uncoupled
  139350. };
  139351. /*** End of inlined file: setup_11.h ***/
  139352. /*** Start of inlined file: setup_16.h ***/
  139353. /*** Start of inlined file: psych_16.h ***/
  139354. static adj_stereo _psy_stereo_modes_16[4]={
  139355. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139356. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139357. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139358. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139359. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139360. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139361. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139362. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139363. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139364. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139365. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139366. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139367. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139368. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139369. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139370. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139371. };
  139372. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139373. static att3 _psy_tone_masteratt_16[4]={
  139374. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139375. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139376. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139377. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139378. };
  139379. static vp_adjblock _vp_tonemask_adj_16[4]={
  139380. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139381. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139382. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139383. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139384. };
  139385. static noise3 _psy_noisebias_16_short[4]={
  139386. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139387. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139388. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139389. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139390. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139391. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139392. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139393. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139394. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139395. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139396. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139397. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139398. };
  139399. static noise3 _psy_noisebias_16_impulse[4]={
  139400. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139401. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139402. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139403. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139404. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139405. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139406. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139407. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139408. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139409. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139410. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139411. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139412. };
  139413. static noise3 _psy_noisebias_16[4]={
  139414. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139415. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139416. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139417. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139418. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139419. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139420. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139421. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139422. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139423. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139424. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139425. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139426. };
  139427. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139428. static int _noise_start_16[3]={ 256,256,9999 };
  139429. static int _noise_part_16[4]={ 8,8,8,8 };
  139430. static int _psy_ath_floater_16[4]={
  139431. -100,-100,-100,-105,
  139432. };
  139433. static int _psy_ath_abs_16[4]={
  139434. -130,-130,-130,-140,
  139435. };
  139436. /*** End of inlined file: psych_16.h ***/
  139437. /*** Start of inlined file: residue_16.h ***/
  139438. static static_bookblock _resbook_16s_0={
  139439. {
  139440. {0},
  139441. {0,0,&_16c0_s_p1_0},
  139442. {0,0,&_16c0_s_p2_0},
  139443. {0,0,&_16c0_s_p3_0},
  139444. {0,0,&_16c0_s_p4_0},
  139445. {0,0,&_16c0_s_p5_0},
  139446. {0,0,&_16c0_s_p6_0},
  139447. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139448. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139449. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139450. }
  139451. };
  139452. static static_bookblock _resbook_16s_1={
  139453. {
  139454. {0},
  139455. {0,0,&_16c1_s_p1_0},
  139456. {0,0,&_16c1_s_p2_0},
  139457. {0,0,&_16c1_s_p3_0},
  139458. {0,0,&_16c1_s_p4_0},
  139459. {0,0,&_16c1_s_p5_0},
  139460. {0,0,&_16c1_s_p6_0},
  139461. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139462. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139463. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139464. }
  139465. };
  139466. static static_bookblock _resbook_16s_2={
  139467. {
  139468. {0},
  139469. {0,0,&_16c2_s_p1_0},
  139470. {0,0,&_16c2_s_p2_0},
  139471. {0,0,&_16c2_s_p3_0},
  139472. {0,0,&_16c2_s_p4_0},
  139473. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139474. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139475. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139476. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139477. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139478. }
  139479. };
  139480. static vorbis_residue_template _res_16s_0[]={
  139481. {2,0, &_residue_44_mid,
  139482. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139483. &_resbook_16s_0,&_resbook_16s_0},
  139484. };
  139485. static vorbis_residue_template _res_16s_1[]={
  139486. {2,0, &_residue_44_mid,
  139487. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139488. &_resbook_16s_1,&_resbook_16s_1},
  139489. {2,0, &_residue_44_mid,
  139490. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139491. &_resbook_16s_1,&_resbook_16s_1}
  139492. };
  139493. static vorbis_residue_template _res_16s_2[]={
  139494. {2,0, &_residue_44_high,
  139495. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139496. &_resbook_16s_2,&_resbook_16s_2},
  139497. {2,0, &_residue_44_high,
  139498. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139499. &_resbook_16s_2,&_resbook_16s_2}
  139500. };
  139501. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139502. { _map_nominal, _res_16s_0 }, /* 0 */
  139503. { _map_nominal, _res_16s_1 }, /* 1 */
  139504. { _map_nominal, _res_16s_2 }, /* 2 */
  139505. };
  139506. static static_bookblock _resbook_16u_0={
  139507. {
  139508. {0},
  139509. {0,0,&_16u0__p1_0},
  139510. {0,0,&_16u0__p2_0},
  139511. {0,0,&_16u0__p3_0},
  139512. {0,0,&_16u0__p4_0},
  139513. {0,0,&_16u0__p5_0},
  139514. {&_16u0__p6_0,&_16u0__p6_1},
  139515. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139516. }
  139517. };
  139518. static static_bookblock _resbook_16u_1={
  139519. {
  139520. {0},
  139521. {0,0,&_16u1__p1_0},
  139522. {0,0,&_16u1__p2_0},
  139523. {0,0,&_16u1__p3_0},
  139524. {0,0,&_16u1__p4_0},
  139525. {0,0,&_16u1__p5_0},
  139526. {0,0,&_16u1__p6_0},
  139527. {&_16u1__p7_0,&_16u1__p7_1},
  139528. {&_16u1__p8_0,&_16u1__p8_1},
  139529. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139530. }
  139531. };
  139532. static static_bookblock _resbook_16u_2={
  139533. {
  139534. {0},
  139535. {0,0,&_16u2_p1_0},
  139536. {0,0,&_16u2_p2_0},
  139537. {0,0,&_16u2_p3_0},
  139538. {0,0,&_16u2_p4_0},
  139539. {&_16u2_p5_0,&_16u2_p5_1},
  139540. {&_16u2_p6_0,&_16u2_p6_1},
  139541. {&_16u2_p7_0,&_16u2_p7_1},
  139542. {&_16u2_p8_0,&_16u2_p8_1},
  139543. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  139544. }
  139545. };
  139546. static vorbis_residue_template _res_16u_0[]={
  139547. {1,0, &_residue_44_low_un,
  139548. &_huff_book__16u0__single,&_huff_book__16u0__single,
  139549. &_resbook_16u_0,&_resbook_16u_0},
  139550. };
  139551. static vorbis_residue_template _res_16u_1[]={
  139552. {1,0, &_residue_44_mid_un,
  139553. &_huff_book__16u1__short,&_huff_book__16u1__short,
  139554. &_resbook_16u_1,&_resbook_16u_1},
  139555. {1,0, &_residue_44_mid_un,
  139556. &_huff_book__16u1__long,&_huff_book__16u1__long,
  139557. &_resbook_16u_1,&_resbook_16u_1}
  139558. };
  139559. static vorbis_residue_template _res_16u_2[]={
  139560. {1,0, &_residue_44_hi_un,
  139561. &_huff_book__16u2__short,&_huff_book__16u2__short,
  139562. &_resbook_16u_2,&_resbook_16u_2},
  139563. {1,0, &_residue_44_hi_un,
  139564. &_huff_book__16u2__long,&_huff_book__16u2__long,
  139565. &_resbook_16u_2,&_resbook_16u_2}
  139566. };
  139567. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  139568. { _map_nominal_u, _res_16u_0 }, /* 0 */
  139569. { _map_nominal_u, _res_16u_1 }, /* 1 */
  139570. { _map_nominal_u, _res_16u_2 }, /* 2 */
  139571. };
  139572. /*** End of inlined file: residue_16.h ***/
  139573. static int blocksize_16_short[3]={
  139574. 1024,512,512
  139575. };
  139576. static int blocksize_16_long[3]={
  139577. 1024,1024,1024
  139578. };
  139579. static int _floor_mapping_16_short[3]={
  139580. 9,3,3
  139581. };
  139582. static int _floor_mapping_16[3]={
  139583. 9,9,9
  139584. };
  139585. static double rate_mapping_16[4]={
  139586. 12000.,20000.,44000.,86000.
  139587. };
  139588. static double rate_mapping_16_uncoupled[4]={
  139589. 16000.,28000.,64000.,100000.
  139590. };
  139591. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  139592. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  139593. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  139594. ve_setup_data_template ve_setup_16_stereo={
  139595. 3,
  139596. rate_mapping_16,
  139597. quality_mapping_16,
  139598. 2,
  139599. 15000,
  139600. 19000,
  139601. blocksize_16_short,
  139602. blocksize_16_long,
  139603. _psy_tone_masteratt_16,
  139604. _psy_tone_0dB,
  139605. _psy_tone_suppress,
  139606. _vp_tonemask_adj_16,
  139607. _vp_tonemask_adj_16,
  139608. _vp_tonemask_adj_16,
  139609. _psy_noiseguards_8,
  139610. _psy_noisebias_16_impulse,
  139611. _psy_noisebias_16_short,
  139612. _psy_noisebias_16_short,
  139613. _psy_noisebias_16,
  139614. _psy_noise_suppress,
  139615. _psy_compand_8,
  139616. _psy_compand_16_mapping,
  139617. _psy_compand_16_mapping,
  139618. {_noise_start_16,_noise_start_16},
  139619. { _noise_part_16, _noise_part_16},
  139620. _noise_thresh_16,
  139621. _psy_ath_floater_16,
  139622. _psy_ath_abs_16,
  139623. _psy_lowpass_16,
  139624. _psy_global_44,
  139625. _global_mapping_16,
  139626. _psy_stereo_modes_16,
  139627. _floor_books,
  139628. _floor,
  139629. _floor_mapping_16_short,
  139630. _floor_mapping_16,
  139631. _mapres_template_16_stereo
  139632. };
  139633. ve_setup_data_template ve_setup_16_uncoupled={
  139634. 3,
  139635. rate_mapping_16_uncoupled,
  139636. quality_mapping_16,
  139637. -1,
  139638. 15000,
  139639. 19000,
  139640. blocksize_16_short,
  139641. blocksize_16_long,
  139642. _psy_tone_masteratt_16,
  139643. _psy_tone_0dB,
  139644. _psy_tone_suppress,
  139645. _vp_tonemask_adj_16,
  139646. _vp_tonemask_adj_16,
  139647. _vp_tonemask_adj_16,
  139648. _psy_noiseguards_8,
  139649. _psy_noisebias_16_impulse,
  139650. _psy_noisebias_16_short,
  139651. _psy_noisebias_16_short,
  139652. _psy_noisebias_16,
  139653. _psy_noise_suppress,
  139654. _psy_compand_8,
  139655. _psy_compand_16_mapping,
  139656. _psy_compand_16_mapping,
  139657. {_noise_start_16,_noise_start_16},
  139658. { _noise_part_16, _noise_part_16},
  139659. _noise_thresh_16,
  139660. _psy_ath_floater_16,
  139661. _psy_ath_abs_16,
  139662. _psy_lowpass_16,
  139663. _psy_global_44,
  139664. _global_mapping_16,
  139665. _psy_stereo_modes_16,
  139666. _floor_books,
  139667. _floor,
  139668. _floor_mapping_16_short,
  139669. _floor_mapping_16,
  139670. _mapres_template_16_uncoupled
  139671. };
  139672. /*** End of inlined file: setup_16.h ***/
  139673. /*** Start of inlined file: setup_22.h ***/
  139674. static double rate_mapping_22[4]={
  139675. 15000.,20000.,44000.,86000.
  139676. };
  139677. static double rate_mapping_22_uncoupled[4]={
  139678. 16000.,28000.,50000.,90000.
  139679. };
  139680. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  139681. ve_setup_data_template ve_setup_22_stereo={
  139682. 3,
  139683. rate_mapping_22,
  139684. quality_mapping_16,
  139685. 2,
  139686. 19000,
  139687. 26000,
  139688. blocksize_16_short,
  139689. blocksize_16_long,
  139690. _psy_tone_masteratt_16,
  139691. _psy_tone_0dB,
  139692. _psy_tone_suppress,
  139693. _vp_tonemask_adj_16,
  139694. _vp_tonemask_adj_16,
  139695. _vp_tonemask_adj_16,
  139696. _psy_noiseguards_8,
  139697. _psy_noisebias_16_impulse,
  139698. _psy_noisebias_16_short,
  139699. _psy_noisebias_16_short,
  139700. _psy_noisebias_16,
  139701. _psy_noise_suppress,
  139702. _psy_compand_8,
  139703. _psy_compand_8_mapping,
  139704. _psy_compand_8_mapping,
  139705. {_noise_start_16,_noise_start_16},
  139706. { _noise_part_16, _noise_part_16},
  139707. _noise_thresh_16,
  139708. _psy_ath_floater_16,
  139709. _psy_ath_abs_16,
  139710. _psy_lowpass_22,
  139711. _psy_global_44,
  139712. _global_mapping_16,
  139713. _psy_stereo_modes_16,
  139714. _floor_books,
  139715. _floor,
  139716. _floor_mapping_16_short,
  139717. _floor_mapping_16,
  139718. _mapres_template_16_stereo
  139719. };
  139720. ve_setup_data_template ve_setup_22_uncoupled={
  139721. 3,
  139722. rate_mapping_22_uncoupled,
  139723. quality_mapping_16,
  139724. -1,
  139725. 19000,
  139726. 26000,
  139727. blocksize_16_short,
  139728. blocksize_16_long,
  139729. _psy_tone_masteratt_16,
  139730. _psy_tone_0dB,
  139731. _psy_tone_suppress,
  139732. _vp_tonemask_adj_16,
  139733. _vp_tonemask_adj_16,
  139734. _vp_tonemask_adj_16,
  139735. _psy_noiseguards_8,
  139736. _psy_noisebias_16_impulse,
  139737. _psy_noisebias_16_short,
  139738. _psy_noisebias_16_short,
  139739. _psy_noisebias_16,
  139740. _psy_noise_suppress,
  139741. _psy_compand_8,
  139742. _psy_compand_8_mapping,
  139743. _psy_compand_8_mapping,
  139744. {_noise_start_16,_noise_start_16},
  139745. { _noise_part_16, _noise_part_16},
  139746. _noise_thresh_16,
  139747. _psy_ath_floater_16,
  139748. _psy_ath_abs_16,
  139749. _psy_lowpass_22,
  139750. _psy_global_44,
  139751. _global_mapping_16,
  139752. _psy_stereo_modes_16,
  139753. _floor_books,
  139754. _floor,
  139755. _floor_mapping_16_short,
  139756. _floor_mapping_16,
  139757. _mapres_template_16_uncoupled
  139758. };
  139759. /*** End of inlined file: setup_22.h ***/
  139760. /*** Start of inlined file: setup_X.h ***/
  139761. static double rate_mapping_X[12]={
  139762. -1.,-1.,-1.,-1.,-1.,-1.,
  139763. -1.,-1.,-1.,-1.,-1.,-1.
  139764. };
  139765. ve_setup_data_template ve_setup_X_stereo={
  139766. 11,
  139767. rate_mapping_X,
  139768. quality_mapping_44,
  139769. 2,
  139770. 50000,
  139771. 200000,
  139772. blocksize_short_44,
  139773. blocksize_long_44,
  139774. _psy_tone_masteratt_44,
  139775. _psy_tone_0dB,
  139776. _psy_tone_suppress,
  139777. _vp_tonemask_adj_otherblock,
  139778. _vp_tonemask_adj_longblock,
  139779. _vp_tonemask_adj_otherblock,
  139780. _psy_noiseguards_44,
  139781. _psy_noisebias_impulse,
  139782. _psy_noisebias_padding,
  139783. _psy_noisebias_trans,
  139784. _psy_noisebias_long,
  139785. _psy_noise_suppress,
  139786. _psy_compand_44,
  139787. _psy_compand_short_mapping,
  139788. _psy_compand_long_mapping,
  139789. {_noise_start_short_44,_noise_start_long_44},
  139790. {_noise_part_short_44,_noise_part_long_44},
  139791. _noise_thresh_44,
  139792. _psy_ath_floater,
  139793. _psy_ath_abs,
  139794. _psy_lowpass_44,
  139795. _psy_global_44,
  139796. _global_mapping_44,
  139797. _psy_stereo_modes_44,
  139798. _floor_books,
  139799. _floor,
  139800. _floor_short_mapping_44,
  139801. _floor_long_mapping_44,
  139802. _mapres_template_44_stereo
  139803. };
  139804. ve_setup_data_template ve_setup_X_uncoupled={
  139805. 11,
  139806. rate_mapping_X,
  139807. quality_mapping_44,
  139808. -1,
  139809. 50000,
  139810. 200000,
  139811. blocksize_short_44,
  139812. blocksize_long_44,
  139813. _psy_tone_masteratt_44,
  139814. _psy_tone_0dB,
  139815. _psy_tone_suppress,
  139816. _vp_tonemask_adj_otherblock,
  139817. _vp_tonemask_adj_longblock,
  139818. _vp_tonemask_adj_otherblock,
  139819. _psy_noiseguards_44,
  139820. _psy_noisebias_impulse,
  139821. _psy_noisebias_padding,
  139822. _psy_noisebias_trans,
  139823. _psy_noisebias_long,
  139824. _psy_noise_suppress,
  139825. _psy_compand_44,
  139826. _psy_compand_short_mapping,
  139827. _psy_compand_long_mapping,
  139828. {_noise_start_short_44,_noise_start_long_44},
  139829. {_noise_part_short_44,_noise_part_long_44},
  139830. _noise_thresh_44,
  139831. _psy_ath_floater,
  139832. _psy_ath_abs,
  139833. _psy_lowpass_44,
  139834. _psy_global_44,
  139835. _global_mapping_44,
  139836. NULL,
  139837. _floor_books,
  139838. _floor,
  139839. _floor_short_mapping_44,
  139840. _floor_long_mapping_44,
  139841. _mapres_template_44_uncoupled
  139842. };
  139843. ve_setup_data_template ve_setup_XX_stereo={
  139844. 2,
  139845. rate_mapping_X,
  139846. quality_mapping_8,
  139847. 2,
  139848. 0,
  139849. 8000,
  139850. blocksize_8,
  139851. blocksize_8,
  139852. _psy_tone_masteratt_8,
  139853. _psy_tone_0dB,
  139854. _psy_tone_suppress,
  139855. _vp_tonemask_adj_8,
  139856. NULL,
  139857. _vp_tonemask_adj_8,
  139858. _psy_noiseguards_8,
  139859. _psy_noisebias_8,
  139860. _psy_noisebias_8,
  139861. NULL,
  139862. NULL,
  139863. _psy_noise_suppress,
  139864. _psy_compand_8,
  139865. _psy_compand_8_mapping,
  139866. NULL,
  139867. {_noise_start_8,_noise_start_8},
  139868. {_noise_part_8,_noise_part_8},
  139869. _noise_thresh_5only,
  139870. _psy_ath_floater_8,
  139871. _psy_ath_abs_8,
  139872. _psy_lowpass_8,
  139873. _psy_global_44,
  139874. _global_mapping_8,
  139875. _psy_stereo_modes_8,
  139876. _floor_books,
  139877. _floor,
  139878. _floor_mapping_8,
  139879. NULL,
  139880. _mapres_template_8_stereo
  139881. };
  139882. ve_setup_data_template ve_setup_XX_uncoupled={
  139883. 2,
  139884. rate_mapping_X,
  139885. quality_mapping_8,
  139886. -1,
  139887. 0,
  139888. 8000,
  139889. blocksize_8,
  139890. blocksize_8,
  139891. _psy_tone_masteratt_8,
  139892. _psy_tone_0dB,
  139893. _psy_tone_suppress,
  139894. _vp_tonemask_adj_8,
  139895. NULL,
  139896. _vp_tonemask_adj_8,
  139897. _psy_noiseguards_8,
  139898. _psy_noisebias_8,
  139899. _psy_noisebias_8,
  139900. NULL,
  139901. NULL,
  139902. _psy_noise_suppress,
  139903. _psy_compand_8,
  139904. _psy_compand_8_mapping,
  139905. NULL,
  139906. {_noise_start_8,_noise_start_8},
  139907. {_noise_part_8,_noise_part_8},
  139908. _noise_thresh_5only,
  139909. _psy_ath_floater_8,
  139910. _psy_ath_abs_8,
  139911. _psy_lowpass_8,
  139912. _psy_global_44,
  139913. _global_mapping_8,
  139914. _psy_stereo_modes_8,
  139915. _floor_books,
  139916. _floor,
  139917. _floor_mapping_8,
  139918. NULL,
  139919. _mapres_template_8_uncoupled
  139920. };
  139921. /*** End of inlined file: setup_X.h ***/
  139922. static ve_setup_data_template *setup_list[]={
  139923. &ve_setup_44_stereo,
  139924. &ve_setup_44_uncoupled,
  139925. &ve_setup_32_stereo,
  139926. &ve_setup_32_uncoupled,
  139927. &ve_setup_22_stereo,
  139928. &ve_setup_22_uncoupled,
  139929. &ve_setup_16_stereo,
  139930. &ve_setup_16_uncoupled,
  139931. &ve_setup_11_stereo,
  139932. &ve_setup_11_uncoupled,
  139933. &ve_setup_8_stereo,
  139934. &ve_setup_8_uncoupled,
  139935. &ve_setup_X_stereo,
  139936. &ve_setup_X_uncoupled,
  139937. &ve_setup_XX_stereo,
  139938. &ve_setup_XX_uncoupled,
  139939. 0
  139940. };
  139941. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  139942. if(vi && vi->codec_setup){
  139943. vi->version=0;
  139944. vi->channels=ch;
  139945. vi->rate=rate;
  139946. return(0);
  139947. }
  139948. return(OV_EINVAL);
  139949. }
  139950. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  139951. static_codebook ***books,
  139952. vorbis_info_floor1 *in,
  139953. int *x){
  139954. int i,k,is=s;
  139955. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  139956. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139957. memcpy(f,in+x[is],sizeof(*f));
  139958. f->n=ci->blocksizes[block]>>1;
  139959. {
  139960. int partitions=f->partitions;
  139961. int maxclass=-1;
  139962. int maxbook=-1;
  139963. for(i=0;i<partitions;i++)
  139964. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  139965. for(i=0;i<=maxclass;i++){
  139966. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  139967. f->class_book[i]+=ci->books;
  139968. for(k=0;k<(1<<f->class_subs[i]);k++){
  139969. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  139970. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  139971. }
  139972. }
  139973. for(i=0;i<=maxbook;i++)
  139974. ci->book_param[ci->books++]=books[x[is]][i];
  139975. }
  139976. ci->floor_type[ci->floors]=1;
  139977. ci->floor_param[ci->floors]=f;
  139978. ci->floors++;
  139979. return;
  139980. }
  139981. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  139982. vorbis_info_psy_global *in,
  139983. double *x){
  139984. int i,is=s;
  139985. double ds=s-is;
  139986. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139987. vorbis_info_psy_global *g=&ci->psy_g_param;
  139988. memcpy(g,in+(int)x[is],sizeof(*g));
  139989. ds=x[is]*(1.-ds)+x[is+1]*ds;
  139990. is=(int)ds;
  139991. ds-=is;
  139992. if(ds==0 && is>0){
  139993. is--;
  139994. ds=1.;
  139995. }
  139996. for(i=0;i<4;i++){
  139997. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  139998. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  139999. }
  140000. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  140001. return;
  140002. }
  140003. static void vorbis_encode_global_stereo(vorbis_info *vi,
  140004. highlevel_encode_setup *hi,
  140005. adj_stereo *p){
  140006. float s=hi->stereo_point_setting;
  140007. int i,is=s;
  140008. double ds=s-is;
  140009. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140010. vorbis_info_psy_global *g=&ci->psy_g_param;
  140011. if(p){
  140012. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140013. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140014. if(hi->managed){
  140015. for(i=0;i<PACKETBLOBS;i++){
  140016. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140017. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140018. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140019. g->coupling_pkHz[i]=kHz;
  140020. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140021. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140022. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140023. }
  140024. }else{
  140025. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140026. for(i=0;i<PACKETBLOBS;i++){
  140027. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140028. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140029. g->coupling_pkHz[i]=kHz;
  140030. }
  140031. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140032. for(i=0;i<PACKETBLOBS;i++){
  140033. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140034. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140035. }
  140036. }
  140037. }else{
  140038. for(i=0;i<PACKETBLOBS;i++){
  140039. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140040. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140041. }
  140042. }
  140043. return;
  140044. }
  140045. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140046. int *nn_start,
  140047. int *nn_partition,
  140048. double *nn_thresh,
  140049. int block){
  140050. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140051. vorbis_info_psy *p=ci->psy_param[block];
  140052. highlevel_encode_setup *hi=&ci->hi;
  140053. int is=s;
  140054. if(block>=ci->psys)
  140055. ci->psys=block+1;
  140056. if(!p){
  140057. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140058. ci->psy_param[block]=p;
  140059. }
  140060. memcpy(p,&_psy_info_template,sizeof(*p));
  140061. p->blockflag=block>>1;
  140062. if(hi->noise_normalize_p){
  140063. p->normal_channel_p=1;
  140064. p->normal_point_p=1;
  140065. p->normal_start=nn_start[is];
  140066. p->normal_partition=nn_partition[is];
  140067. p->normal_thresh=nn_thresh[is];
  140068. }
  140069. return;
  140070. }
  140071. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140072. att3 *att,
  140073. int *max,
  140074. vp_adjblock *in){
  140075. int i,is=s;
  140076. double ds=s-is;
  140077. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140078. vorbis_info_psy *p=ci->psy_param[block];
  140079. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140080. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140081. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140082. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140083. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140084. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140085. for(i=0;i<P_BANDS;i++)
  140086. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140087. return;
  140088. }
  140089. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140090. compandblock *in, double *x){
  140091. int i,is=s;
  140092. double ds=s-is;
  140093. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140094. vorbis_info_psy *p=ci->psy_param[block];
  140095. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140096. is=(int)ds;
  140097. ds-=is;
  140098. if(ds==0 && is>0){
  140099. is--;
  140100. ds=1.;
  140101. }
  140102. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140103. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140104. return;
  140105. }
  140106. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140107. int *suppress){
  140108. int is=s;
  140109. double ds=s-is;
  140110. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140111. vorbis_info_psy *p=ci->psy_param[block];
  140112. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140113. return;
  140114. }
  140115. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140116. int *suppress,
  140117. noise3 *in,
  140118. noiseguard *guard,
  140119. double userbias){
  140120. int i,is=s,j;
  140121. double ds=s-is;
  140122. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140123. vorbis_info_psy *p=ci->psy_param[block];
  140124. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140125. p->noisewindowlomin=guard[block].lo;
  140126. p->noisewindowhimin=guard[block].hi;
  140127. p->noisewindowfixed=guard[block].fixed;
  140128. for(j=0;j<P_NOISECURVES;j++)
  140129. for(i=0;i<P_BANDS;i++)
  140130. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140131. for(j=0;j<P_NOISECURVES;j++){
  140132. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140133. for(i=0;i<P_BANDS;i++){
  140134. p->noiseoff[j][i]+=userbias;
  140135. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140136. }
  140137. }
  140138. return;
  140139. }
  140140. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140141. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140142. vorbis_info_psy *p=ci->psy_param[block];
  140143. p->ath_adjatt=ci->hi.ath_floating_dB;
  140144. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140145. return;
  140146. }
  140147. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140148. int i;
  140149. for(i=0;i<ci->books;i++)
  140150. if(ci->book_param[i]==book)return(i);
  140151. return(ci->books++);
  140152. }
  140153. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140154. int *shortb,int *longb){
  140155. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140156. int is=s;
  140157. int blockshort=shortb[is];
  140158. int blocklong=longb[is];
  140159. ci->blocksizes[0]=blockshort;
  140160. ci->blocksizes[1]=blocklong;
  140161. }
  140162. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140163. int number, int block,
  140164. vorbis_residue_template *res){
  140165. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140166. int i,n;
  140167. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140168. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140169. memcpy(r,res->res,sizeof(*r));
  140170. if(ci->residues<=number)ci->residues=number+1;
  140171. switch(ci->blocksizes[block]){
  140172. case 64:case 128:case 256:
  140173. r->grouping=16;
  140174. break;
  140175. default:
  140176. r->grouping=32;
  140177. break;
  140178. }
  140179. ci->residue_type[number]=res->res_type;
  140180. n=r->end=ci->blocksizes[block]>>1;
  140181. if(res->res_type==2)
  140182. n=r->end*=vi->channels;
  140183. {
  140184. int booklist=0,k;
  140185. if(ci->hi.managed){
  140186. for(i=0;i<r->partitions;i++)
  140187. for(k=0;k<3;k++)
  140188. if(res->books_base_managed->books[i][k])
  140189. r->secondstages[i]|=(1<<k);
  140190. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140191. ci->book_param[r->groupbook]=res->book_aux_managed;
  140192. for(i=0;i<r->partitions;i++){
  140193. for(k=0;k<3;k++){
  140194. if(res->books_base_managed->books[i][k]){
  140195. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140196. r->booklist[booklist++]=bookid;
  140197. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140198. }
  140199. }
  140200. }
  140201. }else{
  140202. for(i=0;i<r->partitions;i++)
  140203. for(k=0;k<3;k++)
  140204. if(res->books_base->books[i][k])
  140205. r->secondstages[i]|=(1<<k);
  140206. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140207. ci->book_param[r->groupbook]=res->book_aux;
  140208. for(i=0;i<r->partitions;i++){
  140209. for(k=0;k<3;k++){
  140210. if(res->books_base->books[i][k]){
  140211. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140212. r->booklist[booklist++]=bookid;
  140213. ci->book_param[bookid]=res->books_base->books[i][k];
  140214. }
  140215. }
  140216. }
  140217. }
  140218. }
  140219. {
  140220. double freq=ci->hi.lowpass_kHz*1000.;
  140221. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140222. double nyq=vi->rate/2.;
  140223. long blocksize=ci->blocksizes[block]>>1;
  140224. if(freq>nyq)freq=nyq;
  140225. f->n=freq/nyq*blocksize;
  140226. if(res->limit_type){
  140227. if(ci->hi.managed)
  140228. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140229. else
  140230. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140231. if(freq>nyq)freq=nyq;
  140232. }
  140233. if(ci->residue_type[block]==2)
  140234. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140235. r->grouping;
  140236. else
  140237. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140238. r->grouping;
  140239. }
  140240. }
  140241. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140242. vorbis_mapping_template *maps){
  140243. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140244. int i,j,is=s,modes=2;
  140245. vorbis_info_mapping0 *map=maps[is].map;
  140246. vorbis_info_mode *mode=_mode_template;
  140247. vorbis_residue_template *res=maps[is].res;
  140248. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140249. for(i=0;i<modes;i++){
  140250. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140251. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140252. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140253. if(i>=ci->modes)ci->modes=i+1;
  140254. ci->map_type[i]=0;
  140255. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140256. if(i>=ci->maps)ci->maps=i+1;
  140257. for(j=0;j<map[i].submaps;j++)
  140258. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140259. ,res+map[i].residuesubmap[j]);
  140260. }
  140261. }
  140262. static double setting_to_approx_bitrate(vorbis_info *vi){
  140263. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140264. highlevel_encode_setup *hi=&ci->hi;
  140265. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140266. int is=hi->base_setting;
  140267. double ds=hi->base_setting-is;
  140268. int ch=vi->channels;
  140269. double *r=setup->rate_mapping;
  140270. if(r==NULL)
  140271. return(-1);
  140272. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140273. }
  140274. static void get_setup_template(vorbis_info *vi,
  140275. long ch,long srate,
  140276. double req,int q_or_bitrate){
  140277. int i=0,j;
  140278. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140279. highlevel_encode_setup *hi=&ci->hi;
  140280. if(q_or_bitrate)req/=ch;
  140281. while(setup_list[i]){
  140282. if(setup_list[i]->coupling_restriction==-1 ||
  140283. setup_list[i]->coupling_restriction==ch){
  140284. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140285. srate<=setup_list[i]->samplerate_max_restriction){
  140286. int mappings=setup_list[i]->mappings;
  140287. double *map=(q_or_bitrate?
  140288. setup_list[i]->rate_mapping:
  140289. setup_list[i]->quality_mapping);
  140290. if(req<map[0]){++i;continue;}
  140291. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140292. for(j=0;j<mappings;j++)
  140293. if(req>=map[j] && req<map[j+1])break;
  140294. hi->setup=setup_list[i];
  140295. if(j==mappings)
  140296. hi->base_setting=j-.001;
  140297. else{
  140298. float low=map[j];
  140299. float high=map[j+1];
  140300. float del=(req-low)/(high-low);
  140301. hi->base_setting=j+del;
  140302. }
  140303. return;
  140304. }
  140305. }
  140306. i++;
  140307. }
  140308. hi->setup=NULL;
  140309. }
  140310. int vorbis_encode_setup_init(vorbis_info *vi){
  140311. int i0=0,singleblock=0;
  140312. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140313. ve_setup_data_template *setup=NULL;
  140314. highlevel_encode_setup *hi=&ci->hi;
  140315. if(ci==NULL)return(OV_EINVAL);
  140316. if(!hi->impulse_block_p)i0=1;
  140317. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140318. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140319. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140320. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140321. setup=(ve_setup_data_template *)hi->setup;
  140322. if(setup==NULL)return(OV_EINVAL);
  140323. hi->set_in_stone=1;
  140324. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140325. setup->blocksize_short,
  140326. setup->blocksize_long);
  140327. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140328. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140329. setup->floor_books,
  140330. setup->floor_params,
  140331. setup->floor_short_mapping);
  140332. if(!singleblock)
  140333. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140334. setup->floor_books,
  140335. setup->floor_params,
  140336. setup->floor_long_mapping);
  140337. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140338. setup->global_params,
  140339. setup->global_mapping);
  140340. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140341. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140342. setup->psy_noise_normal_start[0],
  140343. setup->psy_noise_normal_partition[0],
  140344. setup->psy_noise_normal_thresh,
  140345. 0);
  140346. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140347. setup->psy_noise_normal_start[0],
  140348. setup->psy_noise_normal_partition[0],
  140349. setup->psy_noise_normal_thresh,
  140350. 1);
  140351. if(!singleblock){
  140352. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140353. setup->psy_noise_normal_start[1],
  140354. setup->psy_noise_normal_partition[1],
  140355. setup->psy_noise_normal_thresh,
  140356. 2);
  140357. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140358. setup->psy_noise_normal_start[1],
  140359. setup->psy_noise_normal_partition[1],
  140360. setup->psy_noise_normal_thresh,
  140361. 3);
  140362. }
  140363. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140364. setup->psy_tone_masteratt,
  140365. setup->psy_tone_0dB,
  140366. setup->psy_tone_adj_impulse);
  140367. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140368. setup->psy_tone_masteratt,
  140369. setup->psy_tone_0dB,
  140370. setup->psy_tone_adj_other);
  140371. if(!singleblock){
  140372. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140373. setup->psy_tone_masteratt,
  140374. setup->psy_tone_0dB,
  140375. setup->psy_tone_adj_other);
  140376. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140377. setup->psy_tone_masteratt,
  140378. setup->psy_tone_0dB,
  140379. setup->psy_tone_adj_long);
  140380. }
  140381. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140382. setup->psy_noise_compand,
  140383. setup->psy_noise_compand_short_mapping);
  140384. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140385. setup->psy_noise_compand,
  140386. setup->psy_noise_compand_short_mapping);
  140387. if(!singleblock){
  140388. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140389. setup->psy_noise_compand,
  140390. setup->psy_noise_compand_long_mapping);
  140391. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140392. setup->psy_noise_compand,
  140393. setup->psy_noise_compand_long_mapping);
  140394. }
  140395. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140396. setup->psy_tone_dBsuppress);
  140397. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140398. setup->psy_tone_dBsuppress);
  140399. if(!singleblock){
  140400. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140401. setup->psy_tone_dBsuppress);
  140402. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140403. setup->psy_tone_dBsuppress);
  140404. }
  140405. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140406. setup->psy_noise_dBsuppress,
  140407. setup->psy_noise_bias_impulse,
  140408. setup->psy_noiseguards,
  140409. (i0==0?hi->impulse_noisetune:0.));
  140410. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140411. setup->psy_noise_dBsuppress,
  140412. setup->psy_noise_bias_padding,
  140413. setup->psy_noiseguards,0.);
  140414. if(!singleblock){
  140415. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140416. setup->psy_noise_dBsuppress,
  140417. setup->psy_noise_bias_trans,
  140418. setup->psy_noiseguards,0.);
  140419. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140420. setup->psy_noise_dBsuppress,
  140421. setup->psy_noise_bias_long,
  140422. setup->psy_noiseguards,0.);
  140423. }
  140424. vorbis_encode_ath_setup(vi,0);
  140425. vorbis_encode_ath_setup(vi,1);
  140426. if(!singleblock){
  140427. vorbis_encode_ath_setup(vi,2);
  140428. vorbis_encode_ath_setup(vi,3);
  140429. }
  140430. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140431. if(hi->bitrate_av>0)
  140432. vi->bitrate_nominal=hi->bitrate_av;
  140433. else{
  140434. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140435. }
  140436. vi->bitrate_lower=hi->bitrate_min;
  140437. vi->bitrate_upper=hi->bitrate_max;
  140438. if(hi->bitrate_av)
  140439. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140440. else
  140441. vi->bitrate_window=0.;
  140442. if(hi->managed){
  140443. ci->bi.avg_rate=hi->bitrate_av;
  140444. ci->bi.min_rate=hi->bitrate_min;
  140445. ci->bi.max_rate=hi->bitrate_max;
  140446. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140447. ci->bi.reservoir_bias=
  140448. hi->bitrate_reservoir_bias;
  140449. ci->bi.slew_damp=hi->bitrate_av_damp;
  140450. }
  140451. return(0);
  140452. }
  140453. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140454. long channels,
  140455. long rate){
  140456. int ret=0,i,is;
  140457. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140458. highlevel_encode_setup *hi=&ci->hi;
  140459. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140460. double ds;
  140461. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140462. if(ret)return(ret);
  140463. is=hi->base_setting;
  140464. ds=hi->base_setting-is;
  140465. hi->short_setting=hi->base_setting;
  140466. hi->long_setting=hi->base_setting;
  140467. hi->managed=0;
  140468. hi->impulse_block_p=1;
  140469. hi->noise_normalize_p=1;
  140470. hi->stereo_point_setting=hi->base_setting;
  140471. hi->lowpass_kHz=
  140472. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140473. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140474. setup->psy_ath_float[is+1]*ds;
  140475. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140476. setup->psy_ath_abs[is+1]*ds;
  140477. hi->amplitude_track_dBpersec=-6.;
  140478. hi->trigger_setting=hi->base_setting;
  140479. for(i=0;i<4;i++){
  140480. hi->block[i].tone_mask_setting=hi->base_setting;
  140481. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140482. hi->block[i].noise_bias_setting=hi->base_setting;
  140483. hi->block[i].noise_compand_setting=hi->base_setting;
  140484. }
  140485. return(ret);
  140486. }
  140487. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140488. long channels,
  140489. long rate,
  140490. float quality){
  140491. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140492. highlevel_encode_setup *hi=&ci->hi;
  140493. quality+=.0000001;
  140494. if(quality>=1.)quality=.9999;
  140495. get_setup_template(vi,channels,rate,quality,0);
  140496. if(!hi->setup)return OV_EIMPL;
  140497. return vorbis_encode_setup_setting(vi,channels,rate);
  140498. }
  140499. int vorbis_encode_init_vbr(vorbis_info *vi,
  140500. long channels,
  140501. long rate,
  140502. float base_quality /* 0. to 1. */
  140503. ){
  140504. int ret=0;
  140505. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140506. if(ret){
  140507. vorbis_info_clear(vi);
  140508. return ret;
  140509. }
  140510. ret=vorbis_encode_setup_init(vi);
  140511. if(ret)
  140512. vorbis_info_clear(vi);
  140513. return(ret);
  140514. }
  140515. int vorbis_encode_setup_managed(vorbis_info *vi,
  140516. long channels,
  140517. long rate,
  140518. long max_bitrate,
  140519. long nominal_bitrate,
  140520. long min_bitrate){
  140521. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140522. highlevel_encode_setup *hi=&ci->hi;
  140523. double tnominal=nominal_bitrate;
  140524. int ret=0;
  140525. if(nominal_bitrate<=0.){
  140526. if(max_bitrate>0.){
  140527. if(min_bitrate>0.)
  140528. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140529. else
  140530. nominal_bitrate=max_bitrate*.875;
  140531. }else{
  140532. if(min_bitrate>0.){
  140533. nominal_bitrate=min_bitrate;
  140534. }else{
  140535. return(OV_EINVAL);
  140536. }
  140537. }
  140538. }
  140539. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  140540. if(!hi->setup)return OV_EIMPL;
  140541. ret=vorbis_encode_setup_setting(vi,channels,rate);
  140542. if(ret){
  140543. vorbis_info_clear(vi);
  140544. return ret;
  140545. }
  140546. hi->managed=1;
  140547. hi->bitrate_min=min_bitrate;
  140548. hi->bitrate_max=max_bitrate;
  140549. hi->bitrate_av=tnominal;
  140550. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  140551. hi->bitrate_reservoir=nominal_bitrate*2;
  140552. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  140553. return(ret);
  140554. }
  140555. int vorbis_encode_init(vorbis_info *vi,
  140556. long channels,
  140557. long rate,
  140558. long max_bitrate,
  140559. long nominal_bitrate,
  140560. long min_bitrate){
  140561. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  140562. max_bitrate,
  140563. nominal_bitrate,
  140564. min_bitrate);
  140565. if(ret){
  140566. vorbis_info_clear(vi);
  140567. return(ret);
  140568. }
  140569. ret=vorbis_encode_setup_init(vi);
  140570. if(ret)
  140571. vorbis_info_clear(vi);
  140572. return(ret);
  140573. }
  140574. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  140575. if(vi){
  140576. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140577. highlevel_encode_setup *hi=&ci->hi;
  140578. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  140579. if(setp && hi->set_in_stone)return(OV_EINVAL);
  140580. switch(number){
  140581. case OV_ECTL_RATEMANAGE_GET:
  140582. {
  140583. struct ovectl_ratemanage_arg *ai=
  140584. (struct ovectl_ratemanage_arg *)arg;
  140585. ai->management_active=hi->managed;
  140586. ai->bitrate_hard_window=ai->bitrate_av_window=
  140587. (double)hi->bitrate_reservoir/vi->rate;
  140588. ai->bitrate_av_window_center=1.;
  140589. ai->bitrate_hard_min=hi->bitrate_min;
  140590. ai->bitrate_hard_max=hi->bitrate_max;
  140591. ai->bitrate_av_lo=hi->bitrate_av;
  140592. ai->bitrate_av_hi=hi->bitrate_av;
  140593. }
  140594. return(0);
  140595. case OV_ECTL_RATEMANAGE_SET:
  140596. {
  140597. struct ovectl_ratemanage_arg *ai=
  140598. (struct ovectl_ratemanage_arg *)arg;
  140599. if(ai==NULL){
  140600. hi->managed=0;
  140601. }else{
  140602. hi->managed=ai->management_active;
  140603. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  140604. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  140605. }
  140606. }
  140607. return 0;
  140608. case OV_ECTL_RATEMANAGE_AVG:
  140609. {
  140610. struct ovectl_ratemanage_arg *ai=
  140611. (struct ovectl_ratemanage_arg *)arg;
  140612. if(ai==NULL){
  140613. hi->bitrate_av=0;
  140614. }else{
  140615. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  140616. }
  140617. }
  140618. return(0);
  140619. case OV_ECTL_RATEMANAGE_HARD:
  140620. {
  140621. struct ovectl_ratemanage_arg *ai=
  140622. (struct ovectl_ratemanage_arg *)arg;
  140623. if(ai==NULL){
  140624. hi->bitrate_min=0;
  140625. hi->bitrate_max=0;
  140626. }else{
  140627. hi->bitrate_min=ai->bitrate_hard_min;
  140628. hi->bitrate_max=ai->bitrate_hard_max;
  140629. hi->bitrate_reservoir=ai->bitrate_hard_window*
  140630. (hi->bitrate_max+hi->bitrate_min)*.5;
  140631. }
  140632. if(hi->bitrate_reservoir<128.)
  140633. hi->bitrate_reservoir=128.;
  140634. }
  140635. return(0);
  140636. case OV_ECTL_RATEMANAGE2_GET:
  140637. {
  140638. struct ovectl_ratemanage2_arg *ai=
  140639. (struct ovectl_ratemanage2_arg *)arg;
  140640. if(ai==NULL)return OV_EINVAL;
  140641. ai->management_active=hi->managed;
  140642. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  140643. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  140644. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  140645. ai->bitrate_average_damping=hi->bitrate_av_damp;
  140646. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  140647. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  140648. }
  140649. return (0);
  140650. case OV_ECTL_RATEMANAGE2_SET:
  140651. {
  140652. struct ovectl_ratemanage2_arg *ai=
  140653. (struct ovectl_ratemanage2_arg *)arg;
  140654. if(ai==NULL){
  140655. hi->managed=0;
  140656. }else{
  140657. if(ai->bitrate_limit_min_kbps>0 &&
  140658. ai->bitrate_average_kbps>0 &&
  140659. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  140660. return OV_EINVAL;
  140661. if(ai->bitrate_limit_max_kbps>0 &&
  140662. ai->bitrate_average_kbps>0 &&
  140663. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  140664. return OV_EINVAL;
  140665. if(ai->bitrate_limit_min_kbps>0 &&
  140666. ai->bitrate_limit_max_kbps>0 &&
  140667. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  140668. return OV_EINVAL;
  140669. if(ai->bitrate_average_damping <= 0.)
  140670. return OV_EINVAL;
  140671. if(ai->bitrate_limit_reservoir_bits < 0)
  140672. return OV_EINVAL;
  140673. if(ai->bitrate_limit_reservoir_bias < 0.)
  140674. return OV_EINVAL;
  140675. if(ai->bitrate_limit_reservoir_bias > 1.)
  140676. return OV_EINVAL;
  140677. hi->managed=ai->management_active;
  140678. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  140679. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  140680. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  140681. hi->bitrate_av_damp=ai->bitrate_average_damping;
  140682. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  140683. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  140684. }
  140685. }
  140686. return 0;
  140687. case OV_ECTL_LOWPASS_GET:
  140688. {
  140689. double *farg=(double *)arg;
  140690. *farg=hi->lowpass_kHz;
  140691. }
  140692. return(0);
  140693. case OV_ECTL_LOWPASS_SET:
  140694. {
  140695. double *farg=(double *)arg;
  140696. hi->lowpass_kHz=*farg;
  140697. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  140698. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  140699. }
  140700. return(0);
  140701. case OV_ECTL_IBLOCK_GET:
  140702. {
  140703. double *farg=(double *)arg;
  140704. *farg=hi->impulse_noisetune;
  140705. }
  140706. return(0);
  140707. case OV_ECTL_IBLOCK_SET:
  140708. {
  140709. double *farg=(double *)arg;
  140710. hi->impulse_noisetune=*farg;
  140711. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  140712. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  140713. }
  140714. return(0);
  140715. }
  140716. return(OV_EIMPL);
  140717. }
  140718. return(OV_EINVAL);
  140719. }
  140720. #endif
  140721. /*** End of inlined file: vorbisenc.c ***/
  140722. /*** Start of inlined file: vorbisfile.c ***/
  140723. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  140724. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  140725. // tasks..
  140726. #if JUCE_MSVC
  140727. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  140728. #endif
  140729. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  140730. #if JUCE_USE_OGGVORBIS
  140731. #include <stdlib.h>
  140732. #include <stdio.h>
  140733. #include <errno.h>
  140734. #include <string.h>
  140735. #include <math.h>
  140736. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  140737. over 8k gets what they deserve */
  140738. static long _get_data(OggVorbis_File *vf){
  140739. errno=0;
  140740. if(vf->datasource){
  140741. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  140742. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  140743. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  140744. if(bytes==0 && errno)return(-1);
  140745. return(bytes);
  140746. }else
  140747. return(0);
  140748. }
  140749. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  140750. if(vf->datasource){
  140751. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  140752. vf->offset=offset;
  140753. ogg_sync_reset(&vf->oy);
  140754. }else{
  140755. return;
  140756. }
  140757. }
  140758. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  140759. ogg_int64_t boundary){
  140760. if(boundary>0)boundary+=vf->offset;
  140761. while(1){
  140762. long more;
  140763. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  140764. more=ogg_sync_pageseek(&vf->oy,og);
  140765. if(more<0){
  140766. vf->offset-=more;
  140767. }else{
  140768. if(more==0){
  140769. if(!boundary)return(OV_FALSE);
  140770. {
  140771. long ret=_get_data(vf);
  140772. if(ret==0)return(OV_EOF);
  140773. if(ret<0)return(OV_EREAD);
  140774. }
  140775. }else{
  140776. ogg_int64_t ret=vf->offset;
  140777. vf->offset+=more;
  140778. return(ret);
  140779. }
  140780. }
  140781. }
  140782. }
  140783. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  140784. ogg_int64_t begin=vf->offset;
  140785. ogg_int64_t end=begin;
  140786. ogg_int64_t ret;
  140787. ogg_int64_t offset=-1;
  140788. while(offset==-1){
  140789. begin-=CHUNKSIZE;
  140790. if(begin<0)
  140791. begin=0;
  140792. _seek_helper(vf,begin);
  140793. while(vf->offset<end){
  140794. ret=_get_next_page(vf,og,end-vf->offset);
  140795. if(ret==OV_EREAD)return(OV_EREAD);
  140796. if(ret<0){
  140797. break;
  140798. }else{
  140799. offset=ret;
  140800. }
  140801. }
  140802. }
  140803. _seek_helper(vf,offset);
  140804. ret=_get_next_page(vf,og,CHUNKSIZE);
  140805. if(ret<0)
  140806. return(OV_EFAULT);
  140807. return(offset);
  140808. }
  140809. static int _bisect_forward_serialno(OggVorbis_File *vf,
  140810. ogg_int64_t begin,
  140811. ogg_int64_t searched,
  140812. ogg_int64_t end,
  140813. long currentno,
  140814. long m){
  140815. ogg_int64_t endsearched=end;
  140816. ogg_int64_t next=end;
  140817. ogg_page og;
  140818. ogg_int64_t ret;
  140819. while(searched<endsearched){
  140820. ogg_int64_t bisect;
  140821. if(endsearched-searched<CHUNKSIZE){
  140822. bisect=searched;
  140823. }else{
  140824. bisect=(searched+endsearched)/2;
  140825. }
  140826. _seek_helper(vf,bisect);
  140827. ret=_get_next_page(vf,&og,-1);
  140828. if(ret==OV_EREAD)return(OV_EREAD);
  140829. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  140830. endsearched=bisect;
  140831. if(ret>=0)next=ret;
  140832. }else{
  140833. searched=ret+og.header_len+og.body_len;
  140834. }
  140835. }
  140836. _seek_helper(vf,next);
  140837. ret=_get_next_page(vf,&og,-1);
  140838. if(ret==OV_EREAD)return(OV_EREAD);
  140839. if(searched>=end || ret<0){
  140840. vf->links=m+1;
  140841. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  140842. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  140843. vf->offsets[m+1]=searched;
  140844. }else{
  140845. ret=_bisect_forward_serialno(vf,next,vf->offset,
  140846. end,ogg_page_serialno(&og),m+1);
  140847. if(ret==OV_EREAD)return(OV_EREAD);
  140848. }
  140849. vf->offsets[m]=begin;
  140850. vf->serialnos[m]=currentno;
  140851. return(0);
  140852. }
  140853. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  140854. long *serialno,ogg_page *og_ptr){
  140855. ogg_page og;
  140856. ogg_packet op;
  140857. int i,ret;
  140858. if(!og_ptr){
  140859. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  140860. if(llret==OV_EREAD)return(OV_EREAD);
  140861. if(llret<0)return OV_ENOTVORBIS;
  140862. og_ptr=&og;
  140863. }
  140864. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  140865. if(serialno)*serialno=vf->os.serialno;
  140866. vf->ready_state=STREAMSET;
  140867. vorbis_info_init(vi);
  140868. vorbis_comment_init(vc);
  140869. i=0;
  140870. while(i<3){
  140871. ogg_stream_pagein(&vf->os,og_ptr);
  140872. while(i<3){
  140873. int result=ogg_stream_packetout(&vf->os,&op);
  140874. if(result==0)break;
  140875. if(result==-1){
  140876. ret=OV_EBADHEADER;
  140877. goto bail_header;
  140878. }
  140879. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  140880. goto bail_header;
  140881. }
  140882. i++;
  140883. }
  140884. if(i<3)
  140885. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  140886. ret=OV_EBADHEADER;
  140887. goto bail_header;
  140888. }
  140889. }
  140890. return 0;
  140891. bail_header:
  140892. vorbis_info_clear(vi);
  140893. vorbis_comment_clear(vc);
  140894. vf->ready_state=OPENED;
  140895. return ret;
  140896. }
  140897. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  140898. ogg_page og;
  140899. int i;
  140900. ogg_int64_t ret;
  140901. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  140902. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  140903. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  140904. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  140905. for(i=0;i<vf->links;i++){
  140906. if(i==0){
  140907. vf->dataoffsets[i]=dataoffset;
  140908. _seek_helper(vf,dataoffset);
  140909. }else{
  140910. _seek_helper(vf,vf->offsets[i]);
  140911. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  140912. vf->dataoffsets[i]=-1;
  140913. }else{
  140914. vf->dataoffsets[i]=vf->offset;
  140915. }
  140916. }
  140917. if(vf->dataoffsets[i]!=-1){
  140918. ogg_int64_t accumulated=0;
  140919. long lastblock=-1;
  140920. int result;
  140921. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  140922. while(1){
  140923. ogg_packet op;
  140924. ret=_get_next_page(vf,&og,-1);
  140925. if(ret<0)
  140926. break;
  140927. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  140928. break;
  140929. ogg_stream_pagein(&vf->os,&og);
  140930. while((result=ogg_stream_packetout(&vf->os,&op))){
  140931. if(result>0){ /* ignore holes */
  140932. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  140933. if(lastblock!=-1)
  140934. accumulated+=(lastblock+thisblock)>>2;
  140935. lastblock=thisblock;
  140936. }
  140937. }
  140938. if(ogg_page_granulepos(&og)!=-1){
  140939. accumulated= ogg_page_granulepos(&og)-accumulated;
  140940. break;
  140941. }
  140942. }
  140943. if(accumulated<0)accumulated=0;
  140944. vf->pcmlengths[i*2]=accumulated;
  140945. }
  140946. {
  140947. ogg_int64_t end=vf->offsets[i+1];
  140948. _seek_helper(vf,end);
  140949. while(1){
  140950. ret=_get_prev_page(vf,&og);
  140951. if(ret<0){
  140952. vorbis_info_clear(vf->vi+i);
  140953. vorbis_comment_clear(vf->vc+i);
  140954. break;
  140955. }
  140956. if(ogg_page_granulepos(&og)!=-1){
  140957. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  140958. break;
  140959. }
  140960. vf->offset=ret;
  140961. }
  140962. }
  140963. }
  140964. }
  140965. static int _make_decode_ready(OggVorbis_File *vf){
  140966. if(vf->ready_state>STREAMSET)return 0;
  140967. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  140968. if(vf->seekable){
  140969. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  140970. return OV_EBADLINK;
  140971. }else{
  140972. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  140973. return OV_EBADLINK;
  140974. }
  140975. vorbis_block_init(&vf->vd,&vf->vb);
  140976. vf->ready_state=INITSET;
  140977. vf->bittrack=0.f;
  140978. vf->samptrack=0.f;
  140979. return 0;
  140980. }
  140981. static int _open_seekable2(OggVorbis_File *vf){
  140982. long serialno=vf->current_serialno;
  140983. ogg_int64_t dataoffset=vf->offset, end;
  140984. ogg_page og;
  140985. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  140986. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  140987. end=_get_prev_page(vf,&og);
  140988. if(end<0)return(end);
  140989. if(ogg_page_serialno(&og)!=serialno){
  140990. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  140991. }else{
  140992. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  140993. }
  140994. _prefetch_all_headers(vf,dataoffset);
  140995. return(ov_raw_seek(vf,0));
  140996. }
  140997. static void _decode_clear(OggVorbis_File *vf){
  140998. vorbis_dsp_clear(&vf->vd);
  140999. vorbis_block_clear(&vf->vb);
  141000. vf->ready_state=OPENED;
  141001. }
  141002. static int _fetch_and_process_packet(OggVorbis_File *vf,
  141003. ogg_packet *op_in,
  141004. int readp,
  141005. int spanp){
  141006. ogg_page og;
  141007. while(1){
  141008. if(vf->ready_state==INITSET){
  141009. while(1) {
  141010. ogg_packet op;
  141011. ogg_packet *op_ptr=(op_in?op_in:&op);
  141012. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141013. ogg_int64_t granulepos;
  141014. op_in=NULL;
  141015. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141016. if(result>0){
  141017. granulepos=op_ptr->granulepos;
  141018. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141019. header handling. The
  141020. header packets aren't
  141021. audio, so if/when we
  141022. submit them,
  141023. vorbis_synthesis will
  141024. reject them */
  141025. {
  141026. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141027. if(oldsamples)return(OV_EFAULT);
  141028. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141029. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141030. vf->bittrack+=op_ptr->bytes*8;
  141031. }
  141032. if(granulepos!=-1 && !op_ptr->e_o_s){
  141033. int link=(vf->seekable?vf->current_link:0);
  141034. int i,samples;
  141035. if(vf->seekable && link>0)
  141036. granulepos-=vf->pcmlengths[link*2];
  141037. if(granulepos<0)granulepos=0; /* actually, this
  141038. shouldn't be possible
  141039. here unless the stream
  141040. is very broken */
  141041. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141042. granulepos-=samples;
  141043. for(i=0;i<link;i++)
  141044. granulepos+=vf->pcmlengths[i*2+1];
  141045. vf->pcm_offset=granulepos;
  141046. }
  141047. return(1);
  141048. }
  141049. }
  141050. else
  141051. break;
  141052. }
  141053. }
  141054. if(vf->ready_state>=OPENED){
  141055. ogg_int64_t ret;
  141056. if(!readp)return(0);
  141057. if((ret=_get_next_page(vf,&og,-1))<0){
  141058. return(OV_EOF); /* eof.
  141059. leave unitialized */
  141060. }
  141061. vf->bittrack+=og.header_len*8;
  141062. if(vf->ready_state==INITSET){
  141063. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141064. if(!spanp)
  141065. return(OV_EOF);
  141066. _decode_clear(vf);
  141067. if(!vf->seekable){
  141068. vorbis_info_clear(vf->vi);
  141069. vorbis_comment_clear(vf->vc);
  141070. }
  141071. }
  141072. }
  141073. }
  141074. if(vf->ready_state!=INITSET){
  141075. int link;
  141076. if(vf->ready_state<STREAMSET){
  141077. if(vf->seekable){
  141078. vf->current_serialno=ogg_page_serialno(&og);
  141079. for(link=0;link<vf->links;link++)
  141080. if(vf->serialnos[link]==vf->current_serialno)break;
  141081. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141082. stream. error out,
  141083. leave machine
  141084. uninitialized */
  141085. vf->current_link=link;
  141086. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141087. vf->ready_state=STREAMSET;
  141088. }else{
  141089. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141090. if(ret)return(ret);
  141091. vf->current_link++;
  141092. link=0;
  141093. }
  141094. }
  141095. {
  141096. int ret=_make_decode_ready(vf);
  141097. if(ret<0)return ret;
  141098. }
  141099. }
  141100. ogg_stream_pagein(&vf->os,&og);
  141101. }
  141102. }
  141103. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141104. if(f==NULL)return(-1);
  141105. return fseek(f,off,whence);
  141106. }
  141107. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141108. long ibytes, ov_callbacks callbacks){
  141109. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141110. int ret;
  141111. memset(vf,0,sizeof(*vf));
  141112. vf->datasource=f;
  141113. vf->callbacks = callbacks;
  141114. ogg_sync_init(&vf->oy);
  141115. if(initial){
  141116. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141117. memcpy(buffer,initial,ibytes);
  141118. ogg_sync_wrote(&vf->oy,ibytes);
  141119. }
  141120. if(offsettest!=-1)vf->seekable=1;
  141121. vf->links=1;
  141122. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141123. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141124. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141125. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141126. vf->datasource=NULL;
  141127. ov_clear(vf);
  141128. }else
  141129. vf->ready_state=PARTOPEN;
  141130. return(ret);
  141131. }
  141132. static int _ov_open2(OggVorbis_File *vf){
  141133. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141134. vf->ready_state=OPENED;
  141135. if(vf->seekable){
  141136. int ret=_open_seekable2(vf);
  141137. if(ret){
  141138. vf->datasource=NULL;
  141139. ov_clear(vf);
  141140. }
  141141. return(ret);
  141142. }else
  141143. vf->ready_state=STREAMSET;
  141144. return 0;
  141145. }
  141146. int ov_clear(OggVorbis_File *vf){
  141147. if(vf){
  141148. vorbis_block_clear(&vf->vb);
  141149. vorbis_dsp_clear(&vf->vd);
  141150. ogg_stream_clear(&vf->os);
  141151. if(vf->vi && vf->links){
  141152. int i;
  141153. for(i=0;i<vf->links;i++){
  141154. vorbis_info_clear(vf->vi+i);
  141155. vorbis_comment_clear(vf->vc+i);
  141156. }
  141157. _ogg_free(vf->vi);
  141158. _ogg_free(vf->vc);
  141159. }
  141160. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141161. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141162. if(vf->serialnos)_ogg_free(vf->serialnos);
  141163. if(vf->offsets)_ogg_free(vf->offsets);
  141164. ogg_sync_clear(&vf->oy);
  141165. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141166. memset(vf,0,sizeof(*vf));
  141167. }
  141168. #ifdef DEBUG_LEAKS
  141169. _VDBG_dump();
  141170. #endif
  141171. return(0);
  141172. }
  141173. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141174. ov_callbacks callbacks){
  141175. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141176. if(ret)return ret;
  141177. return _ov_open2(vf);
  141178. }
  141179. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141180. ov_callbacks callbacks = {
  141181. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141182. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141183. (int (*)(void *)) fclose,
  141184. (long (*)(void *)) ftell
  141185. };
  141186. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141187. }
  141188. int ov_halfrate(OggVorbis_File *vf,int flag){
  141189. int i;
  141190. if(vf->vi==NULL)return OV_EINVAL;
  141191. if(!vf->seekable)return OV_EINVAL;
  141192. if(vf->ready_state>=STREAMSET)
  141193. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141194. will be able to swap this on the fly, but
  141195. for now dumping the decode machine is needed
  141196. to reinit the MDCT lookups. 1.1 libvorbis
  141197. is planned to be able to switch on the fly */
  141198. for(i=0;i<vf->links;i++){
  141199. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141200. ov_halfrate(vf,0);
  141201. return OV_EINVAL;
  141202. }
  141203. }
  141204. return 0;
  141205. }
  141206. int ov_halfrate_p(OggVorbis_File *vf){
  141207. if(vf->vi==NULL)return OV_EINVAL;
  141208. return vorbis_synthesis_halfrate_p(vf->vi);
  141209. }
  141210. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141211. ov_callbacks callbacks)
  141212. {
  141213. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141214. }
  141215. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141216. ov_callbacks callbacks = {
  141217. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141218. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141219. (int (*)(void *)) fclose,
  141220. (long (*)(void *)) ftell
  141221. };
  141222. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141223. }
  141224. int ov_test_open(OggVorbis_File *vf){
  141225. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141226. return _ov_open2(vf);
  141227. }
  141228. long ov_streams(OggVorbis_File *vf){
  141229. return vf->links;
  141230. }
  141231. long ov_seekable(OggVorbis_File *vf){
  141232. return vf->seekable;
  141233. }
  141234. long ov_bitrate(OggVorbis_File *vf,int i){
  141235. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141236. if(i>=vf->links)return(OV_EINVAL);
  141237. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141238. if(i<0){
  141239. ogg_int64_t bits=0;
  141240. int i;
  141241. float br;
  141242. for(i=0;i<vf->links;i++)
  141243. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141244. br = bits/ov_time_total(vf,-1);
  141245. return(rint(br));
  141246. }else{
  141247. if(vf->seekable){
  141248. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141249. }else{
  141250. if(vf->vi[i].bitrate_nominal>0){
  141251. return vf->vi[i].bitrate_nominal;
  141252. }else{
  141253. if(vf->vi[i].bitrate_upper>0){
  141254. if(vf->vi[i].bitrate_lower>0){
  141255. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141256. }else{
  141257. return vf->vi[i].bitrate_upper;
  141258. }
  141259. }
  141260. return(OV_FALSE);
  141261. }
  141262. }
  141263. }
  141264. }
  141265. long ov_bitrate_instant(OggVorbis_File *vf){
  141266. int link=(vf->seekable?vf->current_link:0);
  141267. long ret;
  141268. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141269. if(vf->samptrack==0)return(OV_FALSE);
  141270. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141271. vf->bittrack=0.f;
  141272. vf->samptrack=0.f;
  141273. return(ret);
  141274. }
  141275. long ov_serialnumber(OggVorbis_File *vf,int i){
  141276. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141277. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141278. if(i<0){
  141279. return(vf->current_serialno);
  141280. }else{
  141281. return(vf->serialnos[i]);
  141282. }
  141283. }
  141284. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141285. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141286. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141287. if(i<0){
  141288. ogg_int64_t acc=0;
  141289. int i;
  141290. for(i=0;i<vf->links;i++)
  141291. acc+=ov_raw_total(vf,i);
  141292. return(acc);
  141293. }else{
  141294. return(vf->offsets[i+1]-vf->offsets[i]);
  141295. }
  141296. }
  141297. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141298. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141299. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141300. if(i<0){
  141301. ogg_int64_t acc=0;
  141302. int i;
  141303. for(i=0;i<vf->links;i++)
  141304. acc+=ov_pcm_total(vf,i);
  141305. return(acc);
  141306. }else{
  141307. return(vf->pcmlengths[i*2+1]);
  141308. }
  141309. }
  141310. double ov_time_total(OggVorbis_File *vf,int i){
  141311. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141312. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141313. if(i<0){
  141314. double acc=0;
  141315. int i;
  141316. for(i=0;i<vf->links;i++)
  141317. acc+=ov_time_total(vf,i);
  141318. return(acc);
  141319. }else{
  141320. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141321. }
  141322. }
  141323. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141324. ogg_stream_state work_os;
  141325. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141326. if(!vf->seekable)
  141327. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141328. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141329. vf->pcm_offset=-1;
  141330. ogg_stream_reset_serialno(&vf->os,
  141331. vf->current_serialno); /* must set serialno */
  141332. vorbis_synthesis_restart(&vf->vd);
  141333. _seek_helper(vf,pos);
  141334. {
  141335. ogg_page og;
  141336. ogg_packet op;
  141337. int lastblock=0;
  141338. int accblock=0;
  141339. int thisblock;
  141340. int eosflag;
  141341. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141342. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141343. return from not necessarily
  141344. starting from the beginning */
  141345. while(1){
  141346. if(vf->ready_state>=STREAMSET){
  141347. int result=ogg_stream_packetout(&work_os,&op);
  141348. if(result>0){
  141349. if(vf->vi[vf->current_link].codec_setup){
  141350. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141351. if(thisblock<0){
  141352. ogg_stream_packetout(&vf->os,NULL);
  141353. thisblock=0;
  141354. }else{
  141355. if(eosflag)
  141356. ogg_stream_packetout(&vf->os,NULL);
  141357. else
  141358. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141359. }
  141360. if(op.granulepos!=-1){
  141361. int i,link=vf->current_link;
  141362. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141363. if(granulepos<0)granulepos=0;
  141364. for(i=0;i<link;i++)
  141365. granulepos+=vf->pcmlengths[i*2+1];
  141366. vf->pcm_offset=granulepos-accblock;
  141367. break;
  141368. }
  141369. lastblock=thisblock;
  141370. continue;
  141371. }else
  141372. ogg_stream_packetout(&vf->os,NULL);
  141373. }
  141374. }
  141375. if(!lastblock){
  141376. if(_get_next_page(vf,&og,-1)<0){
  141377. vf->pcm_offset=ov_pcm_total(vf,-1);
  141378. break;
  141379. }
  141380. }else{
  141381. vf->pcm_offset=-1;
  141382. break;
  141383. }
  141384. if(vf->ready_state>=STREAMSET)
  141385. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141386. _decode_clear(vf); /* clear out stream state */
  141387. ogg_stream_clear(&work_os);
  141388. }
  141389. if(vf->ready_state<STREAMSET){
  141390. int link;
  141391. vf->current_serialno=ogg_page_serialno(&og);
  141392. for(link=0;link<vf->links;link++)
  141393. if(vf->serialnos[link]==vf->current_serialno)break;
  141394. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141395. error out, leave
  141396. machine uninitialized */
  141397. vf->current_link=link;
  141398. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141399. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141400. vf->ready_state=STREAMSET;
  141401. }
  141402. ogg_stream_pagein(&vf->os,&og);
  141403. ogg_stream_pagein(&work_os,&og);
  141404. eosflag=ogg_page_eos(&og);
  141405. }
  141406. }
  141407. ogg_stream_clear(&work_os);
  141408. vf->bittrack=0.f;
  141409. vf->samptrack=0.f;
  141410. return(0);
  141411. seek_error:
  141412. vf->pcm_offset=-1;
  141413. ogg_stream_clear(&work_os);
  141414. _decode_clear(vf);
  141415. return OV_EBADLINK;
  141416. }
  141417. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141418. int link=-1;
  141419. ogg_int64_t result=0;
  141420. ogg_int64_t total=ov_pcm_total(vf,-1);
  141421. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141422. if(!vf->seekable)return(OV_ENOSEEK);
  141423. if(pos<0 || pos>total)return(OV_EINVAL);
  141424. for(link=vf->links-1;link>=0;link--){
  141425. total-=vf->pcmlengths[link*2+1];
  141426. if(pos>=total)break;
  141427. }
  141428. {
  141429. ogg_int64_t end=vf->offsets[link+1];
  141430. ogg_int64_t begin=vf->offsets[link];
  141431. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141432. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141433. ogg_int64_t target=pos-total+begintime;
  141434. ogg_int64_t best=begin;
  141435. ogg_page og;
  141436. while(begin<end){
  141437. ogg_int64_t bisect;
  141438. if(end-begin<CHUNKSIZE){
  141439. bisect=begin;
  141440. }else{
  141441. bisect=begin +
  141442. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141443. if(bisect<=begin)
  141444. bisect=begin+1;
  141445. }
  141446. _seek_helper(vf,bisect);
  141447. while(begin<end){
  141448. result=_get_next_page(vf,&og,end-vf->offset);
  141449. if(result==OV_EREAD) goto seek_error;
  141450. if(result<0){
  141451. if(bisect<=begin+1)
  141452. end=begin; /* found it */
  141453. else{
  141454. if(bisect==0) goto seek_error;
  141455. bisect-=CHUNKSIZE;
  141456. if(bisect<=begin)bisect=begin+1;
  141457. _seek_helper(vf,bisect);
  141458. }
  141459. }else{
  141460. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141461. if(granulepos==-1)continue;
  141462. if(granulepos<target){
  141463. best=result; /* raw offset of packet with granulepos */
  141464. begin=vf->offset; /* raw offset of next page */
  141465. begintime=granulepos;
  141466. if(target-begintime>44100)break;
  141467. bisect=begin; /* *not* begin + 1 */
  141468. }else{
  141469. if(bisect<=begin+1)
  141470. end=begin; /* found it */
  141471. else{
  141472. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141473. end=result;
  141474. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141475. if(bisect<=begin)bisect=begin+1;
  141476. _seek_helper(vf,bisect);
  141477. }else{
  141478. end=result;
  141479. endtime=granulepos;
  141480. break;
  141481. }
  141482. }
  141483. }
  141484. }
  141485. }
  141486. }
  141487. {
  141488. ogg_page og;
  141489. ogg_packet op;
  141490. _seek_helper(vf,best);
  141491. vf->pcm_offset=-1;
  141492. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141493. if(link!=vf->current_link){
  141494. _decode_clear(vf);
  141495. vf->current_link=link;
  141496. vf->current_serialno=ogg_page_serialno(&og);
  141497. vf->ready_state=STREAMSET;
  141498. }else{
  141499. vorbis_synthesis_restart(&vf->vd);
  141500. }
  141501. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141502. ogg_stream_pagein(&vf->os,&og);
  141503. while(1){
  141504. result=ogg_stream_packetpeek(&vf->os,&op);
  141505. if(result==0){
  141506. _seek_helper(vf,best);
  141507. while(1){
  141508. result=_get_prev_page(vf,&og);
  141509. if(result<0) goto seek_error;
  141510. if(ogg_page_granulepos(&og)>-1 ||
  141511. !ogg_page_continued(&og)){
  141512. return ov_raw_seek(vf,result);
  141513. }
  141514. vf->offset=result;
  141515. }
  141516. }
  141517. if(result<0){
  141518. result = OV_EBADPACKET;
  141519. goto seek_error;
  141520. }
  141521. if(op.granulepos!=-1){
  141522. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141523. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141524. vf->pcm_offset+=total;
  141525. break;
  141526. }else
  141527. result=ogg_stream_packetout(&vf->os,NULL);
  141528. }
  141529. }
  141530. }
  141531. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141532. result=OV_EFAULT;
  141533. goto seek_error;
  141534. }
  141535. vf->bittrack=0.f;
  141536. vf->samptrack=0.f;
  141537. return(0);
  141538. seek_error:
  141539. vf->pcm_offset=-1;
  141540. _decode_clear(vf);
  141541. return (int)result;
  141542. }
  141543. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141544. int thisblock,lastblock=0;
  141545. int ret=ov_pcm_seek_page(vf,pos);
  141546. if(ret<0)return(ret);
  141547. if((ret=_make_decode_ready(vf)))return ret;
  141548. while(1){
  141549. ogg_packet op;
  141550. ogg_page og;
  141551. int ret=ogg_stream_packetpeek(&vf->os,&op);
  141552. if(ret>0){
  141553. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141554. if(thisblock<0){
  141555. ogg_stream_packetout(&vf->os,NULL);
  141556. continue; /* non audio packet */
  141557. }
  141558. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  141559. if(vf->pcm_offset+((thisblock+
  141560. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  141561. ogg_stream_packetout(&vf->os,NULL);
  141562. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  141563. only tracking, no
  141564. pcm_decode */
  141565. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141566. if(op.granulepos>-1){
  141567. int i;
  141568. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141569. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141570. for(i=0;i<vf->current_link;i++)
  141571. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  141572. }
  141573. lastblock=thisblock;
  141574. }else{
  141575. if(ret<0 && ret!=OV_HOLE)break;
  141576. if(_get_next_page(vf,&og,-1)<0)break;
  141577. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  141578. if(vf->ready_state<STREAMSET){
  141579. int link;
  141580. vf->current_serialno=ogg_page_serialno(&og);
  141581. for(link=0;link<vf->links;link++)
  141582. if(vf->serialnos[link]==vf->current_serialno)break;
  141583. if(link==vf->links)return(OV_EBADLINK);
  141584. vf->current_link=link;
  141585. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141586. vf->ready_state=STREAMSET;
  141587. ret=_make_decode_ready(vf);
  141588. if(ret)return ret;
  141589. lastblock=0;
  141590. }
  141591. ogg_stream_pagein(&vf->os,&og);
  141592. }
  141593. }
  141594. vf->bittrack=0.f;
  141595. vf->samptrack=0.f;
  141596. while(vf->pcm_offset<pos){
  141597. ogg_int64_t target=pos-vf->pcm_offset;
  141598. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141599. if(samples>target)samples=target;
  141600. vorbis_synthesis_read(&vf->vd,samples);
  141601. vf->pcm_offset+=samples;
  141602. if(samples<target)
  141603. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  141604. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  141605. }
  141606. return 0;
  141607. }
  141608. int ov_time_seek(OggVorbis_File *vf,double seconds){
  141609. int link=-1;
  141610. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141611. double time_total=ov_time_total(vf,-1);
  141612. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141613. if(!vf->seekable)return(OV_ENOSEEK);
  141614. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141615. for(link=vf->links-1;link>=0;link--){
  141616. pcm_total-=vf->pcmlengths[link*2+1];
  141617. time_total-=ov_time_total(vf,link);
  141618. if(seconds>=time_total)break;
  141619. }
  141620. {
  141621. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141622. return(ov_pcm_seek(vf,target));
  141623. }
  141624. }
  141625. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  141626. int link=-1;
  141627. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141628. double time_total=ov_time_total(vf,-1);
  141629. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141630. if(!vf->seekable)return(OV_ENOSEEK);
  141631. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141632. for(link=vf->links-1;link>=0;link--){
  141633. pcm_total-=vf->pcmlengths[link*2+1];
  141634. time_total-=ov_time_total(vf,link);
  141635. if(seconds>=time_total)break;
  141636. }
  141637. {
  141638. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141639. return(ov_pcm_seek_page(vf,target));
  141640. }
  141641. }
  141642. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  141643. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141644. return(vf->offset);
  141645. }
  141646. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  141647. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141648. return(vf->pcm_offset);
  141649. }
  141650. double ov_time_tell(OggVorbis_File *vf){
  141651. int link=0;
  141652. ogg_int64_t pcm_total=0;
  141653. double time_total=0.f;
  141654. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141655. if(vf->seekable){
  141656. pcm_total=ov_pcm_total(vf,-1);
  141657. time_total=ov_time_total(vf,-1);
  141658. for(link=vf->links-1;link>=0;link--){
  141659. pcm_total-=vf->pcmlengths[link*2+1];
  141660. time_total-=ov_time_total(vf,link);
  141661. if(vf->pcm_offset>=pcm_total)break;
  141662. }
  141663. }
  141664. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  141665. }
  141666. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  141667. if(vf->seekable){
  141668. if(link<0)
  141669. if(vf->ready_state>=STREAMSET)
  141670. return vf->vi+vf->current_link;
  141671. else
  141672. return vf->vi;
  141673. else
  141674. if(link>=vf->links)
  141675. return NULL;
  141676. else
  141677. return vf->vi+link;
  141678. }else{
  141679. return vf->vi;
  141680. }
  141681. }
  141682. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  141683. if(vf->seekable){
  141684. if(link<0)
  141685. if(vf->ready_state>=STREAMSET)
  141686. return vf->vc+vf->current_link;
  141687. else
  141688. return vf->vc;
  141689. else
  141690. if(link>=vf->links)
  141691. return NULL;
  141692. else
  141693. return vf->vc+link;
  141694. }else{
  141695. return vf->vc;
  141696. }
  141697. }
  141698. static int host_is_big_endian() {
  141699. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  141700. unsigned char *bytewise = (unsigned char *)&pattern;
  141701. if (bytewise[0] == 0xfe) return 1;
  141702. return 0;
  141703. }
  141704. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  141705. int bigendianp,int word,int sgned,int *bitstream){
  141706. int i,j;
  141707. int host_endian = host_is_big_endian();
  141708. float **pcm;
  141709. long samples;
  141710. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141711. while(1){
  141712. if(vf->ready_state==INITSET){
  141713. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141714. if(samples)break;
  141715. }
  141716. {
  141717. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141718. if(ret==OV_EOF)
  141719. return(0);
  141720. if(ret<=0)
  141721. return(ret);
  141722. }
  141723. }
  141724. if(samples>0){
  141725. long channels=ov_info(vf,-1)->channels;
  141726. long bytespersample=word * channels;
  141727. vorbis_fpu_control fpu;
  141728. (void) fpu; // (to avoid a warning about it being unused)
  141729. if(samples>length/bytespersample)samples=length/bytespersample;
  141730. if(samples <= 0)
  141731. return OV_EINVAL;
  141732. {
  141733. int val;
  141734. if(word==1){
  141735. int off=(sgned?0:128);
  141736. vorbis_fpu_setround(&fpu);
  141737. for(j=0;j<samples;j++)
  141738. for(i=0;i<channels;i++){
  141739. val=vorbis_ftoi(pcm[i][j]*128.f);
  141740. if(val>127)val=127;
  141741. else if(val<-128)val=-128;
  141742. *buffer++=val+off;
  141743. }
  141744. vorbis_fpu_restore(fpu);
  141745. }else{
  141746. int off=(sgned?0:32768);
  141747. if(host_endian==bigendianp){
  141748. if(sgned){
  141749. vorbis_fpu_setround(&fpu);
  141750. for(i=0;i<channels;i++) { /* It's faster in this order */
  141751. float *src=pcm[i];
  141752. short *dest=((short *)buffer)+i;
  141753. for(j=0;j<samples;j++) {
  141754. val=vorbis_ftoi(src[j]*32768.f);
  141755. if(val>32767)val=32767;
  141756. else if(val<-32768)val=-32768;
  141757. *dest=val;
  141758. dest+=channels;
  141759. }
  141760. }
  141761. vorbis_fpu_restore(fpu);
  141762. }else{
  141763. vorbis_fpu_setround(&fpu);
  141764. for(i=0;i<channels;i++) {
  141765. float *src=pcm[i];
  141766. short *dest=((short *)buffer)+i;
  141767. for(j=0;j<samples;j++) {
  141768. val=vorbis_ftoi(src[j]*32768.f);
  141769. if(val>32767)val=32767;
  141770. else if(val<-32768)val=-32768;
  141771. *dest=val+off;
  141772. dest+=channels;
  141773. }
  141774. }
  141775. vorbis_fpu_restore(fpu);
  141776. }
  141777. }else if(bigendianp){
  141778. vorbis_fpu_setround(&fpu);
  141779. for(j=0;j<samples;j++)
  141780. for(i=0;i<channels;i++){
  141781. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141782. if(val>32767)val=32767;
  141783. else if(val<-32768)val=-32768;
  141784. val+=off;
  141785. *buffer++=(val>>8);
  141786. *buffer++=(val&0xff);
  141787. }
  141788. vorbis_fpu_restore(fpu);
  141789. }else{
  141790. int val;
  141791. vorbis_fpu_setround(&fpu);
  141792. for(j=0;j<samples;j++)
  141793. for(i=0;i<channels;i++){
  141794. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141795. if(val>32767)val=32767;
  141796. else if(val<-32768)val=-32768;
  141797. val+=off;
  141798. *buffer++=(val&0xff);
  141799. *buffer++=(val>>8);
  141800. }
  141801. vorbis_fpu_restore(fpu);
  141802. }
  141803. }
  141804. }
  141805. vorbis_synthesis_read(&vf->vd,samples);
  141806. vf->pcm_offset+=samples;
  141807. if(bitstream)*bitstream=vf->current_link;
  141808. return(samples*bytespersample);
  141809. }else{
  141810. return(samples);
  141811. }
  141812. }
  141813. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  141814. int *bitstream){
  141815. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141816. while(1){
  141817. if(vf->ready_state==INITSET){
  141818. float **pcm;
  141819. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141820. if(samples){
  141821. if(pcm_channels)*pcm_channels=pcm;
  141822. if(samples>length)samples=length;
  141823. vorbis_synthesis_read(&vf->vd,samples);
  141824. vf->pcm_offset+=samples;
  141825. if(bitstream)*bitstream=vf->current_link;
  141826. return samples;
  141827. }
  141828. }
  141829. {
  141830. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141831. if(ret==OV_EOF)return(0);
  141832. if(ret<=0)return(ret);
  141833. }
  141834. }
  141835. }
  141836. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  141837. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  141838. ogg_int64_t off);
  141839. static void _ov_splice(float **pcm,float **lappcm,
  141840. int n1, int n2,
  141841. int ch1, int ch2,
  141842. float *w1, float *w2){
  141843. int i,j;
  141844. float *w=w1;
  141845. int n=n1;
  141846. if(n1>n2){
  141847. n=n2;
  141848. w=w2;
  141849. }
  141850. for(j=0;j<ch1 && j<ch2;j++){
  141851. float *s=lappcm[j];
  141852. float *d=pcm[j];
  141853. for(i=0;i<n;i++){
  141854. float wd=w[i]*w[i];
  141855. float ws=1.-wd;
  141856. d[i]=d[i]*wd + s[i]*ws;
  141857. }
  141858. }
  141859. for(;j<ch2;j++){
  141860. float *d=pcm[j];
  141861. for(i=0;i<n;i++){
  141862. float wd=w[i]*w[i];
  141863. d[i]=d[i]*wd;
  141864. }
  141865. }
  141866. }
  141867. static int _ov_initset(OggVorbis_File *vf){
  141868. while(1){
  141869. if(vf->ready_state==INITSET)break;
  141870. {
  141871. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141872. if(ret<0 && ret!=OV_HOLE)return(ret);
  141873. }
  141874. }
  141875. return 0;
  141876. }
  141877. static int _ov_initprime(OggVorbis_File *vf){
  141878. vorbis_dsp_state *vd=&vf->vd;
  141879. while(1){
  141880. if(vf->ready_state==INITSET)
  141881. if(vorbis_synthesis_pcmout(vd,NULL))break;
  141882. {
  141883. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141884. if(ret<0 && ret!=OV_HOLE)return(ret);
  141885. }
  141886. }
  141887. return 0;
  141888. }
  141889. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  141890. float **lappcm,int lapsize){
  141891. int lapcount=0,i;
  141892. float **pcm;
  141893. while(lapcount<lapsize){
  141894. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  141895. if(samples){
  141896. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141897. for(i=0;i<vi->channels;i++)
  141898. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141899. lapcount+=samples;
  141900. vorbis_synthesis_read(vd,samples);
  141901. }else{
  141902. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  141903. if(ret==OV_EOF)break;
  141904. }
  141905. }
  141906. if(lapcount<lapsize){
  141907. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  141908. if(samples==0){
  141909. for(i=0;i<vi->channels;i++)
  141910. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  141911. lapcount=lapsize;
  141912. }else{
  141913. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141914. for(i=0;i<vi->channels;i++)
  141915. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141916. lapcount+=samples;
  141917. }
  141918. }
  141919. }
  141920. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  141921. vorbis_info *vi1,*vi2;
  141922. float **lappcm;
  141923. float **pcm;
  141924. float *w1,*w2;
  141925. int n1,n2,i,ret,hs1,hs2;
  141926. if(vf1==vf2)return(0); /* degenerate case */
  141927. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  141928. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  141929. ret=_ov_initset(vf1);
  141930. if(ret)return(ret);
  141931. ret=_ov_initprime(vf2);
  141932. if(ret)return(ret);
  141933. vi1=ov_info(vf1,-1);
  141934. vi2=ov_info(vf2,-1);
  141935. hs1=ov_halfrate_p(vf1);
  141936. hs2=ov_halfrate_p(vf2);
  141937. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  141938. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  141939. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  141940. w1=vorbis_window(&vf1->vd,0);
  141941. w2=vorbis_window(&vf2->vd,0);
  141942. for(i=0;i<vi1->channels;i++)
  141943. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141944. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  141945. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  141946. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  141947. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  141948. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  141949. return(0);
  141950. }
  141951. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  141952. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  141953. vorbis_info *vi;
  141954. float **lappcm;
  141955. float **pcm;
  141956. float *w1,*w2;
  141957. int n1,n2,ch1,ch2,hs;
  141958. int i,ret;
  141959. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141960. ret=_ov_initset(vf);
  141961. if(ret)return(ret);
  141962. vi=ov_info(vf,-1);
  141963. hs=ov_halfrate_p(vf);
  141964. ch1=vi->channels;
  141965. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  141966. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  141967. persistent; even if the decode state
  141968. from this link gets dumped, this
  141969. window array continues to exist */
  141970. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  141971. for(i=0;i<ch1;i++)
  141972. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141973. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  141974. ret=localseek(vf,pos);
  141975. if(ret)return ret;
  141976. ret=_ov_initprime(vf);
  141977. if(ret)return(ret);
  141978. vi=ov_info(vf,-1);
  141979. ch2=vi->channels;
  141980. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  141981. w2=vorbis_window(&vf->vd,0);
  141982. vorbis_synthesis_lapout(&vf->vd,&pcm);
  141983. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  141984. return(0);
  141985. }
  141986. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141987. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  141988. }
  141989. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141990. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  141991. }
  141992. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141993. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  141994. }
  141995. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  141996. int (*localseek)(OggVorbis_File *,double)){
  141997. vorbis_info *vi;
  141998. float **lappcm;
  141999. float **pcm;
  142000. float *w1,*w2;
  142001. int n1,n2,ch1,ch2,hs;
  142002. int i,ret;
  142003. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142004. ret=_ov_initset(vf);
  142005. if(ret)return(ret);
  142006. vi=ov_info(vf,-1);
  142007. hs=ov_halfrate_p(vf);
  142008. ch1=vi->channels;
  142009. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142010. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142011. persistent; even if the decode state
  142012. from this link gets dumped, this
  142013. window array continues to exist */
  142014. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142015. for(i=0;i<ch1;i++)
  142016. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142017. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142018. ret=localseek(vf,pos);
  142019. if(ret)return ret;
  142020. ret=_ov_initprime(vf);
  142021. if(ret)return(ret);
  142022. vi=ov_info(vf,-1);
  142023. ch2=vi->channels;
  142024. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142025. w2=vorbis_window(&vf->vd,0);
  142026. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142027. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142028. return(0);
  142029. }
  142030. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142031. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142032. }
  142033. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142034. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142035. }
  142036. #endif
  142037. /*** End of inlined file: vorbisfile.c ***/
  142038. /*** Start of inlined file: window.c ***/
  142039. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  142040. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142041. // tasks..
  142042. #if JUCE_MSVC
  142043. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142044. #endif
  142045. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  142046. #if JUCE_USE_OGGVORBIS
  142047. #include <stdlib.h>
  142048. #include <math.h>
  142049. static float vwin64[32] = {
  142050. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142051. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142052. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142053. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142054. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142055. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142056. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142057. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142058. };
  142059. static float vwin128[64] = {
  142060. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142061. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142062. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142063. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142064. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142065. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142066. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142067. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142068. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142069. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142070. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142071. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142072. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142073. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142074. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142075. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142076. };
  142077. static float vwin256[128] = {
  142078. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142079. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142080. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142081. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142082. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142083. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142084. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142085. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142086. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142087. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142088. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142089. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142090. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142091. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142092. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142093. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142094. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142095. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142096. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142097. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142098. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142099. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142100. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142101. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142102. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142103. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142104. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142105. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142106. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142107. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142108. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142109. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142110. };
  142111. static float vwin512[256] = {
  142112. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142113. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142114. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142115. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142116. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142117. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142118. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142119. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142120. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142121. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142122. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142123. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142124. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142125. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142126. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142127. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142128. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142129. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142130. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142131. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142132. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142133. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142134. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142135. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142136. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142137. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142138. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142139. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142140. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142141. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142142. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142143. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142144. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142145. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142146. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142147. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142148. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142149. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142150. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142151. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142152. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142153. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142154. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142155. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142156. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142157. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142158. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142159. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142160. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142161. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142162. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142163. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142164. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142165. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142166. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142167. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142168. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142169. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142170. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142171. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142172. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142173. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142174. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142175. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142176. };
  142177. static float vwin1024[512] = {
  142178. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142179. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142180. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142181. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142182. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142183. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142184. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142185. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142186. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142187. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142188. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142189. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142190. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142191. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142192. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142193. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142194. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142195. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142196. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142197. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142198. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142199. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142200. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142201. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142202. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142203. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142204. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142205. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142206. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142207. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142208. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142209. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142210. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142211. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142212. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142213. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142214. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142215. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142216. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142217. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142218. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142219. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142220. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142221. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142222. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142223. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142224. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142225. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142226. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142227. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142228. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142229. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142230. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142231. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142232. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142233. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142234. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142235. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142236. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142237. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142238. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142239. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142240. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142241. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142242. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142243. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142244. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142245. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142246. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142247. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142248. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142249. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142250. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142251. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142252. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142253. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142254. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142255. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142256. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142257. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142258. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142259. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142260. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142261. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142262. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142263. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142264. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142265. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142266. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142267. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142268. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142269. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142270. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142271. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142272. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142273. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142274. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142275. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142276. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142277. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142278. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142279. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142280. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142281. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142282. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142283. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142284. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142285. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142286. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142287. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142288. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142289. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142290. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142291. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142292. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142293. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142294. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142295. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142296. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142297. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142298. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142299. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142300. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142301. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142302. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142303. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142304. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142305. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142306. };
  142307. static float vwin2048[1024] = {
  142308. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142309. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142310. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142311. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142312. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142313. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142314. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142315. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142316. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142317. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142318. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142319. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142320. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142321. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142322. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142323. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142324. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142325. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142326. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142327. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142328. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142329. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142330. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142331. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142332. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142333. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142334. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142335. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142336. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142337. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142338. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142339. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142340. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142341. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142342. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142343. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142344. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142345. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142346. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142347. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142348. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142349. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142350. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142351. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142352. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142353. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142354. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142355. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142356. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142357. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142358. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142359. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142360. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142361. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142362. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142363. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142364. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142365. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142366. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142367. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142368. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142369. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142370. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142371. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142372. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142373. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142374. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142375. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142376. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142377. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142378. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142379. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142380. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142381. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142382. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142383. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142384. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142385. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142386. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142387. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142388. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142389. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142390. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142391. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142392. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142393. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142394. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142395. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142396. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142397. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142398. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142399. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142400. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142401. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142402. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142403. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142404. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142405. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142406. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142407. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142408. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142409. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142410. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142411. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142412. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142413. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142414. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142415. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142416. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142417. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142418. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142419. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142420. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142421. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142422. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142423. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142424. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142425. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142426. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142427. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142428. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142429. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142430. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142431. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142432. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142433. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142434. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142435. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142436. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142437. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142438. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142439. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142440. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142441. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142442. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142443. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142444. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142445. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142446. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142447. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142448. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142449. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142450. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142451. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142452. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142453. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142454. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142455. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142456. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142457. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142458. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142459. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142460. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142461. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142462. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142463. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142464. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142465. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142466. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142467. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142468. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142469. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142470. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142471. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142472. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142473. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142474. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142475. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142476. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142477. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142478. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142479. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142480. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142481. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142482. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142483. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142484. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142485. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142486. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142487. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142488. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142489. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142490. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142491. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142492. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142493. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142494. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142495. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142496. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142497. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142498. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142499. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142500. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142501. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142502. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142503. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142504. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142505. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142506. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142507. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142508. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142509. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142510. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142511. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142512. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142513. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142514. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142515. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142516. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142517. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142518. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142519. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142520. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142521. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142522. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142523. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142524. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142525. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142526. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142527. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142528. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142529. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142530. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142531. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142532. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142533. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142534. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  142535. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  142536. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  142537. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  142538. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  142539. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  142540. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  142541. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  142542. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  142543. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  142544. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  142545. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  142546. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  142547. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  142548. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  142549. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  142550. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  142551. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  142552. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  142553. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  142554. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  142555. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  142556. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  142557. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  142558. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  142559. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  142560. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  142561. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  142562. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  142563. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  142564. };
  142565. static float vwin4096[2048] = {
  142566. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  142567. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  142568. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  142569. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  142570. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  142571. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  142572. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  142573. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  142574. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  142575. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  142576. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  142577. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  142578. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  142579. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  142580. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  142581. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  142582. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  142583. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  142584. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  142585. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  142586. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  142587. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  142588. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  142589. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  142590. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  142591. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  142592. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  142593. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  142594. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  142595. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  142596. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  142597. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  142598. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  142599. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  142600. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  142601. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  142602. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  142603. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  142604. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  142605. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  142606. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  142607. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  142608. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  142609. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  142610. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  142611. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  142612. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  142613. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  142614. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  142615. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  142616. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  142617. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  142618. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  142619. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  142620. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  142621. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  142622. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  142623. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  142624. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  142625. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  142626. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  142627. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  142628. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  142629. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  142630. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  142631. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  142632. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  142633. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  142634. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  142635. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  142636. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  142637. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  142638. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  142639. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  142640. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  142641. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  142642. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  142643. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  142644. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  142645. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  142646. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  142647. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  142648. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  142649. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  142650. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  142651. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  142652. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  142653. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  142654. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  142655. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  142656. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  142657. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  142658. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  142659. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  142660. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  142661. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  142662. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  142663. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  142664. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  142665. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  142666. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  142667. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  142668. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  142669. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  142670. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  142671. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  142672. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  142673. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  142674. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  142675. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  142676. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  142677. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  142678. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  142679. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  142680. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  142681. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  142682. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  142683. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  142684. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  142685. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  142686. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  142687. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  142688. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  142689. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  142690. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  142691. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  142692. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  142693. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  142694. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  142695. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  142696. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  142697. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  142698. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  142699. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  142700. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  142701. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  142702. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  142703. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  142704. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  142705. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  142706. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  142707. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  142708. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  142709. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  142710. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  142711. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  142712. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  142713. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  142714. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  142715. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  142716. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  142717. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  142718. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  142719. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  142720. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  142721. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  142722. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  142723. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  142724. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  142725. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  142726. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  142727. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  142728. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  142729. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  142730. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  142731. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  142732. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  142733. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  142734. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  142735. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  142736. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  142737. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  142738. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  142739. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  142740. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  142741. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  142742. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  142743. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  142744. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  142745. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  142746. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  142747. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  142748. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  142749. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  142750. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  142751. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  142752. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  142753. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  142754. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  142755. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  142756. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  142757. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  142758. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  142759. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  142760. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  142761. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  142762. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  142763. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  142764. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  142765. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  142766. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  142767. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  142768. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  142769. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  142770. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  142771. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  142772. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  142773. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  142774. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  142775. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  142776. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  142777. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  142778. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  142779. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  142780. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  142781. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  142782. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  142783. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  142784. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  142785. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  142786. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  142787. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  142788. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  142789. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  142790. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  142791. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  142792. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  142793. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  142794. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  142795. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  142796. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  142797. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  142798. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  142799. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  142800. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  142801. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  142802. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  142803. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  142804. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  142805. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  142806. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  142807. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  142808. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  142809. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  142810. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  142811. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  142812. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  142813. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  142814. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  142815. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  142816. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  142817. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  142818. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  142819. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  142820. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  142821. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  142822. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  142823. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  142824. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  142825. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  142826. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  142827. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  142828. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  142829. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  142830. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  142831. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  142832. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  142833. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  142834. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  142835. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  142836. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  142837. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  142838. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  142839. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  142840. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  142841. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  142842. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  142843. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  142844. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  142845. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  142846. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  142847. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  142848. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  142849. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  142850. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  142851. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  142852. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  142853. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  142854. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  142855. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  142856. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  142857. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  142858. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  142859. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  142860. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  142861. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  142862. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  142863. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  142864. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  142865. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  142866. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  142867. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  142868. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  142869. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  142870. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  142871. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  142872. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  142873. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  142874. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  142875. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  142876. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  142877. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  142878. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  142879. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  142880. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  142881. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  142882. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  142883. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  142884. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  142885. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  142886. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  142887. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  142888. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  142889. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  142890. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  142891. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  142892. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  142893. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  142894. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  142895. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  142896. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  142897. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  142898. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  142899. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  142900. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  142901. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  142902. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  142903. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  142904. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  142905. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  142906. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  142907. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  142908. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  142909. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  142910. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  142911. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  142912. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  142913. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  142914. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  142915. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  142916. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  142917. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  142918. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  142919. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  142920. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  142921. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  142922. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  142923. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  142924. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  142925. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  142926. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  142927. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  142928. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  142929. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  142930. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  142931. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  142932. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  142933. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  142934. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  142935. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  142936. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  142937. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  142938. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  142939. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  142940. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  142941. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  142942. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  142943. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  142944. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  142945. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  142946. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  142947. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  142948. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  142949. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  142950. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  142951. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  142952. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  142953. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  142954. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  142955. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  142956. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  142957. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  142958. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  142959. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  142960. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  142961. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  142962. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  142963. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  142964. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  142965. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  142966. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  142967. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  142968. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  142969. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  142970. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  142971. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  142972. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  142973. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  142974. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  142975. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  142976. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  142977. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  142978. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  142979. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  142980. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  142981. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  142982. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  142983. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  142984. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  142985. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  142986. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  142987. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  142988. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  142989. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  142990. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  142991. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  142992. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  142993. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  142994. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  142995. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  142996. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  142997. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  142998. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  142999. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  143000. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  143001. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  143002. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  143003. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  143004. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  143005. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  143006. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  143007. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  143008. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  143009. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  143010. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143011. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143012. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143013. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143014. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143015. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143016. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143017. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143018. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143019. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143020. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143021. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143022. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143023. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143024. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143025. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143026. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143027. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143028. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143029. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143030. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143031. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143032. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143033. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143034. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143035. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143036. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143037. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143038. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143039. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143040. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143041. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143042. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143043. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143044. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143045. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143046. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143047. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143048. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143049. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143050. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143051. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143052. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143053. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143054. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143055. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143056. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143057. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143058. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143059. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143060. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143061. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143062. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143063. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143064. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143065. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143066. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143067. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143068. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143069. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143070. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143071. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143072. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143073. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143074. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143075. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143076. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143077. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143078. };
  143079. static float vwin8192[4096] = {
  143080. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143081. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143082. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143083. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143084. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143085. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143086. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143087. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143088. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143089. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143090. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143091. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143092. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143093. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143094. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143095. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143096. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143097. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143098. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143099. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143100. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143101. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143102. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143103. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143104. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143105. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143106. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143107. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143108. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143109. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143110. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143111. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143112. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143113. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143114. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143115. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143116. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143117. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143118. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143119. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143120. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143121. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143122. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143123. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143124. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143125. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143126. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143127. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143128. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143129. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143130. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143131. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143132. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143133. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143134. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143135. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143136. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143137. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143138. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143139. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143140. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143141. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143142. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143143. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143144. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143145. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143146. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143147. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143148. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143149. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143150. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143151. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143152. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143153. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143154. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143155. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143156. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143157. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143158. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143159. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143160. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143161. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143162. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143163. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143164. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143165. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143166. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143167. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143168. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143169. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143170. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143171. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143172. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143173. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143174. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143175. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143176. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143177. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143178. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143179. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143180. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143181. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143182. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143183. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143184. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143185. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143186. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143187. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143188. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143189. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143190. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143191. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143192. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143193. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143194. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143195. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143196. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143197. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143198. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143199. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143200. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143201. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143202. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143203. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143204. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143205. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143206. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143207. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143208. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143209. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143210. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143211. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143212. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143213. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143214. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143215. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143216. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143217. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143218. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143219. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143220. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143221. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143222. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143223. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143224. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143225. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143226. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143227. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143228. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143229. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143230. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143231. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143232. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143233. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143234. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143235. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143236. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143237. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143238. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143239. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143240. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143241. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143242. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143243. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143244. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143245. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143246. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143247. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143248. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143249. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143250. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143251. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143252. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143253. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143254. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143255. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143256. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143257. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143258. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143259. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143260. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143261. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143262. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143263. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143264. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143265. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143266. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143267. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143268. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143269. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143270. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143271. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143272. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143273. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143274. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143275. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143276. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143277. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143278. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143279. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143280. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143281. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143282. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143283. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143284. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143285. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143286. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143287. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143288. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143289. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143290. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143291. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143292. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143293. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143294. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143295. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143296. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143297. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143298. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143299. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143300. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143301. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143302. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143303. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143304. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143305. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143306. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143307. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143308. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143309. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143310. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143311. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143312. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143313. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143314. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143315. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143316. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143317. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143318. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143319. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143320. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143321. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143322. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143323. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143324. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143325. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143326. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143327. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143328. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143329. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143330. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143331. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143332. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143333. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143334. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143335. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143336. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143337. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143338. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143339. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143340. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143341. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143342. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143343. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143344. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143345. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143346. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143347. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143348. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143349. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143350. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143351. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143352. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143353. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143354. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143355. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143356. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143357. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143358. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143359. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143360. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143361. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143362. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143363. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143364. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143365. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143366. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143367. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143368. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143369. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143370. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143371. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143372. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143373. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143374. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143375. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143376. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143377. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143378. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143379. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143380. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143381. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143382. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143383. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143384. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143385. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143386. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143387. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143388. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143389. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143390. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143391. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143392. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143393. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143394. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143395. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143396. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143397. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143398. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143399. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143400. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143401. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143402. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143403. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143404. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143405. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143406. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143407. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143408. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143409. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143410. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143411. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143412. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143413. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143414. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143415. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143416. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143417. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143418. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143419. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143420. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143421. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143422. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143423. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143424. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143425. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143426. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143427. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143428. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143429. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143430. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143431. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143432. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143433. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143434. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143435. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143436. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143437. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143438. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143439. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143440. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143441. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143442. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143443. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143444. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143445. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143446. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143447. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143448. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143449. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143450. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143451. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143452. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143453. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143454. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143455. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143456. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143457. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143458. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143459. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143460. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143461. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143462. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143463. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143464. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143465. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143466. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143467. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143468. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143469. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143470. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143471. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143472. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143473. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143474. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143475. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143476. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143477. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143478. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143479. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143480. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143481. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143482. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143483. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143484. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143485. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143486. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143487. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143488. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143489. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143490. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143491. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143492. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143493. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143494. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143495. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143496. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143497. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143498. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143499. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143500. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143501. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143502. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143503. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143504. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143505. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143506. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143507. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143508. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143509. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143510. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143511. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143512. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143513. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143514. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143515. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143516. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143517. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143518. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143519. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143520. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143521. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143522. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143523. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143524. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143525. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143526. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143527. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143528. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143529. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143530. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143531. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143532. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143533. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143534. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  143535. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  143536. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  143537. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  143538. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  143539. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  143540. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  143541. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  143542. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  143543. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  143544. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  143545. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  143546. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  143547. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  143548. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  143549. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  143550. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  143551. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  143552. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  143553. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  143554. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  143555. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  143556. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  143557. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  143558. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  143559. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  143560. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  143561. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  143562. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  143563. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  143564. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  143565. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  143566. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  143567. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  143568. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  143569. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  143570. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  143571. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  143572. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  143573. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  143574. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  143575. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  143576. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  143577. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  143578. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  143579. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  143580. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  143581. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  143582. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  143583. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  143584. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  143585. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  143586. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  143587. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  143588. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  143589. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  143590. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  143591. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  143592. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  143593. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  143594. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  143595. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  143596. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  143597. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  143598. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  143599. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  143600. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  143601. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  143602. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  143603. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  143604. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  143605. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  143606. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  143607. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  143608. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  143609. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  143610. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  143611. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  143612. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  143613. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  143614. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  143615. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  143616. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  143617. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  143618. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  143619. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  143620. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  143621. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  143622. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  143623. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  143624. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  143625. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  143626. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  143627. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  143628. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  143629. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  143630. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  143631. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  143632. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  143633. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  143634. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  143635. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  143636. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  143637. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  143638. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  143639. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  143640. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  143641. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  143642. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  143643. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  143644. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  143645. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  143646. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  143647. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  143648. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  143649. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  143650. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  143651. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  143652. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  143653. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  143654. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  143655. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  143656. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  143657. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  143658. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  143659. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  143660. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  143661. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  143662. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  143663. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  143664. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  143665. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  143666. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  143667. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  143668. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  143669. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  143670. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  143671. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  143672. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  143673. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  143674. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  143675. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  143676. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  143677. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  143678. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  143679. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  143680. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  143681. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  143682. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  143683. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  143684. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  143685. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  143686. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  143687. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  143688. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  143689. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  143690. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  143691. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  143692. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  143693. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  143694. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  143695. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  143696. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  143697. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  143698. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  143699. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  143700. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  143701. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  143702. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  143703. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  143704. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  143705. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  143706. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  143707. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  143708. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  143709. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  143710. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  143711. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  143712. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  143713. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  143714. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  143715. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  143716. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  143717. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  143718. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  143719. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  143720. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  143721. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  143722. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  143723. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  143724. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  143725. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  143726. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  143727. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  143728. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  143729. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  143730. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  143731. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  143732. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  143733. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  143734. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  143735. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  143736. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  143737. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  143738. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  143739. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  143740. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  143741. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  143742. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  143743. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  143744. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  143745. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  143746. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  143747. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  143748. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  143749. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  143750. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  143751. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  143752. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  143753. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  143754. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  143755. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  143756. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  143757. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  143758. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  143759. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  143760. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  143761. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  143762. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  143763. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  143764. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  143765. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  143766. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  143767. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  143768. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  143769. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  143770. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  143771. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  143772. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  143773. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  143774. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  143775. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  143776. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  143777. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  143778. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  143779. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  143780. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  143781. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  143782. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  143783. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  143784. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  143785. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  143786. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  143787. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  143788. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  143789. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  143790. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  143791. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  143792. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  143793. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  143794. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  143795. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  143796. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  143797. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  143798. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  143799. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  143800. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  143801. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  143802. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  143803. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  143804. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  143805. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  143806. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  143807. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  143808. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  143809. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  143810. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  143811. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  143812. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  143813. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  143814. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  143815. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  143816. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  143817. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  143818. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  143819. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  143820. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  143821. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  143822. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  143823. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  143824. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  143825. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  143826. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  143827. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  143828. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  143829. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  143830. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  143831. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  143832. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  143833. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  143834. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  143835. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  143836. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  143837. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  143838. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  143839. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  143840. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  143841. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  143842. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  143843. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  143844. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  143845. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  143846. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  143847. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  143848. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  143849. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  143850. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  143851. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  143852. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  143853. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  143854. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  143855. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  143856. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  143857. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  143858. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  143859. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  143860. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  143861. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  143862. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  143863. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  143864. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  143865. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  143866. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  143867. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  143868. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  143869. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  143870. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  143871. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  143872. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  143873. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  143874. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  143875. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  143876. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  143877. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  143878. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  143879. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  143880. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  143881. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  143882. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  143883. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  143884. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  143885. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  143886. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  143887. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  143888. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  143889. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  143890. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  143891. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  143892. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  143893. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  143894. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  143895. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  143896. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  143897. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  143898. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  143899. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  143900. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  143901. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  143902. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  143903. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  143904. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  143905. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  143906. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  143907. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  143908. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  143909. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  143910. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  143911. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  143912. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  143913. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  143914. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  143915. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  143916. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  143917. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  143918. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  143919. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  143920. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  143921. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  143922. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  143923. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  143924. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  143925. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  143926. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  143927. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  143928. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  143929. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  143930. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  143931. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  143932. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  143933. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  143934. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  143935. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  143936. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  143937. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  143938. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  143939. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  143940. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  143941. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  143942. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  143943. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  143944. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  143945. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  143946. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  143947. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  143948. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  143949. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  143950. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  143951. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  143952. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  143953. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  143954. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  143955. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  143956. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  143957. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  143958. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  143959. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  143960. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  143961. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  143962. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  143963. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  143964. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  143965. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  143966. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  143967. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  143968. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  143969. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  143970. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  143971. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  143972. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  143973. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  143974. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  143975. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  143976. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  143977. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  143978. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  143979. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  143980. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  143981. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  143982. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  143983. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  143984. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  143985. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  143986. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  143987. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  143988. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  143989. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  143990. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  143991. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  143992. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  143993. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  143994. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  143995. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  143996. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  143997. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  143998. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  143999. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  144000. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  144001. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  144002. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  144003. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  144004. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  144005. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  144006. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  144007. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  144008. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  144009. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  144010. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144011. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144012. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144013. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144014. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144015. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144016. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144017. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144018. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144019. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144020. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144021. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144022. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144023. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144024. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144025. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144026. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144027. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144028. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144029. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144030. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144031. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144032. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144033. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144034. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144035. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144036. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144037. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144038. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144039. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144040. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144041. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144042. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144043. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144044. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144045. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144046. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144047. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144048. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144049. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144050. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144051. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144052. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144053. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144054. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144055. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144056. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144057. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144058. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144059. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144060. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144061. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144062. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144063. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144064. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144065. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144066. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144067. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144068. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144069. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144070. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144071. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144072. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144073. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144074. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144075. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144076. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144077. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144078. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144079. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144080. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144081. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144082. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144083. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144084. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144085. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144086. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144087. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144088. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144089. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144090. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144091. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144092. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144093. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144094. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144095. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144096. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144097. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144098. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144099. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144100. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144101. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144102. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144103. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144104. };
  144105. static float *vwin[8] = {
  144106. vwin64,
  144107. vwin128,
  144108. vwin256,
  144109. vwin512,
  144110. vwin1024,
  144111. vwin2048,
  144112. vwin4096,
  144113. vwin8192,
  144114. };
  144115. float *_vorbis_window_get(int n){
  144116. return vwin[n];
  144117. }
  144118. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144119. int lW,int W,int nW){
  144120. lW=(W?lW:0);
  144121. nW=(W?nW:0);
  144122. {
  144123. float *windowLW=vwin[winno[lW]];
  144124. float *windowNW=vwin[winno[nW]];
  144125. long n=blocksizes[W];
  144126. long ln=blocksizes[lW];
  144127. long rn=blocksizes[nW];
  144128. long leftbegin=n/4-ln/4;
  144129. long leftend=leftbegin+ln/2;
  144130. long rightbegin=n/2+n/4-rn/4;
  144131. long rightend=rightbegin+rn/2;
  144132. int i,p;
  144133. for(i=0;i<leftbegin;i++)
  144134. d[i]=0.f;
  144135. for(p=0;i<leftend;i++,p++)
  144136. d[i]*=windowLW[p];
  144137. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144138. d[i]*=windowNW[p];
  144139. for(;i<n;i++)
  144140. d[i]=0.f;
  144141. }
  144142. }
  144143. #endif
  144144. /*** End of inlined file: window.c ***/
  144145. #else
  144146. #include <vorbis/vorbisenc.h>
  144147. #include <vorbis/codec.h>
  144148. #include <vorbis/vorbisfile.h>
  144149. #endif
  144150. }
  144151. #undef max
  144152. #undef min
  144153. BEGIN_JUCE_NAMESPACE
  144154. static const char* const oggFormatName = "Ogg-Vorbis file";
  144155. static const juce_wchar* const oggExtensions[] = { T(".ogg"), 0 };
  144156. class OggReader : public AudioFormatReader
  144157. {
  144158. OggVorbisNamespace::OggVorbis_File ovFile;
  144159. OggVorbisNamespace::ov_callbacks callbacks;
  144160. AudioSampleBuffer reservoir;
  144161. int reservoirStart, samplesInReservoir;
  144162. public:
  144163. OggReader (InputStream* const inp)
  144164. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144165. reservoir (2, 4096),
  144166. reservoirStart (0),
  144167. samplesInReservoir (0)
  144168. {
  144169. using namespace OggVorbisNamespace;
  144170. sampleRate = 0;
  144171. usesFloatingPointData = true;
  144172. callbacks.read_func = &oggReadCallback;
  144173. callbacks.seek_func = &oggSeekCallback;
  144174. callbacks.close_func = &oggCloseCallback;
  144175. callbacks.tell_func = &oggTellCallback;
  144176. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144177. if (err == 0)
  144178. {
  144179. vorbis_info* info = ov_info (&ovFile, -1);
  144180. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144181. numChannels = info->channels;
  144182. bitsPerSample = 16;
  144183. sampleRate = info->rate;
  144184. reservoir.setSize (numChannels,
  144185. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144186. }
  144187. }
  144188. ~OggReader()
  144189. {
  144190. OggVorbisNamespace::ov_clear (&ovFile);
  144191. }
  144192. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144193. int64 startSampleInFile, int numSamples)
  144194. {
  144195. while (numSamples > 0)
  144196. {
  144197. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144198. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144199. {
  144200. // got a few samples overlapping, so use them before seeking..
  144201. const int numToUse = jmin (numSamples, numAvailable);
  144202. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144203. if (destSamples[i] != 0)
  144204. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144205. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144206. sizeof (float) * numToUse);
  144207. startSampleInFile += numToUse;
  144208. numSamples -= numToUse;
  144209. startOffsetInDestBuffer += numToUse;
  144210. if (numSamples == 0)
  144211. break;
  144212. }
  144213. if (startSampleInFile < reservoirStart
  144214. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144215. {
  144216. // buffer miss, so refill the reservoir
  144217. int bitStream = 0;
  144218. reservoirStart = jmax (0, (int) startSampleInFile);
  144219. samplesInReservoir = reservoir.getNumSamples();
  144220. if (reservoirStart != (int) OggVorbisNamespace::ov_pcm_tell (&ovFile))
  144221. OggVorbisNamespace::ov_pcm_seek (&ovFile, reservoirStart);
  144222. int offset = 0;
  144223. int numToRead = samplesInReservoir;
  144224. while (numToRead > 0)
  144225. {
  144226. float** dataIn = 0;
  144227. const int samps = OggVorbisNamespace::ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144228. if (samps <= 0)
  144229. break;
  144230. jassert (samps <= numToRead);
  144231. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144232. {
  144233. memcpy (reservoir.getSampleData (i, offset),
  144234. dataIn[i],
  144235. sizeof (float) * samps);
  144236. }
  144237. numToRead -= samps;
  144238. offset += samps;
  144239. }
  144240. if (numToRead > 0)
  144241. reservoir.clear (offset, numToRead);
  144242. }
  144243. }
  144244. if (numSamples > 0)
  144245. {
  144246. for (int i = numDestChannels; --i >= 0;)
  144247. if (destSamples[i] != 0)
  144248. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144249. sizeof (int) * numSamples);
  144250. }
  144251. return true;
  144252. }
  144253. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144254. {
  144255. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  144256. }
  144257. static int oggSeekCallback (void* datasource, OggVorbisNamespace::ogg_int64_t offset, int whence)
  144258. {
  144259. InputStream* const in = (InputStream*) datasource;
  144260. if (whence == SEEK_CUR)
  144261. offset += in->getPosition();
  144262. else if (whence == SEEK_END)
  144263. offset += in->getTotalLength();
  144264. in->setPosition (offset);
  144265. return 0;
  144266. }
  144267. static int oggCloseCallback (void*)
  144268. {
  144269. return 0;
  144270. }
  144271. static long oggTellCallback (void* datasource)
  144272. {
  144273. return (long) ((InputStream*) datasource)->getPosition();
  144274. }
  144275. juce_UseDebuggingNewOperator
  144276. };
  144277. class OggWriter : public AudioFormatWriter
  144278. {
  144279. OggVorbisNamespace::ogg_stream_state os;
  144280. OggVorbisNamespace::ogg_page og;
  144281. OggVorbisNamespace::ogg_packet op;
  144282. OggVorbisNamespace::vorbis_info vi;
  144283. OggVorbisNamespace::vorbis_comment vc;
  144284. OggVorbisNamespace::vorbis_dsp_state vd;
  144285. OggVorbisNamespace::vorbis_block vb;
  144286. public:
  144287. bool ok;
  144288. OggWriter (OutputStream* const out,
  144289. const double sampleRate,
  144290. const int numChannels,
  144291. const int bitsPerSample,
  144292. const int qualityIndex)
  144293. : AudioFormatWriter (out, TRANS (oggFormatName),
  144294. sampleRate,
  144295. numChannels,
  144296. bitsPerSample)
  144297. {
  144298. using namespace OggVorbisNamespace;
  144299. ok = false;
  144300. vorbis_info_init (&vi);
  144301. if (vorbis_encode_init_vbr (&vi,
  144302. numChannels,
  144303. (int) sampleRate,
  144304. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144305. {
  144306. vorbis_comment_init (&vc);
  144307. if (JUCEApplication::getInstance() != 0)
  144308. vorbis_comment_add_tag (&vc, "ENCODER", const_cast <char*> (JUCEApplication::getInstance()->getApplicationName().toUTF8()));
  144309. vorbis_analysis_init (&vd, &vi);
  144310. vorbis_block_init (&vd, &vb);
  144311. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144312. ogg_packet header;
  144313. ogg_packet header_comm;
  144314. ogg_packet header_code;
  144315. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144316. ogg_stream_packetin (&os, &header);
  144317. ogg_stream_packetin (&os, &header_comm);
  144318. ogg_stream_packetin (&os, &header_code);
  144319. for (;;)
  144320. {
  144321. if (ogg_stream_flush (&os, &og) == 0)
  144322. break;
  144323. output->write (og.header, og.header_len);
  144324. output->write (og.body, og.body_len);
  144325. }
  144326. ok = true;
  144327. }
  144328. }
  144329. ~OggWriter()
  144330. {
  144331. using namespace OggVorbisNamespace;
  144332. if (ok)
  144333. {
  144334. // write a zero-length packet to show ogg that we're finished..
  144335. write (0, 0);
  144336. ogg_stream_clear (&os);
  144337. vorbis_block_clear (&vb);
  144338. vorbis_dsp_clear (&vd);
  144339. vorbis_comment_clear (&vc);
  144340. vorbis_info_clear (&vi);
  144341. output->flush();
  144342. }
  144343. else
  144344. {
  144345. vorbis_info_clear (&vi);
  144346. output = 0; // to stop the base class deleting this, as it needs to be returned
  144347. // to the caller of createWriter()
  144348. }
  144349. }
  144350. bool write (const int** samplesToWrite, int numSamples)
  144351. {
  144352. using namespace OggVorbisNamespace;
  144353. if (! ok)
  144354. return false;
  144355. if (numSamples > 0)
  144356. {
  144357. const double gain = 1.0 / 0x80000000u;
  144358. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144359. for (int i = numChannels; --i >= 0;)
  144360. {
  144361. float* const dst = vorbisBuffer[i];
  144362. const int* const src = samplesToWrite [i];
  144363. if (src != 0 && dst != 0)
  144364. {
  144365. for (int j = 0; j < numSamples; ++j)
  144366. dst[j] = (float) (src[j] * gain);
  144367. }
  144368. }
  144369. }
  144370. vorbis_analysis_wrote (&vd, numSamples);
  144371. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144372. {
  144373. vorbis_analysis (&vb, 0);
  144374. vorbis_bitrate_addblock (&vb);
  144375. while (vorbis_bitrate_flushpacket (&vd, &op))
  144376. {
  144377. ogg_stream_packetin (&os, &op);
  144378. for (;;)
  144379. {
  144380. if (ogg_stream_pageout (&os, &og) == 0)
  144381. break;
  144382. output->write (og.header, og.header_len);
  144383. output->write (og.body, og.body_len);
  144384. if (ogg_page_eos (&og))
  144385. break;
  144386. }
  144387. }
  144388. }
  144389. return true;
  144390. }
  144391. juce_UseDebuggingNewOperator
  144392. };
  144393. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144394. : AudioFormat (TRANS (oggFormatName), (const juce_wchar**) oggExtensions)
  144395. {
  144396. }
  144397. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144398. {
  144399. }
  144400. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144401. {
  144402. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144403. return Array <int> (rates);
  144404. }
  144405. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144406. {
  144407. Array <int> depths;
  144408. depths.add (32);
  144409. return depths;
  144410. }
  144411. bool OggVorbisAudioFormat::canDoStereo()
  144412. {
  144413. return true;
  144414. }
  144415. bool OggVorbisAudioFormat::canDoMono()
  144416. {
  144417. return true;
  144418. }
  144419. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144420. const bool deleteStreamIfOpeningFails)
  144421. {
  144422. ScopedPointer <OggReader> r (new OggReader (in));
  144423. if (r->sampleRate != 0)
  144424. return r.release();
  144425. if (! deleteStreamIfOpeningFails)
  144426. r->input = 0;
  144427. return 0;
  144428. }
  144429. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144430. double sampleRate,
  144431. unsigned int numChannels,
  144432. int bitsPerSample,
  144433. const StringPairArray& /*metadataValues*/,
  144434. int qualityOptionIndex)
  144435. {
  144436. ScopedPointer <OggWriter> w (new OggWriter (out,
  144437. sampleRate,
  144438. numChannels,
  144439. bitsPerSample,
  144440. qualityOptionIndex));
  144441. return w->ok ? w.release() : 0;
  144442. }
  144443. bool OggVorbisAudioFormat::isCompressed()
  144444. {
  144445. return true;
  144446. }
  144447. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144448. {
  144449. StringArray s;
  144450. s.add ("Low Quality");
  144451. s.add ("Medium Quality");
  144452. s.add ("High Quality");
  144453. return s;
  144454. }
  144455. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144456. {
  144457. FileInputStream* const in = source.createInputStream();
  144458. if (in != 0)
  144459. {
  144460. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144461. if (r != 0)
  144462. {
  144463. const int64 numSamps = r->lengthInSamples;
  144464. r = 0;
  144465. const int64 fileNumSamps = source.getSize() / 4;
  144466. const double ratio = numSamps / (double) fileNumSamps;
  144467. if (ratio > 12.0)
  144468. return 0;
  144469. else if (ratio > 6.0)
  144470. return 1;
  144471. else
  144472. return 2;
  144473. }
  144474. }
  144475. return 1;
  144476. }
  144477. END_JUCE_NAMESPACE
  144478. #endif
  144479. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144480. #endif
  144481. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144482. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144483. #if JUCE_MSVC
  144484. #pragma warning (push)
  144485. #endif
  144486. namespace jpeglibNamespace
  144487. {
  144488. #if JUCE_INCLUDE_JPEGLIB_CODE
  144489. #if JUCE_MINGW
  144490. typedef unsigned char boolean;
  144491. #endif
  144492. extern "C"
  144493. {
  144494. #define JPEG_INTERNALS
  144495. #undef FAR
  144496. /*** Start of inlined file: jpeglib.h ***/
  144497. #ifndef JPEGLIB_H
  144498. #define JPEGLIB_H
  144499. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144500. /*** Start of inlined file: jconfig.h ***/
  144501. // disable all the warnings under MSVC
  144502. #ifdef _MSC_VER
  144503. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144504. #endif
  144505. #ifdef __BORLANDC__
  144506. #pragma warn -8057
  144507. #pragma warn -8019
  144508. #pragma warn -8004
  144509. #pragma warn -8008
  144510. #endif
  144511. #define HAVE_PROTOTYPES
  144512. #define HAVE_UNSIGNED_CHAR
  144513. #define HAVE_UNSIGNED_SHORT
  144514. #undef CHAR_IS_UNSIGNED
  144515. #define HAVE_STDDEF_H
  144516. #define HAVE_STDLIB_H
  144517. #undef NEED_BSD_STRINGS
  144518. #undef NEED_SYS_TYPES_H
  144519. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144520. #undef NEED_SHORT_EXTERNAL_NAMES
  144521. #undef INCOMPLETE_TYPES_BROKEN
  144522. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144523. typedef unsigned char boolean;
  144524. #endif
  144525. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144526. #ifdef JPEG_INTERNALS
  144527. #undef RIGHT_SHIFT_IS_UNSIGNED
  144528. #endif /* JPEG_INTERNALS */
  144529. #ifdef JPEG_CJPEG_DJPEG
  144530. #define BMP_SUPPORTED /* BMP image file format */
  144531. #define GIF_SUPPORTED /* GIF image file format */
  144532. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144533. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144534. #define TARGA_SUPPORTED /* Targa image file format */
  144535. #define TWO_FILE_COMMANDLINE /* optional */
  144536. #define USE_SETMODE /* Microsoft has setmode() */
  144537. #undef NEED_SIGNAL_CATCHER
  144538. #undef DONT_USE_B_MODE
  144539. #undef PROGRESS_REPORT /* optional */
  144540. #endif /* JPEG_CJPEG_DJPEG */
  144541. /*** End of inlined file: jconfig.h ***/
  144542. /* widely used configuration options */
  144543. #endif
  144544. /*** Start of inlined file: jmorecfg.h ***/
  144545. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  144546. #define MAX_COMPONENTS 10 /* maximum number of image components */
  144547. #if BITS_IN_JSAMPLE == 8
  144548. #ifdef HAVE_UNSIGNED_CHAR
  144549. typedef unsigned char JSAMPLE;
  144550. #define GETJSAMPLE(value) ((int) (value))
  144551. #else /* not HAVE_UNSIGNED_CHAR */
  144552. typedef char JSAMPLE;
  144553. #ifdef CHAR_IS_UNSIGNED
  144554. #define GETJSAMPLE(value) ((int) (value))
  144555. #else
  144556. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  144557. #endif /* CHAR_IS_UNSIGNED */
  144558. #endif /* HAVE_UNSIGNED_CHAR */
  144559. #define MAXJSAMPLE 255
  144560. #define CENTERJSAMPLE 128
  144561. #endif /* BITS_IN_JSAMPLE == 8 */
  144562. #if BITS_IN_JSAMPLE == 12
  144563. typedef short JSAMPLE;
  144564. #define GETJSAMPLE(value) ((int) (value))
  144565. #define MAXJSAMPLE 4095
  144566. #define CENTERJSAMPLE 2048
  144567. #endif /* BITS_IN_JSAMPLE == 12 */
  144568. typedef short JCOEF;
  144569. #ifdef HAVE_UNSIGNED_CHAR
  144570. typedef unsigned char JOCTET;
  144571. #define GETJOCTET(value) (value)
  144572. #else /* not HAVE_UNSIGNED_CHAR */
  144573. typedef char JOCTET;
  144574. #ifdef CHAR_IS_UNSIGNED
  144575. #define GETJOCTET(value) (value)
  144576. #else
  144577. #define GETJOCTET(value) ((value) & 0xFF)
  144578. #endif /* CHAR_IS_UNSIGNED */
  144579. #endif /* HAVE_UNSIGNED_CHAR */
  144580. #ifdef HAVE_UNSIGNED_CHAR
  144581. typedef unsigned char UINT8;
  144582. #else /* not HAVE_UNSIGNED_CHAR */
  144583. #ifdef CHAR_IS_UNSIGNED
  144584. typedef char UINT8;
  144585. #else /* not CHAR_IS_UNSIGNED */
  144586. typedef short UINT8;
  144587. #endif /* CHAR_IS_UNSIGNED */
  144588. #endif /* HAVE_UNSIGNED_CHAR */
  144589. #ifdef HAVE_UNSIGNED_SHORT
  144590. typedef unsigned short UINT16;
  144591. #else /* not HAVE_UNSIGNED_SHORT */
  144592. typedef unsigned int UINT16;
  144593. #endif /* HAVE_UNSIGNED_SHORT */
  144594. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  144595. typedef short INT16;
  144596. #endif
  144597. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  144598. typedef long INT32;
  144599. #endif
  144600. typedef unsigned int JDIMENSION;
  144601. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  144602. #define METHODDEF(type) static type
  144603. #define LOCAL(type) static type
  144604. #define GLOBAL(type) type
  144605. #define EXTERN(type) extern type
  144606. #ifdef HAVE_PROTOTYPES
  144607. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  144608. #else
  144609. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  144610. #endif
  144611. #ifdef NEED_FAR_POINTERS
  144612. #define FAR far
  144613. #else
  144614. #define FAR
  144615. #endif
  144616. #ifndef HAVE_BOOLEAN
  144617. typedef int boolean;
  144618. #endif
  144619. #ifndef FALSE /* in case these macros already exist */
  144620. #define FALSE 0 /* values of boolean */
  144621. #endif
  144622. #ifndef TRUE
  144623. #define TRUE 1
  144624. #endif
  144625. #ifdef JPEG_INTERNALS
  144626. #define JPEG_INTERNAL_OPTIONS
  144627. #endif
  144628. #ifdef JPEG_INTERNAL_OPTIONS
  144629. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  144630. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  144631. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  144632. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144633. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144634. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144635. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  144636. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  144637. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144638. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144639. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144640. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  144641. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  144642. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  144643. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  144644. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  144645. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  144646. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  144647. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  144648. #define RGB_GREEN 1 /* Offset of Green */
  144649. #define RGB_BLUE 2 /* Offset of Blue */
  144650. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  144651. #ifndef INLINE
  144652. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  144653. #define INLINE __inline__
  144654. #endif
  144655. #ifndef INLINE
  144656. #define INLINE /* default is to define it as empty */
  144657. #endif
  144658. #endif
  144659. #ifndef MULTIPLIER
  144660. #define MULTIPLIER int /* type for fastest integer multiply */
  144661. #endif
  144662. #ifndef FAST_FLOAT
  144663. #ifdef HAVE_PROTOTYPES
  144664. #define FAST_FLOAT float
  144665. #else
  144666. #define FAST_FLOAT double
  144667. #endif
  144668. #endif
  144669. #endif /* JPEG_INTERNAL_OPTIONS */
  144670. /*** End of inlined file: jmorecfg.h ***/
  144671. /* seldom changed options */
  144672. #define JPEG_LIB_VERSION 62 /* Version 6b */
  144673. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  144674. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  144675. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  144676. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  144677. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  144678. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  144679. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  144680. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  144681. #ifndef D_MAX_BLOCKS_IN_MCU
  144682. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  144683. #endif
  144684. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  144685. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  144686. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  144687. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  144688. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  144689. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  144690. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  144691. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  144692. typedef struct {
  144693. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  144694. boolean sent_table; /* TRUE when table has been output */
  144695. } JQUANT_TBL;
  144696. typedef struct {
  144697. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  144698. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  144699. boolean sent_table; /* TRUE when table has been output */
  144700. } JHUFF_TBL;
  144701. typedef struct {
  144702. int component_id; /* identifier for this component (0..255) */
  144703. int component_index; /* its index in SOF or cinfo->comp_info[] */
  144704. int h_samp_factor; /* horizontal sampling factor (1..4) */
  144705. int v_samp_factor; /* vertical sampling factor (1..4) */
  144706. int quant_tbl_no; /* quantization table selector (0..3) */
  144707. int dc_tbl_no; /* DC entropy table selector (0..3) */
  144708. int ac_tbl_no; /* AC entropy table selector (0..3) */
  144709. JDIMENSION width_in_blocks;
  144710. JDIMENSION height_in_blocks;
  144711. int DCT_scaled_size;
  144712. JDIMENSION downsampled_width; /* actual width in samples */
  144713. JDIMENSION downsampled_height; /* actual height in samples */
  144714. boolean component_needed; /* do we need the value of this component? */
  144715. int MCU_width; /* number of blocks per MCU, horizontally */
  144716. int MCU_height; /* number of blocks per MCU, vertically */
  144717. int MCU_blocks; /* MCU_width * MCU_height */
  144718. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  144719. int last_col_width; /* # of non-dummy blocks across in last MCU */
  144720. int last_row_height; /* # of non-dummy blocks down in last MCU */
  144721. JQUANT_TBL * quant_table;
  144722. void * dct_table;
  144723. } jpeg_component_info;
  144724. typedef struct {
  144725. int comps_in_scan; /* number of components encoded in this scan */
  144726. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  144727. int Ss, Se; /* progressive JPEG spectral selection parms */
  144728. int Ah, Al; /* progressive JPEG successive approx. parms */
  144729. } jpeg_scan_info;
  144730. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  144731. struct jpeg_marker_struct {
  144732. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  144733. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  144734. unsigned int original_length; /* # bytes of data in the file */
  144735. unsigned int data_length; /* # bytes of data saved at data[] */
  144736. JOCTET FAR * data; /* the data contained in the marker */
  144737. };
  144738. typedef enum {
  144739. JCS_UNKNOWN, /* error/unspecified */
  144740. JCS_GRAYSCALE, /* monochrome */
  144741. JCS_RGB, /* red/green/blue */
  144742. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  144743. JCS_CMYK, /* C/M/Y/K */
  144744. JCS_YCCK /* Y/Cb/Cr/K */
  144745. } J_COLOR_SPACE;
  144746. typedef enum {
  144747. JDCT_ISLOW, /* slow but accurate integer algorithm */
  144748. JDCT_IFAST, /* faster, less accurate integer method */
  144749. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  144750. } J_DCT_METHOD;
  144751. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  144752. #define JDCT_DEFAULT JDCT_ISLOW
  144753. #endif
  144754. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  144755. #define JDCT_FASTEST JDCT_IFAST
  144756. #endif
  144757. typedef enum {
  144758. JDITHER_NONE, /* no dithering */
  144759. JDITHER_ORDERED, /* simple ordered dither */
  144760. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  144761. } J_DITHER_MODE;
  144762. #define jpeg_common_fields \
  144763. struct jpeg_error_mgr * err; /* Error handler module */\
  144764. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  144765. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  144766. void * client_data; /* Available for use by application */\
  144767. boolean is_decompressor; /* So common code can tell which is which */\
  144768. int global_state /* For checking call sequence validity */
  144769. struct jpeg_common_struct {
  144770. jpeg_common_fields; /* Fields common to both master struct types */
  144771. };
  144772. typedef struct jpeg_common_struct * j_common_ptr;
  144773. typedef struct jpeg_compress_struct * j_compress_ptr;
  144774. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  144775. struct jpeg_compress_struct {
  144776. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  144777. struct jpeg_destination_mgr * dest;
  144778. JDIMENSION image_width; /* input image width */
  144779. JDIMENSION image_height; /* input image height */
  144780. int input_components; /* # of color components in input image */
  144781. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  144782. double input_gamma; /* image gamma of input image */
  144783. int data_precision; /* bits of precision in image data */
  144784. int num_components; /* # of color components in JPEG image */
  144785. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144786. jpeg_component_info * comp_info;
  144787. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144788. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144789. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144790. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144791. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144792. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144793. int num_scans; /* # of entries in scan_info array */
  144794. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  144795. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  144796. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144797. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  144798. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144799. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  144800. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  144801. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  144802. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  144803. boolean write_JFIF_header; /* should a JFIF marker be written? */
  144804. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  144805. UINT8 JFIF_minor_version;
  144806. UINT8 density_unit; /* JFIF code for pixel size units */
  144807. UINT16 X_density; /* Horizontal pixel density */
  144808. UINT16 Y_density; /* Vertical pixel density */
  144809. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  144810. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  144811. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  144812. int max_h_samp_factor; /* largest h_samp_factor */
  144813. int max_v_samp_factor; /* largest v_samp_factor */
  144814. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  144815. int comps_in_scan; /* # of JPEG components in this scan */
  144816. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144817. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144818. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144819. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144820. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  144821. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144822. struct jpeg_comp_master * master;
  144823. struct jpeg_c_main_controller * main;
  144824. struct jpeg_c_prep_controller * prep;
  144825. struct jpeg_c_coef_controller * coef;
  144826. struct jpeg_marker_writer * marker;
  144827. struct jpeg_color_converter * cconvert;
  144828. struct jpeg_downsampler * downsample;
  144829. struct jpeg_forward_dct * fdct;
  144830. struct jpeg_entropy_encoder * entropy;
  144831. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  144832. int script_space_size;
  144833. };
  144834. struct jpeg_decompress_struct {
  144835. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  144836. struct jpeg_source_mgr * src;
  144837. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  144838. JDIMENSION image_height; /* nominal image height */
  144839. int num_components; /* # of color components in JPEG image */
  144840. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144841. J_COLOR_SPACE out_color_space; /* colorspace for output */
  144842. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  144843. double output_gamma; /* image gamma wanted in output */
  144844. boolean buffered_image; /* TRUE=multiple output passes */
  144845. boolean raw_data_out; /* TRUE=downsampled data wanted */
  144846. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  144847. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  144848. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  144849. boolean quantize_colors; /* TRUE=colormapped output wanted */
  144850. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  144851. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  144852. int desired_number_of_colors; /* max # colors to use in created colormap */
  144853. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  144854. boolean enable_external_quant;/* enable future use of external colormap */
  144855. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  144856. JDIMENSION output_width; /* scaled image width */
  144857. JDIMENSION output_height; /* scaled image height */
  144858. int out_color_components; /* # of color components in out_color_space */
  144859. int output_components; /* # of color components returned */
  144860. int rec_outbuf_height; /* min recommended height of scanline buffer */
  144861. int actual_number_of_colors; /* number of entries in use */
  144862. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  144863. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  144864. int input_scan_number; /* Number of SOS markers seen so far */
  144865. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  144866. int output_scan_number; /* Nominal scan number being displayed */
  144867. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  144868. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  144869. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144870. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144871. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144872. int data_precision; /* bits of precision in image data */
  144873. jpeg_component_info * comp_info;
  144874. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  144875. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144876. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144877. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144878. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144879. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  144880. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  144881. UINT8 JFIF_major_version; /* JFIF version number */
  144882. UINT8 JFIF_minor_version;
  144883. UINT8 density_unit; /* JFIF code for pixel size units */
  144884. UINT16 X_density; /* Horizontal pixel density */
  144885. UINT16 Y_density; /* Vertical pixel density */
  144886. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  144887. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  144888. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144889. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  144890. int max_h_samp_factor; /* largest h_samp_factor */
  144891. int max_v_samp_factor; /* largest v_samp_factor */
  144892. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  144893. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  144894. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  144895. int comps_in_scan; /* # of JPEG components in this scan */
  144896. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144897. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144898. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144899. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144900. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  144901. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144902. int unread_marker;
  144903. struct jpeg_decomp_master * master;
  144904. struct jpeg_d_main_controller * main;
  144905. struct jpeg_d_coef_controller * coef;
  144906. struct jpeg_d_post_controller * post;
  144907. struct jpeg_input_controller * inputctl;
  144908. struct jpeg_marker_reader * marker;
  144909. struct jpeg_entropy_decoder * entropy;
  144910. struct jpeg_inverse_dct * idct;
  144911. struct jpeg_upsampler * upsample;
  144912. struct jpeg_color_deconverter * cconvert;
  144913. struct jpeg_color_quantizer * cquantize;
  144914. };
  144915. struct jpeg_error_mgr {
  144916. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  144917. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  144918. JMETHOD(void, output_message, (j_common_ptr cinfo));
  144919. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  144920. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  144921. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  144922. int msg_code;
  144923. #define JMSG_STR_PARM_MAX 80
  144924. union {
  144925. int i[8];
  144926. char s[JMSG_STR_PARM_MAX];
  144927. } msg_parm;
  144928. int trace_level; /* max msg_level that will be displayed */
  144929. long num_warnings; /* number of corrupt-data warnings */
  144930. const char * const * jpeg_message_table; /* Library errors */
  144931. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  144932. const char * const * addon_message_table; /* Non-library errors */
  144933. int first_addon_message; /* code for first string in addon table */
  144934. int last_addon_message; /* code for last string in addon table */
  144935. };
  144936. struct jpeg_progress_mgr {
  144937. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  144938. long pass_counter; /* work units completed in this pass */
  144939. long pass_limit; /* total number of work units in this pass */
  144940. int completed_passes; /* passes completed so far */
  144941. int total_passes; /* total number of passes expected */
  144942. };
  144943. struct jpeg_destination_mgr {
  144944. JOCTET * next_output_byte; /* => next byte to write in buffer */
  144945. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  144946. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  144947. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  144948. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  144949. };
  144950. struct jpeg_source_mgr {
  144951. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  144952. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  144953. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  144954. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  144955. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  144956. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  144957. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  144958. };
  144959. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  144960. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  144961. #define JPOOL_NUMPOOLS 2
  144962. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  144963. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  144964. struct jpeg_memory_mgr {
  144965. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  144966. size_t sizeofobject));
  144967. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  144968. size_t sizeofobject));
  144969. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  144970. JDIMENSION samplesperrow,
  144971. JDIMENSION numrows));
  144972. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  144973. JDIMENSION blocksperrow,
  144974. JDIMENSION numrows));
  144975. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  144976. int pool_id,
  144977. boolean pre_zero,
  144978. JDIMENSION samplesperrow,
  144979. JDIMENSION numrows,
  144980. JDIMENSION maxaccess));
  144981. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  144982. int pool_id,
  144983. boolean pre_zero,
  144984. JDIMENSION blocksperrow,
  144985. JDIMENSION numrows,
  144986. JDIMENSION maxaccess));
  144987. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  144988. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  144989. jvirt_sarray_ptr ptr,
  144990. JDIMENSION start_row,
  144991. JDIMENSION num_rows,
  144992. boolean writable));
  144993. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  144994. jvirt_barray_ptr ptr,
  144995. JDIMENSION start_row,
  144996. JDIMENSION num_rows,
  144997. boolean writable));
  144998. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  144999. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  145000. long max_memory_to_use;
  145001. long max_alloc_chunk;
  145002. };
  145003. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  145004. #ifdef HAVE_PROTOTYPES
  145005. #define JPP(arglist) arglist
  145006. #else
  145007. #define JPP(arglist) ()
  145008. #endif
  145009. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145010. #define jpeg_std_error jStdError
  145011. #define jpeg_CreateCompress jCreaCompress
  145012. #define jpeg_CreateDecompress jCreaDecompress
  145013. #define jpeg_destroy_compress jDestCompress
  145014. #define jpeg_destroy_decompress jDestDecompress
  145015. #define jpeg_stdio_dest jStdDest
  145016. #define jpeg_stdio_src jStdSrc
  145017. #define jpeg_set_defaults jSetDefaults
  145018. #define jpeg_set_colorspace jSetColorspace
  145019. #define jpeg_default_colorspace jDefColorspace
  145020. #define jpeg_set_quality jSetQuality
  145021. #define jpeg_set_linear_quality jSetLQuality
  145022. #define jpeg_add_quant_table jAddQuantTable
  145023. #define jpeg_quality_scaling jQualityScaling
  145024. #define jpeg_simple_progression jSimProgress
  145025. #define jpeg_suppress_tables jSuppressTables
  145026. #define jpeg_alloc_quant_table jAlcQTable
  145027. #define jpeg_alloc_huff_table jAlcHTable
  145028. #define jpeg_start_compress jStrtCompress
  145029. #define jpeg_write_scanlines jWrtScanlines
  145030. #define jpeg_finish_compress jFinCompress
  145031. #define jpeg_write_raw_data jWrtRawData
  145032. #define jpeg_write_marker jWrtMarker
  145033. #define jpeg_write_m_header jWrtMHeader
  145034. #define jpeg_write_m_byte jWrtMByte
  145035. #define jpeg_write_tables jWrtTables
  145036. #define jpeg_read_header jReadHeader
  145037. #define jpeg_start_decompress jStrtDecompress
  145038. #define jpeg_read_scanlines jReadScanlines
  145039. #define jpeg_finish_decompress jFinDecompress
  145040. #define jpeg_read_raw_data jReadRawData
  145041. #define jpeg_has_multiple_scans jHasMultScn
  145042. #define jpeg_start_output jStrtOutput
  145043. #define jpeg_finish_output jFinOutput
  145044. #define jpeg_input_complete jInComplete
  145045. #define jpeg_new_colormap jNewCMap
  145046. #define jpeg_consume_input jConsumeInput
  145047. #define jpeg_calc_output_dimensions jCalcDimensions
  145048. #define jpeg_save_markers jSaveMarkers
  145049. #define jpeg_set_marker_processor jSetMarker
  145050. #define jpeg_read_coefficients jReadCoefs
  145051. #define jpeg_write_coefficients jWrtCoefs
  145052. #define jpeg_copy_critical_parameters jCopyCrit
  145053. #define jpeg_abort_compress jAbrtCompress
  145054. #define jpeg_abort_decompress jAbrtDecompress
  145055. #define jpeg_abort jAbort
  145056. #define jpeg_destroy jDestroy
  145057. #define jpeg_resync_to_restart jResyncRestart
  145058. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145059. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145060. JPP((struct jpeg_error_mgr * err));
  145061. #define jpeg_create_compress(cinfo) \
  145062. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145063. (size_t) sizeof(struct jpeg_compress_struct))
  145064. #define jpeg_create_decompress(cinfo) \
  145065. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145066. (size_t) sizeof(struct jpeg_decompress_struct))
  145067. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145068. int version, size_t structsize));
  145069. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145070. int version, size_t structsize));
  145071. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145072. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145073. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145074. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145075. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145076. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145077. J_COLOR_SPACE colorspace));
  145078. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145079. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145080. boolean force_baseline));
  145081. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145082. int scale_factor,
  145083. boolean force_baseline));
  145084. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145085. const unsigned int *basic_table,
  145086. int scale_factor,
  145087. boolean force_baseline));
  145088. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145089. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145090. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145091. boolean suppress));
  145092. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145093. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145094. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145095. boolean write_all_tables));
  145096. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145097. JSAMPARRAY scanlines,
  145098. JDIMENSION num_lines));
  145099. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145100. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145101. JSAMPIMAGE data,
  145102. JDIMENSION num_lines));
  145103. EXTERN(void) jpeg_write_marker
  145104. JPP((j_compress_ptr cinfo, int marker,
  145105. const JOCTET * dataptr, unsigned int datalen));
  145106. EXTERN(void) jpeg_write_m_header
  145107. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145108. EXTERN(void) jpeg_write_m_byte
  145109. JPP((j_compress_ptr cinfo, int val));
  145110. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145111. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145112. boolean require_image));
  145113. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145114. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145115. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145116. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145117. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145118. JSAMPARRAY scanlines,
  145119. JDIMENSION max_lines));
  145120. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145121. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145122. JSAMPIMAGE data,
  145123. JDIMENSION max_lines));
  145124. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145125. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145126. int scan_number));
  145127. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145128. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145129. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145130. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145131. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145132. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145133. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145134. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145135. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145136. EXTERN(void) jpeg_save_markers
  145137. JPP((j_decompress_ptr cinfo, int marker_code,
  145138. unsigned int length_limit));
  145139. EXTERN(void) jpeg_set_marker_processor
  145140. JPP((j_decompress_ptr cinfo, int marker_code,
  145141. jpeg_marker_parser_method routine));
  145142. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145143. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145144. jvirt_barray_ptr * coef_arrays));
  145145. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145146. j_compress_ptr dstinfo));
  145147. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145148. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145149. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145150. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145151. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145152. int desired));
  145153. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145154. #define JPEG_EOI 0xD9 /* EOI marker code */
  145155. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145156. #define JPEG_COM 0xFE /* COM marker code */
  145157. #ifdef INCOMPLETE_TYPES_BROKEN
  145158. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145159. struct jvirt_sarray_control { long dummy; };
  145160. struct jvirt_barray_control { long dummy; };
  145161. struct jpeg_comp_master { long dummy; };
  145162. struct jpeg_c_main_controller { long dummy; };
  145163. struct jpeg_c_prep_controller { long dummy; };
  145164. struct jpeg_c_coef_controller { long dummy; };
  145165. struct jpeg_marker_writer { long dummy; };
  145166. struct jpeg_color_converter { long dummy; };
  145167. struct jpeg_downsampler { long dummy; };
  145168. struct jpeg_forward_dct { long dummy; };
  145169. struct jpeg_entropy_encoder { long dummy; };
  145170. struct jpeg_decomp_master { long dummy; };
  145171. struct jpeg_d_main_controller { long dummy; };
  145172. struct jpeg_d_coef_controller { long dummy; };
  145173. struct jpeg_d_post_controller { long dummy; };
  145174. struct jpeg_input_controller { long dummy; };
  145175. struct jpeg_marker_reader { long dummy; };
  145176. struct jpeg_entropy_decoder { long dummy; };
  145177. struct jpeg_inverse_dct { long dummy; };
  145178. struct jpeg_upsampler { long dummy; };
  145179. struct jpeg_color_deconverter { long dummy; };
  145180. struct jpeg_color_quantizer { long dummy; };
  145181. #endif /* JPEG_INTERNALS */
  145182. #endif /* INCOMPLETE_TYPES_BROKEN */
  145183. #ifdef JPEG_INTERNALS
  145184. /*** Start of inlined file: jpegint.h ***/
  145185. typedef enum { /* Operating modes for buffer controllers */
  145186. JBUF_PASS_THRU, /* Plain stripwise operation */
  145187. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145188. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145189. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145190. } J_BUF_MODE;
  145191. #define CSTATE_START 100 /* after create_compress */
  145192. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145193. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145194. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145195. #define DSTATE_START 200 /* after create_decompress */
  145196. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145197. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145198. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145199. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145200. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145201. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145202. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145203. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145204. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145205. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145206. struct jpeg_comp_master {
  145207. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145208. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145209. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145210. boolean call_pass_startup; /* True if pass_startup must be called */
  145211. boolean is_last_pass; /* True during last pass */
  145212. };
  145213. struct jpeg_c_main_controller {
  145214. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145215. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145216. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145217. JDIMENSION in_rows_avail));
  145218. };
  145219. struct jpeg_c_prep_controller {
  145220. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145221. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145222. JSAMPARRAY input_buf,
  145223. JDIMENSION *in_row_ctr,
  145224. JDIMENSION in_rows_avail,
  145225. JSAMPIMAGE output_buf,
  145226. JDIMENSION *out_row_group_ctr,
  145227. JDIMENSION out_row_groups_avail));
  145228. };
  145229. struct jpeg_c_coef_controller {
  145230. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145231. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145232. JSAMPIMAGE input_buf));
  145233. };
  145234. struct jpeg_color_converter {
  145235. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145236. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145237. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145238. JDIMENSION output_row, int num_rows));
  145239. };
  145240. struct jpeg_downsampler {
  145241. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145242. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145243. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145244. JSAMPIMAGE output_buf,
  145245. JDIMENSION out_row_group_index));
  145246. boolean need_context_rows; /* TRUE if need rows above & below */
  145247. };
  145248. struct jpeg_forward_dct {
  145249. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145250. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145251. jpeg_component_info * compptr,
  145252. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145253. JDIMENSION start_row, JDIMENSION start_col,
  145254. JDIMENSION num_blocks));
  145255. };
  145256. struct jpeg_entropy_encoder {
  145257. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145258. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145259. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145260. };
  145261. struct jpeg_marker_writer {
  145262. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145263. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145264. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145265. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145266. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145267. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145268. unsigned int datalen));
  145269. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145270. };
  145271. struct jpeg_decomp_master {
  145272. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145273. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145274. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145275. };
  145276. struct jpeg_input_controller {
  145277. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145278. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145279. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145280. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145281. boolean has_multiple_scans; /* True if file has multiple scans */
  145282. boolean eoi_reached; /* True when EOI has been consumed */
  145283. };
  145284. struct jpeg_d_main_controller {
  145285. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145286. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145287. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145288. JDIMENSION out_rows_avail));
  145289. };
  145290. struct jpeg_d_coef_controller {
  145291. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145292. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145293. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145294. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145295. JSAMPIMAGE output_buf));
  145296. jvirt_barray_ptr *coef_arrays;
  145297. };
  145298. struct jpeg_d_post_controller {
  145299. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145300. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145301. JSAMPIMAGE input_buf,
  145302. JDIMENSION *in_row_group_ctr,
  145303. JDIMENSION in_row_groups_avail,
  145304. JSAMPARRAY output_buf,
  145305. JDIMENSION *out_row_ctr,
  145306. JDIMENSION out_rows_avail));
  145307. };
  145308. struct jpeg_marker_reader {
  145309. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145310. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145311. jpeg_marker_parser_method read_restart_marker;
  145312. boolean saw_SOI; /* found SOI? */
  145313. boolean saw_SOF; /* found SOF? */
  145314. int next_restart_num; /* next restart number expected (0-7) */
  145315. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145316. };
  145317. struct jpeg_entropy_decoder {
  145318. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145319. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145320. JBLOCKROW *MCU_data));
  145321. boolean insufficient_data; /* set TRUE after emitting warning */
  145322. };
  145323. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145324. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145325. JCOEFPTR coef_block,
  145326. JSAMPARRAY output_buf, JDIMENSION output_col));
  145327. struct jpeg_inverse_dct {
  145328. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145329. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145330. };
  145331. struct jpeg_upsampler {
  145332. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145333. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145334. JSAMPIMAGE input_buf,
  145335. JDIMENSION *in_row_group_ctr,
  145336. JDIMENSION in_row_groups_avail,
  145337. JSAMPARRAY output_buf,
  145338. JDIMENSION *out_row_ctr,
  145339. JDIMENSION out_rows_avail));
  145340. boolean need_context_rows; /* TRUE if need rows above & below */
  145341. };
  145342. struct jpeg_color_deconverter {
  145343. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145344. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145345. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145346. JSAMPARRAY output_buf, int num_rows));
  145347. };
  145348. struct jpeg_color_quantizer {
  145349. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145350. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145351. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145352. int num_rows));
  145353. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145354. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145355. };
  145356. #undef MAX
  145357. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145358. #undef MIN
  145359. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145360. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145361. #define SHIFT_TEMPS INT32 shift_temp;
  145362. #define RIGHT_SHIFT(x,shft) \
  145363. ((shift_temp = (x)) < 0 ? \
  145364. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145365. (shift_temp >> (shft)))
  145366. #else
  145367. #define SHIFT_TEMPS
  145368. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145369. #endif
  145370. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145371. #define jinit_compress_master jICompress
  145372. #define jinit_c_master_control jICMaster
  145373. #define jinit_c_main_controller jICMainC
  145374. #define jinit_c_prep_controller jICPrepC
  145375. #define jinit_c_coef_controller jICCoefC
  145376. #define jinit_color_converter jICColor
  145377. #define jinit_downsampler jIDownsampler
  145378. #define jinit_forward_dct jIFDCT
  145379. #define jinit_huff_encoder jIHEncoder
  145380. #define jinit_phuff_encoder jIPHEncoder
  145381. #define jinit_marker_writer jIMWriter
  145382. #define jinit_master_decompress jIDMaster
  145383. #define jinit_d_main_controller jIDMainC
  145384. #define jinit_d_coef_controller jIDCoefC
  145385. #define jinit_d_post_controller jIDPostC
  145386. #define jinit_input_controller jIInCtlr
  145387. #define jinit_marker_reader jIMReader
  145388. #define jinit_huff_decoder jIHDecoder
  145389. #define jinit_phuff_decoder jIPHDecoder
  145390. #define jinit_inverse_dct jIIDCT
  145391. #define jinit_upsampler jIUpsampler
  145392. #define jinit_color_deconverter jIDColor
  145393. #define jinit_1pass_quantizer jI1Quant
  145394. #define jinit_2pass_quantizer jI2Quant
  145395. #define jinit_merged_upsampler jIMUpsampler
  145396. #define jinit_memory_mgr jIMemMgr
  145397. #define jdiv_round_up jDivRound
  145398. #define jround_up jRound
  145399. #define jcopy_sample_rows jCopySamples
  145400. #define jcopy_block_row jCopyBlocks
  145401. #define jzero_far jZeroFar
  145402. #define jpeg_zigzag_order jZIGTable
  145403. #define jpeg_natural_order jZAGTable
  145404. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145405. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145406. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145407. boolean transcode_only));
  145408. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145409. boolean need_full_buffer));
  145410. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145411. boolean need_full_buffer));
  145412. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145413. boolean need_full_buffer));
  145414. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145415. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145416. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145417. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145418. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145419. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145420. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145421. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145422. boolean need_full_buffer));
  145423. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145424. boolean need_full_buffer));
  145425. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145426. boolean need_full_buffer));
  145427. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145428. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145429. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145430. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145431. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145432. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145433. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145434. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145435. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145436. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145437. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145438. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145439. EXTERN(long) jround_up JPP((long a, long b));
  145440. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145441. JSAMPARRAY output_array, int dest_row,
  145442. int num_rows, JDIMENSION num_cols));
  145443. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145444. JDIMENSION num_blocks));
  145445. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145446. #if 0 /* This table is not actually needed in v6a */
  145447. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145448. #endif
  145449. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145450. #ifdef INCOMPLETE_TYPES_BROKEN
  145451. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145452. struct jvirt_sarray_control { long dummy; };
  145453. struct jvirt_barray_control { long dummy; };
  145454. #endif
  145455. #endif /* INCOMPLETE_TYPES_BROKEN */
  145456. /*** End of inlined file: jpegint.h ***/
  145457. /* fetch private declarations */
  145458. /*** Start of inlined file: jerror.h ***/
  145459. #ifndef JMESSAGE
  145460. #ifndef JERROR_H
  145461. #define JMAKE_ENUM_LIST
  145462. #else
  145463. #define JMESSAGE(code,string)
  145464. #endif /* JERROR_H */
  145465. #endif /* JMESSAGE */
  145466. #ifdef JMAKE_ENUM_LIST
  145467. typedef enum {
  145468. #define JMESSAGE(code,string) code ,
  145469. #endif /* JMAKE_ENUM_LIST */
  145470. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145471. JMESSAGE(JERR_ARITH_NOTIMPL,
  145472. "Sorry, there are legal restrictions on arithmetic coding")
  145473. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145474. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145475. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145476. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145477. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145478. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145479. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145480. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145481. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145482. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145483. JMESSAGE(JERR_BAD_LIB_VERSION,
  145484. "Wrong JPEG library version: library is %d, caller expects %d")
  145485. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145486. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145487. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145488. JMESSAGE(JERR_BAD_PROGRESSION,
  145489. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145490. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145491. "Invalid progressive parameters at scan script entry %d")
  145492. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145493. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145494. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145495. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145496. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145497. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145498. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145499. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145500. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145501. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145502. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145503. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145504. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145505. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145506. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145507. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145508. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145509. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145510. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145511. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145512. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145513. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145514. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145515. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145516. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145517. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145518. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145519. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145520. "Cannot transcode due to multiple use of quantization table %d")
  145521. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145522. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145523. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145524. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145525. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145526. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145527. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145528. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145529. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145530. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145531. JMESSAGE(JERR_QUANT_COMPONENTS,
  145532. "Cannot quantize more than %d color components")
  145533. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145534. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145535. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145536. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145537. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145538. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  145539. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  145540. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  145541. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  145542. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  145543. JMESSAGE(JERR_TFILE_WRITE,
  145544. "Write failed on temporary file --- out of disk space?")
  145545. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  145546. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  145547. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  145548. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  145549. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  145550. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  145551. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  145552. JMESSAGE(JMSG_VERSION, JVERSION)
  145553. JMESSAGE(JTRC_16BIT_TABLES,
  145554. "Caution: quantization tables are too coarse for baseline JPEG")
  145555. JMESSAGE(JTRC_ADOBE,
  145556. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  145557. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  145558. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  145559. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  145560. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  145561. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  145562. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  145563. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  145564. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  145565. JMESSAGE(JTRC_EOI, "End Of Image")
  145566. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  145567. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  145568. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  145569. "Warning: thumbnail image size does not match data length %u")
  145570. JMESSAGE(JTRC_JFIF_EXTENSION,
  145571. "JFIF extension marker: type 0x%02x, length %u")
  145572. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  145573. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  145574. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  145575. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  145576. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  145577. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  145578. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  145579. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  145580. JMESSAGE(JTRC_RST, "RST%d")
  145581. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  145582. "Smoothing not supported with nonstandard sampling ratios")
  145583. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  145584. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  145585. JMESSAGE(JTRC_SOI, "Start of Image")
  145586. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  145587. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  145588. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  145589. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  145590. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  145591. JMESSAGE(JTRC_THUMB_JPEG,
  145592. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  145593. JMESSAGE(JTRC_THUMB_PALETTE,
  145594. "JFIF extension marker: palette thumbnail image, length %u")
  145595. JMESSAGE(JTRC_THUMB_RGB,
  145596. "JFIF extension marker: RGB thumbnail image, length %u")
  145597. JMESSAGE(JTRC_UNKNOWN_IDS,
  145598. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  145599. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  145600. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  145601. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  145602. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  145603. "Inconsistent progression sequence for component %d coefficient %d")
  145604. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  145605. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  145606. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  145607. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  145608. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  145609. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  145610. JMESSAGE(JWRN_MUST_RESYNC,
  145611. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  145612. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  145613. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  145614. #ifdef JMAKE_ENUM_LIST
  145615. JMSG_LASTMSGCODE
  145616. } J_MESSAGE_CODE;
  145617. #undef JMAKE_ENUM_LIST
  145618. #endif /* JMAKE_ENUM_LIST */
  145619. #undef JMESSAGE
  145620. #ifndef JERROR_H
  145621. #define JERROR_H
  145622. #define ERREXIT(cinfo,code) \
  145623. ((cinfo)->err->msg_code = (code), \
  145624. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145625. #define ERREXIT1(cinfo,code,p1) \
  145626. ((cinfo)->err->msg_code = (code), \
  145627. (cinfo)->err->msg_parm.i[0] = (p1), \
  145628. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145629. #define ERREXIT2(cinfo,code,p1,p2) \
  145630. ((cinfo)->err->msg_code = (code), \
  145631. (cinfo)->err->msg_parm.i[0] = (p1), \
  145632. (cinfo)->err->msg_parm.i[1] = (p2), \
  145633. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145634. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  145635. ((cinfo)->err->msg_code = (code), \
  145636. (cinfo)->err->msg_parm.i[0] = (p1), \
  145637. (cinfo)->err->msg_parm.i[1] = (p2), \
  145638. (cinfo)->err->msg_parm.i[2] = (p3), \
  145639. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145640. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  145641. ((cinfo)->err->msg_code = (code), \
  145642. (cinfo)->err->msg_parm.i[0] = (p1), \
  145643. (cinfo)->err->msg_parm.i[1] = (p2), \
  145644. (cinfo)->err->msg_parm.i[2] = (p3), \
  145645. (cinfo)->err->msg_parm.i[3] = (p4), \
  145646. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145647. #define ERREXITS(cinfo,code,str) \
  145648. ((cinfo)->err->msg_code = (code), \
  145649. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145650. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145651. #define MAKESTMT(stuff) do { stuff } while (0)
  145652. #define WARNMS(cinfo,code) \
  145653. ((cinfo)->err->msg_code = (code), \
  145654. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145655. #define WARNMS1(cinfo,code,p1) \
  145656. ((cinfo)->err->msg_code = (code), \
  145657. (cinfo)->err->msg_parm.i[0] = (p1), \
  145658. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145659. #define WARNMS2(cinfo,code,p1,p2) \
  145660. ((cinfo)->err->msg_code = (code), \
  145661. (cinfo)->err->msg_parm.i[0] = (p1), \
  145662. (cinfo)->err->msg_parm.i[1] = (p2), \
  145663. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145664. #define TRACEMS(cinfo,lvl,code) \
  145665. ((cinfo)->err->msg_code = (code), \
  145666. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145667. #define TRACEMS1(cinfo,lvl,code,p1) \
  145668. ((cinfo)->err->msg_code = (code), \
  145669. (cinfo)->err->msg_parm.i[0] = (p1), \
  145670. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145671. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  145672. ((cinfo)->err->msg_code = (code), \
  145673. (cinfo)->err->msg_parm.i[0] = (p1), \
  145674. (cinfo)->err->msg_parm.i[1] = (p2), \
  145675. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145676. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  145677. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145678. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  145679. (cinfo)->err->msg_code = (code); \
  145680. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145681. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  145682. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145683. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145684. (cinfo)->err->msg_code = (code); \
  145685. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145686. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  145687. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145688. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145689. _mp[4] = (p5); \
  145690. (cinfo)->err->msg_code = (code); \
  145691. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145692. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  145693. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145694. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145695. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  145696. (cinfo)->err->msg_code = (code); \
  145697. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145698. #define TRACEMSS(cinfo,lvl,code,str) \
  145699. ((cinfo)->err->msg_code = (code), \
  145700. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145701. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145702. #endif /* JERROR_H */
  145703. /*** End of inlined file: jerror.h ***/
  145704. /* fetch error codes too */
  145705. #endif
  145706. #endif /* JPEGLIB_H */
  145707. /*** End of inlined file: jpeglib.h ***/
  145708. /*** Start of inlined file: jcapimin.c ***/
  145709. #define JPEG_INTERNALS
  145710. /*** Start of inlined file: jinclude.h ***/
  145711. #ifndef __jinclude_h__
  145712. #define __jinclude_h__
  145713. /*** Start of inlined file: jconfig.h ***/
  145714. // disable all the warnings under MSVC
  145715. #ifdef _MSC_VER
  145716. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  145717. #endif
  145718. #ifdef __BORLANDC__
  145719. #pragma warn -8057
  145720. #pragma warn -8019
  145721. #pragma warn -8004
  145722. #pragma warn -8008
  145723. #endif
  145724. #define HAVE_PROTOTYPES
  145725. #define HAVE_UNSIGNED_CHAR
  145726. #define HAVE_UNSIGNED_SHORT
  145727. #undef CHAR_IS_UNSIGNED
  145728. #define HAVE_STDDEF_H
  145729. #define HAVE_STDLIB_H
  145730. #undef NEED_BSD_STRINGS
  145731. #undef NEED_SYS_TYPES_H
  145732. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145733. #undef NEED_SHORT_EXTERNAL_NAMES
  145734. #undef INCOMPLETE_TYPES_BROKEN
  145735. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145736. typedef unsigned char boolean;
  145737. #endif
  145738. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145739. #ifdef JPEG_INTERNALS
  145740. #undef RIGHT_SHIFT_IS_UNSIGNED
  145741. #endif /* JPEG_INTERNALS */
  145742. #ifdef JPEG_CJPEG_DJPEG
  145743. #define BMP_SUPPORTED /* BMP image file format */
  145744. #define GIF_SUPPORTED /* GIF image file format */
  145745. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145746. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145747. #define TARGA_SUPPORTED /* Targa image file format */
  145748. #define TWO_FILE_COMMANDLINE /* optional */
  145749. #define USE_SETMODE /* Microsoft has setmode() */
  145750. #undef NEED_SIGNAL_CATCHER
  145751. #undef DONT_USE_B_MODE
  145752. #undef PROGRESS_REPORT /* optional */
  145753. #endif /* JPEG_CJPEG_DJPEG */
  145754. /*** End of inlined file: jconfig.h ***/
  145755. /* auto configuration options */
  145756. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  145757. #ifdef HAVE_STDDEF_H
  145758. #include <stddef.h>
  145759. #endif
  145760. #ifdef HAVE_STDLIB_H
  145761. #include <stdlib.h>
  145762. #endif
  145763. #ifdef NEED_SYS_TYPES_H
  145764. #include <sys/types.h>
  145765. #endif
  145766. #include <stdio.h>
  145767. #ifdef NEED_BSD_STRINGS
  145768. #include <strings.h>
  145769. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  145770. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  145771. #else /* not BSD, assume ANSI/SysV string lib */
  145772. #include <string.h>
  145773. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  145774. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  145775. #endif
  145776. #define SIZEOF(object) ((size_t) sizeof(object))
  145777. #define JFREAD(file,buf,sizeofbuf) \
  145778. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145779. #define JFWRITE(file,buf,sizeofbuf) \
  145780. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145781. typedef enum { /* JPEG marker codes */
  145782. M_SOF0 = 0xc0,
  145783. M_SOF1 = 0xc1,
  145784. M_SOF2 = 0xc2,
  145785. M_SOF3 = 0xc3,
  145786. M_SOF5 = 0xc5,
  145787. M_SOF6 = 0xc6,
  145788. M_SOF7 = 0xc7,
  145789. M_JPG = 0xc8,
  145790. M_SOF9 = 0xc9,
  145791. M_SOF10 = 0xca,
  145792. M_SOF11 = 0xcb,
  145793. M_SOF13 = 0xcd,
  145794. M_SOF14 = 0xce,
  145795. M_SOF15 = 0xcf,
  145796. M_DHT = 0xc4,
  145797. M_DAC = 0xcc,
  145798. M_RST0 = 0xd0,
  145799. M_RST1 = 0xd1,
  145800. M_RST2 = 0xd2,
  145801. M_RST3 = 0xd3,
  145802. M_RST4 = 0xd4,
  145803. M_RST5 = 0xd5,
  145804. M_RST6 = 0xd6,
  145805. M_RST7 = 0xd7,
  145806. M_SOI = 0xd8,
  145807. M_EOI = 0xd9,
  145808. M_SOS = 0xda,
  145809. M_DQT = 0xdb,
  145810. M_DNL = 0xdc,
  145811. M_DRI = 0xdd,
  145812. M_DHP = 0xde,
  145813. M_EXP = 0xdf,
  145814. M_APP0 = 0xe0,
  145815. M_APP1 = 0xe1,
  145816. M_APP2 = 0xe2,
  145817. M_APP3 = 0xe3,
  145818. M_APP4 = 0xe4,
  145819. M_APP5 = 0xe5,
  145820. M_APP6 = 0xe6,
  145821. M_APP7 = 0xe7,
  145822. M_APP8 = 0xe8,
  145823. M_APP9 = 0xe9,
  145824. M_APP10 = 0xea,
  145825. M_APP11 = 0xeb,
  145826. M_APP12 = 0xec,
  145827. M_APP13 = 0xed,
  145828. M_APP14 = 0xee,
  145829. M_APP15 = 0xef,
  145830. M_JPG0 = 0xf0,
  145831. M_JPG13 = 0xfd,
  145832. M_COM = 0xfe,
  145833. M_TEM = 0x01,
  145834. M_ERROR = 0x100
  145835. } JPEG_MARKER;
  145836. #ifdef AVOID_TABLES
  145837. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  145838. #else
  145839. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  145840. static const int extend_test[16] = /* entry n is 2**(n-1) */
  145841. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  145842. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  145843. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  145844. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  145845. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  145846. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  145847. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  145848. #endif /* AVOID_TABLES */
  145849. #endif
  145850. /*** End of inlined file: jinclude.h ***/
  145851. GLOBAL(void)
  145852. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  145853. {
  145854. int i;
  145855. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  145856. if (version != JPEG_LIB_VERSION)
  145857. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  145858. if (structsize != SIZEOF(struct jpeg_compress_struct))
  145859. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  145860. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  145861. {
  145862. struct jpeg_error_mgr * err = cinfo->err;
  145863. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  145864. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  145865. cinfo->err = err;
  145866. cinfo->client_data = client_data;
  145867. }
  145868. cinfo->is_decompressor = FALSE;
  145869. jinit_memory_mgr((j_common_ptr) cinfo);
  145870. cinfo->progress = NULL;
  145871. cinfo->dest = NULL;
  145872. cinfo->comp_info = NULL;
  145873. for (i = 0; i < NUM_QUANT_TBLS; i++)
  145874. cinfo->quant_tbl_ptrs[i] = NULL;
  145875. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145876. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  145877. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  145878. }
  145879. cinfo->script_space = NULL;
  145880. cinfo->input_gamma = 1.0; /* in case application forgets */
  145881. cinfo->global_state = CSTATE_START;
  145882. }
  145883. GLOBAL(void)
  145884. jpeg_destroy_compress (j_compress_ptr cinfo)
  145885. {
  145886. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  145887. }
  145888. GLOBAL(void)
  145889. jpeg_abort_compress (j_compress_ptr cinfo)
  145890. {
  145891. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  145892. }
  145893. GLOBAL(void)
  145894. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  145895. {
  145896. int i;
  145897. JQUANT_TBL * qtbl;
  145898. JHUFF_TBL * htbl;
  145899. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  145900. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  145901. qtbl->sent_table = suppress;
  145902. }
  145903. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145904. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  145905. htbl->sent_table = suppress;
  145906. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  145907. htbl->sent_table = suppress;
  145908. }
  145909. }
  145910. GLOBAL(void)
  145911. jpeg_finish_compress (j_compress_ptr cinfo)
  145912. {
  145913. JDIMENSION iMCU_row;
  145914. if (cinfo->global_state == CSTATE_SCANNING ||
  145915. cinfo->global_state == CSTATE_RAW_OK) {
  145916. if (cinfo->next_scanline < cinfo->image_height)
  145917. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  145918. (*cinfo->master->finish_pass) (cinfo);
  145919. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  145920. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145921. while (! cinfo->master->is_last_pass) {
  145922. (*cinfo->master->prepare_for_pass) (cinfo);
  145923. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  145924. if (cinfo->progress != NULL) {
  145925. cinfo->progress->pass_counter = (long) iMCU_row;
  145926. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  145927. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145928. }
  145929. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  145930. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  145931. }
  145932. (*cinfo->master->finish_pass) (cinfo);
  145933. }
  145934. (*cinfo->marker->write_file_trailer) (cinfo);
  145935. (*cinfo->dest->term_destination) (cinfo);
  145936. jpeg_abort((j_common_ptr) cinfo);
  145937. }
  145938. GLOBAL(void)
  145939. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  145940. const JOCTET *dataptr, unsigned int datalen)
  145941. {
  145942. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  145943. if (cinfo->next_scanline != 0 ||
  145944. (cinfo->global_state != CSTATE_SCANNING &&
  145945. cinfo->global_state != CSTATE_RAW_OK &&
  145946. cinfo->global_state != CSTATE_WRCOEFS))
  145947. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145948. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145949. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  145950. while (datalen--) {
  145951. (*write_marker_byte) (cinfo, *dataptr);
  145952. dataptr++;
  145953. }
  145954. }
  145955. GLOBAL(void)
  145956. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  145957. {
  145958. if (cinfo->next_scanline != 0 ||
  145959. (cinfo->global_state != CSTATE_SCANNING &&
  145960. cinfo->global_state != CSTATE_RAW_OK &&
  145961. cinfo->global_state != CSTATE_WRCOEFS))
  145962. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145963. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145964. }
  145965. GLOBAL(void)
  145966. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  145967. {
  145968. (*cinfo->marker->write_marker_byte) (cinfo, val);
  145969. }
  145970. GLOBAL(void)
  145971. jpeg_write_tables (j_compress_ptr cinfo)
  145972. {
  145973. if (cinfo->global_state != CSTATE_START)
  145974. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145975. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145976. (*cinfo->dest->init_destination) (cinfo);
  145977. jinit_marker_writer(cinfo);
  145978. (*cinfo->marker->write_tables_only) (cinfo);
  145979. (*cinfo->dest->term_destination) (cinfo);
  145980. }
  145981. /*** End of inlined file: jcapimin.c ***/
  145982. /*** Start of inlined file: jcapistd.c ***/
  145983. #define JPEG_INTERNALS
  145984. GLOBAL(void)
  145985. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  145986. {
  145987. if (cinfo->global_state != CSTATE_START)
  145988. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145989. if (write_all_tables)
  145990. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  145991. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145992. (*cinfo->dest->init_destination) (cinfo);
  145993. jinit_compress_master(cinfo);
  145994. (*cinfo->master->prepare_for_pass) (cinfo);
  145995. cinfo->next_scanline = 0;
  145996. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  145997. }
  145998. GLOBAL(JDIMENSION)
  145999. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  146000. JDIMENSION num_lines)
  146001. {
  146002. JDIMENSION row_ctr, rows_left;
  146003. if (cinfo->global_state != CSTATE_SCANNING)
  146004. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146005. if (cinfo->next_scanline >= cinfo->image_height)
  146006. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146007. if (cinfo->progress != NULL) {
  146008. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146009. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146010. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146011. }
  146012. if (cinfo->master->call_pass_startup)
  146013. (*cinfo->master->pass_startup) (cinfo);
  146014. rows_left = cinfo->image_height - cinfo->next_scanline;
  146015. if (num_lines > rows_left)
  146016. num_lines = rows_left;
  146017. row_ctr = 0;
  146018. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146019. cinfo->next_scanline += row_ctr;
  146020. return row_ctr;
  146021. }
  146022. GLOBAL(JDIMENSION)
  146023. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146024. JDIMENSION num_lines)
  146025. {
  146026. JDIMENSION lines_per_iMCU_row;
  146027. if (cinfo->global_state != CSTATE_RAW_OK)
  146028. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146029. if (cinfo->next_scanline >= cinfo->image_height) {
  146030. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146031. return 0;
  146032. }
  146033. if (cinfo->progress != NULL) {
  146034. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146035. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146036. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146037. }
  146038. if (cinfo->master->call_pass_startup)
  146039. (*cinfo->master->pass_startup) (cinfo);
  146040. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146041. if (num_lines < lines_per_iMCU_row)
  146042. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146043. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146044. return 0;
  146045. }
  146046. cinfo->next_scanline += lines_per_iMCU_row;
  146047. return lines_per_iMCU_row;
  146048. }
  146049. /*** End of inlined file: jcapistd.c ***/
  146050. /*** Start of inlined file: jccoefct.c ***/
  146051. #define JPEG_INTERNALS
  146052. #ifdef ENTROPY_OPT_SUPPORTED
  146053. #define FULL_COEF_BUFFER_SUPPORTED
  146054. #else
  146055. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146056. #define FULL_COEF_BUFFER_SUPPORTED
  146057. #endif
  146058. #endif
  146059. typedef struct {
  146060. struct jpeg_c_coef_controller pub; /* public fields */
  146061. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146062. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146063. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146064. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146065. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146066. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146067. } my_coef_controller;
  146068. typedef my_coef_controller * my_coef_ptr;
  146069. METHODDEF(boolean) compress_data
  146070. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146071. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146072. METHODDEF(boolean) compress_first_pass
  146073. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146074. METHODDEF(boolean) compress_output
  146075. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146076. #endif
  146077. LOCAL(void)
  146078. start_iMCU_row (j_compress_ptr cinfo)
  146079. {
  146080. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146081. if (cinfo->comps_in_scan > 1) {
  146082. coef->MCU_rows_per_iMCU_row = 1;
  146083. } else {
  146084. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146085. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146086. else
  146087. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146088. }
  146089. coef->mcu_ctr = 0;
  146090. coef->MCU_vert_offset = 0;
  146091. }
  146092. METHODDEF(void)
  146093. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146094. {
  146095. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146096. coef->iMCU_row_num = 0;
  146097. start_iMCU_row(cinfo);
  146098. switch (pass_mode) {
  146099. case JBUF_PASS_THRU:
  146100. if (coef->whole_image[0] != NULL)
  146101. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146102. coef->pub.compress_data = compress_data;
  146103. break;
  146104. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146105. case JBUF_SAVE_AND_PASS:
  146106. if (coef->whole_image[0] == NULL)
  146107. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146108. coef->pub.compress_data = compress_first_pass;
  146109. break;
  146110. case JBUF_CRANK_DEST:
  146111. if (coef->whole_image[0] == NULL)
  146112. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146113. coef->pub.compress_data = compress_output;
  146114. break;
  146115. #endif
  146116. default:
  146117. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146118. break;
  146119. }
  146120. }
  146121. METHODDEF(boolean)
  146122. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146123. {
  146124. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146125. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146126. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146127. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146128. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146129. JDIMENSION ypos, xpos;
  146130. jpeg_component_info *compptr;
  146131. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146132. yoffset++) {
  146133. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146134. MCU_col_num++) {
  146135. blkn = 0;
  146136. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146137. compptr = cinfo->cur_comp_info[ci];
  146138. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146139. : compptr->last_col_width;
  146140. xpos = MCU_col_num * compptr->MCU_sample_width;
  146141. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146142. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146143. if (coef->iMCU_row_num < last_iMCU_row ||
  146144. yoffset+yindex < compptr->last_row_height) {
  146145. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146146. input_buf[compptr->component_index],
  146147. coef->MCU_buffer[blkn],
  146148. ypos, xpos, (JDIMENSION) blockcnt);
  146149. if (blockcnt < compptr->MCU_width) {
  146150. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146151. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146152. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146153. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146154. }
  146155. }
  146156. } else {
  146157. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146158. compptr->MCU_width * SIZEOF(JBLOCK));
  146159. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146160. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146161. }
  146162. }
  146163. blkn += compptr->MCU_width;
  146164. ypos += DCTSIZE;
  146165. }
  146166. }
  146167. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146168. coef->MCU_vert_offset = yoffset;
  146169. coef->mcu_ctr = MCU_col_num;
  146170. return FALSE;
  146171. }
  146172. }
  146173. coef->mcu_ctr = 0;
  146174. }
  146175. coef->iMCU_row_num++;
  146176. start_iMCU_row(cinfo);
  146177. return TRUE;
  146178. }
  146179. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146180. METHODDEF(boolean)
  146181. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146182. {
  146183. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146184. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146185. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146186. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146187. JCOEF lastDC;
  146188. jpeg_component_info *compptr;
  146189. JBLOCKARRAY buffer;
  146190. JBLOCKROW thisblockrow, lastblockrow;
  146191. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146192. ci++, compptr++) {
  146193. buffer = (*cinfo->mem->access_virt_barray)
  146194. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146195. coef->iMCU_row_num * compptr->v_samp_factor,
  146196. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146197. if (coef->iMCU_row_num < last_iMCU_row)
  146198. block_rows = compptr->v_samp_factor;
  146199. else {
  146200. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146201. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146202. }
  146203. blocks_across = compptr->width_in_blocks;
  146204. h_samp_factor = compptr->h_samp_factor;
  146205. ndummy = (int) (blocks_across % h_samp_factor);
  146206. if (ndummy > 0)
  146207. ndummy = h_samp_factor - ndummy;
  146208. for (block_row = 0; block_row < block_rows; block_row++) {
  146209. thisblockrow = buffer[block_row];
  146210. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146211. input_buf[ci], thisblockrow,
  146212. (JDIMENSION) (block_row * DCTSIZE),
  146213. (JDIMENSION) 0, blocks_across);
  146214. if (ndummy > 0) {
  146215. thisblockrow += blocks_across; /* => first dummy block */
  146216. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146217. lastDC = thisblockrow[-1][0];
  146218. for (bi = 0; bi < ndummy; bi++) {
  146219. thisblockrow[bi][0] = lastDC;
  146220. }
  146221. }
  146222. }
  146223. if (coef->iMCU_row_num == last_iMCU_row) {
  146224. blocks_across += ndummy; /* include lower right corner */
  146225. MCUs_across = blocks_across / h_samp_factor;
  146226. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146227. block_row++) {
  146228. thisblockrow = buffer[block_row];
  146229. lastblockrow = buffer[block_row-1];
  146230. jzero_far((void FAR *) thisblockrow,
  146231. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146232. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146233. lastDC = lastblockrow[h_samp_factor-1][0];
  146234. for (bi = 0; bi < h_samp_factor; bi++) {
  146235. thisblockrow[bi][0] = lastDC;
  146236. }
  146237. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146238. lastblockrow += h_samp_factor;
  146239. }
  146240. }
  146241. }
  146242. }
  146243. return compress_output(cinfo, input_buf);
  146244. }
  146245. METHODDEF(boolean)
  146246. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146247. {
  146248. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146249. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146250. int blkn, ci, xindex, yindex, yoffset;
  146251. JDIMENSION start_col;
  146252. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146253. JBLOCKROW buffer_ptr;
  146254. jpeg_component_info *compptr;
  146255. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146256. compptr = cinfo->cur_comp_info[ci];
  146257. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146258. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146259. coef->iMCU_row_num * compptr->v_samp_factor,
  146260. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146261. }
  146262. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146263. yoffset++) {
  146264. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146265. MCU_col_num++) {
  146266. blkn = 0; /* index of current DCT block within MCU */
  146267. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146268. compptr = cinfo->cur_comp_info[ci];
  146269. start_col = MCU_col_num * compptr->MCU_width;
  146270. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146271. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146272. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146273. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146274. }
  146275. }
  146276. }
  146277. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146278. coef->MCU_vert_offset = yoffset;
  146279. coef->mcu_ctr = MCU_col_num;
  146280. return FALSE;
  146281. }
  146282. }
  146283. coef->mcu_ctr = 0;
  146284. }
  146285. coef->iMCU_row_num++;
  146286. start_iMCU_row(cinfo);
  146287. return TRUE;
  146288. }
  146289. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146290. GLOBAL(void)
  146291. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146292. {
  146293. my_coef_ptr coef;
  146294. coef = (my_coef_ptr)
  146295. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146296. SIZEOF(my_coef_controller));
  146297. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146298. coef->pub.start_pass = start_pass_coef;
  146299. if (need_full_buffer) {
  146300. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146301. int ci;
  146302. jpeg_component_info *compptr;
  146303. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146304. ci++, compptr++) {
  146305. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146306. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146307. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146308. (long) compptr->h_samp_factor),
  146309. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146310. (long) compptr->v_samp_factor),
  146311. (JDIMENSION) compptr->v_samp_factor);
  146312. }
  146313. #else
  146314. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146315. #endif
  146316. } else {
  146317. JBLOCKROW buffer;
  146318. int i;
  146319. buffer = (JBLOCKROW)
  146320. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146321. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146322. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146323. coef->MCU_buffer[i] = buffer + i;
  146324. }
  146325. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146326. }
  146327. }
  146328. /*** End of inlined file: jccoefct.c ***/
  146329. /*** Start of inlined file: jccolor.c ***/
  146330. #define JPEG_INTERNALS
  146331. typedef struct {
  146332. struct jpeg_color_converter pub; /* public fields */
  146333. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146334. } my_color_converter;
  146335. typedef my_color_converter * my_cconvert_ptr;
  146336. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146337. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146338. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146339. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146340. #define R_Y_OFF 0 /* offset to R => Y section */
  146341. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146342. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146343. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146344. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146345. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146346. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146347. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146348. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146349. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146350. METHODDEF(void)
  146351. rgb_ycc_start (j_compress_ptr cinfo)
  146352. {
  146353. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146354. INT32 * rgb_ycc_tab;
  146355. INT32 i;
  146356. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146357. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146358. (TABLE_SIZE * SIZEOF(INT32)));
  146359. for (i = 0; i <= MAXJSAMPLE; i++) {
  146360. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146361. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146362. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146363. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146364. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146365. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146366. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146367. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146368. }
  146369. }
  146370. METHODDEF(void)
  146371. rgb_ycc_convert (j_compress_ptr cinfo,
  146372. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146373. JDIMENSION output_row, int num_rows)
  146374. {
  146375. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146376. register int r, g, b;
  146377. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146378. register JSAMPROW inptr;
  146379. register JSAMPROW outptr0, outptr1, outptr2;
  146380. register JDIMENSION col;
  146381. JDIMENSION num_cols = cinfo->image_width;
  146382. while (--num_rows >= 0) {
  146383. inptr = *input_buf++;
  146384. outptr0 = output_buf[0][output_row];
  146385. outptr1 = output_buf[1][output_row];
  146386. outptr2 = output_buf[2][output_row];
  146387. output_row++;
  146388. for (col = 0; col < num_cols; col++) {
  146389. r = GETJSAMPLE(inptr[RGB_RED]);
  146390. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146391. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146392. inptr += RGB_PIXELSIZE;
  146393. outptr0[col] = (JSAMPLE)
  146394. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146395. >> SCALEBITS);
  146396. outptr1[col] = (JSAMPLE)
  146397. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146398. >> SCALEBITS);
  146399. outptr2[col] = (JSAMPLE)
  146400. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146401. >> SCALEBITS);
  146402. }
  146403. }
  146404. }
  146405. METHODDEF(void)
  146406. rgb_gray_convert (j_compress_ptr cinfo,
  146407. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146408. JDIMENSION output_row, int num_rows)
  146409. {
  146410. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146411. register int r, g, b;
  146412. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146413. register JSAMPROW inptr;
  146414. register JSAMPROW outptr;
  146415. register JDIMENSION col;
  146416. JDIMENSION num_cols = cinfo->image_width;
  146417. while (--num_rows >= 0) {
  146418. inptr = *input_buf++;
  146419. outptr = output_buf[0][output_row];
  146420. output_row++;
  146421. for (col = 0; col < num_cols; col++) {
  146422. r = GETJSAMPLE(inptr[RGB_RED]);
  146423. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146424. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146425. inptr += RGB_PIXELSIZE;
  146426. outptr[col] = (JSAMPLE)
  146427. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146428. >> SCALEBITS);
  146429. }
  146430. }
  146431. }
  146432. METHODDEF(void)
  146433. cmyk_ycck_convert (j_compress_ptr cinfo,
  146434. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146435. JDIMENSION output_row, int num_rows)
  146436. {
  146437. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146438. register int r, g, b;
  146439. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146440. register JSAMPROW inptr;
  146441. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146442. register JDIMENSION col;
  146443. JDIMENSION num_cols = cinfo->image_width;
  146444. while (--num_rows >= 0) {
  146445. inptr = *input_buf++;
  146446. outptr0 = output_buf[0][output_row];
  146447. outptr1 = output_buf[1][output_row];
  146448. outptr2 = output_buf[2][output_row];
  146449. outptr3 = output_buf[3][output_row];
  146450. output_row++;
  146451. for (col = 0; col < num_cols; col++) {
  146452. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146453. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146454. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146455. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146456. inptr += 4;
  146457. outptr0[col] = (JSAMPLE)
  146458. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146459. >> SCALEBITS);
  146460. outptr1[col] = (JSAMPLE)
  146461. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146462. >> SCALEBITS);
  146463. outptr2[col] = (JSAMPLE)
  146464. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146465. >> SCALEBITS);
  146466. }
  146467. }
  146468. }
  146469. METHODDEF(void)
  146470. grayscale_convert (j_compress_ptr cinfo,
  146471. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146472. JDIMENSION output_row, int num_rows)
  146473. {
  146474. register JSAMPROW inptr;
  146475. register JSAMPROW outptr;
  146476. register JDIMENSION col;
  146477. JDIMENSION num_cols = cinfo->image_width;
  146478. int instride = cinfo->input_components;
  146479. while (--num_rows >= 0) {
  146480. inptr = *input_buf++;
  146481. outptr = output_buf[0][output_row];
  146482. output_row++;
  146483. for (col = 0; col < num_cols; col++) {
  146484. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146485. inptr += instride;
  146486. }
  146487. }
  146488. }
  146489. METHODDEF(void)
  146490. null_convert (j_compress_ptr cinfo,
  146491. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146492. JDIMENSION output_row, int num_rows)
  146493. {
  146494. register JSAMPROW inptr;
  146495. register JSAMPROW outptr;
  146496. register JDIMENSION col;
  146497. register int ci;
  146498. int nc = cinfo->num_components;
  146499. JDIMENSION num_cols = cinfo->image_width;
  146500. while (--num_rows >= 0) {
  146501. for (ci = 0; ci < nc; ci++) {
  146502. inptr = *input_buf;
  146503. outptr = output_buf[ci][output_row];
  146504. for (col = 0; col < num_cols; col++) {
  146505. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146506. inptr += nc;
  146507. }
  146508. }
  146509. input_buf++;
  146510. output_row++;
  146511. }
  146512. }
  146513. METHODDEF(void)
  146514. null_method (j_compress_ptr cinfo)
  146515. {
  146516. }
  146517. GLOBAL(void)
  146518. jinit_color_converter (j_compress_ptr cinfo)
  146519. {
  146520. my_cconvert_ptr cconvert;
  146521. cconvert = (my_cconvert_ptr)
  146522. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146523. SIZEOF(my_color_converter));
  146524. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146525. cconvert->pub.start_pass = null_method;
  146526. switch (cinfo->in_color_space) {
  146527. case JCS_GRAYSCALE:
  146528. if (cinfo->input_components != 1)
  146529. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146530. break;
  146531. case JCS_RGB:
  146532. #if RGB_PIXELSIZE != 3
  146533. if (cinfo->input_components != RGB_PIXELSIZE)
  146534. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146535. break;
  146536. #endif /* else share code with YCbCr */
  146537. case JCS_YCbCr:
  146538. if (cinfo->input_components != 3)
  146539. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146540. break;
  146541. case JCS_CMYK:
  146542. case JCS_YCCK:
  146543. if (cinfo->input_components != 4)
  146544. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146545. break;
  146546. default: /* JCS_UNKNOWN can be anything */
  146547. if (cinfo->input_components < 1)
  146548. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146549. break;
  146550. }
  146551. switch (cinfo->jpeg_color_space) {
  146552. case JCS_GRAYSCALE:
  146553. if (cinfo->num_components != 1)
  146554. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146555. if (cinfo->in_color_space == JCS_GRAYSCALE)
  146556. cconvert->pub.color_convert = grayscale_convert;
  146557. else if (cinfo->in_color_space == JCS_RGB) {
  146558. cconvert->pub.start_pass = rgb_ycc_start;
  146559. cconvert->pub.color_convert = rgb_gray_convert;
  146560. } else if (cinfo->in_color_space == JCS_YCbCr)
  146561. cconvert->pub.color_convert = grayscale_convert;
  146562. else
  146563. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146564. break;
  146565. case JCS_RGB:
  146566. if (cinfo->num_components != 3)
  146567. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146568. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  146569. cconvert->pub.color_convert = null_convert;
  146570. else
  146571. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146572. break;
  146573. case JCS_YCbCr:
  146574. if (cinfo->num_components != 3)
  146575. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146576. if (cinfo->in_color_space == JCS_RGB) {
  146577. cconvert->pub.start_pass = rgb_ycc_start;
  146578. cconvert->pub.color_convert = rgb_ycc_convert;
  146579. } else if (cinfo->in_color_space == JCS_YCbCr)
  146580. cconvert->pub.color_convert = null_convert;
  146581. else
  146582. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146583. break;
  146584. case JCS_CMYK:
  146585. if (cinfo->num_components != 4)
  146586. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146587. if (cinfo->in_color_space == JCS_CMYK)
  146588. cconvert->pub.color_convert = null_convert;
  146589. else
  146590. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146591. break;
  146592. case JCS_YCCK:
  146593. if (cinfo->num_components != 4)
  146594. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146595. if (cinfo->in_color_space == JCS_CMYK) {
  146596. cconvert->pub.start_pass = rgb_ycc_start;
  146597. cconvert->pub.color_convert = cmyk_ycck_convert;
  146598. } else if (cinfo->in_color_space == JCS_YCCK)
  146599. cconvert->pub.color_convert = null_convert;
  146600. else
  146601. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146602. break;
  146603. default: /* allow null conversion of JCS_UNKNOWN */
  146604. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  146605. cinfo->num_components != cinfo->input_components)
  146606. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146607. cconvert->pub.color_convert = null_convert;
  146608. break;
  146609. }
  146610. }
  146611. /*** End of inlined file: jccolor.c ***/
  146612. #undef FIX
  146613. /*** Start of inlined file: jcdctmgr.c ***/
  146614. #define JPEG_INTERNALS
  146615. /*** Start of inlined file: jdct.h ***/
  146616. #ifndef __jdct_h__
  146617. #define __jdct_h__
  146618. #if BITS_IN_JSAMPLE == 8
  146619. typedef int DCTELEM; /* 16 or 32 bits is fine */
  146620. #else
  146621. typedef INT32 DCTELEM; /* must have 32 bits */
  146622. #endif
  146623. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  146624. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  146625. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  146626. #if BITS_IN_JSAMPLE == 8
  146627. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  146628. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  146629. #else
  146630. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  146631. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  146632. #endif
  146633. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  146634. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  146635. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  146636. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146637. #define jpeg_fdct_islow jFDislow
  146638. #define jpeg_fdct_ifast jFDifast
  146639. #define jpeg_fdct_float jFDfloat
  146640. #define jpeg_idct_islow jRDislow
  146641. #define jpeg_idct_ifast jRDifast
  146642. #define jpeg_idct_float jRDfloat
  146643. #define jpeg_idct_4x4 jRD4x4
  146644. #define jpeg_idct_2x2 jRD2x2
  146645. #define jpeg_idct_1x1 jRD1x1
  146646. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146647. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  146648. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  146649. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  146650. EXTERN(void) jpeg_idct_islow
  146651. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146652. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146653. EXTERN(void) jpeg_idct_ifast
  146654. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146655. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146656. EXTERN(void) jpeg_idct_float
  146657. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146658. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146659. EXTERN(void) jpeg_idct_4x4
  146660. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146661. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146662. EXTERN(void) jpeg_idct_2x2
  146663. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146664. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146665. EXTERN(void) jpeg_idct_1x1
  146666. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146667. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146668. #define ONE ((INT32) 1)
  146669. #define CONST_SCALE (ONE << CONST_BITS)
  146670. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  146671. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  146672. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146673. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  146674. #endif
  146675. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  146676. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  146677. #endif
  146678. #ifndef MULTIPLY16C16 /* default definition */
  146679. #define MULTIPLY16C16(var,const) ((var) * (const))
  146680. #endif
  146681. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146682. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  146683. #endif
  146684. #ifndef MULTIPLY16V16 /* default definition */
  146685. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  146686. #endif
  146687. #endif
  146688. /*** End of inlined file: jdct.h ***/
  146689. /* Private declarations for DCT subsystem */
  146690. typedef struct {
  146691. struct jpeg_forward_dct pub; /* public fields */
  146692. forward_DCT_method_ptr do_dct;
  146693. DCTELEM * divisors[NUM_QUANT_TBLS];
  146694. #ifdef DCT_FLOAT_SUPPORTED
  146695. float_DCT_method_ptr do_float_dct;
  146696. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  146697. #endif
  146698. } my_fdct_controller;
  146699. typedef my_fdct_controller * my_fdct_ptr;
  146700. METHODDEF(void)
  146701. start_pass_fdctmgr (j_compress_ptr cinfo)
  146702. {
  146703. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146704. int ci, qtblno, i;
  146705. jpeg_component_info *compptr;
  146706. JQUANT_TBL * qtbl;
  146707. DCTELEM * dtbl;
  146708. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146709. ci++, compptr++) {
  146710. qtblno = compptr->quant_tbl_no;
  146711. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  146712. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  146713. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  146714. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  146715. switch (cinfo->dct_method) {
  146716. #ifdef DCT_ISLOW_SUPPORTED
  146717. case JDCT_ISLOW:
  146718. if (fdct->divisors[qtblno] == NULL) {
  146719. fdct->divisors[qtblno] = (DCTELEM *)
  146720. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146721. DCTSIZE2 * SIZEOF(DCTELEM));
  146722. }
  146723. dtbl = fdct->divisors[qtblno];
  146724. for (i = 0; i < DCTSIZE2; i++) {
  146725. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  146726. }
  146727. break;
  146728. #endif
  146729. #ifdef DCT_IFAST_SUPPORTED
  146730. case JDCT_IFAST:
  146731. {
  146732. #define CONST_BITS 14
  146733. static const INT16 aanscales[DCTSIZE2] = {
  146734. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146735. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  146736. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  146737. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  146738. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146739. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  146740. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  146741. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  146742. };
  146743. SHIFT_TEMPS
  146744. if (fdct->divisors[qtblno] == NULL) {
  146745. fdct->divisors[qtblno] = (DCTELEM *)
  146746. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146747. DCTSIZE2 * SIZEOF(DCTELEM));
  146748. }
  146749. dtbl = fdct->divisors[qtblno];
  146750. for (i = 0; i < DCTSIZE2; i++) {
  146751. dtbl[i] = (DCTELEM)
  146752. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  146753. (INT32) aanscales[i]),
  146754. CONST_BITS-3);
  146755. }
  146756. }
  146757. break;
  146758. #endif
  146759. #ifdef DCT_FLOAT_SUPPORTED
  146760. case JDCT_FLOAT:
  146761. {
  146762. FAST_FLOAT * fdtbl;
  146763. int row, col;
  146764. static const double aanscalefactor[DCTSIZE] = {
  146765. 1.0, 1.387039845, 1.306562965, 1.175875602,
  146766. 1.0, 0.785694958, 0.541196100, 0.275899379
  146767. };
  146768. if (fdct->float_divisors[qtblno] == NULL) {
  146769. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  146770. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146771. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  146772. }
  146773. fdtbl = fdct->float_divisors[qtblno];
  146774. i = 0;
  146775. for (row = 0; row < DCTSIZE; row++) {
  146776. for (col = 0; col < DCTSIZE; col++) {
  146777. fdtbl[i] = (FAST_FLOAT)
  146778. (1.0 / (((double) qtbl->quantval[i] *
  146779. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  146780. i++;
  146781. }
  146782. }
  146783. }
  146784. break;
  146785. #endif
  146786. default:
  146787. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146788. break;
  146789. }
  146790. }
  146791. }
  146792. METHODDEF(void)
  146793. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146794. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146795. JDIMENSION start_row, JDIMENSION start_col,
  146796. JDIMENSION num_blocks)
  146797. {
  146798. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146799. forward_DCT_method_ptr do_dct = fdct->do_dct;
  146800. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  146801. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146802. JDIMENSION bi;
  146803. sample_data += start_row; /* fold in the vertical offset once */
  146804. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146805. { register DCTELEM *workspaceptr;
  146806. register JSAMPROW elemptr;
  146807. register int elemr;
  146808. workspaceptr = workspace;
  146809. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146810. elemptr = sample_data[elemr] + start_col;
  146811. #if DCTSIZE == 8 /* unroll the inner loop */
  146812. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146813. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146814. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146815. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146816. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146817. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146818. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146819. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146820. #else
  146821. { register int elemc;
  146822. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146823. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146824. }
  146825. }
  146826. #endif
  146827. }
  146828. }
  146829. (*do_dct) (workspace);
  146830. { register DCTELEM temp, qval;
  146831. register int i;
  146832. register JCOEFPTR output_ptr = coef_blocks[bi];
  146833. for (i = 0; i < DCTSIZE2; i++) {
  146834. qval = divisors[i];
  146835. temp = workspace[i];
  146836. #ifdef FAST_DIVIDE
  146837. #define DIVIDE_BY(a,b) a /= b
  146838. #else
  146839. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  146840. #endif
  146841. if (temp < 0) {
  146842. temp = -temp;
  146843. temp += qval>>1; /* for rounding */
  146844. DIVIDE_BY(temp, qval);
  146845. temp = -temp;
  146846. } else {
  146847. temp += qval>>1; /* for rounding */
  146848. DIVIDE_BY(temp, qval);
  146849. }
  146850. output_ptr[i] = (JCOEF) temp;
  146851. }
  146852. }
  146853. }
  146854. }
  146855. #ifdef DCT_FLOAT_SUPPORTED
  146856. METHODDEF(void)
  146857. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146858. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146859. JDIMENSION start_row, JDIMENSION start_col,
  146860. JDIMENSION num_blocks)
  146861. {
  146862. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146863. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  146864. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  146865. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146866. JDIMENSION bi;
  146867. sample_data += start_row; /* fold in the vertical offset once */
  146868. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146869. { register FAST_FLOAT *workspaceptr;
  146870. register JSAMPROW elemptr;
  146871. register int elemr;
  146872. workspaceptr = workspace;
  146873. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146874. elemptr = sample_data[elemr] + start_col;
  146875. #if DCTSIZE == 8 /* unroll the inner loop */
  146876. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146877. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146878. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146879. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146880. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146881. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146882. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146883. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146884. #else
  146885. { register int elemc;
  146886. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146887. *workspaceptr++ = (FAST_FLOAT)
  146888. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146889. }
  146890. }
  146891. #endif
  146892. }
  146893. }
  146894. (*do_dct) (workspace);
  146895. { register FAST_FLOAT temp;
  146896. register int i;
  146897. register JCOEFPTR output_ptr = coef_blocks[bi];
  146898. for (i = 0; i < DCTSIZE2; i++) {
  146899. temp = workspace[i] * divisors[i];
  146900. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  146901. }
  146902. }
  146903. }
  146904. }
  146905. #endif /* DCT_FLOAT_SUPPORTED */
  146906. GLOBAL(void)
  146907. jinit_forward_dct (j_compress_ptr cinfo)
  146908. {
  146909. my_fdct_ptr fdct;
  146910. int i;
  146911. fdct = (my_fdct_ptr)
  146912. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146913. SIZEOF(my_fdct_controller));
  146914. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  146915. fdct->pub.start_pass = start_pass_fdctmgr;
  146916. switch (cinfo->dct_method) {
  146917. #ifdef DCT_ISLOW_SUPPORTED
  146918. case JDCT_ISLOW:
  146919. fdct->pub.forward_DCT = forward_DCT;
  146920. fdct->do_dct = jpeg_fdct_islow;
  146921. break;
  146922. #endif
  146923. #ifdef DCT_IFAST_SUPPORTED
  146924. case JDCT_IFAST:
  146925. fdct->pub.forward_DCT = forward_DCT;
  146926. fdct->do_dct = jpeg_fdct_ifast;
  146927. break;
  146928. #endif
  146929. #ifdef DCT_FLOAT_SUPPORTED
  146930. case JDCT_FLOAT:
  146931. fdct->pub.forward_DCT = forward_DCT_float;
  146932. fdct->do_float_dct = jpeg_fdct_float;
  146933. break;
  146934. #endif
  146935. default:
  146936. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146937. break;
  146938. }
  146939. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146940. fdct->divisors[i] = NULL;
  146941. #ifdef DCT_FLOAT_SUPPORTED
  146942. fdct->float_divisors[i] = NULL;
  146943. #endif
  146944. }
  146945. }
  146946. /*** End of inlined file: jcdctmgr.c ***/
  146947. #undef CONST_BITS
  146948. /*** Start of inlined file: jchuff.c ***/
  146949. #define JPEG_INTERNALS
  146950. /*** Start of inlined file: jchuff.h ***/
  146951. #ifndef _jchuff_h_
  146952. #define _jchuff_h_
  146953. #if BITS_IN_JSAMPLE == 8
  146954. #define MAX_COEF_BITS 10
  146955. #else
  146956. #define MAX_COEF_BITS 14
  146957. #endif
  146958. typedef struct {
  146959. unsigned int ehufco[256]; /* code for each symbol */
  146960. char ehufsi[256]; /* length of code for each symbol */
  146961. } c_derived_tbl;
  146962. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146963. #define jpeg_make_c_derived_tbl jMkCDerived
  146964. #define jpeg_gen_optimal_table jGenOptTbl
  146965. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146966. EXTERN(void) jpeg_make_c_derived_tbl
  146967. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  146968. c_derived_tbl ** pdtbl));
  146969. EXTERN(void) jpeg_gen_optimal_table
  146970. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  146971. #endif
  146972. /*** End of inlined file: jchuff.h ***/
  146973. /* Declarations shared with jcphuff.c */
  146974. typedef struct {
  146975. INT32 put_buffer; /* current bit-accumulation buffer */
  146976. int put_bits; /* # of bits now in it */
  146977. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  146978. } savable_state;
  146979. #ifndef NO_STRUCT_ASSIGN
  146980. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  146981. #else
  146982. #if MAX_COMPS_IN_SCAN == 4
  146983. #define ASSIGN_STATE(dest,src) \
  146984. ((dest).put_buffer = (src).put_buffer, \
  146985. (dest).put_bits = (src).put_bits, \
  146986. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  146987. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  146988. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  146989. (dest).last_dc_val[3] = (src).last_dc_val[3])
  146990. #endif
  146991. #endif
  146992. typedef struct {
  146993. struct jpeg_entropy_encoder pub; /* public fields */
  146994. savable_state saved; /* Bit buffer & DC state at start of MCU */
  146995. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  146996. int next_restart_num; /* next restart number to write (0-7) */
  146997. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  146998. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  146999. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  147000. long * dc_count_ptrs[NUM_HUFF_TBLS];
  147001. long * ac_count_ptrs[NUM_HUFF_TBLS];
  147002. #endif
  147003. } huff_entropy_encoder;
  147004. typedef huff_entropy_encoder * huff_entropy_ptr;
  147005. typedef struct {
  147006. JOCTET * next_output_byte; /* => next byte to write in buffer */
  147007. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  147008. savable_state cur; /* Current bit buffer & DC state */
  147009. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  147010. } working_state;
  147011. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147012. JBLOCKROW *MCU_data));
  147013. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147014. #ifdef ENTROPY_OPT_SUPPORTED
  147015. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147016. JBLOCKROW *MCU_data));
  147017. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147018. #endif
  147019. METHODDEF(void)
  147020. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147021. {
  147022. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147023. int ci, dctbl, actbl;
  147024. jpeg_component_info * compptr;
  147025. if (gather_statistics) {
  147026. #ifdef ENTROPY_OPT_SUPPORTED
  147027. entropy->pub.encode_mcu = encode_mcu_gather;
  147028. entropy->pub.finish_pass = finish_pass_gather;
  147029. #else
  147030. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147031. #endif
  147032. } else {
  147033. entropy->pub.encode_mcu = encode_mcu_huff;
  147034. entropy->pub.finish_pass = finish_pass_huff;
  147035. }
  147036. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147037. compptr = cinfo->cur_comp_info[ci];
  147038. dctbl = compptr->dc_tbl_no;
  147039. actbl = compptr->ac_tbl_no;
  147040. if (gather_statistics) {
  147041. #ifdef ENTROPY_OPT_SUPPORTED
  147042. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147043. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147044. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147045. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147046. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147047. entropy->dc_count_ptrs[dctbl] = (long *)
  147048. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147049. 257 * SIZEOF(long));
  147050. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147051. if (entropy->ac_count_ptrs[actbl] == NULL)
  147052. entropy->ac_count_ptrs[actbl] = (long *)
  147053. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147054. 257 * SIZEOF(long));
  147055. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147056. #endif
  147057. } else {
  147058. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147059. & entropy->dc_derived_tbls[dctbl]);
  147060. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147061. & entropy->ac_derived_tbls[actbl]);
  147062. }
  147063. entropy->saved.last_dc_val[ci] = 0;
  147064. }
  147065. entropy->saved.put_buffer = 0;
  147066. entropy->saved.put_bits = 0;
  147067. entropy->restarts_to_go = cinfo->restart_interval;
  147068. entropy->next_restart_num = 0;
  147069. }
  147070. GLOBAL(void)
  147071. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147072. c_derived_tbl ** pdtbl)
  147073. {
  147074. JHUFF_TBL *htbl;
  147075. c_derived_tbl *dtbl;
  147076. int p, i, l, lastp, si, maxsymbol;
  147077. char huffsize[257];
  147078. unsigned int huffcode[257];
  147079. unsigned int code;
  147080. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147081. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147082. htbl =
  147083. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147084. if (htbl == NULL)
  147085. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147086. if (*pdtbl == NULL)
  147087. *pdtbl = (c_derived_tbl *)
  147088. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147089. SIZEOF(c_derived_tbl));
  147090. dtbl = *pdtbl;
  147091. p = 0;
  147092. for (l = 1; l <= 16; l++) {
  147093. i = (int) htbl->bits[l];
  147094. if (i < 0 || p + i > 256) /* protect against table overrun */
  147095. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147096. while (i--)
  147097. huffsize[p++] = (char) l;
  147098. }
  147099. huffsize[p] = 0;
  147100. lastp = p;
  147101. code = 0;
  147102. si = huffsize[0];
  147103. p = 0;
  147104. while (huffsize[p]) {
  147105. while (((int) huffsize[p]) == si) {
  147106. huffcode[p++] = code;
  147107. code++;
  147108. }
  147109. if (((INT32) code) >= (((INT32) 1) << si))
  147110. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147111. code <<= 1;
  147112. si++;
  147113. }
  147114. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147115. maxsymbol = isDC ? 15 : 255;
  147116. for (p = 0; p < lastp; p++) {
  147117. i = htbl->huffval[p];
  147118. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147119. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147120. dtbl->ehufco[i] = huffcode[p];
  147121. dtbl->ehufsi[i] = huffsize[p];
  147122. }
  147123. }
  147124. #define emit_byte(state,val,action) \
  147125. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147126. if (--(state)->free_in_buffer == 0) \
  147127. if (! dump_buffer(state)) \
  147128. { action; } }
  147129. LOCAL(boolean)
  147130. dump_buffer (working_state * state)
  147131. {
  147132. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147133. if (! (*dest->empty_output_buffer) (state->cinfo))
  147134. return FALSE;
  147135. state->next_output_byte = dest->next_output_byte;
  147136. state->free_in_buffer = dest->free_in_buffer;
  147137. return TRUE;
  147138. }
  147139. INLINE
  147140. LOCAL(boolean)
  147141. emit_bits (working_state * state, unsigned int code, int size)
  147142. {
  147143. register INT32 put_buffer = (INT32) code;
  147144. register int put_bits = state->cur.put_bits;
  147145. if (size == 0)
  147146. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147147. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147148. put_bits += size; /* new number of bits in buffer */
  147149. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147150. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147151. while (put_bits >= 8) {
  147152. int c = (int) ((put_buffer >> 16) & 0xFF);
  147153. emit_byte(state, c, return FALSE);
  147154. if (c == 0xFF) { /* need to stuff a zero byte? */
  147155. emit_byte(state, 0, return FALSE);
  147156. }
  147157. put_buffer <<= 8;
  147158. put_bits -= 8;
  147159. }
  147160. state->cur.put_buffer = put_buffer; /* update state variables */
  147161. state->cur.put_bits = put_bits;
  147162. return TRUE;
  147163. }
  147164. LOCAL(boolean)
  147165. flush_bits (working_state * state)
  147166. {
  147167. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147168. return FALSE;
  147169. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147170. state->cur.put_bits = 0;
  147171. return TRUE;
  147172. }
  147173. LOCAL(boolean)
  147174. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147175. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147176. {
  147177. register int temp, temp2;
  147178. register int nbits;
  147179. register int k, r, i;
  147180. temp = temp2 = block[0] - last_dc_val;
  147181. if (temp < 0) {
  147182. temp = -temp; /* temp is abs value of input */
  147183. temp2--;
  147184. }
  147185. nbits = 0;
  147186. while (temp) {
  147187. nbits++;
  147188. temp >>= 1;
  147189. }
  147190. if (nbits > MAX_COEF_BITS+1)
  147191. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147192. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147193. return FALSE;
  147194. if (nbits) /* emit_bits rejects calls with size 0 */
  147195. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147196. return FALSE;
  147197. r = 0; /* r = run length of zeros */
  147198. for (k = 1; k < DCTSIZE2; k++) {
  147199. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147200. r++;
  147201. } else {
  147202. while (r > 15) {
  147203. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147204. return FALSE;
  147205. r -= 16;
  147206. }
  147207. temp2 = temp;
  147208. if (temp < 0) {
  147209. temp = -temp; /* temp is abs value of input */
  147210. temp2--;
  147211. }
  147212. nbits = 1; /* there must be at least one 1 bit */
  147213. while ((temp >>= 1))
  147214. nbits++;
  147215. if (nbits > MAX_COEF_BITS)
  147216. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147217. i = (r << 4) + nbits;
  147218. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147219. return FALSE;
  147220. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147221. return FALSE;
  147222. r = 0;
  147223. }
  147224. }
  147225. if (r > 0)
  147226. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147227. return FALSE;
  147228. return TRUE;
  147229. }
  147230. LOCAL(boolean)
  147231. emit_restart (working_state * state, int restart_num)
  147232. {
  147233. int ci;
  147234. if (! flush_bits(state))
  147235. return FALSE;
  147236. emit_byte(state, 0xFF, return FALSE);
  147237. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147238. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147239. state->cur.last_dc_val[ci] = 0;
  147240. return TRUE;
  147241. }
  147242. METHODDEF(boolean)
  147243. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147244. {
  147245. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147246. working_state state;
  147247. int blkn, ci;
  147248. jpeg_component_info * compptr;
  147249. state.next_output_byte = cinfo->dest->next_output_byte;
  147250. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147251. ASSIGN_STATE(state.cur, entropy->saved);
  147252. state.cinfo = cinfo;
  147253. if (cinfo->restart_interval) {
  147254. if (entropy->restarts_to_go == 0)
  147255. if (! emit_restart(&state, entropy->next_restart_num))
  147256. return FALSE;
  147257. }
  147258. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147259. ci = cinfo->MCU_membership[blkn];
  147260. compptr = cinfo->cur_comp_info[ci];
  147261. if (! encode_one_block(&state,
  147262. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147263. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147264. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147265. return FALSE;
  147266. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147267. }
  147268. cinfo->dest->next_output_byte = state.next_output_byte;
  147269. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147270. ASSIGN_STATE(entropy->saved, state.cur);
  147271. if (cinfo->restart_interval) {
  147272. if (entropy->restarts_to_go == 0) {
  147273. entropy->restarts_to_go = cinfo->restart_interval;
  147274. entropy->next_restart_num++;
  147275. entropy->next_restart_num &= 7;
  147276. }
  147277. entropy->restarts_to_go--;
  147278. }
  147279. return TRUE;
  147280. }
  147281. METHODDEF(void)
  147282. finish_pass_huff (j_compress_ptr cinfo)
  147283. {
  147284. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147285. working_state state;
  147286. state.next_output_byte = cinfo->dest->next_output_byte;
  147287. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147288. ASSIGN_STATE(state.cur, entropy->saved);
  147289. state.cinfo = cinfo;
  147290. if (! flush_bits(&state))
  147291. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147292. cinfo->dest->next_output_byte = state.next_output_byte;
  147293. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147294. ASSIGN_STATE(entropy->saved, state.cur);
  147295. }
  147296. #ifdef ENTROPY_OPT_SUPPORTED
  147297. LOCAL(void)
  147298. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147299. long dc_counts[], long ac_counts[])
  147300. {
  147301. register int temp;
  147302. register int nbits;
  147303. register int k, r;
  147304. temp = block[0] - last_dc_val;
  147305. if (temp < 0)
  147306. temp = -temp;
  147307. nbits = 0;
  147308. while (temp) {
  147309. nbits++;
  147310. temp >>= 1;
  147311. }
  147312. if (nbits > MAX_COEF_BITS+1)
  147313. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147314. dc_counts[nbits]++;
  147315. r = 0; /* r = run length of zeros */
  147316. for (k = 1; k < DCTSIZE2; k++) {
  147317. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147318. r++;
  147319. } else {
  147320. while (r > 15) {
  147321. ac_counts[0xF0]++;
  147322. r -= 16;
  147323. }
  147324. if (temp < 0)
  147325. temp = -temp;
  147326. nbits = 1; /* there must be at least one 1 bit */
  147327. while ((temp >>= 1))
  147328. nbits++;
  147329. if (nbits > MAX_COEF_BITS)
  147330. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147331. ac_counts[(r << 4) + nbits]++;
  147332. r = 0;
  147333. }
  147334. }
  147335. if (r > 0)
  147336. ac_counts[0]++;
  147337. }
  147338. METHODDEF(boolean)
  147339. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147340. {
  147341. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147342. int blkn, ci;
  147343. jpeg_component_info * compptr;
  147344. if (cinfo->restart_interval) {
  147345. if (entropy->restarts_to_go == 0) {
  147346. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147347. entropy->saved.last_dc_val[ci] = 0;
  147348. entropy->restarts_to_go = cinfo->restart_interval;
  147349. }
  147350. entropy->restarts_to_go--;
  147351. }
  147352. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147353. ci = cinfo->MCU_membership[blkn];
  147354. compptr = cinfo->cur_comp_info[ci];
  147355. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147356. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147357. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147358. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147359. }
  147360. return TRUE;
  147361. }
  147362. GLOBAL(void)
  147363. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147364. {
  147365. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147366. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147367. int codesize[257]; /* codesize[k] = code length of symbol k */
  147368. int others[257]; /* next symbol in current branch of tree */
  147369. int c1, c2;
  147370. int p, i, j;
  147371. long v;
  147372. MEMZERO(bits, SIZEOF(bits));
  147373. MEMZERO(codesize, SIZEOF(codesize));
  147374. for (i = 0; i < 257; i++)
  147375. others[i] = -1; /* init links to empty */
  147376. freq[256] = 1; /* make sure 256 has a nonzero count */
  147377. for (;;) {
  147378. c1 = -1;
  147379. v = 1000000000L;
  147380. for (i = 0; i <= 256; i++) {
  147381. if (freq[i] && freq[i] <= v) {
  147382. v = freq[i];
  147383. c1 = i;
  147384. }
  147385. }
  147386. c2 = -1;
  147387. v = 1000000000L;
  147388. for (i = 0; i <= 256; i++) {
  147389. if (freq[i] && freq[i] <= v && i != c1) {
  147390. v = freq[i];
  147391. c2 = i;
  147392. }
  147393. }
  147394. if (c2 < 0)
  147395. break;
  147396. freq[c1] += freq[c2];
  147397. freq[c2] = 0;
  147398. codesize[c1]++;
  147399. while (others[c1] >= 0) {
  147400. c1 = others[c1];
  147401. codesize[c1]++;
  147402. }
  147403. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147404. codesize[c2]++;
  147405. while (others[c2] >= 0) {
  147406. c2 = others[c2];
  147407. codesize[c2]++;
  147408. }
  147409. }
  147410. for (i = 0; i <= 256; i++) {
  147411. if (codesize[i]) {
  147412. if (codesize[i] > MAX_CLEN)
  147413. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147414. bits[codesize[i]]++;
  147415. }
  147416. }
  147417. for (i = MAX_CLEN; i > 16; i--) {
  147418. while (bits[i] > 0) {
  147419. j = i - 2; /* find length of new prefix to be used */
  147420. while (bits[j] == 0)
  147421. j--;
  147422. bits[i] -= 2; /* remove two symbols */
  147423. bits[i-1]++; /* one goes in this length */
  147424. bits[j+1] += 2; /* two new symbols in this length */
  147425. bits[j]--; /* symbol of this length is now a prefix */
  147426. }
  147427. }
  147428. while (bits[i] == 0) /* find largest codelength still in use */
  147429. i--;
  147430. bits[i]--;
  147431. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147432. p = 0;
  147433. for (i = 1; i <= MAX_CLEN; i++) {
  147434. for (j = 0; j <= 255; j++) {
  147435. if (codesize[j] == i) {
  147436. htbl->huffval[p] = (UINT8) j;
  147437. p++;
  147438. }
  147439. }
  147440. }
  147441. htbl->sent_table = FALSE;
  147442. }
  147443. METHODDEF(void)
  147444. finish_pass_gather (j_compress_ptr cinfo)
  147445. {
  147446. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147447. int ci, dctbl, actbl;
  147448. jpeg_component_info * compptr;
  147449. JHUFF_TBL **htblptr;
  147450. boolean did_dc[NUM_HUFF_TBLS];
  147451. boolean did_ac[NUM_HUFF_TBLS];
  147452. MEMZERO(did_dc, SIZEOF(did_dc));
  147453. MEMZERO(did_ac, SIZEOF(did_ac));
  147454. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147455. compptr = cinfo->cur_comp_info[ci];
  147456. dctbl = compptr->dc_tbl_no;
  147457. actbl = compptr->ac_tbl_no;
  147458. if (! did_dc[dctbl]) {
  147459. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147460. if (*htblptr == NULL)
  147461. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147462. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147463. did_dc[dctbl] = TRUE;
  147464. }
  147465. if (! did_ac[actbl]) {
  147466. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147467. if (*htblptr == NULL)
  147468. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147469. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147470. did_ac[actbl] = TRUE;
  147471. }
  147472. }
  147473. }
  147474. #endif /* ENTROPY_OPT_SUPPORTED */
  147475. GLOBAL(void)
  147476. jinit_huff_encoder (j_compress_ptr cinfo)
  147477. {
  147478. huff_entropy_ptr entropy;
  147479. int i;
  147480. entropy = (huff_entropy_ptr)
  147481. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147482. SIZEOF(huff_entropy_encoder));
  147483. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147484. entropy->pub.start_pass = start_pass_huff;
  147485. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147486. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147487. #ifdef ENTROPY_OPT_SUPPORTED
  147488. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147489. #endif
  147490. }
  147491. }
  147492. /*** End of inlined file: jchuff.c ***/
  147493. #undef emit_byte
  147494. /*** Start of inlined file: jcinit.c ***/
  147495. #define JPEG_INTERNALS
  147496. GLOBAL(void)
  147497. jinit_compress_master (j_compress_ptr cinfo)
  147498. {
  147499. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147500. if (! cinfo->raw_data_in) {
  147501. jinit_color_converter(cinfo);
  147502. jinit_downsampler(cinfo);
  147503. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147504. }
  147505. jinit_forward_dct(cinfo);
  147506. if (cinfo->arith_code) {
  147507. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147508. } else {
  147509. if (cinfo->progressive_mode) {
  147510. #ifdef C_PROGRESSIVE_SUPPORTED
  147511. jinit_phuff_encoder(cinfo);
  147512. #else
  147513. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147514. #endif
  147515. } else
  147516. jinit_huff_encoder(cinfo);
  147517. }
  147518. jinit_c_coef_controller(cinfo,
  147519. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147520. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147521. jinit_marker_writer(cinfo);
  147522. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147523. (*cinfo->marker->write_file_header) (cinfo);
  147524. }
  147525. /*** End of inlined file: jcinit.c ***/
  147526. /*** Start of inlined file: jcmainct.c ***/
  147527. #define JPEG_INTERNALS
  147528. #undef FULL_MAIN_BUFFER_SUPPORTED
  147529. typedef struct {
  147530. struct jpeg_c_main_controller pub; /* public fields */
  147531. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147532. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147533. boolean suspended; /* remember if we suspended output */
  147534. J_BUF_MODE pass_mode; /* current operating mode */
  147535. JSAMPARRAY buffer[MAX_COMPONENTS];
  147536. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147537. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147538. #endif
  147539. } my_main_controller;
  147540. typedef my_main_controller * my_main_ptr;
  147541. METHODDEF(void) process_data_simple_main
  147542. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147543. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147544. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147545. METHODDEF(void) process_data_buffer_main
  147546. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147547. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147548. #endif
  147549. METHODDEF(void)
  147550. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  147551. {
  147552. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147553. if (cinfo->raw_data_in)
  147554. return;
  147555. main_->cur_iMCU_row = 0; /* initialize counters */
  147556. main_->rowgroup_ctr = 0;
  147557. main_->suspended = FALSE;
  147558. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  147559. switch (pass_mode) {
  147560. case JBUF_PASS_THRU:
  147561. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147562. if (main_->whole_image[0] != NULL)
  147563. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147564. #endif
  147565. main_->pub.process_data = process_data_simple_main;
  147566. break;
  147567. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147568. case JBUF_SAVE_SOURCE:
  147569. case JBUF_CRANK_DEST:
  147570. case JBUF_SAVE_AND_PASS:
  147571. if (main_->whole_image[0] == NULL)
  147572. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147573. main_->pub.process_data = process_data_buffer_main;
  147574. break;
  147575. #endif
  147576. default:
  147577. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147578. break;
  147579. }
  147580. }
  147581. METHODDEF(void)
  147582. process_data_simple_main (j_compress_ptr cinfo,
  147583. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147584. JDIMENSION in_rows_avail)
  147585. {
  147586. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147587. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147588. if (main_->rowgroup_ctr < DCTSIZE)
  147589. (*cinfo->prep->pre_process_data) (cinfo,
  147590. input_buf, in_row_ctr, in_rows_avail,
  147591. main_->buffer, &main_->rowgroup_ctr,
  147592. (JDIMENSION) DCTSIZE);
  147593. if (main_->rowgroup_ctr != DCTSIZE)
  147594. return;
  147595. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  147596. if (! main_->suspended) {
  147597. (*in_row_ctr)--;
  147598. main_->suspended = TRUE;
  147599. }
  147600. return;
  147601. }
  147602. if (main_->suspended) {
  147603. (*in_row_ctr)++;
  147604. main_->suspended = FALSE;
  147605. }
  147606. main_->rowgroup_ctr = 0;
  147607. main_->cur_iMCU_row++;
  147608. }
  147609. }
  147610. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147611. METHODDEF(void)
  147612. process_data_buffer_main (j_compress_ptr cinfo,
  147613. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147614. JDIMENSION in_rows_avail)
  147615. {
  147616. my_main_ptr main = (my_main_ptr) cinfo->main;
  147617. int ci;
  147618. jpeg_component_info *compptr;
  147619. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  147620. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147621. if (main->rowgroup_ctr == 0) {
  147622. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147623. ci++, compptr++) {
  147624. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  147625. ((j_common_ptr) cinfo, main->whole_image[ci],
  147626. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  147627. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  147628. }
  147629. if (! writing) {
  147630. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  147631. main->rowgroup_ctr = DCTSIZE;
  147632. }
  147633. }
  147634. if (writing) {
  147635. (*cinfo->prep->pre_process_data) (cinfo,
  147636. input_buf, in_row_ctr, in_rows_avail,
  147637. main->buffer, &main->rowgroup_ctr,
  147638. (JDIMENSION) DCTSIZE);
  147639. if (main->rowgroup_ctr < DCTSIZE)
  147640. return;
  147641. }
  147642. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  147643. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  147644. if (! main->suspended) {
  147645. (*in_row_ctr)--;
  147646. main->suspended = TRUE;
  147647. }
  147648. return;
  147649. }
  147650. if (main->suspended) {
  147651. (*in_row_ctr)++;
  147652. main->suspended = FALSE;
  147653. }
  147654. }
  147655. main->rowgroup_ctr = 0;
  147656. main->cur_iMCU_row++;
  147657. }
  147658. }
  147659. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  147660. GLOBAL(void)
  147661. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  147662. {
  147663. my_main_ptr main_;
  147664. int ci;
  147665. jpeg_component_info *compptr;
  147666. main_ = (my_main_ptr)
  147667. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147668. SIZEOF(my_main_controller));
  147669. cinfo->main = (struct jpeg_c_main_controller *) main_;
  147670. main_->pub.start_pass = start_pass_main;
  147671. if (cinfo->raw_data_in)
  147672. return;
  147673. if (need_full_buffer) {
  147674. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147675. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147676. ci++, compptr++) {
  147677. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  147678. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  147679. compptr->width_in_blocks * DCTSIZE,
  147680. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  147681. (long) compptr->v_samp_factor) * DCTSIZE,
  147682. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147683. }
  147684. #else
  147685. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147686. #endif
  147687. } else {
  147688. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147689. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  147690. #endif
  147691. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147692. ci++, compptr++) {
  147693. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  147694. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147695. compptr->width_in_blocks * DCTSIZE,
  147696. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147697. }
  147698. }
  147699. }
  147700. /*** End of inlined file: jcmainct.c ***/
  147701. /*** Start of inlined file: jcmarker.c ***/
  147702. #define JPEG_INTERNALS
  147703. typedef struct {
  147704. struct jpeg_marker_writer pub; /* public fields */
  147705. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  147706. } my_marker_writer;
  147707. typedef my_marker_writer * my_marker_ptr;
  147708. LOCAL(void)
  147709. emit_byte (j_compress_ptr cinfo, int val)
  147710. {
  147711. struct jpeg_destination_mgr * dest = cinfo->dest;
  147712. *(dest->next_output_byte)++ = (JOCTET) val;
  147713. if (--dest->free_in_buffer == 0) {
  147714. if (! (*dest->empty_output_buffer) (cinfo))
  147715. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147716. }
  147717. }
  147718. LOCAL(void)
  147719. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  147720. {
  147721. emit_byte(cinfo, 0xFF);
  147722. emit_byte(cinfo, (int) mark);
  147723. }
  147724. LOCAL(void)
  147725. emit_2bytes (j_compress_ptr cinfo, int value)
  147726. {
  147727. emit_byte(cinfo, (value >> 8) & 0xFF);
  147728. emit_byte(cinfo, value & 0xFF);
  147729. }
  147730. LOCAL(int)
  147731. emit_dqt (j_compress_ptr cinfo, int index)
  147732. {
  147733. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  147734. int prec;
  147735. int i;
  147736. if (qtbl == NULL)
  147737. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  147738. prec = 0;
  147739. for (i = 0; i < DCTSIZE2; i++) {
  147740. if (qtbl->quantval[i] > 255)
  147741. prec = 1;
  147742. }
  147743. if (! qtbl->sent_table) {
  147744. emit_marker(cinfo, M_DQT);
  147745. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  147746. emit_byte(cinfo, index + (prec<<4));
  147747. for (i = 0; i < DCTSIZE2; i++) {
  147748. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  147749. if (prec)
  147750. emit_byte(cinfo, (int) (qval >> 8));
  147751. emit_byte(cinfo, (int) (qval & 0xFF));
  147752. }
  147753. qtbl->sent_table = TRUE;
  147754. }
  147755. return prec;
  147756. }
  147757. LOCAL(void)
  147758. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  147759. {
  147760. JHUFF_TBL * htbl;
  147761. int length, i;
  147762. if (is_ac) {
  147763. htbl = cinfo->ac_huff_tbl_ptrs[index];
  147764. index += 0x10; /* output index has AC bit set */
  147765. } else {
  147766. htbl = cinfo->dc_huff_tbl_ptrs[index];
  147767. }
  147768. if (htbl == NULL)
  147769. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  147770. if (! htbl->sent_table) {
  147771. emit_marker(cinfo, M_DHT);
  147772. length = 0;
  147773. for (i = 1; i <= 16; i++)
  147774. length += htbl->bits[i];
  147775. emit_2bytes(cinfo, length + 2 + 1 + 16);
  147776. emit_byte(cinfo, index);
  147777. for (i = 1; i <= 16; i++)
  147778. emit_byte(cinfo, htbl->bits[i]);
  147779. for (i = 0; i < length; i++)
  147780. emit_byte(cinfo, htbl->huffval[i]);
  147781. htbl->sent_table = TRUE;
  147782. }
  147783. }
  147784. LOCAL(void)
  147785. emit_dac (j_compress_ptr cinfo)
  147786. {
  147787. #ifdef C_ARITH_CODING_SUPPORTED
  147788. char dc_in_use[NUM_ARITH_TBLS];
  147789. char ac_in_use[NUM_ARITH_TBLS];
  147790. int length, i;
  147791. jpeg_component_info *compptr;
  147792. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147793. dc_in_use[i] = ac_in_use[i] = 0;
  147794. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147795. compptr = cinfo->cur_comp_info[i];
  147796. dc_in_use[compptr->dc_tbl_no] = 1;
  147797. ac_in_use[compptr->ac_tbl_no] = 1;
  147798. }
  147799. length = 0;
  147800. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147801. length += dc_in_use[i] + ac_in_use[i];
  147802. emit_marker(cinfo, M_DAC);
  147803. emit_2bytes(cinfo, length*2 + 2);
  147804. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  147805. if (dc_in_use[i]) {
  147806. emit_byte(cinfo, i);
  147807. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  147808. }
  147809. if (ac_in_use[i]) {
  147810. emit_byte(cinfo, i + 0x10);
  147811. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  147812. }
  147813. }
  147814. #endif /* C_ARITH_CODING_SUPPORTED */
  147815. }
  147816. LOCAL(void)
  147817. emit_dri (j_compress_ptr cinfo)
  147818. {
  147819. emit_marker(cinfo, M_DRI);
  147820. emit_2bytes(cinfo, 4); /* fixed length */
  147821. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  147822. }
  147823. LOCAL(void)
  147824. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  147825. {
  147826. int ci;
  147827. jpeg_component_info *compptr;
  147828. emit_marker(cinfo, code);
  147829. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  147830. if ((long) cinfo->image_height > 65535L ||
  147831. (long) cinfo->image_width > 65535L)
  147832. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  147833. emit_byte(cinfo, cinfo->data_precision);
  147834. emit_2bytes(cinfo, (int) cinfo->image_height);
  147835. emit_2bytes(cinfo, (int) cinfo->image_width);
  147836. emit_byte(cinfo, cinfo->num_components);
  147837. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147838. ci++, compptr++) {
  147839. emit_byte(cinfo, compptr->component_id);
  147840. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  147841. emit_byte(cinfo, compptr->quant_tbl_no);
  147842. }
  147843. }
  147844. LOCAL(void)
  147845. emit_sos (j_compress_ptr cinfo)
  147846. {
  147847. int i, td, ta;
  147848. jpeg_component_info *compptr;
  147849. emit_marker(cinfo, M_SOS);
  147850. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  147851. emit_byte(cinfo, cinfo->comps_in_scan);
  147852. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147853. compptr = cinfo->cur_comp_info[i];
  147854. emit_byte(cinfo, compptr->component_id);
  147855. td = compptr->dc_tbl_no;
  147856. ta = compptr->ac_tbl_no;
  147857. if (cinfo->progressive_mode) {
  147858. if (cinfo->Ss == 0) {
  147859. ta = 0; /* DC scan */
  147860. if (cinfo->Ah != 0 && !cinfo->arith_code)
  147861. td = 0; /* no DC table either */
  147862. } else {
  147863. td = 0; /* AC scan */
  147864. }
  147865. }
  147866. emit_byte(cinfo, (td << 4) + ta);
  147867. }
  147868. emit_byte(cinfo, cinfo->Ss);
  147869. emit_byte(cinfo, cinfo->Se);
  147870. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  147871. }
  147872. LOCAL(void)
  147873. emit_jfif_app0 (j_compress_ptr cinfo)
  147874. {
  147875. emit_marker(cinfo, M_APP0);
  147876. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  147877. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  147878. emit_byte(cinfo, 0x46);
  147879. emit_byte(cinfo, 0x49);
  147880. emit_byte(cinfo, 0x46);
  147881. emit_byte(cinfo, 0);
  147882. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  147883. emit_byte(cinfo, cinfo->JFIF_minor_version);
  147884. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  147885. emit_2bytes(cinfo, (int) cinfo->X_density);
  147886. emit_2bytes(cinfo, (int) cinfo->Y_density);
  147887. emit_byte(cinfo, 0); /* No thumbnail image */
  147888. emit_byte(cinfo, 0);
  147889. }
  147890. LOCAL(void)
  147891. emit_adobe_app14 (j_compress_ptr cinfo)
  147892. {
  147893. emit_marker(cinfo, M_APP14);
  147894. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  147895. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  147896. emit_byte(cinfo, 0x64);
  147897. emit_byte(cinfo, 0x6F);
  147898. emit_byte(cinfo, 0x62);
  147899. emit_byte(cinfo, 0x65);
  147900. emit_2bytes(cinfo, 100); /* Version */
  147901. emit_2bytes(cinfo, 0); /* Flags0 */
  147902. emit_2bytes(cinfo, 0); /* Flags1 */
  147903. switch (cinfo->jpeg_color_space) {
  147904. case JCS_YCbCr:
  147905. emit_byte(cinfo, 1); /* Color transform = 1 */
  147906. break;
  147907. case JCS_YCCK:
  147908. emit_byte(cinfo, 2); /* Color transform = 2 */
  147909. break;
  147910. default:
  147911. emit_byte(cinfo, 0); /* Color transform = 0 */
  147912. break;
  147913. }
  147914. }
  147915. METHODDEF(void)
  147916. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  147917. {
  147918. if (datalen > (unsigned int) 65533) /* safety check */
  147919. ERREXIT(cinfo, JERR_BAD_LENGTH);
  147920. emit_marker(cinfo, (JPEG_MARKER) marker);
  147921. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  147922. }
  147923. METHODDEF(void)
  147924. write_marker_byte (j_compress_ptr cinfo, int val)
  147925. {
  147926. emit_byte(cinfo, val);
  147927. }
  147928. METHODDEF(void)
  147929. write_file_header (j_compress_ptr cinfo)
  147930. {
  147931. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147932. emit_marker(cinfo, M_SOI); /* first the SOI */
  147933. marker->last_restart_interval = 0;
  147934. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  147935. emit_jfif_app0(cinfo);
  147936. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  147937. emit_adobe_app14(cinfo);
  147938. }
  147939. METHODDEF(void)
  147940. write_frame_header (j_compress_ptr cinfo)
  147941. {
  147942. int ci, prec;
  147943. boolean is_baseline;
  147944. jpeg_component_info *compptr;
  147945. prec = 0;
  147946. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147947. ci++, compptr++) {
  147948. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  147949. }
  147950. if (cinfo->arith_code || cinfo->progressive_mode ||
  147951. cinfo->data_precision != 8) {
  147952. is_baseline = FALSE;
  147953. } else {
  147954. is_baseline = TRUE;
  147955. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147956. ci++, compptr++) {
  147957. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  147958. is_baseline = FALSE;
  147959. }
  147960. if (prec && is_baseline) {
  147961. is_baseline = FALSE;
  147962. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  147963. }
  147964. }
  147965. if (cinfo->arith_code) {
  147966. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  147967. } else {
  147968. if (cinfo->progressive_mode)
  147969. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  147970. else if (is_baseline)
  147971. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  147972. else
  147973. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  147974. }
  147975. }
  147976. METHODDEF(void)
  147977. write_scan_header (j_compress_ptr cinfo)
  147978. {
  147979. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147980. int i;
  147981. jpeg_component_info *compptr;
  147982. if (cinfo->arith_code) {
  147983. emit_dac(cinfo);
  147984. } else {
  147985. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147986. compptr = cinfo->cur_comp_info[i];
  147987. if (cinfo->progressive_mode) {
  147988. if (cinfo->Ss == 0) {
  147989. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  147990. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  147991. } else {
  147992. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  147993. }
  147994. } else {
  147995. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  147996. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  147997. }
  147998. }
  147999. }
  148000. if (cinfo->restart_interval != marker->last_restart_interval) {
  148001. emit_dri(cinfo);
  148002. marker->last_restart_interval = cinfo->restart_interval;
  148003. }
  148004. emit_sos(cinfo);
  148005. }
  148006. METHODDEF(void)
  148007. write_file_trailer (j_compress_ptr cinfo)
  148008. {
  148009. emit_marker(cinfo, M_EOI);
  148010. }
  148011. METHODDEF(void)
  148012. write_tables_only (j_compress_ptr cinfo)
  148013. {
  148014. int i;
  148015. emit_marker(cinfo, M_SOI);
  148016. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148017. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148018. (void) emit_dqt(cinfo, i);
  148019. }
  148020. if (! cinfo->arith_code) {
  148021. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148022. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148023. emit_dht(cinfo, i, FALSE);
  148024. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148025. emit_dht(cinfo, i, TRUE);
  148026. }
  148027. }
  148028. emit_marker(cinfo, M_EOI);
  148029. }
  148030. GLOBAL(void)
  148031. jinit_marker_writer (j_compress_ptr cinfo)
  148032. {
  148033. my_marker_ptr marker;
  148034. marker = (my_marker_ptr)
  148035. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148036. SIZEOF(my_marker_writer));
  148037. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148038. marker->pub.write_file_header = write_file_header;
  148039. marker->pub.write_frame_header = write_frame_header;
  148040. marker->pub.write_scan_header = write_scan_header;
  148041. marker->pub.write_file_trailer = write_file_trailer;
  148042. marker->pub.write_tables_only = write_tables_only;
  148043. marker->pub.write_marker_header = write_marker_header;
  148044. marker->pub.write_marker_byte = write_marker_byte;
  148045. marker->last_restart_interval = 0;
  148046. }
  148047. /*** End of inlined file: jcmarker.c ***/
  148048. /*** Start of inlined file: jcmaster.c ***/
  148049. #define JPEG_INTERNALS
  148050. typedef enum {
  148051. main_pass, /* input data, also do first output step */
  148052. huff_opt_pass, /* Huffman code optimization pass */
  148053. output_pass /* data output pass */
  148054. } c_pass_type;
  148055. typedef struct {
  148056. struct jpeg_comp_master pub; /* public fields */
  148057. c_pass_type pass_type; /* the type of the current pass */
  148058. int pass_number; /* # of passes completed */
  148059. int total_passes; /* total # of passes needed */
  148060. int scan_number; /* current index in scan_info[] */
  148061. } my_comp_master;
  148062. typedef my_comp_master * my_master_ptr;
  148063. LOCAL(void)
  148064. initial_setup (j_compress_ptr cinfo)
  148065. {
  148066. int ci;
  148067. jpeg_component_info *compptr;
  148068. long samplesperrow;
  148069. JDIMENSION jd_samplesperrow;
  148070. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148071. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148072. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148073. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148074. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148075. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148076. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148077. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148078. if ((long) jd_samplesperrow != samplesperrow)
  148079. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148080. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148081. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148082. if (cinfo->num_components > MAX_COMPONENTS)
  148083. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148084. MAX_COMPONENTS);
  148085. cinfo->max_h_samp_factor = 1;
  148086. cinfo->max_v_samp_factor = 1;
  148087. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148088. ci++, compptr++) {
  148089. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148090. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148091. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148092. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148093. compptr->h_samp_factor);
  148094. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148095. compptr->v_samp_factor);
  148096. }
  148097. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148098. ci++, compptr++) {
  148099. compptr->component_index = ci;
  148100. compptr->DCT_scaled_size = DCTSIZE;
  148101. compptr->width_in_blocks = (JDIMENSION)
  148102. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148103. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148104. compptr->height_in_blocks = (JDIMENSION)
  148105. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148106. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148107. compptr->downsampled_width = (JDIMENSION)
  148108. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148109. (long) cinfo->max_h_samp_factor);
  148110. compptr->downsampled_height = (JDIMENSION)
  148111. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148112. (long) cinfo->max_v_samp_factor);
  148113. compptr->component_needed = TRUE;
  148114. }
  148115. cinfo->total_iMCU_rows = (JDIMENSION)
  148116. jdiv_round_up((long) cinfo->image_height,
  148117. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148118. }
  148119. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148120. LOCAL(void)
  148121. validate_script (j_compress_ptr cinfo)
  148122. {
  148123. const jpeg_scan_info * scanptr;
  148124. int scanno, ncomps, ci, coefi, thisi;
  148125. int Ss, Se, Ah, Al;
  148126. boolean component_sent[MAX_COMPONENTS];
  148127. #ifdef C_PROGRESSIVE_SUPPORTED
  148128. int * last_bitpos_ptr;
  148129. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148130. #endif
  148131. if (cinfo->num_scans <= 0)
  148132. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148133. scanptr = cinfo->scan_info;
  148134. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148135. #ifdef C_PROGRESSIVE_SUPPORTED
  148136. cinfo->progressive_mode = TRUE;
  148137. last_bitpos_ptr = & last_bitpos[0][0];
  148138. for (ci = 0; ci < cinfo->num_components; ci++)
  148139. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148140. *last_bitpos_ptr++ = -1;
  148141. #else
  148142. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148143. #endif
  148144. } else {
  148145. cinfo->progressive_mode = FALSE;
  148146. for (ci = 0; ci < cinfo->num_components; ci++)
  148147. component_sent[ci] = FALSE;
  148148. }
  148149. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148150. ncomps = scanptr->comps_in_scan;
  148151. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148152. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148153. for (ci = 0; ci < ncomps; ci++) {
  148154. thisi = scanptr->component_index[ci];
  148155. if (thisi < 0 || thisi >= cinfo->num_components)
  148156. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148157. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148158. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148159. }
  148160. Ss = scanptr->Ss;
  148161. Se = scanptr->Se;
  148162. Ah = scanptr->Ah;
  148163. Al = scanptr->Al;
  148164. if (cinfo->progressive_mode) {
  148165. #ifdef C_PROGRESSIVE_SUPPORTED
  148166. #if BITS_IN_JSAMPLE == 8
  148167. #define MAX_AH_AL 10
  148168. #else
  148169. #define MAX_AH_AL 13
  148170. #endif
  148171. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148172. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148173. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148174. if (Ss == 0) {
  148175. if (Se != 0) /* DC and AC together not OK */
  148176. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148177. } else {
  148178. if (ncomps != 1) /* AC scans must be for only one component */
  148179. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148180. }
  148181. for (ci = 0; ci < ncomps; ci++) {
  148182. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148183. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148184. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148185. for (coefi = Ss; coefi <= Se; coefi++) {
  148186. if (last_bitpos_ptr[coefi] < 0) {
  148187. if (Ah != 0)
  148188. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148189. } else {
  148190. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148191. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148192. }
  148193. last_bitpos_ptr[coefi] = Al;
  148194. }
  148195. }
  148196. #endif
  148197. } else {
  148198. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148199. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148200. for (ci = 0; ci < ncomps; ci++) {
  148201. thisi = scanptr->component_index[ci];
  148202. if (component_sent[thisi])
  148203. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148204. component_sent[thisi] = TRUE;
  148205. }
  148206. }
  148207. }
  148208. if (cinfo->progressive_mode) {
  148209. #ifdef C_PROGRESSIVE_SUPPORTED
  148210. for (ci = 0; ci < cinfo->num_components; ci++) {
  148211. if (last_bitpos[ci][0] < 0)
  148212. ERREXIT(cinfo, JERR_MISSING_DATA);
  148213. }
  148214. #endif
  148215. } else {
  148216. for (ci = 0; ci < cinfo->num_components; ci++) {
  148217. if (! component_sent[ci])
  148218. ERREXIT(cinfo, JERR_MISSING_DATA);
  148219. }
  148220. }
  148221. }
  148222. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148223. LOCAL(void)
  148224. select_scan_parameters (j_compress_ptr cinfo)
  148225. {
  148226. int ci;
  148227. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148228. if (cinfo->scan_info != NULL) {
  148229. my_master_ptr master = (my_master_ptr) cinfo->master;
  148230. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148231. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148232. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148233. cinfo->cur_comp_info[ci] =
  148234. &cinfo->comp_info[scanptr->component_index[ci]];
  148235. }
  148236. cinfo->Ss = scanptr->Ss;
  148237. cinfo->Se = scanptr->Se;
  148238. cinfo->Ah = scanptr->Ah;
  148239. cinfo->Al = scanptr->Al;
  148240. }
  148241. else
  148242. #endif
  148243. {
  148244. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148245. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148246. MAX_COMPS_IN_SCAN);
  148247. cinfo->comps_in_scan = cinfo->num_components;
  148248. for (ci = 0; ci < cinfo->num_components; ci++) {
  148249. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148250. }
  148251. cinfo->Ss = 0;
  148252. cinfo->Se = DCTSIZE2-1;
  148253. cinfo->Ah = 0;
  148254. cinfo->Al = 0;
  148255. }
  148256. }
  148257. LOCAL(void)
  148258. per_scan_setup (j_compress_ptr cinfo)
  148259. {
  148260. int ci, mcublks, tmp;
  148261. jpeg_component_info *compptr;
  148262. if (cinfo->comps_in_scan == 1) {
  148263. compptr = cinfo->cur_comp_info[0];
  148264. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148265. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148266. compptr->MCU_width = 1;
  148267. compptr->MCU_height = 1;
  148268. compptr->MCU_blocks = 1;
  148269. compptr->MCU_sample_width = DCTSIZE;
  148270. compptr->last_col_width = 1;
  148271. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148272. if (tmp == 0) tmp = compptr->v_samp_factor;
  148273. compptr->last_row_height = tmp;
  148274. cinfo->blocks_in_MCU = 1;
  148275. cinfo->MCU_membership[0] = 0;
  148276. } else {
  148277. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148278. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148279. MAX_COMPS_IN_SCAN);
  148280. cinfo->MCUs_per_row = (JDIMENSION)
  148281. jdiv_round_up((long) cinfo->image_width,
  148282. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148283. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148284. jdiv_round_up((long) cinfo->image_height,
  148285. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148286. cinfo->blocks_in_MCU = 0;
  148287. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148288. compptr = cinfo->cur_comp_info[ci];
  148289. compptr->MCU_width = compptr->h_samp_factor;
  148290. compptr->MCU_height = compptr->v_samp_factor;
  148291. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148292. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148293. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148294. if (tmp == 0) tmp = compptr->MCU_width;
  148295. compptr->last_col_width = tmp;
  148296. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148297. if (tmp == 0) tmp = compptr->MCU_height;
  148298. compptr->last_row_height = tmp;
  148299. mcublks = compptr->MCU_blocks;
  148300. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148301. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148302. while (mcublks-- > 0) {
  148303. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148304. }
  148305. }
  148306. }
  148307. if (cinfo->restart_in_rows > 0) {
  148308. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148309. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148310. }
  148311. }
  148312. METHODDEF(void)
  148313. prepare_for_pass (j_compress_ptr cinfo)
  148314. {
  148315. my_master_ptr master = (my_master_ptr) cinfo->master;
  148316. switch (master->pass_type) {
  148317. case main_pass:
  148318. select_scan_parameters(cinfo);
  148319. per_scan_setup(cinfo);
  148320. if (! cinfo->raw_data_in) {
  148321. (*cinfo->cconvert->start_pass) (cinfo);
  148322. (*cinfo->downsample->start_pass) (cinfo);
  148323. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148324. }
  148325. (*cinfo->fdct->start_pass) (cinfo);
  148326. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148327. (*cinfo->coef->start_pass) (cinfo,
  148328. (master->total_passes > 1 ?
  148329. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148330. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148331. if (cinfo->optimize_coding) {
  148332. master->pub.call_pass_startup = FALSE;
  148333. } else {
  148334. master->pub.call_pass_startup = TRUE;
  148335. }
  148336. break;
  148337. #ifdef ENTROPY_OPT_SUPPORTED
  148338. case huff_opt_pass:
  148339. select_scan_parameters(cinfo);
  148340. per_scan_setup(cinfo);
  148341. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148342. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148343. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148344. master->pub.call_pass_startup = FALSE;
  148345. break;
  148346. }
  148347. master->pass_type = output_pass;
  148348. master->pass_number++;
  148349. #endif
  148350. case output_pass:
  148351. if (! cinfo->optimize_coding) {
  148352. select_scan_parameters(cinfo);
  148353. per_scan_setup(cinfo);
  148354. }
  148355. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148356. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148357. if (master->scan_number == 0)
  148358. (*cinfo->marker->write_frame_header) (cinfo);
  148359. (*cinfo->marker->write_scan_header) (cinfo);
  148360. master->pub.call_pass_startup = FALSE;
  148361. break;
  148362. default:
  148363. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148364. }
  148365. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148366. if (cinfo->progress != NULL) {
  148367. cinfo->progress->completed_passes = master->pass_number;
  148368. cinfo->progress->total_passes = master->total_passes;
  148369. }
  148370. }
  148371. METHODDEF(void)
  148372. pass_startup (j_compress_ptr cinfo)
  148373. {
  148374. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148375. (*cinfo->marker->write_frame_header) (cinfo);
  148376. (*cinfo->marker->write_scan_header) (cinfo);
  148377. }
  148378. METHODDEF(void)
  148379. finish_pass_master (j_compress_ptr cinfo)
  148380. {
  148381. my_master_ptr master = (my_master_ptr) cinfo->master;
  148382. (*cinfo->entropy->finish_pass) (cinfo);
  148383. switch (master->pass_type) {
  148384. case main_pass:
  148385. master->pass_type = output_pass;
  148386. if (! cinfo->optimize_coding)
  148387. master->scan_number++;
  148388. break;
  148389. case huff_opt_pass:
  148390. master->pass_type = output_pass;
  148391. break;
  148392. case output_pass:
  148393. if (cinfo->optimize_coding)
  148394. master->pass_type = huff_opt_pass;
  148395. master->scan_number++;
  148396. break;
  148397. }
  148398. master->pass_number++;
  148399. }
  148400. GLOBAL(void)
  148401. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148402. {
  148403. my_master_ptr master;
  148404. master = (my_master_ptr)
  148405. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148406. SIZEOF(my_comp_master));
  148407. cinfo->master = (struct jpeg_comp_master *) master;
  148408. master->pub.prepare_for_pass = prepare_for_pass;
  148409. master->pub.pass_startup = pass_startup;
  148410. master->pub.finish_pass = finish_pass_master;
  148411. master->pub.is_last_pass = FALSE;
  148412. initial_setup(cinfo);
  148413. if (cinfo->scan_info != NULL) {
  148414. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148415. validate_script(cinfo);
  148416. #else
  148417. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148418. #endif
  148419. } else {
  148420. cinfo->progressive_mode = FALSE;
  148421. cinfo->num_scans = 1;
  148422. }
  148423. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148424. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148425. if (transcode_only) {
  148426. if (cinfo->optimize_coding)
  148427. master->pass_type = huff_opt_pass;
  148428. else
  148429. master->pass_type = output_pass;
  148430. } else {
  148431. master->pass_type = main_pass;
  148432. }
  148433. master->scan_number = 0;
  148434. master->pass_number = 0;
  148435. if (cinfo->optimize_coding)
  148436. master->total_passes = cinfo->num_scans * 2;
  148437. else
  148438. master->total_passes = cinfo->num_scans;
  148439. }
  148440. /*** End of inlined file: jcmaster.c ***/
  148441. /*** Start of inlined file: jcomapi.c ***/
  148442. #define JPEG_INTERNALS
  148443. GLOBAL(void)
  148444. jpeg_abort (j_common_ptr cinfo)
  148445. {
  148446. int pool;
  148447. if (cinfo->mem == NULL)
  148448. return;
  148449. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148450. (*cinfo->mem->free_pool) (cinfo, pool);
  148451. }
  148452. if (cinfo->is_decompressor) {
  148453. cinfo->global_state = DSTATE_START;
  148454. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148455. } else {
  148456. cinfo->global_state = CSTATE_START;
  148457. }
  148458. }
  148459. GLOBAL(void)
  148460. jpeg_destroy (j_common_ptr cinfo)
  148461. {
  148462. if (cinfo->mem != NULL)
  148463. (*cinfo->mem->self_destruct) (cinfo);
  148464. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148465. cinfo->global_state = 0; /* mark it destroyed */
  148466. }
  148467. GLOBAL(JQUANT_TBL *)
  148468. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148469. {
  148470. JQUANT_TBL *tbl;
  148471. tbl = (JQUANT_TBL *)
  148472. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148473. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148474. return tbl;
  148475. }
  148476. GLOBAL(JHUFF_TBL *)
  148477. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148478. {
  148479. JHUFF_TBL *tbl;
  148480. tbl = (JHUFF_TBL *)
  148481. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148482. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148483. return tbl;
  148484. }
  148485. /*** End of inlined file: jcomapi.c ***/
  148486. /*** Start of inlined file: jcparam.c ***/
  148487. #define JPEG_INTERNALS
  148488. GLOBAL(void)
  148489. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148490. const unsigned int *basic_table,
  148491. int scale_factor, boolean force_baseline)
  148492. {
  148493. JQUANT_TBL ** qtblptr;
  148494. int i;
  148495. long temp;
  148496. if (cinfo->global_state != CSTATE_START)
  148497. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148498. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148499. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148500. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148501. if (*qtblptr == NULL)
  148502. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148503. for (i = 0; i < DCTSIZE2; i++) {
  148504. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148505. if (temp <= 0L) temp = 1L;
  148506. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148507. if (force_baseline && temp > 255L)
  148508. temp = 255L; /* limit to baseline range if requested */
  148509. (*qtblptr)->quantval[i] = (UINT16) temp;
  148510. }
  148511. (*qtblptr)->sent_table = FALSE;
  148512. }
  148513. GLOBAL(void)
  148514. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148515. boolean force_baseline)
  148516. {
  148517. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148518. 16, 11, 10, 16, 24, 40, 51, 61,
  148519. 12, 12, 14, 19, 26, 58, 60, 55,
  148520. 14, 13, 16, 24, 40, 57, 69, 56,
  148521. 14, 17, 22, 29, 51, 87, 80, 62,
  148522. 18, 22, 37, 56, 68, 109, 103, 77,
  148523. 24, 35, 55, 64, 81, 104, 113, 92,
  148524. 49, 64, 78, 87, 103, 121, 120, 101,
  148525. 72, 92, 95, 98, 112, 100, 103, 99
  148526. };
  148527. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148528. 17, 18, 24, 47, 99, 99, 99, 99,
  148529. 18, 21, 26, 66, 99, 99, 99, 99,
  148530. 24, 26, 56, 99, 99, 99, 99, 99,
  148531. 47, 66, 99, 99, 99, 99, 99, 99,
  148532. 99, 99, 99, 99, 99, 99, 99, 99,
  148533. 99, 99, 99, 99, 99, 99, 99, 99,
  148534. 99, 99, 99, 99, 99, 99, 99, 99,
  148535. 99, 99, 99, 99, 99, 99, 99, 99
  148536. };
  148537. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148538. scale_factor, force_baseline);
  148539. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  148540. scale_factor, force_baseline);
  148541. }
  148542. GLOBAL(int)
  148543. jpeg_quality_scaling (int quality)
  148544. {
  148545. if (quality <= 0) quality = 1;
  148546. if (quality > 100) quality = 100;
  148547. if (quality < 50)
  148548. quality = 5000 / quality;
  148549. else
  148550. quality = 200 - quality*2;
  148551. return quality;
  148552. }
  148553. GLOBAL(void)
  148554. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  148555. {
  148556. quality = jpeg_quality_scaling(quality);
  148557. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  148558. }
  148559. LOCAL(void)
  148560. add_huff_table (j_compress_ptr cinfo,
  148561. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  148562. {
  148563. int nsymbols, len;
  148564. if (*htblptr == NULL)
  148565. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148566. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  148567. nsymbols = 0;
  148568. for (len = 1; len <= 16; len++)
  148569. nsymbols += bits[len];
  148570. if (nsymbols < 1 || nsymbols > 256)
  148571. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  148572. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  148573. (*htblptr)->sent_table = FALSE;
  148574. }
  148575. LOCAL(void)
  148576. std_huff_tables (j_compress_ptr cinfo)
  148577. {
  148578. static const UINT8 bits_dc_luminance[17] =
  148579. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  148580. static const UINT8 val_dc_luminance[] =
  148581. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148582. static const UINT8 bits_dc_chrominance[17] =
  148583. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  148584. static const UINT8 val_dc_chrominance[] =
  148585. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148586. static const UINT8 bits_ac_luminance[17] =
  148587. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  148588. static const UINT8 val_ac_luminance[] =
  148589. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  148590. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  148591. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  148592. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  148593. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  148594. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  148595. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  148596. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  148597. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  148598. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  148599. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  148600. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  148601. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  148602. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  148603. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  148604. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  148605. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  148606. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  148607. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  148608. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148609. 0xf9, 0xfa };
  148610. static const UINT8 bits_ac_chrominance[17] =
  148611. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  148612. static const UINT8 val_ac_chrominance[] =
  148613. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  148614. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  148615. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  148616. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  148617. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  148618. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  148619. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  148620. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  148621. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  148622. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  148623. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  148624. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  148625. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  148626. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  148627. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  148628. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  148629. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  148630. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  148631. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  148632. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148633. 0xf9, 0xfa };
  148634. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  148635. bits_dc_luminance, val_dc_luminance);
  148636. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  148637. bits_ac_luminance, val_ac_luminance);
  148638. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  148639. bits_dc_chrominance, val_dc_chrominance);
  148640. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  148641. bits_ac_chrominance, val_ac_chrominance);
  148642. }
  148643. GLOBAL(void)
  148644. jpeg_set_defaults (j_compress_ptr cinfo)
  148645. {
  148646. int i;
  148647. if (cinfo->global_state != CSTATE_START)
  148648. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148649. if (cinfo->comp_info == NULL)
  148650. cinfo->comp_info = (jpeg_component_info *)
  148651. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148652. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  148653. cinfo->data_precision = BITS_IN_JSAMPLE;
  148654. jpeg_set_quality(cinfo, 75, TRUE);
  148655. std_huff_tables(cinfo);
  148656. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148657. cinfo->arith_dc_L[i] = 0;
  148658. cinfo->arith_dc_U[i] = 1;
  148659. cinfo->arith_ac_K[i] = 5;
  148660. }
  148661. cinfo->scan_info = NULL;
  148662. cinfo->num_scans = 0;
  148663. cinfo->raw_data_in = FALSE;
  148664. cinfo->arith_code = FALSE;
  148665. cinfo->optimize_coding = FALSE;
  148666. if (cinfo->data_precision > 8)
  148667. cinfo->optimize_coding = TRUE;
  148668. cinfo->CCIR601_sampling = FALSE;
  148669. cinfo->smoothing_factor = 0;
  148670. cinfo->dct_method = JDCT_DEFAULT;
  148671. cinfo->restart_interval = 0;
  148672. cinfo->restart_in_rows = 0;
  148673. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  148674. cinfo->JFIF_minor_version = 1;
  148675. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  148676. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  148677. cinfo->Y_density = 1;
  148678. jpeg_default_colorspace(cinfo);
  148679. }
  148680. GLOBAL(void)
  148681. jpeg_default_colorspace (j_compress_ptr cinfo)
  148682. {
  148683. switch (cinfo->in_color_space) {
  148684. case JCS_GRAYSCALE:
  148685. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  148686. break;
  148687. case JCS_RGB:
  148688. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148689. break;
  148690. case JCS_YCbCr:
  148691. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148692. break;
  148693. case JCS_CMYK:
  148694. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  148695. break;
  148696. case JCS_YCCK:
  148697. jpeg_set_colorspace(cinfo, JCS_YCCK);
  148698. break;
  148699. case JCS_UNKNOWN:
  148700. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  148701. break;
  148702. default:
  148703. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  148704. }
  148705. }
  148706. GLOBAL(void)
  148707. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  148708. {
  148709. jpeg_component_info * compptr;
  148710. int ci;
  148711. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  148712. (compptr = &cinfo->comp_info[index], \
  148713. compptr->component_id = (id), \
  148714. compptr->h_samp_factor = (hsamp), \
  148715. compptr->v_samp_factor = (vsamp), \
  148716. compptr->quant_tbl_no = (quant), \
  148717. compptr->dc_tbl_no = (dctbl), \
  148718. compptr->ac_tbl_no = (actbl) )
  148719. if (cinfo->global_state != CSTATE_START)
  148720. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148721. cinfo->jpeg_color_space = colorspace;
  148722. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  148723. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  148724. switch (colorspace) {
  148725. case JCS_GRAYSCALE:
  148726. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148727. cinfo->num_components = 1;
  148728. SET_COMP(0, 1, 1,1, 0, 0,0);
  148729. break;
  148730. case JCS_RGB:
  148731. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  148732. cinfo->num_components = 3;
  148733. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  148734. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  148735. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  148736. break;
  148737. case JCS_YCbCr:
  148738. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148739. cinfo->num_components = 3;
  148740. SET_COMP(0, 1, 2,2, 0, 0,0);
  148741. SET_COMP(1, 2, 1,1, 1, 1,1);
  148742. SET_COMP(2, 3, 1,1, 1, 1,1);
  148743. break;
  148744. case JCS_CMYK:
  148745. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  148746. cinfo->num_components = 4;
  148747. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  148748. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  148749. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  148750. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  148751. break;
  148752. case JCS_YCCK:
  148753. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  148754. cinfo->num_components = 4;
  148755. SET_COMP(0, 1, 2,2, 0, 0,0);
  148756. SET_COMP(1, 2, 1,1, 1, 1,1);
  148757. SET_COMP(2, 3, 1,1, 1, 1,1);
  148758. SET_COMP(3, 4, 2,2, 0, 0,0);
  148759. break;
  148760. case JCS_UNKNOWN:
  148761. cinfo->num_components = cinfo->input_components;
  148762. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  148763. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148764. MAX_COMPONENTS);
  148765. for (ci = 0; ci < cinfo->num_components; ci++) {
  148766. SET_COMP(ci, ci, 1,1, 0, 0,0);
  148767. }
  148768. break;
  148769. default:
  148770. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  148771. }
  148772. }
  148773. #ifdef C_PROGRESSIVE_SUPPORTED
  148774. LOCAL(jpeg_scan_info *)
  148775. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  148776. int Ss, int Se, int Ah, int Al)
  148777. {
  148778. scanptr->comps_in_scan = 1;
  148779. scanptr->component_index[0] = ci;
  148780. scanptr->Ss = Ss;
  148781. scanptr->Se = Se;
  148782. scanptr->Ah = Ah;
  148783. scanptr->Al = Al;
  148784. scanptr++;
  148785. return scanptr;
  148786. }
  148787. LOCAL(jpeg_scan_info *)
  148788. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  148789. int Ss, int Se, int Ah, int Al)
  148790. {
  148791. int ci;
  148792. for (ci = 0; ci < ncomps; ci++) {
  148793. scanptr->comps_in_scan = 1;
  148794. scanptr->component_index[0] = ci;
  148795. scanptr->Ss = Ss;
  148796. scanptr->Se = Se;
  148797. scanptr->Ah = Ah;
  148798. scanptr->Al = Al;
  148799. scanptr++;
  148800. }
  148801. return scanptr;
  148802. }
  148803. LOCAL(jpeg_scan_info *)
  148804. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  148805. {
  148806. int ci;
  148807. if (ncomps <= MAX_COMPS_IN_SCAN) {
  148808. scanptr->comps_in_scan = ncomps;
  148809. for (ci = 0; ci < ncomps; ci++)
  148810. scanptr->component_index[ci] = ci;
  148811. scanptr->Ss = scanptr->Se = 0;
  148812. scanptr->Ah = Ah;
  148813. scanptr->Al = Al;
  148814. scanptr++;
  148815. } else {
  148816. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  148817. }
  148818. return scanptr;
  148819. }
  148820. GLOBAL(void)
  148821. jpeg_simple_progression (j_compress_ptr cinfo)
  148822. {
  148823. int ncomps = cinfo->num_components;
  148824. int nscans;
  148825. jpeg_scan_info * scanptr;
  148826. if (cinfo->global_state != CSTATE_START)
  148827. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148828. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148829. nscans = 10;
  148830. } else {
  148831. if (ncomps > MAX_COMPS_IN_SCAN)
  148832. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  148833. else
  148834. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  148835. }
  148836. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  148837. cinfo->script_space_size = MAX(nscans, 10);
  148838. cinfo->script_space = (jpeg_scan_info *)
  148839. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148840. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  148841. }
  148842. scanptr = cinfo->script_space;
  148843. cinfo->scan_info = scanptr;
  148844. cinfo->num_scans = nscans;
  148845. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148846. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148847. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  148848. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  148849. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  148850. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  148851. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  148852. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148853. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  148854. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  148855. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  148856. } else {
  148857. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148858. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  148859. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  148860. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  148861. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148862. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  148863. }
  148864. }
  148865. #endif /* C_PROGRESSIVE_SUPPORTED */
  148866. /*** End of inlined file: jcparam.c ***/
  148867. /*** Start of inlined file: jcphuff.c ***/
  148868. #define JPEG_INTERNALS
  148869. #ifdef C_PROGRESSIVE_SUPPORTED
  148870. typedef struct {
  148871. struct jpeg_entropy_encoder pub; /* public fields */
  148872. boolean gather_statistics;
  148873. JOCTET * next_output_byte; /* => next byte to write in buffer */
  148874. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  148875. INT32 put_buffer; /* current bit-accumulation buffer */
  148876. int put_bits; /* # of bits now in it */
  148877. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  148878. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  148879. int ac_tbl_no; /* the table number of the single component */
  148880. unsigned int EOBRUN; /* run length of EOBs */
  148881. unsigned int BE; /* # of buffered correction bits before MCU */
  148882. char * bit_buffer; /* buffer for correction bits (1 per char) */
  148883. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  148884. int next_restart_num; /* next restart number to write (0-7) */
  148885. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  148886. long * count_ptrs[NUM_HUFF_TBLS];
  148887. } phuff_entropy_encoder;
  148888. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  148889. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  148890. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  148891. #define ISHIFT_TEMPS int ishift_temp;
  148892. #define IRIGHT_SHIFT(x,shft) \
  148893. ((ishift_temp = (x)) < 0 ? \
  148894. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  148895. (ishift_temp >> (shft)))
  148896. #else
  148897. #define ISHIFT_TEMPS
  148898. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  148899. #endif
  148900. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  148901. JBLOCKROW *MCU_data));
  148902. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  148903. JBLOCKROW *MCU_data));
  148904. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  148905. JBLOCKROW *MCU_data));
  148906. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  148907. JBLOCKROW *MCU_data));
  148908. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  148909. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  148910. METHODDEF(void)
  148911. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  148912. {
  148913. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148914. boolean is_DC_band;
  148915. int ci, tbl;
  148916. jpeg_component_info * compptr;
  148917. entropy->cinfo = cinfo;
  148918. entropy->gather_statistics = gather_statistics;
  148919. is_DC_band = (cinfo->Ss == 0);
  148920. if (cinfo->Ah == 0) {
  148921. if (is_DC_band)
  148922. entropy->pub.encode_mcu = encode_mcu_DC_first;
  148923. else
  148924. entropy->pub.encode_mcu = encode_mcu_AC_first;
  148925. } else {
  148926. if (is_DC_band)
  148927. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  148928. else {
  148929. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  148930. if (entropy->bit_buffer == NULL)
  148931. entropy->bit_buffer = (char *)
  148932. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148933. MAX_CORR_BITS * SIZEOF(char));
  148934. }
  148935. }
  148936. if (gather_statistics)
  148937. entropy->pub.finish_pass = finish_pass_gather_phuff;
  148938. else
  148939. entropy->pub.finish_pass = finish_pass_phuff;
  148940. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148941. compptr = cinfo->cur_comp_info[ci];
  148942. entropy->last_dc_val[ci] = 0;
  148943. if (is_DC_band) {
  148944. if (cinfo->Ah != 0) /* DC refinement needs no table */
  148945. continue;
  148946. tbl = compptr->dc_tbl_no;
  148947. } else {
  148948. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  148949. }
  148950. if (gather_statistics) {
  148951. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  148952. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  148953. if (entropy->count_ptrs[tbl] == NULL)
  148954. entropy->count_ptrs[tbl] = (long *)
  148955. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148956. 257 * SIZEOF(long));
  148957. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  148958. } else {
  148959. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  148960. & entropy->derived_tbls[tbl]);
  148961. }
  148962. }
  148963. entropy->EOBRUN = 0;
  148964. entropy->BE = 0;
  148965. entropy->put_buffer = 0;
  148966. entropy->put_bits = 0;
  148967. entropy->restarts_to_go = cinfo->restart_interval;
  148968. entropy->next_restart_num = 0;
  148969. }
  148970. #define emit_byte(entropy,val) \
  148971. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  148972. if (--(entropy)->free_in_buffer == 0) \
  148973. dump_buffer_p(entropy); }
  148974. LOCAL(void)
  148975. dump_buffer_p (phuff_entropy_ptr entropy)
  148976. {
  148977. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  148978. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  148979. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  148980. entropy->next_output_byte = dest->next_output_byte;
  148981. entropy->free_in_buffer = dest->free_in_buffer;
  148982. }
  148983. INLINE
  148984. LOCAL(void)
  148985. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  148986. {
  148987. register INT32 put_buffer = (INT32) code;
  148988. register int put_bits = entropy->put_bits;
  148989. if (size == 0)
  148990. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  148991. if (entropy->gather_statistics)
  148992. return; /* do nothing if we're only getting stats */
  148993. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  148994. put_bits += size; /* new number of bits in buffer */
  148995. put_buffer <<= 24 - put_bits; /* align incoming bits */
  148996. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  148997. while (put_bits >= 8) {
  148998. int c = (int) ((put_buffer >> 16) & 0xFF);
  148999. emit_byte(entropy, c);
  149000. if (c == 0xFF) { /* need to stuff a zero byte? */
  149001. emit_byte(entropy, 0);
  149002. }
  149003. put_buffer <<= 8;
  149004. put_bits -= 8;
  149005. }
  149006. entropy->put_buffer = put_buffer; /* update variables */
  149007. entropy->put_bits = put_bits;
  149008. }
  149009. LOCAL(void)
  149010. flush_bits_p (phuff_entropy_ptr entropy)
  149011. {
  149012. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149013. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149014. entropy->put_bits = 0;
  149015. }
  149016. INLINE
  149017. LOCAL(void)
  149018. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149019. {
  149020. if (entropy->gather_statistics)
  149021. entropy->count_ptrs[tbl_no][symbol]++;
  149022. else {
  149023. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149024. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149025. }
  149026. }
  149027. LOCAL(void)
  149028. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149029. unsigned int nbits)
  149030. {
  149031. if (entropy->gather_statistics)
  149032. return; /* no real work */
  149033. while (nbits > 0) {
  149034. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149035. bufstart++;
  149036. nbits--;
  149037. }
  149038. }
  149039. LOCAL(void)
  149040. emit_eobrun (phuff_entropy_ptr entropy)
  149041. {
  149042. register int temp, nbits;
  149043. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149044. temp = entropy->EOBRUN;
  149045. nbits = 0;
  149046. while ((temp >>= 1))
  149047. nbits++;
  149048. if (nbits > 14)
  149049. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149050. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149051. if (nbits)
  149052. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149053. entropy->EOBRUN = 0;
  149054. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149055. entropy->BE = 0;
  149056. }
  149057. }
  149058. LOCAL(void)
  149059. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149060. {
  149061. int ci;
  149062. emit_eobrun(entropy);
  149063. if (! entropy->gather_statistics) {
  149064. flush_bits_p(entropy);
  149065. emit_byte(entropy, 0xFF);
  149066. emit_byte(entropy, JPEG_RST0 + restart_num);
  149067. }
  149068. if (entropy->cinfo->Ss == 0) {
  149069. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149070. entropy->last_dc_val[ci] = 0;
  149071. } else {
  149072. entropy->EOBRUN = 0;
  149073. entropy->BE = 0;
  149074. }
  149075. }
  149076. METHODDEF(boolean)
  149077. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149078. {
  149079. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149080. register int temp, temp2;
  149081. register int nbits;
  149082. int blkn, ci;
  149083. int Al = cinfo->Al;
  149084. JBLOCKROW block;
  149085. jpeg_component_info * compptr;
  149086. ISHIFT_TEMPS
  149087. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149088. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149089. if (cinfo->restart_interval)
  149090. if (entropy->restarts_to_go == 0)
  149091. emit_restart_p(entropy, entropy->next_restart_num);
  149092. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149093. block = MCU_data[blkn];
  149094. ci = cinfo->MCU_membership[blkn];
  149095. compptr = cinfo->cur_comp_info[ci];
  149096. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149097. temp = temp2 - entropy->last_dc_val[ci];
  149098. entropy->last_dc_val[ci] = temp2;
  149099. temp2 = temp;
  149100. if (temp < 0) {
  149101. temp = -temp; /* temp is abs value of input */
  149102. temp2--;
  149103. }
  149104. nbits = 0;
  149105. while (temp) {
  149106. nbits++;
  149107. temp >>= 1;
  149108. }
  149109. if (nbits > MAX_COEF_BITS+1)
  149110. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149111. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149112. if (nbits) /* emit_bits rejects calls with size 0 */
  149113. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149114. }
  149115. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149116. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149117. if (cinfo->restart_interval) {
  149118. if (entropy->restarts_to_go == 0) {
  149119. entropy->restarts_to_go = cinfo->restart_interval;
  149120. entropy->next_restart_num++;
  149121. entropy->next_restart_num &= 7;
  149122. }
  149123. entropy->restarts_to_go--;
  149124. }
  149125. return TRUE;
  149126. }
  149127. METHODDEF(boolean)
  149128. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149129. {
  149130. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149131. register int temp, temp2;
  149132. register int nbits;
  149133. register int r, k;
  149134. int Se = cinfo->Se;
  149135. int Al = cinfo->Al;
  149136. JBLOCKROW block;
  149137. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149138. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149139. if (cinfo->restart_interval)
  149140. if (entropy->restarts_to_go == 0)
  149141. emit_restart_p(entropy, entropy->next_restart_num);
  149142. block = MCU_data[0];
  149143. r = 0; /* r = run length of zeros */
  149144. for (k = cinfo->Ss; k <= Se; k++) {
  149145. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149146. r++;
  149147. continue;
  149148. }
  149149. if (temp < 0) {
  149150. temp = -temp; /* temp is abs value of input */
  149151. temp >>= Al; /* apply the point transform */
  149152. temp2 = ~temp;
  149153. } else {
  149154. temp >>= Al; /* apply the point transform */
  149155. temp2 = temp;
  149156. }
  149157. if (temp == 0) {
  149158. r++;
  149159. continue;
  149160. }
  149161. if (entropy->EOBRUN > 0)
  149162. emit_eobrun(entropy);
  149163. while (r > 15) {
  149164. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149165. r -= 16;
  149166. }
  149167. nbits = 1; /* there must be at least one 1 bit */
  149168. while ((temp >>= 1))
  149169. nbits++;
  149170. if (nbits > MAX_COEF_BITS)
  149171. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149172. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149173. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149174. r = 0; /* reset zero run length */
  149175. }
  149176. if (r > 0) { /* If there are trailing zeroes, */
  149177. entropy->EOBRUN++; /* count an EOB */
  149178. if (entropy->EOBRUN == 0x7FFF)
  149179. emit_eobrun(entropy); /* force it out to avoid overflow */
  149180. }
  149181. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149182. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149183. if (cinfo->restart_interval) {
  149184. if (entropy->restarts_to_go == 0) {
  149185. entropy->restarts_to_go = cinfo->restart_interval;
  149186. entropy->next_restart_num++;
  149187. entropy->next_restart_num &= 7;
  149188. }
  149189. entropy->restarts_to_go--;
  149190. }
  149191. return TRUE;
  149192. }
  149193. METHODDEF(boolean)
  149194. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149195. {
  149196. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149197. register int temp;
  149198. int blkn;
  149199. int Al = cinfo->Al;
  149200. JBLOCKROW block;
  149201. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149202. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149203. if (cinfo->restart_interval)
  149204. if (entropy->restarts_to_go == 0)
  149205. emit_restart_p(entropy, entropy->next_restart_num);
  149206. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149207. block = MCU_data[blkn];
  149208. temp = (*block)[0];
  149209. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149210. }
  149211. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149212. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149213. if (cinfo->restart_interval) {
  149214. if (entropy->restarts_to_go == 0) {
  149215. entropy->restarts_to_go = cinfo->restart_interval;
  149216. entropy->next_restart_num++;
  149217. entropy->next_restart_num &= 7;
  149218. }
  149219. entropy->restarts_to_go--;
  149220. }
  149221. return TRUE;
  149222. }
  149223. METHODDEF(boolean)
  149224. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149225. {
  149226. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149227. register int temp;
  149228. register int r, k;
  149229. int EOB;
  149230. char *BR_buffer;
  149231. unsigned int BR;
  149232. int Se = cinfo->Se;
  149233. int Al = cinfo->Al;
  149234. JBLOCKROW block;
  149235. int absvalues[DCTSIZE2];
  149236. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149237. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149238. if (cinfo->restart_interval)
  149239. if (entropy->restarts_to_go == 0)
  149240. emit_restart_p(entropy, entropy->next_restart_num);
  149241. block = MCU_data[0];
  149242. EOB = 0;
  149243. for (k = cinfo->Ss; k <= Se; k++) {
  149244. temp = (*block)[jpeg_natural_order[k]];
  149245. if (temp < 0)
  149246. temp = -temp; /* temp is abs value of input */
  149247. temp >>= Al; /* apply the point transform */
  149248. absvalues[k] = temp; /* save abs value for main pass */
  149249. if (temp == 1)
  149250. EOB = k; /* EOB = index of last newly-nonzero coef */
  149251. }
  149252. r = 0; /* r = run length of zeros */
  149253. BR = 0; /* BR = count of buffered bits added now */
  149254. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149255. for (k = cinfo->Ss; k <= Se; k++) {
  149256. if ((temp = absvalues[k]) == 0) {
  149257. r++;
  149258. continue;
  149259. }
  149260. while (r > 15 && k <= EOB) {
  149261. emit_eobrun(entropy);
  149262. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149263. r -= 16;
  149264. emit_buffered_bits(entropy, BR_buffer, BR);
  149265. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149266. BR = 0;
  149267. }
  149268. if (temp > 1) {
  149269. BR_buffer[BR++] = (char) (temp & 1);
  149270. continue;
  149271. }
  149272. emit_eobrun(entropy);
  149273. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149274. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149275. emit_bits_p(entropy, (unsigned int) temp, 1);
  149276. emit_buffered_bits(entropy, BR_buffer, BR);
  149277. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149278. BR = 0;
  149279. r = 0; /* reset zero run length */
  149280. }
  149281. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149282. entropy->EOBRUN++; /* count an EOB */
  149283. entropy->BE += BR; /* concat my correction bits to older ones */
  149284. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149285. emit_eobrun(entropy);
  149286. }
  149287. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149288. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149289. if (cinfo->restart_interval) {
  149290. if (entropy->restarts_to_go == 0) {
  149291. entropy->restarts_to_go = cinfo->restart_interval;
  149292. entropy->next_restart_num++;
  149293. entropy->next_restart_num &= 7;
  149294. }
  149295. entropy->restarts_to_go--;
  149296. }
  149297. return TRUE;
  149298. }
  149299. METHODDEF(void)
  149300. finish_pass_phuff (j_compress_ptr cinfo)
  149301. {
  149302. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149303. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149304. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149305. emit_eobrun(entropy);
  149306. flush_bits_p(entropy);
  149307. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149308. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149309. }
  149310. METHODDEF(void)
  149311. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149312. {
  149313. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149314. boolean is_DC_band;
  149315. int ci, tbl;
  149316. jpeg_component_info * compptr;
  149317. JHUFF_TBL **htblptr;
  149318. boolean did[NUM_HUFF_TBLS];
  149319. emit_eobrun(entropy);
  149320. is_DC_band = (cinfo->Ss == 0);
  149321. MEMZERO(did, SIZEOF(did));
  149322. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149323. compptr = cinfo->cur_comp_info[ci];
  149324. if (is_DC_band) {
  149325. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149326. continue;
  149327. tbl = compptr->dc_tbl_no;
  149328. } else {
  149329. tbl = compptr->ac_tbl_no;
  149330. }
  149331. if (! did[tbl]) {
  149332. if (is_DC_band)
  149333. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149334. else
  149335. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149336. if (*htblptr == NULL)
  149337. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149338. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149339. did[tbl] = TRUE;
  149340. }
  149341. }
  149342. }
  149343. GLOBAL(void)
  149344. jinit_phuff_encoder (j_compress_ptr cinfo)
  149345. {
  149346. phuff_entropy_ptr entropy;
  149347. int i;
  149348. entropy = (phuff_entropy_ptr)
  149349. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149350. SIZEOF(phuff_entropy_encoder));
  149351. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149352. entropy->pub.start_pass = start_pass_phuff;
  149353. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149354. entropy->derived_tbls[i] = NULL;
  149355. entropy->count_ptrs[i] = NULL;
  149356. }
  149357. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149358. }
  149359. #endif /* C_PROGRESSIVE_SUPPORTED */
  149360. /*** End of inlined file: jcphuff.c ***/
  149361. /*** Start of inlined file: jcprepct.c ***/
  149362. #define JPEG_INTERNALS
  149363. #ifdef INPUT_SMOOTHING_SUPPORTED
  149364. #define CONTEXT_ROWS_SUPPORTED
  149365. #endif
  149366. typedef struct {
  149367. struct jpeg_c_prep_controller pub; /* public fields */
  149368. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149369. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149370. int next_buf_row; /* index of next row to store in color_buf */
  149371. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149372. int this_row_group; /* starting row index of group to process */
  149373. int next_buf_stop; /* downsample when we reach this index */
  149374. #endif
  149375. } my_prep_controller;
  149376. typedef my_prep_controller * my_prep_ptr;
  149377. METHODDEF(void)
  149378. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149379. {
  149380. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149381. if (pass_mode != JBUF_PASS_THRU)
  149382. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149383. prep->rows_to_go = cinfo->image_height;
  149384. prep->next_buf_row = 0;
  149385. #ifdef CONTEXT_ROWS_SUPPORTED
  149386. prep->this_row_group = 0;
  149387. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149388. #endif
  149389. }
  149390. LOCAL(void)
  149391. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149392. int input_rows, int output_rows)
  149393. {
  149394. register int row;
  149395. for (row = input_rows; row < output_rows; row++) {
  149396. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149397. 1, num_cols);
  149398. }
  149399. }
  149400. METHODDEF(void)
  149401. pre_process_data (j_compress_ptr cinfo,
  149402. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149403. JDIMENSION in_rows_avail,
  149404. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149405. JDIMENSION out_row_groups_avail)
  149406. {
  149407. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149408. int numrows, ci;
  149409. JDIMENSION inrows;
  149410. jpeg_component_info * compptr;
  149411. while (*in_row_ctr < in_rows_avail &&
  149412. *out_row_group_ctr < out_row_groups_avail) {
  149413. inrows = in_rows_avail - *in_row_ctr;
  149414. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149415. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149416. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149417. prep->color_buf,
  149418. (JDIMENSION) prep->next_buf_row,
  149419. numrows);
  149420. *in_row_ctr += numrows;
  149421. prep->next_buf_row += numrows;
  149422. prep->rows_to_go -= numrows;
  149423. if (prep->rows_to_go == 0 &&
  149424. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149425. for (ci = 0; ci < cinfo->num_components; ci++) {
  149426. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149427. prep->next_buf_row, cinfo->max_v_samp_factor);
  149428. }
  149429. prep->next_buf_row = cinfo->max_v_samp_factor;
  149430. }
  149431. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149432. (*cinfo->downsample->downsample) (cinfo,
  149433. prep->color_buf, (JDIMENSION) 0,
  149434. output_buf, *out_row_group_ctr);
  149435. prep->next_buf_row = 0;
  149436. (*out_row_group_ctr)++;
  149437. }
  149438. if (prep->rows_to_go == 0 &&
  149439. *out_row_group_ctr < out_row_groups_avail) {
  149440. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149441. ci++, compptr++) {
  149442. expand_bottom_edge(output_buf[ci],
  149443. compptr->width_in_blocks * DCTSIZE,
  149444. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149445. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149446. }
  149447. *out_row_group_ctr = out_row_groups_avail;
  149448. break; /* can exit outer loop without test */
  149449. }
  149450. }
  149451. }
  149452. #ifdef CONTEXT_ROWS_SUPPORTED
  149453. METHODDEF(void)
  149454. pre_process_context (j_compress_ptr cinfo,
  149455. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149456. JDIMENSION in_rows_avail,
  149457. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149458. JDIMENSION out_row_groups_avail)
  149459. {
  149460. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149461. int numrows, ci;
  149462. int buf_height = cinfo->max_v_samp_factor * 3;
  149463. JDIMENSION inrows;
  149464. while (*out_row_group_ctr < out_row_groups_avail) {
  149465. if (*in_row_ctr < in_rows_avail) {
  149466. inrows = in_rows_avail - *in_row_ctr;
  149467. numrows = prep->next_buf_stop - prep->next_buf_row;
  149468. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149469. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149470. prep->color_buf,
  149471. (JDIMENSION) prep->next_buf_row,
  149472. numrows);
  149473. if (prep->rows_to_go == cinfo->image_height) {
  149474. for (ci = 0; ci < cinfo->num_components; ci++) {
  149475. int row;
  149476. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149477. jcopy_sample_rows(prep->color_buf[ci], 0,
  149478. prep->color_buf[ci], -row,
  149479. 1, cinfo->image_width);
  149480. }
  149481. }
  149482. }
  149483. *in_row_ctr += numrows;
  149484. prep->next_buf_row += numrows;
  149485. prep->rows_to_go -= numrows;
  149486. } else {
  149487. if (prep->rows_to_go != 0)
  149488. break;
  149489. if (prep->next_buf_row < prep->next_buf_stop) {
  149490. for (ci = 0; ci < cinfo->num_components; ci++) {
  149491. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149492. prep->next_buf_row, prep->next_buf_stop);
  149493. }
  149494. prep->next_buf_row = prep->next_buf_stop;
  149495. }
  149496. }
  149497. if (prep->next_buf_row == prep->next_buf_stop) {
  149498. (*cinfo->downsample->downsample) (cinfo,
  149499. prep->color_buf,
  149500. (JDIMENSION) prep->this_row_group,
  149501. output_buf, *out_row_group_ctr);
  149502. (*out_row_group_ctr)++;
  149503. prep->this_row_group += cinfo->max_v_samp_factor;
  149504. if (prep->this_row_group >= buf_height)
  149505. prep->this_row_group = 0;
  149506. if (prep->next_buf_row >= buf_height)
  149507. prep->next_buf_row = 0;
  149508. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149509. }
  149510. }
  149511. }
  149512. LOCAL(void)
  149513. create_context_buffer (j_compress_ptr cinfo)
  149514. {
  149515. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149516. int rgroup_height = cinfo->max_v_samp_factor;
  149517. int ci, i;
  149518. jpeg_component_info * compptr;
  149519. JSAMPARRAY true_buffer, fake_buffer;
  149520. fake_buffer = (JSAMPARRAY)
  149521. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149522. (cinfo->num_components * 5 * rgroup_height) *
  149523. SIZEOF(JSAMPROW));
  149524. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149525. ci++, compptr++) {
  149526. true_buffer = (*cinfo->mem->alloc_sarray)
  149527. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149528. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149529. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149530. (JDIMENSION) (3 * rgroup_height));
  149531. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149532. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149533. for (i = 0; i < rgroup_height; i++) {
  149534. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149535. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149536. }
  149537. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149538. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  149539. }
  149540. }
  149541. #endif /* CONTEXT_ROWS_SUPPORTED */
  149542. GLOBAL(void)
  149543. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  149544. {
  149545. my_prep_ptr prep;
  149546. int ci;
  149547. jpeg_component_info * compptr;
  149548. if (need_full_buffer) /* safety check */
  149549. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149550. prep = (my_prep_ptr)
  149551. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149552. SIZEOF(my_prep_controller));
  149553. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  149554. prep->pub.start_pass = start_pass_prep;
  149555. if (cinfo->downsample->need_context_rows) {
  149556. #ifdef CONTEXT_ROWS_SUPPORTED
  149557. prep->pub.pre_process_data = pre_process_context;
  149558. create_context_buffer(cinfo);
  149559. #else
  149560. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149561. #endif
  149562. } else {
  149563. prep->pub.pre_process_data = pre_process_data;
  149564. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149565. ci++, compptr++) {
  149566. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  149567. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149568. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149569. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149570. (JDIMENSION) cinfo->max_v_samp_factor);
  149571. }
  149572. }
  149573. }
  149574. /*** End of inlined file: jcprepct.c ***/
  149575. /*** Start of inlined file: jcsample.c ***/
  149576. #define JPEG_INTERNALS
  149577. typedef JMETHOD(void, downsample1_ptr,
  149578. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149579. JSAMPARRAY input_data, JSAMPARRAY output_data));
  149580. typedef struct {
  149581. struct jpeg_downsampler pub; /* public fields */
  149582. downsample1_ptr methods[MAX_COMPONENTS];
  149583. } my_downsampler;
  149584. typedef my_downsampler * my_downsample_ptr;
  149585. METHODDEF(void)
  149586. start_pass_downsample (j_compress_ptr cinfo)
  149587. {
  149588. }
  149589. LOCAL(void)
  149590. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  149591. JDIMENSION input_cols, JDIMENSION output_cols)
  149592. {
  149593. register JSAMPROW ptr;
  149594. register JSAMPLE pixval;
  149595. register int count;
  149596. int row;
  149597. int numcols = (int) (output_cols - input_cols);
  149598. if (numcols > 0) {
  149599. for (row = 0; row < num_rows; row++) {
  149600. ptr = image_data[row] + input_cols;
  149601. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  149602. for (count = numcols; count > 0; count--)
  149603. *ptr++ = pixval;
  149604. }
  149605. }
  149606. }
  149607. METHODDEF(void)
  149608. sep_downsample (j_compress_ptr cinfo,
  149609. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  149610. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  149611. {
  149612. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  149613. int ci;
  149614. jpeg_component_info * compptr;
  149615. JSAMPARRAY in_ptr, out_ptr;
  149616. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149617. ci++, compptr++) {
  149618. in_ptr = input_buf[ci] + in_row_index;
  149619. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  149620. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  149621. }
  149622. }
  149623. METHODDEF(void)
  149624. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149625. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149626. {
  149627. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  149628. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  149629. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149630. JSAMPROW inptr, outptr;
  149631. INT32 outvalue;
  149632. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  149633. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  149634. numpix = h_expand * v_expand;
  149635. numpix2 = numpix/2;
  149636. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149637. cinfo->image_width, output_cols * h_expand);
  149638. inrow = 0;
  149639. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149640. outptr = output_data[outrow];
  149641. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  149642. outcol++, outcol_h += h_expand) {
  149643. outvalue = 0;
  149644. for (v = 0; v < v_expand; v++) {
  149645. inptr = input_data[inrow+v] + outcol_h;
  149646. for (h = 0; h < h_expand; h++) {
  149647. outvalue += (INT32) GETJSAMPLE(*inptr++);
  149648. }
  149649. }
  149650. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  149651. }
  149652. inrow += v_expand;
  149653. }
  149654. }
  149655. METHODDEF(void)
  149656. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149657. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149658. {
  149659. jcopy_sample_rows(input_data, 0, output_data, 0,
  149660. cinfo->max_v_samp_factor, cinfo->image_width);
  149661. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  149662. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  149663. }
  149664. METHODDEF(void)
  149665. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149666. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149667. {
  149668. int outrow;
  149669. JDIMENSION outcol;
  149670. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149671. register JSAMPROW inptr, outptr;
  149672. register int bias;
  149673. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149674. cinfo->image_width, output_cols * 2);
  149675. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149676. outptr = output_data[outrow];
  149677. inptr = input_data[outrow];
  149678. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  149679. for (outcol = 0; outcol < output_cols; outcol++) {
  149680. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  149681. + bias) >> 1);
  149682. bias ^= 1; /* 0=>1, 1=>0 */
  149683. inptr += 2;
  149684. }
  149685. }
  149686. }
  149687. METHODDEF(void)
  149688. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149689. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149690. {
  149691. int inrow, outrow;
  149692. JDIMENSION outcol;
  149693. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149694. register JSAMPROW inptr0, inptr1, outptr;
  149695. register int bias;
  149696. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149697. cinfo->image_width, output_cols * 2);
  149698. inrow = 0;
  149699. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149700. outptr = output_data[outrow];
  149701. inptr0 = input_data[inrow];
  149702. inptr1 = input_data[inrow+1];
  149703. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  149704. for (outcol = 0; outcol < output_cols; outcol++) {
  149705. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149706. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  149707. + bias) >> 2);
  149708. bias ^= 3; /* 1=>2, 2=>1 */
  149709. inptr0 += 2; inptr1 += 2;
  149710. }
  149711. inrow += 2;
  149712. }
  149713. }
  149714. #ifdef INPUT_SMOOTHING_SUPPORTED
  149715. METHODDEF(void)
  149716. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149717. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149718. {
  149719. int inrow, outrow;
  149720. JDIMENSION colctr;
  149721. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149722. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  149723. INT32 membersum, neighsum, memberscale, neighscale;
  149724. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149725. cinfo->image_width, output_cols * 2);
  149726. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  149727. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  149728. inrow = 0;
  149729. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149730. outptr = output_data[outrow];
  149731. inptr0 = input_data[inrow];
  149732. inptr1 = input_data[inrow+1];
  149733. above_ptr = input_data[inrow-1];
  149734. below_ptr = input_data[inrow+2];
  149735. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149736. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149737. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149738. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149739. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  149740. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  149741. neighsum += neighsum;
  149742. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  149743. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  149744. membersum = membersum * memberscale + neighsum * neighscale;
  149745. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149746. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149747. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149748. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149749. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149750. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149751. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149752. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  149753. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  149754. neighsum += neighsum;
  149755. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  149756. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  149757. membersum = membersum * memberscale + neighsum * neighscale;
  149758. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149759. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149760. }
  149761. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149762. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149763. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149764. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149765. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  149766. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  149767. neighsum += neighsum;
  149768. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  149769. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  149770. membersum = membersum * memberscale + neighsum * neighscale;
  149771. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149772. inrow += 2;
  149773. }
  149774. }
  149775. METHODDEF(void)
  149776. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  149777. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149778. {
  149779. int outrow;
  149780. JDIMENSION colctr;
  149781. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149782. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  149783. INT32 membersum, neighsum, memberscale, neighscale;
  149784. int colsum, lastcolsum, nextcolsum;
  149785. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149786. cinfo->image_width, output_cols);
  149787. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  149788. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  149789. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149790. outptr = output_data[outrow];
  149791. inptr = input_data[outrow];
  149792. above_ptr = input_data[outrow-1];
  149793. below_ptr = input_data[outrow+1];
  149794. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  149795. GETJSAMPLE(*inptr);
  149796. membersum = GETJSAMPLE(*inptr++);
  149797. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149798. GETJSAMPLE(*inptr);
  149799. neighsum = colsum + (colsum - membersum) + nextcolsum;
  149800. membersum = membersum * memberscale + neighsum * neighscale;
  149801. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149802. lastcolsum = colsum; colsum = nextcolsum;
  149803. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149804. membersum = GETJSAMPLE(*inptr++);
  149805. above_ptr++; below_ptr++;
  149806. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149807. GETJSAMPLE(*inptr);
  149808. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  149809. membersum = membersum * memberscale + neighsum * neighscale;
  149810. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149811. lastcolsum = colsum; colsum = nextcolsum;
  149812. }
  149813. membersum = GETJSAMPLE(*inptr);
  149814. neighsum = lastcolsum + (colsum - membersum) + colsum;
  149815. membersum = membersum * memberscale + neighsum * neighscale;
  149816. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149817. }
  149818. }
  149819. #endif /* INPUT_SMOOTHING_SUPPORTED */
  149820. GLOBAL(void)
  149821. jinit_downsampler (j_compress_ptr cinfo)
  149822. {
  149823. my_downsample_ptr downsample;
  149824. int ci;
  149825. jpeg_component_info * compptr;
  149826. boolean smoothok = TRUE;
  149827. downsample = (my_downsample_ptr)
  149828. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149829. SIZEOF(my_downsampler));
  149830. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  149831. downsample->pub.start_pass = start_pass_downsample;
  149832. downsample->pub.downsample = sep_downsample;
  149833. downsample->pub.need_context_rows = FALSE;
  149834. if (cinfo->CCIR601_sampling)
  149835. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  149836. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149837. ci++, compptr++) {
  149838. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  149839. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149840. #ifdef INPUT_SMOOTHING_SUPPORTED
  149841. if (cinfo->smoothing_factor) {
  149842. downsample->methods[ci] = fullsize_smooth_downsample;
  149843. downsample->pub.need_context_rows = TRUE;
  149844. } else
  149845. #endif
  149846. downsample->methods[ci] = fullsize_downsample;
  149847. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149848. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149849. smoothok = FALSE;
  149850. downsample->methods[ci] = h2v1_downsample;
  149851. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149852. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  149853. #ifdef INPUT_SMOOTHING_SUPPORTED
  149854. if (cinfo->smoothing_factor) {
  149855. downsample->methods[ci] = h2v2_smooth_downsample;
  149856. downsample->pub.need_context_rows = TRUE;
  149857. } else
  149858. #endif
  149859. downsample->methods[ci] = h2v2_downsample;
  149860. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  149861. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  149862. smoothok = FALSE;
  149863. downsample->methods[ci] = int_downsample;
  149864. } else
  149865. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  149866. }
  149867. #ifdef INPUT_SMOOTHING_SUPPORTED
  149868. if (cinfo->smoothing_factor && !smoothok)
  149869. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  149870. #endif
  149871. }
  149872. /*** End of inlined file: jcsample.c ***/
  149873. /*** Start of inlined file: jctrans.c ***/
  149874. #define JPEG_INTERNALS
  149875. LOCAL(void) transencode_master_selection
  149876. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149877. LOCAL(void) transencode_coef_controller
  149878. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149879. GLOBAL(void)
  149880. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  149881. {
  149882. if (cinfo->global_state != CSTATE_START)
  149883. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149884. jpeg_suppress_tables(cinfo, FALSE);
  149885. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  149886. (*cinfo->dest->init_destination) (cinfo);
  149887. transencode_master_selection(cinfo, coef_arrays);
  149888. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  149889. cinfo->global_state = CSTATE_WRCOEFS;
  149890. }
  149891. GLOBAL(void)
  149892. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  149893. j_compress_ptr dstinfo)
  149894. {
  149895. JQUANT_TBL ** qtblptr;
  149896. jpeg_component_info *incomp, *outcomp;
  149897. JQUANT_TBL *c_quant, *slot_quant;
  149898. int tblno, ci, coefi;
  149899. if (dstinfo->global_state != CSTATE_START)
  149900. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  149901. dstinfo->image_width = srcinfo->image_width;
  149902. dstinfo->image_height = srcinfo->image_height;
  149903. dstinfo->input_components = srcinfo->num_components;
  149904. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  149905. jpeg_set_defaults(dstinfo);
  149906. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  149907. dstinfo->data_precision = srcinfo->data_precision;
  149908. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  149909. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  149910. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  149911. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  149912. if (*qtblptr == NULL)
  149913. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  149914. MEMCOPY((*qtblptr)->quantval,
  149915. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  149916. SIZEOF((*qtblptr)->quantval));
  149917. (*qtblptr)->sent_table = FALSE;
  149918. }
  149919. }
  149920. dstinfo->num_components = srcinfo->num_components;
  149921. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  149922. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  149923. MAX_COMPONENTS);
  149924. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  149925. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  149926. outcomp->component_id = incomp->component_id;
  149927. outcomp->h_samp_factor = incomp->h_samp_factor;
  149928. outcomp->v_samp_factor = incomp->v_samp_factor;
  149929. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  149930. tblno = outcomp->quant_tbl_no;
  149931. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  149932. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  149933. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  149934. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  149935. c_quant = incomp->quant_table;
  149936. if (c_quant != NULL) {
  149937. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  149938. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  149939. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  149940. }
  149941. }
  149942. }
  149943. if (srcinfo->saw_JFIF_marker) {
  149944. if (srcinfo->JFIF_major_version == 1) {
  149945. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  149946. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  149947. }
  149948. dstinfo->density_unit = srcinfo->density_unit;
  149949. dstinfo->X_density = srcinfo->X_density;
  149950. dstinfo->Y_density = srcinfo->Y_density;
  149951. }
  149952. }
  149953. LOCAL(void)
  149954. transencode_master_selection (j_compress_ptr cinfo,
  149955. jvirt_barray_ptr * coef_arrays)
  149956. {
  149957. cinfo->input_components = 1;
  149958. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  149959. if (cinfo->arith_code) {
  149960. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  149961. } else {
  149962. if (cinfo->progressive_mode) {
  149963. #ifdef C_PROGRESSIVE_SUPPORTED
  149964. jinit_phuff_encoder(cinfo);
  149965. #else
  149966. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149967. #endif
  149968. } else
  149969. jinit_huff_encoder(cinfo);
  149970. }
  149971. transencode_coef_controller(cinfo, coef_arrays);
  149972. jinit_marker_writer(cinfo);
  149973. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  149974. (*cinfo->marker->write_file_header) (cinfo);
  149975. }
  149976. typedef struct {
  149977. struct jpeg_c_coef_controller pub; /* public fields */
  149978. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  149979. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  149980. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  149981. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  149982. jvirt_barray_ptr * whole_image;
  149983. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  149984. } my_coef_controller2;
  149985. typedef my_coef_controller2 * my_coef_ptr2;
  149986. LOCAL(void)
  149987. start_iMCU_row2 (j_compress_ptr cinfo)
  149988. {
  149989. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149990. if (cinfo->comps_in_scan > 1) {
  149991. coef->MCU_rows_per_iMCU_row = 1;
  149992. } else {
  149993. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  149994. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  149995. else
  149996. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  149997. }
  149998. coef->mcu_ctr = 0;
  149999. coef->MCU_vert_offset = 0;
  150000. }
  150001. METHODDEF(void)
  150002. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150003. {
  150004. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150005. if (pass_mode != JBUF_CRANK_DEST)
  150006. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150007. coef->iMCU_row_num = 0;
  150008. start_iMCU_row2(cinfo);
  150009. }
  150010. METHODDEF(boolean)
  150011. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150012. {
  150013. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150014. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150015. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150016. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150017. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150018. JDIMENSION start_col;
  150019. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150020. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150021. JBLOCKROW buffer_ptr;
  150022. jpeg_component_info *compptr;
  150023. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150024. compptr = cinfo->cur_comp_info[ci];
  150025. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150026. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150027. coef->iMCU_row_num * compptr->v_samp_factor,
  150028. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150029. }
  150030. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150031. yoffset++) {
  150032. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150033. MCU_col_num++) {
  150034. blkn = 0; /* index of current DCT block within MCU */
  150035. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150036. compptr = cinfo->cur_comp_info[ci];
  150037. start_col = MCU_col_num * compptr->MCU_width;
  150038. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150039. : compptr->last_col_width;
  150040. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150041. if (coef->iMCU_row_num < last_iMCU_row ||
  150042. yindex+yoffset < compptr->last_row_height) {
  150043. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150044. for (xindex = 0; xindex < blockcnt; xindex++)
  150045. MCU_buffer[blkn++] = buffer_ptr++;
  150046. } else {
  150047. xindex = 0;
  150048. }
  150049. for (; xindex < compptr->MCU_width; xindex++) {
  150050. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150051. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150052. blkn++;
  150053. }
  150054. }
  150055. }
  150056. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150057. coef->MCU_vert_offset = yoffset;
  150058. coef->mcu_ctr = MCU_col_num;
  150059. return FALSE;
  150060. }
  150061. }
  150062. coef->mcu_ctr = 0;
  150063. }
  150064. coef->iMCU_row_num++;
  150065. start_iMCU_row2(cinfo);
  150066. return TRUE;
  150067. }
  150068. LOCAL(void)
  150069. transencode_coef_controller (j_compress_ptr cinfo,
  150070. jvirt_barray_ptr * coef_arrays)
  150071. {
  150072. my_coef_ptr2 coef;
  150073. JBLOCKROW buffer;
  150074. int i;
  150075. coef = (my_coef_ptr2)
  150076. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150077. SIZEOF(my_coef_controller2));
  150078. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150079. coef->pub.start_pass = start_pass_coef2;
  150080. coef->pub.compress_data = compress_output2;
  150081. coef->whole_image = coef_arrays;
  150082. buffer = (JBLOCKROW)
  150083. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150084. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150085. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150086. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150087. coef->dummy_buffer[i] = buffer + i;
  150088. }
  150089. }
  150090. /*** End of inlined file: jctrans.c ***/
  150091. /*** Start of inlined file: jdapistd.c ***/
  150092. #define JPEG_INTERNALS
  150093. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150094. GLOBAL(boolean)
  150095. jpeg_start_decompress (j_decompress_ptr cinfo)
  150096. {
  150097. if (cinfo->global_state == DSTATE_READY) {
  150098. jinit_master_decompress(cinfo);
  150099. if (cinfo->buffered_image) {
  150100. cinfo->global_state = DSTATE_BUFIMAGE;
  150101. return TRUE;
  150102. }
  150103. cinfo->global_state = DSTATE_PRELOAD;
  150104. }
  150105. if (cinfo->global_state == DSTATE_PRELOAD) {
  150106. if (cinfo->inputctl->has_multiple_scans) {
  150107. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150108. for (;;) {
  150109. int retcode;
  150110. if (cinfo->progress != NULL)
  150111. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150112. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150113. if (retcode == JPEG_SUSPENDED)
  150114. return FALSE;
  150115. if (retcode == JPEG_REACHED_EOI)
  150116. break;
  150117. if (cinfo->progress != NULL &&
  150118. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150119. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150120. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150121. }
  150122. }
  150123. }
  150124. #else
  150125. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150126. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150127. }
  150128. cinfo->output_scan_number = cinfo->input_scan_number;
  150129. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150130. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150131. return output_pass_setup(cinfo);
  150132. }
  150133. LOCAL(boolean)
  150134. output_pass_setup (j_decompress_ptr cinfo)
  150135. {
  150136. if (cinfo->global_state != DSTATE_PRESCAN) {
  150137. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150138. cinfo->output_scanline = 0;
  150139. cinfo->global_state = DSTATE_PRESCAN;
  150140. }
  150141. while (cinfo->master->is_dummy_pass) {
  150142. #ifdef QUANT_2PASS_SUPPORTED
  150143. while (cinfo->output_scanline < cinfo->output_height) {
  150144. JDIMENSION last_scanline;
  150145. if (cinfo->progress != NULL) {
  150146. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150147. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150148. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150149. }
  150150. last_scanline = cinfo->output_scanline;
  150151. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150152. &cinfo->output_scanline, (JDIMENSION) 0);
  150153. if (cinfo->output_scanline == last_scanline)
  150154. return FALSE; /* No progress made, must suspend */
  150155. }
  150156. (*cinfo->master->finish_output_pass) (cinfo);
  150157. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150158. cinfo->output_scanline = 0;
  150159. #else
  150160. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150161. #endif /* QUANT_2PASS_SUPPORTED */
  150162. }
  150163. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150164. return TRUE;
  150165. }
  150166. GLOBAL(JDIMENSION)
  150167. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150168. JDIMENSION max_lines)
  150169. {
  150170. JDIMENSION row_ctr;
  150171. if (cinfo->global_state != DSTATE_SCANNING)
  150172. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150173. if (cinfo->output_scanline >= cinfo->output_height) {
  150174. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150175. return 0;
  150176. }
  150177. if (cinfo->progress != NULL) {
  150178. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150179. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150180. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150181. }
  150182. row_ctr = 0;
  150183. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150184. cinfo->output_scanline += row_ctr;
  150185. return row_ctr;
  150186. }
  150187. GLOBAL(JDIMENSION)
  150188. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150189. JDIMENSION max_lines)
  150190. {
  150191. JDIMENSION lines_per_iMCU_row;
  150192. if (cinfo->global_state != DSTATE_RAW_OK)
  150193. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150194. if (cinfo->output_scanline >= cinfo->output_height) {
  150195. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150196. return 0;
  150197. }
  150198. if (cinfo->progress != NULL) {
  150199. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150200. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150201. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150202. }
  150203. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150204. if (max_lines < lines_per_iMCU_row)
  150205. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150206. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150207. return 0; /* suspension forced, can do nothing more */
  150208. cinfo->output_scanline += lines_per_iMCU_row;
  150209. return lines_per_iMCU_row;
  150210. }
  150211. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150212. GLOBAL(boolean)
  150213. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150214. {
  150215. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150216. cinfo->global_state != DSTATE_PRESCAN)
  150217. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150218. if (scan_number <= 0)
  150219. scan_number = 1;
  150220. if (cinfo->inputctl->eoi_reached &&
  150221. scan_number > cinfo->input_scan_number)
  150222. scan_number = cinfo->input_scan_number;
  150223. cinfo->output_scan_number = scan_number;
  150224. return output_pass_setup(cinfo);
  150225. }
  150226. GLOBAL(boolean)
  150227. jpeg_finish_output (j_decompress_ptr cinfo)
  150228. {
  150229. if ((cinfo->global_state == DSTATE_SCANNING ||
  150230. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150231. (*cinfo->master->finish_output_pass) (cinfo);
  150232. cinfo->global_state = DSTATE_BUFPOST;
  150233. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150234. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150235. }
  150236. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150237. ! cinfo->inputctl->eoi_reached) {
  150238. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150239. return FALSE; /* Suspend, come back later */
  150240. }
  150241. cinfo->global_state = DSTATE_BUFIMAGE;
  150242. return TRUE;
  150243. }
  150244. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150245. /*** End of inlined file: jdapistd.c ***/
  150246. /*** Start of inlined file: jdapimin.c ***/
  150247. #define JPEG_INTERNALS
  150248. GLOBAL(void)
  150249. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150250. {
  150251. int i;
  150252. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150253. if (version != JPEG_LIB_VERSION)
  150254. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150255. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150256. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150257. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150258. {
  150259. struct jpeg_error_mgr * err = cinfo->err;
  150260. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150261. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150262. cinfo->err = err;
  150263. cinfo->client_data = client_data;
  150264. }
  150265. cinfo->is_decompressor = TRUE;
  150266. jinit_memory_mgr((j_common_ptr) cinfo);
  150267. cinfo->progress = NULL;
  150268. cinfo->src = NULL;
  150269. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150270. cinfo->quant_tbl_ptrs[i] = NULL;
  150271. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150272. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150273. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150274. }
  150275. cinfo->marker_list = NULL;
  150276. jinit_marker_reader(cinfo);
  150277. jinit_input_controller(cinfo);
  150278. cinfo->global_state = DSTATE_START;
  150279. }
  150280. GLOBAL(void)
  150281. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150282. {
  150283. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150284. }
  150285. GLOBAL(void)
  150286. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150287. {
  150288. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150289. }
  150290. LOCAL(void)
  150291. default_decompress_parms (j_decompress_ptr cinfo)
  150292. {
  150293. switch (cinfo->num_components) {
  150294. case 1:
  150295. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150296. cinfo->out_color_space = JCS_GRAYSCALE;
  150297. break;
  150298. case 3:
  150299. if (cinfo->saw_JFIF_marker) {
  150300. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150301. } else if (cinfo->saw_Adobe_marker) {
  150302. switch (cinfo->Adobe_transform) {
  150303. case 0:
  150304. cinfo->jpeg_color_space = JCS_RGB;
  150305. break;
  150306. case 1:
  150307. cinfo->jpeg_color_space = JCS_YCbCr;
  150308. break;
  150309. default:
  150310. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150311. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150312. break;
  150313. }
  150314. } else {
  150315. int cid0 = cinfo->comp_info[0].component_id;
  150316. int cid1 = cinfo->comp_info[1].component_id;
  150317. int cid2 = cinfo->comp_info[2].component_id;
  150318. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150319. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150320. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150321. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150322. else {
  150323. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150324. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150325. }
  150326. }
  150327. cinfo->out_color_space = JCS_RGB;
  150328. break;
  150329. case 4:
  150330. if (cinfo->saw_Adobe_marker) {
  150331. switch (cinfo->Adobe_transform) {
  150332. case 0:
  150333. cinfo->jpeg_color_space = JCS_CMYK;
  150334. break;
  150335. case 2:
  150336. cinfo->jpeg_color_space = JCS_YCCK;
  150337. break;
  150338. default:
  150339. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150340. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150341. break;
  150342. }
  150343. } else {
  150344. cinfo->jpeg_color_space = JCS_CMYK;
  150345. }
  150346. cinfo->out_color_space = JCS_CMYK;
  150347. break;
  150348. default:
  150349. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150350. cinfo->out_color_space = JCS_UNKNOWN;
  150351. break;
  150352. }
  150353. cinfo->scale_num = 1; /* 1:1 scaling */
  150354. cinfo->scale_denom = 1;
  150355. cinfo->output_gamma = 1.0;
  150356. cinfo->buffered_image = FALSE;
  150357. cinfo->raw_data_out = FALSE;
  150358. cinfo->dct_method = JDCT_DEFAULT;
  150359. cinfo->do_fancy_upsampling = TRUE;
  150360. cinfo->do_block_smoothing = TRUE;
  150361. cinfo->quantize_colors = FALSE;
  150362. cinfo->dither_mode = JDITHER_FS;
  150363. #ifdef QUANT_2PASS_SUPPORTED
  150364. cinfo->two_pass_quantize = TRUE;
  150365. #else
  150366. cinfo->two_pass_quantize = FALSE;
  150367. #endif
  150368. cinfo->desired_number_of_colors = 256;
  150369. cinfo->colormap = NULL;
  150370. cinfo->enable_1pass_quant = FALSE;
  150371. cinfo->enable_external_quant = FALSE;
  150372. cinfo->enable_2pass_quant = FALSE;
  150373. }
  150374. GLOBAL(int)
  150375. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150376. {
  150377. int retcode;
  150378. if (cinfo->global_state != DSTATE_START &&
  150379. cinfo->global_state != DSTATE_INHEADER)
  150380. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150381. retcode = jpeg_consume_input(cinfo);
  150382. switch (retcode) {
  150383. case JPEG_REACHED_SOS:
  150384. retcode = JPEG_HEADER_OK;
  150385. break;
  150386. case JPEG_REACHED_EOI:
  150387. if (require_image) /* Complain if application wanted an image */
  150388. ERREXIT(cinfo, JERR_NO_IMAGE);
  150389. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150390. retcode = JPEG_HEADER_TABLES_ONLY;
  150391. break;
  150392. case JPEG_SUSPENDED:
  150393. break;
  150394. }
  150395. return retcode;
  150396. }
  150397. GLOBAL(int)
  150398. jpeg_consume_input (j_decompress_ptr cinfo)
  150399. {
  150400. int retcode = JPEG_SUSPENDED;
  150401. switch (cinfo->global_state) {
  150402. case DSTATE_START:
  150403. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150404. (*cinfo->src->init_source) (cinfo);
  150405. cinfo->global_state = DSTATE_INHEADER;
  150406. case DSTATE_INHEADER:
  150407. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150408. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150409. default_decompress_parms(cinfo);
  150410. cinfo->global_state = DSTATE_READY;
  150411. }
  150412. break;
  150413. case DSTATE_READY:
  150414. retcode = JPEG_REACHED_SOS;
  150415. break;
  150416. case DSTATE_PRELOAD:
  150417. case DSTATE_PRESCAN:
  150418. case DSTATE_SCANNING:
  150419. case DSTATE_RAW_OK:
  150420. case DSTATE_BUFIMAGE:
  150421. case DSTATE_BUFPOST:
  150422. case DSTATE_STOPPING:
  150423. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150424. break;
  150425. default:
  150426. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150427. }
  150428. return retcode;
  150429. }
  150430. GLOBAL(boolean)
  150431. jpeg_input_complete (j_decompress_ptr cinfo)
  150432. {
  150433. if (cinfo->global_state < DSTATE_START ||
  150434. cinfo->global_state > DSTATE_STOPPING)
  150435. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150436. return cinfo->inputctl->eoi_reached;
  150437. }
  150438. GLOBAL(boolean)
  150439. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150440. {
  150441. if (cinfo->global_state < DSTATE_READY ||
  150442. cinfo->global_state > DSTATE_STOPPING)
  150443. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150444. return cinfo->inputctl->has_multiple_scans;
  150445. }
  150446. GLOBAL(boolean)
  150447. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150448. {
  150449. if ((cinfo->global_state == DSTATE_SCANNING ||
  150450. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150451. if (cinfo->output_scanline < cinfo->output_height)
  150452. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150453. (*cinfo->master->finish_output_pass) (cinfo);
  150454. cinfo->global_state = DSTATE_STOPPING;
  150455. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150456. cinfo->global_state = DSTATE_STOPPING;
  150457. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150458. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150459. }
  150460. while (! cinfo->inputctl->eoi_reached) {
  150461. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150462. return FALSE; /* Suspend, come back later */
  150463. }
  150464. (*cinfo->src->term_source) (cinfo);
  150465. jpeg_abort((j_common_ptr) cinfo);
  150466. return TRUE;
  150467. }
  150468. /*** End of inlined file: jdapimin.c ***/
  150469. /*** Start of inlined file: jdatasrc.c ***/
  150470. /*** Start of inlined file: jerror.h ***/
  150471. #ifndef JMESSAGE
  150472. #ifndef JERROR_H
  150473. #define JMAKE_ENUM_LIST
  150474. #else
  150475. #define JMESSAGE(code,string)
  150476. #endif /* JERROR_H */
  150477. #endif /* JMESSAGE */
  150478. #ifdef JMAKE_ENUM_LIST
  150479. typedef enum {
  150480. #define JMESSAGE(code,string) code ,
  150481. #endif /* JMAKE_ENUM_LIST */
  150482. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150483. JMESSAGE(JERR_ARITH_NOTIMPL,
  150484. "Sorry, there are legal restrictions on arithmetic coding")
  150485. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150486. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150487. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150488. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150489. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150490. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150491. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150492. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150493. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150494. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150495. JMESSAGE(JERR_BAD_LIB_VERSION,
  150496. "Wrong JPEG library version: library is %d, caller expects %d")
  150497. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150498. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150499. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150500. JMESSAGE(JERR_BAD_PROGRESSION,
  150501. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150502. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150503. "Invalid progressive parameters at scan script entry %d")
  150504. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150505. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150506. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150507. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150508. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150509. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150510. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150511. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150512. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150513. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150514. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150515. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150516. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150517. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150518. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150519. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150520. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150521. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150522. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150523. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150524. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150525. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150526. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150527. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150528. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150529. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150530. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150531. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150532. "Cannot transcode due to multiple use of quantization table %d")
  150533. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150534. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150535. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150536. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150537. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150538. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  150539. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  150540. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  150541. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  150542. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  150543. JMESSAGE(JERR_QUANT_COMPONENTS,
  150544. "Cannot quantize more than %d color components")
  150545. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  150546. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  150547. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  150548. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  150549. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  150550. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  150551. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  150552. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  150553. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  150554. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  150555. JMESSAGE(JERR_TFILE_WRITE,
  150556. "Write failed on temporary file --- out of disk space?")
  150557. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  150558. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  150559. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  150560. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  150561. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  150562. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  150563. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  150564. JMESSAGE(JMSG_VERSION, JVERSION)
  150565. JMESSAGE(JTRC_16BIT_TABLES,
  150566. "Caution: quantization tables are too coarse for baseline JPEG")
  150567. JMESSAGE(JTRC_ADOBE,
  150568. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  150569. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  150570. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  150571. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  150572. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  150573. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  150574. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  150575. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  150576. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  150577. JMESSAGE(JTRC_EOI, "End Of Image")
  150578. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  150579. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  150580. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  150581. "Warning: thumbnail image size does not match data length %u")
  150582. JMESSAGE(JTRC_JFIF_EXTENSION,
  150583. "JFIF extension marker: type 0x%02x, length %u")
  150584. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  150585. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  150586. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  150587. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  150588. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  150589. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  150590. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  150591. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  150592. JMESSAGE(JTRC_RST, "RST%d")
  150593. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  150594. "Smoothing not supported with nonstandard sampling ratios")
  150595. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  150596. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  150597. JMESSAGE(JTRC_SOI, "Start of Image")
  150598. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  150599. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  150600. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  150601. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  150602. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  150603. JMESSAGE(JTRC_THUMB_JPEG,
  150604. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  150605. JMESSAGE(JTRC_THUMB_PALETTE,
  150606. "JFIF extension marker: palette thumbnail image, length %u")
  150607. JMESSAGE(JTRC_THUMB_RGB,
  150608. "JFIF extension marker: RGB thumbnail image, length %u")
  150609. JMESSAGE(JTRC_UNKNOWN_IDS,
  150610. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  150611. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  150612. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  150613. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  150614. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  150615. "Inconsistent progression sequence for component %d coefficient %d")
  150616. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  150617. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  150618. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  150619. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  150620. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  150621. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  150622. JMESSAGE(JWRN_MUST_RESYNC,
  150623. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  150624. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  150625. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  150626. #ifdef JMAKE_ENUM_LIST
  150627. JMSG_LASTMSGCODE
  150628. } J_MESSAGE_CODE;
  150629. #undef JMAKE_ENUM_LIST
  150630. #endif /* JMAKE_ENUM_LIST */
  150631. #undef JMESSAGE
  150632. #ifndef JERROR_H
  150633. #define JERROR_H
  150634. #define ERREXIT(cinfo,code) \
  150635. ((cinfo)->err->msg_code = (code), \
  150636. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150637. #define ERREXIT1(cinfo,code,p1) \
  150638. ((cinfo)->err->msg_code = (code), \
  150639. (cinfo)->err->msg_parm.i[0] = (p1), \
  150640. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150641. #define ERREXIT2(cinfo,code,p1,p2) \
  150642. ((cinfo)->err->msg_code = (code), \
  150643. (cinfo)->err->msg_parm.i[0] = (p1), \
  150644. (cinfo)->err->msg_parm.i[1] = (p2), \
  150645. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150646. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  150647. ((cinfo)->err->msg_code = (code), \
  150648. (cinfo)->err->msg_parm.i[0] = (p1), \
  150649. (cinfo)->err->msg_parm.i[1] = (p2), \
  150650. (cinfo)->err->msg_parm.i[2] = (p3), \
  150651. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150652. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  150653. ((cinfo)->err->msg_code = (code), \
  150654. (cinfo)->err->msg_parm.i[0] = (p1), \
  150655. (cinfo)->err->msg_parm.i[1] = (p2), \
  150656. (cinfo)->err->msg_parm.i[2] = (p3), \
  150657. (cinfo)->err->msg_parm.i[3] = (p4), \
  150658. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150659. #define ERREXITS(cinfo,code,str) \
  150660. ((cinfo)->err->msg_code = (code), \
  150661. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150662. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150663. #define MAKESTMT(stuff) do { stuff } while (0)
  150664. #define WARNMS(cinfo,code) \
  150665. ((cinfo)->err->msg_code = (code), \
  150666. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150667. #define WARNMS1(cinfo,code,p1) \
  150668. ((cinfo)->err->msg_code = (code), \
  150669. (cinfo)->err->msg_parm.i[0] = (p1), \
  150670. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150671. #define WARNMS2(cinfo,code,p1,p2) \
  150672. ((cinfo)->err->msg_code = (code), \
  150673. (cinfo)->err->msg_parm.i[0] = (p1), \
  150674. (cinfo)->err->msg_parm.i[1] = (p2), \
  150675. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150676. #define TRACEMS(cinfo,lvl,code) \
  150677. ((cinfo)->err->msg_code = (code), \
  150678. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150679. #define TRACEMS1(cinfo,lvl,code,p1) \
  150680. ((cinfo)->err->msg_code = (code), \
  150681. (cinfo)->err->msg_parm.i[0] = (p1), \
  150682. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150683. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  150684. ((cinfo)->err->msg_code = (code), \
  150685. (cinfo)->err->msg_parm.i[0] = (p1), \
  150686. (cinfo)->err->msg_parm.i[1] = (p2), \
  150687. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150688. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  150689. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150690. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  150691. (cinfo)->err->msg_code = (code); \
  150692. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150693. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  150694. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150695. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150696. (cinfo)->err->msg_code = (code); \
  150697. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150698. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  150699. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150700. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150701. _mp[4] = (p5); \
  150702. (cinfo)->err->msg_code = (code); \
  150703. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150704. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  150705. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150706. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150707. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  150708. (cinfo)->err->msg_code = (code); \
  150709. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150710. #define TRACEMSS(cinfo,lvl,code,str) \
  150711. ((cinfo)->err->msg_code = (code), \
  150712. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150713. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150714. #endif /* JERROR_H */
  150715. /*** End of inlined file: jerror.h ***/
  150716. typedef struct {
  150717. struct jpeg_source_mgr pub; /* public fields */
  150718. FILE * infile; /* source stream */
  150719. JOCTET * buffer; /* start of buffer */
  150720. boolean start_of_file; /* have we gotten any data yet? */
  150721. } my_source_mgr;
  150722. typedef my_source_mgr * my_src_ptr;
  150723. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  150724. METHODDEF(void)
  150725. init_source (j_decompress_ptr cinfo)
  150726. {
  150727. my_src_ptr src = (my_src_ptr) cinfo->src;
  150728. src->start_of_file = TRUE;
  150729. }
  150730. METHODDEF(boolean)
  150731. fill_input_buffer (j_decompress_ptr cinfo)
  150732. {
  150733. my_src_ptr src = (my_src_ptr) cinfo->src;
  150734. size_t nbytes;
  150735. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  150736. if (nbytes <= 0) {
  150737. if (src->start_of_file) /* Treat empty input file as fatal error */
  150738. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  150739. WARNMS(cinfo, JWRN_JPEG_EOF);
  150740. src->buffer[0] = (JOCTET) 0xFF;
  150741. src->buffer[1] = (JOCTET) JPEG_EOI;
  150742. nbytes = 2;
  150743. }
  150744. src->pub.next_input_byte = src->buffer;
  150745. src->pub.bytes_in_buffer = nbytes;
  150746. src->start_of_file = FALSE;
  150747. return TRUE;
  150748. }
  150749. METHODDEF(void)
  150750. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  150751. {
  150752. my_src_ptr src = (my_src_ptr) cinfo->src;
  150753. if (num_bytes > 0) {
  150754. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  150755. num_bytes -= (long) src->pub.bytes_in_buffer;
  150756. (void) fill_input_buffer(cinfo);
  150757. }
  150758. src->pub.next_input_byte += (size_t) num_bytes;
  150759. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  150760. }
  150761. }
  150762. METHODDEF(void)
  150763. term_source (j_decompress_ptr cinfo)
  150764. {
  150765. }
  150766. GLOBAL(void)
  150767. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  150768. {
  150769. my_src_ptr src;
  150770. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  150771. cinfo->src = (struct jpeg_source_mgr *)
  150772. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150773. SIZEOF(my_source_mgr));
  150774. src = (my_src_ptr) cinfo->src;
  150775. src->buffer = (JOCTET *)
  150776. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150777. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  150778. }
  150779. src = (my_src_ptr) cinfo->src;
  150780. src->pub.init_source = init_source;
  150781. src->pub.fill_input_buffer = fill_input_buffer;
  150782. src->pub.skip_input_data = skip_input_data;
  150783. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  150784. src->pub.term_source = term_source;
  150785. src->infile = infile;
  150786. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  150787. src->pub.next_input_byte = NULL; /* until buffer loaded */
  150788. }
  150789. /*** End of inlined file: jdatasrc.c ***/
  150790. /*** Start of inlined file: jdcoefct.c ***/
  150791. #define JPEG_INTERNALS
  150792. #ifndef D_PROGRESSIVE_SUPPORTED
  150793. #undef BLOCK_SMOOTHING_SUPPORTED
  150794. #endif
  150795. typedef struct {
  150796. struct jpeg_d_coef_controller pub; /* public fields */
  150797. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  150798. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150799. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150800. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  150801. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150802. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  150803. #endif
  150804. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150805. int * coef_bits_latch;
  150806. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  150807. #endif
  150808. } my_coef_controller3;
  150809. typedef my_coef_controller3 * my_coef_ptr3;
  150810. METHODDEF(int) decompress_onepass
  150811. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150812. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150813. METHODDEF(int) decompress_data
  150814. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150815. #endif
  150816. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150817. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  150818. METHODDEF(int) decompress_smooth_data
  150819. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150820. #endif
  150821. LOCAL(void)
  150822. start_iMCU_row3 (j_decompress_ptr cinfo)
  150823. {
  150824. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150825. if (cinfo->comps_in_scan > 1) {
  150826. coef->MCU_rows_per_iMCU_row = 1;
  150827. } else {
  150828. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  150829. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150830. else
  150831. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150832. }
  150833. coef->MCU_ctr = 0;
  150834. coef->MCU_vert_offset = 0;
  150835. }
  150836. METHODDEF(void)
  150837. start_input_pass (j_decompress_ptr cinfo)
  150838. {
  150839. cinfo->input_iMCU_row = 0;
  150840. start_iMCU_row3(cinfo);
  150841. }
  150842. METHODDEF(void)
  150843. start_output_pass (j_decompress_ptr cinfo)
  150844. {
  150845. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150846. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150847. if (coef->pub.coef_arrays != NULL) {
  150848. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  150849. coef->pub.decompress_data = decompress_smooth_data;
  150850. else
  150851. coef->pub.decompress_data = decompress_data;
  150852. }
  150853. #endif
  150854. cinfo->output_iMCU_row = 0;
  150855. }
  150856. METHODDEF(int)
  150857. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150858. {
  150859. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150860. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150861. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150862. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150863. int blkn, ci, xindex, yindex, yoffset, useful_width;
  150864. JSAMPARRAY output_ptr;
  150865. JDIMENSION start_col, output_col;
  150866. jpeg_component_info *compptr;
  150867. inverse_DCT_method_ptr inverse_DCT;
  150868. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150869. yoffset++) {
  150870. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  150871. MCU_col_num++) {
  150872. jzero_far((void FAR *) coef->MCU_buffer[0],
  150873. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  150874. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150875. coef->MCU_vert_offset = yoffset;
  150876. coef->MCU_ctr = MCU_col_num;
  150877. return JPEG_SUSPENDED;
  150878. }
  150879. blkn = 0; /* index of current DCT block within MCU */
  150880. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150881. compptr = cinfo->cur_comp_info[ci];
  150882. if (! compptr->component_needed) {
  150883. blkn += compptr->MCU_blocks;
  150884. continue;
  150885. }
  150886. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  150887. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150888. : compptr->last_col_width;
  150889. output_ptr = output_buf[compptr->component_index] +
  150890. yoffset * compptr->DCT_scaled_size;
  150891. start_col = MCU_col_num * compptr->MCU_sample_width;
  150892. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150893. if (cinfo->input_iMCU_row < last_iMCU_row ||
  150894. yoffset+yindex < compptr->last_row_height) {
  150895. output_col = start_col;
  150896. for (xindex = 0; xindex < useful_width; xindex++) {
  150897. (*inverse_DCT) (cinfo, compptr,
  150898. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  150899. output_ptr, output_col);
  150900. output_col += compptr->DCT_scaled_size;
  150901. }
  150902. }
  150903. blkn += compptr->MCU_width;
  150904. output_ptr += compptr->DCT_scaled_size;
  150905. }
  150906. }
  150907. }
  150908. coef->MCU_ctr = 0;
  150909. }
  150910. cinfo->output_iMCU_row++;
  150911. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150912. start_iMCU_row3(cinfo);
  150913. return JPEG_ROW_COMPLETED;
  150914. }
  150915. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150916. return JPEG_SCAN_COMPLETED;
  150917. }
  150918. METHODDEF(int)
  150919. dummy_consume_data (j_decompress_ptr cinfo)
  150920. {
  150921. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  150922. }
  150923. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150924. METHODDEF(int)
  150925. consume_data (j_decompress_ptr cinfo)
  150926. {
  150927. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150928. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150929. int blkn, ci, xindex, yindex, yoffset;
  150930. JDIMENSION start_col;
  150931. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150932. JBLOCKROW buffer_ptr;
  150933. jpeg_component_info *compptr;
  150934. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150935. compptr = cinfo->cur_comp_info[ci];
  150936. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150937. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150938. cinfo->input_iMCU_row * compptr->v_samp_factor,
  150939. (JDIMENSION) compptr->v_samp_factor, TRUE);
  150940. }
  150941. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150942. yoffset++) {
  150943. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150944. MCU_col_num++) {
  150945. blkn = 0; /* index of current DCT block within MCU */
  150946. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150947. compptr = cinfo->cur_comp_info[ci];
  150948. start_col = MCU_col_num * compptr->MCU_width;
  150949. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150950. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150951. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  150952. coef->MCU_buffer[blkn++] = buffer_ptr++;
  150953. }
  150954. }
  150955. }
  150956. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150957. coef->MCU_vert_offset = yoffset;
  150958. coef->MCU_ctr = MCU_col_num;
  150959. return JPEG_SUSPENDED;
  150960. }
  150961. }
  150962. coef->MCU_ctr = 0;
  150963. }
  150964. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150965. start_iMCU_row3(cinfo);
  150966. return JPEG_ROW_COMPLETED;
  150967. }
  150968. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150969. return JPEG_SCAN_COMPLETED;
  150970. }
  150971. METHODDEF(int)
  150972. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150973. {
  150974. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150975. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150976. JDIMENSION block_num;
  150977. int ci, block_row, block_rows;
  150978. JBLOCKARRAY buffer;
  150979. JBLOCKROW buffer_ptr;
  150980. JSAMPARRAY output_ptr;
  150981. JDIMENSION output_col;
  150982. jpeg_component_info *compptr;
  150983. inverse_DCT_method_ptr inverse_DCT;
  150984. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  150985. (cinfo->input_scan_number == cinfo->output_scan_number &&
  150986. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  150987. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  150988. return JPEG_SUSPENDED;
  150989. }
  150990. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150991. ci++, compptr++) {
  150992. if (! compptr->component_needed)
  150993. continue;
  150994. buffer = (*cinfo->mem->access_virt_barray)
  150995. ((j_common_ptr) cinfo, coef->whole_image[ci],
  150996. cinfo->output_iMCU_row * compptr->v_samp_factor,
  150997. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150998. if (cinfo->output_iMCU_row < last_iMCU_row)
  150999. block_rows = compptr->v_samp_factor;
  151000. else {
  151001. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151002. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151003. }
  151004. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151005. output_ptr = output_buf[ci];
  151006. for (block_row = 0; block_row < block_rows; block_row++) {
  151007. buffer_ptr = buffer[block_row];
  151008. output_col = 0;
  151009. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  151010. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151011. output_ptr, output_col);
  151012. buffer_ptr++;
  151013. output_col += compptr->DCT_scaled_size;
  151014. }
  151015. output_ptr += compptr->DCT_scaled_size;
  151016. }
  151017. }
  151018. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151019. return JPEG_ROW_COMPLETED;
  151020. return JPEG_SCAN_COMPLETED;
  151021. }
  151022. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151023. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151024. #define Q01_POS 1
  151025. #define Q10_POS 8
  151026. #define Q20_POS 16
  151027. #define Q11_POS 9
  151028. #define Q02_POS 2
  151029. LOCAL(boolean)
  151030. smoothing_ok (j_decompress_ptr cinfo)
  151031. {
  151032. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151033. boolean smoothing_useful = FALSE;
  151034. int ci, coefi;
  151035. jpeg_component_info *compptr;
  151036. JQUANT_TBL * qtable;
  151037. int * coef_bits;
  151038. int * coef_bits_latch;
  151039. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151040. return FALSE;
  151041. if (coef->coef_bits_latch == NULL)
  151042. coef->coef_bits_latch = (int *)
  151043. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151044. cinfo->num_components *
  151045. (SAVED_COEFS * SIZEOF(int)));
  151046. coef_bits_latch = coef->coef_bits_latch;
  151047. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151048. ci++, compptr++) {
  151049. if ((qtable = compptr->quant_table) == NULL)
  151050. return FALSE;
  151051. if (qtable->quantval[0] == 0 ||
  151052. qtable->quantval[Q01_POS] == 0 ||
  151053. qtable->quantval[Q10_POS] == 0 ||
  151054. qtable->quantval[Q20_POS] == 0 ||
  151055. qtable->quantval[Q11_POS] == 0 ||
  151056. qtable->quantval[Q02_POS] == 0)
  151057. return FALSE;
  151058. coef_bits = cinfo->coef_bits[ci];
  151059. if (coef_bits[0] < 0)
  151060. return FALSE;
  151061. for (coefi = 1; coefi <= 5; coefi++) {
  151062. coef_bits_latch[coefi] = coef_bits[coefi];
  151063. if (coef_bits[coefi] != 0)
  151064. smoothing_useful = TRUE;
  151065. }
  151066. coef_bits_latch += SAVED_COEFS;
  151067. }
  151068. return smoothing_useful;
  151069. }
  151070. METHODDEF(int)
  151071. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151072. {
  151073. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151074. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151075. JDIMENSION block_num, last_block_column;
  151076. int ci, block_row, block_rows, access_rows;
  151077. JBLOCKARRAY buffer;
  151078. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151079. JSAMPARRAY output_ptr;
  151080. JDIMENSION output_col;
  151081. jpeg_component_info *compptr;
  151082. inverse_DCT_method_ptr inverse_DCT;
  151083. boolean first_row, last_row;
  151084. JBLOCK workspace;
  151085. int *coef_bits;
  151086. JQUANT_TBL *quanttbl;
  151087. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151088. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151089. int Al, pred;
  151090. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151091. ! cinfo->inputctl->eoi_reached) {
  151092. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151093. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151094. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151095. break;
  151096. }
  151097. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151098. return JPEG_SUSPENDED;
  151099. }
  151100. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151101. ci++, compptr++) {
  151102. if (! compptr->component_needed)
  151103. continue;
  151104. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151105. block_rows = compptr->v_samp_factor;
  151106. access_rows = block_rows * 2; /* this and next iMCU row */
  151107. last_row = FALSE;
  151108. } else {
  151109. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151110. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151111. access_rows = block_rows; /* this iMCU row only */
  151112. last_row = TRUE;
  151113. }
  151114. if (cinfo->output_iMCU_row > 0) {
  151115. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151116. buffer = (*cinfo->mem->access_virt_barray)
  151117. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151118. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151119. (JDIMENSION) access_rows, FALSE);
  151120. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151121. first_row = FALSE;
  151122. } else {
  151123. buffer = (*cinfo->mem->access_virt_barray)
  151124. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151125. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151126. first_row = TRUE;
  151127. }
  151128. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151129. quanttbl = compptr->quant_table;
  151130. Q00 = quanttbl->quantval[0];
  151131. Q01 = quanttbl->quantval[Q01_POS];
  151132. Q10 = quanttbl->quantval[Q10_POS];
  151133. Q20 = quanttbl->quantval[Q20_POS];
  151134. Q11 = quanttbl->quantval[Q11_POS];
  151135. Q02 = quanttbl->quantval[Q02_POS];
  151136. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151137. output_ptr = output_buf[ci];
  151138. for (block_row = 0; block_row < block_rows; block_row++) {
  151139. buffer_ptr = buffer[block_row];
  151140. if (first_row && block_row == 0)
  151141. prev_block_row = buffer_ptr;
  151142. else
  151143. prev_block_row = buffer[block_row-1];
  151144. if (last_row && block_row == block_rows-1)
  151145. next_block_row = buffer_ptr;
  151146. else
  151147. next_block_row = buffer[block_row+1];
  151148. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151149. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151150. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151151. output_col = 0;
  151152. last_block_column = compptr->width_in_blocks - 1;
  151153. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151154. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151155. if (block_num < last_block_column) {
  151156. DC3 = (int) prev_block_row[1][0];
  151157. DC6 = (int) buffer_ptr[1][0];
  151158. DC9 = (int) next_block_row[1][0];
  151159. }
  151160. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151161. num = 36 * Q00 * (DC4 - DC6);
  151162. if (num >= 0) {
  151163. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151164. if (Al > 0 && pred >= (1<<Al))
  151165. pred = (1<<Al)-1;
  151166. } else {
  151167. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151168. if (Al > 0 && pred >= (1<<Al))
  151169. pred = (1<<Al)-1;
  151170. pred = -pred;
  151171. }
  151172. workspace[1] = (JCOEF) pred;
  151173. }
  151174. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151175. num = 36 * Q00 * (DC2 - DC8);
  151176. if (num >= 0) {
  151177. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151178. if (Al > 0 && pred >= (1<<Al))
  151179. pred = (1<<Al)-1;
  151180. } else {
  151181. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151182. if (Al > 0 && pred >= (1<<Al))
  151183. pred = (1<<Al)-1;
  151184. pred = -pred;
  151185. }
  151186. workspace[8] = (JCOEF) pred;
  151187. }
  151188. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151189. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151190. if (num >= 0) {
  151191. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151192. if (Al > 0 && pred >= (1<<Al))
  151193. pred = (1<<Al)-1;
  151194. } else {
  151195. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151196. if (Al > 0 && pred >= (1<<Al))
  151197. pred = (1<<Al)-1;
  151198. pred = -pred;
  151199. }
  151200. workspace[16] = (JCOEF) pred;
  151201. }
  151202. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151203. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151204. if (num >= 0) {
  151205. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151206. if (Al > 0 && pred >= (1<<Al))
  151207. pred = (1<<Al)-1;
  151208. } else {
  151209. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151210. if (Al > 0 && pred >= (1<<Al))
  151211. pred = (1<<Al)-1;
  151212. pred = -pred;
  151213. }
  151214. workspace[9] = (JCOEF) pred;
  151215. }
  151216. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151217. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151218. if (num >= 0) {
  151219. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151220. if (Al > 0 && pred >= (1<<Al))
  151221. pred = (1<<Al)-1;
  151222. } else {
  151223. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151224. if (Al > 0 && pred >= (1<<Al))
  151225. pred = (1<<Al)-1;
  151226. pred = -pred;
  151227. }
  151228. workspace[2] = (JCOEF) pred;
  151229. }
  151230. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151231. output_ptr, output_col);
  151232. DC1 = DC2; DC2 = DC3;
  151233. DC4 = DC5; DC5 = DC6;
  151234. DC7 = DC8; DC8 = DC9;
  151235. buffer_ptr++, prev_block_row++, next_block_row++;
  151236. output_col += compptr->DCT_scaled_size;
  151237. }
  151238. output_ptr += compptr->DCT_scaled_size;
  151239. }
  151240. }
  151241. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151242. return JPEG_ROW_COMPLETED;
  151243. return JPEG_SCAN_COMPLETED;
  151244. }
  151245. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151246. GLOBAL(void)
  151247. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151248. {
  151249. my_coef_ptr3 coef;
  151250. coef = (my_coef_ptr3)
  151251. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151252. SIZEOF(my_coef_controller3));
  151253. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151254. coef->pub.start_input_pass = start_input_pass;
  151255. coef->pub.start_output_pass = start_output_pass;
  151256. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151257. coef->coef_bits_latch = NULL;
  151258. #endif
  151259. if (need_full_buffer) {
  151260. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151261. int ci, access_rows;
  151262. jpeg_component_info *compptr;
  151263. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151264. ci++, compptr++) {
  151265. access_rows = compptr->v_samp_factor;
  151266. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151267. if (cinfo->progressive_mode)
  151268. access_rows *= 3;
  151269. #endif
  151270. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151271. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151272. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151273. (long) compptr->h_samp_factor),
  151274. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151275. (long) compptr->v_samp_factor),
  151276. (JDIMENSION) access_rows);
  151277. }
  151278. coef->pub.consume_data = consume_data;
  151279. coef->pub.decompress_data = decompress_data;
  151280. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151281. #else
  151282. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151283. #endif
  151284. } else {
  151285. JBLOCKROW buffer;
  151286. int i;
  151287. buffer = (JBLOCKROW)
  151288. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151289. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151290. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151291. coef->MCU_buffer[i] = buffer + i;
  151292. }
  151293. coef->pub.consume_data = dummy_consume_data;
  151294. coef->pub.decompress_data = decompress_onepass;
  151295. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151296. }
  151297. }
  151298. /*** End of inlined file: jdcoefct.c ***/
  151299. #undef FIX
  151300. /*** Start of inlined file: jdcolor.c ***/
  151301. #define JPEG_INTERNALS
  151302. typedef struct {
  151303. struct jpeg_color_deconverter pub; /* public fields */
  151304. int * Cr_r_tab; /* => table for Cr to R conversion */
  151305. int * Cb_b_tab; /* => table for Cb to B conversion */
  151306. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151307. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151308. } my_color_deconverter2;
  151309. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151310. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151311. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151312. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151313. LOCAL(void)
  151314. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151315. {
  151316. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151317. int i;
  151318. INT32 x;
  151319. SHIFT_TEMPS
  151320. cconvert->Cr_r_tab = (int *)
  151321. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151322. (MAXJSAMPLE+1) * SIZEOF(int));
  151323. cconvert->Cb_b_tab = (int *)
  151324. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151325. (MAXJSAMPLE+1) * SIZEOF(int));
  151326. cconvert->Cr_g_tab = (INT32 *)
  151327. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151328. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151329. cconvert->Cb_g_tab = (INT32 *)
  151330. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151331. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151332. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151333. cconvert->Cr_r_tab[i] = (int)
  151334. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151335. cconvert->Cb_b_tab[i] = (int)
  151336. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151337. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151338. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151339. }
  151340. }
  151341. METHODDEF(void)
  151342. ycc_rgb_convert (j_decompress_ptr cinfo,
  151343. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151344. JSAMPARRAY output_buf, int num_rows)
  151345. {
  151346. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151347. register int y, cb, cr;
  151348. register JSAMPROW outptr;
  151349. register JSAMPROW inptr0, inptr1, inptr2;
  151350. register JDIMENSION col;
  151351. JDIMENSION num_cols = cinfo->output_width;
  151352. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151353. register int * Crrtab = cconvert->Cr_r_tab;
  151354. register int * Cbbtab = cconvert->Cb_b_tab;
  151355. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151356. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151357. SHIFT_TEMPS
  151358. while (--num_rows >= 0) {
  151359. inptr0 = input_buf[0][input_row];
  151360. inptr1 = input_buf[1][input_row];
  151361. inptr2 = input_buf[2][input_row];
  151362. input_row++;
  151363. outptr = *output_buf++;
  151364. for (col = 0; col < num_cols; col++) {
  151365. y = GETJSAMPLE(inptr0[col]);
  151366. cb = GETJSAMPLE(inptr1[col]);
  151367. cr = GETJSAMPLE(inptr2[col]);
  151368. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151369. outptr[RGB_GREEN] = range_limit[y +
  151370. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151371. SCALEBITS))];
  151372. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151373. outptr += RGB_PIXELSIZE;
  151374. }
  151375. }
  151376. }
  151377. METHODDEF(void)
  151378. null_convert2 (j_decompress_ptr cinfo,
  151379. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151380. JSAMPARRAY output_buf, int num_rows)
  151381. {
  151382. register JSAMPROW inptr, outptr;
  151383. register JDIMENSION count;
  151384. register int num_components = cinfo->num_components;
  151385. JDIMENSION num_cols = cinfo->output_width;
  151386. int ci;
  151387. while (--num_rows >= 0) {
  151388. for (ci = 0; ci < num_components; ci++) {
  151389. inptr = input_buf[ci][input_row];
  151390. outptr = output_buf[0] + ci;
  151391. for (count = num_cols; count > 0; count--) {
  151392. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151393. outptr += num_components;
  151394. }
  151395. }
  151396. input_row++;
  151397. output_buf++;
  151398. }
  151399. }
  151400. METHODDEF(void)
  151401. grayscale_convert2 (j_decompress_ptr cinfo,
  151402. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151403. JSAMPARRAY output_buf, int num_rows)
  151404. {
  151405. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151406. num_rows, cinfo->output_width);
  151407. }
  151408. METHODDEF(void)
  151409. gray_rgb_convert (j_decompress_ptr cinfo,
  151410. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151411. JSAMPARRAY output_buf, int num_rows)
  151412. {
  151413. register JSAMPROW inptr, outptr;
  151414. register JDIMENSION col;
  151415. JDIMENSION num_cols = cinfo->output_width;
  151416. while (--num_rows >= 0) {
  151417. inptr = input_buf[0][input_row++];
  151418. outptr = *output_buf++;
  151419. for (col = 0; col < num_cols; col++) {
  151420. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151421. outptr += RGB_PIXELSIZE;
  151422. }
  151423. }
  151424. }
  151425. METHODDEF(void)
  151426. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151427. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151428. JSAMPARRAY output_buf, int num_rows)
  151429. {
  151430. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151431. register int y, cb, cr;
  151432. register JSAMPROW outptr;
  151433. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151434. register JDIMENSION col;
  151435. JDIMENSION num_cols = cinfo->output_width;
  151436. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151437. register int * Crrtab = cconvert->Cr_r_tab;
  151438. register int * Cbbtab = cconvert->Cb_b_tab;
  151439. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151440. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151441. SHIFT_TEMPS
  151442. while (--num_rows >= 0) {
  151443. inptr0 = input_buf[0][input_row];
  151444. inptr1 = input_buf[1][input_row];
  151445. inptr2 = input_buf[2][input_row];
  151446. inptr3 = input_buf[3][input_row];
  151447. input_row++;
  151448. outptr = *output_buf++;
  151449. for (col = 0; col < num_cols; col++) {
  151450. y = GETJSAMPLE(inptr0[col]);
  151451. cb = GETJSAMPLE(inptr1[col]);
  151452. cr = GETJSAMPLE(inptr2[col]);
  151453. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151454. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151455. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151456. SCALEBITS)))];
  151457. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151458. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151459. outptr += 4;
  151460. }
  151461. }
  151462. }
  151463. METHODDEF(void)
  151464. start_pass_dcolor (j_decompress_ptr cinfo)
  151465. {
  151466. }
  151467. GLOBAL(void)
  151468. jinit_color_deconverter (j_decompress_ptr cinfo)
  151469. {
  151470. my_cconvert_ptr2 cconvert;
  151471. int ci;
  151472. cconvert = (my_cconvert_ptr2)
  151473. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151474. SIZEOF(my_color_deconverter2));
  151475. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151476. cconvert->pub.start_pass = start_pass_dcolor;
  151477. switch (cinfo->jpeg_color_space) {
  151478. case JCS_GRAYSCALE:
  151479. if (cinfo->num_components != 1)
  151480. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151481. break;
  151482. case JCS_RGB:
  151483. case JCS_YCbCr:
  151484. if (cinfo->num_components != 3)
  151485. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151486. break;
  151487. case JCS_CMYK:
  151488. case JCS_YCCK:
  151489. if (cinfo->num_components != 4)
  151490. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151491. break;
  151492. default: /* JCS_UNKNOWN can be anything */
  151493. if (cinfo->num_components < 1)
  151494. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151495. break;
  151496. }
  151497. switch (cinfo->out_color_space) {
  151498. case JCS_GRAYSCALE:
  151499. cinfo->out_color_components = 1;
  151500. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151501. cinfo->jpeg_color_space == JCS_YCbCr) {
  151502. cconvert->pub.color_convert = grayscale_convert2;
  151503. for (ci = 1; ci < cinfo->num_components; ci++)
  151504. cinfo->comp_info[ci].component_needed = FALSE;
  151505. } else
  151506. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151507. break;
  151508. case JCS_RGB:
  151509. cinfo->out_color_components = RGB_PIXELSIZE;
  151510. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151511. cconvert->pub.color_convert = ycc_rgb_convert;
  151512. build_ycc_rgb_table(cinfo);
  151513. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151514. cconvert->pub.color_convert = gray_rgb_convert;
  151515. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151516. cconvert->pub.color_convert = null_convert2;
  151517. } else
  151518. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151519. break;
  151520. case JCS_CMYK:
  151521. cinfo->out_color_components = 4;
  151522. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151523. cconvert->pub.color_convert = ycck_cmyk_convert;
  151524. build_ycc_rgb_table(cinfo);
  151525. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151526. cconvert->pub.color_convert = null_convert2;
  151527. } else
  151528. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151529. break;
  151530. default:
  151531. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151532. cinfo->out_color_components = cinfo->num_components;
  151533. cconvert->pub.color_convert = null_convert2;
  151534. } else /* unsupported non-null conversion */
  151535. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151536. break;
  151537. }
  151538. if (cinfo->quantize_colors)
  151539. cinfo->output_components = 1; /* single colormapped output component */
  151540. else
  151541. cinfo->output_components = cinfo->out_color_components;
  151542. }
  151543. /*** End of inlined file: jdcolor.c ***/
  151544. #undef FIX
  151545. /*** Start of inlined file: jddctmgr.c ***/
  151546. #define JPEG_INTERNALS
  151547. typedef struct {
  151548. struct jpeg_inverse_dct pub; /* public fields */
  151549. int cur_method[MAX_COMPONENTS];
  151550. } my_idct_controller;
  151551. typedef my_idct_controller * my_idct_ptr;
  151552. typedef union {
  151553. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  151554. #ifdef DCT_IFAST_SUPPORTED
  151555. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  151556. #endif
  151557. #ifdef DCT_FLOAT_SUPPORTED
  151558. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  151559. #endif
  151560. } multiplier_table;
  151561. #ifdef DCT_ISLOW_SUPPORTED
  151562. #define PROVIDE_ISLOW_TABLES
  151563. #else
  151564. #ifdef IDCT_SCALING_SUPPORTED
  151565. #define PROVIDE_ISLOW_TABLES
  151566. #endif
  151567. #endif
  151568. METHODDEF(void)
  151569. start_pass (j_decompress_ptr cinfo)
  151570. {
  151571. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  151572. int ci, i;
  151573. jpeg_component_info *compptr;
  151574. int method = 0;
  151575. inverse_DCT_method_ptr method_ptr = NULL;
  151576. JQUANT_TBL * qtbl;
  151577. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151578. ci++, compptr++) {
  151579. switch (compptr->DCT_scaled_size) {
  151580. #ifdef IDCT_SCALING_SUPPORTED
  151581. case 1:
  151582. method_ptr = jpeg_idct_1x1;
  151583. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151584. break;
  151585. case 2:
  151586. method_ptr = jpeg_idct_2x2;
  151587. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151588. break;
  151589. case 4:
  151590. method_ptr = jpeg_idct_4x4;
  151591. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151592. break;
  151593. #endif
  151594. case DCTSIZE:
  151595. switch (cinfo->dct_method) {
  151596. #ifdef DCT_ISLOW_SUPPORTED
  151597. case JDCT_ISLOW:
  151598. method_ptr = jpeg_idct_islow;
  151599. method = JDCT_ISLOW;
  151600. break;
  151601. #endif
  151602. #ifdef DCT_IFAST_SUPPORTED
  151603. case JDCT_IFAST:
  151604. method_ptr = jpeg_idct_ifast;
  151605. method = JDCT_IFAST;
  151606. break;
  151607. #endif
  151608. #ifdef DCT_FLOAT_SUPPORTED
  151609. case JDCT_FLOAT:
  151610. method_ptr = jpeg_idct_float;
  151611. method = JDCT_FLOAT;
  151612. break;
  151613. #endif
  151614. default:
  151615. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151616. break;
  151617. }
  151618. break;
  151619. default:
  151620. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  151621. break;
  151622. }
  151623. idct->pub.inverse_DCT[ci] = method_ptr;
  151624. if (! compptr->component_needed || idct->cur_method[ci] == method)
  151625. continue;
  151626. qtbl = compptr->quant_table;
  151627. if (qtbl == NULL) /* happens if no data yet for component */
  151628. continue;
  151629. idct->cur_method[ci] = method;
  151630. switch (method) {
  151631. #ifdef PROVIDE_ISLOW_TABLES
  151632. case JDCT_ISLOW:
  151633. {
  151634. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  151635. for (i = 0; i < DCTSIZE2; i++) {
  151636. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  151637. }
  151638. }
  151639. break;
  151640. #endif
  151641. #ifdef DCT_IFAST_SUPPORTED
  151642. case JDCT_IFAST:
  151643. {
  151644. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  151645. #define CONST_BITS 14
  151646. static const INT16 aanscales[DCTSIZE2] = {
  151647. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151648. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  151649. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  151650. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  151651. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151652. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  151653. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  151654. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  151655. };
  151656. SHIFT_TEMPS
  151657. for (i = 0; i < DCTSIZE2; i++) {
  151658. ifmtbl[i] = (IFAST_MULT_TYPE)
  151659. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  151660. (INT32) aanscales[i]),
  151661. CONST_BITS-IFAST_SCALE_BITS);
  151662. }
  151663. }
  151664. break;
  151665. #endif
  151666. #ifdef DCT_FLOAT_SUPPORTED
  151667. case JDCT_FLOAT:
  151668. {
  151669. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  151670. int row, col;
  151671. static const double aanscalefactor[DCTSIZE] = {
  151672. 1.0, 1.387039845, 1.306562965, 1.175875602,
  151673. 1.0, 0.785694958, 0.541196100, 0.275899379
  151674. };
  151675. i = 0;
  151676. for (row = 0; row < DCTSIZE; row++) {
  151677. for (col = 0; col < DCTSIZE; col++) {
  151678. fmtbl[i] = (FLOAT_MULT_TYPE)
  151679. ((double) qtbl->quantval[i] *
  151680. aanscalefactor[row] * aanscalefactor[col]);
  151681. i++;
  151682. }
  151683. }
  151684. }
  151685. break;
  151686. #endif
  151687. default:
  151688. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151689. break;
  151690. }
  151691. }
  151692. }
  151693. GLOBAL(void)
  151694. jinit_inverse_dct (j_decompress_ptr cinfo)
  151695. {
  151696. my_idct_ptr idct;
  151697. int ci;
  151698. jpeg_component_info *compptr;
  151699. idct = (my_idct_ptr)
  151700. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151701. SIZEOF(my_idct_controller));
  151702. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  151703. idct->pub.start_pass = start_pass;
  151704. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151705. ci++, compptr++) {
  151706. compptr->dct_table =
  151707. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151708. SIZEOF(multiplier_table));
  151709. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  151710. idct->cur_method[ci] = -1;
  151711. }
  151712. }
  151713. /*** End of inlined file: jddctmgr.c ***/
  151714. #undef CONST_BITS
  151715. #undef ASSIGN_STATE
  151716. /*** Start of inlined file: jdhuff.c ***/
  151717. #define JPEG_INTERNALS
  151718. /*** Start of inlined file: jdhuff.h ***/
  151719. #ifndef __jdhuff_h__
  151720. #define __jdhuff_h__
  151721. #ifdef NEED_SHORT_EXTERNAL_NAMES
  151722. #define jpeg_make_d_derived_tbl jMkDDerived
  151723. #define jpeg_fill_bit_buffer jFilBitBuf
  151724. #define jpeg_huff_decode jHufDecode
  151725. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  151726. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  151727. typedef struct {
  151728. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  151729. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  151730. JHUFF_TBL *pub;
  151731. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  151732. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  151733. } d_derived_tbl;
  151734. EXTERN(void) jpeg_make_d_derived_tbl
  151735. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  151736. d_derived_tbl ** pdtbl));
  151737. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  151738. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  151739. typedef struct { /* Bitreading state saved across MCUs */
  151740. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151741. int bits_left; /* # of unused bits in it */
  151742. } bitread_perm_state;
  151743. typedef struct { /* Bitreading working state within an MCU */
  151744. const JOCTET * next_input_byte; /* => next byte to read from source */
  151745. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  151746. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151747. int bits_left; /* # of unused bits in it */
  151748. j_decompress_ptr cinfo; /* back link to decompress master record */
  151749. } bitread_working_state;
  151750. #define BITREAD_STATE_VARS \
  151751. register bit_buf_type get_buffer; \
  151752. register int bits_left; \
  151753. bitread_working_state br_state
  151754. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  151755. br_state.cinfo = cinfop; \
  151756. br_state.next_input_byte = cinfop->src->next_input_byte; \
  151757. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  151758. get_buffer = permstate.get_buffer; \
  151759. bits_left = permstate.bits_left;
  151760. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  151761. cinfop->src->next_input_byte = br_state.next_input_byte; \
  151762. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  151763. permstate.get_buffer = get_buffer; \
  151764. permstate.bits_left = bits_left
  151765. #define CHECK_BIT_BUFFER(state,nbits,action) \
  151766. { if (bits_left < (nbits)) { \
  151767. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  151768. { action; } \
  151769. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  151770. #define GET_BITS(nbits) \
  151771. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  151772. #define PEEK_BITS(nbits) \
  151773. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  151774. #define DROP_BITS(nbits) \
  151775. (bits_left -= (nbits))
  151776. EXTERN(boolean) jpeg_fill_bit_buffer
  151777. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151778. register int bits_left, int nbits));
  151779. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  151780. { register int nb, look; \
  151781. if (bits_left < HUFF_LOOKAHEAD) { \
  151782. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  151783. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151784. if (bits_left < HUFF_LOOKAHEAD) { \
  151785. nb = 1; goto slowlabel; \
  151786. } \
  151787. } \
  151788. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  151789. if ((nb = htbl->look_nbits[look]) != 0) { \
  151790. DROP_BITS(nb); \
  151791. result = htbl->look_sym[look]; \
  151792. } else { \
  151793. nb = HUFF_LOOKAHEAD+1; \
  151794. slowlabel: \
  151795. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  151796. { failaction; } \
  151797. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151798. } \
  151799. }
  151800. EXTERN(int) jpeg_huff_decode
  151801. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151802. register int bits_left, d_derived_tbl * htbl, int min_bits));
  151803. #endif
  151804. /*** End of inlined file: jdhuff.h ***/
  151805. /* Declarations shared with jdphuff.c */
  151806. typedef struct {
  151807. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  151808. } savable_state2;
  151809. #ifndef NO_STRUCT_ASSIGN
  151810. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  151811. #else
  151812. #if MAX_COMPS_IN_SCAN == 4
  151813. #define ASSIGN_STATE(dest,src) \
  151814. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  151815. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  151816. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  151817. (dest).last_dc_val[3] = (src).last_dc_val[3])
  151818. #endif
  151819. #endif
  151820. typedef struct {
  151821. struct jpeg_entropy_decoder pub; /* public fields */
  151822. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  151823. savable_state2 saved; /* Other state at start of MCU */
  151824. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  151825. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  151826. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  151827. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151828. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151829. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  151830. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  151831. } huff_entropy_decoder2;
  151832. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  151833. METHODDEF(void)
  151834. start_pass_huff_decoder (j_decompress_ptr cinfo)
  151835. {
  151836. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151837. int ci, blkn, dctbl, actbl;
  151838. jpeg_component_info * compptr;
  151839. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  151840. cinfo->Ah != 0 || cinfo->Al != 0)
  151841. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  151842. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151843. compptr = cinfo->cur_comp_info[ci];
  151844. dctbl = compptr->dc_tbl_no;
  151845. actbl = compptr->ac_tbl_no;
  151846. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  151847. & entropy->dc_derived_tbls[dctbl]);
  151848. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  151849. & entropy->ac_derived_tbls[actbl]);
  151850. entropy->saved.last_dc_val[ci] = 0;
  151851. }
  151852. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  151853. ci = cinfo->MCU_membership[blkn];
  151854. compptr = cinfo->cur_comp_info[ci];
  151855. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  151856. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  151857. if (compptr->component_needed) {
  151858. entropy->dc_needed[blkn] = TRUE;
  151859. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  151860. } else {
  151861. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  151862. }
  151863. }
  151864. entropy->bitstate.bits_left = 0;
  151865. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  151866. entropy->pub.insufficient_data = FALSE;
  151867. entropy->restarts_to_go = cinfo->restart_interval;
  151868. }
  151869. GLOBAL(void)
  151870. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  151871. d_derived_tbl ** pdtbl)
  151872. {
  151873. JHUFF_TBL *htbl;
  151874. d_derived_tbl *dtbl;
  151875. int p, i, l, si, numsymbols;
  151876. int lookbits, ctr;
  151877. char huffsize[257];
  151878. unsigned int huffcode[257];
  151879. unsigned int code;
  151880. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  151881. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151882. htbl =
  151883. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  151884. if (htbl == NULL)
  151885. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151886. if (*pdtbl == NULL)
  151887. *pdtbl = (d_derived_tbl *)
  151888. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151889. SIZEOF(d_derived_tbl));
  151890. dtbl = *pdtbl;
  151891. dtbl->pub = htbl; /* fill in back link */
  151892. p = 0;
  151893. for (l = 1; l <= 16; l++) {
  151894. i = (int) htbl->bits[l];
  151895. if (i < 0 || p + i > 256) /* protect against table overrun */
  151896. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151897. while (i--)
  151898. huffsize[p++] = (char) l;
  151899. }
  151900. huffsize[p] = 0;
  151901. numsymbols = p;
  151902. code = 0;
  151903. si = huffsize[0];
  151904. p = 0;
  151905. while (huffsize[p]) {
  151906. while (((int) huffsize[p]) == si) {
  151907. huffcode[p++] = code;
  151908. code++;
  151909. }
  151910. if (((INT32) code) >= (((INT32) 1) << si))
  151911. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151912. code <<= 1;
  151913. si++;
  151914. }
  151915. p = 0;
  151916. for (l = 1; l <= 16; l++) {
  151917. if (htbl->bits[l]) {
  151918. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  151919. p += htbl->bits[l];
  151920. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  151921. } else {
  151922. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  151923. }
  151924. }
  151925. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  151926. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  151927. p = 0;
  151928. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  151929. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  151930. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  151931. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  151932. dtbl->look_nbits[lookbits] = l;
  151933. dtbl->look_sym[lookbits] = htbl->huffval[p];
  151934. lookbits++;
  151935. }
  151936. }
  151937. }
  151938. if (isDC) {
  151939. for (i = 0; i < numsymbols; i++) {
  151940. int sym = htbl->huffval[i];
  151941. if (sym < 0 || sym > 15)
  151942. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151943. }
  151944. }
  151945. }
  151946. #ifdef SLOW_SHIFT_32
  151947. #define MIN_GET_BITS 15 /* minimum allowable value */
  151948. #else
  151949. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  151950. #endif
  151951. GLOBAL(boolean)
  151952. jpeg_fill_bit_buffer (bitread_working_state * state,
  151953. register bit_buf_type get_buffer, register int bits_left,
  151954. int nbits)
  151955. {
  151956. register const JOCTET * next_input_byte = state->next_input_byte;
  151957. register size_t bytes_in_buffer = state->bytes_in_buffer;
  151958. j_decompress_ptr cinfo = state->cinfo;
  151959. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  151960. while (bits_left < MIN_GET_BITS) {
  151961. register int c;
  151962. if (bytes_in_buffer == 0) {
  151963. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151964. return FALSE;
  151965. next_input_byte = cinfo->src->next_input_byte;
  151966. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151967. }
  151968. bytes_in_buffer--;
  151969. c = GETJOCTET(*next_input_byte++);
  151970. if (c == 0xFF) {
  151971. do {
  151972. if (bytes_in_buffer == 0) {
  151973. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151974. return FALSE;
  151975. next_input_byte = cinfo->src->next_input_byte;
  151976. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151977. }
  151978. bytes_in_buffer--;
  151979. c = GETJOCTET(*next_input_byte++);
  151980. } while (c == 0xFF);
  151981. if (c == 0) {
  151982. c = 0xFF;
  151983. } else {
  151984. cinfo->unread_marker = c;
  151985. goto no_more_bytes;
  151986. }
  151987. }
  151988. get_buffer = (get_buffer << 8) | c;
  151989. bits_left += 8;
  151990. } /* end while */
  151991. } else {
  151992. no_more_bytes:
  151993. if (nbits > bits_left) {
  151994. if (! cinfo->entropy->insufficient_data) {
  151995. WARNMS(cinfo, JWRN_HIT_MARKER);
  151996. cinfo->entropy->insufficient_data = TRUE;
  151997. }
  151998. get_buffer <<= MIN_GET_BITS - bits_left;
  151999. bits_left = MIN_GET_BITS;
  152000. }
  152001. }
  152002. state->next_input_byte = next_input_byte;
  152003. state->bytes_in_buffer = bytes_in_buffer;
  152004. state->get_buffer = get_buffer;
  152005. state->bits_left = bits_left;
  152006. return TRUE;
  152007. }
  152008. GLOBAL(int)
  152009. jpeg_huff_decode (bitread_working_state * state,
  152010. register bit_buf_type get_buffer, register int bits_left,
  152011. d_derived_tbl * htbl, int min_bits)
  152012. {
  152013. register int l = min_bits;
  152014. register INT32 code;
  152015. CHECK_BIT_BUFFER(*state, l, return -1);
  152016. code = GET_BITS(l);
  152017. while (code > htbl->maxcode[l]) {
  152018. code <<= 1;
  152019. CHECK_BIT_BUFFER(*state, 1, return -1);
  152020. code |= GET_BITS(1);
  152021. l++;
  152022. }
  152023. state->get_buffer = get_buffer;
  152024. state->bits_left = bits_left;
  152025. if (l > 16) {
  152026. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152027. return 0; /* fake a zero as the safest result */
  152028. }
  152029. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152030. }
  152031. LOCAL(boolean)
  152032. process_restart (j_decompress_ptr cinfo)
  152033. {
  152034. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152035. int ci;
  152036. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152037. entropy->bitstate.bits_left = 0;
  152038. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152039. return FALSE;
  152040. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152041. entropy->saved.last_dc_val[ci] = 0;
  152042. entropy->restarts_to_go = cinfo->restart_interval;
  152043. if (cinfo->unread_marker == 0)
  152044. entropy->pub.insufficient_data = FALSE;
  152045. return TRUE;
  152046. }
  152047. METHODDEF(boolean)
  152048. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152049. {
  152050. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152051. int blkn;
  152052. BITREAD_STATE_VARS;
  152053. savable_state2 state;
  152054. if (cinfo->restart_interval) {
  152055. if (entropy->restarts_to_go == 0)
  152056. if (! process_restart(cinfo))
  152057. return FALSE;
  152058. }
  152059. if (! entropy->pub.insufficient_data) {
  152060. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152061. ASSIGN_STATE(state, entropy->saved);
  152062. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152063. JBLOCKROW block = MCU_data[blkn];
  152064. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152065. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152066. register int s, k, r;
  152067. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152068. if (s) {
  152069. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152070. r = GET_BITS(s);
  152071. s = HUFF_EXTEND(r, s);
  152072. }
  152073. if (entropy->dc_needed[blkn]) {
  152074. int ci = cinfo->MCU_membership[blkn];
  152075. s += state.last_dc_val[ci];
  152076. state.last_dc_val[ci] = s;
  152077. (*block)[0] = (JCOEF) s;
  152078. }
  152079. if (entropy->ac_needed[blkn]) {
  152080. for (k = 1; k < DCTSIZE2; k++) {
  152081. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152082. r = s >> 4;
  152083. s &= 15;
  152084. if (s) {
  152085. k += r;
  152086. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152087. r = GET_BITS(s);
  152088. s = HUFF_EXTEND(r, s);
  152089. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152090. } else {
  152091. if (r != 15)
  152092. break;
  152093. k += 15;
  152094. }
  152095. }
  152096. } else {
  152097. for (k = 1; k < DCTSIZE2; k++) {
  152098. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152099. r = s >> 4;
  152100. s &= 15;
  152101. if (s) {
  152102. k += r;
  152103. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152104. DROP_BITS(s);
  152105. } else {
  152106. if (r != 15)
  152107. break;
  152108. k += 15;
  152109. }
  152110. }
  152111. }
  152112. }
  152113. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152114. ASSIGN_STATE(entropy->saved, state);
  152115. }
  152116. entropy->restarts_to_go--;
  152117. return TRUE;
  152118. }
  152119. GLOBAL(void)
  152120. jinit_huff_decoder (j_decompress_ptr cinfo)
  152121. {
  152122. huff_entropy_ptr2 entropy;
  152123. int i;
  152124. entropy = (huff_entropy_ptr2)
  152125. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152126. SIZEOF(huff_entropy_decoder2));
  152127. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152128. entropy->pub.start_pass = start_pass_huff_decoder;
  152129. entropy->pub.decode_mcu = decode_mcu;
  152130. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152131. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152132. }
  152133. }
  152134. /*** End of inlined file: jdhuff.c ***/
  152135. /*** Start of inlined file: jdinput.c ***/
  152136. #define JPEG_INTERNALS
  152137. typedef struct {
  152138. struct jpeg_input_controller pub; /* public fields */
  152139. boolean inheaders; /* TRUE until first SOS is reached */
  152140. } my_input_controller;
  152141. typedef my_input_controller * my_inputctl_ptr;
  152142. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152143. LOCAL(void)
  152144. initial_setup2 (j_decompress_ptr cinfo)
  152145. {
  152146. int ci;
  152147. jpeg_component_info *compptr;
  152148. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152149. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152150. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152151. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152152. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152153. if (cinfo->num_components > MAX_COMPONENTS)
  152154. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152155. MAX_COMPONENTS);
  152156. cinfo->max_h_samp_factor = 1;
  152157. cinfo->max_v_samp_factor = 1;
  152158. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152159. ci++, compptr++) {
  152160. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152161. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152162. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152163. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152164. compptr->h_samp_factor);
  152165. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152166. compptr->v_samp_factor);
  152167. }
  152168. cinfo->min_DCT_scaled_size = DCTSIZE;
  152169. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152170. ci++, compptr++) {
  152171. compptr->DCT_scaled_size = DCTSIZE;
  152172. compptr->width_in_blocks = (JDIMENSION)
  152173. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152174. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152175. compptr->height_in_blocks = (JDIMENSION)
  152176. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152177. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152178. compptr->downsampled_width = (JDIMENSION)
  152179. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152180. (long) cinfo->max_h_samp_factor);
  152181. compptr->downsampled_height = (JDIMENSION)
  152182. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152183. (long) cinfo->max_v_samp_factor);
  152184. compptr->component_needed = TRUE;
  152185. compptr->quant_table = NULL;
  152186. }
  152187. cinfo->total_iMCU_rows = (JDIMENSION)
  152188. jdiv_round_up((long) cinfo->image_height,
  152189. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152190. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152191. cinfo->inputctl->has_multiple_scans = TRUE;
  152192. else
  152193. cinfo->inputctl->has_multiple_scans = FALSE;
  152194. }
  152195. LOCAL(void)
  152196. per_scan_setup2 (j_decompress_ptr cinfo)
  152197. {
  152198. int ci, mcublks, tmp;
  152199. jpeg_component_info *compptr;
  152200. if (cinfo->comps_in_scan == 1) {
  152201. compptr = cinfo->cur_comp_info[0];
  152202. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152203. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152204. compptr->MCU_width = 1;
  152205. compptr->MCU_height = 1;
  152206. compptr->MCU_blocks = 1;
  152207. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152208. compptr->last_col_width = 1;
  152209. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152210. if (tmp == 0) tmp = compptr->v_samp_factor;
  152211. compptr->last_row_height = tmp;
  152212. cinfo->blocks_in_MCU = 1;
  152213. cinfo->MCU_membership[0] = 0;
  152214. } else {
  152215. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152216. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152217. MAX_COMPS_IN_SCAN);
  152218. cinfo->MCUs_per_row = (JDIMENSION)
  152219. jdiv_round_up((long) cinfo->image_width,
  152220. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152221. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152222. jdiv_round_up((long) cinfo->image_height,
  152223. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152224. cinfo->blocks_in_MCU = 0;
  152225. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152226. compptr = cinfo->cur_comp_info[ci];
  152227. compptr->MCU_width = compptr->h_samp_factor;
  152228. compptr->MCU_height = compptr->v_samp_factor;
  152229. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152230. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152231. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152232. if (tmp == 0) tmp = compptr->MCU_width;
  152233. compptr->last_col_width = tmp;
  152234. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152235. if (tmp == 0) tmp = compptr->MCU_height;
  152236. compptr->last_row_height = tmp;
  152237. mcublks = compptr->MCU_blocks;
  152238. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152239. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152240. while (mcublks-- > 0) {
  152241. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152242. }
  152243. }
  152244. }
  152245. }
  152246. LOCAL(void)
  152247. latch_quant_tables (j_decompress_ptr cinfo)
  152248. {
  152249. int ci, qtblno;
  152250. jpeg_component_info *compptr;
  152251. JQUANT_TBL * qtbl;
  152252. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152253. compptr = cinfo->cur_comp_info[ci];
  152254. if (compptr->quant_table != NULL)
  152255. continue;
  152256. qtblno = compptr->quant_tbl_no;
  152257. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152258. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152259. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152260. qtbl = (JQUANT_TBL *)
  152261. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152262. SIZEOF(JQUANT_TBL));
  152263. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152264. compptr->quant_table = qtbl;
  152265. }
  152266. }
  152267. METHODDEF(void)
  152268. start_input_pass2 (j_decompress_ptr cinfo)
  152269. {
  152270. per_scan_setup2(cinfo);
  152271. latch_quant_tables(cinfo);
  152272. (*cinfo->entropy->start_pass) (cinfo);
  152273. (*cinfo->coef->start_input_pass) (cinfo);
  152274. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152275. }
  152276. METHODDEF(void)
  152277. finish_input_pass (j_decompress_ptr cinfo)
  152278. {
  152279. cinfo->inputctl->consume_input = consume_markers;
  152280. }
  152281. METHODDEF(int)
  152282. consume_markers (j_decompress_ptr cinfo)
  152283. {
  152284. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152285. int val;
  152286. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152287. return JPEG_REACHED_EOI;
  152288. val = (*cinfo->marker->read_markers) (cinfo);
  152289. switch (val) {
  152290. case JPEG_REACHED_SOS: /* Found SOS */
  152291. if (inputctl->inheaders) { /* 1st SOS */
  152292. initial_setup2(cinfo);
  152293. inputctl->inheaders = FALSE;
  152294. } else { /* 2nd or later SOS marker */
  152295. if (! inputctl->pub.has_multiple_scans)
  152296. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152297. start_input_pass2(cinfo);
  152298. }
  152299. break;
  152300. case JPEG_REACHED_EOI: /* Found EOI */
  152301. inputctl->pub.eoi_reached = TRUE;
  152302. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152303. if (cinfo->marker->saw_SOF)
  152304. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152305. } else {
  152306. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152307. cinfo->output_scan_number = cinfo->input_scan_number;
  152308. }
  152309. break;
  152310. case JPEG_SUSPENDED:
  152311. break;
  152312. }
  152313. return val;
  152314. }
  152315. METHODDEF(void)
  152316. reset_input_controller (j_decompress_ptr cinfo)
  152317. {
  152318. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152319. inputctl->pub.consume_input = consume_markers;
  152320. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152321. inputctl->pub.eoi_reached = FALSE;
  152322. inputctl->inheaders = TRUE;
  152323. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152324. (*cinfo->marker->reset_marker_reader) (cinfo);
  152325. cinfo->coef_bits = NULL;
  152326. }
  152327. GLOBAL(void)
  152328. jinit_input_controller (j_decompress_ptr cinfo)
  152329. {
  152330. my_inputctl_ptr inputctl;
  152331. inputctl = (my_inputctl_ptr)
  152332. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152333. SIZEOF(my_input_controller));
  152334. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152335. inputctl->pub.consume_input = consume_markers;
  152336. inputctl->pub.reset_input_controller = reset_input_controller;
  152337. inputctl->pub.start_input_pass = start_input_pass2;
  152338. inputctl->pub.finish_input_pass = finish_input_pass;
  152339. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152340. inputctl->pub.eoi_reached = FALSE;
  152341. inputctl->inheaders = TRUE;
  152342. }
  152343. /*** End of inlined file: jdinput.c ***/
  152344. /*** Start of inlined file: jdmainct.c ***/
  152345. #define JPEG_INTERNALS
  152346. typedef struct {
  152347. struct jpeg_d_main_controller pub; /* public fields */
  152348. JSAMPARRAY buffer[MAX_COMPONENTS];
  152349. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152350. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152351. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152352. int whichptr; /* indicates which pointer set is now in use */
  152353. int context_state; /* process_data state machine status */
  152354. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152355. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152356. } my_main_controller4;
  152357. typedef my_main_controller4 * my_main_ptr4;
  152358. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152359. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152360. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152361. METHODDEF(void) process_data_simple_main2
  152362. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152363. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152364. METHODDEF(void) process_data_context_main
  152365. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152366. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152367. #ifdef QUANT_2PASS_SUPPORTED
  152368. METHODDEF(void) process_data_crank_post
  152369. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152370. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152371. #endif
  152372. LOCAL(void)
  152373. alloc_funny_pointers (j_decompress_ptr cinfo)
  152374. {
  152375. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152376. int ci, rgroup;
  152377. int M = cinfo->min_DCT_scaled_size;
  152378. jpeg_component_info *compptr;
  152379. JSAMPARRAY xbuf;
  152380. main_->xbuffer[0] = (JSAMPIMAGE)
  152381. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152382. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152383. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152384. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152385. ci++, compptr++) {
  152386. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152387. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152388. xbuf = (JSAMPARRAY)
  152389. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152390. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152391. xbuf += rgroup; /* want one row group at negative offsets */
  152392. main_->xbuffer[0][ci] = xbuf;
  152393. xbuf += rgroup * (M + 4);
  152394. main_->xbuffer[1][ci] = xbuf;
  152395. }
  152396. }
  152397. LOCAL(void)
  152398. make_funny_pointers (j_decompress_ptr cinfo)
  152399. {
  152400. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152401. int ci, i, rgroup;
  152402. int M = cinfo->min_DCT_scaled_size;
  152403. jpeg_component_info *compptr;
  152404. JSAMPARRAY buf, xbuf0, xbuf1;
  152405. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152406. ci++, compptr++) {
  152407. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152408. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152409. xbuf0 = main_->xbuffer[0][ci];
  152410. xbuf1 = main_->xbuffer[1][ci];
  152411. buf = main_->buffer[ci];
  152412. for (i = 0; i < rgroup * (M + 2); i++) {
  152413. xbuf0[i] = xbuf1[i] = buf[i];
  152414. }
  152415. for (i = 0; i < rgroup * 2; i++) {
  152416. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152417. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152418. }
  152419. for (i = 0; i < rgroup; i++) {
  152420. xbuf0[i - rgroup] = xbuf0[0];
  152421. }
  152422. }
  152423. }
  152424. LOCAL(void)
  152425. set_wraparound_pointers (j_decompress_ptr cinfo)
  152426. {
  152427. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152428. int ci, i, rgroup;
  152429. int M = cinfo->min_DCT_scaled_size;
  152430. jpeg_component_info *compptr;
  152431. JSAMPARRAY xbuf0, xbuf1;
  152432. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152433. ci++, compptr++) {
  152434. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152435. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152436. xbuf0 = main_->xbuffer[0][ci];
  152437. xbuf1 = main_->xbuffer[1][ci];
  152438. for (i = 0; i < rgroup; i++) {
  152439. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152440. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152441. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152442. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152443. }
  152444. }
  152445. }
  152446. LOCAL(void)
  152447. set_bottom_pointers (j_decompress_ptr cinfo)
  152448. {
  152449. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152450. int ci, i, rgroup, iMCUheight, rows_left;
  152451. jpeg_component_info *compptr;
  152452. JSAMPARRAY xbuf;
  152453. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152454. ci++, compptr++) {
  152455. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152456. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152457. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152458. if (rows_left == 0) rows_left = iMCUheight;
  152459. if (ci == 0) {
  152460. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152461. }
  152462. xbuf = main_->xbuffer[main_->whichptr][ci];
  152463. for (i = 0; i < rgroup * 2; i++) {
  152464. xbuf[rows_left + i] = xbuf[rows_left-1];
  152465. }
  152466. }
  152467. }
  152468. METHODDEF(void)
  152469. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152470. {
  152471. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152472. switch (pass_mode) {
  152473. case JBUF_PASS_THRU:
  152474. if (cinfo->upsample->need_context_rows) {
  152475. main_->pub.process_data = process_data_context_main;
  152476. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152477. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152478. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152479. main_->iMCU_row_ctr = 0;
  152480. } else {
  152481. main_->pub.process_data = process_data_simple_main2;
  152482. }
  152483. main_->buffer_full = FALSE; /* Mark buffer empty */
  152484. main_->rowgroup_ctr = 0;
  152485. break;
  152486. #ifdef QUANT_2PASS_SUPPORTED
  152487. case JBUF_CRANK_DEST:
  152488. main_->pub.process_data = process_data_crank_post;
  152489. break;
  152490. #endif
  152491. default:
  152492. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152493. break;
  152494. }
  152495. }
  152496. METHODDEF(void)
  152497. process_data_simple_main2 (j_decompress_ptr cinfo,
  152498. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152499. JDIMENSION out_rows_avail)
  152500. {
  152501. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152502. JDIMENSION rowgroups_avail;
  152503. if (! main_->buffer_full) {
  152504. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152505. return; /* suspension forced, can do nothing more */
  152506. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152507. }
  152508. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152509. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152510. &main_->rowgroup_ctr, rowgroups_avail,
  152511. output_buf, out_row_ctr, out_rows_avail);
  152512. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152513. main_->buffer_full = FALSE;
  152514. main_->rowgroup_ctr = 0;
  152515. }
  152516. }
  152517. METHODDEF(void)
  152518. process_data_context_main (j_decompress_ptr cinfo,
  152519. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152520. JDIMENSION out_rows_avail)
  152521. {
  152522. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152523. if (! main_->buffer_full) {
  152524. if (! (*cinfo->coef->decompress_data) (cinfo,
  152525. main_->xbuffer[main_->whichptr]))
  152526. return; /* suspension forced, can do nothing more */
  152527. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152528. main_->iMCU_row_ctr++; /* count rows received */
  152529. }
  152530. switch (main_->context_state) {
  152531. case CTX_POSTPONED_ROW:
  152532. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152533. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152534. output_buf, out_row_ctr, out_rows_avail);
  152535. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152536. return; /* Need to suspend */
  152537. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152538. if (*out_row_ctr >= out_rows_avail)
  152539. return; /* Postprocessor exactly filled output buf */
  152540. case CTX_PREPARE_FOR_IMCU:
  152541. main_->rowgroup_ctr = 0;
  152542. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  152543. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  152544. set_bottom_pointers(cinfo);
  152545. main_->context_state = CTX_PROCESS_IMCU;
  152546. case CTX_PROCESS_IMCU:
  152547. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152548. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152549. output_buf, out_row_ctr, out_rows_avail);
  152550. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152551. return; /* Need to suspend */
  152552. if (main_->iMCU_row_ctr == 1)
  152553. set_wraparound_pointers(cinfo);
  152554. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  152555. main_->buffer_full = FALSE;
  152556. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  152557. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  152558. main_->context_state = CTX_POSTPONED_ROW;
  152559. }
  152560. }
  152561. #ifdef QUANT_2PASS_SUPPORTED
  152562. METHODDEF(void)
  152563. process_data_crank_post (j_decompress_ptr cinfo,
  152564. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152565. JDIMENSION out_rows_avail)
  152566. {
  152567. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  152568. (JDIMENSION *) NULL, (JDIMENSION) 0,
  152569. output_buf, out_row_ctr, out_rows_avail);
  152570. }
  152571. #endif /* QUANT_2PASS_SUPPORTED */
  152572. GLOBAL(void)
  152573. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152574. {
  152575. my_main_ptr4 main_;
  152576. int ci, rgroup, ngroups;
  152577. jpeg_component_info *compptr;
  152578. main_ = (my_main_ptr4)
  152579. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152580. SIZEOF(my_main_controller4));
  152581. cinfo->main = (struct jpeg_d_main_controller *) main_;
  152582. main_->pub.start_pass = start_pass_main2;
  152583. if (need_full_buffer) /* shouldn't happen */
  152584. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152585. if (cinfo->upsample->need_context_rows) {
  152586. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  152587. ERREXIT(cinfo, JERR_NOTIMPL);
  152588. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  152589. ngroups = cinfo->min_DCT_scaled_size + 2;
  152590. } else {
  152591. ngroups = cinfo->min_DCT_scaled_size;
  152592. }
  152593. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152594. ci++, compptr++) {
  152595. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152596. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152597. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  152598. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152599. compptr->width_in_blocks * compptr->DCT_scaled_size,
  152600. (JDIMENSION) (rgroup * ngroups));
  152601. }
  152602. }
  152603. /*** End of inlined file: jdmainct.c ***/
  152604. /*** Start of inlined file: jdmarker.c ***/
  152605. #define JPEG_INTERNALS
  152606. typedef struct {
  152607. struct jpeg_marker_reader pub; /* public fields */
  152608. jpeg_marker_parser_method process_COM;
  152609. jpeg_marker_parser_method process_APPn[16];
  152610. unsigned int length_limit_COM;
  152611. unsigned int length_limit_APPn[16];
  152612. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  152613. unsigned int bytes_read; /* data bytes read so far in marker */
  152614. } my_marker_reader;
  152615. typedef my_marker_reader * my_marker_ptr2;
  152616. #define INPUT_VARS(cinfo) \
  152617. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  152618. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  152619. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  152620. #define INPUT_SYNC(cinfo) \
  152621. ( datasrc->next_input_byte = next_input_byte, \
  152622. datasrc->bytes_in_buffer = bytes_in_buffer )
  152623. #define INPUT_RELOAD(cinfo) \
  152624. ( next_input_byte = datasrc->next_input_byte, \
  152625. bytes_in_buffer = datasrc->bytes_in_buffer )
  152626. #define MAKE_BYTE_AVAIL(cinfo,action) \
  152627. if (bytes_in_buffer == 0) { \
  152628. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  152629. { action; } \
  152630. INPUT_RELOAD(cinfo); \
  152631. }
  152632. #define INPUT_BYTE(cinfo,V,action) \
  152633. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152634. bytes_in_buffer--; \
  152635. V = GETJOCTET(*next_input_byte++); )
  152636. #define INPUT_2BYTES(cinfo,V,action) \
  152637. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152638. bytes_in_buffer--; \
  152639. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  152640. MAKE_BYTE_AVAIL(cinfo,action); \
  152641. bytes_in_buffer--; \
  152642. V += GETJOCTET(*next_input_byte++); )
  152643. LOCAL(boolean)
  152644. get_soi (j_decompress_ptr cinfo)
  152645. {
  152646. int i;
  152647. TRACEMS(cinfo, 1, JTRC_SOI);
  152648. if (cinfo->marker->saw_SOI)
  152649. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  152650. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  152651. cinfo->arith_dc_L[i] = 0;
  152652. cinfo->arith_dc_U[i] = 1;
  152653. cinfo->arith_ac_K[i] = 5;
  152654. }
  152655. cinfo->restart_interval = 0;
  152656. cinfo->jpeg_color_space = JCS_UNKNOWN;
  152657. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  152658. cinfo->saw_JFIF_marker = FALSE;
  152659. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  152660. cinfo->JFIF_minor_version = 1;
  152661. cinfo->density_unit = 0;
  152662. cinfo->X_density = 1;
  152663. cinfo->Y_density = 1;
  152664. cinfo->saw_Adobe_marker = FALSE;
  152665. cinfo->Adobe_transform = 0;
  152666. cinfo->marker->saw_SOI = TRUE;
  152667. return TRUE;
  152668. }
  152669. LOCAL(boolean)
  152670. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  152671. {
  152672. INT32 length;
  152673. int c, ci;
  152674. jpeg_component_info * compptr;
  152675. INPUT_VARS(cinfo);
  152676. cinfo->progressive_mode = is_prog;
  152677. cinfo->arith_code = is_arith;
  152678. INPUT_2BYTES(cinfo, length, return FALSE);
  152679. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  152680. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  152681. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  152682. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  152683. length -= 8;
  152684. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  152685. (int) cinfo->image_width, (int) cinfo->image_height,
  152686. cinfo->num_components);
  152687. if (cinfo->marker->saw_SOF)
  152688. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  152689. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  152690. || cinfo->num_components <= 0)
  152691. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  152692. if (length != (cinfo->num_components * 3))
  152693. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152694. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  152695. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  152696. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152697. cinfo->num_components * SIZEOF(jpeg_component_info));
  152698. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152699. ci++, compptr++) {
  152700. compptr->component_index = ci;
  152701. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  152702. INPUT_BYTE(cinfo, c, return FALSE);
  152703. compptr->h_samp_factor = (c >> 4) & 15;
  152704. compptr->v_samp_factor = (c ) & 15;
  152705. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  152706. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  152707. compptr->component_id, compptr->h_samp_factor,
  152708. compptr->v_samp_factor, compptr->quant_tbl_no);
  152709. }
  152710. cinfo->marker->saw_SOF = TRUE;
  152711. INPUT_SYNC(cinfo);
  152712. return TRUE;
  152713. }
  152714. LOCAL(boolean)
  152715. get_sos (j_decompress_ptr cinfo)
  152716. {
  152717. INT32 length;
  152718. int i, ci, n, c, cc;
  152719. jpeg_component_info * compptr;
  152720. INPUT_VARS(cinfo);
  152721. if (! cinfo->marker->saw_SOF)
  152722. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  152723. INPUT_2BYTES(cinfo, length, return FALSE);
  152724. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  152725. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  152726. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  152727. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152728. cinfo->comps_in_scan = n;
  152729. for (i = 0; i < n; i++) {
  152730. INPUT_BYTE(cinfo, cc, return FALSE);
  152731. INPUT_BYTE(cinfo, c, return FALSE);
  152732. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152733. ci++, compptr++) {
  152734. if (cc == compptr->component_id)
  152735. goto id_found;
  152736. }
  152737. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  152738. id_found:
  152739. cinfo->cur_comp_info[i] = compptr;
  152740. compptr->dc_tbl_no = (c >> 4) & 15;
  152741. compptr->ac_tbl_no = (c ) & 15;
  152742. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  152743. compptr->dc_tbl_no, compptr->ac_tbl_no);
  152744. }
  152745. INPUT_BYTE(cinfo, c, return FALSE);
  152746. cinfo->Ss = c;
  152747. INPUT_BYTE(cinfo, c, return FALSE);
  152748. cinfo->Se = c;
  152749. INPUT_BYTE(cinfo, c, return FALSE);
  152750. cinfo->Ah = (c >> 4) & 15;
  152751. cinfo->Al = (c ) & 15;
  152752. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  152753. cinfo->Ah, cinfo->Al);
  152754. cinfo->marker->next_restart_num = 0;
  152755. cinfo->input_scan_number++;
  152756. INPUT_SYNC(cinfo);
  152757. return TRUE;
  152758. }
  152759. #ifdef D_ARITH_CODING_SUPPORTED
  152760. LOCAL(boolean)
  152761. get_dac (j_decompress_ptr cinfo)
  152762. {
  152763. INT32 length;
  152764. int index, val;
  152765. INPUT_VARS(cinfo);
  152766. INPUT_2BYTES(cinfo, length, return FALSE);
  152767. length -= 2;
  152768. while (length > 0) {
  152769. INPUT_BYTE(cinfo, index, return FALSE);
  152770. INPUT_BYTE(cinfo, val, return FALSE);
  152771. length -= 2;
  152772. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  152773. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  152774. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  152775. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  152776. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  152777. } else { /* define DC table */
  152778. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  152779. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  152780. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  152781. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  152782. }
  152783. }
  152784. if (length != 0)
  152785. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152786. INPUT_SYNC(cinfo);
  152787. return TRUE;
  152788. }
  152789. #else /* ! D_ARITH_CODING_SUPPORTED */
  152790. #define get_dac(cinfo) skip_variable(cinfo)
  152791. #endif /* D_ARITH_CODING_SUPPORTED */
  152792. LOCAL(boolean)
  152793. get_dht (j_decompress_ptr cinfo)
  152794. {
  152795. INT32 length;
  152796. UINT8 bits[17];
  152797. UINT8 huffval[256];
  152798. int i, index, count;
  152799. JHUFF_TBL **htblptr;
  152800. INPUT_VARS(cinfo);
  152801. INPUT_2BYTES(cinfo, length, return FALSE);
  152802. length -= 2;
  152803. while (length > 16) {
  152804. INPUT_BYTE(cinfo, index, return FALSE);
  152805. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  152806. bits[0] = 0;
  152807. count = 0;
  152808. for (i = 1; i <= 16; i++) {
  152809. INPUT_BYTE(cinfo, bits[i], return FALSE);
  152810. count += bits[i];
  152811. }
  152812. length -= 1 + 16;
  152813. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152814. bits[1], bits[2], bits[3], bits[4],
  152815. bits[5], bits[6], bits[7], bits[8]);
  152816. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152817. bits[9], bits[10], bits[11], bits[12],
  152818. bits[13], bits[14], bits[15], bits[16]);
  152819. if (count > 256 || ((INT32) count) > length)
  152820. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152821. for (i = 0; i < count; i++)
  152822. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  152823. length -= count;
  152824. if (index & 0x10) { /* AC table definition */
  152825. index -= 0x10;
  152826. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  152827. } else { /* DC table definition */
  152828. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  152829. }
  152830. if (index < 0 || index >= NUM_HUFF_TBLS)
  152831. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  152832. if (*htblptr == NULL)
  152833. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  152834. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  152835. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  152836. }
  152837. if (length != 0)
  152838. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152839. INPUT_SYNC(cinfo);
  152840. return TRUE;
  152841. }
  152842. LOCAL(boolean)
  152843. get_dqt (j_decompress_ptr cinfo)
  152844. {
  152845. INT32 length;
  152846. int n, i, prec;
  152847. unsigned int tmp;
  152848. JQUANT_TBL *quant_ptr;
  152849. INPUT_VARS(cinfo);
  152850. INPUT_2BYTES(cinfo, length, return FALSE);
  152851. length -= 2;
  152852. while (length > 0) {
  152853. INPUT_BYTE(cinfo, n, return FALSE);
  152854. prec = n >> 4;
  152855. n &= 0x0F;
  152856. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  152857. if (n >= NUM_QUANT_TBLS)
  152858. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  152859. if (cinfo->quant_tbl_ptrs[n] == NULL)
  152860. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  152861. quant_ptr = cinfo->quant_tbl_ptrs[n];
  152862. for (i = 0; i < DCTSIZE2; i++) {
  152863. if (prec)
  152864. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152865. else
  152866. INPUT_BYTE(cinfo, tmp, return FALSE);
  152867. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  152868. }
  152869. if (cinfo->err->trace_level >= 2) {
  152870. for (i = 0; i < DCTSIZE2; i += 8) {
  152871. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  152872. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  152873. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  152874. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  152875. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  152876. }
  152877. }
  152878. length -= DCTSIZE2+1;
  152879. if (prec) length -= DCTSIZE2;
  152880. }
  152881. if (length != 0)
  152882. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152883. INPUT_SYNC(cinfo);
  152884. return TRUE;
  152885. }
  152886. LOCAL(boolean)
  152887. get_dri (j_decompress_ptr cinfo)
  152888. {
  152889. INT32 length;
  152890. unsigned int tmp;
  152891. INPUT_VARS(cinfo);
  152892. INPUT_2BYTES(cinfo, length, return FALSE);
  152893. if (length != 4)
  152894. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152895. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152896. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  152897. cinfo->restart_interval = tmp;
  152898. INPUT_SYNC(cinfo);
  152899. return TRUE;
  152900. }
  152901. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  152902. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  152903. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  152904. LOCAL(void)
  152905. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152906. unsigned int datalen, INT32 remaining)
  152907. {
  152908. INT32 totallen = (INT32) datalen + remaining;
  152909. if (datalen >= APP0_DATA_LEN &&
  152910. GETJOCTET(data[0]) == 0x4A &&
  152911. GETJOCTET(data[1]) == 0x46 &&
  152912. GETJOCTET(data[2]) == 0x49 &&
  152913. GETJOCTET(data[3]) == 0x46 &&
  152914. GETJOCTET(data[4]) == 0) {
  152915. cinfo->saw_JFIF_marker = TRUE;
  152916. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  152917. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  152918. cinfo->density_unit = GETJOCTET(data[7]);
  152919. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  152920. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  152921. if (cinfo->JFIF_major_version != 1)
  152922. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  152923. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  152924. TRACEMS5(cinfo, 1, JTRC_JFIF,
  152925. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  152926. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  152927. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  152928. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  152929. GETJOCTET(data[12]), GETJOCTET(data[13]));
  152930. totallen -= APP0_DATA_LEN;
  152931. if (totallen !=
  152932. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  152933. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  152934. } else if (datalen >= 6 &&
  152935. GETJOCTET(data[0]) == 0x4A &&
  152936. GETJOCTET(data[1]) == 0x46 &&
  152937. GETJOCTET(data[2]) == 0x58 &&
  152938. GETJOCTET(data[3]) == 0x58 &&
  152939. GETJOCTET(data[4]) == 0) {
  152940. switch (GETJOCTET(data[5])) {
  152941. case 0x10:
  152942. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  152943. break;
  152944. case 0x11:
  152945. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  152946. break;
  152947. case 0x13:
  152948. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  152949. break;
  152950. default:
  152951. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  152952. GETJOCTET(data[5]), (int) totallen);
  152953. break;
  152954. }
  152955. } else {
  152956. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  152957. }
  152958. }
  152959. LOCAL(void)
  152960. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152961. unsigned int datalen, INT32 remaining)
  152962. {
  152963. unsigned int version, flags0, flags1, transform;
  152964. if (datalen >= APP14_DATA_LEN &&
  152965. GETJOCTET(data[0]) == 0x41 &&
  152966. GETJOCTET(data[1]) == 0x64 &&
  152967. GETJOCTET(data[2]) == 0x6F &&
  152968. GETJOCTET(data[3]) == 0x62 &&
  152969. GETJOCTET(data[4]) == 0x65) {
  152970. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  152971. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  152972. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  152973. transform = GETJOCTET(data[11]);
  152974. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  152975. cinfo->saw_Adobe_marker = TRUE;
  152976. cinfo->Adobe_transform = (UINT8) transform;
  152977. } else {
  152978. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  152979. }
  152980. }
  152981. METHODDEF(boolean)
  152982. get_interesting_appn (j_decompress_ptr cinfo)
  152983. {
  152984. INT32 length;
  152985. JOCTET b[APPN_DATA_LEN];
  152986. unsigned int i, numtoread;
  152987. INPUT_VARS(cinfo);
  152988. INPUT_2BYTES(cinfo, length, return FALSE);
  152989. length -= 2;
  152990. if (length >= APPN_DATA_LEN)
  152991. numtoread = APPN_DATA_LEN;
  152992. else if (length > 0)
  152993. numtoread = (unsigned int) length;
  152994. else
  152995. numtoread = 0;
  152996. for (i = 0; i < numtoread; i++)
  152997. INPUT_BYTE(cinfo, b[i], return FALSE);
  152998. length -= numtoread;
  152999. switch (cinfo->unread_marker) {
  153000. case M_APP0:
  153001. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  153002. break;
  153003. case M_APP14:
  153004. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  153005. break;
  153006. default:
  153007. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153008. break;
  153009. }
  153010. INPUT_SYNC(cinfo);
  153011. if (length > 0)
  153012. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153013. return TRUE;
  153014. }
  153015. #ifdef SAVE_MARKERS_SUPPORTED
  153016. METHODDEF(boolean)
  153017. save_marker (j_decompress_ptr cinfo)
  153018. {
  153019. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153020. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153021. unsigned int bytes_read, data_length;
  153022. JOCTET FAR * data;
  153023. INT32 length = 0;
  153024. INPUT_VARS(cinfo);
  153025. if (cur_marker == NULL) {
  153026. INPUT_2BYTES(cinfo, length, return FALSE);
  153027. length -= 2;
  153028. if (length >= 0) { /* watch out for bogus length word */
  153029. unsigned int limit;
  153030. if (cinfo->unread_marker == (int) M_COM)
  153031. limit = marker->length_limit_COM;
  153032. else
  153033. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153034. if ((unsigned int) length < limit)
  153035. limit = (unsigned int) length;
  153036. cur_marker = (jpeg_saved_marker_ptr)
  153037. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153038. SIZEOF(struct jpeg_marker_struct) + limit);
  153039. cur_marker->next = NULL;
  153040. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153041. cur_marker->original_length = (unsigned int) length;
  153042. cur_marker->data_length = limit;
  153043. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153044. marker->cur_marker = cur_marker;
  153045. marker->bytes_read = 0;
  153046. bytes_read = 0;
  153047. data_length = limit;
  153048. } else {
  153049. bytes_read = data_length = 0;
  153050. data = NULL;
  153051. }
  153052. } else {
  153053. bytes_read = marker->bytes_read;
  153054. data_length = cur_marker->data_length;
  153055. data = cur_marker->data + bytes_read;
  153056. }
  153057. while (bytes_read < data_length) {
  153058. INPUT_SYNC(cinfo); /* move the restart point to here */
  153059. marker->bytes_read = bytes_read;
  153060. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153061. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153062. *data++ = *next_input_byte++;
  153063. bytes_in_buffer--;
  153064. bytes_read++;
  153065. }
  153066. }
  153067. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153068. if (cinfo->marker_list == NULL) {
  153069. cinfo->marker_list = cur_marker;
  153070. } else {
  153071. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153072. while (prev->next != NULL)
  153073. prev = prev->next;
  153074. prev->next = cur_marker;
  153075. }
  153076. data = cur_marker->data;
  153077. length = cur_marker->original_length - data_length;
  153078. }
  153079. marker->cur_marker = NULL;
  153080. switch (cinfo->unread_marker) {
  153081. case M_APP0:
  153082. examine_app0(cinfo, data, data_length, length);
  153083. break;
  153084. case M_APP14:
  153085. examine_app14(cinfo, data, data_length, length);
  153086. break;
  153087. default:
  153088. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153089. (int) (data_length + length));
  153090. break;
  153091. }
  153092. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153093. if (length > 0)
  153094. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153095. return TRUE;
  153096. }
  153097. #endif /* SAVE_MARKERS_SUPPORTED */
  153098. METHODDEF(boolean)
  153099. skip_variable (j_decompress_ptr cinfo)
  153100. {
  153101. INT32 length;
  153102. INPUT_VARS(cinfo);
  153103. INPUT_2BYTES(cinfo, length, return FALSE);
  153104. length -= 2;
  153105. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153106. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153107. if (length > 0)
  153108. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153109. return TRUE;
  153110. }
  153111. LOCAL(boolean)
  153112. next_marker (j_decompress_ptr cinfo)
  153113. {
  153114. int c;
  153115. INPUT_VARS(cinfo);
  153116. for (;;) {
  153117. INPUT_BYTE(cinfo, c, return FALSE);
  153118. while (c != 0xFF) {
  153119. cinfo->marker->discarded_bytes++;
  153120. INPUT_SYNC(cinfo);
  153121. INPUT_BYTE(cinfo, c, return FALSE);
  153122. }
  153123. do {
  153124. INPUT_BYTE(cinfo, c, return FALSE);
  153125. } while (c == 0xFF);
  153126. if (c != 0)
  153127. break; /* found a valid marker, exit loop */
  153128. cinfo->marker->discarded_bytes += 2;
  153129. INPUT_SYNC(cinfo);
  153130. }
  153131. if (cinfo->marker->discarded_bytes != 0) {
  153132. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153133. cinfo->marker->discarded_bytes = 0;
  153134. }
  153135. cinfo->unread_marker = c;
  153136. INPUT_SYNC(cinfo);
  153137. return TRUE;
  153138. }
  153139. LOCAL(boolean)
  153140. first_marker (j_decompress_ptr cinfo)
  153141. {
  153142. int c, c2;
  153143. INPUT_VARS(cinfo);
  153144. INPUT_BYTE(cinfo, c, return FALSE);
  153145. INPUT_BYTE(cinfo, c2, return FALSE);
  153146. if (c != 0xFF || c2 != (int) M_SOI)
  153147. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153148. cinfo->unread_marker = c2;
  153149. INPUT_SYNC(cinfo);
  153150. return TRUE;
  153151. }
  153152. METHODDEF(int)
  153153. read_markers (j_decompress_ptr cinfo)
  153154. {
  153155. for (;;) {
  153156. if (cinfo->unread_marker == 0) {
  153157. if (! cinfo->marker->saw_SOI) {
  153158. if (! first_marker(cinfo))
  153159. return JPEG_SUSPENDED;
  153160. } else {
  153161. if (! next_marker(cinfo))
  153162. return JPEG_SUSPENDED;
  153163. }
  153164. }
  153165. switch (cinfo->unread_marker) {
  153166. case M_SOI:
  153167. if (! get_soi(cinfo))
  153168. return JPEG_SUSPENDED;
  153169. break;
  153170. case M_SOF0: /* Baseline */
  153171. case M_SOF1: /* Extended sequential, Huffman */
  153172. if (! get_sof(cinfo, FALSE, FALSE))
  153173. return JPEG_SUSPENDED;
  153174. break;
  153175. case M_SOF2: /* Progressive, Huffman */
  153176. if (! get_sof(cinfo, TRUE, FALSE))
  153177. return JPEG_SUSPENDED;
  153178. break;
  153179. case M_SOF9: /* Extended sequential, arithmetic */
  153180. if (! get_sof(cinfo, FALSE, TRUE))
  153181. return JPEG_SUSPENDED;
  153182. break;
  153183. case M_SOF10: /* Progressive, arithmetic */
  153184. if (! get_sof(cinfo, TRUE, TRUE))
  153185. return JPEG_SUSPENDED;
  153186. break;
  153187. case M_SOF3: /* Lossless, Huffman */
  153188. case M_SOF5: /* Differential sequential, Huffman */
  153189. case M_SOF6: /* Differential progressive, Huffman */
  153190. case M_SOF7: /* Differential lossless, Huffman */
  153191. case M_JPG: /* Reserved for JPEG extensions */
  153192. case M_SOF11: /* Lossless, arithmetic */
  153193. case M_SOF13: /* Differential sequential, arithmetic */
  153194. case M_SOF14: /* Differential progressive, arithmetic */
  153195. case M_SOF15: /* Differential lossless, arithmetic */
  153196. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153197. break;
  153198. case M_SOS:
  153199. if (! get_sos(cinfo))
  153200. return JPEG_SUSPENDED;
  153201. cinfo->unread_marker = 0; /* processed the marker */
  153202. return JPEG_REACHED_SOS;
  153203. case M_EOI:
  153204. TRACEMS(cinfo, 1, JTRC_EOI);
  153205. cinfo->unread_marker = 0; /* processed the marker */
  153206. return JPEG_REACHED_EOI;
  153207. case M_DAC:
  153208. if (! get_dac(cinfo))
  153209. return JPEG_SUSPENDED;
  153210. break;
  153211. case M_DHT:
  153212. if (! get_dht(cinfo))
  153213. return JPEG_SUSPENDED;
  153214. break;
  153215. case M_DQT:
  153216. if (! get_dqt(cinfo))
  153217. return JPEG_SUSPENDED;
  153218. break;
  153219. case M_DRI:
  153220. if (! get_dri(cinfo))
  153221. return JPEG_SUSPENDED;
  153222. break;
  153223. case M_APP0:
  153224. case M_APP1:
  153225. case M_APP2:
  153226. case M_APP3:
  153227. case M_APP4:
  153228. case M_APP5:
  153229. case M_APP6:
  153230. case M_APP7:
  153231. case M_APP8:
  153232. case M_APP9:
  153233. case M_APP10:
  153234. case M_APP11:
  153235. case M_APP12:
  153236. case M_APP13:
  153237. case M_APP14:
  153238. case M_APP15:
  153239. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153240. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153241. return JPEG_SUSPENDED;
  153242. break;
  153243. case M_COM:
  153244. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153245. return JPEG_SUSPENDED;
  153246. break;
  153247. case M_RST0: /* these are all parameterless */
  153248. case M_RST1:
  153249. case M_RST2:
  153250. case M_RST3:
  153251. case M_RST4:
  153252. case M_RST5:
  153253. case M_RST6:
  153254. case M_RST7:
  153255. case M_TEM:
  153256. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153257. break;
  153258. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153259. if (! skip_variable(cinfo))
  153260. return JPEG_SUSPENDED;
  153261. break;
  153262. default: /* must be DHP, EXP, JPGn, or RESn */
  153263. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153264. break;
  153265. }
  153266. cinfo->unread_marker = 0;
  153267. } /* end loop */
  153268. }
  153269. METHODDEF(boolean)
  153270. read_restart_marker (j_decompress_ptr cinfo)
  153271. {
  153272. if (cinfo->unread_marker == 0) {
  153273. if (! next_marker(cinfo))
  153274. return FALSE;
  153275. }
  153276. if (cinfo->unread_marker ==
  153277. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153278. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153279. cinfo->unread_marker = 0;
  153280. } else {
  153281. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153282. cinfo->marker->next_restart_num))
  153283. return FALSE;
  153284. }
  153285. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153286. return TRUE;
  153287. }
  153288. GLOBAL(boolean)
  153289. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153290. {
  153291. int marker = cinfo->unread_marker;
  153292. int action = 1;
  153293. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153294. for (;;) {
  153295. if (marker < (int) M_SOF0)
  153296. action = 2; /* invalid marker */
  153297. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153298. action = 3; /* valid non-restart marker */
  153299. else {
  153300. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153301. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153302. action = 3; /* one of the next two expected restarts */
  153303. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153304. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153305. action = 2; /* a prior restart, so advance */
  153306. else
  153307. action = 1; /* desired restart or too far away */
  153308. }
  153309. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153310. switch (action) {
  153311. case 1:
  153312. cinfo->unread_marker = 0;
  153313. return TRUE;
  153314. case 2:
  153315. if (! next_marker(cinfo))
  153316. return FALSE;
  153317. marker = cinfo->unread_marker;
  153318. break;
  153319. case 3:
  153320. return TRUE;
  153321. }
  153322. } /* end loop */
  153323. }
  153324. METHODDEF(void)
  153325. reset_marker_reader (j_decompress_ptr cinfo)
  153326. {
  153327. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153328. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153329. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153330. cinfo->unread_marker = 0; /* no pending marker */
  153331. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153332. marker->pub.saw_SOF = FALSE;
  153333. marker->pub.discarded_bytes = 0;
  153334. marker->cur_marker = NULL;
  153335. }
  153336. GLOBAL(void)
  153337. jinit_marker_reader (j_decompress_ptr cinfo)
  153338. {
  153339. my_marker_ptr2 marker;
  153340. int i;
  153341. marker = (my_marker_ptr2)
  153342. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153343. SIZEOF(my_marker_reader));
  153344. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153345. marker->pub.reset_marker_reader = reset_marker_reader;
  153346. marker->pub.read_markers = read_markers;
  153347. marker->pub.read_restart_marker = read_restart_marker;
  153348. marker->process_COM = skip_variable;
  153349. marker->length_limit_COM = 0;
  153350. for (i = 0; i < 16; i++) {
  153351. marker->process_APPn[i] = skip_variable;
  153352. marker->length_limit_APPn[i] = 0;
  153353. }
  153354. marker->process_APPn[0] = get_interesting_appn;
  153355. marker->process_APPn[14] = get_interesting_appn;
  153356. reset_marker_reader(cinfo);
  153357. }
  153358. #ifdef SAVE_MARKERS_SUPPORTED
  153359. GLOBAL(void)
  153360. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153361. unsigned int length_limit)
  153362. {
  153363. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153364. long maxlength;
  153365. jpeg_marker_parser_method processor;
  153366. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153367. if (((long) length_limit) > maxlength)
  153368. length_limit = (unsigned int) maxlength;
  153369. if (length_limit) {
  153370. processor = save_marker;
  153371. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153372. length_limit = APP0_DATA_LEN;
  153373. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153374. length_limit = APP14_DATA_LEN;
  153375. } else {
  153376. processor = skip_variable;
  153377. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153378. processor = get_interesting_appn;
  153379. }
  153380. if (marker_code == (int) M_COM) {
  153381. marker->process_COM = processor;
  153382. marker->length_limit_COM = length_limit;
  153383. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153384. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153385. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153386. } else
  153387. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153388. }
  153389. #endif /* SAVE_MARKERS_SUPPORTED */
  153390. GLOBAL(void)
  153391. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153392. jpeg_marker_parser_method routine)
  153393. {
  153394. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153395. if (marker_code == (int) M_COM)
  153396. marker->process_COM = routine;
  153397. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153398. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153399. else
  153400. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153401. }
  153402. /*** End of inlined file: jdmarker.c ***/
  153403. /*** Start of inlined file: jdmaster.c ***/
  153404. #define JPEG_INTERNALS
  153405. typedef struct {
  153406. struct jpeg_decomp_master pub; /* public fields */
  153407. int pass_number; /* # of passes completed */
  153408. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153409. struct jpeg_color_quantizer * quantizer_1pass;
  153410. struct jpeg_color_quantizer * quantizer_2pass;
  153411. } my_decomp_master;
  153412. typedef my_decomp_master * my_master_ptr6;
  153413. LOCAL(boolean)
  153414. use_merged_upsample (j_decompress_ptr cinfo)
  153415. {
  153416. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153417. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153418. return FALSE;
  153419. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153420. cinfo->out_color_space != JCS_RGB ||
  153421. cinfo->out_color_components != RGB_PIXELSIZE)
  153422. return FALSE;
  153423. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153424. cinfo->comp_info[1].h_samp_factor != 1 ||
  153425. cinfo->comp_info[2].h_samp_factor != 1 ||
  153426. cinfo->comp_info[0].v_samp_factor > 2 ||
  153427. cinfo->comp_info[1].v_samp_factor != 1 ||
  153428. cinfo->comp_info[2].v_samp_factor != 1)
  153429. return FALSE;
  153430. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153431. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153432. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153433. return FALSE;
  153434. return TRUE; /* by golly, it'll work... */
  153435. #else
  153436. return FALSE;
  153437. #endif
  153438. }
  153439. GLOBAL(void)
  153440. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153441. {
  153442. #ifdef IDCT_SCALING_SUPPORTED
  153443. int ci;
  153444. jpeg_component_info *compptr;
  153445. #endif
  153446. if (cinfo->global_state != DSTATE_READY)
  153447. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153448. #ifdef IDCT_SCALING_SUPPORTED
  153449. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153450. cinfo->output_width = (JDIMENSION)
  153451. jdiv_round_up((long) cinfo->image_width, 8L);
  153452. cinfo->output_height = (JDIMENSION)
  153453. jdiv_round_up((long) cinfo->image_height, 8L);
  153454. cinfo->min_DCT_scaled_size = 1;
  153455. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153456. cinfo->output_width = (JDIMENSION)
  153457. jdiv_round_up((long) cinfo->image_width, 4L);
  153458. cinfo->output_height = (JDIMENSION)
  153459. jdiv_round_up((long) cinfo->image_height, 4L);
  153460. cinfo->min_DCT_scaled_size = 2;
  153461. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153462. cinfo->output_width = (JDIMENSION)
  153463. jdiv_round_up((long) cinfo->image_width, 2L);
  153464. cinfo->output_height = (JDIMENSION)
  153465. jdiv_round_up((long) cinfo->image_height, 2L);
  153466. cinfo->min_DCT_scaled_size = 4;
  153467. } else {
  153468. cinfo->output_width = cinfo->image_width;
  153469. cinfo->output_height = cinfo->image_height;
  153470. cinfo->min_DCT_scaled_size = DCTSIZE;
  153471. }
  153472. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153473. ci++, compptr++) {
  153474. int ssize = cinfo->min_DCT_scaled_size;
  153475. while (ssize < DCTSIZE &&
  153476. (compptr->h_samp_factor * ssize * 2 <=
  153477. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153478. (compptr->v_samp_factor * ssize * 2 <=
  153479. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153480. ssize = ssize * 2;
  153481. }
  153482. compptr->DCT_scaled_size = ssize;
  153483. }
  153484. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153485. ci++, compptr++) {
  153486. compptr->downsampled_width = (JDIMENSION)
  153487. jdiv_round_up((long) cinfo->image_width *
  153488. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153489. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153490. compptr->downsampled_height = (JDIMENSION)
  153491. jdiv_round_up((long) cinfo->image_height *
  153492. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153493. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153494. }
  153495. #else /* !IDCT_SCALING_SUPPORTED */
  153496. cinfo->output_width = cinfo->image_width;
  153497. cinfo->output_height = cinfo->image_height;
  153498. #endif /* IDCT_SCALING_SUPPORTED */
  153499. switch (cinfo->out_color_space) {
  153500. case JCS_GRAYSCALE:
  153501. cinfo->out_color_components = 1;
  153502. break;
  153503. case JCS_RGB:
  153504. #if RGB_PIXELSIZE != 3
  153505. cinfo->out_color_components = RGB_PIXELSIZE;
  153506. break;
  153507. #endif /* else share code with YCbCr */
  153508. case JCS_YCbCr:
  153509. cinfo->out_color_components = 3;
  153510. break;
  153511. case JCS_CMYK:
  153512. case JCS_YCCK:
  153513. cinfo->out_color_components = 4;
  153514. break;
  153515. default: /* else must be same colorspace as in file */
  153516. cinfo->out_color_components = cinfo->num_components;
  153517. break;
  153518. }
  153519. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153520. cinfo->out_color_components);
  153521. if (use_merged_upsample(cinfo))
  153522. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153523. else
  153524. cinfo->rec_outbuf_height = 1;
  153525. }
  153526. LOCAL(void)
  153527. prepare_range_limit_table (j_decompress_ptr cinfo)
  153528. {
  153529. JSAMPLE * table;
  153530. int i;
  153531. table = (JSAMPLE *)
  153532. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153533. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153534. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153535. cinfo->sample_range_limit = table;
  153536. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153537. for (i = 0; i <= MAXJSAMPLE; i++)
  153538. table[i] = (JSAMPLE) i;
  153539. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  153540. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  153541. table[i] = MAXJSAMPLE;
  153542. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  153543. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153544. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  153545. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  153546. }
  153547. LOCAL(void)
  153548. master_selection (j_decompress_ptr cinfo)
  153549. {
  153550. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153551. boolean use_c_buffer;
  153552. long samplesperrow;
  153553. JDIMENSION jd_samplesperrow;
  153554. jpeg_calc_output_dimensions(cinfo);
  153555. prepare_range_limit_table(cinfo);
  153556. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  153557. jd_samplesperrow = (JDIMENSION) samplesperrow;
  153558. if ((long) jd_samplesperrow != samplesperrow)
  153559. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  153560. master->pass_number = 0;
  153561. master->using_merged_upsample = use_merged_upsample(cinfo);
  153562. master->quantizer_1pass = NULL;
  153563. master->quantizer_2pass = NULL;
  153564. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  153565. cinfo->enable_1pass_quant = FALSE;
  153566. cinfo->enable_external_quant = FALSE;
  153567. cinfo->enable_2pass_quant = FALSE;
  153568. }
  153569. if (cinfo->quantize_colors) {
  153570. if (cinfo->raw_data_out)
  153571. ERREXIT(cinfo, JERR_NOTIMPL);
  153572. if (cinfo->out_color_components != 3) {
  153573. cinfo->enable_1pass_quant = TRUE;
  153574. cinfo->enable_external_quant = FALSE;
  153575. cinfo->enable_2pass_quant = FALSE;
  153576. cinfo->colormap = NULL;
  153577. } else if (cinfo->colormap != NULL) {
  153578. cinfo->enable_external_quant = TRUE;
  153579. } else if (cinfo->two_pass_quantize) {
  153580. cinfo->enable_2pass_quant = TRUE;
  153581. } else {
  153582. cinfo->enable_1pass_quant = TRUE;
  153583. }
  153584. if (cinfo->enable_1pass_quant) {
  153585. #ifdef QUANT_1PASS_SUPPORTED
  153586. jinit_1pass_quantizer(cinfo);
  153587. master->quantizer_1pass = cinfo->cquantize;
  153588. #else
  153589. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153590. #endif
  153591. }
  153592. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  153593. #ifdef QUANT_2PASS_SUPPORTED
  153594. jinit_2pass_quantizer(cinfo);
  153595. master->quantizer_2pass = cinfo->cquantize;
  153596. #else
  153597. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153598. #endif
  153599. }
  153600. }
  153601. if (! cinfo->raw_data_out) {
  153602. if (master->using_merged_upsample) {
  153603. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153604. jinit_merged_upsampler(cinfo); /* does color conversion too */
  153605. #else
  153606. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153607. #endif
  153608. } else {
  153609. jinit_color_deconverter(cinfo);
  153610. jinit_upsampler(cinfo);
  153611. }
  153612. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  153613. }
  153614. jinit_inverse_dct(cinfo);
  153615. if (cinfo->arith_code) {
  153616. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  153617. } else {
  153618. if (cinfo->progressive_mode) {
  153619. #ifdef D_PROGRESSIVE_SUPPORTED
  153620. jinit_phuff_decoder(cinfo);
  153621. #else
  153622. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153623. #endif
  153624. } else
  153625. jinit_huff_decoder(cinfo);
  153626. }
  153627. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  153628. jinit_d_coef_controller(cinfo, use_c_buffer);
  153629. if (! cinfo->raw_data_out)
  153630. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  153631. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  153632. (*cinfo->inputctl->start_input_pass) (cinfo);
  153633. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153634. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  153635. cinfo->inputctl->has_multiple_scans) {
  153636. int nscans;
  153637. if (cinfo->progressive_mode) {
  153638. nscans = 2 + 3 * cinfo->num_components;
  153639. } else {
  153640. nscans = cinfo->num_components;
  153641. }
  153642. cinfo->progress->pass_counter = 0L;
  153643. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  153644. cinfo->progress->completed_passes = 0;
  153645. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  153646. master->pass_number++;
  153647. }
  153648. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153649. }
  153650. METHODDEF(void)
  153651. prepare_for_output_pass (j_decompress_ptr cinfo)
  153652. {
  153653. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153654. if (master->pub.is_dummy_pass) {
  153655. #ifdef QUANT_2PASS_SUPPORTED
  153656. master->pub.is_dummy_pass = FALSE;
  153657. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  153658. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  153659. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  153660. #else
  153661. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153662. #endif /* QUANT_2PASS_SUPPORTED */
  153663. } else {
  153664. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  153665. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  153666. cinfo->cquantize = master->quantizer_2pass;
  153667. master->pub.is_dummy_pass = TRUE;
  153668. } else if (cinfo->enable_1pass_quant) {
  153669. cinfo->cquantize = master->quantizer_1pass;
  153670. } else {
  153671. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153672. }
  153673. }
  153674. (*cinfo->idct->start_pass) (cinfo);
  153675. (*cinfo->coef->start_output_pass) (cinfo);
  153676. if (! cinfo->raw_data_out) {
  153677. if (! master->using_merged_upsample)
  153678. (*cinfo->cconvert->start_pass) (cinfo);
  153679. (*cinfo->upsample->start_pass) (cinfo);
  153680. if (cinfo->quantize_colors)
  153681. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  153682. (*cinfo->post->start_pass) (cinfo,
  153683. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  153684. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  153685. }
  153686. }
  153687. if (cinfo->progress != NULL) {
  153688. cinfo->progress->completed_passes = master->pass_number;
  153689. cinfo->progress->total_passes = master->pass_number +
  153690. (master->pub.is_dummy_pass ? 2 : 1);
  153691. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  153692. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  153693. }
  153694. }
  153695. }
  153696. METHODDEF(void)
  153697. finish_output_pass (j_decompress_ptr cinfo)
  153698. {
  153699. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153700. if (cinfo->quantize_colors)
  153701. (*cinfo->cquantize->finish_pass) (cinfo);
  153702. master->pass_number++;
  153703. }
  153704. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153705. GLOBAL(void)
  153706. jpeg_new_colormap (j_decompress_ptr cinfo)
  153707. {
  153708. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153709. if (cinfo->global_state != DSTATE_BUFIMAGE)
  153710. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153711. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  153712. cinfo->colormap != NULL) {
  153713. cinfo->cquantize = master->quantizer_2pass;
  153714. (*cinfo->cquantize->new_color_map) (cinfo);
  153715. master->pub.is_dummy_pass = FALSE; /* just in case */
  153716. } else
  153717. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153718. }
  153719. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153720. GLOBAL(void)
  153721. jinit_master_decompress (j_decompress_ptr cinfo)
  153722. {
  153723. my_master_ptr6 master;
  153724. master = (my_master_ptr6)
  153725. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153726. SIZEOF(my_decomp_master));
  153727. cinfo->master = (struct jpeg_decomp_master *) master;
  153728. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  153729. master->pub.finish_output_pass = finish_output_pass;
  153730. master->pub.is_dummy_pass = FALSE;
  153731. master_selection(cinfo);
  153732. }
  153733. /*** End of inlined file: jdmaster.c ***/
  153734. #undef FIX
  153735. /*** Start of inlined file: jdmerge.c ***/
  153736. #define JPEG_INTERNALS
  153737. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153738. typedef struct {
  153739. struct jpeg_upsampler pub; /* public fields */
  153740. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  153741. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153742. JSAMPARRAY output_buf));
  153743. int * Cr_r_tab; /* => table for Cr to R conversion */
  153744. int * Cb_b_tab; /* => table for Cb to B conversion */
  153745. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  153746. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  153747. JSAMPROW spare_row;
  153748. boolean spare_full; /* T if spare buffer is occupied */
  153749. JDIMENSION out_row_width; /* samples per output row */
  153750. JDIMENSION rows_to_go; /* counts rows remaining in image */
  153751. } my_upsampler;
  153752. typedef my_upsampler * my_upsample_ptr;
  153753. #define SCALEBITS 16 /* speediest right-shift on some machines */
  153754. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  153755. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  153756. LOCAL(void)
  153757. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  153758. {
  153759. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153760. int i;
  153761. INT32 x;
  153762. SHIFT_TEMPS
  153763. upsample->Cr_r_tab = (int *)
  153764. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153765. (MAXJSAMPLE+1) * SIZEOF(int));
  153766. upsample->Cb_b_tab = (int *)
  153767. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153768. (MAXJSAMPLE+1) * SIZEOF(int));
  153769. upsample->Cr_g_tab = (INT32 *)
  153770. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153771. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153772. upsample->Cb_g_tab = (INT32 *)
  153773. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153774. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153775. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  153776. upsample->Cr_r_tab[i] = (int)
  153777. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  153778. upsample->Cb_b_tab[i] = (int)
  153779. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  153780. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  153781. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  153782. }
  153783. }
  153784. METHODDEF(void)
  153785. start_pass_merged_upsample (j_decompress_ptr cinfo)
  153786. {
  153787. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153788. upsample->spare_full = FALSE;
  153789. upsample->rows_to_go = cinfo->output_height;
  153790. }
  153791. METHODDEF(void)
  153792. merged_2v_upsample (j_decompress_ptr cinfo,
  153793. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153794. JDIMENSION in_row_groups_avail,
  153795. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153796. JDIMENSION out_rows_avail)
  153797. {
  153798. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153799. JSAMPROW work_ptrs[2];
  153800. JDIMENSION num_rows; /* number of rows returned to caller */
  153801. if (upsample->spare_full) {
  153802. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  153803. 1, upsample->out_row_width);
  153804. num_rows = 1;
  153805. upsample->spare_full = FALSE;
  153806. } else {
  153807. num_rows = 2;
  153808. if (num_rows > upsample->rows_to_go)
  153809. num_rows = upsample->rows_to_go;
  153810. out_rows_avail -= *out_row_ctr;
  153811. if (num_rows > out_rows_avail)
  153812. num_rows = out_rows_avail;
  153813. work_ptrs[0] = output_buf[*out_row_ctr];
  153814. if (num_rows > 1) {
  153815. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  153816. } else {
  153817. work_ptrs[1] = upsample->spare_row;
  153818. upsample->spare_full = TRUE;
  153819. }
  153820. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  153821. }
  153822. *out_row_ctr += num_rows;
  153823. upsample->rows_to_go -= num_rows;
  153824. if (! upsample->spare_full)
  153825. (*in_row_group_ctr)++;
  153826. }
  153827. METHODDEF(void)
  153828. merged_1v_upsample (j_decompress_ptr cinfo,
  153829. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153830. JDIMENSION in_row_groups_avail,
  153831. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153832. JDIMENSION out_rows_avail)
  153833. {
  153834. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153835. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  153836. output_buf + *out_row_ctr);
  153837. (*out_row_ctr)++;
  153838. (*in_row_group_ctr)++;
  153839. }
  153840. METHODDEF(void)
  153841. h2v1_merged_upsample (j_decompress_ptr cinfo,
  153842. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153843. JSAMPARRAY output_buf)
  153844. {
  153845. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153846. register int y, cred, cgreen, cblue;
  153847. int cb, cr;
  153848. register JSAMPROW outptr;
  153849. JSAMPROW inptr0, inptr1, inptr2;
  153850. JDIMENSION col;
  153851. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153852. int * Crrtab = upsample->Cr_r_tab;
  153853. int * Cbbtab = upsample->Cb_b_tab;
  153854. INT32 * Crgtab = upsample->Cr_g_tab;
  153855. INT32 * Cbgtab = upsample->Cb_g_tab;
  153856. SHIFT_TEMPS
  153857. inptr0 = input_buf[0][in_row_group_ctr];
  153858. inptr1 = input_buf[1][in_row_group_ctr];
  153859. inptr2 = input_buf[2][in_row_group_ctr];
  153860. outptr = output_buf[0];
  153861. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153862. cb = GETJSAMPLE(*inptr1++);
  153863. cr = GETJSAMPLE(*inptr2++);
  153864. cred = Crrtab[cr];
  153865. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153866. cblue = Cbbtab[cb];
  153867. y = GETJSAMPLE(*inptr0++);
  153868. outptr[RGB_RED] = range_limit[y + cred];
  153869. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153870. outptr[RGB_BLUE] = range_limit[y + cblue];
  153871. outptr += RGB_PIXELSIZE;
  153872. y = GETJSAMPLE(*inptr0++);
  153873. outptr[RGB_RED] = range_limit[y + cred];
  153874. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153875. outptr[RGB_BLUE] = range_limit[y + cblue];
  153876. outptr += RGB_PIXELSIZE;
  153877. }
  153878. if (cinfo->output_width & 1) {
  153879. cb = GETJSAMPLE(*inptr1);
  153880. cr = GETJSAMPLE(*inptr2);
  153881. cred = Crrtab[cr];
  153882. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153883. cblue = Cbbtab[cb];
  153884. y = GETJSAMPLE(*inptr0);
  153885. outptr[RGB_RED] = range_limit[y + cred];
  153886. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153887. outptr[RGB_BLUE] = range_limit[y + cblue];
  153888. }
  153889. }
  153890. METHODDEF(void)
  153891. h2v2_merged_upsample (j_decompress_ptr cinfo,
  153892. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153893. JSAMPARRAY output_buf)
  153894. {
  153895. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153896. register int y, cred, cgreen, cblue;
  153897. int cb, cr;
  153898. register JSAMPROW outptr0, outptr1;
  153899. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  153900. JDIMENSION col;
  153901. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153902. int * Crrtab = upsample->Cr_r_tab;
  153903. int * Cbbtab = upsample->Cb_b_tab;
  153904. INT32 * Crgtab = upsample->Cr_g_tab;
  153905. INT32 * Cbgtab = upsample->Cb_g_tab;
  153906. SHIFT_TEMPS
  153907. inptr00 = input_buf[0][in_row_group_ctr*2];
  153908. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  153909. inptr1 = input_buf[1][in_row_group_ctr];
  153910. inptr2 = input_buf[2][in_row_group_ctr];
  153911. outptr0 = output_buf[0];
  153912. outptr1 = output_buf[1];
  153913. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153914. cb = GETJSAMPLE(*inptr1++);
  153915. cr = GETJSAMPLE(*inptr2++);
  153916. cred = Crrtab[cr];
  153917. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153918. cblue = Cbbtab[cb];
  153919. y = GETJSAMPLE(*inptr00++);
  153920. outptr0[RGB_RED] = range_limit[y + cred];
  153921. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153922. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153923. outptr0 += RGB_PIXELSIZE;
  153924. y = GETJSAMPLE(*inptr00++);
  153925. outptr0[RGB_RED] = range_limit[y + cred];
  153926. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153927. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153928. outptr0 += RGB_PIXELSIZE;
  153929. y = GETJSAMPLE(*inptr01++);
  153930. outptr1[RGB_RED] = range_limit[y + cred];
  153931. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153932. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153933. outptr1 += RGB_PIXELSIZE;
  153934. y = GETJSAMPLE(*inptr01++);
  153935. outptr1[RGB_RED] = range_limit[y + cred];
  153936. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153937. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153938. outptr1 += RGB_PIXELSIZE;
  153939. }
  153940. if (cinfo->output_width & 1) {
  153941. cb = GETJSAMPLE(*inptr1);
  153942. cr = GETJSAMPLE(*inptr2);
  153943. cred = Crrtab[cr];
  153944. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153945. cblue = Cbbtab[cb];
  153946. y = GETJSAMPLE(*inptr00);
  153947. outptr0[RGB_RED] = range_limit[y + cred];
  153948. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153949. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153950. y = GETJSAMPLE(*inptr01);
  153951. outptr1[RGB_RED] = range_limit[y + cred];
  153952. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153953. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153954. }
  153955. }
  153956. GLOBAL(void)
  153957. jinit_merged_upsampler (j_decompress_ptr cinfo)
  153958. {
  153959. my_upsample_ptr upsample;
  153960. upsample = (my_upsample_ptr)
  153961. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153962. SIZEOF(my_upsampler));
  153963. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  153964. upsample->pub.start_pass = start_pass_merged_upsample;
  153965. upsample->pub.need_context_rows = FALSE;
  153966. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  153967. if (cinfo->max_v_samp_factor == 2) {
  153968. upsample->pub.upsample = merged_2v_upsample;
  153969. upsample->upmethod = h2v2_merged_upsample;
  153970. upsample->spare_row = (JSAMPROW)
  153971. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153972. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  153973. } else {
  153974. upsample->pub.upsample = merged_1v_upsample;
  153975. upsample->upmethod = h2v1_merged_upsample;
  153976. upsample->spare_row = NULL;
  153977. }
  153978. build_ycc_rgb_table2(cinfo);
  153979. }
  153980. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  153981. /*** End of inlined file: jdmerge.c ***/
  153982. #undef ASSIGN_STATE
  153983. /*** Start of inlined file: jdphuff.c ***/
  153984. #define JPEG_INTERNALS
  153985. #ifdef D_PROGRESSIVE_SUPPORTED
  153986. typedef struct {
  153987. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  153988. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  153989. } savable_state3;
  153990. #ifndef NO_STRUCT_ASSIGN
  153991. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  153992. #else
  153993. #if MAX_COMPS_IN_SCAN == 4
  153994. #define ASSIGN_STATE(dest,src) \
  153995. ((dest).EOBRUN = (src).EOBRUN, \
  153996. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  153997. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  153998. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  153999. (dest).last_dc_val[3] = (src).last_dc_val[3])
  154000. #endif
  154001. #endif
  154002. typedef struct {
  154003. struct jpeg_entropy_decoder pub; /* public fields */
  154004. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  154005. savable_state3 saved; /* Other state at start of MCU */
  154006. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  154007. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  154008. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  154009. } phuff_entropy_decoder;
  154010. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154011. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154012. JBLOCKROW *MCU_data));
  154013. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154014. JBLOCKROW *MCU_data));
  154015. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154016. JBLOCKROW *MCU_data));
  154017. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154018. JBLOCKROW *MCU_data));
  154019. METHODDEF(void)
  154020. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154021. {
  154022. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154023. boolean is_DC_band, bad;
  154024. int ci, coefi, tbl;
  154025. int *coef_bit_ptr;
  154026. jpeg_component_info * compptr;
  154027. is_DC_band = (cinfo->Ss == 0);
  154028. bad = FALSE;
  154029. if (is_DC_band) {
  154030. if (cinfo->Se != 0)
  154031. bad = TRUE;
  154032. } else {
  154033. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154034. bad = TRUE;
  154035. if (cinfo->comps_in_scan != 1)
  154036. bad = TRUE;
  154037. }
  154038. if (cinfo->Ah != 0) {
  154039. if (cinfo->Al != cinfo->Ah-1)
  154040. bad = TRUE;
  154041. }
  154042. if (cinfo->Al > 13) /* need not check for < 0 */
  154043. bad = TRUE;
  154044. if (bad)
  154045. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154046. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154047. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154048. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154049. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154050. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154051. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154052. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154053. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154054. if (cinfo->Ah != expected)
  154055. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154056. coef_bit_ptr[coefi] = cinfo->Al;
  154057. }
  154058. }
  154059. if (cinfo->Ah == 0) {
  154060. if (is_DC_band)
  154061. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154062. else
  154063. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154064. } else {
  154065. if (is_DC_band)
  154066. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154067. else
  154068. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154069. }
  154070. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154071. compptr = cinfo->cur_comp_info[ci];
  154072. if (is_DC_band) {
  154073. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154074. tbl = compptr->dc_tbl_no;
  154075. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154076. & entropy->derived_tbls[tbl]);
  154077. }
  154078. } else {
  154079. tbl = compptr->ac_tbl_no;
  154080. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154081. & entropy->derived_tbls[tbl]);
  154082. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154083. }
  154084. entropy->saved.last_dc_val[ci] = 0;
  154085. }
  154086. entropy->bitstate.bits_left = 0;
  154087. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154088. entropy->pub.insufficient_data = FALSE;
  154089. entropy->saved.EOBRUN = 0;
  154090. entropy->restarts_to_go = cinfo->restart_interval;
  154091. }
  154092. LOCAL(boolean)
  154093. process_restartp (j_decompress_ptr cinfo)
  154094. {
  154095. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154096. int ci;
  154097. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154098. entropy->bitstate.bits_left = 0;
  154099. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154100. return FALSE;
  154101. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154102. entropy->saved.last_dc_val[ci] = 0;
  154103. entropy->saved.EOBRUN = 0;
  154104. entropy->restarts_to_go = cinfo->restart_interval;
  154105. if (cinfo->unread_marker == 0)
  154106. entropy->pub.insufficient_data = FALSE;
  154107. return TRUE;
  154108. }
  154109. METHODDEF(boolean)
  154110. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154111. {
  154112. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154113. int Al = cinfo->Al;
  154114. register int s, r;
  154115. int blkn, ci;
  154116. JBLOCKROW block;
  154117. BITREAD_STATE_VARS;
  154118. savable_state3 state;
  154119. d_derived_tbl * tbl;
  154120. jpeg_component_info * compptr;
  154121. if (cinfo->restart_interval) {
  154122. if (entropy->restarts_to_go == 0)
  154123. if (! process_restartp(cinfo))
  154124. return FALSE;
  154125. }
  154126. if (! entropy->pub.insufficient_data) {
  154127. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154128. ASSIGN_STATE(state, entropy->saved);
  154129. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154130. block = MCU_data[blkn];
  154131. ci = cinfo->MCU_membership[blkn];
  154132. compptr = cinfo->cur_comp_info[ci];
  154133. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154134. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154135. if (s) {
  154136. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154137. r = GET_BITS(s);
  154138. s = HUFF_EXTEND(r, s);
  154139. }
  154140. s += state.last_dc_val[ci];
  154141. state.last_dc_val[ci] = s;
  154142. (*block)[0] = (JCOEF) (s << Al);
  154143. }
  154144. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154145. ASSIGN_STATE(entropy->saved, state);
  154146. }
  154147. entropy->restarts_to_go--;
  154148. return TRUE;
  154149. }
  154150. METHODDEF(boolean)
  154151. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154152. {
  154153. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154154. int Se = cinfo->Se;
  154155. int Al = cinfo->Al;
  154156. register int s, k, r;
  154157. unsigned int EOBRUN;
  154158. JBLOCKROW block;
  154159. BITREAD_STATE_VARS;
  154160. d_derived_tbl * tbl;
  154161. if (cinfo->restart_interval) {
  154162. if (entropy->restarts_to_go == 0)
  154163. if (! process_restartp(cinfo))
  154164. return FALSE;
  154165. }
  154166. if (! entropy->pub.insufficient_data) {
  154167. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154168. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154169. EOBRUN--; /* ...process it now (we do nothing) */
  154170. else {
  154171. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154172. block = MCU_data[0];
  154173. tbl = entropy->ac_derived_tbl;
  154174. for (k = cinfo->Ss; k <= Se; k++) {
  154175. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154176. r = s >> 4;
  154177. s &= 15;
  154178. if (s) {
  154179. k += r;
  154180. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154181. r = GET_BITS(s);
  154182. s = HUFF_EXTEND(r, s);
  154183. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154184. } else {
  154185. if (r == 15) { /* ZRL */
  154186. k += 15; /* skip 15 zeroes in band */
  154187. } else { /* EOBr, run length is 2^r + appended bits */
  154188. EOBRUN = 1 << r;
  154189. if (r) { /* EOBr, r > 0 */
  154190. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154191. r = GET_BITS(r);
  154192. EOBRUN += r;
  154193. }
  154194. EOBRUN--; /* this band is processed at this moment */
  154195. break; /* force end-of-band */
  154196. }
  154197. }
  154198. }
  154199. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154200. }
  154201. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154202. }
  154203. entropy->restarts_to_go--;
  154204. return TRUE;
  154205. }
  154206. METHODDEF(boolean)
  154207. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154208. {
  154209. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154210. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154211. int blkn;
  154212. JBLOCKROW block;
  154213. BITREAD_STATE_VARS;
  154214. if (cinfo->restart_interval) {
  154215. if (entropy->restarts_to_go == 0)
  154216. if (! process_restartp(cinfo))
  154217. return FALSE;
  154218. }
  154219. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154220. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154221. block = MCU_data[blkn];
  154222. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154223. if (GET_BITS(1))
  154224. (*block)[0] |= p1;
  154225. }
  154226. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154227. entropy->restarts_to_go--;
  154228. return TRUE;
  154229. }
  154230. METHODDEF(boolean)
  154231. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154232. {
  154233. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154234. int Se = cinfo->Se;
  154235. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154236. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154237. register int s, k, r;
  154238. unsigned int EOBRUN;
  154239. JBLOCKROW block;
  154240. JCOEFPTR thiscoef;
  154241. BITREAD_STATE_VARS;
  154242. d_derived_tbl * tbl;
  154243. int num_newnz;
  154244. int newnz_pos[DCTSIZE2];
  154245. if (cinfo->restart_interval) {
  154246. if (entropy->restarts_to_go == 0)
  154247. if (! process_restartp(cinfo))
  154248. return FALSE;
  154249. }
  154250. if (! entropy->pub.insufficient_data) {
  154251. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154252. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154253. block = MCU_data[0];
  154254. tbl = entropy->ac_derived_tbl;
  154255. num_newnz = 0;
  154256. k = cinfo->Ss;
  154257. if (EOBRUN == 0) {
  154258. for (; k <= Se; k++) {
  154259. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154260. r = s >> 4;
  154261. s &= 15;
  154262. if (s) {
  154263. if (s != 1) /* size of new coef should always be 1 */
  154264. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154265. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154266. if (GET_BITS(1))
  154267. s = p1; /* newly nonzero coef is positive */
  154268. else
  154269. s = m1; /* newly nonzero coef is negative */
  154270. } else {
  154271. if (r != 15) {
  154272. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154273. if (r) {
  154274. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154275. r = GET_BITS(r);
  154276. EOBRUN += r;
  154277. }
  154278. break; /* rest of block is handled by EOB logic */
  154279. }
  154280. }
  154281. do {
  154282. thiscoef = *block + jpeg_natural_order[k];
  154283. if (*thiscoef != 0) {
  154284. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154285. if (GET_BITS(1)) {
  154286. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154287. if (*thiscoef >= 0)
  154288. *thiscoef += p1;
  154289. else
  154290. *thiscoef += m1;
  154291. }
  154292. }
  154293. } else {
  154294. if (--r < 0)
  154295. break; /* reached target zero coefficient */
  154296. }
  154297. k++;
  154298. } while (k <= Se);
  154299. if (s) {
  154300. int pos = jpeg_natural_order[k];
  154301. (*block)[pos] = (JCOEF) s;
  154302. newnz_pos[num_newnz++] = pos;
  154303. }
  154304. }
  154305. }
  154306. if (EOBRUN > 0) {
  154307. for (; k <= Se; k++) {
  154308. thiscoef = *block + jpeg_natural_order[k];
  154309. if (*thiscoef != 0) {
  154310. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154311. if (GET_BITS(1)) {
  154312. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154313. if (*thiscoef >= 0)
  154314. *thiscoef += p1;
  154315. else
  154316. *thiscoef += m1;
  154317. }
  154318. }
  154319. }
  154320. }
  154321. EOBRUN--;
  154322. }
  154323. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154324. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154325. }
  154326. entropy->restarts_to_go--;
  154327. return TRUE;
  154328. undoit:
  154329. while (num_newnz > 0)
  154330. (*block)[newnz_pos[--num_newnz]] = 0;
  154331. return FALSE;
  154332. }
  154333. GLOBAL(void)
  154334. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154335. {
  154336. phuff_entropy_ptr2 entropy;
  154337. int *coef_bit_ptr;
  154338. int ci, i;
  154339. entropy = (phuff_entropy_ptr2)
  154340. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154341. SIZEOF(phuff_entropy_decoder));
  154342. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154343. entropy->pub.start_pass = start_pass_phuff_decoder;
  154344. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154345. entropy->derived_tbls[i] = NULL;
  154346. }
  154347. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154348. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154349. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154350. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154351. for (ci = 0; ci < cinfo->num_components; ci++)
  154352. for (i = 0; i < DCTSIZE2; i++)
  154353. *coef_bit_ptr++ = -1;
  154354. }
  154355. #endif /* D_PROGRESSIVE_SUPPORTED */
  154356. /*** End of inlined file: jdphuff.c ***/
  154357. /*** Start of inlined file: jdpostct.c ***/
  154358. #define JPEG_INTERNALS
  154359. typedef struct {
  154360. struct jpeg_d_post_controller pub; /* public fields */
  154361. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154362. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154363. JDIMENSION strip_height; /* buffer size in rows */
  154364. JDIMENSION starting_row; /* row # of first row in current strip */
  154365. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154366. } my_post_controller;
  154367. typedef my_post_controller * my_post_ptr;
  154368. METHODDEF(void) post_process_1pass
  154369. JPP((j_decompress_ptr cinfo,
  154370. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154371. JDIMENSION in_row_groups_avail,
  154372. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154373. JDIMENSION out_rows_avail));
  154374. #ifdef QUANT_2PASS_SUPPORTED
  154375. METHODDEF(void) post_process_prepass
  154376. JPP((j_decompress_ptr cinfo,
  154377. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154378. JDIMENSION in_row_groups_avail,
  154379. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154380. JDIMENSION out_rows_avail));
  154381. METHODDEF(void) post_process_2pass
  154382. JPP((j_decompress_ptr cinfo,
  154383. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154384. JDIMENSION in_row_groups_avail,
  154385. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154386. JDIMENSION out_rows_avail));
  154387. #endif
  154388. METHODDEF(void)
  154389. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154390. {
  154391. my_post_ptr post = (my_post_ptr) cinfo->post;
  154392. switch (pass_mode) {
  154393. case JBUF_PASS_THRU:
  154394. if (cinfo->quantize_colors) {
  154395. post->pub.post_process_data = post_process_1pass;
  154396. if (post->buffer == NULL) {
  154397. post->buffer = (*cinfo->mem->access_virt_sarray)
  154398. ((j_common_ptr) cinfo, post->whole_image,
  154399. (JDIMENSION) 0, post->strip_height, TRUE);
  154400. }
  154401. } else {
  154402. post->pub.post_process_data = cinfo->upsample->upsample;
  154403. }
  154404. break;
  154405. #ifdef QUANT_2PASS_SUPPORTED
  154406. case JBUF_SAVE_AND_PASS:
  154407. if (post->whole_image == NULL)
  154408. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154409. post->pub.post_process_data = post_process_prepass;
  154410. break;
  154411. case JBUF_CRANK_DEST:
  154412. if (post->whole_image == NULL)
  154413. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154414. post->pub.post_process_data = post_process_2pass;
  154415. break;
  154416. #endif /* QUANT_2PASS_SUPPORTED */
  154417. default:
  154418. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154419. break;
  154420. }
  154421. post->starting_row = post->next_row = 0;
  154422. }
  154423. METHODDEF(void)
  154424. post_process_1pass (j_decompress_ptr cinfo,
  154425. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154426. JDIMENSION in_row_groups_avail,
  154427. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154428. JDIMENSION out_rows_avail)
  154429. {
  154430. my_post_ptr post = (my_post_ptr) cinfo->post;
  154431. JDIMENSION num_rows, max_rows;
  154432. max_rows = out_rows_avail - *out_row_ctr;
  154433. if (max_rows > post->strip_height)
  154434. max_rows = post->strip_height;
  154435. num_rows = 0;
  154436. (*cinfo->upsample->upsample) (cinfo,
  154437. input_buf, in_row_group_ctr, in_row_groups_avail,
  154438. post->buffer, &num_rows, max_rows);
  154439. (*cinfo->cquantize->color_quantize) (cinfo,
  154440. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154441. *out_row_ctr += num_rows;
  154442. }
  154443. #ifdef QUANT_2PASS_SUPPORTED
  154444. METHODDEF(void)
  154445. post_process_prepass (j_decompress_ptr cinfo,
  154446. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154447. JDIMENSION in_row_groups_avail,
  154448. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154449. JDIMENSION out_rows_avail)
  154450. {
  154451. my_post_ptr post = (my_post_ptr) cinfo->post;
  154452. JDIMENSION old_next_row, num_rows;
  154453. if (post->next_row == 0) {
  154454. post->buffer = (*cinfo->mem->access_virt_sarray)
  154455. ((j_common_ptr) cinfo, post->whole_image,
  154456. post->starting_row, post->strip_height, TRUE);
  154457. }
  154458. old_next_row = post->next_row;
  154459. (*cinfo->upsample->upsample) (cinfo,
  154460. input_buf, in_row_group_ctr, in_row_groups_avail,
  154461. post->buffer, &post->next_row, post->strip_height);
  154462. if (post->next_row > old_next_row) {
  154463. num_rows = post->next_row - old_next_row;
  154464. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154465. (JSAMPARRAY) NULL, (int) num_rows);
  154466. *out_row_ctr += num_rows;
  154467. }
  154468. if (post->next_row >= post->strip_height) {
  154469. post->starting_row += post->strip_height;
  154470. post->next_row = 0;
  154471. }
  154472. }
  154473. METHODDEF(void)
  154474. post_process_2pass (j_decompress_ptr cinfo,
  154475. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154476. JDIMENSION in_row_groups_avail,
  154477. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154478. JDIMENSION out_rows_avail)
  154479. {
  154480. my_post_ptr post = (my_post_ptr) cinfo->post;
  154481. JDIMENSION num_rows, max_rows;
  154482. if (post->next_row == 0) {
  154483. post->buffer = (*cinfo->mem->access_virt_sarray)
  154484. ((j_common_ptr) cinfo, post->whole_image,
  154485. post->starting_row, post->strip_height, FALSE);
  154486. }
  154487. num_rows = post->strip_height - post->next_row; /* available in strip */
  154488. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154489. if (num_rows > max_rows)
  154490. num_rows = max_rows;
  154491. max_rows = cinfo->output_height - post->starting_row;
  154492. if (num_rows > max_rows)
  154493. num_rows = max_rows;
  154494. (*cinfo->cquantize->color_quantize) (cinfo,
  154495. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154496. (int) num_rows);
  154497. *out_row_ctr += num_rows;
  154498. post->next_row += num_rows;
  154499. if (post->next_row >= post->strip_height) {
  154500. post->starting_row += post->strip_height;
  154501. post->next_row = 0;
  154502. }
  154503. }
  154504. #endif /* QUANT_2PASS_SUPPORTED */
  154505. GLOBAL(void)
  154506. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154507. {
  154508. my_post_ptr post;
  154509. post = (my_post_ptr)
  154510. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154511. SIZEOF(my_post_controller));
  154512. cinfo->post = (struct jpeg_d_post_controller *) post;
  154513. post->pub.start_pass = start_pass_dpost;
  154514. post->whole_image = NULL; /* flag for no virtual arrays */
  154515. post->buffer = NULL; /* flag for no strip buffer */
  154516. if (cinfo->quantize_colors) {
  154517. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154518. if (need_full_buffer) {
  154519. #ifdef QUANT_2PASS_SUPPORTED
  154520. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154521. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154522. cinfo->output_width * cinfo->out_color_components,
  154523. (JDIMENSION) jround_up((long) cinfo->output_height,
  154524. (long) post->strip_height),
  154525. post->strip_height);
  154526. #else
  154527. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154528. #endif /* QUANT_2PASS_SUPPORTED */
  154529. } else {
  154530. post->buffer = (*cinfo->mem->alloc_sarray)
  154531. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154532. cinfo->output_width * cinfo->out_color_components,
  154533. post->strip_height);
  154534. }
  154535. }
  154536. }
  154537. /*** End of inlined file: jdpostct.c ***/
  154538. #undef FIX
  154539. /*** Start of inlined file: jdsample.c ***/
  154540. #define JPEG_INTERNALS
  154541. typedef JMETHOD(void, upsample1_ptr,
  154542. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154543. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  154544. typedef struct {
  154545. struct jpeg_upsampler pub; /* public fields */
  154546. JSAMPARRAY color_buf[MAX_COMPONENTS];
  154547. upsample1_ptr methods[MAX_COMPONENTS];
  154548. int next_row_out; /* counts rows emitted from color_buf */
  154549. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154550. int rowgroup_height[MAX_COMPONENTS];
  154551. UINT8 h_expand[MAX_COMPONENTS];
  154552. UINT8 v_expand[MAX_COMPONENTS];
  154553. } my_upsampler2;
  154554. typedef my_upsampler2 * my_upsample_ptr2;
  154555. METHODDEF(void)
  154556. start_pass_upsample (j_decompress_ptr cinfo)
  154557. {
  154558. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154559. upsample->next_row_out = cinfo->max_v_samp_factor;
  154560. upsample->rows_to_go = cinfo->output_height;
  154561. }
  154562. METHODDEF(void)
  154563. sep_upsample (j_decompress_ptr cinfo,
  154564. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154565. JDIMENSION in_row_groups_avail,
  154566. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154567. JDIMENSION out_rows_avail)
  154568. {
  154569. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154570. int ci;
  154571. jpeg_component_info * compptr;
  154572. JDIMENSION num_rows;
  154573. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  154574. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154575. ci++, compptr++) {
  154576. (*upsample->methods[ci]) (cinfo, compptr,
  154577. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  154578. upsample->color_buf + ci);
  154579. }
  154580. upsample->next_row_out = 0;
  154581. }
  154582. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  154583. if (num_rows > upsample->rows_to_go)
  154584. num_rows = upsample->rows_to_go;
  154585. out_rows_avail -= *out_row_ctr;
  154586. if (num_rows > out_rows_avail)
  154587. num_rows = out_rows_avail;
  154588. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  154589. (JDIMENSION) upsample->next_row_out,
  154590. output_buf + *out_row_ctr,
  154591. (int) num_rows);
  154592. *out_row_ctr += num_rows;
  154593. upsample->rows_to_go -= num_rows;
  154594. upsample->next_row_out += num_rows;
  154595. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  154596. (*in_row_group_ctr)++;
  154597. }
  154598. METHODDEF(void)
  154599. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154600. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154601. {
  154602. *output_data_ptr = input_data;
  154603. }
  154604. METHODDEF(void)
  154605. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154606. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154607. {
  154608. *output_data_ptr = NULL; /* safety check */
  154609. }
  154610. METHODDEF(void)
  154611. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154612. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154613. {
  154614. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154615. JSAMPARRAY output_data = *output_data_ptr;
  154616. register JSAMPROW inptr, outptr;
  154617. register JSAMPLE invalue;
  154618. register int h;
  154619. JSAMPROW outend;
  154620. int h_expand, v_expand;
  154621. int inrow, outrow;
  154622. h_expand = upsample->h_expand[compptr->component_index];
  154623. v_expand = upsample->v_expand[compptr->component_index];
  154624. inrow = outrow = 0;
  154625. while (outrow < cinfo->max_v_samp_factor) {
  154626. inptr = input_data[inrow];
  154627. outptr = output_data[outrow];
  154628. outend = outptr + cinfo->output_width;
  154629. while (outptr < outend) {
  154630. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154631. for (h = h_expand; h > 0; h--) {
  154632. *outptr++ = invalue;
  154633. }
  154634. }
  154635. if (v_expand > 1) {
  154636. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154637. v_expand-1, cinfo->output_width);
  154638. }
  154639. inrow++;
  154640. outrow += v_expand;
  154641. }
  154642. }
  154643. METHODDEF(void)
  154644. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154645. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154646. {
  154647. JSAMPARRAY output_data = *output_data_ptr;
  154648. register JSAMPROW inptr, outptr;
  154649. register JSAMPLE invalue;
  154650. JSAMPROW outend;
  154651. int inrow;
  154652. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154653. inptr = input_data[inrow];
  154654. outptr = output_data[inrow];
  154655. outend = outptr + cinfo->output_width;
  154656. while (outptr < outend) {
  154657. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154658. *outptr++ = invalue;
  154659. *outptr++ = invalue;
  154660. }
  154661. }
  154662. }
  154663. METHODDEF(void)
  154664. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154665. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154666. {
  154667. JSAMPARRAY output_data = *output_data_ptr;
  154668. register JSAMPROW inptr, outptr;
  154669. register JSAMPLE invalue;
  154670. JSAMPROW outend;
  154671. int inrow, outrow;
  154672. inrow = outrow = 0;
  154673. while (outrow < cinfo->max_v_samp_factor) {
  154674. inptr = input_data[inrow];
  154675. outptr = output_data[outrow];
  154676. outend = outptr + cinfo->output_width;
  154677. while (outptr < outend) {
  154678. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154679. *outptr++ = invalue;
  154680. *outptr++ = invalue;
  154681. }
  154682. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154683. 1, cinfo->output_width);
  154684. inrow++;
  154685. outrow += 2;
  154686. }
  154687. }
  154688. METHODDEF(void)
  154689. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154690. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154691. {
  154692. JSAMPARRAY output_data = *output_data_ptr;
  154693. register JSAMPROW inptr, outptr;
  154694. register int invalue;
  154695. register JDIMENSION colctr;
  154696. int inrow;
  154697. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154698. inptr = input_data[inrow];
  154699. outptr = output_data[inrow];
  154700. invalue = GETJSAMPLE(*inptr++);
  154701. *outptr++ = (JSAMPLE) invalue;
  154702. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  154703. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154704. invalue = GETJSAMPLE(*inptr++) * 3;
  154705. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  154706. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  154707. }
  154708. invalue = GETJSAMPLE(*inptr);
  154709. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  154710. *outptr++ = (JSAMPLE) invalue;
  154711. }
  154712. }
  154713. METHODDEF(void)
  154714. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154715. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154716. {
  154717. JSAMPARRAY output_data = *output_data_ptr;
  154718. register JSAMPROW inptr0, inptr1, outptr;
  154719. #if BITS_IN_JSAMPLE == 8
  154720. register int thiscolsum, lastcolsum, nextcolsum;
  154721. #else
  154722. register INT32 thiscolsum, lastcolsum, nextcolsum;
  154723. #endif
  154724. register JDIMENSION colctr;
  154725. int inrow, outrow, v;
  154726. inrow = outrow = 0;
  154727. while (outrow < cinfo->max_v_samp_factor) {
  154728. for (v = 0; v < 2; v++) {
  154729. inptr0 = input_data[inrow];
  154730. if (v == 0) /* next nearest is row above */
  154731. inptr1 = input_data[inrow-1];
  154732. else /* next nearest is row below */
  154733. inptr1 = input_data[inrow+1];
  154734. outptr = output_data[outrow++];
  154735. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154736. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154737. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  154738. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154739. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154740. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154741. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154742. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154743. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154744. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154745. }
  154746. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154747. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  154748. }
  154749. inrow++;
  154750. }
  154751. }
  154752. GLOBAL(void)
  154753. jinit_upsampler (j_decompress_ptr cinfo)
  154754. {
  154755. my_upsample_ptr2 upsample;
  154756. int ci;
  154757. jpeg_component_info * compptr;
  154758. boolean need_buffer, do_fancy;
  154759. int h_in_group, v_in_group, h_out_group, v_out_group;
  154760. upsample = (my_upsample_ptr2)
  154761. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154762. SIZEOF(my_upsampler2));
  154763. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154764. upsample->pub.start_pass = start_pass_upsample;
  154765. upsample->pub.upsample = sep_upsample;
  154766. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  154767. if (cinfo->CCIR601_sampling) /* this isn't supported */
  154768. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  154769. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  154770. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154771. ci++, compptr++) {
  154772. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  154773. cinfo->min_DCT_scaled_size;
  154774. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  154775. cinfo->min_DCT_scaled_size;
  154776. h_out_group = cinfo->max_h_samp_factor;
  154777. v_out_group = cinfo->max_v_samp_factor;
  154778. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  154779. need_buffer = TRUE;
  154780. if (! compptr->component_needed) {
  154781. upsample->methods[ci] = noop_upsample;
  154782. need_buffer = FALSE;
  154783. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  154784. upsample->methods[ci] = fullsize_upsample;
  154785. need_buffer = FALSE;
  154786. } else if (h_in_group * 2 == h_out_group &&
  154787. v_in_group == v_out_group) {
  154788. if (do_fancy && compptr->downsampled_width > 2)
  154789. upsample->methods[ci] = h2v1_fancy_upsample;
  154790. else
  154791. upsample->methods[ci] = h2v1_upsample;
  154792. } else if (h_in_group * 2 == h_out_group &&
  154793. v_in_group * 2 == v_out_group) {
  154794. if (do_fancy && compptr->downsampled_width > 2) {
  154795. upsample->methods[ci] = h2v2_fancy_upsample;
  154796. upsample->pub.need_context_rows = TRUE;
  154797. } else
  154798. upsample->methods[ci] = h2v2_upsample;
  154799. } else if ((h_out_group % h_in_group) == 0 &&
  154800. (v_out_group % v_in_group) == 0) {
  154801. upsample->methods[ci] = int_upsample;
  154802. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  154803. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  154804. } else
  154805. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  154806. if (need_buffer) {
  154807. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  154808. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154809. (JDIMENSION) jround_up((long) cinfo->output_width,
  154810. (long) cinfo->max_h_samp_factor),
  154811. (JDIMENSION) cinfo->max_v_samp_factor);
  154812. }
  154813. }
  154814. }
  154815. /*** End of inlined file: jdsample.c ***/
  154816. /*** Start of inlined file: jdtrans.c ***/
  154817. #define JPEG_INTERNALS
  154818. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  154819. GLOBAL(jvirt_barray_ptr *)
  154820. jpeg_read_coefficients (j_decompress_ptr cinfo)
  154821. {
  154822. if (cinfo->global_state == DSTATE_READY) {
  154823. transdecode_master_selection(cinfo);
  154824. cinfo->global_state = DSTATE_RDCOEFS;
  154825. }
  154826. if (cinfo->global_state == DSTATE_RDCOEFS) {
  154827. for (;;) {
  154828. int retcode;
  154829. if (cinfo->progress != NULL)
  154830. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  154831. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  154832. if (retcode == JPEG_SUSPENDED)
  154833. return NULL;
  154834. if (retcode == JPEG_REACHED_EOI)
  154835. break;
  154836. if (cinfo->progress != NULL &&
  154837. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  154838. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  154839. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  154840. }
  154841. }
  154842. }
  154843. cinfo->global_state = DSTATE_STOPPING;
  154844. }
  154845. if ((cinfo->global_state == DSTATE_STOPPING ||
  154846. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  154847. return cinfo->coef->coef_arrays;
  154848. }
  154849. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154850. return NULL; /* keep compiler happy */
  154851. }
  154852. LOCAL(void)
  154853. transdecode_master_selection (j_decompress_ptr cinfo)
  154854. {
  154855. cinfo->buffered_image = TRUE;
  154856. if (cinfo->arith_code) {
  154857. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154858. } else {
  154859. if (cinfo->progressive_mode) {
  154860. #ifdef D_PROGRESSIVE_SUPPORTED
  154861. jinit_phuff_decoder(cinfo);
  154862. #else
  154863. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154864. #endif
  154865. } else
  154866. jinit_huff_decoder(cinfo);
  154867. }
  154868. jinit_d_coef_controller(cinfo, TRUE);
  154869. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154870. (*cinfo->inputctl->start_input_pass) (cinfo);
  154871. if (cinfo->progress != NULL) {
  154872. int nscans;
  154873. if (cinfo->progressive_mode) {
  154874. nscans = 2 + 3 * cinfo->num_components;
  154875. } else if (cinfo->inputctl->has_multiple_scans) {
  154876. nscans = cinfo->num_components;
  154877. } else {
  154878. nscans = 1;
  154879. }
  154880. cinfo->progress->pass_counter = 0L;
  154881. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154882. cinfo->progress->completed_passes = 0;
  154883. cinfo->progress->total_passes = 1;
  154884. }
  154885. }
  154886. /*** End of inlined file: jdtrans.c ***/
  154887. /*** Start of inlined file: jfdctflt.c ***/
  154888. #define JPEG_INTERNALS
  154889. #ifdef DCT_FLOAT_SUPPORTED
  154890. #if DCTSIZE != 8
  154891. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154892. #endif
  154893. GLOBAL(void)
  154894. jpeg_fdct_float (FAST_FLOAT * data)
  154895. {
  154896. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154897. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  154898. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  154899. FAST_FLOAT *dataptr;
  154900. int ctr;
  154901. dataptr = data;
  154902. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154903. tmp0 = dataptr[0] + dataptr[7];
  154904. tmp7 = dataptr[0] - dataptr[7];
  154905. tmp1 = dataptr[1] + dataptr[6];
  154906. tmp6 = dataptr[1] - dataptr[6];
  154907. tmp2 = dataptr[2] + dataptr[5];
  154908. tmp5 = dataptr[2] - dataptr[5];
  154909. tmp3 = dataptr[3] + dataptr[4];
  154910. tmp4 = dataptr[3] - dataptr[4];
  154911. tmp10 = tmp0 + tmp3; /* phase 2 */
  154912. tmp13 = tmp0 - tmp3;
  154913. tmp11 = tmp1 + tmp2;
  154914. tmp12 = tmp1 - tmp2;
  154915. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  154916. dataptr[4] = tmp10 - tmp11;
  154917. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154918. dataptr[2] = tmp13 + z1; /* phase 5 */
  154919. dataptr[6] = tmp13 - z1;
  154920. tmp10 = tmp4 + tmp5; /* phase 2 */
  154921. tmp11 = tmp5 + tmp6;
  154922. tmp12 = tmp6 + tmp7;
  154923. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154924. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154925. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154926. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154927. z11 = tmp7 + z3; /* phase 5 */
  154928. z13 = tmp7 - z3;
  154929. dataptr[5] = z13 + z2; /* phase 6 */
  154930. dataptr[3] = z13 - z2;
  154931. dataptr[1] = z11 + z4;
  154932. dataptr[7] = z11 - z4;
  154933. dataptr += DCTSIZE; /* advance pointer to next row */
  154934. }
  154935. dataptr = data;
  154936. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154937. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  154938. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  154939. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  154940. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  154941. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  154942. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  154943. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  154944. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  154945. tmp10 = tmp0 + tmp3; /* phase 2 */
  154946. tmp13 = tmp0 - tmp3;
  154947. tmp11 = tmp1 + tmp2;
  154948. tmp12 = tmp1 - tmp2;
  154949. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  154950. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  154951. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154952. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  154953. dataptr[DCTSIZE*6] = tmp13 - z1;
  154954. tmp10 = tmp4 + tmp5; /* phase 2 */
  154955. tmp11 = tmp5 + tmp6;
  154956. tmp12 = tmp6 + tmp7;
  154957. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154958. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154959. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154960. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154961. z11 = tmp7 + z3; /* phase 5 */
  154962. z13 = tmp7 - z3;
  154963. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  154964. dataptr[DCTSIZE*3] = z13 - z2;
  154965. dataptr[DCTSIZE*1] = z11 + z4;
  154966. dataptr[DCTSIZE*7] = z11 - z4;
  154967. dataptr++; /* advance pointer to next column */
  154968. }
  154969. }
  154970. #endif /* DCT_FLOAT_SUPPORTED */
  154971. /*** End of inlined file: jfdctflt.c ***/
  154972. /*** Start of inlined file: jfdctint.c ***/
  154973. #define JPEG_INTERNALS
  154974. #ifdef DCT_ISLOW_SUPPORTED
  154975. #if DCTSIZE != 8
  154976. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154977. #endif
  154978. #if BITS_IN_JSAMPLE == 8
  154979. #define CONST_BITS 13
  154980. #define PASS1_BITS 2
  154981. #else
  154982. #define CONST_BITS 13
  154983. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  154984. #endif
  154985. #if CONST_BITS == 13
  154986. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  154987. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  154988. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  154989. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  154990. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  154991. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  154992. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  154993. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  154994. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  154995. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  154996. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  154997. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  154998. #else
  154999. #define FIX_0_298631336 FIX(0.298631336)
  155000. #define FIX_0_390180644 FIX(0.390180644)
  155001. #define FIX_0_541196100 FIX(0.541196100)
  155002. #define FIX_0_765366865 FIX(0.765366865)
  155003. #define FIX_0_899976223 FIX(0.899976223)
  155004. #define FIX_1_175875602 FIX(1.175875602)
  155005. #define FIX_1_501321110 FIX(1.501321110)
  155006. #define FIX_1_847759065 FIX(1.847759065)
  155007. #define FIX_1_961570560 FIX(1.961570560)
  155008. #define FIX_2_053119869 FIX(2.053119869)
  155009. #define FIX_2_562915447 FIX(2.562915447)
  155010. #define FIX_3_072711026 FIX(3.072711026)
  155011. #endif
  155012. #if BITS_IN_JSAMPLE == 8
  155013. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155014. #else
  155015. #define MULTIPLY(var,const) ((var) * (const))
  155016. #endif
  155017. GLOBAL(void)
  155018. jpeg_fdct_islow (DCTELEM * data)
  155019. {
  155020. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155021. INT32 tmp10, tmp11, tmp12, tmp13;
  155022. INT32 z1, z2, z3, z4, z5;
  155023. DCTELEM *dataptr;
  155024. int ctr;
  155025. SHIFT_TEMPS
  155026. dataptr = data;
  155027. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155028. tmp0 = dataptr[0] + dataptr[7];
  155029. tmp7 = dataptr[0] - dataptr[7];
  155030. tmp1 = dataptr[1] + dataptr[6];
  155031. tmp6 = dataptr[1] - dataptr[6];
  155032. tmp2 = dataptr[2] + dataptr[5];
  155033. tmp5 = dataptr[2] - dataptr[5];
  155034. tmp3 = dataptr[3] + dataptr[4];
  155035. tmp4 = dataptr[3] - dataptr[4];
  155036. tmp10 = tmp0 + tmp3;
  155037. tmp13 = tmp0 - tmp3;
  155038. tmp11 = tmp1 + tmp2;
  155039. tmp12 = tmp1 - tmp2;
  155040. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155041. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155042. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155043. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155044. CONST_BITS-PASS1_BITS);
  155045. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155046. CONST_BITS-PASS1_BITS);
  155047. z1 = tmp4 + tmp7;
  155048. z2 = tmp5 + tmp6;
  155049. z3 = tmp4 + tmp6;
  155050. z4 = tmp5 + tmp7;
  155051. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155052. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155053. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155054. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155055. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155056. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155057. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155058. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155059. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155060. z3 += z5;
  155061. z4 += z5;
  155062. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155063. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155064. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155065. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155066. dataptr += DCTSIZE; /* advance pointer to next row */
  155067. }
  155068. dataptr = data;
  155069. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155070. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155071. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155072. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155073. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155074. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155075. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155076. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155077. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155078. tmp10 = tmp0 + tmp3;
  155079. tmp13 = tmp0 - tmp3;
  155080. tmp11 = tmp1 + tmp2;
  155081. tmp12 = tmp1 - tmp2;
  155082. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155083. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155084. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155085. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155086. CONST_BITS+PASS1_BITS);
  155087. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155088. CONST_BITS+PASS1_BITS);
  155089. z1 = tmp4 + tmp7;
  155090. z2 = tmp5 + tmp6;
  155091. z3 = tmp4 + tmp6;
  155092. z4 = tmp5 + tmp7;
  155093. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155094. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155095. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155096. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155097. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155098. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155099. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155100. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155101. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155102. z3 += z5;
  155103. z4 += z5;
  155104. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155105. CONST_BITS+PASS1_BITS);
  155106. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155107. CONST_BITS+PASS1_BITS);
  155108. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155109. CONST_BITS+PASS1_BITS);
  155110. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155111. CONST_BITS+PASS1_BITS);
  155112. dataptr++; /* advance pointer to next column */
  155113. }
  155114. }
  155115. #endif /* DCT_ISLOW_SUPPORTED */
  155116. /*** End of inlined file: jfdctint.c ***/
  155117. #undef CONST_BITS
  155118. #undef MULTIPLY
  155119. #undef FIX_0_541196100
  155120. /*** Start of inlined file: jfdctfst.c ***/
  155121. #define JPEG_INTERNALS
  155122. #ifdef DCT_IFAST_SUPPORTED
  155123. #if DCTSIZE != 8
  155124. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155125. #endif
  155126. #define CONST_BITS 8
  155127. #if CONST_BITS == 8
  155128. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155129. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155130. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155131. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155132. #else
  155133. #define FIX_0_382683433 FIX(0.382683433)
  155134. #define FIX_0_541196100 FIX(0.541196100)
  155135. #define FIX_0_707106781 FIX(0.707106781)
  155136. #define FIX_1_306562965 FIX(1.306562965)
  155137. #endif
  155138. #ifndef USE_ACCURATE_ROUNDING
  155139. #undef DESCALE
  155140. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155141. #endif
  155142. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155143. GLOBAL(void)
  155144. jpeg_fdct_ifast (DCTELEM * data)
  155145. {
  155146. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155147. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155148. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155149. DCTELEM *dataptr;
  155150. int ctr;
  155151. SHIFT_TEMPS
  155152. dataptr = data;
  155153. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155154. tmp0 = dataptr[0] + dataptr[7];
  155155. tmp7 = dataptr[0] - dataptr[7];
  155156. tmp1 = dataptr[1] + dataptr[6];
  155157. tmp6 = dataptr[1] - dataptr[6];
  155158. tmp2 = dataptr[2] + dataptr[5];
  155159. tmp5 = dataptr[2] - dataptr[5];
  155160. tmp3 = dataptr[3] + dataptr[4];
  155161. tmp4 = dataptr[3] - dataptr[4];
  155162. tmp10 = tmp0 + tmp3; /* phase 2 */
  155163. tmp13 = tmp0 - tmp3;
  155164. tmp11 = tmp1 + tmp2;
  155165. tmp12 = tmp1 - tmp2;
  155166. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155167. dataptr[4] = tmp10 - tmp11;
  155168. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155169. dataptr[2] = tmp13 + z1; /* phase 5 */
  155170. dataptr[6] = tmp13 - z1;
  155171. tmp10 = tmp4 + tmp5; /* phase 2 */
  155172. tmp11 = tmp5 + tmp6;
  155173. tmp12 = tmp6 + tmp7;
  155174. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155175. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155176. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155177. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155178. z11 = tmp7 + z3; /* phase 5 */
  155179. z13 = tmp7 - z3;
  155180. dataptr[5] = z13 + z2; /* phase 6 */
  155181. dataptr[3] = z13 - z2;
  155182. dataptr[1] = z11 + z4;
  155183. dataptr[7] = z11 - z4;
  155184. dataptr += DCTSIZE; /* advance pointer to next row */
  155185. }
  155186. dataptr = data;
  155187. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155188. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155189. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155190. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155191. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155192. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155193. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155194. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155195. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155196. tmp10 = tmp0 + tmp3; /* phase 2 */
  155197. tmp13 = tmp0 - tmp3;
  155198. tmp11 = tmp1 + tmp2;
  155199. tmp12 = tmp1 - tmp2;
  155200. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155201. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155202. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155203. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155204. dataptr[DCTSIZE*6] = tmp13 - z1;
  155205. tmp10 = tmp4 + tmp5; /* phase 2 */
  155206. tmp11 = tmp5 + tmp6;
  155207. tmp12 = tmp6 + tmp7;
  155208. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155209. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155210. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155211. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155212. z11 = tmp7 + z3; /* phase 5 */
  155213. z13 = tmp7 - z3;
  155214. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155215. dataptr[DCTSIZE*3] = z13 - z2;
  155216. dataptr[DCTSIZE*1] = z11 + z4;
  155217. dataptr[DCTSIZE*7] = z11 - z4;
  155218. dataptr++; /* advance pointer to next column */
  155219. }
  155220. }
  155221. #endif /* DCT_IFAST_SUPPORTED */
  155222. /*** End of inlined file: jfdctfst.c ***/
  155223. #undef FIX_0_541196100
  155224. /*** Start of inlined file: jidctflt.c ***/
  155225. #define JPEG_INTERNALS
  155226. #ifdef DCT_FLOAT_SUPPORTED
  155227. #if DCTSIZE != 8
  155228. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155229. #endif
  155230. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155231. GLOBAL(void)
  155232. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155233. JCOEFPTR coef_block,
  155234. JSAMPARRAY output_buf, JDIMENSION output_col)
  155235. {
  155236. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155237. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155238. FAST_FLOAT z5, z10, z11, z12, z13;
  155239. JCOEFPTR inptr;
  155240. FLOAT_MULT_TYPE * quantptr;
  155241. FAST_FLOAT * wsptr;
  155242. JSAMPROW outptr;
  155243. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155244. int ctr;
  155245. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155246. SHIFT_TEMPS
  155247. inptr = coef_block;
  155248. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155249. wsptr = workspace;
  155250. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155251. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155252. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155253. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155254. inptr[DCTSIZE*7] == 0) {
  155255. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155256. wsptr[DCTSIZE*0] = dcval;
  155257. wsptr[DCTSIZE*1] = dcval;
  155258. wsptr[DCTSIZE*2] = dcval;
  155259. wsptr[DCTSIZE*3] = dcval;
  155260. wsptr[DCTSIZE*4] = dcval;
  155261. wsptr[DCTSIZE*5] = dcval;
  155262. wsptr[DCTSIZE*6] = dcval;
  155263. wsptr[DCTSIZE*7] = dcval;
  155264. inptr++; /* advance pointers to next column */
  155265. quantptr++;
  155266. wsptr++;
  155267. continue;
  155268. }
  155269. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155270. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155271. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155272. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155273. tmp10 = tmp0 + tmp2; /* phase 3 */
  155274. tmp11 = tmp0 - tmp2;
  155275. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155276. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155277. tmp0 = tmp10 + tmp13; /* phase 2 */
  155278. tmp3 = tmp10 - tmp13;
  155279. tmp1 = tmp11 + tmp12;
  155280. tmp2 = tmp11 - tmp12;
  155281. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155282. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155283. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155284. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155285. z13 = tmp6 + tmp5; /* phase 6 */
  155286. z10 = tmp6 - tmp5;
  155287. z11 = tmp4 + tmp7;
  155288. z12 = tmp4 - tmp7;
  155289. tmp7 = z11 + z13; /* phase 5 */
  155290. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155291. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155292. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155293. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155294. tmp6 = tmp12 - tmp7; /* phase 2 */
  155295. tmp5 = tmp11 - tmp6;
  155296. tmp4 = tmp10 + tmp5;
  155297. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155298. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155299. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155300. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155301. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155302. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155303. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155304. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155305. inptr++; /* advance pointers to next column */
  155306. quantptr++;
  155307. wsptr++;
  155308. }
  155309. wsptr = workspace;
  155310. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155311. outptr = output_buf[ctr] + output_col;
  155312. tmp10 = wsptr[0] + wsptr[4];
  155313. tmp11 = wsptr[0] - wsptr[4];
  155314. tmp13 = wsptr[2] + wsptr[6];
  155315. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155316. tmp0 = tmp10 + tmp13;
  155317. tmp3 = tmp10 - tmp13;
  155318. tmp1 = tmp11 + tmp12;
  155319. tmp2 = tmp11 - tmp12;
  155320. z13 = wsptr[5] + wsptr[3];
  155321. z10 = wsptr[5] - wsptr[3];
  155322. z11 = wsptr[1] + wsptr[7];
  155323. z12 = wsptr[1] - wsptr[7];
  155324. tmp7 = z11 + z13;
  155325. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155326. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155327. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155328. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155329. tmp6 = tmp12 - tmp7;
  155330. tmp5 = tmp11 - tmp6;
  155331. tmp4 = tmp10 + tmp5;
  155332. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155333. & RANGE_MASK];
  155334. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155335. & RANGE_MASK];
  155336. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155337. & RANGE_MASK];
  155338. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155339. & RANGE_MASK];
  155340. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155341. & RANGE_MASK];
  155342. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155343. & RANGE_MASK];
  155344. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155345. & RANGE_MASK];
  155346. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155347. & RANGE_MASK];
  155348. wsptr += DCTSIZE; /* advance pointer to next row */
  155349. }
  155350. }
  155351. #endif /* DCT_FLOAT_SUPPORTED */
  155352. /*** End of inlined file: jidctflt.c ***/
  155353. #undef CONST_BITS
  155354. #undef FIX_1_847759065
  155355. #undef MULTIPLY
  155356. #undef DEQUANTIZE
  155357. #undef DESCALE
  155358. /*** Start of inlined file: jidctfst.c ***/
  155359. #define JPEG_INTERNALS
  155360. #ifdef DCT_IFAST_SUPPORTED
  155361. #if DCTSIZE != 8
  155362. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155363. #endif
  155364. #if BITS_IN_JSAMPLE == 8
  155365. #define CONST_BITS 8
  155366. #define PASS1_BITS 2
  155367. #else
  155368. #define CONST_BITS 8
  155369. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155370. #endif
  155371. #if CONST_BITS == 8
  155372. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155373. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155374. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155375. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155376. #else
  155377. #define FIX_1_082392200 FIX(1.082392200)
  155378. #define FIX_1_414213562 FIX(1.414213562)
  155379. #define FIX_1_847759065 FIX(1.847759065)
  155380. #define FIX_2_613125930 FIX(2.613125930)
  155381. #endif
  155382. #ifndef USE_ACCURATE_ROUNDING
  155383. #undef DESCALE
  155384. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155385. #endif
  155386. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155387. #if BITS_IN_JSAMPLE == 8
  155388. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155389. #else
  155390. #define DEQUANTIZE(coef,quantval) \
  155391. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155392. #endif
  155393. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155394. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155395. #if BITS_IN_JSAMPLE == 8
  155396. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155397. #else
  155398. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155399. #endif
  155400. #define IRIGHT_SHIFT(x,shft) \
  155401. ((ishift_temp = (x)) < 0 ? \
  155402. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155403. (ishift_temp >> (shft)))
  155404. #else
  155405. #define ISHIFT_TEMPS
  155406. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155407. #endif
  155408. #ifdef USE_ACCURATE_ROUNDING
  155409. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155410. #else
  155411. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155412. #endif
  155413. GLOBAL(void)
  155414. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155415. JCOEFPTR coef_block,
  155416. JSAMPARRAY output_buf, JDIMENSION output_col)
  155417. {
  155418. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155419. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155420. DCTELEM z5, z10, z11, z12, z13;
  155421. JCOEFPTR inptr;
  155422. IFAST_MULT_TYPE * quantptr;
  155423. int * wsptr;
  155424. JSAMPROW outptr;
  155425. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155426. int ctr;
  155427. int workspace[DCTSIZE2]; /* buffers data between passes */
  155428. SHIFT_TEMPS /* for DESCALE */
  155429. ISHIFT_TEMPS /* for IDESCALE */
  155430. inptr = coef_block;
  155431. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155432. wsptr = workspace;
  155433. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155434. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155435. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155436. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155437. inptr[DCTSIZE*7] == 0) {
  155438. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155439. wsptr[DCTSIZE*0] = dcval;
  155440. wsptr[DCTSIZE*1] = dcval;
  155441. wsptr[DCTSIZE*2] = dcval;
  155442. wsptr[DCTSIZE*3] = dcval;
  155443. wsptr[DCTSIZE*4] = dcval;
  155444. wsptr[DCTSIZE*5] = dcval;
  155445. wsptr[DCTSIZE*6] = dcval;
  155446. wsptr[DCTSIZE*7] = dcval;
  155447. inptr++; /* advance pointers to next column */
  155448. quantptr++;
  155449. wsptr++;
  155450. continue;
  155451. }
  155452. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155453. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155454. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155455. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155456. tmp10 = tmp0 + tmp2; /* phase 3 */
  155457. tmp11 = tmp0 - tmp2;
  155458. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155459. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155460. tmp0 = tmp10 + tmp13; /* phase 2 */
  155461. tmp3 = tmp10 - tmp13;
  155462. tmp1 = tmp11 + tmp12;
  155463. tmp2 = tmp11 - tmp12;
  155464. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155465. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155466. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155467. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155468. z13 = tmp6 + tmp5; /* phase 6 */
  155469. z10 = tmp6 - tmp5;
  155470. z11 = tmp4 + tmp7;
  155471. z12 = tmp4 - tmp7;
  155472. tmp7 = z11 + z13; /* phase 5 */
  155473. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155474. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155475. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155476. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155477. tmp6 = tmp12 - tmp7; /* phase 2 */
  155478. tmp5 = tmp11 - tmp6;
  155479. tmp4 = tmp10 + tmp5;
  155480. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155481. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155482. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155483. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155484. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155485. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155486. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155487. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155488. inptr++; /* advance pointers to next column */
  155489. quantptr++;
  155490. wsptr++;
  155491. }
  155492. wsptr = workspace;
  155493. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155494. outptr = output_buf[ctr] + output_col;
  155495. #ifndef NO_ZERO_ROW_TEST
  155496. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155497. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155498. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155499. & RANGE_MASK];
  155500. outptr[0] = dcval;
  155501. outptr[1] = dcval;
  155502. outptr[2] = dcval;
  155503. outptr[3] = dcval;
  155504. outptr[4] = dcval;
  155505. outptr[5] = dcval;
  155506. outptr[6] = dcval;
  155507. outptr[7] = dcval;
  155508. wsptr += DCTSIZE; /* advance pointer to next row */
  155509. continue;
  155510. }
  155511. #endif
  155512. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155513. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155514. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155515. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155516. - tmp13;
  155517. tmp0 = tmp10 + tmp13;
  155518. tmp3 = tmp10 - tmp13;
  155519. tmp1 = tmp11 + tmp12;
  155520. tmp2 = tmp11 - tmp12;
  155521. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155522. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155523. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155524. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155525. tmp7 = z11 + z13; /* phase 5 */
  155526. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155527. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155528. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155529. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155530. tmp6 = tmp12 - tmp7; /* phase 2 */
  155531. tmp5 = tmp11 - tmp6;
  155532. tmp4 = tmp10 + tmp5;
  155533. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155534. & RANGE_MASK];
  155535. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155536. & RANGE_MASK];
  155537. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155538. & RANGE_MASK];
  155539. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  155540. & RANGE_MASK];
  155541. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  155542. & RANGE_MASK];
  155543. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  155544. & RANGE_MASK];
  155545. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  155546. & RANGE_MASK];
  155547. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  155548. & RANGE_MASK];
  155549. wsptr += DCTSIZE; /* advance pointer to next row */
  155550. }
  155551. }
  155552. #endif /* DCT_IFAST_SUPPORTED */
  155553. /*** End of inlined file: jidctfst.c ***/
  155554. #undef CONST_BITS
  155555. #undef FIX_1_847759065
  155556. #undef MULTIPLY
  155557. #undef DEQUANTIZE
  155558. /*** Start of inlined file: jidctint.c ***/
  155559. #define JPEG_INTERNALS
  155560. #ifdef DCT_ISLOW_SUPPORTED
  155561. #if DCTSIZE != 8
  155562. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155563. #endif
  155564. #if BITS_IN_JSAMPLE == 8
  155565. #define CONST_BITS 13
  155566. #define PASS1_BITS 2
  155567. #else
  155568. #define CONST_BITS 13
  155569. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155570. #endif
  155571. #if CONST_BITS == 13
  155572. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155573. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155574. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155575. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155576. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155577. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155578. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155579. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155580. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155581. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155582. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155583. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155584. #else
  155585. #define FIX_0_298631336 FIX(0.298631336)
  155586. #define FIX_0_390180644 FIX(0.390180644)
  155587. #define FIX_0_541196100 FIX(0.541196100)
  155588. #define FIX_0_765366865 FIX(0.765366865)
  155589. #define FIX_0_899976223 FIX(0.899976223)
  155590. #define FIX_1_175875602 FIX(1.175875602)
  155591. #define FIX_1_501321110 FIX(1.501321110)
  155592. #define FIX_1_847759065 FIX(1.847759065)
  155593. #define FIX_1_961570560 FIX(1.961570560)
  155594. #define FIX_2_053119869 FIX(2.053119869)
  155595. #define FIX_2_562915447 FIX(2.562915447)
  155596. #define FIX_3_072711026 FIX(3.072711026)
  155597. #endif
  155598. #if BITS_IN_JSAMPLE == 8
  155599. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155600. #else
  155601. #define MULTIPLY(var,const) ((var) * (const))
  155602. #endif
  155603. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155604. GLOBAL(void)
  155605. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155606. JCOEFPTR coef_block,
  155607. JSAMPARRAY output_buf, JDIMENSION output_col)
  155608. {
  155609. INT32 tmp0, tmp1, tmp2, tmp3;
  155610. INT32 tmp10, tmp11, tmp12, tmp13;
  155611. INT32 z1, z2, z3, z4, z5;
  155612. JCOEFPTR inptr;
  155613. ISLOW_MULT_TYPE * quantptr;
  155614. int * wsptr;
  155615. JSAMPROW outptr;
  155616. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155617. int ctr;
  155618. int workspace[DCTSIZE2]; /* buffers data between passes */
  155619. SHIFT_TEMPS
  155620. inptr = coef_block;
  155621. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155622. wsptr = workspace;
  155623. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155624. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155625. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155626. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155627. inptr[DCTSIZE*7] == 0) {
  155628. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155629. wsptr[DCTSIZE*0] = dcval;
  155630. wsptr[DCTSIZE*1] = dcval;
  155631. wsptr[DCTSIZE*2] = dcval;
  155632. wsptr[DCTSIZE*3] = dcval;
  155633. wsptr[DCTSIZE*4] = dcval;
  155634. wsptr[DCTSIZE*5] = dcval;
  155635. wsptr[DCTSIZE*6] = dcval;
  155636. wsptr[DCTSIZE*7] = dcval;
  155637. inptr++; /* advance pointers to next column */
  155638. quantptr++;
  155639. wsptr++;
  155640. continue;
  155641. }
  155642. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155643. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155644. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155645. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155646. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155647. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155648. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155649. tmp0 = (z2 + z3) << CONST_BITS;
  155650. tmp1 = (z2 - z3) << CONST_BITS;
  155651. tmp10 = tmp0 + tmp3;
  155652. tmp13 = tmp0 - tmp3;
  155653. tmp11 = tmp1 + tmp2;
  155654. tmp12 = tmp1 - tmp2;
  155655. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155656. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155657. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155658. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155659. z1 = tmp0 + tmp3;
  155660. z2 = tmp1 + tmp2;
  155661. z3 = tmp0 + tmp2;
  155662. z4 = tmp1 + tmp3;
  155663. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155664. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155665. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155666. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155667. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155668. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155669. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155670. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155671. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155672. z3 += z5;
  155673. z4 += z5;
  155674. tmp0 += z1 + z3;
  155675. tmp1 += z2 + z4;
  155676. tmp2 += z2 + z3;
  155677. tmp3 += z1 + z4;
  155678. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  155679. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  155680. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  155681. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  155682. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  155683. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  155684. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  155685. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  155686. inptr++; /* advance pointers to next column */
  155687. quantptr++;
  155688. wsptr++;
  155689. }
  155690. wsptr = workspace;
  155691. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155692. outptr = output_buf[ctr] + output_col;
  155693. #ifndef NO_ZERO_ROW_TEST
  155694. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155695. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155696. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155697. & RANGE_MASK];
  155698. outptr[0] = dcval;
  155699. outptr[1] = dcval;
  155700. outptr[2] = dcval;
  155701. outptr[3] = dcval;
  155702. outptr[4] = dcval;
  155703. outptr[5] = dcval;
  155704. outptr[6] = dcval;
  155705. outptr[7] = dcval;
  155706. wsptr += DCTSIZE; /* advance pointer to next row */
  155707. continue;
  155708. }
  155709. #endif
  155710. z2 = (INT32) wsptr[2];
  155711. z3 = (INT32) wsptr[6];
  155712. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155713. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155714. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155715. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  155716. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  155717. tmp10 = tmp0 + tmp3;
  155718. tmp13 = tmp0 - tmp3;
  155719. tmp11 = tmp1 + tmp2;
  155720. tmp12 = tmp1 - tmp2;
  155721. tmp0 = (INT32) wsptr[7];
  155722. tmp1 = (INT32) wsptr[5];
  155723. tmp2 = (INT32) wsptr[3];
  155724. tmp3 = (INT32) wsptr[1];
  155725. z1 = tmp0 + tmp3;
  155726. z2 = tmp1 + tmp2;
  155727. z3 = tmp0 + tmp2;
  155728. z4 = tmp1 + tmp3;
  155729. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155730. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155731. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155732. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155733. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155734. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155735. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155736. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155737. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155738. z3 += z5;
  155739. z4 += z5;
  155740. tmp0 += z1 + z3;
  155741. tmp1 += z2 + z4;
  155742. tmp2 += z2 + z3;
  155743. tmp3 += z1 + z4;
  155744. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  155745. CONST_BITS+PASS1_BITS+3)
  155746. & RANGE_MASK];
  155747. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  155748. CONST_BITS+PASS1_BITS+3)
  155749. & RANGE_MASK];
  155750. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  155751. CONST_BITS+PASS1_BITS+3)
  155752. & RANGE_MASK];
  155753. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  155754. CONST_BITS+PASS1_BITS+3)
  155755. & RANGE_MASK];
  155756. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  155757. CONST_BITS+PASS1_BITS+3)
  155758. & RANGE_MASK];
  155759. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  155760. CONST_BITS+PASS1_BITS+3)
  155761. & RANGE_MASK];
  155762. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  155763. CONST_BITS+PASS1_BITS+3)
  155764. & RANGE_MASK];
  155765. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  155766. CONST_BITS+PASS1_BITS+3)
  155767. & RANGE_MASK];
  155768. wsptr += DCTSIZE; /* advance pointer to next row */
  155769. }
  155770. }
  155771. #endif /* DCT_ISLOW_SUPPORTED */
  155772. /*** End of inlined file: jidctint.c ***/
  155773. /*** Start of inlined file: jidctred.c ***/
  155774. #define JPEG_INTERNALS
  155775. #ifdef IDCT_SCALING_SUPPORTED
  155776. #if DCTSIZE != 8
  155777. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155778. #endif
  155779. #if BITS_IN_JSAMPLE == 8
  155780. #define CONST_BITS 13
  155781. #define PASS1_BITS 2
  155782. #else
  155783. #define CONST_BITS 13
  155784. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155785. #endif
  155786. #if CONST_BITS == 13
  155787. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  155788. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  155789. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  155790. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  155791. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155792. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  155793. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155794. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  155795. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  155796. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  155797. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155798. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  155799. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155800. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  155801. #else
  155802. #define FIX_0_211164243 FIX(0.211164243)
  155803. #define FIX_0_509795579 FIX(0.509795579)
  155804. #define FIX_0_601344887 FIX(0.601344887)
  155805. #define FIX_0_720959822 FIX(0.720959822)
  155806. #define FIX_0_765366865 FIX(0.765366865)
  155807. #define FIX_0_850430095 FIX(0.850430095)
  155808. #define FIX_0_899976223 FIX(0.899976223)
  155809. #define FIX_1_061594337 FIX(1.061594337)
  155810. #define FIX_1_272758580 FIX(1.272758580)
  155811. #define FIX_1_451774981 FIX(1.451774981)
  155812. #define FIX_1_847759065 FIX(1.847759065)
  155813. #define FIX_2_172734803 FIX(2.172734803)
  155814. #define FIX_2_562915447 FIX(2.562915447)
  155815. #define FIX_3_624509785 FIX(3.624509785)
  155816. #endif
  155817. #if BITS_IN_JSAMPLE == 8
  155818. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155819. #else
  155820. #define MULTIPLY(var,const) ((var) * (const))
  155821. #endif
  155822. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155823. GLOBAL(void)
  155824. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155825. JCOEFPTR coef_block,
  155826. JSAMPARRAY output_buf, JDIMENSION output_col)
  155827. {
  155828. INT32 tmp0, tmp2, tmp10, tmp12;
  155829. INT32 z1, z2, z3, z4;
  155830. JCOEFPTR inptr;
  155831. ISLOW_MULT_TYPE * quantptr;
  155832. int * wsptr;
  155833. JSAMPROW outptr;
  155834. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155835. int ctr;
  155836. int workspace[DCTSIZE*4]; /* buffers data between passes */
  155837. SHIFT_TEMPS
  155838. inptr = coef_block;
  155839. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155840. wsptr = workspace;
  155841. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155842. if (ctr == DCTSIZE-4)
  155843. continue;
  155844. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155845. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  155846. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  155847. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155848. wsptr[DCTSIZE*0] = dcval;
  155849. wsptr[DCTSIZE*1] = dcval;
  155850. wsptr[DCTSIZE*2] = dcval;
  155851. wsptr[DCTSIZE*3] = dcval;
  155852. continue;
  155853. }
  155854. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155855. tmp0 <<= (CONST_BITS+1);
  155856. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155857. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155858. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  155859. tmp10 = tmp0 + tmp2;
  155860. tmp12 = tmp0 - tmp2;
  155861. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155862. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155863. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155864. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155865. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155866. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155867. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155868. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155869. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155870. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155871. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155872. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155873. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  155874. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  155875. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  155876. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  155877. }
  155878. wsptr = workspace;
  155879. for (ctr = 0; ctr < 4; ctr++) {
  155880. outptr = output_buf[ctr] + output_col;
  155881. #ifndef NO_ZERO_ROW_TEST
  155882. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  155883. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155884. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155885. & RANGE_MASK];
  155886. outptr[0] = dcval;
  155887. outptr[1] = dcval;
  155888. outptr[2] = dcval;
  155889. outptr[3] = dcval;
  155890. wsptr += DCTSIZE; /* advance pointer to next row */
  155891. continue;
  155892. }
  155893. #endif
  155894. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  155895. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  155896. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  155897. tmp10 = tmp0 + tmp2;
  155898. tmp12 = tmp0 - tmp2;
  155899. z1 = (INT32) wsptr[7];
  155900. z2 = (INT32) wsptr[5];
  155901. z3 = (INT32) wsptr[3];
  155902. z4 = (INT32) wsptr[1];
  155903. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155904. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155905. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155906. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155907. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155908. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155909. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155910. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155911. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  155912. CONST_BITS+PASS1_BITS+3+1)
  155913. & RANGE_MASK];
  155914. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  155915. CONST_BITS+PASS1_BITS+3+1)
  155916. & RANGE_MASK];
  155917. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  155918. CONST_BITS+PASS1_BITS+3+1)
  155919. & RANGE_MASK];
  155920. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  155921. CONST_BITS+PASS1_BITS+3+1)
  155922. & RANGE_MASK];
  155923. wsptr += DCTSIZE; /* advance pointer to next row */
  155924. }
  155925. }
  155926. GLOBAL(void)
  155927. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155928. JCOEFPTR coef_block,
  155929. JSAMPARRAY output_buf, JDIMENSION output_col)
  155930. {
  155931. INT32 tmp0, tmp10, z1;
  155932. JCOEFPTR inptr;
  155933. ISLOW_MULT_TYPE * quantptr;
  155934. int * wsptr;
  155935. JSAMPROW outptr;
  155936. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155937. int ctr;
  155938. int workspace[DCTSIZE*2]; /* buffers data between passes */
  155939. SHIFT_TEMPS
  155940. inptr = coef_block;
  155941. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155942. wsptr = workspace;
  155943. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155944. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  155945. continue;
  155946. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  155947. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  155948. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155949. wsptr[DCTSIZE*0] = dcval;
  155950. wsptr[DCTSIZE*1] = dcval;
  155951. continue;
  155952. }
  155953. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155954. tmp10 = z1 << (CONST_BITS+2);
  155955. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155956. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  155957. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155958. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  155959. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155960. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  155961. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155962. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155963. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  155964. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  155965. }
  155966. wsptr = workspace;
  155967. for (ctr = 0; ctr < 2; ctr++) {
  155968. outptr = output_buf[ctr] + output_col;
  155969. #ifndef NO_ZERO_ROW_TEST
  155970. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  155971. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155972. & RANGE_MASK];
  155973. outptr[0] = dcval;
  155974. outptr[1] = dcval;
  155975. wsptr += DCTSIZE; /* advance pointer to next row */
  155976. continue;
  155977. }
  155978. #endif
  155979. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  155980. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  155981. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  155982. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  155983. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155984. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  155985. CONST_BITS+PASS1_BITS+3+2)
  155986. & RANGE_MASK];
  155987. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  155988. CONST_BITS+PASS1_BITS+3+2)
  155989. & RANGE_MASK];
  155990. wsptr += DCTSIZE; /* advance pointer to next row */
  155991. }
  155992. }
  155993. GLOBAL(void)
  155994. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155995. JCOEFPTR coef_block,
  155996. JSAMPARRAY output_buf, JDIMENSION output_col)
  155997. {
  155998. int dcval;
  155999. ISLOW_MULT_TYPE * quantptr;
  156000. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156001. SHIFT_TEMPS
  156002. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156003. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  156004. dcval = (int) DESCALE((INT32) dcval, 3);
  156005. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  156006. }
  156007. #endif /* IDCT_SCALING_SUPPORTED */
  156008. /*** End of inlined file: jidctred.c ***/
  156009. /*** Start of inlined file: jmemmgr.c ***/
  156010. #define JPEG_INTERNALS
  156011. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156012. /*** Start of inlined file: jmemsys.h ***/
  156013. #ifndef __jmemsys_h__
  156014. #define __jmemsys_h__
  156015. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156016. #define jpeg_get_small jGetSmall
  156017. #define jpeg_free_small jFreeSmall
  156018. #define jpeg_get_large jGetLarge
  156019. #define jpeg_free_large jFreeLarge
  156020. #define jpeg_mem_available jMemAvail
  156021. #define jpeg_open_backing_store jOpenBackStore
  156022. #define jpeg_mem_init jMemInit
  156023. #define jpeg_mem_term jMemTerm
  156024. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156025. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156026. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156027. size_t sizeofobject));
  156028. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156029. size_t sizeofobject));
  156030. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156031. size_t sizeofobject));
  156032. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156033. #define MAX_ALLOC_CHUNK 1000000000L
  156034. #endif
  156035. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156036. long min_bytes_needed,
  156037. long max_bytes_needed,
  156038. long already_allocated));
  156039. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156040. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156041. typedef unsigned short XMSH; /* type of extended-memory handles */
  156042. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156043. typedef union {
  156044. short file_handle; /* DOS file handle if it's a temp file */
  156045. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156046. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156047. } handle_union;
  156048. #endif /* USE_MSDOS_MEMMGR */
  156049. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156050. #include <Files.h>
  156051. #endif /* USE_MAC_MEMMGR */
  156052. //typedef struct backing_store_struct * backing_store_ptr;
  156053. typedef struct backing_store_struct {
  156054. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156055. struct backing_store_struct *info,
  156056. void FAR * buffer_address,
  156057. long file_offset, long byte_count));
  156058. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156059. struct backing_store_struct *info,
  156060. void FAR * buffer_address,
  156061. long file_offset, long byte_count));
  156062. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156063. struct backing_store_struct *info));
  156064. #ifdef USE_MSDOS_MEMMGR
  156065. handle_union handle; /* reference to backing-store storage object */
  156066. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156067. #else
  156068. #ifdef USE_MAC_MEMMGR
  156069. short temp_file; /* file reference number to temp file */
  156070. FSSpec tempSpec; /* the FSSpec for the temp file */
  156071. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156072. #else
  156073. FILE * temp_file; /* stdio reference to temp file */
  156074. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156075. #endif
  156076. #endif
  156077. } backing_store_info;
  156078. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156079. struct backing_store_struct *info,
  156080. long total_bytes_needed));
  156081. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156082. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156083. #endif
  156084. /*** End of inlined file: jmemsys.h ***/
  156085. /* import the system-dependent declarations */
  156086. #ifndef NO_GETENV
  156087. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156088. extern char * getenv JPP((const char * name));
  156089. #endif
  156090. #endif
  156091. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156092. #define ALIGN_TYPE double
  156093. #endif
  156094. typedef union small_pool_struct * small_pool_ptr;
  156095. typedef union small_pool_struct {
  156096. struct {
  156097. small_pool_ptr next; /* next in list of pools */
  156098. size_t bytes_used; /* how many bytes already used within pool */
  156099. size_t bytes_left; /* bytes still available in this pool */
  156100. } hdr;
  156101. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156102. } small_pool_hdr;
  156103. typedef union large_pool_struct FAR * large_pool_ptr;
  156104. typedef union large_pool_struct {
  156105. struct {
  156106. large_pool_ptr next; /* next in list of pools */
  156107. size_t bytes_used; /* how many bytes already used within pool */
  156108. size_t bytes_left; /* bytes still available in this pool */
  156109. } hdr;
  156110. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156111. } large_pool_hdr;
  156112. typedef struct {
  156113. struct jpeg_memory_mgr pub; /* public fields */
  156114. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156115. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156116. jvirt_sarray_ptr virt_sarray_list;
  156117. jvirt_barray_ptr virt_barray_list;
  156118. long total_space_allocated;
  156119. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156120. } my_memory_mgr;
  156121. typedef my_memory_mgr * my_mem_ptr;
  156122. struct jvirt_sarray_control {
  156123. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156124. JDIMENSION rows_in_array; /* total virtual array height */
  156125. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156126. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156127. JDIMENSION rows_in_mem; /* height of memory buffer */
  156128. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156129. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156130. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156131. boolean pre_zero; /* pre-zero mode requested? */
  156132. boolean dirty; /* do current buffer contents need written? */
  156133. boolean b_s_open; /* is backing-store data valid? */
  156134. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156135. backing_store_info b_s_info; /* System-dependent control info */
  156136. };
  156137. struct jvirt_barray_control {
  156138. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156139. JDIMENSION rows_in_array; /* total virtual array height */
  156140. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156141. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156142. JDIMENSION rows_in_mem; /* height of memory buffer */
  156143. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156144. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156145. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156146. boolean pre_zero; /* pre-zero mode requested? */
  156147. boolean dirty; /* do current buffer contents need written? */
  156148. boolean b_s_open; /* is backing-store data valid? */
  156149. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156150. backing_store_info b_s_info; /* System-dependent control info */
  156151. };
  156152. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156153. LOCAL(void)
  156154. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156155. {
  156156. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156157. small_pool_ptr shdr_ptr;
  156158. large_pool_ptr lhdr_ptr;
  156159. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156160. pool_id, mem->total_space_allocated);
  156161. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156162. lhdr_ptr = lhdr_ptr->hdr.next) {
  156163. fprintf(stderr, " Large chunk used %ld\n",
  156164. (long) lhdr_ptr->hdr.bytes_used);
  156165. }
  156166. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156167. shdr_ptr = shdr_ptr->hdr.next) {
  156168. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156169. (long) shdr_ptr->hdr.bytes_used,
  156170. (long) shdr_ptr->hdr.bytes_left);
  156171. }
  156172. }
  156173. #endif /* MEM_STATS */
  156174. LOCAL(void)
  156175. out_of_memory (j_common_ptr cinfo, int which)
  156176. {
  156177. #ifdef MEM_STATS
  156178. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156179. #endif
  156180. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156181. }
  156182. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156183. {
  156184. 1600, /* first PERMANENT pool */
  156185. 16000 /* first IMAGE pool */
  156186. };
  156187. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156188. {
  156189. 0, /* additional PERMANENT pools */
  156190. 5000 /* additional IMAGE pools */
  156191. };
  156192. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156193. METHODDEF(void *)
  156194. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156195. {
  156196. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156197. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156198. char * data_ptr;
  156199. size_t odd_bytes, min_request, slop;
  156200. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156201. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156202. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156203. if (odd_bytes > 0)
  156204. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156205. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156206. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156207. prev_hdr_ptr = NULL;
  156208. hdr_ptr = mem->small_list[pool_id];
  156209. while (hdr_ptr != NULL) {
  156210. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156211. break; /* found pool with enough space */
  156212. prev_hdr_ptr = hdr_ptr;
  156213. hdr_ptr = hdr_ptr->hdr.next;
  156214. }
  156215. if (hdr_ptr == NULL) {
  156216. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156217. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156218. slop = first_pool_slop[pool_id];
  156219. else
  156220. slop = extra_pool_slop[pool_id];
  156221. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156222. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156223. for (;;) {
  156224. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156225. if (hdr_ptr != NULL)
  156226. break;
  156227. slop /= 2;
  156228. if (slop < MIN_SLOP) /* give up when it gets real small */
  156229. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156230. }
  156231. mem->total_space_allocated += min_request + slop;
  156232. hdr_ptr->hdr.next = NULL;
  156233. hdr_ptr->hdr.bytes_used = 0;
  156234. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156235. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156236. mem->small_list[pool_id] = hdr_ptr;
  156237. else
  156238. prev_hdr_ptr->hdr.next = hdr_ptr;
  156239. }
  156240. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156241. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156242. hdr_ptr->hdr.bytes_used += sizeofobject;
  156243. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156244. return (void *) data_ptr;
  156245. }
  156246. METHODDEF(void FAR *)
  156247. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156248. {
  156249. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156250. large_pool_ptr hdr_ptr;
  156251. size_t odd_bytes;
  156252. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156253. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156254. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156255. if (odd_bytes > 0)
  156256. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156257. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156258. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156259. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156260. SIZEOF(large_pool_hdr));
  156261. if (hdr_ptr == NULL)
  156262. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156263. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156264. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156265. hdr_ptr->hdr.bytes_used = sizeofobject;
  156266. hdr_ptr->hdr.bytes_left = 0;
  156267. mem->large_list[pool_id] = hdr_ptr;
  156268. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156269. }
  156270. METHODDEF(JSAMPARRAY)
  156271. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156272. JDIMENSION samplesperrow, JDIMENSION numrows)
  156273. {
  156274. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156275. JSAMPARRAY result;
  156276. JSAMPROW workspace;
  156277. JDIMENSION rowsperchunk, currow, i;
  156278. long ltemp;
  156279. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156280. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156281. if (ltemp <= 0)
  156282. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156283. if (ltemp < (long) numrows)
  156284. rowsperchunk = (JDIMENSION) ltemp;
  156285. else
  156286. rowsperchunk = numrows;
  156287. mem->last_rowsperchunk = rowsperchunk;
  156288. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156289. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156290. currow = 0;
  156291. while (currow < numrows) {
  156292. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156293. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156294. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156295. * SIZEOF(JSAMPLE)));
  156296. for (i = rowsperchunk; i > 0; i--) {
  156297. result[currow++] = workspace;
  156298. workspace += samplesperrow;
  156299. }
  156300. }
  156301. return result;
  156302. }
  156303. METHODDEF(JBLOCKARRAY)
  156304. alloc_barray (j_common_ptr cinfo, int pool_id,
  156305. JDIMENSION blocksperrow, JDIMENSION numrows)
  156306. {
  156307. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156308. JBLOCKARRAY result;
  156309. JBLOCKROW workspace;
  156310. JDIMENSION rowsperchunk, currow, i;
  156311. long ltemp;
  156312. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156313. ((long) blocksperrow * SIZEOF(JBLOCK));
  156314. if (ltemp <= 0)
  156315. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156316. if (ltemp < (long) numrows)
  156317. rowsperchunk = (JDIMENSION) ltemp;
  156318. else
  156319. rowsperchunk = numrows;
  156320. mem->last_rowsperchunk = rowsperchunk;
  156321. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156322. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156323. currow = 0;
  156324. while (currow < numrows) {
  156325. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156326. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156327. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156328. * SIZEOF(JBLOCK)));
  156329. for (i = rowsperchunk; i > 0; i--) {
  156330. result[currow++] = workspace;
  156331. workspace += blocksperrow;
  156332. }
  156333. }
  156334. return result;
  156335. }
  156336. METHODDEF(jvirt_sarray_ptr)
  156337. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156338. JDIMENSION samplesperrow, JDIMENSION numrows,
  156339. JDIMENSION maxaccess)
  156340. {
  156341. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156342. jvirt_sarray_ptr result;
  156343. if (pool_id != JPOOL_IMAGE)
  156344. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156345. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156346. SIZEOF(struct jvirt_sarray_control));
  156347. result->mem_buffer = NULL; /* marks array not yet realized */
  156348. result->rows_in_array = numrows;
  156349. result->samplesperrow = samplesperrow;
  156350. result->maxaccess = maxaccess;
  156351. result->pre_zero = pre_zero;
  156352. result->b_s_open = FALSE; /* no associated backing-store object */
  156353. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156354. mem->virt_sarray_list = result;
  156355. return result;
  156356. }
  156357. METHODDEF(jvirt_barray_ptr)
  156358. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156359. JDIMENSION blocksperrow, JDIMENSION numrows,
  156360. JDIMENSION maxaccess)
  156361. {
  156362. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156363. jvirt_barray_ptr result;
  156364. if (pool_id != JPOOL_IMAGE)
  156365. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156366. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156367. SIZEOF(struct jvirt_barray_control));
  156368. result->mem_buffer = NULL; /* marks array not yet realized */
  156369. result->rows_in_array = numrows;
  156370. result->blocksperrow = blocksperrow;
  156371. result->maxaccess = maxaccess;
  156372. result->pre_zero = pre_zero;
  156373. result->b_s_open = FALSE; /* no associated backing-store object */
  156374. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156375. mem->virt_barray_list = result;
  156376. return result;
  156377. }
  156378. METHODDEF(void)
  156379. realize_virt_arrays (j_common_ptr cinfo)
  156380. {
  156381. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156382. long space_per_minheight, maximum_space, avail_mem;
  156383. long minheights, max_minheights;
  156384. jvirt_sarray_ptr sptr;
  156385. jvirt_barray_ptr bptr;
  156386. space_per_minheight = 0;
  156387. maximum_space = 0;
  156388. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156389. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156390. space_per_minheight += (long) sptr->maxaccess *
  156391. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156392. maximum_space += (long) sptr->rows_in_array *
  156393. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156394. }
  156395. }
  156396. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156397. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156398. space_per_minheight += (long) bptr->maxaccess *
  156399. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156400. maximum_space += (long) bptr->rows_in_array *
  156401. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156402. }
  156403. }
  156404. if (space_per_minheight <= 0)
  156405. return; /* no unrealized arrays, no work */
  156406. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156407. mem->total_space_allocated);
  156408. if (avail_mem >= maximum_space)
  156409. max_minheights = 1000000000L;
  156410. else {
  156411. max_minheights = avail_mem / space_per_minheight;
  156412. if (max_minheights <= 0)
  156413. max_minheights = 1;
  156414. }
  156415. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156416. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156417. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156418. if (minheights <= max_minheights) {
  156419. sptr->rows_in_mem = sptr->rows_in_array;
  156420. } else {
  156421. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156422. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156423. (long) sptr->rows_in_array *
  156424. (long) sptr->samplesperrow *
  156425. (long) SIZEOF(JSAMPLE));
  156426. sptr->b_s_open = TRUE;
  156427. }
  156428. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156429. sptr->samplesperrow, sptr->rows_in_mem);
  156430. sptr->rowsperchunk = mem->last_rowsperchunk;
  156431. sptr->cur_start_row = 0;
  156432. sptr->first_undef_row = 0;
  156433. sptr->dirty = FALSE;
  156434. }
  156435. }
  156436. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156437. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156438. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156439. if (minheights <= max_minheights) {
  156440. bptr->rows_in_mem = bptr->rows_in_array;
  156441. } else {
  156442. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156443. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156444. (long) bptr->rows_in_array *
  156445. (long) bptr->blocksperrow *
  156446. (long) SIZEOF(JBLOCK));
  156447. bptr->b_s_open = TRUE;
  156448. }
  156449. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156450. bptr->blocksperrow, bptr->rows_in_mem);
  156451. bptr->rowsperchunk = mem->last_rowsperchunk;
  156452. bptr->cur_start_row = 0;
  156453. bptr->first_undef_row = 0;
  156454. bptr->dirty = FALSE;
  156455. }
  156456. }
  156457. }
  156458. LOCAL(void)
  156459. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156460. {
  156461. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156462. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156463. file_offset = ptr->cur_start_row * bytesperrow;
  156464. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156465. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156466. thisrow = (long) ptr->cur_start_row + i;
  156467. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156468. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156469. if (rows <= 0) /* this chunk might be past end of file! */
  156470. break;
  156471. byte_count = rows * bytesperrow;
  156472. if (writing)
  156473. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156474. (void FAR *) ptr->mem_buffer[i],
  156475. file_offset, byte_count);
  156476. else
  156477. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156478. (void FAR *) ptr->mem_buffer[i],
  156479. file_offset, byte_count);
  156480. file_offset += byte_count;
  156481. }
  156482. }
  156483. LOCAL(void)
  156484. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156485. {
  156486. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156487. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156488. file_offset = ptr->cur_start_row * bytesperrow;
  156489. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156490. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156491. thisrow = (long) ptr->cur_start_row + i;
  156492. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156493. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156494. if (rows <= 0) /* this chunk might be past end of file! */
  156495. break;
  156496. byte_count = rows * bytesperrow;
  156497. if (writing)
  156498. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156499. (void FAR *) ptr->mem_buffer[i],
  156500. file_offset, byte_count);
  156501. else
  156502. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156503. (void FAR *) ptr->mem_buffer[i],
  156504. file_offset, byte_count);
  156505. file_offset += byte_count;
  156506. }
  156507. }
  156508. METHODDEF(JSAMPARRAY)
  156509. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156510. JDIMENSION start_row, JDIMENSION num_rows,
  156511. boolean writable)
  156512. {
  156513. JDIMENSION end_row = start_row + num_rows;
  156514. JDIMENSION undef_row;
  156515. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156516. ptr->mem_buffer == NULL)
  156517. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156518. if (start_row < ptr->cur_start_row ||
  156519. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156520. if (! ptr->b_s_open)
  156521. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156522. if (ptr->dirty) {
  156523. do_sarray_io(cinfo, ptr, TRUE);
  156524. ptr->dirty = FALSE;
  156525. }
  156526. if (start_row > ptr->cur_start_row) {
  156527. ptr->cur_start_row = start_row;
  156528. } else {
  156529. long ltemp;
  156530. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156531. if (ltemp < 0)
  156532. ltemp = 0; /* don't fall off front end of file */
  156533. ptr->cur_start_row = (JDIMENSION) ltemp;
  156534. }
  156535. do_sarray_io(cinfo, ptr, FALSE);
  156536. }
  156537. if (ptr->first_undef_row < end_row) {
  156538. if (ptr->first_undef_row < start_row) {
  156539. if (writable) /* writer skipped over a section of array */
  156540. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156541. undef_row = start_row; /* but reader is allowed to read ahead */
  156542. } else {
  156543. undef_row = ptr->first_undef_row;
  156544. }
  156545. if (writable)
  156546. ptr->first_undef_row = end_row;
  156547. if (ptr->pre_zero) {
  156548. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156549. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156550. end_row -= ptr->cur_start_row;
  156551. while (undef_row < end_row) {
  156552. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156553. undef_row++;
  156554. }
  156555. } else {
  156556. if (! writable) /* reader looking at undefined data */
  156557. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156558. }
  156559. }
  156560. if (writable)
  156561. ptr->dirty = TRUE;
  156562. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156563. }
  156564. METHODDEF(JBLOCKARRAY)
  156565. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  156566. JDIMENSION start_row, JDIMENSION num_rows,
  156567. boolean writable)
  156568. {
  156569. JDIMENSION end_row = start_row + num_rows;
  156570. JDIMENSION undef_row;
  156571. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156572. ptr->mem_buffer == NULL)
  156573. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156574. if (start_row < ptr->cur_start_row ||
  156575. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156576. if (! ptr->b_s_open)
  156577. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156578. if (ptr->dirty) {
  156579. do_barray_io(cinfo, ptr, TRUE);
  156580. ptr->dirty = FALSE;
  156581. }
  156582. if (start_row > ptr->cur_start_row) {
  156583. ptr->cur_start_row = start_row;
  156584. } else {
  156585. long ltemp;
  156586. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156587. if (ltemp < 0)
  156588. ltemp = 0; /* don't fall off front end of file */
  156589. ptr->cur_start_row = (JDIMENSION) ltemp;
  156590. }
  156591. do_barray_io(cinfo, ptr, FALSE);
  156592. }
  156593. if (ptr->first_undef_row < end_row) {
  156594. if (ptr->first_undef_row < start_row) {
  156595. if (writable) /* writer skipped over a section of array */
  156596. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156597. undef_row = start_row; /* but reader is allowed to read ahead */
  156598. } else {
  156599. undef_row = ptr->first_undef_row;
  156600. }
  156601. if (writable)
  156602. ptr->first_undef_row = end_row;
  156603. if (ptr->pre_zero) {
  156604. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  156605. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156606. end_row -= ptr->cur_start_row;
  156607. while (undef_row < end_row) {
  156608. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156609. undef_row++;
  156610. }
  156611. } else {
  156612. if (! writable) /* reader looking at undefined data */
  156613. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156614. }
  156615. }
  156616. if (writable)
  156617. ptr->dirty = TRUE;
  156618. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156619. }
  156620. METHODDEF(void)
  156621. free_pool (j_common_ptr cinfo, int pool_id)
  156622. {
  156623. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156624. small_pool_ptr shdr_ptr;
  156625. large_pool_ptr lhdr_ptr;
  156626. size_t space_freed;
  156627. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156628. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156629. #ifdef MEM_STATS
  156630. if (cinfo->err->trace_level > 1)
  156631. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  156632. #endif
  156633. if (pool_id == JPOOL_IMAGE) {
  156634. jvirt_sarray_ptr sptr;
  156635. jvirt_barray_ptr bptr;
  156636. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156637. if (sptr->b_s_open) { /* there may be no backing store */
  156638. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  156639. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  156640. }
  156641. }
  156642. mem->virt_sarray_list = NULL;
  156643. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156644. if (bptr->b_s_open) { /* there may be no backing store */
  156645. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  156646. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  156647. }
  156648. }
  156649. mem->virt_barray_list = NULL;
  156650. }
  156651. lhdr_ptr = mem->large_list[pool_id];
  156652. mem->large_list[pool_id] = NULL;
  156653. while (lhdr_ptr != NULL) {
  156654. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  156655. space_freed = lhdr_ptr->hdr.bytes_used +
  156656. lhdr_ptr->hdr.bytes_left +
  156657. SIZEOF(large_pool_hdr);
  156658. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  156659. mem->total_space_allocated -= space_freed;
  156660. lhdr_ptr = next_lhdr_ptr;
  156661. }
  156662. shdr_ptr = mem->small_list[pool_id];
  156663. mem->small_list[pool_id] = NULL;
  156664. while (shdr_ptr != NULL) {
  156665. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  156666. space_freed = shdr_ptr->hdr.bytes_used +
  156667. shdr_ptr->hdr.bytes_left +
  156668. SIZEOF(small_pool_hdr);
  156669. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  156670. mem->total_space_allocated -= space_freed;
  156671. shdr_ptr = next_shdr_ptr;
  156672. }
  156673. }
  156674. METHODDEF(void)
  156675. self_destruct (j_common_ptr cinfo)
  156676. {
  156677. int pool;
  156678. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156679. free_pool(cinfo, pool);
  156680. }
  156681. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  156682. cinfo->mem = NULL; /* ensures I will be called only once */
  156683. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156684. }
  156685. GLOBAL(void)
  156686. jinit_memory_mgr (j_common_ptr cinfo)
  156687. {
  156688. my_mem_ptr mem;
  156689. long max_to_use;
  156690. int pool;
  156691. size_t test_mac;
  156692. cinfo->mem = NULL; /* for safety if init fails */
  156693. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  156694. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  156695. test_mac = (size_t) MAX_ALLOC_CHUNK;
  156696. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  156697. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  156698. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  156699. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  156700. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  156701. if (mem == NULL) {
  156702. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156703. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  156704. }
  156705. mem->pub.alloc_small = alloc_small;
  156706. mem->pub.alloc_large = alloc_large;
  156707. mem->pub.alloc_sarray = alloc_sarray;
  156708. mem->pub.alloc_barray = alloc_barray;
  156709. mem->pub.request_virt_sarray = request_virt_sarray;
  156710. mem->pub.request_virt_barray = request_virt_barray;
  156711. mem->pub.realize_virt_arrays = realize_virt_arrays;
  156712. mem->pub.access_virt_sarray = access_virt_sarray;
  156713. mem->pub.access_virt_barray = access_virt_barray;
  156714. mem->pub.free_pool = free_pool;
  156715. mem->pub.self_destruct = self_destruct;
  156716. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  156717. mem->pub.max_memory_to_use = max_to_use;
  156718. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156719. mem->small_list[pool] = NULL;
  156720. mem->large_list[pool] = NULL;
  156721. }
  156722. mem->virt_sarray_list = NULL;
  156723. mem->virt_barray_list = NULL;
  156724. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  156725. cinfo->mem = & mem->pub;
  156726. #ifndef NO_GETENV
  156727. { char * memenv;
  156728. if ((memenv = getenv("JPEGMEM")) != NULL) {
  156729. char ch = 'x';
  156730. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  156731. if (ch == 'm' || ch == 'M')
  156732. max_to_use *= 1000L;
  156733. mem->pub.max_memory_to_use = max_to_use * 1000L;
  156734. }
  156735. }
  156736. }
  156737. #endif
  156738. }
  156739. /*** End of inlined file: jmemmgr.c ***/
  156740. /*** Start of inlined file: jmemnobs.c ***/
  156741. #define JPEG_INTERNALS
  156742. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  156743. extern void * malloc JPP((size_t size));
  156744. extern void free JPP((void *ptr));
  156745. #endif
  156746. GLOBAL(void *)
  156747. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  156748. {
  156749. return (void *) malloc(sizeofobject);
  156750. }
  156751. GLOBAL(void)
  156752. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  156753. {
  156754. free(object);
  156755. }
  156756. GLOBAL(void FAR *)
  156757. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  156758. {
  156759. return (void FAR *) malloc(sizeofobject);
  156760. }
  156761. GLOBAL(void)
  156762. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  156763. {
  156764. free(object);
  156765. }
  156766. GLOBAL(long)
  156767. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  156768. long max_bytes_needed, long already_allocated)
  156769. {
  156770. return max_bytes_needed;
  156771. }
  156772. GLOBAL(void)
  156773. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  156774. long total_bytes_needed)
  156775. {
  156776. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  156777. }
  156778. GLOBAL(long)
  156779. jpeg_mem_init (j_common_ptr cinfo)
  156780. {
  156781. return 0; /* just set max_memory_to_use to 0 */
  156782. }
  156783. GLOBAL(void)
  156784. jpeg_mem_term (j_common_ptr cinfo)
  156785. {
  156786. }
  156787. /*** End of inlined file: jmemnobs.c ***/
  156788. /*** Start of inlined file: jquant1.c ***/
  156789. #define JPEG_INTERNALS
  156790. #ifdef QUANT_1PASS_SUPPORTED
  156791. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  156792. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  156793. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  156794. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  156795. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  156796. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  156797. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  156798. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  156799. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  156800. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  156801. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  156802. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  156803. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  156804. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  156805. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  156806. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  156807. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  156808. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  156809. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  156810. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  156811. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  156812. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  156813. };
  156814. #if BITS_IN_JSAMPLE == 8
  156815. typedef INT16 FSERROR; /* 16 bits should be enough */
  156816. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  156817. #else
  156818. typedef INT32 FSERROR; /* may need more than 16 bits */
  156819. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  156820. #endif
  156821. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  156822. #define MAX_Q_COMPS 4 /* max components I can handle */
  156823. typedef struct {
  156824. struct jpeg_color_quantizer pub; /* public fields */
  156825. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  156826. int sv_actual; /* number of entries in use */
  156827. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  156828. boolean is_padded; /* is the colorindex padded for odither? */
  156829. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  156830. int row_index; /* cur row's vertical index in dither matrix */
  156831. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  156832. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  156833. boolean on_odd_row; /* flag to remember which row we are on */
  156834. } my_cquantizer;
  156835. typedef my_cquantizer * my_cquantize_ptr;
  156836. LOCAL(int)
  156837. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  156838. {
  156839. int nc = cinfo->out_color_components; /* number of color components */
  156840. int max_colors = cinfo->desired_number_of_colors;
  156841. int total_colors, iroot, i, j;
  156842. boolean changed;
  156843. long temp;
  156844. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  156845. iroot = 1;
  156846. do {
  156847. iroot++;
  156848. temp = iroot; /* set temp = iroot ** nc */
  156849. for (i = 1; i < nc; i++)
  156850. temp *= iroot;
  156851. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  156852. iroot--; /* now iroot = floor(root) */
  156853. if (iroot < 2)
  156854. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  156855. total_colors = 1;
  156856. for (i = 0; i < nc; i++) {
  156857. Ncolors[i] = iroot;
  156858. total_colors *= iroot;
  156859. }
  156860. do {
  156861. changed = FALSE;
  156862. for (i = 0; i < nc; i++) {
  156863. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  156864. temp = total_colors / Ncolors[j];
  156865. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  156866. if (temp > (long) max_colors)
  156867. break; /* won't fit, done with this pass */
  156868. Ncolors[j]++; /* OK, apply the increment */
  156869. total_colors = (int) temp;
  156870. changed = TRUE;
  156871. }
  156872. } while (changed);
  156873. return total_colors;
  156874. }
  156875. LOCAL(int)
  156876. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156877. {
  156878. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  156879. }
  156880. LOCAL(int)
  156881. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156882. {
  156883. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  156884. }
  156885. LOCAL(void)
  156886. create_colormap (j_decompress_ptr cinfo)
  156887. {
  156888. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156889. JSAMPARRAY colormap; /* Created colormap */
  156890. int total_colors; /* Number of distinct output colors */
  156891. int i,j,k, nci, blksize, blkdist, ptr, val;
  156892. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  156893. if (cinfo->out_color_components == 3)
  156894. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  156895. total_colors, cquantize->Ncolors[0],
  156896. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  156897. else
  156898. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  156899. colormap = (*cinfo->mem->alloc_sarray)
  156900. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156901. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  156902. blkdist = total_colors;
  156903. for (i = 0; i < cinfo->out_color_components; i++) {
  156904. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156905. blksize = blkdist / nci;
  156906. for (j = 0; j < nci; j++) {
  156907. val = output_value(cinfo, i, j, nci-1);
  156908. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  156909. for (k = 0; k < blksize; k++)
  156910. colormap[i][ptr+k] = (JSAMPLE) val;
  156911. }
  156912. }
  156913. blkdist = blksize; /* blksize of this color is blkdist of next */
  156914. }
  156915. cquantize->sv_colormap = colormap;
  156916. cquantize->sv_actual = total_colors;
  156917. }
  156918. LOCAL(void)
  156919. create_colorindex (j_decompress_ptr cinfo)
  156920. {
  156921. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156922. JSAMPROW indexptr;
  156923. int i,j,k, nci, blksize, val, pad;
  156924. if (cinfo->dither_mode == JDITHER_ORDERED) {
  156925. pad = MAXJSAMPLE*2;
  156926. cquantize->is_padded = TRUE;
  156927. } else {
  156928. pad = 0;
  156929. cquantize->is_padded = FALSE;
  156930. }
  156931. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  156932. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156933. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  156934. (JDIMENSION) cinfo->out_color_components);
  156935. blksize = cquantize->sv_actual;
  156936. for (i = 0; i < cinfo->out_color_components; i++) {
  156937. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156938. blksize = blksize / nci;
  156939. if (pad)
  156940. cquantize->colorindex[i] += MAXJSAMPLE;
  156941. indexptr = cquantize->colorindex[i];
  156942. val = 0;
  156943. k = largest_input_value(cinfo, i, 0, nci-1);
  156944. for (j = 0; j <= MAXJSAMPLE; j++) {
  156945. while (j > k) /* advance val if past boundary */
  156946. k = largest_input_value(cinfo, i, ++val, nci-1);
  156947. indexptr[j] = (JSAMPLE) (val * blksize);
  156948. }
  156949. if (pad)
  156950. for (j = 1; j <= MAXJSAMPLE; j++) {
  156951. indexptr[-j] = indexptr[0];
  156952. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  156953. }
  156954. }
  156955. }
  156956. LOCAL(ODITHER_MATRIX_PTR)
  156957. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  156958. {
  156959. ODITHER_MATRIX_PTR odither;
  156960. int j,k;
  156961. INT32 num,den;
  156962. odither = (ODITHER_MATRIX_PTR)
  156963. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156964. SIZEOF(ODITHER_MATRIX));
  156965. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  156966. for (j = 0; j < ODITHER_SIZE; j++) {
  156967. for (k = 0; k < ODITHER_SIZE; k++) {
  156968. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  156969. * MAXJSAMPLE;
  156970. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  156971. }
  156972. }
  156973. return odither;
  156974. }
  156975. LOCAL(void)
  156976. create_odither_tables (j_decompress_ptr cinfo)
  156977. {
  156978. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156979. ODITHER_MATRIX_PTR odither;
  156980. int i, j, nci;
  156981. for (i = 0; i < cinfo->out_color_components; i++) {
  156982. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156983. odither = NULL; /* search for matching prior component */
  156984. for (j = 0; j < i; j++) {
  156985. if (nci == cquantize->Ncolors[j]) {
  156986. odither = cquantize->odither[j];
  156987. break;
  156988. }
  156989. }
  156990. if (odither == NULL) /* need a new table? */
  156991. odither = make_odither_array(cinfo, nci);
  156992. cquantize->odither[i] = odither;
  156993. }
  156994. }
  156995. METHODDEF(void)
  156996. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156997. JSAMPARRAY output_buf, int num_rows)
  156998. {
  156999. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157000. JSAMPARRAY colorindex = cquantize->colorindex;
  157001. register int pixcode, ci;
  157002. register JSAMPROW ptrin, ptrout;
  157003. int row;
  157004. JDIMENSION col;
  157005. JDIMENSION width = cinfo->output_width;
  157006. register int nc = cinfo->out_color_components;
  157007. for (row = 0; row < num_rows; row++) {
  157008. ptrin = input_buf[row];
  157009. ptrout = output_buf[row];
  157010. for (col = width; col > 0; col--) {
  157011. pixcode = 0;
  157012. for (ci = 0; ci < nc; ci++) {
  157013. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157014. }
  157015. *ptrout++ = (JSAMPLE) pixcode;
  157016. }
  157017. }
  157018. }
  157019. METHODDEF(void)
  157020. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157021. JSAMPARRAY output_buf, int num_rows)
  157022. {
  157023. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157024. register int pixcode;
  157025. register JSAMPROW ptrin, ptrout;
  157026. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157027. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157028. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157029. int row;
  157030. JDIMENSION col;
  157031. JDIMENSION width = cinfo->output_width;
  157032. for (row = 0; row < num_rows; row++) {
  157033. ptrin = input_buf[row];
  157034. ptrout = output_buf[row];
  157035. for (col = width; col > 0; col--) {
  157036. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157037. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157038. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157039. *ptrout++ = (JSAMPLE) pixcode;
  157040. }
  157041. }
  157042. }
  157043. METHODDEF(void)
  157044. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157045. JSAMPARRAY output_buf, int num_rows)
  157046. {
  157047. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157048. register JSAMPROW input_ptr;
  157049. register JSAMPROW output_ptr;
  157050. JSAMPROW colorindex_ci;
  157051. int * dither; /* points to active row of dither matrix */
  157052. int row_index, col_index; /* current indexes into dither matrix */
  157053. int nc = cinfo->out_color_components;
  157054. int ci;
  157055. int row;
  157056. JDIMENSION col;
  157057. JDIMENSION width = cinfo->output_width;
  157058. for (row = 0; row < num_rows; row++) {
  157059. jzero_far((void FAR *) output_buf[row],
  157060. (size_t) (width * SIZEOF(JSAMPLE)));
  157061. row_index = cquantize->row_index;
  157062. for (ci = 0; ci < nc; ci++) {
  157063. input_ptr = input_buf[row] + ci;
  157064. output_ptr = output_buf[row];
  157065. colorindex_ci = cquantize->colorindex[ci];
  157066. dither = cquantize->odither[ci][row_index];
  157067. col_index = 0;
  157068. for (col = width; col > 0; col--) {
  157069. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157070. input_ptr += nc;
  157071. output_ptr++;
  157072. col_index = (col_index + 1) & ODITHER_MASK;
  157073. }
  157074. }
  157075. row_index = (row_index + 1) & ODITHER_MASK;
  157076. cquantize->row_index = row_index;
  157077. }
  157078. }
  157079. METHODDEF(void)
  157080. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157081. JSAMPARRAY output_buf, int num_rows)
  157082. {
  157083. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157084. register int pixcode;
  157085. register JSAMPROW input_ptr;
  157086. register JSAMPROW output_ptr;
  157087. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157088. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157089. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157090. int * dither0; /* points to active row of dither matrix */
  157091. int * dither1;
  157092. int * dither2;
  157093. int row_index, col_index; /* current indexes into dither matrix */
  157094. int row;
  157095. JDIMENSION col;
  157096. JDIMENSION width = cinfo->output_width;
  157097. for (row = 0; row < num_rows; row++) {
  157098. row_index = cquantize->row_index;
  157099. input_ptr = input_buf[row];
  157100. output_ptr = output_buf[row];
  157101. dither0 = cquantize->odither[0][row_index];
  157102. dither1 = cquantize->odither[1][row_index];
  157103. dither2 = cquantize->odither[2][row_index];
  157104. col_index = 0;
  157105. for (col = width; col > 0; col--) {
  157106. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157107. dither0[col_index]]);
  157108. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157109. dither1[col_index]]);
  157110. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157111. dither2[col_index]]);
  157112. *output_ptr++ = (JSAMPLE) pixcode;
  157113. col_index = (col_index + 1) & ODITHER_MASK;
  157114. }
  157115. row_index = (row_index + 1) & ODITHER_MASK;
  157116. cquantize->row_index = row_index;
  157117. }
  157118. }
  157119. METHODDEF(void)
  157120. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157121. JSAMPARRAY output_buf, int num_rows)
  157122. {
  157123. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157124. register LOCFSERROR cur; /* current error or pixel value */
  157125. LOCFSERROR belowerr; /* error for pixel below cur */
  157126. LOCFSERROR bpreverr; /* error for below/prev col */
  157127. LOCFSERROR bnexterr; /* error for below/next col */
  157128. LOCFSERROR delta;
  157129. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157130. register JSAMPROW input_ptr;
  157131. register JSAMPROW output_ptr;
  157132. JSAMPROW colorindex_ci;
  157133. JSAMPROW colormap_ci;
  157134. int pixcode;
  157135. int nc = cinfo->out_color_components;
  157136. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157137. int dirnc; /* dir * nc */
  157138. int ci;
  157139. int row;
  157140. JDIMENSION col;
  157141. JDIMENSION width = cinfo->output_width;
  157142. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157143. SHIFT_TEMPS
  157144. for (row = 0; row < num_rows; row++) {
  157145. jzero_far((void FAR *) output_buf[row],
  157146. (size_t) (width * SIZEOF(JSAMPLE)));
  157147. for (ci = 0; ci < nc; ci++) {
  157148. input_ptr = input_buf[row] + ci;
  157149. output_ptr = output_buf[row];
  157150. if (cquantize->on_odd_row) {
  157151. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157152. output_ptr += width-1;
  157153. dir = -1;
  157154. dirnc = -nc;
  157155. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157156. } else {
  157157. dir = 1;
  157158. dirnc = nc;
  157159. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157160. }
  157161. colorindex_ci = cquantize->colorindex[ci];
  157162. colormap_ci = cquantize->sv_colormap[ci];
  157163. cur = 0;
  157164. belowerr = bpreverr = 0;
  157165. for (col = width; col > 0; col--) {
  157166. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157167. cur += GETJSAMPLE(*input_ptr);
  157168. cur = GETJSAMPLE(range_limit[cur]);
  157169. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157170. *output_ptr += (JSAMPLE) pixcode;
  157171. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157172. bnexterr = cur;
  157173. delta = cur * 2;
  157174. cur += delta; /* form error * 3 */
  157175. errorptr[0] = (FSERROR) (bpreverr + cur);
  157176. cur += delta; /* form error * 5 */
  157177. bpreverr = belowerr + cur;
  157178. belowerr = bnexterr;
  157179. cur += delta; /* form error * 7 */
  157180. input_ptr += dirnc; /* advance input ptr to next column */
  157181. output_ptr += dir; /* advance output ptr to next column */
  157182. errorptr += dir; /* advance errorptr to current column */
  157183. }
  157184. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157185. }
  157186. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157187. }
  157188. }
  157189. LOCAL(void)
  157190. alloc_fs_workspace (j_decompress_ptr cinfo)
  157191. {
  157192. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157193. size_t arraysize;
  157194. int i;
  157195. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157196. for (i = 0; i < cinfo->out_color_components; i++) {
  157197. cquantize->fserrors[i] = (FSERRPTR)
  157198. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157199. }
  157200. }
  157201. METHODDEF(void)
  157202. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157203. {
  157204. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157205. size_t arraysize;
  157206. int i;
  157207. cinfo->colormap = cquantize->sv_colormap;
  157208. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157209. switch (cinfo->dither_mode) {
  157210. case JDITHER_NONE:
  157211. if (cinfo->out_color_components == 3)
  157212. cquantize->pub.color_quantize = color_quantize3;
  157213. else
  157214. cquantize->pub.color_quantize = color_quantize;
  157215. break;
  157216. case JDITHER_ORDERED:
  157217. if (cinfo->out_color_components == 3)
  157218. cquantize->pub.color_quantize = quantize3_ord_dither;
  157219. else
  157220. cquantize->pub.color_quantize = quantize_ord_dither;
  157221. cquantize->row_index = 0; /* initialize state for ordered dither */
  157222. if (! cquantize->is_padded)
  157223. create_colorindex(cinfo);
  157224. if (cquantize->odither[0] == NULL)
  157225. create_odither_tables(cinfo);
  157226. break;
  157227. case JDITHER_FS:
  157228. cquantize->pub.color_quantize = quantize_fs_dither;
  157229. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157230. if (cquantize->fserrors[0] == NULL)
  157231. alloc_fs_workspace(cinfo);
  157232. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157233. for (i = 0; i < cinfo->out_color_components; i++)
  157234. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157235. break;
  157236. default:
  157237. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157238. break;
  157239. }
  157240. }
  157241. METHODDEF(void)
  157242. finish_pass_1_quant (j_decompress_ptr cinfo)
  157243. {
  157244. }
  157245. METHODDEF(void)
  157246. new_color_map_1_quant (j_decompress_ptr cinfo)
  157247. {
  157248. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157249. }
  157250. GLOBAL(void)
  157251. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157252. {
  157253. my_cquantize_ptr cquantize;
  157254. cquantize = (my_cquantize_ptr)
  157255. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157256. SIZEOF(my_cquantizer));
  157257. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157258. cquantize->pub.start_pass = start_pass_1_quant;
  157259. cquantize->pub.finish_pass = finish_pass_1_quant;
  157260. cquantize->pub.new_color_map = new_color_map_1_quant;
  157261. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157262. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157263. if (cinfo->out_color_components > MAX_Q_COMPS)
  157264. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157265. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157266. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157267. create_colormap(cinfo);
  157268. create_colorindex(cinfo);
  157269. if (cinfo->dither_mode == JDITHER_FS)
  157270. alloc_fs_workspace(cinfo);
  157271. }
  157272. #endif /* QUANT_1PASS_SUPPORTED */
  157273. /*** End of inlined file: jquant1.c ***/
  157274. /*** Start of inlined file: jquant2.c ***/
  157275. #define JPEG_INTERNALS
  157276. #ifdef QUANT_2PASS_SUPPORTED
  157277. #define R_SCALE 2 /* scale R distances by this much */
  157278. #define G_SCALE 3 /* scale G distances by this much */
  157279. #define B_SCALE 1 /* and B by this much */
  157280. #if RGB_RED == 0
  157281. #define C0_SCALE R_SCALE
  157282. #endif
  157283. #if RGB_BLUE == 0
  157284. #define C0_SCALE B_SCALE
  157285. #endif
  157286. #if RGB_GREEN == 1
  157287. #define C1_SCALE G_SCALE
  157288. #endif
  157289. #if RGB_RED == 2
  157290. #define C2_SCALE R_SCALE
  157291. #endif
  157292. #if RGB_BLUE == 2
  157293. #define C2_SCALE B_SCALE
  157294. #endif
  157295. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157296. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157297. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157298. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157299. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157300. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157301. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157302. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157303. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157304. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157305. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157306. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157307. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157308. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157309. typedef hist2d * hist3d; /* type for top-level pointer */
  157310. #if BITS_IN_JSAMPLE == 8
  157311. typedef INT16 FSERROR; /* 16 bits should be enough */
  157312. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157313. #else
  157314. typedef INT32 FSERROR; /* may need more than 16 bits */
  157315. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157316. #endif
  157317. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157318. typedef struct {
  157319. struct jpeg_color_quantizer pub; /* public fields */
  157320. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157321. int desired; /* desired # of colors = size of colormap */
  157322. hist3d histogram; /* pointer to the histogram */
  157323. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157324. FSERRPTR fserrors; /* accumulated errors */
  157325. boolean on_odd_row; /* flag to remember which row we are on */
  157326. int * error_limiter; /* table for clamping the applied error */
  157327. } my_cquantizer2;
  157328. typedef my_cquantizer2 * my_cquantize_ptr2;
  157329. METHODDEF(void)
  157330. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157331. JSAMPARRAY output_buf, int num_rows)
  157332. {
  157333. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157334. register JSAMPROW ptr;
  157335. register histptr histp;
  157336. register hist3d histogram = cquantize->histogram;
  157337. int row;
  157338. JDIMENSION col;
  157339. JDIMENSION width = cinfo->output_width;
  157340. for (row = 0; row < num_rows; row++) {
  157341. ptr = input_buf[row];
  157342. for (col = width; col > 0; col--) {
  157343. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157344. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157345. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157346. if (++(*histp) <= 0)
  157347. (*histp)--;
  157348. ptr += 3;
  157349. }
  157350. }
  157351. }
  157352. typedef struct {
  157353. int c0min, c0max;
  157354. int c1min, c1max;
  157355. int c2min, c2max;
  157356. INT32 volume;
  157357. long colorcount;
  157358. } box;
  157359. typedef box * boxptr;
  157360. LOCAL(boxptr)
  157361. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157362. {
  157363. register boxptr boxp;
  157364. register int i;
  157365. register long maxc = 0;
  157366. boxptr which = NULL;
  157367. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157368. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157369. which = boxp;
  157370. maxc = boxp->colorcount;
  157371. }
  157372. }
  157373. return which;
  157374. }
  157375. LOCAL(boxptr)
  157376. find_biggest_volume (boxptr boxlist, int numboxes)
  157377. {
  157378. register boxptr boxp;
  157379. register int i;
  157380. register INT32 maxv = 0;
  157381. boxptr which = NULL;
  157382. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157383. if (boxp->volume > maxv) {
  157384. which = boxp;
  157385. maxv = boxp->volume;
  157386. }
  157387. }
  157388. return which;
  157389. }
  157390. LOCAL(void)
  157391. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157392. {
  157393. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157394. hist3d histogram = cquantize->histogram;
  157395. histptr histp;
  157396. int c0,c1,c2;
  157397. int c0min,c0max,c1min,c1max,c2min,c2max;
  157398. INT32 dist0,dist1,dist2;
  157399. long ccount;
  157400. c0min = boxp->c0min; c0max = boxp->c0max;
  157401. c1min = boxp->c1min; c1max = boxp->c1max;
  157402. c2min = boxp->c2min; c2max = boxp->c2max;
  157403. if (c0max > c0min)
  157404. for (c0 = c0min; c0 <= c0max; c0++)
  157405. for (c1 = c1min; c1 <= c1max; c1++) {
  157406. histp = & histogram[c0][c1][c2min];
  157407. for (c2 = c2min; c2 <= c2max; c2++)
  157408. if (*histp++ != 0) {
  157409. boxp->c0min = c0min = c0;
  157410. goto have_c0min;
  157411. }
  157412. }
  157413. have_c0min:
  157414. if (c0max > c0min)
  157415. for (c0 = c0max; c0 >= c0min; c0--)
  157416. for (c1 = c1min; c1 <= c1max; c1++) {
  157417. histp = & histogram[c0][c1][c2min];
  157418. for (c2 = c2min; c2 <= c2max; c2++)
  157419. if (*histp++ != 0) {
  157420. boxp->c0max = c0max = c0;
  157421. goto have_c0max;
  157422. }
  157423. }
  157424. have_c0max:
  157425. if (c1max > c1min)
  157426. for (c1 = c1min; c1 <= c1max; c1++)
  157427. for (c0 = c0min; c0 <= c0max; c0++) {
  157428. histp = & histogram[c0][c1][c2min];
  157429. for (c2 = c2min; c2 <= c2max; c2++)
  157430. if (*histp++ != 0) {
  157431. boxp->c1min = c1min = c1;
  157432. goto have_c1min;
  157433. }
  157434. }
  157435. have_c1min:
  157436. if (c1max > c1min)
  157437. for (c1 = c1max; c1 >= c1min; c1--)
  157438. for (c0 = c0min; c0 <= c0max; c0++) {
  157439. histp = & histogram[c0][c1][c2min];
  157440. for (c2 = c2min; c2 <= c2max; c2++)
  157441. if (*histp++ != 0) {
  157442. boxp->c1max = c1max = c1;
  157443. goto have_c1max;
  157444. }
  157445. }
  157446. have_c1max:
  157447. if (c2max > c2min)
  157448. for (c2 = c2min; c2 <= c2max; c2++)
  157449. for (c0 = c0min; c0 <= c0max; c0++) {
  157450. histp = & histogram[c0][c1min][c2];
  157451. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157452. if (*histp != 0) {
  157453. boxp->c2min = c2min = c2;
  157454. goto have_c2min;
  157455. }
  157456. }
  157457. have_c2min:
  157458. if (c2max > c2min)
  157459. for (c2 = c2max; c2 >= c2min; c2--)
  157460. for (c0 = c0min; c0 <= c0max; c0++) {
  157461. histp = & histogram[c0][c1min][c2];
  157462. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157463. if (*histp != 0) {
  157464. boxp->c2max = c2max = c2;
  157465. goto have_c2max;
  157466. }
  157467. }
  157468. have_c2max:
  157469. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157470. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157471. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157472. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157473. ccount = 0;
  157474. for (c0 = c0min; c0 <= c0max; c0++)
  157475. for (c1 = c1min; c1 <= c1max; c1++) {
  157476. histp = & histogram[c0][c1][c2min];
  157477. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157478. if (*histp != 0) {
  157479. ccount++;
  157480. }
  157481. }
  157482. boxp->colorcount = ccount;
  157483. }
  157484. LOCAL(int)
  157485. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157486. int desired_colors)
  157487. {
  157488. int n,lb;
  157489. int c0,c1,c2,cmax;
  157490. register boxptr b1,b2;
  157491. while (numboxes < desired_colors) {
  157492. if (numboxes*2 <= desired_colors) {
  157493. b1 = find_biggest_color_pop(boxlist, numboxes);
  157494. } else {
  157495. b1 = find_biggest_volume(boxlist, numboxes);
  157496. }
  157497. if (b1 == NULL) /* no splittable boxes left! */
  157498. break;
  157499. b2 = &boxlist[numboxes]; /* where new box will go */
  157500. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157501. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157502. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157503. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157504. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157505. #if RGB_RED == 0
  157506. cmax = c1; n = 1;
  157507. if (c0 > cmax) { cmax = c0; n = 0; }
  157508. if (c2 > cmax) { n = 2; }
  157509. #else
  157510. cmax = c1; n = 1;
  157511. if (c2 > cmax) { cmax = c2; n = 2; }
  157512. if (c0 > cmax) { n = 0; }
  157513. #endif
  157514. switch (n) {
  157515. case 0:
  157516. lb = (b1->c0max + b1->c0min) / 2;
  157517. b1->c0max = lb;
  157518. b2->c0min = lb+1;
  157519. break;
  157520. case 1:
  157521. lb = (b1->c1max + b1->c1min) / 2;
  157522. b1->c1max = lb;
  157523. b2->c1min = lb+1;
  157524. break;
  157525. case 2:
  157526. lb = (b1->c2max + b1->c2min) / 2;
  157527. b1->c2max = lb;
  157528. b2->c2min = lb+1;
  157529. break;
  157530. }
  157531. update_box(cinfo, b1);
  157532. update_box(cinfo, b2);
  157533. numboxes++;
  157534. }
  157535. return numboxes;
  157536. }
  157537. LOCAL(void)
  157538. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  157539. {
  157540. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157541. hist3d histogram = cquantize->histogram;
  157542. histptr histp;
  157543. int c0,c1,c2;
  157544. int c0min,c0max,c1min,c1max,c2min,c2max;
  157545. long count;
  157546. long total = 0;
  157547. long c0total = 0;
  157548. long c1total = 0;
  157549. long c2total = 0;
  157550. c0min = boxp->c0min; c0max = boxp->c0max;
  157551. c1min = boxp->c1min; c1max = boxp->c1max;
  157552. c2min = boxp->c2min; c2max = boxp->c2max;
  157553. for (c0 = c0min; c0 <= c0max; c0++)
  157554. for (c1 = c1min; c1 <= c1max; c1++) {
  157555. histp = & histogram[c0][c1][c2min];
  157556. for (c2 = c2min; c2 <= c2max; c2++) {
  157557. if ((count = *histp++) != 0) {
  157558. total += count;
  157559. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  157560. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  157561. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  157562. }
  157563. }
  157564. }
  157565. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  157566. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  157567. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  157568. }
  157569. LOCAL(void)
  157570. select_colors (j_decompress_ptr cinfo, int desired_colors)
  157571. {
  157572. boxptr boxlist;
  157573. int numboxes;
  157574. int i;
  157575. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  157576. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  157577. numboxes = 1;
  157578. boxlist[0].c0min = 0;
  157579. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  157580. boxlist[0].c1min = 0;
  157581. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  157582. boxlist[0].c2min = 0;
  157583. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  157584. update_box(cinfo, & boxlist[0]);
  157585. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  157586. for (i = 0; i < numboxes; i++)
  157587. compute_color(cinfo, & boxlist[i], i);
  157588. cinfo->actual_number_of_colors = numboxes;
  157589. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  157590. }
  157591. #define BOX_C0_LOG (HIST_C0_BITS-3)
  157592. #define BOX_C1_LOG (HIST_C1_BITS-3)
  157593. #define BOX_C2_LOG (HIST_C2_BITS-3)
  157594. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  157595. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  157596. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  157597. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  157598. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  157599. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  157600. LOCAL(int)
  157601. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157602. JSAMPLE colorlist[])
  157603. {
  157604. int numcolors = cinfo->actual_number_of_colors;
  157605. int maxc0, maxc1, maxc2;
  157606. int centerc0, centerc1, centerc2;
  157607. int i, x, ncolors;
  157608. INT32 minmaxdist, min_dist, max_dist, tdist;
  157609. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  157610. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  157611. centerc0 = (minc0 + maxc0) >> 1;
  157612. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  157613. centerc1 = (minc1 + maxc1) >> 1;
  157614. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  157615. centerc2 = (minc2 + maxc2) >> 1;
  157616. minmaxdist = 0x7FFFFFFFL;
  157617. for (i = 0; i < numcolors; i++) {
  157618. x = GETJSAMPLE(cinfo->colormap[0][i]);
  157619. if (x < minc0) {
  157620. tdist = (x - minc0) * C0_SCALE;
  157621. min_dist = tdist*tdist;
  157622. tdist = (x - maxc0) * C0_SCALE;
  157623. max_dist = tdist*tdist;
  157624. } else if (x > maxc0) {
  157625. tdist = (x - maxc0) * C0_SCALE;
  157626. min_dist = tdist*tdist;
  157627. tdist = (x - minc0) * C0_SCALE;
  157628. max_dist = tdist*tdist;
  157629. } else {
  157630. min_dist = 0;
  157631. if (x <= centerc0) {
  157632. tdist = (x - maxc0) * C0_SCALE;
  157633. max_dist = tdist*tdist;
  157634. } else {
  157635. tdist = (x - minc0) * C0_SCALE;
  157636. max_dist = tdist*tdist;
  157637. }
  157638. }
  157639. x = GETJSAMPLE(cinfo->colormap[1][i]);
  157640. if (x < minc1) {
  157641. tdist = (x - minc1) * C1_SCALE;
  157642. min_dist += tdist*tdist;
  157643. tdist = (x - maxc1) * C1_SCALE;
  157644. max_dist += tdist*tdist;
  157645. } else if (x > maxc1) {
  157646. tdist = (x - maxc1) * C1_SCALE;
  157647. min_dist += tdist*tdist;
  157648. tdist = (x - minc1) * C1_SCALE;
  157649. max_dist += tdist*tdist;
  157650. } else {
  157651. if (x <= centerc1) {
  157652. tdist = (x - maxc1) * C1_SCALE;
  157653. max_dist += tdist*tdist;
  157654. } else {
  157655. tdist = (x - minc1) * C1_SCALE;
  157656. max_dist += tdist*tdist;
  157657. }
  157658. }
  157659. x = GETJSAMPLE(cinfo->colormap[2][i]);
  157660. if (x < minc2) {
  157661. tdist = (x - minc2) * C2_SCALE;
  157662. min_dist += tdist*tdist;
  157663. tdist = (x - maxc2) * C2_SCALE;
  157664. max_dist += tdist*tdist;
  157665. } else if (x > maxc2) {
  157666. tdist = (x - maxc2) * C2_SCALE;
  157667. min_dist += tdist*tdist;
  157668. tdist = (x - minc2) * C2_SCALE;
  157669. max_dist += tdist*tdist;
  157670. } else {
  157671. if (x <= centerc2) {
  157672. tdist = (x - maxc2) * C2_SCALE;
  157673. max_dist += tdist*tdist;
  157674. } else {
  157675. tdist = (x - minc2) * C2_SCALE;
  157676. max_dist += tdist*tdist;
  157677. }
  157678. }
  157679. mindist[i] = min_dist; /* save away the results */
  157680. if (max_dist < minmaxdist)
  157681. minmaxdist = max_dist;
  157682. }
  157683. ncolors = 0;
  157684. for (i = 0; i < numcolors; i++) {
  157685. if (mindist[i] <= minmaxdist)
  157686. colorlist[ncolors++] = (JSAMPLE) i;
  157687. }
  157688. return ncolors;
  157689. }
  157690. LOCAL(void)
  157691. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157692. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  157693. {
  157694. int ic0, ic1, ic2;
  157695. int i, icolor;
  157696. register INT32 * bptr; /* pointer into bestdist[] array */
  157697. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157698. INT32 dist0, dist1; /* initial distance values */
  157699. register INT32 dist2; /* current distance in inner loop */
  157700. INT32 xx0, xx1; /* distance increments */
  157701. register INT32 xx2;
  157702. INT32 inc0, inc1, inc2; /* initial values for increments */
  157703. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157704. bptr = bestdist;
  157705. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  157706. *bptr++ = 0x7FFFFFFFL;
  157707. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  157708. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  157709. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  157710. for (i = 0; i < numcolors; i++) {
  157711. icolor = GETJSAMPLE(colorlist[i]);
  157712. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  157713. dist0 = inc0*inc0;
  157714. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  157715. dist0 += inc1*inc1;
  157716. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  157717. dist0 += inc2*inc2;
  157718. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  157719. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  157720. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  157721. bptr = bestdist;
  157722. cptr = bestcolor;
  157723. xx0 = inc0;
  157724. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  157725. dist1 = dist0;
  157726. xx1 = inc1;
  157727. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  157728. dist2 = dist1;
  157729. xx2 = inc2;
  157730. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  157731. if (dist2 < *bptr) {
  157732. *bptr = dist2;
  157733. *cptr = (JSAMPLE) icolor;
  157734. }
  157735. dist2 += xx2;
  157736. xx2 += 2 * STEP_C2 * STEP_C2;
  157737. bptr++;
  157738. cptr++;
  157739. }
  157740. dist1 += xx1;
  157741. xx1 += 2 * STEP_C1 * STEP_C1;
  157742. }
  157743. dist0 += xx0;
  157744. xx0 += 2 * STEP_C0 * STEP_C0;
  157745. }
  157746. }
  157747. }
  157748. LOCAL(void)
  157749. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  157750. {
  157751. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157752. hist3d histogram = cquantize->histogram;
  157753. int minc0, minc1, minc2; /* lower left corner of update box */
  157754. int ic0, ic1, ic2;
  157755. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157756. register histptr cachep; /* pointer into main cache array */
  157757. JSAMPLE colorlist[MAXNUMCOLORS];
  157758. int numcolors; /* number of candidate colors */
  157759. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157760. c0 >>= BOX_C0_LOG;
  157761. c1 >>= BOX_C1_LOG;
  157762. c2 >>= BOX_C2_LOG;
  157763. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  157764. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  157765. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  157766. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  157767. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  157768. bestcolor);
  157769. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  157770. c1 <<= BOX_C1_LOG;
  157771. c2 <<= BOX_C2_LOG;
  157772. cptr = bestcolor;
  157773. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  157774. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  157775. cachep = & histogram[c0+ic0][c1+ic1][c2];
  157776. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  157777. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  157778. }
  157779. }
  157780. }
  157781. }
  157782. METHODDEF(void)
  157783. pass2_no_dither (j_decompress_ptr cinfo,
  157784. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157785. {
  157786. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157787. hist3d histogram = cquantize->histogram;
  157788. register JSAMPROW inptr, outptr;
  157789. register histptr cachep;
  157790. register int c0, c1, c2;
  157791. int row;
  157792. JDIMENSION col;
  157793. JDIMENSION width = cinfo->output_width;
  157794. for (row = 0; row < num_rows; row++) {
  157795. inptr = input_buf[row];
  157796. outptr = output_buf[row];
  157797. for (col = width; col > 0; col--) {
  157798. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  157799. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  157800. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  157801. cachep = & histogram[c0][c1][c2];
  157802. if (*cachep == 0)
  157803. fill_inverse_cmap(cinfo, c0,c1,c2);
  157804. *outptr++ = (JSAMPLE) (*cachep - 1);
  157805. }
  157806. }
  157807. }
  157808. METHODDEF(void)
  157809. pass2_fs_dither (j_decompress_ptr cinfo,
  157810. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157811. {
  157812. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157813. hist3d histogram = cquantize->histogram;
  157814. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  157815. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  157816. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  157817. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157818. JSAMPROW inptr; /* => current input pixel */
  157819. JSAMPROW outptr; /* => current output pixel */
  157820. histptr cachep;
  157821. int dir; /* +1 or -1 depending on direction */
  157822. int dir3; /* 3*dir, for advancing inptr & errorptr */
  157823. int row;
  157824. JDIMENSION col;
  157825. JDIMENSION width = cinfo->output_width;
  157826. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157827. int *error_limit = cquantize->error_limiter;
  157828. JSAMPROW colormap0 = cinfo->colormap[0];
  157829. JSAMPROW colormap1 = cinfo->colormap[1];
  157830. JSAMPROW colormap2 = cinfo->colormap[2];
  157831. SHIFT_TEMPS
  157832. for (row = 0; row < num_rows; row++) {
  157833. inptr = input_buf[row];
  157834. outptr = output_buf[row];
  157835. if (cquantize->on_odd_row) {
  157836. inptr += (width-1) * 3; /* so point to rightmost pixel */
  157837. outptr += width-1;
  157838. dir = -1;
  157839. dir3 = -3;
  157840. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  157841. cquantize->on_odd_row = FALSE; /* flip for next time */
  157842. } else {
  157843. dir = 1;
  157844. dir3 = 3;
  157845. errorptr = cquantize->fserrors; /* => entry before first real column */
  157846. cquantize->on_odd_row = TRUE; /* flip for next time */
  157847. }
  157848. cur0 = cur1 = cur2 = 0;
  157849. belowerr0 = belowerr1 = belowerr2 = 0;
  157850. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  157851. for (col = width; col > 0; col--) {
  157852. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  157853. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  157854. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  157855. cur0 = error_limit[cur0];
  157856. cur1 = error_limit[cur1];
  157857. cur2 = error_limit[cur2];
  157858. cur0 += GETJSAMPLE(inptr[0]);
  157859. cur1 += GETJSAMPLE(inptr[1]);
  157860. cur2 += GETJSAMPLE(inptr[2]);
  157861. cur0 = GETJSAMPLE(range_limit[cur0]);
  157862. cur1 = GETJSAMPLE(range_limit[cur1]);
  157863. cur2 = GETJSAMPLE(range_limit[cur2]);
  157864. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  157865. if (*cachep == 0)
  157866. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  157867. { register int pixcode = *cachep - 1;
  157868. *outptr = (JSAMPLE) pixcode;
  157869. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  157870. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  157871. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  157872. }
  157873. { register LOCFSERROR bnexterr, delta;
  157874. bnexterr = cur0; /* Process component 0 */
  157875. delta = cur0 * 2;
  157876. cur0 += delta; /* form error * 3 */
  157877. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  157878. cur0 += delta; /* form error * 5 */
  157879. bpreverr0 = belowerr0 + cur0;
  157880. belowerr0 = bnexterr;
  157881. cur0 += delta; /* form error * 7 */
  157882. bnexterr = cur1; /* Process component 1 */
  157883. delta = cur1 * 2;
  157884. cur1 += delta; /* form error * 3 */
  157885. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  157886. cur1 += delta; /* form error * 5 */
  157887. bpreverr1 = belowerr1 + cur1;
  157888. belowerr1 = bnexterr;
  157889. cur1 += delta; /* form error * 7 */
  157890. bnexterr = cur2; /* Process component 2 */
  157891. delta = cur2 * 2;
  157892. cur2 += delta; /* form error * 3 */
  157893. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  157894. cur2 += delta; /* form error * 5 */
  157895. bpreverr2 = belowerr2 + cur2;
  157896. belowerr2 = bnexterr;
  157897. cur2 += delta; /* form error * 7 */
  157898. }
  157899. inptr += dir3; /* Advance pixel pointers to next column */
  157900. outptr += dir;
  157901. errorptr += dir3; /* advance errorptr to current column */
  157902. }
  157903. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  157904. errorptr[1] = (FSERROR) bpreverr1;
  157905. errorptr[2] = (FSERROR) bpreverr2;
  157906. }
  157907. }
  157908. LOCAL(void)
  157909. init_error_limit (j_decompress_ptr cinfo)
  157910. {
  157911. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157912. int * table;
  157913. int in, out;
  157914. table = (int *) (*cinfo->mem->alloc_small)
  157915. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  157916. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  157917. cquantize->error_limiter = table;
  157918. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  157919. out = 0;
  157920. for (in = 0; in < STEPSIZE; in++, out++) {
  157921. table[in] = out; table[-in] = -out;
  157922. }
  157923. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  157924. table[in] = out; table[-in] = -out;
  157925. }
  157926. for (; in <= MAXJSAMPLE; in++) {
  157927. table[in] = out; table[-in] = -out;
  157928. }
  157929. #undef STEPSIZE
  157930. }
  157931. METHODDEF(void)
  157932. finish_pass1 (j_decompress_ptr cinfo)
  157933. {
  157934. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157935. cinfo->colormap = cquantize->sv_colormap;
  157936. select_colors(cinfo, cquantize->desired);
  157937. cquantize->needs_zeroed = TRUE;
  157938. }
  157939. METHODDEF(void)
  157940. finish_pass2 (j_decompress_ptr cinfo)
  157941. {
  157942. }
  157943. METHODDEF(void)
  157944. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157945. {
  157946. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157947. hist3d histogram = cquantize->histogram;
  157948. int i;
  157949. if (cinfo->dither_mode != JDITHER_NONE)
  157950. cinfo->dither_mode = JDITHER_FS;
  157951. if (is_pre_scan) {
  157952. cquantize->pub.color_quantize = prescan_quantize;
  157953. cquantize->pub.finish_pass = finish_pass1;
  157954. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  157955. } else {
  157956. if (cinfo->dither_mode == JDITHER_FS)
  157957. cquantize->pub.color_quantize = pass2_fs_dither;
  157958. else
  157959. cquantize->pub.color_quantize = pass2_no_dither;
  157960. cquantize->pub.finish_pass = finish_pass2;
  157961. i = cinfo->actual_number_of_colors;
  157962. if (i < 1)
  157963. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  157964. if (i > MAXNUMCOLORS)
  157965. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  157966. if (cinfo->dither_mode == JDITHER_FS) {
  157967. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  157968. (3 * SIZEOF(FSERROR)));
  157969. if (cquantize->fserrors == NULL)
  157970. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  157971. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157972. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  157973. if (cquantize->error_limiter == NULL)
  157974. init_error_limit(cinfo);
  157975. cquantize->on_odd_row = FALSE;
  157976. }
  157977. }
  157978. if (cquantize->needs_zeroed) {
  157979. for (i = 0; i < HIST_C0_ELEMS; i++) {
  157980. jzero_far((void FAR *) histogram[i],
  157981. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  157982. }
  157983. cquantize->needs_zeroed = FALSE;
  157984. }
  157985. }
  157986. METHODDEF(void)
  157987. new_color_map_2_quant (j_decompress_ptr cinfo)
  157988. {
  157989. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157990. cquantize->needs_zeroed = TRUE;
  157991. }
  157992. GLOBAL(void)
  157993. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  157994. {
  157995. my_cquantize_ptr2 cquantize;
  157996. int i;
  157997. cquantize = (my_cquantize_ptr2)
  157998. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157999. SIZEOF(my_cquantizer2));
  158000. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158001. cquantize->pub.start_pass = start_pass_2_quant;
  158002. cquantize->pub.new_color_map = new_color_map_2_quant;
  158003. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  158004. cquantize->error_limiter = NULL;
  158005. if (cinfo->out_color_components != 3)
  158006. ERREXIT(cinfo, JERR_NOTIMPL);
  158007. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  158008. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  158009. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158010. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158011. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158012. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158013. }
  158014. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158015. if (cinfo->enable_2pass_quant) {
  158016. int desired = cinfo->desired_number_of_colors;
  158017. if (desired < 8)
  158018. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158019. if (desired > MAXNUMCOLORS)
  158020. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158021. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158022. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158023. cquantize->desired = desired;
  158024. } else
  158025. cquantize->sv_colormap = NULL;
  158026. if (cinfo->dither_mode != JDITHER_NONE)
  158027. cinfo->dither_mode = JDITHER_FS;
  158028. if (cinfo->dither_mode == JDITHER_FS) {
  158029. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158030. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158031. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158032. init_error_limit(cinfo);
  158033. }
  158034. }
  158035. #endif /* QUANT_2PASS_SUPPORTED */
  158036. /*** End of inlined file: jquant2.c ***/
  158037. /*** Start of inlined file: jutils.c ***/
  158038. #define JPEG_INTERNALS
  158039. #if 0 /* This table is not actually needed in v6a */
  158040. const int jpeg_zigzag_order[DCTSIZE2] = {
  158041. 0, 1, 5, 6, 14, 15, 27, 28,
  158042. 2, 4, 7, 13, 16, 26, 29, 42,
  158043. 3, 8, 12, 17, 25, 30, 41, 43,
  158044. 9, 11, 18, 24, 31, 40, 44, 53,
  158045. 10, 19, 23, 32, 39, 45, 52, 54,
  158046. 20, 22, 33, 38, 46, 51, 55, 60,
  158047. 21, 34, 37, 47, 50, 56, 59, 61,
  158048. 35, 36, 48, 49, 57, 58, 62, 63
  158049. };
  158050. #endif
  158051. const int jpeg_natural_order[DCTSIZE2+16] = {
  158052. 0, 1, 8, 16, 9, 2, 3, 10,
  158053. 17, 24, 32, 25, 18, 11, 4, 5,
  158054. 12, 19, 26, 33, 40, 48, 41, 34,
  158055. 27, 20, 13, 6, 7, 14, 21, 28,
  158056. 35, 42, 49, 56, 57, 50, 43, 36,
  158057. 29, 22, 15, 23, 30, 37, 44, 51,
  158058. 58, 59, 52, 45, 38, 31, 39, 46,
  158059. 53, 60, 61, 54, 47, 55, 62, 63,
  158060. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158061. 63, 63, 63, 63, 63, 63, 63, 63
  158062. };
  158063. GLOBAL(long)
  158064. jdiv_round_up (long a, long b)
  158065. {
  158066. return (a + b - 1L) / b;
  158067. }
  158068. GLOBAL(long)
  158069. jround_up (long a, long b)
  158070. {
  158071. a += b - 1L;
  158072. return a - (a % b);
  158073. }
  158074. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158075. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158076. #define FMEMZERO(target,size) MEMZERO(target,size)
  158077. #else /* 80x86 case, define if we can */
  158078. #ifdef USE_FMEM
  158079. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158080. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158081. #endif
  158082. #endif
  158083. GLOBAL(void)
  158084. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158085. JSAMPARRAY output_array, int dest_row,
  158086. int num_rows, JDIMENSION num_cols)
  158087. {
  158088. register JSAMPROW inptr, outptr;
  158089. #ifdef FMEMCOPY
  158090. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158091. #else
  158092. register JDIMENSION count;
  158093. #endif
  158094. register int row;
  158095. input_array += source_row;
  158096. output_array += dest_row;
  158097. for (row = num_rows; row > 0; row--) {
  158098. inptr = *input_array++;
  158099. outptr = *output_array++;
  158100. #ifdef FMEMCOPY
  158101. FMEMCOPY(outptr, inptr, count);
  158102. #else
  158103. for (count = num_cols; count > 0; count--)
  158104. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158105. #endif
  158106. }
  158107. }
  158108. GLOBAL(void)
  158109. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158110. JDIMENSION num_blocks)
  158111. {
  158112. #ifdef FMEMCOPY
  158113. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158114. #else
  158115. register JCOEFPTR inptr, outptr;
  158116. register long count;
  158117. inptr = (JCOEFPTR) input_row;
  158118. outptr = (JCOEFPTR) output_row;
  158119. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158120. *outptr++ = *inptr++;
  158121. }
  158122. #endif
  158123. }
  158124. GLOBAL(void)
  158125. jzero_far (void FAR * target, size_t bytestozero)
  158126. {
  158127. #ifdef FMEMZERO
  158128. FMEMZERO(target, bytestozero);
  158129. #else
  158130. register char FAR * ptr = (char FAR *) target;
  158131. register size_t count;
  158132. for (count = bytestozero; count > 0; count--) {
  158133. *ptr++ = 0;
  158134. }
  158135. #endif
  158136. }
  158137. /*** End of inlined file: jutils.c ***/
  158138. /*** Start of inlined file: transupp.c ***/
  158139. #define JPEG_INTERNALS
  158140. /*** Start of inlined file: transupp.h ***/
  158141. #ifndef TRANSFORMS_SUPPORTED
  158142. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158143. #endif
  158144. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158145. #define jtransform_request_workspace jTrRequest
  158146. #define jtransform_adjust_parameters jTrAdjust
  158147. #define jtransform_execute_transformation jTrExec
  158148. #define jcopy_markers_setup jCMrkSetup
  158149. #define jcopy_markers_execute jCMrkExec
  158150. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158151. typedef enum {
  158152. JXFORM_NONE, /* no transformation */
  158153. JXFORM_FLIP_H, /* horizontal flip */
  158154. JXFORM_FLIP_V, /* vertical flip */
  158155. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158156. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158157. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158158. JXFORM_ROT_180, /* 180-degree rotation */
  158159. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158160. } JXFORM_CODE;
  158161. typedef struct {
  158162. JXFORM_CODE transform; /* image transform operator */
  158163. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158164. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158165. int num_components; /* # of components in workspace */
  158166. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158167. } jpeg_transform_info;
  158168. #if TRANSFORMS_SUPPORTED
  158169. EXTERN(void) jtransform_request_workspace
  158170. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158171. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158172. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158173. jvirt_barray_ptr *src_coef_arrays,
  158174. jpeg_transform_info *info));
  158175. EXTERN(void) jtransform_execute_transformation
  158176. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158177. jvirt_barray_ptr *src_coef_arrays,
  158178. jpeg_transform_info *info));
  158179. #endif /* TRANSFORMS_SUPPORTED */
  158180. typedef enum {
  158181. JCOPYOPT_NONE, /* copy no optional markers */
  158182. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158183. JCOPYOPT_ALL /* copy all optional markers */
  158184. } JCOPY_OPTION;
  158185. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158186. EXTERN(void) jcopy_markers_setup
  158187. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158188. EXTERN(void) jcopy_markers_execute
  158189. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158190. JCOPY_OPTION option));
  158191. /*** End of inlined file: transupp.h ***/
  158192. /* My own external interface */
  158193. #if TRANSFORMS_SUPPORTED
  158194. LOCAL(void)
  158195. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158196. jvirt_barray_ptr *src_coef_arrays)
  158197. {
  158198. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158199. int ci, k, offset_y;
  158200. JBLOCKARRAY buffer;
  158201. JCOEFPTR ptr1, ptr2;
  158202. JCOEF temp1, temp2;
  158203. jpeg_component_info *compptr;
  158204. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158205. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158206. compptr = dstinfo->comp_info + ci;
  158207. comp_width = MCU_cols * compptr->h_samp_factor;
  158208. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158209. blk_y += compptr->v_samp_factor) {
  158210. buffer = (*srcinfo->mem->access_virt_barray)
  158211. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158212. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158213. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158214. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158215. ptr1 = buffer[offset_y][blk_x];
  158216. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158217. for (k = 0; k < DCTSIZE2; k += 2) {
  158218. temp1 = *ptr1; /* swap even column */
  158219. temp2 = *ptr2;
  158220. *ptr1++ = temp2;
  158221. *ptr2++ = temp1;
  158222. temp1 = *ptr1; /* swap odd column with sign change */
  158223. temp2 = *ptr2;
  158224. *ptr1++ = -temp2;
  158225. *ptr2++ = -temp1;
  158226. }
  158227. }
  158228. }
  158229. }
  158230. }
  158231. }
  158232. LOCAL(void)
  158233. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158234. jvirt_barray_ptr *src_coef_arrays,
  158235. jvirt_barray_ptr *dst_coef_arrays)
  158236. {
  158237. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158238. int ci, i, j, offset_y;
  158239. JBLOCKARRAY src_buffer, dst_buffer;
  158240. JBLOCKROW src_row_ptr, dst_row_ptr;
  158241. JCOEFPTR src_ptr, dst_ptr;
  158242. jpeg_component_info *compptr;
  158243. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158244. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158245. compptr = dstinfo->comp_info + ci;
  158246. comp_height = MCU_rows * compptr->v_samp_factor;
  158247. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158248. dst_blk_y += compptr->v_samp_factor) {
  158249. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158250. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158251. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158252. if (dst_blk_y < comp_height) {
  158253. src_buffer = (*srcinfo->mem->access_virt_barray)
  158254. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158255. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158256. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158257. } else {
  158258. src_buffer = (*srcinfo->mem->access_virt_barray)
  158259. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158260. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158261. }
  158262. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158263. if (dst_blk_y < comp_height) {
  158264. dst_row_ptr = dst_buffer[offset_y];
  158265. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158266. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158267. dst_blk_x++) {
  158268. dst_ptr = dst_row_ptr[dst_blk_x];
  158269. src_ptr = src_row_ptr[dst_blk_x];
  158270. for (i = 0; i < DCTSIZE; i += 2) {
  158271. for (j = 0; j < DCTSIZE; j++)
  158272. *dst_ptr++ = *src_ptr++;
  158273. for (j = 0; j < DCTSIZE; j++)
  158274. *dst_ptr++ = - *src_ptr++;
  158275. }
  158276. }
  158277. } else {
  158278. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158279. compptr->width_in_blocks);
  158280. }
  158281. }
  158282. }
  158283. }
  158284. }
  158285. LOCAL(void)
  158286. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158287. jvirt_barray_ptr *src_coef_arrays,
  158288. jvirt_barray_ptr *dst_coef_arrays)
  158289. {
  158290. JDIMENSION dst_blk_x, dst_blk_y;
  158291. int ci, i, j, offset_x, offset_y;
  158292. JBLOCKARRAY src_buffer, dst_buffer;
  158293. JCOEFPTR src_ptr, dst_ptr;
  158294. jpeg_component_info *compptr;
  158295. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158296. compptr = dstinfo->comp_info + ci;
  158297. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158298. dst_blk_y += compptr->v_samp_factor) {
  158299. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158300. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158301. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158302. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158303. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158304. dst_blk_x += compptr->h_samp_factor) {
  158305. src_buffer = (*srcinfo->mem->access_virt_barray)
  158306. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158307. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158308. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158309. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158310. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158311. for (i = 0; i < DCTSIZE; i++)
  158312. for (j = 0; j < DCTSIZE; j++)
  158313. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158314. }
  158315. }
  158316. }
  158317. }
  158318. }
  158319. }
  158320. LOCAL(void)
  158321. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158322. jvirt_barray_ptr *src_coef_arrays,
  158323. jvirt_barray_ptr *dst_coef_arrays)
  158324. {
  158325. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158326. int ci, i, j, offset_x, offset_y;
  158327. JBLOCKARRAY src_buffer, dst_buffer;
  158328. JCOEFPTR src_ptr, dst_ptr;
  158329. jpeg_component_info *compptr;
  158330. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158331. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158332. compptr = dstinfo->comp_info + ci;
  158333. comp_width = MCU_cols * compptr->h_samp_factor;
  158334. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158335. dst_blk_y += compptr->v_samp_factor) {
  158336. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158337. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158338. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158339. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158340. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158341. dst_blk_x += compptr->h_samp_factor) {
  158342. src_buffer = (*srcinfo->mem->access_virt_barray)
  158343. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158344. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158345. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158346. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158347. if (dst_blk_x < comp_width) {
  158348. dst_ptr = dst_buffer[offset_y]
  158349. [comp_width - dst_blk_x - offset_x - 1];
  158350. for (i = 0; i < DCTSIZE; i++) {
  158351. for (j = 0; j < DCTSIZE; j++)
  158352. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158353. i++;
  158354. for (j = 0; j < DCTSIZE; j++)
  158355. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158356. }
  158357. } else {
  158358. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158359. for (i = 0; i < DCTSIZE; i++)
  158360. for (j = 0; j < DCTSIZE; j++)
  158361. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158362. }
  158363. }
  158364. }
  158365. }
  158366. }
  158367. }
  158368. }
  158369. LOCAL(void)
  158370. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158371. jvirt_barray_ptr *src_coef_arrays,
  158372. jvirt_barray_ptr *dst_coef_arrays)
  158373. {
  158374. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158375. int ci, i, j, offset_x, offset_y;
  158376. JBLOCKARRAY src_buffer, dst_buffer;
  158377. JCOEFPTR src_ptr, dst_ptr;
  158378. jpeg_component_info *compptr;
  158379. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158380. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158381. compptr = dstinfo->comp_info + ci;
  158382. comp_height = MCU_rows * compptr->v_samp_factor;
  158383. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158384. dst_blk_y += compptr->v_samp_factor) {
  158385. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158386. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158387. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158388. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158389. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158390. dst_blk_x += compptr->h_samp_factor) {
  158391. src_buffer = (*srcinfo->mem->access_virt_barray)
  158392. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158393. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158394. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158395. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158396. if (dst_blk_y < comp_height) {
  158397. src_ptr = src_buffer[offset_x]
  158398. [comp_height - dst_blk_y - offset_y - 1];
  158399. for (i = 0; i < DCTSIZE; i++) {
  158400. for (j = 0; j < DCTSIZE; j++) {
  158401. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158402. j++;
  158403. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158404. }
  158405. }
  158406. } else {
  158407. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158408. for (i = 0; i < DCTSIZE; i++)
  158409. for (j = 0; j < DCTSIZE; j++)
  158410. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158411. }
  158412. }
  158413. }
  158414. }
  158415. }
  158416. }
  158417. }
  158418. LOCAL(void)
  158419. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158420. jvirt_barray_ptr *src_coef_arrays,
  158421. jvirt_barray_ptr *dst_coef_arrays)
  158422. {
  158423. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158424. int ci, i, j, offset_y;
  158425. JBLOCKARRAY src_buffer, dst_buffer;
  158426. JBLOCKROW src_row_ptr, dst_row_ptr;
  158427. JCOEFPTR src_ptr, dst_ptr;
  158428. jpeg_component_info *compptr;
  158429. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158430. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158431. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158432. compptr = dstinfo->comp_info + ci;
  158433. comp_width = MCU_cols * compptr->h_samp_factor;
  158434. comp_height = MCU_rows * compptr->v_samp_factor;
  158435. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158436. dst_blk_y += compptr->v_samp_factor) {
  158437. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158438. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158439. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158440. if (dst_blk_y < comp_height) {
  158441. src_buffer = (*srcinfo->mem->access_virt_barray)
  158442. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158443. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158444. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158445. } else {
  158446. src_buffer = (*srcinfo->mem->access_virt_barray)
  158447. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158448. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158449. }
  158450. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158451. if (dst_blk_y < comp_height) {
  158452. dst_row_ptr = dst_buffer[offset_y];
  158453. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158454. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158455. dst_ptr = dst_row_ptr[dst_blk_x];
  158456. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158457. for (i = 0; i < DCTSIZE; i += 2) {
  158458. for (j = 0; j < DCTSIZE; j += 2) {
  158459. *dst_ptr++ = *src_ptr++;
  158460. *dst_ptr++ = - *src_ptr++;
  158461. }
  158462. for (j = 0; j < DCTSIZE; j += 2) {
  158463. *dst_ptr++ = - *src_ptr++;
  158464. *dst_ptr++ = *src_ptr++;
  158465. }
  158466. }
  158467. }
  158468. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158469. dst_ptr = dst_row_ptr[dst_blk_x];
  158470. src_ptr = src_row_ptr[dst_blk_x];
  158471. for (i = 0; i < DCTSIZE; i += 2) {
  158472. for (j = 0; j < DCTSIZE; j++)
  158473. *dst_ptr++ = *src_ptr++;
  158474. for (j = 0; j < DCTSIZE; j++)
  158475. *dst_ptr++ = - *src_ptr++;
  158476. }
  158477. }
  158478. } else {
  158479. dst_row_ptr = dst_buffer[offset_y];
  158480. src_row_ptr = src_buffer[offset_y];
  158481. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158482. dst_ptr = dst_row_ptr[dst_blk_x];
  158483. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158484. for (i = 0; i < DCTSIZE2; i += 2) {
  158485. *dst_ptr++ = *src_ptr++;
  158486. *dst_ptr++ = - *src_ptr++;
  158487. }
  158488. }
  158489. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158490. dst_ptr = dst_row_ptr[dst_blk_x];
  158491. src_ptr = src_row_ptr[dst_blk_x];
  158492. for (i = 0; i < DCTSIZE2; i++)
  158493. *dst_ptr++ = *src_ptr++;
  158494. }
  158495. }
  158496. }
  158497. }
  158498. }
  158499. }
  158500. LOCAL(void)
  158501. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158502. jvirt_barray_ptr *src_coef_arrays,
  158503. jvirt_barray_ptr *dst_coef_arrays)
  158504. {
  158505. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158506. int ci, i, j, offset_x, offset_y;
  158507. JBLOCKARRAY src_buffer, dst_buffer;
  158508. JCOEFPTR src_ptr, dst_ptr;
  158509. jpeg_component_info *compptr;
  158510. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158511. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158512. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158513. compptr = dstinfo->comp_info + ci;
  158514. comp_width = MCU_cols * compptr->h_samp_factor;
  158515. comp_height = MCU_rows * compptr->v_samp_factor;
  158516. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158517. dst_blk_y += compptr->v_samp_factor) {
  158518. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158519. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158520. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158521. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158522. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158523. dst_blk_x += compptr->h_samp_factor) {
  158524. src_buffer = (*srcinfo->mem->access_virt_barray)
  158525. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158526. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158527. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158528. if (dst_blk_y < comp_height) {
  158529. src_ptr = src_buffer[offset_x]
  158530. [comp_height - dst_blk_y - offset_y - 1];
  158531. if (dst_blk_x < comp_width) {
  158532. dst_ptr = dst_buffer[offset_y]
  158533. [comp_width - dst_blk_x - offset_x - 1];
  158534. for (i = 0; i < DCTSIZE; i++) {
  158535. for (j = 0; j < DCTSIZE; j++) {
  158536. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158537. j++;
  158538. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158539. }
  158540. i++;
  158541. for (j = 0; j < DCTSIZE; j++) {
  158542. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158543. j++;
  158544. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158545. }
  158546. }
  158547. } else {
  158548. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158549. for (i = 0; i < DCTSIZE; i++) {
  158550. for (j = 0; j < DCTSIZE; j++) {
  158551. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158552. j++;
  158553. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158554. }
  158555. }
  158556. }
  158557. } else {
  158558. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158559. if (dst_blk_x < comp_width) {
  158560. dst_ptr = dst_buffer[offset_y]
  158561. [comp_width - dst_blk_x - offset_x - 1];
  158562. for (i = 0; i < DCTSIZE; i++) {
  158563. for (j = 0; j < DCTSIZE; j++)
  158564. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158565. i++;
  158566. for (j = 0; j < DCTSIZE; j++)
  158567. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158568. }
  158569. } else {
  158570. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158571. for (i = 0; i < DCTSIZE; i++)
  158572. for (j = 0; j < DCTSIZE; j++)
  158573. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158574. }
  158575. }
  158576. }
  158577. }
  158578. }
  158579. }
  158580. }
  158581. }
  158582. GLOBAL(void)
  158583. jtransform_request_workspace (j_decompress_ptr srcinfo,
  158584. jpeg_transform_info *info)
  158585. {
  158586. jvirt_barray_ptr *coef_arrays = NULL;
  158587. jpeg_component_info *compptr;
  158588. int ci;
  158589. if (info->force_grayscale &&
  158590. srcinfo->jpeg_color_space == JCS_YCbCr &&
  158591. srcinfo->num_components == 3) {
  158592. info->num_components = 1;
  158593. } else {
  158594. info->num_components = srcinfo->num_components;
  158595. }
  158596. switch (info->transform) {
  158597. case JXFORM_NONE:
  158598. case JXFORM_FLIP_H:
  158599. break;
  158600. case JXFORM_FLIP_V:
  158601. case JXFORM_ROT_180:
  158602. coef_arrays = (jvirt_barray_ptr *)
  158603. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158604. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158605. for (ci = 0; ci < info->num_components; ci++) {
  158606. compptr = srcinfo->comp_info + ci;
  158607. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158608. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158609. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158610. (long) compptr->h_samp_factor),
  158611. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158612. (long) compptr->v_samp_factor),
  158613. (JDIMENSION) compptr->v_samp_factor);
  158614. }
  158615. break;
  158616. case JXFORM_TRANSPOSE:
  158617. case JXFORM_TRANSVERSE:
  158618. case JXFORM_ROT_90:
  158619. case JXFORM_ROT_270:
  158620. coef_arrays = (jvirt_barray_ptr *)
  158621. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158622. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158623. for (ci = 0; ci < info->num_components; ci++) {
  158624. compptr = srcinfo->comp_info + ci;
  158625. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158626. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158627. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158628. (long) compptr->v_samp_factor),
  158629. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158630. (long) compptr->h_samp_factor),
  158631. (JDIMENSION) compptr->h_samp_factor);
  158632. }
  158633. break;
  158634. }
  158635. info->workspace_coef_arrays = coef_arrays;
  158636. }
  158637. LOCAL(void)
  158638. transpose_critical_parameters (j_compress_ptr dstinfo)
  158639. {
  158640. int tblno, i, j, ci, itemp;
  158641. jpeg_component_info *compptr;
  158642. JQUANT_TBL *qtblptr;
  158643. JDIMENSION dtemp;
  158644. UINT16 qtemp;
  158645. dtemp = dstinfo->image_width;
  158646. dstinfo->image_width = dstinfo->image_height;
  158647. dstinfo->image_height = dtemp;
  158648. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158649. compptr = dstinfo->comp_info + ci;
  158650. itemp = compptr->h_samp_factor;
  158651. compptr->h_samp_factor = compptr->v_samp_factor;
  158652. compptr->v_samp_factor = itemp;
  158653. }
  158654. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  158655. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  158656. if (qtblptr != NULL) {
  158657. for (i = 0; i < DCTSIZE; i++) {
  158658. for (j = 0; j < i; j++) {
  158659. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  158660. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  158661. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  158662. }
  158663. }
  158664. }
  158665. }
  158666. }
  158667. LOCAL(void)
  158668. trim_right_edge (j_compress_ptr dstinfo)
  158669. {
  158670. int ci, max_h_samp_factor;
  158671. JDIMENSION MCU_cols;
  158672. max_h_samp_factor = 1;
  158673. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158674. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  158675. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  158676. }
  158677. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  158678. if (MCU_cols > 0) /* can't trim to 0 pixels */
  158679. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  158680. }
  158681. LOCAL(void)
  158682. trim_bottom_edge (j_compress_ptr dstinfo)
  158683. {
  158684. int ci, max_v_samp_factor;
  158685. JDIMENSION MCU_rows;
  158686. max_v_samp_factor = 1;
  158687. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158688. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  158689. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  158690. }
  158691. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  158692. if (MCU_rows > 0) /* can't trim to 0 pixels */
  158693. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  158694. }
  158695. GLOBAL(jvirt_barray_ptr *)
  158696. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  158697. j_compress_ptr dstinfo,
  158698. jvirt_barray_ptr *src_coef_arrays,
  158699. jpeg_transform_info *info)
  158700. {
  158701. if (info->force_grayscale) {
  158702. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  158703. dstinfo->num_components == 3) ||
  158704. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  158705. dstinfo->num_components == 1)) {
  158706. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  158707. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  158708. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  158709. } else {
  158710. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  158711. }
  158712. }
  158713. switch (info->transform) {
  158714. case JXFORM_NONE:
  158715. break;
  158716. case JXFORM_FLIP_H:
  158717. if (info->trim)
  158718. trim_right_edge(dstinfo);
  158719. break;
  158720. case JXFORM_FLIP_V:
  158721. if (info->trim)
  158722. trim_bottom_edge(dstinfo);
  158723. break;
  158724. case JXFORM_TRANSPOSE:
  158725. transpose_critical_parameters(dstinfo);
  158726. break;
  158727. case JXFORM_TRANSVERSE:
  158728. transpose_critical_parameters(dstinfo);
  158729. if (info->trim) {
  158730. trim_right_edge(dstinfo);
  158731. trim_bottom_edge(dstinfo);
  158732. }
  158733. break;
  158734. case JXFORM_ROT_90:
  158735. transpose_critical_parameters(dstinfo);
  158736. if (info->trim)
  158737. trim_right_edge(dstinfo);
  158738. break;
  158739. case JXFORM_ROT_180:
  158740. if (info->trim) {
  158741. trim_right_edge(dstinfo);
  158742. trim_bottom_edge(dstinfo);
  158743. }
  158744. break;
  158745. case JXFORM_ROT_270:
  158746. transpose_critical_parameters(dstinfo);
  158747. if (info->trim)
  158748. trim_bottom_edge(dstinfo);
  158749. break;
  158750. }
  158751. if (info->workspace_coef_arrays != NULL)
  158752. return info->workspace_coef_arrays;
  158753. return src_coef_arrays;
  158754. }
  158755. GLOBAL(void)
  158756. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  158757. j_compress_ptr dstinfo,
  158758. jvirt_barray_ptr *src_coef_arrays,
  158759. jpeg_transform_info *info)
  158760. {
  158761. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  158762. switch (info->transform) {
  158763. case JXFORM_NONE:
  158764. break;
  158765. case JXFORM_FLIP_H:
  158766. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  158767. break;
  158768. case JXFORM_FLIP_V:
  158769. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158770. break;
  158771. case JXFORM_TRANSPOSE:
  158772. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158773. break;
  158774. case JXFORM_TRANSVERSE:
  158775. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158776. break;
  158777. case JXFORM_ROT_90:
  158778. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158779. break;
  158780. case JXFORM_ROT_180:
  158781. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158782. break;
  158783. case JXFORM_ROT_270:
  158784. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158785. break;
  158786. }
  158787. }
  158788. #endif /* TRANSFORMS_SUPPORTED */
  158789. GLOBAL(void)
  158790. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  158791. {
  158792. #ifdef SAVE_MARKERS_SUPPORTED
  158793. int m;
  158794. if (option != JCOPYOPT_NONE) {
  158795. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  158796. }
  158797. if (option == JCOPYOPT_ALL) {
  158798. for (m = 0; m < 16; m++)
  158799. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  158800. }
  158801. #endif /* SAVE_MARKERS_SUPPORTED */
  158802. }
  158803. GLOBAL(void)
  158804. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158805. JCOPY_OPTION option)
  158806. {
  158807. jpeg_saved_marker_ptr marker;
  158808. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  158809. if (dstinfo->write_JFIF_header &&
  158810. marker->marker == JPEG_APP0 &&
  158811. marker->data_length >= 5 &&
  158812. GETJOCTET(marker->data[0]) == 0x4A &&
  158813. GETJOCTET(marker->data[1]) == 0x46 &&
  158814. GETJOCTET(marker->data[2]) == 0x49 &&
  158815. GETJOCTET(marker->data[3]) == 0x46 &&
  158816. GETJOCTET(marker->data[4]) == 0)
  158817. continue; /* reject duplicate JFIF */
  158818. if (dstinfo->write_Adobe_marker &&
  158819. marker->marker == JPEG_APP0+14 &&
  158820. marker->data_length >= 5 &&
  158821. GETJOCTET(marker->data[0]) == 0x41 &&
  158822. GETJOCTET(marker->data[1]) == 0x64 &&
  158823. GETJOCTET(marker->data[2]) == 0x6F &&
  158824. GETJOCTET(marker->data[3]) == 0x62 &&
  158825. GETJOCTET(marker->data[4]) == 0x65)
  158826. continue; /* reject duplicate Adobe */
  158827. #ifdef NEED_FAR_POINTERS
  158828. {
  158829. unsigned int i;
  158830. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  158831. for (i = 0; i < marker->data_length; i++)
  158832. jpeg_write_m_byte(dstinfo, marker->data[i]);
  158833. }
  158834. #else
  158835. jpeg_write_marker(dstinfo, marker->marker,
  158836. marker->data, marker->data_length);
  158837. #endif
  158838. }
  158839. }
  158840. /*** End of inlined file: transupp.c ***/
  158841. }
  158842. #else
  158843. #define JPEG_INTERNALS
  158844. #undef FAR
  158845. #include <jpeglib.h>
  158846. #endif
  158847. }
  158848. #undef max
  158849. #undef min
  158850. #if JUCE_MSVC
  158851. #pragma warning (pop)
  158852. #endif
  158853. BEGIN_JUCE_NAMESPACE
  158854. namespace JPEGHelpers
  158855. {
  158856. using namespace jpeglibNamespace;
  158857. #if ! JUCE_MSVC
  158858. using jpeglibNamespace::boolean;
  158859. #endif
  158860. struct JPEGDecodingFailure {};
  158861. static void fatalErrorHandler (j_common_ptr)
  158862. {
  158863. throw JPEGDecodingFailure();
  158864. }
  158865. static void silentErrorCallback1 (j_common_ptr) {}
  158866. static void silentErrorCallback2 (j_common_ptr, int) {}
  158867. static void silentErrorCallback3 (j_common_ptr, char*) {}
  158868. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  158869. {
  158870. zerostruct (err);
  158871. err.error_exit = fatalErrorHandler;
  158872. err.emit_message = silentErrorCallback2;
  158873. err.output_message = silentErrorCallback1;
  158874. err.format_message = silentErrorCallback3;
  158875. err.reset_error_mgr = silentErrorCallback1;
  158876. }
  158877. static void dummyCallback1 (j_decompress_ptr)
  158878. {
  158879. }
  158880. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  158881. {
  158882. decompStruct->src->next_input_byte += num;
  158883. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  158884. decompStruct->src->bytes_in_buffer -= num;
  158885. }
  158886. static boolean jpegFill (j_decompress_ptr)
  158887. {
  158888. return 0;
  158889. }
  158890. static const int jpegBufferSize = 512;
  158891. struct JuceJpegDest : public jpeg_destination_mgr
  158892. {
  158893. OutputStream* output;
  158894. char* buffer;
  158895. };
  158896. static void jpegWriteInit (j_compress_ptr)
  158897. {
  158898. }
  158899. static void jpegWriteTerminate (j_compress_ptr cinfo)
  158900. {
  158901. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  158902. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  158903. dest->output->write (dest->buffer, (int) numToWrite);
  158904. }
  158905. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  158906. {
  158907. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  158908. const int numToWrite = jpegBufferSize;
  158909. dest->next_output_byte = (JOCTET*) dest->buffer;
  158910. dest->free_in_buffer = jpegBufferSize;
  158911. return dest->output->write (dest->buffer, numToWrite);
  158912. }
  158913. }
  158914. Image* juce_loadJPEGImageFromStream (InputStream& in)
  158915. {
  158916. using namespace jpeglibNamespace;
  158917. using namespace JPEGHelpers;
  158918. MemoryBlock mb;
  158919. in.readIntoMemoryBlock (mb);
  158920. Image* image = 0;
  158921. if (mb.getSize() > 16)
  158922. {
  158923. struct jpeg_decompress_struct jpegDecompStruct;
  158924. struct jpeg_error_mgr jerr;
  158925. setupSilentErrorHandler (jerr);
  158926. jpegDecompStruct.err = &jerr;
  158927. jpeg_create_decompress (&jpegDecompStruct);
  158928. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  158929. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  158930. jpegDecompStruct.src->init_source = dummyCallback1;
  158931. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  158932. jpegDecompStruct.src->skip_input_data = jpegSkip;
  158933. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  158934. jpegDecompStruct.src->term_source = dummyCallback1;
  158935. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  158936. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  158937. try
  158938. {
  158939. jpeg_read_header (&jpegDecompStruct, TRUE);
  158940. jpeg_calc_output_dimensions (&jpegDecompStruct);
  158941. const int width = jpegDecompStruct.output_width;
  158942. const int height = jpegDecompStruct.output_height;
  158943. jpegDecompStruct.out_color_space = JCS_RGB;
  158944. JSAMPARRAY buffer
  158945. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  158946. JPOOL_IMAGE,
  158947. width * 3, 1);
  158948. if (jpeg_start_decompress (&jpegDecompStruct))
  158949. {
  158950. image = Image::createNativeImage (Image::RGB, width, height, false);
  158951. const bool hasAlphaChan = image->hasAlphaChannel();
  158952. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  158953. for (int y = 0; y < height; ++y)
  158954. {
  158955. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  158956. const uint8* src = *buffer;
  158957. uint8* dest = destData.getLinePointer (y);
  158958. if (hasAlphaChan)
  158959. {
  158960. for (int i = width; --i >= 0;)
  158961. {
  158962. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158963. ((PixelARGB*) dest)->premultiply();
  158964. dest += destData.pixelStride;
  158965. src += 3;
  158966. }
  158967. }
  158968. else
  158969. {
  158970. for (int i = width; --i >= 0;)
  158971. {
  158972. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158973. dest += destData.pixelStride;
  158974. src += 3;
  158975. }
  158976. }
  158977. }
  158978. jpeg_finish_decompress (&jpegDecompStruct);
  158979. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  158980. }
  158981. jpeg_destroy_decompress (&jpegDecompStruct);
  158982. }
  158983. catch (...)
  158984. {}
  158985. }
  158986. return image;
  158987. }
  158988. bool juce_writeJPEGImageToStream (const Image& image,
  158989. OutputStream& out,
  158990. float quality)
  158991. {
  158992. using namespace jpeglibNamespace;
  158993. using namespace JPEGHelpers;
  158994. if (image.hasAlphaChannel())
  158995. {
  158996. // this method could fill the background in white and still save the image..
  158997. jassertfalse
  158998. return true;
  158999. }
  159000. struct jpeg_compress_struct jpegCompStruct;
  159001. struct jpeg_error_mgr jerr;
  159002. setupSilentErrorHandler (jerr);
  159003. jpegCompStruct.err = &jerr;
  159004. jpeg_create_compress (&jpegCompStruct);
  159005. JuceJpegDest dest;
  159006. jpegCompStruct.dest = &dest;
  159007. dest.output = &out;
  159008. HeapBlock <char> tempBuffer (jpegBufferSize);
  159009. dest.buffer = (char*) tempBuffer;
  159010. dest.next_output_byte = (JOCTET*) dest.buffer;
  159011. dest.free_in_buffer = jpegBufferSize;
  159012. dest.init_destination = jpegWriteInit;
  159013. dest.empty_output_buffer = jpegWriteFlush;
  159014. dest.term_destination = jpegWriteTerminate;
  159015. jpegCompStruct.image_width = image.getWidth();
  159016. jpegCompStruct.image_height = image.getHeight();
  159017. jpegCompStruct.input_components = 3;
  159018. jpegCompStruct.in_color_space = JCS_RGB;
  159019. jpegCompStruct.write_JFIF_header = 1;
  159020. jpegCompStruct.X_density = 72;
  159021. jpegCompStruct.Y_density = 72;
  159022. jpeg_set_defaults (&jpegCompStruct);
  159023. jpegCompStruct.dct_method = JDCT_FLOAT;
  159024. jpegCompStruct.optimize_coding = 1;
  159025. // jpegCompStruct.smoothing_factor = 10;
  159026. if (quality < 0.0f)
  159027. quality = 0.85f;
  159028. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159029. jpeg_start_compress (&jpegCompStruct, TRUE);
  159030. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159031. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159032. JPOOL_IMAGE,
  159033. strideBytes, 1);
  159034. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159035. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159036. {
  159037. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159038. uint8* dst = *buffer;
  159039. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159040. {
  159041. *dst++ = ((const PixelRGB*) src)->getRed();
  159042. *dst++ = ((const PixelRGB*) src)->getGreen();
  159043. *dst++ = ((const PixelRGB*) src)->getBlue();
  159044. src += srcData.pixelStride;
  159045. }
  159046. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159047. }
  159048. jpeg_finish_compress (&jpegCompStruct);
  159049. jpeg_destroy_compress (&jpegCompStruct);
  159050. out.flush();
  159051. return true;
  159052. }
  159053. END_JUCE_NAMESPACE
  159054. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  159055. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  159056. #ifdef _MSC_VER
  159057. #pragma warning (push)
  159058. #pragma warning (disable: 4390 4611)
  159059. #endif
  159060. namespace zlibNamespace
  159061. {
  159062. #if JUCE_INCLUDE_ZLIB_CODE
  159063. #undef OS_CODE
  159064. #undef fdopen
  159065. #undef OS_CODE
  159066. #else
  159067. #include <zlib.h>
  159068. #endif
  159069. }
  159070. namespace pnglibNamespace
  159071. {
  159072. using namespace zlibNamespace;
  159073. #if JUCE_INCLUDE_PNGLIB_CODE
  159074. #if _MSC_VER != 1310
  159075. using ::calloc; // (causes conflict in VS.NET 2003)
  159076. using ::malloc;
  159077. using ::free;
  159078. #endif
  159079. extern "C"
  159080. {
  159081. using ::abs;
  159082. #define PNG_INTERNAL
  159083. #define NO_DUMMY_DECL
  159084. #define PNG_SETJMP_NOT_SUPPORTED
  159085. /*** Start of inlined file: png.h ***/
  159086. #ifndef PNG_H
  159087. #define PNG_H
  159088. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159089. #define PNG_HEADER_VERSION_STRING \
  159090. " libpng version 1.2.21 - October 4, 2007\n"
  159091. #define PNG_LIBPNG_VER_SONUM 0
  159092. #define PNG_LIBPNG_VER_DLLNUM 13
  159093. #define PNG_LIBPNG_VER_MAJOR 1
  159094. #define PNG_LIBPNG_VER_MINOR 2
  159095. #define PNG_LIBPNG_VER_RELEASE 21
  159096. #define PNG_LIBPNG_VER_BUILD 0
  159097. #define PNG_LIBPNG_BUILD_ALPHA 1
  159098. #define PNG_LIBPNG_BUILD_BETA 2
  159099. #define PNG_LIBPNG_BUILD_RC 3
  159100. #define PNG_LIBPNG_BUILD_STABLE 4
  159101. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159102. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159103. PNG_LIBPNG_BUILD_STABLE only */
  159104. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159105. PNG_LIBPNG_BUILD_SPECIAL */
  159106. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159107. PNG_LIBPNG_BUILD_PRIVATE */
  159108. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159109. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159110. #ifndef PNG_VERSION_INFO_ONLY
  159111. #endif
  159112. /*** Start of inlined file: pngconf.h ***/
  159113. #ifndef PNGCONF_H
  159114. #define PNGCONF_H
  159115. #define PNG_1_2_X
  159116. // These are some Juce config settings that should remove any unnecessary code bloat..
  159117. #define PNG_NO_STDIO 1
  159118. #define PNG_DEBUG 0
  159119. #define PNG_NO_WARNINGS 1
  159120. #define PNG_NO_ERROR_TEXT 1
  159121. #define PNG_NO_ERROR_NUMBERS 1
  159122. #define PNG_NO_USER_MEM 1
  159123. #define PNG_NO_READ_iCCP 1
  159124. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159125. #define PNG_NO_READ_USER_CHUNKS 1
  159126. #define PNG_NO_READ_iTXt 1
  159127. #define PNG_NO_READ_sCAL 1
  159128. #define PNG_NO_READ_sPLT 1
  159129. #define png_error(a, b) png_err(a)
  159130. #define png_warning(a, b)
  159131. #define png_chunk_error(a, b) png_err(a)
  159132. #define png_chunk_warning(a, b)
  159133. #ifdef PNG_USER_CONFIG
  159134. # ifndef PNG_USER_PRIVATEBUILD
  159135. # define PNG_USER_PRIVATEBUILD
  159136. # endif
  159137. #include "pngusr.h"
  159138. #endif
  159139. #ifdef PNG_CONFIGURE_LIBPNG
  159140. #ifdef HAVE_CONFIG_H
  159141. #include "config.h"
  159142. #endif
  159143. #endif
  159144. #ifdef __STDC__
  159145. #ifdef SPECIALBUILD
  159146. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159147. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159148. #endif
  159149. #ifdef PRIVATEBUILD
  159150. # pragma message("PRIVATEBUILD is deprecated.\
  159151. Use PNG_USER_PRIVATEBUILD instead.")
  159152. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159153. #endif
  159154. #endif /* __STDC__ */
  159155. #ifndef PNG_VERSION_INFO_ONLY
  159156. # define PNG_WARN_UNINITIALIZED_ROW 1
  159157. #ifndef PNG_ZBUF_SIZE
  159158. # define PNG_ZBUF_SIZE 8192
  159159. #endif
  159160. #ifndef PNG_NO_READ_SUPPORTED
  159161. # define PNG_READ_SUPPORTED
  159162. #endif
  159163. #ifndef PNG_NO_WRITE_SUPPORTED
  159164. # define PNG_WRITE_SUPPORTED
  159165. #endif
  159166. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159167. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159168. # define PNG_MNG_FEATURES_SUPPORTED
  159169. # endif
  159170. #endif
  159171. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159172. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159173. # define PNG_FLOATING_POINT_SUPPORTED
  159174. # endif
  159175. #endif
  159176. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159177. # define PNG_MAX_MALLOC_64K
  159178. #endif
  159179. #if defined(__CYGWIN__)
  159180. # if defined(ALL_STATIC)
  159181. # if defined(PNG_BUILD_DLL)
  159182. # undef PNG_BUILD_DLL
  159183. # endif
  159184. # if defined(PNG_USE_DLL)
  159185. # undef PNG_USE_DLL
  159186. # endif
  159187. # if defined(PNG_DLL)
  159188. # undef PNG_DLL
  159189. # endif
  159190. # if !defined(PNG_STATIC)
  159191. # define PNG_STATIC
  159192. # endif
  159193. # else
  159194. # if defined (PNG_BUILD_DLL)
  159195. # if defined(PNG_STATIC)
  159196. # undef PNG_STATIC
  159197. # endif
  159198. # if defined(PNG_USE_DLL)
  159199. # undef PNG_USE_DLL
  159200. # endif
  159201. # if !defined(PNG_DLL)
  159202. # define PNG_DLL
  159203. # endif
  159204. # else
  159205. # if defined(PNG_STATIC)
  159206. # if defined(PNG_USE_DLL)
  159207. # undef PNG_USE_DLL
  159208. # endif
  159209. # if defined(PNG_DLL)
  159210. # undef PNG_DLL
  159211. # endif
  159212. # else
  159213. # if !defined(PNG_USE_DLL)
  159214. # define PNG_USE_DLL
  159215. # endif
  159216. # if !defined(PNG_DLL)
  159217. # define PNG_DLL
  159218. # endif
  159219. # endif
  159220. # endif
  159221. # endif
  159222. #endif
  159223. #if defined(_WIN32_WCE)
  159224. # include <windows.h>
  159225. # define PNG_NO_CONSOLE_IO
  159226. # ifdef PNG_DEBUG
  159227. # undef PNG_DEBUG
  159228. # endif
  159229. #endif
  159230. #ifdef PNG_BUILD_DLL
  159231. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159232. # ifndef PNG_NO_CONSOLE_IO
  159233. # define PNG_NO_CONSOLE_IO
  159234. # endif
  159235. # endif
  159236. #endif
  159237. # ifdef PNG_NO_STDIO
  159238. # ifndef PNG_NO_CONSOLE_IO
  159239. # define PNG_NO_CONSOLE_IO
  159240. # endif
  159241. # ifdef PNG_DEBUG
  159242. # if (PNG_DEBUG > 0)
  159243. # include <stdio.h>
  159244. # endif
  159245. # endif
  159246. # else
  159247. # if !defined(_WIN32_WCE)
  159248. # include <stdio.h>
  159249. # endif
  159250. # endif
  159251. #ifndef PNGARG
  159252. #ifdef OF /* zlib prototype munger */
  159253. # define PNGARG(arglist) OF(arglist)
  159254. #else
  159255. #ifdef _NO_PROTO
  159256. # define PNGARG(arglist) ()
  159257. # ifndef PNG_TYPECAST_NULL
  159258. # define PNG_TYPECAST_NULL
  159259. # endif
  159260. #else
  159261. # define PNGARG(arglist) arglist
  159262. #endif /* _NO_PROTO */
  159263. #endif /* OF */
  159264. #endif /* PNGARG */
  159265. #ifndef MACOS
  159266. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159267. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159268. # define MACOS
  159269. # endif
  159270. #endif
  159271. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159272. # include <sys/types.h>
  159273. #endif
  159274. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159275. # define PNG_SETJMP_SUPPORTED
  159276. #endif
  159277. #ifdef PNG_SETJMP_SUPPORTED
  159278. # ifdef __linux__
  159279. # ifdef _BSD_SOURCE
  159280. # define PNG_SAVE_BSD_SOURCE
  159281. # undef _BSD_SOURCE
  159282. # endif
  159283. # ifdef _SETJMP_H
  159284. __png.h__ already includes setjmp.h;
  159285. __dont__ include it again.;
  159286. # endif
  159287. # endif /* __linux__ */
  159288. # include <setjmp.h>
  159289. # ifdef __linux__
  159290. # ifdef PNG_SAVE_BSD_SOURCE
  159291. # define _BSD_SOURCE
  159292. # undef PNG_SAVE_BSD_SOURCE
  159293. # endif
  159294. # endif /* __linux__ */
  159295. #endif /* PNG_SETJMP_SUPPORTED */
  159296. #ifdef BSD
  159297. #if ! JUCE_MAC
  159298. # include <strings.h>
  159299. #endif
  159300. #else
  159301. # include <string.h>
  159302. #endif
  159303. #ifdef PNG_INTERNAL
  159304. #include <stdlib.h>
  159305. #define PNG_EXTERN
  159306. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159307. # if defined(MACOS)
  159308. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159309. # include <fp.h>
  159310. # endif
  159311. # else
  159312. # include <math.h>
  159313. # endif
  159314. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159315. # include <m68881.h>
  159316. # endif
  159317. #endif
  159318. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159319. # define PNG_ALWAYS_EXTERN
  159320. #endif
  159321. #if defined(__TURBOC__) && defined(__MSDOS__)
  159322. # include <mem.h>
  159323. # include <alloc.h>
  159324. #endif
  159325. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159326. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159327. # include <malloc.h>
  159328. #endif
  159329. #ifndef PNG_DITHER_RED_BITS
  159330. # define PNG_DITHER_RED_BITS 5
  159331. #endif
  159332. #ifndef PNG_DITHER_GREEN_BITS
  159333. # define PNG_DITHER_GREEN_BITS 5
  159334. #endif
  159335. #ifndef PNG_DITHER_BLUE_BITS
  159336. # define PNG_DITHER_BLUE_BITS 5
  159337. #endif
  159338. #ifndef PNG_MAX_GAMMA_8
  159339. # define PNG_MAX_GAMMA_8 11
  159340. #endif
  159341. #ifndef PNG_GAMMA_THRESHOLD
  159342. # define PNG_GAMMA_THRESHOLD 0.05
  159343. #endif
  159344. #endif /* PNG_INTERNAL */
  159345. #ifndef PNG_NO_CONST
  159346. # define PNG_CONST const
  159347. #else
  159348. # define PNG_CONST
  159349. #endif
  159350. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159351. # ifndef PNG_NO_iTXt_SUPPORTED
  159352. # define PNG_NO_iTXt_SUPPORTED
  159353. # endif
  159354. # ifndef PNG_NO_READ_iTXt
  159355. # define PNG_NO_READ_iTXt
  159356. # endif
  159357. # ifndef PNG_NO_WRITE_iTXt
  159358. # define PNG_NO_WRITE_iTXt
  159359. # endif
  159360. #endif
  159361. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159362. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159363. # define PNG_READ_iTXt
  159364. # endif
  159365. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159366. # define PNG_WRITE_iTXt
  159367. # endif
  159368. #endif
  159369. #ifdef PNG_LEGACY_SUPPORTED
  159370. # define PNG_NO_FREE_ME
  159371. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159372. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159373. # define PNG_NO_READ_USER_CHUNKS
  159374. # define PNG_NO_READ_iCCP
  159375. # define PNG_NO_WRITE_iCCP
  159376. # define PNG_NO_READ_iTXt
  159377. # define PNG_NO_WRITE_iTXt
  159378. # define PNG_NO_READ_sCAL
  159379. # define PNG_NO_WRITE_sCAL
  159380. # define PNG_NO_READ_sPLT
  159381. # define PNG_NO_WRITE_sPLT
  159382. # define PNG_NO_INFO_IMAGE
  159383. # define PNG_NO_READ_RGB_TO_GRAY
  159384. # define PNG_NO_READ_USER_TRANSFORM
  159385. # define PNG_NO_WRITE_USER_TRANSFORM
  159386. # define PNG_NO_USER_MEM
  159387. # define PNG_NO_READ_EMPTY_PLTE
  159388. # define PNG_NO_MNG_FEATURES
  159389. # define PNG_NO_FIXED_POINT_SUPPORTED
  159390. #endif
  159391. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159392. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159393. # define PNG_FIXED_POINT_SUPPORTED
  159394. #endif
  159395. #ifndef PNG_NO_FREE_ME
  159396. # define PNG_FREE_ME_SUPPORTED
  159397. #endif
  159398. #if defined(PNG_READ_SUPPORTED)
  159399. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159400. !defined(PNG_NO_READ_TRANSFORMS)
  159401. # define PNG_READ_TRANSFORMS_SUPPORTED
  159402. #endif
  159403. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159404. # ifndef PNG_NO_READ_EXPAND
  159405. # define PNG_READ_EXPAND_SUPPORTED
  159406. # endif
  159407. # ifndef PNG_NO_READ_SHIFT
  159408. # define PNG_READ_SHIFT_SUPPORTED
  159409. # endif
  159410. # ifndef PNG_NO_READ_PACK
  159411. # define PNG_READ_PACK_SUPPORTED
  159412. # endif
  159413. # ifndef PNG_NO_READ_BGR
  159414. # define PNG_READ_BGR_SUPPORTED
  159415. # endif
  159416. # ifndef PNG_NO_READ_SWAP
  159417. # define PNG_READ_SWAP_SUPPORTED
  159418. # endif
  159419. # ifndef PNG_NO_READ_PACKSWAP
  159420. # define PNG_READ_PACKSWAP_SUPPORTED
  159421. # endif
  159422. # ifndef PNG_NO_READ_INVERT
  159423. # define PNG_READ_INVERT_SUPPORTED
  159424. # endif
  159425. # ifndef PNG_NO_READ_DITHER
  159426. # define PNG_READ_DITHER_SUPPORTED
  159427. # endif
  159428. # ifndef PNG_NO_READ_BACKGROUND
  159429. # define PNG_READ_BACKGROUND_SUPPORTED
  159430. # endif
  159431. # ifndef PNG_NO_READ_16_TO_8
  159432. # define PNG_READ_16_TO_8_SUPPORTED
  159433. # endif
  159434. # ifndef PNG_NO_READ_FILLER
  159435. # define PNG_READ_FILLER_SUPPORTED
  159436. # endif
  159437. # ifndef PNG_NO_READ_GAMMA
  159438. # define PNG_READ_GAMMA_SUPPORTED
  159439. # endif
  159440. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159441. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159442. # endif
  159443. # ifndef PNG_NO_READ_SWAP_ALPHA
  159444. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159445. # endif
  159446. # ifndef PNG_NO_READ_INVERT_ALPHA
  159447. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159448. # endif
  159449. # ifndef PNG_NO_READ_STRIP_ALPHA
  159450. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159451. # endif
  159452. # ifndef PNG_NO_READ_USER_TRANSFORM
  159453. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159454. # endif
  159455. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159456. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159457. # endif
  159458. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159459. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159460. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159461. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159462. #endif /* about interlacing capability! You'll */
  159463. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159464. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159465. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159466. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159467. # endif
  159468. #endif
  159469. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159470. #ifndef PNG_NO_READ_EMPTY_PLTE
  159471. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159472. #endif
  159473. #endif
  159474. #endif /* PNG_READ_SUPPORTED */
  159475. #if defined(PNG_WRITE_SUPPORTED)
  159476. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159477. !defined(PNG_NO_WRITE_TRANSFORMS)
  159478. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159479. #endif
  159480. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159481. # ifndef PNG_NO_WRITE_SHIFT
  159482. # define PNG_WRITE_SHIFT_SUPPORTED
  159483. # endif
  159484. # ifndef PNG_NO_WRITE_PACK
  159485. # define PNG_WRITE_PACK_SUPPORTED
  159486. # endif
  159487. # ifndef PNG_NO_WRITE_BGR
  159488. # define PNG_WRITE_BGR_SUPPORTED
  159489. # endif
  159490. # ifndef PNG_NO_WRITE_SWAP
  159491. # define PNG_WRITE_SWAP_SUPPORTED
  159492. # endif
  159493. # ifndef PNG_NO_WRITE_PACKSWAP
  159494. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159495. # endif
  159496. # ifndef PNG_NO_WRITE_INVERT
  159497. # define PNG_WRITE_INVERT_SUPPORTED
  159498. # endif
  159499. # ifndef PNG_NO_WRITE_FILLER
  159500. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159501. # endif
  159502. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159503. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159504. # endif
  159505. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159506. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159507. # endif
  159508. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159509. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159510. # endif
  159511. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159512. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159513. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159514. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159515. encoders, but can cause trouble
  159516. if left undefined */
  159517. #endif
  159518. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159519. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159520. defined(PNG_FLOATING_POINT_SUPPORTED)
  159521. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159522. #endif
  159523. #ifndef PNG_NO_WRITE_FLUSH
  159524. # define PNG_WRITE_FLUSH_SUPPORTED
  159525. #endif
  159526. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159527. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159528. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159529. #endif
  159530. #endif
  159531. #endif /* PNG_WRITE_SUPPORTED */
  159532. #ifndef PNG_1_0_X
  159533. # ifndef PNG_NO_ERROR_NUMBERS
  159534. # define PNG_ERROR_NUMBERS_SUPPORTED
  159535. # endif
  159536. #endif /* PNG_1_0_X */
  159537. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159538. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159539. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159540. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159541. # endif
  159542. #endif
  159543. #ifndef PNG_NO_STDIO
  159544. # define PNG_TIME_RFC1123_SUPPORTED
  159545. #endif
  159546. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159547. # define PNG_EASY_ACCESS_SUPPORTED
  159548. #endif
  159549. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  159550. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  159551. # define PNG_OPTIMIZED_CODE_SUPPORTED
  159552. # endif
  159553. #endif
  159554. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  159555. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  159556. # define PNG_ASSEMBLER_CODE_SUPPORTED
  159557. # endif
  159558. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  159559. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159560. # define PNG_NO_MMX_CODE
  159561. # endif
  159562. # endif
  159563. # if defined(__APPLE__)
  159564. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159565. # define PNG_NO_MMX_CODE
  159566. # endif
  159567. # endif
  159568. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  159569. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159570. # define PNG_NO_MMX_CODE
  159571. # endif
  159572. # endif
  159573. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159574. # define PNG_MMX_CODE_SUPPORTED
  159575. # endif
  159576. #endif
  159577. #if !defined(PNG_1_0_X)
  159578. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  159579. # define PNG_USER_MEM_SUPPORTED
  159580. #endif
  159581. #endif /* PNG_1_0_X */
  159582. #if !defined(PNG_1_0_X)
  159583. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  159584. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  159585. # define PNG_SET_USER_LIMITS_SUPPORTED
  159586. #endif
  159587. #endif
  159588. #endif /* PNG_1_0_X */
  159589. #ifndef PNG_USER_WIDTH_MAX
  159590. # define PNG_USER_WIDTH_MAX 1000000L
  159591. #endif
  159592. #ifndef PNG_USER_HEIGHT_MAX
  159593. # define PNG_USER_HEIGHT_MAX 1000000L
  159594. #endif
  159595. #if defined(PNG_READ_SUPPORTED) && \
  159596. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159597. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  159598. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159599. #endif
  159600. #if defined(PNG_WRITE_SUPPORTED) && \
  159601. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159602. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  159603. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159604. #endif
  159605. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159606. #ifdef PNG_NO_READ_TEXT
  159607. # define PNG_NO_READ_iTXt
  159608. # define PNG_NO_READ_tEXt
  159609. # define PNG_NO_READ_zTXt
  159610. #endif
  159611. #ifndef PNG_NO_READ_bKGD
  159612. # define PNG_READ_bKGD_SUPPORTED
  159613. # define PNG_bKGD_SUPPORTED
  159614. #endif
  159615. #ifndef PNG_NO_READ_cHRM
  159616. # define PNG_READ_cHRM_SUPPORTED
  159617. # define PNG_cHRM_SUPPORTED
  159618. #endif
  159619. #ifndef PNG_NO_READ_gAMA
  159620. # define PNG_READ_gAMA_SUPPORTED
  159621. # define PNG_gAMA_SUPPORTED
  159622. #endif
  159623. #ifndef PNG_NO_READ_hIST
  159624. # define PNG_READ_hIST_SUPPORTED
  159625. # define PNG_hIST_SUPPORTED
  159626. #endif
  159627. #ifndef PNG_NO_READ_iCCP
  159628. # define PNG_READ_iCCP_SUPPORTED
  159629. # define PNG_iCCP_SUPPORTED
  159630. #endif
  159631. #ifndef PNG_NO_READ_iTXt
  159632. # ifndef PNG_READ_iTXt_SUPPORTED
  159633. # define PNG_READ_iTXt_SUPPORTED
  159634. # endif
  159635. # ifndef PNG_iTXt_SUPPORTED
  159636. # define PNG_iTXt_SUPPORTED
  159637. # endif
  159638. #endif
  159639. #ifndef PNG_NO_READ_oFFs
  159640. # define PNG_READ_oFFs_SUPPORTED
  159641. # define PNG_oFFs_SUPPORTED
  159642. #endif
  159643. #ifndef PNG_NO_READ_pCAL
  159644. # define PNG_READ_pCAL_SUPPORTED
  159645. # define PNG_pCAL_SUPPORTED
  159646. #endif
  159647. #ifndef PNG_NO_READ_sCAL
  159648. # define PNG_READ_sCAL_SUPPORTED
  159649. # define PNG_sCAL_SUPPORTED
  159650. #endif
  159651. #ifndef PNG_NO_READ_pHYs
  159652. # define PNG_READ_pHYs_SUPPORTED
  159653. # define PNG_pHYs_SUPPORTED
  159654. #endif
  159655. #ifndef PNG_NO_READ_sBIT
  159656. # define PNG_READ_sBIT_SUPPORTED
  159657. # define PNG_sBIT_SUPPORTED
  159658. #endif
  159659. #ifndef PNG_NO_READ_sPLT
  159660. # define PNG_READ_sPLT_SUPPORTED
  159661. # define PNG_sPLT_SUPPORTED
  159662. #endif
  159663. #ifndef PNG_NO_READ_sRGB
  159664. # define PNG_READ_sRGB_SUPPORTED
  159665. # define PNG_sRGB_SUPPORTED
  159666. #endif
  159667. #ifndef PNG_NO_READ_tEXt
  159668. # define PNG_READ_tEXt_SUPPORTED
  159669. # define PNG_tEXt_SUPPORTED
  159670. #endif
  159671. #ifndef PNG_NO_READ_tIME
  159672. # define PNG_READ_tIME_SUPPORTED
  159673. # define PNG_tIME_SUPPORTED
  159674. #endif
  159675. #ifndef PNG_NO_READ_tRNS
  159676. # define PNG_READ_tRNS_SUPPORTED
  159677. # define PNG_tRNS_SUPPORTED
  159678. #endif
  159679. #ifndef PNG_NO_READ_zTXt
  159680. # define PNG_READ_zTXt_SUPPORTED
  159681. # define PNG_zTXt_SUPPORTED
  159682. #endif
  159683. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  159684. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  159685. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159686. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159687. # endif
  159688. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159689. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159690. # endif
  159691. #endif
  159692. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  159693. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  159694. # define PNG_READ_USER_CHUNKS_SUPPORTED
  159695. # define PNG_USER_CHUNKS_SUPPORTED
  159696. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  159697. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  159698. # endif
  159699. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  159700. # undef PNG_NO_HANDLE_AS_UNKNOWN
  159701. # endif
  159702. #endif
  159703. #ifndef PNG_NO_READ_OPT_PLTE
  159704. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  159705. #endif /* optional PLTE chunk in RGB and RGBA images */
  159706. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  159707. defined(PNG_READ_zTXt_SUPPORTED)
  159708. # define PNG_READ_TEXT_SUPPORTED
  159709. # define PNG_TEXT_SUPPORTED
  159710. #endif
  159711. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  159712. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159713. #ifdef PNG_NO_WRITE_TEXT
  159714. # define PNG_NO_WRITE_iTXt
  159715. # define PNG_NO_WRITE_tEXt
  159716. # define PNG_NO_WRITE_zTXt
  159717. #endif
  159718. #ifndef PNG_NO_WRITE_bKGD
  159719. # define PNG_WRITE_bKGD_SUPPORTED
  159720. # ifndef PNG_bKGD_SUPPORTED
  159721. # define PNG_bKGD_SUPPORTED
  159722. # endif
  159723. #endif
  159724. #ifndef PNG_NO_WRITE_cHRM
  159725. # define PNG_WRITE_cHRM_SUPPORTED
  159726. # ifndef PNG_cHRM_SUPPORTED
  159727. # define PNG_cHRM_SUPPORTED
  159728. # endif
  159729. #endif
  159730. #ifndef PNG_NO_WRITE_gAMA
  159731. # define PNG_WRITE_gAMA_SUPPORTED
  159732. # ifndef PNG_gAMA_SUPPORTED
  159733. # define PNG_gAMA_SUPPORTED
  159734. # endif
  159735. #endif
  159736. #ifndef PNG_NO_WRITE_hIST
  159737. # define PNG_WRITE_hIST_SUPPORTED
  159738. # ifndef PNG_hIST_SUPPORTED
  159739. # define PNG_hIST_SUPPORTED
  159740. # endif
  159741. #endif
  159742. #ifndef PNG_NO_WRITE_iCCP
  159743. # define PNG_WRITE_iCCP_SUPPORTED
  159744. # ifndef PNG_iCCP_SUPPORTED
  159745. # define PNG_iCCP_SUPPORTED
  159746. # endif
  159747. #endif
  159748. #ifndef PNG_NO_WRITE_iTXt
  159749. # ifndef PNG_WRITE_iTXt_SUPPORTED
  159750. # define PNG_WRITE_iTXt_SUPPORTED
  159751. # endif
  159752. # ifndef PNG_iTXt_SUPPORTED
  159753. # define PNG_iTXt_SUPPORTED
  159754. # endif
  159755. #endif
  159756. #ifndef PNG_NO_WRITE_oFFs
  159757. # define PNG_WRITE_oFFs_SUPPORTED
  159758. # ifndef PNG_oFFs_SUPPORTED
  159759. # define PNG_oFFs_SUPPORTED
  159760. # endif
  159761. #endif
  159762. #ifndef PNG_NO_WRITE_pCAL
  159763. # define PNG_WRITE_pCAL_SUPPORTED
  159764. # ifndef PNG_pCAL_SUPPORTED
  159765. # define PNG_pCAL_SUPPORTED
  159766. # endif
  159767. #endif
  159768. #ifndef PNG_NO_WRITE_sCAL
  159769. # define PNG_WRITE_sCAL_SUPPORTED
  159770. # ifndef PNG_sCAL_SUPPORTED
  159771. # define PNG_sCAL_SUPPORTED
  159772. # endif
  159773. #endif
  159774. #ifndef PNG_NO_WRITE_pHYs
  159775. # define PNG_WRITE_pHYs_SUPPORTED
  159776. # ifndef PNG_pHYs_SUPPORTED
  159777. # define PNG_pHYs_SUPPORTED
  159778. # endif
  159779. #endif
  159780. #ifndef PNG_NO_WRITE_sBIT
  159781. # define PNG_WRITE_sBIT_SUPPORTED
  159782. # ifndef PNG_sBIT_SUPPORTED
  159783. # define PNG_sBIT_SUPPORTED
  159784. # endif
  159785. #endif
  159786. #ifndef PNG_NO_WRITE_sPLT
  159787. # define PNG_WRITE_sPLT_SUPPORTED
  159788. # ifndef PNG_sPLT_SUPPORTED
  159789. # define PNG_sPLT_SUPPORTED
  159790. # endif
  159791. #endif
  159792. #ifndef PNG_NO_WRITE_sRGB
  159793. # define PNG_WRITE_sRGB_SUPPORTED
  159794. # ifndef PNG_sRGB_SUPPORTED
  159795. # define PNG_sRGB_SUPPORTED
  159796. # endif
  159797. #endif
  159798. #ifndef PNG_NO_WRITE_tEXt
  159799. # define PNG_WRITE_tEXt_SUPPORTED
  159800. # ifndef PNG_tEXt_SUPPORTED
  159801. # define PNG_tEXt_SUPPORTED
  159802. # endif
  159803. #endif
  159804. #ifndef PNG_NO_WRITE_tIME
  159805. # define PNG_WRITE_tIME_SUPPORTED
  159806. # ifndef PNG_tIME_SUPPORTED
  159807. # define PNG_tIME_SUPPORTED
  159808. # endif
  159809. #endif
  159810. #ifndef PNG_NO_WRITE_tRNS
  159811. # define PNG_WRITE_tRNS_SUPPORTED
  159812. # ifndef PNG_tRNS_SUPPORTED
  159813. # define PNG_tRNS_SUPPORTED
  159814. # endif
  159815. #endif
  159816. #ifndef PNG_NO_WRITE_zTXt
  159817. # define PNG_WRITE_zTXt_SUPPORTED
  159818. # ifndef PNG_zTXt_SUPPORTED
  159819. # define PNG_zTXt_SUPPORTED
  159820. # endif
  159821. #endif
  159822. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  159823. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  159824. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159825. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159826. # endif
  159827. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159828. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159829. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159830. # endif
  159831. # endif
  159832. #endif
  159833. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  159834. defined(PNG_WRITE_zTXt_SUPPORTED)
  159835. # define PNG_WRITE_TEXT_SUPPORTED
  159836. # ifndef PNG_TEXT_SUPPORTED
  159837. # define PNG_TEXT_SUPPORTED
  159838. # endif
  159839. #endif
  159840. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  159841. #ifndef PNG_NO_INFO_IMAGE
  159842. # define PNG_INFO_IMAGE_SUPPORTED
  159843. #endif
  159844. #if defined(PNG_tIME_SUPPORTED)
  159845. # if !defined(_WIN32_WCE)
  159846. # include <time.h>
  159847. # endif
  159848. #endif
  159849. typedef unsigned long png_uint_32;
  159850. typedef long png_int_32;
  159851. typedef unsigned short png_uint_16;
  159852. typedef short png_int_16;
  159853. typedef unsigned char png_byte;
  159854. #ifdef PNG_SIZE_T
  159855. typedef PNG_SIZE_T png_size_t;
  159856. # define png_sizeof(x) png_convert_size(sizeof (x))
  159857. #else
  159858. typedef size_t png_size_t;
  159859. # define png_sizeof(x) sizeof (x)
  159860. #endif
  159861. #ifdef __BORLANDC__
  159862. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  159863. # define LDATA 1
  159864. # else
  159865. # define LDATA 0
  159866. # endif
  159867. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  159868. # define PNG_MAX_MALLOC_64K
  159869. # if (LDATA != 1)
  159870. # ifndef FAR
  159871. # define FAR __far
  159872. # endif
  159873. # define USE_FAR_KEYWORD
  159874. # endif /* LDATA != 1 */
  159875. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  159876. #endif /* __BORLANDC__ */
  159877. #if defined(FAR)
  159878. # if defined(M_I86MM)
  159879. # define USE_FAR_KEYWORD
  159880. # define FARDATA FAR
  159881. # include <dos.h>
  159882. # endif
  159883. #endif
  159884. #ifndef FAR
  159885. # define FAR
  159886. #endif
  159887. #ifndef FARDATA
  159888. # define FARDATA
  159889. #endif
  159890. typedef png_int_32 png_fixed_point;
  159891. typedef void FAR * png_voidp;
  159892. typedef png_byte FAR * png_bytep;
  159893. typedef png_uint_32 FAR * png_uint_32p;
  159894. typedef png_int_32 FAR * png_int_32p;
  159895. typedef png_uint_16 FAR * png_uint_16p;
  159896. typedef png_int_16 FAR * png_int_16p;
  159897. typedef PNG_CONST char FAR * png_const_charp;
  159898. typedef char FAR * png_charp;
  159899. typedef png_fixed_point FAR * png_fixed_point_p;
  159900. #ifndef PNG_NO_STDIO
  159901. #if defined(_WIN32_WCE)
  159902. typedef HANDLE png_FILE_p;
  159903. #else
  159904. typedef FILE * png_FILE_p;
  159905. #endif
  159906. #endif
  159907. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159908. typedef double FAR * png_doublep;
  159909. #endif
  159910. typedef png_byte FAR * FAR * png_bytepp;
  159911. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  159912. typedef png_int_32 FAR * FAR * png_int_32pp;
  159913. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  159914. typedef png_int_16 FAR * FAR * png_int_16pp;
  159915. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  159916. typedef char FAR * FAR * png_charpp;
  159917. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  159918. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159919. typedef double FAR * FAR * png_doublepp;
  159920. #endif
  159921. typedef char FAR * FAR * FAR * png_charppp;
  159922. #if 0
  159923. typedef charf * png_zcharp;
  159924. typedef charf * FAR * png_zcharpp;
  159925. typedef z_stream FAR * png_zstreamp;
  159926. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  159927. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  159928. # define PNG_DLL
  159929. #endif
  159930. #if defined(__CYGWIN__)
  159931. # if !defined(PNG_STATIC)
  159932. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159933. # undef PNG_USE_GLOBAL_ARRAYS
  159934. # endif
  159935. # if !defined(PNG_USE_LOCAL_ARRAYS)
  159936. # define PNG_USE_LOCAL_ARRAYS
  159937. # endif
  159938. # else
  159939. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  159940. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159941. # undef PNG_USE_GLOBAL_ARRAYS
  159942. # endif
  159943. # endif
  159944. # endif
  159945. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159946. # define PNG_USE_LOCAL_ARRAYS
  159947. # endif
  159948. #endif
  159949. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159950. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  159951. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  159952. # define PNG_USE_LOCAL_ARRAYS
  159953. # else
  159954. # define PNG_USE_GLOBAL_ARRAYS
  159955. # endif
  159956. #endif
  159957. #if defined(__CYGWIN__)
  159958. # undef PNGAPI
  159959. # define PNGAPI __cdecl
  159960. # undef PNG_IMPEXP
  159961. # define PNG_IMPEXP
  159962. #endif
  159963. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  159964. # ifndef PNG_NO_MODULEDEF
  159965. # define PNG_NO_MODULEDEF
  159966. # endif
  159967. #endif
  159968. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  159969. # define PNG_IMPEXP
  159970. #endif
  159971. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  159972. (( defined(_Windows) || defined(_WINDOWS) || \
  159973. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  159974. # ifndef PNGAPI
  159975. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  159976. # define PNGAPI __cdecl
  159977. # else
  159978. # define PNGAPI _cdecl
  159979. # endif
  159980. # endif
  159981. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  159982. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  159983. # define PNG_IMPEXP
  159984. # endif
  159985. # if !defined(PNG_IMPEXP)
  159986. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  159987. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  159988. # if defined(_MSC_VER) || defined(__BORLANDC__)
  159989. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  159990. # define PNG_EXPORT PNG_EXPORT_TYPE1
  159991. # else
  159992. # define PNG_EXPORT PNG_EXPORT_TYPE2
  159993. # if defined(PNG_BUILD_DLL)
  159994. # define PNG_IMPEXP __export
  159995. # else
  159996. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  159997. VC++ */
  159998. # endif /* Exists in Borland C++ for
  159999. C++ classes (== huge) */
  160000. # endif
  160001. # endif
  160002. # if !defined(PNG_IMPEXP)
  160003. # if defined(PNG_BUILD_DLL)
  160004. # define PNG_IMPEXP __declspec(dllexport)
  160005. # else
  160006. # define PNG_IMPEXP __declspec(dllimport)
  160007. # endif
  160008. # endif
  160009. # endif /* PNG_IMPEXP */
  160010. #else /* !(DLL || non-cygwin WINDOWS) */
  160011. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160012. # ifndef PNGAPI
  160013. # define PNGAPI _System
  160014. # endif
  160015. # else
  160016. # if 0 /* ... other platforms, with other meanings */
  160017. # endif
  160018. # endif
  160019. #endif
  160020. #ifndef PNGAPI
  160021. # define PNGAPI
  160022. #endif
  160023. #ifndef PNG_IMPEXP
  160024. # define PNG_IMPEXP
  160025. #endif
  160026. #ifdef PNG_BUILDSYMS
  160027. # ifndef PNG_EXPORT
  160028. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160029. # endif
  160030. # ifdef PNG_USE_GLOBAL_ARRAYS
  160031. # ifndef PNG_EXPORT_VAR
  160032. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160033. # endif
  160034. # endif
  160035. #endif
  160036. #ifndef PNG_EXPORT
  160037. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160038. #endif
  160039. #ifdef PNG_USE_GLOBAL_ARRAYS
  160040. # ifndef PNG_EXPORT_VAR
  160041. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160042. # endif
  160043. #endif
  160044. #ifndef PNG_ABORT
  160045. # define PNG_ABORT() abort()
  160046. #endif
  160047. #ifdef PNG_SETJMP_SUPPORTED
  160048. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160049. #else
  160050. # define png_jmpbuf(png_ptr) \
  160051. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160052. #endif
  160053. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160054. # define CHECK 1
  160055. # define NOCHECK 0
  160056. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160057. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160058. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160059. # define png_strcpy _fstrcpy
  160060. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160061. # define png_strlen _fstrlen
  160062. # define png_memcmp _fmemcmp /* SJT: added */
  160063. # define png_memcpy _fmemcpy
  160064. # define png_memset _fmemset
  160065. #else /* use the usual functions */
  160066. # define CVT_PTR(ptr) (ptr)
  160067. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160068. # ifndef PNG_NO_SNPRINTF
  160069. # ifdef _MSC_VER
  160070. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160071. # define png_snprintf2 _snprintf
  160072. # define png_snprintf6 _snprintf
  160073. # else
  160074. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160075. # define png_snprintf2 snprintf
  160076. # define png_snprintf6 snprintf
  160077. # endif
  160078. # else
  160079. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160080. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160081. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160082. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160083. # endif
  160084. # define png_strcpy strcpy
  160085. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160086. # define png_strlen strlen
  160087. # define png_memcmp memcmp /* SJT: added */
  160088. # define png_memcpy memcpy
  160089. # define png_memset memset
  160090. #endif
  160091. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160092. # undef PNG_ZBUF_SIZE
  160093. # define PNG_ZBUF_SIZE 65536L
  160094. #endif
  160095. #endif /* PNG_VERSION_INFO_ONLY */
  160096. #endif /* PNGCONF_H */
  160097. /*** End of inlined file: pngconf.h ***/
  160098. #ifdef _MSC_VER
  160099. #pragma warning (disable: 4996 4100)
  160100. #endif
  160101. #if defined(PNG_USER_PRIVATEBUILD)
  160102. # define PNG_LIBPNG_BUILD_TYPE \
  160103. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160104. #else
  160105. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160106. # define PNG_LIBPNG_BUILD_TYPE \
  160107. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160108. # else
  160109. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160110. # endif
  160111. #endif
  160112. #ifndef PNG_VERSION_INFO_ONLY
  160113. #ifdef __cplusplus
  160114. extern "C" {
  160115. #endif /* __cplusplus */
  160116. #ifndef PNG_NO_TYPECAST_NULL
  160117. #define int_p_NULL (int *)NULL
  160118. #define png_bytep_NULL (png_bytep)NULL
  160119. #define png_bytepp_NULL (png_bytepp)NULL
  160120. #define png_doublep_NULL (png_doublep)NULL
  160121. #define png_error_ptr_NULL (png_error_ptr)NULL
  160122. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160123. #define png_free_ptr_NULL (png_free_ptr)NULL
  160124. #define png_infopp_NULL (png_infopp)NULL
  160125. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160126. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160127. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160128. #define png_structp_NULL (png_structp)NULL
  160129. #define png_uint_16p_NULL (png_uint_16p)NULL
  160130. #define png_voidp_NULL (png_voidp)NULL
  160131. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160132. #else
  160133. #define int_p_NULL NULL
  160134. #define png_bytep_NULL NULL
  160135. #define png_bytepp_NULL NULL
  160136. #define png_doublep_NULL NULL
  160137. #define png_error_ptr_NULL NULL
  160138. #define png_flush_ptr_NULL NULL
  160139. #define png_free_ptr_NULL NULL
  160140. #define png_infopp_NULL NULL
  160141. #define png_malloc_ptr_NULL NULL
  160142. #define png_read_status_ptr_NULL NULL
  160143. #define png_rw_ptr_NULL NULL
  160144. #define png_structp_NULL NULL
  160145. #define png_uint_16p_NULL NULL
  160146. #define png_voidp_NULL NULL
  160147. #define png_write_status_ptr_NULL NULL
  160148. #endif
  160149. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160150. #ifdef PNG_USE_GLOBAL_ARRAYS
  160151. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160152. #else
  160153. #define png_libpng_ver png_get_header_ver(NULL)
  160154. #endif
  160155. #ifdef PNG_USE_GLOBAL_ARRAYS
  160156. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160157. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160158. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160159. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160160. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160161. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160162. #endif
  160163. #endif /* PNG_NO_EXTERN */
  160164. typedef struct png_color_struct
  160165. {
  160166. png_byte red;
  160167. png_byte green;
  160168. png_byte blue;
  160169. } png_color;
  160170. typedef png_color FAR * png_colorp;
  160171. typedef png_color FAR * FAR * png_colorpp;
  160172. typedef struct png_color_16_struct
  160173. {
  160174. png_byte index; /* used for palette files */
  160175. png_uint_16 red; /* for use in red green blue files */
  160176. png_uint_16 green;
  160177. png_uint_16 blue;
  160178. png_uint_16 gray; /* for use in grayscale files */
  160179. } png_color_16;
  160180. typedef png_color_16 FAR * png_color_16p;
  160181. typedef png_color_16 FAR * FAR * png_color_16pp;
  160182. typedef struct png_color_8_struct
  160183. {
  160184. png_byte red; /* for use in red green blue files */
  160185. png_byte green;
  160186. png_byte blue;
  160187. png_byte gray; /* for use in grayscale files */
  160188. png_byte alpha; /* for alpha channel files */
  160189. } png_color_8;
  160190. typedef png_color_8 FAR * png_color_8p;
  160191. typedef png_color_8 FAR * FAR * png_color_8pp;
  160192. typedef struct png_sPLT_entry_struct
  160193. {
  160194. png_uint_16 red;
  160195. png_uint_16 green;
  160196. png_uint_16 blue;
  160197. png_uint_16 alpha;
  160198. png_uint_16 frequency;
  160199. } png_sPLT_entry;
  160200. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160201. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160202. typedef struct png_sPLT_struct
  160203. {
  160204. png_charp name; /* palette name */
  160205. png_byte depth; /* depth of palette samples */
  160206. png_sPLT_entryp entries; /* palette entries */
  160207. png_int_32 nentries; /* number of palette entries */
  160208. } png_sPLT_t;
  160209. typedef png_sPLT_t FAR * png_sPLT_tp;
  160210. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160211. #ifdef PNG_TEXT_SUPPORTED
  160212. typedef struct png_text_struct
  160213. {
  160214. int compression; /* compression value:
  160215. -1: tEXt, none
  160216. 0: zTXt, deflate
  160217. 1: iTXt, none
  160218. 2: iTXt, deflate */
  160219. png_charp key; /* keyword, 1-79 character description of "text" */
  160220. png_charp text; /* comment, may be an empty string (ie "")
  160221. or a NULL pointer */
  160222. png_size_t text_length; /* length of the text string */
  160223. #ifdef PNG_iTXt_SUPPORTED
  160224. png_size_t itxt_length; /* length of the itxt string */
  160225. png_charp lang; /* language code, 0-79 characters
  160226. or a NULL pointer */
  160227. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160228. chars or a NULL pointer */
  160229. #endif
  160230. } png_text;
  160231. typedef png_text FAR * png_textp;
  160232. typedef png_text FAR * FAR * png_textpp;
  160233. #endif
  160234. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160235. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160236. #define PNG_TEXT_COMPRESSION_NONE -1
  160237. #define PNG_TEXT_COMPRESSION_zTXt 0
  160238. #define PNG_ITXT_COMPRESSION_NONE 1
  160239. #define PNG_ITXT_COMPRESSION_zTXt 2
  160240. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160241. typedef struct png_time_struct
  160242. {
  160243. png_uint_16 year; /* full year, as in, 1995 */
  160244. png_byte month; /* month of year, 1 - 12 */
  160245. png_byte day; /* day of month, 1 - 31 */
  160246. png_byte hour; /* hour of day, 0 - 23 */
  160247. png_byte minute; /* minute of hour, 0 - 59 */
  160248. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160249. } png_time;
  160250. typedef png_time FAR * png_timep;
  160251. typedef png_time FAR * FAR * png_timepp;
  160252. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160253. typedef struct png_unknown_chunk_t
  160254. {
  160255. png_byte name[5];
  160256. png_byte *data;
  160257. png_size_t size;
  160258. png_byte location; /* mode of operation at read time */
  160259. }
  160260. png_unknown_chunk;
  160261. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160262. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160263. #endif
  160264. typedef struct png_info_struct
  160265. {
  160266. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160267. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160268. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160269. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160270. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160271. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160272. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160273. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160274. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160275. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160276. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160277. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160278. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160279. png_byte pixel_depth; /* number of bits per pixel */
  160280. png_byte spare_byte; /* to align the data, and for future use */
  160281. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160282. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160283. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160284. #endif
  160285. #if defined(PNG_sRGB_SUPPORTED)
  160286. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160287. #endif
  160288. #if defined(PNG_TEXT_SUPPORTED)
  160289. int num_text; /* number of comments read/to write */
  160290. int max_text; /* current size of text array */
  160291. png_textp text; /* array of comments read/to write */
  160292. #endif /* PNG_TEXT_SUPPORTED */
  160293. #if defined(PNG_tIME_SUPPORTED)
  160294. png_time mod_time;
  160295. #endif
  160296. #if defined(PNG_sBIT_SUPPORTED)
  160297. png_color_8 sig_bit; /* significant bits in color channels */
  160298. #endif
  160299. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160300. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160301. png_bytep trans; /* transparent values for paletted image */
  160302. png_color_16 trans_values; /* transparent color for non-palette image */
  160303. #endif
  160304. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160305. png_color_16 background;
  160306. #endif
  160307. #if defined(PNG_oFFs_SUPPORTED)
  160308. png_int_32 x_offset; /* x offset on page */
  160309. png_int_32 y_offset; /* y offset on page */
  160310. png_byte offset_unit_type; /* offset units type */
  160311. #endif
  160312. #if defined(PNG_pHYs_SUPPORTED)
  160313. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160314. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160315. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160316. #endif
  160317. #if defined(PNG_hIST_SUPPORTED)
  160318. png_uint_16p hist;
  160319. #endif
  160320. #ifdef PNG_cHRM_SUPPORTED
  160321. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160322. float x_white;
  160323. float y_white;
  160324. float x_red;
  160325. float y_red;
  160326. float x_green;
  160327. float y_green;
  160328. float x_blue;
  160329. float y_blue;
  160330. #endif
  160331. #endif
  160332. #if defined(PNG_pCAL_SUPPORTED)
  160333. png_charp pcal_purpose; /* pCAL chunk description string */
  160334. png_int_32 pcal_X0; /* minimum value */
  160335. png_int_32 pcal_X1; /* maximum value */
  160336. png_charp pcal_units; /* Latin-1 string giving physical units */
  160337. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160338. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160339. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160340. #endif
  160341. #ifdef PNG_FREE_ME_SUPPORTED
  160342. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160343. #endif
  160344. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160345. png_unknown_chunkp unknown_chunks;
  160346. png_size_t unknown_chunks_num;
  160347. #endif
  160348. #if defined(PNG_iCCP_SUPPORTED)
  160349. png_charp iccp_name; /* profile name */
  160350. png_charp iccp_profile; /* International Color Consortium profile data */
  160351. png_uint_32 iccp_proflen; /* ICC profile data length */
  160352. png_byte iccp_compression; /* Always zero */
  160353. #endif
  160354. #if defined(PNG_sPLT_SUPPORTED)
  160355. png_sPLT_tp splt_palettes;
  160356. png_uint_32 splt_palettes_num;
  160357. #endif
  160358. #if defined(PNG_sCAL_SUPPORTED)
  160359. png_byte scal_unit; /* unit of physical scale */
  160360. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160361. double scal_pixel_width; /* width of one pixel */
  160362. double scal_pixel_height; /* height of one pixel */
  160363. #endif
  160364. #ifdef PNG_FIXED_POINT_SUPPORTED
  160365. png_charp scal_s_width; /* string containing height */
  160366. png_charp scal_s_height; /* string containing width */
  160367. #endif
  160368. #endif
  160369. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160370. png_bytepp row_pointers; /* the image bits */
  160371. #endif
  160372. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160373. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160374. #endif
  160375. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160376. png_fixed_point int_x_white;
  160377. png_fixed_point int_y_white;
  160378. png_fixed_point int_x_red;
  160379. png_fixed_point int_y_red;
  160380. png_fixed_point int_x_green;
  160381. png_fixed_point int_y_green;
  160382. png_fixed_point int_x_blue;
  160383. png_fixed_point int_y_blue;
  160384. #endif
  160385. } png_info;
  160386. typedef png_info FAR * png_infop;
  160387. typedef png_info FAR * FAR * png_infopp;
  160388. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160389. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160390. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160391. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160392. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160393. #endif
  160394. #define PNG_COLOR_MASK_PALETTE 1
  160395. #define PNG_COLOR_MASK_COLOR 2
  160396. #define PNG_COLOR_MASK_ALPHA 4
  160397. #define PNG_COLOR_TYPE_GRAY 0
  160398. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160399. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160400. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160401. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160402. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160403. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160404. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160405. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160406. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160407. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160408. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160409. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160410. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160411. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160412. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160413. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160414. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160415. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160416. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160417. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160418. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160419. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160420. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160421. #define PNG_SCALE_METER 1 /* meters per pixel */
  160422. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160423. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160424. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160425. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160426. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160427. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160428. #define PNG_sRGB_INTENT_RELATIVE 1
  160429. #define PNG_sRGB_INTENT_SATURATION 2
  160430. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160431. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160432. #define PNG_KEYWORD_MAX_LENGTH 79
  160433. #define PNG_MAX_PALETTE_LENGTH 256
  160434. #define PNG_INFO_gAMA 0x0001
  160435. #define PNG_INFO_sBIT 0x0002
  160436. #define PNG_INFO_cHRM 0x0004
  160437. #define PNG_INFO_PLTE 0x0008
  160438. #define PNG_INFO_tRNS 0x0010
  160439. #define PNG_INFO_bKGD 0x0020
  160440. #define PNG_INFO_hIST 0x0040
  160441. #define PNG_INFO_pHYs 0x0080
  160442. #define PNG_INFO_oFFs 0x0100
  160443. #define PNG_INFO_tIME 0x0200
  160444. #define PNG_INFO_pCAL 0x0400
  160445. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160446. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160447. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160448. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160449. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160450. typedef struct png_row_info_struct
  160451. {
  160452. png_uint_32 width; /* width of row */
  160453. png_uint_32 rowbytes; /* number of bytes in row */
  160454. png_byte color_type; /* color type of row */
  160455. png_byte bit_depth; /* bit depth of row */
  160456. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160457. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160458. } png_row_info;
  160459. typedef png_row_info FAR * png_row_infop;
  160460. typedef png_row_info FAR * FAR * png_row_infopp;
  160461. typedef struct png_struct_def png_struct;
  160462. typedef png_struct FAR * png_structp;
  160463. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160464. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160465. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160466. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160467. int));
  160468. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160469. int));
  160470. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160471. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160472. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160473. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160474. png_uint_32, int));
  160475. #endif
  160476. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160477. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160478. defined(PNG_LEGACY_SUPPORTED)
  160479. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160480. png_row_infop, png_bytep));
  160481. #endif
  160482. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160483. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160484. #endif
  160485. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160486. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160487. #endif
  160488. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160489. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160490. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160491. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160492. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160493. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160494. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160495. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160496. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160497. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160498. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160499. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160500. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160501. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160502. #define PNG_FLAG_MNG_FILTER_64 0x04
  160503. #define PNG_ALL_MNG_FEATURES 0x05
  160504. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160505. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160506. struct png_struct_def
  160507. {
  160508. #ifdef PNG_SETJMP_SUPPORTED
  160509. jmp_buf jmpbuf; /* used in png_error */
  160510. #endif
  160511. png_error_ptr error_fn; /* function for printing errors and aborting */
  160512. png_error_ptr warning_fn; /* function for printing warnings */
  160513. png_voidp error_ptr; /* user supplied struct for error functions */
  160514. png_rw_ptr write_data_fn; /* function for writing output data */
  160515. png_rw_ptr read_data_fn; /* function for reading input data */
  160516. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160517. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160518. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160519. #endif
  160520. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160521. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160522. #endif
  160523. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160524. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160525. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160526. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160527. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160528. png_byte user_transform_channels; /* channels in user transformed pixels */
  160529. #endif
  160530. #endif
  160531. png_uint_32 mode; /* tells us where we are in the PNG file */
  160532. png_uint_32 flags; /* flags indicating various things to libpng */
  160533. png_uint_32 transformations; /* which transformations to perform */
  160534. z_stream zstream; /* pointer to decompression structure (below) */
  160535. png_bytep zbuf; /* buffer for zlib */
  160536. png_size_t zbuf_size; /* size of zbuf */
  160537. int zlib_level; /* holds zlib compression level */
  160538. int zlib_method; /* holds zlib compression method */
  160539. int zlib_window_bits; /* holds zlib compression window bits */
  160540. int zlib_mem_level; /* holds zlib compression memory level */
  160541. int zlib_strategy; /* holds zlib compression strategy */
  160542. png_uint_32 width; /* width of image in pixels */
  160543. png_uint_32 height; /* height of image in pixels */
  160544. png_uint_32 num_rows; /* number of rows in current pass */
  160545. png_uint_32 usr_width; /* width of row at start of write */
  160546. png_uint_32 rowbytes; /* size of row in bytes */
  160547. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  160548. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  160549. png_uint_32 row_number; /* current row in interlace pass */
  160550. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  160551. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  160552. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  160553. png_bytep up_row; /* buffer to save "up" row when filtering */
  160554. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  160555. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  160556. png_row_info row_info; /* used for transformation routines */
  160557. png_uint_32 idat_size; /* current IDAT size for read */
  160558. png_uint_32 crc; /* current chunk CRC value */
  160559. png_colorp palette; /* palette from the input file */
  160560. png_uint_16 num_palette; /* number of color entries in palette */
  160561. png_uint_16 num_trans; /* number of transparency values */
  160562. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  160563. png_byte compression; /* file compression type (always 0) */
  160564. png_byte filter; /* file filter type (always 0) */
  160565. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160566. png_byte pass; /* current interlace pass (0 - 6) */
  160567. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  160568. png_byte color_type; /* color type of file */
  160569. png_byte bit_depth; /* bit depth of file */
  160570. png_byte usr_bit_depth; /* bit depth of users row */
  160571. png_byte pixel_depth; /* number of bits per pixel */
  160572. png_byte channels; /* number of channels in file */
  160573. png_byte usr_channels; /* channels at start of write */
  160574. png_byte sig_bytes; /* magic bytes read/written from start of file */
  160575. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160576. #ifdef PNG_LEGACY_SUPPORTED
  160577. png_byte filler; /* filler byte for pixel expansion */
  160578. #else
  160579. png_uint_16 filler; /* filler bytes for pixel expansion */
  160580. #endif
  160581. #endif
  160582. #if defined(PNG_bKGD_SUPPORTED)
  160583. png_byte background_gamma_type;
  160584. # ifdef PNG_FLOATING_POINT_SUPPORTED
  160585. float background_gamma;
  160586. # endif
  160587. png_color_16 background; /* background color in screen gamma space */
  160588. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160589. png_color_16 background_1; /* background normalized to gamma 1.0 */
  160590. #endif
  160591. #endif /* PNG_bKGD_SUPPORTED */
  160592. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160593. png_flush_ptr output_flush_fn;/* Function for flushing output */
  160594. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  160595. png_uint_32 flush_rows; /* number of rows written since last flush */
  160596. #endif
  160597. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160598. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  160599. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160600. float gamma; /* file gamma value */
  160601. float screen_gamma; /* screen gamma value (display_exponent) */
  160602. #endif
  160603. #endif
  160604. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160605. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  160606. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  160607. png_bytep gamma_to_1; /* converts from file to 1.0 */
  160608. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  160609. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  160610. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  160611. #endif
  160612. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  160613. png_color_8 sig_bit; /* significant bits in each available channel */
  160614. #endif
  160615. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160616. png_color_8 shift; /* shift for significant bit tranformation */
  160617. #endif
  160618. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  160619. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160620. png_bytep trans; /* transparency values for paletted files */
  160621. png_color_16 trans_values; /* transparency values for non-paletted files */
  160622. #endif
  160623. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  160624. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  160625. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160626. png_progressive_info_ptr info_fn; /* called after header data fully read */
  160627. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  160628. png_progressive_end_ptr end_fn; /* called after image is complete */
  160629. png_bytep save_buffer_ptr; /* current location in save_buffer */
  160630. png_bytep save_buffer; /* buffer for previously read data */
  160631. png_bytep current_buffer_ptr; /* current location in current_buffer */
  160632. png_bytep current_buffer; /* buffer for recently used data */
  160633. png_uint_32 push_length; /* size of current input chunk */
  160634. png_uint_32 skip_length; /* bytes to skip in input data */
  160635. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  160636. png_size_t save_buffer_max; /* total size of save_buffer */
  160637. png_size_t buffer_size; /* total amount of available input data */
  160638. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  160639. int process_mode; /* what push library is currently doing */
  160640. int cur_palette; /* current push library palette index */
  160641. # if defined(PNG_TEXT_SUPPORTED)
  160642. png_size_t current_text_size; /* current size of text input data */
  160643. png_size_t current_text_left; /* how much text left to read in input */
  160644. png_charp current_text; /* current text chunk buffer */
  160645. png_charp current_text_ptr; /* current location in current_text */
  160646. # endif /* PNG_TEXT_SUPPORTED */
  160647. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160648. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  160649. png_bytepp offset_table_ptr;
  160650. png_bytep offset_table;
  160651. png_uint_16 offset_table_number;
  160652. png_uint_16 offset_table_count;
  160653. png_uint_16 offset_table_count_free;
  160654. #endif
  160655. #if defined(PNG_READ_DITHER_SUPPORTED)
  160656. png_bytep palette_lookup; /* lookup table for dithering */
  160657. png_bytep dither_index; /* index translation for palette files */
  160658. #endif
  160659. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  160660. png_uint_16p hist; /* histogram */
  160661. #endif
  160662. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  160663. png_byte heuristic_method; /* heuristic for row filter selection */
  160664. png_byte num_prev_filters; /* number of weights for previous rows */
  160665. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  160666. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  160667. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  160668. png_uint_16p filter_costs; /* relative filter calculation cost */
  160669. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  160670. #endif
  160671. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160672. png_charp time_buffer; /* String to hold RFC 1123 time text */
  160673. #endif
  160674. #ifdef PNG_FREE_ME_SUPPORTED
  160675. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160676. #endif
  160677. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160678. png_voidp user_chunk_ptr;
  160679. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  160680. #endif
  160681. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160682. int num_chunk_list;
  160683. png_bytep chunk_list;
  160684. #endif
  160685. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160686. png_byte rgb_to_gray_status;
  160687. png_uint_16 rgb_to_gray_red_coeff;
  160688. png_uint_16 rgb_to_gray_green_coeff;
  160689. png_uint_16 rgb_to_gray_blue_coeff;
  160690. #endif
  160691. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  160692. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160693. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160694. #ifdef PNG_1_0_X
  160695. png_byte mng_features_permitted;
  160696. #else
  160697. png_uint_32 mng_features_permitted;
  160698. #endif /* PNG_1_0_X */
  160699. #endif
  160700. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160701. png_fixed_point int_gamma;
  160702. #endif
  160703. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  160704. png_byte filter_type;
  160705. #endif
  160706. #if defined(PNG_1_0_X)
  160707. png_uint_32 row_buf_size;
  160708. #endif
  160709. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  160710. # if !defined(PNG_1_0_X)
  160711. # if defined(PNG_MMX_CODE_SUPPORTED)
  160712. png_byte mmx_bitdepth_threshold;
  160713. png_uint_32 mmx_rowbytes_threshold;
  160714. # endif
  160715. png_uint_32 asm_flags;
  160716. # endif
  160717. #endif
  160718. #ifdef PNG_USER_MEM_SUPPORTED
  160719. png_voidp mem_ptr; /* user supplied struct for mem functions */
  160720. png_malloc_ptr malloc_fn; /* function for allocating memory */
  160721. png_free_ptr free_fn; /* function for freeing memory */
  160722. #endif
  160723. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  160724. #if defined(PNG_READ_DITHER_SUPPORTED)
  160725. png_bytep dither_sort; /* working sort array */
  160726. png_bytep index_to_palette; /* where the original index currently is */
  160727. png_bytep palette_to_index; /* which original index points to this */
  160728. #endif
  160729. png_byte compression_type;
  160730. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  160731. png_uint_32 user_width_max;
  160732. png_uint_32 user_height_max;
  160733. #endif
  160734. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160735. png_unknown_chunk unknown_chunk;
  160736. #endif
  160737. };
  160738. typedef png_structp version_1_2_21;
  160739. typedef png_struct FAR * FAR * png_structpp;
  160740. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  160741. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  160742. int num_bytes));
  160743. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  160744. png_size_t num_to_check));
  160745. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  160746. extern PNG_EXPORT(png_structp,png_create_read_struct)
  160747. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160748. png_error_ptr error_fn, png_error_ptr warn_fn));
  160749. extern PNG_EXPORT(png_structp,png_create_write_struct)
  160750. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160751. png_error_ptr error_fn, png_error_ptr warn_fn));
  160752. #ifdef PNG_WRITE_SUPPORTED
  160753. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  160754. PNGARG((png_structp png_ptr));
  160755. #endif
  160756. #ifdef PNG_WRITE_SUPPORTED
  160757. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  160758. PNGARG((png_structp png_ptr, png_uint_32 size));
  160759. #endif
  160760. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  160761. #ifdef PNG_USER_MEM_SUPPORTED
  160762. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  160763. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160764. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160765. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160766. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  160767. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160768. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160769. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160770. #endif
  160771. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  160772. png_bytep chunk_name, png_bytep data, png_size_t length));
  160773. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  160774. png_bytep chunk_name, png_uint_32 length));
  160775. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  160776. png_bytep data, png_size_t length));
  160777. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  160778. extern PNG_EXPORT(png_infop,png_create_info_struct)
  160779. PNGARG((png_structp png_ptr));
  160780. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160781. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  160782. #undef png_info_init
  160783. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  160784. png_sizeof(png_info));
  160785. #endif
  160786. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  160787. png_size_t png_info_struct_size));
  160788. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  160789. png_infop info_ptr));
  160790. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  160791. png_infop info_ptr));
  160792. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160793. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  160794. png_infop info_ptr));
  160795. #endif
  160796. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160797. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  160798. PNGARG((png_structp png_ptr, png_timep ptime));
  160799. #endif
  160800. #if !defined(_WIN32_WCE)
  160801. #if defined(PNG_WRITE_tIME_SUPPORTED)
  160802. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  160803. struct tm FAR * ttime));
  160804. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  160805. time_t ttime));
  160806. #endif /* PNG_WRITE_tIME_SUPPORTED */
  160807. #endif /* _WIN32_WCE */
  160808. #if defined(PNG_READ_EXPAND_SUPPORTED)
  160809. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  160810. #if !defined(PNG_1_0_X)
  160811. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  160812. png_ptr));
  160813. #endif
  160814. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  160815. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  160816. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160817. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  160818. #endif
  160819. #endif
  160820. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  160821. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  160822. #endif
  160823. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  160824. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  160825. #endif
  160826. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160827. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160828. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  160829. int error_action, double red, double green ));
  160830. #endif
  160831. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  160832. int error_action, png_fixed_point red, png_fixed_point green ));
  160833. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  160834. png_ptr));
  160835. #endif
  160836. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  160837. png_colorp palette));
  160838. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  160839. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  160840. #endif
  160841. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  160842. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  160843. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  160844. #endif
  160845. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  160846. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  160847. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  160848. #endif
  160849. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160850. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  160851. png_uint_32 filler, int flags));
  160852. #define PNG_FILLER_BEFORE 0
  160853. #define PNG_FILLER_AFTER 1
  160854. #if !defined(PNG_1_0_X)
  160855. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  160856. png_uint_32 filler, int flags));
  160857. #endif
  160858. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  160859. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  160860. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  160861. #endif
  160862. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  160863. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  160864. #endif
  160865. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  160866. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  160867. #endif
  160868. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160869. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  160870. png_color_8p true_bits));
  160871. #endif
  160872. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  160873. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  160874. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  160875. #endif
  160876. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  160877. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  160878. #endif
  160879. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  160880. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160881. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  160882. png_color_16p background_color, int background_gamma_code,
  160883. int need_expand, double background_gamma));
  160884. #endif
  160885. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  160886. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  160887. #define PNG_BACKGROUND_GAMMA_FILE 2
  160888. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  160889. #endif
  160890. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  160891. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  160892. #endif
  160893. #if defined(PNG_READ_DITHER_SUPPORTED)
  160894. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  160895. png_colorp palette, int num_palette, int maximum_colors,
  160896. png_uint_16p histogram, int full_dither));
  160897. #endif
  160898. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160899. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160900. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  160901. double screen_gamma, double default_file_gamma));
  160902. #endif
  160903. #endif
  160904. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160905. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160906. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160907. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  160908. int empty_plte_permitted));
  160909. #endif
  160910. #endif
  160911. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160912. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  160913. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  160914. #endif
  160915. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  160916. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  160917. png_infop info_ptr));
  160918. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160919. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  160920. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  160921. #endif
  160922. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160923. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  160924. png_bytep row,
  160925. png_bytep display_row));
  160926. #endif
  160927. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160928. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  160929. png_bytepp image));
  160930. #endif
  160931. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  160932. png_bytep row));
  160933. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  160934. png_bytepp row, png_uint_32 num_rows));
  160935. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  160936. png_bytepp image));
  160937. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  160938. png_infop info_ptr));
  160939. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160940. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  160941. png_infop info_ptr));
  160942. #endif
  160943. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  160944. png_infopp info_ptr_ptr));
  160945. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  160946. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  160947. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  160948. png_infop end_info_ptr));
  160949. extern PNG_EXPORT(void,png_destroy_write_struct)
  160950. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  160951. extern void png_write_destroy PNGARG((png_structp png_ptr));
  160952. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  160953. int crit_action, int ancil_action));
  160954. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  160955. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  160956. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  160957. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  160958. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  160959. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  160960. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  160961. int filters));
  160962. #define PNG_NO_FILTERS 0x00
  160963. #define PNG_FILTER_NONE 0x08
  160964. #define PNG_FILTER_SUB 0x10
  160965. #define PNG_FILTER_UP 0x20
  160966. #define PNG_FILTER_AVG 0x40
  160967. #define PNG_FILTER_PAETH 0x80
  160968. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  160969. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  160970. #define PNG_FILTER_VALUE_NONE 0
  160971. #define PNG_FILTER_VALUE_SUB 1
  160972. #define PNG_FILTER_VALUE_UP 2
  160973. #define PNG_FILTER_VALUE_AVG 3
  160974. #define PNG_FILTER_VALUE_PAETH 4
  160975. #define PNG_FILTER_VALUE_LAST 5
  160976. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  160977. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160978. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  160979. int heuristic_method, int num_weights, png_doublep filter_weights,
  160980. png_doublep filter_costs));
  160981. #endif
  160982. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  160983. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  160984. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  160985. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  160986. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  160987. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  160988. int level));
  160989. extern PNG_EXPORT(void,png_set_compression_mem_level)
  160990. PNGARG((png_structp png_ptr, int mem_level));
  160991. extern PNG_EXPORT(void,png_set_compression_strategy)
  160992. PNGARG((png_structp png_ptr, int strategy));
  160993. extern PNG_EXPORT(void,png_set_compression_window_bits)
  160994. PNGARG((png_structp png_ptr, int window_bits));
  160995. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  160996. int method));
  160997. #if !defined(PNG_NO_STDIO)
  160998. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  160999. #endif
  161000. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  161001. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  161002. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  161003. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  161004. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  161005. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  161006. png_voidp io_ptr, png_rw_ptr read_data_fn));
  161007. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  161008. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  161009. png_read_status_ptr read_row_fn));
  161010. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  161011. png_write_status_ptr write_row_fn));
  161012. #ifdef PNG_USER_MEM_SUPPORTED
  161013. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161014. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161015. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161016. #endif
  161017. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161018. defined(PNG_LEGACY_SUPPORTED)
  161019. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161020. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161021. #endif
  161022. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161023. defined(PNG_LEGACY_SUPPORTED)
  161024. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161025. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161026. #endif
  161027. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161028. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161029. defined(PNG_LEGACY_SUPPORTED)
  161030. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161031. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161032. int user_transform_channels));
  161033. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161034. PNGARG((png_structp png_ptr));
  161035. #endif
  161036. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161037. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161038. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161039. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161040. png_ptr));
  161041. #endif
  161042. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161043. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161044. png_voidp progressive_ptr,
  161045. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161046. png_progressive_end_ptr end_fn));
  161047. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161048. PNGARG((png_structp png_ptr));
  161049. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161050. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161051. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161052. png_bytep old_row, png_bytep new_row));
  161053. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161054. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161055. png_uint_32 size));
  161056. #if defined(PNG_1_0_X)
  161057. # define png_malloc_warn png_malloc
  161058. #else
  161059. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161060. png_uint_32 size));
  161061. #endif
  161062. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161063. #if defined(PNG_1_0_X)
  161064. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161065. uInt size));
  161066. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161067. #endif
  161068. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161069. png_infop info_ptr, png_uint_32 free_me, int num));
  161070. #ifdef PNG_FREE_ME_SUPPORTED
  161071. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161072. png_infop info_ptr, int freer, png_uint_32 mask));
  161073. #endif
  161074. #define PNG_DESTROY_WILL_FREE_DATA 1
  161075. #define PNG_SET_WILL_FREE_DATA 1
  161076. #define PNG_USER_WILL_FREE_DATA 2
  161077. #define PNG_FREE_HIST 0x0008
  161078. #define PNG_FREE_ICCP 0x0010
  161079. #define PNG_FREE_SPLT 0x0020
  161080. #define PNG_FREE_ROWS 0x0040
  161081. #define PNG_FREE_PCAL 0x0080
  161082. #define PNG_FREE_SCAL 0x0100
  161083. #define PNG_FREE_UNKN 0x0200
  161084. #define PNG_FREE_LIST 0x0400
  161085. #define PNG_FREE_PLTE 0x1000
  161086. #define PNG_FREE_TRNS 0x2000
  161087. #define PNG_FREE_TEXT 0x4000
  161088. #define PNG_FREE_ALL 0x7fff
  161089. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161090. #ifdef PNG_USER_MEM_SUPPORTED
  161091. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161092. png_uint_32 size));
  161093. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161094. png_voidp ptr));
  161095. #endif
  161096. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161097. png_voidp s1, png_voidp s2, png_uint_32 size));
  161098. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161099. png_voidp s1, int value, png_uint_32 size));
  161100. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161101. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161102. int check));
  161103. #endif /* USE_FAR_KEYWORD */
  161104. #ifndef PNG_NO_ERROR_TEXT
  161105. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161106. png_const_charp error_message));
  161107. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161108. png_const_charp error_message));
  161109. #else
  161110. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161111. #endif
  161112. #ifndef PNG_NO_WARNINGS
  161113. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161114. png_const_charp warning_message));
  161115. #ifdef PNG_READ_SUPPORTED
  161116. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161117. png_const_charp warning_message));
  161118. #endif /* PNG_READ_SUPPORTED */
  161119. #endif /* PNG_NO_WARNINGS */
  161120. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161121. png_infop info_ptr, png_uint_32 flag));
  161122. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161123. png_infop info_ptr));
  161124. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161125. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161126. png_infop info_ptr));
  161127. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161128. png_infop info_ptr, png_bytepp row_pointers));
  161129. #endif
  161130. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161131. png_infop info_ptr));
  161132. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161133. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161134. png_ptr, png_infop info_ptr));
  161135. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161136. png_ptr, png_infop info_ptr));
  161137. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161138. png_ptr, png_infop info_ptr));
  161139. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161140. png_ptr, png_infop info_ptr));
  161141. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161142. png_ptr, png_infop info_ptr));
  161143. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161144. png_ptr, png_infop info_ptr));
  161145. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161146. png_ptr, png_infop info_ptr));
  161147. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161148. png_ptr, png_infop info_ptr));
  161149. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161150. png_ptr, png_infop info_ptr));
  161151. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161152. png_ptr, png_infop info_ptr));
  161153. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161154. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161155. png_ptr, png_infop info_ptr));
  161156. #endif
  161157. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161158. png_ptr, png_infop info_ptr));
  161159. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161160. png_ptr, png_infop info_ptr));
  161161. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161162. png_ptr, png_infop info_ptr));
  161163. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161164. png_ptr, png_infop info_ptr));
  161165. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161166. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161167. png_infop info_ptr));
  161168. #if defined(PNG_bKGD_SUPPORTED)
  161169. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161170. png_infop info_ptr, png_color_16p *background));
  161171. #endif
  161172. #if defined(PNG_bKGD_SUPPORTED)
  161173. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161174. png_infop info_ptr, png_color_16p background));
  161175. #endif
  161176. #if defined(PNG_cHRM_SUPPORTED)
  161177. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161178. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161179. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161180. double *red_y, double *green_x, double *green_y, double *blue_x,
  161181. double *blue_y));
  161182. #endif
  161183. #ifdef PNG_FIXED_POINT_SUPPORTED
  161184. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161185. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161186. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161187. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161188. *int_blue_x, png_fixed_point *int_blue_y));
  161189. #endif
  161190. #endif
  161191. #if defined(PNG_cHRM_SUPPORTED)
  161192. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161193. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161194. png_infop info_ptr, double white_x, double white_y, double red_x,
  161195. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161196. #endif
  161197. #ifdef PNG_FIXED_POINT_SUPPORTED
  161198. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161199. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161200. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161201. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161202. png_fixed_point int_blue_y));
  161203. #endif
  161204. #endif
  161205. #if defined(PNG_gAMA_SUPPORTED)
  161206. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161207. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161208. png_infop info_ptr, double *file_gamma));
  161209. #endif
  161210. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161211. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161212. #endif
  161213. #if defined(PNG_gAMA_SUPPORTED)
  161214. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161215. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161216. png_infop info_ptr, double file_gamma));
  161217. #endif
  161218. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161219. png_infop info_ptr, png_fixed_point int_file_gamma));
  161220. #endif
  161221. #if defined(PNG_hIST_SUPPORTED)
  161222. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161223. png_infop info_ptr, png_uint_16p *hist));
  161224. #endif
  161225. #if defined(PNG_hIST_SUPPORTED)
  161226. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161227. png_infop info_ptr, png_uint_16p hist));
  161228. #endif
  161229. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161230. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161231. int *bit_depth, int *color_type, int *interlace_method,
  161232. int *compression_method, int *filter_method));
  161233. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161234. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161235. int color_type, int interlace_method, int compression_method,
  161236. int filter_method));
  161237. #if defined(PNG_oFFs_SUPPORTED)
  161238. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161239. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161240. int *unit_type));
  161241. #endif
  161242. #if defined(PNG_oFFs_SUPPORTED)
  161243. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161244. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161245. int unit_type));
  161246. #endif
  161247. #if defined(PNG_pCAL_SUPPORTED)
  161248. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161249. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161250. int *type, int *nparams, png_charp *units, png_charpp *params));
  161251. #endif
  161252. #if defined(PNG_pCAL_SUPPORTED)
  161253. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161254. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161255. int type, int nparams, png_charp units, png_charpp params));
  161256. #endif
  161257. #if defined(PNG_pHYs_SUPPORTED)
  161258. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161259. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161260. #endif
  161261. #if defined(PNG_pHYs_SUPPORTED)
  161262. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161263. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161264. #endif
  161265. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161266. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161267. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161268. png_infop info_ptr, png_colorp palette, int num_palette));
  161269. #if defined(PNG_sBIT_SUPPORTED)
  161270. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161271. png_infop info_ptr, png_color_8p *sig_bit));
  161272. #endif
  161273. #if defined(PNG_sBIT_SUPPORTED)
  161274. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161275. png_infop info_ptr, png_color_8p sig_bit));
  161276. #endif
  161277. #if defined(PNG_sRGB_SUPPORTED)
  161278. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161279. png_infop info_ptr, int *intent));
  161280. #endif
  161281. #if defined(PNG_sRGB_SUPPORTED)
  161282. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161283. png_infop info_ptr, int intent));
  161284. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161285. png_infop info_ptr, int intent));
  161286. #endif
  161287. #if defined(PNG_iCCP_SUPPORTED)
  161288. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161289. png_infop info_ptr, png_charpp name, int *compression_type,
  161290. png_charpp profile, png_uint_32 *proflen));
  161291. #endif
  161292. #if defined(PNG_iCCP_SUPPORTED)
  161293. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161294. png_infop info_ptr, png_charp name, int compression_type,
  161295. png_charp profile, png_uint_32 proflen));
  161296. #endif
  161297. #if defined(PNG_sPLT_SUPPORTED)
  161298. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161299. png_infop info_ptr, png_sPLT_tpp entries));
  161300. #endif
  161301. #if defined(PNG_sPLT_SUPPORTED)
  161302. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161303. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161304. #endif
  161305. #if defined(PNG_TEXT_SUPPORTED)
  161306. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161307. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161308. #endif
  161309. #if defined(PNG_TEXT_SUPPORTED)
  161310. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161311. png_infop info_ptr, png_textp text_ptr, int num_text));
  161312. #endif
  161313. #if defined(PNG_tIME_SUPPORTED)
  161314. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161315. png_infop info_ptr, png_timep *mod_time));
  161316. #endif
  161317. #if defined(PNG_tIME_SUPPORTED)
  161318. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161319. png_infop info_ptr, png_timep mod_time));
  161320. #endif
  161321. #if defined(PNG_tRNS_SUPPORTED)
  161322. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161323. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161324. png_color_16p *trans_values));
  161325. #endif
  161326. #if defined(PNG_tRNS_SUPPORTED)
  161327. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161328. png_infop info_ptr, png_bytep trans, int num_trans,
  161329. png_color_16p trans_values));
  161330. #endif
  161331. #if defined(PNG_tRNS_SUPPORTED)
  161332. #endif
  161333. #if defined(PNG_sCAL_SUPPORTED)
  161334. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161335. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161336. png_infop info_ptr, int *unit, double *width, double *height));
  161337. #else
  161338. #ifdef PNG_FIXED_POINT_SUPPORTED
  161339. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161340. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161341. #endif
  161342. #endif
  161343. #endif /* PNG_sCAL_SUPPORTED */
  161344. #if defined(PNG_sCAL_SUPPORTED)
  161345. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161346. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161347. png_infop info_ptr, int unit, double width, double height));
  161348. #else
  161349. #ifdef PNG_FIXED_POINT_SUPPORTED
  161350. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161351. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161352. #endif
  161353. #endif
  161354. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161355. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161356. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161357. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161358. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161359. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161360. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161361. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161362. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161363. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161364. #endif
  161365. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161366. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161367. chunk_name));
  161368. #endif
  161369. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161370. png_infop info_ptr, int mask));
  161371. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161372. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161373. png_infop info_ptr,
  161374. int transforms,
  161375. png_voidp params));
  161376. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161377. png_infop info_ptr,
  161378. int transforms,
  161379. png_voidp params));
  161380. #endif
  161381. #ifdef PNG_DEBUG
  161382. #if (PNG_DEBUG > 0)
  161383. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161384. #include <crtdbg.h>
  161385. #if (PNG_DEBUG > 1)
  161386. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161387. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161388. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161389. #endif
  161390. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161391. #ifndef PNG_DEBUG_FILE
  161392. #define PNG_DEBUG_FILE stderr
  161393. #endif /* PNG_DEBUG_FILE */
  161394. #if (PNG_DEBUG > 1)
  161395. #define png_debug(l,m) \
  161396. { \
  161397. int num_tabs=l; \
  161398. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161399. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161400. }
  161401. #define png_debug1(l,m,p1) \
  161402. { \
  161403. int num_tabs=l; \
  161404. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161405. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161406. }
  161407. #define png_debug2(l,m,p1,p2) \
  161408. { \
  161409. int num_tabs=l; \
  161410. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161411. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161412. }
  161413. #endif /* (PNG_DEBUG > 1) */
  161414. #endif /* _MSC_VER */
  161415. #endif /* (PNG_DEBUG > 0) */
  161416. #endif /* PNG_DEBUG */
  161417. #ifndef png_debug
  161418. #define png_debug(l, m)
  161419. #endif
  161420. #ifndef png_debug1
  161421. #define png_debug1(l, m, p1)
  161422. #endif
  161423. #ifndef png_debug2
  161424. #define png_debug2(l, m, p1, p2)
  161425. #endif
  161426. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161427. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161428. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161429. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161430. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161431. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161432. png_ptr, png_uint_32 mng_features_permitted));
  161433. #endif
  161434. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161435. #define PNG_HANDLE_CHUNK_NEVER 1
  161436. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161437. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161438. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161439. #if defined(PNG_MMX_CODE_SUPPORTED)
  161440. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161441. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161442. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161443. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161444. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161445. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161446. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161447. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161448. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161449. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161450. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161451. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161452. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161453. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161454. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161455. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161456. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161457. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161458. | PNG_MMX_READ_FLAGS \
  161459. | PNG_MMX_WRITE_FLAGS )
  161460. #define PNG_SELECT_READ 1
  161461. #define PNG_SELECT_WRITE 2
  161462. #endif /* PNG_MMX_CODE_SUPPORTED */
  161463. #if !defined(PNG_1_0_X)
  161464. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161465. PNGARG((int flag_select, int *compilerID));
  161466. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161467. PNGARG((int flag_select));
  161468. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161469. PNGARG((png_structp png_ptr));
  161470. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161471. PNGARG((png_structp png_ptr));
  161472. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161473. PNGARG((png_structp png_ptr));
  161474. extern PNG_EXPORT(void,png_set_asm_flags)
  161475. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161476. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161477. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161478. png_uint_32 mmx_rowbytes_threshold));
  161479. #endif /* PNG_1_0_X */
  161480. #if !defined(PNG_1_0_X)
  161481. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161482. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161483. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161484. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161485. png_ptr, png_uint_32 strip_mode));
  161486. #endif
  161487. #endif /* PNG_1_0_X */
  161488. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161489. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161490. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161491. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161492. png_ptr));
  161493. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161494. png_ptr));
  161495. #endif
  161496. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161497. # define png_composite(composite, fg, alpha, bg) \
  161498. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161499. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161500. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161501. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161502. # define png_composite_16(composite, fg, alpha, bg) \
  161503. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161504. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161505. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161506. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161507. #else /* standard method using integer division */
  161508. # define png_composite(composite, fg, alpha, bg) \
  161509. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161510. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161511. (png_uint_16)127) / 255)
  161512. # define png_composite_16(composite, fg, alpha, bg) \
  161513. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161514. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161515. (png_uint_32)32767) / (png_uint_32)65535L)
  161516. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161517. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161518. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161519. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161520. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161521. #else
  161522. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161523. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161524. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161525. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161526. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161527. PNGARG((png_structp png_ptr, png_bytep buf));
  161528. extern PNG_EXPORT(void,png_save_uint_32)
  161529. PNGARG((png_bytep buf, png_uint_32 i));
  161530. extern PNG_EXPORT(void,png_save_int_32)
  161531. PNGARG((png_bytep buf, png_int_32 i));
  161532. extern PNG_EXPORT(void,png_save_uint_16)
  161533. PNGARG((png_bytep buf, unsigned int i));
  161534. #define PNG_HAVE_IHDR 0x01
  161535. #define PNG_HAVE_PLTE 0x02
  161536. #define PNG_HAVE_IDAT 0x04
  161537. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161538. #define PNG_HAVE_IEND 0x10
  161539. #if defined(PNG_INTERNAL)
  161540. #define PNG_HAVE_gAMA 0x20
  161541. #define PNG_HAVE_cHRM 0x40
  161542. #define PNG_HAVE_sRGB 0x80
  161543. #define PNG_HAVE_CHUNK_HEADER 0x100
  161544. #define PNG_WROTE_tIME 0x200
  161545. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161546. #define PNG_BACKGROUND_IS_GRAY 0x800
  161547. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  161548. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  161549. #define PNG_BGR 0x0001
  161550. #define PNG_INTERLACE 0x0002
  161551. #define PNG_PACK 0x0004
  161552. #define PNG_SHIFT 0x0008
  161553. #define PNG_SWAP_BYTES 0x0010
  161554. #define PNG_INVERT_MONO 0x0020
  161555. #define PNG_DITHER 0x0040
  161556. #define PNG_BACKGROUND 0x0080
  161557. #define PNG_BACKGROUND_EXPAND 0x0100
  161558. #define PNG_16_TO_8 0x0400
  161559. #define PNG_RGBA 0x0800
  161560. #define PNG_EXPAND 0x1000
  161561. #define PNG_GAMMA 0x2000
  161562. #define PNG_GRAY_TO_RGB 0x4000
  161563. #define PNG_FILLER 0x8000L
  161564. #define PNG_PACKSWAP 0x10000L
  161565. #define PNG_SWAP_ALPHA 0x20000L
  161566. #define PNG_STRIP_ALPHA 0x40000L
  161567. #define PNG_INVERT_ALPHA 0x80000L
  161568. #define PNG_USER_TRANSFORM 0x100000L
  161569. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  161570. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  161571. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  161572. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  161573. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  161574. #define PNG_STRUCT_PNG 0x0001
  161575. #define PNG_STRUCT_INFO 0x0002
  161576. #define PNG_WEIGHT_SHIFT 8
  161577. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  161578. #define PNG_COST_SHIFT 3
  161579. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  161580. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  161581. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  161582. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  161583. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  161584. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  161585. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  161586. #define PNG_FLAG_ROW_INIT 0x0040
  161587. #define PNG_FLAG_FILLER_AFTER 0x0080
  161588. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  161589. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  161590. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  161591. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  161592. #define PNG_FLAG_FREE_PLTE 0x1000
  161593. #define PNG_FLAG_FREE_TRNS 0x2000
  161594. #define PNG_FLAG_FREE_HIST 0x4000
  161595. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  161596. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  161597. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  161598. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  161599. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  161600. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  161601. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  161602. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  161603. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  161604. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  161605. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  161606. PNG_FLAG_CRC_CRITICAL_IGNORE)
  161607. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  161608. PNG_FLAG_CRC_CRITICAL_MASK)
  161609. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  161610. abs((int)((c1).green) - (int)((c2).green)) + \
  161611. abs((int)((c1).blue) - (int)((c2).blue)))
  161612. #define PNG_ROWBYTES(pixel_bits, width) \
  161613. ((pixel_bits) >= 8 ? \
  161614. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  161615. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  161616. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  161617. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  161618. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  161619. #ifdef PNG_USE_GLOBAL_ARRAYS
  161620. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  161621. #else
  161622. #endif
  161623. #endif /* PNG_NO_EXTERN */
  161624. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  161625. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  161626. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  161627. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  161628. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  161629. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  161630. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  161631. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  161632. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  161633. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  161634. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  161635. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  161636. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  161637. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  161638. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  161639. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  161640. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  161641. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  161642. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  161643. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  161644. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  161645. #ifdef PNG_USE_GLOBAL_ARRAYS
  161646. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  161647. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  161648. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  161649. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  161650. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  161651. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  161652. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  161653. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  161654. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  161655. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  161656. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  161657. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  161658. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  161659. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  161660. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  161661. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  161662. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  161663. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  161664. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  161665. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  161666. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  161667. #endif /* PNG_USE_GLOBAL_ARRAYS */
  161668. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161669. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  161670. #undef png_read_init
  161671. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  161672. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161673. #endif
  161674. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  161675. png_const_charp user_png_ver, png_size_t png_struct_size));
  161676. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161677. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  161678. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161679. png_info_size));
  161680. #endif
  161681. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161682. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  161683. #undef png_write_init
  161684. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  161685. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161686. #endif
  161687. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  161688. png_const_charp user_png_ver, png_size_t png_struct_size));
  161689. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  161690. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161691. png_info_size));
  161692. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  161693. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  161694. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  161695. malloc_fn, png_voidp mem_ptr));
  161696. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  161697. png_free_ptr free_fn, png_voidp mem_ptr));
  161698. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  161699. png_infop info_ptr));
  161700. #ifndef PNG_1_0_X
  161701. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  161702. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  161703. #ifdef PNG_SIZE_T
  161704. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  161705. #endif
  161706. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  161707. png_bytep data, png_size_t length));
  161708. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161709. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  161710. png_bytep buffer, png_size_t length));
  161711. #endif
  161712. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  161713. png_bytep data, png_size_t length));
  161714. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161715. #if !defined(PNG_NO_STDIO)
  161716. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  161717. #endif
  161718. #endif
  161719. #else /* PNG_1_0_X */
  161720. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161721. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  161722. png_bytep buffer, png_size_t length));
  161723. #endif
  161724. #endif /* PNG_1_0_X */
  161725. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  161726. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  161727. png_size_t length));
  161728. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  161729. png_size_t length));
  161730. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  161731. png_size_t length));
  161732. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  161733. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  161734. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  161735. int comp_type, png_charp chunkdata, png_size_t chunklength,
  161736. png_size_t prefix_length, png_size_t *data_length));
  161737. #endif
  161738. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  161739. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  161740. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  161741. png_size_t length));
  161742. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161743. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  161744. #endif
  161745. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  161746. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  161747. png_uint_32 height,
  161748. int bit_depth, int color_type, int compression_method, int filter_method,
  161749. int interlace_method));
  161750. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  161751. png_uint_32 num_pal));
  161752. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  161753. png_size_t length));
  161754. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  161755. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  161756. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161757. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  161758. #endif
  161759. #ifdef PNG_FIXED_POINT_SUPPORTED
  161760. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  161761. file_gamma));
  161762. #endif
  161763. #endif
  161764. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  161765. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  161766. int color_type));
  161767. #endif
  161768. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  161769. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161770. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  161771. double white_x, double white_y,
  161772. double red_x, double red_y, double green_x, double green_y,
  161773. double blue_x, double blue_y));
  161774. #endif
  161775. #ifdef PNG_FIXED_POINT_SUPPORTED
  161776. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  161777. png_fixed_point int_white_x, png_fixed_point int_white_y,
  161778. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161779. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161780. png_fixed_point int_blue_y));
  161781. #endif
  161782. #endif
  161783. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  161784. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  161785. int intent));
  161786. #endif
  161787. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  161788. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  161789. png_charp name, int compression_type,
  161790. png_charp profile, int proflen));
  161791. #endif
  161792. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  161793. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  161794. png_sPLT_tp palette));
  161795. #endif
  161796. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  161797. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  161798. png_color_16p values, int number, int color_type));
  161799. #endif
  161800. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  161801. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  161802. png_color_16p values, int color_type));
  161803. #endif
  161804. #if defined(PNG_WRITE_hIST_SUPPORTED)
  161805. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  161806. int num_hist));
  161807. #endif
  161808. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  161809. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  161810. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  161811. png_charp key, png_charpp new_key));
  161812. #endif
  161813. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  161814. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  161815. png_charp text, png_size_t text_len));
  161816. #endif
  161817. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  161818. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  161819. png_charp text, png_size_t text_len, int compression));
  161820. #endif
  161821. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  161822. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  161823. int compression, png_charp key, png_charp lang, png_charp lang_key,
  161824. png_charp text));
  161825. #endif
  161826. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  161827. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  161828. png_infop info_ptr, png_textp text_ptr, int num_text));
  161829. #endif
  161830. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  161831. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  161832. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  161833. #endif
  161834. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  161835. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  161836. png_int_32 X0, png_int_32 X1, int type, int nparams,
  161837. png_charp units, png_charpp params));
  161838. #endif
  161839. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  161840. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  161841. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  161842. int unit_type));
  161843. #endif
  161844. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161845. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  161846. png_timep mod_time));
  161847. #endif
  161848. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  161849. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  161850. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  161851. int unit, double width, double height));
  161852. #else
  161853. #ifdef PNG_FIXED_POINT_SUPPORTED
  161854. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  161855. int unit, png_charp width, png_charp height));
  161856. #endif
  161857. #endif
  161858. #endif
  161859. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  161860. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  161861. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161862. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  161863. #endif
  161864. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  161865. int mask));
  161866. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  161867. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  161868. #endif
  161869. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161870. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  161871. png_bytep row, int pass));
  161872. #endif
  161873. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  161874. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  161875. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  161876. png_row_infop row_info));
  161877. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  161878. png_bytep filtered_row));
  161879. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  161880. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  161881. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  161882. png_infop info_ptr));
  161883. #if defined(PNG_READ_FILLER_SUPPORTED)
  161884. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  161885. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  161886. #endif
  161887. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  161888. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  161889. png_bytep row));
  161890. #endif
  161891. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161892. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  161893. png_bytep row));
  161894. #endif
  161895. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  161896. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  161897. png_bytep row));
  161898. #endif
  161899. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161900. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  161901. png_bytep row));
  161902. #endif
  161903. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  161904. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161905. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  161906. png_bytep row, png_uint_32 flags));
  161907. #endif
  161908. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161909. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  161910. #endif
  161911. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161912. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  161913. #endif
  161914. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161915. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  161916. row_info, png_bytep row));
  161917. #endif
  161918. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161919. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  161920. png_bytep row));
  161921. #endif
  161922. #if defined(PNG_READ_PACK_SUPPORTED)
  161923. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  161924. #endif
  161925. #if defined(PNG_READ_SHIFT_SUPPORTED)
  161926. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  161927. png_color_8p sig_bits));
  161928. #endif
  161929. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161930. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  161931. #endif
  161932. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161933. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  161934. #endif
  161935. #if defined(PNG_READ_DITHER_SUPPORTED)
  161936. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  161937. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  161938. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  161939. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  161940. png_colorp palette, int num_palette));
  161941. # endif
  161942. #endif
  161943. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161944. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  161945. #endif
  161946. #if defined(PNG_WRITE_PACK_SUPPORTED)
  161947. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  161948. png_bytep row, png_uint_32 bit_depth));
  161949. #endif
  161950. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  161951. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  161952. png_color_8p bit_depth));
  161953. #endif
  161954. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161955. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161956. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161957. png_color_16p trans_values, png_color_16p background,
  161958. png_color_16p background_1,
  161959. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  161960. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  161961. png_uint_16pp gamma_16_to_1, int gamma_shift));
  161962. #else
  161963. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161964. png_color_16p trans_values, png_color_16p background));
  161965. #endif
  161966. #endif
  161967. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161968. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  161969. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  161970. int gamma_shift));
  161971. #endif
  161972. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161973. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  161974. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  161975. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  161976. png_bytep row, png_color_16p trans_value));
  161977. #endif
  161978. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  161979. png_uint_32 length));
  161980. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  161981. png_uint_32 length));
  161982. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  161983. png_uint_32 length));
  161984. #if defined(PNG_READ_bKGD_SUPPORTED)
  161985. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  161986. png_uint_32 length));
  161987. #endif
  161988. #if defined(PNG_READ_cHRM_SUPPORTED)
  161989. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  161990. png_uint_32 length));
  161991. #endif
  161992. #if defined(PNG_READ_gAMA_SUPPORTED)
  161993. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  161994. png_uint_32 length));
  161995. #endif
  161996. #if defined(PNG_READ_hIST_SUPPORTED)
  161997. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  161998. png_uint_32 length));
  161999. #endif
  162000. #if defined(PNG_READ_iCCP_SUPPORTED)
  162001. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  162002. png_uint_32 length));
  162003. #endif /* PNG_READ_iCCP_SUPPORTED */
  162004. #if defined(PNG_READ_iTXt_SUPPORTED)
  162005. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162006. png_uint_32 length));
  162007. #endif
  162008. #if defined(PNG_READ_oFFs_SUPPORTED)
  162009. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162010. png_uint_32 length));
  162011. #endif
  162012. #if defined(PNG_READ_pCAL_SUPPORTED)
  162013. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162014. png_uint_32 length));
  162015. #endif
  162016. #if defined(PNG_READ_pHYs_SUPPORTED)
  162017. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162018. png_uint_32 length));
  162019. #endif
  162020. #if defined(PNG_READ_sBIT_SUPPORTED)
  162021. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162022. png_uint_32 length));
  162023. #endif
  162024. #if defined(PNG_READ_sCAL_SUPPORTED)
  162025. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162026. png_uint_32 length));
  162027. #endif
  162028. #if defined(PNG_READ_sPLT_SUPPORTED)
  162029. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162030. png_uint_32 length));
  162031. #endif /* PNG_READ_sPLT_SUPPORTED */
  162032. #if defined(PNG_READ_sRGB_SUPPORTED)
  162033. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162034. png_uint_32 length));
  162035. #endif
  162036. #if defined(PNG_READ_tEXt_SUPPORTED)
  162037. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162038. png_uint_32 length));
  162039. #endif
  162040. #if defined(PNG_READ_tIME_SUPPORTED)
  162041. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162042. png_uint_32 length));
  162043. #endif
  162044. #if defined(PNG_READ_tRNS_SUPPORTED)
  162045. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162046. png_uint_32 length));
  162047. #endif
  162048. #if defined(PNG_READ_zTXt_SUPPORTED)
  162049. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162050. png_uint_32 length));
  162051. #endif
  162052. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162053. png_infop info_ptr, png_uint_32 length));
  162054. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162055. png_bytep chunk_name));
  162056. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162057. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162058. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162059. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162060. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162061. png_infop info_ptr));
  162062. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162063. png_infop info_ptr));
  162064. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162065. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162066. png_uint_32 length));
  162067. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162068. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162069. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162070. png_bytep buffer, png_size_t buffer_length));
  162071. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162072. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162073. png_bytep buffer, png_size_t buffer_length));
  162074. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162075. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162076. png_infop info_ptr, png_uint_32 length));
  162077. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162078. png_infop info_ptr));
  162079. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162080. png_infop info_ptr));
  162081. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162082. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162083. png_infop info_ptr));
  162084. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162085. png_infop info_ptr));
  162086. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162087. #if defined(PNG_READ_tEXt_SUPPORTED)
  162088. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162089. png_infop info_ptr, png_uint_32 length));
  162090. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162091. png_infop info_ptr));
  162092. #endif
  162093. #if defined(PNG_READ_zTXt_SUPPORTED)
  162094. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162095. png_infop info_ptr, png_uint_32 length));
  162096. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162097. png_infop info_ptr));
  162098. #endif
  162099. #if defined(PNG_READ_iTXt_SUPPORTED)
  162100. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162101. png_infop info_ptr, png_uint_32 length));
  162102. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162103. png_infop info_ptr));
  162104. #endif
  162105. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162106. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162107. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162108. png_bytep row));
  162109. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162110. png_bytep row));
  162111. #endif
  162112. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162113. #if defined(PNG_MMX_CODE_SUPPORTED)
  162114. /* PRIVATE */
  162115. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162116. #endif
  162117. #endif
  162118. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162119. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162120. png_infop info_ptr));
  162121. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162122. png_infop info_ptr));
  162123. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162124. png_infop info_ptr));
  162125. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162126. png_infop info_ptr));
  162127. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162128. png_infop info_ptr));
  162129. #if defined(PNG_pHYs_SUPPORTED)
  162130. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162131. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162132. #endif /* PNG_pHYs_SUPPORTED */
  162133. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162134. #endif /* PNG_INTERNAL */
  162135. #ifdef __cplusplus
  162136. }
  162137. #endif
  162138. #endif /* PNG_VERSION_INFO_ONLY */
  162139. #endif /* PNG_H */
  162140. /*** End of inlined file: png.h ***/
  162141. #define PNG_NO_EXTERN
  162142. /*** Start of inlined file: png.c ***/
  162143. #define PNG_INTERNAL
  162144. #define PNG_NO_EXTERN
  162145. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162146. #ifdef PNG_USE_GLOBAL_ARRAYS
  162147. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162148. #ifdef PNG_READ_SUPPORTED
  162149. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162150. #endif /* PNG_READ_SUPPORTED */
  162151. PNG_IHDR;
  162152. PNG_IDAT;
  162153. PNG_IEND;
  162154. PNG_PLTE;
  162155. PNG_bKGD;
  162156. PNG_cHRM;
  162157. PNG_gAMA;
  162158. PNG_hIST;
  162159. PNG_iCCP;
  162160. PNG_iTXt;
  162161. PNG_oFFs;
  162162. PNG_pCAL;
  162163. PNG_sCAL;
  162164. PNG_pHYs;
  162165. PNG_sBIT;
  162166. PNG_sPLT;
  162167. PNG_sRGB;
  162168. PNG_tEXt;
  162169. PNG_tIME;
  162170. PNG_tRNS;
  162171. PNG_zTXt;
  162172. #ifdef PNG_READ_SUPPORTED
  162173. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162174. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162175. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162176. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162177. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162178. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162179. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162180. #endif /* PNG_READ_SUPPORTED */
  162181. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162182. #ifdef PNG_READ_SUPPORTED
  162183. void PNGAPI
  162184. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162185. {
  162186. if(png_ptr == NULL) return;
  162187. png_debug(1, "in png_set_sig_bytes\n");
  162188. if (num_bytes > 8)
  162189. png_error(png_ptr, "Too many bytes for PNG signature.");
  162190. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162191. }
  162192. int PNGAPI
  162193. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162194. {
  162195. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162196. if (num_to_check > 8)
  162197. num_to_check = 8;
  162198. else if (num_to_check < 1)
  162199. return (-1);
  162200. if (start > 7)
  162201. return (-1);
  162202. if (start + num_to_check > 8)
  162203. num_to_check = 8 - start;
  162204. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162205. }
  162206. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162207. int PNGAPI
  162208. png_check_sig(png_bytep sig, int num)
  162209. {
  162210. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162211. }
  162212. #endif
  162213. #endif /* PNG_READ_SUPPORTED */
  162214. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162215. #ifdef PNG_1_0_X
  162216. voidpf PNGAPI
  162217. #else
  162218. voidpf /* private */
  162219. #endif
  162220. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162221. {
  162222. png_voidp ptr;
  162223. png_structp p=(png_structp)png_ptr;
  162224. png_uint_32 save_flags=p->flags;
  162225. png_uint_32 num_bytes;
  162226. if(png_ptr == NULL) return (NULL);
  162227. if (items > PNG_UINT_32_MAX/size)
  162228. {
  162229. png_warning (p, "Potential overflow in png_zalloc()");
  162230. return (NULL);
  162231. }
  162232. num_bytes = (png_uint_32)items * size;
  162233. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162234. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162235. p->flags=save_flags;
  162236. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162237. if (ptr == NULL)
  162238. return ((voidpf)ptr);
  162239. if (num_bytes > (png_uint_32)0x8000L)
  162240. {
  162241. png_memset(ptr, 0, (png_size_t)0x8000L);
  162242. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162243. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162244. }
  162245. else
  162246. {
  162247. png_memset(ptr, 0, (png_size_t)num_bytes);
  162248. }
  162249. #endif
  162250. return ((voidpf)ptr);
  162251. }
  162252. #ifdef PNG_1_0_X
  162253. void PNGAPI
  162254. #else
  162255. void /* private */
  162256. #endif
  162257. png_zfree(voidpf png_ptr, voidpf ptr)
  162258. {
  162259. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162260. }
  162261. void /* PRIVATE */
  162262. png_reset_crc(png_structp png_ptr)
  162263. {
  162264. png_ptr->crc = crc32(0, Z_NULL, 0);
  162265. }
  162266. void /* PRIVATE */
  162267. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162268. {
  162269. int need_crc = 1;
  162270. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162271. {
  162272. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162273. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162274. need_crc = 0;
  162275. }
  162276. else /* critical */
  162277. {
  162278. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162279. need_crc = 0;
  162280. }
  162281. if (need_crc)
  162282. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162283. }
  162284. png_infop PNGAPI
  162285. png_create_info_struct(png_structp png_ptr)
  162286. {
  162287. png_infop info_ptr;
  162288. png_debug(1, "in png_create_info_struct\n");
  162289. if(png_ptr == NULL) return (NULL);
  162290. #ifdef PNG_USER_MEM_SUPPORTED
  162291. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162292. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162293. #else
  162294. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162295. #endif
  162296. if (info_ptr != NULL)
  162297. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162298. return (info_ptr);
  162299. }
  162300. void PNGAPI
  162301. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162302. {
  162303. png_infop info_ptr = NULL;
  162304. if(png_ptr == NULL) return;
  162305. png_debug(1, "in png_destroy_info_struct\n");
  162306. if (info_ptr_ptr != NULL)
  162307. info_ptr = *info_ptr_ptr;
  162308. if (info_ptr != NULL)
  162309. {
  162310. png_info_destroy(png_ptr, info_ptr);
  162311. #ifdef PNG_USER_MEM_SUPPORTED
  162312. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162313. png_ptr->mem_ptr);
  162314. #else
  162315. png_destroy_struct((png_voidp)info_ptr);
  162316. #endif
  162317. *info_ptr_ptr = NULL;
  162318. }
  162319. }
  162320. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162321. #undef png_info_init
  162322. void PNGAPI
  162323. png_info_init(png_infop info_ptr)
  162324. {
  162325. png_info_init_3(&info_ptr, 0);
  162326. }
  162327. #endif
  162328. void PNGAPI
  162329. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162330. {
  162331. png_infop info_ptr = *ptr_ptr;
  162332. if(info_ptr == NULL) return;
  162333. png_debug(1, "in png_info_init_3\n");
  162334. if(png_sizeof(png_info) > png_info_struct_size)
  162335. {
  162336. png_destroy_struct(info_ptr);
  162337. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162338. *ptr_ptr = info_ptr;
  162339. }
  162340. png_memset(info_ptr, 0, png_sizeof (png_info));
  162341. }
  162342. #ifdef PNG_FREE_ME_SUPPORTED
  162343. void PNGAPI
  162344. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162345. int freer, png_uint_32 mask)
  162346. {
  162347. png_debug(1, "in png_data_freer\n");
  162348. if (png_ptr == NULL || info_ptr == NULL)
  162349. return;
  162350. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162351. info_ptr->free_me |= mask;
  162352. else if(freer == PNG_USER_WILL_FREE_DATA)
  162353. info_ptr->free_me &= ~mask;
  162354. else
  162355. png_warning(png_ptr,
  162356. "Unknown freer parameter in png_data_freer.");
  162357. }
  162358. #endif
  162359. void PNGAPI
  162360. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162361. int num)
  162362. {
  162363. png_debug(1, "in png_free_data\n");
  162364. if (png_ptr == NULL || info_ptr == NULL)
  162365. return;
  162366. #if defined(PNG_TEXT_SUPPORTED)
  162367. #ifdef PNG_FREE_ME_SUPPORTED
  162368. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162369. #else
  162370. if (mask & PNG_FREE_TEXT)
  162371. #endif
  162372. {
  162373. if (num != -1)
  162374. {
  162375. if (info_ptr->text && info_ptr->text[num].key)
  162376. {
  162377. png_free(png_ptr, info_ptr->text[num].key);
  162378. info_ptr->text[num].key = NULL;
  162379. }
  162380. }
  162381. else
  162382. {
  162383. int i;
  162384. for (i = 0; i < info_ptr->num_text; i++)
  162385. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162386. png_free(png_ptr, info_ptr->text);
  162387. info_ptr->text = NULL;
  162388. info_ptr->num_text=0;
  162389. }
  162390. }
  162391. #endif
  162392. #if defined(PNG_tRNS_SUPPORTED)
  162393. #ifdef PNG_FREE_ME_SUPPORTED
  162394. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162395. #else
  162396. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162397. #endif
  162398. {
  162399. png_free(png_ptr, info_ptr->trans);
  162400. info_ptr->valid &= ~PNG_INFO_tRNS;
  162401. #ifndef PNG_FREE_ME_SUPPORTED
  162402. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162403. #endif
  162404. info_ptr->trans = NULL;
  162405. }
  162406. #endif
  162407. #if defined(PNG_sCAL_SUPPORTED)
  162408. #ifdef PNG_FREE_ME_SUPPORTED
  162409. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162410. #else
  162411. if (mask & PNG_FREE_SCAL)
  162412. #endif
  162413. {
  162414. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162415. png_free(png_ptr, info_ptr->scal_s_width);
  162416. png_free(png_ptr, info_ptr->scal_s_height);
  162417. info_ptr->scal_s_width = NULL;
  162418. info_ptr->scal_s_height = NULL;
  162419. #endif
  162420. info_ptr->valid &= ~PNG_INFO_sCAL;
  162421. }
  162422. #endif
  162423. #if defined(PNG_pCAL_SUPPORTED)
  162424. #ifdef PNG_FREE_ME_SUPPORTED
  162425. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162426. #else
  162427. if (mask & PNG_FREE_PCAL)
  162428. #endif
  162429. {
  162430. png_free(png_ptr, info_ptr->pcal_purpose);
  162431. png_free(png_ptr, info_ptr->pcal_units);
  162432. info_ptr->pcal_purpose = NULL;
  162433. info_ptr->pcal_units = NULL;
  162434. if (info_ptr->pcal_params != NULL)
  162435. {
  162436. int i;
  162437. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162438. {
  162439. png_free(png_ptr, info_ptr->pcal_params[i]);
  162440. info_ptr->pcal_params[i]=NULL;
  162441. }
  162442. png_free(png_ptr, info_ptr->pcal_params);
  162443. info_ptr->pcal_params = NULL;
  162444. }
  162445. info_ptr->valid &= ~PNG_INFO_pCAL;
  162446. }
  162447. #endif
  162448. #if defined(PNG_iCCP_SUPPORTED)
  162449. #ifdef PNG_FREE_ME_SUPPORTED
  162450. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162451. #else
  162452. if (mask & PNG_FREE_ICCP)
  162453. #endif
  162454. {
  162455. png_free(png_ptr, info_ptr->iccp_name);
  162456. png_free(png_ptr, info_ptr->iccp_profile);
  162457. info_ptr->iccp_name = NULL;
  162458. info_ptr->iccp_profile = NULL;
  162459. info_ptr->valid &= ~PNG_INFO_iCCP;
  162460. }
  162461. #endif
  162462. #if defined(PNG_sPLT_SUPPORTED)
  162463. #ifdef PNG_FREE_ME_SUPPORTED
  162464. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162465. #else
  162466. if (mask & PNG_FREE_SPLT)
  162467. #endif
  162468. {
  162469. if (num != -1)
  162470. {
  162471. if(info_ptr->splt_palettes)
  162472. {
  162473. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162474. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162475. info_ptr->splt_palettes[num].name = NULL;
  162476. info_ptr->splt_palettes[num].entries = NULL;
  162477. }
  162478. }
  162479. else
  162480. {
  162481. if(info_ptr->splt_palettes_num)
  162482. {
  162483. int i;
  162484. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162485. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162486. png_free(png_ptr, info_ptr->splt_palettes);
  162487. info_ptr->splt_palettes = NULL;
  162488. info_ptr->splt_palettes_num = 0;
  162489. }
  162490. info_ptr->valid &= ~PNG_INFO_sPLT;
  162491. }
  162492. }
  162493. #endif
  162494. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162495. if(png_ptr->unknown_chunk.data)
  162496. {
  162497. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162498. png_ptr->unknown_chunk.data = NULL;
  162499. }
  162500. #ifdef PNG_FREE_ME_SUPPORTED
  162501. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162502. #else
  162503. if (mask & PNG_FREE_UNKN)
  162504. #endif
  162505. {
  162506. if (num != -1)
  162507. {
  162508. if(info_ptr->unknown_chunks)
  162509. {
  162510. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162511. info_ptr->unknown_chunks[num].data = NULL;
  162512. }
  162513. }
  162514. else
  162515. {
  162516. int i;
  162517. if(info_ptr->unknown_chunks_num)
  162518. {
  162519. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162520. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162521. png_free(png_ptr, info_ptr->unknown_chunks);
  162522. info_ptr->unknown_chunks = NULL;
  162523. info_ptr->unknown_chunks_num = 0;
  162524. }
  162525. }
  162526. }
  162527. #endif
  162528. #if defined(PNG_hIST_SUPPORTED)
  162529. #ifdef PNG_FREE_ME_SUPPORTED
  162530. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162531. #else
  162532. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162533. #endif
  162534. {
  162535. png_free(png_ptr, info_ptr->hist);
  162536. info_ptr->hist = NULL;
  162537. info_ptr->valid &= ~PNG_INFO_hIST;
  162538. #ifndef PNG_FREE_ME_SUPPORTED
  162539. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162540. #endif
  162541. }
  162542. #endif
  162543. #ifdef PNG_FREE_ME_SUPPORTED
  162544. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162545. #else
  162546. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162547. #endif
  162548. {
  162549. png_zfree(png_ptr, info_ptr->palette);
  162550. info_ptr->palette = NULL;
  162551. info_ptr->valid &= ~PNG_INFO_PLTE;
  162552. #ifndef PNG_FREE_ME_SUPPORTED
  162553. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  162554. #endif
  162555. info_ptr->num_palette = 0;
  162556. }
  162557. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162558. #ifdef PNG_FREE_ME_SUPPORTED
  162559. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  162560. #else
  162561. if (mask & PNG_FREE_ROWS)
  162562. #endif
  162563. {
  162564. if(info_ptr->row_pointers)
  162565. {
  162566. int row;
  162567. for (row = 0; row < (int)info_ptr->height; row++)
  162568. {
  162569. png_free(png_ptr, info_ptr->row_pointers[row]);
  162570. info_ptr->row_pointers[row]=NULL;
  162571. }
  162572. png_free(png_ptr, info_ptr->row_pointers);
  162573. info_ptr->row_pointers=NULL;
  162574. }
  162575. info_ptr->valid &= ~PNG_INFO_IDAT;
  162576. }
  162577. #endif
  162578. #ifdef PNG_FREE_ME_SUPPORTED
  162579. if(num == -1)
  162580. info_ptr->free_me &= ~mask;
  162581. else
  162582. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  162583. #endif
  162584. }
  162585. void /* PRIVATE */
  162586. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  162587. {
  162588. png_debug(1, "in png_info_destroy\n");
  162589. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  162590. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162591. if (png_ptr->num_chunk_list)
  162592. {
  162593. png_free(png_ptr, png_ptr->chunk_list);
  162594. png_ptr->chunk_list=NULL;
  162595. png_ptr->num_chunk_list=0;
  162596. }
  162597. #endif
  162598. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162599. }
  162600. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162601. png_voidp PNGAPI
  162602. png_get_io_ptr(png_structp png_ptr)
  162603. {
  162604. if(png_ptr == NULL) return (NULL);
  162605. return (png_ptr->io_ptr);
  162606. }
  162607. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162608. #if !defined(PNG_NO_STDIO)
  162609. void PNGAPI
  162610. png_init_io(png_structp png_ptr, png_FILE_p fp)
  162611. {
  162612. png_debug(1, "in png_init_io\n");
  162613. if(png_ptr == NULL) return;
  162614. png_ptr->io_ptr = (png_voidp)fp;
  162615. }
  162616. #endif
  162617. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  162618. png_charp PNGAPI
  162619. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  162620. {
  162621. static PNG_CONST char short_months[12][4] =
  162622. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  162623. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  162624. if(png_ptr == NULL) return (NULL);
  162625. if (png_ptr->time_buffer == NULL)
  162626. {
  162627. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  162628. png_sizeof(char)));
  162629. }
  162630. #if defined(_WIN32_WCE)
  162631. {
  162632. wchar_t time_buf[29];
  162633. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  162634. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162635. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162636. ptime->second % 61);
  162637. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  162638. NULL, NULL);
  162639. }
  162640. #else
  162641. #ifdef USE_FAR_KEYWORD
  162642. {
  162643. char near_time_buf[29];
  162644. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  162645. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162646. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162647. ptime->second % 61);
  162648. png_memcpy(png_ptr->time_buffer, near_time_buf,
  162649. 29*png_sizeof(char));
  162650. }
  162651. #else
  162652. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  162653. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162654. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162655. ptime->second % 61);
  162656. #endif
  162657. #endif /* _WIN32_WCE */
  162658. return ((png_charp)png_ptr->time_buffer);
  162659. }
  162660. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  162661. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162662. png_charp PNGAPI
  162663. png_get_copyright(png_structp png_ptr)
  162664. {
  162665. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162666. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  162667. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  162668. Copyright (c) 1996-1997 Andreas Dilger\n\
  162669. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  162670. }
  162671. png_charp PNGAPI
  162672. png_get_libpng_ver(png_structp png_ptr)
  162673. {
  162674. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162675. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162676. }
  162677. png_charp PNGAPI
  162678. png_get_header_ver(png_structp png_ptr)
  162679. {
  162680. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162681. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162682. }
  162683. png_charp PNGAPI
  162684. png_get_header_version(png_structp png_ptr)
  162685. {
  162686. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162687. return ((png_charp) PNG_HEADER_VERSION_STRING
  162688. #ifndef PNG_READ_SUPPORTED
  162689. " (NO READ SUPPORT)"
  162690. #endif
  162691. "\n");
  162692. }
  162693. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162694. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  162695. int PNGAPI
  162696. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  162697. {
  162698. int i;
  162699. png_bytep p;
  162700. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  162701. return 0;
  162702. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  162703. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  162704. if (!png_memcmp(chunk_name, p, 4))
  162705. return ((int)*(p+4));
  162706. return 0;
  162707. }
  162708. #endif
  162709. int PNGAPI
  162710. png_reset_zstream(png_structp png_ptr)
  162711. {
  162712. if (png_ptr == NULL) return Z_STREAM_ERROR;
  162713. return (inflateReset(&png_ptr->zstream));
  162714. }
  162715. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162716. png_uint_32 PNGAPI
  162717. png_access_version_number(void)
  162718. {
  162719. return((png_uint_32) PNG_LIBPNG_VER);
  162720. }
  162721. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162722. #if !defined(PNG_1_0_X)
  162723. int PNGAPI
  162724. png_mmx_support(void)
  162725. {
  162726. return -1;
  162727. }
  162728. #endif /* PNG_1_0_X */
  162729. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  162730. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162731. #ifdef PNG_SIZE_T
  162732. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162733. png_size_t PNGAPI
  162734. png_convert_size(size_t size)
  162735. {
  162736. if (size > (png_size_t)-1)
  162737. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  162738. return ((png_size_t)size);
  162739. }
  162740. #endif /* PNG_SIZE_T */
  162741. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162742. /*** End of inlined file: png.c ***/
  162743. /*** Start of inlined file: pngerror.c ***/
  162744. #define PNG_INTERNAL
  162745. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162746. static void /* PRIVATE */
  162747. png_default_error PNGARG((png_structp png_ptr,
  162748. png_const_charp error_message));
  162749. #ifndef PNG_NO_WARNINGS
  162750. static void /* PRIVATE */
  162751. png_default_warning PNGARG((png_structp png_ptr,
  162752. png_const_charp warning_message));
  162753. #endif /* PNG_NO_WARNINGS */
  162754. #ifndef PNG_NO_ERROR_TEXT
  162755. void PNGAPI
  162756. png_error(png_structp png_ptr, png_const_charp error_message)
  162757. {
  162758. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162759. char msg[16];
  162760. if (png_ptr != NULL)
  162761. {
  162762. if (png_ptr->flags&
  162763. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162764. {
  162765. if (*error_message == '#')
  162766. {
  162767. int offset;
  162768. for (offset=1; offset<15; offset++)
  162769. if (*(error_message+offset) == ' ')
  162770. break;
  162771. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162772. {
  162773. int i;
  162774. for (i=0; i<offset-1; i++)
  162775. msg[i]=error_message[i+1];
  162776. msg[i]='\0';
  162777. error_message=msg;
  162778. }
  162779. else
  162780. error_message+=offset;
  162781. }
  162782. else
  162783. {
  162784. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162785. {
  162786. msg[0]='0';
  162787. msg[1]='\0';
  162788. error_message=msg;
  162789. }
  162790. }
  162791. }
  162792. }
  162793. #endif
  162794. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162795. (*(png_ptr->error_fn))(png_ptr, error_message);
  162796. png_default_error(png_ptr, error_message);
  162797. }
  162798. #else
  162799. void PNGAPI
  162800. png_err(png_structp png_ptr)
  162801. {
  162802. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162803. (*(png_ptr->error_fn))(png_ptr, '\0');
  162804. png_default_error(png_ptr, '\0');
  162805. }
  162806. #endif /* PNG_NO_ERROR_TEXT */
  162807. #ifndef PNG_NO_WARNINGS
  162808. void PNGAPI
  162809. png_warning(png_structp png_ptr, png_const_charp warning_message)
  162810. {
  162811. int offset = 0;
  162812. if (png_ptr != NULL)
  162813. {
  162814. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162815. if (png_ptr->flags&
  162816. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162817. #endif
  162818. {
  162819. if (*warning_message == '#')
  162820. {
  162821. for (offset=1; offset<15; offset++)
  162822. if (*(warning_message+offset) == ' ')
  162823. break;
  162824. }
  162825. }
  162826. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  162827. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  162828. }
  162829. else
  162830. png_default_warning(png_ptr, warning_message+offset);
  162831. }
  162832. #endif /* PNG_NO_WARNINGS */
  162833. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  162834. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  162835. static void /* PRIVATE */
  162836. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  162837. error_message)
  162838. {
  162839. int iout = 0, iin = 0;
  162840. while (iin < 4)
  162841. {
  162842. int c = png_ptr->chunk_name[iin++];
  162843. if (isnonalpha(c))
  162844. {
  162845. buffer[iout++] = '[';
  162846. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  162847. buffer[iout++] = png_digit[c & 0x0f];
  162848. buffer[iout++] = ']';
  162849. }
  162850. else
  162851. {
  162852. buffer[iout++] = (png_byte)c;
  162853. }
  162854. }
  162855. if (error_message == NULL)
  162856. buffer[iout] = 0;
  162857. else
  162858. {
  162859. buffer[iout++] = ':';
  162860. buffer[iout++] = ' ';
  162861. png_strncpy(buffer+iout, error_message, 63);
  162862. buffer[iout+63] = 0;
  162863. }
  162864. }
  162865. #ifdef PNG_READ_SUPPORTED
  162866. void PNGAPI
  162867. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  162868. {
  162869. char msg[18+64];
  162870. if (png_ptr == NULL)
  162871. png_error(png_ptr, error_message);
  162872. else
  162873. {
  162874. png_format_buffer(png_ptr, msg, error_message);
  162875. png_error(png_ptr, msg);
  162876. }
  162877. }
  162878. #endif /* PNG_READ_SUPPORTED */
  162879. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  162880. #ifndef PNG_NO_WARNINGS
  162881. void PNGAPI
  162882. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  162883. {
  162884. char msg[18+64];
  162885. if (png_ptr == NULL)
  162886. png_warning(png_ptr, warning_message);
  162887. else
  162888. {
  162889. png_format_buffer(png_ptr, msg, warning_message);
  162890. png_warning(png_ptr, msg);
  162891. }
  162892. }
  162893. #endif /* PNG_NO_WARNINGS */
  162894. static void /* PRIVATE */
  162895. png_default_error(png_structp png_ptr, png_const_charp error_message)
  162896. {
  162897. #ifndef PNG_NO_CONSOLE_IO
  162898. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162899. if (*error_message == '#')
  162900. {
  162901. int offset;
  162902. char error_number[16];
  162903. for (offset=0; offset<15; offset++)
  162904. {
  162905. error_number[offset] = *(error_message+offset+1);
  162906. if (*(error_message+offset) == ' ')
  162907. break;
  162908. }
  162909. if((offset > 1) && (offset < 15))
  162910. {
  162911. error_number[offset-1]='\0';
  162912. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  162913. error_message+offset);
  162914. }
  162915. else
  162916. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  162917. }
  162918. else
  162919. #endif
  162920. fprintf(stderr, "libpng error: %s\n", error_message);
  162921. #endif
  162922. #ifdef PNG_SETJMP_SUPPORTED
  162923. if (png_ptr)
  162924. {
  162925. # ifdef USE_FAR_KEYWORD
  162926. {
  162927. jmp_buf jmpbuf;
  162928. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  162929. longjmp(jmpbuf, 1);
  162930. }
  162931. # else
  162932. longjmp(png_ptr->jmpbuf, 1);
  162933. # endif
  162934. }
  162935. #else
  162936. PNG_ABORT();
  162937. #endif
  162938. #ifdef PNG_NO_CONSOLE_IO
  162939. error_message = error_message; /* make compiler happy */
  162940. #endif
  162941. }
  162942. #ifndef PNG_NO_WARNINGS
  162943. static void /* PRIVATE */
  162944. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  162945. {
  162946. #ifndef PNG_NO_CONSOLE_IO
  162947. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162948. if (*warning_message == '#')
  162949. {
  162950. int offset;
  162951. char warning_number[16];
  162952. for (offset=0; offset<15; offset++)
  162953. {
  162954. warning_number[offset]=*(warning_message+offset+1);
  162955. if (*(warning_message+offset) == ' ')
  162956. break;
  162957. }
  162958. if((offset > 1) && (offset < 15))
  162959. {
  162960. warning_number[offset-1]='\0';
  162961. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  162962. warning_message+offset);
  162963. }
  162964. else
  162965. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162966. }
  162967. else
  162968. # endif
  162969. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162970. #else
  162971. warning_message = warning_message; /* make compiler happy */
  162972. #endif
  162973. png_ptr = png_ptr; /* make compiler happy */
  162974. }
  162975. #endif /* PNG_NO_WARNINGS */
  162976. void PNGAPI
  162977. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  162978. png_error_ptr error_fn, png_error_ptr warning_fn)
  162979. {
  162980. if (png_ptr == NULL)
  162981. return;
  162982. png_ptr->error_ptr = error_ptr;
  162983. png_ptr->error_fn = error_fn;
  162984. png_ptr->warning_fn = warning_fn;
  162985. }
  162986. png_voidp PNGAPI
  162987. png_get_error_ptr(png_structp png_ptr)
  162988. {
  162989. if (png_ptr == NULL)
  162990. return NULL;
  162991. return ((png_voidp)png_ptr->error_ptr);
  162992. }
  162993. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162994. void PNGAPI
  162995. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  162996. {
  162997. if(png_ptr != NULL)
  162998. {
  162999. png_ptr->flags &=
  163000. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  163001. }
  163002. }
  163003. #endif
  163004. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163005. /*** End of inlined file: pngerror.c ***/
  163006. /*** Start of inlined file: pngget.c ***/
  163007. #define PNG_INTERNAL
  163008. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163009. png_uint_32 PNGAPI
  163010. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  163011. {
  163012. if (png_ptr != NULL && info_ptr != NULL)
  163013. return(info_ptr->valid & flag);
  163014. else
  163015. return(0);
  163016. }
  163017. png_uint_32 PNGAPI
  163018. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163019. {
  163020. if (png_ptr != NULL && info_ptr != NULL)
  163021. return(info_ptr->rowbytes);
  163022. else
  163023. return(0);
  163024. }
  163025. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163026. png_bytepp PNGAPI
  163027. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163028. {
  163029. if (png_ptr != NULL && info_ptr != NULL)
  163030. return(info_ptr->row_pointers);
  163031. else
  163032. return(0);
  163033. }
  163034. #endif
  163035. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163036. png_uint_32 PNGAPI
  163037. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163038. {
  163039. if (png_ptr != NULL && info_ptr != NULL)
  163040. {
  163041. return info_ptr->width;
  163042. }
  163043. return (0);
  163044. }
  163045. png_uint_32 PNGAPI
  163046. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163047. {
  163048. if (png_ptr != NULL && info_ptr != NULL)
  163049. {
  163050. return info_ptr->height;
  163051. }
  163052. return (0);
  163053. }
  163054. png_byte PNGAPI
  163055. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163056. {
  163057. if (png_ptr != NULL && info_ptr != NULL)
  163058. {
  163059. return info_ptr->bit_depth;
  163060. }
  163061. return (0);
  163062. }
  163063. png_byte PNGAPI
  163064. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163065. {
  163066. if (png_ptr != NULL && info_ptr != NULL)
  163067. {
  163068. return info_ptr->color_type;
  163069. }
  163070. return (0);
  163071. }
  163072. png_byte PNGAPI
  163073. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163074. {
  163075. if (png_ptr != NULL && info_ptr != NULL)
  163076. {
  163077. return info_ptr->filter_type;
  163078. }
  163079. return (0);
  163080. }
  163081. png_byte PNGAPI
  163082. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163083. {
  163084. if (png_ptr != NULL && info_ptr != NULL)
  163085. {
  163086. return info_ptr->interlace_type;
  163087. }
  163088. return (0);
  163089. }
  163090. png_byte PNGAPI
  163091. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163092. {
  163093. if (png_ptr != NULL && info_ptr != NULL)
  163094. {
  163095. return info_ptr->compression_type;
  163096. }
  163097. return (0);
  163098. }
  163099. png_uint_32 PNGAPI
  163100. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163101. {
  163102. if (png_ptr != NULL && info_ptr != NULL)
  163103. #if defined(PNG_pHYs_SUPPORTED)
  163104. if (info_ptr->valid & PNG_INFO_pHYs)
  163105. {
  163106. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163107. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163108. return (0);
  163109. else return (info_ptr->x_pixels_per_unit);
  163110. }
  163111. #else
  163112. return (0);
  163113. #endif
  163114. return (0);
  163115. }
  163116. png_uint_32 PNGAPI
  163117. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163118. {
  163119. if (png_ptr != NULL && info_ptr != NULL)
  163120. #if defined(PNG_pHYs_SUPPORTED)
  163121. if (info_ptr->valid & PNG_INFO_pHYs)
  163122. {
  163123. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163124. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163125. return (0);
  163126. else return (info_ptr->y_pixels_per_unit);
  163127. }
  163128. #else
  163129. return (0);
  163130. #endif
  163131. return (0);
  163132. }
  163133. png_uint_32 PNGAPI
  163134. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163135. {
  163136. if (png_ptr != NULL && info_ptr != NULL)
  163137. #if defined(PNG_pHYs_SUPPORTED)
  163138. if (info_ptr->valid & PNG_INFO_pHYs)
  163139. {
  163140. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163141. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163142. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163143. return (0);
  163144. else return (info_ptr->x_pixels_per_unit);
  163145. }
  163146. #else
  163147. return (0);
  163148. #endif
  163149. return (0);
  163150. }
  163151. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163152. float PNGAPI
  163153. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163154. {
  163155. if (png_ptr != NULL && info_ptr != NULL)
  163156. #if defined(PNG_pHYs_SUPPORTED)
  163157. if (info_ptr->valid & PNG_INFO_pHYs)
  163158. {
  163159. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163160. if (info_ptr->x_pixels_per_unit == 0)
  163161. return ((float)0.0);
  163162. else
  163163. return ((float)((float)info_ptr->y_pixels_per_unit
  163164. /(float)info_ptr->x_pixels_per_unit));
  163165. }
  163166. #else
  163167. return (0.0);
  163168. #endif
  163169. return ((float)0.0);
  163170. }
  163171. #endif
  163172. png_int_32 PNGAPI
  163173. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163174. {
  163175. if (png_ptr != NULL && info_ptr != NULL)
  163176. #if defined(PNG_oFFs_SUPPORTED)
  163177. if (info_ptr->valid & PNG_INFO_oFFs)
  163178. {
  163179. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163180. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163181. return (0);
  163182. else return (info_ptr->x_offset);
  163183. }
  163184. #else
  163185. return (0);
  163186. #endif
  163187. return (0);
  163188. }
  163189. png_int_32 PNGAPI
  163190. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163191. {
  163192. if (png_ptr != NULL && info_ptr != NULL)
  163193. #if defined(PNG_oFFs_SUPPORTED)
  163194. if (info_ptr->valid & PNG_INFO_oFFs)
  163195. {
  163196. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163197. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163198. return (0);
  163199. else return (info_ptr->y_offset);
  163200. }
  163201. #else
  163202. return (0);
  163203. #endif
  163204. return (0);
  163205. }
  163206. png_int_32 PNGAPI
  163207. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163208. {
  163209. if (png_ptr != NULL && info_ptr != NULL)
  163210. #if defined(PNG_oFFs_SUPPORTED)
  163211. if (info_ptr->valid & PNG_INFO_oFFs)
  163212. {
  163213. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163214. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163215. return (0);
  163216. else return (info_ptr->x_offset);
  163217. }
  163218. #else
  163219. return (0);
  163220. #endif
  163221. return (0);
  163222. }
  163223. png_int_32 PNGAPI
  163224. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163225. {
  163226. if (png_ptr != NULL && info_ptr != NULL)
  163227. #if defined(PNG_oFFs_SUPPORTED)
  163228. if (info_ptr->valid & PNG_INFO_oFFs)
  163229. {
  163230. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163231. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163232. return (0);
  163233. else return (info_ptr->y_offset);
  163234. }
  163235. #else
  163236. return (0);
  163237. #endif
  163238. return (0);
  163239. }
  163240. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163241. png_uint_32 PNGAPI
  163242. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163243. {
  163244. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163245. *.0254 +.5));
  163246. }
  163247. png_uint_32 PNGAPI
  163248. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163249. {
  163250. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163251. *.0254 +.5));
  163252. }
  163253. png_uint_32 PNGAPI
  163254. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163255. {
  163256. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163257. *.0254 +.5));
  163258. }
  163259. float PNGAPI
  163260. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163261. {
  163262. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163263. *.00003937);
  163264. }
  163265. float PNGAPI
  163266. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163267. {
  163268. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163269. *.00003937);
  163270. }
  163271. #if defined(PNG_pHYs_SUPPORTED)
  163272. png_uint_32 PNGAPI
  163273. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163274. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163275. {
  163276. png_uint_32 retval = 0;
  163277. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163278. {
  163279. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163280. if (res_x != NULL)
  163281. {
  163282. *res_x = info_ptr->x_pixels_per_unit;
  163283. retval |= PNG_INFO_pHYs;
  163284. }
  163285. if (res_y != NULL)
  163286. {
  163287. *res_y = info_ptr->y_pixels_per_unit;
  163288. retval |= PNG_INFO_pHYs;
  163289. }
  163290. if (unit_type != NULL)
  163291. {
  163292. *unit_type = (int)info_ptr->phys_unit_type;
  163293. retval |= PNG_INFO_pHYs;
  163294. if(*unit_type == 1)
  163295. {
  163296. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163297. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163298. }
  163299. }
  163300. }
  163301. return (retval);
  163302. }
  163303. #endif /* PNG_pHYs_SUPPORTED */
  163304. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163305. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163306. png_byte PNGAPI
  163307. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163308. {
  163309. if (png_ptr != NULL && info_ptr != NULL)
  163310. return(info_ptr->channels);
  163311. else
  163312. return (0);
  163313. }
  163314. png_bytep PNGAPI
  163315. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163316. {
  163317. if (png_ptr != NULL && info_ptr != NULL)
  163318. return(info_ptr->signature);
  163319. else
  163320. return (NULL);
  163321. }
  163322. #if defined(PNG_bKGD_SUPPORTED)
  163323. png_uint_32 PNGAPI
  163324. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163325. png_color_16p *background)
  163326. {
  163327. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163328. && background != NULL)
  163329. {
  163330. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163331. *background = &(info_ptr->background);
  163332. return (PNG_INFO_bKGD);
  163333. }
  163334. return (0);
  163335. }
  163336. #endif
  163337. #if defined(PNG_cHRM_SUPPORTED)
  163338. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163339. png_uint_32 PNGAPI
  163340. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163341. double *white_x, double *white_y, double *red_x, double *red_y,
  163342. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163343. {
  163344. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163345. {
  163346. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163347. if (white_x != NULL)
  163348. *white_x = (double)info_ptr->x_white;
  163349. if (white_y != NULL)
  163350. *white_y = (double)info_ptr->y_white;
  163351. if (red_x != NULL)
  163352. *red_x = (double)info_ptr->x_red;
  163353. if (red_y != NULL)
  163354. *red_y = (double)info_ptr->y_red;
  163355. if (green_x != NULL)
  163356. *green_x = (double)info_ptr->x_green;
  163357. if (green_y != NULL)
  163358. *green_y = (double)info_ptr->y_green;
  163359. if (blue_x != NULL)
  163360. *blue_x = (double)info_ptr->x_blue;
  163361. if (blue_y != NULL)
  163362. *blue_y = (double)info_ptr->y_blue;
  163363. return (PNG_INFO_cHRM);
  163364. }
  163365. return (0);
  163366. }
  163367. #endif
  163368. #ifdef PNG_FIXED_POINT_SUPPORTED
  163369. png_uint_32 PNGAPI
  163370. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163371. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163372. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163373. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163374. {
  163375. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163376. {
  163377. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163378. if (white_x != NULL)
  163379. *white_x = info_ptr->int_x_white;
  163380. if (white_y != NULL)
  163381. *white_y = info_ptr->int_y_white;
  163382. if (red_x != NULL)
  163383. *red_x = info_ptr->int_x_red;
  163384. if (red_y != NULL)
  163385. *red_y = info_ptr->int_y_red;
  163386. if (green_x != NULL)
  163387. *green_x = info_ptr->int_x_green;
  163388. if (green_y != NULL)
  163389. *green_y = info_ptr->int_y_green;
  163390. if (blue_x != NULL)
  163391. *blue_x = info_ptr->int_x_blue;
  163392. if (blue_y != NULL)
  163393. *blue_y = info_ptr->int_y_blue;
  163394. return (PNG_INFO_cHRM);
  163395. }
  163396. return (0);
  163397. }
  163398. #endif
  163399. #endif
  163400. #if defined(PNG_gAMA_SUPPORTED)
  163401. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163402. png_uint_32 PNGAPI
  163403. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163404. {
  163405. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163406. && file_gamma != NULL)
  163407. {
  163408. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163409. *file_gamma = (double)info_ptr->gamma;
  163410. return (PNG_INFO_gAMA);
  163411. }
  163412. return (0);
  163413. }
  163414. #endif
  163415. #ifdef PNG_FIXED_POINT_SUPPORTED
  163416. png_uint_32 PNGAPI
  163417. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163418. png_fixed_point *int_file_gamma)
  163419. {
  163420. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163421. && int_file_gamma != NULL)
  163422. {
  163423. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163424. *int_file_gamma = info_ptr->int_gamma;
  163425. return (PNG_INFO_gAMA);
  163426. }
  163427. return (0);
  163428. }
  163429. #endif
  163430. #endif
  163431. #if defined(PNG_sRGB_SUPPORTED)
  163432. png_uint_32 PNGAPI
  163433. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163434. {
  163435. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163436. && file_srgb_intent != NULL)
  163437. {
  163438. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163439. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163440. return (PNG_INFO_sRGB);
  163441. }
  163442. return (0);
  163443. }
  163444. #endif
  163445. #if defined(PNG_iCCP_SUPPORTED)
  163446. png_uint_32 PNGAPI
  163447. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163448. png_charpp name, int *compression_type,
  163449. png_charpp profile, png_uint_32 *proflen)
  163450. {
  163451. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163452. && name != NULL && profile != NULL && proflen != NULL)
  163453. {
  163454. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163455. *name = info_ptr->iccp_name;
  163456. *profile = info_ptr->iccp_profile;
  163457. *proflen = (int)info_ptr->iccp_proflen;
  163458. *compression_type = (int)info_ptr->iccp_compression;
  163459. return (PNG_INFO_iCCP);
  163460. }
  163461. return (0);
  163462. }
  163463. #endif
  163464. #if defined(PNG_sPLT_SUPPORTED)
  163465. png_uint_32 PNGAPI
  163466. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163467. png_sPLT_tpp spalettes)
  163468. {
  163469. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163470. {
  163471. *spalettes = info_ptr->splt_palettes;
  163472. return ((png_uint_32)info_ptr->splt_palettes_num);
  163473. }
  163474. return (0);
  163475. }
  163476. #endif
  163477. #if defined(PNG_hIST_SUPPORTED)
  163478. png_uint_32 PNGAPI
  163479. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163480. {
  163481. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163482. && hist != NULL)
  163483. {
  163484. png_debug1(1, "in %s retrieval function\n", "hIST");
  163485. *hist = info_ptr->hist;
  163486. return (PNG_INFO_hIST);
  163487. }
  163488. return (0);
  163489. }
  163490. #endif
  163491. png_uint_32 PNGAPI
  163492. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163493. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163494. int *color_type, int *interlace_type, int *compression_type,
  163495. int *filter_type)
  163496. {
  163497. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163498. bit_depth != NULL && color_type != NULL)
  163499. {
  163500. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163501. *width = info_ptr->width;
  163502. *height = info_ptr->height;
  163503. *bit_depth = info_ptr->bit_depth;
  163504. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163505. png_error(png_ptr, "Invalid bit depth");
  163506. *color_type = info_ptr->color_type;
  163507. if (info_ptr->color_type > 6)
  163508. png_error(png_ptr, "Invalid color type");
  163509. if (compression_type != NULL)
  163510. *compression_type = info_ptr->compression_type;
  163511. if (filter_type != NULL)
  163512. *filter_type = info_ptr->filter_type;
  163513. if (interlace_type != NULL)
  163514. *interlace_type = info_ptr->interlace_type;
  163515. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163516. png_error(png_ptr, "Invalid image width");
  163517. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163518. png_error(png_ptr, "Invalid image height");
  163519. if (info_ptr->width > (PNG_UINT_32_MAX
  163520. >> 3) /* 8-byte RGBA pixels */
  163521. - 64 /* bigrowbuf hack */
  163522. - 1 /* filter byte */
  163523. - 7*8 /* rounding of width to multiple of 8 pixels */
  163524. - 8) /* extra max_pixel_depth pad */
  163525. {
  163526. png_warning(png_ptr,
  163527. "Width too large for libpng to process image data.");
  163528. }
  163529. return (1);
  163530. }
  163531. return (0);
  163532. }
  163533. #if defined(PNG_oFFs_SUPPORTED)
  163534. png_uint_32 PNGAPI
  163535. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163536. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163537. {
  163538. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163539. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163540. {
  163541. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163542. *offset_x = info_ptr->x_offset;
  163543. *offset_y = info_ptr->y_offset;
  163544. *unit_type = (int)info_ptr->offset_unit_type;
  163545. return (PNG_INFO_oFFs);
  163546. }
  163547. return (0);
  163548. }
  163549. #endif
  163550. #if defined(PNG_pCAL_SUPPORTED)
  163551. png_uint_32 PNGAPI
  163552. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  163553. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  163554. png_charp *units, png_charpp *params)
  163555. {
  163556. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  163557. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  163558. nparams != NULL && units != NULL && params != NULL)
  163559. {
  163560. png_debug1(1, "in %s retrieval function\n", "pCAL");
  163561. *purpose = info_ptr->pcal_purpose;
  163562. *X0 = info_ptr->pcal_X0;
  163563. *X1 = info_ptr->pcal_X1;
  163564. *type = (int)info_ptr->pcal_type;
  163565. *nparams = (int)info_ptr->pcal_nparams;
  163566. *units = info_ptr->pcal_units;
  163567. *params = info_ptr->pcal_params;
  163568. return (PNG_INFO_pCAL);
  163569. }
  163570. return (0);
  163571. }
  163572. #endif
  163573. #if defined(PNG_sCAL_SUPPORTED)
  163574. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163575. png_uint_32 PNGAPI
  163576. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  163577. int *unit, double *width, double *height)
  163578. {
  163579. if (png_ptr != NULL && info_ptr != NULL &&
  163580. (info_ptr->valid & PNG_INFO_sCAL))
  163581. {
  163582. *unit = info_ptr->scal_unit;
  163583. *width = info_ptr->scal_pixel_width;
  163584. *height = info_ptr->scal_pixel_height;
  163585. return (PNG_INFO_sCAL);
  163586. }
  163587. return(0);
  163588. }
  163589. #else
  163590. #ifdef PNG_FIXED_POINT_SUPPORTED
  163591. png_uint_32 PNGAPI
  163592. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  163593. int *unit, png_charpp width, png_charpp height)
  163594. {
  163595. if (png_ptr != NULL && info_ptr != NULL &&
  163596. (info_ptr->valid & PNG_INFO_sCAL))
  163597. {
  163598. *unit = info_ptr->scal_unit;
  163599. *width = info_ptr->scal_s_width;
  163600. *height = info_ptr->scal_s_height;
  163601. return (PNG_INFO_sCAL);
  163602. }
  163603. return(0);
  163604. }
  163605. #endif
  163606. #endif
  163607. #endif
  163608. #if defined(PNG_pHYs_SUPPORTED)
  163609. png_uint_32 PNGAPI
  163610. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  163611. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163612. {
  163613. png_uint_32 retval = 0;
  163614. if (png_ptr != NULL && info_ptr != NULL &&
  163615. (info_ptr->valid & PNG_INFO_pHYs))
  163616. {
  163617. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163618. if (res_x != NULL)
  163619. {
  163620. *res_x = info_ptr->x_pixels_per_unit;
  163621. retval |= PNG_INFO_pHYs;
  163622. }
  163623. if (res_y != NULL)
  163624. {
  163625. *res_y = info_ptr->y_pixels_per_unit;
  163626. retval |= PNG_INFO_pHYs;
  163627. }
  163628. if (unit_type != NULL)
  163629. {
  163630. *unit_type = (int)info_ptr->phys_unit_type;
  163631. retval |= PNG_INFO_pHYs;
  163632. }
  163633. }
  163634. return (retval);
  163635. }
  163636. #endif
  163637. png_uint_32 PNGAPI
  163638. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  163639. int *num_palette)
  163640. {
  163641. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  163642. && palette != NULL)
  163643. {
  163644. png_debug1(1, "in %s retrieval function\n", "PLTE");
  163645. *palette = info_ptr->palette;
  163646. *num_palette = info_ptr->num_palette;
  163647. png_debug1(3, "num_palette = %d\n", *num_palette);
  163648. return (PNG_INFO_PLTE);
  163649. }
  163650. return (0);
  163651. }
  163652. #if defined(PNG_sBIT_SUPPORTED)
  163653. png_uint_32 PNGAPI
  163654. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  163655. {
  163656. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  163657. && sig_bit != NULL)
  163658. {
  163659. png_debug1(1, "in %s retrieval function\n", "sBIT");
  163660. *sig_bit = &(info_ptr->sig_bit);
  163661. return (PNG_INFO_sBIT);
  163662. }
  163663. return (0);
  163664. }
  163665. #endif
  163666. #if defined(PNG_TEXT_SUPPORTED)
  163667. png_uint_32 PNGAPI
  163668. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  163669. int *num_text)
  163670. {
  163671. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  163672. {
  163673. png_debug1(1, "in %s retrieval function\n",
  163674. (png_ptr->chunk_name[0] == '\0' ? "text"
  163675. : (png_const_charp)png_ptr->chunk_name));
  163676. if (text_ptr != NULL)
  163677. *text_ptr = info_ptr->text;
  163678. if (num_text != NULL)
  163679. *num_text = info_ptr->num_text;
  163680. return ((png_uint_32)info_ptr->num_text);
  163681. }
  163682. if (num_text != NULL)
  163683. *num_text = 0;
  163684. return(0);
  163685. }
  163686. #endif
  163687. #if defined(PNG_tIME_SUPPORTED)
  163688. png_uint_32 PNGAPI
  163689. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  163690. {
  163691. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  163692. && mod_time != NULL)
  163693. {
  163694. png_debug1(1, "in %s retrieval function\n", "tIME");
  163695. *mod_time = &(info_ptr->mod_time);
  163696. return (PNG_INFO_tIME);
  163697. }
  163698. return (0);
  163699. }
  163700. #endif
  163701. #if defined(PNG_tRNS_SUPPORTED)
  163702. png_uint_32 PNGAPI
  163703. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  163704. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  163705. {
  163706. png_uint_32 retval = 0;
  163707. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  163708. {
  163709. png_debug1(1, "in %s retrieval function\n", "tRNS");
  163710. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  163711. {
  163712. if (trans != NULL)
  163713. {
  163714. *trans = info_ptr->trans;
  163715. retval |= PNG_INFO_tRNS;
  163716. }
  163717. if (trans_values != NULL)
  163718. *trans_values = &(info_ptr->trans_values);
  163719. }
  163720. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  163721. {
  163722. if (trans_values != NULL)
  163723. {
  163724. *trans_values = &(info_ptr->trans_values);
  163725. retval |= PNG_INFO_tRNS;
  163726. }
  163727. if(trans != NULL)
  163728. *trans = NULL;
  163729. }
  163730. if(num_trans != NULL)
  163731. {
  163732. *num_trans = info_ptr->num_trans;
  163733. retval |= PNG_INFO_tRNS;
  163734. }
  163735. }
  163736. return (retval);
  163737. }
  163738. #endif
  163739. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163740. png_uint_32 PNGAPI
  163741. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  163742. png_unknown_chunkpp unknowns)
  163743. {
  163744. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  163745. {
  163746. *unknowns = info_ptr->unknown_chunks;
  163747. return ((png_uint_32)info_ptr->unknown_chunks_num);
  163748. }
  163749. return (0);
  163750. }
  163751. #endif
  163752. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  163753. png_byte PNGAPI
  163754. png_get_rgb_to_gray_status (png_structp png_ptr)
  163755. {
  163756. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  163757. }
  163758. #endif
  163759. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  163760. png_voidp PNGAPI
  163761. png_get_user_chunk_ptr(png_structp png_ptr)
  163762. {
  163763. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  163764. }
  163765. #endif
  163766. #ifdef PNG_WRITE_SUPPORTED
  163767. png_uint_32 PNGAPI
  163768. png_get_compression_buffer_size(png_structp png_ptr)
  163769. {
  163770. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  163771. }
  163772. #endif
  163773. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  163774. #ifndef PNG_1_0_X
  163775. png_uint_32 PNGAPI
  163776. png_get_asm_flags (png_structp png_ptr)
  163777. {
  163778. return (png_ptr? 0L: 0L);
  163779. }
  163780. png_uint_32 PNGAPI
  163781. png_get_asm_flagmask (int flag_select)
  163782. {
  163783. flag_select=flag_select;
  163784. return 0L;
  163785. }
  163786. png_uint_32 PNGAPI
  163787. png_get_mmx_flagmask (int flag_select, int *compilerID)
  163788. {
  163789. flag_select=flag_select;
  163790. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  163791. return 0L;
  163792. }
  163793. png_byte PNGAPI
  163794. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  163795. {
  163796. return (png_ptr? 0: 0);
  163797. }
  163798. png_uint_32 PNGAPI
  163799. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  163800. {
  163801. return (png_ptr? 0L: 0L);
  163802. }
  163803. #endif /* ?PNG_1_0_X */
  163804. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  163805. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  163806. png_uint_32 PNGAPI
  163807. png_get_user_width_max (png_structp png_ptr)
  163808. {
  163809. return (png_ptr? png_ptr->user_width_max : 0);
  163810. }
  163811. png_uint_32 PNGAPI
  163812. png_get_user_height_max (png_structp png_ptr)
  163813. {
  163814. return (png_ptr? png_ptr->user_height_max : 0);
  163815. }
  163816. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  163817. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163818. /*** End of inlined file: pngget.c ***/
  163819. /*** Start of inlined file: pngmem.c ***/
  163820. #define PNG_INTERNAL
  163821. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163822. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  163823. png_voidp /* PRIVATE */
  163824. png_create_struct(int type)
  163825. {
  163826. #ifdef PNG_USER_MEM_SUPPORTED
  163827. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163828. }
  163829. png_voidp /* PRIVATE */
  163830. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163831. {
  163832. #endif /* PNG_USER_MEM_SUPPORTED */
  163833. png_size_t size;
  163834. png_voidp struct_ptr;
  163835. if (type == PNG_STRUCT_INFO)
  163836. size = png_sizeof(png_info);
  163837. else if (type == PNG_STRUCT_PNG)
  163838. size = png_sizeof(png_struct);
  163839. else
  163840. return (png_get_copyright(NULL));
  163841. #ifdef PNG_USER_MEM_SUPPORTED
  163842. if(malloc_fn != NULL)
  163843. {
  163844. png_struct dummy_struct;
  163845. png_structp png_ptr = &dummy_struct;
  163846. png_ptr->mem_ptr=mem_ptr;
  163847. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  163848. }
  163849. else
  163850. #endif /* PNG_USER_MEM_SUPPORTED */
  163851. struct_ptr = (png_voidp)farmalloc(size);
  163852. if (struct_ptr != NULL)
  163853. png_memset(struct_ptr, 0, size);
  163854. return (struct_ptr);
  163855. }
  163856. void /* PRIVATE */
  163857. png_destroy_struct(png_voidp struct_ptr)
  163858. {
  163859. #ifdef PNG_USER_MEM_SUPPORTED
  163860. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  163861. }
  163862. void /* PRIVATE */
  163863. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  163864. png_voidp mem_ptr)
  163865. {
  163866. #endif
  163867. if (struct_ptr != NULL)
  163868. {
  163869. #ifdef PNG_USER_MEM_SUPPORTED
  163870. if(free_fn != NULL)
  163871. {
  163872. png_struct dummy_struct;
  163873. png_structp png_ptr = &dummy_struct;
  163874. png_ptr->mem_ptr=mem_ptr;
  163875. (*(free_fn))(png_ptr, struct_ptr);
  163876. return;
  163877. }
  163878. #endif /* PNG_USER_MEM_SUPPORTED */
  163879. farfree (struct_ptr);
  163880. }
  163881. }
  163882. png_voidp PNGAPI
  163883. png_malloc(png_structp png_ptr, png_uint_32 size)
  163884. {
  163885. png_voidp ret;
  163886. if (png_ptr == NULL || size == 0)
  163887. return (NULL);
  163888. #ifdef PNG_USER_MEM_SUPPORTED
  163889. if(png_ptr->malloc_fn != NULL)
  163890. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  163891. else
  163892. ret = (png_malloc_default(png_ptr, size));
  163893. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163894. png_error(png_ptr, "Out of memory!");
  163895. return (ret);
  163896. }
  163897. png_voidp PNGAPI
  163898. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  163899. {
  163900. png_voidp ret;
  163901. #endif /* PNG_USER_MEM_SUPPORTED */
  163902. if (png_ptr == NULL || size == 0)
  163903. return (NULL);
  163904. #ifdef PNG_MAX_MALLOC_64K
  163905. if (size > (png_uint_32)65536L)
  163906. {
  163907. png_warning(png_ptr, "Cannot Allocate > 64K");
  163908. ret = NULL;
  163909. }
  163910. else
  163911. #endif
  163912. if (size != (size_t)size)
  163913. ret = NULL;
  163914. else if (size == (png_uint_32)65536L)
  163915. {
  163916. if (png_ptr->offset_table == NULL)
  163917. {
  163918. ret = farmalloc(size);
  163919. if (ret == NULL || ((png_size_t)ret & 0xffff))
  163920. {
  163921. int num_blocks;
  163922. png_uint_32 total_size;
  163923. png_bytep table;
  163924. int i;
  163925. png_byte huge * hptr;
  163926. if (ret != NULL)
  163927. {
  163928. farfree(ret);
  163929. ret = NULL;
  163930. }
  163931. if(png_ptr->zlib_window_bits > 14)
  163932. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  163933. else
  163934. num_blocks = 1;
  163935. if (png_ptr->zlib_mem_level >= 7)
  163936. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  163937. else
  163938. num_blocks++;
  163939. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  163940. table = farmalloc(total_size);
  163941. if (table == NULL)
  163942. {
  163943. #ifndef PNG_USER_MEM_SUPPORTED
  163944. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163945. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  163946. else
  163947. png_warning(png_ptr, "Out Of Memory.");
  163948. #endif
  163949. return (NULL);
  163950. }
  163951. if ((png_size_t)table & 0xfff0)
  163952. {
  163953. #ifndef PNG_USER_MEM_SUPPORTED
  163954. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163955. png_error(png_ptr,
  163956. "Farmalloc didn't return normalized pointer");
  163957. else
  163958. png_warning(png_ptr,
  163959. "Farmalloc didn't return normalized pointer");
  163960. #endif
  163961. return (NULL);
  163962. }
  163963. png_ptr->offset_table = table;
  163964. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  163965. png_sizeof (png_bytep));
  163966. if (png_ptr->offset_table_ptr == NULL)
  163967. {
  163968. #ifndef PNG_USER_MEM_SUPPORTED
  163969. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163970. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  163971. else
  163972. png_warning(png_ptr, "Out Of memory.");
  163973. #endif
  163974. return (NULL);
  163975. }
  163976. hptr = (png_byte huge *)table;
  163977. if ((png_size_t)hptr & 0xf)
  163978. {
  163979. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  163980. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  163981. }
  163982. for (i = 0; i < num_blocks; i++)
  163983. {
  163984. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  163985. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  163986. }
  163987. png_ptr->offset_table_number = num_blocks;
  163988. png_ptr->offset_table_count = 0;
  163989. png_ptr->offset_table_count_free = 0;
  163990. }
  163991. }
  163992. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  163993. {
  163994. #ifndef PNG_USER_MEM_SUPPORTED
  163995. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163996. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  163997. else
  163998. png_warning(png_ptr, "Out of Memory.");
  163999. #endif
  164000. return (NULL);
  164001. }
  164002. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  164003. }
  164004. else
  164005. ret = farmalloc(size);
  164006. #ifndef PNG_USER_MEM_SUPPORTED
  164007. if (ret == NULL)
  164008. {
  164009. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164010. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164011. else
  164012. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164013. }
  164014. #endif
  164015. return (ret);
  164016. }
  164017. void PNGAPI
  164018. png_free(png_structp png_ptr, png_voidp ptr)
  164019. {
  164020. if (png_ptr == NULL || ptr == NULL)
  164021. return;
  164022. #ifdef PNG_USER_MEM_SUPPORTED
  164023. if (png_ptr->free_fn != NULL)
  164024. {
  164025. (*(png_ptr->free_fn))(png_ptr, ptr);
  164026. return;
  164027. }
  164028. else png_free_default(png_ptr, ptr);
  164029. }
  164030. void PNGAPI
  164031. png_free_default(png_structp png_ptr, png_voidp ptr)
  164032. {
  164033. #endif /* PNG_USER_MEM_SUPPORTED */
  164034. if(png_ptr == NULL) return;
  164035. if (png_ptr->offset_table != NULL)
  164036. {
  164037. int i;
  164038. for (i = 0; i < png_ptr->offset_table_count; i++)
  164039. {
  164040. if (ptr == png_ptr->offset_table_ptr[i])
  164041. {
  164042. ptr = NULL;
  164043. png_ptr->offset_table_count_free++;
  164044. break;
  164045. }
  164046. }
  164047. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164048. {
  164049. farfree(png_ptr->offset_table);
  164050. farfree(png_ptr->offset_table_ptr);
  164051. png_ptr->offset_table = NULL;
  164052. png_ptr->offset_table_ptr = NULL;
  164053. }
  164054. }
  164055. if (ptr != NULL)
  164056. {
  164057. farfree(ptr);
  164058. }
  164059. }
  164060. #else /* Not the Borland DOS special memory handler */
  164061. png_voidp /* PRIVATE */
  164062. png_create_struct(int type)
  164063. {
  164064. #ifdef PNG_USER_MEM_SUPPORTED
  164065. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164066. }
  164067. png_voidp /* PRIVATE */
  164068. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164069. {
  164070. #endif /* PNG_USER_MEM_SUPPORTED */
  164071. png_size_t size;
  164072. png_voidp struct_ptr;
  164073. if (type == PNG_STRUCT_INFO)
  164074. size = png_sizeof(png_info);
  164075. else if (type == PNG_STRUCT_PNG)
  164076. size = png_sizeof(png_struct);
  164077. else
  164078. return (NULL);
  164079. #ifdef PNG_USER_MEM_SUPPORTED
  164080. if(malloc_fn != NULL)
  164081. {
  164082. png_struct dummy_struct;
  164083. png_structp png_ptr = &dummy_struct;
  164084. png_ptr->mem_ptr=mem_ptr;
  164085. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164086. if (struct_ptr != NULL)
  164087. png_memset(struct_ptr, 0, size);
  164088. return (struct_ptr);
  164089. }
  164090. #endif /* PNG_USER_MEM_SUPPORTED */
  164091. #if defined(__TURBOC__) && !defined(__FLAT__)
  164092. struct_ptr = (png_voidp)farmalloc(size);
  164093. #else
  164094. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164095. struct_ptr = (png_voidp)halloc(size,1);
  164096. # else
  164097. struct_ptr = (png_voidp)malloc(size);
  164098. # endif
  164099. #endif
  164100. if (struct_ptr != NULL)
  164101. png_memset(struct_ptr, 0, size);
  164102. return (struct_ptr);
  164103. }
  164104. void /* PRIVATE */
  164105. png_destroy_struct(png_voidp struct_ptr)
  164106. {
  164107. #ifdef PNG_USER_MEM_SUPPORTED
  164108. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164109. }
  164110. void /* PRIVATE */
  164111. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164112. png_voidp mem_ptr)
  164113. {
  164114. #endif /* PNG_USER_MEM_SUPPORTED */
  164115. if (struct_ptr != NULL)
  164116. {
  164117. #ifdef PNG_USER_MEM_SUPPORTED
  164118. if(free_fn != NULL)
  164119. {
  164120. png_struct dummy_struct;
  164121. png_structp png_ptr = &dummy_struct;
  164122. png_ptr->mem_ptr=mem_ptr;
  164123. (*(free_fn))(png_ptr, struct_ptr);
  164124. return;
  164125. }
  164126. #endif /* PNG_USER_MEM_SUPPORTED */
  164127. #if defined(__TURBOC__) && !defined(__FLAT__)
  164128. farfree(struct_ptr);
  164129. #else
  164130. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164131. hfree(struct_ptr);
  164132. # else
  164133. free(struct_ptr);
  164134. # endif
  164135. #endif
  164136. }
  164137. }
  164138. png_voidp PNGAPI
  164139. png_malloc(png_structp png_ptr, png_uint_32 size)
  164140. {
  164141. png_voidp ret;
  164142. #ifdef PNG_USER_MEM_SUPPORTED
  164143. if (png_ptr == NULL || size == 0)
  164144. return (NULL);
  164145. if(png_ptr->malloc_fn != NULL)
  164146. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164147. else
  164148. ret = (png_malloc_default(png_ptr, size));
  164149. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164150. png_error(png_ptr, "Out of Memory!");
  164151. return (ret);
  164152. }
  164153. png_voidp PNGAPI
  164154. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164155. {
  164156. png_voidp ret;
  164157. #endif /* PNG_USER_MEM_SUPPORTED */
  164158. if (png_ptr == NULL || size == 0)
  164159. return (NULL);
  164160. #ifdef PNG_MAX_MALLOC_64K
  164161. if (size > (png_uint_32)65536L)
  164162. {
  164163. #ifndef PNG_USER_MEM_SUPPORTED
  164164. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164165. png_error(png_ptr, "Cannot Allocate > 64K");
  164166. else
  164167. #endif
  164168. return NULL;
  164169. }
  164170. #endif
  164171. #if defined(__TURBOC__) && !defined(__FLAT__)
  164172. if (size != (unsigned long)size)
  164173. ret = NULL;
  164174. else
  164175. ret = farmalloc(size);
  164176. #else
  164177. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164178. if (size != (unsigned long)size)
  164179. ret = NULL;
  164180. else
  164181. ret = halloc(size, 1);
  164182. # else
  164183. if (size != (size_t)size)
  164184. ret = NULL;
  164185. else
  164186. ret = malloc((size_t)size);
  164187. # endif
  164188. #endif
  164189. #ifndef PNG_USER_MEM_SUPPORTED
  164190. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164191. png_error(png_ptr, "Out of Memory");
  164192. #endif
  164193. return (ret);
  164194. }
  164195. void PNGAPI
  164196. png_free(png_structp png_ptr, png_voidp ptr)
  164197. {
  164198. if (png_ptr == NULL || ptr == NULL)
  164199. return;
  164200. #ifdef PNG_USER_MEM_SUPPORTED
  164201. if (png_ptr->free_fn != NULL)
  164202. {
  164203. (*(png_ptr->free_fn))(png_ptr, ptr);
  164204. return;
  164205. }
  164206. else png_free_default(png_ptr, ptr);
  164207. }
  164208. void PNGAPI
  164209. png_free_default(png_structp png_ptr, png_voidp ptr)
  164210. {
  164211. if (png_ptr == NULL || ptr == NULL)
  164212. return;
  164213. #endif /* PNG_USER_MEM_SUPPORTED */
  164214. #if defined(__TURBOC__) && !defined(__FLAT__)
  164215. farfree(ptr);
  164216. #else
  164217. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164218. hfree(ptr);
  164219. # else
  164220. free(ptr);
  164221. # endif
  164222. #endif
  164223. }
  164224. #endif /* Not Borland DOS special memory handler */
  164225. #if defined(PNG_1_0_X)
  164226. # define png_malloc_warn png_malloc
  164227. #else
  164228. png_voidp PNGAPI
  164229. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164230. {
  164231. png_voidp ptr;
  164232. png_uint_32 save_flags;
  164233. if(png_ptr == NULL) return (NULL);
  164234. save_flags=png_ptr->flags;
  164235. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164236. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164237. png_ptr->flags=save_flags;
  164238. return(ptr);
  164239. }
  164240. #endif
  164241. png_voidp PNGAPI
  164242. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164243. png_uint_32 length)
  164244. {
  164245. png_size_t size;
  164246. size = (png_size_t)length;
  164247. if ((png_uint_32)size != length)
  164248. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164249. return(png_memcpy (s1, s2, size));
  164250. }
  164251. png_voidp PNGAPI
  164252. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164253. png_uint_32 length)
  164254. {
  164255. png_size_t size;
  164256. size = (png_size_t)length;
  164257. if ((png_uint_32)size != length)
  164258. png_error(png_ptr,"Overflow in png_memset_check.");
  164259. return (png_memset (s1, value, size));
  164260. }
  164261. #ifdef PNG_USER_MEM_SUPPORTED
  164262. void PNGAPI
  164263. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164264. malloc_fn, png_free_ptr free_fn)
  164265. {
  164266. if(png_ptr != NULL) {
  164267. png_ptr->mem_ptr = mem_ptr;
  164268. png_ptr->malloc_fn = malloc_fn;
  164269. png_ptr->free_fn = free_fn;
  164270. }
  164271. }
  164272. png_voidp PNGAPI
  164273. png_get_mem_ptr(png_structp png_ptr)
  164274. {
  164275. if(png_ptr == NULL) return (NULL);
  164276. return ((png_voidp)png_ptr->mem_ptr);
  164277. }
  164278. #endif /* PNG_USER_MEM_SUPPORTED */
  164279. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164280. /*** End of inlined file: pngmem.c ***/
  164281. /*** Start of inlined file: pngread.c ***/
  164282. #define PNG_INTERNAL
  164283. #if defined(PNG_READ_SUPPORTED)
  164284. png_structp PNGAPI
  164285. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164286. png_error_ptr error_fn, png_error_ptr warn_fn)
  164287. {
  164288. #ifdef PNG_USER_MEM_SUPPORTED
  164289. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164290. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164291. }
  164292. png_structp PNGAPI
  164293. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164294. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164295. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164296. {
  164297. #endif /* PNG_USER_MEM_SUPPORTED */
  164298. png_structp png_ptr;
  164299. #ifdef PNG_SETJMP_SUPPORTED
  164300. #ifdef USE_FAR_KEYWORD
  164301. jmp_buf jmpbuf;
  164302. #endif
  164303. #endif
  164304. int i;
  164305. png_debug(1, "in png_create_read_struct\n");
  164306. #ifdef PNG_USER_MEM_SUPPORTED
  164307. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164308. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164309. #else
  164310. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164311. #endif
  164312. if (png_ptr == NULL)
  164313. return (NULL);
  164314. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164315. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164316. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164317. #endif
  164318. #ifdef PNG_SETJMP_SUPPORTED
  164319. #ifdef USE_FAR_KEYWORD
  164320. if (setjmp(jmpbuf))
  164321. #else
  164322. if (setjmp(png_ptr->jmpbuf))
  164323. #endif
  164324. {
  164325. png_free(png_ptr, png_ptr->zbuf);
  164326. png_ptr->zbuf=NULL;
  164327. #ifdef PNG_USER_MEM_SUPPORTED
  164328. png_destroy_struct_2((png_voidp)png_ptr,
  164329. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164330. #else
  164331. png_destroy_struct((png_voidp)png_ptr);
  164332. #endif
  164333. return (NULL);
  164334. }
  164335. #ifdef USE_FAR_KEYWORD
  164336. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164337. #endif
  164338. #endif
  164339. #ifdef PNG_USER_MEM_SUPPORTED
  164340. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164341. #endif
  164342. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164343. i=0;
  164344. do
  164345. {
  164346. if(user_png_ver[i] != png_libpng_ver[i])
  164347. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164348. } while (png_libpng_ver[i++]);
  164349. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164350. {
  164351. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164352. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164353. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164354. {
  164355. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164356. char msg[80];
  164357. if (user_png_ver)
  164358. {
  164359. png_snprintf(msg, 80,
  164360. "Application was compiled with png.h from libpng-%.20s",
  164361. user_png_ver);
  164362. png_warning(png_ptr, msg);
  164363. }
  164364. png_snprintf(msg, 80,
  164365. "Application is running with png.c from libpng-%.20s",
  164366. png_libpng_ver);
  164367. png_warning(png_ptr, msg);
  164368. #endif
  164369. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164370. png_ptr->flags=0;
  164371. #endif
  164372. png_error(png_ptr,
  164373. "Incompatible libpng version in application and library");
  164374. }
  164375. }
  164376. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164377. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164378. (png_uint_32)png_ptr->zbuf_size);
  164379. png_ptr->zstream.zalloc = png_zalloc;
  164380. png_ptr->zstream.zfree = png_zfree;
  164381. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164382. switch (inflateInit(&png_ptr->zstream))
  164383. {
  164384. case Z_OK: /* Do nothing */ break;
  164385. case Z_MEM_ERROR:
  164386. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164387. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164388. default: png_error(png_ptr, "Unknown zlib error");
  164389. }
  164390. png_ptr->zstream.next_out = png_ptr->zbuf;
  164391. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164392. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164393. #ifdef PNG_SETJMP_SUPPORTED
  164394. #ifdef USE_FAR_KEYWORD
  164395. if (setjmp(jmpbuf))
  164396. PNG_ABORT();
  164397. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164398. #else
  164399. if (setjmp(png_ptr->jmpbuf))
  164400. PNG_ABORT();
  164401. #endif
  164402. #endif
  164403. return (png_ptr);
  164404. }
  164405. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164406. #undef png_read_init
  164407. void PNGAPI
  164408. png_read_init(png_structp png_ptr)
  164409. {
  164410. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164411. }
  164412. void PNGAPI
  164413. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164414. png_size_t png_struct_size, png_size_t png_info_size)
  164415. {
  164416. if(png_ptr == NULL) return;
  164417. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164418. if(png_sizeof(png_struct) > png_struct_size ||
  164419. png_sizeof(png_info) > png_info_size)
  164420. {
  164421. char msg[80];
  164422. png_ptr->warning_fn=NULL;
  164423. if (user_png_ver)
  164424. {
  164425. png_snprintf(msg, 80,
  164426. "Application was compiled with png.h from libpng-%.20s",
  164427. user_png_ver);
  164428. png_warning(png_ptr, msg);
  164429. }
  164430. png_snprintf(msg, 80,
  164431. "Application is running with png.c from libpng-%.20s",
  164432. png_libpng_ver);
  164433. png_warning(png_ptr, msg);
  164434. }
  164435. #endif
  164436. if(png_sizeof(png_struct) > png_struct_size)
  164437. {
  164438. png_ptr->error_fn=NULL;
  164439. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164440. png_ptr->flags=0;
  164441. #endif
  164442. png_error(png_ptr,
  164443. "The png struct allocated by the application for reading is too small.");
  164444. }
  164445. if(png_sizeof(png_info) > png_info_size)
  164446. {
  164447. png_ptr->error_fn=NULL;
  164448. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164449. png_ptr->flags=0;
  164450. #endif
  164451. png_error(png_ptr,
  164452. "The info struct allocated by application for reading is too small.");
  164453. }
  164454. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164455. }
  164456. #endif /* PNG_1_0_X || PNG_1_2_X */
  164457. void PNGAPI
  164458. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164459. png_size_t png_struct_size)
  164460. {
  164461. #ifdef PNG_SETJMP_SUPPORTED
  164462. jmp_buf tmp_jmp; /* to save current jump buffer */
  164463. #endif
  164464. int i=0;
  164465. png_structp png_ptr=*ptr_ptr;
  164466. if(png_ptr == NULL) return;
  164467. do
  164468. {
  164469. if(user_png_ver[i] != png_libpng_ver[i])
  164470. {
  164471. #ifdef PNG_LEGACY_SUPPORTED
  164472. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164473. #else
  164474. png_ptr->warning_fn=NULL;
  164475. png_warning(png_ptr,
  164476. "Application uses deprecated png_read_init() and should be recompiled.");
  164477. break;
  164478. #endif
  164479. }
  164480. } while (png_libpng_ver[i++]);
  164481. png_debug(1, "in png_read_init_3\n");
  164482. #ifdef PNG_SETJMP_SUPPORTED
  164483. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164484. #endif
  164485. if(png_sizeof(png_struct) > png_struct_size)
  164486. {
  164487. png_destroy_struct(png_ptr);
  164488. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164489. png_ptr = *ptr_ptr;
  164490. }
  164491. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164492. #ifdef PNG_SETJMP_SUPPORTED
  164493. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164494. #endif
  164495. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164496. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164497. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164498. #endif
  164499. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164500. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164501. (png_uint_32)png_ptr->zbuf_size);
  164502. png_ptr->zstream.zalloc = png_zalloc;
  164503. png_ptr->zstream.zfree = png_zfree;
  164504. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164505. switch (inflateInit(&png_ptr->zstream))
  164506. {
  164507. case Z_OK: /* Do nothing */ break;
  164508. case Z_MEM_ERROR:
  164509. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164510. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164511. default: png_error(png_ptr, "Unknown zlib error");
  164512. }
  164513. png_ptr->zstream.next_out = png_ptr->zbuf;
  164514. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164515. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164516. }
  164517. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164518. void PNGAPI
  164519. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164520. {
  164521. if(png_ptr == NULL) return;
  164522. png_debug(1, "in png_read_info\n");
  164523. if (png_ptr->sig_bytes < 8)
  164524. {
  164525. png_size_t num_checked = png_ptr->sig_bytes,
  164526. num_to_check = 8 - num_checked;
  164527. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164528. png_ptr->sig_bytes = 8;
  164529. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164530. {
  164531. if (num_checked < 4 &&
  164532. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164533. png_error(png_ptr, "Not a PNG file");
  164534. else
  164535. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164536. }
  164537. if (num_checked < 3)
  164538. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164539. }
  164540. for(;;)
  164541. {
  164542. #ifdef PNG_USE_LOCAL_ARRAYS
  164543. PNG_CONST PNG_IHDR;
  164544. PNG_CONST PNG_IDAT;
  164545. PNG_CONST PNG_IEND;
  164546. PNG_CONST PNG_PLTE;
  164547. #if defined(PNG_READ_bKGD_SUPPORTED)
  164548. PNG_CONST PNG_bKGD;
  164549. #endif
  164550. #if defined(PNG_READ_cHRM_SUPPORTED)
  164551. PNG_CONST PNG_cHRM;
  164552. #endif
  164553. #if defined(PNG_READ_gAMA_SUPPORTED)
  164554. PNG_CONST PNG_gAMA;
  164555. #endif
  164556. #if defined(PNG_READ_hIST_SUPPORTED)
  164557. PNG_CONST PNG_hIST;
  164558. #endif
  164559. #if defined(PNG_READ_iCCP_SUPPORTED)
  164560. PNG_CONST PNG_iCCP;
  164561. #endif
  164562. #if defined(PNG_READ_iTXt_SUPPORTED)
  164563. PNG_CONST PNG_iTXt;
  164564. #endif
  164565. #if defined(PNG_READ_oFFs_SUPPORTED)
  164566. PNG_CONST PNG_oFFs;
  164567. #endif
  164568. #if defined(PNG_READ_pCAL_SUPPORTED)
  164569. PNG_CONST PNG_pCAL;
  164570. #endif
  164571. #if defined(PNG_READ_pHYs_SUPPORTED)
  164572. PNG_CONST PNG_pHYs;
  164573. #endif
  164574. #if defined(PNG_READ_sBIT_SUPPORTED)
  164575. PNG_CONST PNG_sBIT;
  164576. #endif
  164577. #if defined(PNG_READ_sCAL_SUPPORTED)
  164578. PNG_CONST PNG_sCAL;
  164579. #endif
  164580. #if defined(PNG_READ_sPLT_SUPPORTED)
  164581. PNG_CONST PNG_sPLT;
  164582. #endif
  164583. #if defined(PNG_READ_sRGB_SUPPORTED)
  164584. PNG_CONST PNG_sRGB;
  164585. #endif
  164586. #if defined(PNG_READ_tEXt_SUPPORTED)
  164587. PNG_CONST PNG_tEXt;
  164588. #endif
  164589. #if defined(PNG_READ_tIME_SUPPORTED)
  164590. PNG_CONST PNG_tIME;
  164591. #endif
  164592. #if defined(PNG_READ_tRNS_SUPPORTED)
  164593. PNG_CONST PNG_tRNS;
  164594. #endif
  164595. #if defined(PNG_READ_zTXt_SUPPORTED)
  164596. PNG_CONST PNG_zTXt;
  164597. #endif
  164598. #endif /* PNG_USE_LOCAL_ARRAYS */
  164599. png_byte chunk_length[4];
  164600. png_uint_32 length;
  164601. png_read_data(png_ptr, chunk_length, 4);
  164602. length = png_get_uint_31(png_ptr,chunk_length);
  164603. png_reset_crc(png_ptr);
  164604. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164605. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  164606. length);
  164607. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164608. if(png_ptr->mode & PNG_AFTER_IDAT)
  164609. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  164610. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164611. png_handle_IHDR(png_ptr, info_ptr, length);
  164612. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164613. png_handle_IEND(png_ptr, info_ptr, length);
  164614. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164615. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164616. {
  164617. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164618. png_ptr->mode |= PNG_HAVE_IDAT;
  164619. png_handle_unknown(png_ptr, info_ptr, length);
  164620. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164621. png_ptr->mode |= PNG_HAVE_PLTE;
  164622. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164623. {
  164624. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164625. png_error(png_ptr, "Missing IHDR before IDAT");
  164626. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164627. !(png_ptr->mode & PNG_HAVE_PLTE))
  164628. png_error(png_ptr, "Missing PLTE before IDAT");
  164629. break;
  164630. }
  164631. }
  164632. #endif
  164633. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164634. png_handle_PLTE(png_ptr, info_ptr, length);
  164635. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164636. {
  164637. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164638. png_error(png_ptr, "Missing IHDR before IDAT");
  164639. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164640. !(png_ptr->mode & PNG_HAVE_PLTE))
  164641. png_error(png_ptr, "Missing PLTE before IDAT");
  164642. png_ptr->idat_size = length;
  164643. png_ptr->mode |= PNG_HAVE_IDAT;
  164644. break;
  164645. }
  164646. #if defined(PNG_READ_bKGD_SUPPORTED)
  164647. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  164648. png_handle_bKGD(png_ptr, info_ptr, length);
  164649. #endif
  164650. #if defined(PNG_READ_cHRM_SUPPORTED)
  164651. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  164652. png_handle_cHRM(png_ptr, info_ptr, length);
  164653. #endif
  164654. #if defined(PNG_READ_gAMA_SUPPORTED)
  164655. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  164656. png_handle_gAMA(png_ptr, info_ptr, length);
  164657. #endif
  164658. #if defined(PNG_READ_hIST_SUPPORTED)
  164659. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  164660. png_handle_hIST(png_ptr, info_ptr, length);
  164661. #endif
  164662. #if defined(PNG_READ_oFFs_SUPPORTED)
  164663. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  164664. png_handle_oFFs(png_ptr, info_ptr, length);
  164665. #endif
  164666. #if defined(PNG_READ_pCAL_SUPPORTED)
  164667. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  164668. png_handle_pCAL(png_ptr, info_ptr, length);
  164669. #endif
  164670. #if defined(PNG_READ_sCAL_SUPPORTED)
  164671. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  164672. png_handle_sCAL(png_ptr, info_ptr, length);
  164673. #endif
  164674. #if defined(PNG_READ_pHYs_SUPPORTED)
  164675. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  164676. png_handle_pHYs(png_ptr, info_ptr, length);
  164677. #endif
  164678. #if defined(PNG_READ_sBIT_SUPPORTED)
  164679. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  164680. png_handle_sBIT(png_ptr, info_ptr, length);
  164681. #endif
  164682. #if defined(PNG_READ_sRGB_SUPPORTED)
  164683. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  164684. png_handle_sRGB(png_ptr, info_ptr, length);
  164685. #endif
  164686. #if defined(PNG_READ_iCCP_SUPPORTED)
  164687. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  164688. png_handle_iCCP(png_ptr, info_ptr, length);
  164689. #endif
  164690. #if defined(PNG_READ_sPLT_SUPPORTED)
  164691. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  164692. png_handle_sPLT(png_ptr, info_ptr, length);
  164693. #endif
  164694. #if defined(PNG_READ_tEXt_SUPPORTED)
  164695. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  164696. png_handle_tEXt(png_ptr, info_ptr, length);
  164697. #endif
  164698. #if defined(PNG_READ_tIME_SUPPORTED)
  164699. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  164700. png_handle_tIME(png_ptr, info_ptr, length);
  164701. #endif
  164702. #if defined(PNG_READ_tRNS_SUPPORTED)
  164703. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  164704. png_handle_tRNS(png_ptr, info_ptr, length);
  164705. #endif
  164706. #if defined(PNG_READ_zTXt_SUPPORTED)
  164707. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  164708. png_handle_zTXt(png_ptr, info_ptr, length);
  164709. #endif
  164710. #if defined(PNG_READ_iTXt_SUPPORTED)
  164711. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  164712. png_handle_iTXt(png_ptr, info_ptr, length);
  164713. #endif
  164714. else
  164715. png_handle_unknown(png_ptr, info_ptr, length);
  164716. }
  164717. }
  164718. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164719. void PNGAPI
  164720. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  164721. {
  164722. png_debug(1, "in png_read_update_info\n");
  164723. if(png_ptr == NULL) return;
  164724. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164725. png_read_start_row(png_ptr);
  164726. else
  164727. png_warning(png_ptr,
  164728. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  164729. png_read_transform_info(png_ptr, info_ptr);
  164730. }
  164731. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164732. void PNGAPI
  164733. png_start_read_image(png_structp png_ptr)
  164734. {
  164735. png_debug(1, "in png_start_read_image\n");
  164736. if(png_ptr == NULL) return;
  164737. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164738. png_read_start_row(png_ptr);
  164739. }
  164740. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164741. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164742. void PNGAPI
  164743. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  164744. {
  164745. #ifdef PNG_USE_LOCAL_ARRAYS
  164746. PNG_CONST PNG_IDAT;
  164747. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  164748. 0xff};
  164749. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  164750. #endif
  164751. int ret;
  164752. if(png_ptr == NULL) return;
  164753. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  164754. png_ptr->row_number, png_ptr->pass);
  164755. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164756. png_read_start_row(png_ptr);
  164757. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  164758. {
  164759. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  164760. if (png_ptr->transformations & PNG_INVERT_MONO)
  164761. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  164762. #endif
  164763. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  164764. if (png_ptr->transformations & PNG_FILLER)
  164765. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  164766. #endif
  164767. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  164768. if (png_ptr->transformations & PNG_PACKSWAP)
  164769. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  164770. #endif
  164771. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  164772. if (png_ptr->transformations & PNG_PACK)
  164773. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  164774. #endif
  164775. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  164776. if (png_ptr->transformations & PNG_SHIFT)
  164777. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  164778. #endif
  164779. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  164780. if (png_ptr->transformations & PNG_BGR)
  164781. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  164782. #endif
  164783. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  164784. if (png_ptr->transformations & PNG_SWAP_BYTES)
  164785. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  164786. #endif
  164787. }
  164788. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164789. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  164790. {
  164791. switch (png_ptr->pass)
  164792. {
  164793. case 0:
  164794. if (png_ptr->row_number & 0x07)
  164795. {
  164796. if (dsp_row != NULL)
  164797. png_combine_row(png_ptr, dsp_row,
  164798. png_pass_dsp_mask[png_ptr->pass]);
  164799. png_read_finish_row(png_ptr);
  164800. return;
  164801. }
  164802. break;
  164803. case 1:
  164804. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  164805. {
  164806. if (dsp_row != NULL)
  164807. png_combine_row(png_ptr, dsp_row,
  164808. png_pass_dsp_mask[png_ptr->pass]);
  164809. png_read_finish_row(png_ptr);
  164810. return;
  164811. }
  164812. break;
  164813. case 2:
  164814. if ((png_ptr->row_number & 0x07) != 4)
  164815. {
  164816. if (dsp_row != NULL && (png_ptr->row_number & 4))
  164817. png_combine_row(png_ptr, dsp_row,
  164818. png_pass_dsp_mask[png_ptr->pass]);
  164819. png_read_finish_row(png_ptr);
  164820. return;
  164821. }
  164822. break;
  164823. case 3:
  164824. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  164825. {
  164826. if (dsp_row != NULL)
  164827. png_combine_row(png_ptr, dsp_row,
  164828. png_pass_dsp_mask[png_ptr->pass]);
  164829. png_read_finish_row(png_ptr);
  164830. return;
  164831. }
  164832. break;
  164833. case 4:
  164834. if ((png_ptr->row_number & 3) != 2)
  164835. {
  164836. if (dsp_row != NULL && (png_ptr->row_number & 2))
  164837. png_combine_row(png_ptr, dsp_row,
  164838. png_pass_dsp_mask[png_ptr->pass]);
  164839. png_read_finish_row(png_ptr);
  164840. return;
  164841. }
  164842. break;
  164843. case 5:
  164844. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  164845. {
  164846. if (dsp_row != NULL)
  164847. png_combine_row(png_ptr, dsp_row,
  164848. png_pass_dsp_mask[png_ptr->pass]);
  164849. png_read_finish_row(png_ptr);
  164850. return;
  164851. }
  164852. break;
  164853. case 6:
  164854. if (!(png_ptr->row_number & 1))
  164855. {
  164856. png_read_finish_row(png_ptr);
  164857. return;
  164858. }
  164859. break;
  164860. }
  164861. }
  164862. #endif
  164863. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  164864. png_error(png_ptr, "Invalid attempt to read row data");
  164865. png_ptr->zstream.next_out = png_ptr->row_buf;
  164866. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  164867. do
  164868. {
  164869. if (!(png_ptr->zstream.avail_in))
  164870. {
  164871. while (!png_ptr->idat_size)
  164872. {
  164873. png_byte chunk_length[4];
  164874. png_crc_finish(png_ptr, 0);
  164875. png_read_data(png_ptr, chunk_length, 4);
  164876. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  164877. png_reset_crc(png_ptr);
  164878. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164879. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164880. png_error(png_ptr, "Not enough image data");
  164881. }
  164882. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  164883. png_ptr->zstream.next_in = png_ptr->zbuf;
  164884. if (png_ptr->zbuf_size > png_ptr->idat_size)
  164885. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  164886. png_crc_read(png_ptr, png_ptr->zbuf,
  164887. (png_size_t)png_ptr->zstream.avail_in);
  164888. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  164889. }
  164890. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  164891. if (ret == Z_STREAM_END)
  164892. {
  164893. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  164894. png_ptr->idat_size)
  164895. png_error(png_ptr, "Extra compressed data");
  164896. png_ptr->mode |= PNG_AFTER_IDAT;
  164897. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  164898. break;
  164899. }
  164900. if (ret != Z_OK)
  164901. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  164902. "Decompression error");
  164903. } while (png_ptr->zstream.avail_out);
  164904. png_ptr->row_info.color_type = png_ptr->color_type;
  164905. png_ptr->row_info.width = png_ptr->iwidth;
  164906. png_ptr->row_info.channels = png_ptr->channels;
  164907. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  164908. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  164909. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  164910. png_ptr->row_info.width);
  164911. if(png_ptr->row_buf[0])
  164912. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  164913. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  164914. (int)(png_ptr->row_buf[0]));
  164915. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  164916. png_ptr->rowbytes + 1);
  164917. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  164918. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  164919. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  164920. {
  164921. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  164922. }
  164923. #endif
  164924. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  164925. png_do_read_transformations(png_ptr);
  164926. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164927. if (png_ptr->interlaced &&
  164928. (png_ptr->transformations & PNG_INTERLACE))
  164929. {
  164930. if (png_ptr->pass < 6)
  164931. png_do_read_interlace(png_ptr);
  164932. if (dsp_row != NULL)
  164933. png_combine_row(png_ptr, dsp_row,
  164934. png_pass_dsp_mask[png_ptr->pass]);
  164935. if (row != NULL)
  164936. png_combine_row(png_ptr, row,
  164937. png_pass_mask[png_ptr->pass]);
  164938. }
  164939. else
  164940. #endif
  164941. {
  164942. if (row != NULL)
  164943. png_combine_row(png_ptr, row, 0xff);
  164944. if (dsp_row != NULL)
  164945. png_combine_row(png_ptr, dsp_row, 0xff);
  164946. }
  164947. png_read_finish_row(png_ptr);
  164948. if (png_ptr->read_row_fn != NULL)
  164949. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  164950. }
  164951. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164952. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164953. void PNGAPI
  164954. png_read_rows(png_structp png_ptr, png_bytepp row,
  164955. png_bytepp display_row, png_uint_32 num_rows)
  164956. {
  164957. png_uint_32 i;
  164958. png_bytepp rp;
  164959. png_bytepp dp;
  164960. png_debug(1, "in png_read_rows\n");
  164961. if(png_ptr == NULL) return;
  164962. rp = row;
  164963. dp = display_row;
  164964. if (rp != NULL && dp != NULL)
  164965. for (i = 0; i < num_rows; i++)
  164966. {
  164967. png_bytep rptr = *rp++;
  164968. png_bytep dptr = *dp++;
  164969. png_read_row(png_ptr, rptr, dptr);
  164970. }
  164971. else if(rp != NULL)
  164972. for (i = 0; i < num_rows; i++)
  164973. {
  164974. png_bytep rptr = *rp;
  164975. png_read_row(png_ptr, rptr, png_bytep_NULL);
  164976. rp++;
  164977. }
  164978. else if(dp != NULL)
  164979. for (i = 0; i < num_rows; i++)
  164980. {
  164981. png_bytep dptr = *dp;
  164982. png_read_row(png_ptr, png_bytep_NULL, dptr);
  164983. dp++;
  164984. }
  164985. }
  164986. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164987. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164988. void PNGAPI
  164989. png_read_image(png_structp png_ptr, png_bytepp image)
  164990. {
  164991. png_uint_32 i,image_height;
  164992. int pass, j;
  164993. png_bytepp rp;
  164994. png_debug(1, "in png_read_image\n");
  164995. if(png_ptr == NULL) return;
  164996. #ifdef PNG_READ_INTERLACING_SUPPORTED
  164997. pass = png_set_interlace_handling(png_ptr);
  164998. #else
  164999. if (png_ptr->interlaced)
  165000. png_error(png_ptr,
  165001. "Cannot read interlaced image -- interlace handler disabled.");
  165002. pass = 1;
  165003. #endif
  165004. image_height=png_ptr->height;
  165005. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  165006. for (j = 0; j < pass; j++)
  165007. {
  165008. rp = image;
  165009. for (i = 0; i < image_height; i++)
  165010. {
  165011. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165012. rp++;
  165013. }
  165014. }
  165015. }
  165016. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165017. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165018. void PNGAPI
  165019. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165020. {
  165021. png_byte chunk_length[4];
  165022. png_uint_32 length;
  165023. png_debug(1, "in png_read_end\n");
  165024. if(png_ptr == NULL) return;
  165025. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165026. do
  165027. {
  165028. #ifdef PNG_USE_LOCAL_ARRAYS
  165029. PNG_CONST PNG_IHDR;
  165030. PNG_CONST PNG_IDAT;
  165031. PNG_CONST PNG_IEND;
  165032. PNG_CONST PNG_PLTE;
  165033. #if defined(PNG_READ_bKGD_SUPPORTED)
  165034. PNG_CONST PNG_bKGD;
  165035. #endif
  165036. #if defined(PNG_READ_cHRM_SUPPORTED)
  165037. PNG_CONST PNG_cHRM;
  165038. #endif
  165039. #if defined(PNG_READ_gAMA_SUPPORTED)
  165040. PNG_CONST PNG_gAMA;
  165041. #endif
  165042. #if defined(PNG_READ_hIST_SUPPORTED)
  165043. PNG_CONST PNG_hIST;
  165044. #endif
  165045. #if defined(PNG_READ_iCCP_SUPPORTED)
  165046. PNG_CONST PNG_iCCP;
  165047. #endif
  165048. #if defined(PNG_READ_iTXt_SUPPORTED)
  165049. PNG_CONST PNG_iTXt;
  165050. #endif
  165051. #if defined(PNG_READ_oFFs_SUPPORTED)
  165052. PNG_CONST PNG_oFFs;
  165053. #endif
  165054. #if defined(PNG_READ_pCAL_SUPPORTED)
  165055. PNG_CONST PNG_pCAL;
  165056. #endif
  165057. #if defined(PNG_READ_pHYs_SUPPORTED)
  165058. PNG_CONST PNG_pHYs;
  165059. #endif
  165060. #if defined(PNG_READ_sBIT_SUPPORTED)
  165061. PNG_CONST PNG_sBIT;
  165062. #endif
  165063. #if defined(PNG_READ_sCAL_SUPPORTED)
  165064. PNG_CONST PNG_sCAL;
  165065. #endif
  165066. #if defined(PNG_READ_sPLT_SUPPORTED)
  165067. PNG_CONST PNG_sPLT;
  165068. #endif
  165069. #if defined(PNG_READ_sRGB_SUPPORTED)
  165070. PNG_CONST PNG_sRGB;
  165071. #endif
  165072. #if defined(PNG_READ_tEXt_SUPPORTED)
  165073. PNG_CONST PNG_tEXt;
  165074. #endif
  165075. #if defined(PNG_READ_tIME_SUPPORTED)
  165076. PNG_CONST PNG_tIME;
  165077. #endif
  165078. #if defined(PNG_READ_tRNS_SUPPORTED)
  165079. PNG_CONST PNG_tRNS;
  165080. #endif
  165081. #if defined(PNG_READ_zTXt_SUPPORTED)
  165082. PNG_CONST PNG_zTXt;
  165083. #endif
  165084. #endif /* PNG_USE_LOCAL_ARRAYS */
  165085. png_read_data(png_ptr, chunk_length, 4);
  165086. length = png_get_uint_31(png_ptr,chunk_length);
  165087. png_reset_crc(png_ptr);
  165088. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165089. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165090. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165091. png_handle_IHDR(png_ptr, info_ptr, length);
  165092. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165093. png_handle_IEND(png_ptr, info_ptr, length);
  165094. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165095. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165096. {
  165097. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165098. {
  165099. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165100. png_error(png_ptr, "Too many IDAT's found");
  165101. }
  165102. png_handle_unknown(png_ptr, info_ptr, length);
  165103. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165104. png_ptr->mode |= PNG_HAVE_PLTE;
  165105. }
  165106. #endif
  165107. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165108. {
  165109. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165110. png_error(png_ptr, "Too many IDAT's found");
  165111. png_crc_finish(png_ptr, length);
  165112. }
  165113. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165114. png_handle_PLTE(png_ptr, info_ptr, length);
  165115. #if defined(PNG_READ_bKGD_SUPPORTED)
  165116. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165117. png_handle_bKGD(png_ptr, info_ptr, length);
  165118. #endif
  165119. #if defined(PNG_READ_cHRM_SUPPORTED)
  165120. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165121. png_handle_cHRM(png_ptr, info_ptr, length);
  165122. #endif
  165123. #if defined(PNG_READ_gAMA_SUPPORTED)
  165124. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165125. png_handle_gAMA(png_ptr, info_ptr, length);
  165126. #endif
  165127. #if defined(PNG_READ_hIST_SUPPORTED)
  165128. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165129. png_handle_hIST(png_ptr, info_ptr, length);
  165130. #endif
  165131. #if defined(PNG_READ_oFFs_SUPPORTED)
  165132. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165133. png_handle_oFFs(png_ptr, info_ptr, length);
  165134. #endif
  165135. #if defined(PNG_READ_pCAL_SUPPORTED)
  165136. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165137. png_handle_pCAL(png_ptr, info_ptr, length);
  165138. #endif
  165139. #if defined(PNG_READ_sCAL_SUPPORTED)
  165140. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165141. png_handle_sCAL(png_ptr, info_ptr, length);
  165142. #endif
  165143. #if defined(PNG_READ_pHYs_SUPPORTED)
  165144. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165145. png_handle_pHYs(png_ptr, info_ptr, length);
  165146. #endif
  165147. #if defined(PNG_READ_sBIT_SUPPORTED)
  165148. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165149. png_handle_sBIT(png_ptr, info_ptr, length);
  165150. #endif
  165151. #if defined(PNG_READ_sRGB_SUPPORTED)
  165152. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165153. png_handle_sRGB(png_ptr, info_ptr, length);
  165154. #endif
  165155. #if defined(PNG_READ_iCCP_SUPPORTED)
  165156. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165157. png_handle_iCCP(png_ptr, info_ptr, length);
  165158. #endif
  165159. #if defined(PNG_READ_sPLT_SUPPORTED)
  165160. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165161. png_handle_sPLT(png_ptr, info_ptr, length);
  165162. #endif
  165163. #if defined(PNG_READ_tEXt_SUPPORTED)
  165164. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165165. png_handle_tEXt(png_ptr, info_ptr, length);
  165166. #endif
  165167. #if defined(PNG_READ_tIME_SUPPORTED)
  165168. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165169. png_handle_tIME(png_ptr, info_ptr, length);
  165170. #endif
  165171. #if defined(PNG_READ_tRNS_SUPPORTED)
  165172. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165173. png_handle_tRNS(png_ptr, info_ptr, length);
  165174. #endif
  165175. #if defined(PNG_READ_zTXt_SUPPORTED)
  165176. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165177. png_handle_zTXt(png_ptr, info_ptr, length);
  165178. #endif
  165179. #if defined(PNG_READ_iTXt_SUPPORTED)
  165180. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165181. png_handle_iTXt(png_ptr, info_ptr, length);
  165182. #endif
  165183. else
  165184. png_handle_unknown(png_ptr, info_ptr, length);
  165185. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165186. }
  165187. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165188. void PNGAPI
  165189. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165190. png_infopp end_info_ptr_ptr)
  165191. {
  165192. png_structp png_ptr = NULL;
  165193. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165194. #ifdef PNG_USER_MEM_SUPPORTED
  165195. png_free_ptr free_fn;
  165196. png_voidp mem_ptr;
  165197. #endif
  165198. png_debug(1, "in png_destroy_read_struct\n");
  165199. if (png_ptr_ptr != NULL)
  165200. png_ptr = *png_ptr_ptr;
  165201. if (info_ptr_ptr != NULL)
  165202. info_ptr = *info_ptr_ptr;
  165203. if (end_info_ptr_ptr != NULL)
  165204. end_info_ptr = *end_info_ptr_ptr;
  165205. #ifdef PNG_USER_MEM_SUPPORTED
  165206. free_fn = png_ptr->free_fn;
  165207. mem_ptr = png_ptr->mem_ptr;
  165208. #endif
  165209. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165210. if (info_ptr != NULL)
  165211. {
  165212. #if defined(PNG_TEXT_SUPPORTED)
  165213. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165214. #endif
  165215. #ifdef PNG_USER_MEM_SUPPORTED
  165216. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165217. (png_voidp)mem_ptr);
  165218. #else
  165219. png_destroy_struct((png_voidp)info_ptr);
  165220. #endif
  165221. *info_ptr_ptr = NULL;
  165222. }
  165223. if (end_info_ptr != NULL)
  165224. {
  165225. #if defined(PNG_READ_TEXT_SUPPORTED)
  165226. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165227. #endif
  165228. #ifdef PNG_USER_MEM_SUPPORTED
  165229. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165230. (png_voidp)mem_ptr);
  165231. #else
  165232. png_destroy_struct((png_voidp)end_info_ptr);
  165233. #endif
  165234. *end_info_ptr_ptr = NULL;
  165235. }
  165236. if (png_ptr != NULL)
  165237. {
  165238. #ifdef PNG_USER_MEM_SUPPORTED
  165239. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165240. (png_voidp)mem_ptr);
  165241. #else
  165242. png_destroy_struct((png_voidp)png_ptr);
  165243. #endif
  165244. *png_ptr_ptr = NULL;
  165245. }
  165246. }
  165247. void /* PRIVATE */
  165248. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165249. {
  165250. #ifdef PNG_SETJMP_SUPPORTED
  165251. jmp_buf tmp_jmp;
  165252. #endif
  165253. png_error_ptr error_fn;
  165254. png_error_ptr warning_fn;
  165255. png_voidp error_ptr;
  165256. #ifdef PNG_USER_MEM_SUPPORTED
  165257. png_free_ptr free_fn;
  165258. #endif
  165259. png_debug(1, "in png_read_destroy\n");
  165260. if (info_ptr != NULL)
  165261. png_info_destroy(png_ptr, info_ptr);
  165262. if (end_info_ptr != NULL)
  165263. png_info_destroy(png_ptr, end_info_ptr);
  165264. png_free(png_ptr, png_ptr->zbuf);
  165265. png_free(png_ptr, png_ptr->big_row_buf);
  165266. png_free(png_ptr, png_ptr->prev_row);
  165267. #if defined(PNG_READ_DITHER_SUPPORTED)
  165268. png_free(png_ptr, png_ptr->palette_lookup);
  165269. png_free(png_ptr, png_ptr->dither_index);
  165270. #endif
  165271. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165272. png_free(png_ptr, png_ptr->gamma_table);
  165273. #endif
  165274. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165275. png_free(png_ptr, png_ptr->gamma_from_1);
  165276. png_free(png_ptr, png_ptr->gamma_to_1);
  165277. #endif
  165278. #ifdef PNG_FREE_ME_SUPPORTED
  165279. if (png_ptr->free_me & PNG_FREE_PLTE)
  165280. png_zfree(png_ptr, png_ptr->palette);
  165281. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165282. #else
  165283. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165284. png_zfree(png_ptr, png_ptr->palette);
  165285. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165286. #endif
  165287. #if defined(PNG_tRNS_SUPPORTED) || \
  165288. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165289. #ifdef PNG_FREE_ME_SUPPORTED
  165290. if (png_ptr->free_me & PNG_FREE_TRNS)
  165291. png_free(png_ptr, png_ptr->trans);
  165292. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165293. #else
  165294. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165295. png_free(png_ptr, png_ptr->trans);
  165296. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165297. #endif
  165298. #endif
  165299. #if defined(PNG_READ_hIST_SUPPORTED)
  165300. #ifdef PNG_FREE_ME_SUPPORTED
  165301. if (png_ptr->free_me & PNG_FREE_HIST)
  165302. png_free(png_ptr, png_ptr->hist);
  165303. png_ptr->free_me &= ~PNG_FREE_HIST;
  165304. #else
  165305. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165306. png_free(png_ptr, png_ptr->hist);
  165307. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165308. #endif
  165309. #endif
  165310. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165311. if (png_ptr->gamma_16_table != NULL)
  165312. {
  165313. int i;
  165314. int istop = (1 << (8 - png_ptr->gamma_shift));
  165315. for (i = 0; i < istop; i++)
  165316. {
  165317. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165318. }
  165319. png_free(png_ptr, png_ptr->gamma_16_table);
  165320. }
  165321. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165322. if (png_ptr->gamma_16_from_1 != NULL)
  165323. {
  165324. int i;
  165325. int istop = (1 << (8 - png_ptr->gamma_shift));
  165326. for (i = 0; i < istop; i++)
  165327. {
  165328. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165329. }
  165330. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165331. }
  165332. if (png_ptr->gamma_16_to_1 != NULL)
  165333. {
  165334. int i;
  165335. int istop = (1 << (8 - png_ptr->gamma_shift));
  165336. for (i = 0; i < istop; i++)
  165337. {
  165338. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165339. }
  165340. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165341. }
  165342. #endif
  165343. #endif
  165344. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165345. png_free(png_ptr, png_ptr->time_buffer);
  165346. #endif
  165347. inflateEnd(&png_ptr->zstream);
  165348. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165349. png_free(png_ptr, png_ptr->save_buffer);
  165350. #endif
  165351. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165352. #ifdef PNG_TEXT_SUPPORTED
  165353. png_free(png_ptr, png_ptr->current_text);
  165354. #endif /* PNG_TEXT_SUPPORTED */
  165355. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165356. #ifdef PNG_SETJMP_SUPPORTED
  165357. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165358. #endif
  165359. error_fn = png_ptr->error_fn;
  165360. warning_fn = png_ptr->warning_fn;
  165361. error_ptr = png_ptr->error_ptr;
  165362. #ifdef PNG_USER_MEM_SUPPORTED
  165363. free_fn = png_ptr->free_fn;
  165364. #endif
  165365. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165366. png_ptr->error_fn = error_fn;
  165367. png_ptr->warning_fn = warning_fn;
  165368. png_ptr->error_ptr = error_ptr;
  165369. #ifdef PNG_USER_MEM_SUPPORTED
  165370. png_ptr->free_fn = free_fn;
  165371. #endif
  165372. #ifdef PNG_SETJMP_SUPPORTED
  165373. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165374. #endif
  165375. }
  165376. void PNGAPI
  165377. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165378. {
  165379. if(png_ptr == NULL) return;
  165380. png_ptr->read_row_fn = read_row_fn;
  165381. }
  165382. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165383. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165384. void PNGAPI
  165385. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165386. int transforms,
  165387. voidp params)
  165388. {
  165389. int row;
  165390. if(png_ptr == NULL) return;
  165391. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165392. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165393. png_set_invert_alpha(png_ptr);
  165394. #endif
  165395. png_read_info(png_ptr, info_ptr);
  165396. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165397. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165398. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165399. if (transforms & PNG_TRANSFORM_STRIP_16)
  165400. png_set_strip_16(png_ptr);
  165401. #endif
  165402. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165403. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165404. png_set_strip_alpha(png_ptr);
  165405. #endif
  165406. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165407. if (transforms & PNG_TRANSFORM_PACKING)
  165408. png_set_packing(png_ptr);
  165409. #endif
  165410. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165411. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165412. png_set_packswap(png_ptr);
  165413. #endif
  165414. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165415. if (transforms & PNG_TRANSFORM_EXPAND)
  165416. if ((png_ptr->bit_depth < 8) ||
  165417. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165418. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165419. png_set_expand(png_ptr);
  165420. #endif
  165421. #if defined(PNG_READ_INVERT_SUPPORTED)
  165422. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165423. png_set_invert_mono(png_ptr);
  165424. #endif
  165425. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165426. if ((transforms & PNG_TRANSFORM_SHIFT)
  165427. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165428. {
  165429. png_color_8p sig_bit;
  165430. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165431. png_set_shift(png_ptr, sig_bit);
  165432. }
  165433. #endif
  165434. #if defined(PNG_READ_BGR_SUPPORTED)
  165435. if (transforms & PNG_TRANSFORM_BGR)
  165436. png_set_bgr(png_ptr);
  165437. #endif
  165438. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165439. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165440. png_set_swap_alpha(png_ptr);
  165441. #endif
  165442. #if defined(PNG_READ_SWAP_SUPPORTED)
  165443. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165444. png_set_swap(png_ptr);
  165445. #endif
  165446. png_read_update_info(png_ptr, info_ptr);
  165447. #ifdef PNG_FREE_ME_SUPPORTED
  165448. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165449. #endif
  165450. if(info_ptr->row_pointers == NULL)
  165451. {
  165452. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165453. info_ptr->height * png_sizeof(png_bytep));
  165454. #ifdef PNG_FREE_ME_SUPPORTED
  165455. info_ptr->free_me |= PNG_FREE_ROWS;
  165456. #endif
  165457. for (row = 0; row < (int)info_ptr->height; row++)
  165458. {
  165459. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165460. png_get_rowbytes(png_ptr, info_ptr));
  165461. }
  165462. }
  165463. png_read_image(png_ptr, info_ptr->row_pointers);
  165464. info_ptr->valid |= PNG_INFO_IDAT;
  165465. png_read_end(png_ptr, info_ptr);
  165466. transforms = transforms; /* quiet compiler warnings */
  165467. params = params;
  165468. }
  165469. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165470. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165471. #endif /* PNG_READ_SUPPORTED */
  165472. /*** End of inlined file: pngread.c ***/
  165473. /*** Start of inlined file: pngpread.c ***/
  165474. #define PNG_INTERNAL
  165475. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165476. #define PNG_READ_SIG_MODE 0
  165477. #define PNG_READ_CHUNK_MODE 1
  165478. #define PNG_READ_IDAT_MODE 2
  165479. #define PNG_SKIP_MODE 3
  165480. #define PNG_READ_tEXt_MODE 4
  165481. #define PNG_READ_zTXt_MODE 5
  165482. #define PNG_READ_DONE_MODE 6
  165483. #define PNG_READ_iTXt_MODE 7
  165484. #define PNG_ERROR_MODE 8
  165485. void PNGAPI
  165486. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165487. png_bytep buffer, png_size_t buffer_size)
  165488. {
  165489. if(png_ptr == NULL) return;
  165490. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165491. while (png_ptr->buffer_size)
  165492. {
  165493. png_process_some_data(png_ptr, info_ptr);
  165494. }
  165495. }
  165496. void /* PRIVATE */
  165497. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165498. {
  165499. if(png_ptr == NULL) return;
  165500. switch (png_ptr->process_mode)
  165501. {
  165502. case PNG_READ_SIG_MODE:
  165503. {
  165504. png_push_read_sig(png_ptr, info_ptr);
  165505. break;
  165506. }
  165507. case PNG_READ_CHUNK_MODE:
  165508. {
  165509. png_push_read_chunk(png_ptr, info_ptr);
  165510. break;
  165511. }
  165512. case PNG_READ_IDAT_MODE:
  165513. {
  165514. png_push_read_IDAT(png_ptr);
  165515. break;
  165516. }
  165517. #if defined(PNG_READ_tEXt_SUPPORTED)
  165518. case PNG_READ_tEXt_MODE:
  165519. {
  165520. png_push_read_tEXt(png_ptr, info_ptr);
  165521. break;
  165522. }
  165523. #endif
  165524. #if defined(PNG_READ_zTXt_SUPPORTED)
  165525. case PNG_READ_zTXt_MODE:
  165526. {
  165527. png_push_read_zTXt(png_ptr, info_ptr);
  165528. break;
  165529. }
  165530. #endif
  165531. #if defined(PNG_READ_iTXt_SUPPORTED)
  165532. case PNG_READ_iTXt_MODE:
  165533. {
  165534. png_push_read_iTXt(png_ptr, info_ptr);
  165535. break;
  165536. }
  165537. #endif
  165538. case PNG_SKIP_MODE:
  165539. {
  165540. png_push_crc_finish(png_ptr);
  165541. break;
  165542. }
  165543. default:
  165544. {
  165545. png_ptr->buffer_size = 0;
  165546. break;
  165547. }
  165548. }
  165549. }
  165550. void /* PRIVATE */
  165551. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  165552. {
  165553. png_size_t num_checked = png_ptr->sig_bytes,
  165554. num_to_check = 8 - num_checked;
  165555. if (png_ptr->buffer_size < num_to_check)
  165556. {
  165557. num_to_check = png_ptr->buffer_size;
  165558. }
  165559. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  165560. num_to_check);
  165561. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  165562. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165563. {
  165564. if (num_checked < 4 &&
  165565. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165566. png_error(png_ptr, "Not a PNG file");
  165567. else
  165568. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165569. }
  165570. else
  165571. {
  165572. if (png_ptr->sig_bytes >= 8)
  165573. {
  165574. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165575. }
  165576. }
  165577. }
  165578. void /* PRIVATE */
  165579. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  165580. {
  165581. #ifdef PNG_USE_LOCAL_ARRAYS
  165582. PNG_CONST PNG_IHDR;
  165583. PNG_CONST PNG_IDAT;
  165584. PNG_CONST PNG_IEND;
  165585. PNG_CONST PNG_PLTE;
  165586. #if defined(PNG_READ_bKGD_SUPPORTED)
  165587. PNG_CONST PNG_bKGD;
  165588. #endif
  165589. #if defined(PNG_READ_cHRM_SUPPORTED)
  165590. PNG_CONST PNG_cHRM;
  165591. #endif
  165592. #if defined(PNG_READ_gAMA_SUPPORTED)
  165593. PNG_CONST PNG_gAMA;
  165594. #endif
  165595. #if defined(PNG_READ_hIST_SUPPORTED)
  165596. PNG_CONST PNG_hIST;
  165597. #endif
  165598. #if defined(PNG_READ_iCCP_SUPPORTED)
  165599. PNG_CONST PNG_iCCP;
  165600. #endif
  165601. #if defined(PNG_READ_iTXt_SUPPORTED)
  165602. PNG_CONST PNG_iTXt;
  165603. #endif
  165604. #if defined(PNG_READ_oFFs_SUPPORTED)
  165605. PNG_CONST PNG_oFFs;
  165606. #endif
  165607. #if defined(PNG_READ_pCAL_SUPPORTED)
  165608. PNG_CONST PNG_pCAL;
  165609. #endif
  165610. #if defined(PNG_READ_pHYs_SUPPORTED)
  165611. PNG_CONST PNG_pHYs;
  165612. #endif
  165613. #if defined(PNG_READ_sBIT_SUPPORTED)
  165614. PNG_CONST PNG_sBIT;
  165615. #endif
  165616. #if defined(PNG_READ_sCAL_SUPPORTED)
  165617. PNG_CONST PNG_sCAL;
  165618. #endif
  165619. #if defined(PNG_READ_sRGB_SUPPORTED)
  165620. PNG_CONST PNG_sRGB;
  165621. #endif
  165622. #if defined(PNG_READ_sPLT_SUPPORTED)
  165623. PNG_CONST PNG_sPLT;
  165624. #endif
  165625. #if defined(PNG_READ_tEXt_SUPPORTED)
  165626. PNG_CONST PNG_tEXt;
  165627. #endif
  165628. #if defined(PNG_READ_tIME_SUPPORTED)
  165629. PNG_CONST PNG_tIME;
  165630. #endif
  165631. #if defined(PNG_READ_tRNS_SUPPORTED)
  165632. PNG_CONST PNG_tRNS;
  165633. #endif
  165634. #if defined(PNG_READ_zTXt_SUPPORTED)
  165635. PNG_CONST PNG_zTXt;
  165636. #endif
  165637. #endif /* PNG_USE_LOCAL_ARRAYS */
  165638. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165639. {
  165640. png_byte chunk_length[4];
  165641. if (png_ptr->buffer_size < 8)
  165642. {
  165643. png_push_save_buffer(png_ptr);
  165644. return;
  165645. }
  165646. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165647. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165648. png_reset_crc(png_ptr);
  165649. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165650. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165651. }
  165652. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165653. if(png_ptr->mode & PNG_AFTER_IDAT)
  165654. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165655. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165656. {
  165657. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165658. {
  165659. png_push_save_buffer(png_ptr);
  165660. return;
  165661. }
  165662. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  165663. }
  165664. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165665. {
  165666. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165667. {
  165668. png_push_save_buffer(png_ptr);
  165669. return;
  165670. }
  165671. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  165672. png_ptr->process_mode = PNG_READ_DONE_MODE;
  165673. png_push_have_end(png_ptr, info_ptr);
  165674. }
  165675. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165676. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165677. {
  165678. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165679. {
  165680. png_push_save_buffer(png_ptr);
  165681. return;
  165682. }
  165683. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165684. png_ptr->mode |= PNG_HAVE_IDAT;
  165685. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165686. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165687. png_ptr->mode |= PNG_HAVE_PLTE;
  165688. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165689. {
  165690. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165691. png_error(png_ptr, "Missing IHDR before IDAT");
  165692. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165693. !(png_ptr->mode & PNG_HAVE_PLTE))
  165694. png_error(png_ptr, "Missing PLTE before IDAT");
  165695. }
  165696. }
  165697. #endif
  165698. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165699. {
  165700. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165701. {
  165702. png_push_save_buffer(png_ptr);
  165703. return;
  165704. }
  165705. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  165706. }
  165707. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165708. {
  165709. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165710. png_error(png_ptr, "Missing IHDR before IDAT");
  165711. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165712. !(png_ptr->mode & PNG_HAVE_PLTE))
  165713. png_error(png_ptr, "Missing PLTE before IDAT");
  165714. if (png_ptr->mode & PNG_HAVE_IDAT)
  165715. {
  165716. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165717. if (png_ptr->push_length == 0)
  165718. return;
  165719. if (png_ptr->mode & PNG_AFTER_IDAT)
  165720. png_error(png_ptr, "Too many IDAT's found");
  165721. }
  165722. png_ptr->idat_size = png_ptr->push_length;
  165723. png_ptr->mode |= PNG_HAVE_IDAT;
  165724. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  165725. png_push_have_info(png_ptr, info_ptr);
  165726. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165727. png_ptr->zstream.next_out = png_ptr->row_buf;
  165728. return;
  165729. }
  165730. #if defined(PNG_READ_gAMA_SUPPORTED)
  165731. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165732. {
  165733. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165734. {
  165735. png_push_save_buffer(png_ptr);
  165736. return;
  165737. }
  165738. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  165739. }
  165740. #endif
  165741. #if defined(PNG_READ_sBIT_SUPPORTED)
  165742. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165743. {
  165744. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165745. {
  165746. png_push_save_buffer(png_ptr);
  165747. return;
  165748. }
  165749. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  165750. }
  165751. #endif
  165752. #if defined(PNG_READ_cHRM_SUPPORTED)
  165753. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165754. {
  165755. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165756. {
  165757. png_push_save_buffer(png_ptr);
  165758. return;
  165759. }
  165760. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  165761. }
  165762. #endif
  165763. #if defined(PNG_READ_sRGB_SUPPORTED)
  165764. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165765. {
  165766. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165767. {
  165768. png_push_save_buffer(png_ptr);
  165769. return;
  165770. }
  165771. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  165772. }
  165773. #endif
  165774. #if defined(PNG_READ_iCCP_SUPPORTED)
  165775. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165776. {
  165777. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165778. {
  165779. png_push_save_buffer(png_ptr);
  165780. return;
  165781. }
  165782. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  165783. }
  165784. #endif
  165785. #if defined(PNG_READ_sPLT_SUPPORTED)
  165786. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165787. {
  165788. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165789. {
  165790. png_push_save_buffer(png_ptr);
  165791. return;
  165792. }
  165793. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  165794. }
  165795. #endif
  165796. #if defined(PNG_READ_tRNS_SUPPORTED)
  165797. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165798. {
  165799. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165800. {
  165801. png_push_save_buffer(png_ptr);
  165802. return;
  165803. }
  165804. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  165805. }
  165806. #endif
  165807. #if defined(PNG_READ_bKGD_SUPPORTED)
  165808. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165809. {
  165810. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165811. {
  165812. png_push_save_buffer(png_ptr);
  165813. return;
  165814. }
  165815. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  165816. }
  165817. #endif
  165818. #if defined(PNG_READ_hIST_SUPPORTED)
  165819. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165820. {
  165821. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165822. {
  165823. png_push_save_buffer(png_ptr);
  165824. return;
  165825. }
  165826. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  165827. }
  165828. #endif
  165829. #if defined(PNG_READ_pHYs_SUPPORTED)
  165830. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165831. {
  165832. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165833. {
  165834. png_push_save_buffer(png_ptr);
  165835. return;
  165836. }
  165837. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  165838. }
  165839. #endif
  165840. #if defined(PNG_READ_oFFs_SUPPORTED)
  165841. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165842. {
  165843. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165844. {
  165845. png_push_save_buffer(png_ptr);
  165846. return;
  165847. }
  165848. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  165849. }
  165850. #endif
  165851. #if defined(PNG_READ_pCAL_SUPPORTED)
  165852. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165853. {
  165854. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165855. {
  165856. png_push_save_buffer(png_ptr);
  165857. return;
  165858. }
  165859. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  165860. }
  165861. #endif
  165862. #if defined(PNG_READ_sCAL_SUPPORTED)
  165863. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165864. {
  165865. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165866. {
  165867. png_push_save_buffer(png_ptr);
  165868. return;
  165869. }
  165870. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  165871. }
  165872. #endif
  165873. #if defined(PNG_READ_tIME_SUPPORTED)
  165874. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165875. {
  165876. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165877. {
  165878. png_push_save_buffer(png_ptr);
  165879. return;
  165880. }
  165881. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  165882. }
  165883. #endif
  165884. #if defined(PNG_READ_tEXt_SUPPORTED)
  165885. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165886. {
  165887. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165888. {
  165889. png_push_save_buffer(png_ptr);
  165890. return;
  165891. }
  165892. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  165893. }
  165894. #endif
  165895. #if defined(PNG_READ_zTXt_SUPPORTED)
  165896. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165897. {
  165898. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165899. {
  165900. png_push_save_buffer(png_ptr);
  165901. return;
  165902. }
  165903. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  165904. }
  165905. #endif
  165906. #if defined(PNG_READ_iTXt_SUPPORTED)
  165907. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165908. {
  165909. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165910. {
  165911. png_push_save_buffer(png_ptr);
  165912. return;
  165913. }
  165914. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  165915. }
  165916. #endif
  165917. else
  165918. {
  165919. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165920. {
  165921. png_push_save_buffer(png_ptr);
  165922. return;
  165923. }
  165924. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165925. }
  165926. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  165927. }
  165928. void /* PRIVATE */
  165929. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  165930. {
  165931. png_ptr->process_mode = PNG_SKIP_MODE;
  165932. png_ptr->skip_length = skip;
  165933. }
  165934. void /* PRIVATE */
  165935. png_push_crc_finish(png_structp png_ptr)
  165936. {
  165937. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  165938. {
  165939. png_size_t save_size;
  165940. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  165941. save_size = (png_size_t)png_ptr->skip_length;
  165942. else
  165943. save_size = png_ptr->save_buffer_size;
  165944. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  165945. png_ptr->skip_length -= save_size;
  165946. png_ptr->buffer_size -= save_size;
  165947. png_ptr->save_buffer_size -= save_size;
  165948. png_ptr->save_buffer_ptr += save_size;
  165949. }
  165950. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  165951. {
  165952. png_size_t save_size;
  165953. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  165954. save_size = (png_size_t)png_ptr->skip_length;
  165955. else
  165956. save_size = png_ptr->current_buffer_size;
  165957. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  165958. png_ptr->skip_length -= save_size;
  165959. png_ptr->buffer_size -= save_size;
  165960. png_ptr->current_buffer_size -= save_size;
  165961. png_ptr->current_buffer_ptr += save_size;
  165962. }
  165963. if (!png_ptr->skip_length)
  165964. {
  165965. if (png_ptr->buffer_size < 4)
  165966. {
  165967. png_push_save_buffer(png_ptr);
  165968. return;
  165969. }
  165970. png_crc_finish(png_ptr, 0);
  165971. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165972. }
  165973. }
  165974. void PNGAPI
  165975. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  165976. {
  165977. png_bytep ptr;
  165978. if(png_ptr == NULL) return;
  165979. ptr = buffer;
  165980. if (png_ptr->save_buffer_size)
  165981. {
  165982. png_size_t save_size;
  165983. if (length < png_ptr->save_buffer_size)
  165984. save_size = length;
  165985. else
  165986. save_size = png_ptr->save_buffer_size;
  165987. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  165988. length -= save_size;
  165989. ptr += save_size;
  165990. png_ptr->buffer_size -= save_size;
  165991. png_ptr->save_buffer_size -= save_size;
  165992. png_ptr->save_buffer_ptr += save_size;
  165993. }
  165994. if (length && png_ptr->current_buffer_size)
  165995. {
  165996. png_size_t save_size;
  165997. if (length < png_ptr->current_buffer_size)
  165998. save_size = length;
  165999. else
  166000. save_size = png_ptr->current_buffer_size;
  166001. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  166002. png_ptr->buffer_size -= save_size;
  166003. png_ptr->current_buffer_size -= save_size;
  166004. png_ptr->current_buffer_ptr += save_size;
  166005. }
  166006. }
  166007. void /* PRIVATE */
  166008. png_push_save_buffer(png_structp png_ptr)
  166009. {
  166010. if (png_ptr->save_buffer_size)
  166011. {
  166012. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166013. {
  166014. png_size_t i,istop;
  166015. png_bytep sp;
  166016. png_bytep dp;
  166017. istop = png_ptr->save_buffer_size;
  166018. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166019. i < istop; i++, sp++, dp++)
  166020. {
  166021. *dp = *sp;
  166022. }
  166023. }
  166024. }
  166025. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166026. png_ptr->save_buffer_max)
  166027. {
  166028. png_size_t new_max;
  166029. png_bytep old_buffer;
  166030. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166031. (png_ptr->current_buffer_size + 256))
  166032. {
  166033. png_error(png_ptr, "Potential overflow of save_buffer");
  166034. }
  166035. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166036. old_buffer = png_ptr->save_buffer;
  166037. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166038. (png_uint_32)new_max);
  166039. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166040. png_free(png_ptr, old_buffer);
  166041. png_ptr->save_buffer_max = new_max;
  166042. }
  166043. if (png_ptr->current_buffer_size)
  166044. {
  166045. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166046. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166047. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166048. png_ptr->current_buffer_size = 0;
  166049. }
  166050. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166051. png_ptr->buffer_size = 0;
  166052. }
  166053. void /* PRIVATE */
  166054. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166055. png_size_t buffer_length)
  166056. {
  166057. png_ptr->current_buffer = buffer;
  166058. png_ptr->current_buffer_size = buffer_length;
  166059. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166060. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166061. }
  166062. void /* PRIVATE */
  166063. png_push_read_IDAT(png_structp png_ptr)
  166064. {
  166065. #ifdef PNG_USE_LOCAL_ARRAYS
  166066. PNG_CONST PNG_IDAT;
  166067. #endif
  166068. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166069. {
  166070. png_byte chunk_length[4];
  166071. if (png_ptr->buffer_size < 8)
  166072. {
  166073. png_push_save_buffer(png_ptr);
  166074. return;
  166075. }
  166076. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166077. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166078. png_reset_crc(png_ptr);
  166079. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166080. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166081. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166082. {
  166083. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166084. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166085. png_error(png_ptr, "Not enough compressed data");
  166086. return;
  166087. }
  166088. png_ptr->idat_size = png_ptr->push_length;
  166089. }
  166090. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166091. {
  166092. png_size_t save_size;
  166093. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166094. {
  166095. save_size = (png_size_t)png_ptr->idat_size;
  166096. if((png_uint_32)save_size != png_ptr->idat_size)
  166097. png_error(png_ptr, "save_size overflowed in pngpread");
  166098. }
  166099. else
  166100. save_size = png_ptr->save_buffer_size;
  166101. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166102. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166103. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166104. png_ptr->idat_size -= save_size;
  166105. png_ptr->buffer_size -= save_size;
  166106. png_ptr->save_buffer_size -= save_size;
  166107. png_ptr->save_buffer_ptr += save_size;
  166108. }
  166109. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166110. {
  166111. png_size_t save_size;
  166112. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166113. {
  166114. save_size = (png_size_t)png_ptr->idat_size;
  166115. if((png_uint_32)save_size != png_ptr->idat_size)
  166116. png_error(png_ptr, "save_size overflowed in pngpread");
  166117. }
  166118. else
  166119. save_size = png_ptr->current_buffer_size;
  166120. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166121. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166122. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166123. png_ptr->idat_size -= save_size;
  166124. png_ptr->buffer_size -= save_size;
  166125. png_ptr->current_buffer_size -= save_size;
  166126. png_ptr->current_buffer_ptr += save_size;
  166127. }
  166128. if (!png_ptr->idat_size)
  166129. {
  166130. if (png_ptr->buffer_size < 4)
  166131. {
  166132. png_push_save_buffer(png_ptr);
  166133. return;
  166134. }
  166135. png_crc_finish(png_ptr, 0);
  166136. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166137. png_ptr->mode |= PNG_AFTER_IDAT;
  166138. }
  166139. }
  166140. void /* PRIVATE */
  166141. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166142. png_size_t buffer_length)
  166143. {
  166144. int ret;
  166145. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166146. png_error(png_ptr, "Extra compression data");
  166147. png_ptr->zstream.next_in = buffer;
  166148. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166149. for(;;)
  166150. {
  166151. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166152. if (ret != Z_OK)
  166153. {
  166154. if (ret == Z_STREAM_END)
  166155. {
  166156. if (png_ptr->zstream.avail_in)
  166157. png_error(png_ptr, "Extra compressed data");
  166158. if (!(png_ptr->zstream.avail_out))
  166159. {
  166160. png_push_process_row(png_ptr);
  166161. }
  166162. png_ptr->mode |= PNG_AFTER_IDAT;
  166163. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166164. break;
  166165. }
  166166. else if (ret == Z_BUF_ERROR)
  166167. break;
  166168. else
  166169. png_error(png_ptr, "Decompression Error");
  166170. }
  166171. if (!(png_ptr->zstream.avail_out))
  166172. {
  166173. if ((
  166174. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166175. png_ptr->interlaced && png_ptr->pass > 6) ||
  166176. (!png_ptr->interlaced &&
  166177. #endif
  166178. png_ptr->row_number == png_ptr->num_rows))
  166179. {
  166180. if (png_ptr->zstream.avail_in)
  166181. {
  166182. png_warning(png_ptr, "Too much data in IDAT chunks");
  166183. }
  166184. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166185. break;
  166186. }
  166187. png_push_process_row(png_ptr);
  166188. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166189. png_ptr->zstream.next_out = png_ptr->row_buf;
  166190. }
  166191. else
  166192. break;
  166193. }
  166194. }
  166195. void /* PRIVATE */
  166196. png_push_process_row(png_structp png_ptr)
  166197. {
  166198. png_ptr->row_info.color_type = png_ptr->color_type;
  166199. png_ptr->row_info.width = png_ptr->iwidth;
  166200. png_ptr->row_info.channels = png_ptr->channels;
  166201. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166202. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166203. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166204. png_ptr->row_info.width);
  166205. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166206. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166207. (int)(png_ptr->row_buf[0]));
  166208. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166209. png_ptr->rowbytes + 1);
  166210. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166211. png_do_read_transformations(png_ptr);
  166212. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166213. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166214. {
  166215. if (png_ptr->pass < 6)
  166216. png_do_read_interlace(png_ptr);
  166217. switch (png_ptr->pass)
  166218. {
  166219. case 0:
  166220. {
  166221. int i;
  166222. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166223. {
  166224. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166225. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166226. }
  166227. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166228. {
  166229. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166230. {
  166231. png_push_have_row(png_ptr, png_bytep_NULL);
  166232. png_read_push_finish_row(png_ptr);
  166233. }
  166234. }
  166235. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166236. {
  166237. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166238. {
  166239. png_push_have_row(png_ptr, png_bytep_NULL);
  166240. png_read_push_finish_row(png_ptr);
  166241. }
  166242. }
  166243. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166244. {
  166245. png_push_have_row(png_ptr, png_bytep_NULL);
  166246. png_read_push_finish_row(png_ptr);
  166247. }
  166248. break;
  166249. }
  166250. case 1:
  166251. {
  166252. int i;
  166253. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166254. {
  166255. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166256. png_read_push_finish_row(png_ptr);
  166257. }
  166258. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166259. {
  166260. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166261. {
  166262. png_push_have_row(png_ptr, png_bytep_NULL);
  166263. png_read_push_finish_row(png_ptr);
  166264. }
  166265. }
  166266. break;
  166267. }
  166268. case 2:
  166269. {
  166270. int i;
  166271. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166272. {
  166273. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166274. png_read_push_finish_row(png_ptr);
  166275. }
  166276. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166277. {
  166278. png_push_have_row(png_ptr, png_bytep_NULL);
  166279. png_read_push_finish_row(png_ptr);
  166280. }
  166281. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166282. {
  166283. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166284. {
  166285. png_push_have_row(png_ptr, png_bytep_NULL);
  166286. png_read_push_finish_row(png_ptr);
  166287. }
  166288. }
  166289. break;
  166290. }
  166291. case 3:
  166292. {
  166293. int i;
  166294. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166295. {
  166296. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166297. png_read_push_finish_row(png_ptr);
  166298. }
  166299. if (png_ptr->pass == 4) /* skip top two generated rows */
  166300. {
  166301. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166302. {
  166303. png_push_have_row(png_ptr, png_bytep_NULL);
  166304. png_read_push_finish_row(png_ptr);
  166305. }
  166306. }
  166307. break;
  166308. }
  166309. case 4:
  166310. {
  166311. int i;
  166312. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166313. {
  166314. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166315. png_read_push_finish_row(png_ptr);
  166316. }
  166317. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166318. {
  166319. png_push_have_row(png_ptr, png_bytep_NULL);
  166320. png_read_push_finish_row(png_ptr);
  166321. }
  166322. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166323. {
  166324. png_push_have_row(png_ptr, png_bytep_NULL);
  166325. png_read_push_finish_row(png_ptr);
  166326. }
  166327. break;
  166328. }
  166329. case 5:
  166330. {
  166331. int i;
  166332. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166333. {
  166334. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166335. png_read_push_finish_row(png_ptr);
  166336. }
  166337. if (png_ptr->pass == 6) /* skip top generated row */
  166338. {
  166339. png_push_have_row(png_ptr, png_bytep_NULL);
  166340. png_read_push_finish_row(png_ptr);
  166341. }
  166342. break;
  166343. }
  166344. case 6:
  166345. {
  166346. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166347. png_read_push_finish_row(png_ptr);
  166348. if (png_ptr->pass != 6)
  166349. break;
  166350. png_push_have_row(png_ptr, png_bytep_NULL);
  166351. png_read_push_finish_row(png_ptr);
  166352. }
  166353. }
  166354. }
  166355. else
  166356. #endif
  166357. {
  166358. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166359. png_read_push_finish_row(png_ptr);
  166360. }
  166361. }
  166362. void /* PRIVATE */
  166363. png_read_push_finish_row(png_structp png_ptr)
  166364. {
  166365. #ifdef PNG_USE_LOCAL_ARRAYS
  166366. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166367. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166368. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166369. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166370. #endif
  166371. png_ptr->row_number++;
  166372. if (png_ptr->row_number < png_ptr->num_rows)
  166373. return;
  166374. if (png_ptr->interlaced)
  166375. {
  166376. png_ptr->row_number = 0;
  166377. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166378. png_ptr->rowbytes + 1);
  166379. do
  166380. {
  166381. png_ptr->pass++;
  166382. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166383. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166384. (png_ptr->pass == 5 && png_ptr->width < 2))
  166385. png_ptr->pass++;
  166386. if (png_ptr->pass > 7)
  166387. png_ptr->pass--;
  166388. if (png_ptr->pass >= 7)
  166389. break;
  166390. png_ptr->iwidth = (png_ptr->width +
  166391. png_pass_inc[png_ptr->pass] - 1 -
  166392. png_pass_start[png_ptr->pass]) /
  166393. png_pass_inc[png_ptr->pass];
  166394. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166395. png_ptr->iwidth) + 1;
  166396. if (png_ptr->transformations & PNG_INTERLACE)
  166397. break;
  166398. png_ptr->num_rows = (png_ptr->height +
  166399. png_pass_yinc[png_ptr->pass] - 1 -
  166400. png_pass_ystart[png_ptr->pass]) /
  166401. png_pass_yinc[png_ptr->pass];
  166402. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166403. }
  166404. }
  166405. #if defined(PNG_READ_tEXt_SUPPORTED)
  166406. void /* PRIVATE */
  166407. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166408. length)
  166409. {
  166410. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166411. {
  166412. png_error(png_ptr, "Out of place tEXt");
  166413. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166414. }
  166415. #ifdef PNG_MAX_MALLOC_64K
  166416. png_ptr->skip_length = 0; /* This may not be necessary */
  166417. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166418. {
  166419. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166420. png_ptr->skip_length = length - (png_uint_32)65535L;
  166421. length = (png_uint_32)65535L;
  166422. }
  166423. #endif
  166424. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166425. (png_uint_32)(length+1));
  166426. png_ptr->current_text[length] = '\0';
  166427. png_ptr->current_text_ptr = png_ptr->current_text;
  166428. png_ptr->current_text_size = (png_size_t)length;
  166429. png_ptr->current_text_left = (png_size_t)length;
  166430. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166431. }
  166432. void /* PRIVATE */
  166433. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166434. {
  166435. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166436. {
  166437. png_size_t text_size;
  166438. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166439. text_size = png_ptr->buffer_size;
  166440. else
  166441. text_size = png_ptr->current_text_left;
  166442. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166443. png_ptr->current_text_left -= text_size;
  166444. png_ptr->current_text_ptr += text_size;
  166445. }
  166446. if (!(png_ptr->current_text_left))
  166447. {
  166448. png_textp text_ptr;
  166449. png_charp text;
  166450. png_charp key;
  166451. int ret;
  166452. if (png_ptr->buffer_size < 4)
  166453. {
  166454. png_push_save_buffer(png_ptr);
  166455. return;
  166456. }
  166457. png_push_crc_finish(png_ptr);
  166458. #if defined(PNG_MAX_MALLOC_64K)
  166459. if (png_ptr->skip_length)
  166460. return;
  166461. #endif
  166462. key = png_ptr->current_text;
  166463. for (text = key; *text; text++)
  166464. ;
  166465. if (text < key + png_ptr->current_text_size)
  166466. text++;
  166467. text_ptr = (png_textp)png_malloc(png_ptr,
  166468. (png_uint_32)png_sizeof(png_text));
  166469. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166470. text_ptr->key = key;
  166471. #ifdef PNG_iTXt_SUPPORTED
  166472. text_ptr->lang = NULL;
  166473. text_ptr->lang_key = NULL;
  166474. #endif
  166475. text_ptr->text = text;
  166476. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166477. png_free(png_ptr, key);
  166478. png_free(png_ptr, text_ptr);
  166479. png_ptr->current_text = NULL;
  166480. if (ret)
  166481. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166482. }
  166483. }
  166484. #endif
  166485. #if defined(PNG_READ_zTXt_SUPPORTED)
  166486. void /* PRIVATE */
  166487. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166488. length)
  166489. {
  166490. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166491. {
  166492. png_error(png_ptr, "Out of place zTXt");
  166493. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166494. }
  166495. #ifdef PNG_MAX_MALLOC_64K
  166496. if (length > (png_uint_32)65535L)
  166497. {
  166498. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166499. png_push_crc_skip(png_ptr, length);
  166500. return;
  166501. }
  166502. #endif
  166503. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166504. (png_uint_32)(length+1));
  166505. png_ptr->current_text[length] = '\0';
  166506. png_ptr->current_text_ptr = png_ptr->current_text;
  166507. png_ptr->current_text_size = (png_size_t)length;
  166508. png_ptr->current_text_left = (png_size_t)length;
  166509. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166510. }
  166511. void /* PRIVATE */
  166512. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166513. {
  166514. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166515. {
  166516. png_size_t text_size;
  166517. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166518. text_size = png_ptr->buffer_size;
  166519. else
  166520. text_size = png_ptr->current_text_left;
  166521. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166522. png_ptr->current_text_left -= text_size;
  166523. png_ptr->current_text_ptr += text_size;
  166524. }
  166525. if (!(png_ptr->current_text_left))
  166526. {
  166527. png_textp text_ptr;
  166528. png_charp text;
  166529. png_charp key;
  166530. int ret;
  166531. png_size_t text_size, key_size;
  166532. if (png_ptr->buffer_size < 4)
  166533. {
  166534. png_push_save_buffer(png_ptr);
  166535. return;
  166536. }
  166537. png_push_crc_finish(png_ptr);
  166538. key = png_ptr->current_text;
  166539. for (text = key; *text; text++)
  166540. ;
  166541. if (text >= key + png_ptr->current_text_size)
  166542. {
  166543. png_ptr->current_text = NULL;
  166544. png_free(png_ptr, key);
  166545. return;
  166546. }
  166547. text++;
  166548. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  166549. {
  166550. png_ptr->current_text = NULL;
  166551. png_free(png_ptr, key);
  166552. return;
  166553. }
  166554. text++;
  166555. png_ptr->zstream.next_in = (png_bytep )text;
  166556. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  166557. (text - key));
  166558. png_ptr->zstream.next_out = png_ptr->zbuf;
  166559. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166560. key_size = text - key;
  166561. text_size = 0;
  166562. text = NULL;
  166563. ret = Z_STREAM_END;
  166564. while (png_ptr->zstream.avail_in)
  166565. {
  166566. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166567. if (ret != Z_OK && ret != Z_STREAM_END)
  166568. {
  166569. inflateReset(&png_ptr->zstream);
  166570. png_ptr->zstream.avail_in = 0;
  166571. png_ptr->current_text = NULL;
  166572. png_free(png_ptr, key);
  166573. png_free(png_ptr, text);
  166574. return;
  166575. }
  166576. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  166577. {
  166578. if (text == NULL)
  166579. {
  166580. text = (png_charp)png_malloc(png_ptr,
  166581. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166582. + key_size + 1));
  166583. png_memcpy(text + key_size, png_ptr->zbuf,
  166584. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166585. png_memcpy(text, key, key_size);
  166586. text_size = key_size + png_ptr->zbuf_size -
  166587. png_ptr->zstream.avail_out;
  166588. *(text + text_size) = '\0';
  166589. }
  166590. else
  166591. {
  166592. png_charp tmp;
  166593. tmp = text;
  166594. text = (png_charp)png_malloc(png_ptr, text_size +
  166595. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166596. + 1));
  166597. png_memcpy(text, tmp, text_size);
  166598. png_free(png_ptr, tmp);
  166599. png_memcpy(text + text_size, png_ptr->zbuf,
  166600. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166601. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  166602. *(text + text_size) = '\0';
  166603. }
  166604. if (ret != Z_STREAM_END)
  166605. {
  166606. png_ptr->zstream.next_out = png_ptr->zbuf;
  166607. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166608. }
  166609. }
  166610. else
  166611. {
  166612. break;
  166613. }
  166614. if (ret == Z_STREAM_END)
  166615. break;
  166616. }
  166617. inflateReset(&png_ptr->zstream);
  166618. png_ptr->zstream.avail_in = 0;
  166619. if (ret != Z_STREAM_END)
  166620. {
  166621. png_ptr->current_text = NULL;
  166622. png_free(png_ptr, key);
  166623. png_free(png_ptr, text);
  166624. return;
  166625. }
  166626. png_ptr->current_text = NULL;
  166627. png_free(png_ptr, key);
  166628. key = text;
  166629. text += key_size;
  166630. text_ptr = (png_textp)png_malloc(png_ptr,
  166631. (png_uint_32)png_sizeof(png_text));
  166632. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  166633. text_ptr->key = key;
  166634. #ifdef PNG_iTXt_SUPPORTED
  166635. text_ptr->lang = NULL;
  166636. text_ptr->lang_key = NULL;
  166637. #endif
  166638. text_ptr->text = text;
  166639. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166640. png_free(png_ptr, key);
  166641. png_free(png_ptr, text_ptr);
  166642. if (ret)
  166643. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166644. }
  166645. }
  166646. #endif
  166647. #if defined(PNG_READ_iTXt_SUPPORTED)
  166648. void /* PRIVATE */
  166649. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166650. length)
  166651. {
  166652. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166653. {
  166654. png_error(png_ptr, "Out of place iTXt");
  166655. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166656. }
  166657. #ifdef PNG_MAX_MALLOC_64K
  166658. png_ptr->skip_length = 0; /* This may not be necessary */
  166659. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166660. {
  166661. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  166662. png_ptr->skip_length = length - (png_uint_32)65535L;
  166663. length = (png_uint_32)65535L;
  166664. }
  166665. #endif
  166666. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166667. (png_uint_32)(length+1));
  166668. png_ptr->current_text[length] = '\0';
  166669. png_ptr->current_text_ptr = png_ptr->current_text;
  166670. png_ptr->current_text_size = (png_size_t)length;
  166671. png_ptr->current_text_left = (png_size_t)length;
  166672. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  166673. }
  166674. void /* PRIVATE */
  166675. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  166676. {
  166677. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166678. {
  166679. png_size_t text_size;
  166680. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166681. text_size = png_ptr->buffer_size;
  166682. else
  166683. text_size = png_ptr->current_text_left;
  166684. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166685. png_ptr->current_text_left -= text_size;
  166686. png_ptr->current_text_ptr += text_size;
  166687. }
  166688. if (!(png_ptr->current_text_left))
  166689. {
  166690. png_textp text_ptr;
  166691. png_charp key;
  166692. int comp_flag;
  166693. png_charp lang;
  166694. png_charp lang_key;
  166695. png_charp text;
  166696. int ret;
  166697. if (png_ptr->buffer_size < 4)
  166698. {
  166699. png_push_save_buffer(png_ptr);
  166700. return;
  166701. }
  166702. png_push_crc_finish(png_ptr);
  166703. #if defined(PNG_MAX_MALLOC_64K)
  166704. if (png_ptr->skip_length)
  166705. return;
  166706. #endif
  166707. key = png_ptr->current_text;
  166708. for (lang = key; *lang; lang++)
  166709. ;
  166710. if (lang < key + png_ptr->current_text_size - 3)
  166711. lang++;
  166712. comp_flag = *lang++;
  166713. lang++; /* skip comp_type, always zero */
  166714. for (lang_key = lang; *lang_key; lang_key++)
  166715. ;
  166716. lang_key++; /* skip NUL separator */
  166717. text=lang_key;
  166718. if (lang_key < key + png_ptr->current_text_size - 1)
  166719. {
  166720. for (; *text; text++)
  166721. ;
  166722. }
  166723. if (text < key + png_ptr->current_text_size)
  166724. text++;
  166725. text_ptr = (png_textp)png_malloc(png_ptr,
  166726. (png_uint_32)png_sizeof(png_text));
  166727. text_ptr->compression = comp_flag + 2;
  166728. text_ptr->key = key;
  166729. text_ptr->lang = lang;
  166730. text_ptr->lang_key = lang_key;
  166731. text_ptr->text = text;
  166732. text_ptr->text_length = 0;
  166733. text_ptr->itxt_length = png_strlen(text);
  166734. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166735. png_ptr->current_text = NULL;
  166736. png_free(png_ptr, text_ptr);
  166737. if (ret)
  166738. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  166739. }
  166740. }
  166741. #endif
  166742. void /* PRIVATE */
  166743. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166744. length)
  166745. {
  166746. png_uint_32 skip=0;
  166747. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  166748. if (!(png_ptr->chunk_name[0] & 0x20))
  166749. {
  166750. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166751. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166752. PNG_HANDLE_CHUNK_ALWAYS
  166753. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166754. && png_ptr->read_user_chunk_fn == NULL
  166755. #endif
  166756. )
  166757. #endif
  166758. png_chunk_error(png_ptr, "unknown critical chunk");
  166759. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166760. }
  166761. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166762. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  166763. {
  166764. #ifdef PNG_MAX_MALLOC_64K
  166765. if (length > (png_uint_32)65535L)
  166766. {
  166767. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  166768. skip = length - (png_uint_32)65535L;
  166769. length = (png_uint_32)65535L;
  166770. }
  166771. #endif
  166772. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  166773. (png_charp)png_ptr->chunk_name, 5);
  166774. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  166775. png_ptr->unknown_chunk.size = (png_size_t)length;
  166776. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  166777. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166778. if(png_ptr->read_user_chunk_fn != NULL)
  166779. {
  166780. int ret;
  166781. ret = (*(png_ptr->read_user_chunk_fn))
  166782. (png_ptr, &png_ptr->unknown_chunk);
  166783. if (ret < 0)
  166784. png_chunk_error(png_ptr, "error in user chunk");
  166785. if (ret == 0)
  166786. {
  166787. if (!(png_ptr->chunk_name[0] & 0x20))
  166788. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166789. PNG_HANDLE_CHUNK_ALWAYS)
  166790. png_chunk_error(png_ptr, "unknown critical chunk");
  166791. png_set_unknown_chunks(png_ptr, info_ptr,
  166792. &png_ptr->unknown_chunk, 1);
  166793. }
  166794. }
  166795. #else
  166796. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  166797. #endif
  166798. png_free(png_ptr, png_ptr->unknown_chunk.data);
  166799. png_ptr->unknown_chunk.data = NULL;
  166800. }
  166801. else
  166802. #endif
  166803. skip=length;
  166804. png_push_crc_skip(png_ptr, skip);
  166805. }
  166806. void /* PRIVATE */
  166807. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  166808. {
  166809. if (png_ptr->info_fn != NULL)
  166810. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  166811. }
  166812. void /* PRIVATE */
  166813. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  166814. {
  166815. if (png_ptr->end_fn != NULL)
  166816. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  166817. }
  166818. void /* PRIVATE */
  166819. png_push_have_row(png_structp png_ptr, png_bytep row)
  166820. {
  166821. if (png_ptr->row_fn != NULL)
  166822. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  166823. (int)png_ptr->pass);
  166824. }
  166825. void PNGAPI
  166826. png_progressive_combine_row (png_structp png_ptr,
  166827. png_bytep old_row, png_bytep new_row)
  166828. {
  166829. #ifdef PNG_USE_LOCAL_ARRAYS
  166830. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  166831. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  166832. #endif
  166833. if(png_ptr == NULL) return;
  166834. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  166835. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  166836. }
  166837. void PNGAPI
  166838. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  166839. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  166840. png_progressive_end_ptr end_fn)
  166841. {
  166842. if(png_ptr == NULL) return;
  166843. png_ptr->info_fn = info_fn;
  166844. png_ptr->row_fn = row_fn;
  166845. png_ptr->end_fn = end_fn;
  166846. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  166847. }
  166848. png_voidp PNGAPI
  166849. png_get_progressive_ptr(png_structp png_ptr)
  166850. {
  166851. if(png_ptr == NULL) return (NULL);
  166852. return png_ptr->io_ptr;
  166853. }
  166854. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  166855. /*** End of inlined file: pngpread.c ***/
  166856. /*** Start of inlined file: pngrio.c ***/
  166857. #define PNG_INTERNAL
  166858. #if defined(PNG_READ_SUPPORTED)
  166859. void /* PRIVATE */
  166860. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166861. {
  166862. png_debug1(4,"reading %d bytes\n", (int)length);
  166863. if (png_ptr->read_data_fn != NULL)
  166864. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  166865. else
  166866. png_error(png_ptr, "Call to NULL read function");
  166867. }
  166868. #if !defined(PNG_NO_STDIO)
  166869. #ifndef USE_FAR_KEYWORD
  166870. void PNGAPI
  166871. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166872. {
  166873. png_size_t check;
  166874. if(png_ptr == NULL) return;
  166875. #if defined(_WIN32_WCE)
  166876. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166877. check = 0;
  166878. #else
  166879. check = (png_size_t)fread(data, (png_size_t)1, length,
  166880. (png_FILE_p)png_ptr->io_ptr);
  166881. #endif
  166882. if (check != length)
  166883. png_error(png_ptr, "Read Error");
  166884. }
  166885. #else
  166886. #define NEAR_BUF_SIZE 1024
  166887. #define MIN(a,b) (a <= b ? a : b)
  166888. static void PNGAPI
  166889. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166890. {
  166891. int check;
  166892. png_byte *n_data;
  166893. png_FILE_p io_ptr;
  166894. if(png_ptr == NULL) return;
  166895. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  166896. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  166897. if ((png_bytep)n_data == data)
  166898. {
  166899. #if defined(_WIN32_WCE)
  166900. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166901. check = 0;
  166902. #else
  166903. check = fread(n_data, 1, length, io_ptr);
  166904. #endif
  166905. }
  166906. else
  166907. {
  166908. png_byte buf[NEAR_BUF_SIZE];
  166909. png_size_t read, remaining, err;
  166910. check = 0;
  166911. remaining = length;
  166912. do
  166913. {
  166914. read = MIN(NEAR_BUF_SIZE, remaining);
  166915. #if defined(_WIN32_WCE)
  166916. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  166917. err = 0;
  166918. #else
  166919. err = fread(buf, (png_size_t)1, read, io_ptr);
  166920. #endif
  166921. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  166922. if(err != read)
  166923. break;
  166924. else
  166925. check += err;
  166926. data += read;
  166927. remaining -= read;
  166928. }
  166929. while (remaining != 0);
  166930. }
  166931. if ((png_uint_32)check != (png_uint_32)length)
  166932. png_error(png_ptr, "read Error");
  166933. }
  166934. #endif
  166935. #endif
  166936. void PNGAPI
  166937. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  166938. png_rw_ptr read_data_fn)
  166939. {
  166940. if(png_ptr == NULL) return;
  166941. png_ptr->io_ptr = io_ptr;
  166942. #if !defined(PNG_NO_STDIO)
  166943. if (read_data_fn != NULL)
  166944. png_ptr->read_data_fn = read_data_fn;
  166945. else
  166946. png_ptr->read_data_fn = png_default_read_data;
  166947. #else
  166948. png_ptr->read_data_fn = read_data_fn;
  166949. #endif
  166950. if (png_ptr->write_data_fn != NULL)
  166951. {
  166952. png_ptr->write_data_fn = NULL;
  166953. png_warning(png_ptr,
  166954. "It's an error to set both read_data_fn and write_data_fn in the ");
  166955. png_warning(png_ptr,
  166956. "same structure. Resetting write_data_fn to NULL.");
  166957. }
  166958. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  166959. png_ptr->output_flush_fn = NULL;
  166960. #endif
  166961. }
  166962. #endif /* PNG_READ_SUPPORTED */
  166963. /*** End of inlined file: pngrio.c ***/
  166964. /*** Start of inlined file: pngrtran.c ***/
  166965. #define PNG_INTERNAL
  166966. #if defined(PNG_READ_SUPPORTED)
  166967. void PNGAPI
  166968. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  166969. {
  166970. png_debug(1, "in png_set_crc_action\n");
  166971. if(png_ptr == NULL) return;
  166972. switch (crit_action)
  166973. {
  166974. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  166975. break;
  166976. case PNG_CRC_WARN_USE: /* warn/use data */
  166977. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166978. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  166979. break;
  166980. case PNG_CRC_QUIET_USE: /* quiet/use data */
  166981. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166982. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  166983. PNG_FLAG_CRC_CRITICAL_IGNORE;
  166984. break;
  166985. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  166986. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  166987. case PNG_CRC_ERROR_QUIT: /* error/quit */
  166988. case PNG_CRC_DEFAULT:
  166989. default:
  166990. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166991. break;
  166992. }
  166993. switch (ancil_action)
  166994. {
  166995. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  166996. break;
  166997. case PNG_CRC_WARN_USE: /* warn/use data */
  166998. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166999. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  167000. break;
  167001. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167002. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167003. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  167004. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167005. break;
  167006. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167007. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167008. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167009. break;
  167010. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  167011. case PNG_CRC_DEFAULT:
  167012. default:
  167013. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167014. break;
  167015. }
  167016. }
  167017. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167018. defined(PNG_FLOATING_POINT_SUPPORTED)
  167019. void PNGAPI
  167020. png_set_background(png_structp png_ptr,
  167021. png_color_16p background_color, int background_gamma_code,
  167022. int need_expand, double background_gamma)
  167023. {
  167024. png_debug(1, "in png_set_background\n");
  167025. if(png_ptr == NULL) return;
  167026. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167027. {
  167028. png_warning(png_ptr, "Application must supply a known background gamma");
  167029. return;
  167030. }
  167031. png_ptr->transformations |= PNG_BACKGROUND;
  167032. png_memcpy(&(png_ptr->background), background_color,
  167033. png_sizeof(png_color_16));
  167034. png_ptr->background_gamma = (float)background_gamma;
  167035. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167036. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167037. }
  167038. #endif
  167039. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167040. void PNGAPI
  167041. png_set_strip_16(png_structp png_ptr)
  167042. {
  167043. png_debug(1, "in png_set_strip_16\n");
  167044. if(png_ptr == NULL) return;
  167045. png_ptr->transformations |= PNG_16_TO_8;
  167046. }
  167047. #endif
  167048. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167049. void PNGAPI
  167050. png_set_strip_alpha(png_structp png_ptr)
  167051. {
  167052. png_debug(1, "in png_set_strip_alpha\n");
  167053. if(png_ptr == NULL) return;
  167054. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167055. }
  167056. #endif
  167057. #if defined(PNG_READ_DITHER_SUPPORTED)
  167058. typedef struct png_dsort_struct
  167059. {
  167060. struct png_dsort_struct FAR * next;
  167061. png_byte left;
  167062. png_byte right;
  167063. } png_dsort;
  167064. typedef png_dsort FAR * png_dsortp;
  167065. typedef png_dsort FAR * FAR * png_dsortpp;
  167066. void PNGAPI
  167067. png_set_dither(png_structp png_ptr, png_colorp palette,
  167068. int num_palette, int maximum_colors, png_uint_16p histogram,
  167069. int full_dither)
  167070. {
  167071. png_debug(1, "in png_set_dither\n");
  167072. if(png_ptr == NULL) return;
  167073. png_ptr->transformations |= PNG_DITHER;
  167074. if (!full_dither)
  167075. {
  167076. int i;
  167077. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167078. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167079. for (i = 0; i < num_palette; i++)
  167080. png_ptr->dither_index[i] = (png_byte)i;
  167081. }
  167082. if (num_palette > maximum_colors)
  167083. {
  167084. if (histogram != NULL)
  167085. {
  167086. int i;
  167087. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167088. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167089. for (i = 0; i < num_palette; i++)
  167090. png_ptr->dither_sort[i] = (png_byte)i;
  167091. for (i = num_palette - 1; i >= maximum_colors; i--)
  167092. {
  167093. int done; /* to stop early if the list is pre-sorted */
  167094. int j;
  167095. done = 1;
  167096. for (j = 0; j < i; j++)
  167097. {
  167098. if (histogram[png_ptr->dither_sort[j]]
  167099. < histogram[png_ptr->dither_sort[j + 1]])
  167100. {
  167101. png_byte t;
  167102. t = png_ptr->dither_sort[j];
  167103. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167104. png_ptr->dither_sort[j + 1] = t;
  167105. done = 0;
  167106. }
  167107. }
  167108. if (done)
  167109. break;
  167110. }
  167111. if (full_dither)
  167112. {
  167113. int j = num_palette;
  167114. for (i = 0; i < maximum_colors; i++)
  167115. {
  167116. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167117. {
  167118. do
  167119. j--;
  167120. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167121. palette[i] = palette[j];
  167122. }
  167123. }
  167124. }
  167125. else
  167126. {
  167127. int j = num_palette;
  167128. for (i = 0; i < maximum_colors; i++)
  167129. {
  167130. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167131. {
  167132. png_color tmp_color;
  167133. do
  167134. j--;
  167135. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167136. tmp_color = palette[j];
  167137. palette[j] = palette[i];
  167138. palette[i] = tmp_color;
  167139. png_ptr->dither_index[j] = (png_byte)i;
  167140. png_ptr->dither_index[i] = (png_byte)j;
  167141. }
  167142. }
  167143. for (i = 0; i < num_palette; i++)
  167144. {
  167145. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167146. {
  167147. int min_d, k, min_k, d_index;
  167148. d_index = png_ptr->dither_index[i];
  167149. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167150. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167151. {
  167152. int d;
  167153. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167154. if (d < min_d)
  167155. {
  167156. min_d = d;
  167157. min_k = k;
  167158. }
  167159. }
  167160. png_ptr->dither_index[i] = (png_byte)min_k;
  167161. }
  167162. }
  167163. }
  167164. png_free(png_ptr, png_ptr->dither_sort);
  167165. png_ptr->dither_sort=NULL;
  167166. }
  167167. else
  167168. {
  167169. int i;
  167170. int max_d;
  167171. int num_new_palette;
  167172. png_dsortp t;
  167173. png_dsortpp hash;
  167174. t=NULL;
  167175. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167176. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167177. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167178. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167179. for (i = 0; i < num_palette; i++)
  167180. {
  167181. png_ptr->index_to_palette[i] = (png_byte)i;
  167182. png_ptr->palette_to_index[i] = (png_byte)i;
  167183. }
  167184. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167185. png_sizeof (png_dsortp)));
  167186. for (i = 0; i < 769; i++)
  167187. hash[i] = NULL;
  167188. num_new_palette = num_palette;
  167189. max_d = 96;
  167190. while (num_new_palette > maximum_colors)
  167191. {
  167192. for (i = 0; i < num_new_palette - 1; i++)
  167193. {
  167194. int j;
  167195. for (j = i + 1; j < num_new_palette; j++)
  167196. {
  167197. int d;
  167198. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167199. if (d <= max_d)
  167200. {
  167201. t = (png_dsortp)png_malloc_warn(png_ptr,
  167202. (png_uint_32)(png_sizeof(png_dsort)));
  167203. if (t == NULL)
  167204. break;
  167205. t->next = hash[d];
  167206. t->left = (png_byte)i;
  167207. t->right = (png_byte)j;
  167208. hash[d] = t;
  167209. }
  167210. }
  167211. if (t == NULL)
  167212. break;
  167213. }
  167214. if (t != NULL)
  167215. for (i = 0; i <= max_d; i++)
  167216. {
  167217. if (hash[i] != NULL)
  167218. {
  167219. png_dsortp p;
  167220. for (p = hash[i]; p; p = p->next)
  167221. {
  167222. if ((int)png_ptr->index_to_palette[p->left]
  167223. < num_new_palette &&
  167224. (int)png_ptr->index_to_palette[p->right]
  167225. < num_new_palette)
  167226. {
  167227. int j, next_j;
  167228. if (num_new_palette & 0x01)
  167229. {
  167230. j = p->left;
  167231. next_j = p->right;
  167232. }
  167233. else
  167234. {
  167235. j = p->right;
  167236. next_j = p->left;
  167237. }
  167238. num_new_palette--;
  167239. palette[png_ptr->index_to_palette[j]]
  167240. = palette[num_new_palette];
  167241. if (!full_dither)
  167242. {
  167243. int k;
  167244. for (k = 0; k < num_palette; k++)
  167245. {
  167246. if (png_ptr->dither_index[k] ==
  167247. png_ptr->index_to_palette[j])
  167248. png_ptr->dither_index[k] =
  167249. png_ptr->index_to_palette[next_j];
  167250. if ((int)png_ptr->dither_index[k] ==
  167251. num_new_palette)
  167252. png_ptr->dither_index[k] =
  167253. png_ptr->index_to_palette[j];
  167254. }
  167255. }
  167256. png_ptr->index_to_palette[png_ptr->palette_to_index
  167257. [num_new_palette]] = png_ptr->index_to_palette[j];
  167258. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167259. = png_ptr->palette_to_index[num_new_palette];
  167260. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167261. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167262. }
  167263. if (num_new_palette <= maximum_colors)
  167264. break;
  167265. }
  167266. if (num_new_palette <= maximum_colors)
  167267. break;
  167268. }
  167269. }
  167270. for (i = 0; i < 769; i++)
  167271. {
  167272. if (hash[i] != NULL)
  167273. {
  167274. png_dsortp p = hash[i];
  167275. while (p)
  167276. {
  167277. t = p->next;
  167278. png_free(png_ptr, p);
  167279. p = t;
  167280. }
  167281. }
  167282. hash[i] = 0;
  167283. }
  167284. max_d += 96;
  167285. }
  167286. png_free(png_ptr, hash);
  167287. png_free(png_ptr, png_ptr->palette_to_index);
  167288. png_free(png_ptr, png_ptr->index_to_palette);
  167289. png_ptr->palette_to_index=NULL;
  167290. png_ptr->index_to_palette=NULL;
  167291. }
  167292. num_palette = maximum_colors;
  167293. }
  167294. if (png_ptr->palette == NULL)
  167295. {
  167296. png_ptr->palette = palette;
  167297. }
  167298. png_ptr->num_palette = (png_uint_16)num_palette;
  167299. if (full_dither)
  167300. {
  167301. int i;
  167302. png_bytep distance;
  167303. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167304. PNG_DITHER_BLUE_BITS;
  167305. int num_red = (1 << PNG_DITHER_RED_BITS);
  167306. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167307. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167308. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167309. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167310. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167311. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167312. png_sizeof (png_byte));
  167313. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167314. png_sizeof(png_byte)));
  167315. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167316. for (i = 0; i < num_palette; i++)
  167317. {
  167318. int ir, ig, ib;
  167319. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167320. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167321. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167322. for (ir = 0; ir < num_red; ir++)
  167323. {
  167324. int dr = ((ir > r) ? ir - r : r - ir);
  167325. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167326. for (ig = 0; ig < num_green; ig++)
  167327. {
  167328. int dg = ((ig > g) ? ig - g : g - ig);
  167329. int dt = dr + dg;
  167330. int dm = ((dr > dg) ? dr : dg);
  167331. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167332. for (ib = 0; ib < num_blue; ib++)
  167333. {
  167334. int d_index = index_g | ib;
  167335. int db = ((ib > b) ? ib - b : b - ib);
  167336. int dmax = ((dm > db) ? dm : db);
  167337. int d = dmax + dt + db;
  167338. if (d < (int)distance[d_index])
  167339. {
  167340. distance[d_index] = (png_byte)d;
  167341. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167342. }
  167343. }
  167344. }
  167345. }
  167346. }
  167347. png_free(png_ptr, distance);
  167348. }
  167349. }
  167350. #endif
  167351. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167352. void PNGAPI
  167353. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167354. {
  167355. png_debug(1, "in png_set_gamma\n");
  167356. if(png_ptr == NULL) return;
  167357. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167358. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167359. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167360. png_ptr->transformations |= PNG_GAMMA;
  167361. png_ptr->gamma = (float)file_gamma;
  167362. png_ptr->screen_gamma = (float)scrn_gamma;
  167363. }
  167364. #endif
  167365. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167366. void PNGAPI
  167367. png_set_expand(png_structp png_ptr)
  167368. {
  167369. png_debug(1, "in png_set_expand\n");
  167370. if(png_ptr == NULL) return;
  167371. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167372. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167373. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167374. #endif
  167375. }
  167376. void PNGAPI
  167377. png_set_palette_to_rgb(png_structp png_ptr)
  167378. {
  167379. png_debug(1, "in png_set_palette_to_rgb\n");
  167380. if(png_ptr == NULL) return;
  167381. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167382. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167383. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167384. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167385. #endif
  167386. }
  167387. #if !defined(PNG_1_0_X)
  167388. void PNGAPI
  167389. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167390. {
  167391. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167392. if(png_ptr == NULL) return;
  167393. png_ptr->transformations |= PNG_EXPAND;
  167394. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167395. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167396. #endif
  167397. }
  167398. #endif
  167399. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167400. void PNGAPI
  167401. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167402. {
  167403. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167404. if(png_ptr == NULL) return;
  167405. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167406. }
  167407. #endif
  167408. void PNGAPI
  167409. png_set_tRNS_to_alpha(png_structp png_ptr)
  167410. {
  167411. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167412. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167413. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167414. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167415. #endif
  167416. }
  167417. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167418. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167419. void PNGAPI
  167420. png_set_gray_to_rgb(png_structp png_ptr)
  167421. {
  167422. png_debug(1, "in png_set_gray_to_rgb\n");
  167423. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167424. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167425. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167426. #endif
  167427. }
  167428. #endif
  167429. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167430. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167431. void PNGAPI
  167432. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167433. double green)
  167434. {
  167435. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167436. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167437. if(png_ptr == NULL) return;
  167438. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167439. }
  167440. #endif
  167441. void PNGAPI
  167442. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167443. png_fixed_point red, png_fixed_point green)
  167444. {
  167445. png_debug(1, "in png_set_rgb_to_gray\n");
  167446. if(png_ptr == NULL) return;
  167447. switch(error_action)
  167448. {
  167449. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167450. break;
  167451. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167452. break;
  167453. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167454. }
  167455. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167456. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167457. png_ptr->transformations |= PNG_EXPAND;
  167458. #else
  167459. {
  167460. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167461. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167462. }
  167463. #endif
  167464. {
  167465. png_uint_16 red_int, green_int;
  167466. if(red < 0 || green < 0)
  167467. {
  167468. red_int = 6968; /* .212671 * 32768 + .5 */
  167469. green_int = 23434; /* .715160 * 32768 + .5 */
  167470. }
  167471. else if(red + green < 100000L)
  167472. {
  167473. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167474. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167475. }
  167476. else
  167477. {
  167478. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167479. red_int = 6968;
  167480. green_int = 23434;
  167481. }
  167482. png_ptr->rgb_to_gray_red_coeff = red_int;
  167483. png_ptr->rgb_to_gray_green_coeff = green_int;
  167484. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167485. }
  167486. }
  167487. #endif
  167488. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167489. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167490. defined(PNG_LEGACY_SUPPORTED)
  167491. void PNGAPI
  167492. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167493. read_user_transform_fn)
  167494. {
  167495. png_debug(1, "in png_set_read_user_transform_fn\n");
  167496. if(png_ptr == NULL) return;
  167497. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167498. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167499. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167500. #endif
  167501. #ifdef PNG_LEGACY_SUPPORTED
  167502. if(read_user_transform_fn)
  167503. png_warning(png_ptr,
  167504. "This version of libpng does not support user transforms");
  167505. #endif
  167506. }
  167507. #endif
  167508. void /* PRIVATE */
  167509. png_init_read_transformations(png_structp png_ptr)
  167510. {
  167511. png_debug(1, "in png_init_read_transformations\n");
  167512. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167513. if(png_ptr != NULL)
  167514. #endif
  167515. {
  167516. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167517. || defined(PNG_READ_GAMMA_SUPPORTED)
  167518. int color_type = png_ptr->color_type;
  167519. #endif
  167520. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167521. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167522. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167523. !(color_type & PNG_COLOR_MASK_COLOR))
  167524. {
  167525. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167526. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167527. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167528. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167529. png_ptr->background.red == png_ptr->background.green &&
  167530. png_ptr->background.red == png_ptr->background.blue)
  167531. {
  167532. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167533. png_ptr->background.gray = png_ptr->background.red;
  167534. }
  167535. #endif
  167536. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167537. (png_ptr->transformations & PNG_EXPAND))
  167538. {
  167539. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167540. {
  167541. switch (png_ptr->bit_depth)
  167542. {
  167543. case 1:
  167544. png_ptr->background.gray *= (png_uint_16)0xff;
  167545. png_ptr->background.red = png_ptr->background.green
  167546. = png_ptr->background.blue = png_ptr->background.gray;
  167547. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167548. {
  167549. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  167550. png_ptr->trans_values.red = png_ptr->trans_values.green
  167551. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167552. }
  167553. break;
  167554. case 2:
  167555. png_ptr->background.gray *= (png_uint_16)0x55;
  167556. png_ptr->background.red = png_ptr->background.green
  167557. = png_ptr->background.blue = png_ptr->background.gray;
  167558. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167559. {
  167560. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  167561. png_ptr->trans_values.red = png_ptr->trans_values.green
  167562. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167563. }
  167564. break;
  167565. case 4:
  167566. png_ptr->background.gray *= (png_uint_16)0x11;
  167567. png_ptr->background.red = png_ptr->background.green
  167568. = png_ptr->background.blue = png_ptr->background.gray;
  167569. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167570. {
  167571. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  167572. png_ptr->trans_values.red = png_ptr->trans_values.green
  167573. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167574. }
  167575. break;
  167576. case 8:
  167577. case 16:
  167578. png_ptr->background.red = png_ptr->background.green
  167579. = png_ptr->background.blue = png_ptr->background.gray;
  167580. break;
  167581. }
  167582. }
  167583. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  167584. {
  167585. png_ptr->background.red =
  167586. png_ptr->palette[png_ptr->background.index].red;
  167587. png_ptr->background.green =
  167588. png_ptr->palette[png_ptr->background.index].green;
  167589. png_ptr->background.blue =
  167590. png_ptr->palette[png_ptr->background.index].blue;
  167591. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167592. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167593. {
  167594. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167595. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167596. #endif
  167597. {
  167598. int i,istop;
  167599. istop=(int)png_ptr->num_trans;
  167600. for (i=0; i<istop; i++)
  167601. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  167602. }
  167603. }
  167604. #endif
  167605. }
  167606. }
  167607. #endif
  167608. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  167609. png_ptr->background_1 = png_ptr->background;
  167610. #endif
  167611. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167612. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  167613. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  167614. < PNG_GAMMA_THRESHOLD))
  167615. {
  167616. int i,k;
  167617. k=0;
  167618. for (i=0; i<png_ptr->num_trans; i++)
  167619. {
  167620. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  167621. k=1; /* partial transparency is present */
  167622. }
  167623. if (k == 0)
  167624. png_ptr->transformations &= (~PNG_GAMMA);
  167625. }
  167626. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  167627. png_ptr->gamma != 0.0)
  167628. {
  167629. png_build_gamma_table(png_ptr);
  167630. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167631. if (png_ptr->transformations & PNG_BACKGROUND)
  167632. {
  167633. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167634. {
  167635. png_color back, back_1;
  167636. png_colorp palette = png_ptr->palette;
  167637. int num_palette = png_ptr->num_palette;
  167638. int i;
  167639. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  167640. {
  167641. back.red = png_ptr->gamma_table[png_ptr->background.red];
  167642. back.green = png_ptr->gamma_table[png_ptr->background.green];
  167643. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  167644. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  167645. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  167646. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  167647. }
  167648. else
  167649. {
  167650. double g, gs;
  167651. switch (png_ptr->background_gamma_type)
  167652. {
  167653. case PNG_BACKGROUND_GAMMA_SCREEN:
  167654. g = (png_ptr->screen_gamma);
  167655. gs = 1.0;
  167656. break;
  167657. case PNG_BACKGROUND_GAMMA_FILE:
  167658. g = 1.0 / (png_ptr->gamma);
  167659. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167660. break;
  167661. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167662. g = 1.0 / (png_ptr->background_gamma);
  167663. gs = 1.0 / (png_ptr->background_gamma *
  167664. png_ptr->screen_gamma);
  167665. break;
  167666. default:
  167667. g = 1.0; /* back_1 */
  167668. gs = 1.0; /* back */
  167669. }
  167670. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  167671. {
  167672. back.red = (png_byte)png_ptr->background.red;
  167673. back.green = (png_byte)png_ptr->background.green;
  167674. back.blue = (png_byte)png_ptr->background.blue;
  167675. }
  167676. else
  167677. {
  167678. back.red = (png_byte)(pow(
  167679. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  167680. back.green = (png_byte)(pow(
  167681. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  167682. back.blue = (png_byte)(pow(
  167683. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  167684. }
  167685. back_1.red = (png_byte)(pow(
  167686. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  167687. back_1.green = (png_byte)(pow(
  167688. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  167689. back_1.blue = (png_byte)(pow(
  167690. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  167691. }
  167692. for (i = 0; i < num_palette; i++)
  167693. {
  167694. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  167695. {
  167696. if (png_ptr->trans[i] == 0)
  167697. {
  167698. palette[i] = back;
  167699. }
  167700. else /* if (png_ptr->trans[i] != 0xff) */
  167701. {
  167702. png_byte v, w;
  167703. v = png_ptr->gamma_to_1[palette[i].red];
  167704. png_composite(w, v, png_ptr->trans[i], back_1.red);
  167705. palette[i].red = png_ptr->gamma_from_1[w];
  167706. v = png_ptr->gamma_to_1[palette[i].green];
  167707. png_composite(w, v, png_ptr->trans[i], back_1.green);
  167708. palette[i].green = png_ptr->gamma_from_1[w];
  167709. v = png_ptr->gamma_to_1[palette[i].blue];
  167710. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  167711. palette[i].blue = png_ptr->gamma_from_1[w];
  167712. }
  167713. }
  167714. else
  167715. {
  167716. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167717. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167718. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167719. }
  167720. }
  167721. }
  167722. else
  167723. {
  167724. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  167725. double g = 1.0;
  167726. double gs = 1.0;
  167727. switch (png_ptr->background_gamma_type)
  167728. {
  167729. case PNG_BACKGROUND_GAMMA_SCREEN:
  167730. g = (png_ptr->screen_gamma);
  167731. gs = 1.0;
  167732. break;
  167733. case PNG_BACKGROUND_GAMMA_FILE:
  167734. g = 1.0 / (png_ptr->gamma);
  167735. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167736. break;
  167737. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167738. g = 1.0 / (png_ptr->background_gamma);
  167739. gs = 1.0 / (png_ptr->background_gamma *
  167740. png_ptr->screen_gamma);
  167741. break;
  167742. }
  167743. png_ptr->background_1.gray = (png_uint_16)(pow(
  167744. (double)png_ptr->background.gray / m, g) * m + .5);
  167745. png_ptr->background.gray = (png_uint_16)(pow(
  167746. (double)png_ptr->background.gray / m, gs) * m + .5);
  167747. if ((png_ptr->background.red != png_ptr->background.green) ||
  167748. (png_ptr->background.red != png_ptr->background.blue) ||
  167749. (png_ptr->background.red != png_ptr->background.gray))
  167750. {
  167751. png_ptr->background_1.red = (png_uint_16)(pow(
  167752. (double)png_ptr->background.red / m, g) * m + .5);
  167753. png_ptr->background_1.green = (png_uint_16)(pow(
  167754. (double)png_ptr->background.green / m, g) * m + .5);
  167755. png_ptr->background_1.blue = (png_uint_16)(pow(
  167756. (double)png_ptr->background.blue / m, g) * m + .5);
  167757. png_ptr->background.red = (png_uint_16)(pow(
  167758. (double)png_ptr->background.red / m, gs) * m + .5);
  167759. png_ptr->background.green = (png_uint_16)(pow(
  167760. (double)png_ptr->background.green / m, gs) * m + .5);
  167761. png_ptr->background.blue = (png_uint_16)(pow(
  167762. (double)png_ptr->background.blue / m, gs) * m + .5);
  167763. }
  167764. else
  167765. {
  167766. png_ptr->background_1.red = png_ptr->background_1.green
  167767. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  167768. png_ptr->background.red = png_ptr->background.green
  167769. = png_ptr->background.blue = png_ptr->background.gray;
  167770. }
  167771. }
  167772. }
  167773. else
  167774. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167775. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167776. {
  167777. png_colorp palette = png_ptr->palette;
  167778. int num_palette = png_ptr->num_palette;
  167779. int i;
  167780. for (i = 0; i < num_palette; i++)
  167781. {
  167782. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167783. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167784. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167785. }
  167786. }
  167787. }
  167788. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167789. else
  167790. #endif
  167791. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  167792. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167793. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167794. (color_type == PNG_COLOR_TYPE_PALETTE))
  167795. {
  167796. int i;
  167797. int istop = (int)png_ptr->num_trans;
  167798. png_color back;
  167799. png_colorp palette = png_ptr->palette;
  167800. back.red = (png_byte)png_ptr->background.red;
  167801. back.green = (png_byte)png_ptr->background.green;
  167802. back.blue = (png_byte)png_ptr->background.blue;
  167803. for (i = 0; i < istop; i++)
  167804. {
  167805. if (png_ptr->trans[i] == 0)
  167806. {
  167807. palette[i] = back;
  167808. }
  167809. else if (png_ptr->trans[i] != 0xff)
  167810. {
  167811. png_composite(palette[i].red, palette[i].red,
  167812. png_ptr->trans[i], back.red);
  167813. png_composite(palette[i].green, palette[i].green,
  167814. png_ptr->trans[i], back.green);
  167815. png_composite(palette[i].blue, palette[i].blue,
  167816. png_ptr->trans[i], back.blue);
  167817. }
  167818. }
  167819. }
  167820. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167821. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167822. if ((png_ptr->transformations & PNG_SHIFT) &&
  167823. (color_type == PNG_COLOR_TYPE_PALETTE))
  167824. {
  167825. png_uint_16 i;
  167826. png_uint_16 istop = png_ptr->num_palette;
  167827. int sr = 8 - png_ptr->sig_bit.red;
  167828. int sg = 8 - png_ptr->sig_bit.green;
  167829. int sb = 8 - png_ptr->sig_bit.blue;
  167830. if (sr < 0 || sr > 8)
  167831. sr = 0;
  167832. if (sg < 0 || sg > 8)
  167833. sg = 0;
  167834. if (sb < 0 || sb > 8)
  167835. sb = 0;
  167836. for (i = 0; i < istop; i++)
  167837. {
  167838. png_ptr->palette[i].red >>= sr;
  167839. png_ptr->palette[i].green >>= sg;
  167840. png_ptr->palette[i].blue >>= sb;
  167841. }
  167842. }
  167843. #endif /* PNG_READ_SHIFT_SUPPORTED */
  167844. }
  167845. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  167846. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  167847. if(png_ptr)
  167848. return;
  167849. #endif
  167850. }
  167851. void /* PRIVATE */
  167852. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  167853. {
  167854. png_debug(1, "in png_read_transform_info\n");
  167855. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167856. if (png_ptr->transformations & PNG_EXPAND)
  167857. {
  167858. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167859. {
  167860. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  167861. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  167862. else
  167863. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  167864. info_ptr->bit_depth = 8;
  167865. info_ptr->num_trans = 0;
  167866. }
  167867. else
  167868. {
  167869. if (png_ptr->num_trans)
  167870. {
  167871. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  167872. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167873. else
  167874. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167875. }
  167876. if (info_ptr->bit_depth < 8)
  167877. info_ptr->bit_depth = 8;
  167878. info_ptr->num_trans = 0;
  167879. }
  167880. }
  167881. #endif
  167882. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167883. if (png_ptr->transformations & PNG_BACKGROUND)
  167884. {
  167885. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167886. info_ptr->num_trans = 0;
  167887. info_ptr->background = png_ptr->background;
  167888. }
  167889. #endif
  167890. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167891. if (png_ptr->transformations & PNG_GAMMA)
  167892. {
  167893. #ifdef PNG_FLOATING_POINT_SUPPORTED
  167894. info_ptr->gamma = png_ptr->gamma;
  167895. #endif
  167896. #ifdef PNG_FIXED_POINT_SUPPORTED
  167897. info_ptr->int_gamma = png_ptr->int_gamma;
  167898. #endif
  167899. }
  167900. #endif
  167901. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167902. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  167903. info_ptr->bit_depth = 8;
  167904. #endif
  167905. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167906. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  167907. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167908. #endif
  167909. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167910. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  167911. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  167912. #endif
  167913. #if defined(PNG_READ_DITHER_SUPPORTED)
  167914. if (png_ptr->transformations & PNG_DITHER)
  167915. {
  167916. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167917. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  167918. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  167919. {
  167920. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  167921. }
  167922. }
  167923. #endif
  167924. #if defined(PNG_READ_PACK_SUPPORTED)
  167925. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  167926. info_ptr->bit_depth = 8;
  167927. #endif
  167928. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167929. info_ptr->channels = 1;
  167930. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  167931. info_ptr->channels = 3;
  167932. else
  167933. info_ptr->channels = 1;
  167934. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167935. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  167936. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167937. #endif
  167938. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  167939. info_ptr->channels++;
  167940. #if defined(PNG_READ_FILLER_SUPPORTED)
  167941. if ((png_ptr->transformations & PNG_FILLER) &&
  167942. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167943. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  167944. {
  167945. info_ptr->channels++;
  167946. #if !defined(PNG_1_0_X)
  167947. if (png_ptr->transformations & PNG_ADD_ALPHA)
  167948. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167949. #endif
  167950. }
  167951. #endif
  167952. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  167953. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167954. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  167955. {
  167956. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  167957. info_ptr->bit_depth = png_ptr->user_transform_depth;
  167958. if(info_ptr->channels < png_ptr->user_transform_channels)
  167959. info_ptr->channels = png_ptr->user_transform_channels;
  167960. }
  167961. #endif
  167962. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  167963. info_ptr->bit_depth);
  167964. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  167965. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  167966. if(png_ptr)
  167967. return;
  167968. #endif
  167969. }
  167970. void /* PRIVATE */
  167971. png_do_read_transformations(png_structp png_ptr)
  167972. {
  167973. png_debug(1, "in png_do_read_transformations\n");
  167974. if (png_ptr->row_buf == NULL)
  167975. {
  167976. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  167977. char msg[50];
  167978. png_snprintf2(msg, 50,
  167979. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  167980. png_ptr->pass);
  167981. png_error(png_ptr, msg);
  167982. #else
  167983. png_error(png_ptr, "NULL row buffer");
  167984. #endif
  167985. }
  167986. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167987. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  167988. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  167989. png_error(png_ptr, "Uninitialized row");
  167990. #else
  167991. png_warning(png_ptr, "Uninitialized row");
  167992. #endif
  167993. #endif
  167994. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167995. if (png_ptr->transformations & PNG_EXPAND)
  167996. {
  167997. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  167998. {
  167999. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168000. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  168001. }
  168002. else
  168003. {
  168004. if (png_ptr->num_trans &&
  168005. (png_ptr->transformations & PNG_EXPAND_tRNS))
  168006. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168007. &(png_ptr->trans_values));
  168008. else
  168009. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168010. NULL);
  168011. }
  168012. }
  168013. #endif
  168014. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168015. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168016. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168017. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168018. #endif
  168019. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168020. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168021. {
  168022. int rgb_error =
  168023. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168024. if(rgb_error)
  168025. {
  168026. png_ptr->rgb_to_gray_status=1;
  168027. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168028. PNG_RGB_TO_GRAY_WARN)
  168029. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168030. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168031. PNG_RGB_TO_GRAY_ERR)
  168032. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168033. }
  168034. }
  168035. #endif
  168036. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168037. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168038. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168039. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168040. #endif
  168041. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168042. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168043. ((png_ptr->num_trans != 0 ) ||
  168044. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168045. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168046. &(png_ptr->trans_values), &(png_ptr->background)
  168047. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168048. , &(png_ptr->background_1),
  168049. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168050. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168051. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168052. png_ptr->gamma_shift
  168053. #endif
  168054. );
  168055. #endif
  168056. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168057. if ((png_ptr->transformations & PNG_GAMMA) &&
  168058. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168059. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168060. ((png_ptr->num_trans != 0) ||
  168061. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168062. #endif
  168063. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168064. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168065. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168066. png_ptr->gamma_shift);
  168067. #endif
  168068. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168069. if (png_ptr->transformations & PNG_16_TO_8)
  168070. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168071. #endif
  168072. #if defined(PNG_READ_DITHER_SUPPORTED)
  168073. if (png_ptr->transformations & PNG_DITHER)
  168074. {
  168075. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168076. png_ptr->palette_lookup, png_ptr->dither_index);
  168077. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168078. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168079. }
  168080. #endif
  168081. #if defined(PNG_READ_INVERT_SUPPORTED)
  168082. if (png_ptr->transformations & PNG_INVERT_MONO)
  168083. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168084. #endif
  168085. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168086. if (png_ptr->transformations & PNG_SHIFT)
  168087. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168088. &(png_ptr->shift));
  168089. #endif
  168090. #if defined(PNG_READ_PACK_SUPPORTED)
  168091. if (png_ptr->transformations & PNG_PACK)
  168092. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168093. #endif
  168094. #if defined(PNG_READ_BGR_SUPPORTED)
  168095. if (png_ptr->transformations & PNG_BGR)
  168096. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168097. #endif
  168098. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168099. if (png_ptr->transformations & PNG_PACKSWAP)
  168100. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168101. #endif
  168102. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168103. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168104. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168105. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168106. #endif
  168107. #if defined(PNG_READ_FILLER_SUPPORTED)
  168108. if (png_ptr->transformations & PNG_FILLER)
  168109. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168110. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168111. #endif
  168112. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168113. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168114. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168115. #endif
  168116. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168117. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168118. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168119. #endif
  168120. #if defined(PNG_READ_SWAP_SUPPORTED)
  168121. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168122. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168123. #endif
  168124. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168125. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168126. {
  168127. if(png_ptr->read_user_transform_fn != NULL)
  168128. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168129. (png_ptr, /* png_ptr */
  168130. &(png_ptr->row_info), /* row_info: */
  168131. png_ptr->row_buf + 1); /* start of pixel data for row */
  168132. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168133. if(png_ptr->user_transform_depth)
  168134. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168135. if(png_ptr->user_transform_channels)
  168136. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168137. #endif
  168138. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168139. png_ptr->row_info.channels);
  168140. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168141. png_ptr->row_info.width);
  168142. }
  168143. #endif
  168144. }
  168145. #if defined(PNG_READ_PACK_SUPPORTED)
  168146. void /* PRIVATE */
  168147. png_do_unpack(png_row_infop row_info, png_bytep row)
  168148. {
  168149. png_debug(1, "in png_do_unpack\n");
  168150. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168151. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168152. #else
  168153. if (row_info->bit_depth < 8)
  168154. #endif
  168155. {
  168156. png_uint_32 i;
  168157. png_uint_32 row_width=row_info->width;
  168158. switch (row_info->bit_depth)
  168159. {
  168160. case 1:
  168161. {
  168162. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168163. png_bytep dp = row + (png_size_t)row_width - 1;
  168164. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168165. for (i = 0; i < row_width; i++)
  168166. {
  168167. *dp = (png_byte)((*sp >> shift) & 0x01);
  168168. if (shift == 7)
  168169. {
  168170. shift = 0;
  168171. sp--;
  168172. }
  168173. else
  168174. shift++;
  168175. dp--;
  168176. }
  168177. break;
  168178. }
  168179. case 2:
  168180. {
  168181. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168182. png_bytep dp = row + (png_size_t)row_width - 1;
  168183. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168184. for (i = 0; i < row_width; i++)
  168185. {
  168186. *dp = (png_byte)((*sp >> shift) & 0x03);
  168187. if (shift == 6)
  168188. {
  168189. shift = 0;
  168190. sp--;
  168191. }
  168192. else
  168193. shift += 2;
  168194. dp--;
  168195. }
  168196. break;
  168197. }
  168198. case 4:
  168199. {
  168200. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168201. png_bytep dp = row + (png_size_t)row_width - 1;
  168202. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168203. for (i = 0; i < row_width; i++)
  168204. {
  168205. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168206. if (shift == 4)
  168207. {
  168208. shift = 0;
  168209. sp--;
  168210. }
  168211. else
  168212. shift = 4;
  168213. dp--;
  168214. }
  168215. break;
  168216. }
  168217. }
  168218. row_info->bit_depth = 8;
  168219. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168220. row_info->rowbytes = row_width * row_info->channels;
  168221. }
  168222. }
  168223. #endif
  168224. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168225. void /* PRIVATE */
  168226. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168227. {
  168228. png_debug(1, "in png_do_unshift\n");
  168229. if (
  168230. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168231. row != NULL && row_info != NULL && sig_bits != NULL &&
  168232. #endif
  168233. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168234. {
  168235. int shift[4];
  168236. int channels = 0;
  168237. int c;
  168238. png_uint_16 value = 0;
  168239. png_uint_32 row_width = row_info->width;
  168240. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168241. {
  168242. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168243. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168244. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168245. }
  168246. else
  168247. {
  168248. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168249. }
  168250. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168251. {
  168252. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168253. }
  168254. for (c = 0; c < channels; c++)
  168255. {
  168256. if (shift[c] <= 0)
  168257. shift[c] = 0;
  168258. else
  168259. value = 1;
  168260. }
  168261. if (!value)
  168262. return;
  168263. switch (row_info->bit_depth)
  168264. {
  168265. case 2:
  168266. {
  168267. png_bytep bp;
  168268. png_uint_32 i;
  168269. png_uint_32 istop = row_info->rowbytes;
  168270. for (bp = row, i = 0; i < istop; i++)
  168271. {
  168272. *bp >>= 1;
  168273. *bp++ &= 0x55;
  168274. }
  168275. break;
  168276. }
  168277. case 4:
  168278. {
  168279. png_bytep bp = row;
  168280. png_uint_32 i;
  168281. png_uint_32 istop = row_info->rowbytes;
  168282. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168283. (png_byte)((int)0xf >> shift[0]));
  168284. for (i = 0; i < istop; i++)
  168285. {
  168286. *bp >>= shift[0];
  168287. *bp++ &= mask;
  168288. }
  168289. break;
  168290. }
  168291. case 8:
  168292. {
  168293. png_bytep bp = row;
  168294. png_uint_32 i;
  168295. png_uint_32 istop = row_width * channels;
  168296. for (i = 0; i < istop; i++)
  168297. {
  168298. *bp++ >>= shift[i%channels];
  168299. }
  168300. break;
  168301. }
  168302. case 16:
  168303. {
  168304. png_bytep bp = row;
  168305. png_uint_32 i;
  168306. png_uint_32 istop = channels * row_width;
  168307. for (i = 0; i < istop; i++)
  168308. {
  168309. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168310. value >>= shift[i%channels];
  168311. *bp++ = (png_byte)(value >> 8);
  168312. *bp++ = (png_byte)(value & 0xff);
  168313. }
  168314. break;
  168315. }
  168316. }
  168317. }
  168318. }
  168319. #endif
  168320. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168321. void /* PRIVATE */
  168322. png_do_chop(png_row_infop row_info, png_bytep row)
  168323. {
  168324. png_debug(1, "in png_do_chop\n");
  168325. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168326. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168327. #else
  168328. if (row_info->bit_depth == 16)
  168329. #endif
  168330. {
  168331. png_bytep sp = row;
  168332. png_bytep dp = row;
  168333. png_uint_32 i;
  168334. png_uint_32 istop = row_info->width * row_info->channels;
  168335. for (i = 0; i<istop; i++, sp += 2, dp++)
  168336. {
  168337. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168338. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168339. #else
  168340. *dp = *sp;
  168341. #endif
  168342. }
  168343. row_info->bit_depth = 8;
  168344. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168345. row_info->rowbytes = row_info->width * row_info->channels;
  168346. }
  168347. }
  168348. #endif
  168349. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168350. void /* PRIVATE */
  168351. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168352. {
  168353. png_debug(1, "in png_do_read_swap_alpha\n");
  168354. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168355. if (row != NULL && row_info != NULL)
  168356. #endif
  168357. {
  168358. png_uint_32 row_width = row_info->width;
  168359. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168360. {
  168361. if (row_info->bit_depth == 8)
  168362. {
  168363. png_bytep sp = row + row_info->rowbytes;
  168364. png_bytep dp = sp;
  168365. png_byte save;
  168366. png_uint_32 i;
  168367. for (i = 0; i < row_width; i++)
  168368. {
  168369. save = *(--sp);
  168370. *(--dp) = *(--sp);
  168371. *(--dp) = *(--sp);
  168372. *(--dp) = *(--sp);
  168373. *(--dp) = save;
  168374. }
  168375. }
  168376. else
  168377. {
  168378. png_bytep sp = row + row_info->rowbytes;
  168379. png_bytep dp = sp;
  168380. png_byte save[2];
  168381. png_uint_32 i;
  168382. for (i = 0; i < row_width; i++)
  168383. {
  168384. save[0] = *(--sp);
  168385. save[1] = *(--sp);
  168386. *(--dp) = *(--sp);
  168387. *(--dp) = *(--sp);
  168388. *(--dp) = *(--sp);
  168389. *(--dp) = *(--sp);
  168390. *(--dp) = *(--sp);
  168391. *(--dp) = *(--sp);
  168392. *(--dp) = save[0];
  168393. *(--dp) = save[1];
  168394. }
  168395. }
  168396. }
  168397. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168398. {
  168399. if (row_info->bit_depth == 8)
  168400. {
  168401. png_bytep sp = row + row_info->rowbytes;
  168402. png_bytep dp = sp;
  168403. png_byte save;
  168404. png_uint_32 i;
  168405. for (i = 0; i < row_width; i++)
  168406. {
  168407. save = *(--sp);
  168408. *(--dp) = *(--sp);
  168409. *(--dp) = save;
  168410. }
  168411. }
  168412. else
  168413. {
  168414. png_bytep sp = row + row_info->rowbytes;
  168415. png_bytep dp = sp;
  168416. png_byte save[2];
  168417. png_uint_32 i;
  168418. for (i = 0; i < row_width; i++)
  168419. {
  168420. save[0] = *(--sp);
  168421. save[1] = *(--sp);
  168422. *(--dp) = *(--sp);
  168423. *(--dp) = *(--sp);
  168424. *(--dp) = save[0];
  168425. *(--dp) = save[1];
  168426. }
  168427. }
  168428. }
  168429. }
  168430. }
  168431. #endif
  168432. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168433. void /* PRIVATE */
  168434. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168435. {
  168436. png_debug(1, "in png_do_read_invert_alpha\n");
  168437. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168438. if (row != NULL && row_info != NULL)
  168439. #endif
  168440. {
  168441. png_uint_32 row_width = row_info->width;
  168442. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168443. {
  168444. if (row_info->bit_depth == 8)
  168445. {
  168446. png_bytep sp = row + row_info->rowbytes;
  168447. png_bytep dp = sp;
  168448. png_uint_32 i;
  168449. for (i = 0; i < row_width; i++)
  168450. {
  168451. *(--dp) = (png_byte)(255 - *(--sp));
  168452. sp-=3;
  168453. dp=sp;
  168454. }
  168455. }
  168456. else
  168457. {
  168458. png_bytep sp = row + row_info->rowbytes;
  168459. png_bytep dp = sp;
  168460. png_uint_32 i;
  168461. for (i = 0; i < row_width; i++)
  168462. {
  168463. *(--dp) = (png_byte)(255 - *(--sp));
  168464. *(--dp) = (png_byte)(255 - *(--sp));
  168465. sp-=6;
  168466. dp=sp;
  168467. }
  168468. }
  168469. }
  168470. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168471. {
  168472. if (row_info->bit_depth == 8)
  168473. {
  168474. png_bytep sp = row + row_info->rowbytes;
  168475. png_bytep dp = sp;
  168476. png_uint_32 i;
  168477. for (i = 0; i < row_width; i++)
  168478. {
  168479. *(--dp) = (png_byte)(255 - *(--sp));
  168480. *(--dp) = *(--sp);
  168481. }
  168482. }
  168483. else
  168484. {
  168485. png_bytep sp = row + row_info->rowbytes;
  168486. png_bytep dp = sp;
  168487. png_uint_32 i;
  168488. for (i = 0; i < row_width; i++)
  168489. {
  168490. *(--dp) = (png_byte)(255 - *(--sp));
  168491. *(--dp) = (png_byte)(255 - *(--sp));
  168492. sp-=2;
  168493. dp=sp;
  168494. }
  168495. }
  168496. }
  168497. }
  168498. }
  168499. #endif
  168500. #if defined(PNG_READ_FILLER_SUPPORTED)
  168501. void /* PRIVATE */
  168502. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168503. png_uint_32 filler, png_uint_32 flags)
  168504. {
  168505. png_uint_32 i;
  168506. png_uint_32 row_width = row_info->width;
  168507. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168508. png_byte lo_filler = (png_byte)(filler & 0xff);
  168509. png_debug(1, "in png_do_read_filler\n");
  168510. if (
  168511. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168512. row != NULL && row_info != NULL &&
  168513. #endif
  168514. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168515. {
  168516. if(row_info->bit_depth == 8)
  168517. {
  168518. if (flags & PNG_FLAG_FILLER_AFTER)
  168519. {
  168520. png_bytep sp = row + (png_size_t)row_width;
  168521. png_bytep dp = sp + (png_size_t)row_width;
  168522. for (i = 1; i < row_width; i++)
  168523. {
  168524. *(--dp) = lo_filler;
  168525. *(--dp) = *(--sp);
  168526. }
  168527. *(--dp) = lo_filler;
  168528. row_info->channels = 2;
  168529. row_info->pixel_depth = 16;
  168530. row_info->rowbytes = row_width * 2;
  168531. }
  168532. else
  168533. {
  168534. png_bytep sp = row + (png_size_t)row_width;
  168535. png_bytep dp = sp + (png_size_t)row_width;
  168536. for (i = 0; i < row_width; i++)
  168537. {
  168538. *(--dp) = *(--sp);
  168539. *(--dp) = lo_filler;
  168540. }
  168541. row_info->channels = 2;
  168542. row_info->pixel_depth = 16;
  168543. row_info->rowbytes = row_width * 2;
  168544. }
  168545. }
  168546. else if(row_info->bit_depth == 16)
  168547. {
  168548. if (flags & PNG_FLAG_FILLER_AFTER)
  168549. {
  168550. png_bytep sp = row + (png_size_t)row_width * 2;
  168551. png_bytep dp = sp + (png_size_t)row_width * 2;
  168552. for (i = 1; i < row_width; i++)
  168553. {
  168554. *(--dp) = hi_filler;
  168555. *(--dp) = lo_filler;
  168556. *(--dp) = *(--sp);
  168557. *(--dp) = *(--sp);
  168558. }
  168559. *(--dp) = hi_filler;
  168560. *(--dp) = lo_filler;
  168561. row_info->channels = 2;
  168562. row_info->pixel_depth = 32;
  168563. row_info->rowbytes = row_width * 4;
  168564. }
  168565. else
  168566. {
  168567. png_bytep sp = row + (png_size_t)row_width * 2;
  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) = hi_filler;
  168574. *(--dp) = lo_filler;
  168575. }
  168576. row_info->channels = 2;
  168577. row_info->pixel_depth = 32;
  168578. row_info->rowbytes = row_width * 4;
  168579. }
  168580. }
  168581. } /* COLOR_TYPE == GRAY */
  168582. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168583. {
  168584. if(row_info->bit_depth == 8)
  168585. {
  168586. if (flags & PNG_FLAG_FILLER_AFTER)
  168587. {
  168588. png_bytep sp = row + (png_size_t)row_width * 3;
  168589. png_bytep dp = sp + (png_size_t)row_width;
  168590. for (i = 1; i < row_width; i++)
  168591. {
  168592. *(--dp) = lo_filler;
  168593. *(--dp) = *(--sp);
  168594. *(--dp) = *(--sp);
  168595. *(--dp) = *(--sp);
  168596. }
  168597. *(--dp) = lo_filler;
  168598. row_info->channels = 4;
  168599. row_info->pixel_depth = 32;
  168600. row_info->rowbytes = row_width * 4;
  168601. }
  168602. else
  168603. {
  168604. png_bytep sp = row + (png_size_t)row_width * 3;
  168605. png_bytep dp = sp + (png_size_t)row_width;
  168606. for (i = 0; i < row_width; i++)
  168607. {
  168608. *(--dp) = *(--sp);
  168609. *(--dp) = *(--sp);
  168610. *(--dp) = *(--sp);
  168611. *(--dp) = lo_filler;
  168612. }
  168613. row_info->channels = 4;
  168614. row_info->pixel_depth = 32;
  168615. row_info->rowbytes = row_width * 4;
  168616. }
  168617. }
  168618. else if(row_info->bit_depth == 16)
  168619. {
  168620. if (flags & PNG_FLAG_FILLER_AFTER)
  168621. {
  168622. png_bytep sp = row + (png_size_t)row_width * 6;
  168623. png_bytep dp = sp + (png_size_t)row_width * 2;
  168624. for (i = 1; i < row_width; i++)
  168625. {
  168626. *(--dp) = hi_filler;
  168627. *(--dp) = lo_filler;
  168628. *(--dp) = *(--sp);
  168629. *(--dp) = *(--sp);
  168630. *(--dp) = *(--sp);
  168631. *(--dp) = *(--sp);
  168632. *(--dp) = *(--sp);
  168633. *(--dp) = *(--sp);
  168634. }
  168635. *(--dp) = hi_filler;
  168636. *(--dp) = lo_filler;
  168637. row_info->channels = 4;
  168638. row_info->pixel_depth = 64;
  168639. row_info->rowbytes = row_width * 8;
  168640. }
  168641. else
  168642. {
  168643. png_bytep sp = row + (png_size_t)row_width * 6;
  168644. png_bytep dp = sp + (png_size_t)row_width * 2;
  168645. for (i = 0; i < row_width; i++)
  168646. {
  168647. *(--dp) = *(--sp);
  168648. *(--dp) = *(--sp);
  168649. *(--dp) = *(--sp);
  168650. *(--dp) = *(--sp);
  168651. *(--dp) = *(--sp);
  168652. *(--dp) = *(--sp);
  168653. *(--dp) = hi_filler;
  168654. *(--dp) = lo_filler;
  168655. }
  168656. row_info->channels = 4;
  168657. row_info->pixel_depth = 64;
  168658. row_info->rowbytes = row_width * 8;
  168659. }
  168660. }
  168661. } /* COLOR_TYPE == RGB */
  168662. }
  168663. #endif
  168664. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168665. void /* PRIVATE */
  168666. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  168667. {
  168668. png_uint_32 i;
  168669. png_uint_32 row_width = row_info->width;
  168670. png_debug(1, "in png_do_gray_to_rgb\n");
  168671. if (row_info->bit_depth >= 8 &&
  168672. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168673. row != NULL && row_info != NULL &&
  168674. #endif
  168675. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  168676. {
  168677. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168678. {
  168679. if (row_info->bit_depth == 8)
  168680. {
  168681. png_bytep sp = row + (png_size_t)row_width - 1;
  168682. png_bytep dp = sp + (png_size_t)row_width * 2;
  168683. for (i = 0; i < row_width; i++)
  168684. {
  168685. *(dp--) = *sp;
  168686. *(dp--) = *sp;
  168687. *(dp--) = *(sp--);
  168688. }
  168689. }
  168690. else
  168691. {
  168692. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168693. png_bytep dp = sp + (png_size_t)row_width * 4;
  168694. for (i = 0; i < row_width; i++)
  168695. {
  168696. *(dp--) = *sp;
  168697. *(dp--) = *(sp - 1);
  168698. *(dp--) = *sp;
  168699. *(dp--) = *(sp - 1);
  168700. *(dp--) = *(sp--);
  168701. *(dp--) = *(sp--);
  168702. }
  168703. }
  168704. }
  168705. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168706. {
  168707. if (row_info->bit_depth == 8)
  168708. {
  168709. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168710. png_bytep dp = sp + (png_size_t)row_width * 2;
  168711. for (i = 0; i < row_width; i++)
  168712. {
  168713. *(dp--) = *(sp--);
  168714. *(dp--) = *sp;
  168715. *(dp--) = *sp;
  168716. *(dp--) = *(sp--);
  168717. }
  168718. }
  168719. else
  168720. {
  168721. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  168722. png_bytep dp = sp + (png_size_t)row_width * 4;
  168723. for (i = 0; i < row_width; i++)
  168724. {
  168725. *(dp--) = *(sp--);
  168726. *(dp--) = *(sp--);
  168727. *(dp--) = *sp;
  168728. *(dp--) = *(sp - 1);
  168729. *(dp--) = *sp;
  168730. *(dp--) = *(sp - 1);
  168731. *(dp--) = *(sp--);
  168732. *(dp--) = *(sp--);
  168733. }
  168734. }
  168735. }
  168736. row_info->channels += (png_byte)2;
  168737. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  168738. row_info->pixel_depth = (png_byte)(row_info->channels *
  168739. row_info->bit_depth);
  168740. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168741. }
  168742. }
  168743. #endif
  168744. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168745. int /* PRIVATE */
  168746. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  168747. {
  168748. png_uint_32 i;
  168749. png_uint_32 row_width = row_info->width;
  168750. int rgb_error = 0;
  168751. png_debug(1, "in png_do_rgb_to_gray\n");
  168752. if (
  168753. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168754. row != NULL && row_info != NULL &&
  168755. #endif
  168756. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  168757. {
  168758. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  168759. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  168760. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  168761. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168762. {
  168763. if (row_info->bit_depth == 8)
  168764. {
  168765. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168766. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168767. {
  168768. png_bytep sp = row;
  168769. png_bytep dp = row;
  168770. for (i = 0; i < row_width; i++)
  168771. {
  168772. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168773. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168774. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168775. if(red != green || red != blue)
  168776. {
  168777. rgb_error |= 1;
  168778. *(dp++) = png_ptr->gamma_from_1[
  168779. (rc*red+gc*green+bc*blue)>>15];
  168780. }
  168781. else
  168782. *(dp++) = *(sp-1);
  168783. }
  168784. }
  168785. else
  168786. #endif
  168787. {
  168788. png_bytep sp = row;
  168789. png_bytep dp = row;
  168790. for (i = 0; i < row_width; i++)
  168791. {
  168792. png_byte red = *(sp++);
  168793. png_byte green = *(sp++);
  168794. png_byte blue = *(sp++);
  168795. if(red != green || red != blue)
  168796. {
  168797. rgb_error |= 1;
  168798. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  168799. }
  168800. else
  168801. *(dp++) = *(sp-1);
  168802. }
  168803. }
  168804. }
  168805. else /* RGB bit_depth == 16 */
  168806. {
  168807. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168808. if (png_ptr->gamma_16_to_1 != NULL &&
  168809. png_ptr->gamma_16_from_1 != NULL)
  168810. {
  168811. png_bytep sp = row;
  168812. png_bytep dp = row;
  168813. for (i = 0; i < row_width; i++)
  168814. {
  168815. png_uint_16 red, green, blue, w;
  168816. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168817. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168818. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168819. if(red == green && red == blue)
  168820. w = red;
  168821. else
  168822. {
  168823. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168824. png_ptr->gamma_shift][red>>8];
  168825. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168826. png_ptr->gamma_shift][green>>8];
  168827. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168828. png_ptr->gamma_shift][blue>>8];
  168829. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  168830. + bc*blue_1)>>15);
  168831. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168832. png_ptr->gamma_shift][gray16 >> 8];
  168833. rgb_error |= 1;
  168834. }
  168835. *(dp++) = (png_byte)((w>>8) & 0xff);
  168836. *(dp++) = (png_byte)(w & 0xff);
  168837. }
  168838. }
  168839. else
  168840. #endif
  168841. {
  168842. png_bytep sp = row;
  168843. png_bytep dp = row;
  168844. for (i = 0; i < row_width; i++)
  168845. {
  168846. png_uint_16 red, green, blue, gray16;
  168847. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168848. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168849. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168850. if(red != green || red != blue)
  168851. rgb_error |= 1;
  168852. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168853. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168854. *(dp++) = (png_byte)(gray16 & 0xff);
  168855. }
  168856. }
  168857. }
  168858. }
  168859. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168860. {
  168861. if (row_info->bit_depth == 8)
  168862. {
  168863. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168864. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168865. {
  168866. png_bytep sp = row;
  168867. png_bytep dp = row;
  168868. for (i = 0; i < row_width; i++)
  168869. {
  168870. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168871. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168872. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168873. if(red != green || red != blue)
  168874. rgb_error |= 1;
  168875. *(dp++) = png_ptr->gamma_from_1
  168876. [(rc*red + gc*green + bc*blue)>>15];
  168877. *(dp++) = *(sp++); /* alpha */
  168878. }
  168879. }
  168880. else
  168881. #endif
  168882. {
  168883. png_bytep sp = row;
  168884. png_bytep dp = row;
  168885. for (i = 0; i < row_width; i++)
  168886. {
  168887. png_byte red = *(sp++);
  168888. png_byte green = *(sp++);
  168889. png_byte blue = *(sp++);
  168890. if(red != green || red != blue)
  168891. rgb_error |= 1;
  168892. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  168893. *(dp++) = *(sp++); /* alpha */
  168894. }
  168895. }
  168896. }
  168897. else /* RGBA bit_depth == 16 */
  168898. {
  168899. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168900. if (png_ptr->gamma_16_to_1 != NULL &&
  168901. png_ptr->gamma_16_from_1 != NULL)
  168902. {
  168903. png_bytep sp = row;
  168904. png_bytep dp = row;
  168905. for (i = 0; i < row_width; i++)
  168906. {
  168907. png_uint_16 red, green, blue, w;
  168908. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168909. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168910. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168911. if(red == green && red == blue)
  168912. w = red;
  168913. else
  168914. {
  168915. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168916. png_ptr->gamma_shift][red>>8];
  168917. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168918. png_ptr->gamma_shift][green>>8];
  168919. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168920. png_ptr->gamma_shift][blue>>8];
  168921. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  168922. + gc * green_1 + bc * blue_1)>>15);
  168923. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168924. png_ptr->gamma_shift][gray16 >> 8];
  168925. rgb_error |= 1;
  168926. }
  168927. *(dp++) = (png_byte)((w>>8) & 0xff);
  168928. *(dp++) = (png_byte)(w & 0xff);
  168929. *(dp++) = *(sp++); /* alpha */
  168930. *(dp++) = *(sp++);
  168931. }
  168932. }
  168933. else
  168934. #endif
  168935. {
  168936. png_bytep sp = row;
  168937. png_bytep dp = row;
  168938. for (i = 0; i < row_width; i++)
  168939. {
  168940. png_uint_16 red, green, blue, gray16;
  168941. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168942. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168943. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168944. if(red != green || red != blue)
  168945. rgb_error |= 1;
  168946. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168947. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168948. *(dp++) = (png_byte)(gray16 & 0xff);
  168949. *(dp++) = *(sp++); /* alpha */
  168950. *(dp++) = *(sp++);
  168951. }
  168952. }
  168953. }
  168954. }
  168955. row_info->channels -= (png_byte)2;
  168956. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  168957. row_info->pixel_depth = (png_byte)(row_info->channels *
  168958. row_info->bit_depth);
  168959. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168960. }
  168961. return rgb_error;
  168962. }
  168963. #endif
  168964. void PNGAPI
  168965. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  168966. {
  168967. int num_palette;
  168968. int color_inc;
  168969. int i;
  168970. int v;
  168971. png_debug(1, "in png_do_build_grayscale_palette\n");
  168972. if (palette == NULL)
  168973. return;
  168974. switch (bit_depth)
  168975. {
  168976. case 1:
  168977. num_palette = 2;
  168978. color_inc = 0xff;
  168979. break;
  168980. case 2:
  168981. num_palette = 4;
  168982. color_inc = 0x55;
  168983. break;
  168984. case 4:
  168985. num_palette = 16;
  168986. color_inc = 0x11;
  168987. break;
  168988. case 8:
  168989. num_palette = 256;
  168990. color_inc = 1;
  168991. break;
  168992. default:
  168993. num_palette = 0;
  168994. color_inc = 0;
  168995. break;
  168996. }
  168997. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  168998. {
  168999. palette[i].red = (png_byte)v;
  169000. palette[i].green = (png_byte)v;
  169001. palette[i].blue = (png_byte)v;
  169002. }
  169003. }
  169004. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  169005. void /* PRIVATE */
  169006. png_correct_palette(png_structp png_ptr, png_colorp palette,
  169007. int num_palette)
  169008. {
  169009. png_debug(1, "in png_correct_palette\n");
  169010. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  169011. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169012. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169013. {
  169014. png_color back, back_1;
  169015. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169016. {
  169017. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169018. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169019. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169020. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169021. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169022. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169023. }
  169024. else
  169025. {
  169026. double g;
  169027. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169028. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169029. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169030. {
  169031. back.red = png_ptr->background.red;
  169032. back.green = png_ptr->background.green;
  169033. back.blue = png_ptr->background.blue;
  169034. }
  169035. else
  169036. {
  169037. back.red =
  169038. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169039. 255.0 + 0.5);
  169040. back.green =
  169041. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169042. 255.0 + 0.5);
  169043. back.blue =
  169044. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169045. 255.0 + 0.5);
  169046. }
  169047. g = 1.0 / png_ptr->background_gamma;
  169048. back_1.red =
  169049. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169050. 255.0 + 0.5);
  169051. back_1.green =
  169052. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169053. 255.0 + 0.5);
  169054. back_1.blue =
  169055. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169056. 255.0 + 0.5);
  169057. }
  169058. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169059. {
  169060. png_uint_32 i;
  169061. for (i = 0; i < (png_uint_32)num_palette; i++)
  169062. {
  169063. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169064. {
  169065. palette[i] = back;
  169066. }
  169067. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169068. {
  169069. png_byte v, w;
  169070. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169071. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169072. palette[i].red = png_ptr->gamma_from_1[w];
  169073. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169074. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169075. palette[i].green = png_ptr->gamma_from_1[w];
  169076. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169077. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169078. palette[i].blue = png_ptr->gamma_from_1[w];
  169079. }
  169080. else
  169081. {
  169082. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169083. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169084. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169085. }
  169086. }
  169087. }
  169088. else
  169089. {
  169090. int i;
  169091. for (i = 0; i < num_palette; i++)
  169092. {
  169093. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169094. {
  169095. palette[i] = back;
  169096. }
  169097. else
  169098. {
  169099. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169100. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169101. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169102. }
  169103. }
  169104. }
  169105. }
  169106. else
  169107. #endif
  169108. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169109. if (png_ptr->transformations & PNG_GAMMA)
  169110. {
  169111. int i;
  169112. for (i = 0; i < num_palette; i++)
  169113. {
  169114. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169115. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169116. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169117. }
  169118. }
  169119. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169120. else
  169121. #endif
  169122. #endif
  169123. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169124. if (png_ptr->transformations & PNG_BACKGROUND)
  169125. {
  169126. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169127. {
  169128. png_color back;
  169129. back.red = (png_byte)png_ptr->background.red;
  169130. back.green = (png_byte)png_ptr->background.green;
  169131. back.blue = (png_byte)png_ptr->background.blue;
  169132. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169133. {
  169134. if (png_ptr->trans[i] == 0)
  169135. {
  169136. palette[i].red = back.red;
  169137. palette[i].green = back.green;
  169138. palette[i].blue = back.blue;
  169139. }
  169140. else if (png_ptr->trans[i] != 0xff)
  169141. {
  169142. png_composite(palette[i].red, png_ptr->palette[i].red,
  169143. png_ptr->trans[i], back.red);
  169144. png_composite(palette[i].green, png_ptr->palette[i].green,
  169145. png_ptr->trans[i], back.green);
  169146. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169147. png_ptr->trans[i], back.blue);
  169148. }
  169149. }
  169150. }
  169151. else /* assume grayscale palette (what else could it be?) */
  169152. {
  169153. int i;
  169154. for (i = 0; i < num_palette; i++)
  169155. {
  169156. if (i == (png_byte)png_ptr->trans_values.gray)
  169157. {
  169158. palette[i].red = (png_byte)png_ptr->background.red;
  169159. palette[i].green = (png_byte)png_ptr->background.green;
  169160. palette[i].blue = (png_byte)png_ptr->background.blue;
  169161. }
  169162. }
  169163. }
  169164. }
  169165. #endif
  169166. }
  169167. #endif
  169168. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169169. void /* PRIVATE */
  169170. png_do_background(png_row_infop row_info, png_bytep row,
  169171. png_color_16p trans_values, png_color_16p background
  169172. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169173. , png_color_16p background_1,
  169174. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169175. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169176. png_uint_16pp gamma_16_to_1, int gamma_shift
  169177. #endif
  169178. )
  169179. {
  169180. png_bytep sp, dp;
  169181. png_uint_32 i;
  169182. png_uint_32 row_width=row_info->width;
  169183. int shift;
  169184. png_debug(1, "in png_do_background\n");
  169185. if (background != NULL &&
  169186. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169187. row != NULL && row_info != NULL &&
  169188. #endif
  169189. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169190. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169191. {
  169192. switch (row_info->color_type)
  169193. {
  169194. case PNG_COLOR_TYPE_GRAY:
  169195. {
  169196. switch (row_info->bit_depth)
  169197. {
  169198. case 1:
  169199. {
  169200. sp = row;
  169201. shift = 7;
  169202. for (i = 0; i < row_width; i++)
  169203. {
  169204. if ((png_uint_16)((*sp >> shift) & 0x01)
  169205. == trans_values->gray)
  169206. {
  169207. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169208. *sp |= (png_byte)(background->gray << shift);
  169209. }
  169210. if (!shift)
  169211. {
  169212. shift = 7;
  169213. sp++;
  169214. }
  169215. else
  169216. shift--;
  169217. }
  169218. break;
  169219. }
  169220. case 2:
  169221. {
  169222. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169223. if (gamma_table != NULL)
  169224. {
  169225. sp = row;
  169226. shift = 6;
  169227. for (i = 0; i < row_width; i++)
  169228. {
  169229. if ((png_uint_16)((*sp >> shift) & 0x03)
  169230. == trans_values->gray)
  169231. {
  169232. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169233. *sp |= (png_byte)(background->gray << shift);
  169234. }
  169235. else
  169236. {
  169237. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169238. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169239. (p << 4) | (p << 6)] >> 6) & 0x03);
  169240. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169241. *sp |= (png_byte)(g << shift);
  169242. }
  169243. if (!shift)
  169244. {
  169245. shift = 6;
  169246. sp++;
  169247. }
  169248. else
  169249. shift -= 2;
  169250. }
  169251. }
  169252. else
  169253. #endif
  169254. {
  169255. sp = row;
  169256. shift = 6;
  169257. for (i = 0; i < row_width; i++)
  169258. {
  169259. if ((png_uint_16)((*sp >> shift) & 0x03)
  169260. == trans_values->gray)
  169261. {
  169262. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169263. *sp |= (png_byte)(background->gray << shift);
  169264. }
  169265. if (!shift)
  169266. {
  169267. shift = 6;
  169268. sp++;
  169269. }
  169270. else
  169271. shift -= 2;
  169272. }
  169273. }
  169274. break;
  169275. }
  169276. case 4:
  169277. {
  169278. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169279. if (gamma_table != NULL)
  169280. {
  169281. sp = row;
  169282. shift = 4;
  169283. for (i = 0; i < row_width; i++)
  169284. {
  169285. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169286. == trans_values->gray)
  169287. {
  169288. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169289. *sp |= (png_byte)(background->gray << shift);
  169290. }
  169291. else
  169292. {
  169293. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169294. png_byte g = (png_byte)((gamma_table[p |
  169295. (p << 4)] >> 4) & 0x0f);
  169296. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169297. *sp |= (png_byte)(g << shift);
  169298. }
  169299. if (!shift)
  169300. {
  169301. shift = 4;
  169302. sp++;
  169303. }
  169304. else
  169305. shift -= 4;
  169306. }
  169307. }
  169308. else
  169309. #endif
  169310. {
  169311. sp = row;
  169312. shift = 4;
  169313. for (i = 0; i < row_width; i++)
  169314. {
  169315. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169316. == trans_values->gray)
  169317. {
  169318. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169319. *sp |= (png_byte)(background->gray << shift);
  169320. }
  169321. if (!shift)
  169322. {
  169323. shift = 4;
  169324. sp++;
  169325. }
  169326. else
  169327. shift -= 4;
  169328. }
  169329. }
  169330. break;
  169331. }
  169332. case 8:
  169333. {
  169334. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169335. if (gamma_table != NULL)
  169336. {
  169337. sp = row;
  169338. for (i = 0; i < row_width; i++, sp++)
  169339. {
  169340. if (*sp == trans_values->gray)
  169341. {
  169342. *sp = (png_byte)background->gray;
  169343. }
  169344. else
  169345. {
  169346. *sp = gamma_table[*sp];
  169347. }
  169348. }
  169349. }
  169350. else
  169351. #endif
  169352. {
  169353. sp = row;
  169354. for (i = 0; i < row_width; i++, sp++)
  169355. {
  169356. if (*sp == trans_values->gray)
  169357. {
  169358. *sp = (png_byte)background->gray;
  169359. }
  169360. }
  169361. }
  169362. break;
  169363. }
  169364. case 16:
  169365. {
  169366. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169367. if (gamma_16 != NULL)
  169368. {
  169369. sp = row;
  169370. for (i = 0; i < row_width; i++, sp += 2)
  169371. {
  169372. png_uint_16 v;
  169373. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169374. if (v == trans_values->gray)
  169375. {
  169376. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169377. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169378. }
  169379. else
  169380. {
  169381. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169382. *sp = (png_byte)((v >> 8) & 0xff);
  169383. *(sp + 1) = (png_byte)(v & 0xff);
  169384. }
  169385. }
  169386. }
  169387. else
  169388. #endif
  169389. {
  169390. sp = row;
  169391. for (i = 0; i < row_width; i++, sp += 2)
  169392. {
  169393. png_uint_16 v;
  169394. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169395. if (v == trans_values->gray)
  169396. {
  169397. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169398. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169399. }
  169400. }
  169401. }
  169402. break;
  169403. }
  169404. }
  169405. break;
  169406. }
  169407. case PNG_COLOR_TYPE_RGB:
  169408. {
  169409. if (row_info->bit_depth == 8)
  169410. {
  169411. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169412. if (gamma_table != NULL)
  169413. {
  169414. sp = row;
  169415. for (i = 0; i < row_width; i++, sp += 3)
  169416. {
  169417. if (*sp == trans_values->red &&
  169418. *(sp + 1) == trans_values->green &&
  169419. *(sp + 2) == trans_values->blue)
  169420. {
  169421. *sp = (png_byte)background->red;
  169422. *(sp + 1) = (png_byte)background->green;
  169423. *(sp + 2) = (png_byte)background->blue;
  169424. }
  169425. else
  169426. {
  169427. *sp = gamma_table[*sp];
  169428. *(sp + 1) = gamma_table[*(sp + 1)];
  169429. *(sp + 2) = gamma_table[*(sp + 2)];
  169430. }
  169431. }
  169432. }
  169433. else
  169434. #endif
  169435. {
  169436. sp = row;
  169437. for (i = 0; i < row_width; i++, sp += 3)
  169438. {
  169439. if (*sp == trans_values->red &&
  169440. *(sp + 1) == trans_values->green &&
  169441. *(sp + 2) == trans_values->blue)
  169442. {
  169443. *sp = (png_byte)background->red;
  169444. *(sp + 1) = (png_byte)background->green;
  169445. *(sp + 2) = (png_byte)background->blue;
  169446. }
  169447. }
  169448. }
  169449. }
  169450. else /* if (row_info->bit_depth == 16) */
  169451. {
  169452. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169453. if (gamma_16 != NULL)
  169454. {
  169455. sp = row;
  169456. for (i = 0; i < row_width; i++, sp += 6)
  169457. {
  169458. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169459. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169460. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169461. if (r == trans_values->red && g == trans_values->green &&
  169462. b == trans_values->blue)
  169463. {
  169464. *sp = (png_byte)((background->red >> 8) & 0xff);
  169465. *(sp + 1) = (png_byte)(background->red & 0xff);
  169466. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169467. *(sp + 3) = (png_byte)(background->green & 0xff);
  169468. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169469. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169470. }
  169471. else
  169472. {
  169473. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169474. *sp = (png_byte)((v >> 8) & 0xff);
  169475. *(sp + 1) = (png_byte)(v & 0xff);
  169476. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169477. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169478. *(sp + 3) = (png_byte)(v & 0xff);
  169479. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169480. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169481. *(sp + 5) = (png_byte)(v & 0xff);
  169482. }
  169483. }
  169484. }
  169485. else
  169486. #endif
  169487. {
  169488. sp = row;
  169489. for (i = 0; i < row_width; i++, sp += 6)
  169490. {
  169491. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169492. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169493. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169494. if (r == trans_values->red && g == trans_values->green &&
  169495. b == trans_values->blue)
  169496. {
  169497. *sp = (png_byte)((background->red >> 8) & 0xff);
  169498. *(sp + 1) = (png_byte)(background->red & 0xff);
  169499. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169500. *(sp + 3) = (png_byte)(background->green & 0xff);
  169501. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169502. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169503. }
  169504. }
  169505. }
  169506. }
  169507. break;
  169508. }
  169509. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169510. {
  169511. if (row_info->bit_depth == 8)
  169512. {
  169513. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169514. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169515. gamma_table != NULL)
  169516. {
  169517. sp = row;
  169518. dp = row;
  169519. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169520. {
  169521. png_uint_16 a = *(sp + 1);
  169522. if (a == 0xff)
  169523. {
  169524. *dp = gamma_table[*sp];
  169525. }
  169526. else if (a == 0)
  169527. {
  169528. *dp = (png_byte)background->gray;
  169529. }
  169530. else
  169531. {
  169532. png_byte v, w;
  169533. v = gamma_to_1[*sp];
  169534. png_composite(w, v, a, background_1->gray);
  169535. *dp = gamma_from_1[w];
  169536. }
  169537. }
  169538. }
  169539. else
  169540. #endif
  169541. {
  169542. sp = row;
  169543. dp = row;
  169544. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169545. {
  169546. png_byte a = *(sp + 1);
  169547. if (a == 0xff)
  169548. {
  169549. *dp = *sp;
  169550. }
  169551. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169552. else if (a == 0)
  169553. {
  169554. *dp = (png_byte)background->gray;
  169555. }
  169556. else
  169557. {
  169558. png_composite(*dp, *sp, a, background_1->gray);
  169559. }
  169560. #else
  169561. *dp = (png_byte)background->gray;
  169562. #endif
  169563. }
  169564. }
  169565. }
  169566. else /* if (png_ptr->bit_depth == 16) */
  169567. {
  169568. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169569. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169570. gamma_16_to_1 != NULL)
  169571. {
  169572. sp = row;
  169573. dp = row;
  169574. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169575. {
  169576. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169577. if (a == (png_uint_16)0xffff)
  169578. {
  169579. png_uint_16 v;
  169580. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169581. *dp = (png_byte)((v >> 8) & 0xff);
  169582. *(dp + 1) = (png_byte)(v & 0xff);
  169583. }
  169584. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169585. else if (a == 0)
  169586. #else
  169587. else
  169588. #endif
  169589. {
  169590. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169591. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169592. }
  169593. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169594. else
  169595. {
  169596. png_uint_16 g, v, w;
  169597. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169598. png_composite_16(v, g, a, background_1->gray);
  169599. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  169600. *dp = (png_byte)((w >> 8) & 0xff);
  169601. *(dp + 1) = (png_byte)(w & 0xff);
  169602. }
  169603. #endif
  169604. }
  169605. }
  169606. else
  169607. #endif
  169608. {
  169609. sp = row;
  169610. dp = row;
  169611. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169612. {
  169613. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169614. if (a == (png_uint_16)0xffff)
  169615. {
  169616. png_memcpy(dp, sp, 2);
  169617. }
  169618. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169619. else if (a == 0)
  169620. #else
  169621. else
  169622. #endif
  169623. {
  169624. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169625. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169626. }
  169627. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169628. else
  169629. {
  169630. png_uint_16 g, v;
  169631. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169632. png_composite_16(v, g, a, background_1->gray);
  169633. *dp = (png_byte)((v >> 8) & 0xff);
  169634. *(dp + 1) = (png_byte)(v & 0xff);
  169635. }
  169636. #endif
  169637. }
  169638. }
  169639. }
  169640. break;
  169641. }
  169642. case PNG_COLOR_TYPE_RGB_ALPHA:
  169643. {
  169644. if (row_info->bit_depth == 8)
  169645. {
  169646. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169647. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169648. gamma_table != NULL)
  169649. {
  169650. sp = row;
  169651. dp = row;
  169652. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169653. {
  169654. png_byte a = *(sp + 3);
  169655. if (a == 0xff)
  169656. {
  169657. *dp = gamma_table[*sp];
  169658. *(dp + 1) = gamma_table[*(sp + 1)];
  169659. *(dp + 2) = gamma_table[*(sp + 2)];
  169660. }
  169661. else if (a == 0)
  169662. {
  169663. *dp = (png_byte)background->red;
  169664. *(dp + 1) = (png_byte)background->green;
  169665. *(dp + 2) = (png_byte)background->blue;
  169666. }
  169667. else
  169668. {
  169669. png_byte v, w;
  169670. v = gamma_to_1[*sp];
  169671. png_composite(w, v, a, background_1->red);
  169672. *dp = gamma_from_1[w];
  169673. v = gamma_to_1[*(sp + 1)];
  169674. png_composite(w, v, a, background_1->green);
  169675. *(dp + 1) = gamma_from_1[w];
  169676. v = gamma_to_1[*(sp + 2)];
  169677. png_composite(w, v, a, background_1->blue);
  169678. *(dp + 2) = gamma_from_1[w];
  169679. }
  169680. }
  169681. }
  169682. else
  169683. #endif
  169684. {
  169685. sp = row;
  169686. dp = row;
  169687. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169688. {
  169689. png_byte a = *(sp + 3);
  169690. if (a == 0xff)
  169691. {
  169692. *dp = *sp;
  169693. *(dp + 1) = *(sp + 1);
  169694. *(dp + 2) = *(sp + 2);
  169695. }
  169696. else if (a == 0)
  169697. {
  169698. *dp = (png_byte)background->red;
  169699. *(dp + 1) = (png_byte)background->green;
  169700. *(dp + 2) = (png_byte)background->blue;
  169701. }
  169702. else
  169703. {
  169704. png_composite(*dp, *sp, a, background->red);
  169705. png_composite(*(dp + 1), *(sp + 1), a,
  169706. background->green);
  169707. png_composite(*(dp + 2), *(sp + 2), a,
  169708. background->blue);
  169709. }
  169710. }
  169711. }
  169712. }
  169713. else /* if (row_info->bit_depth == 16) */
  169714. {
  169715. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169716. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169717. gamma_16_to_1 != NULL)
  169718. {
  169719. sp = row;
  169720. dp = row;
  169721. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169722. {
  169723. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169724. << 8) + (png_uint_16)(*(sp + 7)));
  169725. if (a == (png_uint_16)0xffff)
  169726. {
  169727. png_uint_16 v;
  169728. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169729. *dp = (png_byte)((v >> 8) & 0xff);
  169730. *(dp + 1) = (png_byte)(v & 0xff);
  169731. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169732. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169733. *(dp + 3) = (png_byte)(v & 0xff);
  169734. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169735. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169736. *(dp + 5) = (png_byte)(v & 0xff);
  169737. }
  169738. else if (a == 0)
  169739. {
  169740. *dp = (png_byte)((background->red >> 8) & 0xff);
  169741. *(dp + 1) = (png_byte)(background->red & 0xff);
  169742. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169743. *(dp + 3) = (png_byte)(background->green & 0xff);
  169744. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169745. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169746. }
  169747. else
  169748. {
  169749. png_uint_16 v, w, x;
  169750. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169751. png_composite_16(w, v, a, background_1->red);
  169752. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169753. *dp = (png_byte)((x >> 8) & 0xff);
  169754. *(dp + 1) = (png_byte)(x & 0xff);
  169755. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169756. png_composite_16(w, v, a, background_1->green);
  169757. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169758. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  169759. *(dp + 3) = (png_byte)(x & 0xff);
  169760. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169761. png_composite_16(w, v, a, background_1->blue);
  169762. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  169763. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  169764. *(dp + 5) = (png_byte)(x & 0xff);
  169765. }
  169766. }
  169767. }
  169768. else
  169769. #endif
  169770. {
  169771. sp = row;
  169772. dp = row;
  169773. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169774. {
  169775. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169776. << 8) + (png_uint_16)(*(sp + 7)));
  169777. if (a == (png_uint_16)0xffff)
  169778. {
  169779. png_memcpy(dp, sp, 6);
  169780. }
  169781. else if (a == 0)
  169782. {
  169783. *dp = (png_byte)((background->red >> 8) & 0xff);
  169784. *(dp + 1) = (png_byte)(background->red & 0xff);
  169785. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169786. *(dp + 3) = (png_byte)(background->green & 0xff);
  169787. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169788. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169789. }
  169790. else
  169791. {
  169792. png_uint_16 v;
  169793. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169794. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  169795. + *(sp + 3));
  169796. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  169797. + *(sp + 5));
  169798. png_composite_16(v, r, a, background->red);
  169799. *dp = (png_byte)((v >> 8) & 0xff);
  169800. *(dp + 1) = (png_byte)(v & 0xff);
  169801. png_composite_16(v, g, a, background->green);
  169802. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169803. *(dp + 3) = (png_byte)(v & 0xff);
  169804. png_composite_16(v, b, a, background->blue);
  169805. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169806. *(dp + 5) = (png_byte)(v & 0xff);
  169807. }
  169808. }
  169809. }
  169810. }
  169811. break;
  169812. }
  169813. }
  169814. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  169815. {
  169816. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  169817. row_info->channels--;
  169818. row_info->pixel_depth = (png_byte)(row_info->channels *
  169819. row_info->bit_depth);
  169820. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169821. }
  169822. }
  169823. }
  169824. #endif
  169825. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169826. void /* PRIVATE */
  169827. png_do_gamma(png_row_infop row_info, png_bytep row,
  169828. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  169829. int gamma_shift)
  169830. {
  169831. png_bytep sp;
  169832. png_uint_32 i;
  169833. png_uint_32 row_width=row_info->width;
  169834. png_debug(1, "in png_do_gamma\n");
  169835. if (
  169836. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169837. row != NULL && row_info != NULL &&
  169838. #endif
  169839. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  169840. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  169841. {
  169842. switch (row_info->color_type)
  169843. {
  169844. case PNG_COLOR_TYPE_RGB:
  169845. {
  169846. if (row_info->bit_depth == 8)
  169847. {
  169848. sp = row;
  169849. for (i = 0; i < row_width; i++)
  169850. {
  169851. *sp = gamma_table[*sp];
  169852. sp++;
  169853. *sp = gamma_table[*sp];
  169854. sp++;
  169855. *sp = gamma_table[*sp];
  169856. sp++;
  169857. }
  169858. }
  169859. else /* if (row_info->bit_depth == 16) */
  169860. {
  169861. sp = row;
  169862. for (i = 0; i < row_width; i++)
  169863. {
  169864. png_uint_16 v;
  169865. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169866. *sp = (png_byte)((v >> 8) & 0xff);
  169867. *(sp + 1) = (png_byte)(v & 0xff);
  169868. sp += 2;
  169869. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169870. *sp = (png_byte)((v >> 8) & 0xff);
  169871. *(sp + 1) = (png_byte)(v & 0xff);
  169872. sp += 2;
  169873. 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. case PNG_COLOR_TYPE_RGB_ALPHA:
  169882. {
  169883. if (row_info->bit_depth == 8)
  169884. {
  169885. sp = row;
  169886. for (i = 0; i < row_width; i++)
  169887. {
  169888. *sp = gamma_table[*sp];
  169889. sp++;
  169890. *sp = gamma_table[*sp];
  169891. sp++;
  169892. *sp = gamma_table[*sp];
  169893. sp++;
  169894. sp++;
  169895. }
  169896. }
  169897. else /* if (row_info->bit_depth == 16) */
  169898. {
  169899. sp = row;
  169900. for (i = 0; i < row_width; i++)
  169901. {
  169902. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169903. *sp = (png_byte)((v >> 8) & 0xff);
  169904. *(sp + 1) = (png_byte)(v & 0xff);
  169905. sp += 2;
  169906. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169907. *sp = (png_byte)((v >> 8) & 0xff);
  169908. *(sp + 1) = (png_byte)(v & 0xff);
  169909. sp += 2;
  169910. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169911. *sp = (png_byte)((v >> 8) & 0xff);
  169912. *(sp + 1) = (png_byte)(v & 0xff);
  169913. sp += 4;
  169914. }
  169915. }
  169916. break;
  169917. }
  169918. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169919. {
  169920. if (row_info->bit_depth == 8)
  169921. {
  169922. sp = row;
  169923. for (i = 0; i < row_width; i++)
  169924. {
  169925. *sp = gamma_table[*sp];
  169926. sp += 2;
  169927. }
  169928. }
  169929. else /* if (row_info->bit_depth == 16) */
  169930. {
  169931. sp = row;
  169932. for (i = 0; i < row_width; i++)
  169933. {
  169934. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169935. *sp = (png_byte)((v >> 8) & 0xff);
  169936. *(sp + 1) = (png_byte)(v & 0xff);
  169937. sp += 4;
  169938. }
  169939. }
  169940. break;
  169941. }
  169942. case PNG_COLOR_TYPE_GRAY:
  169943. {
  169944. if (row_info->bit_depth == 2)
  169945. {
  169946. sp = row;
  169947. for (i = 0; i < row_width; i += 4)
  169948. {
  169949. int a = *sp & 0xc0;
  169950. int b = *sp & 0x30;
  169951. int c = *sp & 0x0c;
  169952. int d = *sp & 0x03;
  169953. *sp = (png_byte)(
  169954. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  169955. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  169956. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  169957. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  169958. sp++;
  169959. }
  169960. }
  169961. if (row_info->bit_depth == 4)
  169962. {
  169963. sp = row;
  169964. for (i = 0; i < row_width; i += 2)
  169965. {
  169966. int msb = *sp & 0xf0;
  169967. int lsb = *sp & 0x0f;
  169968. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  169969. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  169970. sp++;
  169971. }
  169972. }
  169973. else if (row_info->bit_depth == 8)
  169974. {
  169975. sp = row;
  169976. for (i = 0; i < row_width; i++)
  169977. {
  169978. *sp = gamma_table[*sp];
  169979. sp++;
  169980. }
  169981. }
  169982. else if (row_info->bit_depth == 16)
  169983. {
  169984. sp = row;
  169985. for (i = 0; i < row_width; i++)
  169986. {
  169987. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169988. *sp = (png_byte)((v >> 8) & 0xff);
  169989. *(sp + 1) = (png_byte)(v & 0xff);
  169990. sp += 2;
  169991. }
  169992. }
  169993. break;
  169994. }
  169995. }
  169996. }
  169997. }
  169998. #endif
  169999. #if defined(PNG_READ_EXPAND_SUPPORTED)
  170000. void /* PRIVATE */
  170001. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  170002. png_colorp palette, png_bytep trans, int num_trans)
  170003. {
  170004. int shift, value;
  170005. png_bytep sp, dp;
  170006. png_uint_32 i;
  170007. png_uint_32 row_width=row_info->width;
  170008. png_debug(1, "in png_do_expand_palette\n");
  170009. if (
  170010. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170011. row != NULL && row_info != NULL &&
  170012. #endif
  170013. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170014. {
  170015. if (row_info->bit_depth < 8)
  170016. {
  170017. switch (row_info->bit_depth)
  170018. {
  170019. case 1:
  170020. {
  170021. sp = row + (png_size_t)((row_width - 1) >> 3);
  170022. dp = row + (png_size_t)row_width - 1;
  170023. shift = 7 - (int)((row_width + 7) & 0x07);
  170024. for (i = 0; i < row_width; i++)
  170025. {
  170026. if ((*sp >> shift) & 0x01)
  170027. *dp = 1;
  170028. else
  170029. *dp = 0;
  170030. if (shift == 7)
  170031. {
  170032. shift = 0;
  170033. sp--;
  170034. }
  170035. else
  170036. shift++;
  170037. dp--;
  170038. }
  170039. break;
  170040. }
  170041. case 2:
  170042. {
  170043. sp = row + (png_size_t)((row_width - 1) >> 2);
  170044. dp = row + (png_size_t)row_width - 1;
  170045. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170046. for (i = 0; i < row_width; i++)
  170047. {
  170048. value = (*sp >> shift) & 0x03;
  170049. *dp = (png_byte)value;
  170050. if (shift == 6)
  170051. {
  170052. shift = 0;
  170053. sp--;
  170054. }
  170055. else
  170056. shift += 2;
  170057. dp--;
  170058. }
  170059. break;
  170060. }
  170061. case 4:
  170062. {
  170063. sp = row + (png_size_t)((row_width - 1) >> 1);
  170064. dp = row + (png_size_t)row_width - 1;
  170065. shift = (int)((row_width & 0x01) << 2);
  170066. for (i = 0; i < row_width; i++)
  170067. {
  170068. value = (*sp >> shift) & 0x0f;
  170069. *dp = (png_byte)value;
  170070. if (shift == 4)
  170071. {
  170072. shift = 0;
  170073. sp--;
  170074. }
  170075. else
  170076. shift += 4;
  170077. dp--;
  170078. }
  170079. break;
  170080. }
  170081. }
  170082. row_info->bit_depth = 8;
  170083. row_info->pixel_depth = 8;
  170084. row_info->rowbytes = row_width;
  170085. }
  170086. switch (row_info->bit_depth)
  170087. {
  170088. case 8:
  170089. {
  170090. if (trans != NULL)
  170091. {
  170092. sp = row + (png_size_t)row_width - 1;
  170093. dp = row + (png_size_t)(row_width << 2) - 1;
  170094. for (i = 0; i < row_width; i++)
  170095. {
  170096. if ((int)(*sp) >= num_trans)
  170097. *dp-- = 0xff;
  170098. else
  170099. *dp-- = trans[*sp];
  170100. *dp-- = palette[*sp].blue;
  170101. *dp-- = palette[*sp].green;
  170102. *dp-- = palette[*sp].red;
  170103. sp--;
  170104. }
  170105. row_info->bit_depth = 8;
  170106. row_info->pixel_depth = 32;
  170107. row_info->rowbytes = row_width * 4;
  170108. row_info->color_type = 6;
  170109. row_info->channels = 4;
  170110. }
  170111. else
  170112. {
  170113. sp = row + (png_size_t)row_width - 1;
  170114. dp = row + (png_size_t)(row_width * 3) - 1;
  170115. for (i = 0; i < row_width; i++)
  170116. {
  170117. *dp-- = palette[*sp].blue;
  170118. *dp-- = palette[*sp].green;
  170119. *dp-- = palette[*sp].red;
  170120. sp--;
  170121. }
  170122. row_info->bit_depth = 8;
  170123. row_info->pixel_depth = 24;
  170124. row_info->rowbytes = row_width * 3;
  170125. row_info->color_type = 2;
  170126. row_info->channels = 3;
  170127. }
  170128. break;
  170129. }
  170130. }
  170131. }
  170132. }
  170133. void /* PRIVATE */
  170134. png_do_expand(png_row_infop row_info, png_bytep row,
  170135. png_color_16p trans_value)
  170136. {
  170137. int shift, value;
  170138. png_bytep sp, dp;
  170139. png_uint_32 i;
  170140. png_uint_32 row_width=row_info->width;
  170141. png_debug(1, "in png_do_expand\n");
  170142. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170143. if (row != NULL && row_info != NULL)
  170144. #endif
  170145. {
  170146. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170147. {
  170148. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170149. if (row_info->bit_depth < 8)
  170150. {
  170151. switch (row_info->bit_depth)
  170152. {
  170153. case 1:
  170154. {
  170155. gray = (png_uint_16)((gray&0x01)*0xff);
  170156. sp = row + (png_size_t)((row_width - 1) >> 3);
  170157. dp = row + (png_size_t)row_width - 1;
  170158. shift = 7 - (int)((row_width + 7) & 0x07);
  170159. for (i = 0; i < row_width; i++)
  170160. {
  170161. if ((*sp >> shift) & 0x01)
  170162. *dp = 0xff;
  170163. else
  170164. *dp = 0;
  170165. if (shift == 7)
  170166. {
  170167. shift = 0;
  170168. sp--;
  170169. }
  170170. else
  170171. shift++;
  170172. dp--;
  170173. }
  170174. break;
  170175. }
  170176. case 2:
  170177. {
  170178. gray = (png_uint_16)((gray&0x03)*0x55);
  170179. sp = row + (png_size_t)((row_width - 1) >> 2);
  170180. dp = row + (png_size_t)row_width - 1;
  170181. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170182. for (i = 0; i < row_width; i++)
  170183. {
  170184. value = (*sp >> shift) & 0x03;
  170185. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170186. (value << 6));
  170187. if (shift == 6)
  170188. {
  170189. shift = 0;
  170190. sp--;
  170191. }
  170192. else
  170193. shift += 2;
  170194. dp--;
  170195. }
  170196. break;
  170197. }
  170198. case 4:
  170199. {
  170200. gray = (png_uint_16)((gray&0x0f)*0x11);
  170201. sp = row + (png_size_t)((row_width - 1) >> 1);
  170202. dp = row + (png_size_t)row_width - 1;
  170203. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170204. for (i = 0; i < row_width; i++)
  170205. {
  170206. value = (*sp >> shift) & 0x0f;
  170207. *dp = (png_byte)(value | (value << 4));
  170208. if (shift == 4)
  170209. {
  170210. shift = 0;
  170211. sp--;
  170212. }
  170213. else
  170214. shift = 4;
  170215. dp--;
  170216. }
  170217. break;
  170218. }
  170219. }
  170220. row_info->bit_depth = 8;
  170221. row_info->pixel_depth = 8;
  170222. row_info->rowbytes = row_width;
  170223. }
  170224. if (trans_value != NULL)
  170225. {
  170226. if (row_info->bit_depth == 8)
  170227. {
  170228. gray = gray & 0xff;
  170229. sp = row + (png_size_t)row_width - 1;
  170230. dp = row + (png_size_t)(row_width << 1) - 1;
  170231. for (i = 0; i < row_width; i++)
  170232. {
  170233. if (*sp == gray)
  170234. *dp-- = 0;
  170235. else
  170236. *dp-- = 0xff;
  170237. *dp-- = *sp--;
  170238. }
  170239. }
  170240. else if (row_info->bit_depth == 16)
  170241. {
  170242. png_byte gray_high = (gray >> 8) & 0xff;
  170243. png_byte gray_low = gray & 0xff;
  170244. sp = row + row_info->rowbytes - 1;
  170245. dp = row + (row_info->rowbytes << 1) - 1;
  170246. for (i = 0; i < row_width; i++)
  170247. {
  170248. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170249. {
  170250. *dp-- = 0;
  170251. *dp-- = 0;
  170252. }
  170253. else
  170254. {
  170255. *dp-- = 0xff;
  170256. *dp-- = 0xff;
  170257. }
  170258. *dp-- = *sp--;
  170259. *dp-- = *sp--;
  170260. }
  170261. }
  170262. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170263. row_info->channels = 2;
  170264. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170265. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170266. row_width);
  170267. }
  170268. }
  170269. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170270. {
  170271. if (row_info->bit_depth == 8)
  170272. {
  170273. png_byte red = trans_value->red & 0xff;
  170274. png_byte green = trans_value->green & 0xff;
  170275. png_byte blue = trans_value->blue & 0xff;
  170276. sp = row + (png_size_t)row_info->rowbytes - 1;
  170277. dp = row + (png_size_t)(row_width << 2) - 1;
  170278. for (i = 0; i < row_width; i++)
  170279. {
  170280. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170281. *dp-- = 0;
  170282. else
  170283. *dp-- = 0xff;
  170284. *dp-- = *sp--;
  170285. *dp-- = *sp--;
  170286. *dp-- = *sp--;
  170287. }
  170288. }
  170289. else if (row_info->bit_depth == 16)
  170290. {
  170291. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170292. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170293. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170294. png_byte red_low = trans_value->red & 0xff;
  170295. png_byte green_low = trans_value->green & 0xff;
  170296. png_byte blue_low = trans_value->blue & 0xff;
  170297. sp = row + row_info->rowbytes - 1;
  170298. dp = row + (png_size_t)(row_width << 3) - 1;
  170299. for (i = 0; i < row_width; i++)
  170300. {
  170301. if (*(sp - 5) == red_high &&
  170302. *(sp - 4) == red_low &&
  170303. *(sp - 3) == green_high &&
  170304. *(sp - 2) == green_low &&
  170305. *(sp - 1) == blue_high &&
  170306. *(sp ) == blue_low)
  170307. {
  170308. *dp-- = 0;
  170309. *dp-- = 0;
  170310. }
  170311. else
  170312. {
  170313. *dp-- = 0xff;
  170314. *dp-- = 0xff;
  170315. }
  170316. *dp-- = *sp--;
  170317. *dp-- = *sp--;
  170318. *dp-- = *sp--;
  170319. *dp-- = *sp--;
  170320. *dp-- = *sp--;
  170321. *dp-- = *sp--;
  170322. }
  170323. }
  170324. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170325. row_info->channels = 4;
  170326. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170327. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170328. }
  170329. }
  170330. }
  170331. #endif
  170332. #if defined(PNG_READ_DITHER_SUPPORTED)
  170333. void /* PRIVATE */
  170334. png_do_dither(png_row_infop row_info, png_bytep row,
  170335. png_bytep palette_lookup, png_bytep dither_lookup)
  170336. {
  170337. png_bytep sp, dp;
  170338. png_uint_32 i;
  170339. png_uint_32 row_width=row_info->width;
  170340. png_debug(1, "in png_do_dither\n");
  170341. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170342. if (row != NULL && row_info != NULL)
  170343. #endif
  170344. {
  170345. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170346. palette_lookup && row_info->bit_depth == 8)
  170347. {
  170348. int r, g, b, p;
  170349. sp = row;
  170350. dp = row;
  170351. for (i = 0; i < row_width; i++)
  170352. {
  170353. r = *sp++;
  170354. g = *sp++;
  170355. b = *sp++;
  170356. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170357. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170358. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170359. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170360. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170361. (PNG_DITHER_BLUE_BITS)) |
  170362. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170363. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170364. *dp++ = palette_lookup[p];
  170365. }
  170366. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170367. row_info->channels = 1;
  170368. row_info->pixel_depth = row_info->bit_depth;
  170369. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170370. }
  170371. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170372. palette_lookup != NULL && row_info->bit_depth == 8)
  170373. {
  170374. int r, g, b, p;
  170375. sp = row;
  170376. dp = row;
  170377. for (i = 0; i < row_width; i++)
  170378. {
  170379. r = *sp++;
  170380. g = *sp++;
  170381. b = *sp++;
  170382. sp++;
  170383. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170384. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170385. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170386. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170387. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170388. (PNG_DITHER_BLUE_BITS)) |
  170389. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170390. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170391. *dp++ = palette_lookup[p];
  170392. }
  170393. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170394. row_info->channels = 1;
  170395. row_info->pixel_depth = row_info->bit_depth;
  170396. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170397. }
  170398. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170399. dither_lookup && row_info->bit_depth == 8)
  170400. {
  170401. sp = row;
  170402. for (i = 0; i < row_width; i++, sp++)
  170403. {
  170404. *sp = dither_lookup[*sp];
  170405. }
  170406. }
  170407. }
  170408. }
  170409. #endif
  170410. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170411. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170412. static PNG_CONST int png_gamma_shift[] =
  170413. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170414. void /* PRIVATE */
  170415. png_build_gamma_table(png_structp png_ptr)
  170416. {
  170417. png_debug(1, "in png_build_gamma_table\n");
  170418. if (png_ptr->bit_depth <= 8)
  170419. {
  170420. int i;
  170421. double g;
  170422. if (png_ptr->screen_gamma > .000001)
  170423. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170424. else
  170425. g = 1.0;
  170426. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170427. (png_uint_32)256);
  170428. for (i = 0; i < 256; i++)
  170429. {
  170430. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170431. g) * 255.0 + .5);
  170432. }
  170433. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170434. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170435. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170436. {
  170437. g = 1.0 / (png_ptr->gamma);
  170438. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170439. (png_uint_32)256);
  170440. for (i = 0; i < 256; i++)
  170441. {
  170442. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170443. g) * 255.0 + .5);
  170444. }
  170445. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170446. (png_uint_32)256);
  170447. if(png_ptr->screen_gamma > 0.000001)
  170448. g = 1.0 / png_ptr->screen_gamma;
  170449. else
  170450. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170451. for (i = 0; i < 256; i++)
  170452. {
  170453. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170454. g) * 255.0 + .5);
  170455. }
  170456. }
  170457. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170458. }
  170459. else
  170460. {
  170461. double g;
  170462. int i, j, shift, num;
  170463. int sig_bit;
  170464. png_uint_32 ig;
  170465. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170466. {
  170467. sig_bit = (int)png_ptr->sig_bit.red;
  170468. if ((int)png_ptr->sig_bit.green > sig_bit)
  170469. sig_bit = png_ptr->sig_bit.green;
  170470. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170471. sig_bit = png_ptr->sig_bit.blue;
  170472. }
  170473. else
  170474. {
  170475. sig_bit = (int)png_ptr->sig_bit.gray;
  170476. }
  170477. if (sig_bit > 0)
  170478. shift = 16 - sig_bit;
  170479. else
  170480. shift = 0;
  170481. if (png_ptr->transformations & PNG_16_TO_8)
  170482. {
  170483. if (shift < (16 - PNG_MAX_GAMMA_8))
  170484. shift = (16 - PNG_MAX_GAMMA_8);
  170485. }
  170486. if (shift > 8)
  170487. shift = 8;
  170488. if (shift < 0)
  170489. shift = 0;
  170490. png_ptr->gamma_shift = (png_byte)shift;
  170491. num = (1 << (8 - shift));
  170492. if (png_ptr->screen_gamma > .000001)
  170493. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170494. else
  170495. g = 1.0;
  170496. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170497. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170498. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170499. {
  170500. double fin, fout;
  170501. png_uint_32 last, max;
  170502. for (i = 0; i < num; i++)
  170503. {
  170504. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170505. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170506. }
  170507. g = 1.0 / g;
  170508. last = 0;
  170509. for (i = 0; i < 256; i++)
  170510. {
  170511. fout = ((double)i + 0.5) / 256.0;
  170512. fin = pow(fout, g);
  170513. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170514. while (last <= max)
  170515. {
  170516. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170517. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170518. (png_uint_16)i | ((png_uint_16)i << 8));
  170519. last++;
  170520. }
  170521. }
  170522. while (last < ((png_uint_32)num << 8))
  170523. {
  170524. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170525. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170526. last++;
  170527. }
  170528. }
  170529. else
  170530. {
  170531. for (i = 0; i < num; i++)
  170532. {
  170533. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170534. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170535. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170536. for (j = 0; j < 256; j++)
  170537. {
  170538. png_ptr->gamma_16_table[i][j] =
  170539. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170540. 65535.0, g) * 65535.0 + .5);
  170541. }
  170542. }
  170543. }
  170544. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170545. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170546. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170547. {
  170548. g = 1.0 / (png_ptr->gamma);
  170549. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  170550. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  170551. for (i = 0; i < num; i++)
  170552. {
  170553. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170554. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170555. ig = (((png_uint_32)i *
  170556. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170557. for (j = 0; j < 256; j++)
  170558. {
  170559. png_ptr->gamma_16_to_1[i][j] =
  170560. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170561. 65535.0, g) * 65535.0 + .5);
  170562. }
  170563. }
  170564. if(png_ptr->screen_gamma > 0.000001)
  170565. g = 1.0 / png_ptr->screen_gamma;
  170566. else
  170567. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170568. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  170569. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170570. for (i = 0; i < num; i++)
  170571. {
  170572. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170573. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170574. ig = (((png_uint_32)i *
  170575. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170576. for (j = 0; j < 256; j++)
  170577. {
  170578. png_ptr->gamma_16_from_1[i][j] =
  170579. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170580. 65535.0, g) * 65535.0 + .5);
  170581. }
  170582. }
  170583. }
  170584. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170585. }
  170586. }
  170587. #endif
  170588. #endif
  170589. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170590. void /* PRIVATE */
  170591. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  170592. {
  170593. png_debug(1, "in png_do_read_intrapixel\n");
  170594. if (
  170595. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170596. row != NULL && row_info != NULL &&
  170597. #endif
  170598. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  170599. {
  170600. int bytes_per_pixel;
  170601. png_uint_32 row_width = row_info->width;
  170602. if (row_info->bit_depth == 8)
  170603. {
  170604. png_bytep rp;
  170605. png_uint_32 i;
  170606. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170607. bytes_per_pixel = 3;
  170608. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170609. bytes_per_pixel = 4;
  170610. else
  170611. return;
  170612. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170613. {
  170614. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  170615. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  170616. }
  170617. }
  170618. else if (row_info->bit_depth == 16)
  170619. {
  170620. png_bytep rp;
  170621. png_uint_32 i;
  170622. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170623. bytes_per_pixel = 6;
  170624. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170625. bytes_per_pixel = 8;
  170626. else
  170627. return;
  170628. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170629. {
  170630. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  170631. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  170632. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  170633. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  170634. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  170635. *(rp ) = (png_byte)((red >> 8) & 0xff);
  170636. *(rp+1) = (png_byte)(red & 0xff);
  170637. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  170638. *(rp+5) = (png_byte)(blue & 0xff);
  170639. }
  170640. }
  170641. }
  170642. }
  170643. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  170644. #endif /* PNG_READ_SUPPORTED */
  170645. /*** End of inlined file: pngrtran.c ***/
  170646. /*** Start of inlined file: pngrutil.c ***/
  170647. #define PNG_INTERNAL
  170648. #if defined(PNG_READ_SUPPORTED)
  170649. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  170650. # define WIN32_WCE_OLD
  170651. #endif
  170652. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170653. # if defined(WIN32_WCE_OLD)
  170654. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  170655. {
  170656. double result = 0;
  170657. int len;
  170658. wchar_t *str, *end;
  170659. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  170660. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  170661. if ( NULL != str )
  170662. {
  170663. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  170664. result = wcstod(str, &end);
  170665. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  170666. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  170667. png_free(png_ptr, str);
  170668. }
  170669. return result;
  170670. }
  170671. # else
  170672. # define png_strtod(p,a,b) strtod(a,b)
  170673. # endif
  170674. #endif
  170675. png_uint_32 PNGAPI
  170676. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  170677. {
  170678. png_uint_32 i = png_get_uint_32(buf);
  170679. if (i > PNG_UINT_31_MAX)
  170680. png_error(png_ptr, "PNG unsigned integer out of range.");
  170681. return (i);
  170682. }
  170683. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  170684. png_uint_32 PNGAPI
  170685. png_get_uint_32(png_bytep buf)
  170686. {
  170687. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  170688. ((png_uint_32)(*(buf + 1)) << 16) +
  170689. ((png_uint_32)(*(buf + 2)) << 8) +
  170690. (png_uint_32)(*(buf + 3));
  170691. return (i);
  170692. }
  170693. png_int_32 PNGAPI
  170694. png_get_int_32(png_bytep buf)
  170695. {
  170696. png_int_32 i = ((png_int_32)(*buf) << 24) +
  170697. ((png_int_32)(*(buf + 1)) << 16) +
  170698. ((png_int_32)(*(buf + 2)) << 8) +
  170699. (png_int_32)(*(buf + 3));
  170700. return (i);
  170701. }
  170702. png_uint_16 PNGAPI
  170703. png_get_uint_16(png_bytep buf)
  170704. {
  170705. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  170706. (png_uint_16)(*(buf + 1)));
  170707. return (i);
  170708. }
  170709. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  170710. void /* PRIVATE */
  170711. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  170712. {
  170713. if(png_ptr == NULL) return;
  170714. png_read_data(png_ptr, buf, length);
  170715. png_calculate_crc(png_ptr, buf, length);
  170716. }
  170717. int /* PRIVATE */
  170718. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  170719. {
  170720. png_size_t i;
  170721. png_size_t istop = png_ptr->zbuf_size;
  170722. for (i = (png_size_t)skip; i > istop; i -= istop)
  170723. {
  170724. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  170725. }
  170726. if (i)
  170727. {
  170728. png_crc_read(png_ptr, png_ptr->zbuf, i);
  170729. }
  170730. if (png_crc_error(png_ptr))
  170731. {
  170732. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  170733. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  170734. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  170735. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  170736. {
  170737. png_chunk_warning(png_ptr, "CRC error");
  170738. }
  170739. else
  170740. {
  170741. png_chunk_error(png_ptr, "CRC error");
  170742. }
  170743. return (1);
  170744. }
  170745. return (0);
  170746. }
  170747. int /* PRIVATE */
  170748. png_crc_error(png_structp png_ptr)
  170749. {
  170750. png_byte crc_bytes[4];
  170751. png_uint_32 crc;
  170752. int need_crc = 1;
  170753. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  170754. {
  170755. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  170756. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170757. need_crc = 0;
  170758. }
  170759. else /* critical */
  170760. {
  170761. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  170762. need_crc = 0;
  170763. }
  170764. png_read_data(png_ptr, crc_bytes, 4);
  170765. if (need_crc)
  170766. {
  170767. crc = png_get_uint_32(crc_bytes);
  170768. return ((int)(crc != png_ptr->crc));
  170769. }
  170770. else
  170771. return (0);
  170772. }
  170773. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  170774. defined(PNG_READ_iCCP_SUPPORTED)
  170775. png_charp /* PRIVATE */
  170776. png_decompress_chunk(png_structp png_ptr, int comp_type,
  170777. png_charp chunkdata, png_size_t chunklength,
  170778. png_size_t prefix_size, png_size_t *newlength)
  170779. {
  170780. static PNG_CONST char msg[] = "Error decoding compressed text";
  170781. png_charp text;
  170782. png_size_t text_size;
  170783. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  170784. {
  170785. int ret = Z_OK;
  170786. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  170787. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  170788. png_ptr->zstream.next_out = png_ptr->zbuf;
  170789. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170790. text_size = 0;
  170791. text = NULL;
  170792. while (png_ptr->zstream.avail_in)
  170793. {
  170794. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  170795. if (ret != Z_OK && ret != Z_STREAM_END)
  170796. {
  170797. if (png_ptr->zstream.msg != NULL)
  170798. png_warning(png_ptr, png_ptr->zstream.msg);
  170799. else
  170800. png_warning(png_ptr, msg);
  170801. inflateReset(&png_ptr->zstream);
  170802. png_ptr->zstream.avail_in = 0;
  170803. if (text == NULL)
  170804. {
  170805. text_size = prefix_size + png_sizeof(msg) + 1;
  170806. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  170807. if (text == NULL)
  170808. {
  170809. png_free(png_ptr,chunkdata);
  170810. png_error(png_ptr,"Not enough memory to decompress chunk");
  170811. }
  170812. png_memcpy(text, chunkdata, prefix_size);
  170813. }
  170814. text[text_size - 1] = 0x00;
  170815. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  170816. text_size = png_sizeof(msg) > text_size ? text_size :
  170817. png_sizeof(msg);
  170818. png_memcpy(text + prefix_size, msg, text_size + 1);
  170819. break;
  170820. }
  170821. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  170822. {
  170823. if (text == NULL)
  170824. {
  170825. text_size = prefix_size +
  170826. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170827. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  170828. if (text == NULL)
  170829. {
  170830. png_free(png_ptr,chunkdata);
  170831. png_error(png_ptr,"Not enough memory to decompress chunk.");
  170832. }
  170833. png_memcpy(text + prefix_size, png_ptr->zbuf,
  170834. text_size - prefix_size);
  170835. png_memcpy(text, chunkdata, prefix_size);
  170836. *(text + text_size) = 0x00;
  170837. }
  170838. else
  170839. {
  170840. png_charp tmp;
  170841. tmp = text;
  170842. text = (png_charp)png_malloc_warn(png_ptr,
  170843. (png_uint_32)(text_size +
  170844. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  170845. if (text == NULL)
  170846. {
  170847. png_free(png_ptr, tmp);
  170848. png_free(png_ptr, chunkdata);
  170849. png_error(png_ptr,"Not enough memory to decompress chunk..");
  170850. }
  170851. png_memcpy(text, tmp, text_size);
  170852. png_free(png_ptr, tmp);
  170853. png_memcpy(text + text_size, png_ptr->zbuf,
  170854. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  170855. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170856. *(text + text_size) = 0x00;
  170857. }
  170858. if (ret == Z_STREAM_END)
  170859. break;
  170860. else
  170861. {
  170862. png_ptr->zstream.next_out = png_ptr->zbuf;
  170863. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170864. }
  170865. }
  170866. }
  170867. if (ret != Z_STREAM_END)
  170868. {
  170869. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170870. char umsg[52];
  170871. if (ret == Z_BUF_ERROR)
  170872. png_snprintf(umsg, 52,
  170873. "Buffer error in compressed datastream in %s chunk",
  170874. png_ptr->chunk_name);
  170875. else if (ret == Z_DATA_ERROR)
  170876. png_snprintf(umsg, 52,
  170877. "Data error in compressed datastream in %s chunk",
  170878. png_ptr->chunk_name);
  170879. else
  170880. png_snprintf(umsg, 52,
  170881. "Incomplete compressed datastream in %s chunk",
  170882. png_ptr->chunk_name);
  170883. png_warning(png_ptr, umsg);
  170884. #else
  170885. png_warning(png_ptr,
  170886. "Incomplete compressed datastream in chunk other than IDAT");
  170887. #endif
  170888. text_size=prefix_size;
  170889. if (text == NULL)
  170890. {
  170891. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  170892. if (text == NULL)
  170893. {
  170894. png_free(png_ptr, chunkdata);
  170895. png_error(png_ptr,"Not enough memory for text.");
  170896. }
  170897. png_memcpy(text, chunkdata, prefix_size);
  170898. }
  170899. *(text + text_size) = 0x00;
  170900. }
  170901. inflateReset(&png_ptr->zstream);
  170902. png_ptr->zstream.avail_in = 0;
  170903. png_free(png_ptr, chunkdata);
  170904. chunkdata = text;
  170905. *newlength=text_size;
  170906. }
  170907. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  170908. {
  170909. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170910. char umsg[50];
  170911. png_snprintf(umsg, 50,
  170912. "Unknown zTXt compression type %d", comp_type);
  170913. png_warning(png_ptr, umsg);
  170914. #else
  170915. png_warning(png_ptr, "Unknown zTXt compression type");
  170916. #endif
  170917. *(chunkdata + prefix_size) = 0x00;
  170918. *newlength=prefix_size;
  170919. }
  170920. return chunkdata;
  170921. }
  170922. #endif
  170923. void /* PRIVATE */
  170924. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170925. {
  170926. png_byte buf[13];
  170927. png_uint_32 width, height;
  170928. int bit_depth, color_type, compression_type, filter_type;
  170929. int interlace_type;
  170930. png_debug(1, "in png_handle_IHDR\n");
  170931. if (png_ptr->mode & PNG_HAVE_IHDR)
  170932. png_error(png_ptr, "Out of place IHDR");
  170933. if (length != 13)
  170934. png_error(png_ptr, "Invalid IHDR chunk");
  170935. png_ptr->mode |= PNG_HAVE_IHDR;
  170936. png_crc_read(png_ptr, buf, 13);
  170937. png_crc_finish(png_ptr, 0);
  170938. width = png_get_uint_31(png_ptr, buf);
  170939. height = png_get_uint_31(png_ptr, buf + 4);
  170940. bit_depth = buf[8];
  170941. color_type = buf[9];
  170942. compression_type = buf[10];
  170943. filter_type = buf[11];
  170944. interlace_type = buf[12];
  170945. png_ptr->width = width;
  170946. png_ptr->height = height;
  170947. png_ptr->bit_depth = (png_byte)bit_depth;
  170948. png_ptr->interlaced = (png_byte)interlace_type;
  170949. png_ptr->color_type = (png_byte)color_type;
  170950. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170951. png_ptr->filter_type = (png_byte)filter_type;
  170952. #endif
  170953. png_ptr->compression_type = (png_byte)compression_type;
  170954. switch (png_ptr->color_type)
  170955. {
  170956. case PNG_COLOR_TYPE_GRAY:
  170957. case PNG_COLOR_TYPE_PALETTE:
  170958. png_ptr->channels = 1;
  170959. break;
  170960. case PNG_COLOR_TYPE_RGB:
  170961. png_ptr->channels = 3;
  170962. break;
  170963. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170964. png_ptr->channels = 2;
  170965. break;
  170966. case PNG_COLOR_TYPE_RGB_ALPHA:
  170967. png_ptr->channels = 4;
  170968. break;
  170969. }
  170970. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  170971. png_ptr->channels);
  170972. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  170973. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  170974. png_debug1(3,"channels = %d\n", png_ptr->channels);
  170975. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  170976. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  170977. color_type, interlace_type, compression_type, filter_type);
  170978. }
  170979. void /* PRIVATE */
  170980. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170981. {
  170982. png_color palette[PNG_MAX_PALETTE_LENGTH];
  170983. int num, i;
  170984. #ifndef PNG_NO_POINTER_INDEXING
  170985. png_colorp pal_ptr;
  170986. #endif
  170987. png_debug(1, "in png_handle_PLTE\n");
  170988. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  170989. png_error(png_ptr, "Missing IHDR before PLTE");
  170990. else if (png_ptr->mode & PNG_HAVE_IDAT)
  170991. {
  170992. png_warning(png_ptr, "Invalid PLTE after IDAT");
  170993. png_crc_finish(png_ptr, length);
  170994. return;
  170995. }
  170996. else if (png_ptr->mode & PNG_HAVE_PLTE)
  170997. png_error(png_ptr, "Duplicate PLTE chunk");
  170998. png_ptr->mode |= PNG_HAVE_PLTE;
  170999. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  171000. {
  171001. png_warning(png_ptr,
  171002. "Ignoring PLTE chunk in grayscale PNG");
  171003. png_crc_finish(png_ptr, length);
  171004. return;
  171005. }
  171006. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171007. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171008. {
  171009. png_crc_finish(png_ptr, length);
  171010. return;
  171011. }
  171012. #endif
  171013. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171014. {
  171015. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171016. {
  171017. png_warning(png_ptr, "Invalid palette chunk");
  171018. png_crc_finish(png_ptr, length);
  171019. return;
  171020. }
  171021. else
  171022. {
  171023. png_error(png_ptr, "Invalid palette chunk");
  171024. }
  171025. }
  171026. num = (int)length / 3;
  171027. #ifndef PNG_NO_POINTER_INDEXING
  171028. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171029. {
  171030. png_byte buf[3];
  171031. png_crc_read(png_ptr, buf, 3);
  171032. pal_ptr->red = buf[0];
  171033. pal_ptr->green = buf[1];
  171034. pal_ptr->blue = buf[2];
  171035. }
  171036. #else
  171037. for (i = 0; i < num; i++)
  171038. {
  171039. png_byte buf[3];
  171040. png_crc_read(png_ptr, buf, 3);
  171041. palette[i].red = buf[0];
  171042. palette[i].green = buf[1];
  171043. palette[i].blue = buf[2];
  171044. }
  171045. #endif
  171046. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171047. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171048. #endif
  171049. {
  171050. png_crc_finish(png_ptr, 0);
  171051. }
  171052. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171053. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171054. {
  171055. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171056. {
  171057. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171058. {
  171059. png_chunk_error(png_ptr, "CRC error");
  171060. }
  171061. else
  171062. {
  171063. png_chunk_warning(png_ptr, "CRC error");
  171064. return;
  171065. }
  171066. }
  171067. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171068. {
  171069. png_chunk_warning(png_ptr, "CRC error");
  171070. }
  171071. }
  171072. #endif
  171073. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171074. #if defined(PNG_READ_tRNS_SUPPORTED)
  171075. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171076. {
  171077. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171078. {
  171079. if (png_ptr->num_trans > (png_uint_16)num)
  171080. {
  171081. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171082. png_ptr->num_trans = (png_uint_16)num;
  171083. }
  171084. if (info_ptr->num_trans > (png_uint_16)num)
  171085. {
  171086. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171087. info_ptr->num_trans = (png_uint_16)num;
  171088. }
  171089. }
  171090. }
  171091. #endif
  171092. }
  171093. void /* PRIVATE */
  171094. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171095. {
  171096. png_debug(1, "in png_handle_IEND\n");
  171097. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171098. {
  171099. png_error(png_ptr, "No image in file");
  171100. }
  171101. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171102. if (length != 0)
  171103. {
  171104. png_warning(png_ptr, "Incorrect IEND chunk length");
  171105. }
  171106. png_crc_finish(png_ptr, length);
  171107. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171108. }
  171109. #if defined(PNG_READ_gAMA_SUPPORTED)
  171110. void /* PRIVATE */
  171111. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171112. {
  171113. png_fixed_point igamma;
  171114. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171115. float file_gamma;
  171116. #endif
  171117. png_byte buf[4];
  171118. png_debug(1, "in png_handle_gAMA\n");
  171119. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171120. png_error(png_ptr, "Missing IHDR before gAMA");
  171121. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171122. {
  171123. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171124. png_crc_finish(png_ptr, length);
  171125. return;
  171126. }
  171127. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171128. png_warning(png_ptr, "Out of place gAMA chunk");
  171129. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171130. #if defined(PNG_READ_sRGB_SUPPORTED)
  171131. && !(info_ptr->valid & PNG_INFO_sRGB)
  171132. #endif
  171133. )
  171134. {
  171135. png_warning(png_ptr, "Duplicate gAMA chunk");
  171136. png_crc_finish(png_ptr, length);
  171137. return;
  171138. }
  171139. if (length != 4)
  171140. {
  171141. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171142. png_crc_finish(png_ptr, length);
  171143. return;
  171144. }
  171145. png_crc_read(png_ptr, buf, 4);
  171146. if (png_crc_finish(png_ptr, 0))
  171147. return;
  171148. igamma = (png_fixed_point)png_get_uint_32(buf);
  171149. if (igamma == 0)
  171150. {
  171151. png_warning(png_ptr,
  171152. "Ignoring gAMA chunk with gamma=0");
  171153. return;
  171154. }
  171155. #if defined(PNG_READ_sRGB_SUPPORTED)
  171156. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171157. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171158. {
  171159. png_warning(png_ptr,
  171160. "Ignoring incorrect gAMA value when sRGB is also present");
  171161. #ifndef PNG_NO_CONSOLE_IO
  171162. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171163. #endif
  171164. return;
  171165. }
  171166. #endif /* PNG_READ_sRGB_SUPPORTED */
  171167. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171168. file_gamma = (float)igamma / (float)100000.0;
  171169. # ifdef PNG_READ_GAMMA_SUPPORTED
  171170. png_ptr->gamma = file_gamma;
  171171. # endif
  171172. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171173. #endif
  171174. #ifdef PNG_FIXED_POINT_SUPPORTED
  171175. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171176. #endif
  171177. }
  171178. #endif
  171179. #if defined(PNG_READ_sBIT_SUPPORTED)
  171180. void /* PRIVATE */
  171181. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171182. {
  171183. png_size_t truelen;
  171184. png_byte buf[4];
  171185. png_debug(1, "in png_handle_sBIT\n");
  171186. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171187. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171188. png_error(png_ptr, "Missing IHDR before sBIT");
  171189. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171190. {
  171191. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171192. png_crc_finish(png_ptr, length);
  171193. return;
  171194. }
  171195. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171196. {
  171197. png_warning(png_ptr, "Out of place sBIT chunk");
  171198. }
  171199. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171200. {
  171201. png_warning(png_ptr, "Duplicate sBIT chunk");
  171202. png_crc_finish(png_ptr, length);
  171203. return;
  171204. }
  171205. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171206. truelen = 3;
  171207. else
  171208. truelen = (png_size_t)png_ptr->channels;
  171209. if (length != truelen || length > 4)
  171210. {
  171211. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171212. png_crc_finish(png_ptr, length);
  171213. return;
  171214. }
  171215. png_crc_read(png_ptr, buf, truelen);
  171216. if (png_crc_finish(png_ptr, 0))
  171217. return;
  171218. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171219. {
  171220. png_ptr->sig_bit.red = buf[0];
  171221. png_ptr->sig_bit.green = buf[1];
  171222. png_ptr->sig_bit.blue = buf[2];
  171223. png_ptr->sig_bit.alpha = buf[3];
  171224. }
  171225. else
  171226. {
  171227. png_ptr->sig_bit.gray = buf[0];
  171228. png_ptr->sig_bit.red = buf[0];
  171229. png_ptr->sig_bit.green = buf[0];
  171230. png_ptr->sig_bit.blue = buf[0];
  171231. png_ptr->sig_bit.alpha = buf[1];
  171232. }
  171233. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171234. }
  171235. #endif
  171236. #if defined(PNG_READ_cHRM_SUPPORTED)
  171237. void /* PRIVATE */
  171238. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171239. {
  171240. png_byte buf[4];
  171241. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171242. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171243. #endif
  171244. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171245. int_y_green, int_x_blue, int_y_blue;
  171246. png_uint_32 uint_x, uint_y;
  171247. png_debug(1, "in png_handle_cHRM\n");
  171248. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171249. png_error(png_ptr, "Missing IHDR before cHRM");
  171250. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171251. {
  171252. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171253. png_crc_finish(png_ptr, length);
  171254. return;
  171255. }
  171256. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171257. png_warning(png_ptr, "Missing PLTE before cHRM");
  171258. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171259. #if defined(PNG_READ_sRGB_SUPPORTED)
  171260. && !(info_ptr->valid & PNG_INFO_sRGB)
  171261. #endif
  171262. )
  171263. {
  171264. png_warning(png_ptr, "Duplicate cHRM chunk");
  171265. png_crc_finish(png_ptr, length);
  171266. return;
  171267. }
  171268. if (length != 32)
  171269. {
  171270. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171271. png_crc_finish(png_ptr, length);
  171272. return;
  171273. }
  171274. png_crc_read(png_ptr, buf, 4);
  171275. uint_x = png_get_uint_32(buf);
  171276. png_crc_read(png_ptr, buf, 4);
  171277. uint_y = png_get_uint_32(buf);
  171278. if (uint_x > 80000L || uint_y > 80000L ||
  171279. uint_x + uint_y > 100000L)
  171280. {
  171281. png_warning(png_ptr, "Invalid cHRM white point");
  171282. png_crc_finish(png_ptr, 24);
  171283. return;
  171284. }
  171285. int_x_white = (png_fixed_point)uint_x;
  171286. int_y_white = (png_fixed_point)uint_y;
  171287. png_crc_read(png_ptr, buf, 4);
  171288. uint_x = png_get_uint_32(buf);
  171289. png_crc_read(png_ptr, buf, 4);
  171290. uint_y = png_get_uint_32(buf);
  171291. if (uint_x + uint_y > 100000L)
  171292. {
  171293. png_warning(png_ptr, "Invalid cHRM red point");
  171294. png_crc_finish(png_ptr, 16);
  171295. return;
  171296. }
  171297. int_x_red = (png_fixed_point)uint_x;
  171298. int_y_red = (png_fixed_point)uint_y;
  171299. png_crc_read(png_ptr, buf, 4);
  171300. uint_x = png_get_uint_32(buf);
  171301. png_crc_read(png_ptr, buf, 4);
  171302. uint_y = png_get_uint_32(buf);
  171303. if (uint_x + uint_y > 100000L)
  171304. {
  171305. png_warning(png_ptr, "Invalid cHRM green point");
  171306. png_crc_finish(png_ptr, 8);
  171307. return;
  171308. }
  171309. int_x_green = (png_fixed_point)uint_x;
  171310. int_y_green = (png_fixed_point)uint_y;
  171311. png_crc_read(png_ptr, buf, 4);
  171312. uint_x = png_get_uint_32(buf);
  171313. png_crc_read(png_ptr, buf, 4);
  171314. uint_y = png_get_uint_32(buf);
  171315. if (uint_x + uint_y > 100000L)
  171316. {
  171317. png_warning(png_ptr, "Invalid cHRM blue point");
  171318. png_crc_finish(png_ptr, 0);
  171319. return;
  171320. }
  171321. int_x_blue = (png_fixed_point)uint_x;
  171322. int_y_blue = (png_fixed_point)uint_y;
  171323. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171324. white_x = (float)int_x_white / (float)100000.0;
  171325. white_y = (float)int_y_white / (float)100000.0;
  171326. red_x = (float)int_x_red / (float)100000.0;
  171327. red_y = (float)int_y_red / (float)100000.0;
  171328. green_x = (float)int_x_green / (float)100000.0;
  171329. green_y = (float)int_y_green / (float)100000.0;
  171330. blue_x = (float)int_x_blue / (float)100000.0;
  171331. blue_y = (float)int_y_blue / (float)100000.0;
  171332. #endif
  171333. #if defined(PNG_READ_sRGB_SUPPORTED)
  171334. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171335. {
  171336. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171337. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171338. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171339. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171340. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171341. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171342. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171343. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171344. {
  171345. png_warning(png_ptr,
  171346. "Ignoring incorrect cHRM value when sRGB is also present");
  171347. #ifndef PNG_NO_CONSOLE_IO
  171348. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171349. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171350. white_x, white_y, red_x, red_y);
  171351. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171352. green_x, green_y, blue_x, blue_y);
  171353. #else
  171354. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171355. int_x_white, int_y_white, int_x_red, int_y_red);
  171356. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171357. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171358. #endif
  171359. #endif /* PNG_NO_CONSOLE_IO */
  171360. }
  171361. png_crc_finish(png_ptr, 0);
  171362. return;
  171363. }
  171364. #endif /* PNG_READ_sRGB_SUPPORTED */
  171365. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171366. png_set_cHRM(png_ptr, info_ptr,
  171367. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171368. #endif
  171369. #ifdef PNG_FIXED_POINT_SUPPORTED
  171370. png_set_cHRM_fixed(png_ptr, info_ptr,
  171371. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171372. int_y_green, int_x_blue, int_y_blue);
  171373. #endif
  171374. if (png_crc_finish(png_ptr, 0))
  171375. return;
  171376. }
  171377. #endif
  171378. #if defined(PNG_READ_sRGB_SUPPORTED)
  171379. void /* PRIVATE */
  171380. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171381. {
  171382. int intent;
  171383. png_byte buf[1];
  171384. png_debug(1, "in png_handle_sRGB\n");
  171385. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171386. png_error(png_ptr, "Missing IHDR before sRGB");
  171387. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171388. {
  171389. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171390. png_crc_finish(png_ptr, length);
  171391. return;
  171392. }
  171393. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171394. png_warning(png_ptr, "Out of place sRGB chunk");
  171395. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171396. {
  171397. png_warning(png_ptr, "Duplicate sRGB chunk");
  171398. png_crc_finish(png_ptr, length);
  171399. return;
  171400. }
  171401. if (length != 1)
  171402. {
  171403. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171404. png_crc_finish(png_ptr, length);
  171405. return;
  171406. }
  171407. png_crc_read(png_ptr, buf, 1);
  171408. if (png_crc_finish(png_ptr, 0))
  171409. return;
  171410. intent = buf[0];
  171411. if (intent >= PNG_sRGB_INTENT_LAST)
  171412. {
  171413. png_warning(png_ptr, "Unknown sRGB intent");
  171414. return;
  171415. }
  171416. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171417. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171418. {
  171419. png_fixed_point igamma;
  171420. #ifdef PNG_FIXED_POINT_SUPPORTED
  171421. igamma=info_ptr->int_gamma;
  171422. #else
  171423. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171424. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171425. # endif
  171426. #endif
  171427. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171428. {
  171429. png_warning(png_ptr,
  171430. "Ignoring incorrect gAMA value when sRGB is also present");
  171431. #ifndef PNG_NO_CONSOLE_IO
  171432. # ifdef PNG_FIXED_POINT_SUPPORTED
  171433. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171434. # else
  171435. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171436. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171437. # endif
  171438. # endif
  171439. #endif
  171440. }
  171441. }
  171442. #endif /* PNG_READ_gAMA_SUPPORTED */
  171443. #ifdef PNG_READ_cHRM_SUPPORTED
  171444. #ifdef PNG_FIXED_POINT_SUPPORTED
  171445. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171446. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171447. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171448. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171449. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171450. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171451. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171452. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171453. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171454. {
  171455. png_warning(png_ptr,
  171456. "Ignoring incorrect cHRM value when sRGB is also present");
  171457. }
  171458. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171459. #endif /* PNG_READ_cHRM_SUPPORTED */
  171460. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171461. }
  171462. #endif /* PNG_READ_sRGB_SUPPORTED */
  171463. #if defined(PNG_READ_iCCP_SUPPORTED)
  171464. void /* PRIVATE */
  171465. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171466. {
  171467. png_charp chunkdata;
  171468. png_byte compression_type;
  171469. png_bytep pC;
  171470. png_charp profile;
  171471. png_uint_32 skip = 0;
  171472. png_uint_32 profile_size, profile_length;
  171473. png_size_t slength, prefix_length, data_length;
  171474. png_debug(1, "in png_handle_iCCP\n");
  171475. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171476. png_error(png_ptr, "Missing IHDR before iCCP");
  171477. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171478. {
  171479. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171480. png_crc_finish(png_ptr, length);
  171481. return;
  171482. }
  171483. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171484. png_warning(png_ptr, "Out of place iCCP chunk");
  171485. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171486. {
  171487. png_warning(png_ptr, "Duplicate iCCP chunk");
  171488. png_crc_finish(png_ptr, length);
  171489. return;
  171490. }
  171491. #ifdef PNG_MAX_MALLOC_64K
  171492. if (length > (png_uint_32)65535L)
  171493. {
  171494. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171495. skip = length - (png_uint_32)65535L;
  171496. length = (png_uint_32)65535L;
  171497. }
  171498. #endif
  171499. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171500. slength = (png_size_t)length;
  171501. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171502. if (png_crc_finish(png_ptr, skip))
  171503. {
  171504. png_free(png_ptr, chunkdata);
  171505. return;
  171506. }
  171507. chunkdata[slength] = 0x00;
  171508. for (profile = chunkdata; *profile; profile++)
  171509. ;
  171510. ++profile;
  171511. if ( profile >= chunkdata + slength - 1)
  171512. {
  171513. png_free(png_ptr, chunkdata);
  171514. png_warning(png_ptr, "Malformed iCCP chunk");
  171515. return;
  171516. }
  171517. compression_type = *profile++;
  171518. if (compression_type)
  171519. {
  171520. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171521. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171522. wrote nonzero) */
  171523. }
  171524. prefix_length = profile - chunkdata;
  171525. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171526. slength, prefix_length, &data_length);
  171527. profile_length = data_length - prefix_length;
  171528. if ( prefix_length > data_length || profile_length < 4)
  171529. {
  171530. png_free(png_ptr, chunkdata);
  171531. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171532. return;
  171533. }
  171534. pC = (png_bytep)(chunkdata+prefix_length);
  171535. profile_size = ((*(pC ))<<24) |
  171536. ((*(pC+1))<<16) |
  171537. ((*(pC+2))<< 8) |
  171538. ((*(pC+3)) );
  171539. if(profile_size < profile_length)
  171540. profile_length = profile_size;
  171541. if(profile_size > profile_length)
  171542. {
  171543. png_free(png_ptr, chunkdata);
  171544. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171545. return;
  171546. }
  171547. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  171548. chunkdata + prefix_length, profile_length);
  171549. png_free(png_ptr, chunkdata);
  171550. }
  171551. #endif /* PNG_READ_iCCP_SUPPORTED */
  171552. #if defined(PNG_READ_sPLT_SUPPORTED)
  171553. void /* PRIVATE */
  171554. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171555. {
  171556. png_bytep chunkdata;
  171557. png_bytep entry_start;
  171558. png_sPLT_t new_palette;
  171559. #ifdef PNG_NO_POINTER_INDEXING
  171560. png_sPLT_entryp pp;
  171561. #endif
  171562. int data_length, entry_size, i;
  171563. png_uint_32 skip = 0;
  171564. png_size_t slength;
  171565. png_debug(1, "in png_handle_sPLT\n");
  171566. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171567. png_error(png_ptr, "Missing IHDR before sPLT");
  171568. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171569. {
  171570. png_warning(png_ptr, "Invalid sPLT after IDAT");
  171571. png_crc_finish(png_ptr, length);
  171572. return;
  171573. }
  171574. #ifdef PNG_MAX_MALLOC_64K
  171575. if (length > (png_uint_32)65535L)
  171576. {
  171577. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  171578. skip = length - (png_uint_32)65535L;
  171579. length = (png_uint_32)65535L;
  171580. }
  171581. #endif
  171582. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  171583. slength = (png_size_t)length;
  171584. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171585. if (png_crc_finish(png_ptr, skip))
  171586. {
  171587. png_free(png_ptr, chunkdata);
  171588. return;
  171589. }
  171590. chunkdata[slength] = 0x00;
  171591. for (entry_start = chunkdata; *entry_start; entry_start++)
  171592. ;
  171593. ++entry_start;
  171594. if (entry_start > chunkdata + slength - 2)
  171595. {
  171596. png_free(png_ptr, chunkdata);
  171597. png_warning(png_ptr, "malformed sPLT chunk");
  171598. return;
  171599. }
  171600. new_palette.depth = *entry_start++;
  171601. entry_size = (new_palette.depth == 8 ? 6 : 10);
  171602. data_length = (slength - (entry_start - chunkdata));
  171603. if (data_length % entry_size)
  171604. {
  171605. png_free(png_ptr, chunkdata);
  171606. png_warning(png_ptr, "sPLT chunk has bad length");
  171607. return;
  171608. }
  171609. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  171610. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  171611. png_sizeof(png_sPLT_entry)))
  171612. {
  171613. png_warning(png_ptr, "sPLT chunk too long");
  171614. return;
  171615. }
  171616. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  171617. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  171618. if (new_palette.entries == NULL)
  171619. {
  171620. png_warning(png_ptr, "sPLT chunk requires too much memory");
  171621. return;
  171622. }
  171623. #ifndef PNG_NO_POINTER_INDEXING
  171624. for (i = 0; i < new_palette.nentries; i++)
  171625. {
  171626. png_sPLT_entryp pp = new_palette.entries + i;
  171627. if (new_palette.depth == 8)
  171628. {
  171629. pp->red = *entry_start++;
  171630. pp->green = *entry_start++;
  171631. pp->blue = *entry_start++;
  171632. pp->alpha = *entry_start++;
  171633. }
  171634. else
  171635. {
  171636. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  171637. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  171638. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  171639. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  171640. }
  171641. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171642. }
  171643. #else
  171644. pp = new_palette.entries;
  171645. for (i = 0; i < new_palette.nentries; i++)
  171646. {
  171647. if (new_palette.depth == 8)
  171648. {
  171649. pp[i].red = *entry_start++;
  171650. pp[i].green = *entry_start++;
  171651. pp[i].blue = *entry_start++;
  171652. pp[i].alpha = *entry_start++;
  171653. }
  171654. else
  171655. {
  171656. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  171657. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  171658. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  171659. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  171660. }
  171661. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171662. }
  171663. #endif
  171664. new_palette.name = (png_charp)chunkdata;
  171665. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  171666. png_free(png_ptr, chunkdata);
  171667. png_free(png_ptr, new_palette.entries);
  171668. }
  171669. #endif /* PNG_READ_sPLT_SUPPORTED */
  171670. #if defined(PNG_READ_tRNS_SUPPORTED)
  171671. void /* PRIVATE */
  171672. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171673. {
  171674. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  171675. int bit_mask;
  171676. png_debug(1, "in png_handle_tRNS\n");
  171677. bit_mask = (1 << png_ptr->bit_depth) - 1;
  171678. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171679. png_error(png_ptr, "Missing IHDR before tRNS");
  171680. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171681. {
  171682. png_warning(png_ptr, "Invalid tRNS after IDAT");
  171683. png_crc_finish(png_ptr, length);
  171684. return;
  171685. }
  171686. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171687. {
  171688. png_warning(png_ptr, "Duplicate tRNS chunk");
  171689. png_crc_finish(png_ptr, length);
  171690. return;
  171691. }
  171692. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  171693. {
  171694. png_byte buf[2];
  171695. if (length != 2)
  171696. {
  171697. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171698. png_crc_finish(png_ptr, length);
  171699. return;
  171700. }
  171701. png_crc_read(png_ptr, buf, 2);
  171702. png_ptr->num_trans = 1;
  171703. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  171704. }
  171705. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  171706. {
  171707. png_byte buf[6];
  171708. if (length != 6)
  171709. {
  171710. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171711. png_crc_finish(png_ptr, length);
  171712. return;
  171713. }
  171714. png_crc_read(png_ptr, buf, (png_size_t)length);
  171715. png_ptr->num_trans = 1;
  171716. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  171717. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  171718. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  171719. }
  171720. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171721. {
  171722. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171723. {
  171724. png_warning(png_ptr, "Missing PLTE before tRNS");
  171725. }
  171726. if (length > (png_uint_32)png_ptr->num_palette ||
  171727. length > PNG_MAX_PALETTE_LENGTH)
  171728. {
  171729. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171730. png_crc_finish(png_ptr, length);
  171731. return;
  171732. }
  171733. if (length == 0)
  171734. {
  171735. png_warning(png_ptr, "Zero length tRNS chunk");
  171736. png_crc_finish(png_ptr, length);
  171737. return;
  171738. }
  171739. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  171740. png_ptr->num_trans = (png_uint_16)length;
  171741. }
  171742. else
  171743. {
  171744. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  171745. png_crc_finish(png_ptr, length);
  171746. return;
  171747. }
  171748. if (png_crc_finish(png_ptr, 0))
  171749. {
  171750. png_ptr->num_trans = 0;
  171751. return;
  171752. }
  171753. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  171754. &(png_ptr->trans_values));
  171755. }
  171756. #endif
  171757. #if defined(PNG_READ_bKGD_SUPPORTED)
  171758. void /* PRIVATE */
  171759. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171760. {
  171761. png_size_t truelen;
  171762. png_byte buf[6];
  171763. png_debug(1, "in png_handle_bKGD\n");
  171764. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171765. png_error(png_ptr, "Missing IHDR before bKGD");
  171766. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171767. {
  171768. png_warning(png_ptr, "Invalid bKGD after IDAT");
  171769. png_crc_finish(png_ptr, length);
  171770. return;
  171771. }
  171772. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  171773. !(png_ptr->mode & PNG_HAVE_PLTE))
  171774. {
  171775. png_warning(png_ptr, "Missing PLTE before bKGD");
  171776. png_crc_finish(png_ptr, length);
  171777. return;
  171778. }
  171779. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  171780. {
  171781. png_warning(png_ptr, "Duplicate bKGD chunk");
  171782. png_crc_finish(png_ptr, length);
  171783. return;
  171784. }
  171785. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171786. truelen = 1;
  171787. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171788. truelen = 6;
  171789. else
  171790. truelen = 2;
  171791. if (length != truelen)
  171792. {
  171793. png_warning(png_ptr, "Incorrect bKGD chunk length");
  171794. png_crc_finish(png_ptr, length);
  171795. return;
  171796. }
  171797. png_crc_read(png_ptr, buf, truelen);
  171798. if (png_crc_finish(png_ptr, 0))
  171799. return;
  171800. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171801. {
  171802. png_ptr->background.index = buf[0];
  171803. if(info_ptr->num_palette)
  171804. {
  171805. if(buf[0] > info_ptr->num_palette)
  171806. {
  171807. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  171808. return;
  171809. }
  171810. png_ptr->background.red =
  171811. (png_uint_16)png_ptr->palette[buf[0]].red;
  171812. png_ptr->background.green =
  171813. (png_uint_16)png_ptr->palette[buf[0]].green;
  171814. png_ptr->background.blue =
  171815. (png_uint_16)png_ptr->palette[buf[0]].blue;
  171816. }
  171817. }
  171818. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  171819. {
  171820. png_ptr->background.red =
  171821. png_ptr->background.green =
  171822. png_ptr->background.blue =
  171823. png_ptr->background.gray = png_get_uint_16(buf);
  171824. }
  171825. else
  171826. {
  171827. png_ptr->background.red = png_get_uint_16(buf);
  171828. png_ptr->background.green = png_get_uint_16(buf + 2);
  171829. png_ptr->background.blue = png_get_uint_16(buf + 4);
  171830. }
  171831. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  171832. }
  171833. #endif
  171834. #if defined(PNG_READ_hIST_SUPPORTED)
  171835. void /* PRIVATE */
  171836. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171837. {
  171838. unsigned int num, i;
  171839. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  171840. png_debug(1, "in png_handle_hIST\n");
  171841. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171842. png_error(png_ptr, "Missing IHDR before hIST");
  171843. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171844. {
  171845. png_warning(png_ptr, "Invalid hIST after IDAT");
  171846. png_crc_finish(png_ptr, length);
  171847. return;
  171848. }
  171849. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171850. {
  171851. png_warning(png_ptr, "Missing PLTE before hIST");
  171852. png_crc_finish(png_ptr, length);
  171853. return;
  171854. }
  171855. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  171856. {
  171857. png_warning(png_ptr, "Duplicate hIST chunk");
  171858. png_crc_finish(png_ptr, length);
  171859. return;
  171860. }
  171861. num = length / 2 ;
  171862. if (num != (unsigned int) png_ptr->num_palette || num >
  171863. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  171864. {
  171865. png_warning(png_ptr, "Incorrect hIST chunk length");
  171866. png_crc_finish(png_ptr, length);
  171867. return;
  171868. }
  171869. for (i = 0; i < num; i++)
  171870. {
  171871. png_byte buf[2];
  171872. png_crc_read(png_ptr, buf, 2);
  171873. readbuf[i] = png_get_uint_16(buf);
  171874. }
  171875. if (png_crc_finish(png_ptr, 0))
  171876. return;
  171877. png_set_hIST(png_ptr, info_ptr, readbuf);
  171878. }
  171879. #endif
  171880. #if defined(PNG_READ_pHYs_SUPPORTED)
  171881. void /* PRIVATE */
  171882. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171883. {
  171884. png_byte buf[9];
  171885. png_uint_32 res_x, res_y;
  171886. int unit_type;
  171887. png_debug(1, "in png_handle_pHYs\n");
  171888. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171889. png_error(png_ptr, "Missing IHDR before pHYs");
  171890. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171891. {
  171892. png_warning(png_ptr, "Invalid pHYs after IDAT");
  171893. png_crc_finish(png_ptr, length);
  171894. return;
  171895. }
  171896. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  171897. {
  171898. png_warning(png_ptr, "Duplicate pHYs chunk");
  171899. png_crc_finish(png_ptr, length);
  171900. return;
  171901. }
  171902. if (length != 9)
  171903. {
  171904. png_warning(png_ptr, "Incorrect pHYs chunk length");
  171905. png_crc_finish(png_ptr, length);
  171906. return;
  171907. }
  171908. png_crc_read(png_ptr, buf, 9);
  171909. if (png_crc_finish(png_ptr, 0))
  171910. return;
  171911. res_x = png_get_uint_32(buf);
  171912. res_y = png_get_uint_32(buf + 4);
  171913. unit_type = buf[8];
  171914. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  171915. }
  171916. #endif
  171917. #if defined(PNG_READ_oFFs_SUPPORTED)
  171918. void /* PRIVATE */
  171919. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171920. {
  171921. png_byte buf[9];
  171922. png_int_32 offset_x, offset_y;
  171923. int unit_type;
  171924. png_debug(1, "in png_handle_oFFs\n");
  171925. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171926. png_error(png_ptr, "Missing IHDR before oFFs");
  171927. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171928. {
  171929. png_warning(png_ptr, "Invalid oFFs after IDAT");
  171930. png_crc_finish(png_ptr, length);
  171931. return;
  171932. }
  171933. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  171934. {
  171935. png_warning(png_ptr, "Duplicate oFFs chunk");
  171936. png_crc_finish(png_ptr, length);
  171937. return;
  171938. }
  171939. if (length != 9)
  171940. {
  171941. png_warning(png_ptr, "Incorrect oFFs chunk length");
  171942. png_crc_finish(png_ptr, length);
  171943. return;
  171944. }
  171945. png_crc_read(png_ptr, buf, 9);
  171946. if (png_crc_finish(png_ptr, 0))
  171947. return;
  171948. offset_x = png_get_int_32(buf);
  171949. offset_y = png_get_int_32(buf + 4);
  171950. unit_type = buf[8];
  171951. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  171952. }
  171953. #endif
  171954. #if defined(PNG_READ_pCAL_SUPPORTED)
  171955. void /* PRIVATE */
  171956. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171957. {
  171958. png_charp purpose;
  171959. png_int_32 X0, X1;
  171960. png_byte type, nparams;
  171961. png_charp buf, units, endptr;
  171962. png_charpp params;
  171963. png_size_t slength;
  171964. int i;
  171965. png_debug(1, "in png_handle_pCAL\n");
  171966. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171967. png_error(png_ptr, "Missing IHDR before pCAL");
  171968. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171969. {
  171970. png_warning(png_ptr, "Invalid pCAL after IDAT");
  171971. png_crc_finish(png_ptr, length);
  171972. return;
  171973. }
  171974. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  171975. {
  171976. png_warning(png_ptr, "Duplicate pCAL chunk");
  171977. png_crc_finish(png_ptr, length);
  171978. return;
  171979. }
  171980. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  171981. length + 1);
  171982. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  171983. if (purpose == NULL)
  171984. {
  171985. png_warning(png_ptr, "No memory for pCAL purpose.");
  171986. return;
  171987. }
  171988. slength = (png_size_t)length;
  171989. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  171990. if (png_crc_finish(png_ptr, 0))
  171991. {
  171992. png_free(png_ptr, purpose);
  171993. return;
  171994. }
  171995. purpose[slength] = 0x00; /* null terminate the last string */
  171996. png_debug(3, "Finding end of pCAL purpose string\n");
  171997. for (buf = purpose; *buf; buf++)
  171998. ;
  171999. endptr = purpose + slength;
  172000. if (endptr <= buf + 12)
  172001. {
  172002. png_warning(png_ptr, "Invalid pCAL data");
  172003. png_free(png_ptr, purpose);
  172004. return;
  172005. }
  172006. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  172007. X0 = png_get_int_32((png_bytep)buf+1);
  172008. X1 = png_get_int_32((png_bytep)buf+5);
  172009. type = buf[9];
  172010. nparams = buf[10];
  172011. units = buf + 11;
  172012. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172013. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172014. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172015. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172016. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172017. {
  172018. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172019. png_free(png_ptr, purpose);
  172020. return;
  172021. }
  172022. else if (type >= PNG_EQUATION_LAST)
  172023. {
  172024. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172025. }
  172026. for (buf = units; *buf; buf++)
  172027. ;
  172028. png_debug(3, "Allocating pCAL parameters array\n");
  172029. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172030. *png_sizeof(png_charp))) ;
  172031. if (params == NULL)
  172032. {
  172033. png_free(png_ptr, purpose);
  172034. png_warning(png_ptr, "No memory for pCAL params.");
  172035. return;
  172036. }
  172037. for (i = 0; i < (int)nparams; i++)
  172038. {
  172039. buf++; /* Skip the null string terminator from previous parameter. */
  172040. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172041. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172042. ;
  172043. if (buf > endptr)
  172044. {
  172045. png_warning(png_ptr, "Invalid pCAL data");
  172046. png_free(png_ptr, purpose);
  172047. png_free(png_ptr, params);
  172048. return;
  172049. }
  172050. }
  172051. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172052. units, params);
  172053. png_free(png_ptr, purpose);
  172054. png_free(png_ptr, params);
  172055. }
  172056. #endif
  172057. #if defined(PNG_READ_sCAL_SUPPORTED)
  172058. void /* PRIVATE */
  172059. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172060. {
  172061. png_charp buffer, ep;
  172062. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172063. double width, height;
  172064. png_charp vp;
  172065. #else
  172066. #ifdef PNG_FIXED_POINT_SUPPORTED
  172067. png_charp swidth, sheight;
  172068. #endif
  172069. #endif
  172070. png_size_t slength;
  172071. png_debug(1, "in png_handle_sCAL\n");
  172072. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172073. png_error(png_ptr, "Missing IHDR before sCAL");
  172074. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172075. {
  172076. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172077. png_crc_finish(png_ptr, length);
  172078. return;
  172079. }
  172080. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172081. {
  172082. png_warning(png_ptr, "Duplicate sCAL chunk");
  172083. png_crc_finish(png_ptr, length);
  172084. return;
  172085. }
  172086. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172087. length + 1);
  172088. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172089. if (buffer == NULL)
  172090. {
  172091. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172092. return;
  172093. }
  172094. slength = (png_size_t)length;
  172095. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172096. if (png_crc_finish(png_ptr, 0))
  172097. {
  172098. png_free(png_ptr, buffer);
  172099. return;
  172100. }
  172101. buffer[slength] = 0x00; /* null terminate the last string */
  172102. ep = buffer + 1; /* skip unit byte */
  172103. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172104. width = png_strtod(png_ptr, ep, &vp);
  172105. if (*vp)
  172106. {
  172107. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172108. return;
  172109. }
  172110. #else
  172111. #ifdef PNG_FIXED_POINT_SUPPORTED
  172112. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172113. if (swidth == NULL)
  172114. {
  172115. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172116. return;
  172117. }
  172118. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172119. #endif
  172120. #endif
  172121. for (ep = buffer; *ep; ep++)
  172122. ;
  172123. ep++;
  172124. if (buffer + slength < ep)
  172125. {
  172126. png_warning(png_ptr, "Truncated sCAL chunk");
  172127. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172128. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172129. png_free(png_ptr, swidth);
  172130. #endif
  172131. png_free(png_ptr, buffer);
  172132. return;
  172133. }
  172134. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172135. height = png_strtod(png_ptr, ep, &vp);
  172136. if (*vp)
  172137. {
  172138. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172139. return;
  172140. }
  172141. #else
  172142. #ifdef PNG_FIXED_POINT_SUPPORTED
  172143. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172144. if (swidth == NULL)
  172145. {
  172146. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172147. return;
  172148. }
  172149. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172150. #endif
  172151. #endif
  172152. if (buffer + slength < ep
  172153. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172154. || width <= 0. || height <= 0.
  172155. #endif
  172156. )
  172157. {
  172158. png_warning(png_ptr, "Invalid sCAL data");
  172159. png_free(png_ptr, buffer);
  172160. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172161. png_free(png_ptr, swidth);
  172162. png_free(png_ptr, sheight);
  172163. #endif
  172164. return;
  172165. }
  172166. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172167. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172168. #else
  172169. #ifdef PNG_FIXED_POINT_SUPPORTED
  172170. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172171. #endif
  172172. #endif
  172173. png_free(png_ptr, buffer);
  172174. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172175. png_free(png_ptr, swidth);
  172176. png_free(png_ptr, sheight);
  172177. #endif
  172178. }
  172179. #endif
  172180. #if defined(PNG_READ_tIME_SUPPORTED)
  172181. void /* PRIVATE */
  172182. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172183. {
  172184. png_byte buf[7];
  172185. png_time mod_time;
  172186. png_debug(1, "in png_handle_tIME\n");
  172187. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172188. png_error(png_ptr, "Out of place tIME chunk");
  172189. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172190. {
  172191. png_warning(png_ptr, "Duplicate tIME chunk");
  172192. png_crc_finish(png_ptr, length);
  172193. return;
  172194. }
  172195. if (png_ptr->mode & PNG_HAVE_IDAT)
  172196. png_ptr->mode |= PNG_AFTER_IDAT;
  172197. if (length != 7)
  172198. {
  172199. png_warning(png_ptr, "Incorrect tIME chunk length");
  172200. png_crc_finish(png_ptr, length);
  172201. return;
  172202. }
  172203. png_crc_read(png_ptr, buf, 7);
  172204. if (png_crc_finish(png_ptr, 0))
  172205. return;
  172206. mod_time.second = buf[6];
  172207. mod_time.minute = buf[5];
  172208. mod_time.hour = buf[4];
  172209. mod_time.day = buf[3];
  172210. mod_time.month = buf[2];
  172211. mod_time.year = png_get_uint_16(buf);
  172212. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172213. }
  172214. #endif
  172215. #if defined(PNG_READ_tEXt_SUPPORTED)
  172216. void /* PRIVATE */
  172217. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172218. {
  172219. png_textp text_ptr;
  172220. png_charp key;
  172221. png_charp text;
  172222. png_uint_32 skip = 0;
  172223. png_size_t slength;
  172224. int ret;
  172225. png_debug(1, "in png_handle_tEXt\n");
  172226. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172227. png_error(png_ptr, "Missing IHDR before tEXt");
  172228. if (png_ptr->mode & PNG_HAVE_IDAT)
  172229. png_ptr->mode |= PNG_AFTER_IDAT;
  172230. #ifdef PNG_MAX_MALLOC_64K
  172231. if (length > (png_uint_32)65535L)
  172232. {
  172233. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172234. skip = length - (png_uint_32)65535L;
  172235. length = (png_uint_32)65535L;
  172236. }
  172237. #endif
  172238. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172239. if (key == NULL)
  172240. {
  172241. png_warning(png_ptr, "No memory to process text chunk.");
  172242. return;
  172243. }
  172244. slength = (png_size_t)length;
  172245. png_crc_read(png_ptr, (png_bytep)key, slength);
  172246. if (png_crc_finish(png_ptr, skip))
  172247. {
  172248. png_free(png_ptr, key);
  172249. return;
  172250. }
  172251. key[slength] = 0x00;
  172252. for (text = key; *text; text++)
  172253. ;
  172254. if (text != key + slength)
  172255. text++;
  172256. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172257. (png_uint_32)png_sizeof(png_text));
  172258. if (text_ptr == NULL)
  172259. {
  172260. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172261. png_free(png_ptr, key);
  172262. return;
  172263. }
  172264. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172265. text_ptr->key = key;
  172266. #ifdef PNG_iTXt_SUPPORTED
  172267. text_ptr->lang = NULL;
  172268. text_ptr->lang_key = NULL;
  172269. text_ptr->itxt_length = 0;
  172270. #endif
  172271. text_ptr->text = text;
  172272. text_ptr->text_length = png_strlen(text);
  172273. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172274. png_free(png_ptr, key);
  172275. png_free(png_ptr, text_ptr);
  172276. if (ret)
  172277. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172278. }
  172279. #endif
  172280. #if defined(PNG_READ_zTXt_SUPPORTED)
  172281. void /* PRIVATE */
  172282. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172283. {
  172284. png_textp text_ptr;
  172285. png_charp chunkdata;
  172286. png_charp text;
  172287. int comp_type;
  172288. int ret;
  172289. png_size_t slength, prefix_len, data_len;
  172290. png_debug(1, "in png_handle_zTXt\n");
  172291. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172292. png_error(png_ptr, "Missing IHDR before zTXt");
  172293. if (png_ptr->mode & PNG_HAVE_IDAT)
  172294. png_ptr->mode |= PNG_AFTER_IDAT;
  172295. #ifdef PNG_MAX_MALLOC_64K
  172296. if (length > (png_uint_32)65535L)
  172297. {
  172298. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172299. png_crc_finish(png_ptr, length);
  172300. return;
  172301. }
  172302. #endif
  172303. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172304. if (chunkdata == NULL)
  172305. {
  172306. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172307. return;
  172308. }
  172309. slength = (png_size_t)length;
  172310. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172311. if (png_crc_finish(png_ptr, 0))
  172312. {
  172313. png_free(png_ptr, chunkdata);
  172314. return;
  172315. }
  172316. chunkdata[slength] = 0x00;
  172317. for (text = chunkdata; *text; text++)
  172318. ;
  172319. if (text >= chunkdata + slength - 2)
  172320. {
  172321. png_warning(png_ptr, "Truncated zTXt chunk");
  172322. png_free(png_ptr, chunkdata);
  172323. return;
  172324. }
  172325. else
  172326. {
  172327. comp_type = *(++text);
  172328. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172329. {
  172330. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172331. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172332. }
  172333. text++; /* skip the compression_method byte */
  172334. }
  172335. prefix_len = text - chunkdata;
  172336. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172337. (png_size_t)length, prefix_len, &data_len);
  172338. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172339. (png_uint_32)png_sizeof(png_text));
  172340. if (text_ptr == NULL)
  172341. {
  172342. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172343. png_free(png_ptr, chunkdata);
  172344. return;
  172345. }
  172346. text_ptr->compression = comp_type;
  172347. text_ptr->key = chunkdata;
  172348. #ifdef PNG_iTXt_SUPPORTED
  172349. text_ptr->lang = NULL;
  172350. text_ptr->lang_key = NULL;
  172351. text_ptr->itxt_length = 0;
  172352. #endif
  172353. text_ptr->text = chunkdata + prefix_len;
  172354. text_ptr->text_length = data_len;
  172355. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172356. png_free(png_ptr, text_ptr);
  172357. png_free(png_ptr, chunkdata);
  172358. if (ret)
  172359. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172360. }
  172361. #endif
  172362. #if defined(PNG_READ_iTXt_SUPPORTED)
  172363. void /* PRIVATE */
  172364. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172365. {
  172366. png_textp text_ptr;
  172367. png_charp chunkdata;
  172368. png_charp key, lang, text, lang_key;
  172369. int comp_flag;
  172370. int comp_type = 0;
  172371. int ret;
  172372. png_size_t slength, prefix_len, data_len;
  172373. png_debug(1, "in png_handle_iTXt\n");
  172374. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172375. png_error(png_ptr, "Missing IHDR before iTXt");
  172376. if (png_ptr->mode & PNG_HAVE_IDAT)
  172377. png_ptr->mode |= PNG_AFTER_IDAT;
  172378. #ifdef PNG_MAX_MALLOC_64K
  172379. if (length > (png_uint_32)65535L)
  172380. {
  172381. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172382. png_crc_finish(png_ptr, length);
  172383. return;
  172384. }
  172385. #endif
  172386. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172387. if (chunkdata == NULL)
  172388. {
  172389. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172390. return;
  172391. }
  172392. slength = (png_size_t)length;
  172393. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172394. if (png_crc_finish(png_ptr, 0))
  172395. {
  172396. png_free(png_ptr, chunkdata);
  172397. return;
  172398. }
  172399. chunkdata[slength] = 0x00;
  172400. for (lang = chunkdata; *lang; lang++)
  172401. ;
  172402. lang++; /* skip NUL separator */
  172403. if (lang >= chunkdata + slength - 3)
  172404. {
  172405. png_warning(png_ptr, "Truncated iTXt chunk");
  172406. png_free(png_ptr, chunkdata);
  172407. return;
  172408. }
  172409. else
  172410. {
  172411. comp_flag = *lang++;
  172412. comp_type = *lang++;
  172413. }
  172414. for (lang_key = lang; *lang_key; lang_key++)
  172415. ;
  172416. lang_key++; /* skip NUL separator */
  172417. if (lang_key >= chunkdata + slength)
  172418. {
  172419. png_warning(png_ptr, "Truncated iTXt chunk");
  172420. png_free(png_ptr, chunkdata);
  172421. return;
  172422. }
  172423. for (text = lang_key; *text; text++)
  172424. ;
  172425. text++; /* skip NUL separator */
  172426. if (text >= chunkdata + slength)
  172427. {
  172428. png_warning(png_ptr, "Malformed iTXt chunk");
  172429. png_free(png_ptr, chunkdata);
  172430. return;
  172431. }
  172432. prefix_len = text - chunkdata;
  172433. key=chunkdata;
  172434. if (comp_flag)
  172435. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172436. (size_t)length, prefix_len, &data_len);
  172437. else
  172438. data_len=png_strlen(chunkdata + prefix_len);
  172439. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172440. (png_uint_32)png_sizeof(png_text));
  172441. if (text_ptr == NULL)
  172442. {
  172443. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172444. png_free(png_ptr, chunkdata);
  172445. return;
  172446. }
  172447. text_ptr->compression = (int)comp_flag + 1;
  172448. text_ptr->lang_key = chunkdata+(lang_key-key);
  172449. text_ptr->lang = chunkdata+(lang-key);
  172450. text_ptr->itxt_length = data_len;
  172451. text_ptr->text_length = 0;
  172452. text_ptr->key = chunkdata;
  172453. text_ptr->text = chunkdata + prefix_len;
  172454. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172455. png_free(png_ptr, text_ptr);
  172456. png_free(png_ptr, chunkdata);
  172457. if (ret)
  172458. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172459. }
  172460. #endif
  172461. void /* PRIVATE */
  172462. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172463. {
  172464. png_uint_32 skip = 0;
  172465. png_debug(1, "in png_handle_unknown\n");
  172466. if (png_ptr->mode & PNG_HAVE_IDAT)
  172467. {
  172468. #ifdef PNG_USE_LOCAL_ARRAYS
  172469. PNG_CONST PNG_IDAT;
  172470. #endif
  172471. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172472. png_ptr->mode |= PNG_AFTER_IDAT;
  172473. }
  172474. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172475. if (!(png_ptr->chunk_name[0] & 0x20))
  172476. {
  172477. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172478. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172479. PNG_HANDLE_CHUNK_ALWAYS
  172480. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172481. && png_ptr->read_user_chunk_fn == NULL
  172482. #endif
  172483. )
  172484. #endif
  172485. png_chunk_error(png_ptr, "unknown critical chunk");
  172486. }
  172487. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172488. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172489. (png_ptr->read_user_chunk_fn != NULL))
  172490. {
  172491. #ifdef PNG_MAX_MALLOC_64K
  172492. if (length > (png_uint_32)65535L)
  172493. {
  172494. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172495. skip = length - (png_uint_32)65535L;
  172496. length = (png_uint_32)65535L;
  172497. }
  172498. #endif
  172499. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172500. (png_charp)png_ptr->chunk_name, 5);
  172501. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172502. png_ptr->unknown_chunk.size = (png_size_t)length;
  172503. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172504. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172505. if(png_ptr->read_user_chunk_fn != NULL)
  172506. {
  172507. int ret;
  172508. ret = (*(png_ptr->read_user_chunk_fn))
  172509. (png_ptr, &png_ptr->unknown_chunk);
  172510. if (ret < 0)
  172511. png_chunk_error(png_ptr, "error in user chunk");
  172512. if (ret == 0)
  172513. {
  172514. if (!(png_ptr->chunk_name[0] & 0x20))
  172515. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172516. PNG_HANDLE_CHUNK_ALWAYS)
  172517. png_chunk_error(png_ptr, "unknown critical chunk");
  172518. png_set_unknown_chunks(png_ptr, info_ptr,
  172519. &png_ptr->unknown_chunk, 1);
  172520. }
  172521. }
  172522. #else
  172523. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172524. #endif
  172525. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172526. png_ptr->unknown_chunk.data = NULL;
  172527. }
  172528. else
  172529. #endif
  172530. skip = length;
  172531. png_crc_finish(png_ptr, skip);
  172532. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172533. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172534. #endif
  172535. }
  172536. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172537. void /* PRIVATE */
  172538. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172539. {
  172540. png_debug(1, "in png_check_chunk_name\n");
  172541. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172542. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172543. {
  172544. png_chunk_error(png_ptr, "invalid chunk type");
  172545. }
  172546. }
  172547. void /* PRIVATE */
  172548. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  172549. {
  172550. png_debug(1,"in png_combine_row\n");
  172551. if (mask == 0xff)
  172552. {
  172553. png_memcpy(row, png_ptr->row_buf + 1,
  172554. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  172555. }
  172556. else
  172557. {
  172558. switch (png_ptr->row_info.pixel_depth)
  172559. {
  172560. case 1:
  172561. {
  172562. png_bytep sp = png_ptr->row_buf + 1;
  172563. png_bytep dp = row;
  172564. int s_inc, s_start, s_end;
  172565. int m = 0x80;
  172566. int shift;
  172567. png_uint_32 i;
  172568. png_uint_32 row_width = png_ptr->width;
  172569. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172570. if (png_ptr->transformations & PNG_PACKSWAP)
  172571. {
  172572. s_start = 0;
  172573. s_end = 7;
  172574. s_inc = 1;
  172575. }
  172576. else
  172577. #endif
  172578. {
  172579. s_start = 7;
  172580. s_end = 0;
  172581. s_inc = -1;
  172582. }
  172583. shift = s_start;
  172584. for (i = 0; i < row_width; i++)
  172585. {
  172586. if (m & mask)
  172587. {
  172588. int value;
  172589. value = (*sp >> shift) & 0x01;
  172590. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  172591. *dp |= (png_byte)(value << shift);
  172592. }
  172593. if (shift == s_end)
  172594. {
  172595. shift = s_start;
  172596. sp++;
  172597. dp++;
  172598. }
  172599. else
  172600. shift += s_inc;
  172601. if (m == 1)
  172602. m = 0x80;
  172603. else
  172604. m >>= 1;
  172605. }
  172606. break;
  172607. }
  172608. case 2:
  172609. {
  172610. png_bytep sp = png_ptr->row_buf + 1;
  172611. png_bytep dp = row;
  172612. int s_start, s_end, s_inc;
  172613. int m = 0x80;
  172614. int shift;
  172615. png_uint_32 i;
  172616. png_uint_32 row_width = png_ptr->width;
  172617. int value;
  172618. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172619. if (png_ptr->transformations & PNG_PACKSWAP)
  172620. {
  172621. s_start = 0;
  172622. s_end = 6;
  172623. s_inc = 2;
  172624. }
  172625. else
  172626. #endif
  172627. {
  172628. s_start = 6;
  172629. s_end = 0;
  172630. s_inc = -2;
  172631. }
  172632. shift = s_start;
  172633. for (i = 0; i < row_width; i++)
  172634. {
  172635. if (m & mask)
  172636. {
  172637. value = (*sp >> shift) & 0x03;
  172638. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  172639. *dp |= (png_byte)(value << shift);
  172640. }
  172641. if (shift == s_end)
  172642. {
  172643. shift = s_start;
  172644. sp++;
  172645. dp++;
  172646. }
  172647. else
  172648. shift += s_inc;
  172649. if (m == 1)
  172650. m = 0x80;
  172651. else
  172652. m >>= 1;
  172653. }
  172654. break;
  172655. }
  172656. case 4:
  172657. {
  172658. png_bytep sp = png_ptr->row_buf + 1;
  172659. png_bytep dp = row;
  172660. int s_start, s_end, s_inc;
  172661. int m = 0x80;
  172662. int shift;
  172663. png_uint_32 i;
  172664. png_uint_32 row_width = png_ptr->width;
  172665. int value;
  172666. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172667. if (png_ptr->transformations & PNG_PACKSWAP)
  172668. {
  172669. s_start = 0;
  172670. s_end = 4;
  172671. s_inc = 4;
  172672. }
  172673. else
  172674. #endif
  172675. {
  172676. s_start = 4;
  172677. s_end = 0;
  172678. s_inc = -4;
  172679. }
  172680. shift = s_start;
  172681. for (i = 0; i < row_width; i++)
  172682. {
  172683. if (m & mask)
  172684. {
  172685. value = (*sp >> shift) & 0xf;
  172686. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  172687. *dp |= (png_byte)(value << shift);
  172688. }
  172689. if (shift == s_end)
  172690. {
  172691. shift = s_start;
  172692. sp++;
  172693. dp++;
  172694. }
  172695. else
  172696. shift += s_inc;
  172697. if (m == 1)
  172698. m = 0x80;
  172699. else
  172700. m >>= 1;
  172701. }
  172702. break;
  172703. }
  172704. default:
  172705. {
  172706. png_bytep sp = png_ptr->row_buf + 1;
  172707. png_bytep dp = row;
  172708. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  172709. png_uint_32 i;
  172710. png_uint_32 row_width = png_ptr->width;
  172711. png_byte m = 0x80;
  172712. for (i = 0; i < row_width; i++)
  172713. {
  172714. if (m & mask)
  172715. {
  172716. png_memcpy(dp, sp, pixel_bytes);
  172717. }
  172718. sp += pixel_bytes;
  172719. dp += pixel_bytes;
  172720. if (m == 1)
  172721. m = 0x80;
  172722. else
  172723. m >>= 1;
  172724. }
  172725. break;
  172726. }
  172727. }
  172728. }
  172729. }
  172730. #ifdef PNG_READ_INTERLACING_SUPPORTED
  172731. void /* PRIVATE */
  172732. png_do_read_interlace(png_structp png_ptr)
  172733. {
  172734. png_row_infop row_info = &(png_ptr->row_info);
  172735. png_bytep row = png_ptr->row_buf + 1;
  172736. int pass = png_ptr->pass;
  172737. png_uint_32 transformations = png_ptr->transformations;
  172738. #ifdef PNG_USE_LOCAL_ARRAYS
  172739. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172740. #endif
  172741. png_debug(1,"in png_do_read_interlace\n");
  172742. if (row != NULL && row_info != NULL)
  172743. {
  172744. png_uint_32 final_width;
  172745. final_width = row_info->width * png_pass_inc[pass];
  172746. switch (row_info->pixel_depth)
  172747. {
  172748. case 1:
  172749. {
  172750. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  172751. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  172752. int sshift, dshift;
  172753. int s_start, s_end, s_inc;
  172754. int jstop = png_pass_inc[pass];
  172755. png_byte v;
  172756. png_uint_32 i;
  172757. int j;
  172758. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172759. if (transformations & PNG_PACKSWAP)
  172760. {
  172761. sshift = (int)((row_info->width + 7) & 0x07);
  172762. dshift = (int)((final_width + 7) & 0x07);
  172763. s_start = 7;
  172764. s_end = 0;
  172765. s_inc = -1;
  172766. }
  172767. else
  172768. #endif
  172769. {
  172770. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  172771. dshift = 7 - (int)((final_width + 7) & 0x07);
  172772. s_start = 0;
  172773. s_end = 7;
  172774. s_inc = 1;
  172775. }
  172776. for (i = 0; i < row_info->width; i++)
  172777. {
  172778. v = (png_byte)((*sp >> sshift) & 0x01);
  172779. for (j = 0; j < jstop; j++)
  172780. {
  172781. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  172782. *dp |= (png_byte)(v << dshift);
  172783. if (dshift == s_end)
  172784. {
  172785. dshift = s_start;
  172786. dp--;
  172787. }
  172788. else
  172789. dshift += s_inc;
  172790. }
  172791. if (sshift == s_end)
  172792. {
  172793. sshift = s_start;
  172794. sp--;
  172795. }
  172796. else
  172797. sshift += s_inc;
  172798. }
  172799. break;
  172800. }
  172801. case 2:
  172802. {
  172803. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  172804. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  172805. int sshift, dshift;
  172806. int s_start, s_end, s_inc;
  172807. int jstop = png_pass_inc[pass];
  172808. png_uint_32 i;
  172809. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172810. if (transformations & PNG_PACKSWAP)
  172811. {
  172812. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  172813. dshift = (int)(((final_width + 3) & 0x03) << 1);
  172814. s_start = 6;
  172815. s_end = 0;
  172816. s_inc = -2;
  172817. }
  172818. else
  172819. #endif
  172820. {
  172821. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  172822. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  172823. s_start = 0;
  172824. s_end = 6;
  172825. s_inc = 2;
  172826. }
  172827. for (i = 0; i < row_info->width; i++)
  172828. {
  172829. png_byte v;
  172830. int j;
  172831. v = (png_byte)((*sp >> sshift) & 0x03);
  172832. for (j = 0; j < jstop; j++)
  172833. {
  172834. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  172835. *dp |= (png_byte)(v << dshift);
  172836. if (dshift == s_end)
  172837. {
  172838. dshift = s_start;
  172839. dp--;
  172840. }
  172841. else
  172842. dshift += s_inc;
  172843. }
  172844. if (sshift == s_end)
  172845. {
  172846. sshift = s_start;
  172847. sp--;
  172848. }
  172849. else
  172850. sshift += s_inc;
  172851. }
  172852. break;
  172853. }
  172854. case 4:
  172855. {
  172856. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  172857. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  172858. int sshift, dshift;
  172859. int s_start, s_end, s_inc;
  172860. png_uint_32 i;
  172861. int jstop = png_pass_inc[pass];
  172862. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172863. if (transformations & PNG_PACKSWAP)
  172864. {
  172865. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  172866. dshift = (int)(((final_width + 1) & 0x01) << 2);
  172867. s_start = 4;
  172868. s_end = 0;
  172869. s_inc = -4;
  172870. }
  172871. else
  172872. #endif
  172873. {
  172874. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  172875. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  172876. s_start = 0;
  172877. s_end = 4;
  172878. s_inc = 4;
  172879. }
  172880. for (i = 0; i < row_info->width; i++)
  172881. {
  172882. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  172883. int j;
  172884. for (j = 0; j < jstop; j++)
  172885. {
  172886. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  172887. *dp |= (png_byte)(v << dshift);
  172888. if (dshift == s_end)
  172889. {
  172890. dshift = s_start;
  172891. dp--;
  172892. }
  172893. else
  172894. dshift += s_inc;
  172895. }
  172896. if (sshift == s_end)
  172897. {
  172898. sshift = s_start;
  172899. sp--;
  172900. }
  172901. else
  172902. sshift += s_inc;
  172903. }
  172904. break;
  172905. }
  172906. default:
  172907. {
  172908. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  172909. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  172910. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  172911. int jstop = png_pass_inc[pass];
  172912. png_uint_32 i;
  172913. for (i = 0; i < row_info->width; i++)
  172914. {
  172915. png_byte v[8];
  172916. int j;
  172917. png_memcpy(v, sp, pixel_bytes);
  172918. for (j = 0; j < jstop; j++)
  172919. {
  172920. png_memcpy(dp, v, pixel_bytes);
  172921. dp -= pixel_bytes;
  172922. }
  172923. sp -= pixel_bytes;
  172924. }
  172925. break;
  172926. }
  172927. }
  172928. row_info->width = final_width;
  172929. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  172930. }
  172931. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  172932. transformations = transformations; /* silence compiler warning */
  172933. #endif
  172934. }
  172935. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  172936. void /* PRIVATE */
  172937. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  172938. png_bytep prev_row, int filter)
  172939. {
  172940. png_debug(1, "in png_read_filter_row\n");
  172941. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  172942. switch (filter)
  172943. {
  172944. case PNG_FILTER_VALUE_NONE:
  172945. break;
  172946. case PNG_FILTER_VALUE_SUB:
  172947. {
  172948. png_uint_32 i;
  172949. png_uint_32 istop = row_info->rowbytes;
  172950. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172951. png_bytep rp = row + bpp;
  172952. png_bytep lp = row;
  172953. for (i = bpp; i < istop; i++)
  172954. {
  172955. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  172956. rp++;
  172957. }
  172958. break;
  172959. }
  172960. case PNG_FILTER_VALUE_UP:
  172961. {
  172962. png_uint_32 i;
  172963. png_uint_32 istop = row_info->rowbytes;
  172964. png_bytep rp = row;
  172965. png_bytep pp = prev_row;
  172966. for (i = 0; i < istop; i++)
  172967. {
  172968. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  172969. rp++;
  172970. }
  172971. break;
  172972. }
  172973. case PNG_FILTER_VALUE_AVG:
  172974. {
  172975. png_uint_32 i;
  172976. png_bytep rp = row;
  172977. png_bytep pp = prev_row;
  172978. png_bytep lp = row;
  172979. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172980. png_uint_32 istop = row_info->rowbytes - bpp;
  172981. for (i = 0; i < bpp; i++)
  172982. {
  172983. *rp = (png_byte)(((int)(*rp) +
  172984. ((int)(*pp++) / 2 )) & 0xff);
  172985. rp++;
  172986. }
  172987. for (i = 0; i < istop; i++)
  172988. {
  172989. *rp = (png_byte)(((int)(*rp) +
  172990. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  172991. rp++;
  172992. }
  172993. break;
  172994. }
  172995. case PNG_FILTER_VALUE_PAETH:
  172996. {
  172997. png_uint_32 i;
  172998. png_bytep rp = row;
  172999. png_bytep pp = prev_row;
  173000. png_bytep lp = row;
  173001. png_bytep cp = prev_row;
  173002. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173003. png_uint_32 istop=row_info->rowbytes - bpp;
  173004. for (i = 0; i < bpp; i++)
  173005. {
  173006. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173007. rp++;
  173008. }
  173009. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  173010. {
  173011. int a, b, c, pa, pb, pc, p;
  173012. a = *lp++;
  173013. b = *pp++;
  173014. c = *cp++;
  173015. p = b - c;
  173016. pc = a - c;
  173017. #ifdef PNG_USE_ABS
  173018. pa = abs(p);
  173019. pb = abs(pc);
  173020. pc = abs(p + pc);
  173021. #else
  173022. pa = p < 0 ? -p : p;
  173023. pb = pc < 0 ? -pc : pc;
  173024. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173025. #endif
  173026. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173027. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173028. rp++;
  173029. }
  173030. break;
  173031. }
  173032. default:
  173033. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173034. *row=0;
  173035. break;
  173036. }
  173037. }
  173038. void /* PRIVATE */
  173039. png_read_finish_row(png_structp png_ptr)
  173040. {
  173041. #ifdef PNG_USE_LOCAL_ARRAYS
  173042. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173043. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173044. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173045. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173046. #endif
  173047. png_debug(1, "in png_read_finish_row\n");
  173048. png_ptr->row_number++;
  173049. if (png_ptr->row_number < png_ptr->num_rows)
  173050. return;
  173051. if (png_ptr->interlaced)
  173052. {
  173053. png_ptr->row_number = 0;
  173054. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173055. png_ptr->rowbytes + 1);
  173056. do
  173057. {
  173058. png_ptr->pass++;
  173059. if (png_ptr->pass >= 7)
  173060. break;
  173061. png_ptr->iwidth = (png_ptr->width +
  173062. png_pass_inc[png_ptr->pass] - 1 -
  173063. png_pass_start[png_ptr->pass]) /
  173064. png_pass_inc[png_ptr->pass];
  173065. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173066. png_ptr->iwidth) + 1;
  173067. if (!(png_ptr->transformations & PNG_INTERLACE))
  173068. {
  173069. png_ptr->num_rows = (png_ptr->height +
  173070. png_pass_yinc[png_ptr->pass] - 1 -
  173071. png_pass_ystart[png_ptr->pass]) /
  173072. png_pass_yinc[png_ptr->pass];
  173073. if (!(png_ptr->num_rows))
  173074. continue;
  173075. }
  173076. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173077. break;
  173078. } while (png_ptr->iwidth == 0);
  173079. if (png_ptr->pass < 7)
  173080. return;
  173081. }
  173082. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173083. {
  173084. #ifdef PNG_USE_LOCAL_ARRAYS
  173085. PNG_CONST PNG_IDAT;
  173086. #endif
  173087. char extra;
  173088. int ret;
  173089. png_ptr->zstream.next_out = (Bytef *)&extra;
  173090. png_ptr->zstream.avail_out = (uInt)1;
  173091. for(;;)
  173092. {
  173093. if (!(png_ptr->zstream.avail_in))
  173094. {
  173095. while (!png_ptr->idat_size)
  173096. {
  173097. png_byte chunk_length[4];
  173098. png_crc_finish(png_ptr, 0);
  173099. png_read_data(png_ptr, chunk_length, 4);
  173100. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173101. png_reset_crc(png_ptr);
  173102. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173103. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173104. png_error(png_ptr, "Not enough image data");
  173105. }
  173106. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173107. png_ptr->zstream.next_in = png_ptr->zbuf;
  173108. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173109. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173110. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173111. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173112. }
  173113. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173114. if (ret == Z_STREAM_END)
  173115. {
  173116. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173117. png_ptr->idat_size)
  173118. png_warning(png_ptr, "Extra compressed data");
  173119. png_ptr->mode |= PNG_AFTER_IDAT;
  173120. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173121. break;
  173122. }
  173123. if (ret != Z_OK)
  173124. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173125. "Decompression Error");
  173126. if (!(png_ptr->zstream.avail_out))
  173127. {
  173128. png_warning(png_ptr, "Extra compressed data.");
  173129. png_ptr->mode |= PNG_AFTER_IDAT;
  173130. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173131. break;
  173132. }
  173133. }
  173134. png_ptr->zstream.avail_out = 0;
  173135. }
  173136. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173137. png_warning(png_ptr, "Extra compression data");
  173138. inflateReset(&png_ptr->zstream);
  173139. png_ptr->mode |= PNG_AFTER_IDAT;
  173140. }
  173141. void /* PRIVATE */
  173142. png_read_start_row(png_structp png_ptr)
  173143. {
  173144. #ifdef PNG_USE_LOCAL_ARRAYS
  173145. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173146. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173147. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173148. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173149. #endif
  173150. int max_pixel_depth;
  173151. png_uint_32 row_bytes;
  173152. png_debug(1, "in png_read_start_row\n");
  173153. png_ptr->zstream.avail_in = 0;
  173154. png_init_read_transformations(png_ptr);
  173155. if (png_ptr->interlaced)
  173156. {
  173157. if (!(png_ptr->transformations & PNG_INTERLACE))
  173158. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173159. png_pass_ystart[0]) / png_pass_yinc[0];
  173160. else
  173161. png_ptr->num_rows = png_ptr->height;
  173162. png_ptr->iwidth = (png_ptr->width +
  173163. png_pass_inc[png_ptr->pass] - 1 -
  173164. png_pass_start[png_ptr->pass]) /
  173165. png_pass_inc[png_ptr->pass];
  173166. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173167. png_ptr->irowbytes = (png_size_t)row_bytes;
  173168. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173169. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173170. }
  173171. else
  173172. {
  173173. png_ptr->num_rows = png_ptr->height;
  173174. png_ptr->iwidth = png_ptr->width;
  173175. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173176. }
  173177. max_pixel_depth = png_ptr->pixel_depth;
  173178. #if defined(PNG_READ_PACK_SUPPORTED)
  173179. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173180. max_pixel_depth = 8;
  173181. #endif
  173182. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173183. if (png_ptr->transformations & PNG_EXPAND)
  173184. {
  173185. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173186. {
  173187. if (png_ptr->num_trans)
  173188. max_pixel_depth = 32;
  173189. else
  173190. max_pixel_depth = 24;
  173191. }
  173192. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173193. {
  173194. if (max_pixel_depth < 8)
  173195. max_pixel_depth = 8;
  173196. if (png_ptr->num_trans)
  173197. max_pixel_depth *= 2;
  173198. }
  173199. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173200. {
  173201. if (png_ptr->num_trans)
  173202. {
  173203. max_pixel_depth *= 4;
  173204. max_pixel_depth /= 3;
  173205. }
  173206. }
  173207. }
  173208. #endif
  173209. #if defined(PNG_READ_FILLER_SUPPORTED)
  173210. if (png_ptr->transformations & (PNG_FILLER))
  173211. {
  173212. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173213. max_pixel_depth = 32;
  173214. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173215. {
  173216. if (max_pixel_depth <= 8)
  173217. max_pixel_depth = 16;
  173218. else
  173219. max_pixel_depth = 32;
  173220. }
  173221. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173222. {
  173223. if (max_pixel_depth <= 32)
  173224. max_pixel_depth = 32;
  173225. else
  173226. max_pixel_depth = 64;
  173227. }
  173228. }
  173229. #endif
  173230. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173231. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173232. {
  173233. if (
  173234. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173235. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173236. #endif
  173237. #if defined(PNG_READ_FILLER_SUPPORTED)
  173238. (png_ptr->transformations & (PNG_FILLER)) ||
  173239. #endif
  173240. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173241. {
  173242. if (max_pixel_depth <= 16)
  173243. max_pixel_depth = 32;
  173244. else
  173245. max_pixel_depth = 64;
  173246. }
  173247. else
  173248. {
  173249. if (max_pixel_depth <= 8)
  173250. {
  173251. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173252. max_pixel_depth = 32;
  173253. else
  173254. max_pixel_depth = 24;
  173255. }
  173256. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173257. max_pixel_depth = 64;
  173258. else
  173259. max_pixel_depth = 48;
  173260. }
  173261. }
  173262. #endif
  173263. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173264. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173265. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173266. {
  173267. int user_pixel_depth=png_ptr->user_transform_depth*
  173268. png_ptr->user_transform_channels;
  173269. if(user_pixel_depth > max_pixel_depth)
  173270. max_pixel_depth=user_pixel_depth;
  173271. }
  173272. #endif
  173273. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173274. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173275. 1 + ((max_pixel_depth + 7) >> 3);
  173276. #ifdef PNG_MAX_MALLOC_64K
  173277. if (row_bytes > (png_uint_32)65536L)
  173278. png_error(png_ptr, "This image requires a row greater than 64KB");
  173279. #endif
  173280. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173281. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173282. #ifdef PNG_MAX_MALLOC_64K
  173283. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173284. png_error(png_ptr, "This image requires a row greater than 64KB");
  173285. #endif
  173286. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173287. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173288. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173289. png_ptr->rowbytes + 1));
  173290. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173291. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173292. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173293. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173294. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173295. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173296. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173297. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173298. }
  173299. #endif /* PNG_READ_SUPPORTED */
  173300. /*** End of inlined file: pngrutil.c ***/
  173301. /*** Start of inlined file: pngset.c ***/
  173302. #define PNG_INTERNAL
  173303. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173304. #if defined(PNG_bKGD_SUPPORTED)
  173305. void PNGAPI
  173306. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173307. {
  173308. png_debug1(1, "in %s storage function\n", "bKGD");
  173309. if (png_ptr == NULL || info_ptr == NULL)
  173310. return;
  173311. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173312. info_ptr->valid |= PNG_INFO_bKGD;
  173313. }
  173314. #endif
  173315. #if defined(PNG_cHRM_SUPPORTED)
  173316. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173317. void PNGAPI
  173318. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173319. double white_x, double white_y, double red_x, double red_y,
  173320. double green_x, double green_y, double blue_x, double blue_y)
  173321. {
  173322. png_debug1(1, "in %s storage function\n", "cHRM");
  173323. if (png_ptr == NULL || info_ptr == NULL)
  173324. return;
  173325. if (white_x < 0.0 || white_y < 0.0 ||
  173326. red_x < 0.0 || red_y < 0.0 ||
  173327. green_x < 0.0 || green_y < 0.0 ||
  173328. blue_x < 0.0 || blue_y < 0.0)
  173329. {
  173330. png_warning(png_ptr,
  173331. "Ignoring attempt to set negative chromaticity value");
  173332. return;
  173333. }
  173334. if (white_x > 21474.83 || white_y > 21474.83 ||
  173335. red_x > 21474.83 || red_y > 21474.83 ||
  173336. green_x > 21474.83 || green_y > 21474.83 ||
  173337. blue_x > 21474.83 || blue_y > 21474.83)
  173338. {
  173339. png_warning(png_ptr,
  173340. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173341. return;
  173342. }
  173343. info_ptr->x_white = (float)white_x;
  173344. info_ptr->y_white = (float)white_y;
  173345. info_ptr->x_red = (float)red_x;
  173346. info_ptr->y_red = (float)red_y;
  173347. info_ptr->x_green = (float)green_x;
  173348. info_ptr->y_green = (float)green_y;
  173349. info_ptr->x_blue = (float)blue_x;
  173350. info_ptr->y_blue = (float)blue_y;
  173351. #ifdef PNG_FIXED_POINT_SUPPORTED
  173352. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173353. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173354. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173355. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173356. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173357. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173358. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173359. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173360. #endif
  173361. info_ptr->valid |= PNG_INFO_cHRM;
  173362. }
  173363. #endif
  173364. #ifdef PNG_FIXED_POINT_SUPPORTED
  173365. void PNGAPI
  173366. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173367. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173368. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173369. png_fixed_point blue_x, png_fixed_point blue_y)
  173370. {
  173371. png_debug1(1, "in %s storage function\n", "cHRM");
  173372. if (png_ptr == NULL || info_ptr == NULL)
  173373. return;
  173374. if (white_x < 0 || white_y < 0 ||
  173375. red_x < 0 || red_y < 0 ||
  173376. green_x < 0 || green_y < 0 ||
  173377. blue_x < 0 || blue_y < 0)
  173378. {
  173379. png_warning(png_ptr,
  173380. "Ignoring attempt to set negative chromaticity value");
  173381. return;
  173382. }
  173383. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173384. if (white_x > (double) PNG_UINT_31_MAX ||
  173385. white_y > (double) PNG_UINT_31_MAX ||
  173386. red_x > (double) PNG_UINT_31_MAX ||
  173387. red_y > (double) PNG_UINT_31_MAX ||
  173388. green_x > (double) PNG_UINT_31_MAX ||
  173389. green_y > (double) PNG_UINT_31_MAX ||
  173390. blue_x > (double) PNG_UINT_31_MAX ||
  173391. blue_y > (double) PNG_UINT_31_MAX)
  173392. #else
  173393. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173394. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173395. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173396. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173397. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173398. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173399. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173400. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173401. #endif
  173402. {
  173403. png_warning(png_ptr,
  173404. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173405. return;
  173406. }
  173407. info_ptr->int_x_white = white_x;
  173408. info_ptr->int_y_white = white_y;
  173409. info_ptr->int_x_red = red_x;
  173410. info_ptr->int_y_red = red_y;
  173411. info_ptr->int_x_green = green_x;
  173412. info_ptr->int_y_green = green_y;
  173413. info_ptr->int_x_blue = blue_x;
  173414. info_ptr->int_y_blue = blue_y;
  173415. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173416. info_ptr->x_white = (float)(white_x/100000.);
  173417. info_ptr->y_white = (float)(white_y/100000.);
  173418. info_ptr->x_red = (float)( red_x/100000.);
  173419. info_ptr->y_red = (float)( red_y/100000.);
  173420. info_ptr->x_green = (float)(green_x/100000.);
  173421. info_ptr->y_green = (float)(green_y/100000.);
  173422. info_ptr->x_blue = (float)( blue_x/100000.);
  173423. info_ptr->y_blue = (float)( blue_y/100000.);
  173424. #endif
  173425. info_ptr->valid |= PNG_INFO_cHRM;
  173426. }
  173427. #endif
  173428. #endif
  173429. #if defined(PNG_gAMA_SUPPORTED)
  173430. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173431. void PNGAPI
  173432. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173433. {
  173434. double gamma;
  173435. png_debug1(1, "in %s storage function\n", "gAMA");
  173436. if (png_ptr == NULL || info_ptr == NULL)
  173437. return;
  173438. if (file_gamma > 21474.83)
  173439. {
  173440. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173441. gamma=21474.83;
  173442. }
  173443. else
  173444. gamma=file_gamma;
  173445. info_ptr->gamma = (float)gamma;
  173446. #ifdef PNG_FIXED_POINT_SUPPORTED
  173447. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173448. #endif
  173449. info_ptr->valid |= PNG_INFO_gAMA;
  173450. if(gamma == 0.0)
  173451. png_warning(png_ptr, "Setting gamma=0");
  173452. }
  173453. #endif
  173454. void PNGAPI
  173455. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173456. int_gamma)
  173457. {
  173458. png_fixed_point gamma;
  173459. png_debug1(1, "in %s storage function\n", "gAMA");
  173460. if (png_ptr == NULL || info_ptr == NULL)
  173461. return;
  173462. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173463. {
  173464. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173465. gamma=PNG_UINT_31_MAX;
  173466. }
  173467. else
  173468. {
  173469. if (int_gamma < 0)
  173470. {
  173471. png_warning(png_ptr, "Setting negative gamma to zero");
  173472. gamma=0;
  173473. }
  173474. else
  173475. gamma=int_gamma;
  173476. }
  173477. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173478. info_ptr->gamma = (float)(gamma/100000.);
  173479. #endif
  173480. #ifdef PNG_FIXED_POINT_SUPPORTED
  173481. info_ptr->int_gamma = gamma;
  173482. #endif
  173483. info_ptr->valid |= PNG_INFO_gAMA;
  173484. if(gamma == 0)
  173485. png_warning(png_ptr, "Setting gamma=0");
  173486. }
  173487. #endif
  173488. #if defined(PNG_hIST_SUPPORTED)
  173489. void PNGAPI
  173490. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173491. {
  173492. int i;
  173493. png_debug1(1, "in %s storage function\n", "hIST");
  173494. if (png_ptr == NULL || info_ptr == NULL)
  173495. return;
  173496. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173497. > PNG_MAX_PALETTE_LENGTH)
  173498. {
  173499. png_warning(png_ptr,
  173500. "Invalid palette size, hIST allocation skipped.");
  173501. return;
  173502. }
  173503. #ifdef PNG_FREE_ME_SUPPORTED
  173504. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173505. #endif
  173506. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173507. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173508. if (png_ptr->hist == NULL)
  173509. {
  173510. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173511. return;
  173512. }
  173513. for (i = 0; i < info_ptr->num_palette; i++)
  173514. png_ptr->hist[i] = hist[i];
  173515. info_ptr->hist = png_ptr->hist;
  173516. info_ptr->valid |= PNG_INFO_hIST;
  173517. #ifdef PNG_FREE_ME_SUPPORTED
  173518. info_ptr->free_me |= PNG_FREE_HIST;
  173519. #else
  173520. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173521. #endif
  173522. }
  173523. #endif
  173524. void PNGAPI
  173525. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173526. png_uint_32 width, png_uint_32 height, int bit_depth,
  173527. int color_type, int interlace_type, int compression_type,
  173528. int filter_type)
  173529. {
  173530. png_debug1(1, "in %s storage function\n", "IHDR");
  173531. if (png_ptr == NULL || info_ptr == NULL)
  173532. return;
  173533. if (width == 0 || height == 0)
  173534. png_error(png_ptr, "Image width or height is zero in IHDR");
  173535. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173536. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173537. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173538. #else
  173539. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173540. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173541. #endif
  173542. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173543. png_error(png_ptr, "Invalid image size in IHDR");
  173544. if ( width > (PNG_UINT_32_MAX
  173545. >> 3) /* 8-byte RGBA pixels */
  173546. - 64 /* bigrowbuf hack */
  173547. - 1 /* filter byte */
  173548. - 7*8 /* rounding of width to multiple of 8 pixels */
  173549. - 8) /* extra max_pixel_depth pad */
  173550. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  173551. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  173552. bit_depth != 8 && bit_depth != 16)
  173553. png_error(png_ptr, "Invalid bit depth in IHDR");
  173554. if (color_type < 0 || color_type == 1 ||
  173555. color_type == 5 || color_type > 6)
  173556. png_error(png_ptr, "Invalid color type in IHDR");
  173557. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  173558. ((color_type == PNG_COLOR_TYPE_RGB ||
  173559. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  173560. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  173561. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  173562. if (interlace_type >= PNG_INTERLACE_LAST)
  173563. png_error(png_ptr, "Unknown interlace method in IHDR");
  173564. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  173565. png_error(png_ptr, "Unknown compression method in IHDR");
  173566. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  173567. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  173568. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  173569. if(filter_type != PNG_FILTER_TYPE_BASE)
  173570. {
  173571. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  173572. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  173573. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  173574. (color_type == PNG_COLOR_TYPE_RGB ||
  173575. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  173576. png_error(png_ptr, "Unknown filter method in IHDR");
  173577. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  173578. png_warning(png_ptr, "Invalid filter method in IHDR");
  173579. }
  173580. #else
  173581. if(filter_type != PNG_FILTER_TYPE_BASE)
  173582. png_error(png_ptr, "Unknown filter method in IHDR");
  173583. #endif
  173584. info_ptr->width = width;
  173585. info_ptr->height = height;
  173586. info_ptr->bit_depth = (png_byte)bit_depth;
  173587. info_ptr->color_type =(png_byte) color_type;
  173588. info_ptr->compression_type = (png_byte)compression_type;
  173589. info_ptr->filter_type = (png_byte)filter_type;
  173590. info_ptr->interlace_type = (png_byte)interlace_type;
  173591. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173592. info_ptr->channels = 1;
  173593. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  173594. info_ptr->channels = 3;
  173595. else
  173596. info_ptr->channels = 1;
  173597. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  173598. info_ptr->channels++;
  173599. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  173600. if (width > (PNG_UINT_32_MAX
  173601. >> 3) /* 8-byte RGBA pixels */
  173602. - 64 /* bigrowbuf hack */
  173603. - 1 /* filter byte */
  173604. - 7*8 /* rounding of width to multiple of 8 pixels */
  173605. - 8) /* extra max_pixel_depth pad */
  173606. info_ptr->rowbytes = (png_size_t)0;
  173607. else
  173608. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  173609. }
  173610. #if defined(PNG_oFFs_SUPPORTED)
  173611. void PNGAPI
  173612. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  173613. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  173614. {
  173615. png_debug1(1, "in %s storage function\n", "oFFs");
  173616. if (png_ptr == NULL || info_ptr == NULL)
  173617. return;
  173618. info_ptr->x_offset = offset_x;
  173619. info_ptr->y_offset = offset_y;
  173620. info_ptr->offset_unit_type = (png_byte)unit_type;
  173621. info_ptr->valid |= PNG_INFO_oFFs;
  173622. }
  173623. #endif
  173624. #if defined(PNG_pCAL_SUPPORTED)
  173625. void PNGAPI
  173626. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  173627. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  173628. png_charp units, png_charpp params)
  173629. {
  173630. png_uint_32 length;
  173631. int i;
  173632. png_debug1(1, "in %s storage function\n", "pCAL");
  173633. if (png_ptr == NULL || info_ptr == NULL)
  173634. return;
  173635. length = png_strlen(purpose) + 1;
  173636. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  173637. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  173638. if (info_ptr->pcal_purpose == NULL)
  173639. {
  173640. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  173641. return;
  173642. }
  173643. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  173644. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  173645. info_ptr->pcal_X0 = X0;
  173646. info_ptr->pcal_X1 = X1;
  173647. info_ptr->pcal_type = (png_byte)type;
  173648. info_ptr->pcal_nparams = (png_byte)nparams;
  173649. length = png_strlen(units) + 1;
  173650. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  173651. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  173652. if (info_ptr->pcal_units == NULL)
  173653. {
  173654. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  173655. return;
  173656. }
  173657. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  173658. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  173659. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  173660. if (info_ptr->pcal_params == NULL)
  173661. {
  173662. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  173663. return;
  173664. }
  173665. info_ptr->pcal_params[nparams] = NULL;
  173666. for (i = 0; i < nparams; i++)
  173667. {
  173668. length = png_strlen(params[i]) + 1;
  173669. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  173670. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  173671. if (info_ptr->pcal_params[i] == NULL)
  173672. {
  173673. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  173674. return;
  173675. }
  173676. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  173677. }
  173678. info_ptr->valid |= PNG_INFO_pCAL;
  173679. #ifdef PNG_FREE_ME_SUPPORTED
  173680. info_ptr->free_me |= PNG_FREE_PCAL;
  173681. #endif
  173682. }
  173683. #endif
  173684. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  173685. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173686. void PNGAPI
  173687. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  173688. int unit, double width, double height)
  173689. {
  173690. png_debug1(1, "in %s storage function\n", "sCAL");
  173691. if (png_ptr == NULL || info_ptr == NULL)
  173692. return;
  173693. info_ptr->scal_unit = (png_byte)unit;
  173694. info_ptr->scal_pixel_width = width;
  173695. info_ptr->scal_pixel_height = height;
  173696. info_ptr->valid |= PNG_INFO_sCAL;
  173697. }
  173698. #else
  173699. #ifdef PNG_FIXED_POINT_SUPPORTED
  173700. void PNGAPI
  173701. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  173702. int unit, png_charp swidth, png_charp sheight)
  173703. {
  173704. png_uint_32 length;
  173705. png_debug1(1, "in %s storage function\n", "sCAL");
  173706. if (png_ptr == NULL || info_ptr == NULL)
  173707. return;
  173708. info_ptr->scal_unit = (png_byte)unit;
  173709. length = png_strlen(swidth) + 1;
  173710. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173711. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  173712. if (info_ptr->scal_s_width == NULL)
  173713. {
  173714. png_warning(png_ptr,
  173715. "Memory allocation failed while processing sCAL.");
  173716. }
  173717. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  173718. length = png_strlen(sheight) + 1;
  173719. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173720. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  173721. if (info_ptr->scal_s_height == NULL)
  173722. {
  173723. png_free (png_ptr, info_ptr->scal_s_width);
  173724. png_warning(png_ptr,
  173725. "Memory allocation failed while processing sCAL.");
  173726. }
  173727. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  173728. info_ptr->valid |= PNG_INFO_sCAL;
  173729. #ifdef PNG_FREE_ME_SUPPORTED
  173730. info_ptr->free_me |= PNG_FREE_SCAL;
  173731. #endif
  173732. }
  173733. #endif
  173734. #endif
  173735. #endif
  173736. #if defined(PNG_pHYs_SUPPORTED)
  173737. void PNGAPI
  173738. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  173739. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  173740. {
  173741. png_debug1(1, "in %s storage function\n", "pHYs");
  173742. if (png_ptr == NULL || info_ptr == NULL)
  173743. return;
  173744. info_ptr->x_pixels_per_unit = res_x;
  173745. info_ptr->y_pixels_per_unit = res_y;
  173746. info_ptr->phys_unit_type = (png_byte)unit_type;
  173747. info_ptr->valid |= PNG_INFO_pHYs;
  173748. }
  173749. #endif
  173750. void PNGAPI
  173751. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  173752. png_colorp palette, int num_palette)
  173753. {
  173754. png_debug1(1, "in %s storage function\n", "PLTE");
  173755. if (png_ptr == NULL || info_ptr == NULL)
  173756. return;
  173757. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  173758. {
  173759. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173760. png_error(png_ptr, "Invalid palette length");
  173761. else
  173762. {
  173763. png_warning(png_ptr, "Invalid palette length");
  173764. return;
  173765. }
  173766. }
  173767. #ifdef PNG_FREE_ME_SUPPORTED
  173768. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  173769. #endif
  173770. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  173771. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  173772. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  173773. png_sizeof(png_color));
  173774. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  173775. info_ptr->palette = png_ptr->palette;
  173776. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  173777. #ifdef PNG_FREE_ME_SUPPORTED
  173778. info_ptr->free_me |= PNG_FREE_PLTE;
  173779. #else
  173780. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  173781. #endif
  173782. info_ptr->valid |= PNG_INFO_PLTE;
  173783. }
  173784. #if defined(PNG_sBIT_SUPPORTED)
  173785. void PNGAPI
  173786. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  173787. png_color_8p sig_bit)
  173788. {
  173789. png_debug1(1, "in %s storage function\n", "sBIT");
  173790. if (png_ptr == NULL || info_ptr == NULL)
  173791. return;
  173792. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  173793. info_ptr->valid |= PNG_INFO_sBIT;
  173794. }
  173795. #endif
  173796. #if defined(PNG_sRGB_SUPPORTED)
  173797. void PNGAPI
  173798. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  173799. {
  173800. png_debug1(1, "in %s storage function\n", "sRGB");
  173801. if (png_ptr == NULL || info_ptr == NULL)
  173802. return;
  173803. info_ptr->srgb_intent = (png_byte)intent;
  173804. info_ptr->valid |= PNG_INFO_sRGB;
  173805. }
  173806. void PNGAPI
  173807. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  173808. int intent)
  173809. {
  173810. #if defined(PNG_gAMA_SUPPORTED)
  173811. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173812. float file_gamma;
  173813. #endif
  173814. #ifdef PNG_FIXED_POINT_SUPPORTED
  173815. png_fixed_point int_file_gamma;
  173816. #endif
  173817. #endif
  173818. #if defined(PNG_cHRM_SUPPORTED)
  173819. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173820. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  173821. #endif
  173822. #ifdef PNG_FIXED_POINT_SUPPORTED
  173823. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  173824. int_green_y, int_blue_x, int_blue_y;
  173825. #endif
  173826. #endif
  173827. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  173828. if (png_ptr == NULL || info_ptr == NULL)
  173829. return;
  173830. png_set_sRGB(png_ptr, info_ptr, intent);
  173831. #if defined(PNG_gAMA_SUPPORTED)
  173832. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173833. file_gamma = (float).45455;
  173834. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  173835. #endif
  173836. #ifdef PNG_FIXED_POINT_SUPPORTED
  173837. int_file_gamma = 45455L;
  173838. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  173839. #endif
  173840. #endif
  173841. #if defined(PNG_cHRM_SUPPORTED)
  173842. #ifdef PNG_FIXED_POINT_SUPPORTED
  173843. int_white_x = 31270L;
  173844. int_white_y = 32900L;
  173845. int_red_x = 64000L;
  173846. int_red_y = 33000L;
  173847. int_green_x = 30000L;
  173848. int_green_y = 60000L;
  173849. int_blue_x = 15000L;
  173850. int_blue_y = 6000L;
  173851. png_set_cHRM_fixed(png_ptr, info_ptr,
  173852. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  173853. int_blue_x, int_blue_y);
  173854. #endif
  173855. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173856. white_x = (float).3127;
  173857. white_y = (float).3290;
  173858. red_x = (float).64;
  173859. red_y = (float).33;
  173860. green_x = (float).30;
  173861. green_y = (float).60;
  173862. blue_x = (float).15;
  173863. blue_y = (float).06;
  173864. png_set_cHRM(png_ptr, info_ptr,
  173865. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  173866. #endif
  173867. #endif
  173868. }
  173869. #endif
  173870. #if defined(PNG_iCCP_SUPPORTED)
  173871. void PNGAPI
  173872. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  173873. png_charp name, int compression_type,
  173874. png_charp profile, png_uint_32 proflen)
  173875. {
  173876. png_charp new_iccp_name;
  173877. png_charp new_iccp_profile;
  173878. png_debug1(1, "in %s storage function\n", "iCCP");
  173879. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  173880. return;
  173881. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  173882. if (new_iccp_name == NULL)
  173883. {
  173884. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  173885. return;
  173886. }
  173887. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  173888. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  173889. if (new_iccp_profile == NULL)
  173890. {
  173891. png_free (png_ptr, new_iccp_name);
  173892. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  173893. return;
  173894. }
  173895. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  173896. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  173897. info_ptr->iccp_proflen = proflen;
  173898. info_ptr->iccp_name = new_iccp_name;
  173899. info_ptr->iccp_profile = new_iccp_profile;
  173900. info_ptr->iccp_compression = (png_byte)compression_type;
  173901. #ifdef PNG_FREE_ME_SUPPORTED
  173902. info_ptr->free_me |= PNG_FREE_ICCP;
  173903. #endif
  173904. info_ptr->valid |= PNG_INFO_iCCP;
  173905. }
  173906. #endif
  173907. #if defined(PNG_TEXT_SUPPORTED)
  173908. void PNGAPI
  173909. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173910. int num_text)
  173911. {
  173912. int ret;
  173913. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  173914. if (ret)
  173915. png_error(png_ptr, "Insufficient memory to store text");
  173916. }
  173917. int /* PRIVATE */
  173918. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173919. int num_text)
  173920. {
  173921. int i;
  173922. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  173923. "text" : (png_const_charp)png_ptr->chunk_name));
  173924. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  173925. return(0);
  173926. if (info_ptr->num_text + num_text > info_ptr->max_text)
  173927. {
  173928. if (info_ptr->text != NULL)
  173929. {
  173930. png_textp old_text;
  173931. int old_max;
  173932. old_max = info_ptr->max_text;
  173933. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  173934. old_text = info_ptr->text;
  173935. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173936. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173937. if (info_ptr->text == NULL)
  173938. {
  173939. png_free(png_ptr, old_text);
  173940. return(1);
  173941. }
  173942. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  173943. png_sizeof(png_text)));
  173944. png_free(png_ptr, old_text);
  173945. }
  173946. else
  173947. {
  173948. info_ptr->max_text = num_text + 8;
  173949. info_ptr->num_text = 0;
  173950. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173951. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173952. if (info_ptr->text == NULL)
  173953. return(1);
  173954. #ifdef PNG_FREE_ME_SUPPORTED
  173955. info_ptr->free_me |= PNG_FREE_TEXT;
  173956. #endif
  173957. }
  173958. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  173959. info_ptr->max_text);
  173960. }
  173961. for (i = 0; i < num_text; i++)
  173962. {
  173963. png_size_t text_length,key_len;
  173964. png_size_t lang_len,lang_key_len;
  173965. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  173966. if (text_ptr[i].key == NULL)
  173967. continue;
  173968. key_len = png_strlen(text_ptr[i].key);
  173969. if(text_ptr[i].compression <= 0)
  173970. {
  173971. lang_len = 0;
  173972. lang_key_len = 0;
  173973. }
  173974. else
  173975. #ifdef PNG_iTXt_SUPPORTED
  173976. {
  173977. if (text_ptr[i].lang != NULL)
  173978. lang_len = png_strlen(text_ptr[i].lang);
  173979. else
  173980. lang_len = 0;
  173981. if (text_ptr[i].lang_key != NULL)
  173982. lang_key_len = png_strlen(text_ptr[i].lang_key);
  173983. else
  173984. lang_key_len = 0;
  173985. }
  173986. #else
  173987. {
  173988. png_warning(png_ptr, "iTXt chunk not supported.");
  173989. continue;
  173990. }
  173991. #endif
  173992. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  173993. {
  173994. text_length = 0;
  173995. #ifdef PNG_iTXt_SUPPORTED
  173996. if(text_ptr[i].compression > 0)
  173997. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  173998. else
  173999. #endif
  174000. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  174001. }
  174002. else
  174003. {
  174004. text_length = png_strlen(text_ptr[i].text);
  174005. textp->compression = text_ptr[i].compression;
  174006. }
  174007. textp->key = (png_charp)png_malloc_warn(png_ptr,
  174008. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  174009. if (textp->key == NULL)
  174010. return(1);
  174011. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174012. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174013. (int)textp->key);
  174014. png_memcpy(textp->key, text_ptr[i].key,
  174015. (png_size_t)(key_len));
  174016. *(textp->key+key_len) = '\0';
  174017. #ifdef PNG_iTXt_SUPPORTED
  174018. if (text_ptr[i].compression > 0)
  174019. {
  174020. textp->lang=textp->key + key_len + 1;
  174021. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174022. *(textp->lang+lang_len) = '\0';
  174023. textp->lang_key=textp->lang + lang_len + 1;
  174024. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174025. *(textp->lang_key+lang_key_len) = '\0';
  174026. textp->text=textp->lang_key + lang_key_len + 1;
  174027. }
  174028. else
  174029. #endif
  174030. {
  174031. #ifdef PNG_iTXt_SUPPORTED
  174032. textp->lang=NULL;
  174033. textp->lang_key=NULL;
  174034. #endif
  174035. textp->text=textp->key + key_len + 1;
  174036. }
  174037. if(text_length)
  174038. png_memcpy(textp->text, text_ptr[i].text,
  174039. (png_size_t)(text_length));
  174040. *(textp->text+text_length) = '\0';
  174041. #ifdef PNG_iTXt_SUPPORTED
  174042. if(textp->compression > 0)
  174043. {
  174044. textp->text_length = 0;
  174045. textp->itxt_length = text_length;
  174046. }
  174047. else
  174048. #endif
  174049. {
  174050. textp->text_length = text_length;
  174051. #ifdef PNG_iTXt_SUPPORTED
  174052. textp->itxt_length = 0;
  174053. #endif
  174054. }
  174055. info_ptr->num_text++;
  174056. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174057. }
  174058. return(0);
  174059. }
  174060. #endif
  174061. #if defined(PNG_tIME_SUPPORTED)
  174062. void PNGAPI
  174063. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174064. {
  174065. png_debug1(1, "in %s storage function\n", "tIME");
  174066. if (png_ptr == NULL || info_ptr == NULL ||
  174067. (png_ptr->mode & PNG_WROTE_tIME))
  174068. return;
  174069. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174070. info_ptr->valid |= PNG_INFO_tIME;
  174071. }
  174072. #endif
  174073. #if defined(PNG_tRNS_SUPPORTED)
  174074. void PNGAPI
  174075. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174076. png_bytep trans, int num_trans, png_color_16p trans_values)
  174077. {
  174078. png_debug1(1, "in %s storage function\n", "tRNS");
  174079. if (png_ptr == NULL || info_ptr == NULL)
  174080. return;
  174081. if (trans != NULL)
  174082. {
  174083. #ifdef PNG_FREE_ME_SUPPORTED
  174084. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174085. #endif
  174086. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174087. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174088. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174089. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174090. #ifdef PNG_FREE_ME_SUPPORTED
  174091. info_ptr->free_me |= PNG_FREE_TRNS;
  174092. #else
  174093. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174094. #endif
  174095. }
  174096. if (trans_values != NULL)
  174097. {
  174098. png_memcpy(&(info_ptr->trans_values), trans_values,
  174099. png_sizeof(png_color_16));
  174100. if (num_trans == 0)
  174101. num_trans = 1;
  174102. }
  174103. info_ptr->num_trans = (png_uint_16)num_trans;
  174104. info_ptr->valid |= PNG_INFO_tRNS;
  174105. }
  174106. #endif
  174107. #if defined(PNG_sPLT_SUPPORTED)
  174108. void PNGAPI
  174109. png_set_sPLT(png_structp png_ptr,
  174110. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174111. {
  174112. png_sPLT_tp np;
  174113. int i;
  174114. if (png_ptr == NULL || info_ptr == NULL)
  174115. return;
  174116. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174117. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174118. if (np == NULL)
  174119. {
  174120. png_warning(png_ptr, "No memory for sPLT palettes.");
  174121. return;
  174122. }
  174123. png_memcpy(np, info_ptr->splt_palettes,
  174124. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174125. png_free(png_ptr, info_ptr->splt_palettes);
  174126. info_ptr->splt_palettes=NULL;
  174127. for (i = 0; i < nentries; i++)
  174128. {
  174129. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174130. png_sPLT_tp from = entries + i;
  174131. to->name = (png_charp)png_malloc_warn(png_ptr,
  174132. png_strlen(from->name) + 1);
  174133. if (to->name == NULL)
  174134. {
  174135. png_warning(png_ptr,
  174136. "Out of memory while processing sPLT chunk");
  174137. }
  174138. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174139. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174140. from->nentries * png_sizeof(png_sPLT_entry));
  174141. png_memcpy(to->entries, from->entries,
  174142. from->nentries * png_sizeof(png_sPLT_entry));
  174143. if (to->entries == NULL)
  174144. {
  174145. png_warning(png_ptr,
  174146. "Out of memory while processing sPLT chunk");
  174147. png_free(png_ptr,to->name);
  174148. to->name = NULL;
  174149. }
  174150. to->nentries = from->nentries;
  174151. to->depth = from->depth;
  174152. }
  174153. info_ptr->splt_palettes = np;
  174154. info_ptr->splt_palettes_num += nentries;
  174155. info_ptr->valid |= PNG_INFO_sPLT;
  174156. #ifdef PNG_FREE_ME_SUPPORTED
  174157. info_ptr->free_me |= PNG_FREE_SPLT;
  174158. #endif
  174159. }
  174160. #endif /* PNG_sPLT_SUPPORTED */
  174161. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174162. void PNGAPI
  174163. png_set_unknown_chunks(png_structp png_ptr,
  174164. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174165. {
  174166. png_unknown_chunkp np;
  174167. int i;
  174168. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174169. return;
  174170. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174171. (info_ptr->unknown_chunks_num + num_unknowns) *
  174172. png_sizeof(png_unknown_chunk));
  174173. if (np == NULL)
  174174. {
  174175. png_warning(png_ptr,
  174176. "Out of memory while processing unknown chunk.");
  174177. return;
  174178. }
  174179. png_memcpy(np, info_ptr->unknown_chunks,
  174180. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174181. png_free(png_ptr, info_ptr->unknown_chunks);
  174182. info_ptr->unknown_chunks=NULL;
  174183. for (i = 0; i < num_unknowns; i++)
  174184. {
  174185. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174186. png_unknown_chunkp from = unknowns + i;
  174187. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174188. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174189. if (to->data == NULL)
  174190. {
  174191. png_warning(png_ptr,
  174192. "Out of memory while processing unknown chunk.");
  174193. }
  174194. else
  174195. {
  174196. png_memcpy(to->data, from->data, from->size);
  174197. to->size = from->size;
  174198. to->location = (png_byte)(png_ptr->mode & 0xff);
  174199. }
  174200. }
  174201. info_ptr->unknown_chunks = np;
  174202. info_ptr->unknown_chunks_num += num_unknowns;
  174203. #ifdef PNG_FREE_ME_SUPPORTED
  174204. info_ptr->free_me |= PNG_FREE_UNKN;
  174205. #endif
  174206. }
  174207. void PNGAPI
  174208. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174209. int chunk, int location)
  174210. {
  174211. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174212. (int)info_ptr->unknown_chunks_num)
  174213. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174214. }
  174215. #endif
  174216. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174217. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174218. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174219. void PNGAPI
  174220. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174221. {
  174222. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174223. if (png_ptr == NULL)
  174224. return;
  174225. png_ptr->mng_features_permitted = (png_byte)
  174226. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174227. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174228. }
  174229. #endif
  174230. #endif
  174231. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174232. png_uint_32 PNGAPI
  174233. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174234. {
  174235. png_debug(1, "in png_permit_mng_features\n");
  174236. if (png_ptr == NULL)
  174237. return (png_uint_32)0;
  174238. png_ptr->mng_features_permitted =
  174239. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174240. return (png_uint_32)png_ptr->mng_features_permitted;
  174241. }
  174242. #endif
  174243. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174244. void PNGAPI
  174245. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174246. chunk_list, int num_chunks)
  174247. {
  174248. png_bytep new_list, p;
  174249. int i, old_num_chunks;
  174250. if (png_ptr == NULL)
  174251. return;
  174252. if (num_chunks == 0)
  174253. {
  174254. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174255. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174256. else
  174257. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174258. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174259. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174260. else
  174261. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174262. return;
  174263. }
  174264. if (chunk_list == NULL)
  174265. return;
  174266. old_num_chunks=png_ptr->num_chunk_list;
  174267. new_list=(png_bytep)png_malloc(png_ptr,
  174268. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174269. if(png_ptr->chunk_list != NULL)
  174270. {
  174271. png_memcpy(new_list, png_ptr->chunk_list,
  174272. (png_size_t)(5*old_num_chunks));
  174273. png_free(png_ptr, png_ptr->chunk_list);
  174274. png_ptr->chunk_list=NULL;
  174275. }
  174276. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174277. (png_size_t)(5*num_chunks));
  174278. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174279. *p=(png_byte)keep;
  174280. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174281. png_ptr->chunk_list=new_list;
  174282. #ifdef PNG_FREE_ME_SUPPORTED
  174283. png_ptr->free_me |= PNG_FREE_LIST;
  174284. #endif
  174285. }
  174286. #endif
  174287. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174288. void PNGAPI
  174289. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174290. png_user_chunk_ptr read_user_chunk_fn)
  174291. {
  174292. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174293. if (png_ptr == NULL)
  174294. return;
  174295. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174296. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174297. }
  174298. #endif
  174299. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174300. void PNGAPI
  174301. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174302. {
  174303. png_debug1(1, "in %s storage function\n", "rows");
  174304. if (png_ptr == NULL || info_ptr == NULL)
  174305. return;
  174306. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174307. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174308. info_ptr->row_pointers = row_pointers;
  174309. if(row_pointers)
  174310. info_ptr->valid |= PNG_INFO_IDAT;
  174311. }
  174312. #endif
  174313. #ifdef PNG_WRITE_SUPPORTED
  174314. void PNGAPI
  174315. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174316. {
  174317. if (png_ptr == NULL)
  174318. return;
  174319. if(png_ptr->zbuf)
  174320. png_free(png_ptr, png_ptr->zbuf);
  174321. png_ptr->zbuf_size = (png_size_t)size;
  174322. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174323. png_ptr->zstream.next_out = png_ptr->zbuf;
  174324. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174325. }
  174326. #endif
  174327. void PNGAPI
  174328. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174329. {
  174330. if (png_ptr && info_ptr)
  174331. info_ptr->valid &= ~(mask);
  174332. }
  174333. #ifndef PNG_1_0_X
  174334. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174335. void PNGAPI
  174336. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174337. {
  174338. if (png_ptr != NULL)
  174339. png_ptr->asm_flags = 0;
  174340. }
  174341. void PNGAPI
  174342. png_set_mmx_thresholds (png_structp png_ptr,
  174343. png_byte mmx_bitdepth_threshold,
  174344. png_uint_32 mmx_rowbytes_threshold)
  174345. {
  174346. if (png_ptr == NULL)
  174347. return;
  174348. }
  174349. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174350. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174351. void PNGAPI
  174352. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174353. png_uint_32 user_height_max)
  174354. {
  174355. if(png_ptr == NULL) return;
  174356. png_ptr->user_width_max = user_width_max;
  174357. png_ptr->user_height_max = user_height_max;
  174358. }
  174359. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174360. #endif /* ?PNG_1_0_X */
  174361. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174362. /*** End of inlined file: pngset.c ***/
  174363. /*** Start of inlined file: pngtrans.c ***/
  174364. #define PNG_INTERNAL
  174365. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174366. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174367. void PNGAPI
  174368. png_set_bgr(png_structp png_ptr)
  174369. {
  174370. png_debug(1, "in png_set_bgr\n");
  174371. if(png_ptr == NULL) return;
  174372. png_ptr->transformations |= PNG_BGR;
  174373. }
  174374. #endif
  174375. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174376. void PNGAPI
  174377. png_set_swap(png_structp png_ptr)
  174378. {
  174379. png_debug(1, "in png_set_swap\n");
  174380. if(png_ptr == NULL) return;
  174381. if (png_ptr->bit_depth == 16)
  174382. png_ptr->transformations |= PNG_SWAP_BYTES;
  174383. }
  174384. #endif
  174385. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174386. void PNGAPI
  174387. png_set_packing(png_structp png_ptr)
  174388. {
  174389. png_debug(1, "in png_set_packing\n");
  174390. if(png_ptr == NULL) return;
  174391. if (png_ptr->bit_depth < 8)
  174392. {
  174393. png_ptr->transformations |= PNG_PACK;
  174394. png_ptr->usr_bit_depth = 8;
  174395. }
  174396. }
  174397. #endif
  174398. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174399. void PNGAPI
  174400. png_set_packswap(png_structp png_ptr)
  174401. {
  174402. png_debug(1, "in png_set_packswap\n");
  174403. if(png_ptr == NULL) return;
  174404. if (png_ptr->bit_depth < 8)
  174405. png_ptr->transformations |= PNG_PACKSWAP;
  174406. }
  174407. #endif
  174408. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174409. void PNGAPI
  174410. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174411. {
  174412. png_debug(1, "in png_set_shift\n");
  174413. if(png_ptr == NULL) return;
  174414. png_ptr->transformations |= PNG_SHIFT;
  174415. png_ptr->shift = *true_bits;
  174416. }
  174417. #endif
  174418. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174419. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174420. int PNGAPI
  174421. png_set_interlace_handling(png_structp png_ptr)
  174422. {
  174423. png_debug(1, "in png_set_interlace handling\n");
  174424. if (png_ptr && png_ptr->interlaced)
  174425. {
  174426. png_ptr->transformations |= PNG_INTERLACE;
  174427. return (7);
  174428. }
  174429. return (1);
  174430. }
  174431. #endif
  174432. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174433. void PNGAPI
  174434. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174435. {
  174436. png_debug(1, "in png_set_filler\n");
  174437. if(png_ptr == NULL) return;
  174438. png_ptr->transformations |= PNG_FILLER;
  174439. png_ptr->filler = (png_byte)filler;
  174440. if (filler_loc == PNG_FILLER_AFTER)
  174441. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174442. else
  174443. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174444. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174445. {
  174446. png_ptr->usr_channels = 4;
  174447. }
  174448. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174449. {
  174450. png_ptr->usr_channels = 2;
  174451. }
  174452. }
  174453. #if !defined(PNG_1_0_X)
  174454. void PNGAPI
  174455. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174456. {
  174457. png_debug(1, "in png_set_add_alpha\n");
  174458. if(png_ptr == NULL) return;
  174459. png_set_filler(png_ptr, filler, filler_loc);
  174460. png_ptr->transformations |= PNG_ADD_ALPHA;
  174461. }
  174462. #endif
  174463. #endif
  174464. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174465. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174466. void PNGAPI
  174467. png_set_swap_alpha(png_structp png_ptr)
  174468. {
  174469. png_debug(1, "in png_set_swap_alpha\n");
  174470. if(png_ptr == NULL) return;
  174471. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174472. }
  174473. #endif
  174474. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174475. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174476. void PNGAPI
  174477. png_set_invert_alpha(png_structp png_ptr)
  174478. {
  174479. png_debug(1, "in png_set_invert_alpha\n");
  174480. if(png_ptr == NULL) return;
  174481. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174482. }
  174483. #endif
  174484. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174485. void PNGAPI
  174486. png_set_invert_mono(png_structp png_ptr)
  174487. {
  174488. png_debug(1, "in png_set_invert_mono\n");
  174489. if(png_ptr == NULL) return;
  174490. png_ptr->transformations |= PNG_INVERT_MONO;
  174491. }
  174492. void /* PRIVATE */
  174493. png_do_invert(png_row_infop row_info, png_bytep row)
  174494. {
  174495. png_debug(1, "in png_do_invert\n");
  174496. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174497. if (row == NULL || row_info == NULL)
  174498. return;
  174499. #endif
  174500. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174501. {
  174502. png_bytep rp = row;
  174503. png_uint_32 i;
  174504. png_uint_32 istop = row_info->rowbytes;
  174505. for (i = 0; i < istop; i++)
  174506. {
  174507. *rp = (png_byte)(~(*rp));
  174508. rp++;
  174509. }
  174510. }
  174511. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174512. row_info->bit_depth == 8)
  174513. {
  174514. png_bytep rp = row;
  174515. png_uint_32 i;
  174516. png_uint_32 istop = row_info->rowbytes;
  174517. for (i = 0; i < istop; i+=2)
  174518. {
  174519. *rp = (png_byte)(~(*rp));
  174520. rp+=2;
  174521. }
  174522. }
  174523. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174524. row_info->bit_depth == 16)
  174525. {
  174526. png_bytep rp = row;
  174527. png_uint_32 i;
  174528. png_uint_32 istop = row_info->rowbytes;
  174529. for (i = 0; i < istop; i+=4)
  174530. {
  174531. *rp = (png_byte)(~(*rp));
  174532. *(rp+1) = (png_byte)(~(*(rp+1)));
  174533. rp+=4;
  174534. }
  174535. }
  174536. }
  174537. #endif
  174538. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174539. void /* PRIVATE */
  174540. png_do_swap(png_row_infop row_info, png_bytep row)
  174541. {
  174542. png_debug(1, "in png_do_swap\n");
  174543. if (
  174544. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174545. row != NULL && row_info != NULL &&
  174546. #endif
  174547. row_info->bit_depth == 16)
  174548. {
  174549. png_bytep rp = row;
  174550. png_uint_32 i;
  174551. png_uint_32 istop= row_info->width * row_info->channels;
  174552. for (i = 0; i < istop; i++, rp += 2)
  174553. {
  174554. png_byte t = *rp;
  174555. *rp = *(rp + 1);
  174556. *(rp + 1) = t;
  174557. }
  174558. }
  174559. }
  174560. #endif
  174561. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174562. static PNG_CONST png_byte onebppswaptable[256] = {
  174563. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  174564. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  174565. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  174566. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  174567. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  174568. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  174569. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  174570. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  174571. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  174572. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  174573. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  174574. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  174575. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  174576. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  174577. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  174578. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  174579. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  174580. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  174581. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  174582. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  174583. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  174584. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  174585. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  174586. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  174587. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  174588. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  174589. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  174590. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  174591. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  174592. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  174593. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  174594. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  174595. };
  174596. static PNG_CONST png_byte twobppswaptable[256] = {
  174597. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  174598. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  174599. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  174600. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  174601. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  174602. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  174603. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  174604. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  174605. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  174606. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  174607. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  174608. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  174609. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  174610. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  174611. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  174612. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  174613. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  174614. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  174615. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  174616. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  174617. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  174618. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  174619. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  174620. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  174621. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  174622. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  174623. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  174624. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  174625. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  174626. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  174627. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  174628. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  174629. };
  174630. static PNG_CONST png_byte fourbppswaptable[256] = {
  174631. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  174632. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  174633. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  174634. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  174635. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  174636. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  174637. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  174638. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  174639. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  174640. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  174641. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  174642. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  174643. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  174644. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  174645. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  174646. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  174647. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  174648. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  174649. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  174650. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  174651. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  174652. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  174653. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  174654. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  174655. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  174656. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  174657. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  174658. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  174659. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  174660. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  174661. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  174662. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  174663. };
  174664. void /* PRIVATE */
  174665. png_do_packswap(png_row_infop row_info, png_bytep row)
  174666. {
  174667. png_debug(1, "in png_do_packswap\n");
  174668. if (
  174669. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174670. row != NULL && row_info != NULL &&
  174671. #endif
  174672. row_info->bit_depth < 8)
  174673. {
  174674. png_bytep rp, end, table;
  174675. end = row + row_info->rowbytes;
  174676. if (row_info->bit_depth == 1)
  174677. table = (png_bytep)onebppswaptable;
  174678. else if (row_info->bit_depth == 2)
  174679. table = (png_bytep)twobppswaptable;
  174680. else if (row_info->bit_depth == 4)
  174681. table = (png_bytep)fourbppswaptable;
  174682. else
  174683. return;
  174684. for (rp = row; rp < end; rp++)
  174685. *rp = table[*rp];
  174686. }
  174687. }
  174688. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  174689. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  174690. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  174691. void /* PRIVATE */
  174692. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  174693. {
  174694. png_debug(1, "in png_do_strip_filler\n");
  174695. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174696. if (row != NULL && row_info != NULL)
  174697. #endif
  174698. {
  174699. png_bytep sp=row;
  174700. png_bytep dp=row;
  174701. png_uint_32 row_width=row_info->width;
  174702. png_uint_32 i;
  174703. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  174704. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  174705. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174706. row_info->channels == 4)
  174707. {
  174708. if (row_info->bit_depth == 8)
  174709. {
  174710. if (flags & PNG_FLAG_FILLER_AFTER)
  174711. {
  174712. dp+=3; sp+=4;
  174713. for (i = 1; i < row_width; i++)
  174714. {
  174715. *dp++ = *sp++;
  174716. *dp++ = *sp++;
  174717. *dp++ = *sp++;
  174718. sp++;
  174719. }
  174720. }
  174721. else
  174722. {
  174723. for (i = 0; i < row_width; i++)
  174724. {
  174725. sp++;
  174726. *dp++ = *sp++;
  174727. *dp++ = *sp++;
  174728. *dp++ = *sp++;
  174729. }
  174730. }
  174731. row_info->pixel_depth = 24;
  174732. row_info->rowbytes = row_width * 3;
  174733. }
  174734. else /* if (row_info->bit_depth == 16) */
  174735. {
  174736. if (flags & PNG_FLAG_FILLER_AFTER)
  174737. {
  174738. sp += 8; dp += 6;
  174739. for (i = 1; i < row_width; i++)
  174740. {
  174741. *dp++ = *sp++;
  174742. *dp++ = *sp++;
  174743. *dp++ = *sp++;
  174744. *dp++ = *sp++;
  174745. *dp++ = *sp++;
  174746. *dp++ = *sp++;
  174747. sp += 2;
  174748. }
  174749. }
  174750. else
  174751. {
  174752. for (i = 0; i < row_width; i++)
  174753. {
  174754. sp+=2;
  174755. *dp++ = *sp++;
  174756. *dp++ = *sp++;
  174757. *dp++ = *sp++;
  174758. *dp++ = *sp++;
  174759. *dp++ = *sp++;
  174760. *dp++ = *sp++;
  174761. }
  174762. }
  174763. row_info->pixel_depth = 48;
  174764. row_info->rowbytes = row_width * 6;
  174765. }
  174766. row_info->channels = 3;
  174767. }
  174768. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  174769. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174770. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174771. row_info->channels == 2)
  174772. {
  174773. if (row_info->bit_depth == 8)
  174774. {
  174775. if (flags & PNG_FLAG_FILLER_AFTER)
  174776. {
  174777. for (i = 0; i < row_width; i++)
  174778. {
  174779. *dp++ = *sp++;
  174780. sp++;
  174781. }
  174782. }
  174783. else
  174784. {
  174785. for (i = 0; i < row_width; i++)
  174786. {
  174787. sp++;
  174788. *dp++ = *sp++;
  174789. }
  174790. }
  174791. row_info->pixel_depth = 8;
  174792. row_info->rowbytes = row_width;
  174793. }
  174794. else /* if (row_info->bit_depth == 16) */
  174795. {
  174796. if (flags & PNG_FLAG_FILLER_AFTER)
  174797. {
  174798. sp += 4; dp += 2;
  174799. for (i = 1; i < row_width; i++)
  174800. {
  174801. *dp++ = *sp++;
  174802. *dp++ = *sp++;
  174803. sp += 2;
  174804. }
  174805. }
  174806. else
  174807. {
  174808. for (i = 0; i < row_width; i++)
  174809. {
  174810. sp += 2;
  174811. *dp++ = *sp++;
  174812. *dp++ = *sp++;
  174813. }
  174814. }
  174815. row_info->pixel_depth = 16;
  174816. row_info->rowbytes = row_width * 2;
  174817. }
  174818. row_info->channels = 1;
  174819. }
  174820. if (flags & PNG_FLAG_STRIP_ALPHA)
  174821. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  174822. }
  174823. }
  174824. #endif
  174825. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174826. void /* PRIVATE */
  174827. png_do_bgr(png_row_infop row_info, png_bytep row)
  174828. {
  174829. png_debug(1, "in png_do_bgr\n");
  174830. if (
  174831. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174832. row != NULL && row_info != NULL &&
  174833. #endif
  174834. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  174835. {
  174836. png_uint_32 row_width = row_info->width;
  174837. if (row_info->bit_depth == 8)
  174838. {
  174839. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174840. {
  174841. png_bytep rp;
  174842. png_uint_32 i;
  174843. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  174844. {
  174845. png_byte save = *rp;
  174846. *rp = *(rp + 2);
  174847. *(rp + 2) = save;
  174848. }
  174849. }
  174850. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174851. {
  174852. png_bytep rp;
  174853. png_uint_32 i;
  174854. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  174855. {
  174856. png_byte save = *rp;
  174857. *rp = *(rp + 2);
  174858. *(rp + 2) = save;
  174859. }
  174860. }
  174861. }
  174862. else if (row_info->bit_depth == 16)
  174863. {
  174864. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174865. {
  174866. png_bytep rp;
  174867. png_uint_32 i;
  174868. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  174869. {
  174870. png_byte save = *rp;
  174871. *rp = *(rp + 4);
  174872. *(rp + 4) = save;
  174873. save = *(rp + 1);
  174874. *(rp + 1) = *(rp + 5);
  174875. *(rp + 5) = save;
  174876. }
  174877. }
  174878. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174879. {
  174880. png_bytep rp;
  174881. png_uint_32 i;
  174882. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  174883. {
  174884. png_byte save = *rp;
  174885. *rp = *(rp + 4);
  174886. *(rp + 4) = save;
  174887. save = *(rp + 1);
  174888. *(rp + 1) = *(rp + 5);
  174889. *(rp + 5) = save;
  174890. }
  174891. }
  174892. }
  174893. }
  174894. }
  174895. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  174896. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  174897. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  174898. defined(PNG_LEGACY_SUPPORTED)
  174899. void PNGAPI
  174900. png_set_user_transform_info(png_structp png_ptr, png_voidp
  174901. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  174902. {
  174903. png_debug(1, "in png_set_user_transform_info\n");
  174904. if(png_ptr == NULL) return;
  174905. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174906. png_ptr->user_transform_ptr = user_transform_ptr;
  174907. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  174908. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  174909. #else
  174910. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  174911. png_warning(png_ptr,
  174912. "This version of libpng does not support user transform info");
  174913. #endif
  174914. }
  174915. #endif
  174916. png_voidp PNGAPI
  174917. png_get_user_transform_ptr(png_structp png_ptr)
  174918. {
  174919. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174920. if (png_ptr == NULL) return (NULL);
  174921. return ((png_voidp)png_ptr->user_transform_ptr);
  174922. #else
  174923. return (NULL);
  174924. #endif
  174925. }
  174926. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174927. /*** End of inlined file: pngtrans.c ***/
  174928. /*** Start of inlined file: pngwio.c ***/
  174929. #define PNG_INTERNAL
  174930. #ifdef PNG_WRITE_SUPPORTED
  174931. void /* PRIVATE */
  174932. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174933. {
  174934. if (png_ptr->write_data_fn != NULL )
  174935. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  174936. else
  174937. png_error(png_ptr, "Call to NULL write function");
  174938. }
  174939. #if !defined(PNG_NO_STDIO)
  174940. #ifndef USE_FAR_KEYWORD
  174941. void PNGAPI
  174942. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174943. {
  174944. png_uint_32 check;
  174945. if(png_ptr == NULL) return;
  174946. #if defined(_WIN32_WCE)
  174947. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  174948. check = 0;
  174949. #else
  174950. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  174951. #endif
  174952. if (check != length)
  174953. png_error(png_ptr, "Write Error");
  174954. }
  174955. #else
  174956. #define NEAR_BUF_SIZE 1024
  174957. #define MIN(a,b) (a <= b ? a : b)
  174958. void PNGAPI
  174959. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174960. {
  174961. png_uint_32 check;
  174962. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  174963. png_FILE_p io_ptr;
  174964. if(png_ptr == NULL) return;
  174965. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  174966. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  174967. if ((png_bytep)near_data == data)
  174968. {
  174969. #if defined(_WIN32_WCE)
  174970. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  174971. check = 0;
  174972. #else
  174973. check = fwrite(near_data, 1, length, io_ptr);
  174974. #endif
  174975. }
  174976. else
  174977. {
  174978. png_byte buf[NEAR_BUF_SIZE];
  174979. png_size_t written, remaining, err;
  174980. check = 0;
  174981. remaining = length;
  174982. do
  174983. {
  174984. written = MIN(NEAR_BUF_SIZE, remaining);
  174985. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  174986. #if defined(_WIN32_WCE)
  174987. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  174988. err = 0;
  174989. #else
  174990. err = fwrite(buf, 1, written, io_ptr);
  174991. #endif
  174992. if (err != written)
  174993. break;
  174994. else
  174995. check += err;
  174996. data += written;
  174997. remaining -= written;
  174998. }
  174999. while (remaining != 0);
  175000. }
  175001. if (check != length)
  175002. png_error(png_ptr, "Write Error");
  175003. }
  175004. #endif
  175005. #endif
  175006. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175007. void /* PRIVATE */
  175008. png_flush(png_structp png_ptr)
  175009. {
  175010. if (png_ptr->output_flush_fn != NULL)
  175011. (*(png_ptr->output_flush_fn))(png_ptr);
  175012. }
  175013. #if !defined(PNG_NO_STDIO)
  175014. void PNGAPI
  175015. png_default_flush(png_structp png_ptr)
  175016. {
  175017. #if !defined(_WIN32_WCE)
  175018. png_FILE_p io_ptr;
  175019. #endif
  175020. if(png_ptr == NULL) return;
  175021. #if !defined(_WIN32_WCE)
  175022. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175023. if (io_ptr != NULL)
  175024. fflush(io_ptr);
  175025. #endif
  175026. }
  175027. #endif
  175028. #endif
  175029. void PNGAPI
  175030. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175031. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175032. {
  175033. if(png_ptr == NULL) return;
  175034. png_ptr->io_ptr = io_ptr;
  175035. #if !defined(PNG_NO_STDIO)
  175036. if (write_data_fn != NULL)
  175037. png_ptr->write_data_fn = write_data_fn;
  175038. else
  175039. png_ptr->write_data_fn = png_default_write_data;
  175040. #else
  175041. png_ptr->write_data_fn = write_data_fn;
  175042. #endif
  175043. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175044. #if !defined(PNG_NO_STDIO)
  175045. if (output_flush_fn != NULL)
  175046. png_ptr->output_flush_fn = output_flush_fn;
  175047. else
  175048. png_ptr->output_flush_fn = png_default_flush;
  175049. #else
  175050. png_ptr->output_flush_fn = output_flush_fn;
  175051. #endif
  175052. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175053. if (png_ptr->read_data_fn != NULL)
  175054. {
  175055. png_ptr->read_data_fn = NULL;
  175056. png_warning(png_ptr,
  175057. "Attempted to set both read_data_fn and write_data_fn in");
  175058. png_warning(png_ptr,
  175059. "the same structure. Resetting read_data_fn to NULL.");
  175060. }
  175061. }
  175062. #if defined(USE_FAR_KEYWORD)
  175063. #if defined(_MSC_VER)
  175064. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175065. {
  175066. void *near_ptr;
  175067. void FAR *far_ptr;
  175068. FP_OFF(near_ptr) = FP_OFF(ptr);
  175069. far_ptr = (void FAR *)near_ptr;
  175070. if(check != 0)
  175071. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175072. png_error(png_ptr,"segment lost in conversion");
  175073. return(near_ptr);
  175074. }
  175075. # else
  175076. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175077. {
  175078. void *near_ptr;
  175079. void FAR *far_ptr;
  175080. near_ptr = (void FAR *)ptr;
  175081. far_ptr = (void FAR *)near_ptr;
  175082. if(check != 0)
  175083. if(far_ptr != ptr)
  175084. png_error(png_ptr,"segment lost in conversion");
  175085. return(near_ptr);
  175086. }
  175087. # endif
  175088. # endif
  175089. #endif /* PNG_WRITE_SUPPORTED */
  175090. /*** End of inlined file: pngwio.c ***/
  175091. /*** Start of inlined file: pngwrite.c ***/
  175092. #define PNG_INTERNAL
  175093. #ifdef PNG_WRITE_SUPPORTED
  175094. void PNGAPI
  175095. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175096. {
  175097. png_debug(1, "in png_write_info_before_PLTE\n");
  175098. if (png_ptr == NULL || info_ptr == NULL)
  175099. return;
  175100. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175101. {
  175102. png_write_sig(png_ptr); /* write PNG signature */
  175103. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175104. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175105. {
  175106. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175107. png_ptr->mng_features_permitted=0;
  175108. }
  175109. #endif
  175110. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175111. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175112. info_ptr->filter_type,
  175113. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175114. info_ptr->interlace_type);
  175115. #else
  175116. 0);
  175117. #endif
  175118. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175119. if (info_ptr->valid & PNG_INFO_gAMA)
  175120. {
  175121. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175122. png_write_gAMA(png_ptr, info_ptr->gamma);
  175123. #else
  175124. #ifdef PNG_FIXED_POINT_SUPPORTED
  175125. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175126. # endif
  175127. #endif
  175128. }
  175129. #endif
  175130. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175131. if (info_ptr->valid & PNG_INFO_sRGB)
  175132. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175133. #endif
  175134. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175135. if (info_ptr->valid & PNG_INFO_iCCP)
  175136. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175137. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175138. #endif
  175139. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175140. if (info_ptr->valid & PNG_INFO_sBIT)
  175141. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175142. #endif
  175143. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175144. if (info_ptr->valid & PNG_INFO_cHRM)
  175145. {
  175146. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175147. png_write_cHRM(png_ptr,
  175148. info_ptr->x_white, info_ptr->y_white,
  175149. info_ptr->x_red, info_ptr->y_red,
  175150. info_ptr->x_green, info_ptr->y_green,
  175151. info_ptr->x_blue, info_ptr->y_blue);
  175152. #else
  175153. # ifdef PNG_FIXED_POINT_SUPPORTED
  175154. png_write_cHRM_fixed(png_ptr,
  175155. info_ptr->int_x_white, info_ptr->int_y_white,
  175156. info_ptr->int_x_red, info_ptr->int_y_red,
  175157. info_ptr->int_x_green, info_ptr->int_y_green,
  175158. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175159. # endif
  175160. #endif
  175161. }
  175162. #endif
  175163. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175164. if (info_ptr->unknown_chunks_num)
  175165. {
  175166. png_unknown_chunk *up;
  175167. png_debug(5, "writing extra chunks\n");
  175168. for (up = info_ptr->unknown_chunks;
  175169. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175170. up++)
  175171. {
  175172. int keep=png_handle_as_unknown(png_ptr, up->name);
  175173. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175174. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175175. !(up->location & PNG_HAVE_IDAT) &&
  175176. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175177. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175178. {
  175179. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175180. }
  175181. }
  175182. }
  175183. #endif
  175184. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175185. }
  175186. }
  175187. void PNGAPI
  175188. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175189. {
  175190. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175191. int i;
  175192. #endif
  175193. png_debug(1, "in png_write_info\n");
  175194. if (png_ptr == NULL || info_ptr == NULL)
  175195. return;
  175196. png_write_info_before_PLTE(png_ptr, info_ptr);
  175197. if (info_ptr->valid & PNG_INFO_PLTE)
  175198. png_write_PLTE(png_ptr, info_ptr->palette,
  175199. (png_uint_32)info_ptr->num_palette);
  175200. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175201. png_error(png_ptr, "Valid palette required for paletted images");
  175202. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175203. if (info_ptr->valid & PNG_INFO_tRNS)
  175204. {
  175205. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175206. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175207. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175208. {
  175209. int j;
  175210. for (j=0; j<(int)info_ptr->num_trans; j++)
  175211. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175212. }
  175213. #endif
  175214. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175215. info_ptr->num_trans, info_ptr->color_type);
  175216. }
  175217. #endif
  175218. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175219. if (info_ptr->valid & PNG_INFO_bKGD)
  175220. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175221. #endif
  175222. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175223. if (info_ptr->valid & PNG_INFO_hIST)
  175224. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175225. #endif
  175226. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175227. if (info_ptr->valid & PNG_INFO_oFFs)
  175228. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175229. info_ptr->offset_unit_type);
  175230. #endif
  175231. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175232. if (info_ptr->valid & PNG_INFO_pCAL)
  175233. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175234. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175235. info_ptr->pcal_units, info_ptr->pcal_params);
  175236. #endif
  175237. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175238. if (info_ptr->valid & PNG_INFO_sCAL)
  175239. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175240. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175241. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175242. #else
  175243. #ifdef PNG_FIXED_POINT_SUPPORTED
  175244. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175245. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175246. #else
  175247. png_warning(png_ptr,
  175248. "png_write_sCAL not supported; sCAL chunk not written.");
  175249. #endif
  175250. #endif
  175251. #endif
  175252. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175253. if (info_ptr->valid & PNG_INFO_pHYs)
  175254. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175255. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175256. #endif
  175257. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175258. if (info_ptr->valid & PNG_INFO_tIME)
  175259. {
  175260. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175261. png_ptr->mode |= PNG_WROTE_tIME;
  175262. }
  175263. #endif
  175264. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175265. if (info_ptr->valid & PNG_INFO_sPLT)
  175266. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175267. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175268. #endif
  175269. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175270. for (i = 0; i < info_ptr->num_text; i++)
  175271. {
  175272. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175273. info_ptr->text[i].compression);
  175274. if (info_ptr->text[i].compression > 0)
  175275. {
  175276. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175277. png_write_iTXt(png_ptr,
  175278. info_ptr->text[i].compression,
  175279. info_ptr->text[i].key,
  175280. info_ptr->text[i].lang,
  175281. info_ptr->text[i].lang_key,
  175282. info_ptr->text[i].text);
  175283. #else
  175284. png_warning(png_ptr, "Unable to write international text");
  175285. #endif
  175286. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175287. }
  175288. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175289. {
  175290. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175291. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175292. info_ptr->text[i].text, 0,
  175293. info_ptr->text[i].compression);
  175294. #else
  175295. png_warning(png_ptr, "Unable to write compressed text");
  175296. #endif
  175297. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175298. }
  175299. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175300. {
  175301. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175302. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175303. info_ptr->text[i].text,
  175304. 0);
  175305. #else
  175306. png_warning(png_ptr, "Unable to write uncompressed text");
  175307. #endif
  175308. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175309. }
  175310. }
  175311. #endif
  175312. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175313. if (info_ptr->unknown_chunks_num)
  175314. {
  175315. png_unknown_chunk *up;
  175316. png_debug(5, "writing extra chunks\n");
  175317. for (up = info_ptr->unknown_chunks;
  175318. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175319. up++)
  175320. {
  175321. int keep=png_handle_as_unknown(png_ptr, up->name);
  175322. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175323. up->location && (up->location & PNG_HAVE_PLTE) &&
  175324. !(up->location & PNG_HAVE_IDAT) &&
  175325. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175326. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175327. {
  175328. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175329. }
  175330. }
  175331. }
  175332. #endif
  175333. }
  175334. void PNGAPI
  175335. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175336. {
  175337. png_debug(1, "in png_write_end\n");
  175338. if (png_ptr == NULL)
  175339. return;
  175340. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175341. png_error(png_ptr, "No IDATs written into file");
  175342. if (info_ptr != NULL)
  175343. {
  175344. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175345. int i; /* local index variable */
  175346. #endif
  175347. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175348. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175349. !(png_ptr->mode & PNG_WROTE_tIME))
  175350. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175351. #endif
  175352. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175353. for (i = 0; i < info_ptr->num_text; i++)
  175354. {
  175355. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175356. info_ptr->text[i].compression);
  175357. if (info_ptr->text[i].compression > 0)
  175358. {
  175359. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175360. png_write_iTXt(png_ptr,
  175361. info_ptr->text[i].compression,
  175362. info_ptr->text[i].key,
  175363. info_ptr->text[i].lang,
  175364. info_ptr->text[i].lang_key,
  175365. info_ptr->text[i].text);
  175366. #else
  175367. png_warning(png_ptr, "Unable to write international text");
  175368. #endif
  175369. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175370. }
  175371. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175372. {
  175373. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175374. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175375. info_ptr->text[i].text, 0,
  175376. info_ptr->text[i].compression);
  175377. #else
  175378. png_warning(png_ptr, "Unable to write compressed text");
  175379. #endif
  175380. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175381. }
  175382. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175383. {
  175384. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175385. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175386. info_ptr->text[i].text, 0);
  175387. #else
  175388. png_warning(png_ptr, "Unable to write uncompressed text");
  175389. #endif
  175390. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175391. }
  175392. }
  175393. #endif
  175394. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175395. if (info_ptr->unknown_chunks_num)
  175396. {
  175397. png_unknown_chunk *up;
  175398. png_debug(5, "writing extra chunks\n");
  175399. for (up = info_ptr->unknown_chunks;
  175400. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175401. up++)
  175402. {
  175403. int keep=png_handle_as_unknown(png_ptr, up->name);
  175404. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175405. up->location && (up->location & PNG_AFTER_IDAT) &&
  175406. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175407. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175408. {
  175409. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175410. }
  175411. }
  175412. }
  175413. #endif
  175414. }
  175415. png_ptr->mode |= PNG_AFTER_IDAT;
  175416. png_write_IEND(png_ptr);
  175417. }
  175418. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175419. #if !defined(_WIN32_WCE)
  175420. void PNGAPI
  175421. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175422. {
  175423. png_debug(1, "in png_convert_from_struct_tm\n");
  175424. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175425. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175426. ptime->day = (png_byte)ttime->tm_mday;
  175427. ptime->hour = (png_byte)ttime->tm_hour;
  175428. ptime->minute = (png_byte)ttime->tm_min;
  175429. ptime->second = (png_byte)ttime->tm_sec;
  175430. }
  175431. void PNGAPI
  175432. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175433. {
  175434. struct tm *tbuf;
  175435. png_debug(1, "in png_convert_from_time_t\n");
  175436. tbuf = gmtime(&ttime);
  175437. png_convert_from_struct_tm(ptime, tbuf);
  175438. }
  175439. #endif
  175440. #endif
  175441. png_structp PNGAPI
  175442. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175443. png_error_ptr error_fn, png_error_ptr warn_fn)
  175444. {
  175445. #ifdef PNG_USER_MEM_SUPPORTED
  175446. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175447. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175448. }
  175449. png_structp PNGAPI
  175450. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175451. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175452. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175453. {
  175454. #endif /* PNG_USER_MEM_SUPPORTED */
  175455. png_structp png_ptr;
  175456. #ifdef PNG_SETJMP_SUPPORTED
  175457. #ifdef USE_FAR_KEYWORD
  175458. jmp_buf jmpbuf;
  175459. #endif
  175460. #endif
  175461. int i;
  175462. png_debug(1, "in png_create_write_struct\n");
  175463. #ifdef PNG_USER_MEM_SUPPORTED
  175464. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175465. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175466. #else
  175467. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175468. #endif /* PNG_USER_MEM_SUPPORTED */
  175469. if (png_ptr == NULL)
  175470. return (NULL);
  175471. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175472. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175473. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175474. #endif
  175475. #ifdef PNG_SETJMP_SUPPORTED
  175476. #ifdef USE_FAR_KEYWORD
  175477. if (setjmp(jmpbuf))
  175478. #else
  175479. if (setjmp(png_ptr->jmpbuf))
  175480. #endif
  175481. {
  175482. png_free(png_ptr, png_ptr->zbuf);
  175483. png_ptr->zbuf=NULL;
  175484. png_destroy_struct(png_ptr);
  175485. return (NULL);
  175486. }
  175487. #ifdef USE_FAR_KEYWORD
  175488. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175489. #endif
  175490. #endif
  175491. #ifdef PNG_USER_MEM_SUPPORTED
  175492. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175493. #endif /* PNG_USER_MEM_SUPPORTED */
  175494. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175495. i=0;
  175496. do
  175497. {
  175498. if(user_png_ver[i] != png_libpng_ver[i])
  175499. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175500. } while (png_libpng_ver[i++]);
  175501. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175502. {
  175503. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175504. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175505. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175506. {
  175507. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175508. char msg[80];
  175509. if (user_png_ver)
  175510. {
  175511. png_snprintf(msg, 80,
  175512. "Application was compiled with png.h from libpng-%.20s",
  175513. user_png_ver);
  175514. png_warning(png_ptr, msg);
  175515. }
  175516. png_snprintf(msg, 80,
  175517. "Application is running with png.c from libpng-%.20s",
  175518. png_libpng_ver);
  175519. png_warning(png_ptr, msg);
  175520. #endif
  175521. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175522. png_ptr->flags=0;
  175523. #endif
  175524. png_error(png_ptr,
  175525. "Incompatible libpng version in application and library");
  175526. }
  175527. }
  175528. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175529. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175530. (png_uint_32)png_ptr->zbuf_size);
  175531. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175532. png_flush_ptr_NULL);
  175533. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175534. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175535. 1, png_doublep_NULL, png_doublep_NULL);
  175536. #endif
  175537. #ifdef PNG_SETJMP_SUPPORTED
  175538. #ifdef USE_FAR_KEYWORD
  175539. if (setjmp(jmpbuf))
  175540. PNG_ABORT();
  175541. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175542. #else
  175543. if (setjmp(png_ptr->jmpbuf))
  175544. PNG_ABORT();
  175545. #endif
  175546. #endif
  175547. return (png_ptr);
  175548. }
  175549. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175550. #undef png_write_init
  175551. void PNGAPI
  175552. png_write_init(png_structp png_ptr)
  175553. {
  175554. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  175555. }
  175556. void PNGAPI
  175557. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  175558. png_size_t png_struct_size, png_size_t png_info_size)
  175559. {
  175560. if(png_ptr == NULL) return;
  175561. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175562. if(png_sizeof(png_struct) > png_struct_size ||
  175563. png_sizeof(png_info) > png_info_size)
  175564. {
  175565. char msg[80];
  175566. png_ptr->warning_fn=NULL;
  175567. if (user_png_ver)
  175568. {
  175569. png_snprintf(msg, 80,
  175570. "Application was compiled with png.h from libpng-%.20s",
  175571. user_png_ver);
  175572. png_warning(png_ptr, msg);
  175573. }
  175574. png_snprintf(msg, 80,
  175575. "Application is running with png.c from libpng-%.20s",
  175576. png_libpng_ver);
  175577. png_warning(png_ptr, msg);
  175578. }
  175579. #endif
  175580. if(png_sizeof(png_struct) > png_struct_size)
  175581. {
  175582. png_ptr->error_fn=NULL;
  175583. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175584. png_ptr->flags=0;
  175585. #endif
  175586. png_error(png_ptr,
  175587. "The png struct allocated by the application for writing is too small.");
  175588. }
  175589. if(png_sizeof(png_info) > png_info_size)
  175590. {
  175591. png_ptr->error_fn=NULL;
  175592. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175593. png_ptr->flags=0;
  175594. #endif
  175595. png_error(png_ptr,
  175596. "The info struct allocated by the application for writing is too small.");
  175597. }
  175598. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  175599. }
  175600. #endif /* PNG_1_0_X || PNG_1_2_X */
  175601. void PNGAPI
  175602. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  175603. png_size_t png_struct_size)
  175604. {
  175605. png_structp png_ptr=*ptr_ptr;
  175606. #ifdef PNG_SETJMP_SUPPORTED
  175607. jmp_buf tmp_jmp; /* to save current jump buffer */
  175608. #endif
  175609. int i = 0;
  175610. if (png_ptr == NULL)
  175611. return;
  175612. do
  175613. {
  175614. if (user_png_ver[i] != png_libpng_ver[i])
  175615. {
  175616. #ifdef PNG_LEGACY_SUPPORTED
  175617. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175618. #else
  175619. png_ptr->warning_fn=NULL;
  175620. png_warning(png_ptr,
  175621. "Application uses deprecated png_write_init() and should be recompiled.");
  175622. break;
  175623. #endif
  175624. }
  175625. } while (png_libpng_ver[i++]);
  175626. png_debug(1, "in png_write_init_3\n");
  175627. #ifdef PNG_SETJMP_SUPPORTED
  175628. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175629. #endif
  175630. if (png_sizeof(png_struct) > png_struct_size)
  175631. {
  175632. png_destroy_struct(png_ptr);
  175633. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175634. *ptr_ptr = png_ptr;
  175635. }
  175636. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175637. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175638. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175639. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175640. #endif
  175641. #ifdef PNG_SETJMP_SUPPORTED
  175642. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175643. #endif
  175644. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175645. png_flush_ptr_NULL);
  175646. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175647. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175648. (png_uint_32)png_ptr->zbuf_size);
  175649. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175650. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175651. 1, png_doublep_NULL, png_doublep_NULL);
  175652. #endif
  175653. }
  175654. void PNGAPI
  175655. png_write_rows(png_structp png_ptr, png_bytepp row,
  175656. png_uint_32 num_rows)
  175657. {
  175658. png_uint_32 i; /* row counter */
  175659. png_bytepp rp; /* row pointer */
  175660. png_debug(1, "in png_write_rows\n");
  175661. if (png_ptr == NULL)
  175662. return;
  175663. for (i = 0, rp = row; i < num_rows; i++, rp++)
  175664. {
  175665. png_write_row(png_ptr, *rp);
  175666. }
  175667. }
  175668. void PNGAPI
  175669. png_write_image(png_structp png_ptr, png_bytepp image)
  175670. {
  175671. png_uint_32 i; /* row index */
  175672. int pass, num_pass; /* pass variables */
  175673. png_bytepp rp; /* points to current row */
  175674. if (png_ptr == NULL)
  175675. return;
  175676. png_debug(1, "in png_write_image\n");
  175677. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175678. num_pass = png_set_interlace_handling(png_ptr);
  175679. #else
  175680. num_pass = 1;
  175681. #endif
  175682. for (pass = 0; pass < num_pass; pass++)
  175683. {
  175684. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  175685. {
  175686. png_write_row(png_ptr, *rp);
  175687. }
  175688. }
  175689. }
  175690. void PNGAPI
  175691. png_write_row(png_structp png_ptr, png_bytep row)
  175692. {
  175693. if (png_ptr == NULL)
  175694. return;
  175695. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  175696. png_ptr->row_number, png_ptr->pass);
  175697. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  175698. {
  175699. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175700. png_error(png_ptr,
  175701. "png_write_info was never called before png_write_row.");
  175702. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  175703. if (png_ptr->transformations & PNG_INVERT_MONO)
  175704. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  175705. #endif
  175706. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  175707. if (png_ptr->transformations & PNG_FILLER)
  175708. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  175709. #endif
  175710. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  175711. if (png_ptr->transformations & PNG_PACKSWAP)
  175712. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  175713. #endif
  175714. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  175715. if (png_ptr->transformations & PNG_PACK)
  175716. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  175717. #endif
  175718. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  175719. if (png_ptr->transformations & PNG_SHIFT)
  175720. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  175721. #endif
  175722. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  175723. if (png_ptr->transformations & PNG_BGR)
  175724. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  175725. #endif
  175726. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  175727. if (png_ptr->transformations & PNG_SWAP_BYTES)
  175728. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  175729. #endif
  175730. png_write_start_row(png_ptr);
  175731. }
  175732. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175733. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  175734. {
  175735. switch (png_ptr->pass)
  175736. {
  175737. case 0:
  175738. if (png_ptr->row_number & 0x07)
  175739. {
  175740. png_write_finish_row(png_ptr);
  175741. return;
  175742. }
  175743. break;
  175744. case 1:
  175745. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  175746. {
  175747. png_write_finish_row(png_ptr);
  175748. return;
  175749. }
  175750. break;
  175751. case 2:
  175752. if ((png_ptr->row_number & 0x07) != 4)
  175753. {
  175754. png_write_finish_row(png_ptr);
  175755. return;
  175756. }
  175757. break;
  175758. case 3:
  175759. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  175760. {
  175761. png_write_finish_row(png_ptr);
  175762. return;
  175763. }
  175764. break;
  175765. case 4:
  175766. if ((png_ptr->row_number & 0x03) != 2)
  175767. {
  175768. png_write_finish_row(png_ptr);
  175769. return;
  175770. }
  175771. break;
  175772. case 5:
  175773. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  175774. {
  175775. png_write_finish_row(png_ptr);
  175776. return;
  175777. }
  175778. break;
  175779. case 6:
  175780. if (!(png_ptr->row_number & 0x01))
  175781. {
  175782. png_write_finish_row(png_ptr);
  175783. return;
  175784. }
  175785. break;
  175786. }
  175787. }
  175788. #endif
  175789. png_ptr->row_info.color_type = png_ptr->color_type;
  175790. png_ptr->row_info.width = png_ptr->usr_width;
  175791. png_ptr->row_info.channels = png_ptr->usr_channels;
  175792. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  175793. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  175794. png_ptr->row_info.channels);
  175795. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  175796. png_ptr->row_info.width);
  175797. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  175798. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  175799. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  175800. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  175801. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  175802. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  175803. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  175804. png_ptr->row_info.rowbytes);
  175805. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175806. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  175807. (png_ptr->transformations & PNG_INTERLACE))
  175808. {
  175809. png_do_write_interlace(&(png_ptr->row_info),
  175810. png_ptr->row_buf + 1, png_ptr->pass);
  175811. if (!(png_ptr->row_info.width))
  175812. {
  175813. png_write_finish_row(png_ptr);
  175814. return;
  175815. }
  175816. }
  175817. #endif
  175818. if (png_ptr->transformations)
  175819. png_do_write_transformations(png_ptr);
  175820. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175821. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175822. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  175823. {
  175824. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  175825. }
  175826. #endif
  175827. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  175828. if (png_ptr->write_row_fn != NULL)
  175829. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  175830. }
  175831. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175832. void PNGAPI
  175833. png_set_flush(png_structp png_ptr, int nrows)
  175834. {
  175835. png_debug(1, "in png_set_flush\n");
  175836. if (png_ptr == NULL)
  175837. return;
  175838. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  175839. }
  175840. void PNGAPI
  175841. png_write_flush(png_structp png_ptr)
  175842. {
  175843. int wrote_IDAT;
  175844. png_debug(1, "in png_write_flush\n");
  175845. if (png_ptr == NULL)
  175846. return;
  175847. if (png_ptr->row_number >= png_ptr->num_rows)
  175848. return;
  175849. do
  175850. {
  175851. int ret;
  175852. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  175853. wrote_IDAT = 0;
  175854. if (ret != Z_OK)
  175855. {
  175856. if (png_ptr->zstream.msg != NULL)
  175857. png_error(png_ptr, png_ptr->zstream.msg);
  175858. else
  175859. png_error(png_ptr, "zlib error");
  175860. }
  175861. if (!(png_ptr->zstream.avail_out))
  175862. {
  175863. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175864. png_ptr->zbuf_size);
  175865. png_ptr->zstream.next_out = png_ptr->zbuf;
  175866. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175867. wrote_IDAT = 1;
  175868. }
  175869. } while(wrote_IDAT == 1);
  175870. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  175871. {
  175872. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175873. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  175874. png_ptr->zstream.next_out = png_ptr->zbuf;
  175875. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175876. }
  175877. png_ptr->flush_rows = 0;
  175878. png_flush(png_ptr);
  175879. }
  175880. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175881. void PNGAPI
  175882. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  175883. {
  175884. png_structp png_ptr = NULL;
  175885. png_infop info_ptr = NULL;
  175886. #ifdef PNG_USER_MEM_SUPPORTED
  175887. png_free_ptr free_fn = NULL;
  175888. png_voidp mem_ptr = NULL;
  175889. #endif
  175890. png_debug(1, "in png_destroy_write_struct\n");
  175891. if (png_ptr_ptr != NULL)
  175892. {
  175893. png_ptr = *png_ptr_ptr;
  175894. #ifdef PNG_USER_MEM_SUPPORTED
  175895. free_fn = png_ptr->free_fn;
  175896. mem_ptr = png_ptr->mem_ptr;
  175897. #endif
  175898. }
  175899. if (info_ptr_ptr != NULL)
  175900. info_ptr = *info_ptr_ptr;
  175901. if (info_ptr != NULL)
  175902. {
  175903. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  175904. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  175905. if (png_ptr->num_chunk_list)
  175906. {
  175907. png_free(png_ptr, png_ptr->chunk_list);
  175908. png_ptr->chunk_list=NULL;
  175909. png_ptr->num_chunk_list=0;
  175910. }
  175911. #endif
  175912. #ifdef PNG_USER_MEM_SUPPORTED
  175913. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  175914. (png_voidp)mem_ptr);
  175915. #else
  175916. png_destroy_struct((png_voidp)info_ptr);
  175917. #endif
  175918. *info_ptr_ptr = NULL;
  175919. }
  175920. if (png_ptr != NULL)
  175921. {
  175922. png_write_destroy(png_ptr);
  175923. #ifdef PNG_USER_MEM_SUPPORTED
  175924. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  175925. (png_voidp)mem_ptr);
  175926. #else
  175927. png_destroy_struct((png_voidp)png_ptr);
  175928. #endif
  175929. *png_ptr_ptr = NULL;
  175930. }
  175931. }
  175932. void /* PRIVATE */
  175933. png_write_destroy(png_structp png_ptr)
  175934. {
  175935. #ifdef PNG_SETJMP_SUPPORTED
  175936. jmp_buf tmp_jmp; /* save jump buffer */
  175937. #endif
  175938. png_error_ptr error_fn;
  175939. png_error_ptr warning_fn;
  175940. png_voidp error_ptr;
  175941. #ifdef PNG_USER_MEM_SUPPORTED
  175942. png_free_ptr free_fn;
  175943. #endif
  175944. png_debug(1, "in png_write_destroy\n");
  175945. deflateEnd(&png_ptr->zstream);
  175946. png_free(png_ptr, png_ptr->zbuf);
  175947. png_free(png_ptr, png_ptr->row_buf);
  175948. png_free(png_ptr, png_ptr->prev_row);
  175949. png_free(png_ptr, png_ptr->sub_row);
  175950. png_free(png_ptr, png_ptr->up_row);
  175951. png_free(png_ptr, png_ptr->avg_row);
  175952. png_free(png_ptr, png_ptr->paeth_row);
  175953. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  175954. png_free(png_ptr, png_ptr->time_buffer);
  175955. #endif
  175956. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175957. png_free(png_ptr, png_ptr->prev_filters);
  175958. png_free(png_ptr, png_ptr->filter_weights);
  175959. png_free(png_ptr, png_ptr->inv_filter_weights);
  175960. png_free(png_ptr, png_ptr->filter_costs);
  175961. png_free(png_ptr, png_ptr->inv_filter_costs);
  175962. #endif
  175963. #ifdef PNG_SETJMP_SUPPORTED
  175964. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175965. #endif
  175966. error_fn = png_ptr->error_fn;
  175967. warning_fn = png_ptr->warning_fn;
  175968. error_ptr = png_ptr->error_ptr;
  175969. #ifdef PNG_USER_MEM_SUPPORTED
  175970. free_fn = png_ptr->free_fn;
  175971. #endif
  175972. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175973. png_ptr->error_fn = error_fn;
  175974. png_ptr->warning_fn = warning_fn;
  175975. png_ptr->error_ptr = error_ptr;
  175976. #ifdef PNG_USER_MEM_SUPPORTED
  175977. png_ptr->free_fn = free_fn;
  175978. #endif
  175979. #ifdef PNG_SETJMP_SUPPORTED
  175980. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175981. #endif
  175982. }
  175983. void PNGAPI
  175984. png_set_filter(png_structp png_ptr, int method, int filters)
  175985. {
  175986. png_debug(1, "in png_set_filter\n");
  175987. if (png_ptr == NULL)
  175988. return;
  175989. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175990. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175991. (method == PNG_INTRAPIXEL_DIFFERENCING))
  175992. method = PNG_FILTER_TYPE_BASE;
  175993. #endif
  175994. if (method == PNG_FILTER_TYPE_BASE)
  175995. {
  175996. switch (filters & (PNG_ALL_FILTERS | 0x07))
  175997. {
  175998. #ifndef PNG_NO_WRITE_FILTER
  175999. case 5:
  176000. case 6:
  176001. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  176002. #endif /* PNG_NO_WRITE_FILTER */
  176003. case PNG_FILTER_VALUE_NONE:
  176004. png_ptr->do_filter=PNG_FILTER_NONE; break;
  176005. #ifndef PNG_NO_WRITE_FILTER
  176006. case PNG_FILTER_VALUE_SUB:
  176007. png_ptr->do_filter=PNG_FILTER_SUB; break;
  176008. case PNG_FILTER_VALUE_UP:
  176009. png_ptr->do_filter=PNG_FILTER_UP; break;
  176010. case PNG_FILTER_VALUE_AVG:
  176011. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176012. case PNG_FILTER_VALUE_PAETH:
  176013. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176014. default: png_ptr->do_filter = (png_byte)filters; break;
  176015. #else
  176016. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176017. #endif /* PNG_NO_WRITE_FILTER */
  176018. }
  176019. if (png_ptr->row_buf != NULL)
  176020. {
  176021. #ifndef PNG_NO_WRITE_FILTER
  176022. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176023. {
  176024. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176025. (png_ptr->rowbytes + 1));
  176026. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176027. }
  176028. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176029. {
  176030. if (png_ptr->prev_row == NULL)
  176031. {
  176032. png_warning(png_ptr, "Can't add Up filter after starting");
  176033. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176034. }
  176035. else
  176036. {
  176037. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176038. (png_ptr->rowbytes + 1));
  176039. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176040. }
  176041. }
  176042. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176043. {
  176044. if (png_ptr->prev_row == NULL)
  176045. {
  176046. png_warning(png_ptr, "Can't add Average filter after starting");
  176047. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176048. }
  176049. else
  176050. {
  176051. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176052. (png_ptr->rowbytes + 1));
  176053. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176054. }
  176055. }
  176056. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176057. png_ptr->paeth_row == NULL)
  176058. {
  176059. if (png_ptr->prev_row == NULL)
  176060. {
  176061. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176062. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176063. }
  176064. else
  176065. {
  176066. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176067. (png_ptr->rowbytes + 1));
  176068. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176069. }
  176070. }
  176071. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176072. #endif /* PNG_NO_WRITE_FILTER */
  176073. png_ptr->do_filter = PNG_FILTER_NONE;
  176074. }
  176075. }
  176076. else
  176077. png_error(png_ptr, "Unknown custom filter method");
  176078. }
  176079. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176080. void PNGAPI
  176081. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176082. int num_weights, png_doublep filter_weights,
  176083. png_doublep filter_costs)
  176084. {
  176085. int i;
  176086. png_debug(1, "in png_set_filter_heuristics\n");
  176087. if (png_ptr == NULL)
  176088. return;
  176089. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176090. {
  176091. png_warning(png_ptr, "Unknown filter heuristic method");
  176092. return;
  176093. }
  176094. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176095. {
  176096. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176097. }
  176098. if (num_weights < 0 || filter_weights == NULL ||
  176099. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176100. {
  176101. num_weights = 0;
  176102. }
  176103. png_ptr->num_prev_filters = (png_byte)num_weights;
  176104. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176105. if (num_weights > 0)
  176106. {
  176107. if (png_ptr->prev_filters == NULL)
  176108. {
  176109. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176110. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176111. for (i = 0; i < num_weights; i++)
  176112. {
  176113. png_ptr->prev_filters[i] = 255;
  176114. }
  176115. }
  176116. if (png_ptr->filter_weights == NULL)
  176117. {
  176118. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176119. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176120. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176121. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176122. for (i = 0; i < num_weights; i++)
  176123. {
  176124. png_ptr->inv_filter_weights[i] =
  176125. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176126. }
  176127. }
  176128. for (i = 0; i < num_weights; i++)
  176129. {
  176130. if (filter_weights[i] < 0.0)
  176131. {
  176132. png_ptr->inv_filter_weights[i] =
  176133. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176134. }
  176135. else
  176136. {
  176137. png_ptr->inv_filter_weights[i] =
  176138. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176139. png_ptr->filter_weights[i] =
  176140. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176141. }
  176142. }
  176143. }
  176144. if (png_ptr->filter_costs == NULL)
  176145. {
  176146. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176147. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176148. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176149. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176150. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176151. {
  176152. png_ptr->inv_filter_costs[i] =
  176153. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176154. }
  176155. }
  176156. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176157. {
  176158. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176159. {
  176160. png_ptr->inv_filter_costs[i] =
  176161. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176162. }
  176163. else if (filter_costs[i] >= 1.0)
  176164. {
  176165. png_ptr->inv_filter_costs[i] =
  176166. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176167. png_ptr->filter_costs[i] =
  176168. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176169. }
  176170. }
  176171. }
  176172. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176173. void PNGAPI
  176174. png_set_compression_level(png_structp png_ptr, int level)
  176175. {
  176176. png_debug(1, "in png_set_compression_level\n");
  176177. if (png_ptr == NULL)
  176178. return;
  176179. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176180. png_ptr->zlib_level = level;
  176181. }
  176182. void PNGAPI
  176183. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176184. {
  176185. png_debug(1, "in png_set_compression_mem_level\n");
  176186. if (png_ptr == NULL)
  176187. return;
  176188. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176189. png_ptr->zlib_mem_level = mem_level;
  176190. }
  176191. void PNGAPI
  176192. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176193. {
  176194. png_debug(1, "in png_set_compression_strategy\n");
  176195. if (png_ptr == NULL)
  176196. return;
  176197. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176198. png_ptr->zlib_strategy = strategy;
  176199. }
  176200. void PNGAPI
  176201. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176202. {
  176203. if (png_ptr == NULL)
  176204. return;
  176205. if (window_bits > 15)
  176206. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176207. else if (window_bits < 8)
  176208. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176209. #ifndef WBITS_8_OK
  176210. if (window_bits == 8)
  176211. {
  176212. png_warning(png_ptr, "Compression window is being reset to 512");
  176213. window_bits=9;
  176214. }
  176215. #endif
  176216. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176217. png_ptr->zlib_window_bits = window_bits;
  176218. }
  176219. void PNGAPI
  176220. png_set_compression_method(png_structp png_ptr, int method)
  176221. {
  176222. png_debug(1, "in png_set_compression_method\n");
  176223. if (png_ptr == NULL)
  176224. return;
  176225. if (method != 8)
  176226. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176227. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176228. png_ptr->zlib_method = method;
  176229. }
  176230. void PNGAPI
  176231. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176232. {
  176233. if (png_ptr == NULL)
  176234. return;
  176235. png_ptr->write_row_fn = write_row_fn;
  176236. }
  176237. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176238. void PNGAPI
  176239. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176240. write_user_transform_fn)
  176241. {
  176242. png_debug(1, "in png_set_write_user_transform_fn\n");
  176243. if (png_ptr == NULL)
  176244. return;
  176245. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176246. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176247. }
  176248. #endif
  176249. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176250. void PNGAPI
  176251. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176252. int transforms, voidp params)
  176253. {
  176254. if (png_ptr == NULL || info_ptr == NULL)
  176255. return;
  176256. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176257. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176258. png_set_invert_alpha(png_ptr);
  176259. #endif
  176260. png_write_info(png_ptr, info_ptr);
  176261. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176262. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176263. png_set_invert_mono(png_ptr);
  176264. #endif
  176265. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176266. if ((transforms & PNG_TRANSFORM_SHIFT)
  176267. && (info_ptr->valid & PNG_INFO_sBIT))
  176268. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176269. #endif
  176270. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176271. if (transforms & PNG_TRANSFORM_PACKING)
  176272. png_set_packing(png_ptr);
  176273. #endif
  176274. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176275. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176276. png_set_swap_alpha(png_ptr);
  176277. #endif
  176278. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176279. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176280. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176281. #endif
  176282. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176283. if (transforms & PNG_TRANSFORM_BGR)
  176284. png_set_bgr(png_ptr);
  176285. #endif
  176286. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176287. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176288. png_set_swap(png_ptr);
  176289. #endif
  176290. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176291. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176292. png_set_packswap(png_ptr);
  176293. #endif
  176294. if (info_ptr->valid & PNG_INFO_IDAT)
  176295. png_write_image(png_ptr, info_ptr->row_pointers);
  176296. png_write_end(png_ptr, info_ptr);
  176297. transforms = transforms; /* quiet compiler warnings */
  176298. params = params;
  176299. }
  176300. #endif
  176301. #endif /* PNG_WRITE_SUPPORTED */
  176302. /*** End of inlined file: pngwrite.c ***/
  176303. /*** Start of inlined file: pngwtran.c ***/
  176304. #define PNG_INTERNAL
  176305. #ifdef PNG_WRITE_SUPPORTED
  176306. void /* PRIVATE */
  176307. png_do_write_transformations(png_structp png_ptr)
  176308. {
  176309. png_debug(1, "in png_do_write_transformations\n");
  176310. if (png_ptr == NULL)
  176311. return;
  176312. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176313. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176314. if(png_ptr->write_user_transform_fn != NULL)
  176315. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176316. (png_ptr, /* png_ptr */
  176317. &(png_ptr->row_info), /* row_info: */
  176318. png_ptr->row_buf + 1); /* start of pixel data for row */
  176319. #endif
  176320. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176321. if (png_ptr->transformations & PNG_FILLER)
  176322. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176323. png_ptr->flags);
  176324. #endif
  176325. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176326. if (png_ptr->transformations & PNG_PACKSWAP)
  176327. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176328. #endif
  176329. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176330. if (png_ptr->transformations & PNG_PACK)
  176331. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176332. (png_uint_32)png_ptr->bit_depth);
  176333. #endif
  176334. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176335. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176336. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176337. #endif
  176338. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176339. if (png_ptr->transformations & PNG_SHIFT)
  176340. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176341. &(png_ptr->shift));
  176342. #endif
  176343. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176344. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176345. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176346. #endif
  176347. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176348. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176349. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176350. #endif
  176351. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176352. if (png_ptr->transformations & PNG_BGR)
  176353. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176354. #endif
  176355. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176356. if (png_ptr->transformations & PNG_INVERT_MONO)
  176357. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176358. #endif
  176359. }
  176360. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176361. void /* PRIVATE */
  176362. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176363. {
  176364. png_debug(1, "in png_do_pack\n");
  176365. if (row_info->bit_depth == 8 &&
  176366. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176367. row != NULL && row_info != NULL &&
  176368. #endif
  176369. row_info->channels == 1)
  176370. {
  176371. switch ((int)bit_depth)
  176372. {
  176373. case 1:
  176374. {
  176375. png_bytep sp, dp;
  176376. int mask, v;
  176377. png_uint_32 i;
  176378. png_uint_32 row_width = row_info->width;
  176379. sp = row;
  176380. dp = row;
  176381. mask = 0x80;
  176382. v = 0;
  176383. for (i = 0; i < row_width; i++)
  176384. {
  176385. if (*sp != 0)
  176386. v |= mask;
  176387. sp++;
  176388. if (mask > 1)
  176389. mask >>= 1;
  176390. else
  176391. {
  176392. mask = 0x80;
  176393. *dp = (png_byte)v;
  176394. dp++;
  176395. v = 0;
  176396. }
  176397. }
  176398. if (mask != 0x80)
  176399. *dp = (png_byte)v;
  176400. break;
  176401. }
  176402. case 2:
  176403. {
  176404. png_bytep sp, dp;
  176405. int shift, v;
  176406. png_uint_32 i;
  176407. png_uint_32 row_width = row_info->width;
  176408. sp = row;
  176409. dp = row;
  176410. shift = 6;
  176411. v = 0;
  176412. for (i = 0; i < row_width; i++)
  176413. {
  176414. png_byte value;
  176415. value = (png_byte)(*sp & 0x03);
  176416. v |= (value << shift);
  176417. if (shift == 0)
  176418. {
  176419. shift = 6;
  176420. *dp = (png_byte)v;
  176421. dp++;
  176422. v = 0;
  176423. }
  176424. else
  176425. shift -= 2;
  176426. sp++;
  176427. }
  176428. if (shift != 6)
  176429. *dp = (png_byte)v;
  176430. break;
  176431. }
  176432. case 4:
  176433. {
  176434. png_bytep sp, dp;
  176435. int shift, v;
  176436. png_uint_32 i;
  176437. png_uint_32 row_width = row_info->width;
  176438. sp = row;
  176439. dp = row;
  176440. shift = 4;
  176441. v = 0;
  176442. for (i = 0; i < row_width; i++)
  176443. {
  176444. png_byte value;
  176445. value = (png_byte)(*sp & 0x0f);
  176446. v |= (value << shift);
  176447. if (shift == 0)
  176448. {
  176449. shift = 4;
  176450. *dp = (png_byte)v;
  176451. dp++;
  176452. v = 0;
  176453. }
  176454. else
  176455. shift -= 4;
  176456. sp++;
  176457. }
  176458. if (shift != 4)
  176459. *dp = (png_byte)v;
  176460. break;
  176461. }
  176462. }
  176463. row_info->bit_depth = (png_byte)bit_depth;
  176464. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176465. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176466. row_info->width);
  176467. }
  176468. }
  176469. #endif
  176470. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176471. void /* PRIVATE */
  176472. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176473. {
  176474. png_debug(1, "in png_do_shift\n");
  176475. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176476. if (row != NULL && row_info != NULL &&
  176477. #else
  176478. if (
  176479. #endif
  176480. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176481. {
  176482. int shift_start[4], shift_dec[4];
  176483. int channels = 0;
  176484. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176485. {
  176486. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176487. shift_dec[channels] = bit_depth->red;
  176488. channels++;
  176489. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176490. shift_dec[channels] = bit_depth->green;
  176491. channels++;
  176492. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176493. shift_dec[channels] = bit_depth->blue;
  176494. channels++;
  176495. }
  176496. else
  176497. {
  176498. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176499. shift_dec[channels] = bit_depth->gray;
  176500. channels++;
  176501. }
  176502. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176503. {
  176504. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176505. shift_dec[channels] = bit_depth->alpha;
  176506. channels++;
  176507. }
  176508. if (row_info->bit_depth < 8)
  176509. {
  176510. png_bytep bp = row;
  176511. png_uint_32 i;
  176512. png_byte mask;
  176513. png_uint_32 row_bytes = row_info->rowbytes;
  176514. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176515. mask = 0x55;
  176516. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176517. mask = 0x11;
  176518. else
  176519. mask = 0xff;
  176520. for (i = 0; i < row_bytes; i++, bp++)
  176521. {
  176522. png_uint_16 v;
  176523. int j;
  176524. v = *bp;
  176525. *bp = 0;
  176526. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176527. {
  176528. if (j > 0)
  176529. *bp |= (png_byte)((v << j) & 0xff);
  176530. else
  176531. *bp |= (png_byte)((v >> (-j)) & mask);
  176532. }
  176533. }
  176534. }
  176535. else if (row_info->bit_depth == 8)
  176536. {
  176537. png_bytep bp = row;
  176538. png_uint_32 i;
  176539. png_uint_32 istop = channels * row_info->width;
  176540. for (i = 0; i < istop; i++, bp++)
  176541. {
  176542. png_uint_16 v;
  176543. int j;
  176544. int c = (int)(i%channels);
  176545. v = *bp;
  176546. *bp = 0;
  176547. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176548. {
  176549. if (j > 0)
  176550. *bp |= (png_byte)((v << j) & 0xff);
  176551. else
  176552. *bp |= (png_byte)((v >> (-j)) & 0xff);
  176553. }
  176554. }
  176555. }
  176556. else
  176557. {
  176558. png_bytep bp;
  176559. png_uint_32 i;
  176560. png_uint_32 istop = channels * row_info->width;
  176561. for (bp = row, i = 0; i < istop; i++)
  176562. {
  176563. int c = (int)(i%channels);
  176564. png_uint_16 value, v;
  176565. int j;
  176566. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  176567. value = 0;
  176568. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176569. {
  176570. if (j > 0)
  176571. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  176572. else
  176573. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  176574. }
  176575. *bp++ = (png_byte)(value >> 8);
  176576. *bp++ = (png_byte)(value & 0xff);
  176577. }
  176578. }
  176579. }
  176580. }
  176581. #endif
  176582. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176583. void /* PRIVATE */
  176584. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  176585. {
  176586. png_debug(1, "in png_do_write_swap_alpha\n");
  176587. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176588. if (row != NULL && row_info != NULL)
  176589. #endif
  176590. {
  176591. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176592. {
  176593. if (row_info->bit_depth == 8)
  176594. {
  176595. png_bytep sp, dp;
  176596. png_uint_32 i;
  176597. png_uint_32 row_width = row_info->width;
  176598. for (i = 0, sp = dp = row; i < row_width; i++)
  176599. {
  176600. png_byte save = *(sp++);
  176601. *(dp++) = *(sp++);
  176602. *(dp++) = *(sp++);
  176603. *(dp++) = *(sp++);
  176604. *(dp++) = save;
  176605. }
  176606. }
  176607. else
  176608. {
  176609. png_bytep sp, dp;
  176610. png_uint_32 i;
  176611. png_uint_32 row_width = row_info->width;
  176612. for (i = 0, sp = dp = row; i < row_width; i++)
  176613. {
  176614. png_byte save[2];
  176615. save[0] = *(sp++);
  176616. save[1] = *(sp++);
  176617. *(dp++) = *(sp++);
  176618. *(dp++) = *(sp++);
  176619. *(dp++) = *(sp++);
  176620. *(dp++) = *(sp++);
  176621. *(dp++) = *(sp++);
  176622. *(dp++) = *(sp++);
  176623. *(dp++) = save[0];
  176624. *(dp++) = save[1];
  176625. }
  176626. }
  176627. }
  176628. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176629. {
  176630. if (row_info->bit_depth == 8)
  176631. {
  176632. png_bytep sp, dp;
  176633. png_uint_32 i;
  176634. png_uint_32 row_width = row_info->width;
  176635. for (i = 0, sp = dp = row; i < row_width; i++)
  176636. {
  176637. png_byte save = *(sp++);
  176638. *(dp++) = *(sp++);
  176639. *(dp++) = save;
  176640. }
  176641. }
  176642. else
  176643. {
  176644. png_bytep sp, dp;
  176645. png_uint_32 i;
  176646. png_uint_32 row_width = row_info->width;
  176647. for (i = 0, sp = dp = row; i < row_width; i++)
  176648. {
  176649. png_byte save[2];
  176650. save[0] = *(sp++);
  176651. save[1] = *(sp++);
  176652. *(dp++) = *(sp++);
  176653. *(dp++) = *(sp++);
  176654. *(dp++) = save[0];
  176655. *(dp++) = save[1];
  176656. }
  176657. }
  176658. }
  176659. }
  176660. }
  176661. #endif
  176662. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176663. void /* PRIVATE */
  176664. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  176665. {
  176666. png_debug(1, "in png_do_write_invert_alpha\n");
  176667. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176668. if (row != NULL && row_info != NULL)
  176669. #endif
  176670. {
  176671. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176672. {
  176673. if (row_info->bit_depth == 8)
  176674. {
  176675. png_bytep sp, dp;
  176676. png_uint_32 i;
  176677. png_uint_32 row_width = row_info->width;
  176678. for (i = 0, sp = dp = row; i < row_width; i++)
  176679. {
  176680. sp+=3; dp = sp;
  176681. *(dp++) = (png_byte)(255 - *(sp++));
  176682. }
  176683. }
  176684. else
  176685. {
  176686. png_bytep sp, dp;
  176687. png_uint_32 i;
  176688. png_uint_32 row_width = row_info->width;
  176689. for (i = 0, sp = dp = row; i < row_width; i++)
  176690. {
  176691. sp+=6; dp = sp;
  176692. *(dp++) = (png_byte)(255 - *(sp++));
  176693. *(dp++) = (png_byte)(255 - *(sp++));
  176694. }
  176695. }
  176696. }
  176697. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176698. {
  176699. if (row_info->bit_depth == 8)
  176700. {
  176701. png_bytep sp, dp;
  176702. png_uint_32 i;
  176703. png_uint_32 row_width = row_info->width;
  176704. for (i = 0, sp = dp = row; i < row_width; i++)
  176705. {
  176706. *(dp++) = *(sp++);
  176707. *(dp++) = (png_byte)(255 - *(sp++));
  176708. }
  176709. }
  176710. else
  176711. {
  176712. png_bytep sp, dp;
  176713. png_uint_32 i;
  176714. png_uint_32 row_width = row_info->width;
  176715. for (i = 0, sp = dp = row; i < row_width; i++)
  176716. {
  176717. sp+=2; dp = sp;
  176718. *(dp++) = (png_byte)(255 - *(sp++));
  176719. *(dp++) = (png_byte)(255 - *(sp++));
  176720. }
  176721. }
  176722. }
  176723. }
  176724. }
  176725. #endif
  176726. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176727. void /* PRIVATE */
  176728. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  176729. {
  176730. png_debug(1, "in png_do_write_intrapixel\n");
  176731. if (
  176732. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176733. row != NULL && row_info != NULL &&
  176734. #endif
  176735. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  176736. {
  176737. int bytes_per_pixel;
  176738. png_uint_32 row_width = row_info->width;
  176739. if (row_info->bit_depth == 8)
  176740. {
  176741. png_bytep rp;
  176742. png_uint_32 i;
  176743. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176744. bytes_per_pixel = 3;
  176745. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176746. bytes_per_pixel = 4;
  176747. else
  176748. return;
  176749. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176750. {
  176751. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  176752. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  176753. }
  176754. }
  176755. else if (row_info->bit_depth == 16)
  176756. {
  176757. png_bytep rp;
  176758. png_uint_32 i;
  176759. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176760. bytes_per_pixel = 6;
  176761. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176762. bytes_per_pixel = 8;
  176763. else
  176764. return;
  176765. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176766. {
  176767. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  176768. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  176769. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  176770. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  176771. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  176772. *(rp ) = (png_byte)((red >> 8) & 0xff);
  176773. *(rp+1) = (png_byte)(red & 0xff);
  176774. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  176775. *(rp+5) = (png_byte)(blue & 0xff);
  176776. }
  176777. }
  176778. }
  176779. }
  176780. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  176781. #endif /* PNG_WRITE_SUPPORTED */
  176782. /*** End of inlined file: pngwtran.c ***/
  176783. /*** Start of inlined file: pngwutil.c ***/
  176784. #define PNG_INTERNAL
  176785. #ifdef PNG_WRITE_SUPPORTED
  176786. void PNGAPI
  176787. png_save_uint_32(png_bytep buf, png_uint_32 i)
  176788. {
  176789. buf[0] = (png_byte)((i >> 24) & 0xff);
  176790. buf[1] = (png_byte)((i >> 16) & 0xff);
  176791. buf[2] = (png_byte)((i >> 8) & 0xff);
  176792. buf[3] = (png_byte)(i & 0xff);
  176793. }
  176794. void PNGAPI
  176795. png_save_int_32(png_bytep buf, png_int_32 i)
  176796. {
  176797. buf[0] = (png_byte)((i >> 24) & 0xff);
  176798. buf[1] = (png_byte)((i >> 16) & 0xff);
  176799. buf[2] = (png_byte)((i >> 8) & 0xff);
  176800. buf[3] = (png_byte)(i & 0xff);
  176801. }
  176802. void PNGAPI
  176803. png_save_uint_16(png_bytep buf, unsigned int i)
  176804. {
  176805. buf[0] = (png_byte)((i >> 8) & 0xff);
  176806. buf[1] = (png_byte)(i & 0xff);
  176807. }
  176808. void PNGAPI
  176809. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  176810. png_bytep data, png_size_t length)
  176811. {
  176812. if(png_ptr == NULL) return;
  176813. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  176814. png_write_chunk_data(png_ptr, data, length);
  176815. png_write_chunk_end(png_ptr);
  176816. }
  176817. void PNGAPI
  176818. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  176819. png_uint_32 length)
  176820. {
  176821. png_byte buf[4];
  176822. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  176823. if(png_ptr == NULL) return;
  176824. png_save_uint_32(buf, length);
  176825. png_write_data(png_ptr, buf, (png_size_t)4);
  176826. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  176827. png_reset_crc(png_ptr);
  176828. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  176829. }
  176830. void PNGAPI
  176831. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  176832. {
  176833. if(png_ptr == NULL) return;
  176834. if (data != NULL && length > 0)
  176835. {
  176836. png_calculate_crc(png_ptr, data, length);
  176837. png_write_data(png_ptr, data, length);
  176838. }
  176839. }
  176840. void PNGAPI
  176841. png_write_chunk_end(png_structp png_ptr)
  176842. {
  176843. png_byte buf[4];
  176844. if(png_ptr == NULL) return;
  176845. png_save_uint_32(buf, png_ptr->crc);
  176846. png_write_data(png_ptr, buf, (png_size_t)4);
  176847. }
  176848. void /* PRIVATE */
  176849. png_write_sig(png_structp png_ptr)
  176850. {
  176851. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  176852. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  176853. (png_size_t)8 - png_ptr->sig_bytes);
  176854. if(png_ptr->sig_bytes < 3)
  176855. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  176856. }
  176857. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  176858. typedef struct
  176859. {
  176860. char *input; /* the uncompressed input data */
  176861. int input_len; /* its length */
  176862. int num_output_ptr; /* number of output pointers used */
  176863. int max_output_ptr; /* size of output_ptr */
  176864. png_charpp output_ptr; /* array of pointers to output */
  176865. } compression_state;
  176866. static int /* PRIVATE */
  176867. png_text_compress(png_structp png_ptr,
  176868. png_charp text, png_size_t text_len, int compression,
  176869. compression_state *comp)
  176870. {
  176871. int ret;
  176872. comp->num_output_ptr = 0;
  176873. comp->max_output_ptr = 0;
  176874. comp->output_ptr = NULL;
  176875. comp->input = NULL;
  176876. comp->input_len = 0;
  176877. if (compression == PNG_TEXT_COMPRESSION_NONE)
  176878. {
  176879. comp->input = text;
  176880. comp->input_len = text_len;
  176881. return((int)text_len);
  176882. }
  176883. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  176884. {
  176885. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176886. char msg[50];
  176887. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  176888. png_warning(png_ptr, msg);
  176889. #else
  176890. png_warning(png_ptr, "Unknown compression type");
  176891. #endif
  176892. }
  176893. png_ptr->zstream.avail_in = (uInt)text_len;
  176894. png_ptr->zstream.next_in = (Bytef *)text;
  176895. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176896. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  176897. do
  176898. {
  176899. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  176900. if (ret != Z_OK)
  176901. {
  176902. if (png_ptr->zstream.msg != NULL)
  176903. png_error(png_ptr, png_ptr->zstream.msg);
  176904. else
  176905. png_error(png_ptr, "zlib error");
  176906. }
  176907. if (!(png_ptr->zstream.avail_out))
  176908. {
  176909. if (comp->num_output_ptr >= comp->max_output_ptr)
  176910. {
  176911. int old_max;
  176912. old_max = comp->max_output_ptr;
  176913. comp->max_output_ptr = comp->num_output_ptr + 4;
  176914. if (comp->output_ptr != NULL)
  176915. {
  176916. png_charpp old_ptr;
  176917. old_ptr = comp->output_ptr;
  176918. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176919. (png_uint_32)(comp->max_output_ptr *
  176920. png_sizeof (png_charpp)));
  176921. png_memcpy(comp->output_ptr, old_ptr, old_max
  176922. * png_sizeof (png_charp));
  176923. png_free(png_ptr, old_ptr);
  176924. }
  176925. else
  176926. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176927. (png_uint_32)(comp->max_output_ptr *
  176928. png_sizeof (png_charp)));
  176929. }
  176930. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  176931. (png_uint_32)png_ptr->zbuf_size);
  176932. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176933. png_ptr->zbuf_size);
  176934. comp->num_output_ptr++;
  176935. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176936. png_ptr->zstream.next_out = png_ptr->zbuf;
  176937. }
  176938. } while (png_ptr->zstream.avail_in);
  176939. do
  176940. {
  176941. ret = deflate(&png_ptr->zstream, Z_FINISH);
  176942. if (ret == Z_OK)
  176943. {
  176944. if (!(png_ptr->zstream.avail_out))
  176945. {
  176946. if (comp->num_output_ptr >= comp->max_output_ptr)
  176947. {
  176948. int old_max;
  176949. old_max = comp->max_output_ptr;
  176950. comp->max_output_ptr = comp->num_output_ptr + 4;
  176951. if (comp->output_ptr != NULL)
  176952. {
  176953. png_charpp old_ptr;
  176954. old_ptr = comp->output_ptr;
  176955. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176956. (png_uint_32)(comp->max_output_ptr *
  176957. png_sizeof (png_charpp)));
  176958. png_memcpy(comp->output_ptr, old_ptr,
  176959. old_max * png_sizeof (png_charp));
  176960. png_free(png_ptr, old_ptr);
  176961. }
  176962. else
  176963. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176964. (png_uint_32)(comp->max_output_ptr *
  176965. png_sizeof (png_charp)));
  176966. }
  176967. comp->output_ptr[comp->num_output_ptr] =
  176968. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  176969. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176970. png_ptr->zbuf_size);
  176971. comp->num_output_ptr++;
  176972. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176973. png_ptr->zstream.next_out = png_ptr->zbuf;
  176974. }
  176975. }
  176976. else if (ret != Z_STREAM_END)
  176977. {
  176978. if (png_ptr->zstream.msg != NULL)
  176979. png_error(png_ptr, png_ptr->zstream.msg);
  176980. else
  176981. png_error(png_ptr, "zlib error");
  176982. }
  176983. } while (ret != Z_STREAM_END);
  176984. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  176985. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  176986. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  176987. return((int)text_len);
  176988. }
  176989. static void /* PRIVATE */
  176990. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  176991. {
  176992. int i;
  176993. if (comp->input)
  176994. {
  176995. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  176996. (png_size_t)comp->input_len);
  176997. return;
  176998. }
  176999. for (i = 0; i < comp->num_output_ptr; i++)
  177000. {
  177001. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  177002. png_ptr->zbuf_size);
  177003. png_free(png_ptr, comp->output_ptr[i]);
  177004. comp->output_ptr[i]=NULL;
  177005. }
  177006. if (comp->max_output_ptr != 0)
  177007. png_free(png_ptr, comp->output_ptr);
  177008. comp->output_ptr=NULL;
  177009. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  177010. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  177011. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177012. deflateReset(&png_ptr->zstream);
  177013. png_ptr->zstream.data_type = Z_BINARY;
  177014. }
  177015. #endif
  177016. void /* PRIVATE */
  177017. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177018. int bit_depth, int color_type, int compression_type, int filter_type,
  177019. int interlace_type)
  177020. {
  177021. #ifdef PNG_USE_LOCAL_ARRAYS
  177022. PNG_IHDR;
  177023. #endif
  177024. png_byte buf[13]; /* buffer to store the IHDR info */
  177025. png_debug(1, "in png_write_IHDR\n");
  177026. switch (color_type)
  177027. {
  177028. case PNG_COLOR_TYPE_GRAY:
  177029. switch (bit_depth)
  177030. {
  177031. case 1:
  177032. case 2:
  177033. case 4:
  177034. case 8:
  177035. case 16: png_ptr->channels = 1; break;
  177036. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177037. }
  177038. break;
  177039. case PNG_COLOR_TYPE_RGB:
  177040. if (bit_depth != 8 && bit_depth != 16)
  177041. png_error(png_ptr, "Invalid bit depth for RGB image");
  177042. png_ptr->channels = 3;
  177043. break;
  177044. case PNG_COLOR_TYPE_PALETTE:
  177045. switch (bit_depth)
  177046. {
  177047. case 1:
  177048. case 2:
  177049. case 4:
  177050. case 8: png_ptr->channels = 1; break;
  177051. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177052. }
  177053. break;
  177054. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177055. if (bit_depth != 8 && bit_depth != 16)
  177056. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177057. png_ptr->channels = 2;
  177058. break;
  177059. case PNG_COLOR_TYPE_RGB_ALPHA:
  177060. if (bit_depth != 8 && bit_depth != 16)
  177061. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177062. png_ptr->channels = 4;
  177063. break;
  177064. default:
  177065. png_error(png_ptr, "Invalid image color type specified");
  177066. }
  177067. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177068. {
  177069. png_warning(png_ptr, "Invalid compression type specified");
  177070. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177071. }
  177072. if (
  177073. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177074. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177075. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177076. (color_type == PNG_COLOR_TYPE_RGB ||
  177077. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177078. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177079. #endif
  177080. filter_type != PNG_FILTER_TYPE_BASE)
  177081. {
  177082. png_warning(png_ptr, "Invalid filter type specified");
  177083. filter_type = PNG_FILTER_TYPE_BASE;
  177084. }
  177085. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177086. if (interlace_type != PNG_INTERLACE_NONE &&
  177087. interlace_type != PNG_INTERLACE_ADAM7)
  177088. {
  177089. png_warning(png_ptr, "Invalid interlace type specified");
  177090. interlace_type = PNG_INTERLACE_ADAM7;
  177091. }
  177092. #else
  177093. interlace_type=PNG_INTERLACE_NONE;
  177094. #endif
  177095. png_ptr->bit_depth = (png_byte)bit_depth;
  177096. png_ptr->color_type = (png_byte)color_type;
  177097. png_ptr->interlaced = (png_byte)interlace_type;
  177098. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177099. png_ptr->filter_type = (png_byte)filter_type;
  177100. #endif
  177101. png_ptr->compression_type = (png_byte)compression_type;
  177102. png_ptr->width = width;
  177103. png_ptr->height = height;
  177104. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177105. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177106. png_ptr->usr_width = png_ptr->width;
  177107. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177108. png_ptr->usr_channels = png_ptr->channels;
  177109. png_save_uint_32(buf, width);
  177110. png_save_uint_32(buf + 4, height);
  177111. buf[8] = (png_byte)bit_depth;
  177112. buf[9] = (png_byte)color_type;
  177113. buf[10] = (png_byte)compression_type;
  177114. buf[11] = (png_byte)filter_type;
  177115. buf[12] = (png_byte)interlace_type;
  177116. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177117. png_ptr->zstream.zalloc = png_zalloc;
  177118. png_ptr->zstream.zfree = png_zfree;
  177119. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177120. if (!(png_ptr->do_filter))
  177121. {
  177122. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177123. png_ptr->bit_depth < 8)
  177124. png_ptr->do_filter = PNG_FILTER_NONE;
  177125. else
  177126. png_ptr->do_filter = PNG_ALL_FILTERS;
  177127. }
  177128. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177129. {
  177130. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177131. png_ptr->zlib_strategy = Z_FILTERED;
  177132. else
  177133. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177134. }
  177135. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177136. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177137. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177138. png_ptr->zlib_mem_level = 8;
  177139. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177140. png_ptr->zlib_window_bits = 15;
  177141. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177142. png_ptr->zlib_method = 8;
  177143. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177144. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177145. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177146. png_error(png_ptr, "zlib failed to initialize compressor");
  177147. png_ptr->zstream.next_out = png_ptr->zbuf;
  177148. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177149. png_ptr->zstream.data_type = Z_BINARY;
  177150. png_ptr->mode = PNG_HAVE_IHDR;
  177151. }
  177152. void /* PRIVATE */
  177153. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177154. {
  177155. #ifdef PNG_USE_LOCAL_ARRAYS
  177156. PNG_PLTE;
  177157. #endif
  177158. png_uint_32 i;
  177159. png_colorp pal_ptr;
  177160. png_byte buf[3];
  177161. png_debug(1, "in png_write_PLTE\n");
  177162. if ((
  177163. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177164. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177165. #endif
  177166. num_pal == 0) || num_pal > 256)
  177167. {
  177168. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177169. {
  177170. png_error(png_ptr, "Invalid number of colors in palette");
  177171. }
  177172. else
  177173. {
  177174. png_warning(png_ptr, "Invalid number of colors in palette");
  177175. return;
  177176. }
  177177. }
  177178. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177179. {
  177180. png_warning(png_ptr,
  177181. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177182. return;
  177183. }
  177184. png_ptr->num_palette = (png_uint_16)num_pal;
  177185. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177186. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177187. #ifndef PNG_NO_POINTER_INDEXING
  177188. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177189. {
  177190. buf[0] = pal_ptr->red;
  177191. buf[1] = pal_ptr->green;
  177192. buf[2] = pal_ptr->blue;
  177193. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177194. }
  177195. #else
  177196. pal_ptr=palette;
  177197. for (i = 0; i < num_pal; i++)
  177198. {
  177199. buf[0] = pal_ptr[i].red;
  177200. buf[1] = pal_ptr[i].green;
  177201. buf[2] = pal_ptr[i].blue;
  177202. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177203. }
  177204. #endif
  177205. png_write_chunk_end(png_ptr);
  177206. png_ptr->mode |= PNG_HAVE_PLTE;
  177207. }
  177208. void /* PRIVATE */
  177209. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177210. {
  177211. #ifdef PNG_USE_LOCAL_ARRAYS
  177212. PNG_IDAT;
  177213. #endif
  177214. png_debug(1, "in png_write_IDAT\n");
  177215. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177216. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177217. {
  177218. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177219. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177220. {
  177221. if (length >= 2 &&
  177222. png_ptr->height < 16384 && png_ptr->width < 16384)
  177223. {
  177224. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177225. ((png_ptr->width *
  177226. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177227. unsigned int z_cinfo = z_cmf >> 4;
  177228. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177229. while (uncompressed_idat_size <= half_z_window_size &&
  177230. half_z_window_size >= 256)
  177231. {
  177232. z_cinfo--;
  177233. half_z_window_size >>= 1;
  177234. }
  177235. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177236. if (data[0] != (png_byte)z_cmf)
  177237. {
  177238. data[0] = (png_byte)z_cmf;
  177239. data[1] &= 0xe0;
  177240. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177241. }
  177242. }
  177243. }
  177244. else
  177245. png_error(png_ptr,
  177246. "Invalid zlib compression method or flags in IDAT");
  177247. }
  177248. png_write_chunk(png_ptr, png_IDAT, data, length);
  177249. png_ptr->mode |= PNG_HAVE_IDAT;
  177250. }
  177251. void /* PRIVATE */
  177252. png_write_IEND(png_structp png_ptr)
  177253. {
  177254. #ifdef PNG_USE_LOCAL_ARRAYS
  177255. PNG_IEND;
  177256. #endif
  177257. png_debug(1, "in png_write_IEND\n");
  177258. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177259. (png_size_t)0);
  177260. png_ptr->mode |= PNG_HAVE_IEND;
  177261. }
  177262. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177263. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177264. void /* PRIVATE */
  177265. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177266. {
  177267. #ifdef PNG_USE_LOCAL_ARRAYS
  177268. PNG_gAMA;
  177269. #endif
  177270. png_uint_32 igamma;
  177271. png_byte buf[4];
  177272. png_debug(1, "in png_write_gAMA\n");
  177273. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177274. png_save_uint_32(buf, igamma);
  177275. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177276. }
  177277. #endif
  177278. #ifdef PNG_FIXED_POINT_SUPPORTED
  177279. void /* PRIVATE */
  177280. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177281. {
  177282. #ifdef PNG_USE_LOCAL_ARRAYS
  177283. PNG_gAMA;
  177284. #endif
  177285. png_byte buf[4];
  177286. png_debug(1, "in png_write_gAMA\n");
  177287. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177288. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177289. }
  177290. #endif
  177291. #endif
  177292. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177293. void /* PRIVATE */
  177294. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177295. {
  177296. #ifdef PNG_USE_LOCAL_ARRAYS
  177297. PNG_sRGB;
  177298. #endif
  177299. png_byte buf[1];
  177300. png_debug(1, "in png_write_sRGB\n");
  177301. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177302. png_warning(png_ptr,
  177303. "Invalid sRGB rendering intent specified");
  177304. buf[0]=(png_byte)srgb_intent;
  177305. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177306. }
  177307. #endif
  177308. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177309. void /* PRIVATE */
  177310. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177311. png_charp profile, int profile_len)
  177312. {
  177313. #ifdef PNG_USE_LOCAL_ARRAYS
  177314. PNG_iCCP;
  177315. #endif
  177316. png_size_t name_len;
  177317. png_charp new_name;
  177318. compression_state comp;
  177319. int embedded_profile_len = 0;
  177320. png_debug(1, "in png_write_iCCP\n");
  177321. comp.num_output_ptr = 0;
  177322. comp.max_output_ptr = 0;
  177323. comp.output_ptr = NULL;
  177324. comp.input = NULL;
  177325. comp.input_len = 0;
  177326. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177327. &new_name)) == 0)
  177328. {
  177329. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177330. return;
  177331. }
  177332. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177333. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177334. if (profile == NULL)
  177335. profile_len = 0;
  177336. if (profile_len > 3)
  177337. embedded_profile_len =
  177338. ((*( (png_bytep)profile ))<<24) |
  177339. ((*( (png_bytep)profile+1))<<16) |
  177340. ((*( (png_bytep)profile+2))<< 8) |
  177341. ((*( (png_bytep)profile+3)) );
  177342. if (profile_len < embedded_profile_len)
  177343. {
  177344. png_warning(png_ptr,
  177345. "Embedded profile length too large in iCCP chunk");
  177346. return;
  177347. }
  177348. if (profile_len > embedded_profile_len)
  177349. {
  177350. png_warning(png_ptr,
  177351. "Truncating profile to actual length in iCCP chunk");
  177352. profile_len = embedded_profile_len;
  177353. }
  177354. if (profile_len)
  177355. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177356. PNG_COMPRESSION_TYPE_BASE, &comp);
  177357. png_write_chunk_start(png_ptr, png_iCCP,
  177358. (png_uint_32)name_len+profile_len+2);
  177359. new_name[name_len+1]=0x00;
  177360. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177361. if (profile_len)
  177362. png_write_compressed_data_out(png_ptr, &comp);
  177363. png_write_chunk_end(png_ptr);
  177364. png_free(png_ptr, new_name);
  177365. }
  177366. #endif
  177367. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177368. void /* PRIVATE */
  177369. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177370. {
  177371. #ifdef PNG_USE_LOCAL_ARRAYS
  177372. PNG_sPLT;
  177373. #endif
  177374. png_size_t name_len;
  177375. png_charp new_name;
  177376. png_byte entrybuf[10];
  177377. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177378. int palette_size = entry_size * spalette->nentries;
  177379. png_sPLT_entryp ep;
  177380. #ifdef PNG_NO_POINTER_INDEXING
  177381. int i;
  177382. #endif
  177383. png_debug(1, "in png_write_sPLT\n");
  177384. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177385. spalette->name, &new_name))==0)
  177386. {
  177387. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177388. return;
  177389. }
  177390. png_write_chunk_start(png_ptr, png_sPLT,
  177391. (png_uint_32)(name_len + 2 + palette_size));
  177392. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177393. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177394. #ifndef PNG_NO_POINTER_INDEXING
  177395. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177396. {
  177397. if (spalette->depth == 8)
  177398. {
  177399. entrybuf[0] = (png_byte)ep->red;
  177400. entrybuf[1] = (png_byte)ep->green;
  177401. entrybuf[2] = (png_byte)ep->blue;
  177402. entrybuf[3] = (png_byte)ep->alpha;
  177403. png_save_uint_16(entrybuf + 4, ep->frequency);
  177404. }
  177405. else
  177406. {
  177407. png_save_uint_16(entrybuf + 0, ep->red);
  177408. png_save_uint_16(entrybuf + 2, ep->green);
  177409. png_save_uint_16(entrybuf + 4, ep->blue);
  177410. png_save_uint_16(entrybuf + 6, ep->alpha);
  177411. png_save_uint_16(entrybuf + 8, ep->frequency);
  177412. }
  177413. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177414. }
  177415. #else
  177416. ep=spalette->entries;
  177417. for (i=0; i>spalette->nentries; i++)
  177418. {
  177419. if (spalette->depth == 8)
  177420. {
  177421. entrybuf[0] = (png_byte)ep[i].red;
  177422. entrybuf[1] = (png_byte)ep[i].green;
  177423. entrybuf[2] = (png_byte)ep[i].blue;
  177424. entrybuf[3] = (png_byte)ep[i].alpha;
  177425. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177426. }
  177427. else
  177428. {
  177429. png_save_uint_16(entrybuf + 0, ep[i].red);
  177430. png_save_uint_16(entrybuf + 2, ep[i].green);
  177431. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177432. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177433. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177434. }
  177435. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177436. }
  177437. #endif
  177438. png_write_chunk_end(png_ptr);
  177439. png_free(png_ptr, new_name);
  177440. }
  177441. #endif
  177442. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177443. void /* PRIVATE */
  177444. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177445. {
  177446. #ifdef PNG_USE_LOCAL_ARRAYS
  177447. PNG_sBIT;
  177448. #endif
  177449. png_byte buf[4];
  177450. png_size_t size;
  177451. png_debug(1, "in png_write_sBIT\n");
  177452. if (color_type & PNG_COLOR_MASK_COLOR)
  177453. {
  177454. png_byte maxbits;
  177455. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177456. png_ptr->usr_bit_depth);
  177457. if (sbit->red == 0 || sbit->red > maxbits ||
  177458. sbit->green == 0 || sbit->green > maxbits ||
  177459. sbit->blue == 0 || sbit->blue > maxbits)
  177460. {
  177461. png_warning(png_ptr, "Invalid sBIT depth specified");
  177462. return;
  177463. }
  177464. buf[0] = sbit->red;
  177465. buf[1] = sbit->green;
  177466. buf[2] = sbit->blue;
  177467. size = 3;
  177468. }
  177469. else
  177470. {
  177471. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177472. {
  177473. png_warning(png_ptr, "Invalid sBIT depth specified");
  177474. return;
  177475. }
  177476. buf[0] = sbit->gray;
  177477. size = 1;
  177478. }
  177479. if (color_type & PNG_COLOR_MASK_ALPHA)
  177480. {
  177481. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177482. {
  177483. png_warning(png_ptr, "Invalid sBIT depth specified");
  177484. return;
  177485. }
  177486. buf[size++] = sbit->alpha;
  177487. }
  177488. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177489. }
  177490. #endif
  177491. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177492. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177493. void /* PRIVATE */
  177494. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177495. double red_x, double red_y, double green_x, double green_y,
  177496. double blue_x, double blue_y)
  177497. {
  177498. #ifdef PNG_USE_LOCAL_ARRAYS
  177499. PNG_cHRM;
  177500. #endif
  177501. png_byte buf[32];
  177502. png_uint_32 itemp;
  177503. png_debug(1, "in png_write_cHRM\n");
  177504. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177505. white_x + white_y > 1.0)
  177506. {
  177507. png_warning(png_ptr, "Invalid cHRM white point specified");
  177508. #if !defined(PNG_NO_CONSOLE_IO)
  177509. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177510. #endif
  177511. return;
  177512. }
  177513. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177514. png_save_uint_32(buf, itemp);
  177515. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177516. png_save_uint_32(buf + 4, itemp);
  177517. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177518. {
  177519. png_warning(png_ptr, "Invalid cHRM red point specified");
  177520. return;
  177521. }
  177522. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177523. png_save_uint_32(buf + 8, itemp);
  177524. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177525. png_save_uint_32(buf + 12, itemp);
  177526. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177527. {
  177528. png_warning(png_ptr, "Invalid cHRM green point specified");
  177529. return;
  177530. }
  177531. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177532. png_save_uint_32(buf + 16, itemp);
  177533. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177534. png_save_uint_32(buf + 20, itemp);
  177535. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177536. {
  177537. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177538. return;
  177539. }
  177540. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177541. png_save_uint_32(buf + 24, itemp);
  177542. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177543. png_save_uint_32(buf + 28, itemp);
  177544. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177545. }
  177546. #endif
  177547. #ifdef PNG_FIXED_POINT_SUPPORTED
  177548. void /* PRIVATE */
  177549. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  177550. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  177551. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  177552. png_fixed_point blue_y)
  177553. {
  177554. #ifdef PNG_USE_LOCAL_ARRAYS
  177555. PNG_cHRM;
  177556. #endif
  177557. png_byte buf[32];
  177558. png_debug(1, "in png_write_cHRM\n");
  177559. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  177560. {
  177561. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  177562. #if !defined(PNG_NO_CONSOLE_IO)
  177563. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  177564. #endif
  177565. return;
  177566. }
  177567. png_save_uint_32(buf, (png_uint_32)white_x);
  177568. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  177569. if (red_x + red_y > 100000L)
  177570. {
  177571. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  177572. return;
  177573. }
  177574. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  177575. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  177576. if (green_x + green_y > 100000L)
  177577. {
  177578. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  177579. return;
  177580. }
  177581. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  177582. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  177583. if (blue_x + blue_y > 100000L)
  177584. {
  177585. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  177586. return;
  177587. }
  177588. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  177589. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  177590. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177591. }
  177592. #endif
  177593. #endif
  177594. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  177595. void /* PRIVATE */
  177596. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  177597. int num_trans, int color_type)
  177598. {
  177599. #ifdef PNG_USE_LOCAL_ARRAYS
  177600. PNG_tRNS;
  177601. #endif
  177602. png_byte buf[6];
  177603. png_debug(1, "in png_write_tRNS\n");
  177604. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177605. {
  177606. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  177607. {
  177608. png_warning(png_ptr,"Invalid number of transparent colors specified");
  177609. return;
  177610. }
  177611. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  177612. }
  177613. else if (color_type == PNG_COLOR_TYPE_GRAY)
  177614. {
  177615. if(tran->gray >= (1 << png_ptr->bit_depth))
  177616. {
  177617. png_warning(png_ptr,
  177618. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  177619. return;
  177620. }
  177621. png_save_uint_16(buf, tran->gray);
  177622. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  177623. }
  177624. else if (color_type == PNG_COLOR_TYPE_RGB)
  177625. {
  177626. png_save_uint_16(buf, tran->red);
  177627. png_save_uint_16(buf + 2, tran->green);
  177628. png_save_uint_16(buf + 4, tran->blue);
  177629. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177630. {
  177631. png_warning(png_ptr,
  177632. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  177633. return;
  177634. }
  177635. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  177636. }
  177637. else
  177638. {
  177639. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  177640. }
  177641. }
  177642. #endif
  177643. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  177644. void /* PRIVATE */
  177645. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  177646. {
  177647. #ifdef PNG_USE_LOCAL_ARRAYS
  177648. PNG_bKGD;
  177649. #endif
  177650. png_byte buf[6];
  177651. png_debug(1, "in png_write_bKGD\n");
  177652. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177653. {
  177654. if (
  177655. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177656. (png_ptr->num_palette ||
  177657. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  177658. #endif
  177659. back->index > png_ptr->num_palette)
  177660. {
  177661. png_warning(png_ptr, "Invalid background palette index");
  177662. return;
  177663. }
  177664. buf[0] = back->index;
  177665. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  177666. }
  177667. else if (color_type & PNG_COLOR_MASK_COLOR)
  177668. {
  177669. png_save_uint_16(buf, back->red);
  177670. png_save_uint_16(buf + 2, back->green);
  177671. png_save_uint_16(buf + 4, back->blue);
  177672. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177673. {
  177674. png_warning(png_ptr,
  177675. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  177676. return;
  177677. }
  177678. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  177679. }
  177680. else
  177681. {
  177682. if(back->gray >= (1 << png_ptr->bit_depth))
  177683. {
  177684. png_warning(png_ptr,
  177685. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  177686. return;
  177687. }
  177688. png_save_uint_16(buf, back->gray);
  177689. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  177690. }
  177691. }
  177692. #endif
  177693. #if defined(PNG_WRITE_hIST_SUPPORTED)
  177694. void /* PRIVATE */
  177695. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  177696. {
  177697. #ifdef PNG_USE_LOCAL_ARRAYS
  177698. PNG_hIST;
  177699. #endif
  177700. int i;
  177701. png_byte buf[3];
  177702. png_debug(1, "in png_write_hIST\n");
  177703. if (num_hist > (int)png_ptr->num_palette)
  177704. {
  177705. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  177706. png_ptr->num_palette);
  177707. png_warning(png_ptr, "Invalid number of histogram entries specified");
  177708. return;
  177709. }
  177710. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  177711. for (i = 0; i < num_hist; i++)
  177712. {
  177713. png_save_uint_16(buf, hist[i]);
  177714. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  177715. }
  177716. png_write_chunk_end(png_ptr);
  177717. }
  177718. #endif
  177719. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  177720. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  177721. png_size_t /* PRIVATE */
  177722. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  177723. {
  177724. png_size_t key_len;
  177725. png_charp kp, dp;
  177726. int kflag;
  177727. int kwarn=0;
  177728. png_debug(1, "in png_check_keyword\n");
  177729. *new_key = NULL;
  177730. if (key == NULL || (key_len = png_strlen(key)) == 0)
  177731. {
  177732. png_warning(png_ptr, "zero length keyword");
  177733. return ((png_size_t)0);
  177734. }
  177735. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  177736. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  177737. if (*new_key == NULL)
  177738. {
  177739. png_warning(png_ptr, "Out of memory while procesing keyword");
  177740. return ((png_size_t)0);
  177741. }
  177742. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  177743. {
  177744. if ((png_byte)*kp < 0x20 ||
  177745. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  177746. {
  177747. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177748. char msg[40];
  177749. png_snprintf(msg, 40,
  177750. "invalid keyword character 0x%02X", (png_byte)*kp);
  177751. png_warning(png_ptr, msg);
  177752. #else
  177753. png_warning(png_ptr, "invalid character in keyword");
  177754. #endif
  177755. *dp = ' ';
  177756. }
  177757. else
  177758. {
  177759. *dp = *kp;
  177760. }
  177761. }
  177762. *dp = '\0';
  177763. kp = *new_key + key_len - 1;
  177764. if (*kp == ' ')
  177765. {
  177766. png_warning(png_ptr, "trailing spaces removed from keyword");
  177767. while (*kp == ' ')
  177768. {
  177769. *(kp--) = '\0';
  177770. key_len--;
  177771. }
  177772. }
  177773. kp = *new_key;
  177774. if (*kp == ' ')
  177775. {
  177776. png_warning(png_ptr, "leading spaces removed from keyword");
  177777. while (*kp == ' ')
  177778. {
  177779. kp++;
  177780. key_len--;
  177781. }
  177782. }
  177783. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  177784. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  177785. {
  177786. if (*kp == ' ' && kflag == 0)
  177787. {
  177788. *(dp++) = *kp;
  177789. kflag = 1;
  177790. }
  177791. else if (*kp == ' ')
  177792. {
  177793. key_len--;
  177794. kwarn=1;
  177795. }
  177796. else
  177797. {
  177798. *(dp++) = *kp;
  177799. kflag = 0;
  177800. }
  177801. }
  177802. *dp = '\0';
  177803. if(kwarn)
  177804. png_warning(png_ptr, "extra interior spaces removed from keyword");
  177805. if (key_len == 0)
  177806. {
  177807. png_free(png_ptr, *new_key);
  177808. *new_key=NULL;
  177809. png_warning(png_ptr, "Zero length keyword");
  177810. }
  177811. if (key_len > 79)
  177812. {
  177813. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  177814. new_key[79] = '\0';
  177815. key_len = 79;
  177816. }
  177817. return (key_len);
  177818. }
  177819. #endif
  177820. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  177821. void /* PRIVATE */
  177822. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  177823. png_size_t text_len)
  177824. {
  177825. #ifdef PNG_USE_LOCAL_ARRAYS
  177826. PNG_tEXt;
  177827. #endif
  177828. png_size_t key_len;
  177829. png_charp new_key;
  177830. png_debug(1, "in png_write_tEXt\n");
  177831. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177832. {
  177833. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  177834. return;
  177835. }
  177836. if (text == NULL || *text == '\0')
  177837. text_len = 0;
  177838. else
  177839. text_len = png_strlen(text);
  177840. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  177841. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177842. if (text_len)
  177843. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  177844. png_write_chunk_end(png_ptr);
  177845. png_free(png_ptr, new_key);
  177846. }
  177847. #endif
  177848. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  177849. void /* PRIVATE */
  177850. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  177851. png_size_t text_len, int compression)
  177852. {
  177853. #ifdef PNG_USE_LOCAL_ARRAYS
  177854. PNG_zTXt;
  177855. #endif
  177856. png_size_t key_len;
  177857. char buf[1];
  177858. png_charp new_key;
  177859. compression_state comp;
  177860. png_debug(1, "in png_write_zTXt\n");
  177861. comp.num_output_ptr = 0;
  177862. comp.max_output_ptr = 0;
  177863. comp.output_ptr = NULL;
  177864. comp.input = NULL;
  177865. comp.input_len = 0;
  177866. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177867. {
  177868. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  177869. return;
  177870. }
  177871. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  177872. {
  177873. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  177874. png_free(png_ptr, new_key);
  177875. return;
  177876. }
  177877. text_len = png_strlen(text);
  177878. text_len = png_text_compress(png_ptr, text, text_len, compression,
  177879. &comp);
  177880. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  177881. (key_len+text_len+2));
  177882. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177883. png_free(png_ptr, new_key);
  177884. buf[0] = (png_byte)compression;
  177885. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  177886. png_write_compressed_data_out(png_ptr, &comp);
  177887. png_write_chunk_end(png_ptr);
  177888. }
  177889. #endif
  177890. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  177891. void /* PRIVATE */
  177892. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  177893. png_charp lang, png_charp lang_key, png_charp text)
  177894. {
  177895. #ifdef PNG_USE_LOCAL_ARRAYS
  177896. PNG_iTXt;
  177897. #endif
  177898. png_size_t lang_len, key_len, lang_key_len, text_len;
  177899. png_charp new_lang, new_key;
  177900. png_byte cbuf[2];
  177901. compression_state comp;
  177902. png_debug(1, "in png_write_iTXt\n");
  177903. comp.num_output_ptr = 0;
  177904. comp.max_output_ptr = 0;
  177905. comp.output_ptr = NULL;
  177906. comp.input = NULL;
  177907. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177908. {
  177909. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  177910. return;
  177911. }
  177912. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  177913. {
  177914. png_warning(png_ptr, "Empty language field in iTXt chunk");
  177915. new_lang = NULL;
  177916. lang_len = 0;
  177917. }
  177918. if (lang_key == NULL)
  177919. lang_key_len = 0;
  177920. else
  177921. lang_key_len = png_strlen(lang_key);
  177922. if (text == NULL)
  177923. text_len = 0;
  177924. else
  177925. text_len = png_strlen(text);
  177926. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  177927. &comp);
  177928. png_write_chunk_start(png_ptr, png_iTXt,
  177929. (png_uint_32)(
  177930. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  177931. + key_len
  177932. + lang_len
  177933. + lang_key_len
  177934. + text_len));
  177935. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177936. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  177937. compression == PNG_TEXT_COMPRESSION_NONE)
  177938. cbuf[0] = 0;
  177939. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  177940. cbuf[0] = 1;
  177941. cbuf[1] = 0;
  177942. png_write_chunk_data(png_ptr, cbuf, 2);
  177943. cbuf[0] = 0;
  177944. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  177945. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  177946. png_write_compressed_data_out(png_ptr, &comp);
  177947. png_write_chunk_end(png_ptr);
  177948. png_free(png_ptr, new_key);
  177949. if (new_lang)
  177950. png_free(png_ptr, new_lang);
  177951. }
  177952. #endif
  177953. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  177954. void /* PRIVATE */
  177955. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  177956. int unit_type)
  177957. {
  177958. #ifdef PNG_USE_LOCAL_ARRAYS
  177959. PNG_oFFs;
  177960. #endif
  177961. png_byte buf[9];
  177962. png_debug(1, "in png_write_oFFs\n");
  177963. if (unit_type >= PNG_OFFSET_LAST)
  177964. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  177965. png_save_int_32(buf, x_offset);
  177966. png_save_int_32(buf + 4, y_offset);
  177967. buf[8] = (png_byte)unit_type;
  177968. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  177969. }
  177970. #endif
  177971. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  177972. void /* PRIVATE */
  177973. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  177974. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  177975. {
  177976. #ifdef PNG_USE_LOCAL_ARRAYS
  177977. PNG_pCAL;
  177978. #endif
  177979. png_size_t purpose_len, units_len, total_len;
  177980. png_uint_32p params_len;
  177981. png_byte buf[10];
  177982. png_charp new_purpose;
  177983. int i;
  177984. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  177985. if (type >= PNG_EQUATION_LAST)
  177986. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  177987. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  177988. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  177989. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  177990. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  177991. total_len = purpose_len + units_len + 10;
  177992. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  177993. *png_sizeof(png_uint_32)));
  177994. for (i = 0; i < nparams; i++)
  177995. {
  177996. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  177997. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  177998. total_len += (png_size_t)params_len[i];
  177999. }
  178000. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  178001. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  178002. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  178003. png_save_int_32(buf, X0);
  178004. png_save_int_32(buf + 4, X1);
  178005. buf[8] = (png_byte)type;
  178006. buf[9] = (png_byte)nparams;
  178007. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  178008. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  178009. png_free(png_ptr, new_purpose);
  178010. for (i = 0; i < nparams; i++)
  178011. {
  178012. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178013. (png_size_t)params_len[i]);
  178014. }
  178015. png_free(png_ptr, params_len);
  178016. png_write_chunk_end(png_ptr);
  178017. }
  178018. #endif
  178019. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178020. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178021. void /* PRIVATE */
  178022. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178023. {
  178024. #ifdef PNG_USE_LOCAL_ARRAYS
  178025. PNG_sCAL;
  178026. #endif
  178027. char buf[64];
  178028. png_size_t total_len;
  178029. png_debug(1, "in png_write_sCAL\n");
  178030. buf[0] = (char)unit;
  178031. #if defined(_WIN32_WCE)
  178032. {
  178033. wchar_t wc_buf[32];
  178034. size_t wc_len;
  178035. swprintf(wc_buf, TEXT("%12.12e"), width);
  178036. wc_len = wcslen(wc_buf);
  178037. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178038. total_len = wc_len + 2;
  178039. swprintf(wc_buf, TEXT("%12.12e"), height);
  178040. wc_len = wcslen(wc_buf);
  178041. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178042. NULL, NULL);
  178043. total_len += wc_len;
  178044. }
  178045. #else
  178046. png_snprintf(buf + 1, 63, "%12.12e", width);
  178047. total_len = 1 + png_strlen(buf + 1) + 1;
  178048. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178049. total_len += png_strlen(buf + total_len);
  178050. #endif
  178051. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178052. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178053. }
  178054. #else
  178055. #ifdef PNG_FIXED_POINT_SUPPORTED
  178056. void /* PRIVATE */
  178057. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178058. png_charp height)
  178059. {
  178060. #ifdef PNG_USE_LOCAL_ARRAYS
  178061. PNG_sCAL;
  178062. #endif
  178063. png_byte buf[64];
  178064. png_size_t wlen, hlen, total_len;
  178065. png_debug(1, "in png_write_sCAL_s\n");
  178066. wlen = png_strlen(width);
  178067. hlen = png_strlen(height);
  178068. total_len = wlen + hlen + 2;
  178069. if (total_len > 64)
  178070. {
  178071. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178072. return;
  178073. }
  178074. buf[0] = (png_byte)unit;
  178075. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178076. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178077. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178078. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178079. }
  178080. #endif
  178081. #endif
  178082. #endif
  178083. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178084. void /* PRIVATE */
  178085. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178086. png_uint_32 y_pixels_per_unit,
  178087. int unit_type)
  178088. {
  178089. #ifdef PNG_USE_LOCAL_ARRAYS
  178090. PNG_pHYs;
  178091. #endif
  178092. png_byte buf[9];
  178093. png_debug(1, "in png_write_pHYs\n");
  178094. if (unit_type >= PNG_RESOLUTION_LAST)
  178095. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178096. png_save_uint_32(buf, x_pixels_per_unit);
  178097. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178098. buf[8] = (png_byte)unit_type;
  178099. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178100. }
  178101. #endif
  178102. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178103. void /* PRIVATE */
  178104. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178105. {
  178106. #ifdef PNG_USE_LOCAL_ARRAYS
  178107. PNG_tIME;
  178108. #endif
  178109. png_byte buf[7];
  178110. png_debug(1, "in png_write_tIME\n");
  178111. if (mod_time->month > 12 || mod_time->month < 1 ||
  178112. mod_time->day > 31 || mod_time->day < 1 ||
  178113. mod_time->hour > 23 || mod_time->second > 60)
  178114. {
  178115. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178116. return;
  178117. }
  178118. png_save_uint_16(buf, mod_time->year);
  178119. buf[2] = mod_time->month;
  178120. buf[3] = mod_time->day;
  178121. buf[4] = mod_time->hour;
  178122. buf[5] = mod_time->minute;
  178123. buf[6] = mod_time->second;
  178124. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178125. }
  178126. #endif
  178127. void /* PRIVATE */
  178128. png_write_start_row(png_structp png_ptr)
  178129. {
  178130. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178131. #ifdef PNG_USE_LOCAL_ARRAYS
  178132. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178133. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178134. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178135. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178136. #endif
  178137. #endif
  178138. png_size_t buf_size;
  178139. png_debug(1, "in png_write_start_row\n");
  178140. buf_size = (png_size_t)(PNG_ROWBYTES(
  178141. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178142. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178143. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178144. #ifndef PNG_NO_WRITE_FILTERING
  178145. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178146. {
  178147. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178148. (png_ptr->rowbytes + 1));
  178149. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178150. }
  178151. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178152. {
  178153. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178154. png_memset(png_ptr->prev_row, 0, buf_size);
  178155. if (png_ptr->do_filter & PNG_FILTER_UP)
  178156. {
  178157. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178158. (png_ptr->rowbytes + 1));
  178159. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178160. }
  178161. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178162. {
  178163. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178164. (png_ptr->rowbytes + 1));
  178165. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178166. }
  178167. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178168. {
  178169. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178170. (png_ptr->rowbytes + 1));
  178171. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178172. }
  178173. #endif /* PNG_NO_WRITE_FILTERING */
  178174. }
  178175. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178176. if (png_ptr->interlaced)
  178177. {
  178178. if (!(png_ptr->transformations & PNG_INTERLACE))
  178179. {
  178180. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178181. png_pass_ystart[0]) / png_pass_yinc[0];
  178182. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178183. png_pass_start[0]) / png_pass_inc[0];
  178184. }
  178185. else
  178186. {
  178187. png_ptr->num_rows = png_ptr->height;
  178188. png_ptr->usr_width = png_ptr->width;
  178189. }
  178190. }
  178191. else
  178192. #endif
  178193. {
  178194. png_ptr->num_rows = png_ptr->height;
  178195. png_ptr->usr_width = png_ptr->width;
  178196. }
  178197. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178198. png_ptr->zstream.next_out = png_ptr->zbuf;
  178199. }
  178200. void /* PRIVATE */
  178201. png_write_finish_row(png_structp png_ptr)
  178202. {
  178203. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178204. #ifdef PNG_USE_LOCAL_ARRAYS
  178205. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178206. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178207. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178208. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178209. #endif
  178210. #endif
  178211. int ret;
  178212. png_debug(1, "in png_write_finish_row\n");
  178213. png_ptr->row_number++;
  178214. if (png_ptr->row_number < png_ptr->num_rows)
  178215. return;
  178216. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178217. if (png_ptr->interlaced)
  178218. {
  178219. png_ptr->row_number = 0;
  178220. if (png_ptr->transformations & PNG_INTERLACE)
  178221. {
  178222. png_ptr->pass++;
  178223. }
  178224. else
  178225. {
  178226. do
  178227. {
  178228. png_ptr->pass++;
  178229. if (png_ptr->pass >= 7)
  178230. break;
  178231. png_ptr->usr_width = (png_ptr->width +
  178232. png_pass_inc[png_ptr->pass] - 1 -
  178233. png_pass_start[png_ptr->pass]) /
  178234. png_pass_inc[png_ptr->pass];
  178235. png_ptr->num_rows = (png_ptr->height +
  178236. png_pass_yinc[png_ptr->pass] - 1 -
  178237. png_pass_ystart[png_ptr->pass]) /
  178238. png_pass_yinc[png_ptr->pass];
  178239. if (png_ptr->transformations & PNG_INTERLACE)
  178240. break;
  178241. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178242. }
  178243. if (png_ptr->pass < 7)
  178244. {
  178245. if (png_ptr->prev_row != NULL)
  178246. png_memset(png_ptr->prev_row, 0,
  178247. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178248. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178249. return;
  178250. }
  178251. }
  178252. #endif
  178253. do
  178254. {
  178255. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178256. if (ret == Z_OK)
  178257. {
  178258. if (!(png_ptr->zstream.avail_out))
  178259. {
  178260. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178261. png_ptr->zstream.next_out = png_ptr->zbuf;
  178262. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178263. }
  178264. }
  178265. else if (ret != Z_STREAM_END)
  178266. {
  178267. if (png_ptr->zstream.msg != NULL)
  178268. png_error(png_ptr, png_ptr->zstream.msg);
  178269. else
  178270. png_error(png_ptr, "zlib error");
  178271. }
  178272. } while (ret != Z_STREAM_END);
  178273. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178274. {
  178275. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178276. png_ptr->zstream.avail_out);
  178277. }
  178278. deflateReset(&png_ptr->zstream);
  178279. png_ptr->zstream.data_type = Z_BINARY;
  178280. }
  178281. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178282. void /* PRIVATE */
  178283. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178284. {
  178285. #ifdef PNG_USE_LOCAL_ARRAYS
  178286. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178287. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178288. #endif
  178289. png_debug(1, "in png_do_write_interlace\n");
  178290. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178291. if (row != NULL && row_info != NULL && pass < 6)
  178292. #else
  178293. if (pass < 6)
  178294. #endif
  178295. {
  178296. switch (row_info->pixel_depth)
  178297. {
  178298. case 1:
  178299. {
  178300. png_bytep sp;
  178301. png_bytep dp;
  178302. int shift;
  178303. int d;
  178304. int value;
  178305. png_uint_32 i;
  178306. png_uint_32 row_width = row_info->width;
  178307. dp = row;
  178308. d = 0;
  178309. shift = 7;
  178310. for (i = png_pass_start[pass]; i < row_width;
  178311. i += png_pass_inc[pass])
  178312. {
  178313. sp = row + (png_size_t)(i >> 3);
  178314. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178315. d |= (value << shift);
  178316. if (shift == 0)
  178317. {
  178318. shift = 7;
  178319. *dp++ = (png_byte)d;
  178320. d = 0;
  178321. }
  178322. else
  178323. shift--;
  178324. }
  178325. if (shift != 7)
  178326. *dp = (png_byte)d;
  178327. break;
  178328. }
  178329. case 2:
  178330. {
  178331. png_bytep sp;
  178332. png_bytep dp;
  178333. int shift;
  178334. int d;
  178335. int value;
  178336. png_uint_32 i;
  178337. png_uint_32 row_width = row_info->width;
  178338. dp = row;
  178339. shift = 6;
  178340. d = 0;
  178341. for (i = png_pass_start[pass]; i < row_width;
  178342. i += png_pass_inc[pass])
  178343. {
  178344. sp = row + (png_size_t)(i >> 2);
  178345. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178346. d |= (value << shift);
  178347. if (shift == 0)
  178348. {
  178349. shift = 6;
  178350. *dp++ = (png_byte)d;
  178351. d = 0;
  178352. }
  178353. else
  178354. shift -= 2;
  178355. }
  178356. if (shift != 6)
  178357. *dp = (png_byte)d;
  178358. break;
  178359. }
  178360. case 4:
  178361. {
  178362. png_bytep sp;
  178363. png_bytep dp;
  178364. int shift;
  178365. int d;
  178366. int value;
  178367. png_uint_32 i;
  178368. png_uint_32 row_width = row_info->width;
  178369. dp = row;
  178370. shift = 4;
  178371. d = 0;
  178372. for (i = png_pass_start[pass]; i < row_width;
  178373. i += png_pass_inc[pass])
  178374. {
  178375. sp = row + (png_size_t)(i >> 1);
  178376. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178377. d |= (value << shift);
  178378. if (shift == 0)
  178379. {
  178380. shift = 4;
  178381. *dp++ = (png_byte)d;
  178382. d = 0;
  178383. }
  178384. else
  178385. shift -= 4;
  178386. }
  178387. if (shift != 4)
  178388. *dp = (png_byte)d;
  178389. break;
  178390. }
  178391. default:
  178392. {
  178393. png_bytep sp;
  178394. png_bytep dp;
  178395. png_uint_32 i;
  178396. png_uint_32 row_width = row_info->width;
  178397. png_size_t pixel_bytes;
  178398. dp = row;
  178399. pixel_bytes = (row_info->pixel_depth >> 3);
  178400. for (i = png_pass_start[pass]; i < row_width;
  178401. i += png_pass_inc[pass])
  178402. {
  178403. sp = row + (png_size_t)i * pixel_bytes;
  178404. if (dp != sp)
  178405. png_memcpy(dp, sp, pixel_bytes);
  178406. dp += pixel_bytes;
  178407. }
  178408. break;
  178409. }
  178410. }
  178411. row_info->width = (row_info->width +
  178412. png_pass_inc[pass] - 1 -
  178413. png_pass_start[pass]) /
  178414. png_pass_inc[pass];
  178415. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178416. row_info->width);
  178417. }
  178418. }
  178419. #endif
  178420. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178421. #define PNG_HISHIFT 10
  178422. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178423. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178424. void /* PRIVATE */
  178425. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178426. {
  178427. png_bytep best_row;
  178428. #ifndef PNG_NO_WRITE_FILTER
  178429. png_bytep prev_row, row_buf;
  178430. png_uint_32 mins, bpp;
  178431. png_byte filter_to_do = png_ptr->do_filter;
  178432. png_uint_32 row_bytes = row_info->rowbytes;
  178433. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178434. int num_p_filters = (int)png_ptr->num_prev_filters;
  178435. #endif
  178436. png_debug(1, "in png_write_find_filter\n");
  178437. bpp = (row_info->pixel_depth + 7) >> 3;
  178438. prev_row = png_ptr->prev_row;
  178439. #endif
  178440. best_row = png_ptr->row_buf;
  178441. #ifndef PNG_NO_WRITE_FILTER
  178442. row_buf = best_row;
  178443. mins = PNG_MAXSUM;
  178444. if ((filter_to_do & PNG_FILTER_NONE) &&
  178445. filter_to_do != PNG_FILTER_NONE)
  178446. {
  178447. png_bytep rp;
  178448. png_uint_32 sum = 0;
  178449. png_uint_32 i;
  178450. int v;
  178451. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178452. {
  178453. v = *rp;
  178454. sum += (v < 128) ? v : 256 - v;
  178455. }
  178456. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178457. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178458. {
  178459. png_uint_32 sumhi, sumlo;
  178460. int j;
  178461. sumlo = sum & PNG_LOMASK;
  178462. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178463. for (j = 0; j < num_p_filters; j++)
  178464. {
  178465. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178466. {
  178467. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178468. PNG_WEIGHT_SHIFT;
  178469. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178470. PNG_WEIGHT_SHIFT;
  178471. }
  178472. }
  178473. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178474. PNG_COST_SHIFT;
  178475. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178476. PNG_COST_SHIFT;
  178477. if (sumhi > PNG_HIMASK)
  178478. sum = PNG_MAXSUM;
  178479. else
  178480. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178481. }
  178482. #endif
  178483. mins = sum;
  178484. }
  178485. if (filter_to_do == PNG_FILTER_SUB)
  178486. {
  178487. png_bytep rp, lp, dp;
  178488. png_uint_32 i;
  178489. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178490. i++, rp++, dp++)
  178491. {
  178492. *dp = *rp;
  178493. }
  178494. for (lp = row_buf + 1; i < row_bytes;
  178495. i++, rp++, lp++, dp++)
  178496. {
  178497. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178498. }
  178499. best_row = png_ptr->sub_row;
  178500. }
  178501. else if (filter_to_do & PNG_FILTER_SUB)
  178502. {
  178503. png_bytep rp, dp, lp;
  178504. png_uint_32 sum = 0, lmins = mins;
  178505. png_uint_32 i;
  178506. int v;
  178507. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178508. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178509. {
  178510. int j;
  178511. png_uint_32 lmhi, lmlo;
  178512. lmlo = lmins & PNG_LOMASK;
  178513. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178514. for (j = 0; j < num_p_filters; j++)
  178515. {
  178516. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178517. {
  178518. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178519. PNG_WEIGHT_SHIFT;
  178520. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178521. PNG_WEIGHT_SHIFT;
  178522. }
  178523. }
  178524. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178525. PNG_COST_SHIFT;
  178526. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178527. PNG_COST_SHIFT;
  178528. if (lmhi > PNG_HIMASK)
  178529. lmins = PNG_MAXSUM;
  178530. else
  178531. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178532. }
  178533. #endif
  178534. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178535. i++, rp++, dp++)
  178536. {
  178537. v = *dp = *rp;
  178538. sum += (v < 128) ? v : 256 - v;
  178539. }
  178540. for (lp = row_buf + 1; i < row_bytes;
  178541. i++, rp++, lp++, dp++)
  178542. {
  178543. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178544. sum += (v < 128) ? v : 256 - v;
  178545. if (sum > lmins) /* We are already worse, don't continue. */
  178546. break;
  178547. }
  178548. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178549. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178550. {
  178551. int j;
  178552. png_uint_32 sumhi, sumlo;
  178553. sumlo = sum & PNG_LOMASK;
  178554. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178555. for (j = 0; j < num_p_filters; j++)
  178556. {
  178557. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178558. {
  178559. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  178560. PNG_WEIGHT_SHIFT;
  178561. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  178562. PNG_WEIGHT_SHIFT;
  178563. }
  178564. }
  178565. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178566. PNG_COST_SHIFT;
  178567. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178568. PNG_COST_SHIFT;
  178569. if (sumhi > PNG_HIMASK)
  178570. sum = PNG_MAXSUM;
  178571. else
  178572. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178573. }
  178574. #endif
  178575. if (sum < mins)
  178576. {
  178577. mins = sum;
  178578. best_row = png_ptr->sub_row;
  178579. }
  178580. }
  178581. if (filter_to_do == PNG_FILTER_UP)
  178582. {
  178583. png_bytep rp, dp, pp;
  178584. png_uint_32 i;
  178585. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178586. pp = prev_row + 1; i < row_bytes;
  178587. i++, rp++, pp++, dp++)
  178588. {
  178589. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  178590. }
  178591. best_row = png_ptr->up_row;
  178592. }
  178593. else if (filter_to_do & PNG_FILTER_UP)
  178594. {
  178595. png_bytep rp, dp, pp;
  178596. png_uint_32 sum = 0, lmins = mins;
  178597. png_uint_32 i;
  178598. int v;
  178599. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178600. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178601. {
  178602. int j;
  178603. png_uint_32 lmhi, lmlo;
  178604. lmlo = lmins & PNG_LOMASK;
  178605. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178606. for (j = 0; j < num_p_filters; j++)
  178607. {
  178608. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178609. {
  178610. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178611. PNG_WEIGHT_SHIFT;
  178612. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178613. PNG_WEIGHT_SHIFT;
  178614. }
  178615. }
  178616. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178617. PNG_COST_SHIFT;
  178618. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178619. PNG_COST_SHIFT;
  178620. if (lmhi > PNG_HIMASK)
  178621. lmins = PNG_MAXSUM;
  178622. else
  178623. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178624. }
  178625. #endif
  178626. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178627. pp = prev_row + 1; i < row_bytes; i++)
  178628. {
  178629. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178630. sum += (v < 128) ? v : 256 - v;
  178631. if (sum > lmins) /* We are already worse, don't continue. */
  178632. break;
  178633. }
  178634. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178635. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178636. {
  178637. int j;
  178638. png_uint_32 sumhi, sumlo;
  178639. sumlo = sum & PNG_LOMASK;
  178640. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178641. for (j = 0; j < num_p_filters; j++)
  178642. {
  178643. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178644. {
  178645. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178646. PNG_WEIGHT_SHIFT;
  178647. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178648. PNG_WEIGHT_SHIFT;
  178649. }
  178650. }
  178651. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178652. PNG_COST_SHIFT;
  178653. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178654. PNG_COST_SHIFT;
  178655. if (sumhi > PNG_HIMASK)
  178656. sum = PNG_MAXSUM;
  178657. else
  178658. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178659. }
  178660. #endif
  178661. if (sum < mins)
  178662. {
  178663. mins = sum;
  178664. best_row = png_ptr->up_row;
  178665. }
  178666. }
  178667. if (filter_to_do == PNG_FILTER_AVG)
  178668. {
  178669. png_bytep rp, dp, pp, lp;
  178670. png_uint_32 i;
  178671. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178672. pp = prev_row + 1; i < bpp; i++)
  178673. {
  178674. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178675. }
  178676. for (lp = row_buf + 1; i < row_bytes; i++)
  178677. {
  178678. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  178679. & 0xff);
  178680. }
  178681. best_row = png_ptr->avg_row;
  178682. }
  178683. else if (filter_to_do & PNG_FILTER_AVG)
  178684. {
  178685. png_bytep rp, dp, pp, lp;
  178686. png_uint_32 sum = 0, lmins = mins;
  178687. png_uint_32 i;
  178688. int v;
  178689. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178690. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178691. {
  178692. int j;
  178693. png_uint_32 lmhi, lmlo;
  178694. lmlo = lmins & PNG_LOMASK;
  178695. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178696. for (j = 0; j < num_p_filters; j++)
  178697. {
  178698. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  178699. {
  178700. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178701. PNG_WEIGHT_SHIFT;
  178702. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178703. PNG_WEIGHT_SHIFT;
  178704. }
  178705. }
  178706. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178707. PNG_COST_SHIFT;
  178708. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178709. PNG_COST_SHIFT;
  178710. if (lmhi > PNG_HIMASK)
  178711. lmins = PNG_MAXSUM;
  178712. else
  178713. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178714. }
  178715. #endif
  178716. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178717. pp = prev_row + 1; i < bpp; i++)
  178718. {
  178719. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178720. sum += (v < 128) ? v : 256 - v;
  178721. }
  178722. for (lp = row_buf + 1; i < row_bytes; i++)
  178723. {
  178724. v = *dp++ =
  178725. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  178726. sum += (v < 128) ? v : 256 - v;
  178727. if (sum > lmins) /* We are already worse, don't continue. */
  178728. break;
  178729. }
  178730. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178731. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178732. {
  178733. int j;
  178734. png_uint_32 sumhi, sumlo;
  178735. sumlo = sum & PNG_LOMASK;
  178736. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178737. for (j = 0; j < num_p_filters; j++)
  178738. {
  178739. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178740. {
  178741. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178742. PNG_WEIGHT_SHIFT;
  178743. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178744. PNG_WEIGHT_SHIFT;
  178745. }
  178746. }
  178747. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178748. PNG_COST_SHIFT;
  178749. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178750. PNG_COST_SHIFT;
  178751. if (sumhi > PNG_HIMASK)
  178752. sum = PNG_MAXSUM;
  178753. else
  178754. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178755. }
  178756. #endif
  178757. if (sum < mins)
  178758. {
  178759. mins = sum;
  178760. best_row = png_ptr->avg_row;
  178761. }
  178762. }
  178763. if (filter_to_do == PNG_FILTER_PAETH)
  178764. {
  178765. png_bytep rp, dp, pp, cp, lp;
  178766. png_uint_32 i;
  178767. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178768. pp = prev_row + 1; i < bpp; i++)
  178769. {
  178770. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178771. }
  178772. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178773. {
  178774. int a, b, c, pa, pb, pc, p;
  178775. b = *pp++;
  178776. c = *cp++;
  178777. a = *lp++;
  178778. p = b - c;
  178779. pc = a - c;
  178780. #ifdef PNG_USE_ABS
  178781. pa = abs(p);
  178782. pb = abs(pc);
  178783. pc = abs(p + pc);
  178784. #else
  178785. pa = p < 0 ? -p : p;
  178786. pb = pc < 0 ? -pc : pc;
  178787. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178788. #endif
  178789. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178790. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178791. }
  178792. best_row = png_ptr->paeth_row;
  178793. }
  178794. else if (filter_to_do & PNG_FILTER_PAETH)
  178795. {
  178796. png_bytep rp, dp, pp, cp, lp;
  178797. png_uint_32 sum = 0, lmins = mins;
  178798. png_uint_32 i;
  178799. int v;
  178800. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178801. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178802. {
  178803. int j;
  178804. png_uint_32 lmhi, lmlo;
  178805. lmlo = lmins & PNG_LOMASK;
  178806. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178807. for (j = 0; j < num_p_filters; j++)
  178808. {
  178809. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178810. {
  178811. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178812. PNG_WEIGHT_SHIFT;
  178813. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178814. PNG_WEIGHT_SHIFT;
  178815. }
  178816. }
  178817. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178818. PNG_COST_SHIFT;
  178819. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178820. PNG_COST_SHIFT;
  178821. if (lmhi > PNG_HIMASK)
  178822. lmins = PNG_MAXSUM;
  178823. else
  178824. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178825. }
  178826. #endif
  178827. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178828. pp = prev_row + 1; i < bpp; i++)
  178829. {
  178830. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178831. sum += (v < 128) ? v : 256 - v;
  178832. }
  178833. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178834. {
  178835. int a, b, c, pa, pb, pc, p;
  178836. b = *pp++;
  178837. c = *cp++;
  178838. a = *lp++;
  178839. #ifndef PNG_SLOW_PAETH
  178840. p = b - c;
  178841. pc = a - c;
  178842. #ifdef PNG_USE_ABS
  178843. pa = abs(p);
  178844. pb = abs(pc);
  178845. pc = abs(p + pc);
  178846. #else
  178847. pa = p < 0 ? -p : p;
  178848. pb = pc < 0 ? -pc : pc;
  178849. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178850. #endif
  178851. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178852. #else /* PNG_SLOW_PAETH */
  178853. p = a + b - c;
  178854. pa = abs(p - a);
  178855. pb = abs(p - b);
  178856. pc = abs(p - c);
  178857. if (pa <= pb && pa <= pc)
  178858. p = a;
  178859. else if (pb <= pc)
  178860. p = b;
  178861. else
  178862. p = c;
  178863. #endif /* PNG_SLOW_PAETH */
  178864. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178865. sum += (v < 128) ? v : 256 - v;
  178866. if (sum > lmins) /* We are already worse, don't continue. */
  178867. break;
  178868. }
  178869. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178870. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178871. {
  178872. int j;
  178873. png_uint_32 sumhi, sumlo;
  178874. sumlo = sum & PNG_LOMASK;
  178875. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178876. for (j = 0; j < num_p_filters; j++)
  178877. {
  178878. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178879. {
  178880. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178881. PNG_WEIGHT_SHIFT;
  178882. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178883. PNG_WEIGHT_SHIFT;
  178884. }
  178885. }
  178886. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178887. PNG_COST_SHIFT;
  178888. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178889. PNG_COST_SHIFT;
  178890. if (sumhi > PNG_HIMASK)
  178891. sum = PNG_MAXSUM;
  178892. else
  178893. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178894. }
  178895. #endif
  178896. if (sum < mins)
  178897. {
  178898. best_row = png_ptr->paeth_row;
  178899. }
  178900. }
  178901. #endif /* PNG_NO_WRITE_FILTER */
  178902. png_write_filtered_row(png_ptr, best_row);
  178903. #ifndef PNG_NO_WRITE_FILTER
  178904. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178905. if (png_ptr->num_prev_filters > 0)
  178906. {
  178907. int j;
  178908. for (j = 1; j < num_p_filters; j++)
  178909. {
  178910. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  178911. }
  178912. png_ptr->prev_filters[j] = best_row[0];
  178913. }
  178914. #endif
  178915. #endif /* PNG_NO_WRITE_FILTER */
  178916. }
  178917. void /* PRIVATE */
  178918. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  178919. {
  178920. png_debug(1, "in png_write_filtered_row\n");
  178921. png_debug1(2, "filter = %d\n", filtered_row[0]);
  178922. png_ptr->zstream.next_in = filtered_row;
  178923. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  178924. do
  178925. {
  178926. int ret; /* return of zlib */
  178927. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  178928. if (ret != Z_OK)
  178929. {
  178930. if (png_ptr->zstream.msg != NULL)
  178931. png_error(png_ptr, png_ptr->zstream.msg);
  178932. else
  178933. png_error(png_ptr, "zlib error");
  178934. }
  178935. if (!(png_ptr->zstream.avail_out))
  178936. {
  178937. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178938. png_ptr->zstream.next_out = png_ptr->zbuf;
  178939. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178940. }
  178941. } while (png_ptr->zstream.avail_in);
  178942. if (png_ptr->prev_row != NULL)
  178943. {
  178944. png_bytep tptr;
  178945. tptr = png_ptr->prev_row;
  178946. png_ptr->prev_row = png_ptr->row_buf;
  178947. png_ptr->row_buf = tptr;
  178948. }
  178949. png_write_finish_row(png_ptr);
  178950. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  178951. png_ptr->flush_rows++;
  178952. if (png_ptr->flush_dist > 0 &&
  178953. png_ptr->flush_rows >= png_ptr->flush_dist)
  178954. {
  178955. png_write_flush(png_ptr);
  178956. }
  178957. #endif
  178958. }
  178959. #endif /* PNG_WRITE_SUPPORTED */
  178960. /*** End of inlined file: pngwutil.c ***/
  178961. }
  178962. #else
  178963. #define PNG_INTERNAL
  178964. #define PNG_SETJMP_NOT_SUPPORTED
  178965. #include <png.h>
  178966. #include <pngconf.h>
  178967. #endif
  178968. }
  178969. #undef max
  178970. #undef min
  178971. #ifdef _MSC_VER
  178972. #pragma warning (pop)
  178973. #endif
  178974. BEGIN_JUCE_NAMESPACE
  178975. using ::calloc;
  178976. using ::malloc;
  178977. using ::free;
  178978. namespace PNGHelpers
  178979. {
  178980. using namespace pnglibNamespace;
  178981. static void readCallback (png_structp png, png_bytep data, png_size_t length)
  178982. {
  178983. static_cast<InputStream*> (png->io_ptr)->read (data, (int) length);
  178984. }
  178985. static void writeDataCallback (png_structp png, png_bytep data, png_size_t length)
  178986. {
  178987. static_cast<OutputStream*> (png->io_ptr)->write (data, (int) length);
  178988. }
  178989. struct PNGErrorStruct {};
  178990. static void errorCallback (png_structp, png_const_charp)
  178991. {
  178992. throw PNGErrorStruct();
  178993. }
  178994. }
  178995. Image* juce_loadPNGImageFromStream (InputStream& in)
  178996. {
  178997. using namespace pnglibNamespace;
  178998. Image* image = 0;
  178999. png_structp pngReadStruct;
  179000. png_infop pngInfoStruct;
  179001. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179002. if (pngReadStruct != 0)
  179003. {
  179004. pngInfoStruct = png_create_info_struct (pngReadStruct);
  179005. if (pngInfoStruct == 0)
  179006. {
  179007. png_destroy_read_struct (&pngReadStruct, 0, 0);
  179008. return 0;
  179009. }
  179010. png_set_error_fn (pngReadStruct, 0, PNGHelpers::errorCallback, PNGHelpers::errorCallback );
  179011. // read the header..
  179012. png_set_read_fn (pngReadStruct, &in, PNGHelpers::readCallback);
  179013. png_uint_32 width, height;
  179014. int bitDepth, colorType, interlaceType;
  179015. png_read_info (pngReadStruct, pngInfoStruct);
  179016. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179017. &width, &height,
  179018. &bitDepth, &colorType,
  179019. &interlaceType, 0, 0);
  179020. if (bitDepth == 16)
  179021. png_set_strip_16 (pngReadStruct);
  179022. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179023. png_set_expand (pngReadStruct);
  179024. if (bitDepth < 8)
  179025. png_set_expand (pngReadStruct);
  179026. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179027. png_set_expand (pngReadStruct);
  179028. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179029. png_set_gray_to_rgb (pngReadStruct);
  179030. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179031. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179032. || pngInfoStruct->num_trans > 0;
  179033. // Load the image into a temp buffer in the pnglib format..
  179034. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179035. {
  179036. HeapBlock <png_bytep> rows (height);
  179037. for (int y = (int) height; --y >= 0;)
  179038. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179039. png_read_image (pngReadStruct, rows);
  179040. png_read_end (pngReadStruct, pngInfoStruct);
  179041. }
  179042. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179043. // now convert the data to a juce image format..
  179044. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179045. (int) width, (int) height, hasAlphaChan);
  179046. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179047. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179048. uint8* srcRow = tempBuffer;
  179049. uint8* destRow = destData.data;
  179050. for (int y = 0; y < (int) height; ++y)
  179051. {
  179052. const uint8* src = srcRow;
  179053. srcRow += (width << 2);
  179054. uint8* dest = destRow;
  179055. destRow += destData.lineStride;
  179056. if (hasAlphaChan)
  179057. {
  179058. for (int i = (int) width; --i >= 0;)
  179059. {
  179060. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179061. ((PixelARGB*) dest)->premultiply();
  179062. dest += destData.pixelStride;
  179063. src += 4;
  179064. }
  179065. }
  179066. else
  179067. {
  179068. for (int i = (int) width; --i >= 0;)
  179069. {
  179070. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179071. dest += destData.pixelStride;
  179072. src += 4;
  179073. }
  179074. }
  179075. }
  179076. }
  179077. return image;
  179078. }
  179079. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179080. {
  179081. using namespace pnglibNamespace;
  179082. const int width = image.getWidth();
  179083. const int height = image.getHeight();
  179084. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179085. if (pngWriteStruct == 0)
  179086. return false;
  179087. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179088. if (pngInfoStruct == 0)
  179089. {
  179090. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179091. return false;
  179092. }
  179093. png_set_write_fn (pngWriteStruct, &out, PNGHelpers::writeDataCallback, 0);
  179094. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179095. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179096. : PNG_COLOR_TYPE_RGB,
  179097. PNG_INTERLACE_NONE,
  179098. PNG_COMPRESSION_TYPE_BASE,
  179099. PNG_FILTER_TYPE_BASE);
  179100. HeapBlock <png_byte> rowData (width * 4);
  179101. png_color_8 sig_bit;
  179102. sig_bit.red = 8;
  179103. sig_bit.green = 8;
  179104. sig_bit.blue = 8;
  179105. sig_bit.alpha = 8;
  179106. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179107. png_write_info (pngWriteStruct, pngInfoStruct);
  179108. png_set_shift (pngWriteStruct, &sig_bit);
  179109. png_set_packing (pngWriteStruct);
  179110. const Image::BitmapData srcData (image, 0, 0, width, height);
  179111. for (int y = 0; y < height; ++y)
  179112. {
  179113. uint8* dst = (uint8*) rowData;
  179114. const uint8* src = srcData.getLinePointer (y);
  179115. if (image.hasAlphaChannel())
  179116. {
  179117. for (int i = width; --i >= 0;)
  179118. {
  179119. PixelARGB p (*(const PixelARGB*) src);
  179120. p.unpremultiply();
  179121. *dst++ = p.getRed();
  179122. *dst++ = p.getGreen();
  179123. *dst++ = p.getBlue();
  179124. *dst++ = p.getAlpha();
  179125. src += srcData.pixelStride;
  179126. }
  179127. }
  179128. else
  179129. {
  179130. for (int i = width; --i >= 0;)
  179131. {
  179132. *dst++ = ((const PixelRGB*) src)->getRed();
  179133. *dst++ = ((const PixelRGB*) src)->getGreen();
  179134. *dst++ = ((const PixelRGB*) src)->getBlue();
  179135. src += srcData.pixelStride;
  179136. }
  179137. }
  179138. png_write_rows (pngWriteStruct, &rowData, 1);
  179139. }
  179140. png_write_end (pngWriteStruct, pngInfoStruct);
  179141. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179142. out.flush();
  179143. return true;
  179144. }
  179145. END_JUCE_NAMESPACE
  179146. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179147. #endif
  179148. //==============================================================================
  179149. #if JUCE_BUILD_NATIVE
  179150. #if JUCE_WINDOWS
  179151. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179152. #if JUCE_WINDOWS
  179153. BEGIN_JUCE_NAMESPACE
  179154. #define JUCE_INCLUDED_FILE 1
  179155. // Now include the actual code files..
  179156. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179157. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179158. // compiled on its own).
  179159. #if JUCE_INCLUDED_FILE
  179160. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179161. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179162. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179163. #ifndef DOXYGEN
  179164. // use with DynamicLibraryLoader to simplify importing functions
  179165. //
  179166. // functionName: function to import
  179167. // localFunctionName: name you want to use to actually call it (must be different)
  179168. // returnType: the return type
  179169. // object: the DynamicLibraryLoader to use
  179170. // params: list of params (bracketed)
  179171. //
  179172. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179173. typedef returnType (WINAPI *type##localFunctionName) params; \
  179174. type##localFunctionName localFunctionName \
  179175. = (type##localFunctionName)object.findProcAddress (#functionName);
  179176. // loads and unloads a DLL automatically
  179177. class JUCE_API DynamicLibraryLoader
  179178. {
  179179. public:
  179180. DynamicLibraryLoader (const String& name);
  179181. ~DynamicLibraryLoader();
  179182. void* findProcAddress (const String& functionName);
  179183. private:
  179184. void* libHandle;
  179185. };
  179186. #endif
  179187. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179188. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179189. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179190. {
  179191. libHandle = LoadLibrary (name);
  179192. }
  179193. DynamicLibraryLoader::~DynamicLibraryLoader()
  179194. {
  179195. FreeLibrary ((HMODULE) libHandle);
  179196. }
  179197. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179198. {
  179199. return (void*) GetProcAddress ((HMODULE) libHandle, functionName.toCString());
  179200. }
  179201. #endif
  179202. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179203. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179204. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179205. // compiled on its own).
  179206. #if JUCE_INCLUDED_FILE
  179207. extern void juce_initialiseThreadEvents();
  179208. void Logger::outputDebugString (const String& text) throw()
  179209. {
  179210. OutputDebugString (text + T("\n"));
  179211. }
  179212. static int64 hiResTicksPerSecond;
  179213. static double hiResTicksScaleFactor;
  179214. #if JUCE_USE_INTRINSICS
  179215. // CPU info functions using intrinsics...
  179216. #pragma intrinsic (__cpuid)
  179217. #pragma intrinsic (__rdtsc)
  179218. const String SystemStats::getCpuVendor() throw()
  179219. {
  179220. int info [4];
  179221. __cpuid (info, 0);
  179222. char v [12];
  179223. memcpy (v, info + 1, 4);
  179224. memcpy (v + 4, info + 3, 4);
  179225. memcpy (v + 8, info + 2, 4);
  179226. return String (v, 12);
  179227. }
  179228. #else
  179229. // CPU info functions using old fashioned inline asm...
  179230. static void juce_getCpuVendor (char* const v)
  179231. {
  179232. int vendor[4];
  179233. zeromem (vendor, 16);
  179234. #ifdef JUCE_64BIT
  179235. #else
  179236. #ifndef __MINGW32__
  179237. __try
  179238. #endif
  179239. {
  179240. #if JUCE_GCC
  179241. unsigned int dummy = 0;
  179242. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179243. #else
  179244. __asm
  179245. {
  179246. mov eax, 0
  179247. cpuid
  179248. mov [vendor], ebx
  179249. mov [vendor + 4], edx
  179250. mov [vendor + 8], ecx
  179251. }
  179252. #endif
  179253. }
  179254. #ifndef __MINGW32__
  179255. __except (EXCEPTION_EXECUTE_HANDLER)
  179256. {
  179257. *v = 0;
  179258. }
  179259. #endif
  179260. #endif
  179261. memcpy (v, vendor, 16);
  179262. }
  179263. const String SystemStats::getCpuVendor() throw()
  179264. {
  179265. char v [16];
  179266. juce_getCpuVendor (v);
  179267. return String (v, 16);
  179268. }
  179269. #endif
  179270. struct CPUFlags
  179271. {
  179272. bool hasMMX : 1;
  179273. bool hasSSE : 1;
  179274. bool hasSSE2 : 1;
  179275. bool has3DNow : 1;
  179276. };
  179277. static CPUFlags cpuFlags;
  179278. bool SystemStats::hasMMX() throw()
  179279. {
  179280. return cpuFlags.hasMMX;
  179281. }
  179282. bool SystemStats::hasSSE() throw()
  179283. {
  179284. return cpuFlags.hasSSE;
  179285. }
  179286. bool SystemStats::hasSSE2() throw()
  179287. {
  179288. return cpuFlags.hasSSE2;
  179289. }
  179290. bool SystemStats::has3DNow() throw()
  179291. {
  179292. return cpuFlags.has3DNow;
  179293. }
  179294. void SystemStats::initialiseStats() throw()
  179295. {
  179296. juce_initialiseThreadEvents();
  179297. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179298. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179299. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179300. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179301. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179302. #else
  179303. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179304. #endif
  179305. LARGE_INTEGER f;
  179306. QueryPerformanceFrequency (&f);
  179307. hiResTicksPerSecond = f.QuadPart;
  179308. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179309. String s (SystemStats::getJUCEVersion());
  179310. #ifdef JUCE_DEBUG
  179311. const MMRESULT res = timeBeginPeriod (1);
  179312. jassert (res == TIMERR_NOERROR);
  179313. #else
  179314. timeBeginPeriod (1);
  179315. #endif
  179316. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179317. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179318. #endif
  179319. }
  179320. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179321. {
  179322. OSVERSIONINFO info;
  179323. info.dwOSVersionInfoSize = sizeof (info);
  179324. GetVersionEx (&info);
  179325. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179326. {
  179327. switch (info.dwMajorVersion)
  179328. {
  179329. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179330. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179331. default: jassertfalse; break; // !! not a supported OS!
  179332. }
  179333. }
  179334. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179335. {
  179336. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179337. return Win98;
  179338. }
  179339. return UnknownOS;
  179340. }
  179341. const String SystemStats::getOperatingSystemName() throw()
  179342. {
  179343. const char* name = "Unknown OS";
  179344. switch (getOperatingSystemType())
  179345. {
  179346. case Windows7: name = "Windows 7"; break;
  179347. case WinVista: name = "Windows Vista"; break;
  179348. case WinXP: name = "Windows XP"; break;
  179349. case Win2000: name = "Windows 2000"; break;
  179350. case Win98: name = "Windows 98"; break;
  179351. default: jassertfalse; break; // !! new type of OS?
  179352. }
  179353. return name;
  179354. }
  179355. bool SystemStats::isOperatingSystem64Bit() throw()
  179356. {
  179357. #ifdef _WIN64
  179358. return true;
  179359. #else
  179360. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179361. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179362. BOOL isWow64 = FALSE;
  179363. return (fnIsWow64Process != 0)
  179364. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179365. && (isWow64 != FALSE);
  179366. #endif
  179367. }
  179368. int SystemStats::getMemorySizeInMegabytes() throw()
  179369. {
  179370. MEMORYSTATUSEX mem;
  179371. mem.dwLength = sizeof (mem);
  179372. GlobalMemoryStatusEx (&mem);
  179373. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179374. }
  179375. int SystemStats::getNumCpus() throw()
  179376. {
  179377. SYSTEM_INFO systemInfo;
  179378. GetSystemInfo (&systemInfo);
  179379. return systemInfo.dwNumberOfProcessors;
  179380. }
  179381. uint32 juce_millisecondsSinceStartup() throw()
  179382. {
  179383. return (uint32) GetTickCount();
  179384. }
  179385. int64 Time::getHighResolutionTicks() throw()
  179386. {
  179387. LARGE_INTEGER ticks;
  179388. QueryPerformanceCounter (&ticks);
  179389. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179390. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179391. // fix for a very obscure PCI hardware bug that can make the counter
  179392. // sometimes jump forwards by a few seconds..
  179393. static int64 hiResTicksOffset = 0;
  179394. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179395. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179396. hiResTicksOffset = newOffset;
  179397. return ticks.QuadPart + hiResTicksOffset;
  179398. }
  179399. double Time::getMillisecondCounterHiRes() throw()
  179400. {
  179401. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179402. }
  179403. int64 Time::getHighResolutionTicksPerSecond() throw()
  179404. {
  179405. return hiResTicksPerSecond;
  179406. }
  179407. int64 SystemStats::getClockCycleCounter() throw()
  179408. {
  179409. #if JUCE_USE_INTRINSICS
  179410. // MS intrinsics version...
  179411. return __rdtsc();
  179412. #elif JUCE_GCC
  179413. // GNU inline asm version...
  179414. unsigned int hi = 0, lo = 0;
  179415. __asm__ __volatile__ (
  179416. "xor %%eax, %%eax \n\
  179417. xor %%edx, %%edx \n\
  179418. rdtsc \n\
  179419. movl %%eax, %[lo] \n\
  179420. movl %%edx, %[hi]"
  179421. :
  179422. : [hi] "m" (hi),
  179423. [lo] "m" (lo)
  179424. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179425. return (int64) ((((uint64) hi) << 32) | lo);
  179426. #else
  179427. // MSVC inline asm version...
  179428. unsigned int hi = 0, lo = 0;
  179429. __asm
  179430. {
  179431. xor eax, eax
  179432. xor edx, edx
  179433. rdtsc
  179434. mov lo, eax
  179435. mov hi, edx
  179436. }
  179437. return (int64) ((((uint64) hi) << 32) | lo);
  179438. #endif
  179439. }
  179440. int SystemStats::getCpuSpeedInMegaherz() throw()
  179441. {
  179442. const int64 cycles = SystemStats::getClockCycleCounter();
  179443. const uint32 millis = Time::getMillisecondCounter();
  179444. int lastResult = 0;
  179445. for (;;)
  179446. {
  179447. int n = 1000000;
  179448. while (--n > 0) {}
  179449. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179450. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179451. if (millisElapsed > 80)
  179452. {
  179453. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179454. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179455. return newResult;
  179456. lastResult = newResult;
  179457. }
  179458. }
  179459. }
  179460. bool Time::setSystemTimeToThisTime() const throw()
  179461. {
  179462. SYSTEMTIME st;
  179463. st.wDayOfWeek = 0;
  179464. st.wYear = (WORD) getYear();
  179465. st.wMonth = (WORD) (getMonth() + 1);
  179466. st.wDay = (WORD) getDayOfMonth();
  179467. st.wHour = (WORD) getHours();
  179468. st.wMinute = (WORD) getMinutes();
  179469. st.wSecond = (WORD) getSeconds();
  179470. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179471. // do this twice because of daylight saving conversion problems - the
  179472. // first one sets it up, the second one kicks it in.
  179473. return SetLocalTime (&st) != 0
  179474. && SetLocalTime (&st) != 0;
  179475. }
  179476. int SystemStats::getPageSize() throw()
  179477. {
  179478. SYSTEM_INFO systemInfo;
  179479. GetSystemInfo (&systemInfo);
  179480. return systemInfo.dwPageSize;
  179481. }
  179482. const String SystemStats::getLogonName()
  179483. {
  179484. TCHAR text [256];
  179485. DWORD len = numElementsInArray (text) - 2;
  179486. zerostruct (text);
  179487. GetUserName (text, &len);
  179488. return String (text, len);
  179489. }
  179490. const String SystemStats::getFullUserName()
  179491. {
  179492. return getLogonName();
  179493. }
  179494. #endif
  179495. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179496. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179497. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179498. // compiled on its own).
  179499. #if JUCE_INCLUDED_FILE
  179500. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179501. extern HWND juce_messageWindowHandle;
  179502. #endif
  179503. #if ! JUCE_USE_INTRINSICS
  179504. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179505. // older ones we have to actually call the ops as win32 functions..
  179506. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179507. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179508. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179509. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179510. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179511. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179512. #endif
  179513. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179514. CriticalSection::CriticalSection() throw()
  179515. {
  179516. // (just to check the MS haven't changed this structure and broken things...)
  179517. #if _MSC_VER >= 1400
  179518. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179519. #else
  179520. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179521. #endif
  179522. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179523. }
  179524. CriticalSection::~CriticalSection() throw()
  179525. {
  179526. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179527. }
  179528. void CriticalSection::enter() const throw()
  179529. {
  179530. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179531. }
  179532. bool CriticalSection::tryEnter() const throw()
  179533. {
  179534. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179535. }
  179536. void CriticalSection::exit() const throw()
  179537. {
  179538. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179539. }
  179540. WaitableEvent::WaitableEvent() throw()
  179541. : internal (CreateEvent (0, FALSE, FALSE, 0))
  179542. {
  179543. }
  179544. WaitableEvent::~WaitableEvent() throw()
  179545. {
  179546. CloseHandle (internal);
  179547. }
  179548. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  179549. {
  179550. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  179551. }
  179552. void WaitableEvent::signal() const throw()
  179553. {
  179554. SetEvent (internal);
  179555. }
  179556. void WaitableEvent::reset() const throw()
  179557. {
  179558. ResetEvent (internal);
  179559. }
  179560. void JUCE_API juce_threadEntryPoint (void*);
  179561. static unsigned int __stdcall threadEntryProc (void* userData)
  179562. {
  179563. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179564. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  179565. GetCurrentThreadId(), TRUE);
  179566. #endif
  179567. juce_threadEntryPoint (userData);
  179568. _endthreadex (0);
  179569. return 0;
  179570. }
  179571. void juce_CloseThreadHandle (void* handle)
  179572. {
  179573. CloseHandle ((HANDLE) handle);
  179574. }
  179575. void* juce_createThread (void* userData)
  179576. {
  179577. unsigned int threadId;
  179578. return (void*) _beginthreadex (0, 0,
  179579. &threadEntryProc,
  179580. userData,
  179581. 0, &threadId);
  179582. }
  179583. void juce_killThread (void* handle)
  179584. {
  179585. if (handle != 0)
  179586. {
  179587. #ifdef JUCE_DEBUG
  179588. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  179589. #endif
  179590. TerminateThread (handle, 0);
  179591. }
  179592. }
  179593. void juce_setCurrentThreadName (const String& name)
  179594. {
  179595. #if defined (JUCE_DEBUG) && JUCE_MSVC
  179596. struct
  179597. {
  179598. DWORD dwType;
  179599. LPCSTR szName;
  179600. DWORD dwThreadID;
  179601. DWORD dwFlags;
  179602. } info;
  179603. info.dwType = 0x1000;
  179604. info.szName = name.toCString();
  179605. info.dwThreadID = GetCurrentThreadId();
  179606. info.dwFlags = 0;
  179607. #define MS_VC_EXCEPTION 0x406d1388
  179608. __try
  179609. {
  179610. RaiseException (MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  179611. }
  179612. __except (EXCEPTION_CONTINUE_EXECUTION)
  179613. {}
  179614. #else
  179615. (void) name;
  179616. #endif
  179617. }
  179618. Thread::ThreadID Thread::getCurrentThreadId()
  179619. {
  179620. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  179621. }
  179622. // priority 1 to 10 where 5=normal, 1=low
  179623. bool juce_setThreadPriority (void* threadHandle, int priority)
  179624. {
  179625. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  179626. if (priority < 1)
  179627. pri = THREAD_PRIORITY_IDLE;
  179628. else if (priority < 2)
  179629. pri = THREAD_PRIORITY_LOWEST;
  179630. else if (priority < 5)
  179631. pri = THREAD_PRIORITY_BELOW_NORMAL;
  179632. else if (priority < 7)
  179633. pri = THREAD_PRIORITY_NORMAL;
  179634. else if (priority < 9)
  179635. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  179636. else if (priority < 10)
  179637. pri = THREAD_PRIORITY_HIGHEST;
  179638. if (threadHandle == 0)
  179639. threadHandle = GetCurrentThread();
  179640. return SetThreadPriority (threadHandle, pri) != FALSE;
  179641. }
  179642. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  179643. {
  179644. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  179645. }
  179646. static HANDLE sleepEvent = 0;
  179647. void juce_initialiseThreadEvents()
  179648. {
  179649. if (sleepEvent == 0)
  179650. #ifdef JUCE_DEBUG
  179651. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  179652. #else
  179653. sleepEvent = CreateEvent (0, 0, 0, 0);
  179654. #endif
  179655. }
  179656. void Thread::yield()
  179657. {
  179658. Sleep (0);
  179659. }
  179660. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  179661. {
  179662. if (millisecs >= 10)
  179663. {
  179664. Sleep (millisecs);
  179665. }
  179666. else
  179667. {
  179668. jassert (sleepEvent != 0);
  179669. // unlike Sleep() this is guaranteed to return to the current thread after
  179670. // the time expires, so we'll use this for short waits, which are more likely
  179671. // to need to be accurate
  179672. WaitForSingleObject (sleepEvent, millisecs);
  179673. }
  179674. }
  179675. static int lastProcessPriority = -1;
  179676. // called by WindowDriver because Windows does wierd things to process priority
  179677. // when you swap apps, and this forces an update when the app is brought to the front.
  179678. void juce_repeatLastProcessPriority()
  179679. {
  179680. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  179681. {
  179682. DWORD p;
  179683. switch (lastProcessPriority)
  179684. {
  179685. case Process::LowPriority:
  179686. p = IDLE_PRIORITY_CLASS;
  179687. break;
  179688. case Process::NormalPriority:
  179689. p = NORMAL_PRIORITY_CLASS;
  179690. break;
  179691. case Process::HighPriority:
  179692. p = HIGH_PRIORITY_CLASS;
  179693. break;
  179694. case Process::RealtimePriority:
  179695. p = REALTIME_PRIORITY_CLASS;
  179696. break;
  179697. default:
  179698. jassertfalse // bad priority value
  179699. return;
  179700. }
  179701. SetPriorityClass (GetCurrentProcess(), p);
  179702. }
  179703. }
  179704. void Process::setPriority (ProcessPriority prior)
  179705. {
  179706. if (lastProcessPriority != (int) prior)
  179707. {
  179708. lastProcessPriority = (int) prior;
  179709. juce_repeatLastProcessPriority();
  179710. }
  179711. }
  179712. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  179713. {
  179714. return IsDebuggerPresent() != FALSE;
  179715. }
  179716. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  179717. {
  179718. return juce_isRunningUnderDebugger();
  179719. }
  179720. void Process::raisePrivilege()
  179721. {
  179722. jassertfalse // xxx not implemented
  179723. }
  179724. void Process::lowerPrivilege()
  179725. {
  179726. jassertfalse // xxx not implemented
  179727. }
  179728. void Process::terminate()
  179729. {
  179730. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179731. _CrtDumpMemoryLeaks();
  179732. #endif
  179733. // bullet in the head in case there's a problem shutting down..
  179734. ExitProcess (0);
  179735. }
  179736. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  179737. {
  179738. void* result = 0;
  179739. JUCE_TRY
  179740. {
  179741. result = (void*) LoadLibrary (name);
  179742. }
  179743. JUCE_CATCH_ALL
  179744. return result;
  179745. }
  179746. void PlatformUtilities::freeDynamicLibrary (void* h)
  179747. {
  179748. JUCE_TRY
  179749. {
  179750. if (h != 0)
  179751. FreeLibrary ((HMODULE) h);
  179752. }
  179753. JUCE_CATCH_ALL
  179754. }
  179755. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  179756. {
  179757. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name.toCString()) : 0;
  179758. }
  179759. InterProcessLock::InterProcessLock (const String& name_)
  179760. : internal (0),
  179761. name (name_),
  179762. reentrancyLevel (0)
  179763. {
  179764. }
  179765. InterProcessLock::~InterProcessLock()
  179766. {
  179767. exit();
  179768. }
  179769. bool InterProcessLock::enter (const int timeOutMillisecs)
  179770. {
  179771. if (reentrancyLevel++ == 0)
  179772. {
  179773. internal = CreateMutex (0, TRUE, "Global\\" + name);
  179774. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  179775. {
  179776. if (timeOutMillisecs == 0
  179777. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  179778. == WAIT_TIMEOUT)
  179779. {
  179780. ReleaseMutex (internal);
  179781. CloseHandle (internal);
  179782. internal = 0;
  179783. }
  179784. }
  179785. }
  179786. return (internal != 0);
  179787. }
  179788. void InterProcessLock::exit()
  179789. {
  179790. if (--reentrancyLevel == 0 && internal != 0)
  179791. {
  179792. ReleaseMutex (internal);
  179793. CloseHandle (internal);
  179794. internal = 0;
  179795. }
  179796. }
  179797. #endif
  179798. /*** End of inlined file: juce_win32_Threads.cpp ***/
  179799. /*** Start of inlined file: juce_win32_Files.cpp ***/
  179800. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179801. // compiled on its own).
  179802. #if JUCE_INCLUDED_FILE
  179803. #ifndef CSIDL_MYMUSIC
  179804. #define CSIDL_MYMUSIC 0x000d
  179805. #endif
  179806. #ifndef CSIDL_MYVIDEO
  179807. #define CSIDL_MYVIDEO 0x000e
  179808. #endif
  179809. const tchar File::separator = T('\\');
  179810. const tchar* File::separatorString = T("\\");
  179811. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  179812. {
  179813. if (fileName.isEmpty())
  179814. return false;
  179815. const DWORD attr = GetFileAttributes (fileName);
  179816. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  179817. : (attr != 0xffffffff);
  179818. }
  179819. bool juce_isDirectory (const String& fileName)
  179820. {
  179821. const DWORD attr = GetFileAttributes (fileName);
  179822. return (attr != 0xffffffff)
  179823. && ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0);
  179824. }
  179825. bool juce_canWriteToFile (const String& fileName)
  179826. {
  179827. const DWORD attr = GetFileAttributes (fileName);
  179828. return ((attr & FILE_ATTRIBUTE_READONLY) == 0);
  179829. }
  179830. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  179831. {
  179832. DWORD attr = GetFileAttributes (fileName);
  179833. if (attr == 0xffffffff)
  179834. return false;
  179835. if (isReadOnly != juce_canWriteToFile (fileName))
  179836. return true;
  179837. if (isReadOnly)
  179838. attr |= FILE_ATTRIBUTE_READONLY;
  179839. else
  179840. attr &= ~FILE_ATTRIBUTE_READONLY;
  179841. return SetFileAttributes (fileName, attr) != FALSE;
  179842. }
  179843. bool File::isHidden() const
  179844. {
  179845. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  179846. }
  179847. bool juce_deleteFile (const String& fileName)
  179848. {
  179849. if (juce_isDirectory (fileName))
  179850. return RemoveDirectory (fileName) != 0;
  179851. return DeleteFile (fileName) != 0;
  179852. }
  179853. bool File::moveToTrash() const
  179854. {
  179855. if (! exists())
  179856. return true;
  179857. SHFILEOPSTRUCT fos;
  179858. zerostruct (fos);
  179859. // The string we pass in must be double null terminated..
  179860. String doubleNullTermPath (getFullPathName() + " ");
  179861. TCHAR* p = (TCHAR*) (const TCHAR*) doubleNullTermPath;
  179862. p [getFullPathName().length()] = 0;
  179863. fos.wFunc = FO_DELETE;
  179864. fos.hwnd = (HWND) 0;
  179865. fos.pFrom = p;
  179866. fos.pTo = NULL;
  179867. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  179868. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  179869. return SHFileOperation (&fos) == 0;
  179870. }
  179871. bool juce_moveFile (const String& source, const String& dest)
  179872. {
  179873. return MoveFile (source, dest) != 0;
  179874. }
  179875. bool juce_copyFile (const String& source, const String& dest)
  179876. {
  179877. return CopyFile (source, dest, false) != 0;
  179878. }
  179879. void juce_createDirectory (const String& fileName)
  179880. {
  179881. if (! juce_fileExists (fileName, true))
  179882. {
  179883. CreateDirectory (fileName, 0);
  179884. }
  179885. }
  179886. // return 0 if not possible
  179887. void* juce_fileOpen (const String& fileName, bool forWriting)
  179888. {
  179889. HANDLE h;
  179890. if (forWriting)
  179891. {
  179892. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  179893. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  179894. if (h != INVALID_HANDLE_VALUE)
  179895. SetFilePointer (h, 0, 0, FILE_END);
  179896. else
  179897. h = 0;
  179898. }
  179899. else
  179900. {
  179901. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  179902. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  179903. if (h == INVALID_HANDLE_VALUE)
  179904. h = 0;
  179905. }
  179906. return (void*) h;
  179907. }
  179908. void juce_fileClose (void* handle)
  179909. {
  179910. CloseHandle (handle);
  179911. }
  179912. int juce_fileRead (void* handle, void* buffer, int size)
  179913. {
  179914. DWORD num = 0;
  179915. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  179916. return num;
  179917. }
  179918. int juce_fileWrite (void* handle, const void* buffer, int size)
  179919. {
  179920. DWORD num;
  179921. WriteFile ((HANDLE) handle,
  179922. buffer, size,
  179923. &num, 0);
  179924. return num;
  179925. }
  179926. int64 juce_fileSetPosition (void* handle, int64 pos)
  179927. {
  179928. LARGE_INTEGER li;
  179929. li.QuadPart = pos;
  179930. li.LowPart = SetFilePointer ((HANDLE) handle,
  179931. li.LowPart,
  179932. &li.HighPart,
  179933. FILE_BEGIN); // (returns -1 if it fails)
  179934. return li.QuadPart;
  179935. }
  179936. int64 juce_fileGetPosition (void* handle)
  179937. {
  179938. LARGE_INTEGER li;
  179939. li.QuadPart = 0;
  179940. li.LowPart = SetFilePointer ((HANDLE) handle,
  179941. 0, &li.HighPart,
  179942. FILE_CURRENT); // (returns -1 if it fails)
  179943. return jmax ((int64) 0, li.QuadPart);
  179944. }
  179945. void juce_fileFlush (void* handle)
  179946. {
  179947. FlushFileBuffers ((HANDLE) handle);
  179948. }
  179949. int64 juce_getFileSize (const String& fileName)
  179950. {
  179951. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179952. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  179953. {
  179954. return (((int64) attributes.nFileSizeHigh) << 32)
  179955. | attributes.nFileSizeLow;
  179956. }
  179957. return 0;
  179958. }
  179959. static int64 fileTimeToTime (const FILETIME* const ft)
  179960. {
  179961. // tell me if this fails!
  179962. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME));
  179963. #if JUCE_GCC
  179964. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000LL) / 10000;
  179965. #else
  179966. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000) / 10000;
  179967. #endif
  179968. }
  179969. static void timeToFileTime (const int64 time, FILETIME* const ft)
  179970. {
  179971. #if JUCE_GCC
  179972. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000LL;
  179973. #else
  179974. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000;
  179975. #endif
  179976. }
  179977. void juce_getFileTimes (const String& fileName,
  179978. int64& modificationTime,
  179979. int64& accessTime,
  179980. int64& creationTime)
  179981. {
  179982. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179983. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  179984. {
  179985. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  179986. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  179987. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  179988. }
  179989. else
  179990. {
  179991. creationTime = accessTime = modificationTime = 0;
  179992. }
  179993. }
  179994. bool juce_setFileTimes (const String& fileName,
  179995. int64 modificationTime,
  179996. int64 accessTime,
  179997. int64 creationTime)
  179998. {
  179999. FILETIME m, a, c;
  180000. if (modificationTime > 0)
  180001. timeToFileTime (modificationTime, &m);
  180002. if (accessTime > 0)
  180003. timeToFileTime (accessTime, &a);
  180004. if (creationTime > 0)
  180005. timeToFileTime (creationTime, &c);
  180006. void* const h = juce_fileOpen (fileName, true);
  180007. bool ok = false;
  180008. if (h != 0)
  180009. {
  180010. ok = SetFileTime ((HANDLE) h,
  180011. (creationTime > 0) ? &c : 0,
  180012. (accessTime > 0) ? &a : 0,
  180013. (modificationTime > 0) ? &m : 0) != 0;
  180014. juce_fileClose (h);
  180015. }
  180016. return ok;
  180017. }
  180018. // return '\0' separated list of strings
  180019. const StringArray juce_getFileSystemRoots()
  180020. {
  180021. TCHAR buffer [2048];
  180022. buffer[0] = 0;
  180023. buffer[1] = 0;
  180024. GetLogicalDriveStrings (2048, buffer);
  180025. TCHAR* n = buffer;
  180026. StringArray roots;
  180027. while (*n != 0)
  180028. {
  180029. roots.add (String (n));
  180030. while (*n++ != 0)
  180031. {
  180032. }
  180033. }
  180034. roots.sort (true);
  180035. return roots;
  180036. }
  180037. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180038. int& volumeSerialNumber)
  180039. {
  180040. TCHAR n [4];
  180041. n[0] = *(const TCHAR*) filenameOnVolume;
  180042. n[1] = L':';
  180043. n[2] = L'\\';
  180044. n[3] = 0;
  180045. TCHAR dest [64];
  180046. DWORD serialNum;
  180047. if (! GetVolumeInformation (n, dest, 64, (DWORD*) &serialNum, 0, 0, 0, 0))
  180048. {
  180049. dest[0] = 0;
  180050. serialNum = 0;
  180051. }
  180052. volumeSerialNumber = serialNum;
  180053. return String (dest);
  180054. }
  180055. static int64 getDiskSpaceInfo (String fn, const bool total)
  180056. {
  180057. if (fn[1] == T(':'))
  180058. fn = fn.substring (0, 2) + T("\\");
  180059. ULARGE_INTEGER spc, tot, totFree;
  180060. if (GetDiskFreeSpaceEx (fn, &spc, &tot, &totFree))
  180061. return (int64) (total ? tot.QuadPart
  180062. : spc.QuadPart);
  180063. return 0;
  180064. }
  180065. int64 File::getBytesFreeOnVolume() const
  180066. {
  180067. return getDiskSpaceInfo (getFullPathName(), false);
  180068. }
  180069. int64 File::getVolumeTotalSize() const
  180070. {
  180071. return getDiskSpaceInfo (getFullPathName(), true);
  180072. }
  180073. static unsigned int getWindowsDriveType (const String& fileName)
  180074. {
  180075. TCHAR n[4];
  180076. n[0] = *(const TCHAR*) fileName;
  180077. n[1] = L':';
  180078. n[2] = L'\\';
  180079. n[3] = 0;
  180080. return GetDriveType (n);
  180081. }
  180082. bool File::isOnCDRomDrive() const
  180083. {
  180084. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180085. }
  180086. bool File::isOnHardDisk() const
  180087. {
  180088. if (fullPath.isEmpty())
  180089. return false;
  180090. const unsigned int n = getWindowsDriveType (getFullPathName());
  180091. if (fullPath.toLowerCase()[0] <= 'b'
  180092. && fullPath[1] == T(':'))
  180093. {
  180094. return n != DRIVE_REMOVABLE;
  180095. }
  180096. else
  180097. {
  180098. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180099. }
  180100. }
  180101. bool File::isOnRemovableDrive() const
  180102. {
  180103. if (fullPath.isEmpty())
  180104. return false;
  180105. const unsigned int n = getWindowsDriveType (getFullPathName());
  180106. return n == DRIVE_CDROM
  180107. || n == DRIVE_REMOTE
  180108. || n == DRIVE_REMOVABLE
  180109. || n == DRIVE_RAMDISK;
  180110. }
  180111. static const File juce_getSpecialFolderPath (int type)
  180112. {
  180113. WCHAR path [MAX_PATH + 256];
  180114. if (SHGetSpecialFolderPath (0, path, type, 0))
  180115. return File (String (path));
  180116. return File::nonexistent;
  180117. }
  180118. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180119. {
  180120. int csidlType = 0;
  180121. switch (type)
  180122. {
  180123. case userHomeDirectory:
  180124. csidlType = CSIDL_PROFILE;
  180125. break;
  180126. case userDocumentsDirectory:
  180127. csidlType = CSIDL_PERSONAL;
  180128. break;
  180129. case userDesktopDirectory:
  180130. csidlType = CSIDL_DESKTOP;
  180131. break;
  180132. case userApplicationDataDirectory:
  180133. csidlType = CSIDL_APPDATA;
  180134. break;
  180135. case commonApplicationDataDirectory:
  180136. csidlType = CSIDL_COMMON_APPDATA;
  180137. break;
  180138. case globalApplicationsDirectory:
  180139. csidlType = CSIDL_PROGRAM_FILES;
  180140. break;
  180141. case userMusicDirectory:
  180142. csidlType = CSIDL_MYMUSIC;
  180143. break;
  180144. case userMoviesDirectory:
  180145. csidlType = CSIDL_MYVIDEO;
  180146. break;
  180147. case tempDirectory:
  180148. {
  180149. WCHAR dest [2048];
  180150. dest[0] = 0;
  180151. GetTempPath (2048, dest);
  180152. return File (String (dest));
  180153. }
  180154. case invokedExecutableFile:
  180155. case currentExecutableFile:
  180156. case currentApplicationFile:
  180157. {
  180158. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180159. WCHAR dest [MAX_PATH + 256];
  180160. dest[0] = 0;
  180161. GetModuleFileName (moduleHandle, dest, numElementsInArray (dest));
  180162. return File (String (dest));
  180163. }
  180164. break;
  180165. default:
  180166. jassertfalse // unknown type?
  180167. return File::nonexistent;
  180168. }
  180169. return juce_getSpecialFolderPath (csidlType);
  180170. }
  180171. const File File::getCurrentWorkingDirectory()
  180172. {
  180173. WCHAR dest [MAX_PATH + 256];
  180174. dest[0] = 0;
  180175. GetCurrentDirectory (numElementsInArray (dest), dest);
  180176. return File (String (dest));
  180177. }
  180178. bool File::setAsCurrentWorkingDirectory() const
  180179. {
  180180. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180181. }
  180182. const String File::getVersion() const
  180183. {
  180184. String result;
  180185. DWORD handle = 0;
  180186. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180187. HeapBlock <char> buffer;
  180188. buffer.calloc (bufferSize);
  180189. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180190. {
  180191. VS_FIXEDFILEINFO* vffi;
  180192. UINT len = 0;
  180193. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180194. {
  180195. result << (int) HIWORD (vffi->dwFileVersionMS) << "."
  180196. << (int) LOWORD (vffi->dwFileVersionMS) << "."
  180197. << (int) HIWORD (vffi->dwFileVersionLS) << "."
  180198. << (int) LOWORD (vffi->dwFileVersionLS);
  180199. }
  180200. }
  180201. return result;
  180202. }
  180203. const File File::getLinkedTarget() const
  180204. {
  180205. File result (*this);
  180206. String p (getFullPathName());
  180207. if (! exists())
  180208. p += T(".lnk");
  180209. else if (getFileExtension() != T(".lnk"))
  180210. return result;
  180211. ComSmartPtr <IShellLink> shellLink;
  180212. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180213. {
  180214. ComSmartPtr <IPersistFile> persistFile;
  180215. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180216. {
  180217. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180218. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180219. {
  180220. WIN32_FIND_DATA winFindData;
  180221. WCHAR resolvedPath [MAX_PATH];
  180222. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180223. result = File (resolvedPath);
  180224. }
  180225. }
  180226. }
  180227. return result;
  180228. }
  180229. template <class FindDataType>
  180230. static void getFindFileInfo (FindDataType& findData,
  180231. String& filename, bool* const isDir, bool* const isHidden,
  180232. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180233. bool* const isReadOnly)
  180234. {
  180235. filename = findData.cFileName;
  180236. if (isDir != 0)
  180237. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180238. if (isHidden != 0)
  180239. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180240. if (fileSize != 0)
  180241. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180242. if (modTime != 0)
  180243. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180244. if (creationTime != 0)
  180245. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180246. if (isReadOnly != 0)
  180247. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180248. }
  180249. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180250. bool* isDir, bool* isHidden, int64* fileSize,
  180251. Time* modTime, Time* creationTime, bool* isReadOnly)
  180252. {
  180253. String wc (directory);
  180254. if (! wc.endsWithChar (File::separator))
  180255. wc += File::separator;
  180256. wc += wildCard;
  180257. WIN32_FIND_DATA findData;
  180258. HANDLE h = FindFirstFile (wc, &findData);
  180259. if (h != INVALID_HANDLE_VALUE)
  180260. {
  180261. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180262. modTime, creationTime, isReadOnly);
  180263. return h;
  180264. }
  180265. firstResult = String::empty;
  180266. return 0;
  180267. }
  180268. bool juce_findFileNext (void* handle, String& resultFile,
  180269. bool* isDir, bool* isHidden, int64* fileSize,
  180270. Time* modTime, Time* creationTime, bool* isReadOnly)
  180271. {
  180272. WIN32_FIND_DATA findData;
  180273. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180274. {
  180275. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180276. modTime, creationTime, isReadOnly);
  180277. return true;
  180278. }
  180279. resultFile = String::empty;
  180280. return false;
  180281. }
  180282. void juce_findFileClose (void* handle)
  180283. {
  180284. FindClose (handle);
  180285. }
  180286. bool juce_launchFile (const String& fileName,
  180287. const String& parameters)
  180288. {
  180289. HINSTANCE hInstance = 0;
  180290. JUCE_TRY
  180291. {
  180292. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180293. }
  180294. JUCE_CATCH_ALL
  180295. return hInstance > (HINSTANCE) 32;
  180296. }
  180297. void File::revealToUser() const
  180298. {
  180299. if (isDirectory())
  180300. startAsProcess();
  180301. else if (getParentDirectory().exists())
  180302. getParentDirectory().startAsProcess();
  180303. }
  180304. class NamedPipeInternal
  180305. {
  180306. public:
  180307. NamedPipeInternal (const String& file, const bool isPipe_)
  180308. : pipeH (0),
  180309. cancelEvent (0),
  180310. connected (false),
  180311. isPipe (isPipe_)
  180312. {
  180313. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180314. pipeH = isPipe ? CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180315. PIPE_UNLIMITED_INSTANCES, 4096, 4096, 0, 0)
  180316. : CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0,
  180317. OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
  180318. }
  180319. ~NamedPipeInternal()
  180320. {
  180321. disconnectPipe();
  180322. if (pipeH != 0)
  180323. CloseHandle (pipeH);
  180324. CloseHandle (cancelEvent);
  180325. }
  180326. bool connect (const int timeOutMs)
  180327. {
  180328. if (! isPipe)
  180329. return true;
  180330. if (! connected)
  180331. {
  180332. OVERLAPPED over;
  180333. zerostruct (over);
  180334. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180335. if (ConnectNamedPipe (pipeH, &over))
  180336. {
  180337. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180338. }
  180339. else
  180340. {
  180341. const int err = GetLastError();
  180342. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180343. {
  180344. HANDLE handles[] = { over.hEvent, cancelEvent };
  180345. if (WaitForMultipleObjects (2, handles, FALSE,
  180346. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180347. connected = true;
  180348. }
  180349. else if (err == ERROR_PIPE_CONNECTED)
  180350. {
  180351. connected = true;
  180352. }
  180353. }
  180354. CloseHandle (over.hEvent);
  180355. }
  180356. return connected;
  180357. }
  180358. void disconnectPipe()
  180359. {
  180360. if (connected)
  180361. {
  180362. DisconnectNamedPipe (pipeH);
  180363. connected = false;
  180364. }
  180365. }
  180366. HANDLE pipeH;
  180367. HANDLE cancelEvent;
  180368. bool connected, isPipe;
  180369. };
  180370. void NamedPipe::close()
  180371. {
  180372. cancelPendingReads();
  180373. const ScopedLock sl (lock);
  180374. delete static_cast<NamedPipeInternal*> (internal);
  180375. internal = 0;
  180376. }
  180377. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180378. {
  180379. close();
  180380. ScopedPointer<NamedPipeInternal> intern (new NamedPipeInternal ("\\\\.\\pipe\\" + pipeName, createPipe));
  180381. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180382. {
  180383. internal = intern.release();
  180384. return true;
  180385. }
  180386. return false;
  180387. }
  180388. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180389. {
  180390. const ScopedLock sl (lock);
  180391. int bytesRead = -1;
  180392. bool waitAgain = true;
  180393. while (waitAgain && internal != 0)
  180394. {
  180395. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180396. waitAgain = false;
  180397. if (! intern->connect (timeOutMilliseconds))
  180398. break;
  180399. if (maxBytesToRead <= 0)
  180400. return 0;
  180401. OVERLAPPED over;
  180402. zerostruct (over);
  180403. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180404. unsigned long numRead;
  180405. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180406. {
  180407. bytesRead = (int) numRead;
  180408. }
  180409. else if (GetLastError() == ERROR_IO_PENDING)
  180410. {
  180411. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180412. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180413. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180414. : INFINITE);
  180415. if (waitResult != WAIT_OBJECT_0)
  180416. {
  180417. // if the operation timed out, let's cancel it...
  180418. CancelIo (intern->pipeH);
  180419. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180420. }
  180421. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180422. {
  180423. bytesRead = (int) numRead;
  180424. }
  180425. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180426. {
  180427. intern->disconnectPipe();
  180428. waitAgain = true;
  180429. }
  180430. }
  180431. else
  180432. {
  180433. waitAgain = internal != 0;
  180434. Sleep (5);
  180435. }
  180436. CloseHandle (over.hEvent);
  180437. }
  180438. return bytesRead;
  180439. }
  180440. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180441. {
  180442. int bytesWritten = -1;
  180443. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180444. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180445. {
  180446. if (numBytesToWrite <= 0)
  180447. return 0;
  180448. OVERLAPPED over;
  180449. zerostruct (over);
  180450. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180451. unsigned long numWritten;
  180452. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180453. {
  180454. bytesWritten = (int) numWritten;
  180455. }
  180456. else if (GetLastError() == ERROR_IO_PENDING)
  180457. {
  180458. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180459. DWORD waitResult;
  180460. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180461. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180462. : INFINITE);
  180463. if (waitResult != WAIT_OBJECT_0)
  180464. {
  180465. CancelIo (intern->pipeH);
  180466. WaitForSingleObject (over.hEvent, INFINITE);
  180467. }
  180468. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180469. {
  180470. bytesWritten = (int) numWritten;
  180471. }
  180472. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180473. {
  180474. intern->disconnectPipe();
  180475. }
  180476. }
  180477. CloseHandle (over.hEvent);
  180478. }
  180479. return bytesWritten;
  180480. }
  180481. void NamedPipe::cancelPendingReads()
  180482. {
  180483. if (internal != 0)
  180484. SetEvent (static_cast<NamedPipeInternal*> (internal)->cancelEvent);
  180485. }
  180486. #endif
  180487. /*** End of inlined file: juce_win32_Files.cpp ***/
  180488. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180489. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180490. // compiled on its own).
  180491. #if JUCE_INCLUDED_FILE
  180492. #ifndef INTERNET_FLAG_NEED_FILE
  180493. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180494. #endif
  180495. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180496. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180497. #endif
  180498. bool juce_isOnLine()
  180499. {
  180500. DWORD connectionType;
  180501. return InternetGetConnectedState (&connectionType, 0) != 0
  180502. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180503. }
  180504. struct ConnectionAndRequestStruct
  180505. {
  180506. HINTERNET connection, request;
  180507. };
  180508. static HINTERNET sessionHandle = 0;
  180509. #ifndef WORKAROUND_TIMEOUT_BUG
  180510. //#define WORKAROUND_TIMEOUT_BUG 1
  180511. #endif
  180512. #if WORKAROUND_TIMEOUT_BUG
  180513. // Required because of a Microsoft bug in setting a timeout
  180514. class InternetConnectThread : public Thread
  180515. {
  180516. public:
  180517. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180518. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180519. {
  180520. startThread();
  180521. }
  180522. ~InternetConnectThread()
  180523. {
  180524. stopThread (60000);
  180525. }
  180526. void run()
  180527. {
  180528. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180529. uc.nPort, _T(""), _T(""),
  180530. isFtp ? INTERNET_SERVICE_FTP
  180531. : INTERNET_SERVICE_HTTP,
  180532. 0, 0);
  180533. notify();
  180534. }
  180535. juce_UseDebuggingNewOperator
  180536. private:
  180537. URL_COMPONENTS& uc;
  180538. HINTERNET& connection;
  180539. const bool isFtp;
  180540. InternetConnectThread (const InternetConnectThread&);
  180541. InternetConnectThread& operator= (const InternetConnectThread&);
  180542. };
  180543. #endif
  180544. void* juce_openInternetFile (const String& url,
  180545. const String& headers,
  180546. const MemoryBlock& postData,
  180547. const bool isPost,
  180548. URL::OpenStreamProgressCallback* callback,
  180549. void* callbackContext,
  180550. int timeOutMs)
  180551. {
  180552. if (sessionHandle == 0)
  180553. sessionHandle = InternetOpen (_T("juce"),
  180554. INTERNET_OPEN_TYPE_PRECONFIG,
  180555. 0, 0, 0);
  180556. if (sessionHandle != 0)
  180557. {
  180558. // break up the url..
  180559. TCHAR file[1024], server[1024];
  180560. URL_COMPONENTS uc;
  180561. zerostruct (uc);
  180562. uc.dwStructSize = sizeof (uc);
  180563. uc.dwUrlPathLength = sizeof (file);
  180564. uc.dwHostNameLength = sizeof (server);
  180565. uc.lpszUrlPath = file;
  180566. uc.lpszHostName = server;
  180567. if (InternetCrackUrl (url, 0, 0, &uc))
  180568. {
  180569. int disable = 1;
  180570. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  180571. if (timeOutMs == 0)
  180572. timeOutMs = 30000;
  180573. else if (timeOutMs < 0)
  180574. timeOutMs = -1;
  180575. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  180576. const bool isFtp = url.startsWithIgnoreCase (T("ftp:"));
  180577. #if WORKAROUND_TIMEOUT_BUG
  180578. HINTERNET connection = 0;
  180579. {
  180580. InternetConnectThread connectThread (uc, connection, isFtp);
  180581. connectThread.wait (timeOutMs);
  180582. if (connection == 0)
  180583. {
  180584. InternetCloseHandle (sessionHandle);
  180585. sessionHandle = 0;
  180586. }
  180587. }
  180588. #else
  180589. HINTERNET connection = InternetConnect (sessionHandle,
  180590. uc.lpszHostName,
  180591. uc.nPort,
  180592. _T(""), _T(""),
  180593. isFtp ? INTERNET_SERVICE_FTP
  180594. : INTERNET_SERVICE_HTTP,
  180595. 0, 0);
  180596. #endif
  180597. if (connection != 0)
  180598. {
  180599. if (isFtp)
  180600. {
  180601. HINTERNET request = FtpOpenFile (connection,
  180602. uc.lpszUrlPath,
  180603. GENERIC_READ,
  180604. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  180605. 0);
  180606. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  180607. result->connection = connection;
  180608. result->request = request;
  180609. return result;
  180610. }
  180611. else
  180612. {
  180613. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  180614. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  180615. if (url.startsWithIgnoreCase (T("https:")))
  180616. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  180617. // IE7 seems to automatically work out when it's https)
  180618. HINTERNET request = HttpOpenRequest (connection,
  180619. isPost ? _T("POST")
  180620. : _T("GET"),
  180621. uc.lpszUrlPath,
  180622. 0, 0, mimeTypes, flags, 0);
  180623. if (request != 0)
  180624. {
  180625. INTERNET_BUFFERS buffers;
  180626. zerostruct (buffers);
  180627. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  180628. buffers.lpcszHeader = (LPCTSTR) headers;
  180629. buffers.dwHeadersLength = headers.length();
  180630. buffers.dwBufferTotal = (DWORD) postData.getSize();
  180631. ConnectionAndRequestStruct* result = 0;
  180632. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  180633. {
  180634. int bytesSent = 0;
  180635. for (;;)
  180636. {
  180637. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  180638. DWORD bytesDone = 0;
  180639. if (bytesToDo > 0
  180640. && ! InternetWriteFile (request,
  180641. ((const char*) postData.getData()) + bytesSent,
  180642. bytesToDo, &bytesDone))
  180643. {
  180644. break;
  180645. }
  180646. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  180647. {
  180648. result = new ConnectionAndRequestStruct();
  180649. result->connection = connection;
  180650. result->request = request;
  180651. HttpEndRequest (request, 0, 0, 0);
  180652. return result;
  180653. }
  180654. bytesSent += bytesDone;
  180655. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  180656. break;
  180657. }
  180658. }
  180659. InternetCloseHandle (request);
  180660. }
  180661. InternetCloseHandle (connection);
  180662. }
  180663. }
  180664. }
  180665. }
  180666. return 0;
  180667. }
  180668. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  180669. {
  180670. DWORD bytesRead = 0;
  180671. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180672. if (crs != 0)
  180673. InternetReadFile (crs->request,
  180674. buffer, bytesToRead,
  180675. &bytesRead);
  180676. return bytesRead;
  180677. }
  180678. int juce_seekInInternetFile (void* handle, int newPosition)
  180679. {
  180680. if (handle != 0)
  180681. {
  180682. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180683. return InternetSetFilePointer (crs->request,
  180684. newPosition, 0,
  180685. FILE_BEGIN, 0);
  180686. }
  180687. else
  180688. {
  180689. return -1;
  180690. }
  180691. }
  180692. int64 juce_getInternetFileContentLength (void* handle)
  180693. {
  180694. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  180695. if (crs != 0)
  180696. {
  180697. DWORD index = 0;
  180698. DWORD result = 0;
  180699. DWORD size = sizeof (result);
  180700. if (HttpQueryInfo (crs->request,
  180701. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  180702. &result,
  180703. &size,
  180704. &index))
  180705. {
  180706. return (int64) result;
  180707. }
  180708. }
  180709. return -1;
  180710. }
  180711. void juce_closeInternetFile (void* handle)
  180712. {
  180713. if (handle != 0)
  180714. {
  180715. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  180716. InternetCloseHandle (crs->request);
  180717. InternetCloseHandle (crs->connection);
  180718. delete crs;
  180719. }
  180720. }
  180721. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  180722. {
  180723. int numFound = 0;
  180724. DynamicLibraryLoader dll ("iphlpapi.dll");
  180725. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  180726. if (getAdaptersInfo != 0)
  180727. {
  180728. ULONG len = sizeof (IP_ADAPTER_INFO);
  180729. MemoryBlock mb;
  180730. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180731. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  180732. {
  180733. mb.setSize (len);
  180734. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180735. }
  180736. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  180737. {
  180738. PIP_ADAPTER_INFO adapter = adapterInfo;
  180739. while (adapter != 0)
  180740. {
  180741. int64 mac = 0;
  180742. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  180743. mac = (mac << 8) | adapter->Address[i];
  180744. if (littleEndian)
  180745. mac = (int64) ByteOrder::swap ((uint64) mac);
  180746. if (numFound < maxNum && mac != 0)
  180747. addresses [numFound++] = mac;
  180748. adapter = adapter->Next;
  180749. }
  180750. }
  180751. }
  180752. return numFound;
  180753. }
  180754. struct ASTAT
  180755. {
  180756. ADAPTER_STATUS adapt;
  180757. NAME_BUFFER NameBuff [30];
  180758. };
  180759. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  180760. {
  180761. int numFound = 0;
  180762. DynamicLibraryLoader dll ("netapi32.dll");
  180763. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  180764. if (NetbiosCall != 0)
  180765. {
  180766. NCB ncb;
  180767. zerostruct (ncb);
  180768. ASTAT astat;
  180769. zerostruct (astat);
  180770. LANA_ENUM enums;
  180771. zerostruct (enums);
  180772. ncb.ncb_command = NCBENUM;
  180773. ncb.ncb_buffer = (unsigned char*) &enums;
  180774. ncb.ncb_length = sizeof (LANA_ENUM);
  180775. NetbiosCall (&ncb);
  180776. for (int i = 0; i < enums.length; ++i)
  180777. {
  180778. zerostruct (ncb);
  180779. ncb.ncb_command = NCBRESET;
  180780. ncb.ncb_lana_num = enums.lana[i];
  180781. if (NetbiosCall (&ncb) == 0)
  180782. {
  180783. zerostruct (ncb);
  180784. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  180785. ncb.ncb_command = NCBASTAT;
  180786. ncb.ncb_lana_num = enums.lana[i];
  180787. ncb.ncb_buffer = (unsigned char*) &astat;
  180788. ncb.ncb_length = sizeof (ASTAT);
  180789. if (NetbiosCall (&ncb) == 0)
  180790. {
  180791. if (astat.adapt.adapter_type == 0xfe)
  180792. {
  180793. uint64 mac = 0;
  180794. for (int i = 6; --i >= 0;)
  180795. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  180796. if (numFound < maxNum && mac != 0)
  180797. addresses [numFound++] = mac;
  180798. }
  180799. }
  180800. }
  180801. }
  180802. }
  180803. return numFound;
  180804. }
  180805. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  180806. {
  180807. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  180808. if (numFound == 0)
  180809. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  180810. return numFound;
  180811. }
  180812. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  180813. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  180814. const String& emailSubject,
  180815. const String& bodyText,
  180816. const StringArray& filesToAttach)
  180817. {
  180818. HMODULE h = LoadLibraryA ("MAPI32.dll");
  180819. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  180820. bool ok = false;
  180821. if (mapiSendMail != 0)
  180822. {
  180823. MapiMessage message;
  180824. zerostruct (message);
  180825. message.lpszSubject = (LPSTR) emailSubject.toCString();
  180826. message.lpszNoteText = (LPSTR) bodyText.toCString();
  180827. MapiRecipDesc recip;
  180828. zerostruct (recip);
  180829. recip.ulRecipClass = MAPI_TO;
  180830. String targetEmailAddress_ (targetEmailAddress);
  180831. if (targetEmailAddress_.isEmpty())
  180832. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  180833. recip.lpszName = (LPSTR) targetEmailAddress_.toCString();
  180834. message.nRecipCount = 1;
  180835. message.lpRecips = &recip;
  180836. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  180837. mb.fillWith (0);
  180838. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  180839. message.nFileCount = filesToAttach.size();
  180840. message.lpFiles = files;
  180841. for (int i = 0; i < filesToAttach.size(); ++i)
  180842. {
  180843. files[i].nPosition = (ULONG) -1;
  180844. files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString();
  180845. }
  180846. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  180847. }
  180848. FreeLibrary (h);
  180849. return ok;
  180850. }
  180851. #endif
  180852. /*** End of inlined file: juce_win32_Network.cpp ***/
  180853. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  180854. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180855. // compiled on its own).
  180856. #if JUCE_INCLUDED_FILE
  180857. static HKEY findKeyForPath (String name,
  180858. const bool createForWriting,
  180859. String& valueName)
  180860. {
  180861. HKEY rootKey = 0;
  180862. if (name.startsWithIgnoreCase (T("HKEY_CURRENT_USER\\")))
  180863. rootKey = HKEY_CURRENT_USER;
  180864. else if (name.startsWithIgnoreCase (T("HKEY_LOCAL_MACHINE\\")))
  180865. rootKey = HKEY_LOCAL_MACHINE;
  180866. else if (name.startsWithIgnoreCase (T("HKEY_CLASSES_ROOT\\")))
  180867. rootKey = HKEY_CLASSES_ROOT;
  180868. if (rootKey != 0)
  180869. {
  180870. name = name.substring (name.indexOfChar (T('\\')) + 1);
  180871. const int lastSlash = name.lastIndexOfChar (T('\\'));
  180872. valueName = name.substring (lastSlash + 1);
  180873. name = name.substring (0, lastSlash);
  180874. HKEY key;
  180875. DWORD result;
  180876. if (createForWriting)
  180877. {
  180878. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  180879. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  180880. return key;
  180881. }
  180882. else
  180883. {
  180884. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  180885. return key;
  180886. }
  180887. }
  180888. return 0;
  180889. }
  180890. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  180891. const String& defaultValue)
  180892. {
  180893. String valueName, result (defaultValue);
  180894. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180895. if (k != 0)
  180896. {
  180897. WCHAR buffer [2048];
  180898. unsigned long bufferSize = sizeof (buffer);
  180899. DWORD type = REG_SZ;
  180900. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  180901. {
  180902. if (type == REG_SZ)
  180903. result = buffer;
  180904. else if (type == REG_DWORD)
  180905. result = String ((int) *(DWORD*) buffer);
  180906. }
  180907. RegCloseKey (k);
  180908. }
  180909. return result;
  180910. }
  180911. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  180912. const String& value)
  180913. {
  180914. String valueName;
  180915. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180916. if (k != 0)
  180917. {
  180918. RegSetValueEx (k, valueName, 0, REG_SZ,
  180919. (const BYTE*) (const WCHAR*) value,
  180920. sizeof (WCHAR) * (value.length() + 1));
  180921. RegCloseKey (k);
  180922. }
  180923. }
  180924. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  180925. {
  180926. bool exists = false;
  180927. String valueName;
  180928. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180929. if (k != 0)
  180930. {
  180931. unsigned char buffer [2048];
  180932. unsigned long bufferSize = sizeof (buffer);
  180933. DWORD type = 0;
  180934. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  180935. exists = true;
  180936. RegCloseKey (k);
  180937. }
  180938. return exists;
  180939. }
  180940. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  180941. {
  180942. String valueName;
  180943. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180944. if (k != 0)
  180945. {
  180946. RegDeleteValue (k, valueName);
  180947. RegCloseKey (k);
  180948. }
  180949. }
  180950. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  180951. {
  180952. String valueName;
  180953. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  180954. if (k != 0)
  180955. {
  180956. RegDeleteKey (k, valueName);
  180957. RegCloseKey (k);
  180958. }
  180959. }
  180960. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  180961. const String& symbolicDescription,
  180962. const String& fullDescription,
  180963. const File& targetExecutable,
  180964. int iconResourceNumber)
  180965. {
  180966. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  180967. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  180968. if (iconResourceNumber != 0)
  180969. setRegistryValue (key + "\\DefaultIcon\\",
  180970. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  180971. setRegistryValue (key + "\\", fullDescription);
  180972. setRegistryValue (key + "\\shell\\open\\command\\",
  180973. targetExecutable.getFullPathName() + " %1");
  180974. }
  180975. bool juce_IsRunningInWine()
  180976. {
  180977. HKEY key;
  180978. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  180979. {
  180980. RegCloseKey (key);
  180981. return true;
  180982. }
  180983. return false;
  180984. }
  180985. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  180986. {
  180987. String s (::GetCommandLineW());
  180988. StringArray tokens;
  180989. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  180990. return tokens.joinIntoString (T(" "), 1);
  180991. }
  180992. static void* currentModuleHandle = 0;
  180993. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  180994. {
  180995. if (currentModuleHandle == 0)
  180996. currentModuleHandle = GetModuleHandle (0);
  180997. return currentModuleHandle;
  180998. }
  180999. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  181000. {
  181001. currentModuleHandle = newHandle;
  181002. }
  181003. void PlatformUtilities::fpuReset()
  181004. {
  181005. #if JUCE_MSVC
  181006. _clearfp();
  181007. #endif
  181008. }
  181009. void PlatformUtilities::beep()
  181010. {
  181011. MessageBeep (MB_OK);
  181012. }
  181013. #endif
  181014. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  181015. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  181016. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  181017. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181018. // compiled on its own).
  181019. #if JUCE_INCLUDED_FILE
  181020. static const unsigned int specialId = WM_APP + 0x4400;
  181021. static const unsigned int broadcastId = WM_APP + 0x4403;
  181022. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  181023. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  181024. HWND juce_messageWindowHandle = 0;
  181025. extern long improbableWindowNumber; // defined in windowing.cpp
  181026. #ifndef WM_APPCOMMAND
  181027. #define WM_APPCOMMAND 0x0319
  181028. #endif
  181029. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  181030. const UINT message,
  181031. const WPARAM wParam,
  181032. const LPARAM lParam) throw()
  181033. {
  181034. JUCE_TRY
  181035. {
  181036. if (h == juce_messageWindowHandle)
  181037. {
  181038. if (message == specialCallbackId)
  181039. {
  181040. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  181041. return (LRESULT) (*func) ((void*) lParam);
  181042. }
  181043. else if (message == specialId)
  181044. {
  181045. // these are trapped early in the dispatch call, but must also be checked
  181046. // here in case there are windows modal dialog boxes doing their own
  181047. // dispatch loop and not calling our version
  181048. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  181049. return 0;
  181050. }
  181051. else if (message == broadcastId)
  181052. {
  181053. const ScopedPointer <String> messageString ((String*) lParam);
  181054. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  181055. return 0;
  181056. }
  181057. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  181058. {
  181059. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  181060. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  181061. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  181062. return 0;
  181063. }
  181064. }
  181065. }
  181066. JUCE_CATCH_EXCEPTION
  181067. return DefWindowProc (h, message, wParam, lParam);
  181068. }
  181069. static bool isEventBlockedByModalComps (MSG& m)
  181070. {
  181071. if (Component::getNumCurrentlyModalComponents() == 0
  181072. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181073. return false;
  181074. switch (m.message)
  181075. {
  181076. case WM_MOUSEMOVE:
  181077. case WM_NCMOUSEMOVE:
  181078. case 0x020A: /* WM_MOUSEWHEEL */
  181079. case 0x020E: /* WM_MOUSEHWHEEL */
  181080. case WM_KEYUP:
  181081. case WM_SYSKEYUP:
  181082. case WM_CHAR:
  181083. case WM_APPCOMMAND:
  181084. case WM_LBUTTONUP:
  181085. case WM_MBUTTONUP:
  181086. case WM_RBUTTONUP:
  181087. case WM_MOUSEACTIVATE:
  181088. case WM_NCMOUSEHOVER:
  181089. case WM_MOUSEHOVER:
  181090. return true;
  181091. case WM_NCLBUTTONDOWN:
  181092. case WM_NCLBUTTONDBLCLK:
  181093. case WM_NCRBUTTONDOWN:
  181094. case WM_NCRBUTTONDBLCLK:
  181095. case WM_NCMBUTTONDOWN:
  181096. case WM_NCMBUTTONDBLCLK:
  181097. case WM_LBUTTONDOWN:
  181098. case WM_LBUTTONDBLCLK:
  181099. case WM_MBUTTONDOWN:
  181100. case WM_MBUTTONDBLCLK:
  181101. case WM_RBUTTONDOWN:
  181102. case WM_RBUTTONDBLCLK:
  181103. case WM_KEYDOWN:
  181104. case WM_SYSKEYDOWN:
  181105. {
  181106. Component* const modal = Component::getCurrentlyModalComponent (0);
  181107. if (modal != 0)
  181108. modal->inputAttemptWhenModal();
  181109. return true;
  181110. }
  181111. default:
  181112. break;
  181113. }
  181114. return false;
  181115. }
  181116. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181117. {
  181118. MSG m;
  181119. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181120. return false;
  181121. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181122. {
  181123. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181124. {
  181125. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181126. }
  181127. else if (m.message == WM_QUIT)
  181128. {
  181129. if (JUCEApplication::getInstance())
  181130. JUCEApplication::getInstance()->systemRequestedQuit();
  181131. }
  181132. else if (! isEventBlockedByModalComps (m))
  181133. {
  181134. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181135. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181136. {
  181137. // if it's someone else's window being clicked on, and the focus is
  181138. // currently on a juce window, pass the kb focus over..
  181139. HWND currentFocus = GetFocus();
  181140. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181141. SetFocus (m.hwnd);
  181142. }
  181143. TranslateMessage (&m);
  181144. DispatchMessage (&m);
  181145. }
  181146. }
  181147. return true;
  181148. }
  181149. bool juce_postMessageToSystemQueue (void* message)
  181150. {
  181151. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181152. }
  181153. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181154. void* userData)
  181155. {
  181156. if (MessageManager::getInstance()->isThisTheMessageThread())
  181157. {
  181158. return (*callback) (userData);
  181159. }
  181160. else
  181161. {
  181162. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181163. // deadlock because the message manager is blocked from running, and can't
  181164. // call your function..
  181165. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181166. return (void*) SendMessage (juce_messageWindowHandle,
  181167. specialCallbackId,
  181168. (WPARAM) callback,
  181169. (LPARAM) userData);
  181170. }
  181171. }
  181172. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181173. {
  181174. if (hwnd != juce_messageWindowHandle)
  181175. (reinterpret_cast <VoidArray*> (lParam))->add ((void*) hwnd);
  181176. return TRUE;
  181177. }
  181178. void MessageManager::broadcastMessage (const String& value) throw()
  181179. {
  181180. VoidArray windows;
  181181. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181182. const String localCopy (value);
  181183. COPYDATASTRUCT data;
  181184. data.dwData = broadcastId;
  181185. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181186. data.lpData = (void*) (const juce_wchar*) localCopy;
  181187. for (int i = windows.size(); --i >= 0;)
  181188. {
  181189. HWND hwnd = (HWND) windows.getUnchecked(i);
  181190. TCHAR windowName [64]; // no need to read longer strings than this
  181191. GetWindowText (hwnd, windowName, 64);
  181192. windowName [63] = 0;
  181193. if (String (windowName) == String (messageWindowName))
  181194. {
  181195. DWORD_PTR result;
  181196. SendMessageTimeout (hwnd, WM_COPYDATA,
  181197. (WPARAM) juce_messageWindowHandle,
  181198. (LPARAM) &data,
  181199. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181200. 8000,
  181201. &result);
  181202. }
  181203. }
  181204. }
  181205. static const String getMessageWindowClassName()
  181206. {
  181207. // this name has to be different for each app/dll instance because otherwise
  181208. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181209. // window class).
  181210. static int number = 0;
  181211. if (number == 0)
  181212. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181213. return T("JUCEcs_") + String (number);
  181214. }
  181215. void MessageManager::doPlatformSpecificInitialisation()
  181216. {
  181217. OleInitialize (0);
  181218. const String className (getMessageWindowClassName());
  181219. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181220. WNDCLASSEX wc;
  181221. zerostruct (wc);
  181222. wc.cbSize = sizeof (wc);
  181223. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181224. wc.cbWndExtra = 4;
  181225. wc.hInstance = hmod;
  181226. wc.lpszClassName = className;
  181227. RegisterClassEx (&wc);
  181228. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181229. messageWindowName,
  181230. 0, 0, 0, 0, 0, 0, 0,
  181231. hmod, 0);
  181232. }
  181233. void MessageManager::doPlatformSpecificShutdown()
  181234. {
  181235. DestroyWindow (juce_messageWindowHandle);
  181236. UnregisterClass (getMessageWindowClassName(), 0);
  181237. OleUninitialize();
  181238. }
  181239. #endif
  181240. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181241. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181242. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181243. // compiled on its own).
  181244. #if JUCE_INCLUDED_FILE
  181245. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181246. // these are in the windows SDK, but need to be repeated here for GCC..
  181247. #ifndef GET_APPCOMMAND_LPARAM
  181248. #define FAPPCOMMAND_MASK 0xF000
  181249. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181250. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181251. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181252. #define APPCOMMAND_MEDIA_STOP 13
  181253. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181254. #define WM_APPCOMMAND 0x0319
  181255. #endif
  181256. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181257. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181258. extern bool juce_IsRunningInWine();
  181259. #ifndef ULW_ALPHA
  181260. #define ULW_ALPHA 0x00000002
  181261. #endif
  181262. #ifndef AC_SRC_ALPHA
  181263. #define AC_SRC_ALPHA 0x01
  181264. #endif
  181265. static HPALETTE palette = 0;
  181266. static bool createPaletteIfNeeded = true;
  181267. static bool shouldDeactivateTitleBar = true;
  181268. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181269. #define WM_TRAYNOTIFY WM_USER + 100
  181270. using ::abs;
  181271. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181272. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181273. bool Desktop::canUseSemiTransparentWindows() throw()
  181274. {
  181275. if (updateLayeredWindow == 0)
  181276. {
  181277. if (! juce_IsRunningInWine())
  181278. {
  181279. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181280. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181281. }
  181282. }
  181283. return updateLayeredWindow != 0;
  181284. }
  181285. const int extendedKeyModifier = 0x10000;
  181286. const int KeyPress::spaceKey = VK_SPACE;
  181287. const int KeyPress::returnKey = VK_RETURN;
  181288. const int KeyPress::escapeKey = VK_ESCAPE;
  181289. const int KeyPress::backspaceKey = VK_BACK;
  181290. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181291. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181292. const int KeyPress::tabKey = VK_TAB;
  181293. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181294. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181295. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181296. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181297. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181298. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181299. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181300. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181301. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181302. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181303. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181304. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181305. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181306. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181307. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181308. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181309. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181310. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181311. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181312. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181313. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181314. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181315. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181316. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181317. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181318. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181319. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181320. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181321. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181322. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181323. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181324. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181325. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181326. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181327. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181328. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181329. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181330. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181331. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181332. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181333. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181334. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181335. const int KeyPress::playKey = 0x30000;
  181336. const int KeyPress::stopKey = 0x30001;
  181337. const int KeyPress::fastForwardKey = 0x30002;
  181338. const int KeyPress::rewindKey = 0x30003;
  181339. class WindowsBitmapImage : public Image
  181340. {
  181341. public:
  181342. HBITMAP hBitmap;
  181343. BITMAPV4HEADER bitmapInfo;
  181344. HDC hdc;
  181345. unsigned char* bitmapData;
  181346. WindowsBitmapImage (const PixelFormat format_,
  181347. const int w, const int h, const bool clearImage)
  181348. : Image (format_, w, h)
  181349. {
  181350. jassert (format_ == RGB || format_ == ARGB);
  181351. pixelStride = (format_ == RGB) ? 3 : 4;
  181352. zerostruct (bitmapInfo);
  181353. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181354. bitmapInfo.bV4Width = w;
  181355. bitmapInfo.bV4Height = h;
  181356. bitmapInfo.bV4Planes = 1;
  181357. bitmapInfo.bV4CSType = 1;
  181358. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181359. if (format_ == ARGB)
  181360. {
  181361. bitmapInfo.bV4AlphaMask = 0xff000000;
  181362. bitmapInfo.bV4RedMask = 0xff0000;
  181363. bitmapInfo.bV4GreenMask = 0xff00;
  181364. bitmapInfo.bV4BlueMask = 0xff;
  181365. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181366. }
  181367. else
  181368. {
  181369. bitmapInfo.bV4V4Compression = BI_RGB;
  181370. }
  181371. lineStride = -((w * pixelStride + 3) & ~3);
  181372. HDC dc = GetDC (0);
  181373. hdc = CreateCompatibleDC (dc);
  181374. ReleaseDC (0, dc);
  181375. SetMapMode (hdc, MM_TEXT);
  181376. hBitmap = CreateDIBSection (hdc,
  181377. (BITMAPINFO*) &(bitmapInfo),
  181378. DIB_RGB_COLORS,
  181379. (void**) &bitmapData,
  181380. 0, 0);
  181381. SelectObject (hdc, hBitmap);
  181382. if (format_ == ARGB && clearImage)
  181383. zeromem (bitmapData, abs (h * lineStride));
  181384. imageData = bitmapData - (lineStride * (h - 1));
  181385. }
  181386. ~WindowsBitmapImage()
  181387. {
  181388. DeleteDC (hdc);
  181389. DeleteObject (hBitmap);
  181390. }
  181391. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181392. const int x, const int y,
  181393. const RectangleList& maskedRegion) throw()
  181394. {
  181395. static HDRAWDIB hdd = 0;
  181396. static bool needToCreateDrawDib = true;
  181397. if (needToCreateDrawDib)
  181398. {
  181399. needToCreateDrawDib = false;
  181400. HDC dc = GetDC (0);
  181401. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181402. ReleaseDC (0, dc);
  181403. // only open if we're not palettised
  181404. if (n > 8)
  181405. hdd = DrawDibOpen();
  181406. }
  181407. if (createPaletteIfNeeded)
  181408. {
  181409. HDC dc = GetDC (0);
  181410. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181411. ReleaseDC (0, dc);
  181412. if (n <= 8)
  181413. palette = CreateHalftonePalette (dc);
  181414. createPaletteIfNeeded = false;
  181415. }
  181416. if (palette != 0)
  181417. {
  181418. SelectPalette (dc, palette, FALSE);
  181419. RealizePalette (dc);
  181420. SetStretchBltMode (dc, HALFTONE);
  181421. }
  181422. SetMapMode (dc, MM_TEXT);
  181423. if (transparent)
  181424. {
  181425. POINT p, pos;
  181426. SIZE size;
  181427. RECT windowBounds;
  181428. GetWindowRect (hwnd, &windowBounds);
  181429. p.x = -x;
  181430. p.y = -y;
  181431. pos.x = windowBounds.left;
  181432. pos.y = windowBounds.top;
  181433. size.cx = windowBounds.right - windowBounds.left;
  181434. size.cy = windowBounds.bottom - windowBounds.top;
  181435. BLENDFUNCTION bf;
  181436. bf.AlphaFormat = AC_SRC_ALPHA;
  181437. bf.BlendFlags = 0;
  181438. bf.BlendOp = AC_SRC_OVER;
  181439. bf.SourceConstantAlpha = 0xff;
  181440. if (! maskedRegion.isEmpty())
  181441. {
  181442. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181443. {
  181444. const Rectangle<int>& r = *i.getRectangle();
  181445. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181446. }
  181447. }
  181448. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181449. }
  181450. else
  181451. {
  181452. int savedDC = 0;
  181453. if (! maskedRegion.isEmpty())
  181454. {
  181455. savedDC = SaveDC (dc);
  181456. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181457. {
  181458. const Rectangle<int>& r = *i.getRectangle();
  181459. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181460. }
  181461. }
  181462. const int w = getWidth();
  181463. const int h = getHeight();
  181464. if (hdd == 0)
  181465. {
  181466. StretchDIBits (dc,
  181467. x, y, w, h,
  181468. 0, 0, w, h,
  181469. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181470. DIB_RGB_COLORS, SRCCOPY);
  181471. }
  181472. else
  181473. {
  181474. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181475. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181476. 0, 0, w, h, 0);
  181477. }
  181478. if (! maskedRegion.isEmpty())
  181479. RestoreDC (dc, savedDC);
  181480. }
  181481. }
  181482. juce_UseDebuggingNewOperator
  181483. private:
  181484. WindowsBitmapImage (const WindowsBitmapImage&);
  181485. WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181486. };
  181487. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181488. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  181489. {
  181490. SHORT k = (SHORT) keyCode;
  181491. if ((keyCode & extendedKeyModifier) == 0
  181492. && (k >= (SHORT) T('a') && k <= (SHORT) T('z')))
  181493. k += (SHORT) T('A') - (SHORT) T('a');
  181494. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181495. (SHORT) '+', VK_OEM_PLUS,
  181496. (SHORT) '-', VK_OEM_MINUS,
  181497. (SHORT) '.', VK_OEM_PERIOD,
  181498. (SHORT) ';', VK_OEM_1,
  181499. (SHORT) ':', VK_OEM_1,
  181500. (SHORT) '/', VK_OEM_2,
  181501. (SHORT) '?', VK_OEM_2,
  181502. (SHORT) '[', VK_OEM_4,
  181503. (SHORT) ']', VK_OEM_6 };
  181504. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181505. if (k == translatedValues [i])
  181506. k = translatedValues [i + 1];
  181507. return (GetKeyState (k) & 0x8000) != 0;
  181508. }
  181509. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  181510. {
  181511. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  181512. return callback (userData);
  181513. else
  181514. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  181515. }
  181516. class Win32ComponentPeer : public ComponentPeer
  181517. {
  181518. public:
  181519. Win32ComponentPeer (Component* const component,
  181520. const int windowStyleFlags)
  181521. : ComponentPeer (component, windowStyleFlags),
  181522. dontRepaint (false),
  181523. fullScreen (false),
  181524. isDragging (false),
  181525. isMouseOver (false),
  181526. hasCreatedCaret (false),
  181527. currentWindowIcon (0),
  181528. taskBarIcon (0),
  181529. dropTarget (0)
  181530. {
  181531. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  181532. setTitle (component->getName());
  181533. if ((windowStyleFlags & windowHasDropShadow) != 0
  181534. && Desktop::canUseSemiTransparentWindows())
  181535. {
  181536. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  181537. if (shadower != 0)
  181538. shadower->setOwner (component);
  181539. }
  181540. else
  181541. {
  181542. shadower = 0;
  181543. }
  181544. }
  181545. ~Win32ComponentPeer()
  181546. {
  181547. setTaskBarIcon (0);
  181548. deleteAndZero (shadower);
  181549. // do this before the next bit to avoid messages arriving for this window
  181550. // before it's destroyed
  181551. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  181552. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  181553. if (currentWindowIcon != 0)
  181554. DestroyIcon (currentWindowIcon);
  181555. if (dropTarget != 0)
  181556. {
  181557. dropTarget->Release();
  181558. dropTarget = 0;
  181559. }
  181560. }
  181561. void* getNativeHandle() const
  181562. {
  181563. return (void*) hwnd;
  181564. }
  181565. void setVisible (bool shouldBeVisible)
  181566. {
  181567. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  181568. if (shouldBeVisible)
  181569. InvalidateRect (hwnd, 0, 0);
  181570. else
  181571. lastPaintTime = 0;
  181572. }
  181573. void setTitle (const String& title)
  181574. {
  181575. SetWindowText (hwnd, title);
  181576. }
  181577. void setPosition (int x, int y)
  181578. {
  181579. offsetWithinParent (x, y);
  181580. SetWindowPos (hwnd, 0,
  181581. x - windowBorder.getLeft(),
  181582. y - windowBorder.getTop(),
  181583. 0, 0,
  181584. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181585. }
  181586. void repaintNowIfTransparent()
  181587. {
  181588. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  181589. handlePaintMessage();
  181590. }
  181591. void updateBorderSize()
  181592. {
  181593. WINDOWINFO info;
  181594. info.cbSize = sizeof (info);
  181595. if (GetWindowInfo (hwnd, &info))
  181596. {
  181597. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  181598. info.rcClient.left - info.rcWindow.left,
  181599. info.rcWindow.bottom - info.rcClient.bottom,
  181600. info.rcWindow.right - info.rcClient.right);
  181601. }
  181602. }
  181603. void setSize (int w, int h)
  181604. {
  181605. SetWindowPos (hwnd, 0, 0, 0,
  181606. w + windowBorder.getLeftAndRight(),
  181607. h + windowBorder.getTopAndBottom(),
  181608. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181609. updateBorderSize();
  181610. repaintNowIfTransparent();
  181611. }
  181612. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  181613. {
  181614. fullScreen = isNowFullScreen;
  181615. offsetWithinParent (x, y);
  181616. SetWindowPos (hwnd, 0,
  181617. x - windowBorder.getLeft(),
  181618. y - windowBorder.getTop(),
  181619. w + windowBorder.getLeftAndRight(),
  181620. h + windowBorder.getTopAndBottom(),
  181621. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181622. updateBorderSize();
  181623. repaintNowIfTransparent();
  181624. }
  181625. const Rectangle<int> getBounds() const
  181626. {
  181627. RECT r;
  181628. GetWindowRect (hwnd, &r);
  181629. Rectangle<int> bounds (r.left, r.top, r.right - r.left, r.bottom - r.top);
  181630. HWND parentH = GetParent (hwnd);
  181631. if (parentH != 0)
  181632. {
  181633. GetWindowRect (parentH, &r);
  181634. bounds.translate (-r.left, -r.top);
  181635. }
  181636. return windowBorder.subtractedFrom (bounds);
  181637. }
  181638. const Point<int> getScreenPosition() const
  181639. {
  181640. RECT r;
  181641. GetWindowRect (hwnd, &r);
  181642. return Point<int> (r.left + windowBorder.getLeft(),
  181643. r.top + windowBorder.getTop());
  181644. }
  181645. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  181646. {
  181647. return relativePosition + getScreenPosition();
  181648. }
  181649. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  181650. {
  181651. return screenPosition - getScreenPosition();
  181652. }
  181653. void setMinimised (bool shouldBeMinimised)
  181654. {
  181655. if (shouldBeMinimised != isMinimised())
  181656. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  181657. }
  181658. bool isMinimised() const
  181659. {
  181660. WINDOWPLACEMENT wp;
  181661. wp.length = sizeof (WINDOWPLACEMENT);
  181662. GetWindowPlacement (hwnd, &wp);
  181663. return wp.showCmd == SW_SHOWMINIMIZED;
  181664. }
  181665. void setFullScreen (bool shouldBeFullScreen)
  181666. {
  181667. setMinimised (false);
  181668. if (fullScreen != shouldBeFullScreen)
  181669. {
  181670. fullScreen = shouldBeFullScreen;
  181671. const Component::SafePointer<Component> deletionChecker (component);
  181672. if (! fullScreen)
  181673. {
  181674. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  181675. if (hasTitleBar())
  181676. ShowWindow (hwnd, SW_SHOWNORMAL);
  181677. if (! boundsCopy.isEmpty())
  181678. {
  181679. setBounds (boundsCopy.getX(),
  181680. boundsCopy.getY(),
  181681. boundsCopy.getWidth(),
  181682. boundsCopy.getHeight(),
  181683. false);
  181684. }
  181685. }
  181686. else
  181687. {
  181688. if (hasTitleBar())
  181689. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  181690. else
  181691. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  181692. }
  181693. if (deletionChecker != 0)
  181694. handleMovedOrResized();
  181695. }
  181696. }
  181697. bool isFullScreen() const
  181698. {
  181699. if (! hasTitleBar())
  181700. return fullScreen;
  181701. WINDOWPLACEMENT wp;
  181702. wp.length = sizeof (wp);
  181703. GetWindowPlacement (hwnd, &wp);
  181704. return wp.showCmd == SW_SHOWMAXIMIZED;
  181705. }
  181706. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  181707. {
  181708. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  181709. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  181710. return false;
  181711. RECT r;
  181712. GetWindowRect (hwnd, &r);
  181713. POINT p;
  181714. p.x = position.getX() + r.left + windowBorder.getLeft();
  181715. p.y = position.getY() + r.top + windowBorder.getTop();
  181716. HWND w = WindowFromPoint (p);
  181717. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  181718. }
  181719. const BorderSize getFrameSize() const
  181720. {
  181721. return windowBorder;
  181722. }
  181723. bool setAlwaysOnTop (bool alwaysOnTop)
  181724. {
  181725. const bool oldDeactivate = shouldDeactivateTitleBar;
  181726. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181727. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  181728. 0, 0, 0, 0,
  181729. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181730. shouldDeactivateTitleBar = oldDeactivate;
  181731. if (shadower != 0)
  181732. shadower->componentBroughtToFront (*component);
  181733. return true;
  181734. }
  181735. void toFront (bool makeActive)
  181736. {
  181737. setMinimised (false);
  181738. const bool oldDeactivate = shouldDeactivateTitleBar;
  181739. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181740. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  181741. : &toFrontCallback2,
  181742. (void*) hwnd);
  181743. shouldDeactivateTitleBar = oldDeactivate;
  181744. if (! makeActive)
  181745. {
  181746. // in this case a broughttofront call won't have occured, so do it now..
  181747. handleBroughtToFront();
  181748. }
  181749. }
  181750. void toBehind (ComponentPeer* other)
  181751. {
  181752. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  181753. jassert (otherPeer != 0); // wrong type of window?
  181754. if (otherPeer != 0)
  181755. {
  181756. setMinimised (false);
  181757. // must be careful not to try to put a topmost window behind a normal one, or win32
  181758. // promotes the normal one to be topmost!
  181759. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  181760. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  181761. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181762. else if (otherPeer->getComponent()->isAlwaysOnTop())
  181763. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  181764. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181765. }
  181766. }
  181767. bool isFocused() const
  181768. {
  181769. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  181770. }
  181771. void grabFocus()
  181772. {
  181773. const bool oldDeactivate = shouldDeactivateTitleBar;
  181774. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181775. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  181776. shouldDeactivateTitleBar = oldDeactivate;
  181777. }
  181778. void textInputRequired (const Point<int>&)
  181779. {
  181780. if (! hasCreatedCaret)
  181781. {
  181782. hasCreatedCaret = true;
  181783. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  181784. }
  181785. ShowCaret (hwnd);
  181786. SetCaretPos (0, 0);
  181787. }
  181788. void repaint (int x, int y, int w, int h)
  181789. {
  181790. const RECT r = { x, y, x + w, y + h };
  181791. InvalidateRect (hwnd, &r, FALSE);
  181792. }
  181793. void performAnyPendingRepaintsNow()
  181794. {
  181795. MSG m;
  181796. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  181797. DispatchMessage (&m);
  181798. }
  181799. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  181800. {
  181801. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  181802. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  181803. return 0;
  181804. }
  181805. void setTaskBarIcon (const Image* const image)
  181806. {
  181807. if (image != 0)
  181808. {
  181809. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  181810. if (taskBarIcon == 0)
  181811. {
  181812. taskBarIcon = new NOTIFYICONDATA();
  181813. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  181814. taskBarIcon->hWnd = (HWND) hwnd;
  181815. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  181816. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  181817. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  181818. taskBarIcon->hIcon = hicon;
  181819. taskBarIcon->szTip[0] = 0;
  181820. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  181821. }
  181822. else
  181823. {
  181824. HICON oldIcon = taskBarIcon->hIcon;
  181825. taskBarIcon->hIcon = hicon;
  181826. taskBarIcon->uFlags = NIF_ICON;
  181827. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181828. DestroyIcon (oldIcon);
  181829. }
  181830. DestroyIcon (hicon);
  181831. }
  181832. else if (taskBarIcon != 0)
  181833. {
  181834. taskBarIcon->uFlags = 0;
  181835. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  181836. DestroyIcon (taskBarIcon->hIcon);
  181837. deleteAndZero (taskBarIcon);
  181838. }
  181839. }
  181840. void setTaskBarIconToolTip (const String& toolTip) const
  181841. {
  181842. if (taskBarIcon != 0)
  181843. {
  181844. taskBarIcon->uFlags = NIF_TIP;
  181845. toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  181846. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181847. }
  181848. }
  181849. bool isInside (HWND h) const
  181850. {
  181851. return GetAncestor (hwnd, GA_ROOT) == h;
  181852. }
  181853. static void updateKeyModifiers() throw()
  181854. {
  181855. int keyMods = 0;
  181856. if (GetKeyState (VK_SHIFT) & 0x8000) keyMods |= ModifierKeys::shiftModifier;
  181857. if (GetKeyState (VK_CONTROL) & 0x8000) keyMods |= ModifierKeys::ctrlModifier;
  181858. if (GetKeyState (VK_MENU) & 0x8000) keyMods |= ModifierKeys::altModifier;
  181859. if (GetKeyState (VK_RMENU) & 0x8000) keyMods &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  181860. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  181861. }
  181862. static void updateModifiersFromWParam (const WPARAM wParam)
  181863. {
  181864. int mouseMods = 0;
  181865. if (wParam & MK_LBUTTON) mouseMods |= ModifierKeys::leftButtonModifier;
  181866. if (wParam & MK_RBUTTON) mouseMods |= ModifierKeys::rightButtonModifier;
  181867. if (wParam & MK_MBUTTON) mouseMods |= ModifierKeys::middleButtonModifier;
  181868. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  181869. updateKeyModifiers();
  181870. }
  181871. static int64 getMouseEventTime()
  181872. {
  181873. static int64 eventTimeOffset = 0;
  181874. static DWORD lastMessageTime = 0;
  181875. const DWORD thisMessageTime = GetMessageTime();
  181876. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  181877. {
  181878. lastMessageTime = thisMessageTime;
  181879. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  181880. }
  181881. return eventTimeOffset + thisMessageTime;
  181882. }
  181883. juce_UseDebuggingNewOperator
  181884. bool dontRepaint;
  181885. static ModifierKeys currentModifiers;
  181886. static ModifierKeys modifiersAtLastCallback;
  181887. private:
  181888. HWND hwnd;
  181889. DropShadower* shadower;
  181890. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  181891. BorderSize windowBorder;
  181892. HICON currentWindowIcon;
  181893. NOTIFYICONDATA* taskBarIcon;
  181894. IDropTarget* dropTarget;
  181895. class TemporaryImage : public Timer
  181896. {
  181897. public:
  181898. TemporaryImage()
  181899. : image (0)
  181900. {
  181901. }
  181902. ~TemporaryImage()
  181903. {
  181904. delete image;
  181905. }
  181906. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  181907. {
  181908. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  181909. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  181910. {
  181911. delete image;
  181912. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  181913. }
  181914. startTimer (3000);
  181915. return image;
  181916. }
  181917. void timerCallback()
  181918. {
  181919. stopTimer();
  181920. deleteAndZero (image);
  181921. }
  181922. private:
  181923. WindowsBitmapImage* image;
  181924. TemporaryImage (const TemporaryImage&);
  181925. TemporaryImage& operator= (const TemporaryImage&);
  181926. };
  181927. TemporaryImage offscreenImageGenerator;
  181928. class WindowClassHolder : public DeletedAtShutdown
  181929. {
  181930. public:
  181931. WindowClassHolder()
  181932. : windowClassName ("JUCE_")
  181933. {
  181934. // this name has to be different for each app/dll instance because otherwise
  181935. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181936. // window class).
  181937. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  181938. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181939. TCHAR moduleFile [1024];
  181940. moduleFile[0] = 0;
  181941. GetModuleFileName (moduleHandle, moduleFile, 1024);
  181942. WORD iconNum = 0;
  181943. WNDCLASSEX wcex;
  181944. wcex.cbSize = sizeof (wcex);
  181945. wcex.style = CS_OWNDC;
  181946. wcex.lpfnWndProc = (WNDPROC) windowProc;
  181947. wcex.lpszClassName = windowClassName;
  181948. wcex.cbClsExtra = 0;
  181949. wcex.cbWndExtra = 32;
  181950. wcex.hInstance = moduleHandle;
  181951. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181952. iconNum = 1;
  181953. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181954. wcex.hCursor = 0;
  181955. wcex.hbrBackground = 0;
  181956. wcex.lpszMenuName = 0;
  181957. RegisterClassEx (&wcex);
  181958. }
  181959. ~WindowClassHolder()
  181960. {
  181961. if (ComponentPeer::getNumPeers() == 0)
  181962. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  181963. clearSingletonInstance();
  181964. }
  181965. String windowClassName;
  181966. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  181967. };
  181968. static void* createWindowCallback (void* userData)
  181969. {
  181970. ((Win32ComponentPeer*) userData)->createWindow();
  181971. return 0;
  181972. }
  181973. void createWindow()
  181974. {
  181975. DWORD exstyle = WS_EX_ACCEPTFILES;
  181976. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  181977. if (hasTitleBar())
  181978. {
  181979. type |= WS_OVERLAPPED;
  181980. exstyle |= WS_EX_APPWINDOW;
  181981. if ((styleFlags & windowHasCloseButton) != 0)
  181982. {
  181983. type |= WS_SYSMENU;
  181984. }
  181985. else
  181986. {
  181987. // annoyingly, windows won't let you have a min/max button without a close button
  181988. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  181989. }
  181990. if ((styleFlags & windowIsResizable) != 0)
  181991. type |= WS_THICKFRAME;
  181992. }
  181993. else
  181994. {
  181995. type |= WS_POPUP | WS_SYSMENU;
  181996. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  181997. exstyle |= WS_EX_TOOLWINDOW;
  181998. else
  181999. exstyle |= WS_EX_APPWINDOW;
  182000. }
  182001. if ((styleFlags & windowHasMinimiseButton) != 0)
  182002. type |= WS_MINIMIZEBOX;
  182003. if ((styleFlags & windowHasMaximiseButton) != 0)
  182004. type |= WS_MAXIMIZEBOX;
  182005. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182006. exstyle |= WS_EX_TRANSPARENT;
  182007. if ((styleFlags & windowIsSemiTransparent) != 0
  182008. && Desktop::canUseSemiTransparentWindows())
  182009. exstyle |= WS_EX_LAYERED;
  182010. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  182011. if (hwnd != 0)
  182012. {
  182013. SetWindowLongPtr (hwnd, 0, 0);
  182014. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  182015. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  182016. if (dropTarget == 0)
  182017. dropTarget = new JuceDropTarget (this);
  182018. RegisterDragDrop (hwnd, dropTarget);
  182019. updateBorderSize();
  182020. // Calling this function here is (for some reason) necessary to make Windows
  182021. // correctly enable the menu items that we specify in the wm_initmenu message.
  182022. GetSystemMenu (hwnd, false);
  182023. }
  182024. else
  182025. {
  182026. jassertfalse
  182027. }
  182028. }
  182029. static void* destroyWindowCallback (void* handle)
  182030. {
  182031. RevokeDragDrop ((HWND) handle);
  182032. DestroyWindow ((HWND) handle);
  182033. return 0;
  182034. }
  182035. static void* toFrontCallback1 (void* h)
  182036. {
  182037. SetForegroundWindow ((HWND) h);
  182038. return 0;
  182039. }
  182040. static void* toFrontCallback2 (void* h)
  182041. {
  182042. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182043. return 0;
  182044. }
  182045. static void* setFocusCallback (void* h)
  182046. {
  182047. SetFocus ((HWND) h);
  182048. return 0;
  182049. }
  182050. static void* getFocusCallback (void*)
  182051. {
  182052. return (void*) GetFocus();
  182053. }
  182054. void offsetWithinParent (int& x, int& y) const
  182055. {
  182056. if (isTransparent())
  182057. {
  182058. HWND parentHwnd = GetParent (hwnd);
  182059. if (parentHwnd != 0)
  182060. {
  182061. RECT parentRect;
  182062. GetWindowRect (parentHwnd, &parentRect);
  182063. x += parentRect.left;
  182064. y += parentRect.top;
  182065. }
  182066. }
  182067. }
  182068. bool isTransparent() const
  182069. {
  182070. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182071. }
  182072. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182073. void setIcon (const Image& newIcon)
  182074. {
  182075. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182076. if (hicon != 0)
  182077. {
  182078. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182079. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182080. if (currentWindowIcon != 0)
  182081. DestroyIcon (currentWindowIcon);
  182082. currentWindowIcon = hicon;
  182083. }
  182084. }
  182085. void handlePaintMessage()
  182086. {
  182087. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182088. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182089. PAINTSTRUCT paintStruct;
  182090. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182091. // message and become re-entrant, but that's OK
  182092. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182093. // corrupt the image it's using to paint into, so do a check here.
  182094. static bool reentrant = false;
  182095. if (reentrant)
  182096. {
  182097. DeleteObject (rgn);
  182098. EndPaint (hwnd, &paintStruct);
  182099. return;
  182100. }
  182101. reentrant = true;
  182102. // this is the rectangle to update..
  182103. int x = paintStruct.rcPaint.left;
  182104. int y = paintStruct.rcPaint.top;
  182105. int w = paintStruct.rcPaint.right - x;
  182106. int h = paintStruct.rcPaint.bottom - y;
  182107. const bool transparent = isTransparent();
  182108. if (transparent)
  182109. {
  182110. // it's not possible to have a transparent window with a title bar at the moment!
  182111. jassert (! hasTitleBar());
  182112. RECT r;
  182113. GetWindowRect (hwnd, &r);
  182114. x = y = 0;
  182115. w = r.right - r.left;
  182116. h = r.bottom - r.top;
  182117. }
  182118. if (w > 0 && h > 0)
  182119. {
  182120. clearMaskedRegion();
  182121. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182122. RectangleList contextClip;
  182123. bool needToPaintAll = true;
  182124. if (regionType == COMPLEXREGION && ! transparent)
  182125. {
  182126. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182127. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182128. DeleteObject (clipRgn);
  182129. char rgnData [8192];
  182130. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182131. if (res > 0 && res <= sizeof (rgnData))
  182132. {
  182133. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182134. if (hdr->iType == RDH_RECTANGLES
  182135. && hdr->rcBound.right - hdr->rcBound.left >= w
  182136. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182137. {
  182138. needToPaintAll = false;
  182139. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182140. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182141. while (--num >= 0)
  182142. {
  182143. // (need to move this one pixel to the left because of a win32 bug)
  182144. const int cx = jmax (x, (int) rects->left - 1);
  182145. const int cy = rects->top;
  182146. const int cw = rects->right - cx;
  182147. const int ch = rects->bottom - rects->top;
  182148. if (cx + cw - x <= w && cy + ch - y <= h)
  182149. {
  182150. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182151. }
  182152. else
  182153. {
  182154. needToPaintAll = true;
  182155. break;
  182156. }
  182157. ++rects;
  182158. }
  182159. }
  182160. }
  182161. }
  182162. if (needToPaintAll)
  182163. {
  182164. contextClip.clear();
  182165. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182166. }
  182167. if (transparent)
  182168. {
  182169. RectangleList::Iterator i (contextClip);
  182170. while (i.next())
  182171. {
  182172. const Rectangle<int>& r = *i.getRectangle();
  182173. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182174. }
  182175. }
  182176. // if the component's not opaque, this won't draw properly unless the platform can support this
  182177. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182178. updateCurrentModifiers();
  182179. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182180. context.clipToRectangleList (contextClip);
  182181. context.setOrigin (-x, -y);
  182182. handlePaint (context);
  182183. if (! dontRepaint)
  182184. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182185. }
  182186. DeleteObject (rgn);
  182187. EndPaint (hwnd, &paintStruct);
  182188. reentrant = false;
  182189. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182190. _fpreset(); // because some graphics cards can unmask FP exceptions
  182191. #endif
  182192. lastPaintTime = Time::getMillisecondCounter();
  182193. }
  182194. void doMouseEvent (const Point<int>& position)
  182195. {
  182196. handleMouseEvent (0, position, currentModifiers, getMouseEventTime());
  182197. }
  182198. void doMouseMove (const Point<int>& position)
  182199. {
  182200. if (! isMouseOver)
  182201. {
  182202. isMouseOver = true;
  182203. updateKeyModifiers();
  182204. TRACKMOUSEEVENT tme;
  182205. tme.cbSize = sizeof (tme);
  182206. tme.dwFlags = TME_LEAVE;
  182207. tme.hwndTrack = hwnd;
  182208. tme.dwHoverTime = 0;
  182209. if (! TrackMouseEvent (&tme))
  182210. jassertfalse;
  182211. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  182212. }
  182213. else if (! isDragging)
  182214. {
  182215. if (! contains (position, false))
  182216. return;
  182217. }
  182218. // (Throttling the incoming queue of mouse-events seems to still be required in XP..)
  182219. static uint32 lastMouseTime = 0;
  182220. const uint32 now = Time::getMillisecondCounter();
  182221. const int maxMouseMovesPerSecond = 60;
  182222. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182223. {
  182224. lastMouseTime = now;
  182225. doMouseEvent (position);
  182226. }
  182227. }
  182228. void doMouseDown (const Point<int>& position, const WPARAM wParam)
  182229. {
  182230. if (GetCapture() != hwnd)
  182231. SetCapture (hwnd);
  182232. doMouseMove (position);
  182233. updateModifiersFromWParam (wParam);
  182234. isDragging = true;
  182235. doMouseEvent (position);
  182236. }
  182237. void doMouseUp (const Point<int>& position, const WPARAM wParam)
  182238. {
  182239. updateModifiersFromWParam (wParam);
  182240. isDragging = false;
  182241. // release the mouse capture if the user has released all buttons
  182242. if ((wParam & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON)) == 0 && hwnd == GetCapture())
  182243. ReleaseCapture();
  182244. doMouseEvent (position);
  182245. }
  182246. void doCaptureChanged()
  182247. {
  182248. if (isDragging)
  182249. doMouseUp (getCurrentMousePos(), (WPARAM) 0);
  182250. }
  182251. void doMouseExit()
  182252. {
  182253. isMouseOver = false;
  182254. doMouseEvent (getCurrentMousePos());
  182255. }
  182256. void doMouseWheel (const Point<int>& position, const WPARAM wParam, const bool isVertical)
  182257. {
  182258. updateKeyModifiers();
  182259. const float amount = jlimit (-1000.0f, 1000.0f, 0.75f * (short) HIWORD (wParam));
  182260. handleMouseWheel (0, position, getMouseEventTime(),
  182261. isVertical ? 0.0f : amount,
  182262. isVertical ? amount : 0.0f);
  182263. }
  182264. void sendModifierKeyChangeIfNeeded()
  182265. {
  182266. if (modifiersAtLastCallback != currentModifiers)
  182267. {
  182268. modifiersAtLastCallback = currentModifiers;
  182269. handleModifierKeysChange();
  182270. }
  182271. }
  182272. bool doKeyUp (const WPARAM key)
  182273. {
  182274. updateKeyModifiers();
  182275. switch (key)
  182276. {
  182277. case VK_SHIFT:
  182278. case VK_CONTROL:
  182279. case VK_MENU:
  182280. case VK_CAPITAL:
  182281. case VK_LWIN:
  182282. case VK_RWIN:
  182283. case VK_APPS:
  182284. case VK_NUMLOCK:
  182285. case VK_SCROLL:
  182286. case VK_LSHIFT:
  182287. case VK_RSHIFT:
  182288. case VK_LCONTROL:
  182289. case VK_LMENU:
  182290. case VK_RCONTROL:
  182291. case VK_RMENU:
  182292. sendModifierKeyChangeIfNeeded();
  182293. }
  182294. return handleKeyUpOrDown (false)
  182295. || Component::getCurrentlyModalComponent() != 0;
  182296. }
  182297. bool doKeyDown (const WPARAM key)
  182298. {
  182299. updateKeyModifiers();
  182300. bool used = false;
  182301. switch (key)
  182302. {
  182303. case VK_SHIFT:
  182304. case VK_LSHIFT:
  182305. case VK_RSHIFT:
  182306. case VK_CONTROL:
  182307. case VK_LCONTROL:
  182308. case VK_RCONTROL:
  182309. case VK_MENU:
  182310. case VK_LMENU:
  182311. case VK_RMENU:
  182312. case VK_LWIN:
  182313. case VK_RWIN:
  182314. case VK_CAPITAL:
  182315. case VK_NUMLOCK:
  182316. case VK_SCROLL:
  182317. case VK_APPS:
  182318. sendModifierKeyChangeIfNeeded();
  182319. break;
  182320. case VK_LEFT:
  182321. case VK_RIGHT:
  182322. case VK_UP:
  182323. case VK_DOWN:
  182324. case VK_PRIOR:
  182325. case VK_NEXT:
  182326. case VK_HOME:
  182327. case VK_END:
  182328. case VK_DELETE:
  182329. case VK_INSERT:
  182330. case VK_F1:
  182331. case VK_F2:
  182332. case VK_F3:
  182333. case VK_F4:
  182334. case VK_F5:
  182335. case VK_F6:
  182336. case VK_F7:
  182337. case VK_F8:
  182338. case VK_F9:
  182339. case VK_F10:
  182340. case VK_F11:
  182341. case VK_F12:
  182342. case VK_F13:
  182343. case VK_F14:
  182344. case VK_F15:
  182345. case VK_F16:
  182346. used = handleKeyUpOrDown (true);
  182347. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182348. break;
  182349. case VK_ADD:
  182350. case VK_SUBTRACT:
  182351. case VK_MULTIPLY:
  182352. case VK_DIVIDE:
  182353. case VK_SEPARATOR:
  182354. case VK_DECIMAL:
  182355. used = handleKeyUpOrDown (true);
  182356. break;
  182357. default:
  182358. used = handleKeyUpOrDown (true);
  182359. {
  182360. MSG msg;
  182361. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182362. {
  182363. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182364. // manually generate the key-press event that matches this key-down.
  182365. const UINT keyChar = MapVirtualKey (key, 2);
  182366. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182367. }
  182368. }
  182369. break;
  182370. }
  182371. if (Component::getCurrentlyModalComponent() != 0)
  182372. used = true;
  182373. return used;
  182374. }
  182375. bool doKeyChar (int key, const LPARAM flags)
  182376. {
  182377. updateKeyModifiers();
  182378. juce_wchar textChar = (juce_wchar) key;
  182379. const int virtualScanCode = (flags >> 16) & 0xff;
  182380. if (key >= '0' && key <= '9')
  182381. {
  182382. switch (virtualScanCode) // check for a numeric keypad scan-code
  182383. {
  182384. case 0x52:
  182385. case 0x4f:
  182386. case 0x50:
  182387. case 0x51:
  182388. case 0x4b:
  182389. case 0x4c:
  182390. case 0x4d:
  182391. case 0x47:
  182392. case 0x48:
  182393. case 0x49:
  182394. key = (key - '0') + KeyPress::numberPad0;
  182395. break;
  182396. default:
  182397. break;
  182398. }
  182399. }
  182400. else
  182401. {
  182402. // convert the scan code to an unmodified character code..
  182403. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182404. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182405. keyChar = LOWORD (keyChar);
  182406. if (keyChar != 0)
  182407. key = (int) keyChar;
  182408. // avoid sending junk text characters for some control-key combinations
  182409. if (textChar < ' ' && currentModifiers.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::altModifier))
  182410. textChar = 0;
  182411. }
  182412. return handleKeyPress (key, textChar);
  182413. }
  182414. bool doAppCommand (const LPARAM lParam)
  182415. {
  182416. int key = 0;
  182417. switch (GET_APPCOMMAND_LPARAM (lParam))
  182418. {
  182419. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182420. key = KeyPress::playKey;
  182421. break;
  182422. case APPCOMMAND_MEDIA_STOP:
  182423. key = KeyPress::stopKey;
  182424. break;
  182425. case APPCOMMAND_MEDIA_NEXTTRACK:
  182426. key = KeyPress::fastForwardKey;
  182427. break;
  182428. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182429. key = KeyPress::rewindKey;
  182430. break;
  182431. }
  182432. if (key != 0)
  182433. {
  182434. updateKeyModifiers();
  182435. if (hwnd == GetActiveWindow())
  182436. {
  182437. handleKeyPress (key, 0);
  182438. return true;
  182439. }
  182440. }
  182441. return false;
  182442. }
  182443. class JuceDropTarget : public IDropTarget
  182444. {
  182445. public:
  182446. JuceDropTarget (Win32ComponentPeer* const owner_)
  182447. : owner (owner_),
  182448. refCount (1)
  182449. {
  182450. }
  182451. virtual ~JuceDropTarget()
  182452. {
  182453. jassert (refCount == 0);
  182454. }
  182455. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  182456. {
  182457. if (id == IID_IUnknown || id == IID_IDropTarget)
  182458. {
  182459. AddRef();
  182460. *result = this;
  182461. return S_OK;
  182462. }
  182463. *result = 0;
  182464. return E_NOINTERFACE;
  182465. }
  182466. ULONG __stdcall AddRef() { return ++refCount; }
  182467. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  182468. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182469. {
  182470. updateFileList (pDataObject);
  182471. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182472. *pdwEffect = DROPEFFECT_COPY;
  182473. return S_OK;
  182474. }
  182475. HRESULT __stdcall DragLeave()
  182476. {
  182477. owner->handleFileDragExit (files);
  182478. return S_OK;
  182479. }
  182480. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182481. {
  182482. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182483. *pdwEffect = DROPEFFECT_COPY;
  182484. return S_OK;
  182485. }
  182486. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182487. {
  182488. updateFileList (pDataObject);
  182489. owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182490. *pdwEffect = DROPEFFECT_COPY;
  182491. return S_OK;
  182492. }
  182493. private:
  182494. Win32ComponentPeer* const owner;
  182495. int refCount;
  182496. StringArray files;
  182497. void updateFileList (IDataObject* const pDataObject)
  182498. {
  182499. files.clear();
  182500. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  182501. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  182502. if (pDataObject->GetData (&format, &medium) == S_OK)
  182503. {
  182504. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  182505. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  182506. unsigned int i = 0;
  182507. if (pDropFiles->fWide)
  182508. {
  182509. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  182510. for (;;)
  182511. {
  182512. unsigned int len = 0;
  182513. while (i + len < totalLen && fname [i + len] != 0)
  182514. ++len;
  182515. if (len == 0)
  182516. break;
  182517. files.add (String (fname + i, len));
  182518. i += len + 1;
  182519. }
  182520. }
  182521. else
  182522. {
  182523. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  182524. for (;;)
  182525. {
  182526. unsigned int len = 0;
  182527. while (i + len < totalLen && fname [i + len] != 0)
  182528. ++len;
  182529. if (len == 0)
  182530. break;
  182531. files.add (String (fname + i, len));
  182532. i += len + 1;
  182533. }
  182534. }
  182535. GlobalUnlock (medium.hGlobal);
  182536. }
  182537. }
  182538. JuceDropTarget (const JuceDropTarget&);
  182539. JuceDropTarget& operator= (const JuceDropTarget&);
  182540. };
  182541. void doSettingChange()
  182542. {
  182543. Desktop::getInstance().refreshMonitorSizes();
  182544. if (fullScreen && ! isMinimised())
  182545. {
  182546. const Rectangle<int> r (component->getParentMonitorArea());
  182547. SetWindowPos (hwnd, 0,
  182548. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  182549. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  182550. }
  182551. }
  182552. public:
  182553. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182554. {
  182555. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  182556. if (peer != 0)
  182557. return peer->peerWindowProc (h, message, wParam, lParam);
  182558. return DefWindowProcW (h, message, wParam, lParam);
  182559. }
  182560. private:
  182561. static const Point<int> getPointFromLParam (LPARAM lParam) throw()
  182562. {
  182563. return Point<int> (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  182564. }
  182565. const Point<int> getCurrentMousePos() throw()
  182566. {
  182567. RECT wr;
  182568. GetWindowRect (hwnd, &wr);
  182569. const DWORD mp = GetMessagePos();
  182570. return Point<int> (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182571. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop());
  182572. }
  182573. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182574. {
  182575. if (isValidPeer (this))
  182576. {
  182577. switch (message)
  182578. {
  182579. case WM_NCHITTEST:
  182580. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182581. return HTTRANSPARENT;
  182582. if (hasTitleBar())
  182583. break;
  182584. return HTCLIENT;
  182585. case WM_PAINT:
  182586. handlePaintMessage();
  182587. return 0;
  182588. case WM_NCPAINT:
  182589. if (wParam != 1)
  182590. handlePaintMessage();
  182591. if (hasTitleBar())
  182592. break;
  182593. return 0;
  182594. case WM_ERASEBKGND:
  182595. case WM_NCCALCSIZE:
  182596. if (hasTitleBar())
  182597. break;
  182598. return 1;
  182599. case WM_MOUSEMOVE:
  182600. doMouseMove (getPointFromLParam (lParam));
  182601. return 0;
  182602. case WM_MOUSELEAVE:
  182603. doMouseExit();
  182604. return 0;
  182605. case WM_LBUTTONDOWN:
  182606. case WM_MBUTTONDOWN:
  182607. case WM_RBUTTONDOWN:
  182608. doMouseDown (getPointFromLParam (lParam), wParam);
  182609. return 0;
  182610. case WM_LBUTTONUP:
  182611. case WM_MBUTTONUP:
  182612. case WM_RBUTTONUP:
  182613. doMouseUp (getPointFromLParam (lParam), wParam);
  182614. return 0;
  182615. case WM_CAPTURECHANGED:
  182616. doCaptureChanged();
  182617. return 0;
  182618. case WM_NCMOUSEMOVE:
  182619. if (hasTitleBar())
  182620. break;
  182621. return 0;
  182622. case 0x020A: /* WM_MOUSEWHEEL */
  182623. doMouseWheel (getCurrentMousePos(), wParam, true);
  182624. return 0;
  182625. case 0x020E: /* WM_MOUSEHWHEEL */
  182626. doMouseWheel (getCurrentMousePos(), wParam, false);
  182627. return 0;
  182628. case WM_WINDOWPOSCHANGING:
  182629. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  182630. {
  182631. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  182632. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  182633. {
  182634. if (constrainer != 0)
  182635. {
  182636. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  182637. component->getY() - windowBorder.getTop(),
  182638. component->getWidth() + windowBorder.getLeftAndRight(),
  182639. component->getHeight() + windowBorder.getTopAndBottom());
  182640. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  182641. constrainer->checkBounds (pos, current,
  182642. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  182643. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  182644. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  182645. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  182646. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  182647. wp->x = pos.getX();
  182648. wp->y = pos.getY();
  182649. wp->cx = pos.getWidth();
  182650. wp->cy = pos.getHeight();
  182651. }
  182652. }
  182653. }
  182654. return 0;
  182655. case WM_WINDOWPOSCHANGED:
  182656. handleMovedOrResized();
  182657. if (dontRepaint)
  182658. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  182659. return 0;
  182660. case WM_KEYDOWN:
  182661. case WM_SYSKEYDOWN:
  182662. if (doKeyDown (wParam))
  182663. return 0;
  182664. break;
  182665. case WM_KEYUP:
  182666. case WM_SYSKEYUP:
  182667. if (doKeyUp (wParam))
  182668. return 0;
  182669. break;
  182670. case WM_CHAR:
  182671. if (doKeyChar ((int) wParam, lParam))
  182672. return 0;
  182673. break;
  182674. case WM_APPCOMMAND:
  182675. if (doAppCommand (lParam))
  182676. return TRUE;
  182677. break;
  182678. case WM_SETFOCUS:
  182679. updateKeyModifiers();
  182680. handleFocusGain();
  182681. break;
  182682. case WM_KILLFOCUS:
  182683. if (hasCreatedCaret)
  182684. {
  182685. hasCreatedCaret = false;
  182686. DestroyCaret();
  182687. }
  182688. handleFocusLoss();
  182689. break;
  182690. case WM_ACTIVATEAPP:
  182691. // Windows does weird things to process priority when you swap apps,
  182692. // so this forces an update when the app is brought to the front
  182693. if (wParam != FALSE)
  182694. juce_repeatLastProcessPriority();
  182695. else
  182696. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  182697. juce_CheckCurrentlyFocusedTopLevelWindow();
  182698. modifiersAtLastCallback = -1;
  182699. return 0;
  182700. case WM_ACTIVATE:
  182701. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  182702. {
  182703. modifiersAtLastCallback = -1;
  182704. updateKeyModifiers();
  182705. if (isMinimised())
  182706. {
  182707. component->repaint();
  182708. handleMovedOrResized();
  182709. if (! ComponentPeer::isValidPeer (this))
  182710. return 0;
  182711. }
  182712. if (LOWORD (wParam) == WA_CLICKACTIVE
  182713. && component->isCurrentlyBlockedByAnotherModalComponent())
  182714. {
  182715. const Point<int> mousePos (component->getMouseXYRelative());
  182716. Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY());
  182717. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  182718. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  182719. return 0;
  182720. }
  182721. handleBroughtToFront();
  182722. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182723. Component::getCurrentlyModalComponent()->toFront (true);
  182724. return 0;
  182725. }
  182726. break;
  182727. case WM_NCACTIVATE:
  182728. // while a temporary window is being shown, prevent Windows from deactivating the
  182729. // title bars of our main windows.
  182730. if (wParam == 0 && ! shouldDeactivateTitleBar)
  182731. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  182732. break;
  182733. case WM_MOUSEACTIVATE:
  182734. if (! component->getMouseClickGrabsKeyboardFocus())
  182735. return MA_NOACTIVATE;
  182736. break;
  182737. case WM_SHOWWINDOW:
  182738. if (wParam != 0)
  182739. handleBroughtToFront();
  182740. break;
  182741. case WM_CLOSE:
  182742. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  182743. handleUserClosingWindow();
  182744. return 0;
  182745. case WM_QUERYENDSESSION:
  182746. if (JUCEApplication::getInstance() != 0)
  182747. {
  182748. JUCEApplication::getInstance()->systemRequestedQuit();
  182749. return MessageManager::getInstance()->hasStopMessageBeenSent();
  182750. }
  182751. return TRUE;
  182752. case WM_TRAYNOTIFY:
  182753. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182754. {
  182755. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  182756. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182757. {
  182758. Component* const current = Component::getCurrentlyModalComponent();
  182759. if (current != 0)
  182760. current->inputAttemptWhenModal();
  182761. }
  182762. }
  182763. else
  182764. {
  182765. ModifierKeys eventMods (ModifierKeys::getCurrentModifiersRealtime());
  182766. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  182767. eventMods = eventMods.withFlags (ModifierKeys::leftButtonModifier);
  182768. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  182769. eventMods = eventMods.withFlags (ModifierKeys::rightButtonModifier);
  182770. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182771. eventMods = eventMods.withoutMouseButtons();
  182772. const MouseEvent e (Desktop::getInstance().getMainMouseSource(),
  182773. Point<int>(), eventMods, component, getMouseEventTime(),
  182774. Point<int>(), getMouseEventTime(), 1, false);
  182775. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  182776. {
  182777. SetFocus (hwnd);
  182778. SetForegroundWindow (hwnd);
  182779. component->mouseDown (e);
  182780. }
  182781. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182782. {
  182783. component->mouseUp (e);
  182784. }
  182785. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182786. {
  182787. component->mouseDoubleClick (e);
  182788. }
  182789. else if (lParam == WM_MOUSEMOVE)
  182790. {
  182791. component->mouseMove (e);
  182792. }
  182793. }
  182794. break;
  182795. case WM_SYNCPAINT:
  182796. return 0;
  182797. case WM_PALETTECHANGED:
  182798. InvalidateRect (h, 0, 0);
  182799. break;
  182800. case WM_DISPLAYCHANGE:
  182801. InvalidateRect (h, 0, 0);
  182802. createPaletteIfNeeded = true;
  182803. // intentional fall-through...
  182804. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  182805. doSettingChange();
  182806. break;
  182807. case WM_INITMENU:
  182808. if (! hasTitleBar())
  182809. {
  182810. if (isFullScreen())
  182811. {
  182812. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  182813. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  182814. }
  182815. else if (! isMinimised())
  182816. {
  182817. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  182818. }
  182819. }
  182820. break;
  182821. case WM_SYSCOMMAND:
  182822. switch (wParam & 0xfff0)
  182823. {
  182824. case SC_CLOSE:
  182825. if (sendInputAttemptWhenModalMessage())
  182826. return 0;
  182827. if (hasTitleBar())
  182828. {
  182829. PostMessage (h, WM_CLOSE, 0, 0);
  182830. return 0;
  182831. }
  182832. break;
  182833. case SC_KEYMENU:
  182834. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  182835. // obscure situations that can arise if a modal loop is started from an alt-key
  182836. // keypress).
  182837. if (hasTitleBar() && h == GetCapture())
  182838. ReleaseCapture();
  182839. break;
  182840. case SC_MAXIMIZE:
  182841. if (sendInputAttemptWhenModalMessage())
  182842. return 0;
  182843. setFullScreen (true);
  182844. return 0;
  182845. case SC_MINIMIZE:
  182846. if (sendInputAttemptWhenModalMessage())
  182847. return 0;
  182848. if (! hasTitleBar())
  182849. {
  182850. setMinimised (true);
  182851. return 0;
  182852. }
  182853. break;
  182854. case SC_RESTORE:
  182855. if (sendInputAttemptWhenModalMessage())
  182856. return 0;
  182857. if (hasTitleBar())
  182858. {
  182859. if (isFullScreen())
  182860. {
  182861. setFullScreen (false);
  182862. return 0;
  182863. }
  182864. }
  182865. else
  182866. {
  182867. if (isMinimised())
  182868. setMinimised (false);
  182869. else if (isFullScreen())
  182870. setFullScreen (false);
  182871. return 0;
  182872. }
  182873. break;
  182874. }
  182875. break;
  182876. case WM_NCLBUTTONDOWN:
  182877. case WM_NCRBUTTONDOWN:
  182878. case WM_NCMBUTTONDOWN:
  182879. sendInputAttemptWhenModalMessage();
  182880. break;
  182881. //case WM_IME_STARTCOMPOSITION;
  182882. // return 0;
  182883. case WM_GETDLGCODE:
  182884. return DLGC_WANTALLKEYS;
  182885. default:
  182886. break;
  182887. }
  182888. }
  182889. return DefWindowProcW (h, message, wParam, lParam);
  182890. }
  182891. bool sendInputAttemptWhenModalMessage()
  182892. {
  182893. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182894. {
  182895. Component* const current = Component::getCurrentlyModalComponent();
  182896. if (current != 0)
  182897. current->inputAttemptWhenModal();
  182898. return true;
  182899. }
  182900. return false;
  182901. }
  182902. Win32ComponentPeer (const Win32ComponentPeer&);
  182903. Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  182904. };
  182905. ModifierKeys Win32ComponentPeer::currentModifiers;
  182906. ModifierKeys Win32ComponentPeer::modifiersAtLastCallback;
  182907. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  182908. {
  182909. return new Win32ComponentPeer (this, styleFlags);
  182910. }
  182911. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  182912. void ModifierKeys::updateCurrentModifiers() throw()
  182913. {
  182914. currentModifiers = Win32ComponentPeer::currentModifiers;
  182915. }
  182916. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182917. {
  182918. Win32ComponentPeer::updateKeyModifiers();
  182919. int keyMods = 0;
  182920. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::leftButtonModifier;
  182921. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::rightButtonModifier;
  182922. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::middleButtonModifier;
  182923. Win32ComponentPeer::currentModifiers
  182924. = Win32ComponentPeer::currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  182925. return Win32ComponentPeer::currentModifiers;
  182926. }
  182927. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  182928. {
  182929. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182930. if (wp != 0)
  182931. wp->setTaskBarIcon (&newImage);
  182932. }
  182933. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  182934. {
  182935. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182936. if (wp != 0)
  182937. wp->setTaskBarIconToolTip (tooltip);
  182938. }
  182939. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  182940. {
  182941. DWORD val = GetWindowLong (h, styleType);
  182942. if (bitIsSet)
  182943. val |= feature;
  182944. else
  182945. val &= ~feature;
  182946. SetWindowLongPtr (h, styleType, val);
  182947. SetWindowPos (h, 0, 0, 0, 0, 0,
  182948. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  182949. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  182950. }
  182951. bool Process::isForegroundProcess()
  182952. {
  182953. HWND fg = GetForegroundWindow();
  182954. if (fg == 0)
  182955. return true;
  182956. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  182957. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  182958. // have to see if any of our windows are children of the foreground window
  182959. fg = GetAncestor (fg, GA_ROOT);
  182960. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  182961. {
  182962. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  182963. if (wp != 0 && wp->isInside (fg))
  182964. return true;
  182965. }
  182966. return false;
  182967. }
  182968. bool AlertWindow::showNativeDialogBox (const String& title,
  182969. const String& bodyText,
  182970. bool isOkCancel)
  182971. {
  182972. return MessageBox (0, bodyText, title,
  182973. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  182974. : MB_OK)) == IDOK;
  182975. }
  182976. void Desktop::createMouseInputSources()
  182977. {
  182978. mouseSources.add (new MouseInputSource (0, true));
  182979. }
  182980. const Point<int> Desktop::getMousePosition()
  182981. {
  182982. POINT mousePos;
  182983. GetCursorPos (&mousePos);
  182984. return Point<int> (mousePos.x, mousePos.y);
  182985. }
  182986. void Desktop::setMousePosition (const Point<int>& newPosition)
  182987. {
  182988. SetCursorPos (newPosition.getX(), newPosition.getY());
  182989. }
  182990. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  182991. {
  182992. return new Image (format, imageWidth, imageHeight, clearImage);
  182993. }
  182994. class ScreenSaverDefeater : public Timer,
  182995. public DeletedAtShutdown
  182996. {
  182997. public:
  182998. ScreenSaverDefeater() throw()
  182999. {
  183000. startTimer (10000);
  183001. timerCallback();
  183002. }
  183003. ~ScreenSaverDefeater() {}
  183004. void timerCallback()
  183005. {
  183006. if (Process::isForegroundProcess())
  183007. {
  183008. // simulate a shift key getting pressed..
  183009. INPUT input[2];
  183010. input[0].type = INPUT_KEYBOARD;
  183011. input[0].ki.wVk = VK_SHIFT;
  183012. input[0].ki.dwFlags = 0;
  183013. input[0].ki.dwExtraInfo = 0;
  183014. input[1].type = INPUT_KEYBOARD;
  183015. input[1].ki.wVk = VK_SHIFT;
  183016. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  183017. input[1].ki.dwExtraInfo = 0;
  183018. SendInput (2, input, sizeof (INPUT));
  183019. }
  183020. }
  183021. };
  183022. static ScreenSaverDefeater* screenSaverDefeater = 0;
  183023. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  183024. {
  183025. if (isEnabled)
  183026. {
  183027. deleteAndZero (screenSaverDefeater);
  183028. }
  183029. else if (screenSaverDefeater == 0)
  183030. {
  183031. screenSaverDefeater = new ScreenSaverDefeater();
  183032. }
  183033. }
  183034. bool Desktop::isScreenSaverEnabled() throw()
  183035. {
  183036. return screenSaverDefeater == 0;
  183037. }
  183038. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  183039. {
  183040. if (enableOrDisable)
  183041. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  183042. }
  183043. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  183044. {
  183045. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  183046. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  183047. return TRUE;
  183048. }
  183049. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  183050. {
  183051. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  183052. // make sure the first in the list is the main monitor
  183053. for (int i = 1; i < monitorCoords.size(); ++i)
  183054. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  183055. monitorCoords.swap (i, 0);
  183056. if (monitorCoords.size() == 0)
  183057. {
  183058. RECT r;
  183059. GetWindowRect (GetDesktopWindow(), &r);
  183060. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  183061. }
  183062. if (clipToWorkArea)
  183063. {
  183064. // clip the main monitor to the active non-taskbar area
  183065. RECT r;
  183066. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183067. Rectangle<int>& screen = monitorCoords.getReference (0);
  183068. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183069. jmax (screen.getY(), (int) r.top));
  183070. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183071. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183072. }
  183073. }
  183074. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183075. {
  183076. Image* im = 0;
  183077. if (bitmap != 0)
  183078. {
  183079. BITMAP bm;
  183080. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183081. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183082. {
  183083. HDC tempDC = GetDC (0);
  183084. HDC dc = CreateCompatibleDC (tempDC);
  183085. ReleaseDC (0, tempDC);
  183086. SelectObject (dc, bitmap);
  183087. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183088. for (int y = bm.bmHeight; --y >= 0;)
  183089. {
  183090. for (int x = bm.bmWidth; --x >= 0;)
  183091. {
  183092. COLORREF col = GetPixel (dc, x, y);
  183093. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183094. (uint8) GetGValue (col),
  183095. (uint8) GetBValue (col)));
  183096. }
  183097. }
  183098. DeleteDC (dc);
  183099. }
  183100. }
  183101. return im;
  183102. }
  183103. static Image* createImageFromHICON (HICON icon) throw()
  183104. {
  183105. ICONINFO info;
  183106. if (GetIconInfo (icon, &info))
  183107. {
  183108. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183109. if (mask == 0)
  183110. return 0;
  183111. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183112. if (image == 0)
  183113. return mask;
  183114. for (int y = image->getHeight(); --y >= 0;)
  183115. {
  183116. for (int x = image->getWidth(); --x >= 0;)
  183117. {
  183118. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183119. if (brightness > 0.0f)
  183120. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183121. }
  183122. }
  183123. delete mask;
  183124. return image;
  183125. }
  183126. return 0;
  183127. }
  183128. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183129. {
  183130. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183131. ICONINFO info;
  183132. info.fIcon = isIcon;
  183133. info.xHotspot = hotspotX;
  183134. info.yHotspot = hotspotY;
  183135. info.hbmMask = mask;
  183136. HICON hi = 0;
  183137. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183138. {
  183139. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183140. Graphics g (bitmap);
  183141. g.drawImageAt (&image, 0, 0);
  183142. info.hbmColor = bitmap.hBitmap;
  183143. hi = CreateIconIndirect (&info);
  183144. }
  183145. else
  183146. {
  183147. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183148. HDC colDC = CreateCompatibleDC (GetDC (0));
  183149. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183150. SelectObject (colDC, colour);
  183151. SelectObject (alphaDC, mask);
  183152. for (int y = image.getHeight(); --y >= 0;)
  183153. {
  183154. for (int x = image.getWidth(); --x >= 0;)
  183155. {
  183156. const Colour c (image.getPixelAt (x, y));
  183157. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183158. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183159. }
  183160. }
  183161. DeleteDC (colDC);
  183162. DeleteDC (alphaDC);
  183163. info.hbmColor = colour;
  183164. hi = CreateIconIndirect (&info);
  183165. DeleteObject (colour);
  183166. }
  183167. DeleteObject (mask);
  183168. return hi;
  183169. }
  183170. Image* juce_createIconForFile (const File& file)
  183171. {
  183172. Image* image = 0;
  183173. WCHAR filename [1024];
  183174. file.getFullPathName().copyToUnicode (filename, 1023);
  183175. WORD iconNum = 0;
  183176. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183177. filename, &iconNum);
  183178. if (icon != 0)
  183179. {
  183180. image = createImageFromHICON (icon);
  183181. DestroyIcon (icon);
  183182. }
  183183. return image;
  183184. }
  183185. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183186. {
  183187. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183188. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183189. const Image* im = &image;
  183190. Image* newIm = 0;
  183191. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183192. {
  183193. im = newIm = image.createCopy (maxW, maxH);
  183194. hotspotX = (hotspotX * maxW) / image.getWidth();
  183195. hotspotY = (hotspotY * maxH) / image.getHeight();
  183196. }
  183197. void* cursorH = 0;
  183198. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183199. if (os == SystemStats::WinXP)
  183200. {
  183201. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183202. }
  183203. else
  183204. {
  183205. const int stride = (maxW + 7) >> 3;
  183206. HeapBlock <uint8> andPlane, xorPlane;
  183207. andPlane.calloc (stride * maxH);
  183208. xorPlane.calloc (stride * maxH);
  183209. int index = 0;
  183210. for (int y = 0; y < maxH; ++y)
  183211. {
  183212. for (int x = 0; x < maxW; ++x)
  183213. {
  183214. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183215. const Colour pixelColour (im->getPixelAt (x, y));
  183216. if (pixelColour.getAlpha() < 127)
  183217. andPlane [index + (x >> 3)] |= bit;
  183218. else if (pixelColour.getBrightness() >= 0.5f)
  183219. xorPlane [index + (x >> 3)] |= bit;
  183220. }
  183221. index += stride;
  183222. }
  183223. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183224. }
  183225. delete newIm;
  183226. return cursorH;
  183227. }
  183228. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  183229. {
  183230. if (cursorHandle != 0 && ! isStandard)
  183231. DestroyCursor ((HCURSOR) cursorHandle);
  183232. }
  183233. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  183234. {
  183235. LPCTSTR cursorName = IDC_ARROW;
  183236. switch (type)
  183237. {
  183238. case MouseCursor::NormalCursor:
  183239. cursorName = IDC_ARROW;
  183240. break;
  183241. case MouseCursor::NoCursor:
  183242. return 0;
  183243. case MouseCursor::DraggingHandCursor:
  183244. {
  183245. static void* dragHandCursor = 0;
  183246. if (dragHandCursor == 0)
  183247. {
  183248. static const unsigned char dragHandData[] =
  183249. { 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,
  183250. 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,
  183251. 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 };
  183252. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183253. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183254. }
  183255. return dragHandCursor;
  183256. }
  183257. case MouseCursor::WaitCursor:
  183258. cursorName = IDC_WAIT;
  183259. break;
  183260. case MouseCursor::IBeamCursor:
  183261. cursorName = IDC_IBEAM;
  183262. break;
  183263. case MouseCursor::PointingHandCursor:
  183264. cursorName = MAKEINTRESOURCE(32649);
  183265. break;
  183266. case MouseCursor::LeftRightResizeCursor:
  183267. case MouseCursor::LeftEdgeResizeCursor:
  183268. case MouseCursor::RightEdgeResizeCursor:
  183269. cursorName = IDC_SIZEWE;
  183270. break;
  183271. case MouseCursor::UpDownResizeCursor:
  183272. case MouseCursor::TopEdgeResizeCursor:
  183273. case MouseCursor::BottomEdgeResizeCursor:
  183274. cursorName = IDC_SIZENS;
  183275. break;
  183276. case MouseCursor::TopLeftCornerResizeCursor:
  183277. case MouseCursor::BottomRightCornerResizeCursor:
  183278. cursorName = IDC_SIZENWSE;
  183279. break;
  183280. case MouseCursor::TopRightCornerResizeCursor:
  183281. case MouseCursor::BottomLeftCornerResizeCursor:
  183282. cursorName = IDC_SIZENESW;
  183283. break;
  183284. case MouseCursor::UpDownLeftRightResizeCursor:
  183285. cursorName = IDC_SIZEALL;
  183286. break;
  183287. case MouseCursor::CrosshairCursor:
  183288. cursorName = IDC_CROSS;
  183289. break;
  183290. case MouseCursor::CopyingCursor:
  183291. // can't seem to find one of these in the win32 list..
  183292. break;
  183293. }
  183294. HCURSOR cursorH = LoadCursor (0, cursorName);
  183295. if (cursorH == 0)
  183296. cursorH = LoadCursor (0, IDC_ARROW);
  183297. return (void*) cursorH;
  183298. }
  183299. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  183300. {
  183301. SetCursor ((HCURSOR) getHandle());
  183302. }
  183303. void MouseCursor::showInAllWindows() const throw()
  183304. {
  183305. showInWindow (0);
  183306. }
  183307. class JuceDropSource : public IDropSource
  183308. {
  183309. int refCount;
  183310. public:
  183311. JuceDropSource()
  183312. : refCount (1)
  183313. {
  183314. }
  183315. virtual ~JuceDropSource()
  183316. {
  183317. jassert (refCount == 0);
  183318. }
  183319. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183320. {
  183321. if (id == IID_IUnknown || id == IID_IDropSource)
  183322. {
  183323. AddRef();
  183324. *result = this;
  183325. return S_OK;
  183326. }
  183327. *result = 0;
  183328. return E_NOINTERFACE;
  183329. }
  183330. ULONG __stdcall AddRef() { return ++refCount; }
  183331. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183332. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183333. {
  183334. if (escapePressed)
  183335. return DRAGDROP_S_CANCEL;
  183336. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183337. return DRAGDROP_S_DROP;
  183338. return S_OK;
  183339. }
  183340. HRESULT __stdcall GiveFeedback (DWORD)
  183341. {
  183342. return DRAGDROP_S_USEDEFAULTCURSORS;
  183343. }
  183344. };
  183345. class JuceEnumFormatEtc : public IEnumFORMATETC
  183346. {
  183347. public:
  183348. JuceEnumFormatEtc (const FORMATETC* const format_)
  183349. : refCount (1),
  183350. format (format_),
  183351. index (0)
  183352. {
  183353. }
  183354. virtual ~JuceEnumFormatEtc()
  183355. {
  183356. jassert (refCount == 0);
  183357. }
  183358. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183359. {
  183360. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183361. {
  183362. AddRef();
  183363. *result = this;
  183364. return S_OK;
  183365. }
  183366. *result = 0;
  183367. return E_NOINTERFACE;
  183368. }
  183369. ULONG __stdcall AddRef() { return ++refCount; }
  183370. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183371. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183372. {
  183373. if (result == 0)
  183374. return E_POINTER;
  183375. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183376. newOne->index = index;
  183377. *result = newOne;
  183378. return S_OK;
  183379. }
  183380. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183381. {
  183382. if (pceltFetched != 0)
  183383. *pceltFetched = 0;
  183384. else if (celt != 1)
  183385. return S_FALSE;
  183386. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183387. {
  183388. copyFormatEtc (lpFormatEtc [0], *format);
  183389. ++index;
  183390. if (pceltFetched != 0)
  183391. *pceltFetched = 1;
  183392. return S_OK;
  183393. }
  183394. return S_FALSE;
  183395. }
  183396. HRESULT __stdcall Skip (ULONG celt)
  183397. {
  183398. if (index + (int) celt >= 1)
  183399. return S_FALSE;
  183400. index += celt;
  183401. return S_OK;
  183402. }
  183403. HRESULT __stdcall Reset()
  183404. {
  183405. index = 0;
  183406. return S_OK;
  183407. }
  183408. private:
  183409. int refCount;
  183410. const FORMATETC* const format;
  183411. int index;
  183412. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183413. {
  183414. dest = source;
  183415. if (source.ptd != 0)
  183416. {
  183417. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183418. *(dest.ptd) = *(source.ptd);
  183419. }
  183420. }
  183421. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183422. JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183423. };
  183424. class JuceDataObject : public IDataObject
  183425. {
  183426. JuceDropSource* const dropSource;
  183427. const FORMATETC* const format;
  183428. const STGMEDIUM* const medium;
  183429. int refCount;
  183430. JuceDataObject (const JuceDataObject&);
  183431. JuceDataObject& operator= (const JuceDataObject&);
  183432. public:
  183433. JuceDataObject (JuceDropSource* const dropSource_,
  183434. const FORMATETC* const format_,
  183435. const STGMEDIUM* const medium_)
  183436. : dropSource (dropSource_),
  183437. format (format_),
  183438. medium (medium_),
  183439. refCount (1)
  183440. {
  183441. }
  183442. virtual ~JuceDataObject()
  183443. {
  183444. jassert (refCount == 0);
  183445. }
  183446. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183447. {
  183448. if (id == IID_IUnknown || id == IID_IDataObject)
  183449. {
  183450. AddRef();
  183451. *result = this;
  183452. return S_OK;
  183453. }
  183454. *result = 0;
  183455. return E_NOINTERFACE;
  183456. }
  183457. ULONG __stdcall AddRef() { return ++refCount; }
  183458. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183459. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183460. {
  183461. if ((pFormatEtc->tymed & format->tymed) != 0
  183462. && pFormatEtc->cfFormat == format->cfFormat
  183463. && pFormatEtc->dwAspect == format->dwAspect)
  183464. {
  183465. pMedium->tymed = format->tymed;
  183466. pMedium->pUnkForRelease = 0;
  183467. if (format->tymed == TYMED_HGLOBAL)
  183468. {
  183469. const SIZE_T len = GlobalSize (medium->hGlobal);
  183470. void* const src = GlobalLock (medium->hGlobal);
  183471. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  183472. memcpy (dst, src, len);
  183473. GlobalUnlock (medium->hGlobal);
  183474. pMedium->hGlobal = dst;
  183475. return S_OK;
  183476. }
  183477. }
  183478. return DV_E_FORMATETC;
  183479. }
  183480. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  183481. {
  183482. if (f == 0)
  183483. return E_INVALIDARG;
  183484. if (f->tymed == format->tymed
  183485. && f->cfFormat == format->cfFormat
  183486. && f->dwAspect == format->dwAspect)
  183487. return S_OK;
  183488. return DV_E_FORMATETC;
  183489. }
  183490. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  183491. {
  183492. pFormatEtcOut->ptd = 0;
  183493. return E_NOTIMPL;
  183494. }
  183495. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  183496. {
  183497. if (result == 0)
  183498. return E_POINTER;
  183499. if (direction == DATADIR_GET)
  183500. {
  183501. *result = new JuceEnumFormatEtc (format);
  183502. return S_OK;
  183503. }
  183504. *result = 0;
  183505. return E_NOTIMPL;
  183506. }
  183507. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  183508. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  183509. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  183510. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  183511. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  183512. };
  183513. static HDROP createHDrop (const StringArray& fileNames) throw()
  183514. {
  183515. int totalChars = 0;
  183516. for (int i = fileNames.size(); --i >= 0;)
  183517. totalChars += fileNames[i].length() + 1;
  183518. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  183519. sizeof (DROPFILES)
  183520. + sizeof (WCHAR) * (totalChars + 2));
  183521. if (hDrop != 0)
  183522. {
  183523. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  183524. pDropFiles->pFiles = sizeof (DROPFILES);
  183525. pDropFiles->fWide = true;
  183526. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  183527. for (int i = 0; i < fileNames.size(); ++i)
  183528. {
  183529. fileNames[i].copyToUnicode (fname, 2048);
  183530. fname += fileNames[i].length() + 1;
  183531. }
  183532. *fname = 0;
  183533. GlobalUnlock (hDrop);
  183534. }
  183535. return hDrop;
  183536. }
  183537. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  183538. {
  183539. JuceDropSource* const source = new JuceDropSource();
  183540. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  183541. DWORD effect;
  183542. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  183543. data->Release();
  183544. source->Release();
  183545. return res == DRAGDROP_S_DROP;
  183546. }
  183547. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  183548. {
  183549. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183550. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183551. medium.hGlobal = createHDrop (files);
  183552. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  183553. : DROPEFFECT_COPY);
  183554. }
  183555. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183556. {
  183557. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183558. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183559. const int numChars = text.length();
  183560. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  183561. char* d = (char*) GlobalLock (medium.hGlobal);
  183562. text.copyToUnicode ((WCHAR*) d, numChars + 1);
  183563. format.cfFormat = CF_UNICODETEXT;
  183564. GlobalUnlock (medium.hGlobal);
  183565. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  183566. }
  183567. #endif
  183568. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  183569. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  183570. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183571. // compiled on its own).
  183572. #if JUCE_INCLUDED_FILE
  183573. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  183574. NEWTEXTMETRICEXW*,
  183575. int type,
  183576. LPARAM lParam)
  183577. {
  183578. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183579. {
  183580. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183581. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters (T("@")));
  183582. }
  183583. return 1;
  183584. }
  183585. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  183586. NEWTEXTMETRICEXW*,
  183587. int type,
  183588. LPARAM lParam)
  183589. {
  183590. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183591. {
  183592. LOGFONTW lf;
  183593. zerostruct (lf);
  183594. lf.lfWeight = FW_DONTCARE;
  183595. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183596. lf.lfQuality = DEFAULT_QUALITY;
  183597. lf.lfCharSet = DEFAULT_CHARSET;
  183598. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183599. lf.lfPitchAndFamily = FF_DONTCARE;
  183600. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183601. fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1);
  183602. HDC dc = CreateCompatibleDC (0);
  183603. EnumFontFamiliesEx (dc, &lf,
  183604. (FONTENUMPROCW) &wfontEnum2,
  183605. lParam, 0);
  183606. DeleteDC (dc);
  183607. }
  183608. return 1;
  183609. }
  183610. const StringArray Font::findAllTypefaceNames() throw()
  183611. {
  183612. StringArray results;
  183613. HDC dc = CreateCompatibleDC (0);
  183614. {
  183615. LOGFONTW lf;
  183616. zerostruct (lf);
  183617. lf.lfWeight = FW_DONTCARE;
  183618. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183619. lf.lfQuality = DEFAULT_QUALITY;
  183620. lf.lfCharSet = DEFAULT_CHARSET;
  183621. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183622. lf.lfPitchAndFamily = FF_DONTCARE;
  183623. lf.lfFaceName[0] = 0;
  183624. EnumFontFamiliesEx (dc, &lf,
  183625. (FONTENUMPROCW) &wfontEnum1,
  183626. (LPARAM) &results, 0);
  183627. }
  183628. DeleteDC (dc);
  183629. results.sort (true);
  183630. return results;
  183631. }
  183632. extern bool juce_IsRunningInWine();
  183633. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  183634. {
  183635. if (juce_IsRunningInWine())
  183636. {
  183637. // If we're running in Wine, then use fonts that might be available on Linux..
  183638. defaultSans = "Bitstream Vera Sans";
  183639. defaultSerif = "Bitstream Vera Serif";
  183640. defaultFixed = "Bitstream Vera Sans Mono";
  183641. }
  183642. else
  183643. {
  183644. defaultSans = "Verdana";
  183645. defaultSerif = "Times";
  183646. defaultFixed = "Lucida Console";
  183647. }
  183648. }
  183649. class FontDCHolder : private DeletedAtShutdown
  183650. {
  183651. public:
  183652. FontDCHolder() throw()
  183653. : dc (0), numKPs (0), size (0),
  183654. bold (false), italic (false)
  183655. {
  183656. }
  183657. ~FontDCHolder() throw()
  183658. {
  183659. if (dc != 0)
  183660. {
  183661. DeleteDC (dc);
  183662. DeleteObject (fontH);
  183663. }
  183664. clearSingletonInstance();
  183665. }
  183666. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  183667. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  183668. {
  183669. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  183670. {
  183671. fontName = fontName_;
  183672. bold = bold_;
  183673. italic = italic_;
  183674. size = size_;
  183675. if (dc != 0)
  183676. {
  183677. DeleteDC (dc);
  183678. DeleteObject (fontH);
  183679. kps.free();
  183680. }
  183681. fontH = 0;
  183682. dc = CreateCompatibleDC (0);
  183683. SetMapperFlags (dc, 0);
  183684. SetMapMode (dc, MM_TEXT);
  183685. LOGFONTW lfw;
  183686. zerostruct (lfw);
  183687. lfw.lfCharSet = DEFAULT_CHARSET;
  183688. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183689. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183690. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  183691. lfw.lfQuality = PROOF_QUALITY;
  183692. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  183693. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  183694. fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1);
  183695. lfw.lfHeight = size > 0 ? size : -256;
  183696. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  183697. if (standardSizedFont != 0)
  183698. {
  183699. if (SelectObject (dc, standardSizedFont) != 0)
  183700. {
  183701. fontH = standardSizedFont;
  183702. if (size == 0)
  183703. {
  183704. OUTLINETEXTMETRIC otm;
  183705. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  183706. {
  183707. lfw.lfHeight = -(int) otm.otmEMSquare;
  183708. fontH = CreateFontIndirect (&lfw);
  183709. SelectObject (dc, fontH);
  183710. DeleteObject (standardSizedFont);
  183711. }
  183712. }
  183713. }
  183714. else
  183715. {
  183716. jassertfalse
  183717. }
  183718. }
  183719. else
  183720. {
  183721. jassertfalse
  183722. }
  183723. }
  183724. return dc;
  183725. }
  183726. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  183727. {
  183728. if (kps == 0)
  183729. {
  183730. numKPs = GetKerningPairs (dc, 0, 0);
  183731. kps.calloc (numKPs);
  183732. GetKerningPairs (dc, numKPs, kps);
  183733. }
  183734. numKPs_ = numKPs;
  183735. return kps;
  183736. }
  183737. private:
  183738. HFONT fontH;
  183739. HDC dc;
  183740. String fontName;
  183741. HeapBlock <KERNINGPAIR> kps;
  183742. int numKPs, size;
  183743. bool bold, italic;
  183744. FontDCHolder (const FontDCHolder&);
  183745. FontDCHolder& operator= (const FontDCHolder&);
  183746. };
  183747. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  183748. class WindowsTypeface : public CustomTypeface
  183749. {
  183750. public:
  183751. WindowsTypeface (const Font& font)
  183752. {
  183753. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  183754. font.isBold(), font.isItalic(), 0);
  183755. TEXTMETRIC tm;
  183756. tm.tmAscent = tm.tmHeight = 1;
  183757. tm.tmDefaultChar = 0;
  183758. GetTextMetrics (dc, &tm);
  183759. setCharacteristics (font.getTypefaceName(),
  183760. tm.tmAscent / (float) tm.tmHeight,
  183761. font.isBold(), font.isItalic(),
  183762. tm.tmDefaultChar);
  183763. }
  183764. bool loadGlyphIfPossible (const juce_wchar character)
  183765. {
  183766. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  183767. GLYPHMETRICS gm;
  183768. {
  183769. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  183770. WORD index = 0;
  183771. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  183772. && index == 0xffff)
  183773. {
  183774. return false;
  183775. }
  183776. }
  183777. Path glyphPath;
  183778. TEXTMETRIC tm;
  183779. if (! GetTextMetrics (dc, &tm))
  183780. {
  183781. addGlyph (character, glyphPath, 0);
  183782. return true;
  183783. }
  183784. const float height = (float) tm.tmHeight;
  183785. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  183786. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  183787. &gm, 0, 0, &identityMatrix);
  183788. if (bufSize > 0)
  183789. {
  183790. HeapBlock<char> data (bufSize);
  183791. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  183792. bufSize, data, &identityMatrix);
  183793. const TTPOLYGONHEADER* pheader = reinterpret_cast<TTPOLYGONHEADER*> (data.getData());
  183794. const float scaleX = 1.0f / height;
  183795. const float scaleY = -1.0f / height;
  183796. while ((char*) pheader < data + bufSize)
  183797. {
  183798. float x = scaleX * pheader->pfxStart.x.value;
  183799. float y = scaleY * pheader->pfxStart.y.value;
  183800. glyphPath.startNewSubPath (x, y);
  183801. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  183802. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  183803. while ((const char*) curve < curveEnd)
  183804. {
  183805. if (curve->wType == TT_PRIM_LINE)
  183806. {
  183807. for (int i = 0; i < curve->cpfx; ++i)
  183808. {
  183809. x = scaleX * curve->apfx[i].x.value;
  183810. y = scaleY * curve->apfx[i].y.value;
  183811. glyphPath.lineTo (x, y);
  183812. }
  183813. }
  183814. else if (curve->wType == TT_PRIM_QSPLINE)
  183815. {
  183816. for (int i = 0; i < curve->cpfx - 1; ++i)
  183817. {
  183818. const float x2 = scaleX * curve->apfx[i].x.value;
  183819. const float y2 = scaleY * curve->apfx[i].y.value;
  183820. float x3, y3;
  183821. if (i < curve->cpfx - 2)
  183822. {
  183823. x3 = 0.5f * (x2 + scaleX * curve->apfx[i + 1].x.value);
  183824. y3 = 0.5f * (y2 + scaleY * curve->apfx[i + 1].y.value);
  183825. }
  183826. else
  183827. {
  183828. x3 = scaleX * curve->apfx[i + 1].x.value;
  183829. y3 = scaleY * curve->apfx[i + 1].y.value;
  183830. }
  183831. glyphPath.quadraticTo (x2, y2, x3, y3);
  183832. x = x3;
  183833. y = y3;
  183834. }
  183835. }
  183836. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  183837. }
  183838. pheader = (const TTPOLYGONHEADER*) curve;
  183839. glyphPath.closeSubPath();
  183840. }
  183841. }
  183842. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  183843. int numKPs;
  183844. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  183845. for (int i = 0; i < numKPs; ++i)
  183846. {
  183847. if (kps[i].wFirst == character)
  183848. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  183849. kps[i].iKernAmount / height);
  183850. }
  183851. return true;
  183852. }
  183853. };
  183854. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  183855. {
  183856. return new WindowsTypeface (font);
  183857. }
  183858. #endif
  183859. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  183860. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  183861. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183862. // compiled on its own).
  183863. #if JUCE_INCLUDED_FILE
  183864. static const void* defaultDirPath = 0;
  183865. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  183866. static Component* currentExtraFileWin = 0;
  183867. static bool areThereAnyAlwaysOnTopWindows()
  183868. {
  183869. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  183870. {
  183871. Component* c = Desktop::getInstance().getComponent (i);
  183872. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  183873. return true;
  183874. }
  183875. return false;
  183876. }
  183877. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  183878. {
  183879. if (msg == BFFM_INITIALIZED)
  183880. {
  183881. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  183882. }
  183883. else if (msg == BFFM_VALIDATEFAILEDW)
  183884. {
  183885. returnedString = (LPCWSTR) lParam;
  183886. }
  183887. else if (msg == BFFM_VALIDATEFAILEDA)
  183888. {
  183889. returnedString = (const char*) lParam;
  183890. }
  183891. return 0;
  183892. }
  183893. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  183894. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  183895. {
  183896. if (currentExtraFileWin != 0)
  183897. {
  183898. if (uiMsg == WM_INITDIALOG)
  183899. {
  183900. HWND dialogH = GetParent (hdlg);
  183901. jassert (dialogH != 0);
  183902. if (dialogH == 0)
  183903. dialogH = hdlg;
  183904. RECT r, cr;
  183905. GetWindowRect (dialogH, &r);
  183906. GetClientRect (dialogH, &cr);
  183907. SetWindowPos (dialogH, 0,
  183908. r.left, r.top,
  183909. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  183910. jmax (150, (int) (r.bottom - r.top)),
  183911. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  183912. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  183913. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  183914. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  183915. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  183916. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  183917. }
  183918. else if (uiMsg == WM_NOTIFY)
  183919. {
  183920. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  183921. if (ofn->hdr.code == CDN_SELCHANGE)
  183922. {
  183923. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  183924. if (comp != 0)
  183925. {
  183926. TCHAR path [MAX_PATH * 2];
  183927. path[0] = 0;
  183928. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  183929. const String fn ((const WCHAR*) path);
  183930. comp->selectedFileChanged (File (fn));
  183931. }
  183932. }
  183933. }
  183934. }
  183935. return 0;
  183936. }
  183937. class FPComponentHolder : public Component
  183938. {
  183939. public:
  183940. FPComponentHolder()
  183941. {
  183942. setVisible (true);
  183943. setOpaque (true);
  183944. }
  183945. ~FPComponentHolder()
  183946. {
  183947. }
  183948. void paint (Graphics& g)
  183949. {
  183950. g.fillAll (Colours::lightgrey);
  183951. }
  183952. private:
  183953. FPComponentHolder (const FPComponentHolder&);
  183954. FPComponentHolder& operator= (const FPComponentHolder&);
  183955. };
  183956. void FileChooser::showPlatformDialog (Array<File>& results,
  183957. const String& title,
  183958. const File& currentFileOrDirectory,
  183959. const String& filter,
  183960. bool selectsDirectory,
  183961. bool /*selectsFiles*/,
  183962. bool isSaveDialogue,
  183963. bool warnAboutOverwritingExistingFiles,
  183964. bool selectMultipleFiles,
  183965. FilePreviewComponent* extraInfoComponent)
  183966. {
  183967. const int numCharsAvailable = 32768;
  183968. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  183969. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  183970. int fnameIdx = 0;
  183971. JUCE_TRY
  183972. {
  183973. // use a modal window as the parent for this dialog box
  183974. // to block input from other app windows
  183975. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  183976. Component w (String::empty);
  183977. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  183978. mainMon.getY() + mainMon.getHeight() / 4,
  183979. 0, 0);
  183980. w.setOpaque (true);
  183981. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  183982. w.addToDesktop (0);
  183983. if (extraInfoComponent == 0)
  183984. w.enterModalState();
  183985. String initialDir;
  183986. if (currentFileOrDirectory.isDirectory())
  183987. {
  183988. initialDir = currentFileOrDirectory.getFullPathName();
  183989. }
  183990. else
  183991. {
  183992. currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable);
  183993. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  183994. }
  183995. if (currentExtraFileWin->isValidComponent())
  183996. {
  183997. jassertfalse
  183998. return;
  183999. }
  184000. if (selectsDirectory)
  184001. {
  184002. LPITEMIDLIST list = 0;
  184003. filenameSpace.fillWith (0);
  184004. {
  184005. BROWSEINFO bi;
  184006. zerostruct (bi);
  184007. bi.hwndOwner = (HWND) w.getWindowHandle();
  184008. bi.pszDisplayName = fname;
  184009. bi.lpszTitle = title;
  184010. bi.lpfn = browseCallbackProc;
  184011. #ifdef BIF_USENEWUI
  184012. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  184013. #else
  184014. bi.ulFlags = 0x50;
  184015. #endif
  184016. defaultDirPath = (const WCHAR*) initialDir;
  184017. list = SHBrowseForFolder (&bi);
  184018. if (! SHGetPathFromIDListW (list, fname))
  184019. {
  184020. fname[0] = 0;
  184021. returnedString = String::empty;
  184022. }
  184023. }
  184024. LPMALLOC al;
  184025. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  184026. al->Free (list);
  184027. defaultDirPath = 0;
  184028. if (returnedString.isNotEmpty())
  184029. {
  184030. const String stringFName (fname);
  184031. results.add (File (stringFName).getSiblingFile (returnedString));
  184032. returnedString = String::empty;
  184033. return;
  184034. }
  184035. }
  184036. else
  184037. {
  184038. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  184039. if (warnAboutOverwritingExistingFiles)
  184040. flags |= OFN_OVERWRITEPROMPT;
  184041. if (selectMultipleFiles)
  184042. flags |= OFN_ALLOWMULTISELECT;
  184043. if (extraInfoComponent != 0)
  184044. {
  184045. flags |= OFN_ENABLEHOOK;
  184046. currentExtraFileWin = new FPComponentHolder();
  184047. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  184048. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  184049. extraInfoComponent->getHeight());
  184050. currentExtraFileWin->addToDesktop (0);
  184051. currentExtraFileWin->enterModalState();
  184052. }
  184053. {
  184054. WCHAR filters [1024];
  184055. zeromem (filters, sizeof (filters));
  184056. filter.copyToUnicode (filters, 1024);
  184057. filter.copyToUnicode (filters + filter.length() + 1,
  184058. 1022 - filter.length());
  184059. OPENFILENAMEW of;
  184060. zerostruct (of);
  184061. #ifdef OPENFILENAME_SIZE_VERSION_400W
  184062. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  184063. #else
  184064. of.lStructSize = sizeof (of);
  184065. #endif
  184066. of.hwndOwner = (HWND) w.getWindowHandle();
  184067. of.lpstrFilter = filters;
  184068. of.nFilterIndex = 1;
  184069. of.lpstrFile = fname;
  184070. of.nMaxFile = numCharsAvailable;
  184071. of.lpstrInitialDir = initialDir;
  184072. of.lpstrTitle = title;
  184073. of.Flags = flags;
  184074. if (extraInfoComponent != 0)
  184075. of.lpfnHook = &openCallback;
  184076. if (isSaveDialogue)
  184077. {
  184078. if (! GetSaveFileName (&of))
  184079. fname[0] = 0;
  184080. else
  184081. fnameIdx = of.nFileOffset;
  184082. }
  184083. else
  184084. {
  184085. if (! GetOpenFileName (&of))
  184086. fname[0] = 0;
  184087. else
  184088. fnameIdx = of.nFileOffset;
  184089. }
  184090. }
  184091. }
  184092. }
  184093. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184094. catch (...)
  184095. {
  184096. fname[0] = 0;
  184097. }
  184098. #endif
  184099. deleteAndZero (currentExtraFileWin);
  184100. const WCHAR* const files = fname;
  184101. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184102. {
  184103. const WCHAR* filename = files + fnameIdx;
  184104. while (*filename != 0)
  184105. {
  184106. const String filepath (String (files) + T("\\") + String (filename));
  184107. results.add (File (filepath));
  184108. filename += CharacterFunctions::length (filename) + 1;
  184109. }
  184110. }
  184111. else if (files[0] != 0)
  184112. {
  184113. results.add (File (files));
  184114. }
  184115. }
  184116. #endif
  184117. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  184118. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  184119. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184120. // compiled on its own).
  184121. #if JUCE_INCLUDED_FILE
  184122. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  184123. {
  184124. if (OpenClipboard (0) != 0)
  184125. {
  184126. if (EmptyClipboard() != 0)
  184127. {
  184128. const int len = text.length();
  184129. if (len > 0)
  184130. {
  184131. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184132. (len + 1) * sizeof (wchar_t));
  184133. if (bufH != 0)
  184134. {
  184135. WCHAR* const data = (WCHAR*) GlobalLock (bufH);
  184136. text.copyToUnicode (data, len);
  184137. GlobalUnlock (bufH);
  184138. SetClipboardData (CF_UNICODETEXT, bufH);
  184139. }
  184140. }
  184141. }
  184142. CloseClipboard();
  184143. }
  184144. }
  184145. const String SystemClipboard::getTextFromClipboard() throw()
  184146. {
  184147. String result;
  184148. if (OpenClipboard (0) != 0)
  184149. {
  184150. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184151. if (bufH != 0)
  184152. {
  184153. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184154. if (data != 0)
  184155. {
  184156. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184157. GlobalUnlock (bufH);
  184158. }
  184159. }
  184160. CloseClipboard();
  184161. }
  184162. return result;
  184163. }
  184164. #endif
  184165. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184166. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184167. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184168. // compiled on its own).
  184169. #if JUCE_INCLUDED_FILE
  184170. namespace ActiveXHelpers
  184171. {
  184172. class JuceIStorage : public IStorage
  184173. {
  184174. int refCount;
  184175. public:
  184176. JuceIStorage() : refCount (1) {}
  184177. virtual ~JuceIStorage()
  184178. {
  184179. jassert (refCount == 0);
  184180. }
  184181. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184182. {
  184183. if (id == IID_IUnknown || id == IID_IStorage)
  184184. {
  184185. AddRef();
  184186. *result = this;
  184187. return S_OK;
  184188. }
  184189. *result = 0;
  184190. return E_NOINTERFACE;
  184191. }
  184192. ULONG __stdcall AddRef() { return ++refCount; }
  184193. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184194. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184195. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184196. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184197. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184198. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184199. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184200. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184201. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184202. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184203. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184204. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184205. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184206. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184207. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184208. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184209. juce_UseDebuggingNewOperator
  184210. };
  184211. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184212. {
  184213. int refCount;
  184214. HWND window;
  184215. public:
  184216. JuceOleInPlaceFrame (HWND window_)
  184217. : refCount (1),
  184218. window (window_)
  184219. {
  184220. }
  184221. virtual ~JuceOleInPlaceFrame()
  184222. {
  184223. jassert (refCount == 0);
  184224. }
  184225. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184226. {
  184227. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184228. {
  184229. AddRef();
  184230. *result = this;
  184231. return S_OK;
  184232. }
  184233. *result = 0;
  184234. return E_NOINTERFACE;
  184235. }
  184236. ULONG __stdcall AddRef() { return ++refCount; }
  184237. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184238. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184239. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184240. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184241. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184242. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184243. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184244. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184245. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184246. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184247. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184248. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184249. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184250. juce_UseDebuggingNewOperator
  184251. };
  184252. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184253. {
  184254. int refCount;
  184255. HWND window;
  184256. JuceOleInPlaceFrame* frame;
  184257. public:
  184258. JuceIOleInPlaceSite (HWND window_)
  184259. : refCount (1),
  184260. window (window_)
  184261. {
  184262. frame = new JuceOleInPlaceFrame (window);
  184263. }
  184264. virtual ~JuceIOleInPlaceSite()
  184265. {
  184266. jassert (refCount == 0);
  184267. frame->Release();
  184268. }
  184269. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184270. {
  184271. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184272. {
  184273. AddRef();
  184274. *result = this;
  184275. return S_OK;
  184276. }
  184277. *result = 0;
  184278. return E_NOINTERFACE;
  184279. }
  184280. ULONG __stdcall AddRef() { return ++refCount; }
  184281. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184282. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184283. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184284. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184285. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184286. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184287. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184288. {
  184289. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184290. *lplpFrame = frame;
  184291. *lplpDoc = 0;
  184292. lpFrameInfo->fMDIApp = FALSE;
  184293. lpFrameInfo->hwndFrame = window;
  184294. lpFrameInfo->haccel = 0;
  184295. lpFrameInfo->cAccelEntries = 0;
  184296. return S_OK;
  184297. }
  184298. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184299. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184300. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184301. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184302. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184303. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184304. juce_UseDebuggingNewOperator
  184305. };
  184306. class JuceIOleClientSite : public IOleClientSite
  184307. {
  184308. int refCount;
  184309. JuceIOleInPlaceSite* inplaceSite;
  184310. public:
  184311. JuceIOleClientSite (HWND window)
  184312. : refCount (1)
  184313. {
  184314. inplaceSite = new JuceIOleInPlaceSite (window);
  184315. }
  184316. virtual ~JuceIOleClientSite()
  184317. {
  184318. jassert (refCount == 0);
  184319. inplaceSite->Release();
  184320. }
  184321. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184322. {
  184323. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184324. {
  184325. AddRef();
  184326. *result = this;
  184327. return S_OK;
  184328. }
  184329. else if (id == IID_IOleInPlaceSite)
  184330. {
  184331. inplaceSite->AddRef();
  184332. *result = inplaceSite;
  184333. return S_OK;
  184334. }
  184335. *result = 0;
  184336. return E_NOINTERFACE;
  184337. }
  184338. ULONG __stdcall AddRef() { return ++refCount; }
  184339. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184340. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184341. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184342. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184343. HRESULT __stdcall ShowObject() { return S_OK; }
  184344. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184345. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184346. juce_UseDebuggingNewOperator
  184347. };
  184348. static VoidArray activeXComps;
  184349. static HWND getHWND (const ActiveXControlComponent* const component)
  184350. {
  184351. HWND hwnd = 0;
  184352. const IID iid = IID_IOleWindow;
  184353. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184354. if (window != 0)
  184355. {
  184356. window->GetWindow (&hwnd);
  184357. window->Release();
  184358. }
  184359. return hwnd;
  184360. }
  184361. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184362. {
  184363. RECT activeXRect, peerRect;
  184364. GetWindowRect (hwnd, &activeXRect);
  184365. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184366. const Point<int> mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left,
  184367. GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top);
  184368. const int64 mouseEventTime = Win32ComponentPeer::getMouseEventTime();
  184369. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184370. switch (message)
  184371. {
  184372. case WM_MOUSEMOVE:
  184373. case WM_LBUTTONDOWN:
  184374. case WM_MBUTTONDOWN:
  184375. case WM_RBUTTONDOWN:
  184376. case WM_LBUTTONUP:
  184377. case WM_MBUTTONUP:
  184378. case WM_RBUTTONUP:
  184379. peer->handleMouseEvent (0, mousePos, Win32ComponentPeer::currentModifiers, mouseEventTime);
  184380. break;
  184381. default:
  184382. break;
  184383. }
  184384. }
  184385. }
  184386. class ActiveXControlComponent::ActiveXControlData : public ComponentMovementWatcher
  184387. {
  184388. ActiveXControlComponent* const owner;
  184389. bool wasShowing;
  184390. public:
  184391. HWND controlHWND;
  184392. IStorage* storage;
  184393. IOleClientSite* clientSite;
  184394. IOleObject* control;
  184395. ActiveXControlData (HWND hwnd,
  184396. ActiveXControlComponent* const owner_)
  184397. : ComponentMovementWatcher (owner_),
  184398. owner (owner_),
  184399. wasShowing (owner_ != 0 && owner_->isShowing()),
  184400. controlHWND (0),
  184401. storage (new ActiveXHelpers::JuceIStorage()),
  184402. clientSite (new ActiveXHelpers::JuceIOleClientSite (hwnd)),
  184403. control (0)
  184404. {
  184405. }
  184406. ~ActiveXControlData()
  184407. {
  184408. if (control != 0)
  184409. {
  184410. control->Close (OLECLOSE_NOSAVE);
  184411. control->Release();
  184412. }
  184413. clientSite->Release();
  184414. storage->Release();
  184415. }
  184416. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184417. {
  184418. Component* const topComp = owner->getTopLevelComponent();
  184419. if (topComp->getPeer() != 0)
  184420. {
  184421. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  184422. owner->setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight()));
  184423. }
  184424. }
  184425. void componentPeerChanged()
  184426. {
  184427. const bool isShowingNow = owner->isShowing();
  184428. if (wasShowing != isShowingNow)
  184429. {
  184430. wasShowing = isShowingNow;
  184431. owner->setControlVisible (isShowingNow);
  184432. }
  184433. componentMovedOrResized (true, true);
  184434. }
  184435. void componentVisibilityChanged (Component&)
  184436. {
  184437. componentPeerChanged();
  184438. }
  184439. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184440. {
  184441. return ((ActiveXControlData*) ax->control) != 0
  184442. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184443. }
  184444. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184445. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184446. {
  184447. for (int i = ActiveXHelpers::activeXComps.size(); --i >= 0;)
  184448. {
  184449. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) ActiveXHelpers::activeXComps.getUnchecked(i);
  184450. if (doesWindowMatch (ax, hwnd))
  184451. {
  184452. switch (message)
  184453. {
  184454. case WM_MOUSEMOVE:
  184455. case WM_LBUTTONDOWN:
  184456. case WM_MBUTTONDOWN:
  184457. case WM_RBUTTONDOWN:
  184458. case WM_LBUTTONUP:
  184459. case WM_MBUTTONUP:
  184460. case WM_RBUTTONUP:
  184461. case WM_LBUTTONDBLCLK:
  184462. case WM_MBUTTONDBLCLK:
  184463. case WM_RBUTTONDBLCLK:
  184464. if (ax->isShowing())
  184465. {
  184466. ComponentPeer* const peer = ax->getPeer();
  184467. if (peer != 0)
  184468. {
  184469. ActiveXHelpers::offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  184470. if (! ax->areMouseEventsAllowed())
  184471. return 0;
  184472. }
  184473. }
  184474. break;
  184475. default:
  184476. break;
  184477. }
  184478. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  184479. }
  184480. }
  184481. return DefWindowProc (hwnd, message, wParam, lParam);
  184482. }
  184483. };
  184484. ActiveXControlComponent::ActiveXControlComponent()
  184485. : originalWndProc (0),
  184486. control (0),
  184487. mouseEventsAllowed (true)
  184488. {
  184489. ActiveXHelpers::activeXComps.add (this);
  184490. }
  184491. ActiveXControlComponent::~ActiveXControlComponent()
  184492. {
  184493. deleteControl();
  184494. ActiveXHelpers::activeXComps.removeValue (this);
  184495. }
  184496. void ActiveXControlComponent::paint (Graphics& g)
  184497. {
  184498. if (control == 0)
  184499. g.fillAll (Colours::lightgrey);
  184500. }
  184501. bool ActiveXControlComponent::createControl (const void* controlIID)
  184502. {
  184503. deleteControl();
  184504. ComponentPeer* const peer = getPeer();
  184505. // the component must have already been added to a real window when you call this!
  184506. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  184507. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  184508. {
  184509. const Point<int> pos (relativePositionToOtherComponent (getTopLevelComponent(), Point<int>()));
  184510. HWND hwnd = (HWND) peer->getNativeHandle();
  184511. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  184512. HRESULT hr;
  184513. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  184514. info->clientSite, info->storage,
  184515. (void**) &(info->control))) == S_OK)
  184516. {
  184517. info->control->SetHostNames (L"Juce", 0);
  184518. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  184519. {
  184520. RECT rect;
  184521. rect.left = pos.getX();
  184522. rect.top = pos.getY();
  184523. rect.right = pos.getX() + getWidth();
  184524. rect.bottom = pos.getY() + getHeight();
  184525. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  184526. {
  184527. control = info.release();
  184528. setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), getWidth(), getHeight()));
  184529. ((ActiveXControlData*) control)->controlHWND = ActiveXHelpers::getHWND (this);
  184530. if (((ActiveXControlData*) control)->controlHWND != 0)
  184531. {
  184532. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  184533. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) ActiveXControlData::activeXHookWndProc);
  184534. }
  184535. return true;
  184536. }
  184537. }
  184538. }
  184539. }
  184540. return false;
  184541. }
  184542. void ActiveXControlComponent::deleteControl()
  184543. {
  184544. ActiveXControlData* const info = (ActiveXControlData*) control;
  184545. if (info != 0)
  184546. {
  184547. delete info;
  184548. control = 0;
  184549. originalWndProc = 0;
  184550. }
  184551. }
  184552. void* ActiveXControlComponent::queryInterface (const void* iid) const
  184553. {
  184554. ActiveXControlData* const info = (ActiveXControlData*) control;
  184555. void* result = 0;
  184556. if (info != 0 && info->control != 0
  184557. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  184558. return result;
  184559. return 0;
  184560. }
  184561. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  184562. {
  184563. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184564. if (hwnd != 0)
  184565. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  184566. }
  184567. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  184568. {
  184569. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184570. if (hwnd != 0)
  184571. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  184572. }
  184573. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  184574. {
  184575. mouseEventsAllowed = eventsCanReachControl;
  184576. }
  184577. #endif
  184578. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184579. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184580. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184581. // compiled on its own).
  184582. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  184583. using namespace QTOLibrary;
  184584. using namespace QTOControlLib;
  184585. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  184586. static bool isQTAvailable = false;
  184587. class QuickTimeMovieComponent::Pimpl
  184588. {
  184589. public:
  184590. Pimpl() : dataHandle (0)
  184591. {
  184592. }
  184593. ~Pimpl()
  184594. {
  184595. clearHandle();
  184596. }
  184597. void clearHandle()
  184598. {
  184599. if (dataHandle != 0)
  184600. {
  184601. DisposeHandle (dataHandle);
  184602. dataHandle = 0;
  184603. }
  184604. }
  184605. IQTControlPtr qtControl;
  184606. IQTMoviePtr qtMovie;
  184607. Handle dataHandle;
  184608. };
  184609. QuickTimeMovieComponent::QuickTimeMovieComponent()
  184610. : movieLoaded (false),
  184611. controllerVisible (true)
  184612. {
  184613. pimpl = new Pimpl();
  184614. setMouseEventsAllowed (false);
  184615. }
  184616. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  184617. {
  184618. closeMovie();
  184619. pimpl->qtControl = 0;
  184620. deleteControl();
  184621. pimpl = 0;
  184622. }
  184623. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  184624. {
  184625. if (! isQTAvailable)
  184626. isQTAvailable = (InitializeQTML (0) == noErr) && (EnterMovies() == noErr);
  184627. return isQTAvailable;
  184628. }
  184629. void QuickTimeMovieComponent::createControlIfNeeded()
  184630. {
  184631. if (isShowing() && ! isControlCreated())
  184632. {
  184633. const IID qtIID = __uuidof (QTControl);
  184634. if (createControl (&qtIID))
  184635. {
  184636. const IID qtInterfaceIID = __uuidof (IQTControl);
  184637. pimpl->qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  184638. if (pimpl->qtControl != 0)
  184639. {
  184640. pimpl->qtControl->Release(); // it has one ref too many at this point
  184641. pimpl->qtControl->QuickTimeInitialize();
  184642. pimpl->qtControl->PutSizing (qtMovieFitsControl);
  184643. if (movieFile != File::nonexistent)
  184644. loadMovie (movieFile, controllerVisible);
  184645. }
  184646. }
  184647. }
  184648. }
  184649. bool QuickTimeMovieComponent::isControlCreated() const
  184650. {
  184651. return isControlOpen();
  184652. }
  184653. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  184654. const bool isControllerVisible)
  184655. {
  184656. const ScopedPointer<InputStream> movieStreamDeleter (movieStream);
  184657. movieFile = File::nonexistent;
  184658. movieLoaded = false;
  184659. pimpl->qtMovie = 0;
  184660. controllerVisible = isControllerVisible;
  184661. createControlIfNeeded();
  184662. if (isControlCreated())
  184663. {
  184664. if (pimpl->qtControl != 0)
  184665. {
  184666. pimpl->qtControl->Put_MovieHandle (0);
  184667. pimpl->clearHandle();
  184668. Movie movie;
  184669. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, pimpl->dataHandle))
  184670. {
  184671. pimpl->qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  184672. pimpl->qtMovie = pimpl->qtControl->GetMovie();
  184673. if (pimpl->qtMovie != 0)
  184674. pimpl->qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  184675. : qtMovieControllerTypeNone);
  184676. }
  184677. if (movie == 0)
  184678. pimpl->clearHandle();
  184679. }
  184680. movieLoaded = (pimpl->qtMovie != 0);
  184681. }
  184682. else
  184683. {
  184684. // You're trying to open a movie when the control hasn't yet been created, probably because
  184685. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  184686. jassertfalse
  184687. }
  184688. return movieLoaded;
  184689. }
  184690. void QuickTimeMovieComponent::closeMovie()
  184691. {
  184692. stop();
  184693. movieFile = File::nonexistent;
  184694. movieLoaded = false;
  184695. pimpl->qtMovie = 0;
  184696. if (pimpl->qtControl != 0)
  184697. pimpl->qtControl->Put_MovieHandle (0);
  184698. pimpl->clearHandle();
  184699. }
  184700. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  184701. {
  184702. return movieFile;
  184703. }
  184704. bool QuickTimeMovieComponent::isMovieOpen() const
  184705. {
  184706. return movieLoaded;
  184707. }
  184708. double QuickTimeMovieComponent::getMovieDuration() const
  184709. {
  184710. if (pimpl->qtMovie != 0)
  184711. return pimpl->qtMovie->GetDuration() / (double) pimpl->qtMovie->GetTimeScale();
  184712. return 0.0;
  184713. }
  184714. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  184715. {
  184716. if (pimpl->qtMovie != 0)
  184717. {
  184718. struct QTRECT r = pimpl->qtMovie->GetNaturalRect();
  184719. width = r.right - r.left;
  184720. height = r.bottom - r.top;
  184721. }
  184722. else
  184723. {
  184724. width = height = 0;
  184725. }
  184726. }
  184727. void QuickTimeMovieComponent::play()
  184728. {
  184729. if (pimpl->qtMovie != 0)
  184730. pimpl->qtMovie->Play();
  184731. }
  184732. void QuickTimeMovieComponent::stop()
  184733. {
  184734. if (pimpl->qtMovie != 0)
  184735. pimpl->qtMovie->Stop();
  184736. }
  184737. bool QuickTimeMovieComponent::isPlaying() const
  184738. {
  184739. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetRate() != 0.0f;
  184740. }
  184741. void QuickTimeMovieComponent::setPosition (const double seconds)
  184742. {
  184743. if (pimpl->qtMovie != 0)
  184744. pimpl->qtMovie->PutTime ((long) (seconds * pimpl->qtMovie->GetTimeScale()));
  184745. }
  184746. double QuickTimeMovieComponent::getPosition() const
  184747. {
  184748. if (pimpl->qtMovie != 0)
  184749. return pimpl->qtMovie->GetTime() / (double) pimpl->qtMovie->GetTimeScale();
  184750. return 0.0;
  184751. }
  184752. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  184753. {
  184754. if (pimpl->qtMovie != 0)
  184755. pimpl->qtMovie->PutRate (newSpeed);
  184756. }
  184757. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  184758. {
  184759. if (pimpl->qtMovie != 0)
  184760. {
  184761. pimpl->qtMovie->PutAudioVolume (newVolume);
  184762. pimpl->qtMovie->PutAudioMute (newVolume <= 0);
  184763. }
  184764. }
  184765. float QuickTimeMovieComponent::getMovieVolume() const
  184766. {
  184767. if (pimpl->qtMovie != 0)
  184768. return pimpl->qtMovie->GetAudioVolume();
  184769. return 0.0f;
  184770. }
  184771. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  184772. {
  184773. if (pimpl->qtMovie != 0)
  184774. pimpl->qtMovie->PutLoop (shouldLoop);
  184775. }
  184776. bool QuickTimeMovieComponent::isLooping() const
  184777. {
  184778. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetLoop();
  184779. }
  184780. bool QuickTimeMovieComponent::isControllerVisible() const
  184781. {
  184782. return controllerVisible;
  184783. }
  184784. void QuickTimeMovieComponent::parentHierarchyChanged()
  184785. {
  184786. createControlIfNeeded();
  184787. QTCompBaseClass::parentHierarchyChanged();
  184788. }
  184789. void QuickTimeMovieComponent::visibilityChanged()
  184790. {
  184791. createControlIfNeeded();
  184792. QTCompBaseClass::visibilityChanged();
  184793. }
  184794. void QuickTimeMovieComponent::paint (Graphics& g)
  184795. {
  184796. if (! isControlCreated())
  184797. g.fillAll (Colours::black);
  184798. }
  184799. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  184800. {
  184801. Handle dataRef = 0;
  184802. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  184803. if (err == noErr)
  184804. {
  184805. Str255 suffix;
  184806. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  184807. StringPtr name = suffix;
  184808. err = PtrAndHand (name, dataRef, name[0] + 1);
  184809. if (err == noErr)
  184810. {
  184811. long atoms[3];
  184812. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  184813. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  184814. atoms[2] = EndianU32_NtoB (MovieFileType);
  184815. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  184816. if (err == noErr)
  184817. return dataRef;
  184818. }
  184819. DisposeHandle (dataRef);
  184820. }
  184821. return 0;
  184822. }
  184823. static CFStringRef juceStringToCFString (const String& s)
  184824. {
  184825. const int len = s.length();
  184826. const juce_wchar* const t = (const juce_wchar*) s;
  184827. HeapBlock <UniChar> temp (len + 2);
  184828. for (int i = 0; i <= len; ++i)
  184829. temp[i] = t[i];
  184830. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  184831. }
  184832. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  184833. {
  184834. Boolean trueBool = true;
  184835. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184836. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  184837. props[prop].propValueSize = sizeof (trueBool);
  184838. props[prop].propValueAddress = &trueBool;
  184839. ++prop;
  184840. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184841. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  184842. props[prop].propValueSize = sizeof (trueBool);
  184843. props[prop].propValueAddress = &trueBool;
  184844. ++prop;
  184845. Boolean isActive = true;
  184846. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  184847. props[prop].propID = kQTNewMoviePropertyID_Active;
  184848. props[prop].propValueSize = sizeof (isActive);
  184849. props[prop].propValueAddress = &isActive;
  184850. ++prop;
  184851. MacSetPort (0);
  184852. jassert (prop <= 5);
  184853. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  184854. return err == noErr;
  184855. }
  184856. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  184857. {
  184858. if (input == 0)
  184859. return false;
  184860. dataHandle = 0;
  184861. bool ok = false;
  184862. QTNewMoviePropertyElement props[5];
  184863. zeromem (props, sizeof (props));
  184864. int prop = 0;
  184865. DataReferenceRecord dr;
  184866. props[prop].propClass = kQTPropertyClass_DataLocation;
  184867. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  184868. props[prop].propValueSize = sizeof (dr);
  184869. props[prop].propValueAddress = (void*) &dr;
  184870. ++prop;
  184871. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  184872. if (fin != 0)
  184873. {
  184874. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  184875. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  184876. &dr.dataRef, &dr.dataRefType);
  184877. ok = openMovie (props, prop, movie);
  184878. DisposeHandle (dr.dataRef);
  184879. CFRelease (filePath);
  184880. }
  184881. else
  184882. {
  184883. // sanity-check because this currently needs to load the whole stream into memory..
  184884. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  184885. dataHandle = NewHandle ((Size) input->getTotalLength());
  184886. HLock (dataHandle);
  184887. // read the entire stream into memory - this is a pain, but can't get it to work
  184888. // properly using a custom callback to supply the data.
  184889. input->read (*dataHandle, (int) input->getTotalLength());
  184890. HUnlock (dataHandle);
  184891. // different types to get QT to try. (We should really be a bit smarter here by
  184892. // working out in advance which one the stream contains, rather than just trying
  184893. // each one)
  184894. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  184895. "\04.avi", "\04.m4a" };
  184896. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  184897. {
  184898. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  184899. dr.dataRefType = HandleDataHandlerSubType;
  184900. ok = openMovie (props, prop, movie);
  184901. DisposeHandle (dr.dataRef);
  184902. }
  184903. }
  184904. return ok;
  184905. }
  184906. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  184907. const bool isControllerVisible)
  184908. {
  184909. const bool ok = loadMovie (static_cast <InputStream*> (movieFile_.createInputStream()), isControllerVisible);
  184910. movieFile = movieFile_;
  184911. return ok;
  184912. }
  184913. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  184914. const bool isControllerVisible)
  184915. {
  184916. return loadMovie (static_cast <InputStream*> (movieURL.createInputStream (false)), isControllerVisible);
  184917. }
  184918. void QuickTimeMovieComponent::goToStart()
  184919. {
  184920. setPosition (0.0);
  184921. }
  184922. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  184923. const RectanglePlacement& placement)
  184924. {
  184925. int normalWidth, normalHeight;
  184926. getMovieNormalSize (normalWidth, normalHeight);
  184927. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  184928. {
  184929. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  184930. placement.applyTo (x, y, w, h,
  184931. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  184932. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  184933. if (w > 0 && h > 0)
  184934. {
  184935. setBounds (roundToInt (x), roundToInt (y),
  184936. roundToInt (w), roundToInt (h));
  184937. }
  184938. }
  184939. else
  184940. {
  184941. setBounds (spaceToFitWithin);
  184942. }
  184943. }
  184944. #endif
  184945. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184946. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  184947. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184948. // compiled on its own).
  184949. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  184950. class WebBrowserComponentInternal : public ActiveXControlComponent
  184951. {
  184952. public:
  184953. WebBrowserComponentInternal()
  184954. : browser (0),
  184955. connectionPoint (0),
  184956. adviseCookie (0)
  184957. {
  184958. }
  184959. ~WebBrowserComponentInternal()
  184960. {
  184961. if (connectionPoint != 0)
  184962. connectionPoint->Unadvise (adviseCookie);
  184963. if (browser != 0)
  184964. browser->Release();
  184965. }
  184966. void createBrowser()
  184967. {
  184968. createControl (&CLSID_WebBrowser);
  184969. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  184970. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  184971. if (connectionPointContainer != 0)
  184972. {
  184973. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  184974. &connectionPoint);
  184975. if (connectionPoint != 0)
  184976. {
  184977. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  184978. jassert (owner != 0);
  184979. EventHandler* handler = new EventHandler (owner);
  184980. connectionPoint->Advise (handler, &adviseCookie);
  184981. }
  184982. }
  184983. }
  184984. void goToURL (const String& url,
  184985. const StringArray* headers,
  184986. const MemoryBlock* postData)
  184987. {
  184988. if (browser != 0)
  184989. {
  184990. LPSAFEARRAY sa = 0;
  184991. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  184992. VariantInit (&flags);
  184993. VariantInit (&frame);
  184994. VariantInit (&postDataVar);
  184995. VariantInit (&headersVar);
  184996. if (headers != 0)
  184997. {
  184998. V_VT (&headersVar) = VT_BSTR;
  184999. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  185000. }
  185001. if (postData != 0 && postData->getSize() > 0)
  185002. {
  185003. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  185004. if (sa != 0)
  185005. {
  185006. void* data = 0;
  185007. SafeArrayAccessData (sa, &data);
  185008. jassert (data != 0);
  185009. if (data != 0)
  185010. {
  185011. postData->copyTo (data, 0, postData->getSize());
  185012. SafeArrayUnaccessData (sa);
  185013. VARIANT postDataVar2;
  185014. VariantInit (&postDataVar2);
  185015. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  185016. V_ARRAY (&postDataVar2) = sa;
  185017. postDataVar = postDataVar2;
  185018. }
  185019. }
  185020. }
  185021. browser->Navigate ((BSTR) (const OLECHAR*) url,
  185022. &flags, &frame,
  185023. &postDataVar, &headersVar);
  185024. if (sa != 0)
  185025. SafeArrayDestroy (sa);
  185026. VariantClear (&flags);
  185027. VariantClear (&frame);
  185028. VariantClear (&postDataVar);
  185029. VariantClear (&headersVar);
  185030. }
  185031. }
  185032. IWebBrowser2* browser;
  185033. juce_UseDebuggingNewOperator
  185034. private:
  185035. IConnectionPoint* connectionPoint;
  185036. DWORD adviseCookie;
  185037. class EventHandler : public IDispatch,
  185038. public ComponentMovementWatcher
  185039. {
  185040. public:
  185041. EventHandler (WebBrowserComponent* owner_)
  185042. : ComponentMovementWatcher (owner_),
  185043. owner (owner_),
  185044. refCount (0)
  185045. {
  185046. }
  185047. ~EventHandler()
  185048. {
  185049. }
  185050. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185051. {
  185052. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  185053. {
  185054. AddRef();
  185055. *result = this;
  185056. return S_OK;
  185057. }
  185058. *result = 0;
  185059. return E_NOINTERFACE;
  185060. }
  185061. ULONG __stdcall AddRef() { return ++refCount; }
  185062. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  185063. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  185064. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  185065. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  185066. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  185067. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185068. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185069. UINT __RPC_FAR* /*puArgErr*/)
  185070. {
  185071. switch (dispIdMember)
  185072. {
  185073. case DISPID_BEFORENAVIGATE2:
  185074. {
  185075. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185076. String url;
  185077. if ((vurl->vt & VT_BYREF) != 0)
  185078. url = *vurl->pbstrVal;
  185079. else
  185080. url = vurl->bstrVal;
  185081. *pDispParams->rgvarg->pboolVal
  185082. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185083. : VARIANT_TRUE;
  185084. return S_OK;
  185085. }
  185086. default:
  185087. break;
  185088. }
  185089. return E_NOTIMPL;
  185090. }
  185091. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185092. void componentPeerChanged() {}
  185093. void componentVisibilityChanged (Component&)
  185094. {
  185095. owner->visibilityChanged();
  185096. }
  185097. juce_UseDebuggingNewOperator
  185098. private:
  185099. WebBrowserComponent* const owner;
  185100. int refCount;
  185101. EventHandler (const EventHandler&);
  185102. EventHandler& operator= (const EventHandler&);
  185103. };
  185104. };
  185105. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185106. : browser (0),
  185107. blankPageShown (false),
  185108. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185109. {
  185110. setOpaque (true);
  185111. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185112. }
  185113. WebBrowserComponent::~WebBrowserComponent()
  185114. {
  185115. delete browser;
  185116. }
  185117. void WebBrowserComponent::goToURL (const String& url,
  185118. const StringArray* headers,
  185119. const MemoryBlock* postData)
  185120. {
  185121. lastURL = url;
  185122. lastHeaders.clear();
  185123. if (headers != 0)
  185124. lastHeaders = *headers;
  185125. lastPostData.setSize (0);
  185126. if (postData != 0)
  185127. lastPostData = *postData;
  185128. blankPageShown = false;
  185129. browser->goToURL (url, headers, postData);
  185130. }
  185131. void WebBrowserComponent::stop()
  185132. {
  185133. if (browser->browser != 0)
  185134. browser->browser->Stop();
  185135. }
  185136. void WebBrowserComponent::goBack()
  185137. {
  185138. lastURL = String::empty;
  185139. blankPageShown = false;
  185140. if (browser->browser != 0)
  185141. browser->browser->GoBack();
  185142. }
  185143. void WebBrowserComponent::goForward()
  185144. {
  185145. lastURL = String::empty;
  185146. if (browser->browser != 0)
  185147. browser->browser->GoForward();
  185148. }
  185149. void WebBrowserComponent::refresh()
  185150. {
  185151. if (browser->browser != 0)
  185152. browser->browser->Refresh();
  185153. }
  185154. void WebBrowserComponent::paint (Graphics& g)
  185155. {
  185156. if (browser->browser == 0)
  185157. g.fillAll (Colours::white);
  185158. }
  185159. void WebBrowserComponent::checkWindowAssociation()
  185160. {
  185161. if (isShowing())
  185162. {
  185163. if (browser->browser == 0 && getPeer() != 0)
  185164. {
  185165. browser->createBrowser();
  185166. reloadLastURL();
  185167. }
  185168. else
  185169. {
  185170. if (blankPageShown)
  185171. goBack();
  185172. }
  185173. }
  185174. else
  185175. {
  185176. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185177. {
  185178. // when the component becomes invisible, some stuff like flash
  185179. // carries on playing audio, so we need to force it onto a blank
  185180. // page to avoid this..
  185181. blankPageShown = true;
  185182. browser->goToURL ("about:blank", 0, 0);
  185183. }
  185184. }
  185185. }
  185186. void WebBrowserComponent::reloadLastURL()
  185187. {
  185188. if (lastURL.isNotEmpty())
  185189. {
  185190. goToURL (lastURL, &lastHeaders, &lastPostData);
  185191. lastURL = String::empty;
  185192. }
  185193. }
  185194. void WebBrowserComponent::parentHierarchyChanged()
  185195. {
  185196. checkWindowAssociation();
  185197. }
  185198. void WebBrowserComponent::resized()
  185199. {
  185200. browser->setSize (getWidth(), getHeight());
  185201. }
  185202. void WebBrowserComponent::visibilityChanged()
  185203. {
  185204. checkWindowAssociation();
  185205. }
  185206. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185207. {
  185208. return true;
  185209. }
  185210. #endif
  185211. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185212. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185213. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185214. // compiled on its own).
  185215. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185216. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185217. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185218. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185219. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185220. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185221. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185222. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185223. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185224. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185225. #define WGL_ACCELERATION_ARB 0x2003
  185226. #define WGL_SWAP_METHOD_ARB 0x2007
  185227. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185228. #define WGL_PIXEL_TYPE_ARB 0x2013
  185229. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185230. #define WGL_COLOR_BITS_ARB 0x2014
  185231. #define WGL_RED_BITS_ARB 0x2015
  185232. #define WGL_GREEN_BITS_ARB 0x2017
  185233. #define WGL_BLUE_BITS_ARB 0x2019
  185234. #define WGL_ALPHA_BITS_ARB 0x201B
  185235. #define WGL_DEPTH_BITS_ARB 0x2022
  185236. #define WGL_STENCIL_BITS_ARB 0x2023
  185237. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185238. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185239. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185240. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185241. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185242. #define WGL_STEREO_ARB 0x2012
  185243. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185244. #define WGL_SAMPLES_ARB 0x2042
  185245. #define WGL_TYPE_RGBA_ARB 0x202B
  185246. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185247. {
  185248. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185249. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185250. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185251. else
  185252. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185253. }
  185254. class WindowedGLContext : public OpenGLContext
  185255. {
  185256. public:
  185257. WindowedGLContext (Component* const component_,
  185258. HGLRC contextToShareWith,
  185259. const OpenGLPixelFormat& pixelFormat)
  185260. : renderContext (0),
  185261. nativeWindow (0),
  185262. dc (0),
  185263. component (component_)
  185264. {
  185265. jassert (component != 0);
  185266. createNativeWindow();
  185267. // Use a default pixel format that should be supported everywhere
  185268. PIXELFORMATDESCRIPTOR pfd;
  185269. zerostruct (pfd);
  185270. pfd.nSize = sizeof (pfd);
  185271. pfd.nVersion = 1;
  185272. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185273. pfd.iPixelType = PFD_TYPE_RGBA;
  185274. pfd.cColorBits = 24;
  185275. pfd.cDepthBits = 16;
  185276. const int format = ChoosePixelFormat (dc, &pfd);
  185277. if (format != 0)
  185278. SetPixelFormat (dc, format, &pfd);
  185279. renderContext = wglCreateContext (dc);
  185280. makeActive();
  185281. setPixelFormat (pixelFormat);
  185282. if (contextToShareWith != 0 && renderContext != 0)
  185283. wglShareLists (contextToShareWith, renderContext);
  185284. }
  185285. ~WindowedGLContext()
  185286. {
  185287. makeInactive();
  185288. wglDeleteContext (renderContext);
  185289. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185290. delete nativeWindow;
  185291. }
  185292. bool makeActive() const throw()
  185293. {
  185294. jassert (renderContext != 0);
  185295. return wglMakeCurrent (dc, renderContext) != 0;
  185296. }
  185297. bool makeInactive() const throw()
  185298. {
  185299. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185300. }
  185301. bool isActive() const throw()
  185302. {
  185303. return wglGetCurrentContext() == renderContext;
  185304. }
  185305. const OpenGLPixelFormat getPixelFormat() const
  185306. {
  185307. OpenGLPixelFormat pf;
  185308. makeActive();
  185309. StringArray availableExtensions;
  185310. getWglExtensions (dc, availableExtensions);
  185311. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185312. return pf;
  185313. }
  185314. void* getRawContext() const throw()
  185315. {
  185316. return renderContext;
  185317. }
  185318. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185319. {
  185320. makeActive();
  185321. PIXELFORMATDESCRIPTOR pfd;
  185322. zerostruct (pfd);
  185323. pfd.nSize = sizeof (pfd);
  185324. pfd.nVersion = 1;
  185325. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185326. pfd.iPixelType = PFD_TYPE_RGBA;
  185327. pfd.iLayerType = PFD_MAIN_PLANE;
  185328. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185329. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185330. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185331. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185332. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185333. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185334. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185335. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185336. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185337. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185338. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185339. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185340. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185341. int format = 0;
  185342. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185343. StringArray availableExtensions;
  185344. getWglExtensions (dc, availableExtensions);
  185345. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185346. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185347. {
  185348. int attributes[64];
  185349. int n = 0;
  185350. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185351. attributes[n++] = GL_TRUE;
  185352. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185353. attributes[n++] = GL_TRUE;
  185354. attributes[n++] = WGL_ACCELERATION_ARB;
  185355. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185356. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185357. attributes[n++] = GL_TRUE;
  185358. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185359. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185360. attributes[n++] = WGL_COLOR_BITS_ARB;
  185361. attributes[n++] = pfd.cColorBits;
  185362. attributes[n++] = WGL_RED_BITS_ARB;
  185363. attributes[n++] = pixelFormat.redBits;
  185364. attributes[n++] = WGL_GREEN_BITS_ARB;
  185365. attributes[n++] = pixelFormat.greenBits;
  185366. attributes[n++] = WGL_BLUE_BITS_ARB;
  185367. attributes[n++] = pixelFormat.blueBits;
  185368. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185369. attributes[n++] = pixelFormat.alphaBits;
  185370. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185371. attributes[n++] = pixelFormat.depthBufferBits;
  185372. if (pixelFormat.stencilBufferBits > 0)
  185373. {
  185374. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185375. attributes[n++] = pixelFormat.stencilBufferBits;
  185376. }
  185377. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185378. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185379. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185380. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185381. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185382. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185383. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185384. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185385. if (availableExtensions.contains ("WGL_ARB_multisample")
  185386. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185387. {
  185388. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185389. attributes[n++] = 1;
  185390. attributes[n++] = WGL_SAMPLES_ARB;
  185391. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185392. }
  185393. attributes[n++] = 0;
  185394. UINT formatsCount;
  185395. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185396. (void) ok;
  185397. jassert (ok);
  185398. }
  185399. else
  185400. {
  185401. format = ChoosePixelFormat (dc, &pfd);
  185402. }
  185403. if (format != 0)
  185404. {
  185405. makeInactive();
  185406. // win32 can't change the pixel format of a window, so need to delete the
  185407. // old one and create a new one..
  185408. jassert (nativeWindow != 0);
  185409. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185410. delete nativeWindow;
  185411. createNativeWindow();
  185412. if (SetPixelFormat (dc, format, &pfd))
  185413. {
  185414. wglDeleteContext (renderContext);
  185415. renderContext = wglCreateContext (dc);
  185416. jassert (renderContext != 0);
  185417. return renderContext != 0;
  185418. }
  185419. }
  185420. return false;
  185421. }
  185422. void updateWindowPosition (int x, int y, int w, int h, int)
  185423. {
  185424. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  185425. x, y, w, h,
  185426. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  185427. }
  185428. void repaint()
  185429. {
  185430. const Rectangle<int> bounds (nativeWindow->getBounds());
  185431. nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight());
  185432. }
  185433. void swapBuffers()
  185434. {
  185435. SwapBuffers (dc);
  185436. }
  185437. bool setSwapInterval (const int numFramesPerSwap)
  185438. {
  185439. makeActive();
  185440. StringArray availableExtensions;
  185441. getWglExtensions (dc, availableExtensions);
  185442. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185443. return availableExtensions.contains ("WGL_EXT_swap_control")
  185444. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185445. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185446. }
  185447. int getSwapInterval() const
  185448. {
  185449. makeActive();
  185450. StringArray availableExtensions;
  185451. getWglExtensions (dc, availableExtensions);
  185452. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  185453. if (availableExtensions.contains ("WGL_EXT_swap_control")
  185454. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  185455. return wglGetSwapIntervalEXT();
  185456. return 0;
  185457. }
  185458. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  185459. {
  185460. jassert (isActive());
  185461. StringArray availableExtensions;
  185462. getWglExtensions (dc, availableExtensions);
  185463. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185464. int numTypes = 0;
  185465. if (availableExtensions.contains("WGL_ARB_pixel_format")
  185466. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185467. {
  185468. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  185469. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  185470. jassertfalse
  185471. }
  185472. else
  185473. {
  185474. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  185475. }
  185476. OpenGLPixelFormat pf;
  185477. for (int i = 0; i < numTypes; ++i)
  185478. {
  185479. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  185480. {
  185481. bool alreadyListed = false;
  185482. for (int j = results.size(); --j >= 0;)
  185483. if (pf == *results.getUnchecked(j))
  185484. alreadyListed = true;
  185485. if (! alreadyListed)
  185486. results.add (new OpenGLPixelFormat (pf));
  185487. }
  185488. }
  185489. }
  185490. void* getNativeWindowHandle() const
  185491. {
  185492. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  185493. }
  185494. juce_UseDebuggingNewOperator
  185495. HGLRC renderContext;
  185496. private:
  185497. Win32ComponentPeer* nativeWindow;
  185498. Component* const component;
  185499. HDC dc;
  185500. void createNativeWindow()
  185501. {
  185502. nativeWindow = new Win32ComponentPeer (component, 0);
  185503. nativeWindow->dontRepaint = true;
  185504. nativeWindow->setVisible (true);
  185505. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  185506. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  185507. if (peer != 0)
  185508. {
  185509. SetParent (hwnd, (HWND) peer->getNativeHandle());
  185510. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  185511. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  185512. }
  185513. dc = GetDC (hwnd);
  185514. }
  185515. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  185516. OpenGLPixelFormat& result,
  185517. const StringArray& availableExtensions) const throw()
  185518. {
  185519. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185520. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185521. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185522. {
  185523. int attributes[32];
  185524. int numAttributes = 0;
  185525. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  185526. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  185527. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  185528. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  185529. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  185530. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  185531. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  185532. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  185533. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  185534. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  185535. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  185536. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  185537. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  185538. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  185539. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185540. if (availableExtensions.contains ("WGL_ARB_multisample"))
  185541. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  185542. int values[32];
  185543. zeromem (values, sizeof (values));
  185544. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  185545. {
  185546. int n = 0;
  185547. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  185548. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  185549. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  185550. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  185551. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  185552. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  185553. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  185554. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  185555. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  185556. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  185557. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  185558. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  185559. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  185560. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  185561. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  185562. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  185563. return isValidFormat;
  185564. }
  185565. else
  185566. {
  185567. jassertfalse
  185568. }
  185569. }
  185570. else
  185571. {
  185572. PIXELFORMATDESCRIPTOR pfd;
  185573. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  185574. {
  185575. result.redBits = pfd.cRedBits;
  185576. result.greenBits = pfd.cGreenBits;
  185577. result.blueBits = pfd.cBlueBits;
  185578. result.alphaBits = pfd.cAlphaBits;
  185579. result.depthBufferBits = pfd.cDepthBits;
  185580. result.stencilBufferBits = pfd.cStencilBits;
  185581. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  185582. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  185583. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  185584. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  185585. result.fullSceneAntiAliasingNumSamples = 0;
  185586. return true;
  185587. }
  185588. else
  185589. {
  185590. jassertfalse
  185591. }
  185592. }
  185593. return false;
  185594. }
  185595. WindowedGLContext (const WindowedGLContext&);
  185596. WindowedGLContext& operator= (const WindowedGLContext&);
  185597. };
  185598. OpenGLContext* OpenGLComponent::createContext()
  185599. {
  185600. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this,
  185601. contextToShareListsWith != 0 ? (HGLRC) contextToShareListsWith->getRawContext() : 0,
  185602. preferredPixelFormat));
  185603. return (c->renderContext != 0) ? c.release() : 0;
  185604. }
  185605. void* OpenGLComponent::getNativeWindowHandle() const
  185606. {
  185607. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle() : 0;
  185608. }
  185609. void juce_glViewport (const int w, const int h)
  185610. {
  185611. glViewport (0, 0, w, h);
  185612. }
  185613. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  185614. OwnedArray <OpenGLPixelFormat>& results)
  185615. {
  185616. Component tempComp;
  185617. {
  185618. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  185619. wc.makeActive();
  185620. wc.findAlternativeOpenGLPixelFormats (results);
  185621. }
  185622. }
  185623. #endif
  185624. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185625. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  185626. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185627. // compiled on its own).
  185628. #if JUCE_INCLUDED_FILE
  185629. #if JUCE_USE_CDREADER
  185630. namespace CDReaderHelpers
  185631. {
  185632. //***************************************************************************
  185633. // %%% TARGET STATUS VALUES %%%
  185634. //***************************************************************************
  185635. #define STATUS_GOOD 0x00 // Status Good
  185636. #define STATUS_CHKCOND 0x02 // Check Condition
  185637. #define STATUS_CONDMET 0x04 // Condition Met
  185638. #define STATUS_BUSY 0x08 // Busy
  185639. #define STATUS_INTERM 0x10 // Intermediate
  185640. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  185641. #define STATUS_RESCONF 0x18 // Reservation conflict
  185642. #define STATUS_COMTERM 0x22 // Command Terminated
  185643. #define STATUS_QFULL 0x28 // Queue full
  185644. //***************************************************************************
  185645. // %%% SCSI MISCELLANEOUS EQUATES %%%
  185646. //***************************************************************************
  185647. #define MAXLUN 7 // Maximum Logical Unit Id
  185648. #define MAXTARG 7 // Maximum Target Id
  185649. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  185650. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  185651. //***************************************************************************
  185652. // %%% Commands for all Device Types %%%
  185653. //***************************************************************************
  185654. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  185655. #define SCSI_COMPARE 0x39 // Compare (O)
  185656. #define SCSI_COPY 0x18 // Copy (O)
  185657. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  185658. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  185659. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  185660. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  185661. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  185662. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  185663. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  185664. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  185665. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  185666. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  185667. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  185668. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  185669. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  185670. //***************************************************************************
  185671. // %%% Commands Unique to Direct Access Devices %%%
  185672. //***************************************************************************
  185673. #define SCSI_COMPARE 0x39 // Compare (O)
  185674. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  185675. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  185676. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  185677. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  185678. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  185679. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  185680. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  185681. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  185682. #define SCSI_READ_LONG 0x3E // Read Long (O)
  185683. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  185684. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  185685. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  185686. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  185687. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  185688. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  185689. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  185690. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  185691. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  185692. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  185693. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  185694. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  185695. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  185696. #define SCSI_VERIFY 0x2F // Verify (O)
  185697. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  185698. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  185699. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  185700. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  185701. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  185702. //***************************************************************************
  185703. // %%% Commands Unique to Sequential Access Devices %%%
  185704. //***************************************************************************
  185705. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  185706. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  185707. #define SCSI_LOCATE 0x2B // Locate (O)
  185708. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  185709. #define SCSI_READ_POS 0x34 // Read Position (O)
  185710. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  185711. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  185712. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  185713. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  185714. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  185715. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  185716. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  185717. //***************************************************************************
  185718. // %%% Commands Unique to Printer Devices %%%
  185719. //***************************************************************************
  185720. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  185721. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  185722. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  185723. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  185724. //***************************************************************************
  185725. // %%% Commands Unique to Processor Devices %%%
  185726. //***************************************************************************
  185727. #define SCSI_RECEIVE 0x08 // Receive (O)
  185728. #define SCSI_SEND 0x0A // Send (O)
  185729. //***************************************************************************
  185730. // %%% Commands Unique to Write-Once Devices %%%
  185731. //***************************************************************************
  185732. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  185733. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  185734. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  185735. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  185736. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  185737. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  185738. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  185739. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  185740. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  185741. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  185742. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  185743. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  185744. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  185745. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  185746. //***************************************************************************
  185747. // %%% Commands Unique to CD-ROM Devices %%%
  185748. //***************************************************************************
  185749. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  185750. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  185751. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  185752. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  185753. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  185754. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  185755. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  185756. #define SCSI_READHEADER 0x44 // Read Header (O)
  185757. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  185758. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  185759. //***************************************************************************
  185760. // %%% Commands Unique to Scanner Devices %%%
  185761. //***************************************************************************
  185762. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  185763. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  185764. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  185765. #define SCSI_SCAN 0x1B // Scan (O)
  185766. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  185767. //***************************************************************************
  185768. // %%% Commands Unique to Optical Memory Devices %%%
  185769. //***************************************************************************
  185770. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  185771. //***************************************************************************
  185772. // %%% Commands Unique to Medium Changer Devices %%%
  185773. //***************************************************************************
  185774. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  185775. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  185776. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  185777. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  185778. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  185779. //***************************************************************************
  185780. // %%% Commands Unique to Communication Devices %%%
  185781. //***************************************************************************
  185782. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  185783. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  185784. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  185785. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  185786. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  185787. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  185788. //***************************************************************************
  185789. // %%% Request Sense Data Format %%%
  185790. //***************************************************************************
  185791. typedef struct {
  185792. BYTE ErrorCode; // Error Code (70H or 71H)
  185793. BYTE SegmentNum; // Number of current segment descriptor
  185794. BYTE SenseKey; // Sense Key(See bit definitions too)
  185795. BYTE InfoByte0; // Information MSB
  185796. BYTE InfoByte1; // Information MID
  185797. BYTE InfoByte2; // Information MID
  185798. BYTE InfoByte3; // Information LSB
  185799. BYTE AddSenLen; // Additional Sense Length
  185800. BYTE ComSpecInf0; // Command Specific Information MSB
  185801. BYTE ComSpecInf1; // Command Specific Information MID
  185802. BYTE ComSpecInf2; // Command Specific Information MID
  185803. BYTE ComSpecInf3; // Command Specific Information LSB
  185804. BYTE AddSenseCode; // Additional Sense Code
  185805. BYTE AddSenQual; // Additional Sense Code Qualifier
  185806. BYTE FieldRepUCode; // Field Replaceable Unit Code
  185807. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  185808. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  185809. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  185810. BYTE AddSenseBytes; // Additional Sense Bytes
  185811. } SENSE_DATA_FMT;
  185812. //***************************************************************************
  185813. // %%% REQUEST SENSE ERROR CODE %%%
  185814. //***************************************************************************
  185815. #define SERROR_CURRENT 0x70 // Current Errors
  185816. #define SERROR_DEFERED 0x71 // Deferred Errors
  185817. //***************************************************************************
  185818. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  185819. //***************************************************************************
  185820. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  185821. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  185822. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  185823. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  185824. //***************************************************************************
  185825. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  185826. //***************************************************************************
  185827. #define KEY_NOSENSE 0x00 // No Sense
  185828. #define KEY_RECERROR 0x01 // Recovered Error
  185829. #define KEY_NOTREADY 0x02 // Not Ready
  185830. #define KEY_MEDIUMERR 0x03 // Medium Error
  185831. #define KEY_HARDERROR 0x04 // Hardware Error
  185832. #define KEY_ILLGLREQ 0x05 // Illegal Request
  185833. #define KEY_UNITATT 0x06 // Unit Attention
  185834. #define KEY_DATAPROT 0x07 // Data Protect
  185835. #define KEY_BLANKCHK 0x08 // Blank Check
  185836. #define KEY_VENDSPEC 0x09 // Vendor Specific
  185837. #define KEY_COPYABORT 0x0A // Copy Abort
  185838. #define KEY_EQUAL 0x0C // Equal (Search)
  185839. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  185840. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  185841. #define KEY_RESERVED 0x0F // Reserved
  185842. //***************************************************************************
  185843. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  185844. //***************************************************************************
  185845. #define DTYPE_DASD 0x00 // Disk Device
  185846. #define DTYPE_SEQD 0x01 // Tape Device
  185847. #define DTYPE_PRNT 0x02 // Printer
  185848. #define DTYPE_PROC 0x03 // Processor
  185849. #define DTYPE_WORM 0x04 // Write-once read-multiple
  185850. #define DTYPE_CROM 0x05 // CD-ROM device
  185851. #define DTYPE_SCAN 0x06 // Scanner device
  185852. #define DTYPE_OPTI 0x07 // Optical memory device
  185853. #define DTYPE_JUKE 0x08 // Medium Changer device
  185854. #define DTYPE_COMM 0x09 // Communications device
  185855. #define DTYPE_RESL 0x0A // Reserved (low)
  185856. #define DTYPE_RESH 0x1E // Reserved (high)
  185857. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  185858. //***************************************************************************
  185859. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  185860. //***************************************************************************
  185861. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  185862. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  185863. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  185864. #define ANSI_RESLO 0x3 // Reserved (low)
  185865. #define ANSI_RESHI 0x7 // Reserved (high)
  185866. typedef struct
  185867. {
  185868. USHORT Length;
  185869. UCHAR ScsiStatus;
  185870. UCHAR PathId;
  185871. UCHAR TargetId;
  185872. UCHAR Lun;
  185873. UCHAR CdbLength;
  185874. UCHAR SenseInfoLength;
  185875. UCHAR DataIn;
  185876. ULONG DataTransferLength;
  185877. ULONG TimeOutValue;
  185878. ULONG DataBufferOffset;
  185879. ULONG SenseInfoOffset;
  185880. UCHAR Cdb[16];
  185881. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  185882. typedef struct
  185883. {
  185884. USHORT Length;
  185885. UCHAR ScsiStatus;
  185886. UCHAR PathId;
  185887. UCHAR TargetId;
  185888. UCHAR Lun;
  185889. UCHAR CdbLength;
  185890. UCHAR SenseInfoLength;
  185891. UCHAR DataIn;
  185892. ULONG DataTransferLength;
  185893. ULONG TimeOutValue;
  185894. PVOID DataBuffer;
  185895. ULONG SenseInfoOffset;
  185896. UCHAR Cdb[16];
  185897. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  185898. typedef struct
  185899. {
  185900. SCSI_PASS_THROUGH_DIRECT spt;
  185901. ULONG Filler;
  185902. UCHAR ucSenseBuf[32];
  185903. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  185904. typedef struct
  185905. {
  185906. ULONG Length;
  185907. UCHAR PortNumber;
  185908. UCHAR PathId;
  185909. UCHAR TargetId;
  185910. UCHAR Lun;
  185911. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  185912. #define METHOD_BUFFERED 0
  185913. #define METHOD_IN_DIRECT 1
  185914. #define METHOD_OUT_DIRECT 2
  185915. #define METHOD_NEITHER 3
  185916. #define FILE_ANY_ACCESS 0
  185917. #ifndef FILE_READ_ACCESS
  185918. #define FILE_READ_ACCESS (0x0001)
  185919. #endif
  185920. #ifndef FILE_WRITE_ACCESS
  185921. #define FILE_WRITE_ACCESS (0x0002)
  185922. #endif
  185923. #define IOCTL_SCSI_BASE 0x00000004
  185924. #define SCSI_IOCTL_DATA_OUT 0
  185925. #define SCSI_IOCTL_DATA_IN 1
  185926. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  185927. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  185928. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  185929. )
  185930. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185931. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  185932. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185933. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  185934. #define SENSE_LEN 14
  185935. #define SRB_DIR_SCSI 0x00
  185936. #define SRB_POSTING 0x01
  185937. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  185938. #define SRB_DIR_IN 0x08
  185939. #define SRB_DIR_OUT 0x10
  185940. #define SRB_EVENT_NOTIFY 0x40
  185941. #define RESIDUAL_COUNT_SUPPORTED 0x02
  185942. #define MAX_SRB_TIMEOUT 1080001u
  185943. #define DEFAULT_SRB_TIMEOUT 1080001u
  185944. #define SC_HA_INQUIRY 0x00
  185945. #define SC_GET_DEV_TYPE 0x01
  185946. #define SC_EXEC_SCSI_CMD 0x02
  185947. #define SC_ABORT_SRB 0x03
  185948. #define SC_RESET_DEV 0x04
  185949. #define SC_SET_HA_PARMS 0x05
  185950. #define SC_GET_DISK_INFO 0x06
  185951. #define SC_RESCAN_SCSI_BUS 0x07
  185952. #define SC_GETSET_TIMEOUTS 0x08
  185953. #define SS_PENDING 0x00
  185954. #define SS_COMP 0x01
  185955. #define SS_ABORTED 0x02
  185956. #define SS_ABORT_FAIL 0x03
  185957. #define SS_ERR 0x04
  185958. #define SS_INVALID_CMD 0x80
  185959. #define SS_INVALID_HA 0x81
  185960. #define SS_NO_DEVICE 0x82
  185961. #define SS_INVALID_SRB 0xE0
  185962. #define SS_OLD_MANAGER 0xE1
  185963. #define SS_BUFFER_ALIGN 0xE1
  185964. #define SS_ILLEGAL_MODE 0xE2
  185965. #define SS_NO_ASPI 0xE3
  185966. #define SS_FAILED_INIT 0xE4
  185967. #define SS_ASPI_IS_BUSY 0xE5
  185968. #define SS_BUFFER_TO_BIG 0xE6
  185969. #define SS_BUFFER_TOO_BIG 0xE6
  185970. #define SS_MISMATCHED_COMPONENTS 0xE7
  185971. #define SS_NO_ADAPTERS 0xE8
  185972. #define SS_INSUFFICIENT_RESOURCES 0xE9
  185973. #define SS_ASPI_IS_SHUTDOWN 0xEA
  185974. #define SS_BAD_INSTALL 0xEB
  185975. #define HASTAT_OK 0x00
  185976. #define HASTAT_SEL_TO 0x11
  185977. #define HASTAT_DO_DU 0x12
  185978. #define HASTAT_BUS_FREE 0x13
  185979. #define HASTAT_PHASE_ERR 0x14
  185980. #define HASTAT_TIMEOUT 0x09
  185981. #define HASTAT_COMMAND_TIMEOUT 0x0B
  185982. #define HASTAT_MESSAGE_REJECT 0x0D
  185983. #define HASTAT_BUS_RESET 0x0E
  185984. #define HASTAT_PARITY_ERROR 0x0F
  185985. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  185986. #define PACKED
  185987. #pragma pack(1)
  185988. typedef struct
  185989. {
  185990. BYTE SRB_Cmd;
  185991. BYTE SRB_Status;
  185992. BYTE SRB_HaID;
  185993. BYTE SRB_Flags;
  185994. DWORD SRB_Hdr_Rsvd;
  185995. BYTE HA_Count;
  185996. BYTE HA_SCSI_ID;
  185997. BYTE HA_ManagerId[16];
  185998. BYTE HA_Identifier[16];
  185999. BYTE HA_Unique[16];
  186000. WORD HA_Rsvd1;
  186001. BYTE pad[20];
  186002. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  186003. typedef struct
  186004. {
  186005. BYTE SRB_Cmd;
  186006. BYTE SRB_Status;
  186007. BYTE SRB_HaID;
  186008. BYTE SRB_Flags;
  186009. DWORD SRB_Hdr_Rsvd;
  186010. BYTE SRB_Target;
  186011. BYTE SRB_Lun;
  186012. BYTE SRB_DeviceType;
  186013. BYTE SRB_Rsvd1;
  186014. BYTE pad[68];
  186015. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  186016. typedef struct
  186017. {
  186018. BYTE SRB_Cmd;
  186019. BYTE SRB_Status;
  186020. BYTE SRB_HaID;
  186021. BYTE SRB_Flags;
  186022. DWORD SRB_Hdr_Rsvd;
  186023. BYTE SRB_Target;
  186024. BYTE SRB_Lun;
  186025. WORD SRB_Rsvd1;
  186026. DWORD SRB_BufLen;
  186027. BYTE FAR *SRB_BufPointer;
  186028. BYTE SRB_SenseLen;
  186029. BYTE SRB_CDBLen;
  186030. BYTE SRB_HaStat;
  186031. BYTE SRB_TargStat;
  186032. VOID FAR *SRB_PostProc;
  186033. BYTE SRB_Rsvd2[20];
  186034. BYTE CDBByte[16];
  186035. BYTE SenseArea[SENSE_LEN+2];
  186036. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  186037. typedef struct
  186038. {
  186039. BYTE SRB_Cmd;
  186040. BYTE SRB_Status;
  186041. BYTE SRB_HaId;
  186042. BYTE SRB_Flags;
  186043. DWORD SRB_Hdr_Rsvd;
  186044. } PACKED SRB, *PSRB, FAR *LPSRB;
  186045. #pragma pack()
  186046. struct CDDeviceInfo
  186047. {
  186048. char vendor[9];
  186049. char productId[17];
  186050. char rev[5];
  186051. char vendorSpec[21];
  186052. BYTE ha;
  186053. BYTE tgt;
  186054. BYTE lun;
  186055. char scsiDriveLetter; // will be 0 if not using scsi
  186056. };
  186057. class CDReadBuffer
  186058. {
  186059. public:
  186060. int startFrame;
  186061. int numFrames;
  186062. int dataStartOffset;
  186063. int dataLength;
  186064. BYTE* buffer;
  186065. int bufferSize;
  186066. int index;
  186067. bool wantsIndex;
  186068. CDReadBuffer (const int numberOfFrames)
  186069. : startFrame (0),
  186070. numFrames (0),
  186071. dataStartOffset (0),
  186072. dataLength (0),
  186073. index (0),
  186074. wantsIndex (false)
  186075. {
  186076. bufferSize = 2352 * numberOfFrames;
  186077. buffer = (BYTE*) juce_malloc (bufferSize);
  186078. }
  186079. ~CDReadBuffer()
  186080. {
  186081. juce_free (buffer);
  186082. }
  186083. bool isZero() const
  186084. {
  186085. BYTE* p = buffer + dataStartOffset;
  186086. for (int i = dataLength; --i >= 0;)
  186087. if (*p++ != 0)
  186088. return false;
  186089. return true;
  186090. }
  186091. };
  186092. class CDDeviceHandle;
  186093. class CDController
  186094. {
  186095. public:
  186096. CDController();
  186097. virtual ~CDController();
  186098. virtual bool read (CDReadBuffer* t) = 0;
  186099. virtual void shutDown();
  186100. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186101. int getLastIndex();
  186102. public:
  186103. bool initialised;
  186104. CDDeviceHandle* deviceInfo;
  186105. int framesToCheck, framesOverlap;
  186106. void prepare (SRB_ExecSCSICmd& s);
  186107. void perform (SRB_ExecSCSICmd& s);
  186108. void setPaused (bool paused);
  186109. };
  186110. #pragma pack(1)
  186111. struct TOCTRACK
  186112. {
  186113. BYTE rsvd;
  186114. BYTE ADR;
  186115. BYTE trackNumber;
  186116. BYTE rsvd2;
  186117. BYTE addr[4];
  186118. };
  186119. struct TOC
  186120. {
  186121. WORD tocLen;
  186122. BYTE firstTrack;
  186123. BYTE lastTrack;
  186124. TOCTRACK tracks[100];
  186125. };
  186126. #pragma pack()
  186127. enum
  186128. {
  186129. READTYPE_ANY = 0,
  186130. READTYPE_ATAPI1 = 1,
  186131. READTYPE_ATAPI2 = 2,
  186132. READTYPE_READ6 = 3,
  186133. READTYPE_READ10 = 4,
  186134. READTYPE_READ_D8 = 5,
  186135. READTYPE_READ_D4 = 6,
  186136. READTYPE_READ_D4_1 = 7,
  186137. READTYPE_READ10_2 = 8
  186138. };
  186139. class CDDeviceHandle
  186140. {
  186141. public:
  186142. CDDeviceHandle (const CDDeviceInfo* const device)
  186143. : scsiHandle (0),
  186144. readType (READTYPE_ANY),
  186145. controller (0)
  186146. {
  186147. memcpy (&info, device, sizeof (info));
  186148. }
  186149. ~CDDeviceHandle()
  186150. {
  186151. if (controller != 0)
  186152. {
  186153. controller->shutDown();
  186154. controller = 0;
  186155. }
  186156. if (scsiHandle != 0)
  186157. CloseHandle (scsiHandle);
  186158. }
  186159. bool readTOC (TOC* lpToc, bool useMSF);
  186160. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186161. void openDrawer (bool shouldBeOpen);
  186162. CDDeviceInfo info;
  186163. HANDLE scsiHandle;
  186164. BYTE readType;
  186165. private:
  186166. ScopedPointer<CDController> controller;
  186167. bool testController (const int readType,
  186168. CDController* const newController,
  186169. CDReadBuffer* const bufferToUse);
  186170. };
  186171. DWORD (*fGetASPI32SupportInfo)(void);
  186172. DWORD (*fSendASPI32Command)(LPSRB);
  186173. static HINSTANCE winAspiLib = 0;
  186174. static bool usingScsi = false;
  186175. static bool initialised = false;
  186176. static bool InitialiseCDRipper()
  186177. {
  186178. if (! initialised)
  186179. {
  186180. initialised = true;
  186181. OSVERSIONINFO info;
  186182. info.dwOSVersionInfoSize = sizeof (info);
  186183. GetVersionEx (&info);
  186184. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186185. if (! usingScsi)
  186186. {
  186187. fGetASPI32SupportInfo = 0;
  186188. fSendASPI32Command = 0;
  186189. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186190. if (winAspiLib != 0)
  186191. {
  186192. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186193. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186194. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186195. return false;
  186196. }
  186197. else
  186198. {
  186199. usingScsi = true;
  186200. }
  186201. }
  186202. }
  186203. return true;
  186204. }
  186205. static void DeinitialiseCDRipper()
  186206. {
  186207. if (winAspiLib != 0)
  186208. {
  186209. fGetASPI32SupportInfo = 0;
  186210. fSendASPI32Command = 0;
  186211. FreeLibrary (winAspiLib);
  186212. winAspiLib = 0;
  186213. }
  186214. initialised = false;
  186215. }
  186216. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186217. {
  186218. TCHAR devicePath[] = { '\\', '\\', '.', '\\', driveLetter, ':', 0, 0 };
  186219. OSVERSIONINFO info;
  186220. info.dwOSVersionInfoSize = sizeof (info);
  186221. GetVersionEx (&info);
  186222. DWORD flags = GENERIC_READ;
  186223. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186224. flags = GENERIC_READ | GENERIC_WRITE;
  186225. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186226. if (h == INVALID_HANDLE_VALUE)
  186227. {
  186228. flags ^= GENERIC_WRITE;
  186229. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186230. }
  186231. return h;
  186232. }
  186233. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186234. const char driveLetter,
  186235. HANDLE& deviceHandle,
  186236. const bool retryOnFailure = true)
  186237. {
  186238. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186239. zerostruct (s);
  186240. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186241. s.spt.CdbLength = srb->SRB_CDBLen;
  186242. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186243. ? SCSI_IOCTL_DATA_IN
  186244. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186245. ? SCSI_IOCTL_DATA_OUT
  186246. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186247. s.spt.DataTransferLength = srb->SRB_BufLen;
  186248. s.spt.TimeOutValue = 5;
  186249. s.spt.DataBuffer = srb->SRB_BufPointer;
  186250. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186251. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186252. srb->SRB_Status = SS_ERR;
  186253. srb->SRB_TargStat = 0x0004;
  186254. DWORD bytesReturned = 0;
  186255. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186256. &s, sizeof (s),
  186257. &s, sizeof (s),
  186258. &bytesReturned, 0) != 0)
  186259. {
  186260. srb->SRB_Status = SS_COMP;
  186261. }
  186262. else if (retryOnFailure)
  186263. {
  186264. const DWORD error = GetLastError();
  186265. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186266. {
  186267. if (error != ERROR_INVALID_HANDLE)
  186268. CloseHandle (deviceHandle);
  186269. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186270. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186271. }
  186272. }
  186273. return srb->SRB_Status;
  186274. }
  186275. // Controller types..
  186276. class ControllerType1 : public CDController
  186277. {
  186278. public:
  186279. ControllerType1() {}
  186280. ~ControllerType1() {}
  186281. bool read (CDReadBuffer* rb)
  186282. {
  186283. if (rb->numFrames * 2352 > rb->bufferSize)
  186284. return false;
  186285. SRB_ExecSCSICmd s;
  186286. prepare (s);
  186287. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186288. s.SRB_BufLen = rb->bufferSize;
  186289. s.SRB_BufPointer = rb->buffer;
  186290. s.SRB_CDBLen = 12;
  186291. s.CDBByte[0] = 0xBE;
  186292. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186293. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186294. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186295. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186296. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186297. perform (s);
  186298. if (s.SRB_Status != SS_COMP)
  186299. return false;
  186300. rb->dataLength = rb->numFrames * 2352;
  186301. rb->dataStartOffset = 0;
  186302. return true;
  186303. }
  186304. };
  186305. class ControllerType2 : public CDController
  186306. {
  186307. public:
  186308. ControllerType2() {}
  186309. ~ControllerType2() {}
  186310. void shutDown()
  186311. {
  186312. if (initialised)
  186313. {
  186314. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186315. SRB_ExecSCSICmd s;
  186316. prepare (s);
  186317. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186318. s.SRB_BufLen = 0x0C;
  186319. s.SRB_BufPointer = bufPointer;
  186320. s.SRB_CDBLen = 6;
  186321. s.CDBByte[0] = 0x15;
  186322. s.CDBByte[4] = 0x0C;
  186323. perform (s);
  186324. }
  186325. }
  186326. bool init()
  186327. {
  186328. SRB_ExecSCSICmd s;
  186329. s.SRB_Status = SS_ERR;
  186330. if (deviceInfo->readType == READTYPE_READ10_2)
  186331. {
  186332. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186333. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186334. for (int i = 0; i < 2; ++i)
  186335. {
  186336. prepare (s);
  186337. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186338. s.SRB_BufLen = 0x14;
  186339. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186340. s.SRB_CDBLen = 6;
  186341. s.CDBByte[0] = 0x15;
  186342. s.CDBByte[1] = 0x10;
  186343. s.CDBByte[4] = 0x14;
  186344. perform (s);
  186345. if (s.SRB_Status != SS_COMP)
  186346. return false;
  186347. }
  186348. }
  186349. else
  186350. {
  186351. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186352. prepare (s);
  186353. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186354. s.SRB_BufLen = 0x0C;
  186355. s.SRB_BufPointer = bufPointer;
  186356. s.SRB_CDBLen = 6;
  186357. s.CDBByte[0] = 0x15;
  186358. s.CDBByte[4] = 0x0C;
  186359. perform (s);
  186360. }
  186361. return s.SRB_Status == SS_COMP;
  186362. }
  186363. bool read (CDReadBuffer* rb)
  186364. {
  186365. if (rb->numFrames * 2352 > rb->bufferSize)
  186366. return false;
  186367. if (!initialised)
  186368. {
  186369. initialised = init();
  186370. if (!initialised)
  186371. return false;
  186372. }
  186373. SRB_ExecSCSICmd s;
  186374. prepare (s);
  186375. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186376. s.SRB_BufLen = rb->bufferSize;
  186377. s.SRB_BufPointer = rb->buffer;
  186378. s.SRB_CDBLen = 10;
  186379. s.CDBByte[0] = 0x28;
  186380. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186381. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186382. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186383. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186384. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186385. perform (s);
  186386. if (s.SRB_Status != SS_COMP)
  186387. return false;
  186388. rb->dataLength = rb->numFrames * 2352;
  186389. rb->dataStartOffset = 0;
  186390. return true;
  186391. }
  186392. };
  186393. class ControllerType3 : public CDController
  186394. {
  186395. public:
  186396. ControllerType3() {}
  186397. ~ControllerType3() {}
  186398. bool read (CDReadBuffer* rb)
  186399. {
  186400. if (rb->numFrames * 2352 > rb->bufferSize)
  186401. return false;
  186402. if (!initialised)
  186403. {
  186404. setPaused (false);
  186405. initialised = true;
  186406. }
  186407. SRB_ExecSCSICmd s;
  186408. prepare (s);
  186409. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186410. s.SRB_BufLen = rb->numFrames * 2352;
  186411. s.SRB_BufPointer = rb->buffer;
  186412. s.SRB_CDBLen = 12;
  186413. s.CDBByte[0] = 0xD8;
  186414. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186415. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186416. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186417. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  186418. perform (s);
  186419. if (s.SRB_Status != SS_COMP)
  186420. return false;
  186421. rb->dataLength = rb->numFrames * 2352;
  186422. rb->dataStartOffset = 0;
  186423. return true;
  186424. }
  186425. };
  186426. class ControllerType4 : public CDController
  186427. {
  186428. public:
  186429. ControllerType4() {}
  186430. ~ControllerType4() {}
  186431. bool selectD4Mode()
  186432. {
  186433. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  186434. SRB_ExecSCSICmd s;
  186435. prepare (s);
  186436. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186437. s.SRB_CDBLen = 6;
  186438. s.SRB_BufLen = 12;
  186439. s.SRB_BufPointer = bufPointer;
  186440. s.CDBByte[0] = 0x15;
  186441. s.CDBByte[1] = 0x10;
  186442. s.CDBByte[4] = 0x08;
  186443. perform (s);
  186444. return s.SRB_Status == SS_COMP;
  186445. }
  186446. bool read (CDReadBuffer* rb)
  186447. {
  186448. if (rb->numFrames * 2352 > rb->bufferSize)
  186449. return false;
  186450. if (!initialised)
  186451. {
  186452. setPaused (true);
  186453. if (deviceInfo->readType == READTYPE_READ_D4_1)
  186454. selectD4Mode();
  186455. initialised = true;
  186456. }
  186457. SRB_ExecSCSICmd s;
  186458. prepare (s);
  186459. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186460. s.SRB_BufLen = rb->bufferSize;
  186461. s.SRB_BufPointer = rb->buffer;
  186462. s.SRB_CDBLen = 10;
  186463. s.CDBByte[0] = 0xD4;
  186464. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186465. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186466. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186467. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186468. perform (s);
  186469. if (s.SRB_Status != SS_COMP)
  186470. return false;
  186471. rb->dataLength = rb->numFrames * 2352;
  186472. rb->dataStartOffset = 0;
  186473. return true;
  186474. }
  186475. };
  186476. CDController::CDController() : initialised (false)
  186477. {
  186478. }
  186479. CDController::~CDController()
  186480. {
  186481. }
  186482. void CDController::prepare (SRB_ExecSCSICmd& s)
  186483. {
  186484. zerostruct (s);
  186485. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186486. s.SRB_HaID = deviceInfo->info.ha;
  186487. s.SRB_Target = deviceInfo->info.tgt;
  186488. s.SRB_Lun = deviceInfo->info.lun;
  186489. s.SRB_SenseLen = SENSE_LEN;
  186490. }
  186491. void CDController::perform (SRB_ExecSCSICmd& s)
  186492. {
  186493. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186494. s.SRB_PostProc = (void*)event;
  186495. ResetEvent (event);
  186496. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  186497. deviceInfo->info.scsiDriveLetter,
  186498. deviceInfo->scsiHandle)
  186499. : fSendASPI32Command ((LPSRB)&s);
  186500. if (status == SS_PENDING)
  186501. WaitForSingleObject (event, 4000);
  186502. CloseHandle (event);
  186503. }
  186504. void CDController::setPaused (bool paused)
  186505. {
  186506. SRB_ExecSCSICmd s;
  186507. prepare (s);
  186508. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186509. s.SRB_CDBLen = 10;
  186510. s.CDBByte[0] = 0x4B;
  186511. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  186512. perform (s);
  186513. }
  186514. void CDController::shutDown()
  186515. {
  186516. }
  186517. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  186518. {
  186519. if (overlapBuffer != 0)
  186520. {
  186521. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  186522. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  186523. if (doJitter
  186524. && overlapBuffer->startFrame > 0
  186525. && overlapBuffer->numFrames > 0
  186526. && overlapBuffer->dataLength > 0)
  186527. {
  186528. const int numFrames = rb->numFrames;
  186529. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  186530. {
  186531. rb->startFrame -= framesOverlap;
  186532. if (framesToCheck < framesOverlap
  186533. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  186534. rb->numFrames += framesOverlap;
  186535. }
  186536. else
  186537. {
  186538. overlapBuffer->dataLength = 0;
  186539. overlapBuffer->startFrame = 0;
  186540. overlapBuffer->numFrames = 0;
  186541. }
  186542. }
  186543. if (! read (rb))
  186544. return false;
  186545. if (doJitter)
  186546. {
  186547. const int checkLen = framesToCheck * 2352;
  186548. const int maxToCheck = rb->dataLength - checkLen;
  186549. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  186550. return true;
  186551. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  186552. bool found = false;
  186553. for (int i = 0; i < maxToCheck; ++i)
  186554. {
  186555. if (!memcmp (p, rb->buffer + i, checkLen))
  186556. {
  186557. i += checkLen;
  186558. rb->dataStartOffset = i;
  186559. rb->dataLength -= i;
  186560. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  186561. found = true;
  186562. break;
  186563. }
  186564. }
  186565. rb->numFrames = rb->dataLength / 2352;
  186566. rb->dataLength = 2352 * rb->numFrames;
  186567. if (!found)
  186568. return false;
  186569. }
  186570. if (canDoJitter)
  186571. {
  186572. memcpy (overlapBuffer->buffer,
  186573. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  186574. 2352 * framesToCheck);
  186575. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  186576. overlapBuffer->numFrames = framesToCheck;
  186577. overlapBuffer->dataLength = 2352 * framesToCheck;
  186578. overlapBuffer->dataStartOffset = 0;
  186579. }
  186580. else
  186581. {
  186582. overlapBuffer->startFrame = 0;
  186583. overlapBuffer->numFrames = 0;
  186584. overlapBuffer->dataLength = 0;
  186585. }
  186586. return true;
  186587. }
  186588. else
  186589. {
  186590. return read (rb);
  186591. }
  186592. }
  186593. int CDController::getLastIndex()
  186594. {
  186595. char qdata[100];
  186596. SRB_ExecSCSICmd s;
  186597. prepare (s);
  186598. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186599. s.SRB_BufLen = sizeof (qdata);
  186600. s.SRB_BufPointer = (BYTE*)qdata;
  186601. s.SRB_CDBLen = 12;
  186602. s.CDBByte[0] = 0x42;
  186603. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186604. s.CDBByte[2] = 64;
  186605. s.CDBByte[3] = 1; // get current position
  186606. s.CDBByte[7] = 0;
  186607. s.CDBByte[8] = (BYTE)sizeof (qdata);
  186608. perform (s);
  186609. if (s.SRB_Status == SS_COMP)
  186610. return qdata[7];
  186611. return 0;
  186612. }
  186613. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  186614. {
  186615. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186616. SRB_ExecSCSICmd s;
  186617. zerostruct (s);
  186618. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186619. s.SRB_HaID = info.ha;
  186620. s.SRB_Target = info.tgt;
  186621. s.SRB_Lun = info.lun;
  186622. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186623. s.SRB_BufLen = 0x324;
  186624. s.SRB_BufPointer = (BYTE*)lpToc;
  186625. s.SRB_SenseLen = 0x0E;
  186626. s.SRB_CDBLen = 0x0A;
  186627. s.SRB_PostProc = (void*)event;
  186628. s.CDBByte[0] = 0x43;
  186629. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  186630. s.CDBByte[7] = 0x03;
  186631. s.CDBByte[8] = 0x24;
  186632. ResetEvent (event);
  186633. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186634. : fSendASPI32Command ((LPSRB)&s);
  186635. if (status == SS_PENDING)
  186636. WaitForSingleObject (event, 4000);
  186637. CloseHandle (event);
  186638. return (s.SRB_Status == SS_COMP);
  186639. }
  186640. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  186641. CDReadBuffer* const overlapBuffer)
  186642. {
  186643. if (controller == 0)
  186644. {
  186645. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  186646. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  186647. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  186648. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  186649. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  186650. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  186651. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  186652. }
  186653. buffer->index = 0;
  186654. if ((controller != 0)
  186655. && controller->readAudio (buffer, overlapBuffer))
  186656. {
  186657. if (buffer->wantsIndex)
  186658. buffer->index = controller->getLastIndex();
  186659. return true;
  186660. }
  186661. return false;
  186662. }
  186663. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  186664. {
  186665. if (shouldBeOpen)
  186666. {
  186667. if (controller != 0)
  186668. {
  186669. controller->shutDown();
  186670. controller = 0;
  186671. }
  186672. if (scsiHandle != 0)
  186673. {
  186674. CloseHandle (scsiHandle);
  186675. scsiHandle = 0;
  186676. }
  186677. }
  186678. SRB_ExecSCSICmd s;
  186679. zerostruct (s);
  186680. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186681. s.SRB_HaID = info.ha;
  186682. s.SRB_Target = info.tgt;
  186683. s.SRB_Lun = info.lun;
  186684. s.SRB_SenseLen = SENSE_LEN;
  186685. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186686. s.SRB_BufLen = 0;
  186687. s.SRB_BufPointer = 0;
  186688. s.SRB_CDBLen = 12;
  186689. s.CDBByte[0] = 0x1b;
  186690. s.CDBByte[1] = (BYTE)(info.lun << 5);
  186691. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  186692. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186693. s.SRB_PostProc = (void*)event;
  186694. ResetEvent (event);
  186695. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186696. : fSendASPI32Command ((LPSRB)&s);
  186697. if (status == SS_PENDING)
  186698. WaitForSingleObject (event, 4000);
  186699. CloseHandle (event);
  186700. }
  186701. bool CDDeviceHandle::testController (const int type,
  186702. CDController* const newController,
  186703. CDReadBuffer* const rb)
  186704. {
  186705. controller = newController;
  186706. readType = (BYTE)type;
  186707. controller->deviceInfo = this;
  186708. controller->framesToCheck = 1;
  186709. controller->framesOverlap = 3;
  186710. bool passed = false;
  186711. memset (rb->buffer, 0xcd, rb->bufferSize);
  186712. if (controller->read (rb))
  186713. {
  186714. passed = true;
  186715. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  186716. int wrong = 0;
  186717. for (int i = rb->dataLength / 4; --i >= 0;)
  186718. {
  186719. if (*p++ == (int) 0xcdcdcdcd)
  186720. {
  186721. if (++wrong == 4)
  186722. {
  186723. passed = false;
  186724. break;
  186725. }
  186726. }
  186727. else
  186728. {
  186729. wrong = 0;
  186730. }
  186731. }
  186732. }
  186733. if (! passed)
  186734. {
  186735. controller->shutDown();
  186736. controller = 0;
  186737. }
  186738. return passed;
  186739. }
  186740. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  186741. {
  186742. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186743. const int bufSize = 128;
  186744. BYTE buffer[bufSize];
  186745. zeromem (buffer, bufSize);
  186746. SRB_ExecSCSICmd s;
  186747. zerostruct (s);
  186748. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186749. s.SRB_HaID = ha;
  186750. s.SRB_Target = tgt;
  186751. s.SRB_Lun = lun;
  186752. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186753. s.SRB_BufLen = bufSize;
  186754. s.SRB_BufPointer = buffer;
  186755. s.SRB_SenseLen = SENSE_LEN;
  186756. s.SRB_CDBLen = 6;
  186757. s.SRB_PostProc = (void*)event;
  186758. s.CDBByte[0] = SCSI_INQUIRY;
  186759. s.CDBByte[4] = 100;
  186760. ResetEvent (event);
  186761. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  186762. WaitForSingleObject (event, 4000);
  186763. CloseHandle (event);
  186764. if (s.SRB_Status == SS_COMP)
  186765. {
  186766. memcpy (dev->vendor, &buffer[8], 8);
  186767. memcpy (dev->productId, &buffer[16], 16);
  186768. memcpy (dev->rev, &buffer[32], 4);
  186769. memcpy (dev->vendorSpec, &buffer[36], 20);
  186770. }
  186771. }
  186772. static int FindCDDevices (CDDeviceInfo* const list,
  186773. int maxItems)
  186774. {
  186775. int count = 0;
  186776. if (usingScsi)
  186777. {
  186778. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  186779. {
  186780. TCHAR drivePath[8];
  186781. drivePath[0] = driveLetter;
  186782. drivePath[1] = ':';
  186783. drivePath[2] = '\\';
  186784. drivePath[3] = 0;
  186785. if (GetDriveType (drivePath) == DRIVE_CDROM)
  186786. {
  186787. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  186788. if (h != INVALID_HANDLE_VALUE)
  186789. {
  186790. BYTE buffer[100], passThroughStruct[1024];
  186791. zeromem (buffer, sizeof (buffer));
  186792. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186793. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  186794. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  186795. p->spt.CdbLength = 6;
  186796. p->spt.SenseInfoLength = 24;
  186797. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  186798. p->spt.DataTransferLength = 100;
  186799. p->spt.TimeOutValue = 2;
  186800. p->spt.DataBuffer = buffer;
  186801. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186802. p->spt.Cdb[0] = 0x12;
  186803. p->spt.Cdb[4] = 100;
  186804. DWORD bytesReturned = 0;
  186805. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186806. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186807. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186808. &bytesReturned, 0) != 0)
  186809. {
  186810. zeromem (&list[count], sizeof (CDDeviceInfo));
  186811. list[count].scsiDriveLetter = driveLetter;
  186812. memcpy (list[count].vendor, &buffer[8], 8);
  186813. memcpy (list[count].productId, &buffer[16], 16);
  186814. memcpy (list[count].rev, &buffer[32], 4);
  186815. memcpy (list[count].vendorSpec, &buffer[36], 20);
  186816. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186817. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  186818. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  186819. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  186820. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  186821. &bytesReturned, 0) != 0)
  186822. {
  186823. list[count].ha = scsiAddr->PortNumber;
  186824. list[count].tgt = scsiAddr->TargetId;
  186825. list[count].lun = scsiAddr->Lun;
  186826. ++count;
  186827. }
  186828. }
  186829. CloseHandle (h);
  186830. }
  186831. }
  186832. }
  186833. }
  186834. else
  186835. {
  186836. const DWORD d = fGetASPI32SupportInfo();
  186837. BYTE status = HIBYTE (LOWORD (d));
  186838. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  186839. return 0;
  186840. const int numAdapters = LOBYTE (LOWORD (d));
  186841. for (BYTE ha = 0; ha < numAdapters; ++ha)
  186842. {
  186843. SRB_HAInquiry s;
  186844. zerostruct (s);
  186845. s.SRB_Cmd = SC_HA_INQUIRY;
  186846. s.SRB_HaID = ha;
  186847. fSendASPI32Command ((LPSRB)&s);
  186848. if (s.SRB_Status == SS_COMP)
  186849. {
  186850. maxItems = (int)s.HA_Unique[3];
  186851. if (maxItems == 0)
  186852. maxItems = 8;
  186853. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  186854. {
  186855. for (BYTE lun = 0; lun < 8; ++lun)
  186856. {
  186857. SRB_GDEVBlock sb;
  186858. zerostruct (sb);
  186859. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  186860. sb.SRB_HaID = ha;
  186861. sb.SRB_Target = tgt;
  186862. sb.SRB_Lun = lun;
  186863. fSendASPI32Command ((LPSRB) &sb);
  186864. if (sb.SRB_Status == SS_COMP
  186865. && sb.SRB_DeviceType == DTYPE_CROM)
  186866. {
  186867. zeromem (&list[count], sizeof (CDDeviceInfo));
  186868. list[count].ha = ha;
  186869. list[count].tgt = tgt;
  186870. list[count].lun = lun;
  186871. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  186872. ++count;
  186873. }
  186874. }
  186875. }
  186876. }
  186877. }
  186878. }
  186879. return count;
  186880. }
  186881. static int ripperUsers = 0;
  186882. static bool initialisedOk = false;
  186883. class DeinitialiseTimer : private Timer,
  186884. private DeletedAtShutdown
  186885. {
  186886. DeinitialiseTimer (const DeinitialiseTimer&);
  186887. DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  186888. public:
  186889. DeinitialiseTimer()
  186890. {
  186891. startTimer (4000);
  186892. }
  186893. ~DeinitialiseTimer()
  186894. {
  186895. if (--ripperUsers == 0)
  186896. DeinitialiseCDRipper();
  186897. }
  186898. void timerCallback()
  186899. {
  186900. delete this;
  186901. }
  186902. juce_UseDebuggingNewOperator
  186903. };
  186904. static void incUserCount()
  186905. {
  186906. if (ripperUsers++ == 0)
  186907. initialisedOk = InitialiseCDRipper();
  186908. }
  186909. static void decUserCount()
  186910. {
  186911. new DeinitialiseTimer();
  186912. }
  186913. struct CDDeviceWrapper
  186914. {
  186915. ScopedPointer<CDDeviceHandle> cdH;
  186916. ScopedPointer<CDReadBuffer> overlapBuffer;
  186917. bool jitter;
  186918. };
  186919. static int getAddressOf (const TOCTRACK* const t)
  186920. {
  186921. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  186922. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  186923. }
  186924. static int getMSFAddressOf (const TOCTRACK* const t)
  186925. {
  186926. return 60 * t->addr[1] + t->addr[2];
  186927. }
  186928. static const int samplesPerFrame = 44100 / 75;
  186929. static const int bytesPerFrame = samplesPerFrame * 4;
  186930. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  186931. {
  186932. SRB_GDEVBlock s;
  186933. zerostruct (s);
  186934. s.SRB_Cmd = SC_GET_DEV_TYPE;
  186935. s.SRB_HaID = device->ha;
  186936. s.SRB_Target = device->tgt;
  186937. s.SRB_Lun = device->lun;
  186938. if (usingScsi)
  186939. {
  186940. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  186941. if (h != INVALID_HANDLE_VALUE)
  186942. {
  186943. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  186944. cdh->scsiHandle = h;
  186945. return cdh;
  186946. }
  186947. }
  186948. else
  186949. {
  186950. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  186951. && s.SRB_DeviceType == DTYPE_CROM)
  186952. {
  186953. return new CDDeviceHandle (device);
  186954. }
  186955. }
  186956. return 0;
  186957. }
  186958. }
  186959. const StringArray AudioCDReader::getAvailableCDNames()
  186960. {
  186961. using namespace CDReaderHelpers;
  186962. StringArray results;
  186963. incUserCount();
  186964. if (initialisedOk)
  186965. {
  186966. CDDeviceInfo list[8];
  186967. const int num = FindCDDevices (list, 8);
  186968. decUserCount();
  186969. for (int i = 0; i < num; ++i)
  186970. {
  186971. String s;
  186972. if (list[i].scsiDriveLetter > 0)
  186973. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << T(": ");
  186974. s << String (list[i].vendor).trim()
  186975. << T(" ") << String (list[i].productId).trim()
  186976. << T(" ") << String (list[i].rev).trim();
  186977. results.add (s);
  186978. }
  186979. }
  186980. return results;
  186981. }
  186982. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  186983. {
  186984. using namespace CDReaderHelpers;
  186985. incUserCount();
  186986. if (initialisedOk)
  186987. {
  186988. CDDeviceInfo list[8];
  186989. const int num = FindCDDevices (list, 8);
  186990. if (((unsigned int) deviceIndex) < (unsigned int) num)
  186991. {
  186992. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  186993. if (handle != 0)
  186994. {
  186995. CDDeviceWrapper* const d = new CDDeviceWrapper();
  186996. d->cdH = handle;
  186997. d->overlapBuffer = new CDReadBuffer(3);
  186998. return new AudioCDReader (d);
  186999. }
  187000. }
  187001. }
  187002. decUserCount();
  187003. return 0;
  187004. }
  187005. AudioCDReader::AudioCDReader (void* handle_)
  187006. : AudioFormatReader (0, T("CD Audio")),
  187007. handle (handle_),
  187008. indexingEnabled (false),
  187009. lastIndex (0),
  187010. firstFrameInBuffer (0),
  187011. samplesInBuffer (0)
  187012. {
  187013. using namespace CDReaderHelpers;
  187014. jassert (handle_ != 0);
  187015. refreshTrackLengths();
  187016. sampleRate = 44100.0;
  187017. bitsPerSample = 16;
  187018. lengthInSamples = getPositionOfTrackStart (numTracks);
  187019. numChannels = 2;
  187020. usesFloatingPointData = false;
  187021. buffer.setSize (4 * bytesPerFrame, true);
  187022. }
  187023. AudioCDReader::~AudioCDReader()
  187024. {
  187025. using namespace CDReaderHelpers;
  187026. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187027. delete device;
  187028. decUserCount();
  187029. }
  187030. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  187031. int64 startSampleInFile, int numSamples)
  187032. {
  187033. using namespace CDReaderHelpers;
  187034. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187035. bool ok = true;
  187036. while (numSamples > 0)
  187037. {
  187038. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  187039. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  187040. if (startSampleInFile >= bufferStartSample
  187041. && startSampleInFile < bufferEndSample)
  187042. {
  187043. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  187044. int* const l = destSamples[0] + startOffsetInDestBuffer;
  187045. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187046. const short* src = (const short*) buffer.getData();
  187047. src += 2 * (startSampleInFile - bufferStartSample);
  187048. for (int i = 0; i < toDo; ++i)
  187049. {
  187050. l[i] = src [i << 1] << 16;
  187051. if (r != 0)
  187052. r[i] = src [(i << 1) + 1] << 16;
  187053. }
  187054. startOffsetInDestBuffer += toDo;
  187055. startSampleInFile += toDo;
  187056. numSamples -= toDo;
  187057. }
  187058. else
  187059. {
  187060. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  187061. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  187062. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  187063. {
  187064. device->overlapBuffer->dataLength = 0;
  187065. device->overlapBuffer->startFrame = 0;
  187066. device->overlapBuffer->numFrames = 0;
  187067. device->jitter = false;
  187068. }
  187069. firstFrameInBuffer = frameNeeded;
  187070. lastIndex = 0;
  187071. CDReadBuffer readBuffer (framesInBuffer + 4);
  187072. readBuffer.wantsIndex = indexingEnabled;
  187073. int i;
  187074. for (i = 5; --i >= 0;)
  187075. {
  187076. readBuffer.startFrame = frameNeeded;
  187077. readBuffer.numFrames = framesInBuffer;
  187078. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187079. break;
  187080. else
  187081. device->overlapBuffer->dataLength = 0;
  187082. }
  187083. if (i >= 0)
  187084. {
  187085. memcpy ((char*) buffer.getData(),
  187086. readBuffer.buffer + readBuffer.dataStartOffset,
  187087. readBuffer.dataLength);
  187088. samplesInBuffer = readBuffer.dataLength >> 2;
  187089. lastIndex = readBuffer.index;
  187090. }
  187091. else
  187092. {
  187093. int* l = destSamples[0] + startOffsetInDestBuffer;
  187094. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187095. while (--numSamples >= 0)
  187096. {
  187097. *l++ = 0;
  187098. if (r != 0)
  187099. *r++ = 0;
  187100. }
  187101. // sometimes the read fails for just the very last couple of blocks, so
  187102. // we'll ignore and errors in the last half-second of the disk..
  187103. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187104. break;
  187105. }
  187106. }
  187107. }
  187108. return ok;
  187109. }
  187110. bool AudioCDReader::isCDStillPresent() const
  187111. {
  187112. using namespace CDReaderHelpers;
  187113. TOC toc;
  187114. zerostruct (toc);
  187115. return ((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, false);
  187116. }
  187117. int AudioCDReader::getNumTracks() const
  187118. {
  187119. return numTracks;
  187120. }
  187121. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187122. {
  187123. using namespace CDReaderHelpers;
  187124. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187125. : 0;
  187126. }
  187127. void AudioCDReader::refreshTrackLengths()
  187128. {
  187129. using namespace CDReaderHelpers;
  187130. zeromem (trackStarts, sizeof (trackStarts));
  187131. zeromem (audioTracks, sizeof (audioTracks));
  187132. TOC toc;
  187133. zerostruct (toc);
  187134. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187135. {
  187136. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187137. for (int i = 0; i <= numTracks; ++i)
  187138. {
  187139. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187140. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187141. }
  187142. }
  187143. else
  187144. {
  187145. numTracks = 0;
  187146. }
  187147. }
  187148. bool AudioCDReader::isTrackAudio (int trackNum) const
  187149. {
  187150. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187151. : false;
  187152. }
  187153. void AudioCDReader::enableIndexScanning (bool b)
  187154. {
  187155. indexingEnabled = b;
  187156. }
  187157. int AudioCDReader::getLastIndex() const
  187158. {
  187159. return lastIndex;
  187160. }
  187161. const int framesPerIndexRead = 4;
  187162. int AudioCDReader::getIndexAt (int samplePos)
  187163. {
  187164. using namespace CDReaderHelpers;
  187165. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187166. const int frameNeeded = samplePos / samplesPerFrame;
  187167. device->overlapBuffer->dataLength = 0;
  187168. device->overlapBuffer->startFrame = 0;
  187169. device->overlapBuffer->numFrames = 0;
  187170. device->jitter = false;
  187171. firstFrameInBuffer = 0;
  187172. lastIndex = 0;
  187173. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187174. readBuffer.wantsIndex = true;
  187175. int i;
  187176. for (i = 5; --i >= 0;)
  187177. {
  187178. readBuffer.startFrame = frameNeeded;
  187179. readBuffer.numFrames = framesPerIndexRead;
  187180. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187181. break;
  187182. }
  187183. if (i >= 0)
  187184. return readBuffer.index;
  187185. return -1;
  187186. }
  187187. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187188. {
  187189. using namespace CDReaderHelpers;
  187190. Array <int> indexes;
  187191. const int trackStart = getPositionOfTrackStart (trackNumber);
  187192. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187193. bool needToScan = true;
  187194. if (trackEnd - trackStart > 20 * 44100)
  187195. {
  187196. // check the end of the track for indexes before scanning the whole thing
  187197. needToScan = false;
  187198. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187199. bool seenAnIndex = false;
  187200. while (pos <= trackEnd - samplesPerFrame)
  187201. {
  187202. const int index = getIndexAt (pos);
  187203. if (index == 0)
  187204. {
  187205. // lead-out, so skip back a bit if we've not found any indexes yet..
  187206. if (seenAnIndex)
  187207. break;
  187208. pos -= 44100 * 5;
  187209. if (pos < trackStart)
  187210. break;
  187211. }
  187212. else
  187213. {
  187214. if (index > 0)
  187215. seenAnIndex = true;
  187216. if (index > 1)
  187217. {
  187218. needToScan = true;
  187219. break;
  187220. }
  187221. pos += samplesPerFrame * framesPerIndexRead;
  187222. }
  187223. }
  187224. }
  187225. if (needToScan)
  187226. {
  187227. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187228. int pos = trackStart;
  187229. int last = -1;
  187230. while (pos < trackEnd - samplesPerFrame * 10)
  187231. {
  187232. const int frameNeeded = pos / samplesPerFrame;
  187233. device->overlapBuffer->dataLength = 0;
  187234. device->overlapBuffer->startFrame = 0;
  187235. device->overlapBuffer->numFrames = 0;
  187236. device->jitter = false;
  187237. firstFrameInBuffer = 0;
  187238. CDReadBuffer readBuffer (4);
  187239. readBuffer.wantsIndex = true;
  187240. int i;
  187241. for (i = 5; --i >= 0;)
  187242. {
  187243. readBuffer.startFrame = frameNeeded;
  187244. readBuffer.numFrames = framesPerIndexRead;
  187245. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187246. break;
  187247. }
  187248. if (i < 0)
  187249. break;
  187250. if (readBuffer.index > last && readBuffer.index > 1)
  187251. {
  187252. last = readBuffer.index;
  187253. indexes.add (pos);
  187254. }
  187255. pos += samplesPerFrame * framesPerIndexRead;
  187256. }
  187257. indexes.removeValue (trackStart);
  187258. }
  187259. return indexes;
  187260. }
  187261. int AudioCDReader::getCDDBId()
  187262. {
  187263. using namespace CDReaderHelpers;
  187264. refreshTrackLengths();
  187265. if (numTracks > 0)
  187266. {
  187267. TOC toc;
  187268. zerostruct (toc);
  187269. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187270. {
  187271. int n = 0;
  187272. for (int i = numTracks; --i >= 0;)
  187273. {
  187274. int j = getMSFAddressOf (&toc.tracks[i]);
  187275. while (j > 0)
  187276. {
  187277. n += (j % 10);
  187278. j /= 10;
  187279. }
  187280. }
  187281. if (n != 0)
  187282. {
  187283. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187284. - getMSFAddressOf (&toc.tracks[0]);
  187285. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187286. }
  187287. }
  187288. }
  187289. return 0;
  187290. }
  187291. void AudioCDReader::ejectDisk()
  187292. {
  187293. using namespace CDReaderHelpers;
  187294. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187295. }
  187296. #endif
  187297. #if JUCE_USE_CDBURNER
  187298. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187299. {
  187300. CoInitialize (0);
  187301. IDiscMaster* dm;
  187302. IDiscRecorder* result = 0;
  187303. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187304. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187305. IID_IDiscMaster,
  187306. (void**) &dm)))
  187307. {
  187308. if (SUCCEEDED (dm->Open()))
  187309. {
  187310. IEnumDiscRecorders* drEnum = 0;
  187311. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187312. {
  187313. IDiscRecorder* dr = 0;
  187314. DWORD dummy;
  187315. int index = 0;
  187316. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187317. {
  187318. if (indexToOpen == index)
  187319. {
  187320. result = dr;
  187321. break;
  187322. }
  187323. else if (list != 0)
  187324. {
  187325. BSTR path;
  187326. if (SUCCEEDED (dr->GetPath (&path)))
  187327. list->add ((const WCHAR*) path);
  187328. }
  187329. ++index;
  187330. dr->Release();
  187331. }
  187332. drEnum->Release();
  187333. }
  187334. if (master == 0)
  187335. dm->Close();
  187336. }
  187337. if (master != 0)
  187338. *master = dm;
  187339. else
  187340. dm->Release();
  187341. }
  187342. return result;
  187343. }
  187344. class AudioCDBurner::Pimpl : public IDiscMasterProgressEvents,
  187345. public Timer
  187346. {
  187347. public:
  187348. Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_)
  187349. : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0),
  187350. listener (0), progress (0), shouldCancel (false), refCount (1)
  187351. {
  187352. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  187353. jassert (SUCCEEDED (hr));
  187354. hr = discMaster->SetActiveDiscRecorder (discRecorder);
  187355. //jassert (SUCCEEDED (hr));
  187356. lastState = getDiskState();
  187357. startTimer (2000);
  187358. }
  187359. ~Pimpl() {}
  187360. void releaseObjects()
  187361. {
  187362. discRecorder->Close();
  187363. if (redbook != 0)
  187364. redbook->Release();
  187365. discRecorder->Release();
  187366. discMaster->Release();
  187367. Release();
  187368. }
  187369. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187370. {
  187371. if (result == 0)
  187372. return E_POINTER;
  187373. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187374. {
  187375. AddRef();
  187376. *result = this;
  187377. return S_OK;
  187378. }
  187379. *result = 0;
  187380. return E_NOINTERFACE;
  187381. }
  187382. ULONG __stdcall AddRef() { return ++refCount; }
  187383. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187384. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187385. {
  187386. if (listener != 0 && ! shouldCancel)
  187387. shouldCancel = listener->audioCDBurnProgress (progress);
  187388. *pbCancel = shouldCancel;
  187389. return S_OK;
  187390. }
  187391. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187392. {
  187393. progress = nCompleted / (float) nTotal;
  187394. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187395. return E_NOTIMPL;
  187396. }
  187397. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187398. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187399. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187400. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187401. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187402. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187403. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187404. class ScopedDiscOpener
  187405. {
  187406. public:
  187407. ScopedDiscOpener (Pimpl& p) : pimpl (p) { pimpl.discRecorder->OpenExclusive(); }
  187408. ~ScopedDiscOpener() { pimpl.discRecorder->Close(); }
  187409. private:
  187410. Pimpl& pimpl;
  187411. ScopedDiscOpener (const ScopedDiscOpener&);
  187412. ScopedDiscOpener& operator= (const ScopedDiscOpener&);
  187413. };
  187414. DiskState getDiskState()
  187415. {
  187416. const ScopedDiscOpener opener (*this);
  187417. long type, flags;
  187418. HRESULT hr = discRecorder->QueryMediaType (&type, &flags);
  187419. if (FAILED (hr))
  187420. return unknown;
  187421. if (type != 0 && (flags & MEDIA_WRITABLE) != 0)
  187422. return writableDiskPresent;
  187423. if (type == 0)
  187424. return noDisc;
  187425. else
  187426. return readOnlyDiskPresent;
  187427. }
  187428. int getIntProperty (const LPOLESTR name, const int defaultReturn) const
  187429. {
  187430. ComSmartPtr<IPropertyStorage> prop;
  187431. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187432. return defaultReturn;
  187433. PROPSPEC iPropSpec;
  187434. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187435. iPropSpec.lpwstr = name;
  187436. PROPVARIANT iPropVariant;
  187437. return FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant))
  187438. ? defaultReturn : (int) iPropVariant.lVal;
  187439. }
  187440. bool setIntProperty (const LPOLESTR name, const int value) const
  187441. {
  187442. ComSmartPtr<IPropertyStorage> prop;
  187443. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187444. return false;
  187445. PROPSPEC iPropSpec;
  187446. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187447. iPropSpec.lpwstr = name;
  187448. PROPVARIANT iPropVariant;
  187449. if (FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant)))
  187450. return false;
  187451. iPropVariant.lVal = (long) value;
  187452. return SUCCEEDED (prop->WriteMultiple (1, &iPropSpec, &iPropVariant, iPropVariant.vt))
  187453. && SUCCEEDED (discRecorder->SetRecorderProperties (prop));
  187454. }
  187455. void timerCallback()
  187456. {
  187457. const DiskState state = getDiskState();
  187458. if (state != lastState)
  187459. {
  187460. lastState = state;
  187461. owner.sendChangeMessage (&owner);
  187462. }
  187463. }
  187464. AudioCDBurner& owner;
  187465. DiskState lastState;
  187466. IDiscMaster* discMaster;
  187467. IDiscRecorder* discRecorder;
  187468. IRedbookDiscMaster* redbook;
  187469. AudioCDBurner::BurnProgressListener* listener;
  187470. float progress;
  187471. bool shouldCancel;
  187472. private:
  187473. int refCount;
  187474. };
  187475. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187476. {
  187477. IDiscMaster* discMaster = 0;
  187478. IDiscRecorder* discRecorder = enumCDBurners (0, deviceIndex, &discMaster);
  187479. if (discRecorder != 0)
  187480. pimpl = new Pimpl (*this, discMaster, discRecorder);
  187481. }
  187482. AudioCDBurner::~AudioCDBurner()
  187483. {
  187484. if (pimpl != 0)
  187485. pimpl.release()->releaseObjects();
  187486. }
  187487. const StringArray AudioCDBurner::findAvailableDevices()
  187488. {
  187489. StringArray devs;
  187490. enumCDBurners (&devs, -1, 0);
  187491. return devs;
  187492. }
  187493. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187494. {
  187495. ScopedPointer<AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  187496. if (b->pimpl == 0)
  187497. b = 0;
  187498. return b.release();
  187499. }
  187500. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  187501. {
  187502. return pimpl->getDiskState();
  187503. }
  187504. bool AudioCDBurner::isDiskPresent() const
  187505. {
  187506. return getDiskState() == writableDiskPresent;
  187507. }
  187508. bool AudioCDBurner::openTray()
  187509. {
  187510. const Pimpl::ScopedDiscOpener opener (*pimpl);
  187511. return SUCCEEDED (pimpl->discRecorder->Eject());
  187512. }
  187513. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  187514. {
  187515. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  187516. DiskState oldState = getDiskState();
  187517. DiskState newState = oldState;
  187518. while (newState == oldState && Time::currentTimeMillis() < timeout)
  187519. {
  187520. newState = getDiskState();
  187521. Thread::sleep (jmin (250, (int) (timeout - Time::currentTimeMillis())));
  187522. }
  187523. return newState;
  187524. }
  187525. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  187526. {
  187527. Array<int> results;
  187528. const int maxSpeed = pimpl->getIntProperty (L"MaxWriteSpeed", 1);
  187529. const int speeds[] = { 1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 64, 80 };
  187530. for (int i = 0; i < numElementsInArray (speeds); ++i)
  187531. if (speeds[i] <= maxSpeed)
  187532. results.add (speeds[i]);
  187533. results.addIfNotAlreadyThere (maxSpeed);
  187534. return results;
  187535. }
  187536. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  187537. {
  187538. if (pimpl->getIntProperty (L"BufferUnderrunFreeCapable", 0) == 0)
  187539. return false;
  187540. pimpl->setIntProperty (L"EnableBufferUnderrunFree", shouldBeEnabled ? -1 : 0);
  187541. return pimpl->getIntProperty (L"EnableBufferUnderrunFree", 0) != 0;
  187542. }
  187543. int AudioCDBurner::getNumAvailableAudioBlocks() const
  187544. {
  187545. long blocksFree = 0;
  187546. pimpl->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  187547. return blocksFree;
  187548. }
  187549. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener, bool ejectDiscAfterwards,
  187550. bool performFakeBurnForTesting, int writeSpeed)
  187551. {
  187552. pimpl->setIntProperty (L"WriteSpeed", writeSpeed > 0 ? writeSpeed : -1);
  187553. pimpl->listener = listener;
  187554. pimpl->progress = 0;
  187555. pimpl->shouldCancel = false;
  187556. UINT_PTR cookie;
  187557. HRESULT hr = pimpl->discMaster->ProgressAdvise ((AudioCDBurner::Pimpl*) pimpl, &cookie);
  187558. hr = pimpl->discMaster->RecordDisc (performFakeBurnForTesting,
  187559. ejectDiscAfterwards);
  187560. String error;
  187561. if (hr != S_OK)
  187562. {
  187563. const char* e = "Couldn't open or write to the CD device";
  187564. if (hr == IMAPI_E_USERABORT)
  187565. e = "User cancelled the write operation";
  187566. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  187567. e = "No Disk present";
  187568. error = e;
  187569. }
  187570. pimpl->discMaster->ProgressUnadvise (cookie);
  187571. pimpl->listener = 0;
  187572. return error;
  187573. }
  187574. bool AudioCDBurner::addAudioTrack (AudioSource* audioSource, int numSamples)
  187575. {
  187576. if (audioSource == 0)
  187577. return false;
  187578. ScopedPointer<AudioSource> source (audioSource);
  187579. long bytesPerBlock;
  187580. HRESULT hr = pimpl->redbook->GetAudioBlockSize (&bytesPerBlock);
  187581. const int samplesPerBlock = bytesPerBlock / 4;
  187582. bool ok = true;
  187583. hr = pimpl->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  187584. HeapBlock <byte> buffer (bytesPerBlock);
  187585. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  187586. int samplesDone = 0;
  187587. source->prepareToPlay (samplesPerBlock, 44100.0);
  187588. while (ok)
  187589. {
  187590. {
  187591. AudioSourceChannelInfo info;
  187592. info.buffer = &sourceBuffer;
  187593. info.numSamples = samplesPerBlock;
  187594. info.startSample = 0;
  187595. sourceBuffer.clear();
  187596. source->getNextAudioBlock (info);
  187597. }
  187598. zeromem (buffer, bytesPerBlock);
  187599. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  187600. buffer, samplesPerBlock, 4);
  187601. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  187602. buffer + 2, samplesPerBlock, 4);
  187603. hr = pimpl->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  187604. if (FAILED (hr))
  187605. ok = false;
  187606. samplesDone += samplesPerBlock;
  187607. if (samplesDone >= numSamples)
  187608. break;
  187609. }
  187610. hr = pimpl->redbook->CloseAudioTrack();
  187611. return ok && hr == S_OK;
  187612. }
  187613. #endif
  187614. #endif
  187615. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  187616. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  187617. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187618. // compiled on its own).
  187619. #if JUCE_INCLUDED_FILE
  187620. using ::free;
  187621. namespace MidiConstants
  187622. {
  187623. static const int midiBufferSize = 1024 * 10;
  187624. static const int numInHeaders = 32;
  187625. static const int inBufferSize = 256;
  187626. }
  187627. class MidiInThread : public Thread
  187628. {
  187629. public:
  187630. MidiInThread (MidiInput* const input_,
  187631. MidiInputCallback* const callback_)
  187632. : Thread ("Juce Midi"),
  187633. hIn (0),
  187634. input (input_),
  187635. callback (callback_),
  187636. isStarted (false),
  187637. startTime (0),
  187638. pendingLength(0)
  187639. {
  187640. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187641. {
  187642. zeromem (&hdr[i], sizeof (MIDIHDR));
  187643. hdr[i].lpData = inData[i];
  187644. hdr[i].dwBufferLength = MidiConstants::inBufferSize;
  187645. }
  187646. };
  187647. ~MidiInThread()
  187648. {
  187649. stop();
  187650. if (hIn != 0)
  187651. {
  187652. int count = 5;
  187653. while (--count >= 0)
  187654. {
  187655. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  187656. break;
  187657. Sleep (20);
  187658. }
  187659. }
  187660. }
  187661. void handle (const uint32 message, const uint32 timeStamp) throw()
  187662. {
  187663. const int byte = message & 0xff;
  187664. if (byte < 0x80)
  187665. return;
  187666. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  187667. const double time = timeStampToTime (timeStamp);
  187668. {
  187669. const ScopedLock sl (lock);
  187670. if (pendingLength < MidiConstants::midiBufferSize - 12)
  187671. {
  187672. char* const p = pending + pendingLength;
  187673. *(double*) p = time;
  187674. *(uint32*) (p + 8) = numBytes;
  187675. *(uint32*) (p + 12) = message;
  187676. pendingLength += 12 + numBytes;
  187677. }
  187678. else
  187679. {
  187680. jassertfalse // midi buffer overflow! You might need to increase the size..
  187681. }
  187682. }
  187683. notify();
  187684. }
  187685. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  187686. {
  187687. const int num = hdr->dwBytesRecorded;
  187688. if (num > 0)
  187689. {
  187690. const double time = timeStampToTime (timeStamp);
  187691. {
  187692. const ScopedLock sl (lock);
  187693. if (pendingLength < MidiConstants::midiBufferSize - (8 + num))
  187694. {
  187695. char* const p = pending + pendingLength;
  187696. *(double*) p = time;
  187697. *(uint32*) (p + 8) = num;
  187698. memcpy (p + 12, hdr->lpData, num);
  187699. pendingLength += 12 + num;
  187700. }
  187701. else
  187702. {
  187703. jassertfalse // midi buffer overflow! You might need to increase the size..
  187704. }
  187705. }
  187706. notify();
  187707. }
  187708. }
  187709. void writeBlock (const int i) throw()
  187710. {
  187711. hdr[i].dwBytesRecorded = 0;
  187712. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187713. jassert (res == MMSYSERR_NOERROR);
  187714. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  187715. jassert (res == MMSYSERR_NOERROR);
  187716. }
  187717. void run()
  187718. {
  187719. MemoryBlock pendingCopy (64);
  187720. while (! threadShouldExit())
  187721. {
  187722. for (int i = 0; i < MidiConstants::numInHeaders; ++i)
  187723. {
  187724. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187725. {
  187726. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187727. (void) res;
  187728. jassert (res == MMSYSERR_NOERROR);
  187729. writeBlock (i);
  187730. }
  187731. }
  187732. int len;
  187733. {
  187734. const ScopedLock sl (lock);
  187735. len = pendingLength;
  187736. if (len > 0)
  187737. {
  187738. pendingCopy.ensureSize (len);
  187739. pendingCopy.copyFrom (pending, 0, len);
  187740. pendingLength = 0;
  187741. }
  187742. }
  187743. //xxx needs to figure out if blocks are broken up or not
  187744. if (len == 0)
  187745. {
  187746. wait (500);
  187747. }
  187748. else
  187749. {
  187750. const char* p = (const char*) pendingCopy.getData();
  187751. while (len > 0)
  187752. {
  187753. const double time = *(const double*) p;
  187754. const int messageLen = *(const int*) (p + 8);
  187755. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  187756. callback->handleIncomingMidiMessage (input, message);
  187757. p += 12 + messageLen;
  187758. len -= 12 + messageLen;
  187759. }
  187760. }
  187761. }
  187762. }
  187763. void start() throw()
  187764. {
  187765. jassert (hIn != 0);
  187766. if (hIn != 0 && ! isStarted)
  187767. {
  187768. stop();
  187769. activeMidiThreads.addIfNotAlreadyThere (this);
  187770. int i;
  187771. for (i = 0; i < MidiConstants::numInHeaders; ++i)
  187772. writeBlock (i);
  187773. startTime = Time::getMillisecondCounter();
  187774. MMRESULT res = midiInStart (hIn);
  187775. jassert (res == MMSYSERR_NOERROR);
  187776. if (res == MMSYSERR_NOERROR)
  187777. {
  187778. isStarted = true;
  187779. pendingLength = 0;
  187780. startThread (6);
  187781. }
  187782. }
  187783. }
  187784. void stop() throw()
  187785. {
  187786. if (isStarted)
  187787. {
  187788. stopThread (5000);
  187789. midiInReset (hIn);
  187790. midiInStop (hIn);
  187791. activeMidiThreads.removeValue (this);
  187792. { const ScopedLock sl (lock); }
  187793. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187794. {
  187795. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187796. {
  187797. int c = 10;
  187798. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  187799. Sleep (20);
  187800. jassert (c >= 0);
  187801. }
  187802. }
  187803. isStarted = false;
  187804. pendingLength = 0;
  187805. }
  187806. }
  187807. static void CALLBACK midiInCallback (HMIDIIN, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR midiMessage, DWORD_PTR timeStamp)
  187808. {
  187809. MidiInThread* const thread = reinterpret_cast <MidiInThread*> (dwInstance);
  187810. if (thread != 0 && activeMidiThreads.contains (thread))
  187811. {
  187812. if (uMsg == MIM_DATA)
  187813. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  187814. else if (uMsg == MIM_LONGDATA)
  187815. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  187816. }
  187817. }
  187818. juce_UseDebuggingNewOperator
  187819. HMIDIIN hIn;
  187820. private:
  187821. static Array <void*, CriticalSection> activeMidiThreads;
  187822. MidiInput* input;
  187823. MidiInputCallback* callback;
  187824. bool isStarted;
  187825. uint32 startTime;
  187826. CriticalSection lock;
  187827. MIDIHDR hdr [MidiConstants::numInHeaders];
  187828. char inData [MidiConstants::numInHeaders] [MidiConstants::inBufferSize];
  187829. int pendingLength;
  187830. char pending [MidiConstants::midiBufferSize];
  187831. double timeStampToTime (uint32 timeStamp) throw()
  187832. {
  187833. timeStamp += startTime;
  187834. const uint32 now = Time::getMillisecondCounter();
  187835. if (timeStamp > now)
  187836. {
  187837. if (timeStamp > now + 2)
  187838. --startTime;
  187839. timeStamp = now;
  187840. }
  187841. return 0.001 * timeStamp;
  187842. }
  187843. MidiInThread (const MidiInThread&);
  187844. MidiInThread& operator= (const MidiInThread&);
  187845. };
  187846. Array <void*, CriticalSection> MidiInThread::activeMidiThreads;
  187847. const StringArray MidiInput::getDevices()
  187848. {
  187849. StringArray s;
  187850. const int num = midiInGetNumDevs();
  187851. for (int i = 0; i < num; ++i)
  187852. {
  187853. MIDIINCAPS mc;
  187854. zerostruct (mc);
  187855. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187856. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187857. }
  187858. return s;
  187859. }
  187860. int MidiInput::getDefaultDeviceIndex()
  187861. {
  187862. return 0;
  187863. }
  187864. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  187865. {
  187866. if (callback == 0)
  187867. return 0;
  187868. UINT deviceId = MIDI_MAPPER;
  187869. int n = 0;
  187870. String name;
  187871. const int num = midiInGetNumDevs();
  187872. for (int i = 0; i < num; ++i)
  187873. {
  187874. MIDIINCAPS mc;
  187875. zerostruct (mc);
  187876. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187877. {
  187878. if (index == n)
  187879. {
  187880. deviceId = i;
  187881. name = String (mc.szPname, sizeof (mc.szPname));
  187882. break;
  187883. }
  187884. ++n;
  187885. }
  187886. }
  187887. ScopedPointer <MidiInput> in (new MidiInput (name));
  187888. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  187889. HMIDIIN h;
  187890. HRESULT err = midiInOpen (&h, deviceId,
  187891. (DWORD_PTR) &MidiInThread::midiInCallback,
  187892. (DWORD_PTR) (MidiInThread*) thread,
  187893. CALLBACK_FUNCTION);
  187894. if (err == MMSYSERR_NOERROR)
  187895. {
  187896. thread->hIn = h;
  187897. in->internal = (void*) thread.release();
  187898. return in.release();
  187899. }
  187900. return 0;
  187901. }
  187902. MidiInput::MidiInput (const String& name_)
  187903. : name (name_),
  187904. internal (0)
  187905. {
  187906. }
  187907. MidiInput::~MidiInput()
  187908. {
  187909. delete static_cast <MidiInThread*> (internal);
  187910. }
  187911. void MidiInput::start()
  187912. {
  187913. static_cast <MidiInThread*> (internal)->start();
  187914. }
  187915. void MidiInput::stop()
  187916. {
  187917. static_cast <MidiInThread*> (internal)->stop();
  187918. }
  187919. struct MidiOutHandle
  187920. {
  187921. int refCount;
  187922. UINT deviceId;
  187923. HMIDIOUT handle;
  187924. static Array<MidiOutHandle*> activeHandles;
  187925. juce_UseDebuggingNewOperator
  187926. };
  187927. Array<MidiOutHandle*> MidiOutHandle::activeHandles;
  187928. const StringArray MidiOutput::getDevices()
  187929. {
  187930. StringArray s;
  187931. const int num = midiOutGetNumDevs();
  187932. for (int i = 0; i < num; ++i)
  187933. {
  187934. MIDIOUTCAPS mc;
  187935. zerostruct (mc);
  187936. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187937. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187938. }
  187939. return s;
  187940. }
  187941. int MidiOutput::getDefaultDeviceIndex()
  187942. {
  187943. const int num = midiOutGetNumDevs();
  187944. int n = 0;
  187945. for (int i = 0; i < num; ++i)
  187946. {
  187947. MIDIOUTCAPS mc;
  187948. zerostruct (mc);
  187949. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187950. {
  187951. if ((mc.wTechnology & MOD_MAPPER) != 0)
  187952. return n;
  187953. ++n;
  187954. }
  187955. }
  187956. return 0;
  187957. }
  187958. MidiOutput* MidiOutput::openDevice (int index)
  187959. {
  187960. UINT deviceId = MIDI_MAPPER;
  187961. const int num = midiOutGetNumDevs();
  187962. int i, n = 0;
  187963. for (i = 0; i < num; ++i)
  187964. {
  187965. MIDIOUTCAPS mc;
  187966. zerostruct (mc);
  187967. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187968. {
  187969. // use the microsoft sw synth as a default - best not to allow deviceId
  187970. // to be MIDI_MAPPER, or else device sharing breaks
  187971. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase (T("microsoft")))
  187972. deviceId = i;
  187973. if (index == n)
  187974. {
  187975. deviceId = i;
  187976. break;
  187977. }
  187978. ++n;
  187979. }
  187980. }
  187981. for (i = MidiOutHandle::activeHandles.size(); --i >= 0;)
  187982. {
  187983. MidiOutHandle* const han = MidiOutHandle::activeHandles.getUnchecked(i);
  187984. if (han != 0 && han->deviceId == deviceId)
  187985. {
  187986. han->refCount++;
  187987. MidiOutput* const out = new MidiOutput();
  187988. out->internal = (void*) han;
  187989. return out;
  187990. }
  187991. }
  187992. for (i = 4; --i >= 0;)
  187993. {
  187994. HMIDIOUT h = 0;
  187995. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  187996. if (res == MMSYSERR_NOERROR)
  187997. {
  187998. MidiOutHandle* const han = new MidiOutHandle();
  187999. han->deviceId = deviceId;
  188000. han->refCount = 1;
  188001. han->handle = h;
  188002. MidiOutHandle::activeHandles.add (han);
  188003. MidiOutput* const out = new MidiOutput();
  188004. out->internal = (void*) han;
  188005. return out;
  188006. }
  188007. else if (res == MMSYSERR_ALLOCATED)
  188008. {
  188009. Sleep (100);
  188010. }
  188011. else
  188012. {
  188013. break;
  188014. }
  188015. }
  188016. return 0;
  188017. }
  188018. MidiOutput::~MidiOutput()
  188019. {
  188020. MidiOutHandle* const h = static_cast <MidiOutHandle*> (internal);
  188021. if (MidiOutHandle::activeHandles.contains (h) && --(h->refCount) == 0)
  188022. {
  188023. midiOutClose (h->handle);
  188024. MidiOutHandle::activeHandles.removeValue (h);
  188025. delete h;
  188026. }
  188027. }
  188028. void MidiOutput::reset()
  188029. {
  188030. const MidiOutHandle* const h = static_cast <const MidiOutHandle*> (internal);
  188031. midiOutReset (h->handle);
  188032. }
  188033. bool MidiOutput::getVolume (float& leftVol,
  188034. float& rightVol)
  188035. {
  188036. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  188037. DWORD n;
  188038. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  188039. {
  188040. const unsigned short* const nn = (const unsigned short*) &n;
  188041. rightVol = nn[0] / (float) 0xffff;
  188042. leftVol = nn[1] / (float) 0xffff;
  188043. return true;
  188044. }
  188045. else
  188046. {
  188047. rightVol = leftVol = 1.0f;
  188048. return false;
  188049. }
  188050. }
  188051. void MidiOutput::setVolume (float leftVol,
  188052. float rightVol)
  188053. {
  188054. const MidiOutHandle* const handle = static_cast <MidiOutHandle*> (internal);
  188055. DWORD n;
  188056. unsigned short* const nn = (unsigned short*) &n;
  188057. nn[0] = (unsigned short) jlimit (0, 0xffff, (int) (rightVol * 0xffff));
  188058. nn[1] = (unsigned short) jlimit (0, 0xffff, (int) (leftVol * 0xffff));
  188059. midiOutSetVolume (handle->handle, n);
  188060. }
  188061. void MidiOutput::sendMessageNow (const MidiMessage& message)
  188062. {
  188063. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  188064. if (message.getRawDataSize() > 3
  188065. || message.isSysEx())
  188066. {
  188067. MIDIHDR h;
  188068. zerostruct (h);
  188069. h.lpData = (char*) message.getRawData();
  188070. h.dwBufferLength = message.getRawDataSize();
  188071. h.dwBytesRecorded = message.getRawDataSize();
  188072. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188073. {
  188074. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188075. if (res == MMSYSERR_NOERROR)
  188076. {
  188077. while ((h.dwFlags & MHDR_DONE) == 0)
  188078. Sleep (1);
  188079. int count = 500; // 1 sec timeout
  188080. while (--count >= 0)
  188081. {
  188082. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188083. if (res == MIDIERR_STILLPLAYING)
  188084. Sleep (2);
  188085. else
  188086. break;
  188087. }
  188088. }
  188089. }
  188090. }
  188091. else
  188092. {
  188093. midiOutShortMsg (handle->handle,
  188094. *(unsigned int*) message.getRawData());
  188095. }
  188096. }
  188097. #endif
  188098. /*** End of inlined file: juce_win32_Midi.cpp ***/
  188099. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  188100. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188101. // compiled on its own).
  188102. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188103. #undef WINDOWS
  188104. // #define ASIO_DEBUGGING
  188105. #ifdef ASIO_DEBUGGING
  188106. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188107. #else
  188108. #define log(a) {}
  188109. #endif
  188110. #ifdef ASIO_DEBUGGING
  188111. static void logError (const String& context, long error)
  188112. {
  188113. String err ("unknown error");
  188114. if (error == ASE_NotPresent)
  188115. err = "Not Present";
  188116. else if (error == ASE_HWMalfunction)
  188117. err = "Hardware Malfunction";
  188118. else if (error == ASE_InvalidParameter)
  188119. err = "Invalid Parameter";
  188120. else if (error == ASE_InvalidMode)
  188121. err = "Invalid Mode";
  188122. else if (error == ASE_SPNotAdvancing)
  188123. err = "Sample position not advancing";
  188124. else if (error == ASE_NoClock)
  188125. err = "No Clock";
  188126. else if (error == ASE_NoMemory)
  188127. err = "Out of memory";
  188128. log (T("!!error: ") + context + T(" - ") + err);
  188129. }
  188130. #else
  188131. #define logError(a, b) {}
  188132. #endif
  188133. class ASIOAudioIODevice;
  188134. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188135. static const int maxASIOChannels = 160;
  188136. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188137. private Timer
  188138. {
  188139. public:
  188140. Component ourWindow;
  188141. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188142. const String& optionalDllForDirectLoading_)
  188143. : AudioIODevice (name_, T("ASIO")),
  188144. asioObject (0),
  188145. classId (classId_),
  188146. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188147. currentBitDepth (16),
  188148. currentSampleRate (0),
  188149. isOpen_ (false),
  188150. isStarted (false),
  188151. postOutput (true),
  188152. insideControlPanelModalLoop (false),
  188153. shouldUsePreferredSize (false)
  188154. {
  188155. name = name_;
  188156. ourWindow.addToDesktop (0);
  188157. windowHandle = ourWindow.getWindowHandle();
  188158. jassert (currentASIODev [slotNumber] == 0);
  188159. currentASIODev [slotNumber] = this;
  188160. openDevice();
  188161. }
  188162. ~ASIOAudioIODevice()
  188163. {
  188164. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188165. if (currentASIODev[i] == this)
  188166. currentASIODev[i] = 0;
  188167. close();
  188168. log ("ASIO - exiting");
  188169. removeCurrentDriver();
  188170. }
  188171. void updateSampleRates()
  188172. {
  188173. // find a list of sample rates..
  188174. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188175. sampleRates.clear();
  188176. if (asioObject != 0)
  188177. {
  188178. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188179. {
  188180. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188181. if (err == 0)
  188182. {
  188183. sampleRates.add ((int) possibleSampleRates[index]);
  188184. log (T("rate: ") + String ((int) possibleSampleRates[index]));
  188185. }
  188186. else if (err != ASE_NoClock)
  188187. {
  188188. logError (T("CanSampleRate"), err);
  188189. }
  188190. }
  188191. if (sampleRates.size() == 0)
  188192. {
  188193. double cr = 0;
  188194. const long err = asioObject->getSampleRate (&cr);
  188195. log (T("No sample rates supported - current rate: ") + String ((int) cr));
  188196. if (err == 0)
  188197. sampleRates.add ((int) cr);
  188198. }
  188199. }
  188200. }
  188201. const StringArray getOutputChannelNames()
  188202. {
  188203. return outputChannelNames;
  188204. }
  188205. const StringArray getInputChannelNames()
  188206. {
  188207. return inputChannelNames;
  188208. }
  188209. int getNumSampleRates()
  188210. {
  188211. return sampleRates.size();
  188212. }
  188213. double getSampleRate (int index)
  188214. {
  188215. return sampleRates [index];
  188216. }
  188217. int getNumBufferSizesAvailable()
  188218. {
  188219. return bufferSizes.size();
  188220. }
  188221. int getBufferSizeSamples (int index)
  188222. {
  188223. return bufferSizes [index];
  188224. }
  188225. int getDefaultBufferSize()
  188226. {
  188227. return preferredSize;
  188228. }
  188229. const String open (const BigInteger& inputChannels,
  188230. const BigInteger& outputChannels,
  188231. double sr,
  188232. int bufferSizeSamples)
  188233. {
  188234. close();
  188235. currentCallback = 0;
  188236. if (bufferSizeSamples <= 0)
  188237. shouldUsePreferredSize = true;
  188238. if (asioObject == 0 || ! isASIOOpen)
  188239. {
  188240. log ("Warning: device not open");
  188241. const String err (openDevice());
  188242. if (asioObject == 0 || ! isASIOOpen)
  188243. return err;
  188244. }
  188245. isStarted = false;
  188246. bufferIndex = -1;
  188247. long err = 0;
  188248. long newPreferredSize = 0;
  188249. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188250. minSize = 0;
  188251. maxSize = 0;
  188252. newPreferredSize = 0;
  188253. granularity = 0;
  188254. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188255. {
  188256. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188257. shouldUsePreferredSize = true;
  188258. preferredSize = newPreferredSize;
  188259. }
  188260. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188261. // dynamic changes to the buffer size...
  188262. shouldUsePreferredSize = shouldUsePreferredSize
  188263. || getName().containsIgnoreCase (T("Digidesign"));
  188264. if (shouldUsePreferredSize)
  188265. {
  188266. log ("Using preferred size for buffer..");
  188267. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188268. {
  188269. bufferSizeSamples = preferredSize;
  188270. }
  188271. else
  188272. {
  188273. bufferSizeSamples = 1024;
  188274. logError ("GetBufferSize1", err);
  188275. }
  188276. shouldUsePreferredSize = false;
  188277. }
  188278. int sampleRate = roundDoubleToInt (sr);
  188279. currentSampleRate = sampleRate;
  188280. currentBlockSizeSamples = bufferSizeSamples;
  188281. currentChansOut.clear();
  188282. currentChansIn.clear();
  188283. zeromem (inBuffers, sizeof (inBuffers));
  188284. zeromem (outBuffers, sizeof (outBuffers));
  188285. updateSampleRates();
  188286. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188287. sampleRate = sampleRates[0];
  188288. jassert (sampleRate != 0);
  188289. if (sampleRate == 0)
  188290. sampleRate = 44100;
  188291. long numSources = 32;
  188292. ASIOClockSource clocks[32];
  188293. zeromem (clocks, sizeof (clocks));
  188294. asioObject->getClockSources (clocks, &numSources);
  188295. bool isSourceSet = false;
  188296. // careful not to remove this loop because it does more than just logging!
  188297. int i;
  188298. for (i = 0; i < numSources; ++i)
  188299. {
  188300. String s ("clock: ");
  188301. s += clocks[i].name;
  188302. if (clocks[i].isCurrentSource)
  188303. {
  188304. isSourceSet = true;
  188305. s << " (cur)";
  188306. }
  188307. log (s);
  188308. }
  188309. if (numSources > 1 && ! isSourceSet)
  188310. {
  188311. log ("setting clock source");
  188312. asioObject->setClockSource (clocks[0].index);
  188313. Thread::sleep (20);
  188314. }
  188315. else
  188316. {
  188317. if (numSources == 0)
  188318. {
  188319. log ("ASIO - no clock sources!");
  188320. }
  188321. }
  188322. double cr = 0;
  188323. err = asioObject->getSampleRate (&cr);
  188324. if (err == 0)
  188325. {
  188326. currentSampleRate = cr;
  188327. }
  188328. else
  188329. {
  188330. logError ("GetSampleRate", err);
  188331. currentSampleRate = 0;
  188332. }
  188333. error = String::empty;
  188334. needToReset = false;
  188335. isReSync = false;
  188336. err = 0;
  188337. bool buffersCreated = false;
  188338. if (currentSampleRate != sampleRate)
  188339. {
  188340. log (T("ASIO samplerate: ") + String (currentSampleRate) + T(" to ") + String (sampleRate));
  188341. err = asioObject->setSampleRate (sampleRate);
  188342. if (err == ASE_NoClock && numSources > 0)
  188343. {
  188344. log ("trying to set a clock source..");
  188345. Thread::sleep (10);
  188346. err = asioObject->setClockSource (clocks[0].index);
  188347. if (err != 0)
  188348. {
  188349. logError ("SetClock", err);
  188350. }
  188351. Thread::sleep (10);
  188352. err = asioObject->setSampleRate (sampleRate);
  188353. }
  188354. }
  188355. if (err == 0)
  188356. {
  188357. currentSampleRate = sampleRate;
  188358. if (needToReset)
  188359. {
  188360. if (isReSync)
  188361. {
  188362. log ("Resync request");
  188363. }
  188364. log ("! Resetting ASIO after sample rate change");
  188365. removeCurrentDriver();
  188366. loadDriver();
  188367. const String error (initDriver());
  188368. if (error.isNotEmpty())
  188369. {
  188370. log (T("ASIOInit: ") + error);
  188371. }
  188372. needToReset = false;
  188373. isReSync = false;
  188374. }
  188375. numActiveInputChans = 0;
  188376. numActiveOutputChans = 0;
  188377. ASIOBufferInfo* info = bufferInfos;
  188378. int i;
  188379. for (i = 0; i < totalNumInputChans; ++i)
  188380. {
  188381. if (inputChannels[i])
  188382. {
  188383. currentChansIn.setBit (i);
  188384. info->isInput = 1;
  188385. info->channelNum = i;
  188386. info->buffers[0] = info->buffers[1] = 0;
  188387. ++info;
  188388. ++numActiveInputChans;
  188389. }
  188390. }
  188391. for (i = 0; i < totalNumOutputChans; ++i)
  188392. {
  188393. if (outputChannels[i])
  188394. {
  188395. currentChansOut.setBit (i);
  188396. info->isInput = 0;
  188397. info->channelNum = i;
  188398. info->buffers[0] = info->buffers[1] = 0;
  188399. ++info;
  188400. ++numActiveOutputChans;
  188401. }
  188402. }
  188403. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188404. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188405. if (currentASIODev[0] == this)
  188406. {
  188407. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188408. callbacks.asioMessage = &asioMessagesCallback0;
  188409. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188410. }
  188411. else if (currentASIODev[1] == this)
  188412. {
  188413. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188414. callbacks.asioMessage = &asioMessagesCallback1;
  188415. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188416. }
  188417. else if (currentASIODev[2] == this)
  188418. {
  188419. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188420. callbacks.asioMessage = &asioMessagesCallback2;
  188421. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188422. }
  188423. else
  188424. {
  188425. jassertfalse
  188426. }
  188427. log ("disposing buffers");
  188428. err = asioObject->disposeBuffers();
  188429. log (T("creating buffers: ") + String (totalBuffers) + T(", ") + String (currentBlockSizeSamples));
  188430. err = asioObject->createBuffers (bufferInfos,
  188431. totalBuffers,
  188432. currentBlockSizeSamples,
  188433. &callbacks);
  188434. if (err != 0)
  188435. {
  188436. currentBlockSizeSamples = preferredSize;
  188437. logError ("create buffers 2", err);
  188438. asioObject->disposeBuffers();
  188439. err = asioObject->createBuffers (bufferInfos,
  188440. totalBuffers,
  188441. currentBlockSizeSamples,
  188442. &callbacks);
  188443. }
  188444. if (err == 0)
  188445. {
  188446. buffersCreated = true;
  188447. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188448. int n = 0;
  188449. Array <int> types;
  188450. currentBitDepth = 16;
  188451. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188452. {
  188453. if (inputChannels[i])
  188454. {
  188455. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188456. ASIOChannelInfo channelInfo;
  188457. zerostruct (channelInfo);
  188458. channelInfo.channel = i;
  188459. channelInfo.isInput = 1;
  188460. asioObject->getChannelInfo (&channelInfo);
  188461. types.addIfNotAlreadyThere (channelInfo.type);
  188462. typeToFormatParameters (channelInfo.type,
  188463. inputChannelBitDepths[n],
  188464. inputChannelBytesPerSample[n],
  188465. inputChannelIsFloat[n],
  188466. inputChannelLittleEndian[n]);
  188467. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188468. ++n;
  188469. }
  188470. }
  188471. jassert (numActiveInputChans == n);
  188472. n = 0;
  188473. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188474. {
  188475. if (outputChannels[i])
  188476. {
  188477. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188478. ASIOChannelInfo channelInfo;
  188479. zerostruct (channelInfo);
  188480. channelInfo.channel = i;
  188481. channelInfo.isInput = 0;
  188482. asioObject->getChannelInfo (&channelInfo);
  188483. types.addIfNotAlreadyThere (channelInfo.type);
  188484. typeToFormatParameters (channelInfo.type,
  188485. outputChannelBitDepths[n],
  188486. outputChannelBytesPerSample[n],
  188487. outputChannelIsFloat[n],
  188488. outputChannelLittleEndian[n]);
  188489. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188490. ++n;
  188491. }
  188492. }
  188493. jassert (numActiveOutputChans == n);
  188494. for (i = types.size(); --i >= 0;)
  188495. {
  188496. log (T("channel format: ") + String (types[i]));
  188497. }
  188498. jassert (n <= totalBuffers);
  188499. for (i = 0; i < numActiveOutputChans; ++i)
  188500. {
  188501. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188502. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188503. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188504. {
  188505. log ("!! Null buffers");
  188506. }
  188507. else
  188508. {
  188509. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188510. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188511. }
  188512. }
  188513. inputLatency = outputLatency = 0;
  188514. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188515. {
  188516. log ("ASIO - no latencies");
  188517. }
  188518. else
  188519. {
  188520. log (T("ASIO latencies: ")
  188521. + String ((int) outputLatency)
  188522. + T(", ")
  188523. + String ((int) inputLatency));
  188524. }
  188525. isOpen_ = true;
  188526. log ("starting ASIO");
  188527. calledback = false;
  188528. err = asioObject->start();
  188529. if (err != 0)
  188530. {
  188531. isOpen_ = false;
  188532. log ("ASIO - stop on failure");
  188533. Thread::sleep (10);
  188534. asioObject->stop();
  188535. error = "Can't start device";
  188536. Thread::sleep (10);
  188537. }
  188538. else
  188539. {
  188540. int count = 300;
  188541. while (--count > 0 && ! calledback)
  188542. Thread::sleep (10);
  188543. isStarted = true;
  188544. if (! calledback)
  188545. {
  188546. error = "Device didn't start correctly";
  188547. log ("ASIO didn't callback - stopping..");
  188548. asioObject->stop();
  188549. }
  188550. }
  188551. }
  188552. else
  188553. {
  188554. error = "Can't create i/o buffers";
  188555. }
  188556. }
  188557. else
  188558. {
  188559. error = "Can't set sample rate: ";
  188560. error << sampleRate;
  188561. }
  188562. if (error.isNotEmpty())
  188563. {
  188564. logError (error, err);
  188565. if (asioObject != 0 && buffersCreated)
  188566. asioObject->disposeBuffers();
  188567. Thread::sleep (20);
  188568. isStarted = false;
  188569. isOpen_ = false;
  188570. close();
  188571. }
  188572. needToReset = false;
  188573. isReSync = false;
  188574. return error;
  188575. }
  188576. void close()
  188577. {
  188578. error = String::empty;
  188579. stopTimer();
  188580. stop();
  188581. if (isASIOOpen && isOpen_)
  188582. {
  188583. const ScopedLock sl (callbackLock);
  188584. isOpen_ = false;
  188585. isStarted = false;
  188586. needToReset = false;
  188587. isReSync = false;
  188588. log ("ASIO - stopping");
  188589. if (asioObject != 0)
  188590. {
  188591. Thread::sleep (20);
  188592. asioObject->stop();
  188593. Thread::sleep (10);
  188594. asioObject->disposeBuffers();
  188595. }
  188596. Thread::sleep (10);
  188597. }
  188598. }
  188599. bool isOpen()
  188600. {
  188601. return isOpen_ || insideControlPanelModalLoop;
  188602. }
  188603. int getCurrentBufferSizeSamples()
  188604. {
  188605. return currentBlockSizeSamples;
  188606. }
  188607. double getCurrentSampleRate()
  188608. {
  188609. return currentSampleRate;
  188610. }
  188611. const BigInteger getActiveOutputChannels() const
  188612. {
  188613. return currentChansOut;
  188614. }
  188615. const BigInteger getActiveInputChannels() const
  188616. {
  188617. return currentChansIn;
  188618. }
  188619. int getCurrentBitDepth()
  188620. {
  188621. return currentBitDepth;
  188622. }
  188623. int getOutputLatencyInSamples()
  188624. {
  188625. return outputLatency + currentBlockSizeSamples / 4;
  188626. }
  188627. int getInputLatencyInSamples()
  188628. {
  188629. return inputLatency + currentBlockSizeSamples / 4;
  188630. }
  188631. void start (AudioIODeviceCallback* callback)
  188632. {
  188633. if (callback != 0)
  188634. {
  188635. callback->audioDeviceAboutToStart (this);
  188636. const ScopedLock sl (callbackLock);
  188637. currentCallback = callback;
  188638. }
  188639. }
  188640. void stop()
  188641. {
  188642. AudioIODeviceCallback* const lastCallback = currentCallback;
  188643. {
  188644. const ScopedLock sl (callbackLock);
  188645. currentCallback = 0;
  188646. }
  188647. if (lastCallback != 0)
  188648. lastCallback->audioDeviceStopped();
  188649. }
  188650. bool isPlaying()
  188651. {
  188652. return isASIOOpen && (currentCallback != 0);
  188653. }
  188654. const String getLastError()
  188655. {
  188656. return error;
  188657. }
  188658. bool hasControlPanel() const
  188659. {
  188660. return true;
  188661. }
  188662. bool showControlPanel()
  188663. {
  188664. log ("ASIO - showing control panel");
  188665. Component modalWindow (String::empty);
  188666. modalWindow.setOpaque (true);
  188667. modalWindow.addToDesktop (0);
  188668. modalWindow.enterModalState();
  188669. bool done = false;
  188670. JUCE_TRY
  188671. {
  188672. // are there are devices that need to be closed before showing their control panel?
  188673. // close();
  188674. insideControlPanelModalLoop = true;
  188675. const uint32 started = Time::getMillisecondCounter();
  188676. if (asioObject != 0)
  188677. {
  188678. asioObject->controlPanel();
  188679. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  188680. log (T("spent: ") + String (spent));
  188681. if (spent > 300)
  188682. {
  188683. shouldUsePreferredSize = true;
  188684. done = true;
  188685. }
  188686. }
  188687. }
  188688. JUCE_CATCH_ALL
  188689. insideControlPanelModalLoop = false;
  188690. return done;
  188691. }
  188692. void resetRequest() throw()
  188693. {
  188694. needToReset = true;
  188695. }
  188696. void resyncRequest() throw()
  188697. {
  188698. needToReset = true;
  188699. isReSync = true;
  188700. }
  188701. void timerCallback()
  188702. {
  188703. if (! insideControlPanelModalLoop)
  188704. {
  188705. stopTimer();
  188706. // used to cause a reset
  188707. log ("! ASIO restart request!");
  188708. if (isOpen_)
  188709. {
  188710. AudioIODeviceCallback* const oldCallback = currentCallback;
  188711. close();
  188712. open (BigInteger (currentChansIn), BigInteger (currentChansOut),
  188713. currentSampleRate, currentBlockSizeSamples);
  188714. if (oldCallback != 0)
  188715. start (oldCallback);
  188716. }
  188717. }
  188718. else
  188719. {
  188720. startTimer (100);
  188721. }
  188722. }
  188723. juce_UseDebuggingNewOperator
  188724. private:
  188725. IASIO* volatile asioObject;
  188726. ASIOCallbacks callbacks;
  188727. void* windowHandle;
  188728. CLSID classId;
  188729. const String optionalDllForDirectLoading;
  188730. String error;
  188731. long totalNumInputChans, totalNumOutputChans;
  188732. StringArray inputChannelNames, outputChannelNames;
  188733. Array<int> sampleRates, bufferSizes;
  188734. long inputLatency, outputLatency;
  188735. long minSize, maxSize, preferredSize, granularity;
  188736. int volatile currentBlockSizeSamples;
  188737. int volatile currentBitDepth;
  188738. double volatile currentSampleRate;
  188739. BigInteger currentChansOut, currentChansIn;
  188740. AudioIODeviceCallback* volatile currentCallback;
  188741. CriticalSection callbackLock;
  188742. ASIOBufferInfo bufferInfos [maxASIOChannels];
  188743. float* inBuffers [maxASIOChannels];
  188744. float* outBuffers [maxASIOChannels];
  188745. int inputChannelBitDepths [maxASIOChannels];
  188746. int outputChannelBitDepths [maxASIOChannels];
  188747. int inputChannelBytesPerSample [maxASIOChannels];
  188748. int outputChannelBytesPerSample [maxASIOChannels];
  188749. bool inputChannelIsFloat [maxASIOChannels];
  188750. bool outputChannelIsFloat [maxASIOChannels];
  188751. bool inputChannelLittleEndian [maxASIOChannels];
  188752. bool outputChannelLittleEndian [maxASIOChannels];
  188753. WaitableEvent event1;
  188754. HeapBlock <float> tempBuffer;
  188755. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  188756. bool isOpen_, isStarted;
  188757. bool volatile isASIOOpen;
  188758. bool volatile calledback;
  188759. bool volatile littleEndian, postOutput, needToReset, isReSync;
  188760. bool volatile insideControlPanelModalLoop;
  188761. bool volatile shouldUsePreferredSize;
  188762. void removeCurrentDriver()
  188763. {
  188764. if (asioObject != 0)
  188765. {
  188766. asioObject->Release();
  188767. asioObject = 0;
  188768. }
  188769. }
  188770. bool loadDriver()
  188771. {
  188772. removeCurrentDriver();
  188773. JUCE_TRY
  188774. {
  188775. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  188776. classId, (void**) &asioObject) == S_OK)
  188777. {
  188778. return true;
  188779. }
  188780. // If a class isn't registered but we have a path for it, we can fallback to
  188781. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  188782. if (optionalDllForDirectLoading.isNotEmpty())
  188783. {
  188784. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  188785. if (h != 0)
  188786. {
  188787. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  188788. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  188789. if (dllGetClassObject != 0)
  188790. {
  188791. IClassFactory* classFactory = 0;
  188792. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  188793. if (classFactory != 0)
  188794. {
  188795. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  188796. classFactory->Release();
  188797. }
  188798. return asioObject != 0;
  188799. }
  188800. }
  188801. }
  188802. }
  188803. JUCE_CATCH_ALL
  188804. asioObject = 0;
  188805. return false;
  188806. }
  188807. const String initDriver()
  188808. {
  188809. if (asioObject != 0)
  188810. {
  188811. char buffer [256];
  188812. zeromem (buffer, sizeof (buffer));
  188813. if (! asioObject->init (windowHandle))
  188814. {
  188815. asioObject->getErrorMessage (buffer);
  188816. return String (buffer, sizeof (buffer) - 1);
  188817. }
  188818. // just in case any daft drivers expect this to be called..
  188819. asioObject->getDriverName (buffer);
  188820. return String::empty;
  188821. }
  188822. return "No Driver";
  188823. }
  188824. const String openDevice()
  188825. {
  188826. // use this in case the driver starts opening dialog boxes..
  188827. Component modalWindow (String::empty);
  188828. modalWindow.setOpaque (true);
  188829. modalWindow.addToDesktop (0);
  188830. modalWindow.enterModalState();
  188831. // open the device and get its info..
  188832. log (T("opening ASIO device: ") + getName());
  188833. needToReset = false;
  188834. isReSync = false;
  188835. outputChannelNames.clear();
  188836. inputChannelNames.clear();
  188837. bufferSizes.clear();
  188838. sampleRates.clear();
  188839. isASIOOpen = false;
  188840. isOpen_ = false;
  188841. totalNumInputChans = 0;
  188842. totalNumOutputChans = 0;
  188843. numActiveInputChans = 0;
  188844. numActiveOutputChans = 0;
  188845. currentCallback = 0;
  188846. error = String::empty;
  188847. if (getName().isEmpty())
  188848. return error;
  188849. long err = 0;
  188850. if (loadDriver())
  188851. {
  188852. if ((error = initDriver()).isEmpty())
  188853. {
  188854. numActiveInputChans = 0;
  188855. numActiveOutputChans = 0;
  188856. totalNumInputChans = 0;
  188857. totalNumOutputChans = 0;
  188858. if (asioObject != 0
  188859. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  188860. {
  188861. log (String ((int) totalNumInputChans) + T(" in, ") + String ((int) totalNumOutputChans) + T(" out"));
  188862. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188863. {
  188864. // find a list of buffer sizes..
  188865. log (String ((int) minSize) + T(" ") + String ((int) maxSize) + T(" ") + String ((int)preferredSize) + T(" ") + String ((int)granularity));
  188866. if (granularity >= 0)
  188867. {
  188868. granularity = jmax (1, (int) granularity);
  188869. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  188870. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  188871. }
  188872. else if (granularity < 0)
  188873. {
  188874. for (int i = 0; i < 18; ++i)
  188875. {
  188876. const int s = (1 << i);
  188877. if (s >= minSize && s <= maxSize)
  188878. bufferSizes.add (s);
  188879. }
  188880. }
  188881. if (! bufferSizes.contains (preferredSize))
  188882. bufferSizes.insert (0, preferredSize);
  188883. double currentRate = 0;
  188884. asioObject->getSampleRate (&currentRate);
  188885. if (currentRate <= 0.0 || currentRate > 192001.0)
  188886. {
  188887. log ("setting sample rate");
  188888. err = asioObject->setSampleRate (44100.0);
  188889. if (err != 0)
  188890. {
  188891. logError ("setting sample rate", err);
  188892. }
  188893. asioObject->getSampleRate (&currentRate);
  188894. }
  188895. currentSampleRate = currentRate;
  188896. postOutput = (asioObject->outputReady() == 0);
  188897. if (postOutput)
  188898. {
  188899. log ("ASIO outputReady = ok");
  188900. }
  188901. updateSampleRates();
  188902. // ..because cubase does it at this point
  188903. inputLatency = outputLatency = 0;
  188904. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188905. {
  188906. log ("ASIO - no latencies");
  188907. }
  188908. log (String ("latencies: ")
  188909. + String ((int) inputLatency)
  188910. + T(", ") + String ((int) outputLatency));
  188911. // create some dummy buffers now.. because cubase does..
  188912. numActiveInputChans = 0;
  188913. numActiveOutputChans = 0;
  188914. ASIOBufferInfo* info = bufferInfos;
  188915. int i, numChans = 0;
  188916. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  188917. {
  188918. info->isInput = 1;
  188919. info->channelNum = i;
  188920. info->buffers[0] = info->buffers[1] = 0;
  188921. ++info;
  188922. ++numChans;
  188923. }
  188924. const int outputBufferIndex = numChans;
  188925. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  188926. {
  188927. info->isInput = 0;
  188928. info->channelNum = i;
  188929. info->buffers[0] = info->buffers[1] = 0;
  188930. ++info;
  188931. ++numChans;
  188932. }
  188933. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188934. if (currentASIODev[0] == this)
  188935. {
  188936. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188937. callbacks.asioMessage = &asioMessagesCallback0;
  188938. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188939. }
  188940. else if (currentASIODev[1] == this)
  188941. {
  188942. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188943. callbacks.asioMessage = &asioMessagesCallback1;
  188944. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188945. }
  188946. else if (currentASIODev[2] == this)
  188947. {
  188948. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188949. callbacks.asioMessage = &asioMessagesCallback2;
  188950. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188951. }
  188952. else
  188953. {
  188954. jassertfalse
  188955. }
  188956. log (T("creating buffers (dummy): ") + String (numChans)
  188957. + T(", ") + String ((int) preferredSize));
  188958. if (preferredSize > 0)
  188959. {
  188960. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  188961. if (err != 0)
  188962. {
  188963. logError ("dummy buffers", err);
  188964. }
  188965. }
  188966. long newInps = 0, newOuts = 0;
  188967. asioObject->getChannels (&newInps, &newOuts);
  188968. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  188969. {
  188970. totalNumInputChans = newInps;
  188971. totalNumOutputChans = newOuts;
  188972. log (String ((int) totalNumInputChans) + T(" in; ")
  188973. + String ((int) totalNumOutputChans) + T(" out"));
  188974. }
  188975. updateSampleRates();
  188976. ASIOChannelInfo channelInfo;
  188977. channelInfo.type = 0;
  188978. for (i = 0; i < totalNumInputChans; ++i)
  188979. {
  188980. zerostruct (channelInfo);
  188981. channelInfo.channel = i;
  188982. channelInfo.isInput = 1;
  188983. asioObject->getChannelInfo (&channelInfo);
  188984. inputChannelNames.add (String (channelInfo.name));
  188985. }
  188986. for (i = 0; i < totalNumOutputChans; ++i)
  188987. {
  188988. zerostruct (channelInfo);
  188989. channelInfo.channel = i;
  188990. channelInfo.isInput = 0;
  188991. asioObject->getChannelInfo (&channelInfo);
  188992. outputChannelNames.add (String (channelInfo.name));
  188993. typeToFormatParameters (channelInfo.type,
  188994. outputChannelBitDepths[i],
  188995. outputChannelBytesPerSample[i],
  188996. outputChannelIsFloat[i],
  188997. outputChannelLittleEndian[i]);
  188998. if (i < 2)
  188999. {
  189000. // clear the channels that are used with the dummy stuff
  189001. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  189002. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  189003. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  189004. }
  189005. }
  189006. outputChannelNames.trim();
  189007. inputChannelNames.trim();
  189008. outputChannelNames.appendNumbersToDuplicates (false, true);
  189009. inputChannelNames.appendNumbersToDuplicates (false, true);
  189010. // start and stop because cubase does it..
  189011. asioObject->getLatencies (&inputLatency, &outputLatency);
  189012. if ((err = asioObject->start()) != 0)
  189013. {
  189014. // ignore an error here, as it might start later after setting other stuff up
  189015. logError ("ASIO start", err);
  189016. }
  189017. Thread::sleep (100);
  189018. asioObject->stop();
  189019. }
  189020. else
  189021. {
  189022. error = "Can't detect buffer sizes";
  189023. }
  189024. }
  189025. else
  189026. {
  189027. error = "Can't detect asio channels";
  189028. }
  189029. }
  189030. }
  189031. else
  189032. {
  189033. error = "No such device";
  189034. }
  189035. if (error.isNotEmpty())
  189036. {
  189037. logError (error, err);
  189038. if (asioObject != 0)
  189039. asioObject->disposeBuffers();
  189040. removeCurrentDriver();
  189041. isASIOOpen = false;
  189042. }
  189043. else
  189044. {
  189045. isASIOOpen = true;
  189046. log ("ASIO device open");
  189047. }
  189048. isOpen_ = false;
  189049. needToReset = false;
  189050. isReSync = false;
  189051. return error;
  189052. }
  189053. void callback (const long index) throw()
  189054. {
  189055. if (isStarted)
  189056. {
  189057. bufferIndex = index;
  189058. processBuffer();
  189059. }
  189060. else
  189061. {
  189062. if (postOutput && (asioObject != 0))
  189063. asioObject->outputReady();
  189064. }
  189065. calledback = true;
  189066. }
  189067. void processBuffer() throw()
  189068. {
  189069. const ASIOBufferInfo* const infos = bufferInfos;
  189070. const int bi = bufferIndex;
  189071. const ScopedLock sl (callbackLock);
  189072. if (needToReset)
  189073. {
  189074. needToReset = false;
  189075. if (isReSync)
  189076. {
  189077. log ("! ASIO resync");
  189078. isReSync = false;
  189079. }
  189080. else
  189081. {
  189082. startTimer (20);
  189083. }
  189084. }
  189085. if (bi >= 0)
  189086. {
  189087. const int samps = currentBlockSizeSamples;
  189088. if (currentCallback != 0)
  189089. {
  189090. int i;
  189091. for (i = 0; i < numActiveInputChans; ++i)
  189092. {
  189093. float* const dst = inBuffers[i];
  189094. jassert (dst != 0);
  189095. const char* const src = (const char*) (infos[i].buffers[bi]);
  189096. if (inputChannelIsFloat[i])
  189097. {
  189098. memcpy (dst, src, samps * sizeof (float));
  189099. }
  189100. else
  189101. {
  189102. jassert (dst == tempBuffer + (samps * i));
  189103. switch (inputChannelBitDepths[i])
  189104. {
  189105. case 16:
  189106. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189107. samps, inputChannelLittleEndian[i]);
  189108. break;
  189109. case 24:
  189110. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189111. samps, inputChannelLittleEndian[i]);
  189112. break;
  189113. case 32:
  189114. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189115. samps, inputChannelLittleEndian[i]);
  189116. break;
  189117. case 64:
  189118. jassertfalse
  189119. break;
  189120. }
  189121. }
  189122. }
  189123. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189124. numActiveInputChans,
  189125. outBuffers,
  189126. numActiveOutputChans,
  189127. samps);
  189128. for (i = 0; i < numActiveOutputChans; ++i)
  189129. {
  189130. float* const src = outBuffers[i];
  189131. jassert (src != 0);
  189132. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189133. if (outputChannelIsFloat[i])
  189134. {
  189135. memcpy (dst, src, samps * sizeof (float));
  189136. }
  189137. else
  189138. {
  189139. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189140. switch (outputChannelBitDepths[i])
  189141. {
  189142. case 16:
  189143. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189144. samps, outputChannelLittleEndian[i]);
  189145. break;
  189146. case 24:
  189147. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189148. samps, outputChannelLittleEndian[i]);
  189149. break;
  189150. case 32:
  189151. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189152. samps, outputChannelLittleEndian[i]);
  189153. break;
  189154. case 64:
  189155. jassertfalse
  189156. break;
  189157. }
  189158. }
  189159. }
  189160. }
  189161. else
  189162. {
  189163. for (int i = 0; i < numActiveOutputChans; ++i)
  189164. {
  189165. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189166. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189167. }
  189168. }
  189169. }
  189170. if (postOutput)
  189171. asioObject->outputReady();
  189172. }
  189173. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189174. {
  189175. if (currentASIODev[0] != 0)
  189176. currentASIODev[0]->callback (index);
  189177. return 0;
  189178. }
  189179. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189180. {
  189181. if (currentASIODev[1] != 0)
  189182. currentASIODev[1]->callback (index);
  189183. return 0;
  189184. }
  189185. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189186. {
  189187. if (currentASIODev[2] != 0)
  189188. currentASIODev[2]->callback (index);
  189189. return 0;
  189190. }
  189191. static void bufferSwitchCallback0 (long index, long) throw()
  189192. {
  189193. if (currentASIODev[0] != 0)
  189194. currentASIODev[0]->callback (index);
  189195. }
  189196. static void bufferSwitchCallback1 (long index, long) throw()
  189197. {
  189198. if (currentASIODev[1] != 0)
  189199. currentASIODev[1]->callback (index);
  189200. }
  189201. static void bufferSwitchCallback2 (long index, long) throw()
  189202. {
  189203. if (currentASIODev[2] != 0)
  189204. currentASIODev[2]->callback (index);
  189205. }
  189206. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189207. {
  189208. return asioMessagesCallback (selector, value, 0);
  189209. }
  189210. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189211. {
  189212. return asioMessagesCallback (selector, value, 1);
  189213. }
  189214. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189215. {
  189216. return asioMessagesCallback (selector, value, 2);
  189217. }
  189218. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189219. {
  189220. switch (selector)
  189221. {
  189222. case kAsioSelectorSupported:
  189223. if (value == kAsioResetRequest
  189224. || value == kAsioEngineVersion
  189225. || value == kAsioResyncRequest
  189226. || value == kAsioLatenciesChanged
  189227. || value == kAsioSupportsInputMonitor)
  189228. return 1;
  189229. break;
  189230. case kAsioBufferSizeChange:
  189231. break;
  189232. case kAsioResetRequest:
  189233. if (currentASIODev[deviceIndex] != 0)
  189234. currentASIODev[deviceIndex]->resetRequest();
  189235. return 1;
  189236. case kAsioResyncRequest:
  189237. if (currentASIODev[deviceIndex] != 0)
  189238. currentASIODev[deviceIndex]->resyncRequest();
  189239. return 1;
  189240. case kAsioLatenciesChanged:
  189241. return 1;
  189242. case kAsioEngineVersion:
  189243. return 2;
  189244. case kAsioSupportsTimeInfo:
  189245. case kAsioSupportsTimeCode:
  189246. return 0;
  189247. }
  189248. return 0;
  189249. }
  189250. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189251. {
  189252. }
  189253. static void convertInt16ToFloat (const char* src,
  189254. float* dest,
  189255. const int srcStrideBytes,
  189256. int numSamples,
  189257. const bool littleEndian) throw()
  189258. {
  189259. const double g = 1.0 / 32768.0;
  189260. if (littleEndian)
  189261. {
  189262. while (--numSamples >= 0)
  189263. {
  189264. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189265. src += srcStrideBytes;
  189266. }
  189267. }
  189268. else
  189269. {
  189270. while (--numSamples >= 0)
  189271. {
  189272. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189273. src += srcStrideBytes;
  189274. }
  189275. }
  189276. }
  189277. static void convertFloatToInt16 (const float* src,
  189278. char* dest,
  189279. const int dstStrideBytes,
  189280. int numSamples,
  189281. const bool littleEndian) throw()
  189282. {
  189283. const double maxVal = (double) 0x7fff;
  189284. if (littleEndian)
  189285. {
  189286. while (--numSamples >= 0)
  189287. {
  189288. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189289. dest += dstStrideBytes;
  189290. }
  189291. }
  189292. else
  189293. {
  189294. while (--numSamples >= 0)
  189295. {
  189296. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189297. dest += dstStrideBytes;
  189298. }
  189299. }
  189300. }
  189301. static void convertInt24ToFloat (const char* src,
  189302. float* dest,
  189303. const int srcStrideBytes,
  189304. int numSamples,
  189305. const bool littleEndian) throw()
  189306. {
  189307. const double g = 1.0 / 0x7fffff;
  189308. if (littleEndian)
  189309. {
  189310. while (--numSamples >= 0)
  189311. {
  189312. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189313. src += srcStrideBytes;
  189314. }
  189315. }
  189316. else
  189317. {
  189318. while (--numSamples >= 0)
  189319. {
  189320. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189321. src += srcStrideBytes;
  189322. }
  189323. }
  189324. }
  189325. static void convertFloatToInt24 (const float* src,
  189326. char* dest,
  189327. const int dstStrideBytes,
  189328. int numSamples,
  189329. const bool littleEndian) throw()
  189330. {
  189331. const double maxVal = (double) 0x7fffff;
  189332. if (littleEndian)
  189333. {
  189334. while (--numSamples >= 0)
  189335. {
  189336. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189337. dest += dstStrideBytes;
  189338. }
  189339. }
  189340. else
  189341. {
  189342. while (--numSamples >= 0)
  189343. {
  189344. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189345. dest += dstStrideBytes;
  189346. }
  189347. }
  189348. }
  189349. static void convertInt32ToFloat (const char* src,
  189350. float* dest,
  189351. const int srcStrideBytes,
  189352. int numSamples,
  189353. const bool littleEndian) throw()
  189354. {
  189355. const double g = 1.0 / 0x7fffffff;
  189356. if (littleEndian)
  189357. {
  189358. while (--numSamples >= 0)
  189359. {
  189360. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189361. src += srcStrideBytes;
  189362. }
  189363. }
  189364. else
  189365. {
  189366. while (--numSamples >= 0)
  189367. {
  189368. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189369. src += srcStrideBytes;
  189370. }
  189371. }
  189372. }
  189373. static void convertFloatToInt32 (const float* src,
  189374. char* dest,
  189375. const int dstStrideBytes,
  189376. int numSamples,
  189377. const bool littleEndian) throw()
  189378. {
  189379. const double maxVal = (double) 0x7fffffff;
  189380. if (littleEndian)
  189381. {
  189382. while (--numSamples >= 0)
  189383. {
  189384. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189385. dest += dstStrideBytes;
  189386. }
  189387. }
  189388. else
  189389. {
  189390. while (--numSamples >= 0)
  189391. {
  189392. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189393. dest += dstStrideBytes;
  189394. }
  189395. }
  189396. }
  189397. static void typeToFormatParameters (const long type,
  189398. int& bitDepth,
  189399. int& byteStride,
  189400. bool& formatIsFloat,
  189401. bool& littleEndian) throw()
  189402. {
  189403. bitDepth = 0;
  189404. littleEndian = false;
  189405. formatIsFloat = false;
  189406. switch (type)
  189407. {
  189408. case ASIOSTInt16MSB:
  189409. case ASIOSTInt16LSB:
  189410. case ASIOSTInt32MSB16:
  189411. case ASIOSTInt32LSB16:
  189412. bitDepth = 16; break;
  189413. case ASIOSTFloat32MSB:
  189414. case ASIOSTFloat32LSB:
  189415. formatIsFloat = true;
  189416. bitDepth = 32; break;
  189417. case ASIOSTInt32MSB:
  189418. case ASIOSTInt32LSB:
  189419. bitDepth = 32; break;
  189420. case ASIOSTInt24MSB:
  189421. case ASIOSTInt24LSB:
  189422. case ASIOSTInt32MSB24:
  189423. case ASIOSTInt32LSB24:
  189424. case ASIOSTInt32MSB18:
  189425. case ASIOSTInt32MSB20:
  189426. case ASIOSTInt32LSB18:
  189427. case ASIOSTInt32LSB20:
  189428. bitDepth = 24; break;
  189429. case ASIOSTFloat64MSB:
  189430. case ASIOSTFloat64LSB:
  189431. default:
  189432. bitDepth = 64;
  189433. break;
  189434. }
  189435. switch (type)
  189436. {
  189437. case ASIOSTInt16MSB:
  189438. case ASIOSTInt32MSB16:
  189439. case ASIOSTFloat32MSB:
  189440. case ASIOSTFloat64MSB:
  189441. case ASIOSTInt32MSB:
  189442. case ASIOSTInt32MSB18:
  189443. case ASIOSTInt32MSB20:
  189444. case ASIOSTInt32MSB24:
  189445. case ASIOSTInt24MSB:
  189446. littleEndian = false; break;
  189447. case ASIOSTInt16LSB:
  189448. case ASIOSTInt32LSB16:
  189449. case ASIOSTFloat32LSB:
  189450. case ASIOSTFloat64LSB:
  189451. case ASIOSTInt32LSB:
  189452. case ASIOSTInt32LSB18:
  189453. case ASIOSTInt32LSB20:
  189454. case ASIOSTInt32LSB24:
  189455. case ASIOSTInt24LSB:
  189456. littleEndian = true; break;
  189457. default:
  189458. break;
  189459. }
  189460. switch (type)
  189461. {
  189462. case ASIOSTInt16LSB:
  189463. case ASIOSTInt16MSB:
  189464. byteStride = 2; break;
  189465. case ASIOSTInt24LSB:
  189466. case ASIOSTInt24MSB:
  189467. byteStride = 3; break;
  189468. case ASIOSTInt32MSB16:
  189469. case ASIOSTInt32LSB16:
  189470. case ASIOSTInt32MSB:
  189471. case ASIOSTInt32MSB18:
  189472. case ASIOSTInt32MSB20:
  189473. case ASIOSTInt32MSB24:
  189474. case ASIOSTInt32LSB:
  189475. case ASIOSTInt32LSB18:
  189476. case ASIOSTInt32LSB20:
  189477. case ASIOSTInt32LSB24:
  189478. case ASIOSTFloat32LSB:
  189479. case ASIOSTFloat32MSB:
  189480. byteStride = 4; break;
  189481. case ASIOSTFloat64MSB:
  189482. case ASIOSTFloat64LSB:
  189483. byteStride = 8; break;
  189484. default:
  189485. break;
  189486. }
  189487. }
  189488. };
  189489. class ASIOAudioIODeviceType : public AudioIODeviceType
  189490. {
  189491. public:
  189492. ASIOAudioIODeviceType()
  189493. : AudioIODeviceType (T("ASIO")),
  189494. hasScanned (false)
  189495. {
  189496. CoInitialize (0);
  189497. }
  189498. ~ASIOAudioIODeviceType()
  189499. {
  189500. }
  189501. void scanForDevices()
  189502. {
  189503. hasScanned = true;
  189504. deviceNames.clear();
  189505. classIds.clear();
  189506. HKEY hk = 0;
  189507. int index = 0;
  189508. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189509. {
  189510. for (;;)
  189511. {
  189512. char name [256];
  189513. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189514. {
  189515. addDriverInfo (name, hk);
  189516. }
  189517. else
  189518. {
  189519. break;
  189520. }
  189521. }
  189522. RegCloseKey (hk);
  189523. }
  189524. }
  189525. const StringArray getDeviceNames (const bool /*wantInputNames*/) const
  189526. {
  189527. jassert (hasScanned); // need to call scanForDevices() before doing this
  189528. return deviceNames;
  189529. }
  189530. int getDefaultDeviceIndex (const bool) const
  189531. {
  189532. jassert (hasScanned); // need to call scanForDevices() before doing this
  189533. for (int i = deviceNames.size(); --i >= 0;)
  189534. if (deviceNames[i].containsIgnoreCase (T("asio4all")))
  189535. return i; // asio4all is a safe choice for a default..
  189536. #if JUCE_DEBUG
  189537. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase (T("digidesign")))
  189538. return 1; // (the digi m-box driver crashes the app when you run
  189539. // it in the debugger, which can be a bit annoying)
  189540. #endif
  189541. return 0;
  189542. }
  189543. static int findFreeSlot()
  189544. {
  189545. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  189546. if (currentASIODev[i] == 0)
  189547. return i;
  189548. jassertfalse; // unfortunately you can only have a finite number
  189549. // of ASIO devices open at the same time..
  189550. return -1;
  189551. }
  189552. int getIndexOfDevice (AudioIODevice* d, const bool /*asInput*/) const
  189553. {
  189554. jassert (hasScanned); // need to call scanForDevices() before doing this
  189555. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  189556. }
  189557. bool hasSeparateInputsAndOutputs() const { return false; }
  189558. AudioIODevice* createDevice (const String& outputDeviceName,
  189559. const String& inputDeviceName)
  189560. {
  189561. // ASIO can't open two different devices for input and output - they must be the same one.
  189562. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  189563. jassert (hasScanned); // need to call scanForDevices() before doing this
  189564. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  189565. : inputDeviceName);
  189566. if (index >= 0)
  189567. {
  189568. const int freeSlot = findFreeSlot();
  189569. if (freeSlot >= 0)
  189570. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  189571. }
  189572. return 0;
  189573. }
  189574. juce_UseDebuggingNewOperator
  189575. private:
  189576. StringArray deviceNames;
  189577. OwnedArray <CLSID> classIds;
  189578. bool hasScanned;
  189579. static bool checkClassIsOk (const String& classId)
  189580. {
  189581. HKEY hk = 0;
  189582. bool ok = false;
  189583. if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS)
  189584. {
  189585. int index = 0;
  189586. for (;;)
  189587. {
  189588. WCHAR buf [512];
  189589. if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS)
  189590. {
  189591. if (classId.equalsIgnoreCase (buf))
  189592. {
  189593. HKEY subKey, pathKey;
  189594. if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189595. {
  189596. if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  189597. {
  189598. WCHAR pathName [1024];
  189599. DWORD dtype = REG_SZ;
  189600. DWORD dsize = sizeof (pathName);
  189601. if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  189602. ok = File (pathName).exists();
  189603. RegCloseKey (pathKey);
  189604. }
  189605. RegCloseKey (subKey);
  189606. }
  189607. break;
  189608. }
  189609. }
  189610. else
  189611. {
  189612. break;
  189613. }
  189614. }
  189615. RegCloseKey (hk);
  189616. }
  189617. return ok;
  189618. }
  189619. void addDriverInfo (const String& keyName, HKEY hk)
  189620. {
  189621. HKEY subKey;
  189622. if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189623. {
  189624. WCHAR buf [256];
  189625. zerostruct (buf);
  189626. DWORD dtype = REG_SZ;
  189627. DWORD dsize = sizeof (buf);
  189628. if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189629. {
  189630. if (dsize > 0 && checkClassIsOk (buf))
  189631. {
  189632. CLSID classId;
  189633. if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK)
  189634. {
  189635. dtype = REG_SZ;
  189636. dsize = sizeof (buf);
  189637. String deviceName;
  189638. if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189639. deviceName = buf;
  189640. else
  189641. deviceName = keyName;
  189642. log (T("found ") + deviceName);
  189643. deviceNames.add (deviceName);
  189644. classIds.add (new CLSID (classId));
  189645. }
  189646. }
  189647. RegCloseKey (subKey);
  189648. }
  189649. }
  189650. }
  189651. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  189652. ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  189653. };
  189654. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  189655. {
  189656. return new ASIOAudioIODeviceType();
  189657. }
  189658. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  189659. void* guid,
  189660. const String& optionalDllForDirectLoading)
  189661. {
  189662. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  189663. if (freeSlot < 0)
  189664. return 0;
  189665. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  189666. }
  189667. #undef log
  189668. #endif
  189669. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  189670. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  189671. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  189672. // compiled on its own).
  189673. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  189674. END_JUCE_NAMESPACE
  189675. extern "C"
  189676. {
  189677. // Declare just the minimum number of interfaces for the DSound objects that we need..
  189678. typedef struct typeDSBUFFERDESC
  189679. {
  189680. DWORD dwSize;
  189681. DWORD dwFlags;
  189682. DWORD dwBufferBytes;
  189683. DWORD dwReserved;
  189684. LPWAVEFORMATEX lpwfxFormat;
  189685. GUID guid3DAlgorithm;
  189686. } DSBUFFERDESC;
  189687. struct IDirectSoundBuffer;
  189688. #undef INTERFACE
  189689. #define INTERFACE IDirectSound
  189690. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  189691. {
  189692. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189693. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189694. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189695. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  189696. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189697. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  189698. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  189699. STDMETHOD(Compact) (THIS) PURE;
  189700. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  189701. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  189702. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189703. };
  189704. #undef INTERFACE
  189705. #define INTERFACE IDirectSoundBuffer
  189706. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  189707. {
  189708. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189709. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189710. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189711. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189712. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189713. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189714. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  189715. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  189716. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  189717. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189718. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  189719. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189720. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  189721. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  189722. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  189723. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  189724. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  189725. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  189726. STDMETHOD(Stop) (THIS) PURE;
  189727. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189728. STDMETHOD(Restore) (THIS) PURE;
  189729. };
  189730. typedef struct typeDSCBUFFERDESC
  189731. {
  189732. DWORD dwSize;
  189733. DWORD dwFlags;
  189734. DWORD dwBufferBytes;
  189735. DWORD dwReserved;
  189736. LPWAVEFORMATEX lpwfxFormat;
  189737. } DSCBUFFERDESC;
  189738. struct IDirectSoundCaptureBuffer;
  189739. #undef INTERFACE
  189740. #define INTERFACE IDirectSoundCapture
  189741. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  189742. {
  189743. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189744. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189745. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189746. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  189747. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189748. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189749. };
  189750. #undef INTERFACE
  189751. #define INTERFACE IDirectSoundCaptureBuffer
  189752. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  189753. {
  189754. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189755. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189756. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189757. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189758. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189759. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189760. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189761. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  189762. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189763. STDMETHOD(Start) (THIS_ DWORD) PURE;
  189764. STDMETHOD(Stop) (THIS) PURE;
  189765. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189766. };
  189767. };
  189768. BEGIN_JUCE_NAMESPACE
  189769. static const String getDSErrorMessage (HRESULT hr)
  189770. {
  189771. const char* result = 0;
  189772. switch (hr)
  189773. {
  189774. case MAKE_HRESULT(1, 0x878, 10):
  189775. result = "Device already allocated";
  189776. break;
  189777. case MAKE_HRESULT(1, 0x878, 30):
  189778. result = "Control unavailable";
  189779. break;
  189780. case E_INVALIDARG:
  189781. result = "Invalid parameter";
  189782. break;
  189783. case MAKE_HRESULT(1, 0x878, 50):
  189784. result = "Invalid call";
  189785. break;
  189786. case E_FAIL:
  189787. result = "Generic error";
  189788. break;
  189789. case MAKE_HRESULT(1, 0x878, 70):
  189790. result = "Priority level error";
  189791. break;
  189792. case E_OUTOFMEMORY:
  189793. result = "Out of memory";
  189794. break;
  189795. case MAKE_HRESULT(1, 0x878, 100):
  189796. result = "Bad format";
  189797. break;
  189798. case E_NOTIMPL:
  189799. result = "Unsupported function";
  189800. break;
  189801. case MAKE_HRESULT(1, 0x878, 120):
  189802. result = "No driver";
  189803. break;
  189804. case MAKE_HRESULT(1, 0x878, 130):
  189805. result = "Already initialised";
  189806. break;
  189807. case CLASS_E_NOAGGREGATION:
  189808. result = "No aggregation";
  189809. break;
  189810. case MAKE_HRESULT(1, 0x878, 150):
  189811. result = "Buffer lost";
  189812. break;
  189813. case MAKE_HRESULT(1, 0x878, 160):
  189814. result = "Another app has priority";
  189815. break;
  189816. case MAKE_HRESULT(1, 0x878, 170):
  189817. result = "Uninitialised";
  189818. break;
  189819. case E_NOINTERFACE:
  189820. result = "No interface";
  189821. break;
  189822. case S_OK:
  189823. result = "No error";
  189824. break;
  189825. default:
  189826. return "Unknown error: " + String ((int) hr);
  189827. }
  189828. return result;
  189829. }
  189830. #define DS_DEBUGGING 1
  189831. #ifdef DS_DEBUGGING
  189832. #define CATCH JUCE_CATCH_EXCEPTION
  189833. #undef log
  189834. #define log(a) Logger::writeToLog(a);
  189835. #undef logError
  189836. #define logError(a) logDSError(a, __LINE__);
  189837. static void logDSError (HRESULT hr, int lineNum)
  189838. {
  189839. if (hr != S_OK)
  189840. {
  189841. String error ("DS error at line ");
  189842. error << lineNum << T(" - ") << getDSErrorMessage (hr);
  189843. log (error);
  189844. }
  189845. }
  189846. #else
  189847. #define CATCH JUCE_CATCH_ALL
  189848. #define log(a)
  189849. #define logError(a)
  189850. #endif
  189851. #define DSOUND_FUNCTION(functionName, params) \
  189852. typedef HRESULT (WINAPI *type##functionName) params; \
  189853. static type##functionName ds##functionName = 0;
  189854. #define DSOUND_FUNCTION_LOAD(functionName) \
  189855. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  189856. jassert (ds##functionName != 0);
  189857. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  189858. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  189859. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  189860. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  189861. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189862. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189863. static void initialiseDSoundFunctions()
  189864. {
  189865. if (dsDirectSoundCreate == 0)
  189866. {
  189867. HMODULE h = LoadLibraryA ("dsound.dll");
  189868. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  189869. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  189870. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  189871. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  189872. }
  189873. }
  189874. class DSoundInternalOutChannel
  189875. {
  189876. String name;
  189877. LPGUID guid;
  189878. int sampleRate, bufferSizeSamples;
  189879. float* leftBuffer;
  189880. float* rightBuffer;
  189881. IDirectSound* pDirectSound;
  189882. IDirectSoundBuffer* pOutputBuffer;
  189883. DWORD writeOffset;
  189884. int totalBytesPerBuffer;
  189885. int bytesPerBuffer;
  189886. unsigned int lastPlayCursor;
  189887. public:
  189888. int bitDepth;
  189889. bool doneFlag;
  189890. DSoundInternalOutChannel (const String& name_,
  189891. LPGUID guid_,
  189892. int rate,
  189893. int bufferSize,
  189894. float* left,
  189895. float* right)
  189896. : name (name_),
  189897. guid (guid_),
  189898. sampleRate (rate),
  189899. bufferSizeSamples (bufferSize),
  189900. leftBuffer (left),
  189901. rightBuffer (right),
  189902. pDirectSound (0),
  189903. pOutputBuffer (0),
  189904. bitDepth (16)
  189905. {
  189906. }
  189907. ~DSoundInternalOutChannel()
  189908. {
  189909. close();
  189910. }
  189911. void close()
  189912. {
  189913. HRESULT hr;
  189914. if (pOutputBuffer != 0)
  189915. {
  189916. JUCE_TRY
  189917. {
  189918. log (T("closing dsound out: ") + name);
  189919. hr = pOutputBuffer->Stop();
  189920. logError (hr);
  189921. }
  189922. CATCH
  189923. JUCE_TRY
  189924. {
  189925. hr = pOutputBuffer->Release();
  189926. logError (hr);
  189927. }
  189928. CATCH
  189929. pOutputBuffer = 0;
  189930. }
  189931. if (pDirectSound != 0)
  189932. {
  189933. JUCE_TRY
  189934. {
  189935. hr = pDirectSound->Release();
  189936. logError (hr);
  189937. }
  189938. CATCH
  189939. pDirectSound = 0;
  189940. }
  189941. }
  189942. const String open()
  189943. {
  189944. log (T("opening dsound out device: ") + name
  189945. + T(" rate=") + String (sampleRate)
  189946. + T(" bits=") + String (bitDepth)
  189947. + T(" buf=") + String (bufferSizeSamples));
  189948. pDirectSound = 0;
  189949. pOutputBuffer = 0;
  189950. writeOffset = 0;
  189951. String error;
  189952. HRESULT hr = E_NOINTERFACE;
  189953. if (dsDirectSoundCreate != 0)
  189954. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  189955. if (hr == S_OK)
  189956. {
  189957. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  189958. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  189959. const int numChannels = 2;
  189960. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  189961. logError (hr);
  189962. if (hr == S_OK)
  189963. {
  189964. IDirectSoundBuffer* pPrimaryBuffer;
  189965. DSBUFFERDESC primaryDesc;
  189966. zerostruct (primaryDesc);
  189967. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189968. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  189969. primaryDesc.dwBufferBytes = 0;
  189970. primaryDesc.lpwfxFormat = 0;
  189971. log ("opening dsound out step 2");
  189972. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  189973. logError (hr);
  189974. if (hr == S_OK)
  189975. {
  189976. WAVEFORMATEX wfFormat;
  189977. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  189978. wfFormat.nChannels = (unsigned short) numChannels;
  189979. wfFormat.nSamplesPerSec = sampleRate;
  189980. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  189981. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  189982. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  189983. wfFormat.cbSize = 0;
  189984. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  189985. logError (hr);
  189986. if (hr == S_OK)
  189987. {
  189988. DSBUFFERDESC secondaryDesc;
  189989. zerostruct (secondaryDesc);
  189990. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189991. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  189992. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  189993. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  189994. secondaryDesc.lpwfxFormat = &wfFormat;
  189995. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  189996. logError (hr);
  189997. if (hr == S_OK)
  189998. {
  189999. log ("opening dsound out step 3");
  190000. DWORD dwDataLen;
  190001. unsigned char* pDSBuffData;
  190002. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  190003. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  190004. logError (hr);
  190005. if (hr == S_OK)
  190006. {
  190007. zeromem (pDSBuffData, dwDataLen);
  190008. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  190009. if (hr == S_OK)
  190010. {
  190011. hr = pOutputBuffer->SetCurrentPosition (0);
  190012. if (hr == S_OK)
  190013. {
  190014. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  190015. if (hr == S_OK)
  190016. return String::empty;
  190017. }
  190018. }
  190019. }
  190020. }
  190021. }
  190022. }
  190023. }
  190024. }
  190025. error = getDSErrorMessage (hr);
  190026. close();
  190027. return error;
  190028. }
  190029. void synchronisePosition()
  190030. {
  190031. if (pOutputBuffer != 0)
  190032. {
  190033. DWORD playCursor;
  190034. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  190035. }
  190036. }
  190037. bool service()
  190038. {
  190039. if (pOutputBuffer == 0)
  190040. return true;
  190041. DWORD playCursor, writeCursor;
  190042. for (;;)
  190043. {
  190044. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  190045. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190046. {
  190047. pOutputBuffer->Restore();
  190048. continue;
  190049. }
  190050. if (hr == S_OK)
  190051. break;
  190052. logError (hr);
  190053. jassertfalse
  190054. return true;
  190055. }
  190056. int playWriteGap = writeCursor - playCursor;
  190057. if (playWriteGap < 0)
  190058. playWriteGap += totalBytesPerBuffer;
  190059. int bytesEmpty = playCursor - writeOffset;
  190060. if (bytesEmpty < 0)
  190061. bytesEmpty += totalBytesPerBuffer;
  190062. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  190063. {
  190064. writeOffset = writeCursor;
  190065. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  190066. }
  190067. if (bytesEmpty >= bytesPerBuffer)
  190068. {
  190069. LPBYTE lpbuf1 = 0;
  190070. LPBYTE lpbuf2 = 0;
  190071. DWORD dwSize1 = 0;
  190072. DWORD dwSize2 = 0;
  190073. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  190074. bytesPerBuffer,
  190075. (void**) &lpbuf1, &dwSize1,
  190076. (void**) &lpbuf2, &dwSize2, 0);
  190077. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190078. {
  190079. pOutputBuffer->Restore();
  190080. hr = pOutputBuffer->Lock (writeOffset,
  190081. bytesPerBuffer,
  190082. (void**) &lpbuf1, &dwSize1,
  190083. (void**) &lpbuf2, &dwSize2, 0);
  190084. }
  190085. if (hr == S_OK)
  190086. {
  190087. if (bitDepth == 16)
  190088. {
  190089. const float gainL = 32767.0f;
  190090. const float gainR = 32767.0f;
  190091. int* dest = (int*)lpbuf1;
  190092. const float* left = leftBuffer;
  190093. const float* right = rightBuffer;
  190094. int samples1 = dwSize1 >> 2;
  190095. int samples2 = dwSize2 >> 2;
  190096. if (left == 0)
  190097. {
  190098. while (--samples1 >= 0)
  190099. {
  190100. int r = roundToInt (gainR * *right++);
  190101. if (r < -32768)
  190102. r = -32768;
  190103. else if (r > 32767)
  190104. r = 32767;
  190105. *dest++ = (r << 16);
  190106. }
  190107. dest = (int*)lpbuf2;
  190108. while (--samples2 >= 0)
  190109. {
  190110. int r = roundToInt (gainR * *right++);
  190111. if (r < -32768)
  190112. r = -32768;
  190113. else if (r > 32767)
  190114. r = 32767;
  190115. *dest++ = (r << 16);
  190116. }
  190117. }
  190118. else if (right == 0)
  190119. {
  190120. while (--samples1 >= 0)
  190121. {
  190122. int l = roundToInt (gainL * *left++);
  190123. if (l < -32768)
  190124. l = -32768;
  190125. else if (l > 32767)
  190126. l = 32767;
  190127. l &= 0xffff;
  190128. *dest++ = l;
  190129. }
  190130. dest = (int*)lpbuf2;
  190131. while (--samples2 >= 0)
  190132. {
  190133. int l = roundToInt (gainL * *left++);
  190134. if (l < -32768)
  190135. l = -32768;
  190136. else if (l > 32767)
  190137. l = 32767;
  190138. l &= 0xffff;
  190139. *dest++ = l;
  190140. }
  190141. }
  190142. else
  190143. {
  190144. while (--samples1 >= 0)
  190145. {
  190146. int l = roundToInt (gainL * *left++);
  190147. if (l < -32768)
  190148. l = -32768;
  190149. else if (l > 32767)
  190150. l = 32767;
  190151. l &= 0xffff;
  190152. int r = roundToInt (gainR * *right++);
  190153. if (r < -32768)
  190154. r = -32768;
  190155. else if (r > 32767)
  190156. r = 32767;
  190157. *dest++ = (r << 16) | l;
  190158. }
  190159. dest = (int*)lpbuf2;
  190160. while (--samples2 >= 0)
  190161. {
  190162. int l = roundToInt (gainL * *left++);
  190163. if (l < -32768)
  190164. l = -32768;
  190165. else if (l > 32767)
  190166. l = 32767;
  190167. l &= 0xffff;
  190168. int r = roundToInt (gainR * *right++);
  190169. if (r < -32768)
  190170. r = -32768;
  190171. else if (r > 32767)
  190172. r = 32767;
  190173. *dest++ = (r << 16) | l;
  190174. }
  190175. }
  190176. }
  190177. else
  190178. {
  190179. jassertfalse
  190180. }
  190181. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190182. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190183. }
  190184. else
  190185. {
  190186. jassertfalse
  190187. logError (hr);
  190188. }
  190189. bytesEmpty -= bytesPerBuffer;
  190190. return true;
  190191. }
  190192. else
  190193. {
  190194. return false;
  190195. }
  190196. }
  190197. };
  190198. struct DSoundInternalInChannel
  190199. {
  190200. String name;
  190201. LPGUID guid;
  190202. int sampleRate, bufferSizeSamples;
  190203. float* leftBuffer;
  190204. float* rightBuffer;
  190205. IDirectSound* pDirectSound;
  190206. IDirectSoundCapture* pDirectSoundCapture;
  190207. IDirectSoundCaptureBuffer* pInputBuffer;
  190208. public:
  190209. unsigned int readOffset;
  190210. int bytesPerBuffer, totalBytesPerBuffer;
  190211. int bitDepth;
  190212. bool doneFlag;
  190213. DSoundInternalInChannel (const String& name_,
  190214. LPGUID guid_,
  190215. int rate,
  190216. int bufferSize,
  190217. float* left,
  190218. float* right)
  190219. : name (name_),
  190220. guid (guid_),
  190221. sampleRate (rate),
  190222. bufferSizeSamples (bufferSize),
  190223. leftBuffer (left),
  190224. rightBuffer (right),
  190225. pDirectSound (0),
  190226. pDirectSoundCapture (0),
  190227. pInputBuffer (0),
  190228. bitDepth (16)
  190229. {
  190230. }
  190231. ~DSoundInternalInChannel()
  190232. {
  190233. close();
  190234. }
  190235. void close()
  190236. {
  190237. HRESULT hr;
  190238. if (pInputBuffer != 0)
  190239. {
  190240. JUCE_TRY
  190241. {
  190242. log (T("closing dsound in: ") + name);
  190243. hr = pInputBuffer->Stop();
  190244. logError (hr);
  190245. }
  190246. CATCH
  190247. JUCE_TRY
  190248. {
  190249. hr = pInputBuffer->Release();
  190250. logError (hr);
  190251. }
  190252. CATCH
  190253. pInputBuffer = 0;
  190254. }
  190255. if (pDirectSoundCapture != 0)
  190256. {
  190257. JUCE_TRY
  190258. {
  190259. hr = pDirectSoundCapture->Release();
  190260. logError (hr);
  190261. }
  190262. CATCH
  190263. pDirectSoundCapture = 0;
  190264. }
  190265. if (pDirectSound != 0)
  190266. {
  190267. JUCE_TRY
  190268. {
  190269. hr = pDirectSound->Release();
  190270. logError (hr);
  190271. }
  190272. CATCH
  190273. pDirectSound = 0;
  190274. }
  190275. }
  190276. const String open()
  190277. {
  190278. log (T("opening dsound in device: ") + name
  190279. + T(" rate=") + String (sampleRate) + T(" bits=") + String (bitDepth) + T(" buf=") + String (bufferSizeSamples));
  190280. pDirectSound = 0;
  190281. pDirectSoundCapture = 0;
  190282. pInputBuffer = 0;
  190283. readOffset = 0;
  190284. totalBytesPerBuffer = 0;
  190285. String error;
  190286. HRESULT hr = E_NOINTERFACE;
  190287. if (dsDirectSoundCaptureCreate != 0)
  190288. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190289. logError (hr);
  190290. if (hr == S_OK)
  190291. {
  190292. const int numChannels = 2;
  190293. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190294. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190295. WAVEFORMATEX wfFormat;
  190296. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190297. wfFormat.nChannels = (unsigned short)numChannels;
  190298. wfFormat.nSamplesPerSec = sampleRate;
  190299. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190300. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190301. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190302. wfFormat.cbSize = 0;
  190303. DSCBUFFERDESC captureDesc;
  190304. zerostruct (captureDesc);
  190305. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190306. captureDesc.dwFlags = 0;
  190307. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190308. captureDesc.lpwfxFormat = &wfFormat;
  190309. log (T("opening dsound in step 2"));
  190310. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190311. logError (hr);
  190312. if (hr == S_OK)
  190313. {
  190314. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190315. logError (hr);
  190316. if (hr == S_OK)
  190317. return String::empty;
  190318. }
  190319. }
  190320. error = getDSErrorMessage (hr);
  190321. close();
  190322. return error;
  190323. }
  190324. void synchronisePosition()
  190325. {
  190326. if (pInputBuffer != 0)
  190327. {
  190328. DWORD capturePos;
  190329. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190330. }
  190331. }
  190332. bool service()
  190333. {
  190334. if (pInputBuffer == 0)
  190335. return true;
  190336. DWORD capturePos, readPos;
  190337. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190338. logError (hr);
  190339. if (hr != S_OK)
  190340. return true;
  190341. int bytesFilled = readPos - readOffset;
  190342. if (bytesFilled < 0)
  190343. bytesFilled += totalBytesPerBuffer;
  190344. if (bytesFilled >= bytesPerBuffer)
  190345. {
  190346. LPBYTE lpbuf1 = 0;
  190347. LPBYTE lpbuf2 = 0;
  190348. DWORD dwsize1 = 0;
  190349. DWORD dwsize2 = 0;
  190350. HRESULT hr = pInputBuffer->Lock (readOffset,
  190351. bytesPerBuffer,
  190352. (void**) &lpbuf1, &dwsize1,
  190353. (void**) &lpbuf2, &dwsize2, 0);
  190354. if (hr == S_OK)
  190355. {
  190356. if (bitDepth == 16)
  190357. {
  190358. const float g = 1.0f / 32768.0f;
  190359. float* destL = leftBuffer;
  190360. float* destR = rightBuffer;
  190361. int samples1 = dwsize1 >> 2;
  190362. int samples2 = dwsize2 >> 2;
  190363. const short* src = (const short*)lpbuf1;
  190364. if (destL == 0)
  190365. {
  190366. while (--samples1 >= 0)
  190367. {
  190368. ++src;
  190369. *destR++ = *src++ * g;
  190370. }
  190371. src = (const short*)lpbuf2;
  190372. while (--samples2 >= 0)
  190373. {
  190374. ++src;
  190375. *destR++ = *src++ * g;
  190376. }
  190377. }
  190378. else if (destR == 0)
  190379. {
  190380. while (--samples1 >= 0)
  190381. {
  190382. *destL++ = *src++ * g;
  190383. ++src;
  190384. }
  190385. src = (const short*)lpbuf2;
  190386. while (--samples2 >= 0)
  190387. {
  190388. *destL++ = *src++ * g;
  190389. ++src;
  190390. }
  190391. }
  190392. else
  190393. {
  190394. while (--samples1 >= 0)
  190395. {
  190396. *destL++ = *src++ * g;
  190397. *destR++ = *src++ * g;
  190398. }
  190399. src = (const short*)lpbuf2;
  190400. while (--samples2 >= 0)
  190401. {
  190402. *destL++ = *src++ * g;
  190403. *destR++ = *src++ * g;
  190404. }
  190405. }
  190406. }
  190407. else
  190408. {
  190409. jassertfalse
  190410. }
  190411. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190412. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190413. }
  190414. else
  190415. {
  190416. logError (hr);
  190417. jassertfalse
  190418. }
  190419. bytesFilled -= bytesPerBuffer;
  190420. return true;
  190421. }
  190422. else
  190423. {
  190424. return false;
  190425. }
  190426. }
  190427. };
  190428. class DSoundAudioIODevice : public AudioIODevice,
  190429. public Thread
  190430. {
  190431. public:
  190432. DSoundAudioIODevice (const String& deviceName,
  190433. const int outputDeviceIndex_,
  190434. const int inputDeviceIndex_)
  190435. : AudioIODevice (deviceName, "DirectSound"),
  190436. Thread ("Juce DSound"),
  190437. isOpen_ (false),
  190438. isStarted (false),
  190439. outputDeviceIndex (outputDeviceIndex_),
  190440. inputDeviceIndex (inputDeviceIndex_),
  190441. numInputBuffers (0),
  190442. numOutputBuffers (0),
  190443. totalSamplesOut (0),
  190444. sampleRate (0.0),
  190445. inputBuffers (0),
  190446. outputBuffers (0),
  190447. callback (0),
  190448. bufferSizeSamples (0)
  190449. {
  190450. if (outputDeviceIndex_ >= 0)
  190451. {
  190452. outChannels.add (TRANS("Left"));
  190453. outChannels.add (TRANS("Right"));
  190454. }
  190455. if (inputDeviceIndex_ >= 0)
  190456. {
  190457. inChannels.add (TRANS("Left"));
  190458. inChannels.add (TRANS("Right"));
  190459. }
  190460. }
  190461. ~DSoundAudioIODevice()
  190462. {
  190463. close();
  190464. }
  190465. const StringArray getOutputChannelNames()
  190466. {
  190467. return outChannels;
  190468. }
  190469. const StringArray getInputChannelNames()
  190470. {
  190471. return inChannels;
  190472. }
  190473. int getNumSampleRates()
  190474. {
  190475. return 4;
  190476. }
  190477. double getSampleRate (int index)
  190478. {
  190479. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190480. return samps [jlimit (0, 3, index)];
  190481. }
  190482. int getNumBufferSizesAvailable()
  190483. {
  190484. return 50;
  190485. }
  190486. int getBufferSizeSamples (int index)
  190487. {
  190488. int n = 64;
  190489. for (int i = 0; i < index; ++i)
  190490. n += (n < 512) ? 32
  190491. : ((n < 1024) ? 64
  190492. : ((n < 2048) ? 128 : 256));
  190493. return n;
  190494. }
  190495. int getDefaultBufferSize()
  190496. {
  190497. return 2560;
  190498. }
  190499. const String open (const BigInteger& inputChannels,
  190500. const BigInteger& outputChannels,
  190501. double sampleRate,
  190502. int bufferSizeSamples)
  190503. {
  190504. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190505. isOpen_ = lastError.isEmpty();
  190506. return lastError;
  190507. }
  190508. void close()
  190509. {
  190510. stop();
  190511. if (isOpen_)
  190512. {
  190513. closeDevice();
  190514. isOpen_ = false;
  190515. }
  190516. }
  190517. bool isOpen()
  190518. {
  190519. return isOpen_ && isThreadRunning();
  190520. }
  190521. int getCurrentBufferSizeSamples()
  190522. {
  190523. return bufferSizeSamples;
  190524. }
  190525. double getCurrentSampleRate()
  190526. {
  190527. return sampleRate;
  190528. }
  190529. int getCurrentBitDepth()
  190530. {
  190531. int i, bits = 256;
  190532. for (i = inChans.size(); --i >= 0;)
  190533. bits = jmin (bits, inChans[i]->bitDepth);
  190534. for (i = outChans.size(); --i >= 0;)
  190535. bits = jmin (bits, outChans[i]->bitDepth);
  190536. if (bits > 32)
  190537. bits = 16;
  190538. return bits;
  190539. }
  190540. const BigInteger getActiveOutputChannels() const
  190541. {
  190542. return enabledOutputs;
  190543. }
  190544. const BigInteger getActiveInputChannels() const
  190545. {
  190546. return enabledInputs;
  190547. }
  190548. int getOutputLatencyInSamples()
  190549. {
  190550. return (int) (getCurrentBufferSizeSamples() * 1.5);
  190551. }
  190552. int getInputLatencyInSamples()
  190553. {
  190554. return getOutputLatencyInSamples();
  190555. }
  190556. void start (AudioIODeviceCallback* call)
  190557. {
  190558. if (isOpen_ && call != 0 && ! isStarted)
  190559. {
  190560. if (! isThreadRunning())
  190561. {
  190562. // something gone wrong and the thread's stopped..
  190563. isOpen_ = false;
  190564. return;
  190565. }
  190566. call->audioDeviceAboutToStart (this);
  190567. const ScopedLock sl (startStopLock);
  190568. callback = call;
  190569. isStarted = true;
  190570. }
  190571. }
  190572. void stop()
  190573. {
  190574. if (isStarted)
  190575. {
  190576. AudioIODeviceCallback* const callbackLocal = callback;
  190577. {
  190578. const ScopedLock sl (startStopLock);
  190579. isStarted = false;
  190580. }
  190581. if (callbackLocal != 0)
  190582. callbackLocal->audioDeviceStopped();
  190583. }
  190584. }
  190585. bool isPlaying()
  190586. {
  190587. return isStarted && isOpen_ && isThreadRunning();
  190588. }
  190589. const String getLastError()
  190590. {
  190591. return lastError;
  190592. }
  190593. juce_UseDebuggingNewOperator
  190594. StringArray inChannels, outChannels;
  190595. int outputDeviceIndex, inputDeviceIndex;
  190596. private:
  190597. bool isOpen_;
  190598. bool isStarted;
  190599. String lastError;
  190600. OwnedArray <DSoundInternalInChannel> inChans;
  190601. OwnedArray <DSoundInternalOutChannel> outChans;
  190602. WaitableEvent startEvent;
  190603. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  190604. int volatile totalSamplesOut;
  190605. int64 volatile lastBlockTime;
  190606. double sampleRate;
  190607. BigInteger enabledInputs, enabledOutputs;
  190608. HeapBlock <float*> inputBuffers, outputBuffers;
  190609. AudioIODeviceCallback* callback;
  190610. CriticalSection startStopLock;
  190611. DSoundAudioIODevice (const DSoundAudioIODevice&);
  190612. DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  190613. const String openDevice (const BigInteger& inputChannels,
  190614. const BigInteger& outputChannels,
  190615. double sampleRate_,
  190616. int bufferSizeSamples_);
  190617. void closeDevice()
  190618. {
  190619. isStarted = false;
  190620. stopThread (5000);
  190621. inChans.clear();
  190622. outChans.clear();
  190623. int i;
  190624. for (i = 0; i < numInputBuffers; ++i)
  190625. juce_free (inputBuffers[i]);
  190626. inputBuffers.free();
  190627. numInputBuffers = 0;
  190628. for (i = 0; i < numOutputBuffers; ++i)
  190629. juce_free (outputBuffers[i]);
  190630. outputBuffers.free();
  190631. numOutputBuffers = 0;
  190632. }
  190633. void resync()
  190634. {
  190635. if (! threadShouldExit())
  190636. {
  190637. sleep (5);
  190638. int i;
  190639. for (i = 0; i < outChans.size(); ++i)
  190640. outChans.getUnchecked(i)->synchronisePosition();
  190641. for (i = 0; i < inChans.size(); ++i)
  190642. inChans.getUnchecked(i)->synchronisePosition();
  190643. }
  190644. }
  190645. public:
  190646. void run()
  190647. {
  190648. while (! threadShouldExit())
  190649. {
  190650. if (wait (100))
  190651. break;
  190652. }
  190653. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  190654. const int maxTimeMS = jmax (5, 3 * latencyMs);
  190655. while (! threadShouldExit())
  190656. {
  190657. int numToDo = 0;
  190658. uint32 startTime = Time::getMillisecondCounter();
  190659. int i;
  190660. for (i = inChans.size(); --i >= 0;)
  190661. {
  190662. inChans.getUnchecked(i)->doneFlag = false;
  190663. ++numToDo;
  190664. }
  190665. for (i = outChans.size(); --i >= 0;)
  190666. {
  190667. outChans.getUnchecked(i)->doneFlag = false;
  190668. ++numToDo;
  190669. }
  190670. if (numToDo > 0)
  190671. {
  190672. const int maxCount = 3;
  190673. int count = maxCount;
  190674. for (;;)
  190675. {
  190676. for (i = inChans.size(); --i >= 0;)
  190677. {
  190678. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  190679. if ((! in->doneFlag) && in->service())
  190680. {
  190681. in->doneFlag = true;
  190682. --numToDo;
  190683. }
  190684. }
  190685. for (i = outChans.size(); --i >= 0;)
  190686. {
  190687. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  190688. if ((! out->doneFlag) && out->service())
  190689. {
  190690. out->doneFlag = true;
  190691. --numToDo;
  190692. }
  190693. }
  190694. if (numToDo <= 0)
  190695. break;
  190696. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  190697. {
  190698. resync();
  190699. break;
  190700. }
  190701. if (--count <= 0)
  190702. {
  190703. Sleep (1);
  190704. count = maxCount;
  190705. }
  190706. if (threadShouldExit())
  190707. return;
  190708. }
  190709. }
  190710. else
  190711. {
  190712. sleep (1);
  190713. }
  190714. const ScopedLock sl (startStopLock);
  190715. if (isStarted)
  190716. {
  190717. JUCE_TRY
  190718. {
  190719. callback->audioDeviceIOCallback (const_cast <const float**> (inputBuffers.getData()),
  190720. numInputBuffers,
  190721. outputBuffers,
  190722. numOutputBuffers,
  190723. bufferSizeSamples);
  190724. }
  190725. JUCE_CATCH_EXCEPTION
  190726. totalSamplesOut += bufferSizeSamples;
  190727. }
  190728. else
  190729. {
  190730. for (i = 0; i < numOutputBuffers; ++i)
  190731. if (outputBuffers[i] != 0)
  190732. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  190733. totalSamplesOut = 0;
  190734. sleep (1);
  190735. }
  190736. }
  190737. }
  190738. };
  190739. class DSoundAudioIODeviceType : public AudioIODeviceType
  190740. {
  190741. public:
  190742. DSoundAudioIODeviceType()
  190743. : AudioIODeviceType (T("DirectSound")),
  190744. hasScanned (false)
  190745. {
  190746. initialiseDSoundFunctions();
  190747. }
  190748. ~DSoundAudioIODeviceType()
  190749. {
  190750. }
  190751. void scanForDevices()
  190752. {
  190753. hasScanned = true;
  190754. outputDeviceNames.clear();
  190755. outputGuids.clear();
  190756. inputDeviceNames.clear();
  190757. inputGuids.clear();
  190758. if (dsDirectSoundEnumerateW != 0)
  190759. {
  190760. dsDirectSoundEnumerateW (outputEnumProcW, this);
  190761. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  190762. }
  190763. }
  190764. const StringArray getDeviceNames (const bool wantInputNames) const
  190765. {
  190766. jassert (hasScanned); // need to call scanForDevices() before doing this
  190767. return wantInputNames ? inputDeviceNames
  190768. : outputDeviceNames;
  190769. }
  190770. int getDefaultDeviceIndex (const bool /*forInput*/) const
  190771. {
  190772. jassert (hasScanned); // need to call scanForDevices() before doing this
  190773. return 0;
  190774. }
  190775. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  190776. {
  190777. jassert (hasScanned); // need to call scanForDevices() before doing this
  190778. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  190779. if (d == 0)
  190780. return -1;
  190781. return asInput ? d->inputDeviceIndex
  190782. : d->outputDeviceIndex;
  190783. }
  190784. bool hasSeparateInputsAndOutputs() const { return true; }
  190785. AudioIODevice* createDevice (const String& outputDeviceName,
  190786. const String& inputDeviceName)
  190787. {
  190788. jassert (hasScanned); // need to call scanForDevices() before doing this
  190789. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  190790. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  190791. if (outputIndex >= 0 || inputIndex >= 0)
  190792. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  190793. : inputDeviceName,
  190794. outputIndex, inputIndex);
  190795. return 0;
  190796. }
  190797. juce_UseDebuggingNewOperator
  190798. StringArray outputDeviceNames;
  190799. OwnedArray <GUID> outputGuids;
  190800. StringArray inputDeviceNames;
  190801. OwnedArray <GUID> inputGuids;
  190802. private:
  190803. bool hasScanned;
  190804. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  190805. {
  190806. desc = desc.trim();
  190807. if (desc.isNotEmpty())
  190808. {
  190809. const String origDesc (desc);
  190810. int n = 2;
  190811. while (outputDeviceNames.contains (desc))
  190812. desc = origDesc + T(" (") + String (n++) + T(")");
  190813. outputDeviceNames.add (desc);
  190814. if (lpGUID != 0)
  190815. outputGuids.add (new GUID (*lpGUID));
  190816. else
  190817. outputGuids.add (0);
  190818. }
  190819. return TRUE;
  190820. }
  190821. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190822. {
  190823. return ((DSoundAudioIODeviceType*) object)
  190824. ->outputEnumProc (lpGUID, String (description));
  190825. }
  190826. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190827. {
  190828. return ((DSoundAudioIODeviceType*) object)
  190829. ->outputEnumProc (lpGUID, String (description));
  190830. }
  190831. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  190832. {
  190833. desc = desc.trim();
  190834. if (desc.isNotEmpty())
  190835. {
  190836. const String origDesc (desc);
  190837. int n = 2;
  190838. while (inputDeviceNames.contains (desc))
  190839. desc = origDesc + T(" (") + String (n++) + T(")");
  190840. inputDeviceNames.add (desc);
  190841. if (lpGUID != 0)
  190842. inputGuids.add (new GUID (*lpGUID));
  190843. else
  190844. inputGuids.add (0);
  190845. }
  190846. return TRUE;
  190847. }
  190848. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190849. {
  190850. return ((DSoundAudioIODeviceType*) object)
  190851. ->inputEnumProc (lpGUID, String (description));
  190852. }
  190853. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190854. {
  190855. return ((DSoundAudioIODeviceType*) object)
  190856. ->inputEnumProc (lpGUID, String (description));
  190857. }
  190858. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  190859. DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  190860. };
  190861. const String DSoundAudioIODevice::openDevice (const BigInteger& inputChannels,
  190862. const BigInteger& outputChannels,
  190863. double sampleRate_,
  190864. int bufferSizeSamples_)
  190865. {
  190866. closeDevice();
  190867. totalSamplesOut = 0;
  190868. sampleRate = sampleRate_;
  190869. if (bufferSizeSamples_ <= 0)
  190870. bufferSizeSamples_ = 960; // use as a default size if none is set.
  190871. bufferSizeSamples = bufferSizeSamples_ & ~7;
  190872. DSoundAudioIODeviceType dlh;
  190873. dlh.scanForDevices();
  190874. enabledInputs = inputChannels;
  190875. enabledInputs.setRange (inChannels.size(),
  190876. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  190877. false);
  190878. numInputBuffers = enabledInputs.countNumberOfSetBits();
  190879. inputBuffers.calloc (numInputBuffers + 2);
  190880. int i, numIns = 0;
  190881. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  190882. {
  190883. float* left = 0;
  190884. float* right = 0;
  190885. if (enabledInputs[i])
  190886. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190887. if (enabledInputs[i + 1])
  190888. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190889. if (left != 0 || right != 0)
  190890. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  190891. dlh.inputGuids [inputDeviceIndex],
  190892. (int) sampleRate, bufferSizeSamples,
  190893. left, right));
  190894. }
  190895. enabledOutputs = outputChannels;
  190896. enabledOutputs.setRange (outChannels.size(),
  190897. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  190898. false);
  190899. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  190900. outputBuffers.calloc (numOutputBuffers + 2);
  190901. int numOuts = 0;
  190902. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  190903. {
  190904. float* left = 0;
  190905. float* right = 0;
  190906. if (enabledOutputs[i])
  190907. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190908. if (enabledOutputs[i + 1])
  190909. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190910. if (left != 0 || right != 0)
  190911. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  190912. dlh.outputGuids [outputDeviceIndex],
  190913. (int) sampleRate, bufferSizeSamples,
  190914. left, right));
  190915. }
  190916. String error;
  190917. // boost our priority while opening the devices to try to get better sync between them
  190918. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  190919. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  190920. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  190921. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  190922. for (i = 0; i < outChans.size(); ++i)
  190923. {
  190924. error = outChans[i]->open();
  190925. if (error.isNotEmpty())
  190926. {
  190927. error = T("Error opening ") + dlh.outputDeviceNames[i]
  190928. + T(": \"") + error + T("\"");
  190929. break;
  190930. }
  190931. }
  190932. if (error.isEmpty())
  190933. {
  190934. for (i = 0; i < inChans.size(); ++i)
  190935. {
  190936. error = inChans[i]->open();
  190937. if (error.isNotEmpty())
  190938. {
  190939. error = T("Error opening ") + dlh.inputDeviceNames[i]
  190940. + T(": \"") + error + T("\"");
  190941. break;
  190942. }
  190943. }
  190944. }
  190945. if (error.isEmpty())
  190946. {
  190947. totalSamplesOut = 0;
  190948. for (i = 0; i < outChans.size(); ++i)
  190949. outChans.getUnchecked(i)->synchronisePosition();
  190950. for (i = 0; i < inChans.size(); ++i)
  190951. inChans.getUnchecked(i)->synchronisePosition();
  190952. startThread (9);
  190953. sleep (10);
  190954. notify();
  190955. }
  190956. else
  190957. {
  190958. log (error);
  190959. }
  190960. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  190961. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  190962. return error;
  190963. }
  190964. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  190965. {
  190966. return new DSoundAudioIODeviceType();
  190967. }
  190968. #undef log
  190969. #endif
  190970. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  190971. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  190972. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190973. // compiled on its own).
  190974. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  190975. #if 1
  190976. const String getAudioErrorDesc (HRESULT hr)
  190977. {
  190978. const char* e = 0;
  190979. switch (hr)
  190980. {
  190981. case E_POINTER: e = "E_POINTER"; break;
  190982. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  190983. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  190984. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  190985. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  190986. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  190987. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  190988. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  190989. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  190990. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  190991. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  190992. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  190993. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  190994. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  190995. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  190996. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  190997. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  190998. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  190999. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  191000. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  191001. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  191002. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  191003. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  191004. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  191005. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  191006. default: return String::toHexString ((int) hr);
  191007. }
  191008. return e;
  191009. }
  191010. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  191011. #define OK(a) wasapi_checkResult(a)
  191012. static bool wasapi_checkResult (HRESULT hr)
  191013. {
  191014. logFailure (hr);
  191015. return SUCCEEDED (hr);
  191016. }
  191017. #else
  191018. #define logFailure(hr) {}
  191019. #define OK(a) SUCCEEDED(a)
  191020. #endif
  191021. static const String wasapi_getDeviceID (IMMDevice* const device)
  191022. {
  191023. String s;
  191024. WCHAR* deviceId = 0;
  191025. if (OK (device->GetId (&deviceId)))
  191026. {
  191027. s = String (deviceId);
  191028. CoTaskMemFree (deviceId);
  191029. }
  191030. return s;
  191031. }
  191032. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  191033. {
  191034. EDataFlow flow = eRender;
  191035. ComSmartPtr <IMMEndpoint> endPoint;
  191036. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  191037. (void) OK (endPoint->GetDataFlow (&flow));
  191038. return flow;
  191039. }
  191040. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  191041. {
  191042. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  191043. }
  191044. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  191045. {
  191046. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  191047. : sizeof (WAVEFORMATEX));
  191048. }
  191049. class WASAPIDeviceBase
  191050. {
  191051. public:
  191052. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191053. : device (device_),
  191054. sampleRate (0),
  191055. numChannels (0),
  191056. actualNumChannels (0),
  191057. defaultSampleRate (0),
  191058. minBufferSize (0),
  191059. defaultBufferSize (0),
  191060. latencySamples (0),
  191061. useExclusiveMode (useExclusiveMode_)
  191062. {
  191063. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  191064. ComSmartPtr <IAudioClient> tempClient (createClient());
  191065. if (tempClient == 0)
  191066. return;
  191067. REFERENCE_TIME defaultPeriod, minPeriod;
  191068. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  191069. return;
  191070. WAVEFORMATEX* mixFormat = 0;
  191071. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  191072. return;
  191073. WAVEFORMATEXTENSIBLE format;
  191074. wasapi_copyWavFormat (format, mixFormat);
  191075. CoTaskMemFree (mixFormat);
  191076. actualNumChannels = numChannels = format.Format.nChannels;
  191077. defaultSampleRate = format.Format.nSamplesPerSec;
  191078. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191079. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191080. FloatElementComparator<double> comparator;
  191081. rates.addSorted (comparator, defaultSampleRate);
  191082. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191083. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191084. {
  191085. if (ratesToTest[i] == defaultSampleRate)
  191086. continue;
  191087. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191088. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191089. (WAVEFORMATEX*) &format, 0)))
  191090. if (! rates.contains (ratesToTest[i]))
  191091. rates.addSorted (comparator, ratesToTest[i]);
  191092. }
  191093. }
  191094. ~WASAPIDeviceBase()
  191095. {
  191096. device = 0;
  191097. CloseHandle (clientEvent);
  191098. }
  191099. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191100. bool openClient (const double newSampleRate, const BigInteger& newChannels)
  191101. {
  191102. sampleRate = newSampleRate;
  191103. channels = newChannels;
  191104. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191105. numChannels = channels.getHighestBit() + 1;
  191106. if (numChannels == 0)
  191107. return true;
  191108. client = createClient();
  191109. if (client != 0
  191110. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191111. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191112. {
  191113. channelMaps.clear();
  191114. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191115. if (channels[i])
  191116. channelMaps.add (i);
  191117. REFERENCE_TIME latency;
  191118. if (OK (client->GetStreamLatency (&latency)))
  191119. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191120. (void) OK (client->GetBufferSize (&actualBufferSize));
  191121. return OK (client->SetEventHandle (clientEvent));
  191122. }
  191123. return false;
  191124. }
  191125. void closeClient()
  191126. {
  191127. if (client != 0)
  191128. client->Stop();
  191129. client = 0;
  191130. ResetEvent (clientEvent);
  191131. }
  191132. ComSmartPtr <IMMDevice> device;
  191133. ComSmartPtr <IAudioClient> client;
  191134. double sampleRate, defaultSampleRate;
  191135. int numChannels, actualNumChannels;
  191136. int minBufferSize, defaultBufferSize, latencySamples;
  191137. const bool useExclusiveMode;
  191138. Array <double> rates;
  191139. HANDLE clientEvent;
  191140. BigInteger channels;
  191141. AudioDataConverters::DataFormat dataFormat;
  191142. Array <int> channelMaps;
  191143. UINT32 actualBufferSize;
  191144. int bytesPerSample;
  191145. private:
  191146. const ComSmartPtr <IAudioClient> createClient()
  191147. {
  191148. ComSmartPtr <IAudioClient> client;
  191149. if (device != 0)
  191150. {
  191151. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191152. logFailure (hr);
  191153. }
  191154. return client;
  191155. }
  191156. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191157. {
  191158. WAVEFORMATEXTENSIBLE format;
  191159. zerostruct (format);
  191160. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191161. {
  191162. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191163. }
  191164. else
  191165. {
  191166. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191167. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191168. }
  191169. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191170. format.Format.nChannels = (WORD) numChannels;
  191171. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191172. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191173. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191174. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191175. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191176. switch (numChannels)
  191177. {
  191178. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191179. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191180. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191181. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191182. 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;
  191183. default: break;
  191184. }
  191185. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191186. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191187. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191188. logFailure (hr);
  191189. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191190. {
  191191. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191192. hr = S_OK;
  191193. }
  191194. CoTaskMemFree (nearestFormat);
  191195. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191196. if (useExclusiveMode)
  191197. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191198. GUID session;
  191199. if (hr == S_OK
  191200. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191201. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191202. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191203. {
  191204. actualNumChannels = format.Format.nChannels;
  191205. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191206. bytesPerSample = format.Format.wBitsPerSample / 8;
  191207. dataFormat = isFloat ? AudioDataConverters::float32LE
  191208. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191209. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191210. : AudioDataConverters::int16LE)));
  191211. return true;
  191212. }
  191213. return false;
  191214. }
  191215. };
  191216. class WASAPIInputDevice : public WASAPIDeviceBase
  191217. {
  191218. public:
  191219. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191220. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191221. reservoir (1, 1)
  191222. {
  191223. }
  191224. ~WASAPIInputDevice()
  191225. {
  191226. close();
  191227. }
  191228. bool open (const double newSampleRate, const BigInteger& newChannels)
  191229. {
  191230. reservoirSize = 0;
  191231. reservoirCapacity = 16384;
  191232. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191233. return openClient (newSampleRate, newChannels)
  191234. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191235. }
  191236. void close()
  191237. {
  191238. closeClient();
  191239. captureClient = 0;
  191240. reservoir.setSize (0);
  191241. }
  191242. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191243. {
  191244. if (numChannels <= 0)
  191245. return;
  191246. int offset = 0;
  191247. while (bufferSize > 0)
  191248. {
  191249. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191250. {
  191251. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191252. for (int i = 0; i < numDestBuffers; ++i)
  191253. {
  191254. float* const dest = destBuffers[i] + offset;
  191255. const int srcChan = channelMaps.getUnchecked(i);
  191256. switch (dataFormat)
  191257. {
  191258. case AudioDataConverters::float32LE:
  191259. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191260. break;
  191261. case AudioDataConverters::int32LE:
  191262. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191263. break;
  191264. case AudioDataConverters::int24LE:
  191265. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191266. break;
  191267. case AudioDataConverters::int16LE:
  191268. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191269. break;
  191270. default: jassertfalse; break;
  191271. }
  191272. }
  191273. bufferSize -= samplesToDo;
  191274. offset += samplesToDo;
  191275. reservoirSize -= samplesToDo;
  191276. }
  191277. else
  191278. {
  191279. UINT32 packetLength = 0;
  191280. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191281. break;
  191282. if (packetLength == 0)
  191283. {
  191284. if (thread.threadShouldExit())
  191285. break;
  191286. Thread::sleep (1);
  191287. continue;
  191288. }
  191289. uint8* inputData = 0;
  191290. UINT32 numSamplesAvailable;
  191291. DWORD flags;
  191292. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191293. {
  191294. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191295. for (int i = 0; i < numDestBuffers; ++i)
  191296. {
  191297. float* const dest = destBuffers[i] + offset;
  191298. const int srcChan = channelMaps.getUnchecked(i);
  191299. switch (dataFormat)
  191300. {
  191301. case AudioDataConverters::float32LE:
  191302. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191303. break;
  191304. case AudioDataConverters::int32LE:
  191305. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191306. break;
  191307. case AudioDataConverters::int24LE:
  191308. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191309. break;
  191310. case AudioDataConverters::int16LE:
  191311. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191312. break;
  191313. default: jassertfalse; break;
  191314. }
  191315. }
  191316. bufferSize -= samplesToDo;
  191317. offset += samplesToDo;
  191318. if (samplesToDo < (int) numSamplesAvailable)
  191319. {
  191320. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191321. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191322. bytesPerSample * actualNumChannels * reservoirSize);
  191323. }
  191324. captureClient->ReleaseBuffer (numSamplesAvailable);
  191325. }
  191326. }
  191327. }
  191328. }
  191329. ComSmartPtr <IAudioCaptureClient> captureClient;
  191330. MemoryBlock reservoir;
  191331. int reservoirSize, reservoirCapacity;
  191332. };
  191333. class WASAPIOutputDevice : public WASAPIDeviceBase
  191334. {
  191335. public:
  191336. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191337. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191338. {
  191339. }
  191340. ~WASAPIOutputDevice()
  191341. {
  191342. close();
  191343. }
  191344. bool open (const double newSampleRate, const BigInteger& newChannels)
  191345. {
  191346. return openClient (newSampleRate, newChannels)
  191347. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191348. }
  191349. void close()
  191350. {
  191351. closeClient();
  191352. renderClient = 0;
  191353. }
  191354. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191355. {
  191356. if (numChannels <= 0)
  191357. return;
  191358. int offset = 0;
  191359. while (bufferSize > 0)
  191360. {
  191361. UINT32 padding = 0;
  191362. if (! OK (client->GetCurrentPadding (&padding)))
  191363. return;
  191364. int samplesToDo = useExclusiveMode ? bufferSize
  191365. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191366. if (samplesToDo <= 0)
  191367. {
  191368. if (thread.threadShouldExit())
  191369. break;
  191370. Thread::sleep (0);
  191371. continue;
  191372. }
  191373. uint8* outputData = 0;
  191374. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191375. {
  191376. for (int i = 0; i < numSrcBuffers; ++i)
  191377. {
  191378. const float* const source = srcBuffers[i] + offset;
  191379. const int destChan = channelMaps.getUnchecked(i);
  191380. switch (dataFormat)
  191381. {
  191382. case AudioDataConverters::float32LE:
  191383. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191384. break;
  191385. case AudioDataConverters::int32LE:
  191386. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191387. break;
  191388. case AudioDataConverters::int24LE:
  191389. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191390. break;
  191391. case AudioDataConverters::int16LE:
  191392. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191393. break;
  191394. default: jassertfalse; break;
  191395. }
  191396. }
  191397. renderClient->ReleaseBuffer (samplesToDo, 0);
  191398. offset += samplesToDo;
  191399. bufferSize -= samplesToDo;
  191400. }
  191401. }
  191402. }
  191403. ComSmartPtr <IAudioRenderClient> renderClient;
  191404. };
  191405. class WASAPIAudioIODevice : public AudioIODevice,
  191406. public Thread
  191407. {
  191408. public:
  191409. WASAPIAudioIODevice (const String& deviceName,
  191410. const String& outputDeviceId_,
  191411. const String& inputDeviceId_,
  191412. const bool useExclusiveMode_)
  191413. : AudioIODevice (deviceName, "Windows Audio"),
  191414. Thread ("Juce WASAPI"),
  191415. isOpen_ (false),
  191416. isStarted (false),
  191417. outputDevice (0),
  191418. outputDeviceId (outputDeviceId_),
  191419. inputDevice (0),
  191420. inputDeviceId (inputDeviceId_),
  191421. useExclusiveMode (useExclusiveMode_),
  191422. currentBufferSizeSamples (0),
  191423. currentSampleRate (0),
  191424. callback (0)
  191425. {
  191426. }
  191427. ~WASAPIAudioIODevice()
  191428. {
  191429. close();
  191430. deleteAndZero (inputDevice);
  191431. deleteAndZero (outputDevice);
  191432. }
  191433. bool initialise()
  191434. {
  191435. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191436. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191437. latencyIn = latencyOut = 0;
  191438. Array <double> ratesIn, ratesOut;
  191439. if (createDevices())
  191440. {
  191441. jassert (inputDevice != 0 || outputDevice != 0);
  191442. if (inputDevice != 0 && outputDevice != 0)
  191443. {
  191444. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191445. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191446. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191447. sampleRates = inputDevice->rates;
  191448. sampleRates.removeValuesNotIn (outputDevice->rates);
  191449. }
  191450. else
  191451. {
  191452. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191453. defaultSampleRate = d->defaultSampleRate;
  191454. minBufferSize = d->minBufferSize;
  191455. defaultBufferSize = d->defaultBufferSize;
  191456. sampleRates = d->rates;
  191457. }
  191458. IntegerElementComparator<int> comparator;
  191459. bufferSizes.addSorted (comparator, defaultBufferSize);
  191460. if (minBufferSize != defaultBufferSize)
  191461. bufferSizes.addSorted (comparator, minBufferSize);
  191462. int n = 64;
  191463. for (int i = 0; i < 40; ++i)
  191464. {
  191465. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191466. bufferSizes.addSorted (comparator, n);
  191467. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191468. }
  191469. return true;
  191470. }
  191471. return false;
  191472. }
  191473. const StringArray getOutputChannelNames()
  191474. {
  191475. StringArray outChannels;
  191476. if (outputDevice != 0)
  191477. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191478. outChannels.add ("Output channel " + String (i));
  191479. return outChannels;
  191480. }
  191481. const StringArray getInputChannelNames()
  191482. {
  191483. StringArray inChannels;
  191484. if (inputDevice != 0)
  191485. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191486. inChannels.add ("Input channel " + String (i));
  191487. return inChannels;
  191488. }
  191489. int getNumSampleRates() { return sampleRates.size(); }
  191490. double getSampleRate (int index) { return sampleRates [index]; }
  191491. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191492. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191493. int getDefaultBufferSize() { return defaultBufferSize; }
  191494. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191495. double getCurrentSampleRate() { return currentSampleRate; }
  191496. int getCurrentBitDepth() { return 32; }
  191497. int getOutputLatencyInSamples() { return latencyOut; }
  191498. int getInputLatencyInSamples() { return latencyIn; }
  191499. const BigInteger getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BigInteger(); }
  191500. const BigInteger getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BigInteger(); }
  191501. const String getLastError() { return lastError; }
  191502. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  191503. double sampleRate, int bufferSizeSamples)
  191504. {
  191505. close();
  191506. lastError = String::empty;
  191507. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191508. {
  191509. lastError = "The input and output devices don't share a common sample rate!";
  191510. return lastError;
  191511. }
  191512. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191513. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191514. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191515. {
  191516. lastError = "Couldn't open the input device!";
  191517. return lastError;
  191518. }
  191519. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191520. {
  191521. close();
  191522. lastError = "Couldn't open the output device!";
  191523. return lastError;
  191524. }
  191525. if (inputDevice != 0)
  191526. ResetEvent (inputDevice->clientEvent);
  191527. if (outputDevice != 0)
  191528. ResetEvent (outputDevice->clientEvent);
  191529. startThread (8);
  191530. Thread::sleep (5);
  191531. if (inputDevice != 0 && inputDevice->client != 0)
  191532. {
  191533. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  191534. HRESULT hr = inputDevice->client->Start();
  191535. logFailure (hr); //xxx handle this
  191536. }
  191537. if (outputDevice != 0 && outputDevice->client != 0)
  191538. {
  191539. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  191540. HRESULT hr = outputDevice->client->Start();
  191541. logFailure (hr); //xxx handle this
  191542. }
  191543. isOpen_ = true;
  191544. return lastError;
  191545. }
  191546. void close()
  191547. {
  191548. stop();
  191549. if (inputDevice != 0)
  191550. SetEvent (inputDevice->clientEvent);
  191551. if (outputDevice != 0)
  191552. SetEvent (outputDevice->clientEvent);
  191553. stopThread (5000);
  191554. if (inputDevice != 0)
  191555. inputDevice->close();
  191556. if (outputDevice != 0)
  191557. outputDevice->close();
  191558. isOpen_ = false;
  191559. }
  191560. bool isOpen() { return isOpen_ && isThreadRunning(); }
  191561. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  191562. void start (AudioIODeviceCallback* call)
  191563. {
  191564. if (isOpen_ && call != 0 && ! isStarted)
  191565. {
  191566. if (! isThreadRunning())
  191567. {
  191568. // something's gone wrong and the thread's stopped..
  191569. isOpen_ = false;
  191570. return;
  191571. }
  191572. call->audioDeviceAboutToStart (this);
  191573. const ScopedLock sl (startStopLock);
  191574. callback = call;
  191575. isStarted = true;
  191576. }
  191577. }
  191578. void stop()
  191579. {
  191580. if (isStarted)
  191581. {
  191582. AudioIODeviceCallback* const callbackLocal = callback;
  191583. {
  191584. const ScopedLock sl (startStopLock);
  191585. isStarted = false;
  191586. }
  191587. if (callbackLocal != 0)
  191588. callbackLocal->audioDeviceStopped();
  191589. }
  191590. }
  191591. void setMMThreadPriority()
  191592. {
  191593. DynamicLibraryLoader dll ("avrt.dll");
  191594. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  191595. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  191596. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  191597. {
  191598. DWORD dummy = 0;
  191599. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  191600. if (h != 0)
  191601. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  191602. }
  191603. }
  191604. void run()
  191605. {
  191606. setMMThreadPriority();
  191607. const int bufferSize = currentBufferSizeSamples;
  191608. HANDLE events[2];
  191609. int numEvents = 0;
  191610. if (inputDevice != 0)
  191611. events [numEvents++] = inputDevice->clientEvent;
  191612. if (outputDevice != 0)
  191613. events [numEvents++] = outputDevice->clientEvent;
  191614. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  191615. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  191616. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  191617. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  191618. float** const inputBuffers = ins.getArrayOfChannels();
  191619. float** const outputBuffers = outs.getArrayOfChannels();
  191620. ins.clear();
  191621. while (! threadShouldExit())
  191622. {
  191623. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  191624. : WaitForMultipleObjects (numEvents, events, true, 1000);
  191625. if (result == WAIT_TIMEOUT)
  191626. continue;
  191627. if (threadShouldExit())
  191628. break;
  191629. if (inputDevice != 0)
  191630. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  191631. // Make the callback..
  191632. {
  191633. const ScopedLock sl (startStopLock);
  191634. if (isStarted)
  191635. {
  191636. JUCE_TRY
  191637. {
  191638. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191639. numInputBuffers,
  191640. outputBuffers,
  191641. numOutputBuffers,
  191642. bufferSize);
  191643. }
  191644. JUCE_CATCH_EXCEPTION
  191645. }
  191646. else
  191647. {
  191648. outs.clear();
  191649. }
  191650. }
  191651. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  191652. continue;
  191653. if (outputDevice != 0)
  191654. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  191655. }
  191656. }
  191657. juce_UseDebuggingNewOperator
  191658. String outputDeviceId, inputDeviceId;
  191659. String lastError;
  191660. private:
  191661. // Device stats...
  191662. WASAPIInputDevice* inputDevice;
  191663. WASAPIOutputDevice* outputDevice;
  191664. const bool useExclusiveMode;
  191665. double defaultSampleRate;
  191666. int minBufferSize, defaultBufferSize;
  191667. int latencyIn, latencyOut;
  191668. Array <double> sampleRates;
  191669. Array <int> bufferSizes;
  191670. // Active state...
  191671. bool isOpen_, isStarted;
  191672. int currentBufferSizeSamples;
  191673. double currentSampleRate;
  191674. AudioIODeviceCallback* callback;
  191675. CriticalSection startStopLock;
  191676. bool createDevices()
  191677. {
  191678. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191679. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191680. return false;
  191681. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191682. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  191683. return false;
  191684. UINT32 numDevices = 0;
  191685. if (! OK (deviceCollection->GetCount (&numDevices)))
  191686. return false;
  191687. for (UINT32 i = 0; i < numDevices; ++i)
  191688. {
  191689. ComSmartPtr <IMMDevice> device;
  191690. if (! OK (deviceCollection->Item (i, &device)))
  191691. continue;
  191692. const String deviceId (wasapi_getDeviceID (device));
  191693. if (deviceId.isEmpty())
  191694. continue;
  191695. const EDataFlow flow = wasapi_getDataFlow (device);
  191696. if (deviceId == inputDeviceId && flow == eCapture)
  191697. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  191698. else if (deviceId == outputDeviceId && flow == eRender)
  191699. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  191700. }
  191701. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  191702. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  191703. }
  191704. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  191705. WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  191706. };
  191707. class WASAPIAudioIODeviceType : public AudioIODeviceType
  191708. {
  191709. public:
  191710. WASAPIAudioIODeviceType()
  191711. : AudioIODeviceType (T("Windows Audio")),
  191712. hasScanned (false)
  191713. {
  191714. }
  191715. ~WASAPIAudioIODeviceType()
  191716. {
  191717. }
  191718. void scanForDevices()
  191719. {
  191720. hasScanned = true;
  191721. outputDeviceNames.clear();
  191722. inputDeviceNames.clear();
  191723. outputDeviceIds.clear();
  191724. inputDeviceIds.clear();
  191725. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191726. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191727. return;
  191728. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  191729. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  191730. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191731. UINT32 numDevices = 0;
  191732. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  191733. && OK (deviceCollection->GetCount (&numDevices))))
  191734. return;
  191735. for (UINT32 i = 0; i < numDevices; ++i)
  191736. {
  191737. ComSmartPtr <IMMDevice> device;
  191738. if (! OK (deviceCollection->Item (i, &device)))
  191739. continue;
  191740. const String deviceId (wasapi_getDeviceID (device));
  191741. DWORD state = 0;
  191742. if (! OK (device->GetState (&state)))
  191743. continue;
  191744. if (state != DEVICE_STATE_ACTIVE)
  191745. continue;
  191746. String name;
  191747. {
  191748. ComSmartPtr <IPropertyStore> properties;
  191749. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  191750. continue;
  191751. PROPVARIANT value;
  191752. PropVariantInit (&value);
  191753. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  191754. name = value.pwszVal;
  191755. PropVariantClear (&value);
  191756. }
  191757. const EDataFlow flow = wasapi_getDataFlow (device);
  191758. if (flow == eRender)
  191759. {
  191760. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  191761. outputDeviceIds.insert (index, deviceId);
  191762. outputDeviceNames.insert (index, name);
  191763. }
  191764. else if (flow == eCapture)
  191765. {
  191766. const int index = (deviceId == defaultCapture) ? 0 : -1;
  191767. inputDeviceIds.insert (index, deviceId);
  191768. inputDeviceNames.insert (index, name);
  191769. }
  191770. }
  191771. inputDeviceNames.appendNumbersToDuplicates (false, false);
  191772. outputDeviceNames.appendNumbersToDuplicates (false, false);
  191773. }
  191774. const StringArray getDeviceNames (const bool wantInputNames) const
  191775. {
  191776. jassert (hasScanned); // need to call scanForDevices() before doing this
  191777. return wantInputNames ? inputDeviceNames
  191778. : outputDeviceNames;
  191779. }
  191780. int getDefaultDeviceIndex (const bool /*forInput*/) const
  191781. {
  191782. jassert (hasScanned); // need to call scanForDevices() before doing this
  191783. return 0;
  191784. }
  191785. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  191786. {
  191787. jassert (hasScanned); // need to call scanForDevices() before doing this
  191788. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  191789. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  191790. : outputDeviceIds.indexOf (d->outputDeviceId));
  191791. }
  191792. bool hasSeparateInputsAndOutputs() const { return true; }
  191793. AudioIODevice* createDevice (const String& outputDeviceName,
  191794. const String& inputDeviceName)
  191795. {
  191796. jassert (hasScanned); // need to call scanForDevices() before doing this
  191797. const bool useExclusiveMode = false;
  191798. ScopedPointer<WASAPIAudioIODevice> device;
  191799. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191800. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191801. if (outputIndex >= 0 || inputIndex >= 0)
  191802. {
  191803. device = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191804. : inputDeviceName,
  191805. outputDeviceIds [outputIndex],
  191806. inputDeviceIds [inputIndex],
  191807. useExclusiveMode);
  191808. if (! device->initialise())
  191809. device = 0;
  191810. }
  191811. return device.release();
  191812. }
  191813. juce_UseDebuggingNewOperator
  191814. StringArray outputDeviceNames, outputDeviceIds;
  191815. StringArray inputDeviceNames, inputDeviceIds;
  191816. private:
  191817. bool hasScanned;
  191818. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  191819. {
  191820. String s;
  191821. IMMDevice* dev = 0;
  191822. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  191823. eMultimedia, &dev)))
  191824. {
  191825. WCHAR* deviceId = 0;
  191826. if (OK (dev->GetId (&deviceId)))
  191827. {
  191828. s = String (deviceId);
  191829. CoTaskMemFree (deviceId);
  191830. }
  191831. dev->Release();
  191832. }
  191833. return s;
  191834. }
  191835. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  191836. WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  191837. };
  191838. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  191839. {
  191840. return new WASAPIAudioIODeviceType();
  191841. }
  191842. #undef logFailure
  191843. #undef OK
  191844. #endif
  191845. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  191846. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  191847. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191848. // compiled on its own).
  191849. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  191850. class DShowCameraDeviceInteral : public ChangeBroadcaster
  191851. {
  191852. public:
  191853. DShowCameraDeviceInteral (CameraDevice* const owner_,
  191854. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  191855. const ComSmartPtr <IBaseFilter>& filter_,
  191856. int minWidth, int minHeight,
  191857. int maxWidth, int maxHeight)
  191858. : owner (owner_),
  191859. captureGraphBuilder (captureGraphBuilder_),
  191860. filter (filter_),
  191861. ok (false),
  191862. imageNeedsFlipping (false),
  191863. width (0),
  191864. height (0),
  191865. activeUsers (0),
  191866. recordNextFrameTime (false),
  191867. activeImage (0),
  191868. loadingImage (0)
  191869. {
  191870. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  191871. if (FAILED (hr))
  191872. return;
  191873. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  191874. if (FAILED (hr))
  191875. return;
  191876. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  191877. if (FAILED (hr))
  191878. return;
  191879. {
  191880. ComSmartPtr <IAMStreamConfig> streamConfig;
  191881. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter,
  191882. IID_IAMStreamConfig, (void**) &streamConfig);
  191883. if (streamConfig != 0)
  191884. {
  191885. getVideoSizes (streamConfig);
  191886. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  191887. return;
  191888. }
  191889. }
  191890. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  191891. if (FAILED (hr))
  191892. return;
  191893. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  191894. if (FAILED (hr))
  191895. return;
  191896. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  191897. if (FAILED (hr))
  191898. return;
  191899. if (! connectFilters (filter, smartTee))
  191900. return;
  191901. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  191902. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  191903. if (FAILED (hr))
  191904. return;
  191905. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  191906. if (FAILED (hr))
  191907. return;
  191908. AM_MEDIA_TYPE mt;
  191909. zerostruct (mt);
  191910. mt.majortype = MEDIATYPE_Video;
  191911. mt.subtype = MEDIASUBTYPE_RGB24;
  191912. mt.formattype = FORMAT_VideoInfo;
  191913. sampleGrabber->SetMediaType (&mt);
  191914. callback = new GrabberCallback (*this);
  191915. sampleGrabber->SetCallback (callback, 1);
  191916. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  191917. if (FAILED (hr))
  191918. return;
  191919. ComSmartPtr <IPin> grabberInputPin;
  191920. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  191921. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  191922. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  191923. return;
  191924. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  191925. if (FAILED (hr))
  191926. return;
  191927. zerostruct (mt);
  191928. hr = sampleGrabber->GetConnectedMediaType (&mt);
  191929. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  191930. width = pVih->bmiHeader.biWidth;
  191931. height = pVih->bmiHeader.biHeight;
  191932. ComSmartPtr <IBaseFilter> nullFilter;
  191933. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  191934. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  191935. if (connectFilters (sampleGrabberBase, nullFilter)
  191936. && addGraphToRot())
  191937. {
  191938. activeImage = new Image (Image::RGB, width, height, true);
  191939. loadingImage = new Image (Image::RGB, width, height, true);
  191940. ok = true;
  191941. }
  191942. }
  191943. ~DShowCameraDeviceInteral()
  191944. {
  191945. if (mediaControl != 0)
  191946. mediaControl->Stop();
  191947. removeGraphFromRot();
  191948. for (int i = viewerComps.size(); --i >= 0;)
  191949. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  191950. callback = 0;
  191951. graphBuilder = 0;
  191952. sampleGrabber = 0;
  191953. mediaControl = 0;
  191954. filter = 0;
  191955. captureGraphBuilder = 0;
  191956. smartTee = 0;
  191957. smartTeePreviewOutputPin = 0;
  191958. smartTeeCaptureOutputPin = 0;
  191959. asfWriter = 0;
  191960. delete activeImage;
  191961. delete loadingImage;
  191962. }
  191963. void addUser()
  191964. {
  191965. if (ok && activeUsers++ == 0)
  191966. mediaControl->Run();
  191967. }
  191968. void removeUser()
  191969. {
  191970. if (ok && --activeUsers == 0)
  191971. mediaControl->Stop();
  191972. }
  191973. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  191974. {
  191975. if (recordNextFrameTime)
  191976. {
  191977. const double defaultCameraLatency = 0.1;
  191978. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  191979. recordNextFrameTime = false;
  191980. ComSmartPtr <IPin> pin;
  191981. if (getPin (filter, PINDIR_OUTPUT, &pin))
  191982. {
  191983. ComSmartPtr <IAMPushSource> pushSource;
  191984. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  191985. if (pushSource != 0)
  191986. {
  191987. REFERENCE_TIME latency = 0;
  191988. hr = pushSource->GetLatency (&latency);
  191989. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  191990. }
  191991. }
  191992. }
  191993. {
  191994. const int lineStride = width * 3;
  191995. const ScopedLock sl (imageSwapLock);
  191996. {
  191997. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  191998. for (int i = 0; i < height; ++i)
  191999. memcpy (destData.getLinePointer ((height - 1) - i),
  192000. buffer + lineStride * i,
  192001. lineStride);
  192002. }
  192003. imageNeedsFlipping = true;
  192004. }
  192005. if (listeners.size() > 0)
  192006. callListeners (*loadingImage);
  192007. sendChangeMessage (this);
  192008. }
  192009. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  192010. {
  192011. if (imageNeedsFlipping)
  192012. {
  192013. const ScopedLock sl (imageSwapLock);
  192014. swapVariables (loadingImage, activeImage);
  192015. imageNeedsFlipping = false;
  192016. }
  192017. RectanglePlacement rp (RectanglePlacement::centred);
  192018. double dx = 0, dy = 0, dw = width, dh = height;
  192019. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  192020. const int rx = roundToInt (dx), ry = roundToInt (dy);
  192021. const int rw = roundToInt (dw), rh = roundToInt (dh);
  192022. g.saveState();
  192023. g.excludeClipRegion (Rectangle<int> (rx, ry, rw, rh));
  192024. g.fillAll (Colours::black);
  192025. g.restoreState();
  192026. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  192027. }
  192028. bool createFileCaptureFilter (const File& file)
  192029. {
  192030. removeFileCaptureFilter();
  192031. file.deleteFile();
  192032. mediaControl->Stop();
  192033. firstRecordedTime = Time();
  192034. recordNextFrameTime = true;
  192035. HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter, CLSCTX_INPROC_SERVER);
  192036. if (SUCCEEDED (hr))
  192037. {
  192038. ComSmartPtr <IFileSinkFilter> fileSink;
  192039. hr = asfWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  192040. if (SUCCEEDED (hr))
  192041. {
  192042. hr = fileSink->SetFileName (file.getFullPathName(), 0);
  192043. if (SUCCEEDED (hr))
  192044. {
  192045. hr = graphBuilder->AddFilter (asfWriter, _T("AsfWriter"));
  192046. if (SUCCEEDED (hr))
  192047. {
  192048. ComSmartPtr <IConfigAsfWriter> asfConfig;
  192049. hr = asfWriter->QueryInterface (IID_IConfigAsfWriter, (void**) &asfConfig);
  192050. asfConfig->SetIndexMode (true);
  192051. ComSmartPtr <IWMProfileManager> profileManager;
  192052. hr = WMCreateProfileManager (&profileManager);
  192053. // This gibberish is the DirectShow profile for a video-only wmv file.
  192054. String prof ("<profile version=\"589824\" storageformat=\"1\" name=\"Quality\" description=\"Quality type for output.\"><streamconfig "
  192055. "majortype=\"{73646976-0000-0010-8000-00AA00389B71}\" streamnumber=\"1\" streamname=\"Video Stream\" inputname=\"Video409\" bitrate=\"894960\" "
  192056. "bufferwindow=\"0\" reliabletransport=\"1\" decodercomplexity=\"AU\" rfc1766langid=\"en-us\"><videomediaprops maxkeyframespacing=\"50000000\" quality=\"90\"/>"
  192057. "<wmmediatype subtype=\"{33564D57-0000-0010-8000-00AA00389B71}\" bfixedsizesamples=\"0\" btemporalcompression=\"1\" lsamplesize=\"0\"> <videoinfoheader "
  192058. "dwbitrate=\"894960\" dwbiterrorrate=\"0\" avgtimeperframe=\"100000\"><rcsource left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <rctarget "
  192059. "left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <bitmapinfoheader biwidth=\"$WIDTH\" biheight=\"$HEIGHT\" biplanes=\"1\" bibitcount=\"24\" "
  192060. "bicompression=\"WMV3\" bisizeimage=\"0\" bixpelspermeter=\"0\" biypelspermeter=\"0\" biclrused=\"0\" biclrimportant=\"0\"/> "
  192061. "</videoinfoheader></wmmediatype></streamconfig></profile>");
  192062. prof = prof.replace (T("$WIDTH"), String (width))
  192063. .replace (T("$HEIGHT"), String (height));
  192064. ComSmartPtr <IWMProfile> currentProfile;
  192065. hr = profileManager->LoadProfileByData ((const WCHAR*) prof, &currentProfile);
  192066. hr = asfConfig->ConfigureFilterUsingProfile (currentProfile);
  192067. if (SUCCEEDED (hr))
  192068. {
  192069. ComSmartPtr <IPin> asfWriterInputPin;
  192070. if (getPin (asfWriter, PINDIR_INPUT, &asfWriterInputPin, "Video Input 01"))
  192071. {
  192072. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin);
  192073. if (SUCCEEDED (hr)
  192074. && ok && activeUsers > 0
  192075. && SUCCEEDED (mediaControl->Run()))
  192076. {
  192077. return true;
  192078. }
  192079. }
  192080. }
  192081. }
  192082. }
  192083. }
  192084. }
  192085. removeFileCaptureFilter();
  192086. if (ok && activeUsers > 0)
  192087. mediaControl->Run();
  192088. return false;
  192089. }
  192090. void removeFileCaptureFilter()
  192091. {
  192092. mediaControl->Stop();
  192093. if (asfWriter != 0)
  192094. {
  192095. graphBuilder->RemoveFilter (asfWriter);
  192096. asfWriter = 0;
  192097. }
  192098. if (ok && activeUsers > 0)
  192099. mediaControl->Run();
  192100. }
  192101. void addListener (CameraImageListener* listenerToAdd)
  192102. {
  192103. const ScopedLock sl (listenerLock);
  192104. if (listeners.size() == 0)
  192105. addUser();
  192106. listeners.addIfNotAlreadyThere (listenerToAdd);
  192107. }
  192108. void removeListener (CameraImageListener* listenerToRemove)
  192109. {
  192110. const ScopedLock sl (listenerLock);
  192111. listeners.removeValue (listenerToRemove);
  192112. if (listeners.size() == 0)
  192113. removeUser();
  192114. }
  192115. void callListeners (Image& image)
  192116. {
  192117. const ScopedLock sl (listenerLock);
  192118. for (int i = listeners.size(); --i >= 0;)
  192119. {
  192120. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192121. if (l != 0)
  192122. l->imageReceived (image);
  192123. }
  192124. }
  192125. class DShowCaptureViewerComp : public Component,
  192126. public ChangeListener
  192127. {
  192128. public:
  192129. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192130. : owner (owner_)
  192131. {
  192132. setOpaque (true);
  192133. owner->addChangeListener (this);
  192134. owner->addUser();
  192135. owner->viewerComps.add (this);
  192136. setSize (owner_->width, owner_->height);
  192137. }
  192138. ~DShowCaptureViewerComp()
  192139. {
  192140. if (owner != 0)
  192141. {
  192142. owner->viewerComps.removeValue (this);
  192143. owner->removeUser();
  192144. owner->removeChangeListener (this);
  192145. }
  192146. }
  192147. void ownerDeleted()
  192148. {
  192149. owner = 0;
  192150. }
  192151. void paint (Graphics& g)
  192152. {
  192153. g.setColour (Colours::black);
  192154. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192155. if (owner != 0)
  192156. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192157. else
  192158. g.fillAll (Colours::black);
  192159. }
  192160. void changeListenerCallback (void*)
  192161. {
  192162. repaint();
  192163. }
  192164. private:
  192165. DShowCameraDeviceInteral* owner;
  192166. };
  192167. bool ok;
  192168. int width, height;
  192169. Time firstRecordedTime;
  192170. VoidArray viewerComps;
  192171. private:
  192172. CameraDevice* const owner;
  192173. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192174. ComSmartPtr <IBaseFilter> filter;
  192175. ComSmartPtr <IBaseFilter> smartTee;
  192176. ComSmartPtr <IGraphBuilder> graphBuilder;
  192177. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192178. ComSmartPtr <IMediaControl> mediaControl;
  192179. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192180. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192181. ComSmartPtr <IBaseFilter> asfWriter;
  192182. int activeUsers;
  192183. Array <int> widths, heights;
  192184. DWORD graphRegistrationID;
  192185. CriticalSection imageSwapLock;
  192186. bool imageNeedsFlipping;
  192187. Image* loadingImage;
  192188. Image* activeImage;
  192189. bool recordNextFrameTime;
  192190. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192191. {
  192192. widths.clear();
  192193. heights.clear();
  192194. int count = 0, size = 0;
  192195. streamConfig->GetNumberOfCapabilities (&count, &size);
  192196. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192197. {
  192198. for (int i = 0; i < count; ++i)
  192199. {
  192200. VIDEO_STREAM_CONFIG_CAPS scc;
  192201. AM_MEDIA_TYPE* config;
  192202. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192203. if (SUCCEEDED (hr))
  192204. {
  192205. const int w = scc.InputSize.cx;
  192206. const int h = scc.InputSize.cy;
  192207. bool duplicate = false;
  192208. for (int j = widths.size(); --j >= 0;)
  192209. {
  192210. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192211. {
  192212. duplicate = true;
  192213. break;
  192214. }
  192215. }
  192216. if (! duplicate)
  192217. {
  192218. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192219. widths.add (w);
  192220. heights.add (h);
  192221. }
  192222. deleteMediaType (config);
  192223. }
  192224. }
  192225. }
  192226. }
  192227. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192228. const int minWidth, const int minHeight,
  192229. const int maxWidth, const int maxHeight)
  192230. {
  192231. int count = 0, size = 0, bestArea = 0, bestIndex = -1;
  192232. streamConfig->GetNumberOfCapabilities (&count, &size);
  192233. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192234. {
  192235. AM_MEDIA_TYPE* config;
  192236. VIDEO_STREAM_CONFIG_CAPS scc;
  192237. for (int i = 0; i < count; ++i)
  192238. {
  192239. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192240. if (SUCCEEDED (hr))
  192241. {
  192242. if (scc.InputSize.cx >= minWidth
  192243. && scc.InputSize.cy >= minHeight
  192244. && scc.InputSize.cx <= maxWidth
  192245. && scc.InputSize.cy <= maxHeight)
  192246. {
  192247. int area = scc.InputSize.cx * scc.InputSize.cy;
  192248. if (area > bestArea)
  192249. {
  192250. bestIndex = i;
  192251. bestArea = area;
  192252. }
  192253. }
  192254. deleteMediaType (config);
  192255. }
  192256. }
  192257. if (bestIndex >= 0)
  192258. {
  192259. HRESULT hr = streamConfig->GetStreamCaps (bestIndex, &config, (BYTE*) &scc);
  192260. hr = streamConfig->SetFormat (config);
  192261. deleteMediaType (config);
  192262. return SUCCEEDED (hr);
  192263. }
  192264. }
  192265. return false;
  192266. }
  192267. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192268. {
  192269. ComSmartPtr <IEnumPins> enumerator;
  192270. ComSmartPtr <IPin> pin;
  192271. filter->EnumPins (&enumerator);
  192272. while (enumerator->Next (1, &pin, 0) == S_OK)
  192273. {
  192274. PIN_DIRECTION dir;
  192275. pin->QueryDirection (&dir);
  192276. if (wantedDirection == dir)
  192277. {
  192278. PIN_INFO info;
  192279. zerostruct (info);
  192280. pin->QueryPinInfo (&info);
  192281. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192282. {
  192283. pin.p->AddRef();
  192284. *result = pin;
  192285. return true;
  192286. }
  192287. }
  192288. }
  192289. return false;
  192290. }
  192291. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192292. {
  192293. ComSmartPtr <IPin> in, out;
  192294. return getPin (first, PINDIR_OUTPUT, &out)
  192295. && getPin (second, PINDIR_INPUT, &in)
  192296. && SUCCEEDED (graphBuilder->Connect (out, in));
  192297. }
  192298. bool addGraphToRot()
  192299. {
  192300. ComSmartPtr <IRunningObjectTable> rot;
  192301. if (FAILED (GetRunningObjectTable (0, &rot)))
  192302. return false;
  192303. ComSmartPtr <IMoniker> moniker;
  192304. WCHAR buffer[128];
  192305. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192306. if (FAILED (hr))
  192307. return false;
  192308. graphRegistrationID = 0;
  192309. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192310. }
  192311. void removeGraphFromRot()
  192312. {
  192313. ComSmartPtr <IRunningObjectTable> rot;
  192314. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192315. rot->Revoke (graphRegistrationID);
  192316. }
  192317. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192318. {
  192319. if (pmt->cbFormat != 0)
  192320. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192321. if (pmt->pUnk != 0)
  192322. pmt->pUnk->Release();
  192323. CoTaskMemFree (pmt);
  192324. }
  192325. class GrabberCallback : public ISampleGrabberCB
  192326. {
  192327. public:
  192328. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192329. : owner (owner_)
  192330. {
  192331. }
  192332. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192333. {
  192334. if (id == IID_IUnknown)
  192335. *result = dynamic_cast <IUnknown*> (this);
  192336. else if (id == IID_ISampleGrabberCB)
  192337. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192338. else
  192339. {
  192340. *result = 0;
  192341. return E_NOINTERFACE;
  192342. }
  192343. AddRef();
  192344. return S_OK;
  192345. }
  192346. ULONG __stdcall AddRef() { return ++refCount; }
  192347. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192348. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192349. {
  192350. return E_FAIL;
  192351. }
  192352. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192353. {
  192354. owner.handleFrame (time, buffer, bufferSize);
  192355. return S_OK;
  192356. }
  192357. private:
  192358. int refCount;
  192359. DShowCameraDeviceInteral& owner;
  192360. GrabberCallback (const GrabberCallback&);
  192361. GrabberCallback& operator= (const GrabberCallback&);
  192362. };
  192363. ComSmartPtr <GrabberCallback> callback;
  192364. VoidArray listeners;
  192365. CriticalSection listenerLock;
  192366. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192367. DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192368. };
  192369. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192370. : name (name_)
  192371. {
  192372. isRecording = false;
  192373. }
  192374. CameraDevice::~CameraDevice()
  192375. {
  192376. stopRecording();
  192377. delete (DShowCameraDeviceInteral*) internal;
  192378. internal = 0;
  192379. }
  192380. Component* CameraDevice::createViewerComponent()
  192381. {
  192382. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192383. }
  192384. const String CameraDevice::getFileExtension()
  192385. {
  192386. return ".wmv";
  192387. }
  192388. void CameraDevice::startRecordingToFile (const File& file, int quality)
  192389. {
  192390. stopRecording();
  192391. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192392. d->addUser();
  192393. isRecording = d->createFileCaptureFilter (file);
  192394. }
  192395. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192396. {
  192397. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192398. return d->firstRecordedTime;
  192399. }
  192400. void CameraDevice::stopRecording()
  192401. {
  192402. if (isRecording)
  192403. {
  192404. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192405. d->removeFileCaptureFilter();
  192406. d->removeUser();
  192407. isRecording = false;
  192408. }
  192409. }
  192410. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192411. {
  192412. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192413. if (listenerToAdd != 0)
  192414. d->addListener (listenerToAdd);
  192415. }
  192416. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192417. {
  192418. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192419. if (listenerToRemove != 0)
  192420. d->removeListener (listenerToRemove);
  192421. }
  192422. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192423. const int deviceIndexToOpen,
  192424. String& name)
  192425. {
  192426. int index = 0;
  192427. ComSmartPtr <IBaseFilter> result;
  192428. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192429. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192430. if (SUCCEEDED (hr))
  192431. {
  192432. ComSmartPtr <IEnumMoniker> enumerator;
  192433. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192434. if (SUCCEEDED (hr) && enumerator != 0)
  192435. {
  192436. ComSmartPtr <IBaseFilter> captureFilter;
  192437. ComSmartPtr <IMoniker> moniker;
  192438. ULONG fetched;
  192439. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192440. {
  192441. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192442. if (SUCCEEDED (hr))
  192443. {
  192444. ComSmartPtr <IPropertyBag> propertyBag;
  192445. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192446. if (SUCCEEDED (hr))
  192447. {
  192448. VARIANT var;
  192449. var.vt = VT_BSTR;
  192450. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192451. propertyBag = 0;
  192452. if (SUCCEEDED (hr))
  192453. {
  192454. if (names != 0)
  192455. names->add (var.bstrVal);
  192456. if (index == deviceIndexToOpen)
  192457. {
  192458. name = var.bstrVal;
  192459. result = captureFilter;
  192460. captureFilter = 0;
  192461. break;
  192462. }
  192463. ++index;
  192464. }
  192465. moniker = 0;
  192466. }
  192467. captureFilter = 0;
  192468. }
  192469. }
  192470. }
  192471. }
  192472. return result;
  192473. }
  192474. const StringArray CameraDevice::getAvailableDevices()
  192475. {
  192476. StringArray devs;
  192477. String dummy;
  192478. enumerateCameras (&devs, -1, dummy);
  192479. return devs;
  192480. }
  192481. CameraDevice* CameraDevice::openDevice (int index,
  192482. int minWidth, int minHeight,
  192483. int maxWidth, int maxHeight)
  192484. {
  192485. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192486. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192487. if (SUCCEEDED (hr))
  192488. {
  192489. String name;
  192490. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192491. if (filter != 0)
  192492. {
  192493. CameraDevice* const cam = new CameraDevice (name, index);
  192494. DShowCameraDeviceInteral* const intern
  192495. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192496. minWidth, minHeight, maxWidth, maxHeight);
  192497. cam->internal = intern;
  192498. if (intern->ok)
  192499. return cam;
  192500. else
  192501. delete cam;
  192502. }
  192503. }
  192504. return 0;
  192505. }
  192506. #endif
  192507. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192508. #endif
  192509. // Auto-link the other win32 libs that are needed by library calls..
  192510. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192511. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192512. // Auto-links to various win32 libs that are needed by library calls..
  192513. #pragma comment(lib, "kernel32.lib")
  192514. #pragma comment(lib, "user32.lib")
  192515. #pragma comment(lib, "shell32.lib")
  192516. #pragma comment(lib, "gdi32.lib")
  192517. #pragma comment(lib, "vfw32.lib")
  192518. #pragma comment(lib, "comdlg32.lib")
  192519. #pragma comment(lib, "winmm.lib")
  192520. #pragma comment(lib, "wininet.lib")
  192521. #pragma comment(lib, "ole32.lib")
  192522. #pragma comment(lib, "oleaut32.lib")
  192523. #pragma comment(lib, "advapi32.lib")
  192524. #pragma comment(lib, "ws2_32.lib")
  192525. #pragma comment(lib, "comsupp.lib")
  192526. #pragma comment(lib, "version.lib")
  192527. #if JUCE_OPENGL
  192528. #pragma comment(lib, "OpenGL32.Lib")
  192529. #pragma comment(lib, "GlU32.Lib")
  192530. #endif
  192531. #if JUCE_QUICKTIME
  192532. #pragma comment (lib, "QTMLClient.lib")
  192533. #endif
  192534. #if JUCE_USE_CAMERA
  192535. #pragma comment (lib, "Strmiids.lib")
  192536. #pragma comment (lib, "wmvcore.lib")
  192537. #endif
  192538. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192539. #endif
  192540. END_JUCE_NAMESPACE
  192541. #endif
  192542. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  192543. #endif
  192544. #if JUCE_LINUX
  192545. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  192546. #if JUCE_LINUX
  192547. BEGIN_JUCE_NAMESPACE
  192548. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  192549. #define SUPPORT_AFFINITIES 1
  192550. #endif
  192551. #define JUCE_INCLUDED_FILE 1
  192552. // Now include the actual code files..
  192553. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  192554. CriticalSection::CriticalSection() throw()
  192555. {
  192556. pthread_mutexattr_t atts;
  192557. pthread_mutexattr_init (&atts);
  192558. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  192559. pthread_mutex_init (&internal, &atts);
  192560. }
  192561. CriticalSection::~CriticalSection() throw()
  192562. {
  192563. pthread_mutex_destroy (&internal);
  192564. }
  192565. void CriticalSection::enter() const throw()
  192566. {
  192567. pthread_mutex_lock (&internal);
  192568. }
  192569. bool CriticalSection::tryEnter() const throw()
  192570. {
  192571. return pthread_mutex_trylock (&internal) == 0;
  192572. }
  192573. void CriticalSection::exit() const throw()
  192574. {
  192575. pthread_mutex_unlock (&internal);
  192576. }
  192577. class WaitableEventImpl
  192578. {
  192579. public:
  192580. WaitableEventImpl()
  192581. : triggered (false)
  192582. {
  192583. pthread_cond_init (&condition, 0);
  192584. pthread_mutex_init (&mutex, 0);
  192585. }
  192586. ~WaitableEventImpl()
  192587. {
  192588. pthread_cond_destroy (&condition);
  192589. pthread_mutex_destroy (&mutex);
  192590. }
  192591. bool wait (const int timeOutMillisecs) throw()
  192592. {
  192593. pthread_mutex_lock (&mutex);
  192594. if (! triggered)
  192595. {
  192596. if (timeOutMillisecs < 0)
  192597. {
  192598. do
  192599. {
  192600. pthread_cond_wait (&condition, &mutex);
  192601. }
  192602. while (! triggered);
  192603. }
  192604. else
  192605. {
  192606. struct timeval now;
  192607. gettimeofday (&now, 0);
  192608. struct timespec time;
  192609. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  192610. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  192611. if (time.tv_nsec >= 1000000000)
  192612. {
  192613. time.tv_nsec -= 1000000000;
  192614. time.tv_sec++;
  192615. }
  192616. do
  192617. {
  192618. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  192619. {
  192620. pthread_mutex_unlock (&mutex);
  192621. return false;
  192622. }
  192623. }
  192624. while (! triggered);
  192625. }
  192626. }
  192627. triggered = false;
  192628. pthread_mutex_unlock (&mutex);
  192629. return true;
  192630. }
  192631. void signal() throw()
  192632. {
  192633. pthread_mutex_lock (&mutex);
  192634. triggered = true;
  192635. pthread_cond_broadcast (&condition);
  192636. pthread_mutex_unlock (&mutex);
  192637. }
  192638. void reset() throw()
  192639. {
  192640. pthread_mutex_lock (&mutex);
  192641. triggered = false;
  192642. pthread_mutex_unlock (&mutex);
  192643. }
  192644. private:
  192645. pthread_cond_t condition;
  192646. pthread_mutex_t mutex;
  192647. bool triggered;
  192648. WaitableEventImpl (const WaitableEventImpl&);
  192649. WaitableEventImpl& operator= (const WaitableEventImpl&);
  192650. };
  192651. WaitableEvent::WaitableEvent() throw()
  192652. : internal (new WaitableEventImpl())
  192653. {
  192654. }
  192655. WaitableEvent::~WaitableEvent() throw()
  192656. {
  192657. delete static_cast <WaitableEventImpl*> (internal);
  192658. }
  192659. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  192660. {
  192661. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  192662. }
  192663. void WaitableEvent::signal() const throw()
  192664. {
  192665. static_cast <WaitableEventImpl*> (internal)->signal();
  192666. }
  192667. void WaitableEvent::reset() const throw()
  192668. {
  192669. static_cast <WaitableEventImpl*> (internal)->reset();
  192670. }
  192671. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  192672. {
  192673. struct timespec time;
  192674. time.tv_sec = millisecs / 1000;
  192675. time.tv_nsec = (millisecs % 1000) * 1000000;
  192676. nanosleep (&time, 0);
  192677. }
  192678. const tchar File::separator = T('/');
  192679. const tchar* File::separatorString = T("/");
  192680. const File File::getCurrentWorkingDirectory()
  192681. {
  192682. HeapBlock<char> heapBuffer;
  192683. char localBuffer [1024];
  192684. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  192685. int bufferSize = 4096;
  192686. while (cwd == 0 && errno == ERANGE)
  192687. {
  192688. heapBuffer.malloc (bufferSize);
  192689. cwd = getcwd (heapBuffer, bufferSize - 1);
  192690. bufferSize += 1024;
  192691. }
  192692. return File (String::fromUTF8 (cwd));
  192693. }
  192694. bool File::setAsCurrentWorkingDirectory() const
  192695. {
  192696. return chdir (getFullPathName().toUTF8()) == 0;
  192697. }
  192698. bool juce_copyFile (const String& s, const String& d);
  192699. static bool juce_stat (const String& fileName, struct stat& info)
  192700. {
  192701. return fileName.isNotEmpty()
  192702. && (stat (fileName.toUTF8(), &info) == 0);
  192703. }
  192704. bool juce_isDirectory (const String& fileName)
  192705. {
  192706. struct stat info;
  192707. return fileName.isEmpty()
  192708. || (juce_stat (fileName, info)
  192709. && ((info.st_mode & S_IFDIR) != 0));
  192710. }
  192711. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  192712. {
  192713. if (fileName.isEmpty())
  192714. return false;
  192715. const char* const fileNameUTF8 = fileName.toUTF8();
  192716. bool exists = access (fileNameUTF8, F_OK) == 0;
  192717. if (exists && dontCountDirectories)
  192718. {
  192719. struct stat info;
  192720. const int res = stat (fileNameUTF8, &info);
  192721. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  192722. exists = false;
  192723. }
  192724. return exists;
  192725. }
  192726. int64 juce_getFileSize (const String& fileName)
  192727. {
  192728. struct stat info;
  192729. return juce_stat (fileName, info) ? info.st_size : 0;
  192730. }
  192731. bool juce_canWriteToFile (const String& fileName)
  192732. {
  192733. return access (fileName.toUTF8(), W_OK) == 0;
  192734. }
  192735. bool juce_deleteFile (const String& fileName)
  192736. {
  192737. if (juce_isDirectory (fileName))
  192738. return rmdir (fileName.toUTF8()) == 0;
  192739. else
  192740. return remove (fileName.toUTF8()) == 0;
  192741. }
  192742. bool juce_moveFile (const String& source, const String& dest)
  192743. {
  192744. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  192745. return true;
  192746. if (juce_canWriteToFile (source)
  192747. && juce_copyFile (source, dest))
  192748. {
  192749. if (juce_deleteFile (source))
  192750. return true;
  192751. juce_deleteFile (dest);
  192752. }
  192753. return false;
  192754. }
  192755. void juce_createDirectory (const String& fileName)
  192756. {
  192757. mkdir (fileName.toUTF8(), 0777);
  192758. }
  192759. void* juce_fileOpen (const String& fileName, bool forWriting)
  192760. {
  192761. int flags = O_RDONLY;
  192762. if (forWriting)
  192763. {
  192764. if (juce_fileExists (fileName, false))
  192765. {
  192766. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  192767. if (f != -1)
  192768. lseek (f, 0, SEEK_END);
  192769. return (void*) f;
  192770. }
  192771. else
  192772. {
  192773. flags = O_RDWR + O_CREAT;
  192774. }
  192775. }
  192776. return (void*) open (fileName.toUTF8(), flags, 00644);
  192777. }
  192778. void juce_fileClose (void* handle)
  192779. {
  192780. if (handle != 0)
  192781. close ((int) (pointer_sized_int) handle);
  192782. }
  192783. int juce_fileRead (void* handle, void* buffer, int size)
  192784. {
  192785. if (handle != 0)
  192786. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  192787. return 0;
  192788. }
  192789. int juce_fileWrite (void* handle, const void* buffer, int size)
  192790. {
  192791. if (handle != 0)
  192792. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  192793. return 0;
  192794. }
  192795. int64 juce_fileSetPosition (void* handle, int64 pos)
  192796. {
  192797. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  192798. return pos;
  192799. return -1;
  192800. }
  192801. int64 juce_fileGetPosition (void* handle)
  192802. {
  192803. if (handle != 0)
  192804. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  192805. else
  192806. return -1;
  192807. }
  192808. void juce_fileFlush (void* handle)
  192809. {
  192810. if (handle != 0)
  192811. fsync ((int) (pointer_sized_int) handle);
  192812. }
  192813. const File juce_getExecutableFile()
  192814. {
  192815. Dl_info exeInfo;
  192816. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  192817. return File (String::fromUTF8 (exeInfo.dli_fname));
  192818. }
  192819. // if this file doesn't exist, find a parent of it that does..
  192820. static bool doStatFS (const File* file, struct statfs& result)
  192821. {
  192822. File f (*file);
  192823. for (int i = 5; --i >= 0;)
  192824. {
  192825. if (f.exists())
  192826. break;
  192827. f = f.getParentDirectory();
  192828. }
  192829. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  192830. }
  192831. int64 File::getBytesFreeOnVolume() const
  192832. {
  192833. struct statfs buf;
  192834. if (doStatFS (this, buf))
  192835. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  192836. return 0;
  192837. }
  192838. int64 File::getVolumeTotalSize() const
  192839. {
  192840. struct statfs buf;
  192841. if (doStatFS (this, buf))
  192842. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  192843. return 0;
  192844. }
  192845. const String juce_getVolumeLabel (const String& filenameOnVolume,
  192846. int& volumeSerialNumber)
  192847. {
  192848. volumeSerialNumber = 0;
  192849. #if JUCE_MAC
  192850. struct VolAttrBuf
  192851. {
  192852. u_int32_t length;
  192853. attrreference_t mountPointRef;
  192854. char mountPointSpace [MAXPATHLEN];
  192855. } attrBuf;
  192856. struct attrlist attrList;
  192857. zerostruct (attrList);
  192858. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  192859. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  192860. File f (filenameOnVolume);
  192861. for (;;)
  192862. {
  192863. if (getattrlist (f.getFullPathName().toUTF8(),
  192864. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  192865. {
  192866. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  192867. (int) attrBuf.mountPointRef.attr_length);
  192868. }
  192869. const File parent (f.getParentDirectory());
  192870. if (f == parent)
  192871. break;
  192872. f = parent;
  192873. }
  192874. #endif
  192875. return String::empty;
  192876. }
  192877. void juce_runSystemCommand (const String& command)
  192878. {
  192879. int result = system (command.toUTF8());
  192880. (void) result;
  192881. }
  192882. const String juce_getOutputFromCommand (const String& command)
  192883. {
  192884. // slight bodge here, as we just pipe the output into a temp file and read it...
  192885. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  192886. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  192887. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  192888. String result (tempFile.loadFileAsString());
  192889. tempFile.deleteFile();
  192890. return result;
  192891. }
  192892. InterProcessLock::InterProcessLock (const String& name_)
  192893. : internal (0),
  192894. name (name_),
  192895. reentrancyLevel (0)
  192896. {
  192897. #if JUCE_MAC
  192898. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  192899. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  192900. #else
  192901. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  192902. #endif
  192903. temp.create();
  192904. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  192905. }
  192906. InterProcessLock::~InterProcessLock()
  192907. {
  192908. while (reentrancyLevel > 0)
  192909. this->exit();
  192910. close (internal);
  192911. }
  192912. bool InterProcessLock::enter (const int timeOutMillisecs)
  192913. {
  192914. if (internal == 0)
  192915. return false;
  192916. if (reentrancyLevel != 0)
  192917. return true;
  192918. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  192919. struct flock fl;
  192920. zerostruct (fl);
  192921. fl.l_whence = SEEK_SET;
  192922. fl.l_type = F_WRLCK;
  192923. for (;;)
  192924. {
  192925. const int result = fcntl (internal, F_SETLK, &fl);
  192926. if (result >= 0)
  192927. {
  192928. ++reentrancyLevel;
  192929. return true;
  192930. }
  192931. if (errno != EINTR)
  192932. {
  192933. if (timeOutMillisecs == 0
  192934. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  192935. break;
  192936. Thread::sleep (10);
  192937. }
  192938. }
  192939. return false;
  192940. }
  192941. void InterProcessLock::exit()
  192942. {
  192943. if (reentrancyLevel > 0 && internal != 0)
  192944. {
  192945. --reentrancyLevel;
  192946. struct flock fl;
  192947. zerostruct (fl);
  192948. fl.l_whence = SEEK_SET;
  192949. fl.l_type = F_UNLCK;
  192950. for (;;)
  192951. {
  192952. const int result = fcntl (internal, F_SETLKW, &fl);
  192953. if (result >= 0 || errno != EINTR)
  192954. break;
  192955. }
  192956. }
  192957. }
  192958. /*** End of inlined file: juce_posix_SharedCode.h ***/
  192959. /*** Start of inlined file: juce_linux_Files.cpp ***/
  192960. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  192961. // compiled on its own).
  192962. #if JUCE_INCLUDED_FILE
  192963. static const short U_ISOFS_SUPER_MAGIC = 0x9660; // linux/iso_fs.h
  192964. static const short U_MSDOS_SUPER_MAGIC = 0x4d44; // linux/msdos_fs.h
  192965. static const short U_NFS_SUPER_MAGIC = 0x6969; // linux/nfs_fs.h
  192966. static const short U_SMB_SUPER_MAGIC = 0x517B; // linux/smb_fs.h
  192967. void juce_getFileTimes (const String& fileName,
  192968. int64& modificationTime,
  192969. int64& accessTime,
  192970. int64& creationTime)
  192971. {
  192972. modificationTime = 0;
  192973. accessTime = 0;
  192974. creationTime = 0;
  192975. struct stat info;
  192976. const int res = stat (fileName.toUTF8(), &info);
  192977. if (res == 0)
  192978. {
  192979. modificationTime = (int64) info.st_mtime * 1000;
  192980. accessTime = (int64) info.st_atime * 1000;
  192981. creationTime = (int64) info.st_ctime * 1000;
  192982. }
  192983. }
  192984. bool juce_setFileTimes (const String& fileName,
  192985. int64 modificationTime,
  192986. int64 accessTime,
  192987. int64 creationTime)
  192988. {
  192989. struct utimbuf times;
  192990. times.actime = (time_t) (accessTime / 1000);
  192991. times.modtime = (time_t) (modificationTime / 1000);
  192992. return utime (fileName.toUTF8(), &times) == 0;
  192993. }
  192994. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  192995. {
  192996. struct stat info;
  192997. const int res = stat (fileName.toUTF8(), &info);
  192998. if (res != 0)
  192999. return false;
  193000. info.st_mode &= 0777; // Just permissions
  193001. if( isReadOnly )
  193002. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  193003. else
  193004. // Give everybody write permission?
  193005. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  193006. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  193007. }
  193008. bool juce_copyFile (const String& s, const String& d)
  193009. {
  193010. const File source (s), dest (d);
  193011. FileInputStream* in = source.createInputStream();
  193012. bool ok = false;
  193013. if (in != 0)
  193014. {
  193015. if (dest.deleteFile())
  193016. {
  193017. FileOutputStream* const out = dest.createOutputStream();
  193018. if (out != 0)
  193019. {
  193020. const int bytesCopied = out->writeFromInputStream (*in, -1);
  193021. delete out;
  193022. ok = (bytesCopied == source.getSize());
  193023. if (! ok)
  193024. dest.deleteFile();
  193025. }
  193026. }
  193027. delete in;
  193028. }
  193029. return ok;
  193030. }
  193031. const StringArray juce_getFileSystemRoots()
  193032. {
  193033. StringArray s;
  193034. s.add (T("/"));
  193035. return s;
  193036. }
  193037. bool File::isOnCDRomDrive() const
  193038. {
  193039. struct statfs buf;
  193040. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193041. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  193042. // Assume not if this fails for some reason
  193043. return false;
  193044. }
  193045. bool File::isOnHardDisk() const
  193046. {
  193047. struct statfs buf;
  193048. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193049. {
  193050. switch (buf.f_type)
  193051. {
  193052. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  193053. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  193054. case U_NFS_SUPER_MAGIC: // Network NFS
  193055. case U_SMB_SUPER_MAGIC: // Network Samba
  193056. return false;
  193057. default:
  193058. // Assume anything else is a hard-disk (but note it could
  193059. // be a RAM disk. There isn't a good way of determining
  193060. // this for sure)
  193061. return true;
  193062. }
  193063. }
  193064. // Assume so if this fails for some reason
  193065. return true;
  193066. }
  193067. bool File::isOnRemovableDrive() const
  193068. {
  193069. jassertfalse // xxx not implemented for linux!
  193070. return false;
  193071. }
  193072. bool File::isHidden() const
  193073. {
  193074. return getFileName().startsWithChar (T('.'));
  193075. }
  193076. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193077. const File File::getSpecialLocation (const SpecialLocationType type)
  193078. {
  193079. switch (type)
  193080. {
  193081. case userHomeDirectory:
  193082. {
  193083. const char* homeDir = getenv ("HOME");
  193084. if (homeDir == 0)
  193085. {
  193086. struct passwd* const pw = getpwuid (getuid());
  193087. if (pw != 0)
  193088. homeDir = pw->pw_dir;
  193089. }
  193090. return File (String::fromUTF8 (homeDir));
  193091. }
  193092. case userDocumentsDirectory:
  193093. case userMusicDirectory:
  193094. case userMoviesDirectory:
  193095. case userApplicationDataDirectory:
  193096. return File ("~");
  193097. case userDesktopDirectory:
  193098. return File ("~/Desktop");
  193099. case commonApplicationDataDirectory:
  193100. return File ("/var");
  193101. case globalApplicationsDirectory:
  193102. return File ("/usr");
  193103. case tempDirectory:
  193104. {
  193105. File tmp ("/var/tmp");
  193106. if (! tmp.isDirectory())
  193107. {
  193108. tmp = T("/tmp");
  193109. if (! tmp.isDirectory())
  193110. tmp = File::getCurrentWorkingDirectory();
  193111. }
  193112. return tmp;
  193113. }
  193114. case invokedExecutableFile:
  193115. if (juce_Argv0 != 0)
  193116. return File (String::fromUTF8 (juce_Argv0));
  193117. // deliberate fall-through...
  193118. case currentExecutableFile:
  193119. case currentApplicationFile:
  193120. return juce_getExecutableFile();
  193121. default:
  193122. jassertfalse // unknown type?
  193123. break;
  193124. }
  193125. return File::nonexistent;
  193126. }
  193127. const String File::getVersion() const
  193128. {
  193129. return String::empty; // xxx not yet implemented
  193130. }
  193131. const File File::getLinkedTarget() const
  193132. {
  193133. char buffer [4096];
  193134. size_t numChars = readlink (getFullPathName().toUTF8(),
  193135. buffer, sizeof (buffer));
  193136. if (numChars > 0 && numChars <= sizeof (buffer))
  193137. return File (String::fromUTF8 (buffer, (int) numChars));
  193138. return *this;
  193139. }
  193140. bool File::moveToTrash() const
  193141. {
  193142. if (! exists())
  193143. return true;
  193144. File trashCan (T("~/.Trash"));
  193145. if (! trashCan.isDirectory())
  193146. trashCan = T("~/.local/share/Trash/files");
  193147. if (! trashCan.isDirectory())
  193148. return false;
  193149. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193150. getFileExtension()));
  193151. }
  193152. struct FindFileStruct
  193153. {
  193154. String parentDir, wildCard;
  193155. DIR* dir;
  193156. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193157. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193158. {
  193159. const char* const wildcardUTF8 = wildCard.toUTF8();
  193160. for (;;)
  193161. {
  193162. struct dirent* const de = readdir (dir);
  193163. if (de == 0)
  193164. break;
  193165. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193166. {
  193167. result = String::fromUTF8 (de->d_name);
  193168. const String path (parentDir + result);
  193169. if (isDir != 0 || fileSize != 0)
  193170. {
  193171. struct stat info;
  193172. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193173. if (isDir != 0)
  193174. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193175. if (isHidden != 0)
  193176. *isHidden = (de->d_name[0] == '.');
  193177. if (fileSize != 0)
  193178. *fileSize = statOk ? info.st_size : 0;
  193179. }
  193180. if (modTime != 0 || creationTime != 0)
  193181. {
  193182. int64 m, a, c;
  193183. juce_getFileTimes (path, m, a, c);
  193184. if (modTime != 0)
  193185. *modTime = m;
  193186. if (creationTime != 0)
  193187. *creationTime = c;
  193188. }
  193189. if (isReadOnly != 0)
  193190. *isReadOnly = ! juce_canWriteToFile (path);
  193191. return true;
  193192. }
  193193. }
  193194. return false;
  193195. }
  193196. };
  193197. // returns 0 on failure
  193198. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193199. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193200. Time* creationTime, bool* isReadOnly)
  193201. {
  193202. DIR* d = opendir (directory.toUTF8());
  193203. if (d != 0)
  193204. {
  193205. FindFileStruct* ff = new FindFileStruct();
  193206. ff->parentDir = directory;
  193207. if (!ff->parentDir.endsWithChar (File::separator))
  193208. ff->parentDir += File::separator;
  193209. ff->wildCard = wildCard;
  193210. if (wildCard == T("*.*"))
  193211. ff->wildCard = T("*");
  193212. ff->dir = d;
  193213. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193214. {
  193215. return ff;
  193216. }
  193217. else
  193218. {
  193219. firstResultFile = String::empty;
  193220. isDir = false;
  193221. isHidden = false;
  193222. closedir (d);
  193223. delete ff;
  193224. }
  193225. }
  193226. return 0;
  193227. }
  193228. bool juce_findFileNext (void* handle, String& resultFile,
  193229. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193230. {
  193231. FindFileStruct* const ff = (FindFileStruct*) handle;
  193232. if (ff != 0)
  193233. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193234. return false;
  193235. }
  193236. void juce_findFileClose (void* handle)
  193237. {
  193238. FindFileStruct* const ff = (FindFileStruct*) handle;
  193239. if (ff != 0)
  193240. {
  193241. closedir (ff->dir);
  193242. delete ff;
  193243. }
  193244. }
  193245. bool juce_launchFile (const String& fileName,
  193246. const String& parameters)
  193247. {
  193248. String cmdString (fileName.replace (T(" "), T("\\ "),false));
  193249. cmdString << " " << parameters;
  193250. if (URL::isProbablyAWebsiteURL (fileName)
  193251. || cmdString.startsWithIgnoreCase (T("file:"))
  193252. || URL::isProbablyAnEmailAddress (fileName))
  193253. {
  193254. // create a command that tries to launch a bunch of likely browsers
  193255. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193256. StringArray cmdLines;
  193257. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193258. cmdLines.add (String (browserNames[i]) + T(" ") + cmdString.trim().quoted());
  193259. cmdString = cmdLines.joinIntoString (T(" || "));
  193260. }
  193261. const char* const argv[4] = { "/bin/sh", "-c", cmdString.toUTF8(), 0 };
  193262. const int cpid = fork();
  193263. if (cpid == 0)
  193264. {
  193265. setsid();
  193266. // Child process
  193267. execve (argv[0], (char**) argv, environ);
  193268. exit (0);
  193269. }
  193270. return cpid >= 0;
  193271. }
  193272. void File::revealToUser() const
  193273. {
  193274. if (isDirectory())
  193275. startAsProcess();
  193276. else if (getParentDirectory().exists())
  193277. getParentDirectory().startAsProcess();
  193278. }
  193279. #endif
  193280. /*** End of inlined file: juce_linux_Files.cpp ***/
  193281. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193282. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193283. // compiled on its own).
  193284. #if JUCE_INCLUDED_FILE
  193285. struct NamedPipeInternal
  193286. {
  193287. String pipeInName, pipeOutName;
  193288. int pipeIn, pipeOut;
  193289. bool volatile createdPipe, blocked, stopReadOperation;
  193290. static void signalHandler (int) {}
  193291. };
  193292. void NamedPipe::cancelPendingReads()
  193293. {
  193294. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193295. {
  193296. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193297. intern->stopReadOperation = true;
  193298. char buffer [1] = { 0 };
  193299. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193300. (void) bytesWritten;
  193301. int timeout = 2000;
  193302. while (intern->blocked && --timeout >= 0)
  193303. Thread::sleep (2);
  193304. intern->stopReadOperation = false;
  193305. }
  193306. }
  193307. void NamedPipe::close()
  193308. {
  193309. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193310. if (intern != 0)
  193311. {
  193312. internal = 0;
  193313. if (intern->pipeIn != -1)
  193314. ::close (intern->pipeIn);
  193315. if (intern->pipeOut != -1)
  193316. ::close (intern->pipeOut);
  193317. if (intern->createdPipe)
  193318. {
  193319. unlink (intern->pipeInName.toUTF8());
  193320. unlink (intern->pipeOutName.toUTF8());
  193321. }
  193322. delete intern;
  193323. }
  193324. }
  193325. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193326. {
  193327. close();
  193328. NamedPipeInternal* const intern = new NamedPipeInternal();
  193329. internal = intern;
  193330. intern->createdPipe = createPipe;
  193331. intern->blocked = false;
  193332. intern->stopReadOperation = false;
  193333. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193334. siginterrupt (SIGPIPE, 1);
  193335. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  193336. intern->pipeInName = pipePath + T("_in");
  193337. intern->pipeOutName = pipePath + T("_out");
  193338. intern->pipeIn = -1;
  193339. intern->pipeOut = -1;
  193340. if (createPipe)
  193341. {
  193342. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  193343. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  193344. {
  193345. delete intern;
  193346. internal = 0;
  193347. return false;
  193348. }
  193349. }
  193350. return true;
  193351. }
  193352. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193353. {
  193354. int bytesRead = -1;
  193355. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193356. if (intern != 0)
  193357. {
  193358. intern->blocked = true;
  193359. if (intern->pipeIn == -1)
  193360. {
  193361. if (intern->createdPipe)
  193362. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  193363. else
  193364. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  193365. if (intern->pipeIn == -1)
  193366. {
  193367. intern->blocked = false;
  193368. return -1;
  193369. }
  193370. }
  193371. bytesRead = 0;
  193372. char* p = (char*) destBuffer;
  193373. while (bytesRead < maxBytesToRead)
  193374. {
  193375. const int bytesThisTime = maxBytesToRead - bytesRead;
  193376. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193377. if (numRead <= 0 || intern->stopReadOperation)
  193378. {
  193379. bytesRead = -1;
  193380. break;
  193381. }
  193382. bytesRead += numRead;
  193383. p += bytesRead;
  193384. }
  193385. intern->blocked = false;
  193386. }
  193387. return bytesRead;
  193388. }
  193389. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193390. {
  193391. int bytesWritten = -1;
  193392. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193393. if (intern != 0)
  193394. {
  193395. if (intern->pipeOut == -1)
  193396. {
  193397. if (intern->createdPipe)
  193398. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  193399. else
  193400. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  193401. if (intern->pipeOut == -1)
  193402. {
  193403. return -1;
  193404. }
  193405. }
  193406. const char* p = (const char*) sourceBuffer;
  193407. bytesWritten = 0;
  193408. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193409. while (bytesWritten < numBytesToWrite
  193410. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193411. {
  193412. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193413. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193414. if (numWritten <= 0)
  193415. {
  193416. bytesWritten = -1;
  193417. break;
  193418. }
  193419. bytesWritten += numWritten;
  193420. p += bytesWritten;
  193421. }
  193422. }
  193423. return bytesWritten;
  193424. }
  193425. #endif
  193426. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193427. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193428. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193429. // compiled on its own).
  193430. #if JUCE_INCLUDED_FILE
  193431. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  193432. {
  193433. int numResults = 0;
  193434. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193435. if (s != -1)
  193436. {
  193437. char buf [1024];
  193438. struct ifconf ifc;
  193439. ifc.ifc_len = sizeof (buf);
  193440. ifc.ifc_buf = buf;
  193441. ioctl (s, SIOCGIFCONF, &ifc);
  193442. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193443. {
  193444. struct ifreq ifr;
  193445. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193446. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193447. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193448. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193449. && numResults < maxNum)
  193450. {
  193451. int64 a = 0;
  193452. for (int j = 6; --j >= 0;)
  193453. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193454. *addresses++ = a;
  193455. ++numResults;
  193456. }
  193457. }
  193458. close (s);
  193459. }
  193460. return numResults;
  193461. }
  193462. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193463. const String& emailSubject,
  193464. const String& bodyText,
  193465. const StringArray& filesToAttach)
  193466. {
  193467. jassertfalse // xxx todo
  193468. return false;
  193469. }
  193470. class JUCE_HTTPSocketStream
  193471. {
  193472. public:
  193473. JUCE_HTTPSocketStream()
  193474. : readPosition (0),
  193475. socketHandle (-1),
  193476. levelsOfRedirection (0),
  193477. timeoutSeconds (15)
  193478. {
  193479. }
  193480. ~JUCE_HTTPSocketStream()
  193481. {
  193482. closeSocket();
  193483. }
  193484. bool open (const String& url,
  193485. const String& headers,
  193486. const MemoryBlock& postData,
  193487. const bool isPost,
  193488. URL::OpenStreamProgressCallback* callback,
  193489. void* callbackContext,
  193490. int timeOutMs)
  193491. {
  193492. closeSocket();
  193493. uint32 timeOutTime = Time::getMillisecondCounter();
  193494. if (timeOutMs == 0)
  193495. timeOutTime += 60000;
  193496. else if (timeOutMs < 0)
  193497. timeOutTime = 0xffffffff;
  193498. else
  193499. timeOutTime += timeOutMs;
  193500. String hostName, hostPath;
  193501. int hostPort;
  193502. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193503. return false;
  193504. const struct hostent* host = 0;
  193505. int port = 0;
  193506. String proxyName, proxyPath;
  193507. int proxyPort = 0;
  193508. String proxyURL (getenv ("http_proxy"));
  193509. if (proxyURL.startsWithIgnoreCase (T("http://")))
  193510. {
  193511. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193512. return false;
  193513. host = gethostbyname (proxyName.toUTF8());
  193514. port = proxyPort;
  193515. }
  193516. else
  193517. {
  193518. host = gethostbyname (hostName.toUTF8());
  193519. port = hostPort;
  193520. }
  193521. if (host == 0)
  193522. return false;
  193523. struct sockaddr_in address;
  193524. zerostruct (address);
  193525. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  193526. address.sin_family = host->h_addrtype;
  193527. address.sin_port = htons (port);
  193528. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193529. if (socketHandle == -1)
  193530. return false;
  193531. int receiveBufferSize = 16384;
  193532. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193533. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193534. #if JUCE_MAC
  193535. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193536. #endif
  193537. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193538. {
  193539. closeSocket();
  193540. return false;
  193541. }
  193542. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193543. proxyName, proxyPort,
  193544. hostPath, url,
  193545. headers, postData,
  193546. isPost));
  193547. size_t totalHeaderSent = 0;
  193548. while (totalHeaderSent < requestHeader.getSize())
  193549. {
  193550. if (Time::getMillisecondCounter() > timeOutTime)
  193551. {
  193552. closeSocket();
  193553. return false;
  193554. }
  193555. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193556. if (send (socketHandle,
  193557. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193558. numToSend, 0)
  193559. != numToSend)
  193560. {
  193561. closeSocket();
  193562. return false;
  193563. }
  193564. totalHeaderSent += numToSend;
  193565. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193566. {
  193567. closeSocket();
  193568. return false;
  193569. }
  193570. }
  193571. const String responseHeader (readResponse (timeOutTime));
  193572. if (responseHeader.isNotEmpty())
  193573. {
  193574. //DBG (responseHeader);
  193575. StringArray lines;
  193576. lines.addLines (responseHeader);
  193577. // NB - using charToString() here instead of just T(" "), because that was
  193578. // causing a mysterious gcc internal compiler error...
  193579. const int statusCode = responseHeader.fromFirstOccurrenceOf (String::charToString (T(' ')), false, false)
  193580. .substring (0, 3).getIntValue();
  193581. //int contentLength = findHeaderItem (lines, T("Content-Length:")).getIntValue();
  193582. //bool isChunked = findHeaderItem (lines, T("Transfer-Encoding:")).equalsIgnoreCase ("chunked");
  193583. String location (findHeaderItem (lines, T("Location:")));
  193584. if (statusCode >= 300 && statusCode < 400
  193585. && location.isNotEmpty())
  193586. {
  193587. if (! location.startsWithIgnoreCase (T("http://")))
  193588. location = T("http://") + location;
  193589. if (levelsOfRedirection++ < 3)
  193590. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  193591. }
  193592. else
  193593. {
  193594. levelsOfRedirection = 0;
  193595. return true;
  193596. }
  193597. }
  193598. closeSocket();
  193599. return false;
  193600. }
  193601. int read (void* buffer, int bytesToRead)
  193602. {
  193603. fd_set readbits;
  193604. FD_ZERO (&readbits);
  193605. FD_SET (socketHandle, &readbits);
  193606. struct timeval tv;
  193607. tv.tv_sec = timeoutSeconds;
  193608. tv.tv_usec = 0;
  193609. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193610. return 0; // (timeout)
  193611. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  193612. readPosition += bytesRead;
  193613. return bytesRead;
  193614. }
  193615. int readPosition;
  193616. juce_UseDebuggingNewOperator
  193617. private:
  193618. int socketHandle, levelsOfRedirection;
  193619. const int timeoutSeconds;
  193620. void closeSocket()
  193621. {
  193622. if (socketHandle >= 0)
  193623. close (socketHandle);
  193624. socketHandle = -1;
  193625. }
  193626. const MemoryBlock createRequestHeader (const String& hostName,
  193627. const int hostPort,
  193628. const String& proxyName,
  193629. const int proxyPort,
  193630. const String& hostPath,
  193631. const String& originalURL,
  193632. const String& headers,
  193633. const MemoryBlock& postData,
  193634. const bool isPost)
  193635. {
  193636. String header (isPost ? "POST " : "GET ");
  193637. if (proxyName.isEmpty())
  193638. {
  193639. header << hostPath << " HTTP/1.0\r\nHost: "
  193640. << hostName << ':' << hostPort;
  193641. }
  193642. else
  193643. {
  193644. header << originalURL << " HTTP/1.0\r\nHost: "
  193645. << proxyName << ':' << proxyPort;
  193646. }
  193647. header << "\r\nUser-Agent: JUCE/"
  193648. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  193649. << "\r\nConnection: Close\r\nContent-Length: "
  193650. << postData.getSize() << "\r\n"
  193651. << headers << "\r\n";
  193652. MemoryBlock mb;
  193653. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  193654. mb.append (postData.getData(), postData.getSize());
  193655. return mb;
  193656. }
  193657. const String readResponse (const uint32 timeOutTime)
  193658. {
  193659. int bytesRead = 0, numConsecutiveLFs = 0;
  193660. MemoryBlock buffer (1024, true);
  193661. while (numConsecutiveLFs < 2 && bytesRead < 32768
  193662. && Time::getMillisecondCounter() <= timeOutTime)
  193663. {
  193664. fd_set readbits;
  193665. FD_ZERO (&readbits);
  193666. FD_SET (socketHandle, &readbits);
  193667. struct timeval tv;
  193668. tv.tv_sec = timeoutSeconds;
  193669. tv.tv_usec = 0;
  193670. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193671. return String::empty; // (timeout)
  193672. buffer.ensureSize (bytesRead + 8, true);
  193673. char* const dest = (char*) buffer.getData() + bytesRead;
  193674. if (recv (socketHandle, dest, 1, 0) == -1)
  193675. return String::empty;
  193676. const char lastByte = *dest;
  193677. ++bytesRead;
  193678. if (lastByte == '\n')
  193679. ++numConsecutiveLFs;
  193680. else if (lastByte != '\r')
  193681. numConsecutiveLFs = 0;
  193682. }
  193683. const String header (String::fromUTF8 ((const char*) buffer.getData()));
  193684. if (header.startsWithIgnoreCase (T("HTTP/")))
  193685. return header.trimEnd();
  193686. return String::empty;
  193687. }
  193688. static bool decomposeURL (const String& url,
  193689. String& host, String& path, int& port)
  193690. {
  193691. if (! url.startsWithIgnoreCase (T("http://")))
  193692. return false;
  193693. const int nextSlash = url.indexOfChar (7, '/');
  193694. int nextColon = url.indexOfChar (7, ':');
  193695. if (nextColon > nextSlash && nextSlash > 0)
  193696. nextColon = -1;
  193697. if (nextColon >= 0)
  193698. {
  193699. host = url.substring (7, nextColon);
  193700. if (nextSlash >= 0)
  193701. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  193702. else
  193703. port = url.substring (nextColon + 1).getIntValue();
  193704. }
  193705. else
  193706. {
  193707. port = 80;
  193708. if (nextSlash >= 0)
  193709. host = url.substring (7, nextSlash);
  193710. else
  193711. host = url.substring (7);
  193712. }
  193713. if (nextSlash >= 0)
  193714. path = url.substring (nextSlash);
  193715. else
  193716. path = T("/");
  193717. return true;
  193718. }
  193719. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  193720. {
  193721. for (int i = 0; i < lines.size(); ++i)
  193722. if (lines[i].startsWithIgnoreCase (itemName))
  193723. return lines[i].substring (itemName.length()).trim();
  193724. return String::empty;
  193725. }
  193726. };
  193727. bool juce_isOnLine()
  193728. {
  193729. return true;
  193730. }
  193731. void* juce_openInternetFile (const String& url,
  193732. const String& headers,
  193733. const MemoryBlock& postData,
  193734. const bool isPost,
  193735. URL::OpenStreamProgressCallback* callback,
  193736. void* callbackContext,
  193737. int timeOutMs)
  193738. {
  193739. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  193740. if (s->open (url, headers, postData, isPost,
  193741. callback, callbackContext, timeOutMs))
  193742. return s;
  193743. delete s;
  193744. return 0;
  193745. }
  193746. void juce_closeInternetFile (void* handle)
  193747. {
  193748. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193749. if (s != 0)
  193750. delete s;
  193751. }
  193752. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  193753. {
  193754. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193755. if (s != 0)
  193756. return s->read (buffer, bytesToRead);
  193757. return 0;
  193758. }
  193759. int64 juce_getInternetFileContentLength (void* handle)
  193760. {
  193761. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193762. if (s != 0)
  193763. {
  193764. //xxx todo
  193765. jassertfalse
  193766. }
  193767. return -1;
  193768. }
  193769. int juce_seekInInternetFile (void* handle, int newPosition)
  193770. {
  193771. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193772. if (s != 0)
  193773. return s->readPosition;
  193774. return 0;
  193775. }
  193776. #endif
  193777. /*** End of inlined file: juce_linux_Network.cpp ***/
  193778. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  193779. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193780. // compiled on its own).
  193781. #if JUCE_INCLUDED_FILE
  193782. void Logger::outputDebugString (const String& text) throw()
  193783. {
  193784. std::cerr << text << std::endl;
  193785. }
  193786. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  193787. {
  193788. return Linux;
  193789. }
  193790. const String SystemStats::getOperatingSystemName() throw()
  193791. {
  193792. return T("Linux");
  193793. }
  193794. bool SystemStats::isOperatingSystem64Bit() throw()
  193795. {
  193796. #if JUCE_64BIT
  193797. return true;
  193798. #else
  193799. //xxx not sure how to find this out?..
  193800. return false;
  193801. #endif
  193802. }
  193803. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  193804. {
  193805. String info;
  193806. char buf [256];
  193807. FILE* f = fopen ("/proc/cpuinfo", "r");
  193808. while (f != 0 && fgets (buf, sizeof(buf), f))
  193809. {
  193810. if (strncmp (buf, key, strlen (key)) == 0)
  193811. {
  193812. char* p = buf;
  193813. while (*p && *p != '\n')
  193814. ++p;
  193815. if (*p != 0)
  193816. *p = 0;
  193817. p = buf;
  193818. while (*p != 0 && *p != ':')
  193819. ++p;
  193820. if (*p != 0 && *(p + 1) != 0)
  193821. info = p + 2;
  193822. if (! lastOne)
  193823. break;
  193824. }
  193825. }
  193826. fclose (f);
  193827. return info;
  193828. }
  193829. bool SystemStats::hasMMX() throw()
  193830. {
  193831. return getCpuInfo ("flags").contains (T("mmx"));
  193832. }
  193833. bool SystemStats::hasSSE() throw()
  193834. {
  193835. return getCpuInfo ("flags").contains (T("sse"));
  193836. }
  193837. bool SystemStats::hasSSE2() throw()
  193838. {
  193839. return getCpuInfo ("flags").contains (T("sse2"));
  193840. }
  193841. bool SystemStats::has3DNow() throw()
  193842. {
  193843. return getCpuInfo ("flags").contains (T("3dnow"));
  193844. }
  193845. const String SystemStats::getCpuVendor() throw()
  193846. {
  193847. return getCpuInfo ("vendor_id");
  193848. }
  193849. int SystemStats::getCpuSpeedInMegaherz() throw()
  193850. {
  193851. const String speed (getCpuInfo ("cpu MHz"));
  193852. return (int) (speed.getFloatValue() + 0.5f);
  193853. }
  193854. int SystemStats::getMemorySizeInMegabytes() throw()
  193855. {
  193856. struct sysinfo sysi;
  193857. if (sysinfo (&sysi) == 0)
  193858. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  193859. return 0;
  193860. }
  193861. uint32 juce_millisecondsSinceStartup() throw()
  193862. {
  193863. static unsigned int calibrate = 0;
  193864. static bool calibrated = false;
  193865. timeval t;
  193866. unsigned int ret = 0;
  193867. if (! gettimeofday (&t, 0))
  193868. {
  193869. if (! calibrated)
  193870. {
  193871. struct sysinfo sysi;
  193872. if (sysinfo (&sysi) == 0)
  193873. // Safe to assume system was not brought up earlier than 1970!
  193874. calibrate = t.tv_sec - sysi.uptime;
  193875. calibrated = true;
  193876. }
  193877. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  193878. }
  193879. return ret;
  193880. }
  193881. double Time::getMillisecondCounterHiRes() throw()
  193882. {
  193883. return getHighResolutionTicks() * 0.001;
  193884. }
  193885. int64 Time::getHighResolutionTicks() throw()
  193886. {
  193887. timeval t;
  193888. if (gettimeofday (&t, 0))
  193889. return 0;
  193890. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  193891. }
  193892. int64 Time::getHighResolutionTicksPerSecond() throw()
  193893. {
  193894. // Microseconds
  193895. return 1000000;
  193896. }
  193897. bool Time::setSystemTimeToThisTime() const throw()
  193898. {
  193899. timeval t;
  193900. t.tv_sec = millisSinceEpoch % 1000000;
  193901. t.tv_usec = millisSinceEpoch - t.tv_sec;
  193902. return settimeofday (&t, NULL) ? false : true;
  193903. }
  193904. int SystemStats::getPageSize() throw()
  193905. {
  193906. static int systemPageSize = 0;
  193907. if (systemPageSize == 0)
  193908. systemPageSize = sysconf (_SC_PAGESIZE);
  193909. return systemPageSize;
  193910. }
  193911. int SystemStats::getNumCpus() throw()
  193912. {
  193913. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  193914. return lastCpu + 1;
  193915. }
  193916. const String SystemStats::getLogonName()
  193917. {
  193918. const char* user = getenv ("USER");
  193919. if (user == 0)
  193920. {
  193921. struct passwd* const pw = getpwuid (getuid());
  193922. if (pw != 0)
  193923. user = pw->pw_name;
  193924. }
  193925. return String::fromUTF8 (user);
  193926. }
  193927. const String SystemStats::getFullUserName()
  193928. {
  193929. return getLogonName();
  193930. }
  193931. void SystemStats::initialiseStats() throw()
  193932. {
  193933. // Process starts off as root when running suid
  193934. Process::lowerPrivilege();
  193935. String s (SystemStats::getJUCEVersion());
  193936. }
  193937. void PlatformUtilities::fpuReset()
  193938. {
  193939. }
  193940. #endif
  193941. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  193942. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  193943. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193944. // compiled on its own).
  193945. #if JUCE_INCLUDED_FILE
  193946. void JUCE_API juce_threadEntryPoint (void*);
  193947. void* threadEntryProc (void* value)
  193948. {
  193949. // New threads start off as root when running suid
  193950. Process::lowerPrivilege();
  193951. juce_threadEntryPoint (value);
  193952. return 0;
  193953. }
  193954. void* juce_createThread (void* userData)
  193955. {
  193956. pthread_t handle = 0;
  193957. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  193958. {
  193959. pthread_detach (handle);
  193960. return (void*)handle;
  193961. }
  193962. return 0;
  193963. }
  193964. void juce_killThread (void* handle)
  193965. {
  193966. if (handle != 0)
  193967. pthread_cancel ((pthread_t)handle);
  193968. }
  193969. void juce_setCurrentThreadName (const String& /*name*/)
  193970. {
  193971. }
  193972. Thread::ThreadID Thread::getCurrentThreadId()
  193973. {
  193974. return (ThreadID) pthread_self();
  193975. }
  193976. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  193977. // priority of the current thread
  193978. bool juce_setThreadPriority (void* handle, int priority)
  193979. {
  193980. struct sched_param param;
  193981. int policy, maxp, minp, pri;
  193982. if (handle == 0)
  193983. handle = (void*) pthread_self();
  193984. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  193985. && policy != SCHED_OTHER)
  193986. {
  193987. minp = sched_get_priority_min(policy);
  193988. maxp = sched_get_priority_max(policy);
  193989. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  193990. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  193991. // Realtime process priority
  193992. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  193993. else
  193994. // High process priority
  193995. param.__sched_priority = minp + pri;
  193996. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  193997. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  193998. }
  193999. return false;
  194000. }
  194001. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  194002. {
  194003. #if SUPPORT_AFFINITIES
  194004. cpu_set_t affinity;
  194005. CPU_ZERO (&affinity);
  194006. for (int i = 0; i < 32; ++i)
  194007. if ((affinityMask & (1 << i)) != 0)
  194008. CPU_SET (i, &affinity);
  194009. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  194010. sched_yield();
  194011. #else
  194012. /* affinities aren't supported because either the appropriate header files weren't found,
  194013. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  194014. */
  194015. jassertfalse
  194016. #endif
  194017. }
  194018. void Thread::yield()
  194019. {
  194020. sched_yield();
  194021. }
  194022. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  194023. void Process::setPriority (ProcessPriority prior)
  194024. {
  194025. struct sched_param param;
  194026. int policy, maxp, minp;
  194027. const int p = (int) prior;
  194028. if (p <= 1)
  194029. policy = SCHED_OTHER;
  194030. else
  194031. policy = SCHED_RR;
  194032. minp = sched_get_priority_min (policy);
  194033. maxp = sched_get_priority_max (policy);
  194034. if (p < 2)
  194035. param.__sched_priority = 0;
  194036. else if (p == 2 )
  194037. // Set to middle of lower realtime priority range
  194038. param.__sched_priority = minp + (maxp - minp) / 4;
  194039. else
  194040. // Set to middle of higher realtime priority range
  194041. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  194042. pthread_setschedparam (pthread_self(), policy, &param);
  194043. }
  194044. void Process::terminate()
  194045. {
  194046. exit (0);
  194047. }
  194048. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  194049. {
  194050. static char testResult = 0;
  194051. if (testResult == 0)
  194052. {
  194053. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  194054. if (testResult >= 0)
  194055. {
  194056. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  194057. testResult = 1;
  194058. }
  194059. }
  194060. return testResult < 0;
  194061. }
  194062. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  194063. {
  194064. return juce_isRunningUnderDebugger();
  194065. }
  194066. void Process::raisePrivilege()
  194067. {
  194068. // If running suid root, change effective user
  194069. // to root
  194070. if (geteuid() != 0 && getuid() == 0)
  194071. {
  194072. setreuid (geteuid(), getuid());
  194073. setregid (getegid(), getgid());
  194074. }
  194075. }
  194076. void Process::lowerPrivilege()
  194077. {
  194078. // If runing suid root, change effective user
  194079. // back to real user
  194080. if (geteuid() == 0 && getuid() != 0)
  194081. {
  194082. setreuid (geteuid(), getuid());
  194083. setregid (getegid(), getgid());
  194084. }
  194085. }
  194086. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194087. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194088. {
  194089. return dlopen (name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194090. }
  194091. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194092. {
  194093. dlclose(handle);
  194094. }
  194095. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194096. {
  194097. return dlsym (libraryHandle, procedureName.toCString());
  194098. }
  194099. #endif
  194100. #endif
  194101. /*** End of inlined file: juce_linux_Threads.cpp ***/
  194102. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194103. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  194104. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194105. // compiled on its own).
  194106. #if JUCE_INCLUDED_FILE
  194107. #ifdef JUCE_DEBUG
  194108. #define JUCE_DEBUG_XERRORS 1
  194109. #endif
  194110. extern Display* display;
  194111. extern Window juce_messageWindowHandle;
  194112. static String localClipboardContent;
  194113. static Atom atom_UTF8_STRING;
  194114. static Atom atom_CLIPBOARD;
  194115. static Atom atom_TARGETS;
  194116. static void initSelectionAtoms()
  194117. {
  194118. static bool isInitialised = false;
  194119. if (! isInitialised)
  194120. {
  194121. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194122. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194123. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194124. }
  194125. }
  194126. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194127. // works only for strings shorter than 1000000 bytes
  194128. static String juce_readWindowProperty (Window window, Atom prop,
  194129. Atom fmt, // XA_STRING or UTF8_STRING
  194130. bool deleteAfterReading)
  194131. {
  194132. String returnData;
  194133. char* clipData;
  194134. Atom actualType;
  194135. int actualFormat;
  194136. unsigned long numItems, bytesLeft;
  194137. if (XGetWindowProperty (display, window, prop,
  194138. 0L /* offset */, 1000000 /* length (max) */, False,
  194139. AnyPropertyType /* format */,
  194140. &actualType, &actualFormat, &numItems, &bytesLeft,
  194141. (unsigned char**) &clipData) == Success)
  194142. {
  194143. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194144. {
  194145. returnData = String::fromUTF8 (clipData, numItems);
  194146. }
  194147. else if (actualType == XA_STRING && actualFormat == 8)
  194148. {
  194149. returnData = String (clipData, numItems);
  194150. }
  194151. if (clipData != 0)
  194152. XFree (clipData);
  194153. jassert (bytesLeft == 0 || numItems == 1000000);
  194154. }
  194155. if (deleteAfterReading)
  194156. XDeleteProperty (display, window, prop);
  194157. return returnData;
  194158. }
  194159. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194160. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194161. {
  194162. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194163. // The selection owner will be asked to set the JUCE_SEL property on the
  194164. // juce_messageWindowHandle with the selection content
  194165. XConvertSelection (display, selection, requested_format, property_name,
  194166. juce_messageWindowHandle, CurrentTime);
  194167. int timeoutMs = 200; // will wait at most for 200 ms
  194168. do
  194169. {
  194170. XEvent event;
  194171. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194172. {
  194173. if (event.xselection.property == property_name)
  194174. {
  194175. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194176. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194177. event.xselection.property,
  194178. requested_format, true);
  194179. return true;
  194180. }
  194181. else
  194182. {
  194183. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194184. }
  194185. }
  194186. // not very elegant.. we could do a select() or something like that...
  194187. // however clipboard content requesting is inherently slow on x11, it
  194188. // often takes 50ms or more so...
  194189. Thread::sleep (4);
  194190. timeoutMs -= 4;
  194191. }
  194192. while (timeoutMs > 0);
  194193. DBG("timeout for juce_requestSelectionContent");
  194194. return false;
  194195. }
  194196. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194197. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194198. {
  194199. initSelectionAtoms();
  194200. // the selection content is sent to the target window as a window property
  194201. XSelectionEvent reply;
  194202. reply.type = SelectionNotify;
  194203. reply.display = evt.display;
  194204. reply.requestor = evt.requestor;
  194205. reply.selection = evt.selection;
  194206. reply.target = evt.target;
  194207. reply.property = None; // == "fail"
  194208. reply.time = evt.time;
  194209. HeapBlock <char> data;
  194210. int propertyFormat = 0, numDataItems = 0;
  194211. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194212. {
  194213. if (evt.target == XA_STRING)
  194214. {
  194215. // format data according to system locale
  194216. numDataItems = localClipboardContent.getNumBytesAsCString() + 1;
  194217. data.calloc (numDataItems + 1);
  194218. localClipboardContent.copyToCString (data, numDataItems);
  194219. propertyFormat = 8; // bits/item
  194220. }
  194221. else if (evt.target == atom_UTF8_STRING)
  194222. {
  194223. // translate to utf8
  194224. numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1;
  194225. data.calloc (numDataItems + 1);
  194226. localClipboardContent.copyToUTF8 (data, numDataItems);
  194227. propertyFormat = 8; // bits/item
  194228. }
  194229. else if (evt.target == atom_TARGETS)
  194230. {
  194231. // another application wants to know what we are able to send
  194232. numDataItems = 2;
  194233. propertyFormat = 32; // atoms are 32-bit
  194234. data.calloc (numDataItems * 4);
  194235. Atom* atoms = reinterpret_cast<Atom*> (data.getData());
  194236. atoms[0] = atom_UTF8_STRING;
  194237. atoms[1] = XA_STRING;
  194238. }
  194239. }
  194240. else
  194241. {
  194242. DBG ("requested unsupported clipboard");
  194243. }
  194244. if (data != 0)
  194245. {
  194246. const int maxReasonableSelectionSize = 1000000;
  194247. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194248. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194249. {
  194250. XChangeProperty (evt.display, evt.requestor,
  194251. evt.property, evt.target,
  194252. propertyFormat /* 8 or 32 */, PropModeReplace,
  194253. reinterpret_cast<const unsigned char*> (data.getData()), numDataItems);
  194254. reply.property = evt.property; // " == success"
  194255. }
  194256. }
  194257. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194258. }
  194259. void SystemClipboard::copyTextToClipboard (const String& clipText) throw()
  194260. {
  194261. initSelectionAtoms();
  194262. localClipboardContent = clipText;
  194263. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194264. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194265. }
  194266. const String SystemClipboard::getTextFromClipboard() throw()
  194267. {
  194268. initSelectionAtoms();
  194269. String content;
  194270. Atom selection = XA_PRIMARY;
  194271. Window selectionOwner = None;
  194272. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194273. {
  194274. selection = atom_CLIPBOARD;
  194275. selectionOwner = XGetSelectionOwner (display, selection);
  194276. }
  194277. if (selectionOwner != None)
  194278. {
  194279. if (selectionOwner == juce_messageWindowHandle)
  194280. {
  194281. content = localClipboardContent;
  194282. }
  194283. else
  194284. {
  194285. // first try: we want an utf8 string
  194286. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194287. if (! ok)
  194288. {
  194289. // second chance, ask for a good old locale-dependent string ..
  194290. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194291. }
  194292. }
  194293. }
  194294. return content;
  194295. }
  194296. #endif
  194297. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194298. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194299. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194300. // compiled on its own).
  194301. #if JUCE_INCLUDED_FILE
  194302. #ifdef JUCE_DEBUG
  194303. #define JUCE_DEBUG_XERRORS 1
  194304. #endif
  194305. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194306. Window juce_messageWindowHandle = None;
  194307. XContext improbableNumber; // This is referenced from Windowing.cpp
  194308. extern void juce_windowMessageReceive (XEvent* event); // Defined in Windowing.cpp
  194309. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt); // Defined in Clipboard.cpp
  194310. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194311. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194312. class InternalMessageQueue
  194313. {
  194314. public:
  194315. InternalMessageQueue()
  194316. : bytesInSocket (0)
  194317. {
  194318. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194319. (void) ret; jassert (ret == 0);
  194320. //setNonBlocking (fd[0]);
  194321. //setNonBlocking (fd[1]);
  194322. }
  194323. ~InternalMessageQueue()
  194324. {
  194325. close (fd[0]);
  194326. close (fd[1]);
  194327. }
  194328. void postMessage (Message* msg)
  194329. {
  194330. const int maxBytesInSocketQueue = 128;
  194331. ScopedLock sl (lock);
  194332. queue.add (msg);
  194333. if (bytesInSocket < maxBytesInSocketQueue)
  194334. {
  194335. ++bytesInSocket;
  194336. ScopedUnlock ul (lock);
  194337. const unsigned char x = 0xff;
  194338. size_t bytesWritten = write (fd[0], &x, 1);
  194339. (void) bytesWritten;
  194340. }
  194341. }
  194342. bool isEmpty() const
  194343. {
  194344. ScopedLock sl (lock);
  194345. return queue.size() == 0;
  194346. }
  194347. Message* popNextMessage()
  194348. {
  194349. ScopedLock sl (lock);
  194350. if (bytesInSocket > 0)
  194351. {
  194352. --bytesInSocket;
  194353. ScopedUnlock ul (lock);
  194354. unsigned char x;
  194355. size_t numBytes = read (fd[1], &x, 1);
  194356. (void) numBytes;
  194357. }
  194358. Message* m = queue[0];
  194359. queue.remove (0, false /* deleteObject */);
  194360. return m;
  194361. }
  194362. int getWaitHandle() const { return fd[1]; }
  194363. private:
  194364. CriticalSection lock;
  194365. OwnedArray <Message> queue;
  194366. int fd[2];
  194367. int bytesInSocket;
  194368. static bool setNonBlocking (int handle)
  194369. {
  194370. int socketFlags = fcntl (handle, F_GETFL, 0);
  194371. if (socketFlags == -1)
  194372. return false;
  194373. socketFlags |= O_NONBLOCK;
  194374. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194375. }
  194376. };
  194377. struct MessageThreadFuncCall
  194378. {
  194379. enum { uniqueID = 0x73774623 };
  194380. MessageCallbackFunction* func;
  194381. void* parameter;
  194382. void* result;
  194383. CriticalSection lock;
  194384. WaitableEvent event;
  194385. };
  194386. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194387. // error handling in X11
  194388. static bool errorOccurred = false;
  194389. static bool keyboardBreakOccurred = false;
  194390. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194391. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194392. // Usually happens when client-server connection is broken
  194393. static int ioErrorHandler (Display* display)
  194394. {
  194395. DBG (T("ERROR: connection to X server broken.. terminating."));
  194396. errorOccurred = true;
  194397. if (JUCEApplication::getInstance() != 0)
  194398. Process::terminate();
  194399. return 0;
  194400. }
  194401. // A protocol error has occurred
  194402. static int errorHandler (Display* display, XErrorEvent* event)
  194403. {
  194404. #ifdef JUCE_DEBUG_XERRORS
  194405. char errorStr[64] = { 0 };
  194406. char requestStr[64] = { 0 };
  194407. XGetErrorText (display, event->error_code, errorStr, 64);
  194408. XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(),
  194409. "Unknown", requestStr, 64);
  194410. DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr));
  194411. #endif
  194412. return 0;
  194413. }
  194414. // Breakin from keyboard
  194415. static void signalHandler (int sig)
  194416. {
  194417. if (sig == SIGINT)
  194418. {
  194419. keyboardBreakOccurred = true;
  194420. return;
  194421. }
  194422. static bool reentrant = false;
  194423. if (! reentrant)
  194424. {
  194425. reentrant = true;
  194426. // Illegal instruction
  194427. fflush (stdout);
  194428. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194429. errorOccurred = true;
  194430. if (JUCEApplication::getInstance() != 0)
  194431. Process::terminate();
  194432. }
  194433. else
  194434. {
  194435. if (JUCEApplication::getInstance() != 0)
  194436. exit(0);
  194437. }
  194438. }
  194439. void MessageManager::doPlatformSpecificInitialisation()
  194440. {
  194441. // Initialise xlib for multiple thread support
  194442. static bool initThreadCalled = false;
  194443. if (! initThreadCalled)
  194444. {
  194445. if (! XInitThreads())
  194446. {
  194447. // This is fatal! Print error and closedown
  194448. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194449. if (JUCEApplication::getInstance() != 0)
  194450. Process::terminate();
  194451. return;
  194452. }
  194453. initThreadCalled = true;
  194454. }
  194455. // This is called if the client/server connection is broken
  194456. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194457. // This is called if a protocol error occurs
  194458. oldErrorHandler = XSetErrorHandler (errorHandler);
  194459. // Install signal handler for break-in
  194460. struct sigaction saction;
  194461. sigset_t maskSet;
  194462. sigemptyset (&maskSet);
  194463. saction.sa_handler = signalHandler;
  194464. saction.sa_mask = maskSet;
  194465. saction.sa_flags = 0;
  194466. sigaction (SIGINT, &saction, NULL);
  194467. #ifndef _DEBUG
  194468. // Setup signal handlers for various fatal errors
  194469. sigaction (SIGILL, &saction, NULL);
  194470. sigaction (SIGBUS, &saction, NULL);
  194471. sigaction (SIGFPE, &saction, NULL);
  194472. sigaction (SIGSEGV, &saction, NULL);
  194473. sigaction (SIGSYS, &saction, NULL);
  194474. #endif
  194475. // Create the internal message queue
  194476. juce_internalMessageQueue = new InternalMessageQueue();
  194477. // Try to connect to a display
  194478. String displayName (getenv ("DISPLAY"));
  194479. if (displayName.isEmpty())
  194480. displayName = ":0.0";
  194481. display = XOpenDisplay (displayName.toCString());
  194482. if (display == 0)
  194483. {
  194484. // This is not fatal! we can run headless.
  194485. return;
  194486. }
  194487. // Get defaults for various properties
  194488. int screen = DefaultScreen (display);
  194489. Window root = RootWindow (display, screen);
  194490. Visual* visual = DefaultVisual (display, screen);
  194491. // Create a context to store user data associated with Windows we
  194492. // create in WindowDriver
  194493. improbableNumber = XUniqueContext();
  194494. // We're only interested in client messages for this window
  194495. // which are always sent
  194496. XSetWindowAttributes swa;
  194497. swa.event_mask = NoEventMask;
  194498. // Create our message window (this will never be mapped)
  194499. juce_messageWindowHandle = XCreateWindow (display, root,
  194500. 0, 0, 1, 1, 0, 0, InputOnly,
  194501. visual, CWEventMask, &swa);
  194502. }
  194503. void MessageManager::doPlatformSpecificShutdown()
  194504. {
  194505. deleteAndZero (juce_internalMessageQueue);
  194506. if (display != 0 && ! errorOccurred)
  194507. {
  194508. XDestroyWindow (display, juce_messageWindowHandle);
  194509. XCloseDisplay (display);
  194510. // reset pointers
  194511. juce_messageWindowHandle = 0;
  194512. display = 0;
  194513. // Restore original error handlers
  194514. XSetIOErrorHandler (oldIOErrorHandler);
  194515. oldIOErrorHandler = 0;
  194516. XSetErrorHandler (oldErrorHandler);
  194517. oldErrorHandler = 0;
  194518. }
  194519. }
  194520. bool juce_postMessageToSystemQueue (void* message)
  194521. {
  194522. if (errorOccurred)
  194523. return false;
  194524. juce_internalMessageQueue->postMessage ((Message*) message);
  194525. return true;
  194526. }
  194527. void MessageManager::broadcastMessage (const String& value) throw()
  194528. {
  194529. }
  194530. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194531. void* parameter)
  194532. {
  194533. if (errorOccurred)
  194534. return 0;
  194535. if (! isThisTheMessageThread())
  194536. {
  194537. MessageThreadFuncCall messageCallContext;
  194538. messageCallContext.func = func;
  194539. messageCallContext.parameter = parameter;
  194540. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194541. 0, 0, &messageCallContext));
  194542. // Wait for it to complete before continuing
  194543. messageCallContext.event.wait();
  194544. return messageCallContext.result;
  194545. }
  194546. else
  194547. {
  194548. // Just call the function directly
  194549. return func (parameter);
  194550. }
  194551. }
  194552. // Wait for an event (either XEvent, or an internal Message)
  194553. static bool juce_sleepUntilEvent (const int timeoutMs)
  194554. {
  194555. if (! juce_internalMessageQueue->isEmpty())
  194556. return true;
  194557. if (display != 0)
  194558. {
  194559. ScopedXLock xlock;
  194560. if (XPending (display))
  194561. return true;
  194562. }
  194563. struct timeval tv;
  194564. tv.tv_sec = 0;
  194565. tv.tv_usec = timeoutMs * 1000;
  194566. int fd0 = juce_internalMessageQueue->getWaitHandle();
  194567. int fdmax = fd0;
  194568. fd_set readset;
  194569. FD_ZERO (&readset);
  194570. FD_SET (fd0, &readset);
  194571. if (display != 0)
  194572. {
  194573. ScopedXLock xlock;
  194574. int fd1 = XConnectionNumber (display);
  194575. FD_SET (fd1, &readset);
  194576. fdmax = jmax (fd0, fd1);
  194577. }
  194578. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  194579. return (ret > 0); // ret <= 0 if error or timeout
  194580. }
  194581. // Handle next XEvent (if any)
  194582. static bool juce_dispatchNextXEvent()
  194583. {
  194584. if (display == 0)
  194585. return false;
  194586. XEvent evt;
  194587. {
  194588. ScopedXLock xlock;
  194589. if (! XPending (display))
  194590. return false;
  194591. XNextEvent (display, &evt);
  194592. }
  194593. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  194594. {
  194595. juce_handleSelectionRequest (evt.xselectionrequest);
  194596. }
  194597. else if (evt.xany.window != juce_messageWindowHandle)
  194598. {
  194599. juce_windowMessageReceive (&evt);
  194600. }
  194601. return true;
  194602. }
  194603. // Handle next internal Message (if any)
  194604. static bool juce_dispatchNextInternalMessage()
  194605. {
  194606. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  194607. if (msg == 0)
  194608. return false;
  194609. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  194610. {
  194611. // Handle callback message
  194612. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  194613. call->result = (*(call->func)) (call->parameter);
  194614. call->event.signal();
  194615. }
  194616. else
  194617. {
  194618. // Handle "normal" messages
  194619. MessageManager::getInstance()->deliverMessage (msg.release());
  194620. }
  194621. return true;
  194622. }
  194623. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  194624. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  194625. {
  194626. for (;;)
  194627. {
  194628. if (errorOccurred)
  194629. break;
  194630. if (keyboardBreakOccurred)
  194631. {
  194632. errorOccurred = true;
  194633. if (JUCEApplication::getInstance() != 0)
  194634. Process::terminate();
  194635. break;
  194636. }
  194637. static int totalEventCount = 0;
  194638. ++totalEventCount;
  194639. // The purpose here is to give either priority to XEvents or
  194640. // to internal messages This is necessary to keep a "good"
  194641. // behaviour when the cpu is overloaded
  194642. if (totalEventCount & 1)
  194643. {
  194644. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  194645. return true;
  194646. }
  194647. else
  194648. {
  194649. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  194650. return true;
  194651. }
  194652. if (returnIfNoPendingMessages) // early exit
  194653. break;
  194654. // the timeout is to be on the safe side, but it does not seem to be useful
  194655. juce_sleepUntilEvent (2000);
  194656. }
  194657. return false;
  194658. }
  194659. #endif
  194660. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  194661. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  194662. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194663. // compiled on its own).
  194664. #if JUCE_INCLUDED_FILE
  194665. class FreeTypeFontFace
  194666. {
  194667. public:
  194668. enum FontStyle
  194669. {
  194670. Plain = 0,
  194671. Bold = 1,
  194672. Italic = 2
  194673. };
  194674. struct FontNameIndex
  194675. {
  194676. String fileName;
  194677. int faceIndex;
  194678. };
  194679. FreeTypeFontFace (const String& familyName) throw()
  194680. : hasSerif (false),
  194681. monospaced (false)
  194682. {
  194683. family = familyName;
  194684. }
  194685. void setFileName (const String& name, const int faceIndex, FontStyle style) throw()
  194686. {
  194687. if (names [(int) style].fileName.isEmpty())
  194688. {
  194689. names [(int) style].fileName = name;
  194690. names [(int) style].faceIndex = faceIndex;
  194691. }
  194692. }
  194693. const String& getFamilyName() const throw() { return family; }
  194694. const String& getFileName (const int style, int& faceIndex) const throw()
  194695. {
  194696. faceIndex = names[style].faceIndex;
  194697. return names[style].fileName;
  194698. }
  194699. void setMonospaced (bool mono) throw() { monospaced = mono; }
  194700. bool getMonospaced() const throw() { return monospaced; }
  194701. void setSerif (const bool serif) throw() { hasSerif = serif; }
  194702. bool getSerif() const throw() { return hasSerif; }
  194703. private:
  194704. String family;
  194705. FontNameIndex names[4];
  194706. bool hasSerif, monospaced;
  194707. };
  194708. class FreeTypeInterface : public DeletedAtShutdown
  194709. {
  194710. public:
  194711. FreeTypeInterface() throw()
  194712. : lastFace (0),
  194713. lastBold (false),
  194714. lastItalic (false)
  194715. {
  194716. if (FT_Init_FreeType (&ftLib) != 0)
  194717. {
  194718. ftLib = 0;
  194719. DBG (T("Failed to initialize FreeType"));
  194720. }
  194721. StringArray fontDirs;
  194722. fontDirs.addTokens (String::fromUTF8 (getenv ("JUCE_FONT_PATH")), ";,", String::empty);
  194723. fontDirs.removeEmptyStrings (true);
  194724. if (fontDirs.size() == 0)
  194725. {
  194726. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  194727. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  194728. if (fontsInfo != 0)
  194729. {
  194730. forEachXmlChildElementWithTagName (*fontsInfo, e, T("dir"))
  194731. {
  194732. fontDirs.add (e->getAllSubText().trim());
  194733. }
  194734. delete fontsInfo;
  194735. }
  194736. }
  194737. if (fontDirs.size() == 0)
  194738. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  194739. for (int i = 0; i < fontDirs.size(); ++i)
  194740. enumerateFaces (fontDirs[i]);
  194741. }
  194742. ~FreeTypeInterface() throw()
  194743. {
  194744. if (lastFace != 0)
  194745. FT_Done_Face (lastFace);
  194746. if (ftLib != 0)
  194747. FT_Done_FreeType (ftLib);
  194748. clearSingletonInstance();
  194749. }
  194750. FreeTypeFontFace* findOrCreate (const String& familyName,
  194751. const bool create = false) throw()
  194752. {
  194753. for (int i = 0; i < faces.size(); i++)
  194754. if (faces[i]->getFamilyName() == familyName)
  194755. return faces[i];
  194756. if (! create)
  194757. return NULL;
  194758. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  194759. faces.add (newFace);
  194760. return newFace;
  194761. }
  194762. // Enumerate all font faces available in a given directory
  194763. void enumerateFaces (const String& path) throw()
  194764. {
  194765. File dirPath (path);
  194766. if (path.isEmpty() || ! dirPath.isDirectory())
  194767. return;
  194768. DirectoryIterator di (dirPath, true);
  194769. while (di.next())
  194770. {
  194771. File possible (di.getFile());
  194772. if (possible.hasFileExtension (T("ttf"))
  194773. || possible.hasFileExtension (T("pfb"))
  194774. || possible.hasFileExtension (T("pcf")))
  194775. {
  194776. FT_Face face;
  194777. int faceIndex = 0;
  194778. int numFaces = 0;
  194779. do
  194780. {
  194781. if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(),
  194782. faceIndex, &face) == 0)
  194783. {
  194784. if (faceIndex == 0)
  194785. numFaces = face->num_faces;
  194786. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  194787. {
  194788. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  194789. int style = (int) FreeTypeFontFace::Plain;
  194790. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  194791. style |= (int) FreeTypeFontFace::Bold;
  194792. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  194793. style |= (int) FreeTypeFontFace::Italic;
  194794. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  194795. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  194796. // Surely there must be a better way to do this?
  194797. const String name (face->family_name);
  194798. newFace->setSerif (! (name.containsIgnoreCase (T("Sans"))
  194799. || name.containsIgnoreCase (T("Verdana"))
  194800. || name.containsIgnoreCase (T("Arial"))));
  194801. }
  194802. FT_Done_Face (face);
  194803. }
  194804. ++faceIndex;
  194805. }
  194806. while (faceIndex < numFaces);
  194807. }
  194808. }
  194809. }
  194810. // Create a FreeType face object for a given font
  194811. FT_Face createFT_Face (const String& fontName,
  194812. const bool bold,
  194813. const bool italic) throw()
  194814. {
  194815. FT_Face face = 0;
  194816. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  194817. {
  194818. face = lastFace;
  194819. }
  194820. else
  194821. {
  194822. if (lastFace != 0)
  194823. {
  194824. FT_Done_Face (lastFace);
  194825. lastFace = 0;
  194826. }
  194827. lastFontName = fontName;
  194828. lastBold = bold;
  194829. lastItalic = italic;
  194830. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  194831. if (ftFace != 0)
  194832. {
  194833. int style = (int) FreeTypeFontFace::Plain;
  194834. if (bold)
  194835. style |= (int) FreeTypeFontFace::Bold;
  194836. if (italic)
  194837. style |= (int) FreeTypeFontFace::Italic;
  194838. int faceIndex;
  194839. String fileName (ftFace->getFileName (style, faceIndex));
  194840. if (fileName.isEmpty())
  194841. {
  194842. style ^= (int) FreeTypeFontFace::Bold;
  194843. fileName = ftFace->getFileName (style, faceIndex);
  194844. if (fileName.isEmpty())
  194845. {
  194846. style ^= (int) FreeTypeFontFace::Bold;
  194847. style ^= (int) FreeTypeFontFace::Italic;
  194848. fileName = ftFace->getFileName (style, faceIndex);
  194849. if (! fileName.length())
  194850. {
  194851. style ^= (int) FreeTypeFontFace::Bold;
  194852. fileName = ftFace->getFileName (style, faceIndex);
  194853. }
  194854. }
  194855. }
  194856. if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace))
  194857. {
  194858. face = lastFace;
  194859. // If there isn't a unicode charmap then select the first one.
  194860. if (FT_Select_Charmap (face, ft_encoding_unicode))
  194861. FT_Set_Charmap (face, face->charmaps[0]);
  194862. }
  194863. }
  194864. }
  194865. return face;
  194866. }
  194867. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character) throw()
  194868. {
  194869. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  194870. const float height = (float) (face->ascender - face->descender);
  194871. const float scaleX = 1.0f / height;
  194872. const float scaleY = -1.0f / height;
  194873. Path destShape;
  194874. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  194875. || face->glyph->format != ft_glyph_format_outline)
  194876. {
  194877. return false;
  194878. }
  194879. const FT_Outline* const outline = &face->glyph->outline;
  194880. const short* const contours = outline->contours;
  194881. const char* const tags = outline->tags;
  194882. FT_Vector* const points = outline->points;
  194883. for (int c = 0; c < outline->n_contours; c++)
  194884. {
  194885. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  194886. const int endPoint = contours[c];
  194887. for (int p = startPoint; p <= endPoint; p++)
  194888. {
  194889. const float x = scaleX * points[p].x;
  194890. const float y = scaleY * points[p].y;
  194891. if (p == startPoint)
  194892. {
  194893. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194894. {
  194895. float x2 = scaleX * points [endPoint].x;
  194896. float y2 = scaleY * points [endPoint].y;
  194897. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  194898. {
  194899. x2 = (x + x2) * 0.5f;
  194900. y2 = (y + y2) * 0.5f;
  194901. }
  194902. destShape.startNewSubPath (x2, y2);
  194903. }
  194904. else
  194905. {
  194906. destShape.startNewSubPath (x, y);
  194907. }
  194908. }
  194909. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  194910. {
  194911. if (p != startPoint)
  194912. destShape.lineTo (x, y);
  194913. }
  194914. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194915. {
  194916. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  194917. float x2 = scaleX * points [nextIndex].x;
  194918. float y2 = scaleY * points [nextIndex].y;
  194919. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  194920. {
  194921. x2 = (x + x2) * 0.5f;
  194922. y2 = (y + y2) * 0.5f;
  194923. }
  194924. else
  194925. {
  194926. ++p;
  194927. }
  194928. destShape.quadraticTo (x, y, x2, y2);
  194929. }
  194930. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  194931. {
  194932. if (p >= endPoint)
  194933. return false;
  194934. const int next1 = p + 1;
  194935. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  194936. const float x2 = scaleX * points [next1].x;
  194937. const float y2 = scaleY * points [next1].y;
  194938. const float x3 = scaleX * points [next2].x;
  194939. const float y3 = scaleY * points [next2].y;
  194940. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  194941. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  194942. return false;
  194943. destShape.cubicTo (x, y, x2, y2, x3, y3);
  194944. p += 2;
  194945. }
  194946. }
  194947. destShape.closeSubPath();
  194948. }
  194949. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  194950. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  194951. addKerning (face, dest, character, glyphIndex);
  194952. return true;
  194953. }
  194954. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex) throw()
  194955. {
  194956. const float height = (float) (face->ascender - face->descender);
  194957. uint32 rightGlyphIndex;
  194958. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  194959. while (rightGlyphIndex != 0)
  194960. {
  194961. FT_Vector kerning;
  194962. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  194963. {
  194964. if (kerning.x != 0)
  194965. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  194966. }
  194967. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  194968. }
  194969. }
  194970. // Add a glyph to a font
  194971. bool addGlyphToFont (const uint32 character,
  194972. const tchar* fontName, bool bold, bool italic,
  194973. CustomTypeface& dest) throw()
  194974. {
  194975. FT_Face face = createFT_Face (fontName, bold, italic);
  194976. if (face != 0)
  194977. return addGlyph (face, dest, character);
  194978. return false;
  194979. }
  194980. void getFamilyNames (StringArray& familyNames) const throw()
  194981. {
  194982. for (int i = 0; i < faces.size(); i++)
  194983. familyNames.add (faces[i]->getFamilyName());
  194984. }
  194985. void getMonospacedNames (StringArray& monoSpaced) const throw()
  194986. {
  194987. for (int i = 0; i < faces.size(); i++)
  194988. if (faces[i]->getMonospaced())
  194989. monoSpaced.add (faces[i]->getFamilyName());
  194990. }
  194991. void getSerifNames (StringArray& serif) const throw()
  194992. {
  194993. for (int i = 0; i < faces.size(); i++)
  194994. if (faces[i]->getSerif())
  194995. serif.add (faces[i]->getFamilyName());
  194996. }
  194997. void getSansSerifNames (StringArray& sansSerif) const throw()
  194998. {
  194999. for (int i = 0; i < faces.size(); i++)
  195000. if (! faces[i]->getSerif())
  195001. sansSerif.add (faces[i]->getFamilyName());
  195002. }
  195003. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  195004. private:
  195005. FT_Library ftLib;
  195006. FT_Face lastFace;
  195007. String lastFontName;
  195008. bool lastBold, lastItalic;
  195009. OwnedArray<FreeTypeFontFace> faces;
  195010. };
  195011. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  195012. class FreetypeTypeface : public CustomTypeface
  195013. {
  195014. public:
  195015. FreetypeTypeface (const Font& font)
  195016. {
  195017. FT_Face face = FreeTypeInterface::getInstance()
  195018. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  195019. if (face == 0)
  195020. {
  195021. #ifdef JUCE_DEBUG
  195022. String msg (T("Failed to create typeface: "));
  195023. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  195024. DBG (msg);
  195025. #endif
  195026. }
  195027. else
  195028. {
  195029. setCharacteristics (font.getTypefaceName(),
  195030. face->ascender / (float) (face->ascender - face->descender),
  195031. font.isBold(), font.isItalic(),
  195032. L' ');
  195033. }
  195034. }
  195035. bool loadGlyphIfPossible (const juce_wchar character)
  195036. {
  195037. return FreeTypeInterface::getInstance()
  195038. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  195039. }
  195040. };
  195041. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  195042. {
  195043. return new FreetypeTypeface (font);
  195044. }
  195045. const StringArray Font::findAllTypefaceNames() throw()
  195046. {
  195047. StringArray s;
  195048. FreeTypeInterface::getInstance()->getFamilyNames (s);
  195049. s.sort (true);
  195050. return s;
  195051. }
  195052. static const String pickBestFont (const StringArray& names,
  195053. const char* const choicesString)
  195054. {
  195055. StringArray choices;
  195056. choices.addTokens (String (choicesString), ",", String::empty);
  195057. choices.trim();
  195058. choices.removeEmptyStrings();
  195059. int i, j;
  195060. for (j = 0; j < choices.size(); ++j)
  195061. if (names.contains (choices[j], true))
  195062. return choices[j];
  195063. for (j = 0; j < choices.size(); ++j)
  195064. for (i = 0; i < names.size(); i++)
  195065. if (names[i].startsWithIgnoreCase (choices[j]))
  195066. return names[i];
  195067. for (j = 0; j < choices.size(); ++j)
  195068. for (i = 0; i < names.size(); i++)
  195069. if (names[i].containsIgnoreCase (choices[j]))
  195070. return names[i];
  195071. return names[0];
  195072. }
  195073. static const String linux_getDefaultSansSerifFontName()
  195074. {
  195075. StringArray allFonts;
  195076. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195077. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195078. }
  195079. static const String linux_getDefaultSerifFontName()
  195080. {
  195081. StringArray allFonts;
  195082. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195083. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195084. }
  195085. static const String linux_getDefaultMonospacedFontName()
  195086. {
  195087. StringArray allFonts;
  195088. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195089. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195090. }
  195091. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  195092. {
  195093. defaultSans = linux_getDefaultSansSerifFontName();
  195094. defaultSerif = linux_getDefaultSerifFontName();
  195095. defaultFixed = linux_getDefaultMonospacedFontName();
  195096. }
  195097. #endif
  195098. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  195099. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  195100. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195101. // compiled on its own).
  195102. #if JUCE_INCLUDED_FILE
  195103. namespace Atoms
  195104. {
  195105. enum ProtocolItems
  195106. {
  195107. TAKE_FOCUS = 0,
  195108. DELETE_WINDOW = 1
  195109. };
  195110. static Atom Protocols, ProtocolList[2], ChangeState, State,
  195111. ActiveWin, Pid, WindowType, WindowState,
  195112. XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus,
  195113. XdndDrop, XdndFinished, XdndSelection, XdndTypeList, XdndActionList,
  195114. XdndActionDescription, XdndActionCopy,
  195115. allowedActions[5],
  195116. allowedMimeTypes[2];
  195117. const unsigned long DndVersion = 3;
  195118. static void initialiseAtoms()
  195119. {
  195120. static bool atomsInitialised = false;
  195121. if (! atomsInitialised)
  195122. {
  195123. atomsInitialised = true;
  195124. Protocols = XInternAtom (display, "WM_PROTOCOLS", True);
  195125. ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", True);
  195126. ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", True);
  195127. ChangeState = XInternAtom (display, "WM_CHANGE_STATE", True);
  195128. State = XInternAtom (display, "WM_STATE", True);
  195129. ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  195130. Pid = XInternAtom (display, "_NET_WM_PID", False);
  195131. WindowType = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  195132. WindowState = XInternAtom (display, "_NET_WM_WINDOW_STATE", True);
  195133. XdndAware = XInternAtom (display, "XdndAware", False);
  195134. XdndEnter = XInternAtom (display, "XdndEnter", False);
  195135. XdndLeave = XInternAtom (display, "XdndLeave", False);
  195136. XdndPosition = XInternAtom (display, "XdndPosition", False);
  195137. XdndStatus = XInternAtom (display, "XdndStatus", False);
  195138. XdndDrop = XInternAtom (display, "XdndDrop", False);
  195139. XdndFinished = XInternAtom (display, "XdndFinished", False);
  195140. XdndSelection = XInternAtom (display, "XdndSelection", False);
  195141. XdndTypeList = XInternAtom (display, "XdndTypeList", False);
  195142. XdndActionList = XInternAtom (display, "XdndActionList", False);
  195143. XdndActionCopy = XInternAtom (display, "XdndActionCopy", False);
  195144. XdndActionDescription = XInternAtom (display, "XdndActionDescription", False);
  195145. allowedMimeTypes [0] = XInternAtom (display, "text/plain", False);
  195146. allowedMimeTypes [1] = XInternAtom (display, "text/uri-list", False);
  195147. allowedActions [0] = XInternAtom (display, "XdndActionMove", False);
  195148. allowedActions [1] = XdndActionCopy;
  195149. allowedActions [2] = XInternAtom (display, "XdndActionLink", False);
  195150. allowedActions [3] = XInternAtom (display, "XdndActionAsk", False);
  195151. allowedActions [4] = XInternAtom (display, "XdndActionPrivate", False);
  195152. }
  195153. }
  195154. }
  195155. enum SystemTrayValues
  195156. {
  195157. SYSTEM_TRAY_REQUEST_DOCK = 0,
  195158. SYSTEM_TRAY_BEGIN_MESSAGE = 1,
  195159. SYSTEM_TRAY_CANCEL_MESSAGE = 2
  195160. };
  195161. static XErrorHandler oldHandler = 0;
  195162. static int trappedErrorCode = 0;
  195163. extern "C" int errorTrapHandler (Display* dpy, XErrorEvent* err)
  195164. {
  195165. trappedErrorCode = err->error_code;
  195166. return 0;
  195167. }
  195168. static void trapErrors()
  195169. {
  195170. trappedErrorCode = 0;
  195171. oldHandler = XSetErrorHandler (errorTrapHandler);
  195172. }
  195173. static bool untrapErrors()
  195174. {
  195175. XSetErrorHandler (oldHandler);
  195176. return (trappedErrorCode == 0);
  195177. }
  195178. static bool isActiveApplication = false;
  195179. bool Process::isForegroundProcess()
  195180. {
  195181. return isActiveApplication;
  195182. }
  195183. // These are defined in juce_linux_Messaging.cpp
  195184. extern Display* display;
  195185. extern XContext improbableNumber;
  195186. static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  195187. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  195188. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  195189. namespace Keys
  195190. {
  195191. enum MouseButtons
  195192. {
  195193. NoButton = 0,
  195194. LeftButton = 1,
  195195. MiddleButton = 2,
  195196. RightButton = 3,
  195197. WheelUp = 4,
  195198. WheelDown = 5
  195199. };
  195200. static int AltMask = 0;
  195201. static int NumLockMask = 0;
  195202. static bool numLock = false;
  195203. static bool capsLock = false;
  195204. static char keyStates [32];
  195205. static const int extendedKeyModifier = 0x10000000;
  195206. }
  195207. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195208. {
  195209. int keysym;
  195210. if (keyCode & Keys::extendedKeyModifier)
  195211. {
  195212. keysym = 0xff00 | (keyCode & 0xff);
  195213. }
  195214. else
  195215. {
  195216. keysym = keyCode;
  195217. if (keysym == (XK_Tab & 0xff)
  195218. || keysym == (XK_Return & 0xff)
  195219. || keysym == (XK_Escape & 0xff)
  195220. || keysym == (XK_BackSpace & 0xff))
  195221. {
  195222. keysym |= 0xff00;
  195223. }
  195224. }
  195225. ScopedXLock xlock;
  195226. const int keycode = XKeysymToKeycode (display, keysym);
  195227. const int keybyte = keycode >> 3;
  195228. const int keybit = (1 << (keycode & 7));
  195229. return (Keys::keyStates [keybyte] & keybit) != 0;
  195230. }
  195231. #if JUCE_USE_XSHM
  195232. static bool isShmAvailable() throw()
  195233. {
  195234. static bool isChecked = false;
  195235. static bool isAvailable = false;
  195236. if (! isChecked)
  195237. {
  195238. isChecked = true;
  195239. int major, minor;
  195240. Bool pixmaps;
  195241. ScopedXLock xlock;
  195242. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195243. {
  195244. trapErrors();
  195245. XShmSegmentInfo segmentInfo;
  195246. zerostruct (segmentInfo);
  195247. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195248. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195249. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195250. xImage->bytes_per_line * xImage->height,
  195251. IPC_CREAT | 0777)) >= 0)
  195252. {
  195253. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195254. if (segmentInfo.shmaddr != (void*) -1)
  195255. {
  195256. segmentInfo.readOnly = False;
  195257. xImage->data = segmentInfo.shmaddr;
  195258. XSync (display, False);
  195259. if (XShmAttach (display, &segmentInfo) != 0)
  195260. {
  195261. XSync (display, False);
  195262. XShmDetach (display, &segmentInfo);
  195263. isAvailable = true;
  195264. }
  195265. }
  195266. XFlush (display);
  195267. XDestroyImage (xImage);
  195268. shmdt (segmentInfo.shmaddr);
  195269. }
  195270. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195271. isAvailable &= untrapErrors();
  195272. }
  195273. }
  195274. return isAvailable;
  195275. }
  195276. #endif
  195277. #if JUCE_USE_XRENDER
  195278. namespace XRender
  195279. {
  195280. typedef Status (*tXRenderQueryVersion) (Display*, int*, int*);
  195281. typedef XRenderPictFormat* (*tXrenderFindStandardFormat) (Display*, int);
  195282. typedef XRenderPictFormat* (*tXRenderFindFormat) (Display*, unsigned long, XRenderPictFormat*, int);
  195283. typedef XRenderPictFormat* (*tXRenderFindVisualFormat) (Display*, Visual*);
  195284. static tXRenderQueryVersion xRenderQueryVersion = 0;
  195285. static tXrenderFindStandardFormat xRenderFindStandardFormat = 0;
  195286. static tXRenderFindFormat xRenderFindFormat = 0;
  195287. static tXRenderFindVisualFormat xRenderFindVisualFormat = 0;
  195288. static bool isAvailable()
  195289. {
  195290. static bool isChecked = false;
  195291. static bool isAvailable = false;
  195292. if (! isChecked)
  195293. {
  195294. ScopedXLock xlock;
  195295. isChecked = true;
  195296. if (xRenderQueryVersion == 0)
  195297. {
  195298. void* h = dlopen ("libXrender.so", RTLD_GLOBAL | RTLD_NOW);
  195299. if (h != 0)
  195300. {
  195301. xRenderQueryVersion = (tXRenderQueryVersion) dlsym (h, "XRenderQueryVersion");
  195302. xRenderFindStandardFormat = (tXrenderFindStandardFormat) dlsym (h, "XrenderFindStandardFormat");
  195303. xRenderFindFormat = (tXRenderFindFormat) dlsym (h, "XRenderFindFormat");
  195304. xRenderFindVisualFormat = (tXRenderFindVisualFormat) dlsym (h, "XRenderFindVisualFormat");
  195305. }
  195306. }
  195307. if (xRenderQueryVersion != 0
  195308. && xRenderFindStandardFormat != 0
  195309. && xRenderFindFormat != 0
  195310. && xRenderFindVisualFormat != 0)
  195311. {
  195312. int major, minor;
  195313. if (xRenderQueryVersion (display, &major, &minor))
  195314. isAvailable = true;
  195315. }
  195316. }
  195317. return isAvailable;
  195318. }
  195319. static XRenderPictFormat* findPictureFormat()
  195320. {
  195321. ScopedXLock xlock;
  195322. XRenderPictFormat* pictFormat = 0;
  195323. if (isAvailable())
  195324. {
  195325. pictFormat = xRenderFindStandardFormat (display, PictStandardARGB32);
  195326. if (pictFormat == 0)
  195327. {
  195328. XRenderPictFormat desiredFormat;
  195329. desiredFormat.type = PictTypeDirect;
  195330. desiredFormat.depth = 32;
  195331. desiredFormat.direct.alphaMask = 0xff;
  195332. desiredFormat.direct.redMask = 0xff;
  195333. desiredFormat.direct.greenMask = 0xff;
  195334. desiredFormat.direct.blueMask = 0xff;
  195335. desiredFormat.direct.alpha = 24;
  195336. desiredFormat.direct.red = 16;
  195337. desiredFormat.direct.green = 8;
  195338. desiredFormat.direct.blue = 0;
  195339. pictFormat = xRenderFindFormat (display,
  195340. PictFormatType | PictFormatDepth
  195341. | PictFormatRedMask | PictFormatRed
  195342. | PictFormatGreenMask | PictFormatGreen
  195343. | PictFormatBlueMask | PictFormatBlue
  195344. | PictFormatAlphaMask | PictFormatAlpha,
  195345. &desiredFormat,
  195346. 0);
  195347. }
  195348. }
  195349. return pictFormat;
  195350. }
  195351. }
  195352. #endif
  195353. namespace Visuals
  195354. {
  195355. static Visual* findVisualWithDepth (const int desiredDepth) throw()
  195356. {
  195357. ScopedXLock xlock;
  195358. Visual* visual = 0;
  195359. int numVisuals = 0;
  195360. long desiredMask = VisualNoMask;
  195361. XVisualInfo desiredVisual;
  195362. desiredVisual.screen = DefaultScreen (display);
  195363. desiredVisual.depth = desiredDepth;
  195364. desiredMask = VisualScreenMask | VisualDepthMask;
  195365. if (desiredDepth == 32)
  195366. {
  195367. desiredVisual.c_class = TrueColor;
  195368. desiredVisual.red_mask = 0x00FF0000;
  195369. desiredVisual.green_mask = 0x0000FF00;
  195370. desiredVisual.blue_mask = 0x000000FF;
  195371. desiredVisual.bits_per_rgb = 8;
  195372. desiredMask |= VisualClassMask;
  195373. desiredMask |= VisualRedMaskMask;
  195374. desiredMask |= VisualGreenMaskMask;
  195375. desiredMask |= VisualBlueMaskMask;
  195376. desiredMask |= VisualBitsPerRGBMask;
  195377. }
  195378. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195379. desiredMask,
  195380. &desiredVisual,
  195381. &numVisuals);
  195382. if (xvinfos != 0)
  195383. {
  195384. for (int i = 0; i < numVisuals; i++)
  195385. {
  195386. if (xvinfos[i].depth == desiredDepth)
  195387. {
  195388. visual = xvinfos[i].visual;
  195389. break;
  195390. }
  195391. }
  195392. XFree (xvinfos);
  195393. }
  195394. return visual;
  195395. }
  195396. static Visual* findVisualFormat (const int desiredDepth, int& matchedDepth) throw()
  195397. {
  195398. Visual* visual = 0;
  195399. if (desiredDepth == 32)
  195400. {
  195401. #if JUCE_USE_XSHM
  195402. if (isShmAvailable())
  195403. {
  195404. #if JUCE_USE_XRENDER
  195405. if (XRender::isAvailable())
  195406. {
  195407. XRenderPictFormat* pictFormat = XRender::findPictureFormat();
  195408. if (pictFormat != 0)
  195409. {
  195410. int numVisuals = 0;
  195411. XVisualInfo desiredVisual;
  195412. desiredVisual.screen = DefaultScreen (display);
  195413. desiredVisual.depth = 32;
  195414. desiredVisual.bits_per_rgb = 8;
  195415. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195416. VisualScreenMask | VisualDepthMask | VisualBitsPerRGBMask,
  195417. &desiredVisual, &numVisuals);
  195418. if (xvinfos != 0)
  195419. {
  195420. for (int i = 0; i < numVisuals; ++i)
  195421. {
  195422. XRenderPictFormat* pictVisualFormat = XRender::xRenderFindVisualFormat (display, xvinfos[i].visual);
  195423. if (pictVisualFormat != 0
  195424. && pictVisualFormat->type == PictTypeDirect
  195425. && pictVisualFormat->direct.alphaMask)
  195426. {
  195427. visual = xvinfos[i].visual;
  195428. matchedDepth = 32;
  195429. break;
  195430. }
  195431. }
  195432. XFree (xvinfos);
  195433. }
  195434. }
  195435. }
  195436. #endif
  195437. if (visual == 0)
  195438. {
  195439. visual = findVisualWithDepth (32);
  195440. if (visual != 0)
  195441. matchedDepth = 32;
  195442. }
  195443. }
  195444. #endif
  195445. }
  195446. if (visual == 0 && desiredDepth >= 24)
  195447. {
  195448. visual = findVisualWithDepth (24);
  195449. if (visual != 0)
  195450. matchedDepth = 24;
  195451. }
  195452. if (visual == 0 && desiredDepth >= 16)
  195453. {
  195454. visual = findVisualWithDepth (16);
  195455. if (visual != 0)
  195456. matchedDepth = 16;
  195457. }
  195458. return visual;
  195459. }
  195460. }
  195461. class XBitmapImage : public Image
  195462. {
  195463. public:
  195464. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195465. const bool clearImage, const int imageDepth_, Visual* visual)
  195466. : Image (format_, w, h),
  195467. imageDepth (imageDepth_),
  195468. gc (None)
  195469. {
  195470. jassert (format_ == RGB || format_ == ARGB);
  195471. pixelStride = (format_ == RGB) ? 3 : 4;
  195472. lineStride = ((w * pixelStride + 3) & ~3);
  195473. ScopedXLock xlock;
  195474. #if JUCE_USE_XSHM
  195475. usingXShm = false;
  195476. if ((imageDepth > 16) && isShmAvailable())
  195477. {
  195478. zerostruct (segmentInfo);
  195479. segmentInfo.shmid = -1;
  195480. segmentInfo.shmaddr = (char *) -1;
  195481. segmentInfo.readOnly = False;
  195482. xImage = XShmCreateImage (display, visual, imageDepth, ZPixmap, 0, &segmentInfo, w, h);
  195483. if (xImage != 0)
  195484. {
  195485. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195486. xImage->bytes_per_line * xImage->height,
  195487. IPC_CREAT | 0777)) >= 0)
  195488. {
  195489. if (segmentInfo.shmid != -1)
  195490. {
  195491. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195492. if (segmentInfo.shmaddr != (void*) -1)
  195493. {
  195494. segmentInfo.readOnly = False;
  195495. xImage->data = segmentInfo.shmaddr;
  195496. imageData = (uint8*) segmentInfo.shmaddr;
  195497. if (XShmAttach (display, &segmentInfo) != 0)
  195498. {
  195499. usingXShm = true;
  195500. }
  195501. else
  195502. {
  195503. jassertfalse
  195504. }
  195505. }
  195506. else
  195507. {
  195508. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195509. }
  195510. }
  195511. }
  195512. }
  195513. }
  195514. if (! usingXShm)
  195515. #endif
  195516. {
  195517. imageDataAllocated.malloc (lineStride * h);
  195518. imageData = imageDataAllocated;
  195519. if (format_ == ARGB && clearImage)
  195520. zeromem (imageData, h * lineStride);
  195521. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195522. xImage->width = w;
  195523. xImage->height = h;
  195524. xImage->xoffset = 0;
  195525. xImage->format = ZPixmap;
  195526. xImage->data = (char*) imageData;
  195527. xImage->byte_order = ImageByteOrder (display);
  195528. xImage->bitmap_unit = BitmapUnit (display);
  195529. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195530. xImage->bitmap_pad = 32;
  195531. xImage->depth = pixelStride * 8;
  195532. xImage->bytes_per_line = lineStride;
  195533. xImage->bits_per_pixel = pixelStride * 8;
  195534. xImage->red_mask = 0x00FF0000;
  195535. xImage->green_mask = 0x0000FF00;
  195536. xImage->blue_mask = 0x000000FF;
  195537. if (imageDepth == 16)
  195538. {
  195539. const int pixelStride = 2;
  195540. const int lineStride = ((w * pixelStride + 3) & ~3);
  195541. imageData16Bit.malloc (lineStride * h);
  195542. xImage->data = imageData16Bit;
  195543. xImage->bitmap_pad = 16;
  195544. xImage->depth = pixelStride * 8;
  195545. xImage->bytes_per_line = lineStride;
  195546. xImage->bits_per_pixel = pixelStride * 8;
  195547. xImage->red_mask = visual->red_mask;
  195548. xImage->green_mask = visual->green_mask;
  195549. xImage->blue_mask = visual->blue_mask;
  195550. }
  195551. if (! XInitImage (xImage))
  195552. {
  195553. jassertfalse
  195554. }
  195555. }
  195556. }
  195557. ~XBitmapImage()
  195558. {
  195559. ScopedXLock xlock;
  195560. #if JUCE_USE_XSHM
  195561. if (usingXShm)
  195562. {
  195563. XShmDetach (display, &segmentInfo);
  195564. XFlush (display);
  195565. XDestroyImage (xImage);
  195566. shmdt (segmentInfo.shmaddr);
  195567. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195568. }
  195569. else
  195570. #endif
  195571. {
  195572. xImage->data = 0;
  195573. XDestroyImage (xImage);
  195574. }
  195575. }
  195576. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195577. {
  195578. ScopedXLock xlock;
  195579. if (gc == 0)
  195580. {
  195581. XGCValues gcvalues;
  195582. gcvalues.foreground = None;
  195583. gcvalues.background = None;
  195584. gcvalues.function = GXcopy;
  195585. gcvalues.plane_mask = AllPlanes;
  195586. gcvalues.clip_mask = None;
  195587. gcvalues.graphics_exposures = False;
  195588. gc = XCreateGC (display, window,
  195589. GCBackground | GCForeground | GCFunction | GCPlaneMask | GCClipMask | GCGraphicsExposures,
  195590. &gcvalues);
  195591. }
  195592. if (imageDepth == 16)
  195593. {
  195594. const uint32 rMask = xImage->red_mask;
  195595. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195596. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195597. const uint32 gMask = xImage->green_mask;
  195598. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195599. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195600. const uint32 bMask = xImage->blue_mask;
  195601. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  195602. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  195603. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  195604. for (int y = sy; y < sy + dh; ++y)
  195605. {
  195606. const uint8* p = srcData.getPixelPointer (sx, y);
  195607. for (int x = sx; x < sx + dw; ++x)
  195608. {
  195609. const PixelRGB* const pixel = (const PixelRGB*) p;
  195610. p += srcData.pixelStride;
  195611. XPutPixel (xImage, x, y,
  195612. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  195613. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  195614. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  195615. }
  195616. }
  195617. }
  195618. // blit results to screen.
  195619. #if JUCE_USE_XSHM
  195620. if (usingXShm)
  195621. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  195622. else
  195623. #endif
  195624. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  195625. }
  195626. juce_UseDebuggingNewOperator
  195627. private:
  195628. XImage* xImage;
  195629. const int imageDepth;
  195630. HeapBlock <char> imageData16Bit;
  195631. GC gc;
  195632. #if JUCE_USE_XSHM
  195633. XShmSegmentInfo segmentInfo;
  195634. bool usingXShm;
  195635. #endif
  195636. static int getShiftNeeded (const uint32 mask) throw()
  195637. {
  195638. for (int i = 32; --i >= 0;)
  195639. if (((mask >> i) & 1) != 0)
  195640. return i - 7;
  195641. jassertfalse
  195642. return 0;
  195643. }
  195644. };
  195645. class LinuxComponentPeer : public ComponentPeer
  195646. {
  195647. public:
  195648. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  195649. : ComponentPeer (component, windowStyleFlags),
  195650. windowH (0),
  195651. parentWindow (0),
  195652. wx (0),
  195653. wy (0),
  195654. ww (0),
  195655. wh (0),
  195656. fullScreen (false),
  195657. mapped (false),
  195658. visual (0),
  195659. depth (0)
  195660. {
  195661. // it's dangerous to create a window on a thread other than the message thread..
  195662. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195663. repainter = new LinuxRepaintManager (this);
  195664. createWindow();
  195665. setTitle (component->getName());
  195666. }
  195667. ~LinuxComponentPeer()
  195668. {
  195669. // it's dangerous to delete a window on a thread other than the message thread..
  195670. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195671. deleteIconPixmaps();
  195672. destroyWindow();
  195673. windowH = 0;
  195674. }
  195675. void* getNativeHandle() const
  195676. {
  195677. return (void*) windowH;
  195678. }
  195679. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  195680. {
  195681. XPointer peer = 0;
  195682. ScopedXLock xlock;
  195683. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  195684. {
  195685. if (peer != 0 && ! ComponentPeer::isValidPeer ((LinuxComponentPeer*) peer))
  195686. peer = 0;
  195687. }
  195688. return (LinuxComponentPeer*) peer;
  195689. }
  195690. void setVisible (bool shouldBeVisible)
  195691. {
  195692. ScopedXLock xlock;
  195693. if (shouldBeVisible)
  195694. XMapWindow (display, windowH);
  195695. else
  195696. XUnmapWindow (display, windowH);
  195697. }
  195698. void setTitle (const String& title)
  195699. {
  195700. setWindowTitle (windowH, title);
  195701. }
  195702. void setPosition (int x, int y)
  195703. {
  195704. setBounds (x, y, ww, wh, false);
  195705. }
  195706. void setSize (int w, int h)
  195707. {
  195708. setBounds (wx, wy, w, h, false);
  195709. }
  195710. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  195711. {
  195712. fullScreen = isNowFullScreen;
  195713. if (windowH != 0)
  195714. {
  195715. Component::SafePointer<Component> deletionChecker (component);
  195716. wx = x;
  195717. wy = y;
  195718. ww = jmax (1, w);
  195719. wh = jmax (1, h);
  195720. ScopedXLock xlock;
  195721. // Make sure the Window manager does what we want
  195722. XSizeHints* hints = XAllocSizeHints();
  195723. hints->flags = USSize | USPosition;
  195724. hints->width = ww;
  195725. hints->height = wh;
  195726. hints->x = wx;
  195727. hints->y = wy;
  195728. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  195729. {
  195730. hints->min_width = hints->max_width = hints->width;
  195731. hints->min_height = hints->max_height = hints->height;
  195732. hints->flags |= PMinSize | PMaxSize;
  195733. }
  195734. XSetWMNormalHints (display, windowH, hints);
  195735. XFree (hints);
  195736. XMoveResizeWindow (display, windowH,
  195737. wx - windowBorder.getLeft(),
  195738. wy - windowBorder.getTop(), ww, wh);
  195739. if (deletionChecker != 0)
  195740. {
  195741. updateBorderSize();
  195742. handleMovedOrResized();
  195743. }
  195744. }
  195745. }
  195746. const Rectangle<int> getBounds() const { return Rectangle<int> (wx, wy, ww, wh); }
  195747. const Point<int> getScreenPosition() const { return Point<int> (wx, wy); }
  195748. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  195749. {
  195750. return relativePosition + getScreenPosition();
  195751. }
  195752. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  195753. {
  195754. return screenPosition - getScreenPosition();
  195755. }
  195756. void setMinimised (bool shouldBeMinimised)
  195757. {
  195758. if (shouldBeMinimised)
  195759. {
  195760. Window root = RootWindow (display, DefaultScreen (display));
  195761. XClientMessageEvent clientMsg;
  195762. clientMsg.display = display;
  195763. clientMsg.window = windowH;
  195764. clientMsg.type = ClientMessage;
  195765. clientMsg.format = 32;
  195766. clientMsg.message_type = Atoms::ChangeState;
  195767. clientMsg.data.l[0] = IconicState;
  195768. ScopedXLock xlock;
  195769. XSendEvent (display, root, false,
  195770. SubstructureRedirectMask | SubstructureNotifyMask,
  195771. (XEvent*) &clientMsg);
  195772. }
  195773. else
  195774. {
  195775. setVisible (true);
  195776. }
  195777. }
  195778. bool isMinimised() const
  195779. {
  195780. bool minimised = false;
  195781. unsigned char* stateProp;
  195782. unsigned long nitems, bytesLeft;
  195783. Atom actualType;
  195784. int actualFormat;
  195785. ScopedXLock xlock;
  195786. if (XGetWindowProperty (display, windowH, Atoms::State, 0, 64, False,
  195787. Atoms::State, &actualType, &actualFormat, &nitems, &bytesLeft,
  195788. &stateProp) == Success
  195789. && actualType == Atoms::State
  195790. && actualFormat == 32
  195791. && nitems > 0)
  195792. {
  195793. if (((unsigned long*) stateProp)[0] == IconicState)
  195794. minimised = true;
  195795. XFree (stateProp);
  195796. }
  195797. return minimised;
  195798. }
  195799. void setFullScreen (const bool shouldBeFullScreen)
  195800. {
  195801. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  195802. setMinimised (false);
  195803. if (fullScreen != shouldBeFullScreen)
  195804. {
  195805. if (shouldBeFullScreen)
  195806. r = Desktop::getInstance().getMainMonitorArea();
  195807. if (! r.isEmpty())
  195808. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  195809. getComponent()->repaint();
  195810. }
  195811. }
  195812. bool isFullScreen() const
  195813. {
  195814. return fullScreen;
  195815. }
  195816. bool isChildWindowOf (Window possibleParent) const
  195817. {
  195818. Window* windowList = 0;
  195819. uint32 windowListSize = 0;
  195820. Window parent, root;
  195821. ScopedXLock xlock;
  195822. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  195823. {
  195824. if (windowList != 0)
  195825. XFree (windowList);
  195826. return parent == possibleParent;
  195827. }
  195828. return false;
  195829. }
  195830. bool isFrontWindow() const
  195831. {
  195832. Window* windowList = 0;
  195833. uint32 windowListSize = 0;
  195834. bool result = false;
  195835. ScopedXLock xlock;
  195836. Window parent, root = RootWindow (display, DefaultScreen (display));
  195837. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  195838. {
  195839. for (int i = windowListSize; --i >= 0;)
  195840. {
  195841. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  195842. if (peer != 0)
  195843. {
  195844. result = (peer == this);
  195845. break;
  195846. }
  195847. }
  195848. }
  195849. if (windowList != 0)
  195850. XFree (windowList);
  195851. return result;
  195852. }
  195853. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  195854. {
  195855. int x = position.getX();
  195856. int y = position.getY();
  195857. if (((unsigned int) x) >= (unsigned int) ww
  195858. || ((unsigned int) y) >= (unsigned int) wh)
  195859. return false;
  195860. bool inFront = false;
  195861. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  195862. {
  195863. Component* const c = Desktop::getInstance().getComponent (i);
  195864. if (inFront)
  195865. {
  195866. if (c->contains (x + wx - c->getScreenX(),
  195867. y + wy - c->getScreenY()))
  195868. {
  195869. return false;
  195870. }
  195871. }
  195872. else if (c == getComponent())
  195873. {
  195874. inFront = true;
  195875. }
  195876. }
  195877. if (trueIfInAChildWindow)
  195878. return true;
  195879. ::Window root, child;
  195880. unsigned int bw, depth;
  195881. int wx, wy, w, h;
  195882. ScopedXLock xlock;
  195883. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  195884. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  195885. &bw, &depth))
  195886. {
  195887. return false;
  195888. }
  195889. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  195890. return false;
  195891. return child == None;
  195892. }
  195893. const BorderSize getFrameSize() const
  195894. {
  195895. return BorderSize();
  195896. }
  195897. bool setAlwaysOnTop (bool alwaysOnTop)
  195898. {
  195899. if (windowH != 0)
  195900. {
  195901. const bool wasVisible = component->isVisible();
  195902. if (wasVisible)
  195903. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  195904. {
  195905. ScopedXLock xlock;
  195906. XSetWindowAttributes swa;
  195907. swa.override_redirect = alwaysOnTop ? True : False;
  195908. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  195909. }
  195910. if (wasVisible)
  195911. setVisible (true);
  195912. }
  195913. return true;
  195914. }
  195915. void toFront (bool makeActive)
  195916. {
  195917. if (makeActive)
  195918. {
  195919. setVisible (true);
  195920. grabFocus();
  195921. }
  195922. XEvent ev;
  195923. ev.xclient.type = ClientMessage;
  195924. ev.xclient.serial = 0;
  195925. ev.xclient.send_event = True;
  195926. ev.xclient.message_type = Atoms::ActiveWin;
  195927. ev.xclient.window = windowH;
  195928. ev.xclient.format = 32;
  195929. ev.xclient.data.l[0] = 2;
  195930. ev.xclient.data.l[1] = CurrentTime;
  195931. ev.xclient.data.l[2] = 0;
  195932. ev.xclient.data.l[3] = 0;
  195933. ev.xclient.data.l[4] = 0;
  195934. {
  195935. ScopedXLock xlock;
  195936. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  195937. False,
  195938. SubstructureRedirectMask | SubstructureNotifyMask,
  195939. &ev);
  195940. XWindowAttributes attr;
  195941. XGetWindowAttributes (display, windowH, &attr);
  195942. if (attr.override_redirect)
  195943. XRaiseWindow (display, windowH);
  195944. XSync (display, False);
  195945. }
  195946. handleBroughtToFront();
  195947. }
  195948. void toBehind (ComponentPeer* other)
  195949. {
  195950. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  195951. jassert (otherPeer != 0); // wrong type of window?
  195952. if (otherPeer != 0)
  195953. {
  195954. setMinimised (false);
  195955. Window newStack[] = { otherPeer->windowH, windowH };
  195956. ScopedXLock xlock;
  195957. XRestackWindows (display, newStack, 2);
  195958. }
  195959. }
  195960. bool isFocused() const
  195961. {
  195962. int revert;
  195963. Window focusedWindow = 0;
  195964. ScopedXLock xlock;
  195965. XGetInputFocus (display, &focusedWindow, &revert);
  195966. return focusedWindow == windowH;
  195967. }
  195968. void grabFocus()
  195969. {
  195970. XWindowAttributes atts;
  195971. ScopedXLock xlock;
  195972. if (windowH != 0
  195973. && XGetWindowAttributes (display, windowH, &atts)
  195974. && atts.map_state == IsViewable
  195975. && ! isFocused())
  195976. {
  195977. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  195978. isActiveApplication = true;
  195979. }
  195980. }
  195981. void textInputRequired (const Point<int>&)
  195982. {
  195983. }
  195984. void repaint (int x, int y, int w, int h)
  195985. {
  195986. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  195987. 0, 0,
  195988. getComponent()->getWidth(),
  195989. getComponent()->getHeight()))
  195990. {
  195991. repainter->repaint (x, y, w, h);
  195992. }
  195993. }
  195994. void performAnyPendingRepaintsNow()
  195995. {
  195996. repainter->performAnyPendingRepaintsNow();
  195997. }
  195998. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  195999. {
  196000. ScopedXLock xlock;
  196001. const int width = image.getWidth();
  196002. const int height = image.getHeight();
  196003. HeapBlock <uint32> colour (width * height);
  196004. int index = 0;
  196005. for (int y = 0; y < height; ++y)
  196006. for (int x = 0; x < width; ++x)
  196007. colour[index++] = image.getPixelAt (x, y).getARGB();
  196008. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  196009. 0, reinterpret_cast<char*> (colour.getData()),
  196010. width, height, 32, 0);
  196011. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  196012. width, height, 24);
  196013. GC gc = XCreateGC (display, pixmap, 0, 0);
  196014. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  196015. XFreeGC (display, gc);
  196016. return pixmap;
  196017. }
  196018. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  196019. {
  196020. ScopedXLock xlock;
  196021. const int width = image.getWidth();
  196022. const int height = image.getHeight();
  196023. const int stride = (width + 7) >> 3;
  196024. HeapBlock <uint8> mask;
  196025. mask.calloc (stride * height);
  196026. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  196027. for (int y = 0; y < height; ++y)
  196028. {
  196029. for (int x = 0; x < width; ++x)
  196030. {
  196031. const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  196032. const int offset = y * stride + (x >> 3);
  196033. if (image.getPixelAt (x, y).getAlpha() >= 128)
  196034. mask[offset] |= bit;
  196035. }
  196036. }
  196037. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  196038. reinterpret_cast<char*> (mask.getData()), width, height, 1, 0, 1);
  196039. }
  196040. void setIcon (const Image& newIcon)
  196041. {
  196042. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  196043. HeapBlock <unsigned long> data (dataSize);
  196044. int index = 0;
  196045. data[index++] = newIcon.getWidth();
  196046. data[index++] = newIcon.getHeight();
  196047. for (int y = 0; y < newIcon.getHeight(); ++y)
  196048. for (int x = 0; x < newIcon.getWidth(); ++x)
  196049. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  196050. ScopedXLock xlock;
  196051. XChangeProperty (display, windowH,
  196052. XInternAtom (display, "_NET_WM_ICON", False),
  196053. XA_CARDINAL, 32, PropModeReplace,
  196054. reinterpret_cast<unsigned char*> (data.getData()), dataSize);
  196055. deleteIconPixmaps();
  196056. XWMHints* wmHints = XGetWMHints (display, windowH);
  196057. if (wmHints == 0)
  196058. wmHints = XAllocWMHints();
  196059. wmHints->flags |= IconPixmapHint | IconMaskHint;
  196060. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  196061. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  196062. XSetWMHints (display, windowH, wmHints);
  196063. XFree (wmHints);
  196064. XSync (display, False);
  196065. }
  196066. void deleteIconPixmaps()
  196067. {
  196068. ScopedXLock xlock;
  196069. XWMHints* wmHints = XGetWMHints (display, windowH);
  196070. if (wmHints != 0)
  196071. {
  196072. if ((wmHints->flags & IconPixmapHint) != 0)
  196073. {
  196074. wmHints->flags &= ~IconPixmapHint;
  196075. XFreePixmap (display, wmHints->icon_pixmap);
  196076. }
  196077. if ((wmHints->flags & IconMaskHint) != 0)
  196078. {
  196079. wmHints->flags &= ~IconMaskHint;
  196080. XFreePixmap (display, wmHints->icon_mask);
  196081. }
  196082. XSetWMHints (display, windowH, wmHints);
  196083. XFree (wmHints);
  196084. }
  196085. }
  196086. void handleWindowMessage (XEvent* event)
  196087. {
  196088. switch (event->xany.type)
  196089. {
  196090. case 2: // 'KeyPress'
  196091. {
  196092. ScopedXLock xlock;
  196093. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196094. updateKeyStates (keyEvent->keycode, true);
  196095. char utf8 [64];
  196096. zeromem (utf8, sizeof (utf8));
  196097. KeySym sym;
  196098. {
  196099. const char* oldLocale = ::setlocale (LC_ALL, 0);
  196100. ::setlocale (LC_ALL, "");
  196101. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196102. ::setlocale (LC_ALL, oldLocale);
  196103. }
  196104. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 (utf8, sizeof (utf8) - 1);
  196105. int keyCode = (int) unicodeChar;
  196106. if (keyCode < 0x20)
  196107. keyCode = XKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0);
  196108. const ModifierKeys oldMods (currentModifiers);
  196109. bool keyPressed = false;
  196110. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196111. if ((sym & 0xff00) == 0xff00)
  196112. {
  196113. // Translate keypad
  196114. if (sym == XK_KP_Divide)
  196115. keyCode = XK_slash;
  196116. else if (sym == XK_KP_Multiply)
  196117. keyCode = XK_asterisk;
  196118. else if (sym == XK_KP_Subtract)
  196119. keyCode = XK_hyphen;
  196120. else if (sym == XK_KP_Add)
  196121. keyCode = XK_plus;
  196122. else if (sym == XK_KP_Enter)
  196123. keyCode = XK_Return;
  196124. else if (sym == XK_KP_Decimal)
  196125. keyCode = Keys::numLock ? XK_period : XK_Delete;
  196126. else if (sym == XK_KP_0)
  196127. keyCode = Keys::numLock ? XK_0 : XK_Insert;
  196128. else if (sym == XK_KP_1)
  196129. keyCode = Keys::numLock ? XK_1 : XK_End;
  196130. else if (sym == XK_KP_2)
  196131. keyCode = Keys::numLock ? XK_2 : XK_Down;
  196132. else if (sym == XK_KP_3)
  196133. keyCode = Keys::numLock ? XK_3 : XK_Page_Down;
  196134. else if (sym == XK_KP_4)
  196135. keyCode = Keys::numLock ? XK_4 : XK_Left;
  196136. else if (sym == XK_KP_5)
  196137. keyCode = XK_5;
  196138. else if (sym == XK_KP_6)
  196139. keyCode = Keys::numLock ? XK_6 : XK_Right;
  196140. else if (sym == XK_KP_7)
  196141. keyCode = Keys::numLock ? XK_7 : XK_Home;
  196142. else if (sym == XK_KP_8)
  196143. keyCode = Keys::numLock ? XK_8 : XK_Up;
  196144. else if (sym == XK_KP_9)
  196145. keyCode = Keys::numLock ? XK_9 : XK_Page_Up;
  196146. switch (sym)
  196147. {
  196148. case XK_Left:
  196149. case XK_Right:
  196150. case XK_Up:
  196151. case XK_Down:
  196152. case XK_Page_Up:
  196153. case XK_Page_Down:
  196154. case XK_End:
  196155. case XK_Home:
  196156. case XK_Delete:
  196157. case XK_Insert:
  196158. keyPressed = true;
  196159. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196160. break;
  196161. case XK_Tab:
  196162. case XK_Return:
  196163. case XK_Escape:
  196164. case XK_BackSpace:
  196165. keyPressed = true;
  196166. keyCode &= 0xff;
  196167. break;
  196168. default:
  196169. {
  196170. if (sym >= XK_F1 && sym <= XK_F16)
  196171. {
  196172. keyPressed = true;
  196173. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196174. }
  196175. break;
  196176. }
  196177. }
  196178. }
  196179. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196180. keyPressed = true;
  196181. if (oldMods != currentModifiers)
  196182. handleModifierKeysChange();
  196183. if (keyDownChange)
  196184. handleKeyUpOrDown (true);
  196185. if (keyPressed)
  196186. handleKeyPress (keyCode, unicodeChar);
  196187. break;
  196188. }
  196189. case KeyRelease:
  196190. {
  196191. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196192. updateKeyStates (keyEvent->keycode, false);
  196193. ScopedXLock xlock;
  196194. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196195. const ModifierKeys oldMods (currentModifiers);
  196196. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196197. if (oldMods != currentModifiers)
  196198. handleModifierKeysChange();
  196199. if (keyDownChange)
  196200. handleKeyUpOrDown (false);
  196201. break;
  196202. }
  196203. case ButtonPress:
  196204. {
  196205. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196206. updateKeyModifiers (buttonPressEvent->state);
  196207. bool buttonMsg = false;
  196208. const int map = pointerMap [buttonPressEvent->button - Button1];
  196209. if (map == Keys::WheelUp || map == Keys::WheelDown)
  196210. {
  196211. handleMouseWheel (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y),
  196212. getEventTime (buttonPressEvent->time), 0, map == Keys::WheelDown ? -84.0f : 84.0f);
  196213. }
  196214. if (map == Keys::LeftButton)
  196215. {
  196216. currentModifiers = currentModifiers.withFlags (ModifierKeys::leftButtonModifier);
  196217. buttonMsg = true;
  196218. }
  196219. else if (map == Keys::RightButton)
  196220. {
  196221. currentModifiers = currentModifiers.withFlags (ModifierKeys::rightButtonModifier);
  196222. buttonMsg = true;
  196223. }
  196224. else if (map == Keys::MiddleButton)
  196225. {
  196226. currentModifiers = currentModifiers.withFlags (ModifierKeys::middleButtonModifier);
  196227. buttonMsg = true;
  196228. }
  196229. if (buttonMsg)
  196230. {
  196231. toFront (true);
  196232. handleMouseEvent (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y), currentModifiers,
  196233. getEventTime (buttonPressEvent->time));
  196234. }
  196235. clearLastMousePos();
  196236. break;
  196237. }
  196238. case ButtonRelease:
  196239. {
  196240. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196241. updateKeyModifiers (buttonRelEvent->state);
  196242. const int map = pointerMap [buttonRelEvent->button - Button1];
  196243. if (map == Keys::LeftButton)
  196244. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::leftButtonModifier);
  196245. else if (map == Keys::RightButton)
  196246. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::rightButtonModifier);
  196247. else if (map == Keys::MiddleButton)
  196248. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::middleButtonModifier);
  196249. handleMouseEvent (0, Point<int> (buttonRelEvent->x, buttonRelEvent->y), currentModifiers,
  196250. getEventTime (buttonRelEvent->time));
  196251. clearLastMousePos();
  196252. break;
  196253. }
  196254. case MotionNotify:
  196255. {
  196256. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196257. updateKeyModifiers (movedEvent->state);
  196258. const Point<int> mousePos (Desktop::getMousePosition());
  196259. if (lastMousePos != mousePos)
  196260. {
  196261. lastMousePos = mousePos;
  196262. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196263. {
  196264. Window wRoot = 0, wParent = 0;
  196265. {
  196266. ScopedXLock xlock;
  196267. unsigned int numChildren;
  196268. Window* wChild = 0;
  196269. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196270. }
  196271. if (wParent != 0
  196272. && wParent != windowH
  196273. && wParent != wRoot)
  196274. {
  196275. parentWindow = wParent;
  196276. updateBounds();
  196277. }
  196278. else
  196279. {
  196280. parentWindow = 0;
  196281. }
  196282. }
  196283. handleMouseEvent (0, mousePos - getScreenPosition(), currentModifiers, getEventTime (movedEvent->time));
  196284. }
  196285. break;
  196286. }
  196287. case EnterNotify:
  196288. {
  196289. clearLastMousePos();
  196290. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196291. if (! currentModifiers.isAnyMouseButtonDown())
  196292. {
  196293. updateKeyModifiers (enterEvent->state);
  196294. handleMouseEvent (0, Point<int> (enterEvent->x, enterEvent->y), currentModifiers, getEventTime (enterEvent->time));
  196295. }
  196296. break;
  196297. }
  196298. case LeaveNotify:
  196299. {
  196300. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196301. // Suppress the normal leave if we've got a pointer grab, or if
  196302. // it's a bogus one caused by clicking a mouse button when running
  196303. // in a Window manager
  196304. if (((! currentModifiers.isAnyMouseButtonDown()) && leaveEvent->mode == NotifyNormal)
  196305. || leaveEvent->mode == NotifyUngrab)
  196306. {
  196307. updateKeyModifiers (leaveEvent->state);
  196308. handleMouseEvent (0, Point<int> (leaveEvent->x, leaveEvent->y), currentModifiers, getEventTime (leaveEvent->time));
  196309. }
  196310. break;
  196311. }
  196312. case FocusIn:
  196313. {
  196314. isActiveApplication = true;
  196315. if (isFocused())
  196316. handleFocusGain();
  196317. break;
  196318. }
  196319. case FocusOut:
  196320. {
  196321. isActiveApplication = false;
  196322. if (! isFocused())
  196323. handleFocusLoss();
  196324. break;
  196325. }
  196326. case Expose:
  196327. {
  196328. // Batch together all pending expose events
  196329. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196330. XEvent nextEvent;
  196331. ScopedXLock xlock;
  196332. if (exposeEvent->window != windowH)
  196333. {
  196334. Window child;
  196335. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196336. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196337. &child);
  196338. }
  196339. repaint (exposeEvent->x, exposeEvent->y,
  196340. exposeEvent->width, exposeEvent->height);
  196341. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196342. {
  196343. XPeekEvent (display, (XEvent*) &nextEvent);
  196344. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196345. break;
  196346. XNextEvent (display, (XEvent*) &nextEvent);
  196347. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196348. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196349. nextExposeEvent->width, nextExposeEvent->height);
  196350. }
  196351. break;
  196352. }
  196353. case CirculateNotify:
  196354. case CreateNotify:
  196355. case DestroyNotify:
  196356. // Think we can ignore these
  196357. break;
  196358. case ConfigureNotify:
  196359. {
  196360. updateBounds();
  196361. updateBorderSize();
  196362. handleMovedOrResized();
  196363. // if the native title bar is dragged, need to tell any active menus, etc.
  196364. if ((styleFlags & windowHasTitleBar) != 0
  196365. && component->isCurrentlyBlockedByAnotherModalComponent())
  196366. {
  196367. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196368. if (currentModalComp != 0)
  196369. currentModalComp->inputAttemptWhenModal();
  196370. }
  196371. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196372. if (confEvent->window == windowH
  196373. && confEvent->above != 0
  196374. && isFrontWindow())
  196375. {
  196376. handleBroughtToFront();
  196377. }
  196378. break;
  196379. }
  196380. case ReparentNotify:
  196381. case GravityNotify:
  196382. {
  196383. parentWindow = 0;
  196384. Window wRoot = 0;
  196385. Window* wChild = 0;
  196386. unsigned int numChildren;
  196387. {
  196388. ScopedXLock xlock;
  196389. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196390. }
  196391. if (parentWindow == windowH || parentWindow == wRoot)
  196392. parentWindow = 0;
  196393. updateBounds();
  196394. updateBorderSize();
  196395. handleMovedOrResized();
  196396. break;
  196397. }
  196398. case MapNotify:
  196399. mapped = true;
  196400. handleBroughtToFront();
  196401. break;
  196402. case UnmapNotify:
  196403. mapped = false;
  196404. break;
  196405. case MappingNotify:
  196406. {
  196407. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196408. if (mappingEvent->request != MappingPointer)
  196409. {
  196410. // Deal with modifier/keyboard mapping
  196411. ScopedXLock xlock;
  196412. XRefreshKeyboardMapping (mappingEvent);
  196413. updateModifierMappings();
  196414. }
  196415. break;
  196416. }
  196417. case ClientMessage:
  196418. {
  196419. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196420. if (clientMsg->message_type == Atoms::Protocols && clientMsg->format == 32)
  196421. {
  196422. const Atom atom = (Atom) clientMsg->data.l[0];
  196423. if (atom == Atoms::ProtocolList [Atoms::TAKE_FOCUS])
  196424. {
  196425. XWindowAttributes atts;
  196426. ScopedXLock xlock;
  196427. if (clientMsg->window != 0
  196428. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196429. {
  196430. if (atts.map_state == IsViewable)
  196431. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196432. }
  196433. }
  196434. else if (atom == Atoms::ProtocolList [Atoms::DELETE_WINDOW])
  196435. {
  196436. handleUserClosingWindow();
  196437. }
  196438. }
  196439. else if (clientMsg->message_type == Atoms::XdndEnter)
  196440. {
  196441. handleDragAndDropEnter (clientMsg);
  196442. }
  196443. else if (clientMsg->message_type == Atoms::XdndLeave)
  196444. {
  196445. resetDragAndDrop();
  196446. }
  196447. else if (clientMsg->message_type == Atoms::XdndPosition)
  196448. {
  196449. handleDragAndDropPosition (clientMsg);
  196450. }
  196451. else if (clientMsg->message_type == Atoms::XdndDrop)
  196452. {
  196453. handleDragAndDropDrop (clientMsg);
  196454. }
  196455. else if (clientMsg->message_type == Atoms::XdndStatus)
  196456. {
  196457. handleDragAndDropStatus (clientMsg);
  196458. }
  196459. else if (clientMsg->message_type == Atoms::XdndFinished)
  196460. {
  196461. resetDragAndDrop();
  196462. }
  196463. break;
  196464. }
  196465. case SelectionNotify:
  196466. handleDragAndDropSelection (event);
  196467. break;
  196468. case SelectionClear:
  196469. case SelectionRequest:
  196470. break;
  196471. default:
  196472. #if JUCE_USE_XSHM
  196473. {
  196474. ScopedXLock xlock;
  196475. if (event->xany.type == XShmGetEventBase (display))
  196476. repainter->notifyPaintCompleted();
  196477. }
  196478. #endif
  196479. break;
  196480. }
  196481. }
  196482. void showMouseCursor (Cursor cursor) throw()
  196483. {
  196484. ScopedXLock xlock;
  196485. XDefineCursor (display, windowH, cursor);
  196486. }
  196487. void setTaskBarIcon (const Image& image)
  196488. {
  196489. ScopedXLock xlock;
  196490. taskbarImage = image.createCopy();
  196491. Screen* const screen = XDefaultScreenOfDisplay (display);
  196492. const int screenNumber = XScreenNumberOfScreen (screen);
  196493. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196494. screenAtom << screenNumber;
  196495. Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false);
  196496. XGrabServer (display);
  196497. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196498. if (managerWin != None)
  196499. XSelectInput (display, managerWin, StructureNotifyMask);
  196500. XUngrabServer (display);
  196501. XFlush (display);
  196502. if (managerWin != None)
  196503. {
  196504. XEvent ev;
  196505. zerostruct (ev);
  196506. ev.xclient.type = ClientMessage;
  196507. ev.xclient.window = managerWin;
  196508. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196509. ev.xclient.format = 32;
  196510. ev.xclient.data.l[0] = CurrentTime;
  196511. ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
  196512. ev.xclient.data.l[2] = windowH;
  196513. ev.xclient.data.l[3] = 0;
  196514. ev.xclient.data.l[4] = 0;
  196515. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196516. XSync (display, False);
  196517. }
  196518. // For older KDE's ...
  196519. long atomData = 1;
  196520. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196521. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196522. // For more recent KDE's...
  196523. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196524. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196525. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196526. XSizeHints* hints = XAllocSizeHints();
  196527. hints->flags = PMinSize;
  196528. hints->min_width = 22;
  196529. hints->min_height = 22;
  196530. XSetWMNormalHints (display, windowH, hints);
  196531. XFree (hints);
  196532. }
  196533. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196534. juce_UseDebuggingNewOperator
  196535. bool dontRepaint;
  196536. static ModifierKeys currentModifiers;
  196537. private:
  196538. class LinuxRepaintManager : public Timer
  196539. {
  196540. public:
  196541. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196542. : peer (peer_),
  196543. lastTimeImageUsed (0)
  196544. {
  196545. #if JUCE_USE_XSHM
  196546. shmCompletedDrawing = true;
  196547. useARGBImagesForRendering = isShmAvailable();
  196548. if (useARGBImagesForRendering)
  196549. {
  196550. ScopedXLock xlock;
  196551. XShmSegmentInfo segmentinfo;
  196552. XImage* const testImage
  196553. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196554. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196555. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196556. XDestroyImage (testImage);
  196557. }
  196558. #endif
  196559. }
  196560. ~LinuxRepaintManager()
  196561. {
  196562. }
  196563. void timerCallback()
  196564. {
  196565. #if JUCE_USE_XSHM
  196566. if (! shmCompletedDrawing)
  196567. return;
  196568. #endif
  196569. if (! regionsNeedingRepaint.isEmpty())
  196570. {
  196571. stopTimer();
  196572. performAnyPendingRepaintsNow();
  196573. }
  196574. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196575. {
  196576. stopTimer();
  196577. image = 0;
  196578. }
  196579. }
  196580. void repaint (int x, int y, int w, int h)
  196581. {
  196582. if (! isTimerRunning())
  196583. startTimer (repaintTimerPeriod);
  196584. regionsNeedingRepaint.add (x, y, w, h);
  196585. }
  196586. void performAnyPendingRepaintsNow()
  196587. {
  196588. #if JUCE_USE_XSHM
  196589. if (! shmCompletedDrawing)
  196590. {
  196591. startTimer (repaintTimerPeriod);
  196592. return;
  196593. }
  196594. #endif
  196595. peer->clearMaskedRegion();
  196596. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196597. regionsNeedingRepaint.clear();
  196598. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  196599. if (! totalArea.isEmpty())
  196600. {
  196601. if (image == 0 || image->getWidth() < totalArea.getWidth()
  196602. || image->getHeight() < totalArea.getHeight())
  196603. {
  196604. #if JUCE_USE_XSHM
  196605. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  196606. : Image::RGB,
  196607. #else
  196608. image = new XBitmapImage (Image::RGB,
  196609. #endif
  196610. (totalArea.getWidth() + 31) & ~31,
  196611. (totalArea.getHeight() + 31) & ~31,
  196612. false,
  196613. peer->depth,
  196614. peer->visual);
  196615. }
  196616. startTimer (repaintTimerPeriod);
  196617. LowLevelGraphicsSoftwareRenderer context (*image);
  196618. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  196619. if (context.clipToRectangleList (originalRepaintRegion))
  196620. {
  196621. if (peer->depth == 32)
  196622. {
  196623. RectangleList::Iterator i (originalRepaintRegion);
  196624. while (i.next())
  196625. {
  196626. const Rectangle<int>& r = *i.getRectangle();
  196627. image->clear (r.getX() - totalArea.getX(), r.getY() - totalArea.getY(), r.getWidth(), r.getHeight());
  196628. }
  196629. }
  196630. peer->handlePaint (context);
  196631. }
  196632. if (! peer->maskedRegion.isEmpty())
  196633. originalRepaintRegion.subtract (peer->maskedRegion);
  196634. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  196635. {
  196636. #if JUCE_USE_XSHM
  196637. shmCompletedDrawing = false;
  196638. #endif
  196639. const Rectangle<int>& r = *i.getRectangle();
  196640. image->blitToWindow (peer->windowH,
  196641. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  196642. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  196643. }
  196644. }
  196645. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  196646. startTimer (repaintTimerPeriod);
  196647. }
  196648. #if JUCE_USE_XSHM
  196649. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  196650. #endif
  196651. private:
  196652. enum { repaintTimerPeriod = 1000 / 100 };
  196653. LinuxComponentPeer* const peer;
  196654. ScopedPointer <XBitmapImage> image;
  196655. uint32 lastTimeImageUsed;
  196656. RectangleList regionsNeedingRepaint;
  196657. #if JUCE_USE_XSHM
  196658. bool useARGBImagesForRendering, shmCompletedDrawing;
  196659. #endif
  196660. LinuxRepaintManager (const LinuxRepaintManager&);
  196661. LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  196662. };
  196663. ScopedPointer <LinuxRepaintManager> repainter;
  196664. friend class LinuxRepaintManager;
  196665. Window windowH, parentWindow;
  196666. int wx, wy, ww, wh;
  196667. ScopedPointer<Image> taskbarImage;
  196668. bool fullScreen, mapped;
  196669. Visual* visual;
  196670. int depth;
  196671. BorderSize windowBorder;
  196672. struct MotifWmHints
  196673. {
  196674. unsigned long flags;
  196675. unsigned long functions;
  196676. unsigned long decorations;
  196677. long input_mode;
  196678. unsigned long status;
  196679. };
  196680. static void updateKeyStates (const int keycode, const bool press) throw()
  196681. {
  196682. const int keybyte = keycode >> 3;
  196683. const int keybit = (1 << (keycode & 7));
  196684. if (press)
  196685. Keys::keyStates [keybyte] |= keybit;
  196686. else
  196687. Keys::keyStates [keybyte] &= ~keybit;
  196688. }
  196689. static void updateKeyModifiers (const int status) throw()
  196690. {
  196691. int keyMods = 0;
  196692. if (status & ShiftMask) keyMods |= ModifierKeys::shiftModifier;
  196693. if (status & ControlMask) keyMods |= ModifierKeys::ctrlModifier;
  196694. if (status & Keys::AltMask) keyMods |= ModifierKeys::altModifier;
  196695. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  196696. Keys::numLock = ((status & Keys::NumLockMask) != 0);
  196697. Keys::capsLock = ((status & LockMask) != 0);
  196698. }
  196699. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  196700. {
  196701. int modifier = 0;
  196702. bool isModifier = true;
  196703. switch (sym)
  196704. {
  196705. case XK_Shift_L:
  196706. case XK_Shift_R:
  196707. modifier = ModifierKeys::shiftModifier;
  196708. break;
  196709. case XK_Control_L:
  196710. case XK_Control_R:
  196711. modifier = ModifierKeys::ctrlModifier;
  196712. break;
  196713. case XK_Alt_L:
  196714. case XK_Alt_R:
  196715. modifier = ModifierKeys::altModifier;
  196716. break;
  196717. case XK_Num_Lock:
  196718. if (press)
  196719. Keys::numLock = ! Keys::numLock;
  196720. break;
  196721. case XK_Caps_Lock:
  196722. if (press)
  196723. Keys::capsLock = ! Keys::capsLock;
  196724. break;
  196725. case XK_Scroll_Lock:
  196726. break;
  196727. default:
  196728. isModifier = false;
  196729. break;
  196730. }
  196731. if (modifier != 0)
  196732. {
  196733. if (press)
  196734. currentModifiers = currentModifiers.withFlags (modifier);
  196735. else
  196736. currentModifiers = currentModifiers.withoutFlags (modifier);
  196737. }
  196738. return isModifier;
  196739. }
  196740. // Alt and Num lock are not defined by standard X
  196741. // modifier constants: check what they're mapped to
  196742. static void updateModifierMappings() throw()
  196743. {
  196744. ScopedXLock xlock;
  196745. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  196746. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  196747. Keys::AltMask = 0;
  196748. Keys::NumLockMask = 0;
  196749. XModifierKeymap* mapping = XGetModifierMapping (display);
  196750. if (mapping)
  196751. {
  196752. for (int i = 0; i < 8; i++)
  196753. {
  196754. if (mapping->modifiermap [i << 1] == altLeftCode)
  196755. Keys::AltMask = 1 << i;
  196756. else if (mapping->modifiermap [i << 1] == numLockCode)
  196757. Keys::NumLockMask = 1 << i;
  196758. }
  196759. XFreeModifiermap (mapping);
  196760. }
  196761. }
  196762. void removeWindowDecorations (Window wndH)
  196763. {
  196764. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196765. if (hints != None)
  196766. {
  196767. MotifWmHints motifHints;
  196768. zerostruct (motifHints);
  196769. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  196770. motifHints.decorations = 0;
  196771. ScopedXLock xlock;
  196772. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196773. (unsigned char*) &motifHints, 4);
  196774. }
  196775. hints = XInternAtom (display, "_WIN_HINTS", True);
  196776. if (hints != None)
  196777. {
  196778. long gnomeHints = 0;
  196779. ScopedXLock xlock;
  196780. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196781. (unsigned char*) &gnomeHints, 1);
  196782. }
  196783. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  196784. if (hints != None)
  196785. {
  196786. long kwmHints = 2; /*KDE_tinyDecoration*/
  196787. ScopedXLock xlock;
  196788. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196789. (unsigned char*) &kwmHints, 1);
  196790. }
  196791. }
  196792. void addWindowButtons (Window wndH)
  196793. {
  196794. ScopedXLock xlock;
  196795. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196796. if (hints != None)
  196797. {
  196798. MotifWmHints motifHints;
  196799. zerostruct (motifHints);
  196800. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  196801. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  196802. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  196803. if ((styleFlags & windowHasCloseButton) != 0)
  196804. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  196805. if ((styleFlags & windowHasMinimiseButton) != 0)
  196806. {
  196807. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  196808. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  196809. }
  196810. if ((styleFlags & windowHasMaximiseButton) != 0)
  196811. {
  196812. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  196813. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  196814. }
  196815. if ((styleFlags & windowIsResizable) != 0)
  196816. {
  196817. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  196818. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  196819. }
  196820. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  196821. }
  196822. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  196823. if (hints != None)
  196824. {
  196825. int netHints [6];
  196826. int num = 0;
  196827. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  196828. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  196829. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  196830. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  196831. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  196832. (unsigned char*) &netHints, num);
  196833. }
  196834. }
  196835. void setWindowType (Window wndH)
  196836. {
  196837. int netHints [2];
  196838. int numHints = 0;
  196839. if ((styleFlags & windowIsTemporary) != 0
  196840. || ((styleFlags & windowHasDropShadow) == 0 && Desktop::canUseSemiTransparentWindows()))
  196841. {
  196842. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_COMBO", True);
  196843. }
  196844. else
  196845. {
  196846. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  196847. }
  196848. if (netHints [numHints] != 0)
  196849. ++numHints;
  196850. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  196851. if (netHints [numHints] != 0)
  196852. ++numHints;
  196853. XChangeProperty (display, wndH, Atoms::WindowType, XA_ATOM, 32, PropModeReplace,
  196854. (unsigned char*) &netHints, numHints);
  196855. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  196856. {
  196857. }
  196858. }
  196859. void createWindow()
  196860. {
  196861. ScopedXLock xlock;
  196862. Atoms::initialiseAtoms();
  196863. resetDragAndDrop();
  196864. // Get defaults for various properties
  196865. const int screen = DefaultScreen (display);
  196866. Window root = RootWindow (display, screen);
  196867. // Try to obtain a 32-bit visual or fallback to 24 or 16
  196868. visual = Visuals::findVisualFormat ((styleFlags & windowIsSemiTransparent) ? 32 : 24, depth);
  196869. if (visual == 0)
  196870. {
  196871. Logger::outputDebugString ("ERROR: System doesn't support 32, 24 or 16 bit RGB display.\n");
  196872. Process::terminate();
  196873. }
  196874. // Create and install a colormap suitable fr our visual
  196875. Colormap colormap = XCreateColormap (display, root, visual, AllocNone);
  196876. XInstallColormap (display, colormap);
  196877. // Set up the window attributes
  196878. XSetWindowAttributes swa;
  196879. swa.border_pixel = 0;
  196880. swa.background_pixmap = None;
  196881. swa.colormap = colormap;
  196882. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  196883. swa.event_mask = eventMask;
  196884. Window wndH = XCreateWindow (display, root,
  196885. 0, 0, 1, 1,
  196886. 0, depth, InputOutput, visual,
  196887. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  196888. &swa);
  196889. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  196890. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  196891. GrabModeAsync, GrabModeAsync, None, None);
  196892. // Set the window context to identify the window handle object
  196893. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  196894. {
  196895. // Failed
  196896. jassertfalse
  196897. Logger::outputDebugString ("Failed to create context information for window.\n");
  196898. XDestroyWindow (display, wndH);
  196899. wndH = 0;
  196900. }
  196901. // Set window manager hints
  196902. XWMHints* wmHints = XAllocWMHints();
  196903. wmHints->flags = InputHint | StateHint;
  196904. wmHints->input = True; // Locally active input model
  196905. wmHints->initial_state = NormalState;
  196906. XSetWMHints (display, wndH, wmHints);
  196907. XFree (wmHints);
  196908. // Set the window type
  196909. setWindowType (wndH);
  196910. // Define decoration
  196911. if ((styleFlags & windowHasTitleBar) == 0)
  196912. removeWindowDecorations (wndH);
  196913. else
  196914. addWindowButtons (wndH);
  196915. // Set window name
  196916. setWindowTitle (wndH, getComponent()->getName());
  196917. // Associate the PID, allowing to be shut down when something goes wrong
  196918. unsigned long pid = getpid();
  196919. XChangeProperty (display, wndH, Atoms::Pid, XA_CARDINAL, 32, PropModeReplace,
  196920. (unsigned char*) &pid, 1);
  196921. // Set window manager protocols
  196922. XChangeProperty (display, wndH, Atoms::Protocols, XA_ATOM, 32, PropModeReplace,
  196923. (unsigned char*) Atoms::ProtocolList, 2);
  196924. // Set drag and drop flags
  196925. XChangeProperty (display, wndH, Atoms::XdndTypeList, XA_ATOM, 32, PropModeReplace,
  196926. (const unsigned char*) Atoms::allowedMimeTypes, numElementsInArray (Atoms::allowedMimeTypes));
  196927. XChangeProperty (display, wndH, Atoms::XdndActionList, XA_ATOM, 32, PropModeReplace,
  196928. (const unsigned char*) Atoms::allowedActions, numElementsInArray (Atoms::allowedActions));
  196929. XChangeProperty (display, wndH, Atoms::XdndActionDescription, XA_STRING, 8, PropModeReplace,
  196930. (const unsigned char*) "", 0);
  196931. unsigned long dndVersion = Atoms::DndVersion;
  196932. XChangeProperty (display, wndH, Atoms::XdndAware, XA_ATOM, 32, PropModeReplace,
  196933. (const unsigned char*) &dndVersion, 1);
  196934. // Initialise the pointer and keyboard mapping
  196935. // This is not the same as the logical pointer mapping the X server uses:
  196936. // we don't mess with this.
  196937. static bool mappingInitialised = false;
  196938. if (! mappingInitialised)
  196939. {
  196940. mappingInitialised = true;
  196941. const int numButtons = XGetPointerMapping (display, 0, 0);
  196942. if (numButtons == 2)
  196943. {
  196944. pointerMap[0] = Keys::LeftButton;
  196945. pointerMap[1] = Keys::RightButton;
  196946. pointerMap[2] = pointerMap[3] = pointerMap[4] = Keys::NoButton;
  196947. }
  196948. else if (numButtons >= 3)
  196949. {
  196950. pointerMap[0] = Keys::LeftButton;
  196951. pointerMap[1] = Keys::MiddleButton;
  196952. pointerMap[2] = Keys::RightButton;
  196953. if (numButtons >= 5)
  196954. {
  196955. pointerMap[3] = Keys::WheelUp;
  196956. pointerMap[4] = Keys::WheelDown;
  196957. }
  196958. }
  196959. updateModifierMappings();
  196960. }
  196961. windowH = wndH;
  196962. }
  196963. void destroyWindow()
  196964. {
  196965. ScopedXLock xlock;
  196966. XPointer handlePointer;
  196967. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  196968. XDeleteContext (display, (XID) windowH, improbableNumber);
  196969. XDestroyWindow (display, windowH);
  196970. // Wait for it to complete and then remove any events for this
  196971. // window from the event queue.
  196972. XSync (display, false);
  196973. XEvent event;
  196974. while (XCheckWindowEvent (display, windowH, eventMask, &event) == True)
  196975. {}
  196976. }
  196977. static int64 getEventTime (::Time t)
  196978. {
  196979. static int64 eventTimeOffset = 0x12345678;
  196980. const int64 thisMessageTime = t;
  196981. if (eventTimeOffset == 0x12345678)
  196982. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  196983. return eventTimeOffset + thisMessageTime;
  196984. }
  196985. static void setWindowTitle (Window xwin, const String& title)
  196986. {
  196987. XTextProperty nameProperty;
  196988. char* strings[] = { const_cast <char*> (title.toUTF8()) };
  196989. ScopedXLock xlock;
  196990. if (XStringListToTextProperty (strings, 1, &nameProperty))
  196991. {
  196992. XSetWMName (display, xwin, &nameProperty);
  196993. XSetWMIconName (display, xwin, &nameProperty);
  196994. XFree (nameProperty.value);
  196995. }
  196996. }
  196997. void updateBorderSize()
  196998. {
  196999. if ((styleFlags & windowHasTitleBar) == 0)
  197000. {
  197001. windowBorder = BorderSize (0);
  197002. }
  197003. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  197004. {
  197005. ScopedXLock xlock;
  197006. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  197007. if (hints != None)
  197008. {
  197009. unsigned char* data = 0;
  197010. unsigned long nitems, bytesLeft;
  197011. Atom actualType;
  197012. int actualFormat;
  197013. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  197014. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197015. &data) == Success)
  197016. {
  197017. const unsigned long* const sizes = (const unsigned long*) data;
  197018. if (actualFormat == 32)
  197019. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  197020. (int) sizes[3], (int) sizes[1]);
  197021. XFree (data);
  197022. }
  197023. }
  197024. }
  197025. }
  197026. void updateBounds()
  197027. {
  197028. jassert (windowH != 0);
  197029. if (windowH != 0)
  197030. {
  197031. Window root, child;
  197032. unsigned int bw, depth;
  197033. ScopedXLock xlock;
  197034. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  197035. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  197036. &bw, &depth))
  197037. {
  197038. wx = wy = ww = wh = 0;
  197039. }
  197040. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  197041. {
  197042. wx = wy = 0;
  197043. }
  197044. }
  197045. }
  197046. void resetDragAndDrop()
  197047. {
  197048. dragAndDropFiles.clear();
  197049. lastDropPos = Point<int> (-1, -1);
  197050. dragAndDropCurrentMimeType = 0;
  197051. dragAndDropSourceWindow = 0;
  197052. srcMimeTypeAtomList.clear();
  197053. }
  197054. void sendDragAndDropMessage (XClientMessageEvent& msg)
  197055. {
  197056. msg.type = ClientMessage;
  197057. msg.display = display;
  197058. msg.window = dragAndDropSourceWindow;
  197059. msg.format = 32;
  197060. msg.data.l[0] = windowH;
  197061. ScopedXLock xlock;
  197062. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  197063. }
  197064. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  197065. {
  197066. XClientMessageEvent msg;
  197067. zerostruct (msg);
  197068. msg.message_type = Atoms::XdndStatus;
  197069. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  197070. msg.data.l[4] = dropAction;
  197071. sendDragAndDropMessage (msg);
  197072. }
  197073. void sendDragAndDropLeave()
  197074. {
  197075. XClientMessageEvent msg;
  197076. zerostruct (msg);
  197077. msg.message_type = Atoms::XdndLeave;
  197078. sendDragAndDropMessage (msg);
  197079. }
  197080. void sendDragAndDropFinish()
  197081. {
  197082. XClientMessageEvent msg;
  197083. zerostruct (msg);
  197084. msg.message_type = Atoms::XdndFinished;
  197085. sendDragAndDropMessage (msg);
  197086. }
  197087. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197088. {
  197089. if ((clientMsg->data.l[1] & 1) == 0)
  197090. {
  197091. sendDragAndDropLeave();
  197092. if (dragAndDropFiles.size() > 0)
  197093. handleFileDragExit (dragAndDropFiles);
  197094. dragAndDropFiles.clear();
  197095. }
  197096. }
  197097. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197098. {
  197099. if (dragAndDropSourceWindow == 0)
  197100. return;
  197101. dragAndDropSourceWindow = clientMsg->data.l[0];
  197102. Point<int> dropPos ((int) clientMsg->data.l[2] >> 16,
  197103. (int) clientMsg->data.l[2] & 0xffff);
  197104. dropPos -= getScreenPosition();
  197105. if (lastDropPos != dropPos)
  197106. {
  197107. lastDropPos = dropPos;
  197108. dragAndDropTimestamp = clientMsg->data.l[3];
  197109. Atom targetAction = Atoms::XdndActionCopy;
  197110. for (int i = numElementsInArray (Atoms::allowedActions); --i >= 0;)
  197111. {
  197112. if ((Atom) clientMsg->data.l[4] == Atoms::allowedActions[i])
  197113. {
  197114. targetAction = Atoms::allowedActions[i];
  197115. break;
  197116. }
  197117. }
  197118. sendDragAndDropStatus (true, targetAction);
  197119. if (dragAndDropFiles.size() == 0)
  197120. updateDraggedFileList (clientMsg);
  197121. if (dragAndDropFiles.size() > 0)
  197122. handleFileDragMove (dragAndDropFiles, dropPos);
  197123. }
  197124. }
  197125. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197126. {
  197127. if (dragAndDropFiles.size() == 0)
  197128. updateDraggedFileList (clientMsg);
  197129. const StringArray files (dragAndDropFiles);
  197130. const Point<int> lastPos (lastDropPos);
  197131. sendDragAndDropFinish();
  197132. resetDragAndDrop();
  197133. if (files.size() > 0)
  197134. handleFileDragDrop (files, lastPos);
  197135. }
  197136. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197137. {
  197138. dragAndDropFiles.clear();
  197139. srcMimeTypeAtomList.clear();
  197140. dragAndDropCurrentMimeType = 0;
  197141. const unsigned long dndCurrentVersion = static_cast <unsigned long> (clientMsg->data.l[1] & 0xff000000) >> 24;
  197142. if (dndCurrentVersion < 3 || dndCurrentVersion > Atoms::DndVersion)
  197143. {
  197144. dragAndDropSourceWindow = 0;
  197145. return;
  197146. }
  197147. dragAndDropSourceWindow = clientMsg->data.l[0];
  197148. if ((clientMsg->data.l[1] & 1) != 0)
  197149. {
  197150. Atom actual;
  197151. int format;
  197152. unsigned long count = 0, remaining = 0;
  197153. unsigned char* data = 0;
  197154. ScopedXLock xlock;
  197155. XGetWindowProperty (display, dragAndDropSourceWindow, Atoms::XdndTypeList,
  197156. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197157. &count, &remaining, &data);
  197158. if (data != 0)
  197159. {
  197160. if (actual == XA_ATOM && format == 32 && count != 0)
  197161. {
  197162. const unsigned long* const types = (const unsigned long*) data;
  197163. for (unsigned int i = 0; i < count; ++i)
  197164. if (types[i] != None)
  197165. srcMimeTypeAtomList.add (types[i]);
  197166. }
  197167. XFree (data);
  197168. }
  197169. }
  197170. if (srcMimeTypeAtomList.size() == 0)
  197171. {
  197172. for (int i = 2; i < 5; ++i)
  197173. if (clientMsg->data.l[i] != None)
  197174. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197175. if (srcMimeTypeAtomList.size() == 0)
  197176. {
  197177. dragAndDropSourceWindow = 0;
  197178. return;
  197179. }
  197180. }
  197181. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197182. for (int j = 0; j < numElementsInArray (Atoms::allowedMimeTypes); ++j)
  197183. if (srcMimeTypeAtomList[i] == Atoms::allowedMimeTypes[j])
  197184. dragAndDropCurrentMimeType = Atoms::allowedMimeTypes[j];
  197185. handleDragAndDropPosition (clientMsg);
  197186. }
  197187. void handleDragAndDropSelection (const XEvent* const evt)
  197188. {
  197189. dragAndDropFiles.clear();
  197190. if (evt->xselection.property != 0)
  197191. {
  197192. StringArray lines;
  197193. {
  197194. MemoryBlock dropData;
  197195. for (;;)
  197196. {
  197197. Atom actual;
  197198. uint8* data = 0;
  197199. unsigned long count = 0, remaining = 0;
  197200. int format = 0;
  197201. ScopedXLock xlock;
  197202. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197203. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197204. &format, &count, &remaining, &data) == Success)
  197205. {
  197206. dropData.append (data, count * format / 8);
  197207. XFree (data);
  197208. if (remaining == 0)
  197209. break;
  197210. }
  197211. else
  197212. {
  197213. XFree (data);
  197214. break;
  197215. }
  197216. }
  197217. lines.addLines (dropData.toString());
  197218. }
  197219. for (int i = 0; i < lines.size(); ++i)
  197220. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf (T("file://"), false, true)));
  197221. dragAndDropFiles.trim();
  197222. dragAndDropFiles.removeEmptyStrings();
  197223. }
  197224. }
  197225. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197226. {
  197227. dragAndDropFiles.clear();
  197228. if (dragAndDropSourceWindow != None
  197229. && dragAndDropCurrentMimeType != 0)
  197230. {
  197231. dragAndDropTimestamp = clientMsg->data.l[2];
  197232. ScopedXLock xlock;
  197233. XConvertSelection (display,
  197234. Atoms::XdndSelection,
  197235. dragAndDropCurrentMimeType,
  197236. XInternAtom (display, "JXSelectionWindowProperty", 0),
  197237. windowH,
  197238. dragAndDropTimestamp);
  197239. }
  197240. }
  197241. StringArray dragAndDropFiles;
  197242. int dragAndDropTimestamp;
  197243. Point<int> lastDropPos;
  197244. Atom dragAndDropCurrentMimeType;
  197245. Window dragAndDropSourceWindow;
  197246. Array <Atom> srcMimeTypeAtomList;
  197247. static int pointerMap[5];
  197248. static Point<int> lastMousePos;
  197249. static void clearLastMousePos() throw()
  197250. {
  197251. lastMousePos = Point<int> (0x100000, 0x100000);
  197252. }
  197253. };
  197254. ModifierKeys LinuxComponentPeer::currentModifiers;
  197255. int LinuxComponentPeer::pointerMap[5];
  197256. Point<int> LinuxComponentPeer::lastMousePos;
  197257. void ModifierKeys::updateCurrentModifiers() throw()
  197258. {
  197259. currentModifiers = LinuxComponentPeer::currentModifiers;
  197260. }
  197261. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  197262. {
  197263. Window root, child;
  197264. int x, y, winx, winy;
  197265. unsigned int mask;
  197266. int mouseMods = 0;
  197267. ScopedXLock xlock;
  197268. if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
  197269. &root, &child, &x, &y, &winx, &winy, &mask) != False)
  197270. {
  197271. if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier;
  197272. if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier;
  197273. if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier;
  197274. }
  197275. LinuxComponentPeer::currentModifiers = LinuxComponentPeer::currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  197276. return LinuxComponentPeer::currentModifiers;
  197277. }
  197278. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197279. {
  197280. if (enableOrDisable)
  197281. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197282. }
  197283. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197284. {
  197285. return new LinuxComponentPeer (this, styleFlags);
  197286. }
  197287. // (this callback is hooked up in the messaging code)
  197288. void juce_windowMessageReceive (XEvent* event)
  197289. {
  197290. if (event->xany.window != None)
  197291. {
  197292. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197293. if (ComponentPeer::isValidPeer (peer))
  197294. peer->handleWindowMessage (event);
  197295. }
  197296. else
  197297. {
  197298. switch (event->xany.type)
  197299. {
  197300. case KeymapNotify:
  197301. {
  197302. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197303. memcpy (Keys::keyStates, keymapEvent->key_vector, 32);
  197304. break;
  197305. }
  197306. default:
  197307. break;
  197308. }
  197309. }
  197310. }
  197311. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197312. {
  197313. if (display == 0)
  197314. return;
  197315. #if JUCE_USE_XINERAMA
  197316. int major_opcode, first_event, first_error;
  197317. ScopedXLock xlock;
  197318. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197319. {
  197320. typedef Bool (*tXineramaIsActive) (Display*);
  197321. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197322. static tXineramaIsActive xXineramaIsActive = 0;
  197323. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197324. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197325. {
  197326. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197327. if (h != 0)
  197328. {
  197329. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197330. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197331. }
  197332. }
  197333. if (xXineramaIsActive != 0
  197334. && xXineramaQueryScreens != 0
  197335. && xXineramaIsActive (display))
  197336. {
  197337. int numMonitors = 0;
  197338. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197339. if (screens != 0)
  197340. {
  197341. for (int i = numMonitors; --i >= 0;)
  197342. {
  197343. int index = screens[i].screen_number;
  197344. if (index >= 0)
  197345. {
  197346. while (monitorCoords.size() < index)
  197347. monitorCoords.add (Rectangle<int>());
  197348. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197349. screens[i].y_org,
  197350. screens[i].width,
  197351. screens[i].height));
  197352. }
  197353. }
  197354. XFree (screens);
  197355. }
  197356. }
  197357. }
  197358. if (monitorCoords.size() == 0)
  197359. #endif
  197360. {
  197361. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197362. if (hints != None)
  197363. {
  197364. const int numMonitors = ScreenCount (display);
  197365. for (int i = 0; i < numMonitors; ++i)
  197366. {
  197367. Window root = RootWindow (display, i);
  197368. unsigned long nitems, bytesLeft;
  197369. Atom actualType;
  197370. int actualFormat;
  197371. unsigned char* data = 0;
  197372. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197373. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197374. &data) == Success)
  197375. {
  197376. const long* const position = (const long*) data;
  197377. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197378. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197379. position[2], position[3]));
  197380. XFree (data);
  197381. }
  197382. }
  197383. }
  197384. if (monitorCoords.size() == 0)
  197385. {
  197386. monitorCoords.add (Rectangle<int> (0, 0,
  197387. DisplayWidth (display, DefaultScreen (display)),
  197388. DisplayHeight (display, DefaultScreen (display))));
  197389. }
  197390. }
  197391. }
  197392. void Desktop::createMouseInputSources()
  197393. {
  197394. mouseSources.add (new MouseInputSource (0, true));
  197395. }
  197396. bool Desktop::canUseSemiTransparentWindows() throw()
  197397. {
  197398. int matchedDepth = 0;
  197399. const int desiredDepth = 32;
  197400. return Visuals::findVisualFormat (desiredDepth, matchedDepth) != 0
  197401. && (matchedDepth == desiredDepth);
  197402. }
  197403. const Point<int> Desktop::getMousePosition()
  197404. {
  197405. Window root, child;
  197406. int x, y, winx, winy;
  197407. unsigned int mask;
  197408. ScopedXLock xlock;
  197409. if (XQueryPointer (display,
  197410. RootWindow (display, DefaultScreen (display)),
  197411. &root, &child,
  197412. &x, &y, &winx, &winy, &mask) == False)
  197413. {
  197414. // Pointer not on the default screen
  197415. x = y = -1;
  197416. }
  197417. return Point<int> (x, y);
  197418. }
  197419. void Desktop::setMousePosition (const Point<int>& newPosition)
  197420. {
  197421. ScopedXLock xlock;
  197422. Window root = RootWindow (display, DefaultScreen (display));
  197423. XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY());
  197424. }
  197425. static bool screenSaverAllowed = true;
  197426. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197427. {
  197428. if (screenSaverAllowed != isEnabled)
  197429. {
  197430. screenSaverAllowed = isEnabled;
  197431. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197432. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197433. if (xScreenSaverSuspend == 0)
  197434. {
  197435. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197436. if (h != 0)
  197437. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197438. }
  197439. ScopedXLock xlock;
  197440. if (xScreenSaverSuspend != 0)
  197441. xScreenSaverSuspend (display, ! isEnabled);
  197442. }
  197443. }
  197444. bool Desktop::isScreenSaverEnabled() throw()
  197445. {
  197446. return screenSaverAllowed;
  197447. }
  197448. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197449. {
  197450. ScopedXLock xlock;
  197451. Window root = RootWindow (display, DefaultScreen (display));
  197452. const unsigned int imageW = image.getWidth();
  197453. const unsigned int imageH = image.getHeight();
  197454. unsigned int cursorW, cursorH;
  197455. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197456. return 0;
  197457. Image im (Image::ARGB, cursorW, cursorH, true);
  197458. Graphics g (im);
  197459. if (imageW > cursorW || imageH > cursorH)
  197460. {
  197461. hotspotX = (hotspotX * cursorW) / imageW;
  197462. hotspotY = (hotspotY * cursorH) / imageH;
  197463. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197464. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197465. false);
  197466. }
  197467. else
  197468. {
  197469. g.drawImageAt (&image, 0, 0);
  197470. }
  197471. const int stride = (cursorW + 7) >> 3;
  197472. HeapBlock <uint8> maskPlane, sourcePlane;
  197473. maskPlane.calloc (stride * cursorH);
  197474. sourcePlane.calloc (stride * cursorH);
  197475. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197476. for (int y = cursorH; --y >= 0;)
  197477. {
  197478. for (int x = cursorW; --x >= 0;)
  197479. {
  197480. const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197481. const int offset = y * stride + (x >> 3);
  197482. const Colour c (im.getPixelAt (x, y));
  197483. if (c.getAlpha() >= 128)
  197484. maskPlane[offset] |= mask;
  197485. if (c.getBrightness() >= 0.5f)
  197486. sourcePlane[offset] |= mask;
  197487. }
  197488. }
  197489. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast <char*> (sourcePlane.getData()), cursorW, cursorH, 0xffff, 0, 1);
  197490. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, reinterpret_cast <char*> (maskPlane.getData()), cursorW, cursorH, 0xffff, 0, 1);
  197491. XColor white, black;
  197492. black.red = black.green = black.blue = 0;
  197493. white.red = white.green = white.blue = 0xffff;
  197494. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197495. XFreePixmap (display, sourcePixmap);
  197496. XFreePixmap (display, maskPixmap);
  197497. return result;
  197498. }
  197499. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197500. {
  197501. ScopedXLock xlock;
  197502. if (cursorHandle != None)
  197503. XFreeCursor (display, (Cursor) cursorHandle);
  197504. }
  197505. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197506. {
  197507. unsigned int shape;
  197508. switch (type)
  197509. {
  197510. case MouseCursor::NoCursor:
  197511. {
  197512. const Image im (Image::ARGB, 16, 16, true);
  197513. return juce_createMouseCursorFromImage (im, 0, 0);
  197514. }
  197515. case MouseCursor::NormalCursor:
  197516. return (void*) None; // Use parent cursor
  197517. case MouseCursor::DraggingHandCursor:
  197518. {
  197519. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197520. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197521. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197522. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197523. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197524. const int dragHandDataSize = 99;
  197525. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) dragHandData, dragHandDataSize));
  197526. return juce_createMouseCursorFromImage (*im, 8, 7);
  197527. }
  197528. case MouseCursor::CopyingCursor:
  197529. {
  197530. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197531. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197532. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197533. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197534. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197535. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197536. const int copyCursorSize = 119;
  197537. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) copyCursorData, copyCursorSize));
  197538. return juce_createMouseCursorFromImage (*im, 1, 3);
  197539. }
  197540. case MouseCursor::WaitCursor:
  197541. shape = XC_watch;
  197542. break;
  197543. case MouseCursor::IBeamCursor:
  197544. shape = XC_xterm;
  197545. break;
  197546. case MouseCursor::PointingHandCursor:
  197547. shape = XC_hand2;
  197548. break;
  197549. case MouseCursor::LeftRightResizeCursor:
  197550. shape = XC_sb_h_double_arrow;
  197551. break;
  197552. case MouseCursor::UpDownResizeCursor:
  197553. shape = XC_sb_v_double_arrow;
  197554. break;
  197555. case MouseCursor::UpDownLeftRightResizeCursor:
  197556. shape = XC_fleur;
  197557. break;
  197558. case MouseCursor::TopEdgeResizeCursor:
  197559. shape = XC_top_side;
  197560. break;
  197561. case MouseCursor::BottomEdgeResizeCursor:
  197562. shape = XC_bottom_side;
  197563. break;
  197564. case MouseCursor::LeftEdgeResizeCursor:
  197565. shape = XC_left_side;
  197566. break;
  197567. case MouseCursor::RightEdgeResizeCursor:
  197568. shape = XC_right_side;
  197569. break;
  197570. case MouseCursor::TopLeftCornerResizeCursor:
  197571. shape = XC_top_left_corner;
  197572. break;
  197573. case MouseCursor::TopRightCornerResizeCursor:
  197574. shape = XC_top_right_corner;
  197575. break;
  197576. case MouseCursor::BottomLeftCornerResizeCursor:
  197577. shape = XC_bottom_left_corner;
  197578. break;
  197579. case MouseCursor::BottomRightCornerResizeCursor:
  197580. shape = XC_bottom_right_corner;
  197581. break;
  197582. case MouseCursor::CrosshairCursor:
  197583. shape = XC_crosshair;
  197584. break;
  197585. default:
  197586. return (void*) None; // Use parent cursor
  197587. }
  197588. ScopedXLock xlock;
  197589. return (void*) XCreateFontCursor (display, shape);
  197590. }
  197591. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  197592. {
  197593. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197594. if (lp != 0)
  197595. lp->showMouseCursor ((Cursor) getHandle());
  197596. }
  197597. void MouseCursor::showInAllWindows() const throw()
  197598. {
  197599. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197600. showInWindow (ComponentPeer::getPeer (i));
  197601. }
  197602. Image* juce_createIconForFile (const File& file)
  197603. {
  197604. return 0;
  197605. }
  197606. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197607. {
  197608. return new Image (format, imageWidth, imageHeight, clearImage);
  197609. }
  197610. #if JUCE_OPENGL
  197611. class WindowedGLContext : public OpenGLContext
  197612. {
  197613. public:
  197614. WindowedGLContext (Component* const component,
  197615. const OpenGLPixelFormat& pixelFormat_,
  197616. GLXContext sharedContext)
  197617. : renderContext (0),
  197618. embeddedWindow (0),
  197619. pixelFormat (pixelFormat_)
  197620. {
  197621. jassert (component != 0);
  197622. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197623. if (peer == 0)
  197624. return;
  197625. ScopedXLock xlock;
  197626. XSync (display, False);
  197627. GLint attribs [64];
  197628. int n = 0;
  197629. attribs[n++] = GLX_RGBA;
  197630. attribs[n++] = GLX_DOUBLEBUFFER;
  197631. attribs[n++] = GLX_RED_SIZE;
  197632. attribs[n++] = pixelFormat.redBits;
  197633. attribs[n++] = GLX_GREEN_SIZE;
  197634. attribs[n++] = pixelFormat.greenBits;
  197635. attribs[n++] = GLX_BLUE_SIZE;
  197636. attribs[n++] = pixelFormat.blueBits;
  197637. attribs[n++] = GLX_ALPHA_SIZE;
  197638. attribs[n++] = pixelFormat.alphaBits;
  197639. attribs[n++] = GLX_DEPTH_SIZE;
  197640. attribs[n++] = pixelFormat.depthBufferBits;
  197641. attribs[n++] = GLX_STENCIL_SIZE;
  197642. attribs[n++] = pixelFormat.stencilBufferBits;
  197643. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197644. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197645. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197646. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197647. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197648. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197649. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197650. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197651. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197652. attribs[n++] = None;
  197653. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197654. if (bestVisual == 0)
  197655. return;
  197656. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197657. Window windowH = (Window) peer->getNativeHandle();
  197658. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197659. XSetWindowAttributes swa;
  197660. swa.colormap = colourMap;
  197661. swa.border_pixel = 0;
  197662. swa.event_mask = ExposureMask | StructureNotifyMask;
  197663. embeddedWindow = XCreateWindow (display, windowH,
  197664. 0, 0, 1, 1, 0,
  197665. bestVisual->depth,
  197666. InputOutput,
  197667. bestVisual->visual,
  197668. CWBorderPixel | CWColormap | CWEventMask,
  197669. &swa);
  197670. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197671. XMapWindow (display, embeddedWindow);
  197672. XFreeColormap (display, colourMap);
  197673. XFree (bestVisual);
  197674. XSync (display, False);
  197675. }
  197676. ~WindowedGLContext()
  197677. {
  197678. makeInactive();
  197679. ScopedXLock xlock;
  197680. glXDestroyContext (display, renderContext);
  197681. XUnmapWindow (display, embeddedWindow);
  197682. XDestroyWindow (display, embeddedWindow);
  197683. }
  197684. bool makeActive() const throw()
  197685. {
  197686. jassert (renderContext != 0);
  197687. ScopedXLock xlock;
  197688. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197689. && XSync (display, False);
  197690. }
  197691. bool makeInactive() const throw()
  197692. {
  197693. ScopedXLock xlock;
  197694. return (! isActive()) || glXMakeCurrent (display, None, 0);
  197695. }
  197696. bool isActive() const throw()
  197697. {
  197698. ScopedXLock xlock;
  197699. return glXGetCurrentContext() == renderContext;
  197700. }
  197701. const OpenGLPixelFormat getPixelFormat() const
  197702. {
  197703. return pixelFormat;
  197704. }
  197705. void* getRawContext() const throw()
  197706. {
  197707. return renderContext;
  197708. }
  197709. void updateWindowPosition (int x, int y, int w, int h, int)
  197710. {
  197711. ScopedXLock xlock;
  197712. XMoveResizeWindow (display, embeddedWindow,
  197713. x, y, jmax (1, w), jmax (1, h));
  197714. }
  197715. void swapBuffers()
  197716. {
  197717. ScopedXLock xlock;
  197718. glXSwapBuffers (display, embeddedWindow);
  197719. }
  197720. bool setSwapInterval (const int numFramesPerSwap)
  197721. {
  197722. // xxx needs doing..
  197723. return false;
  197724. }
  197725. int getSwapInterval() const
  197726. {
  197727. // xxx needs doing..
  197728. return 0;
  197729. }
  197730. void repaint()
  197731. {
  197732. }
  197733. juce_UseDebuggingNewOperator
  197734. GLXContext renderContext;
  197735. private:
  197736. Window embeddedWindow;
  197737. OpenGLPixelFormat pixelFormat;
  197738. WindowedGLContext (const WindowedGLContext&);
  197739. WindowedGLContext& operator= (const WindowedGLContext&);
  197740. };
  197741. OpenGLContext* OpenGLComponent::createContext()
  197742. {
  197743. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  197744. contextToShareListsWith != 0 ? (GLXContext) contextToShareListsWith->getRawContext() : 0));
  197745. return (c->renderContext != 0) ? c.release() : 0;
  197746. }
  197747. void juce_glViewport (const int w, const int h)
  197748. {
  197749. glViewport (0, 0, w, h);
  197750. }
  197751. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  197752. OwnedArray <OpenGLPixelFormat>& results)
  197753. {
  197754. results.add (new OpenGLPixelFormat()); // xxx
  197755. }
  197756. #endif
  197757. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  197758. {
  197759. jassertfalse // not implemented!
  197760. return false;
  197761. }
  197762. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  197763. {
  197764. jassertfalse // not implemented!
  197765. return false;
  197766. }
  197767. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  197768. {
  197769. if (! isOnDesktop ())
  197770. addToDesktop (0);
  197771. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197772. if (wp != 0)
  197773. {
  197774. wp->setTaskBarIcon (newImage);
  197775. setVisible (true);
  197776. toFront (false);
  197777. repaint();
  197778. }
  197779. }
  197780. void SystemTrayIconComponent::paint (Graphics& g)
  197781. {
  197782. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197783. if (wp != 0)
  197784. {
  197785. const Image* const image = wp->getTaskbarIcon();
  197786. if (image != 0)
  197787. {
  197788. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  197789. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197790. false);
  197791. }
  197792. }
  197793. }
  197794. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  197795. {
  197796. // xxx not yet implemented!
  197797. }
  197798. void PlatformUtilities::beep()
  197799. {
  197800. std::cout << "\a" << std::flush;
  197801. }
  197802. bool AlertWindow::showNativeDialogBox (const String& title,
  197803. const String& bodyText,
  197804. bool isOkCancel)
  197805. {
  197806. // use a non-native one for the time being..
  197807. if (isOkCancel)
  197808. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  197809. else
  197810. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  197811. return true;
  197812. }
  197813. const int KeyPress::spaceKey = XK_space & 0xff;
  197814. const int KeyPress::returnKey = XK_Return & 0xff;
  197815. const int KeyPress::escapeKey = XK_Escape & 0xff;
  197816. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  197817. const int KeyPress::leftKey = (XK_Left & 0xff) | Keys::extendedKeyModifier;
  197818. const int KeyPress::rightKey = (XK_Right & 0xff) | Keys::extendedKeyModifier;
  197819. const int KeyPress::upKey = (XK_Up & 0xff) | Keys::extendedKeyModifier;
  197820. const int KeyPress::downKey = (XK_Down & 0xff) | Keys::extendedKeyModifier;
  197821. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | Keys::extendedKeyModifier;
  197822. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | Keys::extendedKeyModifier;
  197823. const int KeyPress::endKey = (XK_End & 0xff) | Keys::extendedKeyModifier;
  197824. const int KeyPress::homeKey = (XK_Home & 0xff) | Keys::extendedKeyModifier;
  197825. const int KeyPress::insertKey = (XK_Insert & 0xff) | Keys::extendedKeyModifier;
  197826. const int KeyPress::deleteKey = (XK_Delete & 0xff) | Keys::extendedKeyModifier;
  197827. const int KeyPress::tabKey = XK_Tab & 0xff;
  197828. const int KeyPress::F1Key = (XK_F1 & 0xff) | Keys::extendedKeyModifier;
  197829. const int KeyPress::F2Key = (XK_F2 & 0xff) | Keys::extendedKeyModifier;
  197830. const int KeyPress::F3Key = (XK_F3 & 0xff) | Keys::extendedKeyModifier;
  197831. const int KeyPress::F4Key = (XK_F4 & 0xff) | Keys::extendedKeyModifier;
  197832. const int KeyPress::F5Key = (XK_F5 & 0xff) | Keys::extendedKeyModifier;
  197833. const int KeyPress::F6Key = (XK_F6 & 0xff) | Keys::extendedKeyModifier;
  197834. const int KeyPress::F7Key = (XK_F7 & 0xff) | Keys::extendedKeyModifier;
  197835. const int KeyPress::F8Key = (XK_F8 & 0xff) | Keys::extendedKeyModifier;
  197836. const int KeyPress::F9Key = (XK_F9 & 0xff) | Keys::extendedKeyModifier;
  197837. const int KeyPress::F10Key = (XK_F10 & 0xff) | Keys::extendedKeyModifier;
  197838. const int KeyPress::F11Key = (XK_F11 & 0xff) | Keys::extendedKeyModifier;
  197839. const int KeyPress::F12Key = (XK_F12 & 0xff) | Keys::extendedKeyModifier;
  197840. const int KeyPress::F13Key = (XK_F13 & 0xff) | Keys::extendedKeyModifier;
  197841. const int KeyPress::F14Key = (XK_F14 & 0xff) | Keys::extendedKeyModifier;
  197842. const int KeyPress::F15Key = (XK_F15 & 0xff) | Keys::extendedKeyModifier;
  197843. const int KeyPress::F16Key = (XK_F16 & 0xff) | Keys::extendedKeyModifier;
  197844. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | Keys::extendedKeyModifier;
  197845. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | Keys::extendedKeyModifier;
  197846. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | Keys::extendedKeyModifier;
  197847. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | Keys::extendedKeyModifier;
  197848. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | Keys::extendedKeyModifier;
  197849. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | Keys::extendedKeyModifier;
  197850. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | Keys::extendedKeyModifier;
  197851. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| Keys::extendedKeyModifier;
  197852. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| Keys::extendedKeyModifier;
  197853. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| Keys::extendedKeyModifier;
  197854. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| Keys::extendedKeyModifier;
  197855. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| Keys::extendedKeyModifier;
  197856. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| Keys::extendedKeyModifier;
  197857. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| Keys::extendedKeyModifier;
  197858. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| Keys::extendedKeyModifier;
  197859. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| Keys::extendedKeyModifier;
  197860. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| Keys::extendedKeyModifier;
  197861. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| Keys::extendedKeyModifier;
  197862. const int KeyPress::playKey = (0xffeeff00) | Keys::extendedKeyModifier;
  197863. const int KeyPress::stopKey = (0xffeeff01) | Keys::extendedKeyModifier;
  197864. const int KeyPress::fastForwardKey = (0xffeeff02) | Keys::extendedKeyModifier;
  197865. const int KeyPress::rewindKey = (0xffeeff03) | Keys::extendedKeyModifier;
  197866. #endif
  197867. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  197868. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  197869. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  197870. // compiled on its own).
  197871. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  197872. static const int maxNumChans = 64;
  197873. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  197874. {
  197875. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  197876. snd_pcm_hw_params_t* hwParams;
  197877. snd_pcm_hw_params_alloca (&hwParams);
  197878. for (int i = 0; ratesToTry[i] != 0; ++i)
  197879. {
  197880. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  197881. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  197882. {
  197883. rates.addIfNotAlreadyThere (ratesToTry[i]);
  197884. }
  197885. }
  197886. }
  197887. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  197888. {
  197889. snd_pcm_hw_params_t *params;
  197890. snd_pcm_hw_params_alloca (&params);
  197891. if (snd_pcm_hw_params_any (handle, params) >= 0)
  197892. {
  197893. snd_pcm_hw_params_get_channels_min (params, minChans);
  197894. snd_pcm_hw_params_get_channels_max (params, maxChans);
  197895. }
  197896. }
  197897. static void getDeviceProperties (const String& deviceID,
  197898. unsigned int& minChansOut,
  197899. unsigned int& maxChansOut,
  197900. unsigned int& minChansIn,
  197901. unsigned int& maxChansIn,
  197902. Array <int>& rates)
  197903. {
  197904. if (deviceID.isEmpty())
  197905. return;
  197906. snd_ctl_t* handle;
  197907. if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (T(","), false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  197908. {
  197909. snd_pcm_info_t* info;
  197910. snd_pcm_info_alloca (&info);
  197911. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  197912. snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (T(","), false, false).getIntValue());
  197913. snd_pcm_info_set_subdevice (info, 0);
  197914. if (snd_ctl_pcm_info (handle, info) >= 0)
  197915. {
  197916. snd_pcm_t* pcmHandle;
  197917. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197918. {
  197919. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  197920. getDeviceSampleRates (pcmHandle, rates);
  197921. snd_pcm_close (pcmHandle);
  197922. }
  197923. }
  197924. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  197925. if (snd_ctl_pcm_info (handle, info) >= 0)
  197926. {
  197927. snd_pcm_t* pcmHandle;
  197928. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197929. {
  197930. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  197931. if (rates.size() == 0)
  197932. getDeviceSampleRates (pcmHandle, rates);
  197933. snd_pcm_close (pcmHandle);
  197934. }
  197935. }
  197936. snd_ctl_close (handle);
  197937. }
  197938. }
  197939. class ALSADevice
  197940. {
  197941. public:
  197942. ALSADevice (const String& deviceID,
  197943. const bool forInput)
  197944. : handle (0),
  197945. bitDepth (16),
  197946. numChannelsRunning (0),
  197947. isInput (forInput),
  197948. sampleFormat (AudioDataConverters::int16LE)
  197949. {
  197950. failed (snd_pcm_open (&handle, deviceID.toUTF8(),
  197951. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  197952. SND_PCM_ASYNC));
  197953. }
  197954. ~ALSADevice()
  197955. {
  197956. if (handle != 0)
  197957. snd_pcm_close (handle);
  197958. }
  197959. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  197960. {
  197961. if (handle == 0)
  197962. return false;
  197963. snd_pcm_hw_params_t* hwParams;
  197964. snd_pcm_hw_params_alloca (&hwParams);
  197965. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  197966. return false;
  197967. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  197968. isInterleaved = false;
  197969. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  197970. isInterleaved = true;
  197971. else
  197972. {
  197973. jassertfalse
  197974. return false;
  197975. }
  197976. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  197977. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  197978. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  197979. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  197980. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  197981. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  197982. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  197983. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  197984. bitDepth = 0;
  197985. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  197986. {
  197987. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  197988. {
  197989. bitDepth = formatsToTry [i + 1];
  197990. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  197991. break;
  197992. }
  197993. }
  197994. if (bitDepth == 0)
  197995. {
  197996. error = "device doesn't support a compatible PCM format";
  197997. DBG (T("ALSA error: ") + error + T("\n"));
  197998. return false;
  197999. }
  198000. int dir = 0;
  198001. unsigned int periods = 4;
  198002. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  198003. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  198004. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  198005. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  198006. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  198007. || failed (snd_pcm_hw_params (handle, hwParams)))
  198008. {
  198009. return false;
  198010. }
  198011. snd_pcm_sw_params_t* swParams;
  198012. snd_pcm_sw_params_alloca (&swParams);
  198013. snd_pcm_uframes_t boundary;
  198014. if (failed (snd_pcm_sw_params_current (handle, swParams))
  198015. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  198016. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  198017. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  198018. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  198019. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  198020. || failed (snd_pcm_sw_params (handle, swParams)))
  198021. {
  198022. return false;
  198023. }
  198024. numChannelsRunning = numChannels;
  198025. return true;
  198026. }
  198027. bool write (float** const data, const int numSamples)
  198028. {
  198029. if (isInterleaved)
  198030. {
  198031. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198032. float* interleaved = reinterpret_cast <float*> (scratch.getData());
  198033. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  198034. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198035. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  198036. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198037. return false;
  198038. }
  198039. else
  198040. {
  198041. for (int i = 0; i < numChannelsRunning; ++i)
  198042. if (data[i] != 0)
  198043. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  198044. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  198045. if (failed (num))
  198046. {
  198047. if (num == -EPIPE)
  198048. {
  198049. if (failed (snd_pcm_prepare (handle)))
  198050. return false;
  198051. }
  198052. else if (num != -ESTRPIPE)
  198053. return false;
  198054. }
  198055. }
  198056. return true;
  198057. }
  198058. bool read (float** const data, const int numSamples)
  198059. {
  198060. if (isInterleaved)
  198061. {
  198062. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198063. float* interleaved = reinterpret_cast <float*> (scratch.getData());
  198064. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  198065. if (failed (num))
  198066. {
  198067. if (num == -EPIPE)
  198068. {
  198069. if (failed (snd_pcm_prepare (handle)))
  198070. return false;
  198071. }
  198072. else if (num != -ESTRPIPE)
  198073. return false;
  198074. }
  198075. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198076. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198077. }
  198078. else
  198079. {
  198080. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198081. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198082. return false;
  198083. for (int i = 0; i < numChannelsRunning; ++i)
  198084. if (data[i] != 0)
  198085. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198086. }
  198087. return true;
  198088. }
  198089. juce_UseDebuggingNewOperator
  198090. snd_pcm_t* handle;
  198091. String error;
  198092. int bitDepth, numChannelsRunning;
  198093. private:
  198094. const bool isInput;
  198095. bool isInterleaved;
  198096. MemoryBlock scratch;
  198097. AudioDataConverters::DataFormat sampleFormat;
  198098. bool failed (const int errorNum)
  198099. {
  198100. if (errorNum >= 0)
  198101. return false;
  198102. error = snd_strerror (errorNum);
  198103. DBG (T("ALSA error: ") + error + T("\n"));
  198104. return true;
  198105. }
  198106. };
  198107. class ALSAThread : public Thread
  198108. {
  198109. public:
  198110. ALSAThread (const String& inputId_,
  198111. const String& outputId_)
  198112. : Thread ("Juce ALSA"),
  198113. sampleRate (0),
  198114. bufferSize (0),
  198115. callback (0),
  198116. inputId (inputId_),
  198117. outputId (outputId_),
  198118. outputDevice (0),
  198119. inputDevice (0),
  198120. numCallbacks (0),
  198121. totalNumInputChannels (0),
  198122. totalNumOutputChannels (0)
  198123. {
  198124. zeromem (outputChannelData, sizeof (outputChannelData));
  198125. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198126. zeromem (inputChannelData, sizeof (inputChannelData));
  198127. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198128. initialiseRatesAndChannels();
  198129. }
  198130. ~ALSAThread()
  198131. {
  198132. close();
  198133. }
  198134. void open (BigInteger inputChannels,
  198135. BigInteger outputChannels,
  198136. const double sampleRate_,
  198137. const int bufferSize_)
  198138. {
  198139. close();
  198140. error = String::empty;
  198141. sampleRate = sampleRate_;
  198142. bufferSize = bufferSize_;
  198143. currentInputChans.clear();
  198144. currentOutputChans.clear();
  198145. if (inputChannels.getHighestBit() >= 0)
  198146. {
  198147. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198148. {
  198149. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198150. if (inputChannels[i])
  198151. {
  198152. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198153. currentInputChans.setBit (i);
  198154. }
  198155. }
  198156. }
  198157. if (outputChannels.getHighestBit() >= 0)
  198158. {
  198159. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198160. {
  198161. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198162. if (outputChannels[i])
  198163. {
  198164. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198165. currentOutputChans.setBit (i);
  198166. }
  198167. }
  198168. }
  198169. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198170. {
  198171. outputDevice = new ALSADevice (outputId, false);
  198172. if (outputDevice->error.isNotEmpty())
  198173. {
  198174. error = outputDevice->error;
  198175. deleteAndZero (outputDevice);
  198176. return;
  198177. }
  198178. currentOutputChans.setRange (0, minChansOut, true);
  198179. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198180. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198181. bufferSize))
  198182. {
  198183. error = outputDevice->error;
  198184. deleteAndZero (outputDevice);
  198185. return;
  198186. }
  198187. }
  198188. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198189. {
  198190. inputDevice = new ALSADevice (inputId, true);
  198191. if (inputDevice->error.isNotEmpty())
  198192. {
  198193. error = inputDevice->error;
  198194. deleteAndZero (inputDevice);
  198195. return;
  198196. }
  198197. currentInputChans.setRange (0, minChansIn, true);
  198198. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198199. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198200. bufferSize))
  198201. {
  198202. error = inputDevice->error;
  198203. deleteAndZero (inputDevice);
  198204. return;
  198205. }
  198206. }
  198207. if (outputDevice == 0 && inputDevice == 0)
  198208. {
  198209. error = "no channels";
  198210. return;
  198211. }
  198212. if (outputDevice != 0 && inputDevice != 0)
  198213. {
  198214. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198215. }
  198216. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198217. return;
  198218. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198219. return;
  198220. startThread (9);
  198221. int count = 1000;
  198222. while (numCallbacks == 0)
  198223. {
  198224. sleep (5);
  198225. if (--count < 0 || ! isThreadRunning())
  198226. {
  198227. error = "device didn't start";
  198228. break;
  198229. }
  198230. }
  198231. }
  198232. void close()
  198233. {
  198234. stopThread (6000);
  198235. deleteAndZero (inputDevice);
  198236. deleteAndZero (outputDevice);
  198237. for (int i = 0; i < maxNumChans; ++i)
  198238. {
  198239. juce_free (inputChannelData [i]);
  198240. juce_free (outputChannelData [i]);
  198241. }
  198242. zeromem (outputChannelData, sizeof (outputChannelData));
  198243. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198244. zeromem (inputChannelData, sizeof (inputChannelData));
  198245. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198246. totalNumOutputChannels = 0;
  198247. totalNumInputChannels = 0;
  198248. numCallbacks = 0;
  198249. }
  198250. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198251. {
  198252. const ScopedLock sl (callbackLock);
  198253. callback = newCallback;
  198254. }
  198255. void run()
  198256. {
  198257. while (! threadShouldExit())
  198258. {
  198259. if (inputDevice != 0)
  198260. {
  198261. if (! inputDevice->read (inputChannelData, bufferSize))
  198262. {
  198263. DBG ("ALSA: read failure");
  198264. break;
  198265. }
  198266. }
  198267. if (threadShouldExit())
  198268. break;
  198269. {
  198270. const ScopedLock sl (callbackLock);
  198271. ++numCallbacks;
  198272. if (callback != 0)
  198273. {
  198274. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198275. totalNumInputChannels,
  198276. outputChannelDataForCallback,
  198277. totalNumOutputChannels,
  198278. bufferSize);
  198279. }
  198280. else
  198281. {
  198282. for (int i = 0; i < totalNumOutputChannels; ++i)
  198283. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198284. }
  198285. }
  198286. if (outputDevice != 0)
  198287. {
  198288. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198289. if (threadShouldExit())
  198290. break;
  198291. failed (snd_pcm_avail_update (outputDevice->handle));
  198292. if (! outputDevice->write (outputChannelData, bufferSize))
  198293. {
  198294. DBG ("ALSA: write failure");
  198295. break;
  198296. }
  198297. }
  198298. }
  198299. }
  198300. int getBitDepth() const throw()
  198301. {
  198302. if (outputDevice != 0)
  198303. return outputDevice->bitDepth;
  198304. if (inputDevice != 0)
  198305. return inputDevice->bitDepth;
  198306. return 16;
  198307. }
  198308. juce_UseDebuggingNewOperator
  198309. String error;
  198310. double sampleRate;
  198311. int bufferSize;
  198312. BigInteger currentInputChans, currentOutputChans;
  198313. Array <int> sampleRates;
  198314. StringArray channelNamesOut, channelNamesIn;
  198315. AudioIODeviceCallback* callback;
  198316. private:
  198317. const String inputId, outputId;
  198318. ALSADevice* outputDevice;
  198319. ALSADevice* inputDevice;
  198320. int numCallbacks;
  198321. CriticalSection callbackLock;
  198322. float* outputChannelData [maxNumChans];
  198323. float* outputChannelDataForCallback [maxNumChans];
  198324. int totalNumInputChannels;
  198325. float* inputChannelData [maxNumChans];
  198326. float* inputChannelDataForCallback [maxNumChans];
  198327. int totalNumOutputChannels;
  198328. unsigned int minChansOut, maxChansOut;
  198329. unsigned int minChansIn, maxChansIn;
  198330. bool failed (const int errorNum) throw()
  198331. {
  198332. if (errorNum >= 0)
  198333. return false;
  198334. error = snd_strerror (errorNum);
  198335. DBG (T("ALSA error: ") + error + T("\n"));
  198336. return true;
  198337. }
  198338. void initialiseRatesAndChannels() throw()
  198339. {
  198340. sampleRates.clear();
  198341. channelNamesOut.clear();
  198342. channelNamesIn.clear();
  198343. minChansOut = 0;
  198344. maxChansOut = 0;
  198345. minChansIn = 0;
  198346. maxChansIn = 0;
  198347. unsigned int dummy = 0;
  198348. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198349. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198350. unsigned int i;
  198351. for (i = 0; i < maxChansOut; ++i)
  198352. channelNamesOut.add (T("channel ") + String ((int) i + 1));
  198353. for (i = 0; i < maxChansIn; ++i)
  198354. channelNamesIn.add (T("channel ") + String ((int) i + 1));
  198355. }
  198356. };
  198357. class ALSAAudioIODevice : public AudioIODevice
  198358. {
  198359. public:
  198360. ALSAAudioIODevice (const String& deviceName,
  198361. const String& inputId_,
  198362. const String& outputId_)
  198363. : AudioIODevice (deviceName, T("ALSA")),
  198364. inputId (inputId_),
  198365. outputId (outputId_),
  198366. isOpen_ (false),
  198367. isStarted (false),
  198368. internal (0)
  198369. {
  198370. internal = new ALSAThread (inputId, outputId);
  198371. }
  198372. ~ALSAAudioIODevice()
  198373. {
  198374. delete internal;
  198375. }
  198376. const StringArray getOutputChannelNames()
  198377. {
  198378. return internal->channelNamesOut;
  198379. }
  198380. const StringArray getInputChannelNames()
  198381. {
  198382. return internal->channelNamesIn;
  198383. }
  198384. int getNumSampleRates()
  198385. {
  198386. return internal->sampleRates.size();
  198387. }
  198388. double getSampleRate (int index)
  198389. {
  198390. return internal->sampleRates [index];
  198391. }
  198392. int getNumBufferSizesAvailable()
  198393. {
  198394. return 50;
  198395. }
  198396. int getBufferSizeSamples (int index)
  198397. {
  198398. int n = 16;
  198399. for (int i = 0; i < index; ++i)
  198400. n += n < 64 ? 16
  198401. : (n < 512 ? 32
  198402. : (n < 1024 ? 64
  198403. : (n < 2048 ? 128 : 256)));
  198404. return n;
  198405. }
  198406. int getDefaultBufferSize()
  198407. {
  198408. return 512;
  198409. }
  198410. const String open (const BigInteger& inputChannels,
  198411. const BigInteger& outputChannels,
  198412. double sampleRate,
  198413. int bufferSizeSamples)
  198414. {
  198415. close();
  198416. if (bufferSizeSamples <= 0)
  198417. bufferSizeSamples = getDefaultBufferSize();
  198418. if (sampleRate <= 0)
  198419. {
  198420. for (int i = 0; i < getNumSampleRates(); ++i)
  198421. {
  198422. if (getSampleRate (i) >= 44100)
  198423. {
  198424. sampleRate = getSampleRate (i);
  198425. break;
  198426. }
  198427. }
  198428. }
  198429. internal->open (inputChannels, outputChannels,
  198430. sampleRate, bufferSizeSamples);
  198431. isOpen_ = internal->error.isEmpty();
  198432. return internal->error;
  198433. }
  198434. void close()
  198435. {
  198436. stop();
  198437. internal->close();
  198438. isOpen_ = false;
  198439. }
  198440. bool isOpen()
  198441. {
  198442. return isOpen_;
  198443. }
  198444. int getCurrentBufferSizeSamples()
  198445. {
  198446. return internal->bufferSize;
  198447. }
  198448. double getCurrentSampleRate()
  198449. {
  198450. return internal->sampleRate;
  198451. }
  198452. int getCurrentBitDepth()
  198453. {
  198454. return internal->getBitDepth();
  198455. }
  198456. const BigInteger getActiveOutputChannels() const
  198457. {
  198458. return internal->currentOutputChans;
  198459. }
  198460. const BigInteger getActiveInputChannels() const
  198461. {
  198462. return internal->currentInputChans;
  198463. }
  198464. int getOutputLatencyInSamples()
  198465. {
  198466. return 0;
  198467. }
  198468. int getInputLatencyInSamples()
  198469. {
  198470. return 0;
  198471. }
  198472. void start (AudioIODeviceCallback* callback)
  198473. {
  198474. if (! isOpen_)
  198475. callback = 0;
  198476. internal->setCallback (callback);
  198477. if (callback != 0)
  198478. callback->audioDeviceAboutToStart (this);
  198479. isStarted = (callback != 0);
  198480. }
  198481. void stop()
  198482. {
  198483. AudioIODeviceCallback* const oldCallback = internal->callback;
  198484. start (0);
  198485. if (oldCallback != 0)
  198486. oldCallback->audioDeviceStopped();
  198487. }
  198488. bool isPlaying()
  198489. {
  198490. return isStarted && internal->error.isEmpty();
  198491. }
  198492. const String getLastError()
  198493. {
  198494. return internal->error;
  198495. }
  198496. String inputId, outputId;
  198497. private:
  198498. bool isOpen_, isStarted;
  198499. ALSAThread* internal;
  198500. };
  198501. class ALSAAudioIODeviceType : public AudioIODeviceType
  198502. {
  198503. public:
  198504. ALSAAudioIODeviceType()
  198505. : AudioIODeviceType (T("ALSA")),
  198506. hasScanned (false)
  198507. {
  198508. }
  198509. ~ALSAAudioIODeviceType()
  198510. {
  198511. }
  198512. void scanForDevices()
  198513. {
  198514. if (hasScanned)
  198515. return;
  198516. hasScanned = true;
  198517. inputNames.clear();
  198518. inputIds.clear();
  198519. outputNames.clear();
  198520. outputIds.clear();
  198521. snd_ctl_t* handle;
  198522. snd_ctl_card_info_t* info;
  198523. snd_ctl_card_info_alloca (&info);
  198524. int cardNum = -1;
  198525. while (outputIds.size() + inputIds.size() <= 32)
  198526. {
  198527. snd_card_next (&cardNum);
  198528. if (cardNum < 0)
  198529. break;
  198530. if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198531. {
  198532. if (snd_ctl_card_info (handle, info) >= 0)
  198533. {
  198534. String cardId (snd_ctl_card_info_get_id (info));
  198535. if (cardId.removeCharacters (T("0123456789")).isEmpty())
  198536. cardId = String (cardNum);
  198537. int device = -1;
  198538. for (;;)
  198539. {
  198540. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198541. break;
  198542. String id, name;
  198543. id << "hw:" << cardId << ',' << device;
  198544. bool isInput, isOutput;
  198545. if (testDevice (id, isInput, isOutput))
  198546. {
  198547. name << snd_ctl_card_info_get_name (info);
  198548. if (name.isEmpty())
  198549. name = id;
  198550. if (isInput)
  198551. {
  198552. inputNames.add (name);
  198553. inputIds.add (id);
  198554. }
  198555. if (isOutput)
  198556. {
  198557. outputNames.add (name);
  198558. outputIds.add (id);
  198559. }
  198560. }
  198561. }
  198562. }
  198563. snd_ctl_close (handle);
  198564. }
  198565. }
  198566. inputNames.appendNumbersToDuplicates (false, true);
  198567. outputNames.appendNumbersToDuplicates (false, true);
  198568. }
  198569. const StringArray getDeviceNames (const bool wantInputNames) const
  198570. {
  198571. jassert (hasScanned); // need to call scanForDevices() before doing this
  198572. return wantInputNames ? inputNames : outputNames;
  198573. }
  198574. int getDefaultDeviceIndex (const bool forInput) const
  198575. {
  198576. jassert (hasScanned); // need to call scanForDevices() before doing this
  198577. return 0;
  198578. }
  198579. bool hasSeparateInputsAndOutputs() const { return true; }
  198580. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  198581. {
  198582. jassert (hasScanned); // need to call scanForDevices() before doing this
  198583. ALSAAudioIODevice* const d = dynamic_cast <ALSAAudioIODevice*> (device);
  198584. if (d == 0)
  198585. return -1;
  198586. return asInput ? inputIds.indexOf (d->inputId)
  198587. : outputIds.indexOf (d->outputId);
  198588. }
  198589. AudioIODevice* createDevice (const String& outputDeviceName,
  198590. const String& inputDeviceName)
  198591. {
  198592. jassert (hasScanned); // need to call scanForDevices() before doing this
  198593. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198594. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198595. String deviceName (outputIndex >= 0 ? outputDeviceName
  198596. : inputDeviceName);
  198597. if (inputIndex >= 0 || outputIndex >= 0)
  198598. return new ALSAAudioIODevice (deviceName,
  198599. inputIds [inputIndex],
  198600. outputIds [outputIndex]);
  198601. return 0;
  198602. }
  198603. juce_UseDebuggingNewOperator
  198604. private:
  198605. StringArray inputNames, outputNames, inputIds, outputIds;
  198606. bool hasScanned;
  198607. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198608. {
  198609. unsigned int minChansOut = 0, maxChansOut = 0;
  198610. unsigned int minChansIn = 0, maxChansIn = 0;
  198611. Array <int> rates;
  198612. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198613. DBG (T("ALSA device: ") + id
  198614. + T(" outs=") + String ((int) minChansOut) + T("-") + String ((int) maxChansOut)
  198615. + T(" ins=") + String ((int) minChansIn) + T("-") + String ((int) maxChansIn)
  198616. + T(" rates=") + String (rates.size()));
  198617. isInput = maxChansIn > 0;
  198618. isOutput = maxChansOut > 0;
  198619. return (isInput || isOutput) && rates.size() > 0;
  198620. }
  198621. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198622. ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198623. };
  198624. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198625. {
  198626. return new ALSAAudioIODeviceType();
  198627. }
  198628. #endif
  198629. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198630. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198631. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198632. // compiled on its own).
  198633. #ifdef JUCE_INCLUDED_FILE
  198634. #if JUCE_JACK
  198635. static void* juce_libjack_handle = 0;
  198636. void* juce_load_jack_function (const char* const name)
  198637. {
  198638. if (juce_libjack_handle == 0)
  198639. return 0;
  198640. return dlsym (juce_libjack_handle, name);
  198641. }
  198642. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198643. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198644. return_type fn_name argument_types { \
  198645. static fn_name##_ptr_t fn = 0; \
  198646. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198647. if (fn) return (*fn)arguments; \
  198648. else return 0; \
  198649. }
  198650. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198651. typedef void (*fn_name##_ptr_t)argument_types; \
  198652. void fn_name argument_types { \
  198653. static fn_name##_ptr_t fn = 0; \
  198654. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198655. if (fn) (*fn)arguments; \
  198656. }
  198657. 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));
  198658. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198659. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198660. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198661. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198662. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198663. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198664. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198665. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198666. 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));
  198667. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198668. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198669. 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));
  198670. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198671. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198672. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198673. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198674. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198675. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198676. #if JUCE_DEBUG
  198677. #define JACK_LOGGING_ENABLED 1
  198678. #endif
  198679. #if JACK_LOGGING_ENABLED
  198680. static void jack_Log (const String& s)
  198681. {
  198682. std::cerr << s << std::endl;
  198683. }
  198684. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198685. {
  198686. if (status & JackServerFailed || status & JackServerError)
  198687. jack_Log ("Unable to connect to JACK server");
  198688. if (status & JackVersionError)
  198689. jack_Log ("Client's protocol version does not match");
  198690. if (status & JackInvalidOption)
  198691. jack_Log ("The operation contained an invalid or unsupported option");
  198692. if (status & JackNameNotUnique)
  198693. jack_Log ("The desired client name was not unique");
  198694. if (status & JackNoSuchClient)
  198695. jack_Log ("Requested client does not exist");
  198696. if (status & JackInitFailure)
  198697. jack_Log ("Unable to initialize client");
  198698. }
  198699. #else
  198700. #define dumpJackErrorMessage(a) {}
  198701. #define jack_Log(...) {}
  198702. #endif
  198703. #ifndef JUCE_JACK_CLIENT_NAME
  198704. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  198705. #endif
  198706. class JackAudioIODevice : public AudioIODevice
  198707. {
  198708. public:
  198709. JackAudioIODevice (const String& deviceName,
  198710. const String& inputId_,
  198711. const String& outputId_)
  198712. : AudioIODevice (deviceName, T("JACK")),
  198713. inputId (inputId_),
  198714. outputId (outputId_),
  198715. isOpen_ (false),
  198716. callback (0),
  198717. totalNumberOfInputChannels (0),
  198718. totalNumberOfOutputChannels (0)
  198719. {
  198720. jassert (deviceName.isNotEmpty());
  198721. jack_status_t status;
  198722. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  198723. if (client == 0)
  198724. {
  198725. dumpJackErrorMessage (status);
  198726. }
  198727. else
  198728. {
  198729. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  198730. // open input ports
  198731. const StringArray inputChannels (getInputChannelNames());
  198732. for (int i = 0; i < inputChannels.size(); i++)
  198733. {
  198734. String inputName;
  198735. inputName << "in_" << ++totalNumberOfInputChannels;
  198736. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(),
  198737. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  198738. }
  198739. // open output ports
  198740. const StringArray outputChannels (getOutputChannelNames());
  198741. for (int i = 0; i < outputChannels.size (); i++)
  198742. {
  198743. String outputName;
  198744. outputName << "out_" << ++totalNumberOfOutputChannels;
  198745. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(),
  198746. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  198747. }
  198748. inChans.calloc (totalNumberOfInputChannels + 2);
  198749. outChans.calloc (totalNumberOfOutputChannels + 2);
  198750. }
  198751. }
  198752. ~JackAudioIODevice()
  198753. {
  198754. close();
  198755. if (client != 0)
  198756. {
  198757. JUCE_NAMESPACE::jack_client_close (client);
  198758. client = 0;
  198759. }
  198760. }
  198761. const StringArray getChannelNames (bool forInput) const
  198762. {
  198763. StringArray names;
  198764. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  198765. forInput ? JackPortIsInput : JackPortIsOutput);
  198766. if (ports != 0)
  198767. {
  198768. int j = 0;
  198769. while (ports[j] != 0)
  198770. {
  198771. const String portName (ports [j++]);
  198772. if (portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198773. names.add (portName.fromFirstOccurrenceOf (T(":"), false, false));
  198774. }
  198775. free (ports);
  198776. }
  198777. return names;
  198778. }
  198779. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  198780. const StringArray getInputChannelNames() { return getChannelNames (true); }
  198781. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  198782. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  198783. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  198784. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  198785. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  198786. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  198787. double sampleRate, int bufferSizeSamples)
  198788. {
  198789. if (client == 0)
  198790. {
  198791. lastError = T("No JACK client running");
  198792. return lastError;
  198793. }
  198794. lastError = String::empty;
  198795. close();
  198796. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  198797. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  198798. JUCE_NAMESPACE::jack_activate (client);
  198799. isOpen_ = true;
  198800. if (! inputChannels.isZero())
  198801. {
  198802. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198803. if (ports != 0)
  198804. {
  198805. const int numInputChannels = inputChannels.getHighestBit() + 1;
  198806. for (int i = 0; i < numInputChannels; ++i)
  198807. {
  198808. const String portName (ports[i]);
  198809. if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198810. {
  198811. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  198812. if (error != 0)
  198813. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198814. }
  198815. }
  198816. free (ports);
  198817. }
  198818. }
  198819. if (! outputChannels.isZero())
  198820. {
  198821. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198822. if (ports != 0)
  198823. {
  198824. const int numOutputChannels = outputChannels.getHighestBit() + 1;
  198825. for (int i = 0; i < numOutputChannels; ++i)
  198826. {
  198827. const String portName (ports[i]);
  198828. if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  198829. {
  198830. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  198831. if (error != 0)
  198832. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198833. }
  198834. }
  198835. free (ports);
  198836. }
  198837. }
  198838. return lastError;
  198839. }
  198840. void close()
  198841. {
  198842. stop();
  198843. if (client != 0)
  198844. {
  198845. JUCE_NAMESPACE::jack_deactivate (client);
  198846. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  198847. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  198848. }
  198849. isOpen_ = false;
  198850. }
  198851. void start (AudioIODeviceCallback* newCallback)
  198852. {
  198853. if (isOpen_ && newCallback != callback)
  198854. {
  198855. if (newCallback != 0)
  198856. newCallback->audioDeviceAboutToStart (this);
  198857. AudioIODeviceCallback* const oldCallback = callback;
  198858. {
  198859. const ScopedLock sl (callbackLock);
  198860. callback = newCallback;
  198861. }
  198862. if (oldCallback != 0)
  198863. oldCallback->audioDeviceStopped();
  198864. }
  198865. }
  198866. void stop()
  198867. {
  198868. start (0);
  198869. }
  198870. bool isOpen() { return isOpen_; }
  198871. bool isPlaying() { return callback != 0; }
  198872. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  198873. double getCurrentSampleRate() { return getSampleRate (0); }
  198874. int getCurrentBitDepth() { return 32; }
  198875. const String getLastError() { return lastError; }
  198876. const BigInteger getActiveOutputChannels() const
  198877. {
  198878. BigInteger outputBits;
  198879. for (int i = 0; i < outputPorts.size(); i++)
  198880. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  198881. outputBits.setBit (i);
  198882. return outputBits;
  198883. }
  198884. const BigInteger getActiveInputChannels() const
  198885. {
  198886. BigInteger inputBits;
  198887. for (int i = 0; i < inputPorts.size(); i++)
  198888. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  198889. inputBits.setBit (i);
  198890. return inputBits;
  198891. }
  198892. int getOutputLatencyInSamples()
  198893. {
  198894. int latency = 0;
  198895. for (int i = 0; i < outputPorts.size(); i++)
  198896. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  198897. return latency;
  198898. }
  198899. int getInputLatencyInSamples()
  198900. {
  198901. int latency = 0;
  198902. for (int i = 0; i < inputPorts.size(); i++)
  198903. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  198904. return latency;
  198905. }
  198906. String inputId, outputId;
  198907. private:
  198908. void process (const int numSamples)
  198909. {
  198910. int i, numActiveInChans = 0, numActiveOutChans = 0;
  198911. for (i = 0; i < totalNumberOfInputChannels; ++i)
  198912. {
  198913. jack_default_audio_sample_t* in
  198914. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  198915. if (in != 0)
  198916. inChans [numActiveInChans++] = (float*) in;
  198917. }
  198918. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  198919. {
  198920. jack_default_audio_sample_t* out
  198921. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  198922. if (out != 0)
  198923. outChans [numActiveOutChans++] = (float*) out;
  198924. }
  198925. const ScopedLock sl (callbackLock);
  198926. if (callback != 0)
  198927. {
  198928. callback->audioDeviceIOCallback (const_cast<const float**> (inChans.getData()), numActiveInChans,
  198929. outChans, numActiveOutChans, numSamples);
  198930. }
  198931. else
  198932. {
  198933. for (i = 0; i < numActiveOutChans; ++i)
  198934. zeromem (outChans[i], sizeof (float) * numSamples);
  198935. }
  198936. }
  198937. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  198938. {
  198939. if (callbackArgument != 0)
  198940. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  198941. return 0;
  198942. }
  198943. static void threadInitCallback (void* callbackArgument)
  198944. {
  198945. jack_Log ("JackAudioIODevice::initialise");
  198946. }
  198947. static void shutdownCallback (void* callbackArgument)
  198948. {
  198949. jack_Log ("JackAudioIODevice::shutdown");
  198950. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  198951. if (device != 0)
  198952. {
  198953. device->client = 0;
  198954. device->close();
  198955. }
  198956. }
  198957. static void errorCallback (const char* msg)
  198958. {
  198959. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  198960. }
  198961. bool isOpen_;
  198962. jack_client_t* client;
  198963. String lastError;
  198964. AudioIODeviceCallback* callback;
  198965. CriticalSection callbackLock;
  198966. HeapBlock <float*> inChans, outChans;
  198967. int totalNumberOfInputChannels;
  198968. int totalNumberOfOutputChannels;
  198969. VoidArray inputPorts, outputPorts;
  198970. };
  198971. class JackAudioIODeviceType : public AudioIODeviceType
  198972. {
  198973. public:
  198974. JackAudioIODeviceType()
  198975. : AudioIODeviceType (T("JACK")),
  198976. hasScanned (false)
  198977. {
  198978. }
  198979. ~JackAudioIODeviceType()
  198980. {
  198981. }
  198982. void scanForDevices()
  198983. {
  198984. hasScanned = true;
  198985. inputNames.clear();
  198986. inputIds.clear();
  198987. outputNames.clear();
  198988. outputIds.clear();
  198989. if (juce_libjack_handle == 0)
  198990. {
  198991. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  198992. if (juce_libjack_handle == 0)
  198993. return;
  198994. }
  198995. // open a dummy client
  198996. jack_status_t status;
  198997. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  198998. if (client == 0)
  198999. {
  199000. dumpJackErrorMessage (status);
  199001. }
  199002. else
  199003. {
  199004. // scan for output devices
  199005. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199006. if (ports != 0)
  199007. {
  199008. int j = 0;
  199009. while (ports[j] != 0)
  199010. {
  199011. String clientName (ports[j]);
  199012. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199013. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199014. && ! inputNames.contains (clientName))
  199015. {
  199016. inputNames.add (clientName);
  199017. inputIds.add (ports [j]);
  199018. }
  199019. ++j;
  199020. }
  199021. free (ports);
  199022. }
  199023. // scan for input devices
  199024. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199025. if (ports != 0)
  199026. {
  199027. int j = 0;
  199028. while (ports[j] != 0)
  199029. {
  199030. String clientName (ports[j]);
  199031. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199032. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199033. && ! outputNames.contains (clientName))
  199034. {
  199035. outputNames.add (clientName);
  199036. outputIds.add (ports [j]);
  199037. }
  199038. ++j;
  199039. }
  199040. free (ports);
  199041. }
  199042. JUCE_NAMESPACE::jack_client_close (client);
  199043. }
  199044. }
  199045. const StringArray getDeviceNames (const bool wantInputNames) const
  199046. {
  199047. jassert (hasScanned); // need to call scanForDevices() before doing this
  199048. return wantInputNames ? inputNames : outputNames;
  199049. }
  199050. int getDefaultDeviceIndex (const bool forInput) const
  199051. {
  199052. jassert (hasScanned); // need to call scanForDevices() before doing this
  199053. return 0;
  199054. }
  199055. bool hasSeparateInputsAndOutputs() const { return true; }
  199056. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199057. {
  199058. jassert (hasScanned); // need to call scanForDevices() before doing this
  199059. JackAudioIODevice* const d = dynamic_cast <JackAudioIODevice*> (device);
  199060. if (d == 0)
  199061. return -1;
  199062. return asInput ? inputIds.indexOf (d->inputId)
  199063. : outputIds.indexOf (d->outputId);
  199064. }
  199065. AudioIODevice* createDevice (const String& outputDeviceName,
  199066. const String& inputDeviceName)
  199067. {
  199068. jassert (hasScanned); // need to call scanForDevices() before doing this
  199069. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199070. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199071. if (inputIndex >= 0 || outputIndex >= 0)
  199072. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199073. : inputDeviceName,
  199074. inputIds [inputIndex],
  199075. outputIds [outputIndex]);
  199076. return 0;
  199077. }
  199078. juce_UseDebuggingNewOperator
  199079. private:
  199080. StringArray inputNames, outputNames, inputIds, outputIds;
  199081. bool hasScanned;
  199082. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199083. JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199084. };
  199085. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199086. {
  199087. return new JackAudioIODeviceType();
  199088. }
  199089. #else // if JACK is turned off..
  199090. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199091. #endif
  199092. #endif
  199093. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199094. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199095. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199096. // compiled on its own).
  199097. #if JUCE_INCLUDED_FILE
  199098. #if JUCE_ALSA
  199099. static snd_seq_t* iterateDevices (const bool forInput,
  199100. StringArray& deviceNamesFound,
  199101. const int deviceIndexToOpen)
  199102. {
  199103. snd_seq_t* returnedHandle = 0;
  199104. snd_seq_t* seqHandle;
  199105. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199106. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199107. {
  199108. snd_seq_system_info_t* systemInfo;
  199109. snd_seq_client_info_t* clientInfo;
  199110. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199111. {
  199112. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199113. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199114. {
  199115. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199116. while (--numClients >= 0 && returnedHandle == 0)
  199117. {
  199118. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199119. {
  199120. snd_seq_port_info_t* portInfo;
  199121. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199122. {
  199123. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199124. const int client = snd_seq_client_info_get_client (clientInfo);
  199125. snd_seq_port_info_set_client (portInfo, client);
  199126. snd_seq_port_info_set_port (portInfo, -1);
  199127. while (--numPorts >= 0)
  199128. {
  199129. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199130. && (snd_seq_port_info_get_capability (portInfo)
  199131. & (forInput ? SND_SEQ_PORT_CAP_READ
  199132. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199133. {
  199134. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199135. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199136. {
  199137. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199138. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199139. if (sourcePort != -1)
  199140. {
  199141. snd_seq_set_client_name (seqHandle,
  199142. forInput ? "Juce Midi Input"
  199143. : "Juce Midi Output");
  199144. const int portId
  199145. = snd_seq_create_simple_port (seqHandle,
  199146. forInput ? "Juce Midi In Port"
  199147. : "Juce Midi Out Port",
  199148. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199149. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199150. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199151. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199152. returnedHandle = seqHandle;
  199153. }
  199154. }
  199155. }
  199156. }
  199157. snd_seq_port_info_free (portInfo);
  199158. }
  199159. }
  199160. }
  199161. snd_seq_client_info_free (clientInfo);
  199162. }
  199163. snd_seq_system_info_free (systemInfo);
  199164. }
  199165. if (returnedHandle == 0)
  199166. snd_seq_close (seqHandle);
  199167. }
  199168. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199169. return returnedHandle;
  199170. }
  199171. static snd_seq_t* createDevice (const bool forInput,
  199172. const String& deviceNameToOpen)
  199173. {
  199174. snd_seq_t* seqHandle = 0;
  199175. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199176. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199177. {
  199178. snd_seq_set_client_name (seqHandle,
  199179. (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString());
  199180. const int portId
  199181. = snd_seq_create_simple_port (seqHandle,
  199182. forInput ? "in"
  199183. : "out",
  199184. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199185. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199186. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199187. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199188. if (portId < 0)
  199189. {
  199190. snd_seq_close (seqHandle);
  199191. seqHandle = 0;
  199192. }
  199193. }
  199194. return seqHandle;
  199195. }
  199196. class MidiOutputDevice
  199197. {
  199198. public:
  199199. MidiOutputDevice (MidiOutput* const midiOutput_,
  199200. snd_seq_t* const seqHandle_)
  199201. :
  199202. midiOutput (midiOutput_),
  199203. seqHandle (seqHandle_),
  199204. maxEventSize (16 * 1024)
  199205. {
  199206. jassert (seqHandle != 0 && midiOutput != 0);
  199207. snd_midi_event_new (maxEventSize, &midiParser);
  199208. }
  199209. ~MidiOutputDevice()
  199210. {
  199211. snd_midi_event_free (midiParser);
  199212. snd_seq_close (seqHandle);
  199213. }
  199214. void sendMessageNow (const MidiMessage& message)
  199215. {
  199216. if (message.getRawDataSize() > maxEventSize)
  199217. {
  199218. maxEventSize = message.getRawDataSize();
  199219. snd_midi_event_free (midiParser);
  199220. snd_midi_event_new (maxEventSize, &midiParser);
  199221. }
  199222. snd_seq_event_t event;
  199223. snd_seq_ev_clear (&event);
  199224. snd_midi_event_encode (midiParser,
  199225. message.getRawData(),
  199226. message.getRawDataSize(),
  199227. &event);
  199228. snd_midi_event_reset_encode (midiParser);
  199229. snd_seq_ev_set_source (&event, 0);
  199230. snd_seq_ev_set_subs (&event);
  199231. snd_seq_ev_set_direct (&event);
  199232. snd_seq_event_output (seqHandle, &event);
  199233. snd_seq_drain_output (seqHandle);
  199234. }
  199235. juce_UseDebuggingNewOperator
  199236. private:
  199237. MidiOutput* const midiOutput;
  199238. snd_seq_t* const seqHandle;
  199239. snd_midi_event_t* midiParser;
  199240. int maxEventSize;
  199241. };
  199242. const StringArray MidiOutput::getDevices()
  199243. {
  199244. StringArray devices;
  199245. iterateDevices (false, devices, -1);
  199246. return devices;
  199247. }
  199248. int MidiOutput::getDefaultDeviceIndex()
  199249. {
  199250. return 0;
  199251. }
  199252. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199253. {
  199254. MidiOutput* newDevice = 0;
  199255. StringArray devices;
  199256. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199257. if (handle != 0)
  199258. {
  199259. newDevice = new MidiOutput();
  199260. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199261. }
  199262. return newDevice;
  199263. }
  199264. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199265. {
  199266. MidiOutput* newDevice = 0;
  199267. snd_seq_t* const handle = createDevice (false, deviceName);
  199268. if (handle != 0)
  199269. {
  199270. newDevice = new MidiOutput();
  199271. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199272. }
  199273. return newDevice;
  199274. }
  199275. MidiOutput::~MidiOutput()
  199276. {
  199277. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199278. delete device;
  199279. }
  199280. void MidiOutput::reset()
  199281. {
  199282. }
  199283. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199284. {
  199285. return false;
  199286. }
  199287. void MidiOutput::setVolume (float leftVol, float rightVol)
  199288. {
  199289. }
  199290. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199291. {
  199292. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199293. }
  199294. class MidiInputThread : public Thread
  199295. {
  199296. public:
  199297. MidiInputThread (MidiInput* const midiInput_,
  199298. snd_seq_t* const seqHandle_,
  199299. MidiInputCallback* const callback_)
  199300. : Thread (T("Juce MIDI Input")),
  199301. midiInput (midiInput_),
  199302. seqHandle (seqHandle_),
  199303. callback (callback_)
  199304. {
  199305. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199306. }
  199307. ~MidiInputThread()
  199308. {
  199309. snd_seq_close (seqHandle);
  199310. }
  199311. void run()
  199312. {
  199313. const int maxEventSize = 16 * 1024;
  199314. snd_midi_event_t* midiParser;
  199315. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199316. {
  199317. HeapBlock <uint8> buffer (maxEventSize);
  199318. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199319. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199320. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199321. while (! threadShouldExit())
  199322. {
  199323. if (poll (pfd, numPfds, 500) > 0)
  199324. {
  199325. snd_seq_event_t* inputEvent = 0;
  199326. snd_seq_nonblock (seqHandle, 1);
  199327. do
  199328. {
  199329. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199330. {
  199331. // xxx what about SYSEXes that are too big for the buffer?
  199332. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199333. snd_midi_event_reset_decode (midiParser);
  199334. if (numBytes > 0)
  199335. {
  199336. const MidiMessage message ((const uint8*) buffer,
  199337. numBytes,
  199338. Time::getMillisecondCounter() * 0.001);
  199339. callback->handleIncomingMidiMessage (midiInput, message);
  199340. }
  199341. snd_seq_free_event (inputEvent);
  199342. }
  199343. }
  199344. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199345. snd_seq_free_event (inputEvent);
  199346. }
  199347. }
  199348. snd_midi_event_free (midiParser);
  199349. }
  199350. };
  199351. juce_UseDebuggingNewOperator
  199352. private:
  199353. MidiInput* const midiInput;
  199354. snd_seq_t* const seqHandle;
  199355. MidiInputCallback* const callback;
  199356. };
  199357. MidiInput::MidiInput (const String& name_)
  199358. : name (name_),
  199359. internal (0)
  199360. {
  199361. }
  199362. MidiInput::~MidiInput()
  199363. {
  199364. stop();
  199365. MidiInputThread* const thread = (MidiInputThread*) internal;
  199366. delete thread;
  199367. }
  199368. void MidiInput::start()
  199369. {
  199370. ((MidiInputThread*) internal)->startThread();
  199371. }
  199372. void MidiInput::stop()
  199373. {
  199374. ((MidiInputThread*) internal)->stopThread (3000);
  199375. }
  199376. int MidiInput::getDefaultDeviceIndex()
  199377. {
  199378. return 0;
  199379. }
  199380. const StringArray MidiInput::getDevices()
  199381. {
  199382. StringArray devices;
  199383. iterateDevices (true, devices, -1);
  199384. return devices;
  199385. }
  199386. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199387. {
  199388. MidiInput* newDevice = 0;
  199389. StringArray devices;
  199390. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199391. if (handle != 0)
  199392. {
  199393. newDevice = new MidiInput (devices [deviceIndex]);
  199394. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199395. }
  199396. return newDevice;
  199397. }
  199398. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199399. {
  199400. MidiInput* newDevice = 0;
  199401. snd_seq_t* const handle = createDevice (true, deviceName);
  199402. if (handle != 0)
  199403. {
  199404. newDevice = new MidiInput (deviceName);
  199405. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199406. }
  199407. return newDevice;
  199408. }
  199409. #else
  199410. // (These are just stub functions if ALSA is unavailable...)
  199411. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199412. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199413. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199414. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199415. MidiOutput::~MidiOutput() {}
  199416. void MidiOutput::reset() {}
  199417. bool MidiOutput::getVolume (float&, float&) { return false; }
  199418. void MidiOutput::setVolume (float, float) {}
  199419. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199420. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199421. MidiInput::~MidiInput() {}
  199422. void MidiInput::start() {}
  199423. void MidiInput::stop() {}
  199424. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199425. const StringArray MidiInput::getDevices() { return StringArray(); }
  199426. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199427. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199428. #endif
  199429. #endif
  199430. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199431. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199432. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199433. // compiled on its own).
  199434. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199435. AudioCDReader::AudioCDReader()
  199436. : AudioFormatReader (0, T("CD Audio"))
  199437. {
  199438. }
  199439. const StringArray AudioCDReader::getAvailableCDNames()
  199440. {
  199441. StringArray names;
  199442. return names;
  199443. }
  199444. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199445. {
  199446. return 0;
  199447. }
  199448. AudioCDReader::~AudioCDReader()
  199449. {
  199450. }
  199451. void AudioCDReader::refreshTrackLengths()
  199452. {
  199453. }
  199454. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199455. int64 startSampleInFile, int numSamples)
  199456. {
  199457. return false;
  199458. }
  199459. bool AudioCDReader::isCDStillPresent() const
  199460. {
  199461. return false;
  199462. }
  199463. int AudioCDReader::getNumTracks() const
  199464. {
  199465. return 0;
  199466. }
  199467. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199468. {
  199469. return 0;
  199470. }
  199471. bool AudioCDReader::isTrackAudio (int trackNum) const
  199472. {
  199473. return false;
  199474. }
  199475. void AudioCDReader::enableIndexScanning (bool b)
  199476. {
  199477. }
  199478. int AudioCDReader::getLastIndex() const
  199479. {
  199480. return 0;
  199481. }
  199482. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199483. {
  199484. return Array<int>();
  199485. }
  199486. int AudioCDReader::getCDDBId()
  199487. {
  199488. return 0;
  199489. }
  199490. #endif
  199491. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199492. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199493. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199494. // compiled on its own).
  199495. #if JUCE_INCLUDED_FILE
  199496. void FileChooser::showPlatformDialog (Array<File>& results,
  199497. const String& title,
  199498. const File& file,
  199499. const String& filters,
  199500. bool isDirectory,
  199501. bool selectsFiles,
  199502. bool isSave,
  199503. bool warnAboutOverwritingExistingFiles,
  199504. bool selectMultipleFiles,
  199505. FilePreviewComponent* previewComponent)
  199506. {
  199507. const tchar* const separator = T(":");
  199508. String command ("zenity --file-selection");
  199509. if (title.isNotEmpty())
  199510. command << " --title=\"" << title << "\"";
  199511. if (file != File::nonexistent)
  199512. command << " --filename=\"" << file.getFullPathName () << "\"";
  199513. if (isDirectory)
  199514. command << " --directory";
  199515. if (isSave)
  199516. command << " --save";
  199517. if (selectMultipleFiles)
  199518. command << " --multiple --separator=\"" << separator << "\"";
  199519. command << " 2>&1";
  199520. MemoryOutputStream result;
  199521. int status = -1;
  199522. FILE* stream = popen (command.toUTF8(), "r");
  199523. if (stream != 0)
  199524. {
  199525. for (;;)
  199526. {
  199527. char buffer [1024];
  199528. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199529. if (bytesRead <= 0)
  199530. break;
  199531. result.write (buffer, bytesRead);
  199532. }
  199533. status = pclose (stream);
  199534. }
  199535. if (status == 0)
  199536. {
  199537. String resultString (String::fromUTF8 (result.getData(), result.getDataSize()));
  199538. StringArray tokens;
  199539. if (selectMultipleFiles)
  199540. tokens.addTokens (resultString, separator, String::empty);
  199541. else
  199542. tokens.add (resultString);
  199543. for (int i = 0; i < tokens.size(); i++)
  199544. results.add (File (tokens[i]));
  199545. return;
  199546. }
  199547. //xxx ain't got one!
  199548. jassertfalse
  199549. }
  199550. #endif
  199551. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199552. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199553. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199554. // compiled on its own).
  199555. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199556. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199557. : browser (0),
  199558. blankPageShown (false),
  199559. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199560. {
  199561. setOpaque (true);
  199562. }
  199563. WebBrowserComponent::~WebBrowserComponent()
  199564. {
  199565. }
  199566. void WebBrowserComponent::goToURL (const String& url,
  199567. const StringArray* headers,
  199568. const MemoryBlock* postData)
  199569. {
  199570. lastURL = url;
  199571. lastHeaders.clear();
  199572. if (headers != 0)
  199573. lastHeaders = *headers;
  199574. lastPostData.setSize (0);
  199575. if (postData != 0)
  199576. lastPostData = *postData;
  199577. blankPageShown = false;
  199578. }
  199579. void WebBrowserComponent::stop()
  199580. {
  199581. }
  199582. void WebBrowserComponent::goBack()
  199583. {
  199584. lastURL = String::empty;
  199585. blankPageShown = false;
  199586. }
  199587. void WebBrowserComponent::goForward()
  199588. {
  199589. lastURL = String::empty;
  199590. }
  199591. void WebBrowserComponent::refresh()
  199592. {
  199593. }
  199594. void WebBrowserComponent::paint (Graphics& g)
  199595. {
  199596. g.fillAll (Colours::white);
  199597. }
  199598. void WebBrowserComponent::checkWindowAssociation()
  199599. {
  199600. }
  199601. void WebBrowserComponent::reloadLastURL()
  199602. {
  199603. if (lastURL.isNotEmpty())
  199604. {
  199605. goToURL (lastURL, &lastHeaders, &lastPostData);
  199606. lastURL = String::empty;
  199607. }
  199608. }
  199609. void WebBrowserComponent::parentHierarchyChanged()
  199610. {
  199611. checkWindowAssociation();
  199612. }
  199613. void WebBrowserComponent::resized()
  199614. {
  199615. }
  199616. void WebBrowserComponent::visibilityChanged()
  199617. {
  199618. checkWindowAssociation();
  199619. }
  199620. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199621. {
  199622. return true;
  199623. }
  199624. #endif
  199625. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199626. #endif
  199627. END_JUCE_NAMESPACE
  199628. #endif
  199629. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199630. #endif
  199631. #if JUCE_MAC || JUCE_IPHONE
  199632. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199633. #if JUCE_MAC || JUCE_IPHONE
  199634. BEGIN_JUCE_NAMESPACE
  199635. #undef Point
  199636. #define JUCE_INCLUDED_FILE 1
  199637. // Now include the actual code files..
  199638. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199639. #ifndef JUCE_ObjCExtraSuffix
  199640. #define JUCE_ObjCExtraSuffix 3
  199641. #endif
  199642. #define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e
  199643. #define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e)
  199644. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix)
  199645. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199646. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199647. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199648. // compiled on its own).
  199649. #if JUCE_INCLUDED_FILE
  199650. static const String nsStringToJuce (NSString* s)
  199651. {
  199652. return String::fromUTF8 ([s UTF8String]);
  199653. }
  199654. static NSString* juceStringToNS (const String& s)
  199655. {
  199656. return [NSString stringWithUTF8String: s.toUTF8()];
  199657. }
  199658. static const String convertUTF16ToString (const UniChar* utf16)
  199659. {
  199660. String s;
  199661. while (*utf16 != 0)
  199662. s += (juce_wchar) *utf16++;
  199663. return s;
  199664. }
  199665. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199666. {
  199667. String result;
  199668. if (cfString != 0)
  199669. {
  199670. CFRange range = { 0, CFStringGetLength (cfString) };
  199671. HeapBlock <UniChar> u (range.length + 1);
  199672. CFStringGetCharacters (cfString, range, u);
  199673. u[range.length] = 0;
  199674. result = convertUTF16ToString (u);
  199675. }
  199676. return result;
  199677. }
  199678. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199679. {
  199680. const int len = s.length();
  199681. const juce_wchar* t = (const juce_wchar*) s;
  199682. HeapBlock <UniChar> temp (len + 2);
  199683. for (int i = 0; i <= len; ++i)
  199684. temp[i] = t[i];
  199685. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  199686. }
  199687. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  199688. {
  199689. #if JUCE_IPHONE
  199690. const ScopedAutoReleasePool pool;
  199691. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  199692. #else
  199693. UnicodeMapping map;
  199694. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199695. kUnicodeNoSubset,
  199696. kTextEncodingDefaultFormat);
  199697. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199698. kUnicodeCanonicalCompVariant,
  199699. kTextEncodingDefaultFormat);
  199700. map.mappingVersion = kUnicodeUseLatestMapping;
  199701. UnicodeToTextInfo conversionInfo = 0;
  199702. String result;
  199703. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  199704. {
  199705. const int len = s.length();
  199706. HeapBlock <UniChar> tempIn, tempOut;
  199707. tempIn.calloc (len + 2);
  199708. tempOut.calloc (len + 2);
  199709. for (int i = 0; i <= len; ++i)
  199710. tempIn[i] = s[i];
  199711. ByteCount bytesRead = 0;
  199712. ByteCount outputBufferSize = 0;
  199713. if (ConvertFromUnicodeToText (conversionInfo,
  199714. len * sizeof (UniChar), tempIn,
  199715. kUnicodeDefaultDirectionMask,
  199716. 0, 0, 0, 0,
  199717. len * sizeof (UniChar), &bytesRead,
  199718. &outputBufferSize, tempOut) == noErr)
  199719. {
  199720. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  199721. tchar* t = const_cast <tchar*> ((const tchar*) result);
  199722. unsigned int i;
  199723. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  199724. t[i] = (tchar) tempOut[i];
  199725. t[i] = 0;
  199726. }
  199727. DisposeUnicodeToTextInfo (&conversionInfo);
  199728. }
  199729. return result;
  199730. #endif
  199731. }
  199732. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  199733. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  199734. {
  199735. #if JUCE_IPHONE
  199736. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  199737. forPasteboardType: @"public.text"];
  199738. #else
  199739. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  199740. owner: nil];
  199741. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  199742. forType: NSStringPboardType];
  199743. #endif
  199744. }
  199745. const String SystemClipboard::getTextFromClipboard() throw()
  199746. {
  199747. #if JUCE_IPHONE
  199748. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  199749. #else
  199750. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  199751. #endif
  199752. return text == 0 ? String::empty
  199753. : nsStringToJuce (text);
  199754. }
  199755. #endif
  199756. #endif
  199757. /*** End of inlined file: juce_mac_Strings.mm ***/
  199758. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  199759. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199760. // compiled on its own).
  199761. #if JUCE_INCLUDED_FILE
  199762. namespace SystemStatsHelpers
  199763. {
  199764. static int64 highResTimerFrequency = 0;
  199765. static double highResTimerToMillisecRatio = 0;
  199766. #if JUCE_INTEL
  199767. static void juce_getCpuVendor (char* const v) throw()
  199768. {
  199769. int vendor[4];
  199770. zerostruct (vendor);
  199771. int dummy = 0;
  199772. asm ("mov %%ebx, %%esi \n\t"
  199773. "cpuid \n\t"
  199774. "xchg %%esi, %%ebx"
  199775. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  199776. memcpy (v, vendor, 16);
  199777. }
  199778. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  199779. {
  199780. unsigned int cpu = 0;
  199781. unsigned int ext = 0;
  199782. unsigned int family = 0;
  199783. unsigned int dummy = 0;
  199784. asm ("mov %%ebx, %%esi \n\t"
  199785. "cpuid \n\t"
  199786. "xchg %%esi, %%ebx"
  199787. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  199788. familyModel = family;
  199789. extFeatures = ext;
  199790. return cpu;
  199791. }
  199792. struct CPUFlags
  199793. {
  199794. bool hasMMX : 1;
  199795. bool hasSSE : 1;
  199796. bool hasSSE2 : 1;
  199797. bool has3DNow : 1;
  199798. };
  199799. static CPUFlags cpuFlags;
  199800. #endif
  199801. }
  199802. void SystemStats::initialiseStats() throw()
  199803. {
  199804. using namespace SystemStatsHelpers;
  199805. static bool initialised = false;
  199806. if (! initialised)
  199807. {
  199808. initialised = true;
  199809. #if JUCE_MAC
  199810. // extremely annoying: adding this line stops the apple menu items from working. Of
  199811. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  199812. // any events.
  199813. //NSApplicationLoad();
  199814. [NSApplication sharedApplication];
  199815. #endif
  199816. #if JUCE_INTEL
  199817. {
  199818. unsigned int familyModel, extFeatures;
  199819. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  199820. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  199821. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  199822. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  199823. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  199824. }
  199825. #endif
  199826. mach_timebase_info_data_t timebase;
  199827. (void) mach_timebase_info (&timebase);
  199828. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  199829. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  199830. String s (SystemStats::getJUCEVersion());
  199831. rlimit lim;
  199832. getrlimit (RLIMIT_NOFILE, &lim);
  199833. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  199834. setrlimit (RLIMIT_NOFILE, &lim);
  199835. }
  199836. }
  199837. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  199838. {
  199839. return MacOSX;
  199840. }
  199841. const String SystemStats::getOperatingSystemName() throw()
  199842. {
  199843. return T("Mac OS X");
  199844. }
  199845. bool SystemStats::isOperatingSystem64Bit() throw()
  199846. {
  199847. #if JUCE_64BIT
  199848. return true;
  199849. #else
  199850. //xxx not sure how to find this out?..
  199851. return false;
  199852. #endif
  199853. }
  199854. int SystemStats::getMemorySizeInMegabytes() throw()
  199855. {
  199856. uint64 mem = 0;
  199857. size_t memSize = sizeof (mem);
  199858. int mib[] = { CTL_HW, HW_MEMSIZE };
  199859. sysctl (mib, 2, &mem, &memSize, 0, 0);
  199860. return (int) (mem / (1024 * 1024));
  199861. }
  199862. bool SystemStats::hasMMX() throw()
  199863. {
  199864. #if JUCE_INTEL
  199865. return SystemStatsHelpers::cpuFlags.hasMMX;
  199866. #else
  199867. return false;
  199868. #endif
  199869. }
  199870. bool SystemStats::hasSSE() throw()
  199871. {
  199872. #if JUCE_INTEL
  199873. return SystemStatsHelpers::cpuFlags.hasSSE;
  199874. #else
  199875. return false;
  199876. #endif
  199877. }
  199878. bool SystemStats::hasSSE2() throw()
  199879. {
  199880. #if JUCE_INTEL
  199881. return SystemStatsHelpers::cpuFlags.hasSSE2;
  199882. #else
  199883. return false;
  199884. #endif
  199885. }
  199886. bool SystemStats::has3DNow() throw()
  199887. {
  199888. #if JUCE_INTEL
  199889. return SystemStatsHelpers::cpuFlags.has3DNow;
  199890. #else
  199891. return false;
  199892. #endif
  199893. }
  199894. const String SystemStats::getCpuVendor() throw()
  199895. {
  199896. #if JUCE_INTEL
  199897. char v [16];
  199898. SystemStatsHelpers::juce_getCpuVendor (v);
  199899. return String (v, 16);
  199900. #else
  199901. return String::empty;
  199902. #endif
  199903. }
  199904. int SystemStats::getCpuSpeedInMegaherz() throw()
  199905. {
  199906. uint64 speedHz = 0;
  199907. size_t speedSize = sizeof (speedHz);
  199908. int mib[] = { CTL_HW, HW_CPU_FREQ };
  199909. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  199910. #if JUCE_BIG_ENDIAN
  199911. if (speedSize == 4)
  199912. speedHz >>= 32;
  199913. #endif
  199914. return (int) (speedHz / 1000000);
  199915. }
  199916. int SystemStats::getNumCpus() throw()
  199917. {
  199918. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  199919. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  199920. #else
  199921. return MPProcessors();
  199922. #endif
  199923. }
  199924. const String SystemStats::getLogonName()
  199925. {
  199926. return nsStringToJuce (NSUserName());
  199927. }
  199928. const String SystemStats::getFullUserName()
  199929. {
  199930. return nsStringToJuce (NSFullUserName());
  199931. }
  199932. uint32 juce_millisecondsSinceStartup() throw()
  199933. {
  199934. return (uint32) (mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio);
  199935. }
  199936. double Time::getMillisecondCounterHiRes() throw()
  199937. {
  199938. return mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio;
  199939. }
  199940. int64 Time::getHighResolutionTicks() throw()
  199941. {
  199942. return (int64) mach_absolute_time();
  199943. }
  199944. int64 Time::getHighResolutionTicksPerSecond() throw()
  199945. {
  199946. return SystemStatsHelpers::highResTimerFrequency;
  199947. }
  199948. int64 SystemStats::getClockCycleCounter() throw()
  199949. {
  199950. return (int64) mach_absolute_time();
  199951. }
  199952. bool Time::setSystemTimeToThisTime() const throw()
  199953. {
  199954. jassertfalse
  199955. return false;
  199956. }
  199957. int SystemStats::getPageSize() throw()
  199958. {
  199959. return (int) NSPageSize();
  199960. }
  199961. void PlatformUtilities::fpuReset()
  199962. {
  199963. }
  199964. #endif
  199965. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  199966. /*** Start of inlined file: juce_mac_Network.mm ***/
  199967. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199968. // compiled on its own).
  199969. #if JUCE_INCLUDED_FILE
  199970. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  199971. {
  199972. #ifndef IFT_ETHER
  199973. #define IFT_ETHER 6
  199974. #endif
  199975. ifaddrs* addrs = 0;
  199976. int numResults = 0;
  199977. if (getifaddrs (&addrs) == 0)
  199978. {
  199979. const ifaddrs* cursor = addrs;
  199980. while (cursor != 0 && numResults < maxNum)
  199981. {
  199982. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  199983. if (sto->ss_family == AF_LINK)
  199984. {
  199985. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  199986. if (sadd->sdl_type == IFT_ETHER)
  199987. {
  199988. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  199989. uint64 a = 0;
  199990. for (int i = 6; --i >= 0;)
  199991. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  199992. *addresses++ = (int64) a;
  199993. ++numResults;
  199994. }
  199995. }
  199996. cursor = cursor->ifa_next;
  199997. }
  199998. freeifaddrs (addrs);
  199999. }
  200000. return numResults;
  200001. }
  200002. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  200003. const String& emailSubject,
  200004. const String& bodyText,
  200005. const StringArray& filesToAttach)
  200006. {
  200007. #if JUCE_IPHONE
  200008. //xxx probably need to use MFMailComposeViewController
  200009. jassertfalse
  200010. return false;
  200011. #else
  200012. const ScopedAutoReleasePool pool;
  200013. String script;
  200014. script << "tell application \"Mail\"\r\n"
  200015. "set newMessage to make new outgoing message with properties {subject:\""
  200016. << emailSubject.replace (T("\""), T("\\\""))
  200017. << "\", content:\""
  200018. << bodyText.replace (T("\""), T("\\\""))
  200019. << "\" & return & return}\r\n"
  200020. "tell newMessage\r\n"
  200021. "set visible to true\r\n"
  200022. "set sender to \"sdfsdfsdfewf\"\r\n"
  200023. "make new to recipient at end of to recipients with properties {address:\""
  200024. << targetEmailAddress
  200025. << "\"}\r\n";
  200026. for (int i = 0; i < filesToAttach.size(); ++i)
  200027. {
  200028. script << "tell content\r\n"
  200029. "make new attachment with properties {file name:\""
  200030. << filesToAttach[i].replace (T("\""), T("\\\""))
  200031. << "\"} at after the last paragraph\r\n"
  200032. "end tell\r\n";
  200033. }
  200034. script << "end tell\r\n"
  200035. "end tell\r\n";
  200036. NSAppleScript* s = [[NSAppleScript alloc]
  200037. initWithSource: juceStringToNS (script)];
  200038. NSDictionary* error = 0;
  200039. const bool ok = [s executeAndReturnError: &error] != nil;
  200040. [s release];
  200041. return ok;
  200042. #endif
  200043. }
  200044. END_JUCE_NAMESPACE
  200045. using namespace JUCE_NAMESPACE;
  200046. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  200047. @interface JuceURLConnection : NSObject
  200048. {
  200049. @public
  200050. NSURLRequest* request;
  200051. NSURLConnection* connection;
  200052. NSMutableData* data;
  200053. Thread* runLoopThread;
  200054. bool initialised, hasFailed, hasFinished;
  200055. int position;
  200056. int64 contentLength;
  200057. NSLock* dataLock;
  200058. }
  200059. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200060. - (void) dealloc;
  200061. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200062. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200063. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200064. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200065. - (BOOL) isOpen;
  200066. - (int) read: (char*) dest numBytes: (int) num;
  200067. - (int) readPosition;
  200068. - (void) stop;
  200069. - (void) createConnection;
  200070. @end
  200071. class JuceURLConnectionMessageThread : public Thread
  200072. {
  200073. JuceURLConnection* owner;
  200074. public:
  200075. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200076. : Thread (T("http connection")),
  200077. owner (owner_)
  200078. {
  200079. }
  200080. ~JuceURLConnectionMessageThread()
  200081. {
  200082. stopThread (10000);
  200083. }
  200084. void run()
  200085. {
  200086. [owner createConnection];
  200087. while (! threadShouldExit())
  200088. {
  200089. const ScopedAutoReleasePool pool;
  200090. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200091. }
  200092. }
  200093. };
  200094. @implementation JuceURLConnection
  200095. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200096. withCallback: (URL::OpenStreamProgressCallback*) callback
  200097. withContext: (void*) context;
  200098. {
  200099. [super init];
  200100. request = req;
  200101. [request retain];
  200102. data = [[NSMutableData data] retain];
  200103. dataLock = [[NSLock alloc] init];
  200104. connection = 0;
  200105. initialised = false;
  200106. hasFailed = false;
  200107. hasFinished = false;
  200108. contentLength = -1;
  200109. runLoopThread = new JuceURLConnectionMessageThread (self);
  200110. runLoopThread->startThread();
  200111. while (runLoopThread->isThreadRunning() && ! initialised)
  200112. {
  200113. if (callback != 0)
  200114. callback (context, -1, (int) [[request HTTPBody] length]);
  200115. Thread::sleep (1);
  200116. }
  200117. return self;
  200118. }
  200119. - (void) dealloc
  200120. {
  200121. [self stop];
  200122. delete runLoopThread;
  200123. [connection release];
  200124. [data release];
  200125. [dataLock release];
  200126. [request release];
  200127. [super dealloc];
  200128. }
  200129. - (void) createConnection
  200130. {
  200131. connection = [[NSURLConnection alloc] initWithRequest: request
  200132. delegate: [self retain]];
  200133. if (connection == nil)
  200134. runLoopThread->signalThreadShouldExit();
  200135. }
  200136. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200137. {
  200138. [dataLock lock];
  200139. [data setLength: 0];
  200140. [dataLock unlock];
  200141. initialised = true;
  200142. contentLength = [response expectedContentLength];
  200143. }
  200144. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200145. {
  200146. DBG (nsStringToJuce ([error description]));
  200147. hasFailed = true;
  200148. initialised = true;
  200149. runLoopThread->signalThreadShouldExit();
  200150. }
  200151. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200152. {
  200153. [dataLock lock];
  200154. [data appendData: newData];
  200155. [dataLock unlock];
  200156. initialised = true;
  200157. }
  200158. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200159. {
  200160. hasFinished = true;
  200161. initialised = true;
  200162. runLoopThread->signalThreadShouldExit();
  200163. }
  200164. - (BOOL) isOpen
  200165. {
  200166. return connection != 0 && ! hasFailed;
  200167. }
  200168. - (int) readPosition
  200169. {
  200170. return position;
  200171. }
  200172. - (int) read: (char*) dest numBytes: (int) numNeeded
  200173. {
  200174. int numDone = 0;
  200175. while (numNeeded > 0)
  200176. {
  200177. int available = jmin (numNeeded, (int) [data length]);
  200178. if (available > 0)
  200179. {
  200180. [dataLock lock];
  200181. [data getBytes: dest length: available];
  200182. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200183. [dataLock unlock];
  200184. numDone += available;
  200185. numNeeded -= available;
  200186. dest += available;
  200187. }
  200188. else
  200189. {
  200190. if (hasFailed || hasFinished)
  200191. break;
  200192. Thread::sleep (1);
  200193. }
  200194. }
  200195. position += numDone;
  200196. return numDone;
  200197. }
  200198. - (void) stop
  200199. {
  200200. [connection cancel];
  200201. runLoopThread->stopThread (10000);
  200202. }
  200203. @end
  200204. BEGIN_JUCE_NAMESPACE
  200205. bool juce_isOnLine()
  200206. {
  200207. return true;
  200208. }
  200209. void* juce_openInternetFile (const String& url,
  200210. const String& headers,
  200211. const MemoryBlock& postData,
  200212. const bool isPost,
  200213. URL::OpenStreamProgressCallback* callback,
  200214. void* callbackContext,
  200215. int timeOutMs)
  200216. {
  200217. const ScopedAutoReleasePool pool;
  200218. NSMutableURLRequest* req = [NSMutableURLRequest
  200219. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200220. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200221. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200222. if (req == nil)
  200223. return 0;
  200224. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200225. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200226. StringArray headerLines;
  200227. headerLines.addLines (headers);
  200228. headerLines.removeEmptyStrings (true);
  200229. for (int i = 0; i < headerLines.size(); ++i)
  200230. {
  200231. const String key (headerLines[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  200232. const String value (headerLines[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  200233. if (key.isNotEmpty() && value.isNotEmpty())
  200234. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200235. }
  200236. if (isPost && postData.getSize() > 0)
  200237. {
  200238. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200239. length: postData.getSize()]];
  200240. }
  200241. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200242. withCallback: callback
  200243. withContext: callbackContext];
  200244. if ([s isOpen])
  200245. return s;
  200246. [s release];
  200247. return 0;
  200248. }
  200249. void juce_closeInternetFile (void* handle)
  200250. {
  200251. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200252. if (s != 0)
  200253. {
  200254. const ScopedAutoReleasePool pool;
  200255. [s stop];
  200256. [s release];
  200257. }
  200258. }
  200259. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200260. {
  200261. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200262. if (s != 0)
  200263. {
  200264. const ScopedAutoReleasePool pool;
  200265. return [s read: (char*) buffer numBytes: bytesToRead];
  200266. }
  200267. return 0;
  200268. }
  200269. int64 juce_getInternetFileContentLength (void* handle)
  200270. {
  200271. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200272. if (s != 0)
  200273. return s->contentLength;
  200274. return -1;
  200275. }
  200276. int juce_seekInInternetFile (void* handle, int newPosition)
  200277. {
  200278. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200279. if (s != 0)
  200280. return [s readPosition];
  200281. return 0;
  200282. }
  200283. #endif
  200284. /*** End of inlined file: juce_mac_Network.mm ***/
  200285. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200286. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200287. // compiled on its own).
  200288. #if JUCE_INCLUDED_FILE
  200289. struct NamedPipeInternal
  200290. {
  200291. String pipeInName, pipeOutName;
  200292. int pipeIn, pipeOut;
  200293. bool volatile createdPipe, blocked, stopReadOperation;
  200294. static void signalHandler (int) {}
  200295. };
  200296. void NamedPipe::cancelPendingReads()
  200297. {
  200298. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200299. {
  200300. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200301. intern->stopReadOperation = true;
  200302. char buffer [1] = { 0 };
  200303. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200304. (void) bytesWritten;
  200305. int timeout = 2000;
  200306. while (intern->blocked && --timeout >= 0)
  200307. Thread::sleep (2);
  200308. intern->stopReadOperation = false;
  200309. }
  200310. }
  200311. void NamedPipe::close()
  200312. {
  200313. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200314. if (intern != 0)
  200315. {
  200316. internal = 0;
  200317. if (intern->pipeIn != -1)
  200318. ::close (intern->pipeIn);
  200319. if (intern->pipeOut != -1)
  200320. ::close (intern->pipeOut);
  200321. if (intern->createdPipe)
  200322. {
  200323. unlink (intern->pipeInName.toUTF8());
  200324. unlink (intern->pipeOutName.toUTF8());
  200325. }
  200326. delete intern;
  200327. }
  200328. }
  200329. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200330. {
  200331. close();
  200332. NamedPipeInternal* const intern = new NamedPipeInternal();
  200333. internal = intern;
  200334. intern->createdPipe = createPipe;
  200335. intern->blocked = false;
  200336. intern->stopReadOperation = false;
  200337. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200338. siginterrupt (SIGPIPE, 1);
  200339. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  200340. intern->pipeInName = pipePath + T("_in");
  200341. intern->pipeOutName = pipePath + T("_out");
  200342. intern->pipeIn = -1;
  200343. intern->pipeOut = -1;
  200344. if (createPipe)
  200345. {
  200346. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  200347. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  200348. {
  200349. delete intern;
  200350. internal = 0;
  200351. return false;
  200352. }
  200353. }
  200354. return true;
  200355. }
  200356. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200357. {
  200358. int bytesRead = -1;
  200359. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200360. if (intern != 0)
  200361. {
  200362. intern->blocked = true;
  200363. if (intern->pipeIn == -1)
  200364. {
  200365. if (intern->createdPipe)
  200366. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  200367. else
  200368. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  200369. if (intern->pipeIn == -1)
  200370. {
  200371. intern->blocked = false;
  200372. return -1;
  200373. }
  200374. }
  200375. bytesRead = 0;
  200376. char* p = (char*) destBuffer;
  200377. while (bytesRead < maxBytesToRead)
  200378. {
  200379. const int bytesThisTime = maxBytesToRead - bytesRead;
  200380. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200381. if (numRead <= 0 || intern->stopReadOperation)
  200382. {
  200383. bytesRead = -1;
  200384. break;
  200385. }
  200386. bytesRead += numRead;
  200387. p += bytesRead;
  200388. }
  200389. intern->blocked = false;
  200390. }
  200391. return bytesRead;
  200392. }
  200393. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200394. {
  200395. int bytesWritten = -1;
  200396. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200397. if (intern != 0)
  200398. {
  200399. if (intern->pipeOut == -1)
  200400. {
  200401. if (intern->createdPipe)
  200402. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  200403. else
  200404. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  200405. if (intern->pipeOut == -1)
  200406. {
  200407. return -1;
  200408. }
  200409. }
  200410. const char* p = (const char*) sourceBuffer;
  200411. bytesWritten = 0;
  200412. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200413. while (bytesWritten < numBytesToWrite
  200414. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200415. {
  200416. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200417. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200418. if (numWritten <= 0)
  200419. {
  200420. bytesWritten = -1;
  200421. break;
  200422. }
  200423. bytesWritten += numWritten;
  200424. p += bytesWritten;
  200425. }
  200426. }
  200427. return bytesWritten;
  200428. }
  200429. #endif
  200430. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200431. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200432. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200433. // compiled on its own).
  200434. #if JUCE_INCLUDED_FILE
  200435. void JUCE_API juce_threadEntryPoint (void*);
  200436. void* threadEntryProc (void* userData)
  200437. {
  200438. const ScopedAutoReleasePool pool;
  200439. juce_threadEntryPoint (userData);
  200440. return 0;
  200441. }
  200442. void* juce_createThread (void* userData)
  200443. {
  200444. pthread_t handle = 0;
  200445. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200446. {
  200447. pthread_detach (handle);
  200448. return (void*) handle;
  200449. }
  200450. return 0;
  200451. }
  200452. void juce_killThread (void* handle)
  200453. {
  200454. if (handle != 0)
  200455. pthread_cancel ((pthread_t) handle);
  200456. }
  200457. void juce_setCurrentThreadName (const String& /*name*/)
  200458. {
  200459. }
  200460. bool juce_setThreadPriority (void* handle, int priority)
  200461. {
  200462. if (handle == 0)
  200463. handle = (void*) pthread_self();
  200464. struct sched_param param;
  200465. int policy;
  200466. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200467. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200468. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200469. }
  200470. Thread::ThreadID Thread::getCurrentThreadId()
  200471. {
  200472. return static_cast <ThreadID> (pthread_self());
  200473. }
  200474. void Thread::yield()
  200475. {
  200476. sched_yield();
  200477. }
  200478. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200479. {
  200480. // xxx
  200481. jassertfalse
  200482. }
  200483. bool Process::isForegroundProcess()
  200484. {
  200485. #if JUCE_MAC
  200486. return [NSApp isActive];
  200487. #else
  200488. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200489. #endif
  200490. }
  200491. void Process::raisePrivilege()
  200492. {
  200493. jassertfalse
  200494. }
  200495. void Process::lowerPrivilege()
  200496. {
  200497. jassertfalse
  200498. }
  200499. void Process::terminate()
  200500. {
  200501. exit (0);
  200502. }
  200503. void Process::setPriority (ProcessPriority p)
  200504. {
  200505. // xxx
  200506. }
  200507. #endif
  200508. /*** End of inlined file: juce_mac_Threads.mm ***/
  200509. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200510. CriticalSection::CriticalSection() throw()
  200511. {
  200512. pthread_mutexattr_t atts;
  200513. pthread_mutexattr_init (&atts);
  200514. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200515. pthread_mutex_init (&internal, &atts);
  200516. }
  200517. CriticalSection::~CriticalSection() throw()
  200518. {
  200519. pthread_mutex_destroy (&internal);
  200520. }
  200521. void CriticalSection::enter() const throw()
  200522. {
  200523. pthread_mutex_lock (&internal);
  200524. }
  200525. bool CriticalSection::tryEnter() const throw()
  200526. {
  200527. return pthread_mutex_trylock (&internal) == 0;
  200528. }
  200529. void CriticalSection::exit() const throw()
  200530. {
  200531. pthread_mutex_unlock (&internal);
  200532. }
  200533. class WaitableEventImpl
  200534. {
  200535. public:
  200536. WaitableEventImpl()
  200537. : triggered (false)
  200538. {
  200539. pthread_cond_init (&condition, 0);
  200540. pthread_mutex_init (&mutex, 0);
  200541. }
  200542. ~WaitableEventImpl()
  200543. {
  200544. pthread_cond_destroy (&condition);
  200545. pthread_mutex_destroy (&mutex);
  200546. }
  200547. bool wait (const int timeOutMillisecs) throw()
  200548. {
  200549. pthread_mutex_lock (&mutex);
  200550. if (! triggered)
  200551. {
  200552. if (timeOutMillisecs < 0)
  200553. {
  200554. do
  200555. {
  200556. pthread_cond_wait (&condition, &mutex);
  200557. }
  200558. while (! triggered);
  200559. }
  200560. else
  200561. {
  200562. struct timeval now;
  200563. gettimeofday (&now, 0);
  200564. struct timespec time;
  200565. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  200566. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200567. if (time.tv_nsec >= 1000000000)
  200568. {
  200569. time.tv_nsec -= 1000000000;
  200570. time.tv_sec++;
  200571. }
  200572. do
  200573. {
  200574. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  200575. {
  200576. pthread_mutex_unlock (&mutex);
  200577. return false;
  200578. }
  200579. }
  200580. while (! triggered);
  200581. }
  200582. }
  200583. triggered = false;
  200584. pthread_mutex_unlock (&mutex);
  200585. return true;
  200586. }
  200587. void signal() throw()
  200588. {
  200589. pthread_mutex_lock (&mutex);
  200590. triggered = true;
  200591. pthread_cond_broadcast (&condition);
  200592. pthread_mutex_unlock (&mutex);
  200593. }
  200594. void reset() throw()
  200595. {
  200596. pthread_mutex_lock (&mutex);
  200597. triggered = false;
  200598. pthread_mutex_unlock (&mutex);
  200599. }
  200600. private:
  200601. pthread_cond_t condition;
  200602. pthread_mutex_t mutex;
  200603. bool triggered;
  200604. WaitableEventImpl (const WaitableEventImpl&);
  200605. WaitableEventImpl& operator= (const WaitableEventImpl&);
  200606. };
  200607. WaitableEvent::WaitableEvent() throw()
  200608. : internal (new WaitableEventImpl())
  200609. {
  200610. }
  200611. WaitableEvent::~WaitableEvent() throw()
  200612. {
  200613. delete static_cast <WaitableEventImpl*> (internal);
  200614. }
  200615. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200616. {
  200617. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  200618. }
  200619. void WaitableEvent::signal() const throw()
  200620. {
  200621. static_cast <WaitableEventImpl*> (internal)->signal();
  200622. }
  200623. void WaitableEvent::reset() const throw()
  200624. {
  200625. static_cast <WaitableEventImpl*> (internal)->reset();
  200626. }
  200627. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200628. {
  200629. struct timespec time;
  200630. time.tv_sec = millisecs / 1000;
  200631. time.tv_nsec = (millisecs % 1000) * 1000000;
  200632. nanosleep (&time, 0);
  200633. }
  200634. const tchar File::separator = T('/');
  200635. const tchar* File::separatorString = T("/");
  200636. const File File::getCurrentWorkingDirectory()
  200637. {
  200638. HeapBlock<char> heapBuffer;
  200639. char localBuffer [1024];
  200640. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  200641. int bufferSize = 4096;
  200642. while (cwd == 0 && errno == ERANGE)
  200643. {
  200644. heapBuffer.malloc (bufferSize);
  200645. cwd = getcwd (heapBuffer, bufferSize - 1);
  200646. bufferSize += 1024;
  200647. }
  200648. return File (String::fromUTF8 (cwd));
  200649. }
  200650. bool File::setAsCurrentWorkingDirectory() const
  200651. {
  200652. return chdir (getFullPathName().toUTF8()) == 0;
  200653. }
  200654. bool juce_copyFile (const String& s, const String& d);
  200655. static bool juce_stat (const String& fileName, struct stat& info)
  200656. {
  200657. return fileName.isNotEmpty()
  200658. && (stat (fileName.toUTF8(), &info) == 0);
  200659. }
  200660. bool juce_isDirectory (const String& fileName)
  200661. {
  200662. struct stat info;
  200663. return fileName.isEmpty()
  200664. || (juce_stat (fileName, info)
  200665. && ((info.st_mode & S_IFDIR) != 0));
  200666. }
  200667. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200668. {
  200669. if (fileName.isEmpty())
  200670. return false;
  200671. const char* const fileNameUTF8 = fileName.toUTF8();
  200672. bool exists = access (fileNameUTF8, F_OK) == 0;
  200673. if (exists && dontCountDirectories)
  200674. {
  200675. struct stat info;
  200676. const int res = stat (fileNameUTF8, &info);
  200677. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200678. exists = false;
  200679. }
  200680. return exists;
  200681. }
  200682. int64 juce_getFileSize (const String& fileName)
  200683. {
  200684. struct stat info;
  200685. return juce_stat (fileName, info) ? info.st_size : 0;
  200686. }
  200687. bool juce_canWriteToFile (const String& fileName)
  200688. {
  200689. return access (fileName.toUTF8(), W_OK) == 0;
  200690. }
  200691. bool juce_deleteFile (const String& fileName)
  200692. {
  200693. if (juce_isDirectory (fileName))
  200694. return rmdir (fileName.toUTF8()) == 0;
  200695. else
  200696. return remove (fileName.toUTF8()) == 0;
  200697. }
  200698. bool juce_moveFile (const String& source, const String& dest)
  200699. {
  200700. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  200701. return true;
  200702. if (juce_canWriteToFile (source)
  200703. && juce_copyFile (source, dest))
  200704. {
  200705. if (juce_deleteFile (source))
  200706. return true;
  200707. juce_deleteFile (dest);
  200708. }
  200709. return false;
  200710. }
  200711. void juce_createDirectory (const String& fileName)
  200712. {
  200713. mkdir (fileName.toUTF8(), 0777);
  200714. }
  200715. void* juce_fileOpen (const String& fileName, bool forWriting)
  200716. {
  200717. int flags = O_RDONLY;
  200718. if (forWriting)
  200719. {
  200720. if (juce_fileExists (fileName, false))
  200721. {
  200722. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  200723. if (f != -1)
  200724. lseek (f, 0, SEEK_END);
  200725. return (void*) f;
  200726. }
  200727. else
  200728. {
  200729. flags = O_RDWR + O_CREAT;
  200730. }
  200731. }
  200732. return (void*) open (fileName.toUTF8(), flags, 00644);
  200733. }
  200734. void juce_fileClose (void* handle)
  200735. {
  200736. if (handle != 0)
  200737. close ((int) (pointer_sized_int) handle);
  200738. }
  200739. int juce_fileRead (void* handle, void* buffer, int size)
  200740. {
  200741. if (handle != 0)
  200742. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  200743. return 0;
  200744. }
  200745. int juce_fileWrite (void* handle, const void* buffer, int size)
  200746. {
  200747. if (handle != 0)
  200748. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  200749. return 0;
  200750. }
  200751. int64 juce_fileSetPosition (void* handle, int64 pos)
  200752. {
  200753. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  200754. return pos;
  200755. return -1;
  200756. }
  200757. int64 juce_fileGetPosition (void* handle)
  200758. {
  200759. if (handle != 0)
  200760. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  200761. else
  200762. return -1;
  200763. }
  200764. void juce_fileFlush (void* handle)
  200765. {
  200766. if (handle != 0)
  200767. fsync ((int) (pointer_sized_int) handle);
  200768. }
  200769. const File juce_getExecutableFile()
  200770. {
  200771. Dl_info exeInfo;
  200772. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  200773. return File (String::fromUTF8 (exeInfo.dli_fname));
  200774. }
  200775. // if this file doesn't exist, find a parent of it that does..
  200776. static bool doStatFS (const File* file, struct statfs& result)
  200777. {
  200778. File f (*file);
  200779. for (int i = 5; --i >= 0;)
  200780. {
  200781. if (f.exists())
  200782. break;
  200783. f = f.getParentDirectory();
  200784. }
  200785. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  200786. }
  200787. int64 File::getBytesFreeOnVolume() const
  200788. {
  200789. struct statfs buf;
  200790. if (doStatFS (this, buf))
  200791. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  200792. return 0;
  200793. }
  200794. int64 File::getVolumeTotalSize() const
  200795. {
  200796. struct statfs buf;
  200797. if (doStatFS (this, buf))
  200798. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  200799. return 0;
  200800. }
  200801. const String juce_getVolumeLabel (const String& filenameOnVolume,
  200802. int& volumeSerialNumber)
  200803. {
  200804. volumeSerialNumber = 0;
  200805. #if JUCE_MAC
  200806. struct VolAttrBuf
  200807. {
  200808. u_int32_t length;
  200809. attrreference_t mountPointRef;
  200810. char mountPointSpace [MAXPATHLEN];
  200811. } attrBuf;
  200812. struct attrlist attrList;
  200813. zerostruct (attrList);
  200814. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  200815. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  200816. File f (filenameOnVolume);
  200817. for (;;)
  200818. {
  200819. if (getattrlist (f.getFullPathName().toUTF8(),
  200820. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  200821. {
  200822. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  200823. (int) attrBuf.mountPointRef.attr_length);
  200824. }
  200825. const File parent (f.getParentDirectory());
  200826. if (f == parent)
  200827. break;
  200828. f = parent;
  200829. }
  200830. #endif
  200831. return String::empty;
  200832. }
  200833. void juce_runSystemCommand (const String& command)
  200834. {
  200835. int result = system (command.toUTF8());
  200836. (void) result;
  200837. }
  200838. const String juce_getOutputFromCommand (const String& command)
  200839. {
  200840. // slight bodge here, as we just pipe the output into a temp file and read it...
  200841. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  200842. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  200843. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  200844. String result (tempFile.loadFileAsString());
  200845. tempFile.deleteFile();
  200846. return result;
  200847. }
  200848. InterProcessLock::InterProcessLock (const String& name_)
  200849. : internal (0),
  200850. name (name_),
  200851. reentrancyLevel (0)
  200852. {
  200853. #if JUCE_MAC
  200854. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  200855. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  200856. #else
  200857. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  200858. #endif
  200859. temp.create();
  200860. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  200861. }
  200862. InterProcessLock::~InterProcessLock()
  200863. {
  200864. while (reentrancyLevel > 0)
  200865. this->exit();
  200866. close (internal);
  200867. }
  200868. bool InterProcessLock::enter (const int timeOutMillisecs)
  200869. {
  200870. if (internal == 0)
  200871. return false;
  200872. if (reentrancyLevel != 0)
  200873. return true;
  200874. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  200875. struct flock fl;
  200876. zerostruct (fl);
  200877. fl.l_whence = SEEK_SET;
  200878. fl.l_type = F_WRLCK;
  200879. for (;;)
  200880. {
  200881. const int result = fcntl (internal, F_SETLK, &fl);
  200882. if (result >= 0)
  200883. {
  200884. ++reentrancyLevel;
  200885. return true;
  200886. }
  200887. if (errno != EINTR)
  200888. {
  200889. if (timeOutMillisecs == 0
  200890. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  200891. break;
  200892. Thread::sleep (10);
  200893. }
  200894. }
  200895. return false;
  200896. }
  200897. void InterProcessLock::exit()
  200898. {
  200899. if (reentrancyLevel > 0 && internal != 0)
  200900. {
  200901. --reentrancyLevel;
  200902. struct flock fl;
  200903. zerostruct (fl);
  200904. fl.l_whence = SEEK_SET;
  200905. fl.l_type = F_UNLCK;
  200906. for (;;)
  200907. {
  200908. const int result = fcntl (internal, F_SETLKW, &fl);
  200909. if (result >= 0 || errno != EINTR)
  200910. break;
  200911. }
  200912. }
  200913. }
  200914. /*** End of inlined file: juce_posix_SharedCode.h ***/
  200915. /*** Start of inlined file: juce_mac_Files.mm ***/
  200916. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200917. // compiled on its own).
  200918. #if JUCE_INCLUDED_FILE
  200919. void juce_getFileTimes (const String& fileName,
  200920. int64& modificationTime,
  200921. int64& accessTime,
  200922. int64& creationTime)
  200923. {
  200924. modificationTime = 0;
  200925. accessTime = 0;
  200926. creationTime = 0;
  200927. struct stat info;
  200928. const int res = stat (fileName.toUTF8(), &info);
  200929. if (res == 0)
  200930. {
  200931. modificationTime = (int64) info.st_mtime * 1000;
  200932. accessTime = (int64) info.st_atime * 1000;
  200933. creationTime = (int64) info.st_ctime * 1000;
  200934. }
  200935. }
  200936. bool juce_setFileTimes (const String& fileName,
  200937. int64 modificationTime,
  200938. int64 accessTime,
  200939. int64 creationTime)
  200940. {
  200941. struct utimbuf times;
  200942. times.actime = (time_t) (accessTime / 1000);
  200943. times.modtime = (time_t) (modificationTime / 1000);
  200944. return utime (fileName.toUTF8(), &times) == 0;
  200945. }
  200946. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  200947. {
  200948. struct stat info;
  200949. const int res = stat (fileName.toUTF8(), &info);
  200950. if (res != 0)
  200951. return false;
  200952. info.st_mode &= 0777; // Just permissions
  200953. if (isReadOnly)
  200954. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  200955. else
  200956. // Give everybody write permission?
  200957. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  200958. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  200959. }
  200960. bool juce_copyFile (const String& src, const String& dst)
  200961. {
  200962. const ScopedAutoReleasePool pool;
  200963. NSFileManager* fm = [NSFileManager defaultManager];
  200964. return [fm fileExistsAtPath: juceStringToNS (src)]
  200965. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  200966. && [fm copyItemAtPath: juceStringToNS (src)
  200967. toPath: juceStringToNS (dst)
  200968. error: nil];
  200969. #else
  200970. && [fm copyPath: juceStringToNS (src)
  200971. toPath: juceStringToNS (dst)
  200972. handler: nil];
  200973. #endif
  200974. }
  200975. const StringArray juce_getFileSystemRoots()
  200976. {
  200977. StringArray s;
  200978. s.add (T("/"));
  200979. return s;
  200980. }
  200981. static bool isFileOnDriveType (const File* const f, const char** types)
  200982. {
  200983. struct statfs buf;
  200984. if (doStatFS (f, buf))
  200985. {
  200986. const String type (buf.f_fstypename);
  200987. while (*types != 0)
  200988. if (type.equalsIgnoreCase (*types++))
  200989. return true;
  200990. }
  200991. return false;
  200992. }
  200993. bool File::isOnCDRomDrive() const
  200994. {
  200995. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  200996. return isFileOnDriveType (this, (const char**) cdTypes);
  200997. }
  200998. bool File::isOnHardDisk() const
  200999. {
  201000. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  201001. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  201002. }
  201003. bool File::isOnRemovableDrive() const
  201004. {
  201005. #if JUCE_IPHONE
  201006. return false; // xxx is this possible?
  201007. #else
  201008. const ScopedAutoReleasePool pool;
  201009. BOOL removable = false;
  201010. [[NSWorkspace sharedWorkspace]
  201011. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  201012. isRemovable: &removable
  201013. isWritable: nil
  201014. isUnmountable: nil
  201015. description: nil
  201016. type: nil];
  201017. return removable;
  201018. #endif
  201019. }
  201020. static bool juce_isHiddenFile (const String& path)
  201021. {
  201022. #if JUCE_IPHONE
  201023. return File (path).getFileName().startsWithChar (T('.'));
  201024. #else
  201025. FSRef ref;
  201026. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  201027. return false;
  201028. FSCatalogInfo info;
  201029. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  201030. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  201031. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201032. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201033. #endif
  201034. }
  201035. bool File::isHidden() const
  201036. {
  201037. return juce_isHiddenFile (getFullPathName());
  201038. }
  201039. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  201040. const File File::getSpecialLocation (const SpecialLocationType type)
  201041. {
  201042. const ScopedAutoReleasePool pool;
  201043. String resultPath;
  201044. switch (type)
  201045. {
  201046. case userHomeDirectory:
  201047. resultPath = nsStringToJuce (NSHomeDirectory());
  201048. break;
  201049. case userDocumentsDirectory:
  201050. resultPath = "~/Documents";
  201051. break;
  201052. case userDesktopDirectory:
  201053. resultPath = "~/Desktop";
  201054. break;
  201055. case userApplicationDataDirectory:
  201056. resultPath = "~/Library";
  201057. break;
  201058. case commonApplicationDataDirectory:
  201059. resultPath = "/Library";
  201060. break;
  201061. case globalApplicationsDirectory:
  201062. resultPath = "/Applications";
  201063. break;
  201064. case userMusicDirectory:
  201065. resultPath = "~/Music";
  201066. break;
  201067. case userMoviesDirectory:
  201068. resultPath = "~/Movies";
  201069. break;
  201070. case tempDirectory:
  201071. {
  201072. File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
  201073. tmp.createDirectory();
  201074. return tmp.getFullPathName();
  201075. }
  201076. case invokedExecutableFile:
  201077. if (juce_Argv0 != 0)
  201078. return File (String::fromUTF8 (juce_Argv0));
  201079. // deliberate fall-through...
  201080. case currentExecutableFile:
  201081. return juce_getExecutableFile();
  201082. case currentApplicationFile:
  201083. {
  201084. const File exe (juce_getExecutableFile());
  201085. const File parent (exe.getParentDirectory());
  201086. return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
  201087. ? parent.getParentDirectory().getParentDirectory()
  201088. : exe;
  201089. }
  201090. default:
  201091. jassertfalse // unknown type?
  201092. break;
  201093. }
  201094. if (resultPath.isNotEmpty())
  201095. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201096. return File::nonexistent;
  201097. }
  201098. const String File::getVersion() const
  201099. {
  201100. const ScopedAutoReleasePool pool;
  201101. String result;
  201102. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201103. if (bundle != 0)
  201104. {
  201105. NSDictionary* info = [bundle infoDictionary];
  201106. if (info != 0)
  201107. {
  201108. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201109. if (name != nil)
  201110. result = nsStringToJuce (name);
  201111. }
  201112. }
  201113. return result;
  201114. }
  201115. const File File::getLinkedTarget() const
  201116. {
  201117. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201118. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201119. #else
  201120. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201121. #endif
  201122. if (dest != nil)
  201123. return File (nsStringToJuce (dest));
  201124. return *this;
  201125. }
  201126. bool File::moveToTrash() const
  201127. {
  201128. if (! exists())
  201129. return true;
  201130. #if JUCE_IPHONE
  201131. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201132. #else
  201133. const ScopedAutoReleasePool pool;
  201134. NSString* p = juceStringToNS (getFullPathName());
  201135. return [[NSWorkspace sharedWorkspace]
  201136. performFileOperation: NSWorkspaceRecycleOperation
  201137. source: [p stringByDeletingLastPathComponent]
  201138. destination: @""
  201139. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201140. tag: nil ];
  201141. #endif
  201142. }
  201143. struct FindFileStruct
  201144. {
  201145. NSDirectoryEnumerator* enumerator;
  201146. String parentDir, wildCard;
  201147. };
  201148. bool juce_findFileNext (void* handle, String& resultFile,
  201149. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201150. {
  201151. ScopedAutoReleasePool pool;
  201152. FindFileStruct* ff = (FindFileStruct*) handle;
  201153. NSString* file;
  201154. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201155. for (;;)
  201156. {
  201157. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201158. return false;
  201159. [ff->enumerator skipDescendents];
  201160. resultFile = nsStringToJuce (file);
  201161. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201162. continue;
  201163. const String path (ff->parentDir + resultFile);
  201164. if (isDir != 0 || fileSize != 0)
  201165. {
  201166. struct stat info;
  201167. const bool statOk = juce_stat (path, info);
  201168. if (isDir != 0)
  201169. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201170. if (isHidden != 0)
  201171. *isHidden = juce_isHiddenFile (path);
  201172. if (fileSize != 0)
  201173. *fileSize = statOk ? info.st_size : 0;
  201174. }
  201175. if (modTime != 0 || creationTime != 0)
  201176. {
  201177. int64 m, a, c;
  201178. juce_getFileTimes (path, m, a, c);
  201179. if (modTime != 0)
  201180. *modTime = m;
  201181. if (creationTime != 0)
  201182. *creationTime = c;
  201183. }
  201184. if (isReadOnly != 0)
  201185. *isReadOnly = ! juce_canWriteToFile (path);
  201186. return true;
  201187. }
  201188. }
  201189. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201190. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201191. Time* creationTime, bool* isReadOnly)
  201192. {
  201193. ScopedAutoReleasePool pool;
  201194. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201195. if (e != 0)
  201196. {
  201197. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201198. ff->enumerator = [e retain];
  201199. ff->parentDir = directory;
  201200. ff->wildCard = wildCard;
  201201. if (! ff->parentDir.endsWithChar (File::separator))
  201202. ff->parentDir += File::separator;
  201203. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201204. return ff.release();
  201205. [e release];
  201206. }
  201207. return 0;
  201208. }
  201209. void juce_findFileClose (void* handle)
  201210. {
  201211. ScopedAutoReleasePool pool;
  201212. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201213. [ff->enumerator release];
  201214. }
  201215. bool juce_launchExecutable (const String& pathAndArguments)
  201216. {
  201217. const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 };
  201218. const int cpid = fork();
  201219. if (cpid == 0)
  201220. {
  201221. // Child process
  201222. if (execve (argv[0], (char**) argv, 0) < 0)
  201223. exit (0);
  201224. }
  201225. else
  201226. {
  201227. if (cpid < 0)
  201228. return false;
  201229. }
  201230. return true;
  201231. }
  201232. bool juce_launchFile (const String& fileName, const String& parameters)
  201233. {
  201234. #if JUCE_IPHONE
  201235. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201236. #else
  201237. const ScopedAutoReleasePool pool;
  201238. if (parameters.isEmpty())
  201239. {
  201240. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201241. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201242. }
  201243. bool ok = false;
  201244. FSRef ref;
  201245. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201246. {
  201247. if (PlatformUtilities::isBundle (fileName))
  201248. {
  201249. NSMutableArray* urls = [NSMutableArray array];
  201250. StringArray docs;
  201251. docs.addTokens (parameters, true);
  201252. for (int i = 0; i < docs.size(); ++i)
  201253. [urls addObject: juceStringToNS (docs[i])];
  201254. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201255. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201256. options: 0
  201257. additionalEventParamDescriptor: nil
  201258. launchIdentifiers: nil];
  201259. }
  201260. else
  201261. {
  201262. ok = juce_launchExecutable (T("\"") + fileName + T("\" ") + parameters);
  201263. }
  201264. }
  201265. return ok;
  201266. #endif
  201267. }
  201268. void File::revealToUser() const
  201269. {
  201270. #if ! JUCE_IPHONE
  201271. if (exists())
  201272. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201273. else if (getParentDirectory().exists())
  201274. getParentDirectory().revealToUser();
  201275. #endif
  201276. }
  201277. #if ! JUCE_IPHONE
  201278. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201279. {
  201280. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201281. }
  201282. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201283. {
  201284. char path [2048];
  201285. zerostruct (path);
  201286. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201287. return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path));
  201288. return String::empty;
  201289. }
  201290. #endif
  201291. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201292. {
  201293. const ScopedAutoReleasePool pool;
  201294. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201295. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201296. #else
  201297. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201298. #endif
  201299. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201300. return [fileDict fileHFSTypeCode];
  201301. }
  201302. bool PlatformUtilities::isBundle (const String& filename)
  201303. {
  201304. #if JUCE_IPHONE
  201305. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201306. #else
  201307. const ScopedAutoReleasePool pool;
  201308. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201309. #endif
  201310. }
  201311. #endif
  201312. /*** End of inlined file: juce_mac_Files.mm ***/
  201313. #if JUCE_IPHONE
  201314. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201315. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201316. // compiled on its own).
  201317. #if JUCE_INCLUDED_FILE
  201318. static JUCEApplication* juce_intialisingApp;
  201319. END_JUCE_NAMESPACE
  201320. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201321. {
  201322. }
  201323. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201324. - (void) applicationWillResignActive: (UIApplication*) application;
  201325. @end
  201326. @implementation JuceAppStartupDelegate
  201327. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201328. {
  201329. String dummy;
  201330. if (! juce_intialisingApp->initialiseApp (dummy))
  201331. exit (0);
  201332. }
  201333. - (void) applicationWillResignActive: (UIApplication*) application
  201334. {
  201335. JUCEApplication::shutdownAppAndClearUp();
  201336. }
  201337. @end
  201338. BEGIN_JUCE_NAMESPACE
  201339. int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app)
  201340. {
  201341. juce_intialisingApp = app;
  201342. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  201343. }
  201344. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201345. {
  201346. pool = [[NSAutoreleasePool alloc] init];
  201347. }
  201348. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201349. {
  201350. [((NSAutoreleasePool*) pool) release];
  201351. }
  201352. void PlatformUtilities::beep()
  201353. {
  201354. //xxx
  201355. //AudioServicesPlaySystemSound ();
  201356. }
  201357. void PlatformUtilities::addItemToDock (const File& file)
  201358. {
  201359. }
  201360. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201361. END_JUCE_NAMESPACE
  201362. @interface JuceAlertBoxDelegate : NSObject
  201363. {
  201364. @public
  201365. bool clickedOk;
  201366. }
  201367. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201368. @end
  201369. @implementation JuceAlertBoxDelegate
  201370. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201371. {
  201372. clickedOk = (buttonIndex == 0);
  201373. alertView.hidden = true;
  201374. }
  201375. @end
  201376. BEGIN_JUCE_NAMESPACE
  201377. // (This function is used directly by other bits of code)
  201378. bool juce_iPhoneShowModalAlert (const String& title,
  201379. const String& bodyText,
  201380. NSString* okButtonText,
  201381. NSString* cancelButtonText)
  201382. {
  201383. const ScopedAutoReleasePool pool;
  201384. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201385. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201386. message: juceStringToNS (bodyText)
  201387. delegate: callback
  201388. cancelButtonTitle: okButtonText
  201389. otherButtonTitles: cancelButtonText, nil];
  201390. [alert retain];
  201391. [alert show];
  201392. while (! alert.hidden && alert.superview != nil)
  201393. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201394. const bool result = callback->clickedOk;
  201395. [alert release];
  201396. [callback release];
  201397. return result;
  201398. }
  201399. bool AlertWindow::showNativeDialogBox (const String& title,
  201400. const String& bodyText,
  201401. bool isOkCancel)
  201402. {
  201403. return juce_iPhoneShowModalAlert (title, bodyText,
  201404. @"OK",
  201405. isOkCancel ? @"Cancel" : nil);
  201406. }
  201407. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201408. {
  201409. jassertfalse // no such thing on the iphone!
  201410. return false;
  201411. }
  201412. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201413. {
  201414. jassertfalse // no such thing on the iphone!
  201415. return false;
  201416. }
  201417. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201418. {
  201419. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201420. }
  201421. bool Desktop::isScreenSaverEnabled() throw()
  201422. {
  201423. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201424. }
  201425. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201426. {
  201427. const ScopedAutoReleasePool pool;
  201428. monitorCoords.clear();
  201429. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201430. : [[UIScreen mainScreen] bounds];
  201431. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201432. (int) r.origin.y,
  201433. (int) r.size.width,
  201434. (int) r.size.height));
  201435. }
  201436. #endif
  201437. #endif
  201438. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201439. #else
  201440. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201441. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201442. // compiled on its own).
  201443. #if JUCE_INCLUDED_FILE
  201444. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201445. {
  201446. pool = [[NSAutoreleasePool alloc] init];
  201447. }
  201448. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201449. {
  201450. [((NSAutoreleasePool*) pool) release];
  201451. }
  201452. void PlatformUtilities::beep()
  201453. {
  201454. NSBeep();
  201455. }
  201456. void PlatformUtilities::addItemToDock (const File& file)
  201457. {
  201458. // check that it's not already there...
  201459. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201460. .containsIgnoreCase (file.getFullPathName()))
  201461. {
  201462. 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>"
  201463. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201464. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201465. }
  201466. }
  201467. int PlatformUtilities::getOSXMinorVersionNumber()
  201468. {
  201469. SInt32 versionMinor = 0;
  201470. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201471. (void) err;
  201472. jassert (err == noErr);
  201473. return (int) versionMinor;
  201474. }
  201475. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201476. bool AlertWindow::showNativeDialogBox (const String& title,
  201477. const String& bodyText,
  201478. bool isOkCancel)
  201479. {
  201480. const ScopedAutoReleasePool pool;
  201481. return NSRunAlertPanel (juceStringToNS (title),
  201482. juceStringToNS (bodyText),
  201483. @"Ok",
  201484. isOkCancel ? @"Cancel" : nil,
  201485. nil) == NSAlertDefaultReturn;
  201486. }
  201487. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201488. {
  201489. if (files.size() == 0)
  201490. return false;
  201491. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource(0);
  201492. if (draggingSource == 0)
  201493. {
  201494. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201495. return false;
  201496. }
  201497. Component* sourceComp = draggingSource->getComponentUnderMouse();
  201498. if (sourceComp == 0)
  201499. {
  201500. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201501. return false;
  201502. }
  201503. const ScopedAutoReleasePool pool;
  201504. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201505. if (view == 0)
  201506. return false;
  201507. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201508. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201509. owner: nil];
  201510. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201511. for (int i = 0; i < files.size(); ++i)
  201512. [filesArray addObject: juceStringToNS (files[i])];
  201513. [pboard setPropertyList: filesArray
  201514. forType: NSFilenamesPboardType];
  201515. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201516. fromView: nil];
  201517. dragPosition.x -= 16;
  201518. dragPosition.y -= 16;
  201519. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201520. at: dragPosition
  201521. offset: NSMakeSize (0, 0)
  201522. event: [[view window] currentEvent]
  201523. pasteboard: pboard
  201524. source: view
  201525. slideBack: YES];
  201526. return true;
  201527. }
  201528. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201529. {
  201530. jassertfalse // not implemented!
  201531. return false;
  201532. }
  201533. bool Desktop::canUseSemiTransparentWindows() throw()
  201534. {
  201535. return true;
  201536. }
  201537. const Point<int> Desktop::getMousePosition()
  201538. {
  201539. const ScopedAutoReleasePool pool;
  201540. const NSPoint p ([NSEvent mouseLocation]);
  201541. return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
  201542. }
  201543. void Desktop::setMousePosition (const Point<int>& newPosition)
  201544. {
  201545. // this rubbish needs to be done around the warp call, to avoid causing a
  201546. // bizarre glitch..
  201547. CGAssociateMouseAndMouseCursorPosition (false);
  201548. CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY()));
  201549. CGAssociateMouseAndMouseCursorPosition (true);
  201550. }
  201551. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201552. class ScreenSaverDefeater : public Timer,
  201553. public DeletedAtShutdown
  201554. {
  201555. public:
  201556. ScreenSaverDefeater() throw()
  201557. {
  201558. startTimer (10000);
  201559. timerCallback();
  201560. }
  201561. ~ScreenSaverDefeater() {}
  201562. void timerCallback()
  201563. {
  201564. if (Process::isForegroundProcess())
  201565. UpdateSystemActivity (UsrActivity);
  201566. }
  201567. };
  201568. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201569. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201570. {
  201571. if (isEnabled)
  201572. {
  201573. deleteAndZero (screenSaverDefeater);
  201574. }
  201575. else if (screenSaverDefeater == 0)
  201576. {
  201577. screenSaverDefeater = new ScreenSaverDefeater();
  201578. }
  201579. }
  201580. bool Desktop::isScreenSaverEnabled() throw()
  201581. {
  201582. return screenSaverDefeater == 0;
  201583. }
  201584. #else
  201585. static IOPMAssertionID screenSaverDisablerID = 0;
  201586. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201587. {
  201588. if (isEnabled)
  201589. {
  201590. if (screenSaverDisablerID != 0)
  201591. {
  201592. IOPMAssertionRelease (screenSaverDisablerID);
  201593. screenSaverDisablerID = 0;
  201594. }
  201595. }
  201596. else
  201597. {
  201598. if (screenSaverDisablerID == 0)
  201599. {
  201600. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201601. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201602. CFSTR ("Juce"), &screenSaverDisablerID);
  201603. #else
  201604. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201605. &screenSaverDisablerID);
  201606. #endif
  201607. }
  201608. }
  201609. }
  201610. bool Desktop::isScreenSaverEnabled() throw()
  201611. {
  201612. return screenSaverDisablerID == 0;
  201613. }
  201614. #endif
  201615. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201616. {
  201617. const ScopedAutoReleasePool pool;
  201618. monitorCoords.clear();
  201619. NSArray* screens = [NSScreen screens];
  201620. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201621. for (unsigned int i = 0; i < [screens count]; ++i)
  201622. {
  201623. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201624. NSRect r = clipToWorkArea ? [s visibleFrame]
  201625. : [s frame];
  201626. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201627. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201628. (int) r.size.width,
  201629. (int) r.size.height));
  201630. }
  201631. jassert (monitorCoords.size() > 0);
  201632. }
  201633. #endif
  201634. #endif
  201635. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201636. #endif
  201637. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201638. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201639. // compiled on its own).
  201640. #if JUCE_INCLUDED_FILE
  201641. void Logger::outputDebugString (const String& text) throw()
  201642. {
  201643. std::cerr << text << std::endl;
  201644. }
  201645. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201646. {
  201647. static char testResult = 0;
  201648. if (testResult == 0)
  201649. {
  201650. struct kinfo_proc info;
  201651. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201652. size_t sz = sizeof (info);
  201653. sysctl (m, 4, &info, &sz, 0, 0);
  201654. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201655. }
  201656. return testResult > 0;
  201657. }
  201658. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201659. {
  201660. return juce_isRunningUnderDebugger();
  201661. }
  201662. #endif
  201663. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201664. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201665. #if JUCE_IPHONE
  201666. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201667. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201668. // compiled on its own).
  201669. #if JUCE_INCLUDED_FILE
  201670. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201671. #define SUPPORT_10_4_FONTS 1
  201672. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201673. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201674. #define SUPPORT_ONLY_10_4_FONTS 1
  201675. #endif
  201676. END_JUCE_NAMESPACE
  201677. @interface NSFont (PrivateHack)
  201678. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201679. @end
  201680. BEGIN_JUCE_NAMESPACE
  201681. #endif
  201682. class MacTypeface : public Typeface
  201683. {
  201684. public:
  201685. MacTypeface (const Font& font)
  201686. : Typeface (font.getTypefaceName())
  201687. {
  201688. const ScopedAutoReleasePool pool;
  201689. renderingTransform = CGAffineTransformIdentity;
  201690. bool needsItalicTransform = false;
  201691. #if JUCE_IPHONE
  201692. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201693. if (font.isItalic() || font.isBold())
  201694. {
  201695. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201696. for (NSString* i in familyFonts)
  201697. {
  201698. const String fn (nsStringToJuce (i));
  201699. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  201700. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  201701. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  201702. || afterDash.containsIgnoreCase (T("italic"))
  201703. || fn.endsWithIgnoreCase (T("oblique"))
  201704. || fn.endsWithIgnoreCase (T("italic"));
  201705. if (probablyBold == font.isBold()
  201706. && probablyItalic == font.isItalic())
  201707. {
  201708. fontName = i;
  201709. needsItalicTransform = false;
  201710. break;
  201711. }
  201712. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  201713. {
  201714. fontName = i;
  201715. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  201716. }
  201717. }
  201718. if (needsItalicTransform)
  201719. renderingTransform.c = 0.15f;
  201720. }
  201721. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  201722. const int ascender = abs (CGFontGetAscent (fontRef));
  201723. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  201724. ascent = ascender / totalHeight;
  201725. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201726. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  201727. #else
  201728. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  201729. if (font.isItalic())
  201730. {
  201731. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  201732. toHaveTrait: NSItalicFontMask];
  201733. if (newFont == nsFont)
  201734. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  201735. nsFont = newFont;
  201736. }
  201737. if (font.isBold())
  201738. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  201739. [nsFont retain];
  201740. ascent = fabsf ((float) [nsFont ascender]);
  201741. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  201742. ascent /= totalSize;
  201743. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  201744. if (needsItalicTransform)
  201745. {
  201746. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  201747. renderingTransform.c = 0.15f;
  201748. }
  201749. #if SUPPORT_ONLY_10_4_FONTS
  201750. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201751. if (atsFont == 0)
  201752. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201753. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201754. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201755. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201756. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201757. #else
  201758. #if SUPPORT_10_4_FONTS
  201759. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201760. {
  201761. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201762. if (atsFont == 0)
  201763. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201764. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  201765. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201766. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201767. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201768. }
  201769. else
  201770. #endif
  201771. {
  201772. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  201773. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  201774. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201775. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  201776. }
  201777. #endif
  201778. #endif
  201779. }
  201780. ~MacTypeface()
  201781. {
  201782. #if ! JUCE_IPHONE
  201783. [nsFont release];
  201784. #endif
  201785. if (fontRef != 0)
  201786. CGFontRelease (fontRef);
  201787. }
  201788. float getAscent() const
  201789. {
  201790. return ascent;
  201791. }
  201792. float getDescent() const
  201793. {
  201794. return 1.0f - ascent;
  201795. }
  201796. float getStringWidth (const String& text)
  201797. {
  201798. if (fontRef == 0 || text.isEmpty())
  201799. return 0;
  201800. const int length = text.length();
  201801. HeapBlock <CGGlyph> glyphs;
  201802. createGlyphsForString (text, length, glyphs);
  201803. float x = 0;
  201804. #if SUPPORT_ONLY_10_4_FONTS
  201805. HeapBlock <NSSize> advances (length);
  201806. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201807. for (int i = 0; i < length; ++i)
  201808. x += advances[i].width;
  201809. #else
  201810. #if SUPPORT_10_4_FONTS
  201811. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201812. {
  201813. HeapBlock <NSSize> advances (length);
  201814. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  201815. for (int i = 0; i < length; ++i)
  201816. x += advances[i].width;
  201817. }
  201818. else
  201819. #endif
  201820. {
  201821. HeapBlock <int> advances (length);
  201822. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201823. for (int i = 0; i < length; ++i)
  201824. x += advances[i];
  201825. }
  201826. #endif
  201827. return x * unitsToHeightScaleFactor;
  201828. }
  201829. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  201830. {
  201831. xOffsets.add (0);
  201832. if (fontRef == 0 || text.isEmpty())
  201833. return;
  201834. const int length = text.length();
  201835. HeapBlock <CGGlyph> glyphs;
  201836. createGlyphsForString (text, length, glyphs);
  201837. #if SUPPORT_ONLY_10_4_FONTS
  201838. HeapBlock <NSSize> advances (length);
  201839. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201840. int x = 0;
  201841. for (int i = 0; i < length; ++i)
  201842. {
  201843. x += advances[i].width;
  201844. xOffsets.add (x * unitsToHeightScaleFactor);
  201845. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  201846. }
  201847. #else
  201848. #if SUPPORT_10_4_FONTS
  201849. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201850. {
  201851. HeapBlock <NSSize> advances (length);
  201852. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201853. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  201854. float x = 0;
  201855. for (int i = 0; i < length; ++i)
  201856. {
  201857. x += advances[i].width;
  201858. xOffsets.add (x * unitsToHeightScaleFactor);
  201859. resultGlyphs.add (nsGlyphs[i]);
  201860. }
  201861. }
  201862. else
  201863. #endif
  201864. {
  201865. HeapBlock <int> advances (length);
  201866. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201867. {
  201868. int x = 0;
  201869. for (int i = 0; i < length; ++i)
  201870. {
  201871. x += advances [i];
  201872. xOffsets.add (x * unitsToHeightScaleFactor);
  201873. resultGlyphs.add (glyphs[i]);
  201874. }
  201875. }
  201876. }
  201877. #endif
  201878. }
  201879. bool getOutlineForGlyph (int glyphNumber, Path& path)
  201880. {
  201881. #if JUCE_IPHONE
  201882. return false;
  201883. #else
  201884. if (nsFont == 0)
  201885. return false;
  201886. // we might need to apply a transform to the path, so it mustn't have anything else in it
  201887. jassert (path.isEmpty());
  201888. const ScopedAutoReleasePool pool;
  201889. NSBezierPath* bez = [NSBezierPath bezierPath];
  201890. [bez moveToPoint: NSMakePoint (0, 0)];
  201891. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  201892. inFont: nsFont];
  201893. for (int i = 0; i < [bez elementCount]; ++i)
  201894. {
  201895. NSPoint p[3];
  201896. switch ([bez elementAtIndex: i associatedPoints: p])
  201897. {
  201898. case NSMoveToBezierPathElement:
  201899. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  201900. break;
  201901. case NSLineToBezierPathElement:
  201902. path.lineTo ((float) p[0].x, (float) -p[0].y);
  201903. break;
  201904. case NSCurveToBezierPathElement:
  201905. 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);
  201906. break;
  201907. case NSClosePathBezierPathElement:
  201908. path.closeSubPath();
  201909. break;
  201910. default:
  201911. jassertfalse
  201912. break;
  201913. }
  201914. }
  201915. path.applyTransform (pathTransform);
  201916. return true;
  201917. #endif
  201918. }
  201919. juce_UseDebuggingNewOperator
  201920. CGFontRef fontRef;
  201921. float fontHeightToCGSizeFactor;
  201922. CGAffineTransform renderingTransform;
  201923. private:
  201924. float ascent, unitsToHeightScaleFactor;
  201925. #if JUCE_IPHONE
  201926. #else
  201927. NSFont* nsFont;
  201928. AffineTransform pathTransform;
  201929. #endif
  201930. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  201931. {
  201932. #if SUPPORT_10_4_FONTS
  201933. #if ! SUPPORT_ONLY_10_4_FONTS
  201934. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201935. #endif
  201936. {
  201937. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  201938. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201939. for (int i = 0; i < length; ++i)
  201940. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  201941. return;
  201942. }
  201943. #endif
  201944. #if ! SUPPORT_ONLY_10_4_FONTS
  201945. if (charToGlyphMapper == 0)
  201946. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  201947. glyphs.malloc (length);
  201948. for (int i = 0; i < length; ++i)
  201949. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  201950. #endif
  201951. }
  201952. #if ! SUPPORT_ONLY_10_4_FONTS
  201953. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  201954. class CharToGlyphMapper
  201955. {
  201956. public:
  201957. CharToGlyphMapper (CGFontRef fontRef)
  201958. : segCount (0), endCode (0), startCode (0), idDelta (0),
  201959. idRangeOffset (0), glyphIndexes (0)
  201960. {
  201961. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  201962. if (cmapTable != 0)
  201963. {
  201964. const int numSubtables = getValue16 (cmapTable, 2);
  201965. for (int i = 0; i < numSubtables; ++i)
  201966. {
  201967. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  201968. {
  201969. const int offset = getValue32 (cmapTable, i * 8 + 8);
  201970. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  201971. {
  201972. const int length = getValue16 (cmapTable, offset + 2);
  201973. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  201974. segCount = segCountX2 / 2;
  201975. const int endCodeOffset = offset + 14;
  201976. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  201977. const int idDeltaOffset = startCodeOffset + segCountX2;
  201978. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  201979. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  201980. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  201981. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  201982. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  201983. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  201984. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  201985. }
  201986. break;
  201987. }
  201988. }
  201989. CFRelease (cmapTable);
  201990. }
  201991. }
  201992. ~CharToGlyphMapper()
  201993. {
  201994. if (endCode != 0)
  201995. {
  201996. CFRelease (endCode);
  201997. CFRelease (startCode);
  201998. CFRelease (idDelta);
  201999. CFRelease (idRangeOffset);
  202000. CFRelease (glyphIndexes);
  202001. }
  202002. }
  202003. int getGlyphForCharacter (const juce_wchar c) const
  202004. {
  202005. for (int i = 0; i < segCount; ++i)
  202006. {
  202007. if (getValue16 (endCode, i * 2) >= c)
  202008. {
  202009. const int start = getValue16 (startCode, i * 2);
  202010. if (start > c)
  202011. break;
  202012. const int delta = getValue16 (idDelta, i * 2);
  202013. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  202014. if (rangeOffset == 0)
  202015. return delta + c;
  202016. else
  202017. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  202018. }
  202019. }
  202020. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  202021. return jmax (-1, c - 29);
  202022. }
  202023. private:
  202024. int segCount;
  202025. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  202026. static uint16 getValue16 (CFDataRef data, const int index)
  202027. {
  202028. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  202029. }
  202030. static uint32 getValue32 (CFDataRef data, const int index)
  202031. {
  202032. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  202033. }
  202034. };
  202035. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  202036. #endif
  202037. MacTypeface (const MacTypeface&);
  202038. MacTypeface& operator= (const MacTypeface&);
  202039. };
  202040. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  202041. {
  202042. return new MacTypeface (font);
  202043. }
  202044. const StringArray Font::findAllTypefaceNames() throw()
  202045. {
  202046. StringArray names;
  202047. const ScopedAutoReleasePool pool;
  202048. #if JUCE_IPHONE
  202049. NSArray* fonts = [UIFont familyNames];
  202050. #else
  202051. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202052. #endif
  202053. for (unsigned int i = 0; i < [fonts count]; ++i)
  202054. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202055. names.sort (true);
  202056. return names;
  202057. }
  202058. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  202059. {
  202060. #if JUCE_IPHONE
  202061. defaultSans = "Helvetica";
  202062. defaultSerif = "Times New Roman";
  202063. defaultFixed = "Courier New";
  202064. #else
  202065. defaultSans = "Lucida Grande";
  202066. defaultSerif = "Times New Roman";
  202067. defaultFixed = "Monaco";
  202068. #endif
  202069. }
  202070. #endif
  202071. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202072. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202073. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202074. // compiled on its own).
  202075. #if JUCE_INCLUDED_FILE
  202076. class CoreGraphicsImage : public Image
  202077. {
  202078. public:
  202079. CoreGraphicsImage (const PixelFormat format_,
  202080. const int imageWidth_,
  202081. const int imageHeight_,
  202082. const bool clearImage)
  202083. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202084. {
  202085. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  202086. : CGColorSpaceCreateDeviceRGB();
  202087. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202088. colourSpace, getCGImageFlags (*this));
  202089. CGColorSpaceRelease (colourSpace);
  202090. }
  202091. ~CoreGraphicsImage()
  202092. {
  202093. CGContextRelease (context);
  202094. }
  202095. LowLevelGraphicsContext* createLowLevelContext();
  202096. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202097. {
  202098. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202099. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202100. {
  202101. return CGBitmapContextCreateImage (nativeImage->context);
  202102. }
  202103. else
  202104. {
  202105. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202106. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202107. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202108. 8, srcData.pixelStride * 8, srcData.lineStride,
  202109. colourSpace, getCGImageFlags (juceImage), provider,
  202110. 0, true, kCGRenderingIntentDefault);
  202111. CGDataProviderRelease (provider);
  202112. return imageRef;
  202113. }
  202114. }
  202115. #if JUCE_MAC
  202116. static NSImage* createNSImage (const Image& image)
  202117. {
  202118. const ScopedAutoReleasePool pool;
  202119. NSImage* im = [[NSImage alloc] init];
  202120. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202121. [im lockFocus];
  202122. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202123. CGImageRef imageRef = createImage (image, false, colourSpace);
  202124. CGColorSpaceRelease (colourSpace);
  202125. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202126. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202127. CGImageRelease (imageRef);
  202128. [im unlockFocus];
  202129. return im;
  202130. }
  202131. #endif
  202132. CGContextRef context;
  202133. private:
  202134. static CGBitmapInfo getCGImageFlags (const Image& image)
  202135. {
  202136. #if JUCE_BIG_ENDIAN
  202137. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202138. #else
  202139. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202140. #endif
  202141. }
  202142. };
  202143. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202144. {
  202145. #if USE_COREGRAPHICS_RENDERING
  202146. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202147. #else
  202148. return new Image (format, imageWidth, imageHeight, clearImage);
  202149. #endif
  202150. }
  202151. class CoreGraphicsContext : public LowLevelGraphicsContext
  202152. {
  202153. public:
  202154. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202155. : context (context_),
  202156. flipHeight (flipHeight_),
  202157. state (new SavedState()),
  202158. numGradientLookupEntries (0)
  202159. {
  202160. CGContextRetain (context);
  202161. CGContextSaveGState(context);
  202162. CGContextSetShouldSmoothFonts (context, true);
  202163. CGContextSetShouldAntialias (context, true);
  202164. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202165. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202166. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202167. gradientCallbacks.version = 0;
  202168. gradientCallbacks.evaluate = gradientCallback;
  202169. gradientCallbacks.releaseInfo = 0;
  202170. setFont (Font());
  202171. }
  202172. ~CoreGraphicsContext()
  202173. {
  202174. CGContextRestoreGState (context);
  202175. CGContextRelease (context);
  202176. CGColorSpaceRelease (rgbColourSpace);
  202177. CGColorSpaceRelease (greyColourSpace);
  202178. }
  202179. bool isVectorDevice() const { return false; }
  202180. void setOrigin (int x, int y)
  202181. {
  202182. CGContextTranslateCTM (context, x, -y);
  202183. }
  202184. bool clipToRectangle (const Rectangle<int>& r)
  202185. {
  202186. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202187. return ! isClipEmpty();
  202188. }
  202189. bool clipToRectangleList (const RectangleList& clipRegion)
  202190. {
  202191. if (clipRegion.isEmpty())
  202192. {
  202193. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202194. return false;
  202195. }
  202196. else
  202197. {
  202198. const int numRects = clipRegion.getNumRectangles();
  202199. HeapBlock <CGRect> rects (numRects);
  202200. for (int i = 0; i < numRects; ++i)
  202201. {
  202202. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202203. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202204. }
  202205. CGContextClipToRects (context, rects, numRects);
  202206. return ! isClipEmpty();
  202207. }
  202208. }
  202209. void excludeClipRectangle (const Rectangle<int>& r)
  202210. {
  202211. RectangleList remaining (getClipBounds());
  202212. remaining.subtract (r);
  202213. clipToRectangleList (remaining);
  202214. }
  202215. void clipToPath (const Path& path, const AffineTransform& transform)
  202216. {
  202217. createPath (path, transform);
  202218. CGContextClip (context);
  202219. }
  202220. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202221. {
  202222. if (! transform.isSingularity())
  202223. {
  202224. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202225. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202226. flip();
  202227. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202228. applyTransform (t);
  202229. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202230. CGContextClipToMask (context, r, image);
  202231. applyTransform (t.inverted());
  202232. flip();
  202233. CGImageRelease (image);
  202234. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202235. }
  202236. }
  202237. bool clipRegionIntersects (const Rectangle<int>& r)
  202238. {
  202239. return getClipBounds().intersects (r);
  202240. }
  202241. const Rectangle<int> getClipBounds() const
  202242. {
  202243. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202244. return Rectangle<int> (roundToInt (bounds.origin.x),
  202245. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202246. roundToInt (bounds.size.width),
  202247. roundToInt (bounds.size.height));
  202248. }
  202249. bool isClipEmpty() const
  202250. {
  202251. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202252. }
  202253. void saveState()
  202254. {
  202255. CGContextSaveGState (context);
  202256. stateStack.add (new SavedState (*state));
  202257. }
  202258. void restoreState()
  202259. {
  202260. CGContextRestoreGState (context);
  202261. SavedState* const top = stateStack.getLast();
  202262. if (top != 0)
  202263. {
  202264. state = top;
  202265. stateStack.removeLast (1, false);
  202266. }
  202267. else
  202268. {
  202269. jassertfalse // trying to pop with an empty stack!
  202270. }
  202271. }
  202272. void setFill (const FillType& fillType)
  202273. {
  202274. state->fillType = fillType;
  202275. if (fillType.isColour())
  202276. {
  202277. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202278. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202279. CGContextSetAlpha (context, 1.0f);
  202280. }
  202281. }
  202282. void setOpacity (float newOpacity)
  202283. {
  202284. state->fillType.setOpacity (newOpacity);
  202285. setFill (state->fillType);
  202286. }
  202287. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202288. {
  202289. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202290. ? kCGInterpolationLow
  202291. : kCGInterpolationHigh);
  202292. }
  202293. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202294. {
  202295. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202296. if (replaceExistingContents)
  202297. {
  202298. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202299. CGContextClearRect (context, cgRect);
  202300. #else
  202301. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202302. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202303. CGContextClearRect (context, cgRect);
  202304. else
  202305. #endif
  202306. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202307. #endif
  202308. fillRect (r, false);
  202309. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202310. }
  202311. else
  202312. {
  202313. if (state->fillType.isColour())
  202314. {
  202315. CGContextFillRect (context, cgRect);
  202316. }
  202317. else if (state->fillType.isGradient())
  202318. {
  202319. CGContextSaveGState (context);
  202320. CGContextClipToRect (context, cgRect);
  202321. drawGradient();
  202322. CGContextRestoreGState (context);
  202323. }
  202324. else
  202325. {
  202326. CGContextSaveGState (context);
  202327. CGContextClipToRect (context, cgRect);
  202328. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202329. CGContextRestoreGState (context);
  202330. }
  202331. }
  202332. }
  202333. void fillPath (const Path& path, const AffineTransform& transform)
  202334. {
  202335. CGContextSaveGState (context);
  202336. if (state->fillType.isColour())
  202337. {
  202338. flip();
  202339. applyTransform (transform);
  202340. createPath (path);
  202341. if (path.isUsingNonZeroWinding())
  202342. CGContextFillPath (context);
  202343. else
  202344. CGContextEOFillPath (context);
  202345. }
  202346. else
  202347. {
  202348. createPath (path, transform);
  202349. if (path.isUsingNonZeroWinding())
  202350. CGContextClip (context);
  202351. else
  202352. CGContextEOClip (context);
  202353. if (state->fillType.isGradient())
  202354. drawGradient();
  202355. else
  202356. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202357. }
  202358. CGContextRestoreGState (context);
  202359. }
  202360. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202361. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202362. {
  202363. jassert (sourceImage.getBounds().contains (srcClip));
  202364. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202365. CGImageRef image = fullImage;
  202366. if (srcClip != sourceImage.getBounds())
  202367. {
  202368. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202369. srcClip.getWidth(), srcClip.getHeight()));
  202370. CGImageRelease (fullImage);
  202371. }
  202372. CGContextSaveGState (context);
  202373. CGContextSetAlpha (context, state->fillType.getOpacity());
  202374. flip();
  202375. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202376. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202377. if (fillEntireClipAsTiles)
  202378. {
  202379. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  202380. CGContextDrawTiledImage (context, imageRect, image);
  202381. #else
  202382. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202383. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202384. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202385. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202386. CGContextDrawTiledImage (context, imageRect, image);
  202387. else
  202388. #endif
  202389. {
  202390. // Fallback to manually doing a tiled fill on 10.4
  202391. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202392. const int iw = srcClip.getWidth();
  202393. const int ih = srcClip.getHeight();
  202394. int x = 0, y = 0;
  202395. while (x > clip.origin.x) x -= iw;
  202396. while (y > clip.origin.y) y -= ih;
  202397. const int right = (int) (clip.origin.x + clip.size.width);
  202398. const int bottom = (int) (clip.origin.y + clip.size.height);
  202399. while (y < bottom)
  202400. {
  202401. for (int x2 = x; x2 < right; x2 += iw)
  202402. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202403. y += ih;
  202404. }
  202405. }
  202406. #endif
  202407. }
  202408. else
  202409. {
  202410. CGContextDrawImage (context, imageRect, image);
  202411. }
  202412. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202413. CGContextRestoreGState (context);
  202414. }
  202415. void drawLine (double x1, double y1, double x2, double y2)
  202416. {
  202417. CGContextSetLineCap (context, kCGLineCapSquare);
  202418. CGContextSetLineWidth (context, 1.0f);
  202419. CGContextSetRGBStrokeColor (context,
  202420. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202421. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202422. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  202423. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  202424. CGContextStrokeLineSegments (context, line, 1);
  202425. }
  202426. void drawVerticalLine (const int x, double top, double bottom)
  202427. {
  202428. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202429. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202430. #else
  202431. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202432. // the x co-ord slightly to trick it..
  202433. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202434. #endif
  202435. }
  202436. void drawHorizontalLine (const int y, double left, double right)
  202437. {
  202438. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202439. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202440. #else
  202441. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202442. // the x co-ord slightly to trick it..
  202443. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202444. #endif
  202445. }
  202446. void setFont (const Font& newFont)
  202447. {
  202448. if (state->font != newFont)
  202449. {
  202450. state->fontRef = 0;
  202451. state->font = newFont;
  202452. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202453. if (mf != 0)
  202454. {
  202455. state->fontRef = mf->fontRef;
  202456. CGContextSetFont (context, state->fontRef);
  202457. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202458. state->fontTransform = mf->renderingTransform;
  202459. state->fontTransform.a *= state->font.getHorizontalScale();
  202460. CGContextSetTextMatrix (context, state->fontTransform);
  202461. }
  202462. }
  202463. }
  202464. const Font getFont()
  202465. {
  202466. return state->font;
  202467. }
  202468. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202469. {
  202470. if (state->fontRef != 0 && state->fillType.isColour())
  202471. {
  202472. if (transform.isOnlyTranslation())
  202473. {
  202474. CGGlyph g = glyphNumber;
  202475. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202476. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202477. }
  202478. else
  202479. {
  202480. CGContextSaveGState (context);
  202481. flip();
  202482. applyTransform (transform);
  202483. CGAffineTransform t = state->fontTransform;
  202484. t.d = -t.d;
  202485. CGContextSetTextMatrix (context, t);
  202486. CGGlyph g = glyphNumber;
  202487. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202488. CGContextSetTextMatrix (context, state->fontTransform);
  202489. CGContextRestoreGState (context);
  202490. }
  202491. }
  202492. else
  202493. {
  202494. Path p;
  202495. Font& f = state->font;
  202496. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202497. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202498. .followedBy (transform));
  202499. }
  202500. }
  202501. private:
  202502. CGContextRef context;
  202503. const CGFloat flipHeight;
  202504. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202505. CGFunctionCallbacks gradientCallbacks;
  202506. struct SavedState
  202507. {
  202508. SavedState()
  202509. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202510. {
  202511. }
  202512. SavedState (const SavedState& other)
  202513. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202514. fontTransform (other.fontTransform)
  202515. {
  202516. }
  202517. ~SavedState()
  202518. {
  202519. }
  202520. FillType fillType;
  202521. Font font;
  202522. CGFontRef fontRef;
  202523. CGAffineTransform fontTransform;
  202524. };
  202525. ScopedPointer <SavedState> state;
  202526. OwnedArray <SavedState> stateStack;
  202527. HeapBlock <PixelARGB> gradientLookupTable;
  202528. int numGradientLookupEntries;
  202529. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202530. {
  202531. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202532. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202533. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202534. colour.unpremultiply();
  202535. outData[0] = colour.getRed() / 255.0f;
  202536. outData[1] = colour.getGreen() / 255.0f;
  202537. outData[2] = colour.getBlue() / 255.0f;
  202538. outData[3] = colour.getAlpha() / 255.0f;
  202539. }
  202540. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202541. {
  202542. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202543. --numGradientLookupEntries;
  202544. CGShadingRef result = 0;
  202545. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  202546. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202547. if (gradient.isRadial)
  202548. {
  202549. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202550. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202551. function, true, true);
  202552. }
  202553. else
  202554. {
  202555. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202556. CGPointMake (gradient.x2, gradient.y2),
  202557. function, true, true);
  202558. }
  202559. CGFunctionRelease (function);
  202560. return result;
  202561. }
  202562. void drawGradient()
  202563. {
  202564. flip();
  202565. applyTransform (state->fillType.transform);
  202566. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202567. // you draw a gradient with high quality interp enabled).
  202568. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202569. CGContextSetAlpha (context, state->fillType.getOpacity());
  202570. CGContextDrawShading (context, shading);
  202571. CGShadingRelease (shading);
  202572. }
  202573. void createPath (const Path& path) const
  202574. {
  202575. CGContextBeginPath (context);
  202576. Path::Iterator i (path);
  202577. while (i.next())
  202578. {
  202579. switch (i.elementType)
  202580. {
  202581. case Path::Iterator::startNewSubPath:
  202582. CGContextMoveToPoint (context, i.x1, i.y1);
  202583. break;
  202584. case Path::Iterator::lineTo:
  202585. CGContextAddLineToPoint (context, i.x1, i.y1);
  202586. break;
  202587. case Path::Iterator::quadraticTo:
  202588. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202589. break;
  202590. case Path::Iterator::cubicTo:
  202591. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202592. break;
  202593. case Path::Iterator::closePath:
  202594. CGContextClosePath (context); break;
  202595. default:
  202596. jassertfalse
  202597. break;
  202598. }
  202599. }
  202600. }
  202601. void createPath (const Path& path, const AffineTransform& transform) const
  202602. {
  202603. CGContextBeginPath (context);
  202604. Path::Iterator i (path);
  202605. while (i.next())
  202606. {
  202607. switch (i.elementType)
  202608. {
  202609. case Path::Iterator::startNewSubPath:
  202610. transform.transformPoint (i.x1, i.y1);
  202611. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202612. break;
  202613. case Path::Iterator::lineTo:
  202614. transform.transformPoint (i.x1, i.y1);
  202615. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202616. break;
  202617. case Path::Iterator::quadraticTo:
  202618. transform.transformPoint (i.x1, i.y1);
  202619. transform.transformPoint (i.x2, i.y2);
  202620. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202621. break;
  202622. case Path::Iterator::cubicTo:
  202623. transform.transformPoint (i.x1, i.y1);
  202624. transform.transformPoint (i.x2, i.y2);
  202625. transform.transformPoint (i.x3, i.y3);
  202626. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202627. break;
  202628. case Path::Iterator::closePath:
  202629. CGContextClosePath (context); break;
  202630. default:
  202631. jassertfalse
  202632. break;
  202633. }
  202634. }
  202635. }
  202636. static Image* createAlphaChannelImage (const Image& im)
  202637. {
  202638. if (im.getFormat() == Image::SingleChannel)
  202639. return const_cast <Image*> (&im);
  202640. return im.createCopyOfAlphaChannel();
  202641. }
  202642. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202643. {
  202644. if (im.getFormat() != Image::SingleChannel)
  202645. delete alphaIm;
  202646. }
  202647. void flip() const
  202648. {
  202649. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202650. }
  202651. void applyTransform (const AffineTransform& transform) const
  202652. {
  202653. CGAffineTransform t;
  202654. t.a = transform.mat00;
  202655. t.b = transform.mat10;
  202656. t.c = transform.mat01;
  202657. t.d = transform.mat11;
  202658. t.tx = transform.mat02;
  202659. t.ty = transform.mat12;
  202660. CGContextConcatCTM (context, t);
  202661. }
  202662. CoreGraphicsContext (const CoreGraphicsContext&);
  202663. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  202664. };
  202665. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202666. {
  202667. return new CoreGraphicsContext (context, imageHeight);
  202668. }
  202669. #endif
  202670. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202671. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202672. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202673. // compiled on its own).
  202674. #if JUCE_INCLUDED_FILE
  202675. class UIViewComponentPeer;
  202676. END_JUCE_NAMESPACE
  202677. #define JuceUIView MakeObjCClassName(JuceUIView)
  202678. @interface JuceUIView : UIView <UITextFieldDelegate>
  202679. {
  202680. @public
  202681. UIViewComponentPeer* owner;
  202682. UITextField *hiddenTextField;
  202683. }
  202684. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202685. - (void) dealloc;
  202686. - (void) drawRect: (CGRect) r;
  202687. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202688. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202689. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202690. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202691. - (BOOL) becomeFirstResponder;
  202692. - (BOOL) resignFirstResponder;
  202693. - (BOOL) canBecomeFirstResponder;
  202694. - (void) asyncRepaint: (id) rect;
  202695. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) string;
  202696. - (BOOL) textFieldShouldClear: (UITextField*) textField;
  202697. - (BOOL) textFieldShouldReturn: (UITextField*) textField;
  202698. @end
  202699. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202700. @interface JuceUIWindow : UIWindow
  202701. {
  202702. @private
  202703. UIViewComponentPeer* owner;
  202704. bool isZooming;
  202705. }
  202706. - (void) setOwner: (UIViewComponentPeer*) owner;
  202707. - (void) becomeKeyWindow;
  202708. @end
  202709. BEGIN_JUCE_NAMESPACE
  202710. class UIViewComponentPeer : public ComponentPeer,
  202711. public FocusChangeListener
  202712. {
  202713. public:
  202714. UIViewComponentPeer (Component* const component,
  202715. const int windowStyleFlags,
  202716. UIView* viewToAttachTo);
  202717. ~UIViewComponentPeer();
  202718. void* getNativeHandle() const;
  202719. void setVisible (bool shouldBeVisible);
  202720. void setTitle (const String& title);
  202721. void setPosition (int x, int y);
  202722. void setSize (int w, int h);
  202723. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  202724. const Rectangle<int> getBounds() const;
  202725. const Rectangle<int> getBounds (const bool global) const;
  202726. const Point<int> getScreenPosition() const;
  202727. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  202728. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  202729. void setMinimised (bool shouldBeMinimised);
  202730. bool isMinimised() const;
  202731. void setFullScreen (bool shouldBeFullScreen);
  202732. bool isFullScreen() const;
  202733. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  202734. const BorderSize getFrameSize() const;
  202735. bool setAlwaysOnTop (bool alwaysOnTop);
  202736. void toFront (bool makeActiveWindow);
  202737. void toBehind (ComponentPeer* other);
  202738. void setIcon (const Image& newIcon);
  202739. virtual void drawRect (CGRect r);
  202740. virtual bool canBecomeKeyWindow();
  202741. virtual bool windowShouldClose();
  202742. virtual void redirectMovedOrResized();
  202743. virtual CGRect constrainRect (CGRect r);
  202744. virtual void viewFocusGain();
  202745. virtual void viewFocusLoss();
  202746. bool isFocused() const;
  202747. void grabFocus();
  202748. void textInputRequired (const Point<int>& position);
  202749. virtual BOOL textFieldReplaceCharacters (const Range<int>& range, const String& text);
  202750. virtual BOOL textFieldShouldClear();
  202751. virtual BOOL textFieldShouldReturn();
  202752. void updateHiddenTextContent (TextInputTarget* target);
  202753. void globalFocusChanged (Component*);
  202754. void handleTouches (UIEvent* e, bool isDown, bool isUp, bool isCancel);
  202755. void repaint (int x, int y, int w, int h);
  202756. void performAnyPendingRepaintsNow();
  202757. juce_UseDebuggingNewOperator
  202758. UIWindow* window;
  202759. JuceUIView* view;
  202760. bool isSharedWindow, fullScreen, insideDrawRect;
  202761. static ModifierKeys currentModifiers;
  202762. static int64 getMouseTime (UIEvent* e)
  202763. {
  202764. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  202765. + (int64) ([e timestamp] * 1000.0);
  202766. }
  202767. Array <UITouch*> currentTouches;
  202768. };
  202769. END_JUCE_NAMESPACE
  202770. @implementation JuceUIView
  202771. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  202772. withFrame: (CGRect) frame
  202773. {
  202774. [super initWithFrame: frame];
  202775. owner = owner_;
  202776. hiddenTextField = [[UITextField alloc] initWithFrame: CGRectMake (0, 0, 0, 0)];
  202777. [self addSubview: hiddenTextField];
  202778. hiddenTextField.delegate = self;
  202779. return self;
  202780. }
  202781. - (void) dealloc
  202782. {
  202783. [hiddenTextField removeFromSuperview];
  202784. [hiddenTextField release];
  202785. [super dealloc];
  202786. }
  202787. - (void) drawRect: (CGRect) r
  202788. {
  202789. if (owner != 0)
  202790. owner->drawRect (r);
  202791. }
  202792. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  202793. {
  202794. return false;
  202795. }
  202796. ModifierKeys UIViewComponentPeer::currentModifiers;
  202797. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  202798. {
  202799. return UIViewComponentPeer::currentModifiers;
  202800. }
  202801. void ModifierKeys::updateCurrentModifiers() throw()
  202802. {
  202803. currentModifiers = UIViewComponentPeer::currentModifiers;
  202804. }
  202805. JUCE_NAMESPACE::Point<int> juce_lastMousePos;
  202806. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  202807. {
  202808. if (owner != 0)
  202809. owner->handleTouches (event, true, false, false);
  202810. }
  202811. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  202812. {
  202813. if (owner != 0)
  202814. owner->handleTouches (event, false, false, false);
  202815. }
  202816. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  202817. {
  202818. if (owner != 0)
  202819. owner->handleTouches (event, false, true, false);
  202820. }
  202821. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  202822. {
  202823. if (owner != 0)
  202824. owner->handleTouches (event, false, true, true);
  202825. [self touchesEnded: touches withEvent: event];
  202826. }
  202827. - (BOOL) becomeFirstResponder
  202828. {
  202829. if (owner != 0)
  202830. owner->viewFocusGain();
  202831. return true;
  202832. }
  202833. - (BOOL) resignFirstResponder
  202834. {
  202835. if (owner != 0)
  202836. owner->viewFocusLoss();
  202837. return true;
  202838. }
  202839. - (BOOL) canBecomeFirstResponder
  202840. {
  202841. return owner != 0 && owner->canBecomeKeyWindow();
  202842. }
  202843. - (void) asyncRepaint: (id) rect
  202844. {
  202845. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  202846. [self setNeedsDisplayInRect: *r];
  202847. }
  202848. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) text
  202849. {
  202850. return owner->textFieldReplaceCharacters (Range<int> (range.location, range.location + range.length),
  202851. nsStringToJuce (text));
  202852. }
  202853. - (BOOL) textFieldShouldClear: (UITextField*) textField
  202854. {
  202855. return owner->textFieldShouldClear();
  202856. }
  202857. - (BOOL) textFieldShouldReturn: (UITextField*) textField
  202858. {
  202859. return owner->textFieldShouldReturn();
  202860. }
  202861. @end
  202862. @implementation JuceUIWindow
  202863. - (void) setOwner: (UIViewComponentPeer*) owner_
  202864. {
  202865. owner = owner_;
  202866. isZooming = false;
  202867. }
  202868. - (void) becomeKeyWindow
  202869. {
  202870. [super becomeKeyWindow];
  202871. if (owner != 0)
  202872. owner->grabFocus();
  202873. }
  202874. @end
  202875. BEGIN_JUCE_NAMESPACE
  202876. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  202877. const int windowStyleFlags,
  202878. UIView* viewToAttachTo)
  202879. : ComponentPeer (component, windowStyleFlags),
  202880. window (0),
  202881. view (0),
  202882. isSharedWindow (viewToAttachTo != 0),
  202883. fullScreen (false),
  202884. insideDrawRect (false)
  202885. {
  202886. CGRect r = CGRectMake (0, 0, (float) component->getWidth(), (float) component->getHeight());
  202887. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  202888. if (isSharedWindow)
  202889. {
  202890. window = [viewToAttachTo window];
  202891. [viewToAttachTo addSubview: view];
  202892. setVisible (component->isVisible());
  202893. }
  202894. else
  202895. {
  202896. r.origin.x = (float) component->getX();
  202897. r.origin.y = (float) component->getY();
  202898. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  202899. window = [[JuceUIWindow alloc] init];
  202900. window.frame = r;
  202901. window.opaque = component->isOpaque();
  202902. view.opaque = component->isOpaque();
  202903. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202904. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202905. [((JuceUIWindow*) window) setOwner: this];
  202906. if (component->isAlwaysOnTop())
  202907. window.windowLevel = UIWindowLevelAlert;
  202908. [window addSubview: view];
  202909. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202910. view.hidden = ! component->isVisible();
  202911. window.hidden = ! component->isVisible();
  202912. view.multipleTouchEnabled = YES;
  202913. }
  202914. setTitle (component->getName());
  202915. Desktop::getInstance().addFocusChangeListener (this);
  202916. }
  202917. UIViewComponentPeer::~UIViewComponentPeer()
  202918. {
  202919. Desktop::getInstance().removeFocusChangeListener (this);
  202920. view->owner = 0;
  202921. [view removeFromSuperview];
  202922. [view release];
  202923. if (! isSharedWindow)
  202924. {
  202925. [((JuceUIWindow*) window) setOwner: 0];
  202926. [window release];
  202927. }
  202928. }
  202929. void* UIViewComponentPeer::getNativeHandle() const
  202930. {
  202931. return view;
  202932. }
  202933. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  202934. {
  202935. view.hidden = ! shouldBeVisible;
  202936. if (! isSharedWindow)
  202937. window.hidden = ! shouldBeVisible;
  202938. }
  202939. void UIViewComponentPeer::setTitle (const String& title)
  202940. {
  202941. // xxx is this possible?
  202942. }
  202943. void UIViewComponentPeer::setPosition (int x, int y)
  202944. {
  202945. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  202946. }
  202947. void UIViewComponentPeer::setSize (int w, int h)
  202948. {
  202949. setBounds (component->getX(), component->getY(), w, h, false);
  202950. }
  202951. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  202952. {
  202953. fullScreen = isNowFullScreen;
  202954. w = jmax (0, w);
  202955. h = jmax (0, h);
  202956. CGRect r;
  202957. r.origin.x = (float) x;
  202958. r.origin.y = (float) y;
  202959. r.size.width = (float) w;
  202960. r.size.height = (float) h;
  202961. if (isSharedWindow)
  202962. {
  202963. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  202964. if ([view frame].size.width != r.size.width
  202965. || [view frame].size.height != r.size.height)
  202966. [view setNeedsDisplay];
  202967. view.frame = r;
  202968. }
  202969. else
  202970. {
  202971. window.frame = r;
  202972. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202973. }
  202974. }
  202975. const Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
  202976. {
  202977. CGRect r = [view frame];
  202978. if (global && [view window] != 0)
  202979. {
  202980. r = [view convertRect: r toView: nil];
  202981. CGRect wr = [[view window] frame];
  202982. r.origin.x += wr.origin.x;
  202983. r.origin.y += wr.origin.y;
  202984. }
  202985. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y,
  202986. (int) r.size.width, (int) r.size.height);
  202987. }
  202988. const Rectangle<int> UIViewComponentPeer::getBounds() const
  202989. {
  202990. return getBounds (! isSharedWindow);
  202991. }
  202992. const Point<int> UIViewComponentPeer::getScreenPosition() const
  202993. {
  202994. return getBounds (true).getPosition();
  202995. }
  202996. const Point<int> UIViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  202997. {
  202998. return relativePosition + getScreenPosition();
  202999. }
  203000. const Point<int> UIViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  203001. {
  203002. return screenPosition - getScreenPosition();
  203003. }
  203004. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  203005. {
  203006. if (constrainer != 0)
  203007. {
  203008. CGRect current = [window frame];
  203009. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  203010. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  203011. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  203012. (int) r.size.width, (int) r.size.height);
  203013. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  203014. (int) current.size.width, (int) current.size.height);
  203015. constrainer->checkBounds (pos, original,
  203016. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  203017. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  203018. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  203019. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  203020. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  203021. r.origin.x = pos.getX();
  203022. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  203023. r.size.width = pos.getWidth();
  203024. r.size.height = pos.getHeight();
  203025. }
  203026. return r;
  203027. }
  203028. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  203029. {
  203030. // xxx
  203031. }
  203032. bool UIViewComponentPeer::isMinimised() const
  203033. {
  203034. return false;
  203035. }
  203036. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  203037. {
  203038. if (! isSharedWindow)
  203039. {
  203040. Rectangle<int> r (lastNonFullscreenBounds);
  203041. setMinimised (false);
  203042. if (fullScreen != shouldBeFullScreen)
  203043. {
  203044. if (shouldBeFullScreen)
  203045. r = Desktop::getInstance().getMainMonitorArea();
  203046. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  203047. if (r != getComponent()->getBounds() && ! r.isEmpty())
  203048. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203049. }
  203050. }
  203051. }
  203052. bool UIViewComponentPeer::isFullScreen() const
  203053. {
  203054. return fullScreen;
  203055. }
  203056. bool UIViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  203057. {
  203058. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  203059. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  203060. return false;
  203061. CGPoint p;
  203062. p.x = (float) position.getX();
  203063. p.y = (float) position.getY();
  203064. UIView* v = [view hitTest: p withEvent: nil];
  203065. if (trueIfInAChildWindow)
  203066. return v != nil;
  203067. return v == view;
  203068. }
  203069. const BorderSize UIViewComponentPeer::getFrameSize() const
  203070. {
  203071. BorderSize b;
  203072. if (! isSharedWindow)
  203073. {
  203074. CGRect v = [view convertRect: [view frame] toView: nil];
  203075. CGRect w = [window frame];
  203076. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203077. b.setBottom ((int) v.origin.y);
  203078. b.setLeft ((int) v.origin.x);
  203079. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203080. }
  203081. return b;
  203082. }
  203083. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203084. {
  203085. if (! isSharedWindow)
  203086. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203087. return true;
  203088. }
  203089. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203090. {
  203091. if (isSharedWindow)
  203092. [[view superview] bringSubviewToFront: view];
  203093. if (window != 0 && component->isVisible())
  203094. [window makeKeyAndVisible];
  203095. }
  203096. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203097. {
  203098. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203099. if (isSharedWindow)
  203100. {
  203101. [[view superview] insertSubview: view belowSubview: o->view];
  203102. }
  203103. else
  203104. {
  203105. jassertfalse // don't know how to do this
  203106. }
  203107. }
  203108. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203109. {
  203110. // to do..
  203111. }
  203112. void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, const bool isUp, bool isCancel)
  203113. {
  203114. NSArray* touches = [[event touchesForView: view] allObjects];
  203115. for (unsigned int i = 0; i < [touches count]; ++i)
  203116. {
  203117. UITouch* touch = [touches objectAtIndex: i];
  203118. CGPoint p = [touch locationInView: view];
  203119. const Point<int> pos ((int) p.x, (int) p.y);
  203120. juce_lastMousePos = pos + getScreenPosition();
  203121. const int64 time = getMouseTime (event);
  203122. int touchIndex = currentTouches.indexOf (touch);
  203123. if (touchIndex < 0)
  203124. {
  203125. touchIndex = currentTouches.size();
  203126. currentTouches.add (touch);
  203127. }
  203128. if (isDown)
  203129. {
  203130. currentModifiers = currentModifiers.withoutMouseButtons();
  203131. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203132. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
  203133. }
  203134. else if (isUp)
  203135. {
  203136. currentModifiers = currentModifiers.withoutMouseButtons();
  203137. currentTouches.remove (touchIndex);
  203138. }
  203139. if (isCancel)
  203140. currentTouches.clear();
  203141. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203142. }
  203143. }
  203144. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203145. void UIViewComponentPeer::viewFocusGain()
  203146. {
  203147. if (currentlyFocusedPeer != this)
  203148. {
  203149. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203150. currentlyFocusedPeer->handleFocusLoss();
  203151. currentlyFocusedPeer = this;
  203152. handleFocusGain();
  203153. }
  203154. }
  203155. void UIViewComponentPeer::viewFocusLoss()
  203156. {
  203157. if (currentlyFocusedPeer == this)
  203158. {
  203159. currentlyFocusedPeer = 0;
  203160. handleFocusLoss();
  203161. }
  203162. }
  203163. void juce_HandleProcessFocusChange()
  203164. {
  203165. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203166. {
  203167. if (Process::isForegroundProcess())
  203168. {
  203169. currentlyFocusedPeer->handleFocusGain();
  203170. ComponentPeer::bringModalComponentToFront();
  203171. }
  203172. else
  203173. {
  203174. currentlyFocusedPeer->handleFocusLoss();
  203175. // turn kiosk mode off if we lose focus..
  203176. Desktop::getInstance().setKioskModeComponent (0);
  203177. }
  203178. }
  203179. }
  203180. bool UIViewComponentPeer::isFocused() const
  203181. {
  203182. return isSharedWindow ? this == currentlyFocusedPeer
  203183. : (window != 0 && [window isKeyWindow]);
  203184. }
  203185. void UIViewComponentPeer::grabFocus()
  203186. {
  203187. if (window != 0)
  203188. {
  203189. [window makeKeyWindow];
  203190. viewFocusGain();
  203191. }
  203192. }
  203193. void UIViewComponentPeer::textInputRequired (const Point<int>&)
  203194. {
  203195. }
  203196. void UIViewComponentPeer::updateHiddenTextContent (TextInputTarget* target)
  203197. {
  203198. view->hiddenTextField.text = juceStringToNS (target->getTextInRange (Range<int> (0, target->getHighlightedRegion().getStart())));
  203199. }
  203200. BOOL UIViewComponentPeer::textFieldReplaceCharacters (const Range<int>& range, const String& text)
  203201. {
  203202. TextInputTarget* const target = findCurrentTextInputTarget();
  203203. if (target != 0)
  203204. {
  203205. const Range<int> currentSelection (target->getHighlightedRegion());
  203206. if (range.getLength() == 1 && text.isEmpty()) // (detect backspace)
  203207. if (currentSelection.isEmpty())
  203208. target->setHighlightedRegion (currentSelection.withStart (currentSelection.getStart() - 1));
  203209. target->insertTextAtCaret (text);
  203210. updateHiddenTextContent (target);
  203211. }
  203212. return NO;
  203213. }
  203214. BOOL UIViewComponentPeer::textFieldShouldClear()
  203215. {
  203216. TextInputTarget* const target = findCurrentTextInputTarget();
  203217. if (target != 0)
  203218. {
  203219. target->setHighlightedRegion (Range<int> (0, std::numeric_limits<int>::max()));
  203220. target->insertTextAtCaret (String::empty);
  203221. updateHiddenTextContent (target);
  203222. }
  203223. return YES;
  203224. }
  203225. BOOL UIViewComponentPeer::textFieldShouldReturn()
  203226. {
  203227. TextInputTarget* const target = findCurrentTextInputTarget();
  203228. if (target != 0)
  203229. {
  203230. target->insertTextAtCaret (T("\n"));
  203231. updateHiddenTextContent (target);
  203232. }
  203233. return YES;
  203234. }
  203235. void UIViewComponentPeer::globalFocusChanged (Component*)
  203236. {
  203237. TextInputTarget* const target = findCurrentTextInputTarget();
  203238. if (target != 0)
  203239. {
  203240. Component* comp = dynamic_cast<Component*> (target);
  203241. Point<int> pos (comp->relativePositionToOtherComponent (component, Point<int>()));
  203242. view->hiddenTextField.frame = CGRectMake (pos.getX(), pos.getY(), 0, 0);
  203243. updateHiddenTextContent (target);
  203244. [view->hiddenTextField becomeFirstResponder];
  203245. }
  203246. else
  203247. {
  203248. [view->hiddenTextField resignFirstResponder];
  203249. }
  203250. }
  203251. void UIViewComponentPeer::drawRect (CGRect r)
  203252. {
  203253. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203254. return;
  203255. CGContextRef cg = UIGraphicsGetCurrentContext();
  203256. if (! component->isOpaque())
  203257. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203258. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203259. CoreGraphicsContext g (cg, view.bounds.size.height);
  203260. insideDrawRect = true;
  203261. handlePaint (g);
  203262. insideDrawRect = false;
  203263. }
  203264. bool UIViewComponentPeer::canBecomeKeyWindow()
  203265. {
  203266. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203267. }
  203268. bool UIViewComponentPeer::windowShouldClose()
  203269. {
  203270. if (! isValidPeer (this))
  203271. return YES;
  203272. handleUserClosingWindow();
  203273. return NO;
  203274. }
  203275. void UIViewComponentPeer::redirectMovedOrResized()
  203276. {
  203277. handleMovedOrResized();
  203278. }
  203279. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203280. {
  203281. }
  203282. class AsyncRepaintMessage : public CallbackMessage
  203283. {
  203284. public:
  203285. UIViewComponentPeer* const peer;
  203286. const Rectangle<int> rect;
  203287. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203288. : peer (peer_), rect (rect_)
  203289. {
  203290. }
  203291. void messageCallback()
  203292. {
  203293. if (ComponentPeer::isValidPeer (peer))
  203294. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203295. }
  203296. };
  203297. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203298. {
  203299. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203300. {
  203301. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203302. }
  203303. else
  203304. {
  203305. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203306. }
  203307. }
  203308. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203309. {
  203310. }
  203311. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203312. {
  203313. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203314. }
  203315. Image* juce_createIconForFile (const File& file)
  203316. {
  203317. return 0;
  203318. }
  203319. void Desktop::createMouseInputSources()
  203320. {
  203321. for (int i = 0; i < 10; ++i)
  203322. mouseSources.add (new MouseInputSource (i, false));
  203323. }
  203324. bool Desktop::canUseSemiTransparentWindows() throw()
  203325. {
  203326. return true;
  203327. }
  203328. const Point<int> Desktop::getMousePosition()
  203329. {
  203330. return juce_lastMousePos;
  203331. }
  203332. void Desktop::setMousePosition (const Point<int>&)
  203333. {
  203334. }
  203335. const int KeyPress::spaceKey = ' ';
  203336. const int KeyPress::returnKey = 0x0d;
  203337. const int KeyPress::escapeKey = 0x1b;
  203338. const int KeyPress::backspaceKey = 0x7f;
  203339. const int KeyPress::leftKey = 0x1000;
  203340. const int KeyPress::rightKey = 0x1001;
  203341. const int KeyPress::upKey = 0x1002;
  203342. const int KeyPress::downKey = 0x1003;
  203343. const int KeyPress::pageUpKey = 0x1004;
  203344. const int KeyPress::pageDownKey = 0x1005;
  203345. const int KeyPress::endKey = 0x1006;
  203346. const int KeyPress::homeKey = 0x1007;
  203347. const int KeyPress::deleteKey = 0x1008;
  203348. const int KeyPress::insertKey = -1;
  203349. const int KeyPress::tabKey = 9;
  203350. const int KeyPress::F1Key = 0x2001;
  203351. const int KeyPress::F2Key = 0x2002;
  203352. const int KeyPress::F3Key = 0x2003;
  203353. const int KeyPress::F4Key = 0x2004;
  203354. const int KeyPress::F5Key = 0x2005;
  203355. const int KeyPress::F6Key = 0x2006;
  203356. const int KeyPress::F7Key = 0x2007;
  203357. const int KeyPress::F8Key = 0x2008;
  203358. const int KeyPress::F9Key = 0x2009;
  203359. const int KeyPress::F10Key = 0x200a;
  203360. const int KeyPress::F11Key = 0x200b;
  203361. const int KeyPress::F12Key = 0x200c;
  203362. const int KeyPress::F13Key = 0x200d;
  203363. const int KeyPress::F14Key = 0x200e;
  203364. const int KeyPress::F15Key = 0x200f;
  203365. const int KeyPress::F16Key = 0x2010;
  203366. const int KeyPress::numberPad0 = 0x30020;
  203367. const int KeyPress::numberPad1 = 0x30021;
  203368. const int KeyPress::numberPad2 = 0x30022;
  203369. const int KeyPress::numberPad3 = 0x30023;
  203370. const int KeyPress::numberPad4 = 0x30024;
  203371. const int KeyPress::numberPad5 = 0x30025;
  203372. const int KeyPress::numberPad6 = 0x30026;
  203373. const int KeyPress::numberPad7 = 0x30027;
  203374. const int KeyPress::numberPad8 = 0x30028;
  203375. const int KeyPress::numberPad9 = 0x30029;
  203376. const int KeyPress::numberPadAdd = 0x3002a;
  203377. const int KeyPress::numberPadSubtract = 0x3002b;
  203378. const int KeyPress::numberPadMultiply = 0x3002c;
  203379. const int KeyPress::numberPadDivide = 0x3002d;
  203380. const int KeyPress::numberPadSeparator = 0x3002e;
  203381. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203382. const int KeyPress::numberPadEquals = 0x30030;
  203383. const int KeyPress::numberPadDelete = 0x30031;
  203384. const int KeyPress::playKey = 0x30000;
  203385. const int KeyPress::stopKey = 0x30001;
  203386. const int KeyPress::fastForwardKey = 0x30002;
  203387. const int KeyPress::rewindKey = 0x30003;
  203388. #endif
  203389. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203390. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203391. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203392. // compiled on its own).
  203393. #if JUCE_INCLUDED_FILE
  203394. struct CallbackMessagePayload
  203395. {
  203396. MessageCallbackFunction* function;
  203397. void* parameter;
  203398. void* volatile result;
  203399. bool volatile hasBeenExecuted;
  203400. };
  203401. END_JUCE_NAMESPACE
  203402. using namespace JUCE_NAMESPACE;
  203403. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203404. {
  203405. }
  203406. - (JuceAppDelegate*) init;
  203407. - (void) dealloc;
  203408. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203409. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203410. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203411. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203412. - (void) customEvent: (id) data;
  203413. - (void) performCallback: (id) info;
  203414. @end
  203415. @implementation JuceAppDelegate
  203416. - (JuceAppDelegate*) init
  203417. {
  203418. [super init];
  203419. [[UIApplication sharedApplication] setDelegate: self];
  203420. return self;
  203421. }
  203422. - (void) dealloc
  203423. {
  203424. [[UIApplication sharedApplication] setDelegate: nil];
  203425. [super dealloc];
  203426. }
  203427. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203428. {
  203429. if (JUCEApplication::getInstance() != 0)
  203430. {
  203431. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203432. return YES;
  203433. }
  203434. return NO;
  203435. }
  203436. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203437. {
  203438. juce_HandleProcessFocusChange();
  203439. }
  203440. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203441. {
  203442. juce_HandleProcessFocusChange();
  203443. }
  203444. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203445. {
  203446. juce_HandleProcessFocusChange();
  203447. }
  203448. - (void) customEvent: (id) n
  203449. {
  203450. NSData* data = (NSData*) n;
  203451. void* message = 0;
  203452. [data getBytes: &message length: sizeof (message)];
  203453. [data release];
  203454. if (message != 0)
  203455. MessageManager::getInstance()->deliverMessage (message);
  203456. }
  203457. - (void) performCallback: (id) info
  203458. {
  203459. if ([info isKindOfClass: [NSData class]])
  203460. {
  203461. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203462. if (pl != 0)
  203463. {
  203464. pl->result = (*pl->function) (pl->parameter);
  203465. pl->hasBeenExecuted = true;
  203466. }
  203467. }
  203468. else
  203469. {
  203470. jassertfalse // should never get here!
  203471. }
  203472. }
  203473. @end
  203474. BEGIN_JUCE_NAMESPACE
  203475. static JuceAppDelegate* juceAppDelegate = 0;
  203476. void MessageManager::runDispatchLoop()
  203477. {
  203478. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203479. runDispatchLoopUntil (-1);
  203480. }
  203481. void MessageManager::stopDispatchLoop()
  203482. {
  203483. exit (0); // iPhone apps get no mercy..
  203484. }
  203485. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203486. {
  203487. const ScopedAutoReleasePool pool;
  203488. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203489. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203490. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203491. while (! quitMessagePosted)
  203492. {
  203493. const ScopedAutoReleasePool pool;
  203494. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203495. beforeDate: endDate];
  203496. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203497. break;
  203498. }
  203499. return ! quitMessagePosted;
  203500. }
  203501. static CFRunLoopRef runLoop = 0;
  203502. static CFRunLoopSourceRef runLoopSource = 0;
  203503. static Array <void*, CriticalSection>* pendingMessages = 0;
  203504. static void runLoopSourceCallback (void*)
  203505. {
  203506. if (pendingMessages != 0)
  203507. {
  203508. int numDispatched = 0;
  203509. do
  203510. {
  203511. void* const nextMessage = pendingMessages->remove (0);
  203512. if (nextMessage == 0)
  203513. return;
  203514. const ScopedAutoReleasePool pool;
  203515. MessageManager::getInstance()->deliverMessage (nextMessage);
  203516. } while (++numDispatched <= 4);
  203517. CFRunLoopSourceSignal (runLoopSource);
  203518. CFRunLoopWakeUp (runLoop);
  203519. }
  203520. }
  203521. void MessageManager::doPlatformSpecificInitialisation()
  203522. {
  203523. pendingMessages = new Array <void*, CriticalSection>();
  203524. runLoop = CFRunLoopGetCurrent();
  203525. CFRunLoopSourceContext sourceContext;
  203526. zerostruct (sourceContext);
  203527. sourceContext.perform = runLoopSourceCallback;
  203528. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203529. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203530. if (juceAppDelegate == 0)
  203531. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203532. }
  203533. void MessageManager::doPlatformSpecificShutdown()
  203534. {
  203535. CFRunLoopSourceInvalidate (runLoopSource);
  203536. CFRelease (runLoopSource);
  203537. runLoopSource = 0;
  203538. if (pendingMessages != 0)
  203539. {
  203540. while (pendingMessages->size() > 0)
  203541. delete ((Message*) pendingMessages->remove(0));
  203542. deleteAndZero (pendingMessages);
  203543. }
  203544. if (juceAppDelegate != 0)
  203545. {
  203546. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203547. [juceAppDelegate release];
  203548. juceAppDelegate = 0;
  203549. }
  203550. }
  203551. bool juce_postMessageToSystemQueue (void* message)
  203552. {
  203553. if (pendingMessages != 0)
  203554. {
  203555. pendingMessages->add (message);
  203556. CFRunLoopSourceSignal (runLoopSource);
  203557. CFRunLoopWakeUp (runLoop);
  203558. }
  203559. return true;
  203560. }
  203561. void MessageManager::broadcastMessage (const String& value) throw()
  203562. {
  203563. }
  203564. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203565. void* data)
  203566. {
  203567. if (isThisTheMessageThread())
  203568. {
  203569. return (*callback) (data);
  203570. }
  203571. else
  203572. {
  203573. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203574. // deadlock because the message manager is blocked from running, so can never
  203575. // call your function..
  203576. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203577. const ScopedAutoReleasePool pool;
  203578. CallbackMessagePayload cmp;
  203579. cmp.function = callback;
  203580. cmp.parameter = data;
  203581. cmp.result = 0;
  203582. cmp.hasBeenExecuted = false;
  203583. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203584. withObject: [NSData dataWithBytesNoCopy: &cmp
  203585. length: sizeof (cmp)
  203586. freeWhenDone: NO]
  203587. waitUntilDone: YES];
  203588. return cmp.result;
  203589. }
  203590. }
  203591. #endif
  203592. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203593. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203594. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203595. // compiled on its own).
  203596. #if JUCE_INCLUDED_FILE
  203597. #if JUCE_MAC
  203598. END_JUCE_NAMESPACE
  203599. using namespace JUCE_NAMESPACE;
  203600. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203601. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203602. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203603. #else
  203604. @interface JuceFileChooserDelegate : NSObject
  203605. #endif
  203606. {
  203607. StringArray* filters;
  203608. }
  203609. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203610. - (void) dealloc;
  203611. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203612. @end
  203613. @implementation JuceFileChooserDelegate
  203614. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203615. {
  203616. [super init];
  203617. filters = filters_;
  203618. return self;
  203619. }
  203620. - (void) dealloc
  203621. {
  203622. delete filters;
  203623. [super dealloc];
  203624. }
  203625. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203626. {
  203627. const File f (nsStringToJuce (filename));
  203628. for (int i = filters->size(); --i >= 0;)
  203629. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203630. return true;
  203631. return f.isDirectory();
  203632. }
  203633. @end
  203634. BEGIN_JUCE_NAMESPACE
  203635. void FileChooser::showPlatformDialog (Array<File>& results,
  203636. const String& title,
  203637. const File& currentFileOrDirectory,
  203638. const String& filter,
  203639. bool selectsDirectory,
  203640. bool selectsFiles,
  203641. bool isSaveDialogue,
  203642. bool warnAboutOverwritingExistingFiles,
  203643. bool selectMultipleFiles,
  203644. FilePreviewComponent* extraInfoComponent)
  203645. {
  203646. const ScopedAutoReleasePool pool;
  203647. StringArray* filters = new StringArray();
  203648. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), String::empty);
  203649. filters->trim();
  203650. filters->removeEmptyStrings();
  203651. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203652. [delegate autorelease];
  203653. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203654. : [NSOpenPanel openPanel];
  203655. [panel setTitle: juceStringToNS (title)];
  203656. if (! isSaveDialogue)
  203657. {
  203658. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203659. [openPanel setCanChooseDirectories: selectsDirectory];
  203660. [openPanel setCanChooseFiles: selectsFiles];
  203661. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203662. }
  203663. [panel setDelegate: delegate];
  203664. if (isSaveDialogue || selectsDirectory)
  203665. [panel setCanCreateDirectories: YES];
  203666. String directory, filename;
  203667. if (currentFileOrDirectory.isDirectory())
  203668. {
  203669. directory = currentFileOrDirectory.getFullPathName();
  203670. }
  203671. else
  203672. {
  203673. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203674. filename = currentFileOrDirectory.getFileName();
  203675. }
  203676. if ([panel runModalForDirectory: juceStringToNS (directory)
  203677. file: juceStringToNS (filename)]
  203678. == NSOKButton)
  203679. {
  203680. if (isSaveDialogue)
  203681. {
  203682. results.add (File (nsStringToJuce ([panel filename])));
  203683. }
  203684. else
  203685. {
  203686. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203687. NSArray* urls = [openPanel filenames];
  203688. for (unsigned int i = 0; i < [urls count]; ++i)
  203689. {
  203690. NSString* f = [urls objectAtIndex: i];
  203691. results.add (File (nsStringToJuce (f)));
  203692. }
  203693. }
  203694. }
  203695. [panel setDelegate: nil];
  203696. }
  203697. #else
  203698. void FileChooser::showPlatformDialog (Array<File>& results,
  203699. const String& title,
  203700. const File& currentFileOrDirectory,
  203701. const String& filter,
  203702. bool selectsDirectory,
  203703. bool selectsFiles,
  203704. bool isSaveDialogue,
  203705. bool warnAboutOverwritingExistingFiles,
  203706. bool selectMultipleFiles,
  203707. FilePreviewComponent* extraInfoComponent)
  203708. {
  203709. const ScopedAutoReleasePool pool;
  203710. jassertfalse //xxx to do
  203711. }
  203712. #endif
  203713. #endif
  203714. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203715. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203716. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203717. // compiled on its own).
  203718. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203719. #if JUCE_MAC
  203720. END_JUCE_NAMESPACE
  203721. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203722. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203723. {
  203724. CriticalSection* contextLock;
  203725. bool needsUpdate;
  203726. }
  203727. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203728. - (bool) makeActive;
  203729. - (void) makeInactive;
  203730. - (void) reshape;
  203731. @end
  203732. @implementation ThreadSafeNSOpenGLView
  203733. - (id) initWithFrame: (NSRect) frameRect
  203734. pixelFormat: (NSOpenGLPixelFormat*) format
  203735. {
  203736. contextLock = new CriticalSection();
  203737. self = [super initWithFrame: frameRect pixelFormat: format];
  203738. if (self != nil)
  203739. [[NSNotificationCenter defaultCenter] addObserver: self
  203740. selector: @selector (_surfaceNeedsUpdate:)
  203741. name: NSViewGlobalFrameDidChangeNotification
  203742. object: self];
  203743. return self;
  203744. }
  203745. - (void) dealloc
  203746. {
  203747. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203748. delete contextLock;
  203749. [super dealloc];
  203750. }
  203751. - (bool) makeActive
  203752. {
  203753. const ScopedLock sl (*contextLock);
  203754. if ([self openGLContext] == 0)
  203755. return false;
  203756. [[self openGLContext] makeCurrentContext];
  203757. if (needsUpdate)
  203758. {
  203759. [super update];
  203760. needsUpdate = false;
  203761. }
  203762. return true;
  203763. }
  203764. - (void) makeInactive
  203765. {
  203766. const ScopedLock sl (*contextLock);
  203767. [NSOpenGLContext clearCurrentContext];
  203768. }
  203769. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  203770. {
  203771. const ScopedLock sl (*contextLock);
  203772. needsUpdate = true;
  203773. }
  203774. - (void) update
  203775. {
  203776. const ScopedLock sl (*contextLock);
  203777. needsUpdate = true;
  203778. }
  203779. - (void) reshape
  203780. {
  203781. const ScopedLock sl (*contextLock);
  203782. needsUpdate = true;
  203783. }
  203784. @end
  203785. BEGIN_JUCE_NAMESPACE
  203786. class WindowedGLContext : public OpenGLContext
  203787. {
  203788. public:
  203789. WindowedGLContext (Component* const component,
  203790. const OpenGLPixelFormat& pixelFormat_,
  203791. NSOpenGLContext* sharedContext)
  203792. : renderContext (0),
  203793. pixelFormat (pixelFormat_)
  203794. {
  203795. jassert (component != 0);
  203796. NSOpenGLPixelFormatAttribute attribs [64];
  203797. int n = 0;
  203798. attribs[n++] = NSOpenGLPFADoubleBuffer;
  203799. attribs[n++] = NSOpenGLPFAAccelerated;
  203800. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  203801. attribs[n++] = NSOpenGLPFAColorSize;
  203802. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  203803. pixelFormat.greenBits,
  203804. pixelFormat.blueBits);
  203805. attribs[n++] = NSOpenGLPFAAlphaSize;
  203806. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  203807. attribs[n++] = NSOpenGLPFADepthSize;
  203808. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  203809. attribs[n++] = NSOpenGLPFAStencilSize;
  203810. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  203811. attribs[n++] = NSOpenGLPFAAccumSize;
  203812. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  203813. pixelFormat.accumulationBufferGreenBits,
  203814. pixelFormat.accumulationBufferBlueBits,
  203815. pixelFormat.accumulationBufferAlphaBits);
  203816. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  203817. attribs[n++] = NSOpenGLPFASampleBuffers;
  203818. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  203819. attribs[n++] = NSOpenGLPFAClosestPolicy;
  203820. attribs[n++] = NSOpenGLPFANoRecovery;
  203821. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  203822. NSOpenGLPixelFormat* format
  203823. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  203824. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  203825. pixelFormat: format];
  203826. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  203827. shareContext: sharedContext] autorelease];
  203828. const GLint swapInterval = 1;
  203829. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  203830. [view setOpenGLContext: renderContext];
  203831. [renderContext setView: view];
  203832. [format release];
  203833. viewHolder = new NSViewComponentInternal (view, component);
  203834. }
  203835. ~WindowedGLContext()
  203836. {
  203837. makeInactive();
  203838. [renderContext clearDrawable];
  203839. viewHolder = 0;
  203840. }
  203841. bool makeActive() const throw()
  203842. {
  203843. jassert (renderContext != 0);
  203844. [view makeActive];
  203845. return isActive();
  203846. }
  203847. bool makeInactive() const throw()
  203848. {
  203849. [view makeInactive];
  203850. return true;
  203851. }
  203852. bool isActive() const throw()
  203853. {
  203854. return [NSOpenGLContext currentContext] == renderContext;
  203855. }
  203856. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203857. void* getRawContext() const throw() { return renderContext; }
  203858. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203859. {
  203860. }
  203861. void swapBuffers()
  203862. {
  203863. [renderContext flushBuffer];
  203864. }
  203865. bool setSwapInterval (const int numFramesPerSwap)
  203866. {
  203867. [renderContext setValues: (const GLint*) &numFramesPerSwap
  203868. forParameter: NSOpenGLCPSwapInterval];
  203869. return true;
  203870. }
  203871. int getSwapInterval() const
  203872. {
  203873. GLint numFrames = 0;
  203874. [renderContext getValues: &numFrames
  203875. forParameter: NSOpenGLCPSwapInterval];
  203876. return numFrames;
  203877. }
  203878. void repaint()
  203879. {
  203880. // we need to invalidate the juce view that holds this gl view, to make it
  203881. // cause a repaint callback
  203882. NSView* v = (NSView*) viewHolder->view;
  203883. NSRect r = [v frame];
  203884. // bit of a bodge here.. if we only invalidate the area of the gl component,
  203885. // it's completely covered by the NSOpenGLView, so the OS throws away the
  203886. // repaint message, thus never causing our paint() callback, and never repainting
  203887. // the comp. So invalidating just a little bit around the edge helps..
  203888. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  203889. }
  203890. void* getNativeWindowHandle() const { return viewHolder->view; }
  203891. juce_UseDebuggingNewOperator
  203892. NSOpenGLContext* renderContext;
  203893. ThreadSafeNSOpenGLView* view;
  203894. private:
  203895. OpenGLPixelFormat pixelFormat;
  203896. ScopedPointer <NSViewComponentInternal> viewHolder;
  203897. WindowedGLContext (const WindowedGLContext&);
  203898. WindowedGLContext& operator= (const WindowedGLContext&);
  203899. };
  203900. OpenGLContext* OpenGLComponent::createContext()
  203901. {
  203902. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  203903. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  203904. return (c->renderContext != 0) ? c.release() : 0;
  203905. }
  203906. void* OpenGLComponent::getNativeWindowHandle() const
  203907. {
  203908. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  203909. : 0;
  203910. }
  203911. void juce_glViewport (const int w, const int h)
  203912. {
  203913. glViewport (0, 0, w, h);
  203914. }
  203915. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  203916. OwnedArray <OpenGLPixelFormat>& results)
  203917. {
  203918. /* GLint attribs [64];
  203919. int n = 0;
  203920. attribs[n++] = AGL_RGBA;
  203921. attribs[n++] = AGL_DOUBLEBUFFER;
  203922. attribs[n++] = AGL_ACCELERATED;
  203923. attribs[n++] = AGL_NO_RECOVERY;
  203924. attribs[n++] = AGL_NONE;
  203925. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  203926. while (p != 0)
  203927. {
  203928. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  203929. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  203930. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  203931. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  203932. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  203933. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  203934. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  203935. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  203936. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  203937. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  203938. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  203939. results.add (pf);
  203940. p = aglNextPixelFormat (p);
  203941. }*/
  203942. //jassertfalse //xxx can't see how you do this in cocoa!
  203943. }
  203944. #else
  203945. END_JUCE_NAMESPACE
  203946. @interface JuceGLView : UIView
  203947. {
  203948. }
  203949. + (Class) layerClass;
  203950. @end
  203951. @implementation JuceGLView
  203952. + (Class) layerClass
  203953. {
  203954. return [CAEAGLLayer class];
  203955. }
  203956. @end
  203957. BEGIN_JUCE_NAMESPACE
  203958. class GLESContext : public OpenGLContext
  203959. {
  203960. public:
  203961. GLESContext (UIViewComponentPeer* peer,
  203962. Component* const component_,
  203963. const OpenGLPixelFormat& pixelFormat_,
  203964. const GLESContext* const sharedContext,
  203965. NSUInteger apiType)
  203966. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  203967. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  203968. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  203969. {
  203970. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  203971. view.opaque = YES;
  203972. view.hidden = NO;
  203973. view.backgroundColor = [UIColor blackColor];
  203974. view.userInteractionEnabled = NO;
  203975. glLayer = (CAEAGLLayer*) [view layer];
  203976. [peer->view addSubview: view];
  203977. if (sharedContext != 0)
  203978. context = [[EAGLContext alloc] initWithAPI: apiType
  203979. sharegroup: [sharedContext->context sharegroup]];
  203980. else
  203981. context = [[EAGLContext alloc] initWithAPI: apiType];
  203982. createGLBuffers();
  203983. }
  203984. ~GLESContext()
  203985. {
  203986. makeInactive();
  203987. [context release];
  203988. [view removeFromSuperview];
  203989. [view release];
  203990. freeGLBuffers();
  203991. }
  203992. bool makeActive() const throw()
  203993. {
  203994. jassert (context != 0);
  203995. [EAGLContext setCurrentContext: context];
  203996. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  203997. return true;
  203998. }
  203999. void swapBuffers()
  204000. {
  204001. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  204002. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  204003. }
  204004. bool makeInactive() const throw()
  204005. {
  204006. return [EAGLContext setCurrentContext: nil];
  204007. }
  204008. bool isActive() const throw()
  204009. {
  204010. return [EAGLContext currentContext] == context;
  204011. }
  204012. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  204013. void* getRawContext() const throw() { return (void*) glLayer; }
  204014. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  204015. {
  204016. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  204017. if (lastWidth != w || lastHeight != h)
  204018. {
  204019. lastWidth = w;
  204020. lastHeight = h;
  204021. freeGLBuffers();
  204022. createGLBuffers();
  204023. }
  204024. }
  204025. bool setSwapInterval (const int numFramesPerSwap)
  204026. {
  204027. numFrames = numFramesPerSwap;
  204028. return true;
  204029. }
  204030. int getSwapInterval() const
  204031. {
  204032. return numFrames;
  204033. }
  204034. void repaint()
  204035. {
  204036. }
  204037. void createGLBuffers()
  204038. {
  204039. makeActive();
  204040. glGenFramebuffersOES (1, &frameBufferHandle);
  204041. glGenRenderbuffersOES (1, &colorBufferHandle);
  204042. glGenRenderbuffersOES (1, &depthBufferHandle);
  204043. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  204044. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  204045. GLint width, height;
  204046. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  204047. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  204048. if (useDepthBuffer)
  204049. {
  204050. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  204051. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  204052. }
  204053. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  204054. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  204055. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  204056. if (useDepthBuffer)
  204057. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  204058. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  204059. }
  204060. void freeGLBuffers()
  204061. {
  204062. if (frameBufferHandle != 0)
  204063. {
  204064. glDeleteFramebuffersOES (1, &frameBufferHandle);
  204065. frameBufferHandle = 0;
  204066. }
  204067. if (colorBufferHandle != 0)
  204068. {
  204069. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  204070. colorBufferHandle = 0;
  204071. }
  204072. if (depthBufferHandle != 0)
  204073. {
  204074. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  204075. depthBufferHandle = 0;
  204076. }
  204077. }
  204078. juce_UseDebuggingNewOperator
  204079. private:
  204080. Component::SafePointer<Component> component;
  204081. OpenGLPixelFormat pixelFormat;
  204082. JuceGLView* view;
  204083. CAEAGLLayer* glLayer;
  204084. EAGLContext* context;
  204085. bool useDepthBuffer;
  204086. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  204087. int numFrames;
  204088. int lastWidth, lastHeight;
  204089. GLESContext (const GLESContext&);
  204090. GLESContext& operator= (const GLESContext&);
  204091. };
  204092. OpenGLContext* OpenGLComponent::createContext()
  204093. {
  204094. ScopedAutoReleasePool pool;
  204095. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  204096. if (peer != 0)
  204097. return new GLESContext (peer, this, preferredPixelFormat,
  204098. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  204099. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  204100. return 0;
  204101. }
  204102. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204103. OwnedArray <OpenGLPixelFormat>& /*results*/)
  204104. {
  204105. }
  204106. void juce_glViewport (const int w, const int h)
  204107. {
  204108. glViewport (0, 0, w, h);
  204109. }
  204110. #endif
  204111. #endif
  204112. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204113. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204114. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204115. // compiled on its own).
  204116. #if JUCE_INCLUDED_FILE
  204117. #if JUCE_MAC
  204118. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  204119. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  204120. {
  204121. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204122. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204123. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204124. [im release];
  204125. return (void*) c;
  204126. }
  204127. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  204128. {
  204129. MemoryInputStream stream (data, size, false);
  204130. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  204131. jassert (im != 0);
  204132. if (im == 0)
  204133. return 0;
  204134. return juce_createMouseCursorFromImage (*im,
  204135. (int) (hx * im->getWidth()),
  204136. (int) (hy * im->getHeight()));
  204137. }
  204138. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204139. {
  204140. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204141. MemoryBlock mb;
  204142. if (f.getChildFile (filename).loadFileAsData (mb))
  204143. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  204144. return 0;
  204145. }
  204146. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  204147. {
  204148. const ScopedAutoReleasePool pool;
  204149. NSCursor* c = 0;
  204150. switch (type)
  204151. {
  204152. case MouseCursor::NormalCursor:
  204153. c = [NSCursor arrowCursor];
  204154. break;
  204155. case MouseCursor::NoCursor:
  204156. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  204157. case MouseCursor::DraggingHandCursor:
  204158. c = [NSCursor openHandCursor];
  204159. break;
  204160. case MouseCursor::CopyingCursor:
  204161. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204162. case MouseCursor::WaitCursor:
  204163. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204164. break;
  204165. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204166. case MouseCursor::IBeamCursor:
  204167. c = [NSCursor IBeamCursor];
  204168. break;
  204169. case MouseCursor::PointingHandCursor:
  204170. c = [NSCursor pointingHandCursor];
  204171. break;
  204172. case MouseCursor::LeftRightResizeCursor:
  204173. c = [NSCursor resizeLeftRightCursor];
  204174. break;
  204175. case MouseCursor::LeftEdgeResizeCursor:
  204176. c = [NSCursor resizeLeftCursor];
  204177. break;
  204178. case MouseCursor::RightEdgeResizeCursor:
  204179. c = [NSCursor resizeRightCursor];
  204180. break;
  204181. case MouseCursor::UpDownResizeCursor:
  204182. case MouseCursor::TopEdgeResizeCursor:
  204183. case MouseCursor::BottomEdgeResizeCursor:
  204184. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204185. case MouseCursor::TopLeftCornerResizeCursor:
  204186. case MouseCursor::BottomRightCornerResizeCursor:
  204187. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204188. case MouseCursor::TopRightCornerResizeCursor:
  204189. case MouseCursor::BottomLeftCornerResizeCursor:
  204190. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204191. case MouseCursor::UpDownLeftRightResizeCursor:
  204192. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204193. case MouseCursor::CrosshairCursor:
  204194. c = [NSCursor crosshairCursor];
  204195. break;
  204196. }
  204197. [c retain];
  204198. return (void*) c;
  204199. }
  204200. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204201. {
  204202. NSCursor* c = (NSCursor*) cursorHandle;
  204203. [c release];
  204204. }
  204205. void MouseCursor::showInAllWindows() const throw()
  204206. {
  204207. showInWindow (0);
  204208. }
  204209. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204210. {
  204211. NSCursor* const c = (NSCursor*) getHandle();
  204212. [c set];
  204213. }
  204214. #else
  204215. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204216. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204217. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204218. void MouseCursor::showInAllWindows() const throw() {}
  204219. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204220. #endif
  204221. #endif
  204222. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204223. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204224. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204225. // compiled on its own).
  204226. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204227. #if JUCE_MAC
  204228. END_JUCE_NAMESPACE
  204229. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204230. @interface DownloadClickDetector : NSObject
  204231. {
  204232. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204233. }
  204234. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204235. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204236. request: (NSURLRequest*) request
  204237. frame: (WebFrame*) frame
  204238. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204239. @end
  204240. @implementation DownloadClickDetector
  204241. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204242. {
  204243. [super init];
  204244. ownerComponent = ownerComponent_;
  204245. return self;
  204246. }
  204247. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204248. request: (NSURLRequest*) request
  204249. frame: (WebFrame*) frame
  204250. decisionListener: (id <WebPolicyDecisionListener>) listener
  204251. {
  204252. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204253. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204254. [listener use];
  204255. else
  204256. [listener ignore];
  204257. }
  204258. @end
  204259. BEGIN_JUCE_NAMESPACE
  204260. class WebBrowserComponentInternal : public NSViewComponent
  204261. {
  204262. public:
  204263. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204264. {
  204265. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204266. frameName: @""
  204267. groupName: @""];
  204268. setView (webView);
  204269. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204270. [webView setPolicyDelegate: clickListener];
  204271. }
  204272. ~WebBrowserComponentInternal()
  204273. {
  204274. [webView setPolicyDelegate: nil];
  204275. [clickListener release];
  204276. setView (0);
  204277. }
  204278. void goToURL (const String& url,
  204279. const StringArray* headers,
  204280. const MemoryBlock* postData)
  204281. {
  204282. NSMutableURLRequest* r
  204283. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204284. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204285. timeoutInterval: 30.0];
  204286. if (postData != 0 && postData->getSize() > 0)
  204287. {
  204288. [r setHTTPMethod: @"POST"];
  204289. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204290. length: postData->getSize()]];
  204291. }
  204292. if (headers != 0)
  204293. {
  204294. for (int i = 0; i < headers->size(); ++i)
  204295. {
  204296. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  204297. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  204298. [r setValue: juceStringToNS (headerValue)
  204299. forHTTPHeaderField: juceStringToNS (headerName)];
  204300. }
  204301. }
  204302. stop();
  204303. [[webView mainFrame] loadRequest: r];
  204304. }
  204305. void goBack()
  204306. {
  204307. [webView goBack];
  204308. }
  204309. void goForward()
  204310. {
  204311. [webView goForward];
  204312. }
  204313. void stop()
  204314. {
  204315. [webView stopLoading: nil];
  204316. }
  204317. void refresh()
  204318. {
  204319. [webView reload: nil];
  204320. }
  204321. private:
  204322. WebView* webView;
  204323. DownloadClickDetector* clickListener;
  204324. };
  204325. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204326. : browser (0),
  204327. blankPageShown (false),
  204328. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204329. {
  204330. setOpaque (true);
  204331. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204332. }
  204333. WebBrowserComponent::~WebBrowserComponent()
  204334. {
  204335. deleteAndZero (browser);
  204336. }
  204337. void WebBrowserComponent::goToURL (const String& url,
  204338. const StringArray* headers,
  204339. const MemoryBlock* postData)
  204340. {
  204341. lastURL = url;
  204342. lastHeaders.clear();
  204343. if (headers != 0)
  204344. lastHeaders = *headers;
  204345. lastPostData.setSize (0);
  204346. if (postData != 0)
  204347. lastPostData = *postData;
  204348. blankPageShown = false;
  204349. browser->goToURL (url, headers, postData);
  204350. }
  204351. void WebBrowserComponent::stop()
  204352. {
  204353. browser->stop();
  204354. }
  204355. void WebBrowserComponent::goBack()
  204356. {
  204357. lastURL = String::empty;
  204358. blankPageShown = false;
  204359. browser->goBack();
  204360. }
  204361. void WebBrowserComponent::goForward()
  204362. {
  204363. lastURL = String::empty;
  204364. browser->goForward();
  204365. }
  204366. void WebBrowserComponent::refresh()
  204367. {
  204368. browser->refresh();
  204369. }
  204370. void WebBrowserComponent::paint (Graphics& g)
  204371. {
  204372. }
  204373. void WebBrowserComponent::checkWindowAssociation()
  204374. {
  204375. if (isShowing())
  204376. {
  204377. if (blankPageShown)
  204378. goBack();
  204379. }
  204380. else
  204381. {
  204382. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204383. {
  204384. // when the component becomes invisible, some stuff like flash
  204385. // carries on playing audio, so we need to force it onto a blank
  204386. // page to avoid this, (and send it back when it's made visible again).
  204387. blankPageShown = true;
  204388. browser->goToURL ("about:blank", 0, 0);
  204389. }
  204390. }
  204391. }
  204392. void WebBrowserComponent::reloadLastURL()
  204393. {
  204394. if (lastURL.isNotEmpty())
  204395. {
  204396. goToURL (lastURL, &lastHeaders, &lastPostData);
  204397. lastURL = String::empty;
  204398. }
  204399. }
  204400. void WebBrowserComponent::parentHierarchyChanged()
  204401. {
  204402. checkWindowAssociation();
  204403. }
  204404. void WebBrowserComponent::resized()
  204405. {
  204406. browser->setSize (getWidth(), getHeight());
  204407. }
  204408. void WebBrowserComponent::visibilityChanged()
  204409. {
  204410. checkWindowAssociation();
  204411. }
  204412. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204413. {
  204414. return true;
  204415. }
  204416. #else
  204417. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204418. {
  204419. }
  204420. WebBrowserComponent::~WebBrowserComponent()
  204421. {
  204422. }
  204423. void WebBrowserComponent::goToURL (const String& url,
  204424. const StringArray* headers,
  204425. const MemoryBlock* postData)
  204426. {
  204427. }
  204428. void WebBrowserComponent::stop()
  204429. {
  204430. }
  204431. void WebBrowserComponent::goBack()
  204432. {
  204433. }
  204434. void WebBrowserComponent::goForward()
  204435. {
  204436. }
  204437. void WebBrowserComponent::refresh()
  204438. {
  204439. }
  204440. void WebBrowserComponent::paint (Graphics& g)
  204441. {
  204442. }
  204443. void WebBrowserComponent::checkWindowAssociation()
  204444. {
  204445. }
  204446. void WebBrowserComponent::reloadLastURL()
  204447. {
  204448. }
  204449. void WebBrowserComponent::parentHierarchyChanged()
  204450. {
  204451. }
  204452. void WebBrowserComponent::resized()
  204453. {
  204454. }
  204455. void WebBrowserComponent::visibilityChanged()
  204456. {
  204457. }
  204458. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204459. {
  204460. return true;
  204461. }
  204462. #endif
  204463. #endif
  204464. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204465. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204466. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204467. // compiled on its own).
  204468. #if JUCE_INCLUDED_FILE
  204469. class IPhoneAudioIODevice : public AudioIODevice
  204470. {
  204471. public:
  204472. IPhoneAudioIODevice (const String& deviceName)
  204473. : AudioIODevice (deviceName, T("Audio")),
  204474. audioUnit (0),
  204475. isRunning (false),
  204476. callback (0),
  204477. actualBufferSize (0),
  204478. floatData (1, 2)
  204479. {
  204480. numInputChannels = 2;
  204481. numOutputChannels = 2;
  204482. preferredBufferSize = 0;
  204483. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204484. updateDeviceInfo();
  204485. }
  204486. ~IPhoneAudioIODevice()
  204487. {
  204488. close();
  204489. }
  204490. const StringArray getOutputChannelNames()
  204491. {
  204492. StringArray s;
  204493. s.add ("Left");
  204494. s.add ("Right");
  204495. return s;
  204496. }
  204497. const StringArray getInputChannelNames()
  204498. {
  204499. StringArray s;
  204500. if (audioInputIsAvailable)
  204501. {
  204502. s.add ("Left");
  204503. s.add ("Right");
  204504. }
  204505. return s;
  204506. }
  204507. int getNumSampleRates()
  204508. {
  204509. return 1;
  204510. }
  204511. double getSampleRate (int index)
  204512. {
  204513. return sampleRate;
  204514. }
  204515. int getNumBufferSizesAvailable()
  204516. {
  204517. return 1;
  204518. }
  204519. int getBufferSizeSamples (int index)
  204520. {
  204521. return getDefaultBufferSize();
  204522. }
  204523. int getDefaultBufferSize()
  204524. {
  204525. return 1024;
  204526. }
  204527. const String open (const BigInteger& inputChannels,
  204528. const BigInteger& outputChannels,
  204529. double sampleRate,
  204530. int bufferSize)
  204531. {
  204532. close();
  204533. lastError = String::empty;
  204534. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204535. // xxx set up channel mapping
  204536. activeOutputChans = outputChannels;
  204537. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204538. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204539. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204540. activeInputChans = inputChannels;
  204541. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204542. numInputChannels = activeInputChans.countNumberOfSetBits();
  204543. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204544. AudioSessionSetActive (true);
  204545. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204546. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204547. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204548. fixAudioRouteIfSetToReceiver();
  204549. updateDeviceInfo();
  204550. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204551. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204552. actualBufferSize = preferredBufferSize;
  204553. prepareFloatBuffers();
  204554. isRunning = true;
  204555. propertyChanged (0, 0, 0); // creates and starts the AU
  204556. lastError = audioUnit != 0 ? String::empty
  204557. : T("Couldn't open the device");
  204558. return lastError;
  204559. }
  204560. void close()
  204561. {
  204562. if (isRunning)
  204563. {
  204564. isRunning = false;
  204565. AudioSessionSetActive (false);
  204566. if (audioUnit != 0)
  204567. {
  204568. AudioComponentInstanceDispose (audioUnit);
  204569. audioUnit = 0;
  204570. }
  204571. }
  204572. }
  204573. bool isOpen()
  204574. {
  204575. return isRunning;
  204576. }
  204577. int getCurrentBufferSizeSamples()
  204578. {
  204579. return actualBufferSize;
  204580. }
  204581. double getCurrentSampleRate()
  204582. {
  204583. return sampleRate;
  204584. }
  204585. int getCurrentBitDepth()
  204586. {
  204587. return 16;
  204588. }
  204589. const BigInteger getActiveOutputChannels() const
  204590. {
  204591. return activeOutputChans;
  204592. }
  204593. const BigInteger getActiveInputChannels() const
  204594. {
  204595. return activeInputChans;
  204596. }
  204597. int getOutputLatencyInSamples()
  204598. {
  204599. return 0; //xxx
  204600. }
  204601. int getInputLatencyInSamples()
  204602. {
  204603. return 0; //xxx
  204604. }
  204605. void start (AudioIODeviceCallback* callback_)
  204606. {
  204607. if (isRunning && callback != callback_)
  204608. {
  204609. if (callback_ != 0)
  204610. callback_->audioDeviceAboutToStart (this);
  204611. const ScopedLock sl (callbackLock);
  204612. callback = callback_;
  204613. }
  204614. }
  204615. void stop()
  204616. {
  204617. if (isRunning)
  204618. {
  204619. AudioIODeviceCallback* lastCallback;
  204620. {
  204621. const ScopedLock sl (callbackLock);
  204622. lastCallback = callback;
  204623. callback = 0;
  204624. }
  204625. if (lastCallback != 0)
  204626. lastCallback->audioDeviceStopped();
  204627. }
  204628. }
  204629. bool isPlaying()
  204630. {
  204631. return isRunning && callback != 0;
  204632. }
  204633. const String getLastError()
  204634. {
  204635. return lastError;
  204636. }
  204637. private:
  204638. CriticalSection callbackLock;
  204639. Float64 sampleRate;
  204640. int numInputChannels, numOutputChannels;
  204641. int preferredBufferSize;
  204642. int actualBufferSize;
  204643. bool isRunning;
  204644. String lastError;
  204645. AudioStreamBasicDescription format;
  204646. AudioUnit audioUnit;
  204647. UInt32 audioInputIsAvailable;
  204648. AudioIODeviceCallback* callback;
  204649. BigInteger activeOutputChans, activeInputChans;
  204650. AudioSampleBuffer floatData;
  204651. float* inputChannels[3];
  204652. float* outputChannels[3];
  204653. bool monoInputChannelNumber, monoOutputChannelNumber;
  204654. void prepareFloatBuffers()
  204655. {
  204656. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204657. zerostruct (inputChannels);
  204658. zerostruct (outputChannels);
  204659. for (int i = 0; i < numInputChannels; ++i)
  204660. inputChannels[i] = floatData.getSampleData (i);
  204661. for (int i = 0; i < numOutputChannels; ++i)
  204662. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204663. }
  204664. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204665. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204666. {
  204667. OSStatus err = noErr;
  204668. if (audioInputIsAvailable)
  204669. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204670. const ScopedLock sl (callbackLock);
  204671. if (callback != 0)
  204672. {
  204673. if (audioInputIsAvailable && numInputChannels > 0)
  204674. {
  204675. short* shortData = (short*) ioData->mBuffers[0].mData;
  204676. if (numInputChannels >= 2)
  204677. {
  204678. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204679. {
  204680. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204681. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204682. }
  204683. }
  204684. else
  204685. {
  204686. if (monoInputChannelNumber > 0)
  204687. ++shortData;
  204688. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204689. {
  204690. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204691. ++shortData;
  204692. }
  204693. }
  204694. }
  204695. else
  204696. {
  204697. for (int i = numInputChannels; --i >= 0;)
  204698. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204699. }
  204700. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204701. outputChannels, numOutputChannels,
  204702. (int) inNumberFrames);
  204703. short* shortData = (short*) ioData->mBuffers[0].mData;
  204704. int n = 0;
  204705. if (numOutputChannels >= 2)
  204706. {
  204707. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204708. {
  204709. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204710. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204711. }
  204712. }
  204713. else if (numOutputChannels == 1)
  204714. {
  204715. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204716. {
  204717. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204718. shortData [n++] = s;
  204719. shortData [n++] = s;
  204720. }
  204721. }
  204722. else
  204723. {
  204724. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204725. }
  204726. }
  204727. else
  204728. {
  204729. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204730. }
  204731. return err;
  204732. }
  204733. void updateDeviceInfo()
  204734. {
  204735. UInt32 size = sizeof (sampleRate);
  204736. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204737. size = sizeof (audioInputIsAvailable);
  204738. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204739. }
  204740. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204741. {
  204742. if (! isRunning)
  204743. return;
  204744. if (inPropertyValue != 0)
  204745. {
  204746. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204747. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204748. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204749. SInt32 routeChangeReason;
  204750. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204751. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204752. fixAudioRouteIfSetToReceiver();
  204753. }
  204754. updateDeviceInfo();
  204755. createAudioUnit();
  204756. AudioSessionSetActive (true);
  204757. if (audioUnit != 0)
  204758. {
  204759. UInt32 formatSize = sizeof (format);
  204760. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204761. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204762. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204763. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204764. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204765. AudioOutputUnitStart (audioUnit);
  204766. }
  204767. }
  204768. void interruptionListener (UInt32 inInterruption)
  204769. {
  204770. if (inInterruption == kAudioSessionEndInterruption)
  204771. {
  204772. isRunning = true;
  204773. AudioSessionSetActive (true);
  204774. AudioOutputUnitStart (audioUnit);
  204775. }
  204776. }
  204777. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204778. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204779. {
  204780. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204781. }
  204782. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204783. {
  204784. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204785. }
  204786. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204787. {
  204788. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204789. }
  204790. void resetFormat (const int numChannels)
  204791. {
  204792. memset (&format, 0, sizeof (format));
  204793. format.mFormatID = kAudioFormatLinearPCM;
  204794. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204795. format.mBitsPerChannel = 8 * sizeof (short);
  204796. format.mChannelsPerFrame = 2;
  204797. format.mFramesPerPacket = 1;
  204798. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204799. }
  204800. bool createAudioUnit()
  204801. {
  204802. if (audioUnit != 0)
  204803. {
  204804. AudioComponentInstanceDispose (audioUnit);
  204805. audioUnit = 0;
  204806. }
  204807. resetFormat (2);
  204808. AudioComponentDescription desc;
  204809. desc.componentType = kAudioUnitType_Output;
  204810. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204811. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204812. desc.componentFlags = 0;
  204813. desc.componentFlagsMask = 0;
  204814. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204815. AudioComponentInstanceNew (comp, &audioUnit);
  204816. if (audioUnit == 0)
  204817. return false;
  204818. const UInt32 one = 1;
  204819. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204820. AudioChannelLayout layout;
  204821. layout.mChannelBitmap = 0;
  204822. layout.mNumberChannelDescriptions = 0;
  204823. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204824. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204825. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204826. AURenderCallbackStruct inputProc;
  204827. inputProc.inputProc = processStatic;
  204828. inputProc.inputProcRefCon = this;
  204829. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204830. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204831. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204832. AudioUnitInitialize (audioUnit);
  204833. return true;
  204834. }
  204835. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204836. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204837. static void fixAudioRouteIfSetToReceiver()
  204838. {
  204839. CFStringRef audioRoute = 0;
  204840. UInt32 propertySize = sizeof (audioRoute);
  204841. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204842. {
  204843. NSString* route = (NSString*) audioRoute;
  204844. //DBG ("audio route: " + nsStringToJuce (route));
  204845. if ([route hasPrefix: @"Receiver"])
  204846. {
  204847. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204848. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204849. }
  204850. CFRelease (audioRoute);
  204851. }
  204852. }
  204853. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204854. IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204855. };
  204856. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204857. {
  204858. public:
  204859. IPhoneAudioIODeviceType()
  204860. : AudioIODeviceType (T("iPhone Audio"))
  204861. {
  204862. }
  204863. ~IPhoneAudioIODeviceType()
  204864. {
  204865. }
  204866. void scanForDevices()
  204867. {
  204868. }
  204869. const StringArray getDeviceNames (const bool wantInputNames) const
  204870. {
  204871. StringArray s;
  204872. s.add ("iPhone Audio");
  204873. return s;
  204874. }
  204875. int getDefaultDeviceIndex (const bool forInput) const
  204876. {
  204877. return 0;
  204878. }
  204879. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  204880. {
  204881. return device != 0 ? 0 : -1;
  204882. }
  204883. bool hasSeparateInputsAndOutputs() const { return false; }
  204884. AudioIODevice* createDevice (const String& outputDeviceName,
  204885. const String& inputDeviceName)
  204886. {
  204887. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204888. {
  204889. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204890. : inputDeviceName);
  204891. }
  204892. return 0;
  204893. }
  204894. juce_UseDebuggingNewOperator
  204895. private:
  204896. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204897. IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204898. };
  204899. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204900. {
  204901. return new IPhoneAudioIODeviceType();
  204902. }
  204903. #endif
  204904. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  204905. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  204906. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204907. // compiled on its own).
  204908. #if JUCE_INCLUDED_FILE
  204909. #if JUCE_MAC
  204910. #undef log
  204911. #define log(a) Logger::writeToLog(a)
  204912. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  204913. {
  204914. if (err == noErr)
  204915. return true;
  204916. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  204917. jassertfalse
  204918. return false;
  204919. }
  204920. #undef OK
  204921. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  204922. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  204923. {
  204924. String result;
  204925. CFStringRef str = 0;
  204926. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  204927. if (str != 0)
  204928. {
  204929. result = PlatformUtilities::cfStringToJuceString (str);
  204930. CFRelease (str);
  204931. str = 0;
  204932. }
  204933. MIDIEntityRef entity = 0;
  204934. MIDIEndpointGetEntity (endpoint, &entity);
  204935. if (entity == 0)
  204936. return result; // probably virtual
  204937. if (result.isEmpty())
  204938. {
  204939. // endpoint name has zero length - try the entity
  204940. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  204941. if (str != 0)
  204942. {
  204943. result += PlatformUtilities::cfStringToJuceString (str);
  204944. CFRelease (str);
  204945. str = 0;
  204946. }
  204947. }
  204948. // now consider the device's name
  204949. MIDIDeviceRef device = 0;
  204950. MIDIEntityGetDevice (entity, &device);
  204951. if (device == 0)
  204952. return result;
  204953. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  204954. if (str != 0)
  204955. {
  204956. const String s (PlatformUtilities::cfStringToJuceString (str));
  204957. CFRelease (str);
  204958. // if an external device has only one entity, throw away
  204959. // the endpoint name and just use the device name
  204960. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  204961. {
  204962. result = s;
  204963. }
  204964. else if (! result.startsWithIgnoreCase (s))
  204965. {
  204966. // prepend the device name to the entity name
  204967. result = (s + T(" ") + result).trimEnd();
  204968. }
  204969. }
  204970. return result;
  204971. }
  204972. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  204973. {
  204974. String result;
  204975. // Does the endpoint have connections?
  204976. CFDataRef connections = 0;
  204977. int numConnections = 0;
  204978. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  204979. if (connections != 0)
  204980. {
  204981. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  204982. if (numConnections > 0)
  204983. {
  204984. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  204985. for (int i = 0; i < numConnections; ++i, ++pid)
  204986. {
  204987. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  204988. MIDIObjectRef connObject;
  204989. MIDIObjectType connObjectType;
  204990. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  204991. if (err == noErr)
  204992. {
  204993. String s;
  204994. if (connObjectType == kMIDIObjectType_ExternalSource
  204995. || connObjectType == kMIDIObjectType_ExternalDestination)
  204996. {
  204997. // Connected to an external device's endpoint (10.3 and later).
  204998. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  204999. }
  205000. else
  205001. {
  205002. // Connected to an external device (10.2) (or something else, catch-all)
  205003. CFStringRef str = 0;
  205004. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  205005. if (str != 0)
  205006. {
  205007. s = PlatformUtilities::cfStringToJuceString (str);
  205008. CFRelease (str);
  205009. }
  205010. }
  205011. if (s.isNotEmpty())
  205012. {
  205013. if (result.isNotEmpty())
  205014. result += (", ");
  205015. result += s;
  205016. }
  205017. }
  205018. }
  205019. }
  205020. CFRelease (connections);
  205021. }
  205022. if (result.isNotEmpty())
  205023. return result;
  205024. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  205025. return getEndpointName (endpoint, false);
  205026. }
  205027. const StringArray MidiOutput::getDevices()
  205028. {
  205029. StringArray s;
  205030. const ItemCount num = MIDIGetNumberOfDestinations();
  205031. for (ItemCount i = 0; i < num; ++i)
  205032. {
  205033. MIDIEndpointRef dest = MIDIGetDestination (i);
  205034. if (dest != 0)
  205035. {
  205036. String name (getConnectedEndpointName (dest));
  205037. if (name.isEmpty())
  205038. name = "<error>";
  205039. s.add (name);
  205040. }
  205041. else
  205042. {
  205043. s.add ("<error>");
  205044. }
  205045. }
  205046. return s;
  205047. }
  205048. int MidiOutput::getDefaultDeviceIndex()
  205049. {
  205050. return 0;
  205051. }
  205052. static MIDIClientRef globalMidiClient;
  205053. static bool hasGlobalClientBeenCreated = false;
  205054. static bool makeSureClientExists()
  205055. {
  205056. if (! hasGlobalClientBeenCreated)
  205057. {
  205058. String name (T("JUCE"));
  205059. if (JUCEApplication::getInstance() != 0)
  205060. name = JUCEApplication::getInstance()->getApplicationName();
  205061. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  205062. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  205063. CFRelease (appName);
  205064. }
  205065. return hasGlobalClientBeenCreated;
  205066. }
  205067. class MidiPortAndEndpoint
  205068. {
  205069. public:
  205070. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205071. : port (port_), endPoint (endPoint_)
  205072. {
  205073. }
  205074. ~MidiPortAndEndpoint()
  205075. {
  205076. if (port != 0)
  205077. MIDIPortDispose (port);
  205078. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205079. MIDIEndpointDispose (endPoint);
  205080. }
  205081. MIDIPortRef port;
  205082. MIDIEndpointRef endPoint;
  205083. };
  205084. MidiOutput* MidiOutput::openDevice (int index)
  205085. {
  205086. MidiOutput* mo = 0;
  205087. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205088. {
  205089. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205090. CFStringRef pname;
  205091. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205092. {
  205093. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  205094. if (makeSureClientExists())
  205095. {
  205096. MIDIPortRef port;
  205097. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205098. {
  205099. mo = new MidiOutput();
  205100. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  205101. }
  205102. }
  205103. CFRelease (pname);
  205104. }
  205105. }
  205106. return mo;
  205107. }
  205108. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205109. {
  205110. MidiOutput* mo = 0;
  205111. if (makeSureClientExists())
  205112. {
  205113. MIDIEndpointRef endPoint;
  205114. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205115. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205116. {
  205117. mo = new MidiOutput();
  205118. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  205119. }
  205120. CFRelease (name);
  205121. }
  205122. return mo;
  205123. }
  205124. MidiOutput::~MidiOutput()
  205125. {
  205126. delete (MidiPortAndEndpoint*) internal;
  205127. }
  205128. void MidiOutput::reset()
  205129. {
  205130. }
  205131. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205132. {
  205133. return false;
  205134. }
  205135. void MidiOutput::setVolume (float leftVol, float rightVol)
  205136. {
  205137. }
  205138. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205139. {
  205140. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205141. if (message.isSysEx())
  205142. {
  205143. const int maxPacketSize = 256;
  205144. int pos = 0, bytesLeft = message.getRawDataSize();
  205145. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205146. HeapBlock <MIDIPacketList> packets;
  205147. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205148. packets->numPackets = numPackets;
  205149. MIDIPacket* p = packets->packet;
  205150. for (int i = 0; i < numPackets; ++i)
  205151. {
  205152. p->timeStamp = 0;
  205153. p->length = jmin (maxPacketSize, bytesLeft);
  205154. memcpy (p->data, message.getRawData() + pos, p->length);
  205155. pos += p->length;
  205156. bytesLeft -= p->length;
  205157. p = MIDIPacketNext (p);
  205158. }
  205159. if (mpe->port != 0)
  205160. MIDISend (mpe->port, mpe->endPoint, packets);
  205161. else
  205162. MIDIReceived (mpe->endPoint, packets);
  205163. }
  205164. else
  205165. {
  205166. MIDIPacketList packets;
  205167. packets.numPackets = 1;
  205168. packets.packet[0].timeStamp = 0;
  205169. packets.packet[0].length = message.getRawDataSize();
  205170. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205171. if (mpe->port != 0)
  205172. MIDISend (mpe->port, mpe->endPoint, &packets);
  205173. else
  205174. MIDIReceived (mpe->endPoint, &packets);
  205175. }
  205176. }
  205177. const StringArray MidiInput::getDevices()
  205178. {
  205179. StringArray s;
  205180. const ItemCount num = MIDIGetNumberOfSources();
  205181. for (ItemCount i = 0; i < num; ++i)
  205182. {
  205183. MIDIEndpointRef source = MIDIGetSource (i);
  205184. if (source != 0)
  205185. {
  205186. String name (getConnectedEndpointName (source));
  205187. if (name.isEmpty())
  205188. name = "<error>";
  205189. s.add (name);
  205190. }
  205191. else
  205192. {
  205193. s.add ("<error>");
  205194. }
  205195. }
  205196. return s;
  205197. }
  205198. int MidiInput::getDefaultDeviceIndex()
  205199. {
  205200. return 0;
  205201. }
  205202. struct MidiPortAndCallback
  205203. {
  205204. MidiInput* input;
  205205. MidiPortAndEndpoint* portAndEndpoint;
  205206. MidiInputCallback* callback;
  205207. MemoryBlock pendingData;
  205208. int pendingBytes;
  205209. double pendingDataTime;
  205210. bool active;
  205211. void processSysex (const uint8*& d, int& size, const double time)
  205212. {
  205213. if (*d == 0xf0)
  205214. {
  205215. pendingBytes = 0;
  205216. pendingDataTime = time;
  205217. }
  205218. pendingData.ensureSize (pendingBytes + size, false);
  205219. uint8* totalMessage = (uint8*) pendingData.getData();
  205220. uint8* dest = totalMessage + pendingBytes;
  205221. while (size > 0)
  205222. {
  205223. if (pendingBytes > 0 && *d >= 0x80)
  205224. {
  205225. if (*d >= 0xfa || *d == 0xf8)
  205226. {
  205227. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  205228. ++d;
  205229. --size;
  205230. }
  205231. else
  205232. {
  205233. if (*d == 0xf7)
  205234. {
  205235. *dest++ = *d++;
  205236. pendingBytes++;
  205237. --size;
  205238. }
  205239. break;
  205240. }
  205241. }
  205242. else
  205243. {
  205244. *dest++ = *d++;
  205245. pendingBytes++;
  205246. --size;
  205247. }
  205248. }
  205249. if (totalMessage [pendingBytes - 1] == 0xf7)
  205250. {
  205251. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  205252. pendingBytes = 0;
  205253. }
  205254. else
  205255. {
  205256. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  205257. }
  205258. }
  205259. };
  205260. namespace CoreMidiCallbacks
  205261. {
  205262. static CriticalSection callbackLock;
  205263. static VoidArray activeCallbacks;
  205264. }
  205265. static void midiInputProc (const MIDIPacketList* pktlist,
  205266. void* readProcRefCon,
  205267. void* srcConnRefCon)
  205268. {
  205269. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205270. const double originalTime = time;
  205271. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205272. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205273. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  205274. {
  205275. const MIDIPacket* packet = &pktlist->packet[0];
  205276. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205277. {
  205278. const uint8* d = (const uint8*) (packet->data);
  205279. int size = packet->length;
  205280. while (size > 0)
  205281. {
  205282. time = originalTime;
  205283. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205284. {
  205285. mpc->processSysex (d, size, time);
  205286. }
  205287. else
  205288. {
  205289. int used = 0;
  205290. const MidiMessage m (d, size, used, 0, time);
  205291. if (used <= 0)
  205292. {
  205293. jassertfalse // malformed midi message
  205294. break;
  205295. }
  205296. else
  205297. {
  205298. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205299. }
  205300. size -= used;
  205301. d += used;
  205302. }
  205303. }
  205304. packet = MIDIPacketNext (packet);
  205305. }
  205306. }
  205307. }
  205308. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205309. {
  205310. MidiInput* mi = 0;
  205311. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205312. {
  205313. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205314. if (endPoint != 0)
  205315. {
  205316. CFStringRef pname;
  205317. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205318. {
  205319. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  205320. if (makeSureClientExists())
  205321. {
  205322. MIDIPortRef port;
  205323. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205324. mpc->active = false;
  205325. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205326. {
  205327. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205328. {
  205329. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205330. mpc->callback = callback;
  205331. mpc->pendingBytes = 0;
  205332. mpc->pendingData.ensureSize (128);
  205333. mi = new MidiInput (getDevices() [index]);
  205334. mpc->input = mi;
  205335. mi->internal = (void*) mpc;
  205336. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205337. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205338. }
  205339. else
  205340. {
  205341. OK (MIDIPortDispose (port));
  205342. }
  205343. }
  205344. }
  205345. }
  205346. CFRelease (pname);
  205347. }
  205348. }
  205349. return mi;
  205350. }
  205351. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205352. {
  205353. MidiInput* mi = 0;
  205354. if (makeSureClientExists())
  205355. {
  205356. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205357. mpc->active = false;
  205358. MIDIEndpointRef endPoint;
  205359. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205360. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205361. {
  205362. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205363. mpc->callback = callback;
  205364. mpc->pendingBytes = 0;
  205365. mpc->pendingData.ensureSize (128);
  205366. mi = new MidiInput (deviceName);
  205367. mpc->input = mi;
  205368. mi->internal = (void*) mpc;
  205369. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205370. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205371. }
  205372. CFRelease (name);
  205373. }
  205374. return mi;
  205375. }
  205376. MidiInput::MidiInput (const String& name_)
  205377. : name (name_)
  205378. {
  205379. }
  205380. MidiInput::~MidiInput()
  205381. {
  205382. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205383. mpc->active = false;
  205384. {
  205385. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205386. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  205387. }
  205388. if (mpc->portAndEndpoint->port != 0)
  205389. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205390. delete mpc->portAndEndpoint;
  205391. delete mpc;
  205392. }
  205393. void MidiInput::start()
  205394. {
  205395. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205396. ((MidiPortAndCallback*) internal)->active = true;
  205397. }
  205398. void MidiInput::stop()
  205399. {
  205400. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205401. ((MidiPortAndCallback*) internal)->active = false;
  205402. }
  205403. #undef log
  205404. #else
  205405. MidiOutput::~MidiOutput()
  205406. {
  205407. }
  205408. void MidiOutput::reset()
  205409. {
  205410. }
  205411. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205412. {
  205413. return false;
  205414. }
  205415. void MidiOutput::setVolume (float leftVol, float rightVol)
  205416. {
  205417. }
  205418. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205419. {
  205420. }
  205421. const StringArray MidiOutput::getDevices()
  205422. {
  205423. return StringArray();
  205424. }
  205425. MidiOutput* MidiOutput::openDevice (int index)
  205426. {
  205427. return 0;
  205428. }
  205429. const StringArray MidiInput::getDevices()
  205430. {
  205431. return StringArray();
  205432. }
  205433. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205434. {
  205435. return 0;
  205436. }
  205437. #endif
  205438. #endif
  205439. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205440. #else
  205441. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205442. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205443. // compiled on its own).
  205444. #if JUCE_INCLUDED_FILE
  205445. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205446. #define SUPPORT_10_4_FONTS 1
  205447. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205448. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205449. #define SUPPORT_ONLY_10_4_FONTS 1
  205450. #endif
  205451. END_JUCE_NAMESPACE
  205452. @interface NSFont (PrivateHack)
  205453. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205454. @end
  205455. BEGIN_JUCE_NAMESPACE
  205456. #endif
  205457. class MacTypeface : public Typeface
  205458. {
  205459. public:
  205460. MacTypeface (const Font& font)
  205461. : Typeface (font.getTypefaceName())
  205462. {
  205463. const ScopedAutoReleasePool pool;
  205464. renderingTransform = CGAffineTransformIdentity;
  205465. bool needsItalicTransform = false;
  205466. #if JUCE_IPHONE
  205467. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205468. if (font.isItalic() || font.isBold())
  205469. {
  205470. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205471. for (NSString* i in familyFonts)
  205472. {
  205473. const String fn (nsStringToJuce (i));
  205474. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  205475. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  205476. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  205477. || afterDash.containsIgnoreCase (T("italic"))
  205478. || fn.endsWithIgnoreCase (T("oblique"))
  205479. || fn.endsWithIgnoreCase (T("italic"));
  205480. if (probablyBold == font.isBold()
  205481. && probablyItalic == font.isItalic())
  205482. {
  205483. fontName = i;
  205484. needsItalicTransform = false;
  205485. break;
  205486. }
  205487. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205488. {
  205489. fontName = i;
  205490. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205491. }
  205492. }
  205493. if (needsItalicTransform)
  205494. renderingTransform.c = 0.15f;
  205495. }
  205496. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205497. const int ascender = abs (CGFontGetAscent (fontRef));
  205498. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205499. ascent = ascender / totalHeight;
  205500. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205501. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205502. #else
  205503. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205504. if (font.isItalic())
  205505. {
  205506. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205507. toHaveTrait: NSItalicFontMask];
  205508. if (newFont == nsFont)
  205509. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205510. nsFont = newFont;
  205511. }
  205512. if (font.isBold())
  205513. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205514. [nsFont retain];
  205515. ascent = fabsf ((float) [nsFont ascender]);
  205516. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205517. ascent /= totalSize;
  205518. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205519. if (needsItalicTransform)
  205520. {
  205521. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205522. renderingTransform.c = 0.15f;
  205523. }
  205524. #if SUPPORT_ONLY_10_4_FONTS
  205525. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205526. if (atsFont == 0)
  205527. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205528. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205529. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205530. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205531. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205532. #else
  205533. #if SUPPORT_10_4_FONTS
  205534. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205535. {
  205536. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205537. if (atsFont == 0)
  205538. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205539. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205540. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205541. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205542. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205543. }
  205544. else
  205545. #endif
  205546. {
  205547. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205548. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205549. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205550. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205551. }
  205552. #endif
  205553. #endif
  205554. }
  205555. ~MacTypeface()
  205556. {
  205557. #if ! JUCE_IPHONE
  205558. [nsFont release];
  205559. #endif
  205560. if (fontRef != 0)
  205561. CGFontRelease (fontRef);
  205562. }
  205563. float getAscent() const
  205564. {
  205565. return ascent;
  205566. }
  205567. float getDescent() const
  205568. {
  205569. return 1.0f - ascent;
  205570. }
  205571. float getStringWidth (const String& text)
  205572. {
  205573. if (fontRef == 0 || text.isEmpty())
  205574. return 0;
  205575. const int length = text.length();
  205576. HeapBlock <CGGlyph> glyphs;
  205577. createGlyphsForString (text, length, glyphs);
  205578. float x = 0;
  205579. #if SUPPORT_ONLY_10_4_FONTS
  205580. HeapBlock <NSSize> advances (length);
  205581. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205582. for (int i = 0; i < length; ++i)
  205583. x += advances[i].width;
  205584. #else
  205585. #if SUPPORT_10_4_FONTS
  205586. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205587. {
  205588. HeapBlock <NSSize> advances (length);
  205589. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  205590. for (int i = 0; i < length; ++i)
  205591. x += advances[i].width;
  205592. }
  205593. else
  205594. #endif
  205595. {
  205596. HeapBlock <int> advances (length);
  205597. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205598. for (int i = 0; i < length; ++i)
  205599. x += advances[i];
  205600. }
  205601. #endif
  205602. return x * unitsToHeightScaleFactor;
  205603. }
  205604. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205605. {
  205606. xOffsets.add (0);
  205607. if (fontRef == 0 || text.isEmpty())
  205608. return;
  205609. const int length = text.length();
  205610. HeapBlock <CGGlyph> glyphs;
  205611. createGlyphsForString (text, length, glyphs);
  205612. #if SUPPORT_ONLY_10_4_FONTS
  205613. HeapBlock <NSSize> advances (length);
  205614. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205615. int x = 0;
  205616. for (int i = 0; i < length; ++i)
  205617. {
  205618. x += advances[i].width;
  205619. xOffsets.add (x * unitsToHeightScaleFactor);
  205620. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  205621. }
  205622. #else
  205623. #if SUPPORT_10_4_FONTS
  205624. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205625. {
  205626. HeapBlock <NSSize> advances (length);
  205627. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205628. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  205629. float x = 0;
  205630. for (int i = 0; i < length; ++i)
  205631. {
  205632. x += advances[i].width;
  205633. xOffsets.add (x * unitsToHeightScaleFactor);
  205634. resultGlyphs.add (nsGlyphs[i]);
  205635. }
  205636. }
  205637. else
  205638. #endif
  205639. {
  205640. HeapBlock <int> advances (length);
  205641. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205642. {
  205643. int x = 0;
  205644. for (int i = 0; i < length; ++i)
  205645. {
  205646. x += advances [i];
  205647. xOffsets.add (x * unitsToHeightScaleFactor);
  205648. resultGlyphs.add (glyphs[i]);
  205649. }
  205650. }
  205651. }
  205652. #endif
  205653. }
  205654. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205655. {
  205656. #if JUCE_IPHONE
  205657. return false;
  205658. #else
  205659. if (nsFont == 0)
  205660. return false;
  205661. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205662. jassert (path.isEmpty());
  205663. const ScopedAutoReleasePool pool;
  205664. NSBezierPath* bez = [NSBezierPath bezierPath];
  205665. [bez moveToPoint: NSMakePoint (0, 0)];
  205666. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205667. inFont: nsFont];
  205668. for (int i = 0; i < [bez elementCount]; ++i)
  205669. {
  205670. NSPoint p[3];
  205671. switch ([bez elementAtIndex: i associatedPoints: p])
  205672. {
  205673. case NSMoveToBezierPathElement:
  205674. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205675. break;
  205676. case NSLineToBezierPathElement:
  205677. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205678. break;
  205679. case NSCurveToBezierPathElement:
  205680. 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);
  205681. break;
  205682. case NSClosePathBezierPathElement:
  205683. path.closeSubPath();
  205684. break;
  205685. default:
  205686. jassertfalse
  205687. break;
  205688. }
  205689. }
  205690. path.applyTransform (pathTransform);
  205691. return true;
  205692. #endif
  205693. }
  205694. juce_UseDebuggingNewOperator
  205695. CGFontRef fontRef;
  205696. float fontHeightToCGSizeFactor;
  205697. CGAffineTransform renderingTransform;
  205698. private:
  205699. float ascent, unitsToHeightScaleFactor;
  205700. #if JUCE_IPHONE
  205701. #else
  205702. NSFont* nsFont;
  205703. AffineTransform pathTransform;
  205704. #endif
  205705. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205706. {
  205707. #if SUPPORT_10_4_FONTS
  205708. #if ! SUPPORT_ONLY_10_4_FONTS
  205709. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205710. #endif
  205711. {
  205712. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205713. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205714. for (int i = 0; i < length; ++i)
  205715. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205716. return;
  205717. }
  205718. #endif
  205719. #if ! SUPPORT_ONLY_10_4_FONTS
  205720. if (charToGlyphMapper == 0)
  205721. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205722. glyphs.malloc (length);
  205723. for (int i = 0; i < length; ++i)
  205724. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205725. #endif
  205726. }
  205727. #if ! SUPPORT_ONLY_10_4_FONTS
  205728. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205729. class CharToGlyphMapper
  205730. {
  205731. public:
  205732. CharToGlyphMapper (CGFontRef fontRef)
  205733. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205734. idRangeOffset (0), glyphIndexes (0)
  205735. {
  205736. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205737. if (cmapTable != 0)
  205738. {
  205739. const int numSubtables = getValue16 (cmapTable, 2);
  205740. for (int i = 0; i < numSubtables; ++i)
  205741. {
  205742. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205743. {
  205744. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205745. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205746. {
  205747. const int length = getValue16 (cmapTable, offset + 2);
  205748. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205749. segCount = segCountX2 / 2;
  205750. const int endCodeOffset = offset + 14;
  205751. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205752. const int idDeltaOffset = startCodeOffset + segCountX2;
  205753. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205754. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205755. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205756. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205757. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205758. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205759. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205760. }
  205761. break;
  205762. }
  205763. }
  205764. CFRelease (cmapTable);
  205765. }
  205766. }
  205767. ~CharToGlyphMapper()
  205768. {
  205769. if (endCode != 0)
  205770. {
  205771. CFRelease (endCode);
  205772. CFRelease (startCode);
  205773. CFRelease (idDelta);
  205774. CFRelease (idRangeOffset);
  205775. CFRelease (glyphIndexes);
  205776. }
  205777. }
  205778. int getGlyphForCharacter (const juce_wchar c) const
  205779. {
  205780. for (int i = 0; i < segCount; ++i)
  205781. {
  205782. if (getValue16 (endCode, i * 2) >= c)
  205783. {
  205784. const int start = getValue16 (startCode, i * 2);
  205785. if (start > c)
  205786. break;
  205787. const int delta = getValue16 (idDelta, i * 2);
  205788. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205789. if (rangeOffset == 0)
  205790. return delta + c;
  205791. else
  205792. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205793. }
  205794. }
  205795. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205796. return jmax (-1, c - 29);
  205797. }
  205798. private:
  205799. int segCount;
  205800. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205801. static uint16 getValue16 (CFDataRef data, const int index)
  205802. {
  205803. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205804. }
  205805. static uint32 getValue32 (CFDataRef data, const int index)
  205806. {
  205807. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205808. }
  205809. };
  205810. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205811. #endif
  205812. MacTypeface (const MacTypeface&);
  205813. MacTypeface& operator= (const MacTypeface&);
  205814. };
  205815. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205816. {
  205817. return new MacTypeface (font);
  205818. }
  205819. const StringArray Font::findAllTypefaceNames() throw()
  205820. {
  205821. StringArray names;
  205822. const ScopedAutoReleasePool pool;
  205823. #if JUCE_IPHONE
  205824. NSArray* fonts = [UIFont familyNames];
  205825. #else
  205826. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205827. #endif
  205828. for (unsigned int i = 0; i < [fonts count]; ++i)
  205829. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205830. names.sort (true);
  205831. return names;
  205832. }
  205833. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  205834. {
  205835. #if JUCE_IPHONE
  205836. defaultSans = "Helvetica";
  205837. defaultSerif = "Times New Roman";
  205838. defaultFixed = "Courier New";
  205839. #else
  205840. defaultSans = "Lucida Grande";
  205841. defaultSerif = "Times New Roman";
  205842. defaultFixed = "Monaco";
  205843. #endif
  205844. }
  205845. #endif
  205846. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205847. // (must go before juce_mac_CoreGraphicsContext.mm)
  205848. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205849. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205850. // compiled on its own).
  205851. #if JUCE_INCLUDED_FILE
  205852. class CoreGraphicsImage : public Image
  205853. {
  205854. public:
  205855. CoreGraphicsImage (const PixelFormat format_,
  205856. const int imageWidth_,
  205857. const int imageHeight_,
  205858. const bool clearImage)
  205859. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205860. {
  205861. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  205862. : CGColorSpaceCreateDeviceRGB();
  205863. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205864. colourSpace, getCGImageFlags (*this));
  205865. CGColorSpaceRelease (colourSpace);
  205866. }
  205867. ~CoreGraphicsImage()
  205868. {
  205869. CGContextRelease (context);
  205870. }
  205871. LowLevelGraphicsContext* createLowLevelContext();
  205872. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205873. {
  205874. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205875. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205876. {
  205877. return CGBitmapContextCreateImage (nativeImage->context);
  205878. }
  205879. else
  205880. {
  205881. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205882. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205883. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205884. 8, srcData.pixelStride * 8, srcData.lineStride,
  205885. colourSpace, getCGImageFlags (juceImage), provider,
  205886. 0, true, kCGRenderingIntentDefault);
  205887. CGDataProviderRelease (provider);
  205888. return imageRef;
  205889. }
  205890. }
  205891. #if JUCE_MAC
  205892. static NSImage* createNSImage (const Image& image)
  205893. {
  205894. const ScopedAutoReleasePool pool;
  205895. NSImage* im = [[NSImage alloc] init];
  205896. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205897. [im lockFocus];
  205898. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205899. CGImageRef imageRef = createImage (image, false, colourSpace);
  205900. CGColorSpaceRelease (colourSpace);
  205901. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205902. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205903. CGImageRelease (imageRef);
  205904. [im unlockFocus];
  205905. return im;
  205906. }
  205907. #endif
  205908. CGContextRef context;
  205909. private:
  205910. static CGBitmapInfo getCGImageFlags (const Image& image)
  205911. {
  205912. #if JUCE_BIG_ENDIAN
  205913. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  205914. #else
  205915. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  205916. #endif
  205917. }
  205918. };
  205919. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  205920. {
  205921. #if USE_COREGRAPHICS_RENDERING
  205922. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  205923. #else
  205924. return new Image (format, imageWidth, imageHeight, clearImage);
  205925. #endif
  205926. }
  205927. class CoreGraphicsContext : public LowLevelGraphicsContext
  205928. {
  205929. public:
  205930. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  205931. : context (context_),
  205932. flipHeight (flipHeight_),
  205933. state (new SavedState()),
  205934. numGradientLookupEntries (0)
  205935. {
  205936. CGContextRetain (context);
  205937. CGContextSaveGState(context);
  205938. CGContextSetShouldSmoothFonts (context, true);
  205939. CGContextSetShouldAntialias (context, true);
  205940. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205941. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  205942. greyColourSpace = CGColorSpaceCreateDeviceGray();
  205943. gradientCallbacks.version = 0;
  205944. gradientCallbacks.evaluate = gradientCallback;
  205945. gradientCallbacks.releaseInfo = 0;
  205946. setFont (Font());
  205947. }
  205948. ~CoreGraphicsContext()
  205949. {
  205950. CGContextRestoreGState (context);
  205951. CGContextRelease (context);
  205952. CGColorSpaceRelease (rgbColourSpace);
  205953. CGColorSpaceRelease (greyColourSpace);
  205954. }
  205955. bool isVectorDevice() const { return false; }
  205956. void setOrigin (int x, int y)
  205957. {
  205958. CGContextTranslateCTM (context, x, -y);
  205959. }
  205960. bool clipToRectangle (const Rectangle<int>& r)
  205961. {
  205962. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  205963. return ! isClipEmpty();
  205964. }
  205965. bool clipToRectangleList (const RectangleList& clipRegion)
  205966. {
  205967. if (clipRegion.isEmpty())
  205968. {
  205969. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  205970. return false;
  205971. }
  205972. else
  205973. {
  205974. const int numRects = clipRegion.getNumRectangles();
  205975. HeapBlock <CGRect> rects (numRects);
  205976. for (int i = 0; i < numRects; ++i)
  205977. {
  205978. const Rectangle<int>& r = clipRegion.getRectangle(i);
  205979. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205980. }
  205981. CGContextClipToRects (context, rects, numRects);
  205982. return ! isClipEmpty();
  205983. }
  205984. }
  205985. void excludeClipRectangle (const Rectangle<int>& r)
  205986. {
  205987. RectangleList remaining (getClipBounds());
  205988. remaining.subtract (r);
  205989. clipToRectangleList (remaining);
  205990. }
  205991. void clipToPath (const Path& path, const AffineTransform& transform)
  205992. {
  205993. createPath (path, transform);
  205994. CGContextClip (context);
  205995. }
  205996. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  205997. {
  205998. if (! transform.isSingularity())
  205999. {
  206000. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  206001. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  206002. flip();
  206003. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  206004. applyTransform (t);
  206005. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  206006. CGContextClipToMask (context, r, image);
  206007. applyTransform (t.inverted());
  206008. flip();
  206009. CGImageRelease (image);
  206010. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  206011. }
  206012. }
  206013. bool clipRegionIntersects (const Rectangle<int>& r)
  206014. {
  206015. return getClipBounds().intersects (r);
  206016. }
  206017. const Rectangle<int> getClipBounds() const
  206018. {
  206019. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206020. return Rectangle<int> (roundToInt (bounds.origin.x),
  206021. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  206022. roundToInt (bounds.size.width),
  206023. roundToInt (bounds.size.height));
  206024. }
  206025. bool isClipEmpty() const
  206026. {
  206027. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  206028. }
  206029. void saveState()
  206030. {
  206031. CGContextSaveGState (context);
  206032. stateStack.add (new SavedState (*state));
  206033. }
  206034. void restoreState()
  206035. {
  206036. CGContextRestoreGState (context);
  206037. SavedState* const top = stateStack.getLast();
  206038. if (top != 0)
  206039. {
  206040. state = top;
  206041. stateStack.removeLast (1, false);
  206042. }
  206043. else
  206044. {
  206045. jassertfalse // trying to pop with an empty stack!
  206046. }
  206047. }
  206048. void setFill (const FillType& fillType)
  206049. {
  206050. state->fillType = fillType;
  206051. if (fillType.isColour())
  206052. {
  206053. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  206054. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  206055. CGContextSetAlpha (context, 1.0f);
  206056. }
  206057. }
  206058. void setOpacity (float newOpacity)
  206059. {
  206060. state->fillType.setOpacity (newOpacity);
  206061. setFill (state->fillType);
  206062. }
  206063. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  206064. {
  206065. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  206066. ? kCGInterpolationLow
  206067. : kCGInterpolationHigh);
  206068. }
  206069. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  206070. {
  206071. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206072. if (replaceExistingContents)
  206073. {
  206074. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206075. CGContextClearRect (context, cgRect);
  206076. #else
  206077. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206078. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206079. CGContextClearRect (context, cgRect);
  206080. else
  206081. #endif
  206082. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206083. #endif
  206084. fillRect (r, false);
  206085. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206086. }
  206087. else
  206088. {
  206089. if (state->fillType.isColour())
  206090. {
  206091. CGContextFillRect (context, cgRect);
  206092. }
  206093. else if (state->fillType.isGradient())
  206094. {
  206095. CGContextSaveGState (context);
  206096. CGContextClipToRect (context, cgRect);
  206097. drawGradient();
  206098. CGContextRestoreGState (context);
  206099. }
  206100. else
  206101. {
  206102. CGContextSaveGState (context);
  206103. CGContextClipToRect (context, cgRect);
  206104. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206105. CGContextRestoreGState (context);
  206106. }
  206107. }
  206108. }
  206109. void fillPath (const Path& path, const AffineTransform& transform)
  206110. {
  206111. CGContextSaveGState (context);
  206112. if (state->fillType.isColour())
  206113. {
  206114. flip();
  206115. applyTransform (transform);
  206116. createPath (path);
  206117. if (path.isUsingNonZeroWinding())
  206118. CGContextFillPath (context);
  206119. else
  206120. CGContextEOFillPath (context);
  206121. }
  206122. else
  206123. {
  206124. createPath (path, transform);
  206125. if (path.isUsingNonZeroWinding())
  206126. CGContextClip (context);
  206127. else
  206128. CGContextEOClip (context);
  206129. if (state->fillType.isGradient())
  206130. drawGradient();
  206131. else
  206132. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206133. }
  206134. CGContextRestoreGState (context);
  206135. }
  206136. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206137. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206138. {
  206139. jassert (sourceImage.getBounds().contains (srcClip));
  206140. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206141. CGImageRef image = fullImage;
  206142. if (srcClip != sourceImage.getBounds())
  206143. {
  206144. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206145. srcClip.getWidth(), srcClip.getHeight()));
  206146. CGImageRelease (fullImage);
  206147. }
  206148. CGContextSaveGState (context);
  206149. CGContextSetAlpha (context, state->fillType.getOpacity());
  206150. flip();
  206151. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206152. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206153. if (fillEntireClipAsTiles)
  206154. {
  206155. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  206156. CGContextDrawTiledImage (context, imageRect, image);
  206157. #else
  206158. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206159. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206160. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206161. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206162. CGContextDrawTiledImage (context, imageRect, image);
  206163. else
  206164. #endif
  206165. {
  206166. // Fallback to manually doing a tiled fill on 10.4
  206167. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206168. const int iw = srcClip.getWidth();
  206169. const int ih = srcClip.getHeight();
  206170. int x = 0, y = 0;
  206171. while (x > clip.origin.x) x -= iw;
  206172. while (y > clip.origin.y) y -= ih;
  206173. const int right = (int) (clip.origin.x + clip.size.width);
  206174. const int bottom = (int) (clip.origin.y + clip.size.height);
  206175. while (y < bottom)
  206176. {
  206177. for (int x2 = x; x2 < right; x2 += iw)
  206178. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206179. y += ih;
  206180. }
  206181. }
  206182. #endif
  206183. }
  206184. else
  206185. {
  206186. CGContextDrawImage (context, imageRect, image);
  206187. }
  206188. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206189. CGContextRestoreGState (context);
  206190. }
  206191. void drawLine (double x1, double y1, double x2, double y2)
  206192. {
  206193. CGContextSetLineCap (context, kCGLineCapSquare);
  206194. CGContextSetLineWidth (context, 1.0f);
  206195. CGContextSetRGBStrokeColor (context,
  206196. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206197. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206198. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  206199. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  206200. CGContextStrokeLineSegments (context, line, 1);
  206201. }
  206202. void drawVerticalLine (const int x, double top, double bottom)
  206203. {
  206204. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206205. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206206. #else
  206207. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206208. // the x co-ord slightly to trick it..
  206209. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206210. #endif
  206211. }
  206212. void drawHorizontalLine (const int y, double left, double right)
  206213. {
  206214. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206215. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206216. #else
  206217. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206218. // the x co-ord slightly to trick it..
  206219. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206220. #endif
  206221. }
  206222. void setFont (const Font& newFont)
  206223. {
  206224. if (state->font != newFont)
  206225. {
  206226. state->fontRef = 0;
  206227. state->font = newFont;
  206228. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206229. if (mf != 0)
  206230. {
  206231. state->fontRef = mf->fontRef;
  206232. CGContextSetFont (context, state->fontRef);
  206233. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206234. state->fontTransform = mf->renderingTransform;
  206235. state->fontTransform.a *= state->font.getHorizontalScale();
  206236. CGContextSetTextMatrix (context, state->fontTransform);
  206237. }
  206238. }
  206239. }
  206240. const Font getFont()
  206241. {
  206242. return state->font;
  206243. }
  206244. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206245. {
  206246. if (state->fontRef != 0 && state->fillType.isColour())
  206247. {
  206248. if (transform.isOnlyTranslation())
  206249. {
  206250. CGGlyph g = glyphNumber;
  206251. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206252. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206253. }
  206254. else
  206255. {
  206256. CGContextSaveGState (context);
  206257. flip();
  206258. applyTransform (transform);
  206259. CGAffineTransform t = state->fontTransform;
  206260. t.d = -t.d;
  206261. CGContextSetTextMatrix (context, t);
  206262. CGGlyph g = glyphNumber;
  206263. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206264. CGContextSetTextMatrix (context, state->fontTransform);
  206265. CGContextRestoreGState (context);
  206266. }
  206267. }
  206268. else
  206269. {
  206270. Path p;
  206271. Font& f = state->font;
  206272. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206273. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206274. .followedBy (transform));
  206275. }
  206276. }
  206277. private:
  206278. CGContextRef context;
  206279. const CGFloat flipHeight;
  206280. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206281. CGFunctionCallbacks gradientCallbacks;
  206282. struct SavedState
  206283. {
  206284. SavedState()
  206285. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206286. {
  206287. }
  206288. SavedState (const SavedState& other)
  206289. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206290. fontTransform (other.fontTransform)
  206291. {
  206292. }
  206293. ~SavedState()
  206294. {
  206295. }
  206296. FillType fillType;
  206297. Font font;
  206298. CGFontRef fontRef;
  206299. CGAffineTransform fontTransform;
  206300. };
  206301. ScopedPointer <SavedState> state;
  206302. OwnedArray <SavedState> stateStack;
  206303. HeapBlock <PixelARGB> gradientLookupTable;
  206304. int numGradientLookupEntries;
  206305. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206306. {
  206307. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206308. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206309. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206310. colour.unpremultiply();
  206311. outData[0] = colour.getRed() / 255.0f;
  206312. outData[1] = colour.getGreen() / 255.0f;
  206313. outData[2] = colour.getBlue() / 255.0f;
  206314. outData[3] = colour.getAlpha() / 255.0f;
  206315. }
  206316. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206317. {
  206318. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206319. --numGradientLookupEntries;
  206320. CGShadingRef result = 0;
  206321. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206322. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206323. if (gradient.isRadial)
  206324. {
  206325. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206326. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206327. function, true, true);
  206328. }
  206329. else
  206330. {
  206331. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206332. CGPointMake (gradient.x2, gradient.y2),
  206333. function, true, true);
  206334. }
  206335. CGFunctionRelease (function);
  206336. return result;
  206337. }
  206338. void drawGradient()
  206339. {
  206340. flip();
  206341. applyTransform (state->fillType.transform);
  206342. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206343. // you draw a gradient with high quality interp enabled).
  206344. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206345. CGContextSetAlpha (context, state->fillType.getOpacity());
  206346. CGContextDrawShading (context, shading);
  206347. CGShadingRelease (shading);
  206348. }
  206349. void createPath (const Path& path) const
  206350. {
  206351. CGContextBeginPath (context);
  206352. Path::Iterator i (path);
  206353. while (i.next())
  206354. {
  206355. switch (i.elementType)
  206356. {
  206357. case Path::Iterator::startNewSubPath:
  206358. CGContextMoveToPoint (context, i.x1, i.y1);
  206359. break;
  206360. case Path::Iterator::lineTo:
  206361. CGContextAddLineToPoint (context, i.x1, i.y1);
  206362. break;
  206363. case Path::Iterator::quadraticTo:
  206364. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206365. break;
  206366. case Path::Iterator::cubicTo:
  206367. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206368. break;
  206369. case Path::Iterator::closePath:
  206370. CGContextClosePath (context); break;
  206371. default:
  206372. jassertfalse
  206373. break;
  206374. }
  206375. }
  206376. }
  206377. void createPath (const Path& path, const AffineTransform& transform) const
  206378. {
  206379. CGContextBeginPath (context);
  206380. Path::Iterator i (path);
  206381. while (i.next())
  206382. {
  206383. switch (i.elementType)
  206384. {
  206385. case Path::Iterator::startNewSubPath:
  206386. transform.transformPoint (i.x1, i.y1);
  206387. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206388. break;
  206389. case Path::Iterator::lineTo:
  206390. transform.transformPoint (i.x1, i.y1);
  206391. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206392. break;
  206393. case Path::Iterator::quadraticTo:
  206394. transform.transformPoint (i.x1, i.y1);
  206395. transform.transformPoint (i.x2, i.y2);
  206396. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206397. break;
  206398. case Path::Iterator::cubicTo:
  206399. transform.transformPoint (i.x1, i.y1);
  206400. transform.transformPoint (i.x2, i.y2);
  206401. transform.transformPoint (i.x3, i.y3);
  206402. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206403. break;
  206404. case Path::Iterator::closePath:
  206405. CGContextClosePath (context); break;
  206406. default:
  206407. jassertfalse
  206408. break;
  206409. }
  206410. }
  206411. }
  206412. static Image* createAlphaChannelImage (const Image& im)
  206413. {
  206414. if (im.getFormat() == Image::SingleChannel)
  206415. return const_cast <Image*> (&im);
  206416. return im.createCopyOfAlphaChannel();
  206417. }
  206418. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206419. {
  206420. if (im.getFormat() != Image::SingleChannel)
  206421. delete alphaIm;
  206422. }
  206423. void flip() const
  206424. {
  206425. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206426. }
  206427. void applyTransform (const AffineTransform& transform) const
  206428. {
  206429. CGAffineTransform t;
  206430. t.a = transform.mat00;
  206431. t.b = transform.mat10;
  206432. t.c = transform.mat01;
  206433. t.d = transform.mat11;
  206434. t.tx = transform.mat02;
  206435. t.ty = transform.mat12;
  206436. CGContextConcatCTM (context, t);
  206437. }
  206438. CoreGraphicsContext (const CoreGraphicsContext&);
  206439. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  206440. };
  206441. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206442. {
  206443. return new CoreGraphicsContext (context, imageHeight);
  206444. }
  206445. #endif
  206446. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206447. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206448. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206449. // compiled on its own).
  206450. #if JUCE_INCLUDED_FILE
  206451. class NSViewComponentPeer;
  206452. END_JUCE_NAMESPACE
  206453. #define JuceNSView MakeObjCClassName(JuceNSView)
  206454. @interface JuceNSView : NSView<NSTextInput>
  206455. {
  206456. @public
  206457. NSViewComponentPeer* owner;
  206458. NSNotificationCenter* notificationCenter;
  206459. String* stringBeingComposed;
  206460. bool textWasInserted;
  206461. }
  206462. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206463. - (void) dealloc;
  206464. - (BOOL) isOpaque;
  206465. - (void) drawRect: (NSRect) r;
  206466. - (void) mouseDown: (NSEvent*) ev;
  206467. - (void) asyncMouseDown: (NSEvent*) ev;
  206468. - (void) mouseUp: (NSEvent*) ev;
  206469. - (void) asyncMouseUp: (NSEvent*) ev;
  206470. - (void) mouseDragged: (NSEvent*) ev;
  206471. - (void) mouseMoved: (NSEvent*) ev;
  206472. - (void) mouseEntered: (NSEvent*) ev;
  206473. - (void) mouseExited: (NSEvent*) ev;
  206474. - (void) rightMouseDown: (NSEvent*) ev;
  206475. - (void) rightMouseDragged: (NSEvent*) ev;
  206476. - (void) rightMouseUp: (NSEvent*) ev;
  206477. - (void) otherMouseDown: (NSEvent*) ev;
  206478. - (void) otherMouseDragged: (NSEvent*) ev;
  206479. - (void) otherMouseUp: (NSEvent*) ev;
  206480. - (void) scrollWheel: (NSEvent*) ev;
  206481. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206482. - (void) frameChanged: (NSNotification*) n;
  206483. - (void) viewDidMoveToWindow;
  206484. - (void) keyDown: (NSEvent*) ev;
  206485. - (void) keyUp: (NSEvent*) ev;
  206486. // NSTextInput Methods
  206487. - (void) insertText: (id) aString;
  206488. - (void) doCommandBySelector: (SEL) aSelector;
  206489. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange;
  206490. - (void) unmarkText;
  206491. - (BOOL) hasMarkedText;
  206492. - (long) conversationIdentifier;
  206493. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange;
  206494. - (NSRange) markedRange;
  206495. - (NSRange) selectedRange;
  206496. - (NSRect) firstRectForCharacterRange: (NSRange) theRange;
  206497. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint;
  206498. - (NSArray*) validAttributesForMarkedText;
  206499. - (void) flagsChanged: (NSEvent*) ev;
  206500. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206501. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206502. #endif
  206503. - (BOOL) becomeFirstResponder;
  206504. - (BOOL) resignFirstResponder;
  206505. - (BOOL) acceptsFirstResponder;
  206506. - (void) asyncRepaint: (id) rect;
  206507. - (NSArray*) getSupportedDragTypes;
  206508. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206509. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206510. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206511. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206512. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206513. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206514. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206515. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206516. @end
  206517. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206518. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206519. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206520. #else
  206521. @interface JuceNSWindow : NSWindow
  206522. #endif
  206523. {
  206524. @private
  206525. NSViewComponentPeer* owner;
  206526. bool isZooming;
  206527. }
  206528. - (void) setOwner: (NSViewComponentPeer*) owner;
  206529. - (BOOL) canBecomeKeyWindow;
  206530. - (void) becomeKeyWindow;
  206531. - (BOOL) windowShouldClose: (id) window;
  206532. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206533. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206534. - (void) zoom: (id) sender;
  206535. @end
  206536. BEGIN_JUCE_NAMESPACE
  206537. class NSViewComponentPeer : public ComponentPeer
  206538. {
  206539. public:
  206540. NSViewComponentPeer (Component* const component,
  206541. const int windowStyleFlags,
  206542. NSView* viewToAttachTo);
  206543. ~NSViewComponentPeer();
  206544. void* getNativeHandle() const;
  206545. void setVisible (bool shouldBeVisible);
  206546. void setTitle (const String& title);
  206547. void setPosition (int x, int y);
  206548. void setSize (int w, int h);
  206549. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206550. const Rectangle<int> getBounds (const bool global) const;
  206551. const Rectangle<int> getBounds() const;
  206552. const Point<int> getScreenPosition() const;
  206553. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  206554. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  206555. void setMinimised (bool shouldBeMinimised);
  206556. bool isMinimised() const;
  206557. void setFullScreen (bool shouldBeFullScreen);
  206558. bool isFullScreen() const;
  206559. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  206560. const BorderSize getFrameSize() const;
  206561. bool setAlwaysOnTop (bool alwaysOnTop);
  206562. void toFront (bool makeActiveWindow);
  206563. void toBehind (ComponentPeer* other);
  206564. void setIcon (const Image& newIcon);
  206565. const StringArray getAvailableRenderingEngines() throw();
  206566. int getCurrentRenderingEngine() throw();
  206567. void setCurrentRenderingEngine (int index) throw();
  206568. virtual void redirectMouseDown (NSEvent* ev);
  206569. virtual void redirectMouseUp (NSEvent* ev);
  206570. virtual void redirectMouseDrag (NSEvent* ev);
  206571. virtual void redirectMouseMove (NSEvent* ev);
  206572. virtual void redirectMouseEnter (NSEvent* ev);
  206573. virtual void redirectMouseExit (NSEvent* ev);
  206574. virtual void redirectMouseWheel (NSEvent* ev);
  206575. void sendMouseEvent (NSEvent* ev);
  206576. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206577. virtual bool redirectKeyDown (NSEvent* ev);
  206578. virtual bool redirectKeyUp (NSEvent* ev);
  206579. virtual void redirectModKeyChange (NSEvent* ev);
  206580. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206581. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206582. #endif
  206583. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206584. virtual bool isOpaque();
  206585. virtual void drawRect (NSRect r);
  206586. virtual bool canBecomeKeyWindow();
  206587. virtual bool windowShouldClose();
  206588. virtual void redirectMovedOrResized();
  206589. virtual void viewMovedToWindow();
  206590. virtual NSRect constrainRect (NSRect r);
  206591. static void showArrowCursorIfNeeded();
  206592. static void updateModifiers (NSEvent* e);
  206593. static void updateKeysDown (NSEvent* ev, bool isKeyDown);
  206594. static int getKeyCodeFromEvent (NSEvent* ev)
  206595. {
  206596. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206597. int keyCode = unmodified[0];
  206598. if (keyCode == 0x19) // (backwards-tab)
  206599. keyCode = '\t';
  206600. else if (keyCode == 0x03) // (enter)
  206601. keyCode = '\r';
  206602. return keyCode;
  206603. }
  206604. static int64 getMouseTime (NSEvent* e)
  206605. {
  206606. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  206607. + (int64) ([e timestamp] * 1000.0);
  206608. }
  206609. static const Point<int> getMousePos (NSEvent* e, NSView* view)
  206610. {
  206611. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  206612. return Point<int> (roundToInt (p.x), roundToInt ([view frame].size.height - p.y));
  206613. }
  206614. static int getModifierForButtonNumber (const NSInteger num)
  206615. {
  206616. return num == 0 ? ModifierKeys::leftButtonModifier
  206617. : (num == 1 ? ModifierKeys::rightButtonModifier
  206618. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  206619. }
  206620. virtual void viewFocusGain();
  206621. virtual void viewFocusLoss();
  206622. bool isFocused() const;
  206623. void grabFocus();
  206624. void textInputRequired (const Point<int>& position);
  206625. void repaint (int x, int y, int w, int h);
  206626. void performAnyPendingRepaintsNow();
  206627. juce_UseDebuggingNewOperator
  206628. NSWindow* window;
  206629. JuceNSView* view;
  206630. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206631. static ModifierKeys currentModifiers;
  206632. static ComponentPeer* currentlyFocusedPeer;
  206633. static VoidArray keysCurrentlyDown;
  206634. };
  206635. END_JUCE_NAMESPACE
  206636. @implementation JuceNSView
  206637. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206638. withFrame: (NSRect) frame
  206639. {
  206640. [super initWithFrame: frame];
  206641. owner = owner_;
  206642. stringBeingComposed = 0;
  206643. textWasInserted = false;
  206644. notificationCenter = [NSNotificationCenter defaultCenter];
  206645. [notificationCenter addObserver: self
  206646. selector: @selector (frameChanged:)
  206647. name: NSViewFrameDidChangeNotification
  206648. object: self];
  206649. if (! owner_->isSharedWindow)
  206650. {
  206651. [notificationCenter addObserver: self
  206652. selector: @selector (frameChanged:)
  206653. name: NSWindowDidMoveNotification
  206654. object: owner_->window];
  206655. }
  206656. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206657. return self;
  206658. }
  206659. - (void) dealloc
  206660. {
  206661. [notificationCenter removeObserver: self];
  206662. delete stringBeingComposed;
  206663. [super dealloc];
  206664. }
  206665. - (void) drawRect: (NSRect) r
  206666. {
  206667. if (owner != 0)
  206668. owner->drawRect (r);
  206669. }
  206670. - (BOOL) isOpaque
  206671. {
  206672. return owner == 0 || owner->isOpaque();
  206673. }
  206674. - (void) mouseDown: (NSEvent*) ev
  206675. {
  206676. // In some host situations, the host will stop modal loops from working
  206677. // correctly if they're called from a mouse event, so we'll trigger
  206678. // the event asynchronously..
  206679. if (JUCEApplication::getInstance() == 0)
  206680. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206681. withObject: ev
  206682. waitUntilDone: NO];
  206683. else
  206684. [self asyncMouseDown: ev];
  206685. }
  206686. - (void) asyncMouseDown: (NSEvent*) ev
  206687. {
  206688. if (owner != 0)
  206689. owner->redirectMouseDown (ev);
  206690. }
  206691. - (void) mouseUp: (NSEvent*) ev
  206692. {
  206693. // In some host situations, the host will stop modal loops from working
  206694. // correctly if they're called from a mouse event, so we'll trigger
  206695. // the event asynchronously..
  206696. if (JUCEApplication::getInstance() == 0)
  206697. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206698. withObject: ev
  206699. waitUntilDone: NO];
  206700. else
  206701. [self asyncMouseUp: ev];
  206702. }
  206703. - (void) asyncMouseUp: (NSEvent*) ev
  206704. {
  206705. if (owner != 0)
  206706. owner->redirectMouseUp (ev);
  206707. }
  206708. - (void) mouseDragged: (NSEvent*) ev
  206709. {
  206710. if (owner != 0)
  206711. owner->redirectMouseDrag (ev);
  206712. }
  206713. - (void) mouseMoved: (NSEvent*) ev
  206714. {
  206715. if (owner != 0)
  206716. owner->redirectMouseMove (ev);
  206717. }
  206718. - (void) mouseEntered: (NSEvent*) ev
  206719. {
  206720. if (owner != 0)
  206721. owner->redirectMouseEnter (ev);
  206722. }
  206723. - (void) mouseExited: (NSEvent*) ev
  206724. {
  206725. if (owner != 0)
  206726. owner->redirectMouseExit (ev);
  206727. }
  206728. - (void) rightMouseDown: (NSEvent*) ev
  206729. {
  206730. [self mouseDown: ev];
  206731. }
  206732. - (void) rightMouseDragged: (NSEvent*) ev
  206733. {
  206734. [self mouseDragged: ev];
  206735. }
  206736. - (void) rightMouseUp: (NSEvent*) ev
  206737. {
  206738. [self mouseUp: ev];
  206739. }
  206740. - (void) otherMouseDown: (NSEvent*) ev
  206741. {
  206742. [self mouseDown: ev];
  206743. }
  206744. - (void) otherMouseDragged: (NSEvent*) ev
  206745. {
  206746. [self mouseDragged: ev];
  206747. }
  206748. - (void) otherMouseUp: (NSEvent*) ev
  206749. {
  206750. [self mouseUp: ev];
  206751. }
  206752. - (void) scrollWheel: (NSEvent*) ev
  206753. {
  206754. if (owner != 0)
  206755. owner->redirectMouseWheel (ev);
  206756. }
  206757. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206758. {
  206759. return YES;
  206760. }
  206761. - (void) frameChanged: (NSNotification*) n
  206762. {
  206763. if (owner != 0)
  206764. owner->redirectMovedOrResized();
  206765. }
  206766. - (void) viewDidMoveToWindow
  206767. {
  206768. if (owner != 0)
  206769. owner->viewMovedToWindow();
  206770. }
  206771. - (void) asyncRepaint: (id) rect
  206772. {
  206773. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206774. [self setNeedsDisplayInRect: *r];
  206775. }
  206776. - (void) keyDown: (NSEvent*) ev
  206777. {
  206778. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206779. textWasInserted = false;
  206780. if (target != 0)
  206781. [self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  206782. else
  206783. deleteAndZero (stringBeingComposed);
  206784. if ((! textWasInserted) && (owner == 0 || ! owner->redirectKeyDown (ev)))
  206785. [super keyDown: ev];
  206786. }
  206787. - (void) keyUp: (NSEvent*) ev
  206788. {
  206789. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206790. [super keyUp: ev];
  206791. }
  206792. - (void) insertText: (id) aString
  206793. {
  206794. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  206795. if ([aString length] > 0)
  206796. {
  206797. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206798. if (target != 0)
  206799. {
  206800. target->insertTextAtCaret (nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString));
  206801. textWasInserted = true;
  206802. }
  206803. }
  206804. deleteAndZero (stringBeingComposed);
  206805. }
  206806. - (void) doCommandBySelector: (SEL) aSelector
  206807. {
  206808. }
  206809. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selectionRange
  206810. {
  206811. if (stringBeingComposed == 0)
  206812. stringBeingComposed = new String();
  206813. *stringBeingComposed = nsStringToJuce ([aString isKindOfClass:[NSAttributedString class]] ? [aString string] : aString);
  206814. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206815. if (target != 0)
  206816. {
  206817. const Range<int> currentHighlight (target->getHighlightedRegion());
  206818. target->insertTextAtCaret (*stringBeingComposed);
  206819. target->setHighlightedRegion (currentHighlight.withLength (stringBeingComposed->length()));
  206820. textWasInserted = true;
  206821. }
  206822. }
  206823. - (void) unmarkText
  206824. {
  206825. if (stringBeingComposed != 0)
  206826. {
  206827. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206828. if (target != 0)
  206829. {
  206830. target->insertTextAtCaret (*stringBeingComposed);
  206831. textWasInserted = true;
  206832. }
  206833. }
  206834. deleteAndZero (stringBeingComposed);
  206835. }
  206836. - (BOOL) hasMarkedText
  206837. {
  206838. return stringBeingComposed != 0;
  206839. }
  206840. - (long) conversationIdentifier
  206841. {
  206842. return (long) (pointer_sized_int) self;
  206843. }
  206844. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange
  206845. {
  206846. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206847. if (target != 0)
  206848. {
  206849. const Range<int> r ((int) theRange.location,
  206850. (int) (theRange.location + theRange.length));
  206851. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  206852. }
  206853. return nil;
  206854. }
  206855. - (NSRange) markedRange
  206856. {
  206857. return stringBeingComposed != 0 ? NSMakeRange (0, stringBeingComposed->length())
  206858. : NSMakeRange (NSNotFound, 0);
  206859. }
  206860. - (NSRange) selectedRange
  206861. {
  206862. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206863. if (target != 0)
  206864. {
  206865. const Range<int> highlight (target->getHighlightedRegion());
  206866. if (! highlight.isEmpty())
  206867. return NSMakeRange (highlight.getStart(), highlight.getLength());
  206868. }
  206869. return NSMakeRange (NSNotFound, 0);
  206870. }
  206871. - (NSRect) firstRectForCharacterRange: (NSRange) theRange
  206872. {
  206873. JUCE_NAMESPACE::Component* const comp = dynamic_cast <JUCE_NAMESPACE::Component*> (owner->findCurrentTextInputTarget());
  206874. if (comp == 0)
  206875. return NSMakeRect (0, 0, 0, 0);
  206876. const Rectangle<int> bounds (comp->getScreenBounds());
  206877. return NSMakeRect (bounds.getX(),
  206878. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  206879. bounds.getWidth(),
  206880. bounds.getHeight());
  206881. }
  206882. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint
  206883. {
  206884. return NSNotFound;
  206885. }
  206886. - (NSArray*) validAttributesForMarkedText
  206887. {
  206888. return [NSArray array];
  206889. }
  206890. - (void) flagsChanged: (NSEvent*) ev
  206891. {
  206892. if (owner != 0)
  206893. owner->redirectModKeyChange (ev);
  206894. }
  206895. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206896. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206897. {
  206898. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206899. return true;
  206900. return [super performKeyEquivalent: ev];
  206901. }
  206902. #endif
  206903. - (BOOL) becomeFirstResponder
  206904. {
  206905. if (owner != 0)
  206906. owner->viewFocusGain();
  206907. return true;
  206908. }
  206909. - (BOOL) resignFirstResponder
  206910. {
  206911. if (owner != 0)
  206912. owner->viewFocusLoss();
  206913. return true;
  206914. }
  206915. - (BOOL) acceptsFirstResponder
  206916. {
  206917. return owner != 0 && owner->canBecomeKeyWindow();
  206918. }
  206919. - (NSArray*) getSupportedDragTypes
  206920. {
  206921. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206922. }
  206923. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206924. {
  206925. return owner != 0 && owner->sendDragCallback (type, sender);
  206926. }
  206927. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206928. {
  206929. if ([self sendDragCallback: 0 sender: sender])
  206930. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206931. else
  206932. return NSDragOperationNone;
  206933. }
  206934. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206935. {
  206936. if ([self sendDragCallback: 0 sender: sender])
  206937. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206938. else
  206939. return NSDragOperationNone;
  206940. }
  206941. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206942. {
  206943. [self sendDragCallback: 1 sender: sender];
  206944. }
  206945. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206946. {
  206947. [self sendDragCallback: 1 sender: sender];
  206948. }
  206949. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206950. {
  206951. return YES;
  206952. }
  206953. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206954. {
  206955. return [self sendDragCallback: 2 sender: sender];
  206956. }
  206957. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206958. {
  206959. }
  206960. @end
  206961. @implementation JuceNSWindow
  206962. - (void) setOwner: (NSViewComponentPeer*) owner_
  206963. {
  206964. owner = owner_;
  206965. isZooming = false;
  206966. }
  206967. - (BOOL) canBecomeKeyWindow
  206968. {
  206969. return owner != 0 && owner->canBecomeKeyWindow();
  206970. }
  206971. - (void) becomeKeyWindow
  206972. {
  206973. [super becomeKeyWindow];
  206974. if (owner != 0)
  206975. owner->grabFocus();
  206976. }
  206977. - (BOOL) windowShouldClose: (id) window
  206978. {
  206979. return owner == 0 || owner->windowShouldClose();
  206980. }
  206981. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206982. {
  206983. if (owner != 0)
  206984. frameRect = owner->constrainRect (frameRect);
  206985. return frameRect;
  206986. }
  206987. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206988. {
  206989. if (isZooming)
  206990. return proposedFrameSize;
  206991. NSRect frameRect = [self frame];
  206992. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206993. frameRect.size = proposedFrameSize;
  206994. if (owner != 0)
  206995. frameRect = owner->constrainRect (frameRect);
  206996. return frameRect.size;
  206997. }
  206998. - (void) zoom: (id) sender
  206999. {
  207000. isZooming = true;
  207001. [super zoom: sender];
  207002. isZooming = false;
  207003. }
  207004. - (void) windowWillMove: (NSNotification*) notification
  207005. {
  207006. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  207007. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  207008. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  207009. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  207010. }
  207011. @end
  207012. BEGIN_JUCE_NAMESPACE
  207013. ModifierKeys NSViewComponentPeer::currentModifiers;
  207014. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = 0;
  207015. VoidArray NSViewComponentPeer::keysCurrentlyDown;
  207016. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  207017. {
  207018. if (NSViewComponentPeer::keysCurrentlyDown.contains ((void*) keyCode))
  207019. return true;
  207020. if (keyCode >= 'A' && keyCode <= 'Z'
  207021. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  207022. return true;
  207023. if (keyCode >= 'a' && keyCode <= 'z'
  207024. && NSViewComponentPeer::keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  207025. return true;
  207026. return false;
  207027. }
  207028. void NSViewComponentPeer::updateModifiers (NSEvent* e)
  207029. {
  207030. int m = 0;
  207031. if (([e modifierFlags] & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  207032. if (([e modifierFlags] & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  207033. if (([e modifierFlags] & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  207034. if (([e modifierFlags] & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  207035. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  207036. }
  207037. void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
  207038. {
  207039. updateModifiers (ev);
  207040. int keyCode = getKeyCodeFromEvent (ev);
  207041. if (keyCode != 0)
  207042. {
  207043. if (isKeyDown)
  207044. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  207045. else
  207046. keysCurrentlyDown.removeValue ((void*) keyCode);
  207047. }
  207048. }
  207049. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  207050. {
  207051. return NSViewComponentPeer::currentModifiers;
  207052. }
  207053. void ModifierKeys::updateCurrentModifiers() throw()
  207054. {
  207055. currentModifiers = NSViewComponentPeer::currentModifiers;
  207056. }
  207057. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  207058. const int windowStyleFlags,
  207059. NSView* viewToAttachTo)
  207060. : ComponentPeer (component_, windowStyleFlags),
  207061. window (0),
  207062. view (0),
  207063. isSharedWindow (viewToAttachTo != 0),
  207064. fullScreen (false),
  207065. insideDrawRect (false),
  207066. #if USE_COREGRAPHICS_RENDERING
  207067. usingCoreGraphics (true),
  207068. #else
  207069. usingCoreGraphics (false),
  207070. #endif
  207071. recursiveToFrontCall (false)
  207072. {
  207073. NSRect r;
  207074. r.origin.x = 0;
  207075. r.origin.y = 0;
  207076. r.size.width = (float) component->getWidth();
  207077. r.size.height = (float) component->getHeight();
  207078. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207079. [view setPostsFrameChangedNotifications: YES];
  207080. if (isSharedWindow)
  207081. {
  207082. window = [viewToAttachTo window];
  207083. [viewToAttachTo addSubview: view];
  207084. setVisible (component->isVisible());
  207085. }
  207086. else
  207087. {
  207088. r.origin.x = (float) component->getX();
  207089. r.origin.y = (float) component->getY();
  207090. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207091. unsigned int style = 0;
  207092. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207093. style = NSBorderlessWindowMask;
  207094. else
  207095. style = NSTitledWindowMask;
  207096. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207097. style |= NSMiniaturizableWindowMask;
  207098. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207099. style |= NSClosableWindowMask;
  207100. if ((windowStyleFlags & windowIsResizable) != 0)
  207101. style |= NSResizableWindowMask;
  207102. window = [[JuceNSWindow alloc] initWithContentRect: r
  207103. styleMask: style
  207104. backing: NSBackingStoreBuffered
  207105. defer: YES];
  207106. [((JuceNSWindow*) window) setOwner: this];
  207107. [window orderOut: nil];
  207108. [window setDelegate: (JuceNSWindow*) window];
  207109. [window setOpaque: component->isOpaque()];
  207110. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207111. if (component->isAlwaysOnTop())
  207112. [window setLevel: NSFloatingWindowLevel];
  207113. [window setContentView: view];
  207114. [window setAutodisplay: YES];
  207115. [window setAcceptsMouseMovedEvents: YES];
  207116. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207117. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207118. [window setReleasedWhenClosed: YES];
  207119. [window retain];
  207120. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207121. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207122. }
  207123. setTitle (component->getName());
  207124. }
  207125. NSViewComponentPeer::~NSViewComponentPeer()
  207126. {
  207127. view->owner = 0;
  207128. [view removeFromSuperview];
  207129. [view release];
  207130. if (! isSharedWindow)
  207131. {
  207132. [((JuceNSWindow*) window) setOwner: 0];
  207133. [window close];
  207134. [window release];
  207135. }
  207136. }
  207137. void* NSViewComponentPeer::getNativeHandle() const
  207138. {
  207139. return view;
  207140. }
  207141. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207142. {
  207143. if (isSharedWindow)
  207144. {
  207145. [view setHidden: ! shouldBeVisible];
  207146. }
  207147. else
  207148. {
  207149. if (shouldBeVisible)
  207150. {
  207151. [window orderFront: nil];
  207152. handleBroughtToFront();
  207153. }
  207154. else
  207155. {
  207156. [window orderOut: nil];
  207157. }
  207158. }
  207159. }
  207160. void NSViewComponentPeer::setTitle (const String& title)
  207161. {
  207162. const ScopedAutoReleasePool pool;
  207163. if (! isSharedWindow)
  207164. [window setTitle: juceStringToNS (title)];
  207165. }
  207166. void NSViewComponentPeer::setPosition (int x, int y)
  207167. {
  207168. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207169. }
  207170. void NSViewComponentPeer::setSize (int w, int h)
  207171. {
  207172. setBounds (component->getX(), component->getY(), w, h, false);
  207173. }
  207174. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  207175. {
  207176. fullScreen = isNowFullScreen;
  207177. w = jmax (0, w);
  207178. h = jmax (0, h);
  207179. NSRect r;
  207180. r.origin.x = (float) x;
  207181. r.origin.y = (float) y;
  207182. r.size.width = (float) w;
  207183. r.size.height = (float) h;
  207184. if (isSharedWindow)
  207185. {
  207186. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207187. if ([view frame].size.width != r.size.width
  207188. || [view frame].size.height != r.size.height)
  207189. [view setNeedsDisplay: true];
  207190. [view setFrame: r];
  207191. }
  207192. else
  207193. {
  207194. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207195. [window setFrame: [window frameRectForContentRect: r]
  207196. display: true];
  207197. }
  207198. }
  207199. const Rectangle<int> NSViewComponentPeer::getBounds (const bool global) const
  207200. {
  207201. NSRect r = [view frame];
  207202. if (global && [view window] != 0)
  207203. {
  207204. r = [view convertRect: r toView: nil];
  207205. NSRect wr = [[view window] frame];
  207206. r.origin.x += wr.origin.x;
  207207. r.origin.y += wr.origin.y;
  207208. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207209. }
  207210. else
  207211. {
  207212. r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
  207213. }
  207214. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y, (int) r.size.width, (int) r.size.height);
  207215. }
  207216. const Rectangle<int> NSViewComponentPeer::getBounds() const
  207217. {
  207218. return getBounds (! isSharedWindow);
  207219. }
  207220. const Point<int> NSViewComponentPeer::getScreenPosition() const
  207221. {
  207222. return getBounds (true).getPosition();
  207223. }
  207224. const Point<int> NSViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  207225. {
  207226. return relativePosition + getScreenPosition();
  207227. }
  207228. const Point<int> NSViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  207229. {
  207230. return screenPosition - getScreenPosition();
  207231. }
  207232. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207233. {
  207234. if (constrainer != 0)
  207235. {
  207236. NSRect current = [window frame];
  207237. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207238. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207239. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207240. (int) r.size.width, (int) r.size.height);
  207241. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207242. (int) current.size.width, (int) current.size.height);
  207243. constrainer->checkBounds (pos, original,
  207244. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207245. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207246. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207247. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207248. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207249. r.origin.x = pos.getX();
  207250. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207251. r.size.width = pos.getWidth();
  207252. r.size.height = pos.getHeight();
  207253. }
  207254. return r;
  207255. }
  207256. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207257. {
  207258. if (! isSharedWindow)
  207259. {
  207260. if (shouldBeMinimised)
  207261. [window miniaturize: nil];
  207262. else
  207263. [window deminiaturize: nil];
  207264. }
  207265. }
  207266. bool NSViewComponentPeer::isMinimised() const
  207267. {
  207268. return window != 0 && [window isMiniaturized];
  207269. }
  207270. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207271. {
  207272. if (! isSharedWindow)
  207273. {
  207274. Rectangle<int> r (lastNonFullscreenBounds);
  207275. setMinimised (false);
  207276. if (fullScreen != shouldBeFullScreen)
  207277. {
  207278. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207279. {
  207280. fullScreen = true;
  207281. [window performZoom: nil];
  207282. }
  207283. else
  207284. {
  207285. if (shouldBeFullScreen)
  207286. r = Desktop::getInstance().getMainMonitorArea();
  207287. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207288. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207289. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207290. }
  207291. }
  207292. }
  207293. }
  207294. bool NSViewComponentPeer::isFullScreen() const
  207295. {
  207296. return fullScreen;
  207297. }
  207298. bool NSViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  207299. {
  207300. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  207301. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  207302. return false;
  207303. NSPoint p;
  207304. p.x = (float) position.getX();
  207305. p.y = (float) position.getY();
  207306. NSView* v = [view hitTest: p];
  207307. if (trueIfInAChildWindow)
  207308. return v != nil;
  207309. return v == view;
  207310. }
  207311. const BorderSize NSViewComponentPeer::getFrameSize() const
  207312. {
  207313. BorderSize b;
  207314. if (! isSharedWindow)
  207315. {
  207316. NSRect v = [view convertRect: [view frame] toView: nil];
  207317. NSRect w = [window frame];
  207318. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207319. b.setBottom ((int) v.origin.y);
  207320. b.setLeft ((int) v.origin.x);
  207321. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207322. }
  207323. return b;
  207324. }
  207325. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207326. {
  207327. if (! isSharedWindow)
  207328. {
  207329. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207330. : NSNormalWindowLevel];
  207331. }
  207332. return true;
  207333. }
  207334. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207335. {
  207336. if (isSharedWindow)
  207337. {
  207338. [[view superview] addSubview: view
  207339. positioned: NSWindowAbove
  207340. relativeTo: nil];
  207341. }
  207342. if (window != 0 && component->isVisible())
  207343. {
  207344. if (makeActiveWindow)
  207345. [window makeKeyAndOrderFront: nil];
  207346. else
  207347. [window orderFront: nil];
  207348. if (! recursiveToFrontCall)
  207349. {
  207350. recursiveToFrontCall = true;
  207351. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207352. handleBroughtToFront();
  207353. recursiveToFrontCall = false;
  207354. }
  207355. }
  207356. }
  207357. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207358. {
  207359. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207360. if (isSharedWindow)
  207361. {
  207362. [[view superview] addSubview: view
  207363. positioned: NSWindowBelow
  207364. relativeTo: o->view];
  207365. }
  207366. else
  207367. {
  207368. [window orderWindow: NSWindowBelow
  207369. relativeTo: o->window != 0 ? [o->window windowNumber]
  207370. : nil ];
  207371. }
  207372. }
  207373. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207374. {
  207375. // to do..
  207376. }
  207377. void NSViewComponentPeer::viewFocusGain()
  207378. {
  207379. if (currentlyFocusedPeer != this)
  207380. {
  207381. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207382. currentlyFocusedPeer->handleFocusLoss();
  207383. currentlyFocusedPeer = this;
  207384. handleFocusGain();
  207385. }
  207386. }
  207387. void NSViewComponentPeer::viewFocusLoss()
  207388. {
  207389. if (currentlyFocusedPeer == this)
  207390. {
  207391. currentlyFocusedPeer = 0;
  207392. handleFocusLoss();
  207393. }
  207394. }
  207395. void juce_HandleProcessFocusChange()
  207396. {
  207397. NSViewComponentPeer::keysCurrentlyDown.clear();
  207398. if (NSViewComponentPeer::isValidPeer (NSViewComponentPeer::currentlyFocusedPeer))
  207399. {
  207400. if (Process::isForegroundProcess())
  207401. {
  207402. NSViewComponentPeer::currentlyFocusedPeer->handleFocusGain();
  207403. ComponentPeer::bringModalComponentToFront();
  207404. }
  207405. else
  207406. {
  207407. NSViewComponentPeer::currentlyFocusedPeer->handleFocusLoss();
  207408. // turn kiosk mode off if we lose focus..
  207409. Desktop::getInstance().setKioskModeComponent (0);
  207410. }
  207411. }
  207412. }
  207413. bool NSViewComponentPeer::isFocused() const
  207414. {
  207415. return isSharedWindow ? this == currentlyFocusedPeer
  207416. : (window != 0 && [window isKeyWindow]);
  207417. }
  207418. void NSViewComponentPeer::grabFocus()
  207419. {
  207420. if (window != 0)
  207421. {
  207422. [window makeKeyWindow];
  207423. [window makeFirstResponder: view];
  207424. viewFocusGain();
  207425. }
  207426. }
  207427. void NSViewComponentPeer::textInputRequired (const Point<int>&)
  207428. {
  207429. }
  207430. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207431. {
  207432. String unicode (nsStringToJuce ([ev characters]));
  207433. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207434. int keyCode = getKeyCodeFromEvent (ev);
  207435. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207436. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207437. if (unicode.isNotEmpty() || keyCode != 0)
  207438. {
  207439. if (isKeyDown)
  207440. {
  207441. bool used = false;
  207442. while (unicode.length() > 0)
  207443. {
  207444. juce_wchar textCharacter = unicode[0];
  207445. unicode = unicode.substring (1);
  207446. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207447. textCharacter = 0;
  207448. used = handleKeyUpOrDown (true) || used;
  207449. used = handleKeyPress (keyCode, textCharacter) || used;
  207450. }
  207451. return used;
  207452. }
  207453. else
  207454. {
  207455. if (handleKeyUpOrDown (false))
  207456. return true;
  207457. }
  207458. }
  207459. return false;
  207460. }
  207461. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207462. {
  207463. updateKeysDown (ev, true);
  207464. bool used = handleKeyEvent (ev, true);
  207465. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207466. {
  207467. // for command keys, the key-up event is thrown away, so simulate one..
  207468. updateKeysDown (ev, false);
  207469. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207470. }
  207471. // (If we're running modally, don't allow unused keystrokes to be passed
  207472. // along to other blocked views..)
  207473. if (Component::getCurrentlyModalComponent() != 0)
  207474. used = true;
  207475. return used;
  207476. }
  207477. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207478. {
  207479. updateKeysDown (ev, false);
  207480. return handleKeyEvent (ev, false)
  207481. || Component::getCurrentlyModalComponent() != 0;
  207482. }
  207483. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207484. {
  207485. keysCurrentlyDown.clear();
  207486. handleKeyUpOrDown (true);
  207487. updateModifiers (ev);
  207488. handleModifierKeysChange();
  207489. }
  207490. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207491. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207492. {
  207493. if ([ev type] == NSKeyDown)
  207494. return redirectKeyDown (ev);
  207495. else if ([ev type] == NSKeyUp)
  207496. return redirectKeyUp (ev);
  207497. return false;
  207498. }
  207499. #endif
  207500. void NSViewComponentPeer::sendMouseEvent (NSEvent* ev)
  207501. {
  207502. updateModifiers (ev);
  207503. handleMouseEvent (0, getMousePos (ev, view), currentModifiers, getMouseTime (ev));
  207504. }
  207505. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207506. {
  207507. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207508. sendMouseEvent (ev);
  207509. }
  207510. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207511. {
  207512. currentModifiers = currentModifiers.withoutFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207513. sendMouseEvent (ev);
  207514. showArrowCursorIfNeeded();
  207515. }
  207516. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207517. {
  207518. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207519. sendMouseEvent (ev);
  207520. }
  207521. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207522. {
  207523. currentModifiers = currentModifiers.withoutMouseButtons();
  207524. sendMouseEvent (ev);
  207525. showArrowCursorIfNeeded();
  207526. }
  207527. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207528. {
  207529. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207530. currentModifiers = currentModifiers.withoutMouseButtons();
  207531. sendMouseEvent (ev);
  207532. }
  207533. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207534. {
  207535. currentModifiers = currentModifiers.withoutMouseButtons();
  207536. sendMouseEvent (ev);
  207537. }
  207538. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207539. {
  207540. updateModifiers (ev);
  207541. handleMouseWheel (0, getMousePos (ev, view), getMouseTime (ev),
  207542. [ev deltaX] * 10.0f, [ev deltaY] * 10.0f);
  207543. }
  207544. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207545. {
  207546. MouseInputSource& mouse = Desktop::getInstance().getMainMouseSource();
  207547. if (mouse.getComponentUnderMouse() == 0
  207548. && Desktop::getInstance().findComponentAt (mouse.getScreenPosition()) == 0)
  207549. {
  207550. [[NSCursor arrowCursor] set];
  207551. }
  207552. }
  207553. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207554. {
  207555. NSString* bestType
  207556. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207557. if (bestType == nil)
  207558. return false;
  207559. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207560. const Point<int> pos ((int) p.x, (int) ([view frame].size.height - p.y));
  207561. StringArray files;
  207562. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207563. if (list == nil)
  207564. return false;
  207565. if ([list isKindOfClass: [NSArray class]])
  207566. {
  207567. NSArray* items = (NSArray*) list;
  207568. for (unsigned int i = 0; i < [items count]; ++i)
  207569. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207570. }
  207571. if (files.size() == 0)
  207572. return false;
  207573. if (type == 0)
  207574. handleFileDragMove (files, pos);
  207575. else if (type == 1)
  207576. handleFileDragExit (files);
  207577. else if (type == 2)
  207578. handleFileDragDrop (files, pos);
  207579. return true;
  207580. }
  207581. bool NSViewComponentPeer::isOpaque()
  207582. {
  207583. return component == 0 || component->isOpaque();
  207584. }
  207585. void NSViewComponentPeer::drawRect (NSRect r)
  207586. {
  207587. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207588. return;
  207589. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207590. if (! component->isOpaque())
  207591. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207592. #if USE_COREGRAPHICS_RENDERING
  207593. if (usingCoreGraphics)
  207594. {
  207595. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207596. insideDrawRect = true;
  207597. handlePaint (context);
  207598. insideDrawRect = false;
  207599. }
  207600. else
  207601. #endif
  207602. {
  207603. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207604. (int) (r.size.width + 0.5f),
  207605. (int) (r.size.height + 0.5f),
  207606. ! getComponent()->isOpaque());
  207607. LowLevelGraphicsSoftwareRenderer context (temp);
  207608. context.setOrigin (-roundToInt (r.origin.x),
  207609. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207610. const NSRect* rects = 0;
  207611. NSInteger numRects = 0;
  207612. [view getRectsBeingDrawn: &rects count: &numRects];
  207613. RectangleList clip;
  207614. for (int i = 0; i < numRects; ++i)
  207615. {
  207616. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207617. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207618. roundToInt (rects[i].size.width),
  207619. roundToInt (rects[i].size.height)));
  207620. }
  207621. if (context.clipToRectangleList (clip))
  207622. {
  207623. insideDrawRect = true;
  207624. handlePaint (context);
  207625. insideDrawRect = false;
  207626. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207627. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207628. CGColorSpaceRelease (colourSpace);
  207629. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207630. CGImageRelease (image);
  207631. }
  207632. }
  207633. }
  207634. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207635. {
  207636. StringArray s;
  207637. s.add ("Software Renderer");
  207638. #if USE_COREGRAPHICS_RENDERING
  207639. s.add ("CoreGraphics Renderer");
  207640. #endif
  207641. return s;
  207642. }
  207643. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207644. {
  207645. return usingCoreGraphics ? 1 : 0;
  207646. }
  207647. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207648. {
  207649. #if USE_COREGRAPHICS_RENDERING
  207650. if (usingCoreGraphics != (index > 0))
  207651. {
  207652. usingCoreGraphics = index > 0;
  207653. [view setNeedsDisplay: true];
  207654. }
  207655. #endif
  207656. }
  207657. bool NSViewComponentPeer::canBecomeKeyWindow()
  207658. {
  207659. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207660. }
  207661. bool NSViewComponentPeer::windowShouldClose()
  207662. {
  207663. if (! isValidPeer (this))
  207664. return YES;
  207665. handleUserClosingWindow();
  207666. return NO;
  207667. }
  207668. void NSViewComponentPeer::redirectMovedOrResized()
  207669. {
  207670. handleMovedOrResized();
  207671. }
  207672. void NSViewComponentPeer::viewMovedToWindow()
  207673. {
  207674. if (isSharedWindow)
  207675. window = [view window];
  207676. }
  207677. void Desktop::createMouseInputSources()
  207678. {
  207679. mouseSources.add (new MouseInputSource (0, true));
  207680. }
  207681. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207682. {
  207683. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207684. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207685. // is apparently still available in 64-bit apps..
  207686. if (enableOrDisable)
  207687. {
  207688. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207689. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207690. }
  207691. else
  207692. {
  207693. SetSystemUIMode (kUIModeNormal, 0);
  207694. }
  207695. }
  207696. class AsyncRepaintMessage : public CallbackMessage
  207697. {
  207698. public:
  207699. NSViewComponentPeer* const peer;
  207700. const Rectangle<int> rect;
  207701. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207702. : peer (peer_), rect (rect_)
  207703. {
  207704. }
  207705. void messageCallback()
  207706. {
  207707. if (ComponentPeer::isValidPeer (peer))
  207708. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207709. }
  207710. };
  207711. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207712. {
  207713. if (insideDrawRect)
  207714. {
  207715. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207716. }
  207717. else
  207718. {
  207719. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207720. (float) w, (float) h)];
  207721. }
  207722. }
  207723. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207724. {
  207725. [view displayIfNeeded];
  207726. }
  207727. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207728. {
  207729. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207730. }
  207731. Image* juce_createIconForFile (const File& file)
  207732. {
  207733. const ScopedAutoReleasePool pool;
  207734. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207735. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207736. [NSGraphicsContext saveGraphicsState];
  207737. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207738. [image drawAtPoint: NSMakePoint (0, 0)
  207739. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207740. operation: NSCompositeSourceOver fraction: 1.0f];
  207741. [[NSGraphicsContext currentContext] flushGraphics];
  207742. [NSGraphicsContext restoreGraphicsState];
  207743. return result;
  207744. }
  207745. const int KeyPress::spaceKey = ' ';
  207746. const int KeyPress::returnKey = 0x0d;
  207747. const int KeyPress::escapeKey = 0x1b;
  207748. const int KeyPress::backspaceKey = 0x7f;
  207749. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207750. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207751. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207752. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207753. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207754. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207755. const int KeyPress::endKey = NSEndFunctionKey;
  207756. const int KeyPress::homeKey = NSHomeFunctionKey;
  207757. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207758. const int KeyPress::insertKey = -1;
  207759. const int KeyPress::tabKey = 9;
  207760. const int KeyPress::F1Key = NSF1FunctionKey;
  207761. const int KeyPress::F2Key = NSF2FunctionKey;
  207762. const int KeyPress::F3Key = NSF3FunctionKey;
  207763. const int KeyPress::F4Key = NSF4FunctionKey;
  207764. const int KeyPress::F5Key = NSF5FunctionKey;
  207765. const int KeyPress::F6Key = NSF6FunctionKey;
  207766. const int KeyPress::F7Key = NSF7FunctionKey;
  207767. const int KeyPress::F8Key = NSF8FunctionKey;
  207768. const int KeyPress::F9Key = NSF9FunctionKey;
  207769. const int KeyPress::F10Key = NSF10FunctionKey;
  207770. const int KeyPress::F11Key = NSF1FunctionKey;
  207771. const int KeyPress::F12Key = NSF12FunctionKey;
  207772. const int KeyPress::F13Key = NSF13FunctionKey;
  207773. const int KeyPress::F14Key = NSF14FunctionKey;
  207774. const int KeyPress::F15Key = NSF15FunctionKey;
  207775. const int KeyPress::F16Key = NSF16FunctionKey;
  207776. const int KeyPress::numberPad0 = 0x30020;
  207777. const int KeyPress::numberPad1 = 0x30021;
  207778. const int KeyPress::numberPad2 = 0x30022;
  207779. const int KeyPress::numberPad3 = 0x30023;
  207780. const int KeyPress::numberPad4 = 0x30024;
  207781. const int KeyPress::numberPad5 = 0x30025;
  207782. const int KeyPress::numberPad6 = 0x30026;
  207783. const int KeyPress::numberPad7 = 0x30027;
  207784. const int KeyPress::numberPad8 = 0x30028;
  207785. const int KeyPress::numberPad9 = 0x30029;
  207786. const int KeyPress::numberPadAdd = 0x3002a;
  207787. const int KeyPress::numberPadSubtract = 0x3002b;
  207788. const int KeyPress::numberPadMultiply = 0x3002c;
  207789. const int KeyPress::numberPadDivide = 0x3002d;
  207790. const int KeyPress::numberPadSeparator = 0x3002e;
  207791. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207792. const int KeyPress::numberPadEquals = 0x30030;
  207793. const int KeyPress::numberPadDelete = 0x30031;
  207794. const int KeyPress::playKey = 0x30000;
  207795. const int KeyPress::stopKey = 0x30001;
  207796. const int KeyPress::fastForwardKey = 0x30002;
  207797. const int KeyPress::rewindKey = 0x30003;
  207798. #endif
  207799. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207800. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207801. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207802. // compiled on its own).
  207803. #if JUCE_INCLUDED_FILE
  207804. #if JUCE_MAC
  207805. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  207806. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207807. {
  207808. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207809. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207810. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207811. [im release];
  207812. return (void*) c;
  207813. }
  207814. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207815. {
  207816. MemoryInputStream stream (data, size, false);
  207817. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  207818. jassert (im != 0);
  207819. if (im == 0)
  207820. return 0;
  207821. return juce_createMouseCursorFromImage (*im,
  207822. (int) (hx * im->getWidth()),
  207823. (int) (hy * im->getHeight()));
  207824. }
  207825. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207826. {
  207827. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207828. MemoryBlock mb;
  207829. if (f.getChildFile (filename).loadFileAsData (mb))
  207830. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207831. return 0;
  207832. }
  207833. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  207834. {
  207835. const ScopedAutoReleasePool pool;
  207836. NSCursor* c = 0;
  207837. switch (type)
  207838. {
  207839. case MouseCursor::NormalCursor:
  207840. c = [NSCursor arrowCursor];
  207841. break;
  207842. case MouseCursor::NoCursor:
  207843. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  207844. case MouseCursor::DraggingHandCursor:
  207845. c = [NSCursor openHandCursor];
  207846. break;
  207847. case MouseCursor::CopyingCursor:
  207848. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207849. case MouseCursor::WaitCursor:
  207850. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207851. break;
  207852. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207853. case MouseCursor::IBeamCursor:
  207854. c = [NSCursor IBeamCursor];
  207855. break;
  207856. case MouseCursor::PointingHandCursor:
  207857. c = [NSCursor pointingHandCursor];
  207858. break;
  207859. case MouseCursor::LeftRightResizeCursor:
  207860. c = [NSCursor resizeLeftRightCursor];
  207861. break;
  207862. case MouseCursor::LeftEdgeResizeCursor:
  207863. c = [NSCursor resizeLeftCursor];
  207864. break;
  207865. case MouseCursor::RightEdgeResizeCursor:
  207866. c = [NSCursor resizeRightCursor];
  207867. break;
  207868. case MouseCursor::UpDownResizeCursor:
  207869. case MouseCursor::TopEdgeResizeCursor:
  207870. case MouseCursor::BottomEdgeResizeCursor:
  207871. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207872. case MouseCursor::TopLeftCornerResizeCursor:
  207873. case MouseCursor::BottomRightCornerResizeCursor:
  207874. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207875. case MouseCursor::TopRightCornerResizeCursor:
  207876. case MouseCursor::BottomLeftCornerResizeCursor:
  207877. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207878. case MouseCursor::UpDownLeftRightResizeCursor:
  207879. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207880. case MouseCursor::CrosshairCursor:
  207881. c = [NSCursor crosshairCursor];
  207882. break;
  207883. }
  207884. [c retain];
  207885. return (void*) c;
  207886. }
  207887. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  207888. {
  207889. NSCursor* c = (NSCursor*) cursorHandle;
  207890. [c release];
  207891. }
  207892. void MouseCursor::showInAllWindows() const throw()
  207893. {
  207894. showInWindow (0);
  207895. }
  207896. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  207897. {
  207898. NSCursor* const c = (NSCursor*) getHandle();
  207899. [c set];
  207900. }
  207901. #else
  207902. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  207903. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  207904. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  207905. void MouseCursor::showInAllWindows() const throw() {}
  207906. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  207907. #endif
  207908. #endif
  207909. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207910. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207911. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207912. // compiled on its own).
  207913. #if JUCE_INCLUDED_FILE
  207914. class NSViewComponentInternal : public ComponentMovementWatcher
  207915. {
  207916. Component* const owner;
  207917. NSViewComponentPeer* currentPeer;
  207918. bool wasShowing;
  207919. public:
  207920. NSView* const view;
  207921. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207922. : ComponentMovementWatcher (owner_),
  207923. owner (owner_),
  207924. currentPeer (0),
  207925. wasShowing (false),
  207926. view (view_)
  207927. {
  207928. [view_ retain];
  207929. if (owner_->isShowing())
  207930. componentPeerChanged();
  207931. }
  207932. ~NSViewComponentInternal()
  207933. {
  207934. [view removeFromSuperview];
  207935. [view release];
  207936. }
  207937. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207938. {
  207939. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207940. // The ComponentMovementWatcher version of this method avoids calling
  207941. // us when the top-level comp is resized, but for an NSView we need to know this
  207942. // because with inverted co-ords, we need to update the position even if the
  207943. // top-left pos hasn't changed
  207944. if (comp.isOnDesktop() && wasResized)
  207945. componentMovedOrResized (wasMoved, wasResized);
  207946. }
  207947. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207948. {
  207949. Component* const topComp = owner->getTopLevelComponent();
  207950. if (topComp->getPeer() != 0)
  207951. {
  207952. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  207953. NSRect r;
  207954. r.origin.x = (float) pos.getX();
  207955. r.origin.y = (float) pos.getY();
  207956. r.size.width = (float) owner->getWidth();
  207957. r.size.height = (float) owner->getHeight();
  207958. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207959. [view setFrame: r];
  207960. }
  207961. }
  207962. void componentPeerChanged()
  207963. {
  207964. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207965. if (currentPeer != peer)
  207966. {
  207967. [view removeFromSuperview];
  207968. currentPeer = peer;
  207969. if (peer != 0)
  207970. {
  207971. [peer->view addSubview: view];
  207972. componentMovedOrResized (false, false);
  207973. }
  207974. }
  207975. [view setHidden: ! owner->isShowing()];
  207976. }
  207977. void componentVisibilityChanged (Component&)
  207978. {
  207979. componentPeerChanged();
  207980. }
  207981. juce_UseDebuggingNewOperator
  207982. private:
  207983. NSViewComponentInternal (const NSViewComponentInternal&);
  207984. NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  207985. };
  207986. NSViewComponent::NSViewComponent()
  207987. {
  207988. }
  207989. NSViewComponent::~NSViewComponent()
  207990. {
  207991. }
  207992. void NSViewComponent::setView (void* view)
  207993. {
  207994. if (view != getView())
  207995. {
  207996. if (view != 0)
  207997. info = new NSViewComponentInternal ((NSView*) view, this);
  207998. else
  207999. info = 0;
  208000. }
  208001. }
  208002. void* NSViewComponent::getView() const
  208003. {
  208004. return info == 0 ? 0 : info->view;
  208005. }
  208006. void NSViewComponent::paint (Graphics& g)
  208007. {
  208008. }
  208009. #endif
  208010. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  208011. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  208012. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208013. // compiled on its own).
  208014. #if JUCE_INCLUDED_FILE
  208015. AppleRemoteDevice::AppleRemoteDevice()
  208016. : device (0),
  208017. queue (0),
  208018. remoteId (0)
  208019. {
  208020. }
  208021. AppleRemoteDevice::~AppleRemoteDevice()
  208022. {
  208023. stop();
  208024. }
  208025. static io_object_t getAppleRemoteDevice()
  208026. {
  208027. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  208028. io_iterator_t iter = 0;
  208029. io_object_t iod = 0;
  208030. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  208031. && iter != 0)
  208032. {
  208033. iod = IOIteratorNext (iter);
  208034. }
  208035. IOObjectRelease (iter);
  208036. return iod;
  208037. }
  208038. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  208039. {
  208040. jassert (*device == 0);
  208041. io_name_t classname;
  208042. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  208043. {
  208044. IOCFPlugInInterface** cfPlugInInterface = 0;
  208045. SInt32 score = 0;
  208046. if (IOCreatePlugInInterfaceForService (iod,
  208047. kIOHIDDeviceUserClientTypeID,
  208048. kIOCFPlugInInterfaceID,
  208049. &cfPlugInInterface,
  208050. &score) == kIOReturnSuccess)
  208051. {
  208052. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  208053. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  208054. device);
  208055. (void) hr;
  208056. (*cfPlugInInterface)->Release (cfPlugInInterface);
  208057. }
  208058. }
  208059. return *device != 0;
  208060. }
  208061. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  208062. {
  208063. if (queue != 0)
  208064. return true;
  208065. stop();
  208066. bool result = false;
  208067. io_object_t iod = getAppleRemoteDevice();
  208068. if (iod != 0)
  208069. {
  208070. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  208071. result = true;
  208072. else
  208073. stop();
  208074. IOObjectRelease (iod);
  208075. }
  208076. return result;
  208077. }
  208078. void AppleRemoteDevice::stop()
  208079. {
  208080. if (queue != 0)
  208081. {
  208082. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208083. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208084. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208085. queue = 0;
  208086. }
  208087. if (device != 0)
  208088. {
  208089. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208090. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208091. device = 0;
  208092. }
  208093. }
  208094. bool AppleRemoteDevice::isActive() const
  208095. {
  208096. return queue != 0;
  208097. }
  208098. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208099. {
  208100. if (result == kIOReturnSuccess)
  208101. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208102. }
  208103. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208104. {
  208105. Array <int> cookies;
  208106. CFArrayRef elements;
  208107. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208108. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208109. return false;
  208110. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208111. {
  208112. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208113. // get the cookie
  208114. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208115. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208116. continue;
  208117. long number;
  208118. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208119. continue;
  208120. cookies.add ((int) number);
  208121. }
  208122. CFRelease (elements);
  208123. if ((*(IOHIDDeviceInterface**) device)
  208124. ->open ((IOHIDDeviceInterface**) device,
  208125. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208126. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208127. {
  208128. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208129. if (queue != 0)
  208130. {
  208131. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208132. for (int i = 0; i < cookies.size(); ++i)
  208133. {
  208134. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208135. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208136. }
  208137. CFRunLoopSourceRef eventSource;
  208138. if ((*(IOHIDQueueInterface**) queue)
  208139. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208140. {
  208141. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208142. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208143. {
  208144. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208145. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208146. return true;
  208147. }
  208148. }
  208149. }
  208150. }
  208151. return false;
  208152. }
  208153. void AppleRemoteDevice::handleCallbackInternal()
  208154. {
  208155. int totalValues = 0;
  208156. AbsoluteTime nullTime = { 0, 0 };
  208157. char cookies [12];
  208158. int numCookies = 0;
  208159. while (numCookies < numElementsInArray (cookies))
  208160. {
  208161. IOHIDEventStruct e;
  208162. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208163. break;
  208164. if ((int) e.elementCookie == 19)
  208165. {
  208166. remoteId = e.value;
  208167. buttonPressed (switched, false);
  208168. }
  208169. else
  208170. {
  208171. totalValues += e.value;
  208172. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208173. }
  208174. }
  208175. cookies [numCookies++] = 0;
  208176. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208177. static const char buttonPatterns[] =
  208178. {
  208179. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208180. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208181. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208182. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208183. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208184. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208185. 0x1f, 0x12, 0x04, 0x02, 0,
  208186. 0x1f, 0x12, 0x03, 0x02, 0,
  208187. 0x1f, 0x12, 0x1f, 0x12, 0,
  208188. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208189. 19, 0
  208190. };
  208191. int buttonNum = (int) menuButton;
  208192. int i = 0;
  208193. while (i < numElementsInArray (buttonPatterns))
  208194. {
  208195. if (strcmp (cookies, buttonPatterns + i) == 0)
  208196. {
  208197. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208198. break;
  208199. }
  208200. i += (int) strlen (buttonPatterns + i) + 1;
  208201. ++buttonNum;
  208202. }
  208203. }
  208204. #endif
  208205. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208206. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208207. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208208. // compiled on its own).
  208209. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208210. #if JUCE_MAC
  208211. END_JUCE_NAMESPACE
  208212. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208213. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208214. {
  208215. CriticalSection* contextLock;
  208216. bool needsUpdate;
  208217. }
  208218. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208219. - (bool) makeActive;
  208220. - (void) makeInactive;
  208221. - (void) reshape;
  208222. @end
  208223. @implementation ThreadSafeNSOpenGLView
  208224. - (id) initWithFrame: (NSRect) frameRect
  208225. pixelFormat: (NSOpenGLPixelFormat*) format
  208226. {
  208227. contextLock = new CriticalSection();
  208228. self = [super initWithFrame: frameRect pixelFormat: format];
  208229. if (self != nil)
  208230. [[NSNotificationCenter defaultCenter] addObserver: self
  208231. selector: @selector (_surfaceNeedsUpdate:)
  208232. name: NSViewGlobalFrameDidChangeNotification
  208233. object: self];
  208234. return self;
  208235. }
  208236. - (void) dealloc
  208237. {
  208238. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208239. delete contextLock;
  208240. [super dealloc];
  208241. }
  208242. - (bool) makeActive
  208243. {
  208244. const ScopedLock sl (*contextLock);
  208245. if ([self openGLContext] == 0)
  208246. return false;
  208247. [[self openGLContext] makeCurrentContext];
  208248. if (needsUpdate)
  208249. {
  208250. [super update];
  208251. needsUpdate = false;
  208252. }
  208253. return true;
  208254. }
  208255. - (void) makeInactive
  208256. {
  208257. const ScopedLock sl (*contextLock);
  208258. [NSOpenGLContext clearCurrentContext];
  208259. }
  208260. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208261. {
  208262. const ScopedLock sl (*contextLock);
  208263. needsUpdate = true;
  208264. }
  208265. - (void) update
  208266. {
  208267. const ScopedLock sl (*contextLock);
  208268. needsUpdate = true;
  208269. }
  208270. - (void) reshape
  208271. {
  208272. const ScopedLock sl (*contextLock);
  208273. needsUpdate = true;
  208274. }
  208275. @end
  208276. BEGIN_JUCE_NAMESPACE
  208277. class WindowedGLContext : public OpenGLContext
  208278. {
  208279. public:
  208280. WindowedGLContext (Component* const component,
  208281. const OpenGLPixelFormat& pixelFormat_,
  208282. NSOpenGLContext* sharedContext)
  208283. : renderContext (0),
  208284. pixelFormat (pixelFormat_)
  208285. {
  208286. jassert (component != 0);
  208287. NSOpenGLPixelFormatAttribute attribs [64];
  208288. int n = 0;
  208289. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208290. attribs[n++] = NSOpenGLPFAAccelerated;
  208291. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208292. attribs[n++] = NSOpenGLPFAColorSize;
  208293. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208294. pixelFormat.greenBits,
  208295. pixelFormat.blueBits);
  208296. attribs[n++] = NSOpenGLPFAAlphaSize;
  208297. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208298. attribs[n++] = NSOpenGLPFADepthSize;
  208299. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208300. attribs[n++] = NSOpenGLPFAStencilSize;
  208301. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208302. attribs[n++] = NSOpenGLPFAAccumSize;
  208303. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208304. pixelFormat.accumulationBufferGreenBits,
  208305. pixelFormat.accumulationBufferBlueBits,
  208306. pixelFormat.accumulationBufferAlphaBits);
  208307. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208308. attribs[n++] = NSOpenGLPFASampleBuffers;
  208309. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208310. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208311. attribs[n++] = NSOpenGLPFANoRecovery;
  208312. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208313. NSOpenGLPixelFormat* format
  208314. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208315. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208316. pixelFormat: format];
  208317. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208318. shareContext: sharedContext] autorelease];
  208319. const GLint swapInterval = 1;
  208320. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208321. [view setOpenGLContext: renderContext];
  208322. [renderContext setView: view];
  208323. [format release];
  208324. viewHolder = new NSViewComponentInternal (view, component);
  208325. }
  208326. ~WindowedGLContext()
  208327. {
  208328. makeInactive();
  208329. [renderContext clearDrawable];
  208330. viewHolder = 0;
  208331. }
  208332. bool makeActive() const throw()
  208333. {
  208334. jassert (renderContext != 0);
  208335. [view makeActive];
  208336. return isActive();
  208337. }
  208338. bool makeInactive() const throw()
  208339. {
  208340. [view makeInactive];
  208341. return true;
  208342. }
  208343. bool isActive() const throw()
  208344. {
  208345. return [NSOpenGLContext currentContext] == renderContext;
  208346. }
  208347. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208348. void* getRawContext() const throw() { return renderContext; }
  208349. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208350. {
  208351. }
  208352. void swapBuffers()
  208353. {
  208354. [renderContext flushBuffer];
  208355. }
  208356. bool setSwapInterval (const int numFramesPerSwap)
  208357. {
  208358. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208359. forParameter: NSOpenGLCPSwapInterval];
  208360. return true;
  208361. }
  208362. int getSwapInterval() const
  208363. {
  208364. GLint numFrames = 0;
  208365. [renderContext getValues: &numFrames
  208366. forParameter: NSOpenGLCPSwapInterval];
  208367. return numFrames;
  208368. }
  208369. void repaint()
  208370. {
  208371. // we need to invalidate the juce view that holds this gl view, to make it
  208372. // cause a repaint callback
  208373. NSView* v = (NSView*) viewHolder->view;
  208374. NSRect r = [v frame];
  208375. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208376. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208377. // repaint message, thus never causing our paint() callback, and never repainting
  208378. // the comp. So invalidating just a little bit around the edge helps..
  208379. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208380. }
  208381. void* getNativeWindowHandle() const { return viewHolder->view; }
  208382. juce_UseDebuggingNewOperator
  208383. NSOpenGLContext* renderContext;
  208384. ThreadSafeNSOpenGLView* view;
  208385. private:
  208386. OpenGLPixelFormat pixelFormat;
  208387. ScopedPointer <NSViewComponentInternal> viewHolder;
  208388. WindowedGLContext (const WindowedGLContext&);
  208389. WindowedGLContext& operator= (const WindowedGLContext&);
  208390. };
  208391. OpenGLContext* OpenGLComponent::createContext()
  208392. {
  208393. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  208394. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  208395. return (c->renderContext != 0) ? c.release() : 0;
  208396. }
  208397. void* OpenGLComponent::getNativeWindowHandle() const
  208398. {
  208399. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  208400. : 0;
  208401. }
  208402. void juce_glViewport (const int w, const int h)
  208403. {
  208404. glViewport (0, 0, w, h);
  208405. }
  208406. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208407. OwnedArray <OpenGLPixelFormat>& results)
  208408. {
  208409. /* GLint attribs [64];
  208410. int n = 0;
  208411. attribs[n++] = AGL_RGBA;
  208412. attribs[n++] = AGL_DOUBLEBUFFER;
  208413. attribs[n++] = AGL_ACCELERATED;
  208414. attribs[n++] = AGL_NO_RECOVERY;
  208415. attribs[n++] = AGL_NONE;
  208416. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208417. while (p != 0)
  208418. {
  208419. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208420. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208421. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208422. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208423. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208424. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208425. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208426. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208427. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208428. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208429. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208430. results.add (pf);
  208431. p = aglNextPixelFormat (p);
  208432. }*/
  208433. //jassertfalse //xxx can't see how you do this in cocoa!
  208434. }
  208435. #else
  208436. END_JUCE_NAMESPACE
  208437. @interface JuceGLView : UIView
  208438. {
  208439. }
  208440. + (Class) layerClass;
  208441. @end
  208442. @implementation JuceGLView
  208443. + (Class) layerClass
  208444. {
  208445. return [CAEAGLLayer class];
  208446. }
  208447. @end
  208448. BEGIN_JUCE_NAMESPACE
  208449. class GLESContext : public OpenGLContext
  208450. {
  208451. public:
  208452. GLESContext (UIViewComponentPeer* peer,
  208453. Component* const component_,
  208454. const OpenGLPixelFormat& pixelFormat_,
  208455. const GLESContext* const sharedContext,
  208456. NSUInteger apiType)
  208457. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  208458. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  208459. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  208460. {
  208461. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  208462. view.opaque = YES;
  208463. view.hidden = NO;
  208464. view.backgroundColor = [UIColor blackColor];
  208465. view.userInteractionEnabled = NO;
  208466. glLayer = (CAEAGLLayer*) [view layer];
  208467. [peer->view addSubview: view];
  208468. if (sharedContext != 0)
  208469. context = [[EAGLContext alloc] initWithAPI: apiType
  208470. sharegroup: [sharedContext->context sharegroup]];
  208471. else
  208472. context = [[EAGLContext alloc] initWithAPI: apiType];
  208473. createGLBuffers();
  208474. }
  208475. ~GLESContext()
  208476. {
  208477. makeInactive();
  208478. [context release];
  208479. [view removeFromSuperview];
  208480. [view release];
  208481. freeGLBuffers();
  208482. }
  208483. bool makeActive() const throw()
  208484. {
  208485. jassert (context != 0);
  208486. [EAGLContext setCurrentContext: context];
  208487. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208488. return true;
  208489. }
  208490. void swapBuffers()
  208491. {
  208492. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208493. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  208494. }
  208495. bool makeInactive() const throw()
  208496. {
  208497. return [EAGLContext setCurrentContext: nil];
  208498. }
  208499. bool isActive() const throw()
  208500. {
  208501. return [EAGLContext currentContext] == context;
  208502. }
  208503. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208504. void* getRawContext() const throw() { return (void*) glLayer; }
  208505. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208506. {
  208507. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  208508. if (lastWidth != w || lastHeight != h)
  208509. {
  208510. lastWidth = w;
  208511. lastHeight = h;
  208512. freeGLBuffers();
  208513. createGLBuffers();
  208514. }
  208515. }
  208516. bool setSwapInterval (const int numFramesPerSwap)
  208517. {
  208518. numFrames = numFramesPerSwap;
  208519. return true;
  208520. }
  208521. int getSwapInterval() const
  208522. {
  208523. return numFrames;
  208524. }
  208525. void repaint()
  208526. {
  208527. }
  208528. void createGLBuffers()
  208529. {
  208530. makeActive();
  208531. glGenFramebuffersOES (1, &frameBufferHandle);
  208532. glGenRenderbuffersOES (1, &colorBufferHandle);
  208533. glGenRenderbuffersOES (1, &depthBufferHandle);
  208534. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208535. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  208536. GLint width, height;
  208537. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  208538. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  208539. if (useDepthBuffer)
  208540. {
  208541. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  208542. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  208543. }
  208544. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208545. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208546. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  208547. if (useDepthBuffer)
  208548. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  208549. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  208550. }
  208551. void freeGLBuffers()
  208552. {
  208553. if (frameBufferHandle != 0)
  208554. {
  208555. glDeleteFramebuffersOES (1, &frameBufferHandle);
  208556. frameBufferHandle = 0;
  208557. }
  208558. if (colorBufferHandle != 0)
  208559. {
  208560. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  208561. colorBufferHandle = 0;
  208562. }
  208563. if (depthBufferHandle != 0)
  208564. {
  208565. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  208566. depthBufferHandle = 0;
  208567. }
  208568. }
  208569. juce_UseDebuggingNewOperator
  208570. private:
  208571. Component::SafePointer<Component> component;
  208572. OpenGLPixelFormat pixelFormat;
  208573. JuceGLView* view;
  208574. CAEAGLLayer* glLayer;
  208575. EAGLContext* context;
  208576. bool useDepthBuffer;
  208577. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  208578. int numFrames;
  208579. int lastWidth, lastHeight;
  208580. GLESContext (const GLESContext&);
  208581. GLESContext& operator= (const GLESContext&);
  208582. };
  208583. OpenGLContext* OpenGLComponent::createContext()
  208584. {
  208585. ScopedAutoReleasePool pool;
  208586. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  208587. if (peer != 0)
  208588. return new GLESContext (peer, this, preferredPixelFormat,
  208589. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  208590. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  208591. return 0;
  208592. }
  208593. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208594. OwnedArray <OpenGLPixelFormat>& /*results*/)
  208595. {
  208596. }
  208597. void juce_glViewport (const int w, const int h)
  208598. {
  208599. glViewport (0, 0, w, h);
  208600. }
  208601. #endif
  208602. #endif
  208603. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208604. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208605. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208606. // compiled on its own).
  208607. #if JUCE_INCLUDED_FILE
  208608. class JuceMainMenuHandler;
  208609. END_JUCE_NAMESPACE
  208610. using namespace JUCE_NAMESPACE;
  208611. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208612. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208613. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208614. #else
  208615. @interface JuceMenuCallback : NSObject
  208616. #endif
  208617. {
  208618. JuceMainMenuHandler* owner;
  208619. }
  208620. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208621. - (void) dealloc;
  208622. - (void) menuItemInvoked: (id) menu;
  208623. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208624. @end
  208625. BEGIN_JUCE_NAMESPACE
  208626. class JuceMainMenuHandler : private MenuBarModelListener,
  208627. private DeletedAtShutdown
  208628. {
  208629. public:
  208630. static JuceMainMenuHandler* instance;
  208631. JuceMainMenuHandler()
  208632. : currentModel (0),
  208633. lastUpdateTime (0)
  208634. {
  208635. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208636. }
  208637. ~JuceMainMenuHandler()
  208638. {
  208639. setMenu (0);
  208640. jassert (instance == this);
  208641. instance = 0;
  208642. [callback release];
  208643. }
  208644. void setMenu (MenuBarModel* const newMenuBarModel)
  208645. {
  208646. if (currentModel != newMenuBarModel)
  208647. {
  208648. if (currentModel != 0)
  208649. currentModel->removeListener (this);
  208650. currentModel = newMenuBarModel;
  208651. if (currentModel != 0)
  208652. currentModel->addListener (this);
  208653. menuBarItemsChanged (0);
  208654. }
  208655. }
  208656. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208657. const String& name, const int menuId, const int tag)
  208658. {
  208659. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208660. action: nil
  208661. keyEquivalent: @""];
  208662. [item setTag: tag];
  208663. NSMenu* sub = createMenu (child, name, menuId, tag);
  208664. [parent setSubmenu: sub forItem: item];
  208665. [sub setAutoenablesItems: false];
  208666. [sub release];
  208667. }
  208668. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208669. const String& name, const int menuId, const int tag)
  208670. {
  208671. [parentItem setTag: tag];
  208672. NSMenu* menu = [parentItem submenu];
  208673. [menu setTitle: juceStringToNS (name)];
  208674. while ([menu numberOfItems] > 0)
  208675. [menu removeItemAtIndex: 0];
  208676. PopupMenu::MenuItemIterator iter (menuToCopy);
  208677. while (iter.next())
  208678. addMenuItem (iter, menu, menuId, tag);
  208679. [menu setAutoenablesItems: false];
  208680. [menu update];
  208681. }
  208682. void menuBarItemsChanged (MenuBarModel*)
  208683. {
  208684. lastUpdateTime = Time::getMillisecondCounter();
  208685. StringArray menuNames;
  208686. if (currentModel != 0)
  208687. menuNames = currentModel->getMenuBarNames();
  208688. NSMenu* menuBar = [NSApp mainMenu];
  208689. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208690. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208691. int menuId = 1;
  208692. for (int i = 0; i < menuNames.size(); ++i)
  208693. {
  208694. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208695. if (i >= [menuBar numberOfItems] - 1)
  208696. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208697. else
  208698. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208699. }
  208700. }
  208701. static void flashMenuBar (NSMenu* menu)
  208702. {
  208703. if ([[menu title] isEqualToString: @"Apple"])
  208704. return;
  208705. [menu retain];
  208706. const unichar f35Key = NSF35FunctionKey;
  208707. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208708. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208709. action: nil
  208710. keyEquivalent: f35String];
  208711. [item setTarget: nil];
  208712. [menu insertItem: item atIndex: [menu numberOfItems]];
  208713. [item release];
  208714. if ([menu indexOfItem: item] >= 0)
  208715. {
  208716. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208717. location: NSZeroPoint
  208718. modifierFlags: NSCommandKeyMask
  208719. timestamp: 0
  208720. windowNumber: 0
  208721. context: [NSGraphicsContext currentContext]
  208722. characters: f35String
  208723. charactersIgnoringModifiers: f35String
  208724. isARepeat: NO
  208725. keyCode: 0];
  208726. [menu performKeyEquivalent: f35Event];
  208727. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208728. }
  208729. [menu release];
  208730. }
  208731. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208732. {
  208733. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208734. {
  208735. NSMenuItem* m = [menu itemAtIndex: i];
  208736. if ([m tag] == info.commandID)
  208737. return m;
  208738. if ([m submenu] != 0)
  208739. {
  208740. NSMenuItem* found = findMenuItem ([m submenu], info);
  208741. if (found != 0)
  208742. return found;
  208743. }
  208744. }
  208745. return 0;
  208746. }
  208747. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208748. {
  208749. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208750. if (item != 0)
  208751. flashMenuBar ([item menu]);
  208752. }
  208753. void updateMenus()
  208754. {
  208755. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208756. menuBarItemsChanged (0);
  208757. }
  208758. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208759. {
  208760. if (currentModel != 0)
  208761. {
  208762. if (commandManager != 0)
  208763. {
  208764. ApplicationCommandTarget::InvocationInfo info (commandId);
  208765. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208766. commandManager->invoke (info, true);
  208767. }
  208768. currentModel->menuItemSelected (commandId, topLevelIndex);
  208769. }
  208770. }
  208771. MenuBarModel* currentModel;
  208772. uint32 lastUpdateTime;
  208773. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208774. const int topLevelMenuId, const int topLevelIndex)
  208775. {
  208776. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf (T("<end>"), false, true));
  208777. if (text == 0)
  208778. text = @"";
  208779. if (iter.isSeparator)
  208780. {
  208781. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208782. }
  208783. else if (iter.isSectionHeader)
  208784. {
  208785. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208786. action: nil
  208787. keyEquivalent: @""];
  208788. [item setEnabled: false];
  208789. }
  208790. else if (iter.subMenu != 0)
  208791. {
  208792. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208793. action: nil
  208794. keyEquivalent: @""];
  208795. [item setTag: iter.itemId];
  208796. [item setEnabled: iter.isEnabled];
  208797. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208798. [sub setDelegate: nil];
  208799. [menuToAddTo setSubmenu: sub forItem: item];
  208800. [sub release];
  208801. }
  208802. else
  208803. {
  208804. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208805. action: @selector (menuItemInvoked:)
  208806. keyEquivalent: @""];
  208807. [item setTag: iter.itemId];
  208808. [item setEnabled: iter.isEnabled];
  208809. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208810. [item setTarget: (id) callback];
  208811. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208812. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208813. [item setRepresentedObject: info];
  208814. if (iter.commandManager != 0)
  208815. {
  208816. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208817. ->getKeyPressesAssignedToCommand (iter.itemId));
  208818. if (keyPresses.size() > 0)
  208819. {
  208820. const KeyPress& kp = keyPresses.getReference(0);
  208821. juce_wchar key = kp.getTextCharacter();
  208822. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208823. key = NSBackspaceCharacter;
  208824. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208825. key = NSDeleteCharacter;
  208826. else if (key == 0)
  208827. key = (juce_wchar) kp.getKeyCode();
  208828. unsigned int mods = 0;
  208829. if (kp.getModifiers().isShiftDown())
  208830. mods |= NSShiftKeyMask;
  208831. if (kp.getModifiers().isCtrlDown())
  208832. mods |= NSControlKeyMask;
  208833. if (kp.getModifiers().isAltDown())
  208834. mods |= NSAlternateKeyMask;
  208835. if (kp.getModifiers().isCommandDown())
  208836. mods |= NSCommandKeyMask;
  208837. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208838. [item setKeyEquivalentModifierMask: mods];
  208839. }
  208840. }
  208841. }
  208842. }
  208843. JuceMenuCallback* callback;
  208844. private:
  208845. NSMenu* createMenu (const PopupMenu menu,
  208846. const String& menuName,
  208847. const int topLevelMenuId,
  208848. const int topLevelIndex)
  208849. {
  208850. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208851. [m setAutoenablesItems: false];
  208852. [m setDelegate: callback];
  208853. PopupMenu::MenuItemIterator iter (menu);
  208854. while (iter.next())
  208855. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208856. [m update];
  208857. return m;
  208858. }
  208859. };
  208860. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208861. END_JUCE_NAMESPACE
  208862. @implementation JuceMenuCallback
  208863. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208864. {
  208865. [super init];
  208866. owner = owner_;
  208867. return self;
  208868. }
  208869. - (void) dealloc
  208870. {
  208871. [super dealloc];
  208872. }
  208873. - (void) menuItemInvoked: (id) menu
  208874. {
  208875. NSMenuItem* item = (NSMenuItem*) menu;
  208876. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208877. {
  208878. // 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
  208879. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208880. // into the focused component and let it trigger the menu item indirectly.
  208881. NSEvent* e = [NSApp currentEvent];
  208882. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208883. {
  208884. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent() != 0)
  208885. {
  208886. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208887. if (peer != 0)
  208888. {
  208889. if ([e type] == NSKeyDown)
  208890. peer->redirectKeyDown (e);
  208891. else
  208892. peer->redirectKeyUp (e);
  208893. return;
  208894. }
  208895. }
  208896. }
  208897. NSArray* info = (NSArray*) [item representedObject];
  208898. owner->invoke ((int) [item tag],
  208899. (ApplicationCommandManager*) (pointer_sized_int)
  208900. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208901. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208902. }
  208903. }
  208904. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208905. {
  208906. if (JuceMainMenuHandler::instance != 0)
  208907. JuceMainMenuHandler::instance->updateMenus();
  208908. }
  208909. @end
  208910. BEGIN_JUCE_NAMESPACE
  208911. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208912. const PopupMenu* extraItems)
  208913. {
  208914. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208915. {
  208916. PopupMenu::MenuItemIterator iter (*extraItems);
  208917. while (iter.next())
  208918. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208919. [menu addItem: [NSMenuItem separatorItem]];
  208920. }
  208921. NSMenuItem* item;
  208922. // Services...
  208923. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208924. action: nil keyEquivalent: @""];
  208925. [menu addItem: item];
  208926. [item release];
  208927. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208928. [menu setSubmenu: servicesMenu forItem: item];
  208929. [NSApp setServicesMenu: servicesMenu];
  208930. [servicesMenu release];
  208931. [menu addItem: [NSMenuItem separatorItem]];
  208932. // Hide + Show stuff...
  208933. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208934. action: @selector (hide:) keyEquivalent: @"h"];
  208935. [item setTarget: NSApp];
  208936. [menu addItem: item];
  208937. [item release];
  208938. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208939. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208940. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208941. [item setTarget: NSApp];
  208942. [menu addItem: item];
  208943. [item release];
  208944. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208945. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208946. [item setTarget: NSApp];
  208947. [menu addItem: item];
  208948. [item release];
  208949. [menu addItem: [NSMenuItem separatorItem]];
  208950. // Quit item....
  208951. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208952. action: @selector (terminate:) keyEquivalent: @"q"];
  208953. [item setTarget: NSApp];
  208954. [menu addItem: item];
  208955. [item release];
  208956. return menu;
  208957. }
  208958. // Since our app has no NIB, this initialises a standard app menu...
  208959. static void rebuildMainMenu (const PopupMenu* extraItems)
  208960. {
  208961. // this can't be used in a plugin!
  208962. jassert (JUCEApplication::getInstance() != 0);
  208963. if (JUCEApplication::getInstance() != 0)
  208964. {
  208965. const ScopedAutoReleasePool pool;
  208966. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208967. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208968. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208969. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208970. [mainMenu setSubmenu: appMenu forItem: item];
  208971. [NSApp setMainMenu: mainMenu];
  208972. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208973. [appMenu release];
  208974. [mainMenu release];
  208975. }
  208976. }
  208977. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208978. const PopupMenu* extraAppleMenuItems)
  208979. {
  208980. if (getMacMainMenu() != newMenuBarModel)
  208981. {
  208982. const ScopedAutoReleasePool pool;
  208983. if (newMenuBarModel == 0)
  208984. {
  208985. delete JuceMainMenuHandler::instance;
  208986. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208987. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208988. extraAppleMenuItems = 0;
  208989. }
  208990. else
  208991. {
  208992. if (JuceMainMenuHandler::instance == 0)
  208993. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208994. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208995. }
  208996. }
  208997. rebuildMainMenu (extraAppleMenuItems);
  208998. if (newMenuBarModel != 0)
  208999. newMenuBarModel->menuItemsChanged();
  209000. }
  209001. MenuBarModel* MenuBarModel::getMacMainMenu()
  209002. {
  209003. return JuceMainMenuHandler::instance != 0
  209004. ? JuceMainMenuHandler::instance->currentModel : 0;
  209005. }
  209006. void initialiseMainMenu()
  209007. {
  209008. if (JUCEApplication::getInstance() != 0) // only needed in an app
  209009. rebuildMainMenu (0);
  209010. }
  209011. #endif
  209012. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  209013. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  209014. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209015. // compiled on its own).
  209016. #if JUCE_INCLUDED_FILE
  209017. #if JUCE_MAC
  209018. END_JUCE_NAMESPACE
  209019. using namespace JUCE_NAMESPACE;
  209020. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  209021. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  209022. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  209023. #else
  209024. @interface JuceFileChooserDelegate : NSObject
  209025. #endif
  209026. {
  209027. StringArray* filters;
  209028. }
  209029. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  209030. - (void) dealloc;
  209031. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  209032. @end
  209033. @implementation JuceFileChooserDelegate
  209034. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  209035. {
  209036. [super init];
  209037. filters = filters_;
  209038. return self;
  209039. }
  209040. - (void) dealloc
  209041. {
  209042. delete filters;
  209043. [super dealloc];
  209044. }
  209045. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  209046. {
  209047. const File f (nsStringToJuce (filename));
  209048. for (int i = filters->size(); --i >= 0;)
  209049. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  209050. return true;
  209051. return f.isDirectory();
  209052. }
  209053. @end
  209054. BEGIN_JUCE_NAMESPACE
  209055. void FileChooser::showPlatformDialog (Array<File>& results,
  209056. const String& title,
  209057. const File& currentFileOrDirectory,
  209058. const String& filter,
  209059. bool selectsDirectory,
  209060. bool selectsFiles,
  209061. bool isSaveDialogue,
  209062. bool warnAboutOverwritingExistingFiles,
  209063. bool selectMultipleFiles,
  209064. FilePreviewComponent* extraInfoComponent)
  209065. {
  209066. const ScopedAutoReleasePool pool;
  209067. StringArray* filters = new StringArray();
  209068. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), String::empty);
  209069. filters->trim();
  209070. filters->removeEmptyStrings();
  209071. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  209072. [delegate autorelease];
  209073. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  209074. : [NSOpenPanel openPanel];
  209075. [panel setTitle: juceStringToNS (title)];
  209076. if (! isSaveDialogue)
  209077. {
  209078. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209079. [openPanel setCanChooseDirectories: selectsDirectory];
  209080. [openPanel setCanChooseFiles: selectsFiles];
  209081. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  209082. }
  209083. [panel setDelegate: delegate];
  209084. if (isSaveDialogue || selectsDirectory)
  209085. [panel setCanCreateDirectories: YES];
  209086. String directory, filename;
  209087. if (currentFileOrDirectory.isDirectory())
  209088. {
  209089. directory = currentFileOrDirectory.getFullPathName();
  209090. }
  209091. else
  209092. {
  209093. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  209094. filename = currentFileOrDirectory.getFileName();
  209095. }
  209096. if ([panel runModalForDirectory: juceStringToNS (directory)
  209097. file: juceStringToNS (filename)]
  209098. == NSOKButton)
  209099. {
  209100. if (isSaveDialogue)
  209101. {
  209102. results.add (File (nsStringToJuce ([panel filename])));
  209103. }
  209104. else
  209105. {
  209106. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209107. NSArray* urls = [openPanel filenames];
  209108. for (unsigned int i = 0; i < [urls count]; ++i)
  209109. {
  209110. NSString* f = [urls objectAtIndex: i];
  209111. results.add (File (nsStringToJuce (f)));
  209112. }
  209113. }
  209114. }
  209115. [panel setDelegate: nil];
  209116. }
  209117. #else
  209118. void FileChooser::showPlatformDialog (Array<File>& results,
  209119. const String& title,
  209120. const File& currentFileOrDirectory,
  209121. const String& filter,
  209122. bool selectsDirectory,
  209123. bool selectsFiles,
  209124. bool isSaveDialogue,
  209125. bool warnAboutOverwritingExistingFiles,
  209126. bool selectMultipleFiles,
  209127. FilePreviewComponent* extraInfoComponent)
  209128. {
  209129. const ScopedAutoReleasePool pool;
  209130. jassertfalse //xxx to do
  209131. }
  209132. #endif
  209133. #endif
  209134. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  209135. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209136. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209137. // compiled on its own).
  209138. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  209139. END_JUCE_NAMESPACE
  209140. #define NonInterceptingQTMovieView MakeObjCClassName(NonInterceptingQTMovieView)
  209141. @interface NonInterceptingQTMovieView : QTMovieView
  209142. {
  209143. }
  209144. - (id) initWithFrame: (NSRect) frame;
  209145. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent;
  209146. - (NSView*) hitTest: (NSPoint) p;
  209147. @end
  209148. @implementation NonInterceptingQTMovieView
  209149. - (id) initWithFrame: (NSRect) frame
  209150. {
  209151. self = [super initWithFrame: frame];
  209152. [self setNextResponder: [self superview]];
  209153. return self;
  209154. }
  209155. - (void) dealloc
  209156. {
  209157. [super dealloc];
  209158. }
  209159. - (NSView*) hitTest: (NSPoint) point
  209160. {
  209161. return [self isControllerVisible] ? [super hitTest: point] : nil;
  209162. }
  209163. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent
  209164. {
  209165. return YES;
  209166. }
  209167. @end
  209168. BEGIN_JUCE_NAMESPACE
  209169. #define theMovie (static_cast <QTMovie*> (movie))
  209170. QuickTimeMovieComponent::QuickTimeMovieComponent()
  209171. : movie (0)
  209172. {
  209173. setOpaque (true);
  209174. setVisible (true);
  209175. QTMovieView* view = [[NonInterceptingQTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  209176. setView (view);
  209177. [view release];
  209178. }
  209179. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  209180. {
  209181. closeMovie();
  209182. setView (0);
  209183. }
  209184. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  209185. {
  209186. return true;
  209187. }
  209188. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  209189. {
  209190. // unfortunately, QTMovie objects can only be created on the main thread..
  209191. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209192. QTMovie* movie = 0;
  209193. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  209194. if (fin != 0)
  209195. {
  209196. movieFile = fin->getFile();
  209197. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  209198. error: nil];
  209199. }
  209200. else
  209201. {
  209202. MemoryBlock temp;
  209203. movieStream->readIntoMemoryBlock (temp);
  209204. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  209205. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209206. {
  209207. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209208. length: temp.getSize()]
  209209. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209210. MIMEType: @""]
  209211. error: nil];
  209212. if (movie != 0)
  209213. break;
  209214. }
  209215. }
  209216. return movie;
  209217. }
  209218. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209219. const bool isControllerVisible_)
  209220. {
  209221. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209222. }
  209223. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209224. const bool controllerVisible_)
  209225. {
  209226. closeMovie();
  209227. if (getPeer() == 0)
  209228. {
  209229. // To open a movie, this component must be visible inside a functioning window, so that
  209230. // the QT control can be assigned to the window.
  209231. jassertfalse
  209232. return false;
  209233. }
  209234. movie = openMovieFromStream (movieStream, movieFile);
  209235. [theMovie retain];
  209236. QTMovieView* view = (QTMovieView*) getView();
  209237. [view setMovie: theMovie];
  209238. [view setControllerVisible: controllerVisible_];
  209239. setLooping (looping);
  209240. return movie != nil;
  209241. }
  209242. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209243. const bool isControllerVisible_)
  209244. {
  209245. // unfortunately, QTMovie objects can only be created on the main thread..
  209246. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209247. closeMovie();
  209248. if (getPeer() == 0)
  209249. {
  209250. // To open a movie, this component must be visible inside a functioning window, so that
  209251. // the QT control can be assigned to the window.
  209252. jassertfalse
  209253. return false;
  209254. }
  209255. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209256. NSError* err;
  209257. if ([QTMovie canInitWithURL: url])
  209258. movie = [QTMovie movieWithURL: url error: &err];
  209259. [theMovie retain];
  209260. QTMovieView* view = (QTMovieView*) getView();
  209261. [view setMovie: theMovie];
  209262. [view setControllerVisible: controllerVisible];
  209263. setLooping (looping);
  209264. return movie != nil;
  209265. }
  209266. void QuickTimeMovieComponent::closeMovie()
  209267. {
  209268. stop();
  209269. QTMovieView* view = (QTMovieView*) getView();
  209270. [view setMovie: nil];
  209271. [theMovie release];
  209272. movie = 0;
  209273. movieFile = File::nonexistent;
  209274. }
  209275. bool QuickTimeMovieComponent::isMovieOpen() const
  209276. {
  209277. return movie != nil;
  209278. }
  209279. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209280. {
  209281. return movieFile;
  209282. }
  209283. void QuickTimeMovieComponent::play()
  209284. {
  209285. [theMovie play];
  209286. }
  209287. void QuickTimeMovieComponent::stop()
  209288. {
  209289. [theMovie stop];
  209290. }
  209291. bool QuickTimeMovieComponent::isPlaying() const
  209292. {
  209293. return movie != 0 && [theMovie rate] != 0;
  209294. }
  209295. void QuickTimeMovieComponent::setPosition (const double seconds)
  209296. {
  209297. if (movie != 0)
  209298. {
  209299. QTTime t;
  209300. t.timeValue = (uint64) (100000.0 * seconds);
  209301. t.timeScale = 100000;
  209302. t.flags = 0;
  209303. [theMovie setCurrentTime: t];
  209304. }
  209305. }
  209306. double QuickTimeMovieComponent::getPosition() const
  209307. {
  209308. if (movie == 0)
  209309. return 0.0;
  209310. QTTime t = [theMovie currentTime];
  209311. return t.timeValue / (double) t.timeScale;
  209312. }
  209313. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209314. {
  209315. [theMovie setRate: newSpeed];
  209316. }
  209317. double QuickTimeMovieComponent::getMovieDuration() const
  209318. {
  209319. if (movie == 0)
  209320. return 0.0;
  209321. QTTime t = [theMovie duration];
  209322. return t.timeValue / (double) t.timeScale;
  209323. }
  209324. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209325. {
  209326. looping = shouldLoop;
  209327. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209328. forKey: QTMovieLoopsAttribute];
  209329. }
  209330. bool QuickTimeMovieComponent::isLooping() const
  209331. {
  209332. return looping;
  209333. }
  209334. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209335. {
  209336. [theMovie setVolume: newVolume];
  209337. }
  209338. float QuickTimeMovieComponent::getMovieVolume() const
  209339. {
  209340. return movie != 0 ? [theMovie volume] : 0.0f;
  209341. }
  209342. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209343. {
  209344. width = 0;
  209345. height = 0;
  209346. if (movie != 0)
  209347. {
  209348. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209349. width = (int) s.width;
  209350. height = (int) s.height;
  209351. }
  209352. }
  209353. void QuickTimeMovieComponent::paint (Graphics& g)
  209354. {
  209355. if (movie == 0)
  209356. g.fillAll (Colours::black);
  209357. }
  209358. bool QuickTimeMovieComponent::isControllerVisible() const
  209359. {
  209360. return controllerVisible;
  209361. }
  209362. void QuickTimeMovieComponent::goToStart()
  209363. {
  209364. setPosition (0.0);
  209365. }
  209366. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209367. const RectanglePlacement& placement)
  209368. {
  209369. int normalWidth, normalHeight;
  209370. getMovieNormalSize (normalWidth, normalHeight);
  209371. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209372. {
  209373. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209374. placement.applyTo (x, y, w, h,
  209375. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209376. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209377. if (w > 0 && h > 0)
  209378. {
  209379. setBounds (roundToInt (x), roundToInt (y),
  209380. roundToInt (w), roundToInt (h));
  209381. }
  209382. }
  209383. else
  209384. {
  209385. setBounds (spaceToFitWithin);
  209386. }
  209387. }
  209388. #if ! (JUCE_MAC && JUCE_64BIT)
  209389. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209390. {
  209391. if (movieStream == 0)
  209392. return false;
  209393. File file;
  209394. QTMovie* movie = openMovieFromStream (movieStream, file);
  209395. if (movie != nil)
  209396. result = [movie quickTimeMovie];
  209397. return movie != nil;
  209398. }
  209399. #endif
  209400. #endif
  209401. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209402. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209403. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209404. // compiled on its own).
  209405. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209406. const int kilobytesPerSecond1x = 176;
  209407. END_JUCE_NAMESPACE
  209408. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209409. @interface OpenDiskDevice : NSObject
  209410. {
  209411. @public
  209412. DRDevice* device;
  209413. NSMutableArray* tracks;
  209414. bool underrunProtection;
  209415. }
  209416. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device;
  209417. - (void) dealloc;
  209418. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209419. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209420. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed;
  209421. @end
  209422. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209423. @interface AudioTrackProducer : NSObject
  209424. {
  209425. JUCE_NAMESPACE::AudioSource* source;
  209426. int readPosition, lengthInFrames;
  209427. }
  209428. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209429. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209430. - (void) dealloc;
  209431. - (void) setupTrackProperties: (DRTrack*) track;
  209432. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209433. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209434. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209435. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209436. toMedia:(NSDictionary*)mediaInfo;
  209437. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209438. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209439. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209440. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209441. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209442. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209443. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209444. ioFlags:(uint32_t*)flags;
  209445. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209446. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209447. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209448. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209449. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209450. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209451. ioFlags:(uint32_t*)flags;
  209452. @end
  209453. @implementation OpenDiskDevice
  209454. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device_
  209455. {
  209456. [super init];
  209457. device = device_;
  209458. tracks = [[NSMutableArray alloc] init];
  209459. underrunProtection = true;
  209460. return self;
  209461. }
  209462. - (void) dealloc
  209463. {
  209464. [tracks release];
  209465. [super dealloc];
  209466. }
  209467. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209468. {
  209469. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209470. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209471. [p setupTrackProperties: t];
  209472. [tracks addObject: t];
  209473. [t release];
  209474. [p release];
  209475. }
  209476. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209477. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed
  209478. {
  209479. DRBurn* burn = [DRBurn burnForDevice: device];
  209480. if (! [device acquireExclusiveAccess])
  209481. {
  209482. *error = "Couldn't open or write to the CD device";
  209483. return;
  209484. }
  209485. [device acquireMediaReservation];
  209486. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209487. [d autorelease];
  209488. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209489. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209490. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount) forKey: DRBurnCompletionActionKey];
  209491. if (burnSpeed > 0)
  209492. [d setObject: [NSNumber numberWithFloat: burnSpeed * JUCE_NAMESPACE::kilobytesPerSecond1x] forKey: DRBurnRequestedSpeedKey];
  209493. if (! underrunProtection)
  209494. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnUnderrunProtectionKey];
  209495. [burn setProperties: d];
  209496. [burn writeLayout: tracks];
  209497. for (;;)
  209498. {
  209499. JUCE_NAMESPACE::Thread::sleep (300);
  209500. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209501. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209502. {
  209503. [burn abort];
  209504. *error = "User cancelled the write operation";
  209505. break;
  209506. }
  209507. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209508. {
  209509. *error = "Write operation failed";
  209510. break;
  209511. }
  209512. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209513. {
  209514. break;
  209515. }
  209516. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209517. objectForKey: DRErrorStatusErrorStringKey];
  209518. if ([err length] > 0)
  209519. {
  209520. *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]);
  209521. break;
  209522. }
  209523. }
  209524. [device releaseMediaReservation];
  209525. [device releaseExclusiveAccess];
  209526. }
  209527. @end
  209528. @implementation AudioTrackProducer
  209529. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209530. {
  209531. lengthInFrames = lengthInFrames_;
  209532. readPosition = 0;
  209533. return self;
  209534. }
  209535. - (void) setupTrackProperties: (DRTrack*) track
  209536. {
  209537. NSMutableDictionary* p = [[track properties] mutableCopy];
  209538. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209539. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209540. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209541. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209542. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209543. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209544. [track setProperties: p];
  209545. [p release];
  209546. }
  209547. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209548. {
  209549. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209550. if (s != nil)
  209551. s->source = source_;
  209552. return s;
  209553. }
  209554. - (void) dealloc
  209555. {
  209556. if (source != 0)
  209557. {
  209558. source->releaseResources();
  209559. delete source;
  209560. }
  209561. [super dealloc];
  209562. }
  209563. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209564. {
  209565. }
  209566. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209567. {
  209568. return true;
  209569. }
  209570. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209571. {
  209572. return lengthInFrames;
  209573. }
  209574. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209575. toMedia: (NSDictionary*) mediaInfo
  209576. {
  209577. if (source != 0)
  209578. source->prepareToPlay (44100 / 75, 44100);
  209579. readPosition = 0;
  209580. return true;
  209581. }
  209582. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209583. {
  209584. if (source != 0)
  209585. source->prepareToPlay (44100 / 75, 44100);
  209586. return true;
  209587. }
  209588. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209589. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209590. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209591. {
  209592. if (source != 0)
  209593. {
  209594. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209595. if (numSamples > 0)
  209596. {
  209597. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209598. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209599. info.buffer = &tempBuffer;
  209600. info.startSample = 0;
  209601. info.numSamples = numSamples;
  209602. source->getNextAudioBlock (info);
  209603. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209604. buffer, numSamples, 4);
  209605. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209606. buffer + 2, numSamples, 4);
  209607. readPosition += numSamples;
  209608. }
  209609. return numSamples * 4;
  209610. }
  209611. return 0;
  209612. }
  209613. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209614. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209615. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209616. ioFlags: (uint32_t*) flags
  209617. {
  209618. zeromem (buffer, bufferLength);
  209619. return bufferLength;
  209620. }
  209621. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209622. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209623. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209624. {
  209625. return true;
  209626. }
  209627. @end
  209628. BEGIN_JUCE_NAMESPACE
  209629. class AudioCDBurner::Pimpl : public Timer
  209630. {
  209631. public:
  209632. Pimpl (AudioCDBurner& owner_, const int deviceIndex)
  209633. : device (0), owner (owner_)
  209634. {
  209635. DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex];
  209636. if (dev != 0)
  209637. {
  209638. device = [[OpenDiskDevice alloc] initWithDRDevice: dev];
  209639. lastState = getDiskState();
  209640. startTimer (1000);
  209641. }
  209642. }
  209643. ~Pimpl()
  209644. {
  209645. stopTimer();
  209646. [device release];
  209647. }
  209648. void timerCallback()
  209649. {
  209650. const DiskState state = getDiskState();
  209651. if (state != lastState)
  209652. {
  209653. lastState = state;
  209654. owner.sendChangeMessage (&owner);
  209655. }
  209656. }
  209657. DiskState getDiskState() const
  209658. {
  209659. if ([device->device isValid])
  209660. {
  209661. NSDictionary* status = [device->device status];
  209662. NSString* state = [status objectForKey: DRDeviceMediaStateKey];
  209663. if ([state isEqualTo: DRDeviceMediaStateNone])
  209664. {
  209665. if ([[status objectForKey: DRDeviceIsTrayOpenKey] boolValue])
  209666. return trayOpen;
  209667. return noDisc;
  209668. }
  209669. if ([state isEqualTo: DRDeviceMediaStateMediaPresent])
  209670. {
  209671. if ([[[status objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceMediaBlocksFreeKey] intValue] > 0)
  209672. return writableDiskPresent;
  209673. else
  209674. return readOnlyDiskPresent;
  209675. }
  209676. }
  209677. return unknown;
  209678. }
  209679. bool openTray() { return [device->device isValid] && [device->device ejectMedia]; }
  209680. const Array<int> getAvailableWriteSpeeds() const
  209681. {
  209682. Array<int> results;
  209683. if ([device->device isValid])
  209684. {
  209685. NSArray* speeds = [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey];
  209686. for (unsigned int i = 0; i < [speeds count]; ++i)
  209687. {
  209688. const int kbPerSec = [[speeds objectAtIndex: i] intValue];
  209689. results.add (kbPerSec / kilobytesPerSecond1x);
  209690. }
  209691. }
  209692. return results;
  209693. }
  209694. bool setBufferUnderrunProtection (const bool shouldBeEnabled)
  209695. {
  209696. if ([device->device isValid])
  209697. {
  209698. device->underrunProtection = shouldBeEnabled;
  209699. return shouldBeEnabled && [[[device->device status] objectForKey: DRDeviceCanUnderrunProtectCDKey] boolValue];
  209700. }
  209701. return false;
  209702. }
  209703. int getNumAvailableAudioBlocks() const
  209704. {
  209705. return [[[[device->device status] objectForKey: DRDeviceMediaInfoKey]
  209706. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209707. }
  209708. OpenDiskDevice* device;
  209709. private:
  209710. DiskState lastState;
  209711. AudioCDBurner& owner;
  209712. };
  209713. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209714. {
  209715. pimpl = new Pimpl (*this, deviceIndex);
  209716. }
  209717. AudioCDBurner::~AudioCDBurner()
  209718. {
  209719. }
  209720. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209721. {
  209722. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209723. if (b->pimpl->device == 0)
  209724. b = 0;
  209725. return b.release();
  209726. }
  209727. static NSArray* findDiskBurnerDevices()
  209728. {
  209729. NSMutableArray* results = [NSMutableArray array];
  209730. NSArray* devs = [DRDevice devices];
  209731. if (devs != 0)
  209732. {
  209733. int num = [devs count];
  209734. int i;
  209735. for (i = 0; i < num; ++i)
  209736. {
  209737. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209738. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209739. if (name != nil)
  209740. [results addObject: name];
  209741. }
  209742. }
  209743. return results;
  209744. }
  209745. const StringArray AudioCDBurner::findAvailableDevices()
  209746. {
  209747. NSArray* names = findDiskBurnerDevices();
  209748. StringArray s;
  209749. for (unsigned int i = 0; i < [names count]; ++i)
  209750. s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String]));
  209751. return s;
  209752. }
  209753. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  209754. {
  209755. return pimpl->getDiskState();
  209756. }
  209757. bool AudioCDBurner::isDiskPresent() const
  209758. {
  209759. return getDiskState() == writableDiskPresent;
  209760. }
  209761. bool AudioCDBurner::openTray()
  209762. {
  209763. return pimpl->openTray();
  209764. }
  209765. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  209766. {
  209767. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  209768. DiskState oldState = getDiskState();
  209769. DiskState newState = oldState;
  209770. while (newState == oldState && Time::currentTimeMillis() < timeout)
  209771. {
  209772. newState = getDiskState();
  209773. Thread::sleep (100);
  209774. }
  209775. return newState;
  209776. }
  209777. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  209778. {
  209779. return pimpl->getAvailableWriteSpeeds();
  209780. }
  209781. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  209782. {
  209783. return pimpl->setBufferUnderrunProtection (shouldBeEnabled);
  209784. }
  209785. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209786. {
  209787. return pimpl->getNumAvailableAudioBlocks();
  209788. }
  209789. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209790. {
  209791. if ([pimpl->device->device isValid])
  209792. {
  209793. [pimpl->device addSourceTrack: source numSamples: numSamps];
  209794. return true;
  209795. }
  209796. return false;
  209797. }
  209798. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209799. bool ejectDiscAfterwards,
  209800. bool performFakeBurnForTesting,
  209801. int writeSpeed)
  209802. {
  209803. String error ("Couldn't open or write to the CD device");
  209804. if ([pimpl->device->device isValid])
  209805. {
  209806. error = String::empty;
  209807. [pimpl->device burn: listener
  209808. errorString: &error
  209809. ejectAfterwards: ejectDiscAfterwards
  209810. isFake: performFakeBurnForTesting
  209811. speed: writeSpeed];
  209812. }
  209813. return error;
  209814. }
  209815. #endif
  209816. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  209817. void AudioCDReader::ejectDisk()
  209818. {
  209819. const ScopedAutoReleasePool p;
  209820. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209821. }
  209822. #endif
  209823. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209824. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209825. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209826. // compiled on its own).
  209827. #if JUCE_INCLUDED_FILE
  209828. class AppDelegateRedirector
  209829. {
  209830. public:
  209831. AppDelegateRedirector()
  209832. {
  209833. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209834. runLoop = CFRunLoopGetMain();
  209835. #else
  209836. runLoop = CFRunLoopGetCurrent();
  209837. #endif
  209838. CFRunLoopSourceContext sourceContext;
  209839. zerostruct (sourceContext);
  209840. sourceContext.info = this;
  209841. sourceContext.perform = runLoopSourceCallback;
  209842. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209843. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209844. }
  209845. virtual ~AppDelegateRedirector()
  209846. {
  209847. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209848. CFRunLoopSourceInvalidate (runLoopSource);
  209849. CFRelease (runLoopSource);
  209850. while (messages.size() > 0)
  209851. delete ((Message*) messages.remove(0));
  209852. }
  209853. virtual NSApplicationTerminateReply shouldTerminate()
  209854. {
  209855. if (JUCEApplication::getInstance() != 0)
  209856. {
  209857. JUCEApplication::getInstance()->systemRequestedQuit();
  209858. return NSTerminateCancel;
  209859. }
  209860. return NSTerminateNow;
  209861. }
  209862. virtual BOOL openFile (const NSString* filename)
  209863. {
  209864. if (JUCEApplication::getInstance() != 0)
  209865. {
  209866. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209867. return YES;
  209868. }
  209869. return NO;
  209870. }
  209871. virtual void openFiles (NSArray* filenames)
  209872. {
  209873. StringArray files;
  209874. for (unsigned int i = 0; i < [filenames count]; ++i)
  209875. {
  209876. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209877. if (filename.containsChar (T(' ')))
  209878. filename = filename.quoted('"');
  209879. files.add (filename);
  209880. }
  209881. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209882. {
  209883. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
  209884. }
  209885. }
  209886. virtual void focusChanged()
  209887. {
  209888. juce_HandleProcessFocusChange();
  209889. }
  209890. struct CallbackMessagePayload
  209891. {
  209892. MessageCallbackFunction* function;
  209893. void* parameter;
  209894. void* volatile result;
  209895. bool volatile hasBeenExecuted;
  209896. };
  209897. virtual void performCallback (CallbackMessagePayload* pl)
  209898. {
  209899. pl->result = (*pl->function) (pl->parameter);
  209900. pl->hasBeenExecuted = true;
  209901. }
  209902. virtual void deleteSelf()
  209903. {
  209904. delete this;
  209905. }
  209906. void postMessage (void* m)
  209907. {
  209908. messages.add (m);
  209909. CFRunLoopSourceSignal (runLoopSource);
  209910. CFRunLoopWakeUp (runLoop);
  209911. }
  209912. private:
  209913. CFRunLoopRef runLoop;
  209914. CFRunLoopSourceRef runLoopSource;
  209915. Array <void*, CriticalSection> messages;
  209916. void runLoopCallback()
  209917. {
  209918. int numDispatched = 0;
  209919. do
  209920. {
  209921. void* const nextMessage = messages.remove (0);
  209922. if (nextMessage == 0)
  209923. return;
  209924. const ScopedAutoReleasePool pool;
  209925. MessageManager::getInstance()->deliverMessage (nextMessage);
  209926. } while (++numDispatched <= 4);
  209927. CFRunLoopSourceSignal (runLoopSource);
  209928. CFRunLoopWakeUp (runLoop);
  209929. }
  209930. static void runLoopSourceCallback (void* info)
  209931. {
  209932. ((AppDelegateRedirector*) info)->runLoopCallback();
  209933. }
  209934. };
  209935. END_JUCE_NAMESPACE
  209936. using namespace JUCE_NAMESPACE;
  209937. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209938. @interface JuceAppDelegate : NSObject
  209939. {
  209940. @private
  209941. id oldDelegate;
  209942. @public
  209943. AppDelegateRedirector* redirector;
  209944. }
  209945. - (JuceAppDelegate*) init;
  209946. - (void) dealloc;
  209947. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209948. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209949. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209950. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209951. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209952. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209953. - (void) performCallback: (id) info;
  209954. - (void) dummyMethod;
  209955. @end
  209956. @implementation JuceAppDelegate
  209957. - (JuceAppDelegate*) init
  209958. {
  209959. [super init];
  209960. redirector = new AppDelegateRedirector();
  209961. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209962. if (JUCEApplication::getInstance() != 0)
  209963. {
  209964. oldDelegate = [NSApp delegate];
  209965. [NSApp setDelegate: self];
  209966. }
  209967. else
  209968. {
  209969. oldDelegate = 0;
  209970. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209971. name: NSApplicationDidResignActiveNotification object: NSApp];
  209972. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209973. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209974. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209975. name: NSApplicationWillUnhideNotification object: NSApp];
  209976. }
  209977. return self;
  209978. }
  209979. - (void) dealloc
  209980. {
  209981. if (oldDelegate != 0)
  209982. [NSApp setDelegate: oldDelegate];
  209983. redirector->deleteSelf();
  209984. [super dealloc];
  209985. }
  209986. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209987. {
  209988. return redirector->shouldTerminate();
  209989. }
  209990. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209991. {
  209992. return redirector->openFile (filename);
  209993. }
  209994. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209995. {
  209996. return redirector->openFiles (filenames);
  209997. }
  209998. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209999. {
  210000. redirector->focusChanged();
  210001. }
  210002. - (void) applicationDidResignActive: (NSNotification*) aNotification
  210003. {
  210004. redirector->focusChanged();
  210005. }
  210006. - (void) applicationWillUnhide: (NSNotification*) aNotification
  210007. {
  210008. redirector->focusChanged();
  210009. }
  210010. - (void) performCallback: (id) info
  210011. {
  210012. if ([info isKindOfClass: [NSData class]])
  210013. {
  210014. AppDelegateRedirector::CallbackMessagePayload* pl
  210015. = (AppDelegateRedirector::CallbackMessagePayload*) [((NSData*) info) bytes];
  210016. if (pl != 0)
  210017. redirector->performCallback (pl);
  210018. }
  210019. else
  210020. {
  210021. jassertfalse // should never get here!
  210022. }
  210023. }
  210024. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  210025. @end
  210026. BEGIN_JUCE_NAMESPACE
  210027. static JuceAppDelegate* juceAppDelegate = 0;
  210028. void MessageManager::runDispatchLoop()
  210029. {
  210030. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  210031. {
  210032. const ScopedAutoReleasePool pool;
  210033. // must only be called by the message thread!
  210034. jassert (isThisTheMessageThread());
  210035. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  210036. @try
  210037. {
  210038. [NSApp run];
  210039. }
  210040. @catch (NSException* e)
  210041. {
  210042. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  210043. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  210044. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  210045. }
  210046. @finally
  210047. {
  210048. }
  210049. #else
  210050. [NSApp run];
  210051. #endif
  210052. }
  210053. }
  210054. void MessageManager::stopDispatchLoop()
  210055. {
  210056. quitMessagePosted = true;
  210057. [NSApp stop: nil];
  210058. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  210059. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  210060. }
  210061. static bool isEventBlockedByModalComps (NSEvent* e)
  210062. {
  210063. if (Component::getNumCurrentlyModalComponents() == 0)
  210064. return false;
  210065. NSWindow* const w = [e window];
  210066. if (w == 0 || [w worksWhenModal])
  210067. return false;
  210068. bool isKey = false, isInputAttempt = false;
  210069. switch ([e type])
  210070. {
  210071. case NSKeyDown:
  210072. case NSKeyUp:
  210073. isKey = isInputAttempt = true;
  210074. break;
  210075. case NSLeftMouseDown:
  210076. case NSRightMouseDown:
  210077. case NSOtherMouseDown:
  210078. isInputAttempt = true;
  210079. break;
  210080. case NSLeftMouseDragged:
  210081. case NSRightMouseDragged:
  210082. case NSLeftMouseUp:
  210083. case NSRightMouseUp:
  210084. case NSOtherMouseUp:
  210085. case NSOtherMouseDragged:
  210086. if (Desktop::getInstance().getDraggingMouseSource(0) != 0)
  210087. return false;
  210088. break;
  210089. case NSMouseMoved:
  210090. case NSMouseEntered:
  210091. case NSMouseExited:
  210092. case NSCursorUpdate:
  210093. case NSScrollWheel:
  210094. case NSTabletPoint:
  210095. case NSTabletProximity:
  210096. break;
  210097. default:
  210098. return false;
  210099. }
  210100. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  210101. {
  210102. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  210103. NSView* const compView = (NSView*) peer->getNativeHandle();
  210104. if ([compView window] == w)
  210105. {
  210106. if (isKey)
  210107. {
  210108. if (compView == [w firstResponder])
  210109. return false;
  210110. }
  210111. else
  210112. {
  210113. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  210114. [compView bounds]))
  210115. return false;
  210116. }
  210117. }
  210118. }
  210119. if (isInputAttempt)
  210120. {
  210121. if (! [NSApp isActive])
  210122. [NSApp activateIgnoringOtherApps: YES];
  210123. Component* const modal = Component::getCurrentlyModalComponent (0);
  210124. if (modal != 0)
  210125. modal->inputAttemptWhenModal();
  210126. }
  210127. return true;
  210128. }
  210129. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  210130. {
  210131. const ScopedAutoReleasePool pool;
  210132. jassert (isThisTheMessageThread()); // must only be called by the message thread
  210133. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  210134. while (! quitMessagePosted)
  210135. {
  210136. const ScopedAutoReleasePool pool2;
  210137. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  210138. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  210139. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  210140. inMode: NSDefaultRunLoopMode
  210141. dequeue: YES];
  210142. if (e != 0 && ! isEventBlockedByModalComps (e))
  210143. [NSApp sendEvent: e];
  210144. if (Time::getMillisecondCounter() >= endTime)
  210145. break;
  210146. }
  210147. return ! quitMessagePosted;
  210148. }
  210149. void MessageManager::doPlatformSpecificInitialisation()
  210150. {
  210151. if (juceAppDelegate == 0)
  210152. juceAppDelegate = [[JuceAppDelegate alloc] init];
  210153. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  210154. // correctly (needed prior to 10.5)
  210155. if (! [NSThread isMultiThreaded])
  210156. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  210157. toTarget: juceAppDelegate
  210158. withObject: nil];
  210159. initialiseMainMenu();
  210160. }
  210161. void MessageManager::doPlatformSpecificShutdown()
  210162. {
  210163. if (juceAppDelegate != 0)
  210164. {
  210165. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  210166. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  210167. [juceAppDelegate release];
  210168. juceAppDelegate = 0;
  210169. }
  210170. }
  210171. bool juce_postMessageToSystemQueue (void* message)
  210172. {
  210173. juceAppDelegate->redirector->postMessage (message);
  210174. return true;
  210175. }
  210176. void MessageManager::broadcastMessage (const String& value) throw()
  210177. {
  210178. }
  210179. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  210180. void* data)
  210181. {
  210182. if (isThisTheMessageThread())
  210183. {
  210184. return (*callback) (data);
  210185. }
  210186. else
  210187. {
  210188. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  210189. // deadlock because the message manager is blocked from running, so can never
  210190. // call your function..
  210191. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  210192. const ScopedAutoReleasePool pool;
  210193. AppDelegateRedirector::CallbackMessagePayload cmp;
  210194. cmp.function = callback;
  210195. cmp.parameter = data;
  210196. cmp.result = 0;
  210197. cmp.hasBeenExecuted = false;
  210198. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  210199. withObject: [NSData dataWithBytesNoCopy: &cmp
  210200. length: sizeof (cmp)
  210201. freeWhenDone: NO]
  210202. waitUntilDone: YES];
  210203. return cmp.result;
  210204. }
  210205. }
  210206. #endif
  210207. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  210208. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210209. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210210. // compiled on its own).
  210211. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  210212. #if JUCE_MAC
  210213. END_JUCE_NAMESPACE
  210214. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  210215. @interface DownloadClickDetector : NSObject
  210216. {
  210217. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  210218. }
  210219. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  210220. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210221. request: (NSURLRequest*) request
  210222. frame: (WebFrame*) frame
  210223. decisionListener: (id<WebPolicyDecisionListener>) listener;
  210224. @end
  210225. @implementation DownloadClickDetector
  210226. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  210227. {
  210228. [super init];
  210229. ownerComponent = ownerComponent_;
  210230. return self;
  210231. }
  210232. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210233. request: (NSURLRequest*) request
  210234. frame: (WebFrame*) frame
  210235. decisionListener: (id <WebPolicyDecisionListener>) listener
  210236. {
  210237. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  210238. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  210239. [listener use];
  210240. else
  210241. [listener ignore];
  210242. }
  210243. @end
  210244. BEGIN_JUCE_NAMESPACE
  210245. class WebBrowserComponentInternal : public NSViewComponent
  210246. {
  210247. public:
  210248. WebBrowserComponentInternal (WebBrowserComponent* owner)
  210249. {
  210250. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  210251. frameName: @""
  210252. groupName: @""];
  210253. setView (webView);
  210254. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  210255. [webView setPolicyDelegate: clickListener];
  210256. }
  210257. ~WebBrowserComponentInternal()
  210258. {
  210259. [webView setPolicyDelegate: nil];
  210260. [clickListener release];
  210261. setView (0);
  210262. }
  210263. void goToURL (const String& url,
  210264. const StringArray* headers,
  210265. const MemoryBlock* postData)
  210266. {
  210267. NSMutableURLRequest* r
  210268. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210269. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210270. timeoutInterval: 30.0];
  210271. if (postData != 0 && postData->getSize() > 0)
  210272. {
  210273. [r setHTTPMethod: @"POST"];
  210274. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210275. length: postData->getSize()]];
  210276. }
  210277. if (headers != 0)
  210278. {
  210279. for (int i = 0; i < headers->size(); ++i)
  210280. {
  210281. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  210282. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  210283. [r setValue: juceStringToNS (headerValue)
  210284. forHTTPHeaderField: juceStringToNS (headerName)];
  210285. }
  210286. }
  210287. stop();
  210288. [[webView mainFrame] loadRequest: r];
  210289. }
  210290. void goBack()
  210291. {
  210292. [webView goBack];
  210293. }
  210294. void goForward()
  210295. {
  210296. [webView goForward];
  210297. }
  210298. void stop()
  210299. {
  210300. [webView stopLoading: nil];
  210301. }
  210302. void refresh()
  210303. {
  210304. [webView reload: nil];
  210305. }
  210306. private:
  210307. WebView* webView;
  210308. DownloadClickDetector* clickListener;
  210309. };
  210310. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210311. : browser (0),
  210312. blankPageShown (false),
  210313. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210314. {
  210315. setOpaque (true);
  210316. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210317. }
  210318. WebBrowserComponent::~WebBrowserComponent()
  210319. {
  210320. deleteAndZero (browser);
  210321. }
  210322. void WebBrowserComponent::goToURL (const String& url,
  210323. const StringArray* headers,
  210324. const MemoryBlock* postData)
  210325. {
  210326. lastURL = url;
  210327. lastHeaders.clear();
  210328. if (headers != 0)
  210329. lastHeaders = *headers;
  210330. lastPostData.setSize (0);
  210331. if (postData != 0)
  210332. lastPostData = *postData;
  210333. blankPageShown = false;
  210334. browser->goToURL (url, headers, postData);
  210335. }
  210336. void WebBrowserComponent::stop()
  210337. {
  210338. browser->stop();
  210339. }
  210340. void WebBrowserComponent::goBack()
  210341. {
  210342. lastURL = String::empty;
  210343. blankPageShown = false;
  210344. browser->goBack();
  210345. }
  210346. void WebBrowserComponent::goForward()
  210347. {
  210348. lastURL = String::empty;
  210349. browser->goForward();
  210350. }
  210351. void WebBrowserComponent::refresh()
  210352. {
  210353. browser->refresh();
  210354. }
  210355. void WebBrowserComponent::paint (Graphics& g)
  210356. {
  210357. }
  210358. void WebBrowserComponent::checkWindowAssociation()
  210359. {
  210360. if (isShowing())
  210361. {
  210362. if (blankPageShown)
  210363. goBack();
  210364. }
  210365. else
  210366. {
  210367. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210368. {
  210369. // when the component becomes invisible, some stuff like flash
  210370. // carries on playing audio, so we need to force it onto a blank
  210371. // page to avoid this, (and send it back when it's made visible again).
  210372. blankPageShown = true;
  210373. browser->goToURL ("about:blank", 0, 0);
  210374. }
  210375. }
  210376. }
  210377. void WebBrowserComponent::reloadLastURL()
  210378. {
  210379. if (lastURL.isNotEmpty())
  210380. {
  210381. goToURL (lastURL, &lastHeaders, &lastPostData);
  210382. lastURL = String::empty;
  210383. }
  210384. }
  210385. void WebBrowserComponent::parentHierarchyChanged()
  210386. {
  210387. checkWindowAssociation();
  210388. }
  210389. void WebBrowserComponent::resized()
  210390. {
  210391. browser->setSize (getWidth(), getHeight());
  210392. }
  210393. void WebBrowserComponent::visibilityChanged()
  210394. {
  210395. checkWindowAssociation();
  210396. }
  210397. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210398. {
  210399. return true;
  210400. }
  210401. #else
  210402. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210403. {
  210404. }
  210405. WebBrowserComponent::~WebBrowserComponent()
  210406. {
  210407. }
  210408. void WebBrowserComponent::goToURL (const String& url,
  210409. const StringArray* headers,
  210410. const MemoryBlock* postData)
  210411. {
  210412. }
  210413. void WebBrowserComponent::stop()
  210414. {
  210415. }
  210416. void WebBrowserComponent::goBack()
  210417. {
  210418. }
  210419. void WebBrowserComponent::goForward()
  210420. {
  210421. }
  210422. void WebBrowserComponent::refresh()
  210423. {
  210424. }
  210425. void WebBrowserComponent::paint (Graphics& g)
  210426. {
  210427. }
  210428. void WebBrowserComponent::checkWindowAssociation()
  210429. {
  210430. }
  210431. void WebBrowserComponent::reloadLastURL()
  210432. {
  210433. }
  210434. void WebBrowserComponent::parentHierarchyChanged()
  210435. {
  210436. }
  210437. void WebBrowserComponent::resized()
  210438. {
  210439. }
  210440. void WebBrowserComponent::visibilityChanged()
  210441. {
  210442. }
  210443. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210444. {
  210445. return true;
  210446. }
  210447. #endif
  210448. #endif
  210449. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210450. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210451. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210452. // compiled on its own).
  210453. #if JUCE_INCLUDED_FILE
  210454. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210455. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210456. #endif
  210457. #undef log
  210458. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210459. #define log(a) Logger::writeToLog (a)
  210460. #else
  210461. #define log(a)
  210462. #endif
  210463. #undef OK
  210464. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210465. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210466. {
  210467. if (err == noErr)
  210468. return true;
  210469. Logger::writeToLog (T("CoreAudio error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  210470. jassertfalse
  210471. return false;
  210472. }
  210473. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210474. #else
  210475. #define OK(a) (a == noErr)
  210476. #endif
  210477. class CoreAudioInternal : public Timer
  210478. {
  210479. public:
  210480. CoreAudioInternal (AudioDeviceID id)
  210481. : inputLatency (0),
  210482. outputLatency (0),
  210483. callback (0),
  210484. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210485. audioProcID (0),
  210486. #endif
  210487. inputDevice (0),
  210488. isSlaveDevice (false),
  210489. deviceID (id),
  210490. started (false),
  210491. sampleRate (0),
  210492. bufferSize (512),
  210493. numInputChans (0),
  210494. numOutputChans (0),
  210495. callbacksAllowed (true),
  210496. numInputChannelInfos (0),
  210497. numOutputChannelInfos (0)
  210498. {
  210499. jassert (deviceID != 0);
  210500. updateDetailsFromDevice();
  210501. AudioObjectPropertyAddress pa;
  210502. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210503. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210504. pa.mElement = kAudioObjectPropertyElementWildcard;
  210505. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210506. }
  210507. ~CoreAudioInternal()
  210508. {
  210509. AudioObjectPropertyAddress pa;
  210510. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210511. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210512. pa.mElement = kAudioObjectPropertyElementWildcard;
  210513. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210514. stop (false);
  210515. delete inputDevice;
  210516. }
  210517. void allocateTempBuffers()
  210518. {
  210519. const int tempBufSize = bufferSize + 4;
  210520. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210521. tempInputBuffers.calloc (numInputChans + 2);
  210522. tempOutputBuffers.calloc (numOutputChans + 2);
  210523. int i, count = 0;
  210524. for (i = 0; i < numInputChans; ++i)
  210525. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210526. for (i = 0; i < numOutputChans; ++i)
  210527. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210528. }
  210529. // returns the number of actual available channels
  210530. void fillInChannelInfo (const bool input)
  210531. {
  210532. int chanNum = 0;
  210533. UInt32 size;
  210534. AudioObjectPropertyAddress pa;
  210535. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210536. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210537. pa.mElement = kAudioObjectPropertyElementMaster;
  210538. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210539. {
  210540. HeapBlock <AudioBufferList> bufList;
  210541. bufList.calloc (size, 1);
  210542. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210543. {
  210544. const int numStreams = bufList->mNumberBuffers;
  210545. for (int i = 0; i < numStreams; ++i)
  210546. {
  210547. const AudioBuffer& b = bufList->mBuffers[i];
  210548. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210549. {
  210550. String name;
  210551. {
  210552. char channelName [256];
  210553. zerostruct (channelName);
  210554. UInt32 nameSize = sizeof (channelName);
  210555. UInt32 channelNum = chanNum + 1;
  210556. pa.mSelector = kAudioDevicePropertyChannelName;
  210557. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210558. name = String::fromUTF8 (channelName, nameSize);
  210559. }
  210560. if (input)
  210561. {
  210562. if (activeInputChans[chanNum])
  210563. {
  210564. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210565. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210566. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210567. ++numInputChannelInfos;
  210568. }
  210569. if (name.isEmpty())
  210570. name << "Input " << (chanNum + 1);
  210571. inChanNames.add (name);
  210572. }
  210573. else
  210574. {
  210575. if (activeOutputChans[chanNum])
  210576. {
  210577. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210578. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210579. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210580. ++numOutputChannelInfos;
  210581. }
  210582. if (name.isEmpty())
  210583. name << "Output " << (chanNum + 1);
  210584. outChanNames.add (name);
  210585. }
  210586. ++chanNum;
  210587. }
  210588. }
  210589. }
  210590. }
  210591. }
  210592. void updateDetailsFromDevice()
  210593. {
  210594. stopTimer();
  210595. if (deviceID == 0)
  210596. return;
  210597. const ScopedLock sl (callbackLock);
  210598. Float64 sr;
  210599. UInt32 size = sizeof (Float64);
  210600. AudioObjectPropertyAddress pa;
  210601. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210602. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210603. pa.mElement = kAudioObjectPropertyElementMaster;
  210604. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210605. sampleRate = sr;
  210606. UInt32 framesPerBuf;
  210607. size = sizeof (framesPerBuf);
  210608. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210609. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210610. {
  210611. bufferSize = framesPerBuf;
  210612. allocateTempBuffers();
  210613. }
  210614. bufferSizes.clear();
  210615. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210616. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210617. {
  210618. HeapBlock <AudioValueRange> ranges;
  210619. ranges.calloc (size, 1);
  210620. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210621. {
  210622. bufferSizes.add ((int) ranges[0].mMinimum);
  210623. for (int i = 32; i < 2048; i += 32)
  210624. {
  210625. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210626. {
  210627. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210628. {
  210629. bufferSizes.addIfNotAlreadyThere (i);
  210630. break;
  210631. }
  210632. }
  210633. }
  210634. if (bufferSize > 0)
  210635. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210636. }
  210637. }
  210638. if (bufferSizes.size() == 0 && bufferSize > 0)
  210639. bufferSizes.add (bufferSize);
  210640. sampleRates.clear();
  210641. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210642. String rates;
  210643. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210644. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210645. {
  210646. HeapBlock <AudioValueRange> ranges;
  210647. ranges.calloc (size, 1);
  210648. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210649. {
  210650. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210651. {
  210652. bool ok = false;
  210653. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210654. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210655. ok = true;
  210656. if (ok)
  210657. {
  210658. sampleRates.add (possibleRates[i]);
  210659. rates << possibleRates[i] << T(" ");
  210660. }
  210661. }
  210662. }
  210663. }
  210664. if (sampleRates.size() == 0 && sampleRate > 0)
  210665. {
  210666. sampleRates.add (sampleRate);
  210667. rates << sampleRate;
  210668. }
  210669. log (T("sr: ") + rates);
  210670. inputLatency = 0;
  210671. outputLatency = 0;
  210672. UInt32 lat;
  210673. size = sizeof (lat);
  210674. pa.mSelector = kAudioDevicePropertyLatency;
  210675. pa.mScope = kAudioDevicePropertyScopeInput;
  210676. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210677. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210678. inputLatency = (int) lat;
  210679. pa.mScope = kAudioDevicePropertyScopeOutput;
  210680. size = sizeof (lat);
  210681. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210682. outputLatency = (int) lat;
  210683. log (T("lat: ") + String (inputLatency) + T(" ") + String (outputLatency));
  210684. inChanNames.clear();
  210685. outChanNames.clear();
  210686. inputChannelInfo.calloc (numInputChans + 2);
  210687. numInputChannelInfos = 0;
  210688. outputChannelInfo.calloc (numOutputChans + 2);
  210689. numOutputChannelInfos = 0;
  210690. fillInChannelInfo (true);
  210691. fillInChannelInfo (false);
  210692. }
  210693. const StringArray getSources (bool input)
  210694. {
  210695. StringArray s;
  210696. HeapBlock <OSType> types;
  210697. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210698. for (int i = 0; i < num; ++i)
  210699. {
  210700. AudioValueTranslation avt;
  210701. char buffer[256];
  210702. avt.mInputData = (void*) &(types[i]);
  210703. avt.mInputDataSize = sizeof (UInt32);
  210704. avt.mOutputData = buffer;
  210705. avt.mOutputDataSize = 256;
  210706. UInt32 transSize = sizeof (avt);
  210707. AudioObjectPropertyAddress pa;
  210708. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210709. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210710. pa.mElement = kAudioObjectPropertyElementMaster;
  210711. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210712. {
  210713. DBG (buffer);
  210714. s.add (buffer);
  210715. }
  210716. }
  210717. return s;
  210718. }
  210719. int getCurrentSourceIndex (bool input) const
  210720. {
  210721. OSType currentSourceID = 0;
  210722. UInt32 size = sizeof (currentSourceID);
  210723. int result = -1;
  210724. AudioObjectPropertyAddress pa;
  210725. pa.mSelector = kAudioDevicePropertyDataSource;
  210726. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210727. pa.mElement = kAudioObjectPropertyElementMaster;
  210728. if (deviceID != 0)
  210729. {
  210730. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210731. {
  210732. HeapBlock <OSType> types;
  210733. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210734. for (int i = 0; i < num; ++i)
  210735. {
  210736. if (types[num] == currentSourceID)
  210737. {
  210738. result = i;
  210739. break;
  210740. }
  210741. }
  210742. }
  210743. }
  210744. return result;
  210745. }
  210746. void setCurrentSourceIndex (int index, bool input)
  210747. {
  210748. if (deviceID != 0)
  210749. {
  210750. HeapBlock <OSType> types;
  210751. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210752. if (((unsigned int) index) < (unsigned int) num)
  210753. {
  210754. AudioObjectPropertyAddress pa;
  210755. pa.mSelector = kAudioDevicePropertyDataSource;
  210756. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210757. pa.mElement = kAudioObjectPropertyElementMaster;
  210758. OSType typeId = types[index];
  210759. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210760. }
  210761. }
  210762. }
  210763. const String reopen (const BigInteger& inputChannels,
  210764. const BigInteger& outputChannels,
  210765. double newSampleRate,
  210766. int bufferSizeSamples)
  210767. {
  210768. String error;
  210769. log ("CoreAudio reopen");
  210770. callbacksAllowed = false;
  210771. stopTimer();
  210772. stop (false);
  210773. activeInputChans = inputChannels;
  210774. activeInputChans.setRange (inChanNames.size(),
  210775. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210776. false);
  210777. activeOutputChans = outputChannels;
  210778. activeOutputChans.setRange (outChanNames.size(),
  210779. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210780. false);
  210781. numInputChans = activeInputChans.countNumberOfSetBits();
  210782. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210783. // set sample rate
  210784. AudioObjectPropertyAddress pa;
  210785. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210786. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210787. pa.mElement = kAudioObjectPropertyElementMaster;
  210788. Float64 sr = newSampleRate;
  210789. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210790. {
  210791. error = "Couldn't change sample rate";
  210792. }
  210793. else
  210794. {
  210795. // change buffer size
  210796. UInt32 framesPerBuf = bufferSizeSamples;
  210797. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210798. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210799. {
  210800. error = "Couldn't change buffer size";
  210801. }
  210802. else
  210803. {
  210804. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210805. // correctly report their new settings until some random time in the future, so
  210806. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210807. // to make sure we're using the correct numbers..
  210808. updateDetailsFromDevice();
  210809. sampleRate = newSampleRate;
  210810. bufferSize = bufferSizeSamples;
  210811. if (sampleRates.size() == 0)
  210812. error = "Device has no available sample-rates";
  210813. else if (bufferSizes.size() == 0)
  210814. error = "Device has no available buffer-sizes";
  210815. else if (inputDevice != 0)
  210816. error = inputDevice->reopen (inputChannels,
  210817. outputChannels,
  210818. newSampleRate,
  210819. bufferSizeSamples);
  210820. }
  210821. }
  210822. callbacksAllowed = true;
  210823. return error;
  210824. }
  210825. bool start (AudioIODeviceCallback* cb)
  210826. {
  210827. if (! started)
  210828. {
  210829. callback = 0;
  210830. if (deviceID != 0)
  210831. {
  210832. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210833. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210834. #else
  210835. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210836. #endif
  210837. {
  210838. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210839. {
  210840. started = true;
  210841. }
  210842. else
  210843. {
  210844. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210845. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210846. #else
  210847. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210848. audioProcID = 0;
  210849. #endif
  210850. }
  210851. }
  210852. }
  210853. }
  210854. if (started)
  210855. {
  210856. const ScopedLock sl (callbackLock);
  210857. callback = cb;
  210858. }
  210859. if (inputDevice != 0)
  210860. return started && inputDevice->start (cb);
  210861. else
  210862. return started;
  210863. }
  210864. void stop (bool leaveInterruptRunning)
  210865. {
  210866. {
  210867. const ScopedLock sl (callbackLock);
  210868. callback = 0;
  210869. }
  210870. if (started
  210871. && (deviceID != 0)
  210872. && ! leaveInterruptRunning)
  210873. {
  210874. OK (AudioDeviceStop (deviceID, audioIOProc));
  210875. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210876. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210877. #else
  210878. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210879. audioProcID = 0;
  210880. #endif
  210881. started = false;
  210882. { const ScopedLock sl (callbackLock); }
  210883. // wait until it's definately stopped calling back..
  210884. for (int i = 40; --i >= 0;)
  210885. {
  210886. Thread::sleep (50);
  210887. UInt32 running = 0;
  210888. UInt32 size = sizeof (running);
  210889. AudioObjectPropertyAddress pa;
  210890. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210891. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210892. pa.mElement = kAudioObjectPropertyElementMaster;
  210893. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210894. if (running == 0)
  210895. break;
  210896. }
  210897. const ScopedLock sl (callbackLock);
  210898. }
  210899. if (inputDevice != 0)
  210900. inputDevice->stop (leaveInterruptRunning);
  210901. }
  210902. double getSampleRate() const
  210903. {
  210904. return sampleRate;
  210905. }
  210906. int getBufferSize() const
  210907. {
  210908. return bufferSize;
  210909. }
  210910. void audioCallback (const AudioBufferList* inInputData,
  210911. AudioBufferList* outOutputData)
  210912. {
  210913. int i;
  210914. const ScopedLock sl (callbackLock);
  210915. if (callback != 0)
  210916. {
  210917. if (inputDevice == 0)
  210918. {
  210919. for (i = numInputChans; --i >= 0;)
  210920. {
  210921. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210922. float* dest = tempInputBuffers [i];
  210923. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210924. + info.dataOffsetSamples;
  210925. const int stride = info.dataStrideSamples;
  210926. if (stride != 0) // if this is zero, info is invalid
  210927. {
  210928. for (int j = bufferSize; --j >= 0;)
  210929. {
  210930. *dest++ = *src;
  210931. src += stride;
  210932. }
  210933. }
  210934. }
  210935. }
  210936. if (! isSlaveDevice)
  210937. {
  210938. if (inputDevice == 0)
  210939. {
  210940. callback->audioDeviceIOCallback (const_cast<const float**> (tempInputBuffers.getData()),
  210941. numInputChans,
  210942. tempOutputBuffers,
  210943. numOutputChans,
  210944. bufferSize);
  210945. }
  210946. else
  210947. {
  210948. jassert (inputDevice->bufferSize == bufferSize);
  210949. // Sometimes the two linked devices seem to get their callbacks in
  210950. // parallel, so we need to lock both devices to stop the input data being
  210951. // changed while inside our callback..
  210952. const ScopedLock sl2 (inputDevice->callbackLock);
  210953. callback->audioDeviceIOCallback (const_cast<const float**> (inputDevice->tempInputBuffers.getData()),
  210954. inputDevice->numInputChans,
  210955. tempOutputBuffers,
  210956. numOutputChans,
  210957. bufferSize);
  210958. }
  210959. for (i = numOutputChans; --i >= 0;)
  210960. {
  210961. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210962. const float* src = tempOutputBuffers [i];
  210963. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210964. + info.dataOffsetSamples;
  210965. const int stride = info.dataStrideSamples;
  210966. if (stride != 0) // if this is zero, info is invalid
  210967. {
  210968. for (int j = bufferSize; --j >= 0;)
  210969. {
  210970. *dest = *src++;
  210971. dest += stride;
  210972. }
  210973. }
  210974. }
  210975. }
  210976. }
  210977. else
  210978. {
  210979. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210980. {
  210981. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210982. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210983. + info.dataOffsetSamples;
  210984. const int stride = info.dataStrideSamples;
  210985. if (stride != 0) // if this is zero, info is invalid
  210986. {
  210987. for (int j = bufferSize; --j >= 0;)
  210988. {
  210989. *dest = 0.0f;
  210990. dest += stride;
  210991. }
  210992. }
  210993. }
  210994. }
  210995. }
  210996. // called by callbacks
  210997. void deviceDetailsChanged()
  210998. {
  210999. if (callbacksAllowed)
  211000. startTimer (100);
  211001. }
  211002. void timerCallback()
  211003. {
  211004. stopTimer();
  211005. log ("CoreAudio device changed callback");
  211006. const double oldSampleRate = sampleRate;
  211007. const int oldBufferSize = bufferSize;
  211008. updateDetailsFromDevice();
  211009. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  211010. {
  211011. callbacksAllowed = false;
  211012. stop (false);
  211013. updateDetailsFromDevice();
  211014. callbacksAllowed = true;
  211015. }
  211016. }
  211017. CoreAudioInternal* getRelatedDevice() const
  211018. {
  211019. UInt32 size = 0;
  211020. ScopedPointer <CoreAudioInternal> result;
  211021. AudioObjectPropertyAddress pa;
  211022. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  211023. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211024. pa.mElement = kAudioObjectPropertyElementMaster;
  211025. if (deviceID != 0
  211026. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  211027. && size > 0)
  211028. {
  211029. HeapBlock <AudioDeviceID> devs;
  211030. devs.calloc (size, 1);
  211031. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  211032. {
  211033. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  211034. {
  211035. if (devs[i] != deviceID && devs[i] != 0)
  211036. {
  211037. result = new CoreAudioInternal (devs[i]);
  211038. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  211039. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  211040. if (thisIsInput != otherIsInput
  211041. || (inChanNames.size() + outChanNames.size() == 0)
  211042. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  211043. break;
  211044. result = 0;
  211045. }
  211046. }
  211047. }
  211048. }
  211049. return result.release();
  211050. }
  211051. juce_UseDebuggingNewOperator
  211052. int inputLatency, outputLatency;
  211053. BigInteger activeInputChans, activeOutputChans;
  211054. StringArray inChanNames, outChanNames;
  211055. Array <double> sampleRates;
  211056. Array <int> bufferSizes;
  211057. AudioIODeviceCallback* callback;
  211058. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  211059. AudioDeviceIOProcID audioProcID;
  211060. #endif
  211061. CoreAudioInternal* inputDevice;
  211062. bool isSlaveDevice;
  211063. private:
  211064. CriticalSection callbackLock;
  211065. AudioDeviceID deviceID;
  211066. bool started;
  211067. double sampleRate;
  211068. int bufferSize;
  211069. HeapBlock <float> audioBuffer;
  211070. int numInputChans, numOutputChans;
  211071. bool callbacksAllowed;
  211072. struct CallbackDetailsForChannel
  211073. {
  211074. int streamNum;
  211075. int dataOffsetSamples;
  211076. int dataStrideSamples;
  211077. };
  211078. int numInputChannelInfos, numOutputChannelInfos;
  211079. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  211080. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  211081. CoreAudioInternal (const CoreAudioInternal&);
  211082. CoreAudioInternal& operator= (const CoreAudioInternal&);
  211083. static OSStatus audioIOProc (AudioDeviceID inDevice,
  211084. const AudioTimeStamp* inNow,
  211085. const AudioBufferList* inInputData,
  211086. const AudioTimeStamp* inInputTime,
  211087. AudioBufferList* outOutputData,
  211088. const AudioTimeStamp* inOutputTime,
  211089. void* device)
  211090. {
  211091. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  211092. return noErr;
  211093. }
  211094. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211095. {
  211096. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211097. switch (pa->mSelector)
  211098. {
  211099. case kAudioDevicePropertyBufferSize:
  211100. case kAudioDevicePropertyBufferFrameSize:
  211101. case kAudioDevicePropertyNominalSampleRate:
  211102. case kAudioDevicePropertyStreamFormat:
  211103. case kAudioDevicePropertyDeviceIsAlive:
  211104. intern->deviceDetailsChanged();
  211105. break;
  211106. case kAudioDevicePropertyBufferSizeRange:
  211107. case kAudioDevicePropertyVolumeScalar:
  211108. case kAudioDevicePropertyMute:
  211109. case kAudioDevicePropertyPlayThru:
  211110. case kAudioDevicePropertyDataSource:
  211111. case kAudioDevicePropertyDeviceIsRunning:
  211112. break;
  211113. }
  211114. return noErr;
  211115. }
  211116. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  211117. {
  211118. AudioObjectPropertyAddress pa;
  211119. pa.mSelector = kAudioDevicePropertyDataSources;
  211120. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211121. pa.mElement = kAudioObjectPropertyElementMaster;
  211122. UInt32 size = 0;
  211123. if (deviceID != 0
  211124. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211125. {
  211126. types.calloc (size, 1);
  211127. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  211128. return size / (int) sizeof (OSType);
  211129. }
  211130. return 0;
  211131. }
  211132. };
  211133. class CoreAudioIODevice : public AudioIODevice
  211134. {
  211135. public:
  211136. CoreAudioIODevice (const String& deviceName,
  211137. AudioDeviceID inputDeviceId,
  211138. const int inputIndex_,
  211139. AudioDeviceID outputDeviceId,
  211140. const int outputIndex_)
  211141. : AudioIODevice (deviceName, "CoreAudio"),
  211142. inputIndex (inputIndex_),
  211143. outputIndex (outputIndex_),
  211144. isOpen_ (false),
  211145. isStarted (false)
  211146. {
  211147. internal = 0;
  211148. CoreAudioInternal* device = 0;
  211149. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  211150. {
  211151. jassert (inputDeviceId != 0);
  211152. device = new CoreAudioInternal (inputDeviceId);
  211153. }
  211154. else
  211155. {
  211156. device = new CoreAudioInternal (outputDeviceId);
  211157. if (inputDeviceId != 0)
  211158. {
  211159. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  211160. device->inputDevice = secondDevice;
  211161. secondDevice->isSlaveDevice = true;
  211162. }
  211163. }
  211164. internal = device;
  211165. AudioObjectPropertyAddress pa;
  211166. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211167. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211168. pa.mElement = kAudioObjectPropertyElementWildcard;
  211169. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211170. }
  211171. ~CoreAudioIODevice()
  211172. {
  211173. AudioObjectPropertyAddress pa;
  211174. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211175. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211176. pa.mElement = kAudioObjectPropertyElementWildcard;
  211177. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211178. delete internal;
  211179. }
  211180. const StringArray getOutputChannelNames()
  211181. {
  211182. return internal->outChanNames;
  211183. }
  211184. const StringArray getInputChannelNames()
  211185. {
  211186. if (internal->inputDevice != 0)
  211187. return internal->inputDevice->inChanNames;
  211188. else
  211189. return internal->inChanNames;
  211190. }
  211191. int getNumSampleRates()
  211192. {
  211193. return internal->sampleRates.size();
  211194. }
  211195. double getSampleRate (int index)
  211196. {
  211197. return internal->sampleRates [index];
  211198. }
  211199. int getNumBufferSizesAvailable()
  211200. {
  211201. return internal->bufferSizes.size();
  211202. }
  211203. int getBufferSizeSamples (int index)
  211204. {
  211205. return internal->bufferSizes [index];
  211206. }
  211207. int getDefaultBufferSize()
  211208. {
  211209. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  211210. if (getBufferSizeSamples(i) >= 512)
  211211. return getBufferSizeSamples(i);
  211212. return 512;
  211213. }
  211214. const String open (const BigInteger& inputChannels,
  211215. const BigInteger& outputChannels,
  211216. double sampleRate,
  211217. int bufferSizeSamples)
  211218. {
  211219. isOpen_ = true;
  211220. if (bufferSizeSamples <= 0)
  211221. bufferSizeSamples = getDefaultBufferSize();
  211222. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  211223. isOpen_ = lastError.isEmpty();
  211224. return lastError;
  211225. }
  211226. void close()
  211227. {
  211228. isOpen_ = false;
  211229. internal->stop (false);
  211230. }
  211231. bool isOpen()
  211232. {
  211233. return isOpen_;
  211234. }
  211235. int getCurrentBufferSizeSamples()
  211236. {
  211237. return internal != 0 ? internal->getBufferSize() : 512;
  211238. }
  211239. double getCurrentSampleRate()
  211240. {
  211241. return internal != 0 ? internal->getSampleRate() : 0;
  211242. }
  211243. int getCurrentBitDepth()
  211244. {
  211245. return 32; // no way to find out, so just assume it's high..
  211246. }
  211247. const BigInteger getActiveOutputChannels() const
  211248. {
  211249. return internal != 0 ? internal->activeOutputChans : BigInteger();
  211250. }
  211251. const BigInteger getActiveInputChannels() const
  211252. {
  211253. BigInteger chans;
  211254. if (internal != 0)
  211255. {
  211256. chans = internal->activeInputChans;
  211257. if (internal->inputDevice != 0)
  211258. chans |= internal->inputDevice->activeInputChans;
  211259. }
  211260. return chans;
  211261. }
  211262. int getOutputLatencyInSamples()
  211263. {
  211264. if (internal == 0)
  211265. return 0;
  211266. // this seems like a good guess at getting the latency right - comparing
  211267. // this with a round-trip measurement, it gets it to within a few millisecs
  211268. // for the built-in mac soundcard
  211269. return internal->outputLatency + internal->getBufferSize() * 2;
  211270. }
  211271. int getInputLatencyInSamples()
  211272. {
  211273. if (internal == 0)
  211274. return 0;
  211275. return internal->inputLatency + internal->getBufferSize() * 2;
  211276. }
  211277. void start (AudioIODeviceCallback* callback)
  211278. {
  211279. if (internal != 0 && ! isStarted)
  211280. {
  211281. if (callback != 0)
  211282. callback->audioDeviceAboutToStart (this);
  211283. isStarted = true;
  211284. internal->start (callback);
  211285. }
  211286. }
  211287. void stop()
  211288. {
  211289. if (isStarted && internal != 0)
  211290. {
  211291. AudioIODeviceCallback* const lastCallback = internal->callback;
  211292. isStarted = false;
  211293. internal->stop (true);
  211294. if (lastCallback != 0)
  211295. lastCallback->audioDeviceStopped();
  211296. }
  211297. }
  211298. bool isPlaying()
  211299. {
  211300. if (internal->callback == 0)
  211301. isStarted = false;
  211302. return isStarted;
  211303. }
  211304. const String getLastError()
  211305. {
  211306. return lastError;
  211307. }
  211308. int inputIndex, outputIndex;
  211309. juce_UseDebuggingNewOperator
  211310. private:
  211311. CoreAudioInternal* internal;
  211312. bool isOpen_, isStarted;
  211313. String lastError;
  211314. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211315. {
  211316. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211317. switch (pa->mSelector)
  211318. {
  211319. case kAudioHardwarePropertyDevices:
  211320. intern->deviceDetailsChanged();
  211321. break;
  211322. case kAudioHardwarePropertyDefaultOutputDevice:
  211323. case kAudioHardwarePropertyDefaultInputDevice:
  211324. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211325. break;
  211326. }
  211327. return noErr;
  211328. }
  211329. CoreAudioIODevice (const CoreAudioIODevice&);
  211330. CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211331. };
  211332. class CoreAudioIODeviceType : public AudioIODeviceType
  211333. {
  211334. public:
  211335. CoreAudioIODeviceType()
  211336. : AudioIODeviceType (T("CoreAudio")),
  211337. hasScanned (false)
  211338. {
  211339. }
  211340. ~CoreAudioIODeviceType()
  211341. {
  211342. }
  211343. void scanForDevices()
  211344. {
  211345. hasScanned = true;
  211346. inputDeviceNames.clear();
  211347. outputDeviceNames.clear();
  211348. inputIds.clear();
  211349. outputIds.clear();
  211350. UInt32 size;
  211351. AudioObjectPropertyAddress pa;
  211352. pa.mSelector = kAudioHardwarePropertyDevices;
  211353. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211354. pa.mElement = kAudioObjectPropertyElementMaster;
  211355. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211356. {
  211357. HeapBlock <AudioDeviceID> devs;
  211358. devs.calloc (size, 1);
  211359. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211360. {
  211361. static bool alreadyLogged = false;
  211362. const int num = size / (int) sizeof (AudioDeviceID);
  211363. for (int i = 0; i < num; ++i)
  211364. {
  211365. char name [1024];
  211366. size = sizeof (name);
  211367. pa.mSelector = kAudioDevicePropertyDeviceName;
  211368. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211369. {
  211370. const String nameString (String::fromUTF8 (name, (int) strlen (name)));
  211371. if (! alreadyLogged)
  211372. log (T("CoreAudio device: ") + nameString);
  211373. const int numIns = getNumChannels (devs[i], true);
  211374. const int numOuts = getNumChannels (devs[i], false);
  211375. if (numIns > 0)
  211376. {
  211377. inputDeviceNames.add (nameString);
  211378. inputIds.add (devs[i]);
  211379. }
  211380. if (numOuts > 0)
  211381. {
  211382. outputDeviceNames.add (nameString);
  211383. outputIds.add (devs[i]);
  211384. }
  211385. }
  211386. }
  211387. alreadyLogged = true;
  211388. }
  211389. }
  211390. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211391. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211392. }
  211393. const StringArray getDeviceNames (const bool wantInputNames) const
  211394. {
  211395. jassert (hasScanned); // need to call scanForDevices() before doing this
  211396. if (wantInputNames)
  211397. return inputDeviceNames;
  211398. else
  211399. return outputDeviceNames;
  211400. }
  211401. int getDefaultDeviceIndex (const bool forInput) const
  211402. {
  211403. jassert (hasScanned); // need to call scanForDevices() before doing this
  211404. AudioDeviceID deviceID;
  211405. UInt32 size = sizeof (deviceID);
  211406. // if they're asking for any input channels at all, use the default input, so we
  211407. // get the built-in mic rather than the built-in output with no inputs..
  211408. AudioObjectPropertyAddress pa;
  211409. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211410. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211411. pa.mElement = kAudioObjectPropertyElementMaster;
  211412. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211413. {
  211414. if (forInput)
  211415. {
  211416. for (int i = inputIds.size(); --i >= 0;)
  211417. if (inputIds[i] == deviceID)
  211418. return i;
  211419. }
  211420. else
  211421. {
  211422. for (int i = outputIds.size(); --i >= 0;)
  211423. if (outputIds[i] == deviceID)
  211424. return i;
  211425. }
  211426. }
  211427. return 0;
  211428. }
  211429. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  211430. {
  211431. jassert (hasScanned); // need to call scanForDevices() before doing this
  211432. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211433. if (d == 0)
  211434. return -1;
  211435. return asInput ? d->inputIndex
  211436. : d->outputIndex;
  211437. }
  211438. bool hasSeparateInputsAndOutputs() const { return true; }
  211439. AudioIODevice* createDevice (const String& outputDeviceName,
  211440. const String& inputDeviceName)
  211441. {
  211442. jassert (hasScanned); // need to call scanForDevices() before doing this
  211443. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211444. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211445. String deviceName (outputDeviceName);
  211446. if (deviceName.isEmpty())
  211447. deviceName = inputDeviceName;
  211448. if (index >= 0)
  211449. return new CoreAudioIODevice (deviceName,
  211450. inputIds [inputIndex],
  211451. inputIndex,
  211452. outputIds [outputIndex],
  211453. outputIndex);
  211454. return 0;
  211455. }
  211456. juce_UseDebuggingNewOperator
  211457. private:
  211458. StringArray inputDeviceNames, outputDeviceNames;
  211459. Array <AudioDeviceID> inputIds, outputIds;
  211460. bool hasScanned;
  211461. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211462. {
  211463. int total = 0;
  211464. UInt32 size;
  211465. AudioObjectPropertyAddress pa;
  211466. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211467. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211468. pa.mElement = kAudioObjectPropertyElementMaster;
  211469. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211470. {
  211471. HeapBlock <AudioBufferList> bufList;
  211472. bufList.calloc (size, 1);
  211473. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211474. {
  211475. const int numStreams = bufList->mNumberBuffers;
  211476. for (int i = 0; i < numStreams; ++i)
  211477. {
  211478. const AudioBuffer& b = bufList->mBuffers[i];
  211479. total += b.mNumberChannels;
  211480. }
  211481. }
  211482. }
  211483. return total;
  211484. }
  211485. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211486. CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211487. };
  211488. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211489. {
  211490. return new CoreAudioIODeviceType();
  211491. }
  211492. #undef log
  211493. #endif
  211494. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211495. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211496. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211497. // compiled on its own).
  211498. #if JUCE_INCLUDED_FILE
  211499. #if JUCE_MAC
  211500. #undef log
  211501. #define log(a) Logger::writeToLog(a)
  211502. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211503. {
  211504. if (err == noErr)
  211505. return true;
  211506. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  211507. jassertfalse
  211508. return false;
  211509. }
  211510. #undef OK
  211511. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211512. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211513. {
  211514. String result;
  211515. CFStringRef str = 0;
  211516. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211517. if (str != 0)
  211518. {
  211519. result = PlatformUtilities::cfStringToJuceString (str);
  211520. CFRelease (str);
  211521. str = 0;
  211522. }
  211523. MIDIEntityRef entity = 0;
  211524. MIDIEndpointGetEntity (endpoint, &entity);
  211525. if (entity == 0)
  211526. return result; // probably virtual
  211527. if (result.isEmpty())
  211528. {
  211529. // endpoint name has zero length - try the entity
  211530. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211531. if (str != 0)
  211532. {
  211533. result += PlatformUtilities::cfStringToJuceString (str);
  211534. CFRelease (str);
  211535. str = 0;
  211536. }
  211537. }
  211538. // now consider the device's name
  211539. MIDIDeviceRef device = 0;
  211540. MIDIEntityGetDevice (entity, &device);
  211541. if (device == 0)
  211542. return result;
  211543. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211544. if (str != 0)
  211545. {
  211546. const String s (PlatformUtilities::cfStringToJuceString (str));
  211547. CFRelease (str);
  211548. // if an external device has only one entity, throw away
  211549. // the endpoint name and just use the device name
  211550. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211551. {
  211552. result = s;
  211553. }
  211554. else if (! result.startsWithIgnoreCase (s))
  211555. {
  211556. // prepend the device name to the entity name
  211557. result = (s + T(" ") + result).trimEnd();
  211558. }
  211559. }
  211560. return result;
  211561. }
  211562. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211563. {
  211564. String result;
  211565. // Does the endpoint have connections?
  211566. CFDataRef connections = 0;
  211567. int numConnections = 0;
  211568. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211569. if (connections != 0)
  211570. {
  211571. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211572. if (numConnections > 0)
  211573. {
  211574. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211575. for (int i = 0; i < numConnections; ++i, ++pid)
  211576. {
  211577. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211578. MIDIObjectRef connObject;
  211579. MIDIObjectType connObjectType;
  211580. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211581. if (err == noErr)
  211582. {
  211583. String s;
  211584. if (connObjectType == kMIDIObjectType_ExternalSource
  211585. || connObjectType == kMIDIObjectType_ExternalDestination)
  211586. {
  211587. // Connected to an external device's endpoint (10.3 and later).
  211588. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211589. }
  211590. else
  211591. {
  211592. // Connected to an external device (10.2) (or something else, catch-all)
  211593. CFStringRef str = 0;
  211594. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211595. if (str != 0)
  211596. {
  211597. s = PlatformUtilities::cfStringToJuceString (str);
  211598. CFRelease (str);
  211599. }
  211600. }
  211601. if (s.isNotEmpty())
  211602. {
  211603. if (result.isNotEmpty())
  211604. result += (", ");
  211605. result += s;
  211606. }
  211607. }
  211608. }
  211609. }
  211610. CFRelease (connections);
  211611. }
  211612. if (result.isNotEmpty())
  211613. return result;
  211614. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211615. return getEndpointName (endpoint, false);
  211616. }
  211617. const StringArray MidiOutput::getDevices()
  211618. {
  211619. StringArray s;
  211620. const ItemCount num = MIDIGetNumberOfDestinations();
  211621. for (ItemCount i = 0; i < num; ++i)
  211622. {
  211623. MIDIEndpointRef dest = MIDIGetDestination (i);
  211624. if (dest != 0)
  211625. {
  211626. String name (getConnectedEndpointName (dest));
  211627. if (name.isEmpty())
  211628. name = "<error>";
  211629. s.add (name);
  211630. }
  211631. else
  211632. {
  211633. s.add ("<error>");
  211634. }
  211635. }
  211636. return s;
  211637. }
  211638. int MidiOutput::getDefaultDeviceIndex()
  211639. {
  211640. return 0;
  211641. }
  211642. static MIDIClientRef globalMidiClient;
  211643. static bool hasGlobalClientBeenCreated = false;
  211644. static bool makeSureClientExists()
  211645. {
  211646. if (! hasGlobalClientBeenCreated)
  211647. {
  211648. String name (T("JUCE"));
  211649. if (JUCEApplication::getInstance() != 0)
  211650. name = JUCEApplication::getInstance()->getApplicationName();
  211651. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211652. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211653. CFRelease (appName);
  211654. }
  211655. return hasGlobalClientBeenCreated;
  211656. }
  211657. class MidiPortAndEndpoint
  211658. {
  211659. public:
  211660. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211661. : port (port_), endPoint (endPoint_)
  211662. {
  211663. }
  211664. ~MidiPortAndEndpoint()
  211665. {
  211666. if (port != 0)
  211667. MIDIPortDispose (port);
  211668. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211669. MIDIEndpointDispose (endPoint);
  211670. }
  211671. MIDIPortRef port;
  211672. MIDIEndpointRef endPoint;
  211673. };
  211674. MidiOutput* MidiOutput::openDevice (int index)
  211675. {
  211676. MidiOutput* mo = 0;
  211677. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211678. {
  211679. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211680. CFStringRef pname;
  211681. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211682. {
  211683. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  211684. if (makeSureClientExists())
  211685. {
  211686. MIDIPortRef port;
  211687. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211688. {
  211689. mo = new MidiOutput();
  211690. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211691. }
  211692. }
  211693. CFRelease (pname);
  211694. }
  211695. }
  211696. return mo;
  211697. }
  211698. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211699. {
  211700. MidiOutput* mo = 0;
  211701. if (makeSureClientExists())
  211702. {
  211703. MIDIEndpointRef endPoint;
  211704. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211705. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211706. {
  211707. mo = new MidiOutput();
  211708. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211709. }
  211710. CFRelease (name);
  211711. }
  211712. return mo;
  211713. }
  211714. MidiOutput::~MidiOutput()
  211715. {
  211716. delete (MidiPortAndEndpoint*) internal;
  211717. }
  211718. void MidiOutput::reset()
  211719. {
  211720. }
  211721. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211722. {
  211723. return false;
  211724. }
  211725. void MidiOutput::setVolume (float leftVol, float rightVol)
  211726. {
  211727. }
  211728. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211729. {
  211730. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211731. if (message.isSysEx())
  211732. {
  211733. const int maxPacketSize = 256;
  211734. int pos = 0, bytesLeft = message.getRawDataSize();
  211735. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211736. HeapBlock <MIDIPacketList> packets;
  211737. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211738. packets->numPackets = numPackets;
  211739. MIDIPacket* p = packets->packet;
  211740. for (int i = 0; i < numPackets; ++i)
  211741. {
  211742. p->timeStamp = 0;
  211743. p->length = jmin (maxPacketSize, bytesLeft);
  211744. memcpy (p->data, message.getRawData() + pos, p->length);
  211745. pos += p->length;
  211746. bytesLeft -= p->length;
  211747. p = MIDIPacketNext (p);
  211748. }
  211749. if (mpe->port != 0)
  211750. MIDISend (mpe->port, mpe->endPoint, packets);
  211751. else
  211752. MIDIReceived (mpe->endPoint, packets);
  211753. }
  211754. else
  211755. {
  211756. MIDIPacketList packets;
  211757. packets.numPackets = 1;
  211758. packets.packet[0].timeStamp = 0;
  211759. packets.packet[0].length = message.getRawDataSize();
  211760. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211761. if (mpe->port != 0)
  211762. MIDISend (mpe->port, mpe->endPoint, &packets);
  211763. else
  211764. MIDIReceived (mpe->endPoint, &packets);
  211765. }
  211766. }
  211767. const StringArray MidiInput::getDevices()
  211768. {
  211769. StringArray s;
  211770. const ItemCount num = MIDIGetNumberOfSources();
  211771. for (ItemCount i = 0; i < num; ++i)
  211772. {
  211773. MIDIEndpointRef source = MIDIGetSource (i);
  211774. if (source != 0)
  211775. {
  211776. String name (getConnectedEndpointName (source));
  211777. if (name.isEmpty())
  211778. name = "<error>";
  211779. s.add (name);
  211780. }
  211781. else
  211782. {
  211783. s.add ("<error>");
  211784. }
  211785. }
  211786. return s;
  211787. }
  211788. int MidiInput::getDefaultDeviceIndex()
  211789. {
  211790. return 0;
  211791. }
  211792. struct MidiPortAndCallback
  211793. {
  211794. MidiInput* input;
  211795. MidiPortAndEndpoint* portAndEndpoint;
  211796. MidiInputCallback* callback;
  211797. MemoryBlock pendingData;
  211798. int pendingBytes;
  211799. double pendingDataTime;
  211800. bool active;
  211801. void processSysex (const uint8*& d, int& size, const double time)
  211802. {
  211803. if (*d == 0xf0)
  211804. {
  211805. pendingBytes = 0;
  211806. pendingDataTime = time;
  211807. }
  211808. pendingData.ensureSize (pendingBytes + size, false);
  211809. uint8* totalMessage = (uint8*) pendingData.getData();
  211810. uint8* dest = totalMessage + pendingBytes;
  211811. while (size > 0)
  211812. {
  211813. if (pendingBytes > 0 && *d >= 0x80)
  211814. {
  211815. if (*d >= 0xfa || *d == 0xf8)
  211816. {
  211817. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  211818. ++d;
  211819. --size;
  211820. }
  211821. else
  211822. {
  211823. if (*d == 0xf7)
  211824. {
  211825. *dest++ = *d++;
  211826. pendingBytes++;
  211827. --size;
  211828. }
  211829. break;
  211830. }
  211831. }
  211832. else
  211833. {
  211834. *dest++ = *d++;
  211835. pendingBytes++;
  211836. --size;
  211837. }
  211838. }
  211839. if (totalMessage [pendingBytes - 1] == 0xf7)
  211840. {
  211841. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  211842. pendingBytes = 0;
  211843. }
  211844. else
  211845. {
  211846. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  211847. }
  211848. }
  211849. };
  211850. namespace CoreMidiCallbacks
  211851. {
  211852. static CriticalSection callbackLock;
  211853. static VoidArray activeCallbacks;
  211854. }
  211855. static void midiInputProc (const MIDIPacketList* pktlist,
  211856. void* readProcRefCon,
  211857. void* srcConnRefCon)
  211858. {
  211859. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211860. const double originalTime = time;
  211861. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211862. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211863. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  211864. {
  211865. const MIDIPacket* packet = &pktlist->packet[0];
  211866. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211867. {
  211868. const uint8* d = (const uint8*) (packet->data);
  211869. int size = packet->length;
  211870. while (size > 0)
  211871. {
  211872. time = originalTime;
  211873. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211874. {
  211875. mpc->processSysex (d, size, time);
  211876. }
  211877. else
  211878. {
  211879. int used = 0;
  211880. const MidiMessage m (d, size, used, 0, time);
  211881. if (used <= 0)
  211882. {
  211883. jassertfalse // malformed midi message
  211884. break;
  211885. }
  211886. else
  211887. {
  211888. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211889. }
  211890. size -= used;
  211891. d += used;
  211892. }
  211893. }
  211894. packet = MIDIPacketNext (packet);
  211895. }
  211896. }
  211897. }
  211898. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211899. {
  211900. MidiInput* mi = 0;
  211901. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211902. {
  211903. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211904. if (endPoint != 0)
  211905. {
  211906. CFStringRef pname;
  211907. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211908. {
  211909. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  211910. if (makeSureClientExists())
  211911. {
  211912. MIDIPortRef port;
  211913. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211914. mpc->active = false;
  211915. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211916. {
  211917. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211918. {
  211919. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211920. mpc->callback = callback;
  211921. mpc->pendingBytes = 0;
  211922. mpc->pendingData.ensureSize (128);
  211923. mi = new MidiInput (getDevices() [index]);
  211924. mpc->input = mi;
  211925. mi->internal = (void*) mpc;
  211926. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211927. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211928. }
  211929. else
  211930. {
  211931. OK (MIDIPortDispose (port));
  211932. }
  211933. }
  211934. }
  211935. }
  211936. CFRelease (pname);
  211937. }
  211938. }
  211939. return mi;
  211940. }
  211941. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211942. {
  211943. MidiInput* mi = 0;
  211944. if (makeSureClientExists())
  211945. {
  211946. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211947. mpc->active = false;
  211948. MIDIEndpointRef endPoint;
  211949. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211950. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211951. {
  211952. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211953. mpc->callback = callback;
  211954. mpc->pendingBytes = 0;
  211955. mpc->pendingData.ensureSize (128);
  211956. mi = new MidiInput (deviceName);
  211957. mpc->input = mi;
  211958. mi->internal = (void*) mpc;
  211959. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211960. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211961. }
  211962. CFRelease (name);
  211963. }
  211964. return mi;
  211965. }
  211966. MidiInput::MidiInput (const String& name_)
  211967. : name (name_)
  211968. {
  211969. }
  211970. MidiInput::~MidiInput()
  211971. {
  211972. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211973. mpc->active = false;
  211974. {
  211975. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211976. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  211977. }
  211978. if (mpc->portAndEndpoint->port != 0)
  211979. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211980. delete mpc->portAndEndpoint;
  211981. delete mpc;
  211982. }
  211983. void MidiInput::start()
  211984. {
  211985. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211986. ((MidiPortAndCallback*) internal)->active = true;
  211987. }
  211988. void MidiInput::stop()
  211989. {
  211990. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211991. ((MidiPortAndCallback*) internal)->active = false;
  211992. }
  211993. #undef log
  211994. #else
  211995. MidiOutput::~MidiOutput()
  211996. {
  211997. }
  211998. void MidiOutput::reset()
  211999. {
  212000. }
  212001. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  212002. {
  212003. return false;
  212004. }
  212005. void MidiOutput::setVolume (float leftVol, float rightVol)
  212006. {
  212007. }
  212008. void MidiOutput::sendMessageNow (const MidiMessage& message)
  212009. {
  212010. }
  212011. const StringArray MidiOutput::getDevices()
  212012. {
  212013. return StringArray();
  212014. }
  212015. MidiOutput* MidiOutput::openDevice (int index)
  212016. {
  212017. return 0;
  212018. }
  212019. const StringArray MidiInput::getDevices()
  212020. {
  212021. return StringArray();
  212022. }
  212023. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  212024. {
  212025. return 0;
  212026. }
  212027. #endif
  212028. #endif
  212029. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  212030. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  212031. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  212032. // compiled on its own).
  212033. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  212034. #if ! JUCE_QUICKTIME
  212035. #error "On the Mac, cameras use Quicktime, so if you turn on JUCE_USE_CAMERA, you also need to enable JUCE_QUICKTIME"
  212036. #endif
  212037. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  212038. class QTCameraDeviceInteral;
  212039. END_JUCE_NAMESPACE
  212040. @interface QTCaptureCallbackDelegate : NSObject
  212041. {
  212042. @public
  212043. CameraDevice* owner;
  212044. QTCameraDeviceInteral* internal;
  212045. int64 firstPresentationTime;
  212046. int64 averageTimeOffset;
  212047. }
  212048. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  212049. - (void) dealloc;
  212050. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212051. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212052. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212053. fromConnection: (QTCaptureConnection*) connection;
  212054. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212055. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212056. fromConnection: (QTCaptureConnection*) connection;
  212057. @end
  212058. BEGIN_JUCE_NAMESPACE
  212059. class QTCameraDeviceInteral
  212060. {
  212061. public:
  212062. QTCameraDeviceInteral (CameraDevice* owner, int index)
  212063. {
  212064. const ScopedAutoReleasePool pool;
  212065. session = [[QTCaptureSession alloc] init];
  212066. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212067. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  212068. input = 0;
  212069. audioInput = 0;
  212070. audioDevice = 0;
  212071. fileOutput = 0;
  212072. imageOutput = 0;
  212073. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  212074. internalDev: this];
  212075. NSError* err = 0;
  212076. [device retain];
  212077. [device open: &err];
  212078. if (err == 0)
  212079. {
  212080. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212081. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212082. [session addInput: input error: &err];
  212083. if (err == 0)
  212084. {
  212085. resetFile();
  212086. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  212087. [imageOutput setDelegate: callbackDelegate];
  212088. if (err == 0)
  212089. {
  212090. [session startRunning];
  212091. return;
  212092. }
  212093. }
  212094. }
  212095. openingError = nsStringToJuce ([err description]);
  212096. DBG (openingError);
  212097. }
  212098. ~QTCameraDeviceInteral()
  212099. {
  212100. [session stopRunning];
  212101. [session removeOutput: imageOutput];
  212102. [session release];
  212103. [input release];
  212104. [device release];
  212105. [audioDevice release];
  212106. [audioInput release];
  212107. [fileOutput release];
  212108. [imageOutput release];
  212109. [callbackDelegate release];
  212110. }
  212111. void resetFile()
  212112. {
  212113. [fileOutput recordToOutputFileURL: nil];
  212114. [session removeOutput: fileOutput];
  212115. [fileOutput release];
  212116. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  212117. [session removeInput: audioInput];
  212118. [audioInput release];
  212119. audioInput = 0;
  212120. [audioDevice release];
  212121. audioDevice = 0;
  212122. [fileOutput setDelegate: callbackDelegate];
  212123. }
  212124. void addDefaultAudioInput()
  212125. {
  212126. NSError* err = nil;
  212127. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  212128. if ([audioDevice open: &err])
  212129. [audioDevice retain];
  212130. else
  212131. audioDevice = nil;
  212132. if (audioDevice != 0)
  212133. {
  212134. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  212135. [session addInput: audioInput error: &err];
  212136. }
  212137. }
  212138. void addListener (CameraImageListener* listenerToAdd)
  212139. {
  212140. const ScopedLock sl (listenerLock);
  212141. if (listeners.size() == 0)
  212142. [session addOutput: imageOutput error: nil];
  212143. listeners.addIfNotAlreadyThere (listenerToAdd);
  212144. }
  212145. void removeListener (CameraImageListener* listenerToRemove)
  212146. {
  212147. const ScopedLock sl (listenerLock);
  212148. listeners.removeValue (listenerToRemove);
  212149. if (listeners.size() == 0)
  212150. [session removeOutput: imageOutput];
  212151. }
  212152. void callListeners (CIImage* frame, int w, int h)
  212153. {
  212154. CoreGraphicsImage image (Image::ARGB, w, h, false);
  212155. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  212156. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  212157. CGContextFlush (image.context);
  212158. const ScopedLock sl (listenerLock);
  212159. for (int i = listeners.size(); --i >= 0;)
  212160. {
  212161. CameraImageListener* l = (CameraImageListener*) listeners[i];
  212162. if (l != 0)
  212163. l->imageReceived (image);
  212164. }
  212165. }
  212166. QTCaptureDevice* device;
  212167. QTCaptureDeviceInput* input;
  212168. QTCaptureDevice* audioDevice;
  212169. QTCaptureDeviceInput* audioInput;
  212170. QTCaptureSession* session;
  212171. QTCaptureMovieFileOutput* fileOutput;
  212172. QTCaptureDecompressedVideoOutput* imageOutput;
  212173. QTCaptureCallbackDelegate* callbackDelegate;
  212174. String openingError;
  212175. VoidArray listeners;
  212176. CriticalSection listenerLock;
  212177. };
  212178. END_JUCE_NAMESPACE
  212179. @implementation QTCaptureCallbackDelegate
  212180. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  212181. internalDev: (QTCameraDeviceInteral*) d
  212182. {
  212183. [super init];
  212184. owner = owner_;
  212185. internal = d;
  212186. firstPresentationTime = 0;
  212187. averageTimeOffset = 0;
  212188. return self;
  212189. }
  212190. - (void) dealloc
  212191. {
  212192. [super dealloc];
  212193. }
  212194. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212195. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212196. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212197. fromConnection: (QTCaptureConnection*) connection
  212198. {
  212199. if (internal->listeners.size() > 0)
  212200. {
  212201. const ScopedAutoReleasePool pool;
  212202. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  212203. CVPixelBufferGetWidth (videoFrame),
  212204. CVPixelBufferGetHeight (videoFrame));
  212205. }
  212206. }
  212207. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212208. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212209. fromConnection: (QTCaptureConnection*) connection
  212210. {
  212211. const Time now (Time::getCurrentTime());
  212212. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  212213. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute];
  212214. #else
  212215. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"];
  212216. #endif
  212217. int64 presentationTime = (hosttime != nil)
  212218. ? ((int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000 + 40)
  212219. : (([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale + 50);
  212220. const int64 timeDiff = now.toMilliseconds() - presentationTime;
  212221. if (firstPresentationTime == 0)
  212222. {
  212223. firstPresentationTime = presentationTime;
  212224. averageTimeOffset = timeDiff;
  212225. }
  212226. else
  212227. {
  212228. averageTimeOffset = (averageTimeOffset * 120 + timeDiff * 8) / 128;
  212229. }
  212230. }
  212231. @end
  212232. BEGIN_JUCE_NAMESPACE
  212233. class QTCaptureViewerComp : public NSViewComponent
  212234. {
  212235. public:
  212236. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  212237. {
  212238. const ScopedAutoReleasePool pool;
  212239. captureView = [[QTCaptureView alloc] init];
  212240. [captureView setCaptureSession: internal->session];
  212241. setSize (640, 480); // xxx need to somehow get the movie size - how?
  212242. setView (captureView);
  212243. }
  212244. ~QTCaptureViewerComp()
  212245. {
  212246. setView (0);
  212247. [captureView setCaptureSession: nil];
  212248. [captureView release];
  212249. }
  212250. QTCaptureView* captureView;
  212251. };
  212252. CameraDevice::CameraDevice (const String& name_, int index)
  212253. : name (name_)
  212254. {
  212255. isRecording = false;
  212256. internal = new QTCameraDeviceInteral (this, index);
  212257. }
  212258. CameraDevice::~CameraDevice()
  212259. {
  212260. stopRecording();
  212261. delete static_cast <QTCameraDeviceInteral*> (internal);
  212262. internal = 0;
  212263. }
  212264. Component* CameraDevice::createViewerComponent()
  212265. {
  212266. return new QTCaptureViewerComp (this, static_cast <QTCameraDeviceInteral*> (internal));
  212267. }
  212268. const String CameraDevice::getFileExtension()
  212269. {
  212270. return ".mov";
  212271. }
  212272. void CameraDevice::startRecordingToFile (const File& file, int quality)
  212273. {
  212274. stopRecording();
  212275. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212276. d->callbackDelegate->firstPresentationTime = 0;
  212277. file.deleteFile();
  212278. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212279. // out wrong, so we'll put some audio in there too..,
  212280. d->addDefaultAudioInput();
  212281. [d->session addOutput: d->fileOutput error: nil];
  212282. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212283. for (;;)
  212284. {
  212285. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212286. if (connection == 0)
  212287. break;
  212288. QTCompressionOptions* options = 0;
  212289. NSString* mediaType = [connection mediaType];
  212290. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212291. options = [QTCompressionOptions compressionOptionsWithIdentifier:
  212292. quality >= 1 ? @"QTCompressionOptionsSD480SizeH264Video"
  212293. : @"QTCompressionOptions240SizeH264Video"];
  212294. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212295. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212296. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212297. }
  212298. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212299. isRecording = true;
  212300. }
  212301. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212302. {
  212303. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212304. if (d->callbackDelegate->firstPresentationTime != 0)
  212305. return Time (d->callbackDelegate->firstPresentationTime + d->callbackDelegate->averageTimeOffset);
  212306. return Time();
  212307. }
  212308. void CameraDevice::stopRecording()
  212309. {
  212310. if (isRecording)
  212311. {
  212312. static_cast <QTCameraDeviceInteral*> (internal)->resetFile();
  212313. isRecording = false;
  212314. }
  212315. }
  212316. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212317. {
  212318. if (listenerToAdd != 0)
  212319. static_cast <QTCameraDeviceInteral*> (internal)->addListener (listenerToAdd);
  212320. }
  212321. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212322. {
  212323. if (listenerToRemove != 0)
  212324. static_cast <QTCameraDeviceInteral*> (internal)->removeListener (listenerToRemove);
  212325. }
  212326. const StringArray CameraDevice::getAvailableDevices()
  212327. {
  212328. const ScopedAutoReleasePool pool;
  212329. StringArray results;
  212330. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212331. for (int i = 0; i < (int) [devs count]; ++i)
  212332. {
  212333. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212334. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212335. }
  212336. return results;
  212337. }
  212338. CameraDevice* CameraDevice::openDevice (int index,
  212339. int minWidth, int minHeight,
  212340. int maxWidth, int maxHeight)
  212341. {
  212342. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212343. if (static_cast <QTCameraDeviceInteral*> (d->internal)->openingError.isEmpty())
  212344. return d.release();
  212345. return 0;
  212346. }
  212347. #endif
  212348. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212349. #endif
  212350. #endif
  212351. END_JUCE_NAMESPACE
  212352. #endif
  212353. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212354. #endif
  212355. #endif